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 /* Miscellaneous data and functions needed for the parser. */
66 /* Objective-C specific parser/lexer information. */
68 static int objc_pq_context
= 0;
70 /* The following flag is needed to contextualize Objective-C lexical
71 analysis. In some cases (e.g., 'int NSObject;'), it is undesirable
72 to bind an identifier to an Objective-C class, even if a class with
74 static int objc_need_raw_identifier
= 0;
75 #define OBJC_NEED_RAW_IDENTIFIER(VAL) \
77 if (c_dialect_objc ()) \
78 objc_need_raw_identifier = VAL; \
81 /* The reserved keyword table. */
85 ENUM_BITFIELD(rid
) rid
: 16;
86 unsigned int disable
: 16;
89 /* Disable mask. Keywords are disabled if (reswords[i].disable &
91 #define D_C89 0x01 /* not in C89 */
92 #define D_EXT 0x02 /* GCC extension */
93 #define D_EXT89 0x04 /* GCC extension incorporated in C99 */
94 #define D_OBJC 0x08 /* Objective C only */
96 static const struct resword reswords
[] =
98 { "_Bool", RID_BOOL
, 0 },
99 { "_Complex", RID_COMPLEX
, 0 },
100 { "_Decimal32", RID_DFLOAT32
, D_EXT
},
101 { "_Decimal64", RID_DFLOAT64
, D_EXT
},
102 { "_Decimal128", RID_DFLOAT128
, D_EXT
},
103 { "__FUNCTION__", RID_FUNCTION_NAME
, 0 },
104 { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME
, 0 },
105 { "__alignof", RID_ALIGNOF
, 0 },
106 { "__alignof__", RID_ALIGNOF
, 0 },
107 { "__asm", RID_ASM
, 0 },
108 { "__asm__", RID_ASM
, 0 },
109 { "__attribute", RID_ATTRIBUTE
, 0 },
110 { "__attribute__", RID_ATTRIBUTE
, 0 },
111 { "__builtin_choose_expr", RID_CHOOSE_EXPR
, 0 },
112 { "__builtin_offsetof", RID_OFFSETOF
, 0 },
113 { "__builtin_types_compatible_p", RID_TYPES_COMPATIBLE_P
, 0 },
114 { "__builtin_va_arg", RID_VA_ARG
, 0 },
115 { "__complex", RID_COMPLEX
, 0 },
116 { "__complex__", RID_COMPLEX
, 0 },
117 { "__const", RID_CONST
, 0 },
118 { "__const__", RID_CONST
, 0 },
119 { "__extension__", RID_EXTENSION
, 0 },
120 { "__func__", RID_C99_FUNCTION_NAME
, 0 },
121 { "__imag", RID_IMAGPART
, 0 },
122 { "__imag__", RID_IMAGPART
, 0 },
123 { "__inline", RID_INLINE
, 0 },
124 { "__inline__", RID_INLINE
, 0 },
125 { "__label__", RID_LABEL
, 0 },
126 { "__real", RID_REALPART
, 0 },
127 { "__real__", RID_REALPART
, 0 },
128 { "__restrict", RID_RESTRICT
, 0 },
129 { "__restrict__", RID_RESTRICT
, 0 },
130 { "__signed", RID_SIGNED
, 0 },
131 { "__signed__", RID_SIGNED
, 0 },
132 { "__thread", RID_THREAD
, 0 },
133 { "__typeof", RID_TYPEOF
, 0 },
134 { "__typeof__", RID_TYPEOF
, 0 },
135 { "__volatile", RID_VOLATILE
, 0 },
136 { "__volatile__", RID_VOLATILE
, 0 },
137 { "asm", RID_ASM
, D_EXT
},
138 { "auto", RID_AUTO
, 0 },
139 { "break", RID_BREAK
, 0 },
140 { "case", RID_CASE
, 0 },
141 { "char", RID_CHAR
, 0 },
142 { "const", RID_CONST
, 0 },
143 { "continue", RID_CONTINUE
, 0 },
144 { "default", RID_DEFAULT
, 0 },
146 { "double", RID_DOUBLE
, 0 },
147 { "else", RID_ELSE
, 0 },
148 { "enum", RID_ENUM
, 0 },
149 { "extern", RID_EXTERN
, 0 },
150 { "float", RID_FLOAT
, 0 },
151 { "for", RID_FOR
, 0 },
152 { "goto", RID_GOTO
, 0 },
154 { "inline", RID_INLINE
, D_EXT89
},
155 { "int", RID_INT
, 0 },
156 { "long", RID_LONG
, 0 },
157 { "register", RID_REGISTER
, 0 },
158 { "restrict", RID_RESTRICT
, D_C89
},
159 { "return", RID_RETURN
, 0 },
160 { "short", RID_SHORT
, 0 },
161 { "signed", RID_SIGNED
, 0 },
162 { "sizeof", RID_SIZEOF
, 0 },
163 { "static", RID_STATIC
, 0 },
164 { "struct", RID_STRUCT
, 0 },
165 { "switch", RID_SWITCH
, 0 },
166 { "typedef", RID_TYPEDEF
, 0 },
167 { "typeof", RID_TYPEOF
, D_EXT
},
168 { "union", RID_UNION
, 0 },
169 { "unsigned", RID_UNSIGNED
, 0 },
170 { "void", RID_VOID
, 0 },
171 { "volatile", RID_VOLATILE
, 0 },
172 { "while", RID_WHILE
, 0 },
173 /* These Objective-C keywords are recognized only immediately after
175 { "class", RID_AT_CLASS
, D_OBJC
},
176 { "compatibility_alias", RID_AT_ALIAS
, D_OBJC
},
177 { "defs", RID_AT_DEFS
, D_OBJC
},
178 { "encode", RID_AT_ENCODE
, D_OBJC
},
179 { "end", RID_AT_END
, D_OBJC
},
180 { "implementation", RID_AT_IMPLEMENTATION
, D_OBJC
},
181 { "interface", RID_AT_INTERFACE
, D_OBJC
},
182 { "private", RID_AT_PRIVATE
, D_OBJC
},
183 { "protected", RID_AT_PROTECTED
, D_OBJC
},
184 { "protocol", RID_AT_PROTOCOL
, D_OBJC
},
185 { "public", RID_AT_PUBLIC
, D_OBJC
},
186 { "selector", RID_AT_SELECTOR
, D_OBJC
},
187 { "throw", RID_AT_THROW
, D_OBJC
},
188 { "try", RID_AT_TRY
, D_OBJC
},
189 { "catch", RID_AT_CATCH
, D_OBJC
},
190 { "finally", RID_AT_FINALLY
, D_OBJC
},
191 { "synchronized", RID_AT_SYNCHRONIZED
, D_OBJC
},
192 /* These are recognized only in protocol-qualifier context
194 { "bycopy", RID_BYCOPY
, D_OBJC
},
195 { "byref", RID_BYREF
, D_OBJC
},
196 { "in", RID_IN
, D_OBJC
},
197 { "inout", RID_INOUT
, D_OBJC
},
198 { "oneway", RID_ONEWAY
, D_OBJC
},
199 { "out", RID_OUT
, D_OBJC
},
201 #define N_reswords (sizeof reswords / sizeof (struct resword))
203 /* All OpenMP clauses. OpenMP 2.5. */
204 typedef enum pragma_omp_clause
{
205 PRAGMA_OMP_CLAUSE_NONE
= 0,
207 PRAGMA_OMP_CLAUSE_COPYIN
,
208 PRAGMA_OMP_CLAUSE_COPYPRIVATE
,
209 PRAGMA_OMP_CLAUSE_DEFAULT
,
210 PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
,
211 PRAGMA_OMP_CLAUSE_IF
,
212 PRAGMA_OMP_CLAUSE_LASTPRIVATE
,
213 PRAGMA_OMP_CLAUSE_NOWAIT
,
214 PRAGMA_OMP_CLAUSE_NUM_THREADS
,
215 PRAGMA_OMP_CLAUSE_ORDERED
,
216 PRAGMA_OMP_CLAUSE_PRIVATE
,
217 PRAGMA_OMP_CLAUSE_REDUCTION
,
218 PRAGMA_OMP_CLAUSE_SCHEDULE
,
219 PRAGMA_OMP_CLAUSE_SHARED
223 /* Initialization routine for this file. */
228 /* The only initialization required is of the reserved word
232 int mask
= (flag_isoc99
? 0 : D_C89
)
233 | (flag_no_asm
? (flag_isoc99
? D_EXT
: D_EXT
|D_EXT89
) : 0);
235 if (!c_dialect_objc ())
238 ridpointers
= GGC_CNEWVEC (tree
, (int) RID_MAX
);
239 for (i
= 0; i
< N_reswords
; i
++)
241 /* If a keyword is disabled, do not enter it into the table
242 and so create a canonical spelling that isn't a keyword. */
243 if (reswords
[i
].disable
& mask
)
246 id
= get_identifier (reswords
[i
].word
);
247 C_RID_CODE (id
) = reswords
[i
].rid
;
248 C_IS_RESERVED_WORD (id
) = 1;
249 ridpointers
[(int) reswords
[i
].rid
] = id
;
253 /* The C lexer intermediates between the lexer in cpplib and c-lex.c
254 and the C parser. Unlike the C++ lexer, the parser structure
255 stores the lexer information instead of using a separate structure.
256 Identifiers are separated into ordinary identifiers, type names,
257 keywords and some other Objective-C types of identifiers, and some
258 look-ahead is maintained.
260 ??? It might be a good idea to lex the whole file up front (as for
261 C++). It would then be possible to share more of the C and C++
262 lexer code, if desired. */
264 /* The following local token type is used. */
267 #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1))
269 /* More information about the type of a CPP_NAME token. */
270 typedef enum c_id_kind
{
271 /* An ordinary identifier. */
273 /* An identifier declared as a typedef name. */
275 /* An identifier declared as an Objective-C class name. */
277 /* Not an identifier. */
281 /* A single C token after string literal concatenation and conversion
282 of preprocessing tokens to tokens. */
283 typedef struct c_token
GTY (())
285 /* The kind of token. */
286 ENUM_BITFIELD (cpp_ttype
) type
: 8;
287 /* If this token is a CPP_NAME, this value indicates whether also
288 declared as some kind of type. Otherwise, it is C_ID_NONE. */
289 ENUM_BITFIELD (c_id_kind
) id_kind
: 8;
290 /* If this token is a keyword, this value indicates which keyword.
291 Otherwise, this value is RID_MAX. */
292 ENUM_BITFIELD (rid
) keyword
: 8;
293 /* If this token is a CPP_PRAGMA, this indicates the pragma that
294 was seen. Otherwise it is PRAGMA_NONE. */
295 ENUM_BITFIELD (pragma_kind
) pragma_kind
: 7;
296 /* True if this token is from a system header. */
297 BOOL_BITFIELD in_system_header
: 1;
298 /* The value associated with this token, if any. */
300 /* The location at which this token was found. */
304 /* A parser structure recording information about the state and
305 context of parsing. Includes lexer information with up to two
306 tokens of look-ahead; more are not needed for C. */
307 typedef struct c_parser
GTY(())
309 /* The look-ahead tokens. */
311 /* How many look-ahead tokens are available (0, 1 or 2). */
313 /* True if a syntax error is being recovered from; false otherwise.
314 c_parser_error sets this flag. It should clear this flag when
315 enough tokens have been consumed to recover from the error. */
316 BOOL_BITFIELD error
: 1;
317 /* True if we're processing a pragma, and shouldn't automatically
318 consume CPP_PRAGMA_EOL. */
319 BOOL_BITFIELD in_pragma
: 1;
323 /* The actual parser and external interface. ??? Does this need to be
324 garbage-collected? */
326 static GTY (()) c_parser
*the_parser
;
329 /* Read in and lex a single token, storing it in *TOKEN. */
332 c_lex_one_token (c_token
*token
)
334 timevar_push (TV_LEX
);
336 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
, NULL
);
337 token
->id_kind
= C_ID_NONE
;
338 token
->keyword
= RID_MAX
;
339 token
->pragma_kind
= PRAGMA_NONE
;
340 token
->in_system_header
= in_system_header
;
348 int objc_force_identifier
= objc_need_raw_identifier
;
349 OBJC_NEED_RAW_IDENTIFIER (0);
351 if (C_IS_RESERVED_WORD (token
->value
))
353 enum rid rid_code
= C_RID_CODE (token
->value
);
355 if (c_dialect_objc ())
357 if (!OBJC_IS_AT_KEYWORD (rid_code
)
358 && (!OBJC_IS_PQ_KEYWORD (rid_code
) || objc_pq_context
))
360 /* Return the canonical spelling for this keyword. */
361 token
->value
= ridpointers
[(int) rid_code
];
362 token
->type
= CPP_KEYWORD
;
363 token
->keyword
= rid_code
;
369 /* Return the canonical spelling for this keyword. */
370 token
->value
= ridpointers
[(int) rid_code
];
371 token
->type
= CPP_KEYWORD
;
372 token
->keyword
= rid_code
;
377 decl
= lookup_name (token
->value
);
380 if (TREE_CODE (decl
) == TYPE_DECL
)
382 token
->id_kind
= C_ID_TYPENAME
;
386 else if (c_dialect_objc ())
388 tree objc_interface_decl
= objc_is_class_name (token
->value
);
389 /* Objective-C class names are in the same namespace as
390 variables and typedefs, and hence are shadowed by local
392 if (objc_interface_decl
393 && (global_bindings_p ()
394 || (!objc_force_identifier
&& !decl
)))
396 token
->value
= objc_interface_decl
;
397 token
->id_kind
= C_ID_CLASSNAME
;
401 token
->id_kind
= C_ID_ID
;
405 /* This only happens in Objective-C; it must be a keyword. */
406 token
->type
= CPP_KEYWORD
;
407 token
->keyword
= C_RID_CODE (token
->value
);
411 case CPP_CLOSE_PAREN
:
413 /* These tokens may affect the interpretation of any identifiers
414 following, if doing Objective-C. */
415 OBJC_NEED_RAW_IDENTIFIER (0);
418 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
419 token
->pragma_kind
= TREE_INT_CST_LOW (token
->value
);
425 timevar_pop (TV_LEX
);
428 /* Return a pointer to the next token from PARSER, reading it in if
431 static inline c_token
*
432 c_parser_peek_token (c_parser
*parser
)
434 if (parser
->tokens_avail
== 0)
436 c_lex_one_token (&parser
->tokens
[0]);
437 parser
->tokens_avail
= 1;
439 return &parser
->tokens
[0];
442 /* Return true if the next token from PARSER has the indicated
446 c_parser_next_token_is (c_parser
*parser
, enum cpp_ttype type
)
448 return c_parser_peek_token (parser
)->type
== type
;
451 /* Return true if the next token from PARSER does not have the
455 c_parser_next_token_is_not (c_parser
*parser
, enum cpp_ttype type
)
457 return !c_parser_next_token_is (parser
, type
);
460 /* Return true if the next token from PARSER is the indicated
464 c_parser_next_token_is_keyword (c_parser
*parser
, enum rid keyword
)
468 /* Peek at the next token. */
469 token
= c_parser_peek_token (parser
);
470 /* Check to see if it is the indicated keyword. */
471 return token
->keyword
== keyword
;
474 /* Return true if TOKEN can start a type name,
477 c_token_starts_typename (c_token
*token
)
482 switch (token
->id_kind
)
489 gcc_assert (c_dialect_objc ());
495 switch (token
->keyword
)
524 if (c_dialect_objc ())
532 /* Return true if the next token from PARSER can start a type name,
535 c_parser_next_token_starts_typename (c_parser
*parser
)
537 c_token
*token
= c_parser_peek_token (parser
);
538 return c_token_starts_typename (token
);
541 /* Return true if TOKEN can start declaration specifiers, false
544 c_token_starts_declspecs (c_token
*token
)
549 switch (token
->id_kind
)
556 gcc_assert (c_dialect_objc ());
562 switch (token
->keyword
)
598 if (c_dialect_objc ())
606 /* Return true if the next token from PARSER can start declaration
607 specifiers, false otherwise. */
609 c_parser_next_token_starts_declspecs (c_parser
*parser
)
611 c_token
*token
= c_parser_peek_token (parser
);
612 return c_token_starts_declspecs (token
);
615 /* Return a pointer to the next-but-one token from PARSER, reading it
616 in if necessary. The next token is already read in. */
619 c_parser_peek_2nd_token (c_parser
*parser
)
621 if (parser
->tokens_avail
>= 2)
622 return &parser
->tokens
[1];
623 gcc_assert (parser
->tokens_avail
== 1);
624 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
625 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
626 c_lex_one_token (&parser
->tokens
[1]);
627 parser
->tokens_avail
= 2;
628 return &parser
->tokens
[1];
631 /* Consume the next token from PARSER. */
634 c_parser_consume_token (c_parser
*parser
)
636 gcc_assert (parser
->tokens_avail
>= 1);
637 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
638 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
639 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
640 if (parser
->tokens_avail
== 2)
641 parser
->tokens
[0] = parser
->tokens
[1];
642 parser
->tokens_avail
--;
645 /* Expect the current token to be a #pragma. Consume it and remember
646 that we've begun parsing a pragma. */
649 c_parser_consume_pragma (c_parser
*parser
)
651 gcc_assert (!parser
->in_pragma
);
652 gcc_assert (parser
->tokens_avail
>= 1);
653 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
654 if (parser
->tokens_avail
== 2)
655 parser
->tokens
[0] = parser
->tokens
[1];
656 parser
->tokens_avail
--;
657 parser
->in_pragma
= true;
660 /* Update the globals input_location and in_system_header from
663 c_parser_set_source_position_from_token (c_token
*token
)
665 if (token
->type
!= CPP_EOF
)
667 input_location
= token
->location
;
668 in_system_header
= token
->in_system_header
;
672 /* Issue a diagnostic of the form
673 FILE:LINE: MESSAGE before TOKEN
674 where TOKEN is the next token in the input stream of PARSER.
675 MESSAGE (specified by the caller) is usually of the form "expected
678 Do not issue a diagnostic if still recovering from an error.
680 ??? This is taken from the C++ parser, but building up messages in
681 this way is not i18n-friendly and some other approach should be
685 c_parser_error (c_parser
*parser
, const char *gmsgid
)
687 c_token
*token
= c_parser_peek_token (parser
);
690 parser
->error
= true;
693 /* This diagnostic makes more sense if it is tagged to the line of
694 the token we just peeked at. */
695 c_parser_set_source_position_from_token (token
);
696 c_parse_error (gmsgid
,
697 /* Because c_parse_error does not understand
698 CPP_KEYWORD, keywords are treated like
700 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
704 /* If the next token is of the indicated TYPE, consume it. Otherwise,
705 issue the error MSGID. If MSGID is NULL then a message has already
706 been produced and no message will be produced this time. Returns
707 true if found, false otherwise. */
710 c_parser_require (c_parser
*parser
,
714 if (c_parser_next_token_is (parser
, type
))
716 c_parser_consume_token (parser
);
721 c_parser_error (parser
, msgid
);
726 /* If the next token is the indicated keyword, consume it. Otherwise,
727 issue the error MSGID. Returns true if found, false otherwise. */
730 c_parser_require_keyword (c_parser
*parser
,
734 if (c_parser_next_token_is_keyword (parser
, keyword
))
736 c_parser_consume_token (parser
);
741 c_parser_error (parser
, msgid
);
746 /* Like c_parser_require, except that tokens will be skipped until the
747 desired token is found. An error message is still produced if the
748 next token is not as expected. If MSGID is NULL then a message has
749 already been produced and no message will be produced this
753 c_parser_skip_until_found (c_parser
*parser
,
757 unsigned nesting_depth
= 0;
759 if (c_parser_require (parser
, type
, msgid
))
762 /* Skip tokens until the desired token is found. */
765 /* Peek at the next token. */
766 c_token
*token
= c_parser_peek_token (parser
);
767 /* If we've reached the token we want, consume it and stop. */
768 if (token
->type
== type
&& !nesting_depth
)
770 c_parser_consume_token (parser
);
774 /* If we've run out of tokens, stop. */
775 if (token
->type
== CPP_EOF
)
777 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
779 if (token
->type
== CPP_OPEN_BRACE
780 || token
->type
== CPP_OPEN_PAREN
781 || token
->type
== CPP_OPEN_SQUARE
)
783 else if (token
->type
== CPP_CLOSE_BRACE
784 || token
->type
== CPP_CLOSE_PAREN
785 || token
->type
== CPP_CLOSE_SQUARE
)
787 if (nesting_depth
-- == 0)
790 /* Consume this token. */
791 c_parser_consume_token (parser
);
793 parser
->error
= false;
796 /* Skip tokens until the end of a parameter is found, but do not
797 consume the comma, semicolon or closing delimiter. */
800 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
802 unsigned nesting_depth
= 0;
806 c_token
*token
= c_parser_peek_token (parser
);
807 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
810 /* If we've run out of tokens, stop. */
811 if (token
->type
== CPP_EOF
)
813 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
815 if (token
->type
== CPP_OPEN_BRACE
816 || token
->type
== CPP_OPEN_PAREN
817 || token
->type
== CPP_OPEN_SQUARE
)
819 else if (token
->type
== CPP_CLOSE_BRACE
820 || token
->type
== CPP_CLOSE_PAREN
821 || token
->type
== CPP_CLOSE_SQUARE
)
823 if (nesting_depth
-- == 0)
826 /* Consume this token. */
827 c_parser_consume_token (parser
);
829 parser
->error
= false;
832 /* Expect to be at the end of the pragma directive and consume an
833 end of line marker. */
836 c_parser_skip_to_pragma_eol (c_parser
*parser
)
838 gcc_assert (parser
->in_pragma
);
839 parser
->in_pragma
= false;
841 if (!c_parser_require (parser
, CPP_PRAGMA_EOL
, "expected end of line"))
844 c_token
*token
= c_parser_peek_token (parser
);
845 if (token
->type
== CPP_EOF
)
847 if (token
->type
== CPP_PRAGMA_EOL
)
849 c_parser_consume_token (parser
);
852 c_parser_consume_token (parser
);
855 parser
->error
= false;
858 /* Skip tokens until we have consumed an entire block, or until we
859 have consumed a non-nested ';'. */
862 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
864 unsigned nesting_depth
= 0;
865 bool save_error
= parser
->error
;
871 /* Peek at the next token. */
872 token
= c_parser_peek_token (parser
);
880 if (parser
->in_pragma
)
885 /* If the next token is a ';', we have reached the
886 end of the statement. */
889 /* Consume the ';'. */
890 c_parser_consume_token (parser
);
895 case CPP_CLOSE_BRACE
:
896 /* If the next token is a non-nested '}', then we have
897 reached the end of the current block. */
898 if (nesting_depth
== 0 || --nesting_depth
== 0)
900 c_parser_consume_token (parser
);
906 /* If it the next token is a '{', then we are entering a new
907 block. Consume the entire block. */
912 /* If we see a pragma, consume the whole thing at once. We
913 have some safeguards against consuming pragmas willy-nilly.
914 Normally, we'd expect to be here with parser->error set,
915 which disables these safeguards. But it's possible to get
916 here for secondary error recovery, after parser->error has
918 c_parser_consume_pragma (parser
);
919 c_parser_skip_to_pragma_eol (parser
);
920 parser
->error
= save_error
;
927 c_parser_consume_token (parser
);
931 parser
->error
= false;
934 /* Save the warning flags which are controlled by __extension__. */
937 disable_extension_diagnostics (void)
940 | (warn_pointer_arith
<< 1)
941 | (warn_traditional
<< 2)
944 warn_pointer_arith
= 0;
945 warn_traditional
= 0;
950 /* Restore the warning flags which are controlled by __extension__.
951 FLAGS is the return value from disable_extension_diagnostics. */
954 restore_extension_diagnostics (int flags
)
956 pedantic
= flags
& 1;
957 warn_pointer_arith
= (flags
>> 1) & 1;
958 warn_traditional
= (flags
>> 2) & 1;
959 flag_iso
= (flags
>> 3) & 1;
962 /* Possibly kinds of declarator to parse. */
963 typedef enum c_dtr_syn
{
964 /* A normal declarator with an identifier. */
966 /* An abstract declarator (maybe empty). */
968 /* A parameter declarator: may be either, but after a type name does
969 not redeclare a typedef name as an identifier if it can
970 alternatively be interpreted as a typedef name; see DR#009,
971 applied in C90 TC1, omitted from C99 and reapplied in C99 TC2
972 following DR#249. For example, given a typedef T, "int T" and
973 "int *T" are valid parameter declarations redeclaring T, while
974 "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are
975 abstract declarators rather than involving redundant parentheses;
976 the same applies with attributes inside the parentheses before
981 static void c_parser_external_declaration (c_parser
*);
982 static void c_parser_asm_definition (c_parser
*);
983 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool, bool);
984 static void c_parser_declspecs (c_parser
*, struct c_declspecs
*, bool, bool,
986 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
987 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
988 static tree
c_parser_struct_declaration (c_parser
*);
989 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
990 static struct c_declarator
*c_parser_declarator (c_parser
*, bool, c_dtr_syn
,
992 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
994 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
996 struct c_declarator
*);
997 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
998 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
);
999 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1000 static tree
c_parser_simple_asm_expr (c_parser
*);
1001 static tree
c_parser_attributes (c_parser
*);
1002 static struct c_type_name
*c_parser_type_name (c_parser
*);
1003 static struct c_expr
c_parser_initializer (c_parser
*);
1004 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool);
1005 static void c_parser_initelt (c_parser
*);
1006 static void c_parser_initval (c_parser
*, struct c_expr
*);
1007 static tree
c_parser_compound_statement (c_parser
*);
1008 static void c_parser_compound_statement_nostart (c_parser
*);
1009 static void c_parser_label (c_parser
*);
1010 static void c_parser_statement (c_parser
*);
1011 static void c_parser_statement_after_labels (c_parser
*);
1012 static void c_parser_if_statement (c_parser
*);
1013 static void c_parser_switch_statement (c_parser
*);
1014 static void c_parser_while_statement (c_parser
*);
1015 static void c_parser_do_statement (c_parser
*);
1016 static void c_parser_for_statement (c_parser
*);
1017 static tree
c_parser_asm_statement (c_parser
*);
1018 static tree
c_parser_asm_operands (c_parser
*, bool);
1019 static tree
c_parser_asm_clobbers (c_parser
*);
1020 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*);
1021 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1023 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*);
1024 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1025 static struct c_expr
c_parser_unary_expression (c_parser
*);
1026 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1027 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1028 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1029 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1030 struct c_type_name
*);
1031 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1033 static struct c_expr
c_parser_expression (c_parser
*);
1034 static struct c_expr
c_parser_expression_conv (c_parser
*);
1035 static tree
c_parser_expr_list (c_parser
*, bool);
1036 static void c_parser_omp_construct (c_parser
*);
1037 static void c_parser_omp_threadprivate (c_parser
*);
1038 static void c_parser_omp_barrier (c_parser
*);
1039 static void c_parser_omp_flush (c_parser
*);
1041 enum pragma_context
{ pragma_external
, pragma_stmt
, pragma_compound
};
1042 static bool c_parser_pragma (c_parser
*, enum pragma_context
);
1044 /* These Objective-C parser functions are only ever called when
1045 compiling Objective-C. */
1046 static void c_parser_objc_class_definition (c_parser
*);
1047 static void c_parser_objc_class_instance_variables (c_parser
*);
1048 static void c_parser_objc_class_declaration (c_parser
*);
1049 static void c_parser_objc_alias_declaration (c_parser
*);
1050 static void c_parser_objc_protocol_definition (c_parser
*);
1051 static enum tree_code
c_parser_objc_method_type (c_parser
*);
1052 static void c_parser_objc_method_definition (c_parser
*);
1053 static void c_parser_objc_methodprotolist (c_parser
*);
1054 static void c_parser_objc_methodproto (c_parser
*);
1055 static tree
c_parser_objc_method_decl (c_parser
*);
1056 static tree
c_parser_objc_type_name (c_parser
*);
1057 static tree
c_parser_objc_protocol_refs (c_parser
*);
1058 static void c_parser_objc_try_catch_statement (c_parser
*);
1059 static void c_parser_objc_synchronized_statement (c_parser
*);
1060 static tree
c_parser_objc_selector (c_parser
*);
1061 static tree
c_parser_objc_selector_arg (c_parser
*);
1062 static tree
c_parser_objc_receiver (c_parser
*);
1063 static tree
c_parser_objc_message_args (c_parser
*);
1064 static tree
c_parser_objc_keywordexpr (c_parser
*);
1066 /* Parse a translation unit (C90 6.7, C99 6.9).
1069 external-declarations
1071 external-declarations:
1072 external-declaration
1073 external-declarations external-declaration
1082 c_parser_translation_unit (c_parser
*parser
)
1084 if (c_parser_next_token_is (parser
, CPP_EOF
))
1087 pedwarn ("ISO C forbids an empty source file");
1091 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1095 c_parser_external_declaration (parser
);
1096 obstack_free (&parser_obstack
, obstack_position
);
1098 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1102 /* Parse an external declaration (C90 6.7, C99 6.9).
1104 external-declaration:
1110 external-declaration:
1113 __extension__ external-declaration
1117 external-declaration:
1118 objc-class-definition
1119 objc-class-declaration
1120 objc-alias-declaration
1121 objc-protocol-definition
1122 objc-method-definition
1127 c_parser_external_declaration (c_parser
*parser
)
1130 switch (c_parser_peek_token (parser
)->type
)
1133 switch (c_parser_peek_token (parser
)->keyword
)
1136 ext
= disable_extension_diagnostics ();
1137 c_parser_consume_token (parser
);
1138 c_parser_external_declaration (parser
);
1139 restore_extension_diagnostics (ext
);
1142 c_parser_asm_definition (parser
);
1144 case RID_AT_INTERFACE
:
1145 case RID_AT_IMPLEMENTATION
:
1146 gcc_assert (c_dialect_objc ());
1147 c_parser_objc_class_definition (parser
);
1150 gcc_assert (c_dialect_objc ());
1151 c_parser_objc_class_declaration (parser
);
1154 gcc_assert (c_dialect_objc ());
1155 c_parser_objc_alias_declaration (parser
);
1157 case RID_AT_PROTOCOL
:
1158 gcc_assert (c_dialect_objc ());
1159 c_parser_objc_protocol_definition (parser
);
1162 gcc_assert (c_dialect_objc ());
1163 c_parser_consume_token (parser
);
1164 objc_finish_implementation ();
1172 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
1173 c_parser_consume_token (parser
);
1176 c_parser_pragma (parser
, pragma_external
);
1180 if (c_dialect_objc ())
1182 c_parser_objc_method_definition (parser
);
1185 /* Else fall through, and yield a syntax error trying to parse
1186 as a declaration or function definition. */
1189 /* A declaration or a function definition. We can only tell
1190 which after parsing the declaration specifiers, if any, and
1191 the first declarator. */
1192 c_parser_declaration_or_fndef (parser
, true, true, false, true);
1198 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1199 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1200 accepted; otherwise (old-style parameter declarations) only other
1201 declarations are accepted. If NESTED is true, we are inside a
1202 function or parsing old-style parameter declarations; any functions
1203 encountered are nested functions and declaration specifiers are
1204 required; otherwise we are at top level and functions are normal
1205 functions and declaration specifiers may be optional. If EMPTY_OK
1206 is true, empty declarations are OK (subject to all other
1207 constraints); otherwise (old-style parameter declarations) they are
1208 diagnosed. If START_ATTR_OK is true, the declaration specifiers
1209 may start with attributes; otherwise they may not.
1212 declaration-specifiers init-declarator-list[opt] ;
1214 function-definition:
1215 declaration-specifiers[opt] declarator declaration-list[opt]
1220 declaration-list declaration
1222 init-declarator-list:
1224 init-declarator-list , init-declarator
1227 declarator simple-asm-expr[opt] attributes[opt]
1228 declarator simple-asm-expr[opt] attributes[opt] = initializer
1232 nested-function-definition:
1233 declaration-specifiers declarator declaration-list[opt]
1236 The simple-asm-expr and attributes are GNU extensions.
1238 This function does not handle __extension__; that is handled in its
1239 callers. ??? Following the old parser, __extension__ may start
1240 external declarations, declarations in functions and declarations
1241 at the start of "for" loops, but not old-style parameter
1244 C99 requires declaration specifiers in a function definition; the
1245 absence is diagnosed through the diagnosis of implicit int. In GNU
1246 C we also allow but diagnose declarations without declaration
1247 specifiers, but only at top level (elsewhere they conflict with
1253 threadprivate-directive */
1256 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
, bool empty_ok
,
1257 bool nested
, bool start_attr_ok
)
1259 struct c_declspecs
*specs
;
1261 tree all_prefix_attrs
;
1262 bool diagnosed_no_specs
= false;
1264 specs
= build_null_declspecs ();
1265 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
);
1268 c_parser_skip_to_end_of_block_or_statement (parser
);
1271 if (nested
&& !specs
->declspecs_seen_p
)
1273 c_parser_error (parser
, "expected declaration specifiers");
1274 c_parser_skip_to_end_of_block_or_statement (parser
);
1277 finish_declspecs (specs
);
1278 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1284 shadow_tag_warned (specs
, 1);
1285 pedwarn ("empty declaration");
1287 c_parser_consume_token (parser
);
1290 pending_xref_error ();
1291 prefix_attrs
= specs
->attrs
;
1292 all_prefix_attrs
= prefix_attrs
;
1293 specs
->attrs
= NULL_TREE
;
1296 struct c_declarator
*declarator
;
1299 /* Declaring either one or more declarators (in which case we
1300 should diagnose if there were no declaration specifiers) or a
1301 function definition (in which case the diagnostic for
1302 implicit int suffices). */
1303 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
1304 C_DTR_NORMAL
, &dummy
);
1305 if (declarator
== NULL
)
1307 c_parser_skip_to_end_of_block_or_statement (parser
);
1310 if (c_parser_next_token_is (parser
, CPP_EQ
)
1311 || c_parser_next_token_is (parser
, CPP_COMMA
)
1312 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1313 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1314 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1316 tree asm_name
= NULL_TREE
;
1317 tree postfix_attrs
= NULL_TREE
;
1318 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1320 diagnosed_no_specs
= true;
1321 pedwarn ("data definition has no type or storage class");
1323 /* Having seen a data definition, there cannot now be a
1324 function definition. */
1326 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1327 asm_name
= c_parser_simple_asm_expr (parser
);
1328 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1329 postfix_attrs
= c_parser_attributes (parser
);
1330 if (c_parser_next_token_is (parser
, CPP_EQ
))
1334 c_parser_consume_token (parser
);
1335 /* The declaration of the variable is in effect while
1336 its initializer is parsed. */
1337 d
= start_decl (declarator
, specs
, true,
1338 chainon (postfix_attrs
, all_prefix_attrs
));
1340 d
= error_mark_node
;
1341 start_init (d
, asm_name
, global_bindings_p ());
1342 init
= c_parser_initializer (parser
);
1344 if (d
!= error_mark_node
)
1346 maybe_warn_string_init (TREE_TYPE (d
), init
);
1347 finish_decl (d
, init
.value
, asm_name
);
1352 tree d
= start_decl (declarator
, specs
, false,
1353 chainon (postfix_attrs
,
1356 finish_decl (d
, NULL_TREE
, asm_name
);
1358 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1360 c_parser_consume_token (parser
);
1361 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1362 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1365 all_prefix_attrs
= prefix_attrs
;
1368 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1370 c_parser_consume_token (parser
);
1375 c_parser_error (parser
, "expected %<,%> or %<;%>");
1376 c_parser_skip_to_end_of_block_or_statement (parser
);
1382 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
1383 "%<asm%> or %<__attribute__%>");
1384 c_parser_skip_to_end_of_block_or_statement (parser
);
1387 /* Function definition (nested or otherwise). */
1391 pedwarn ("ISO C forbids nested functions");
1392 push_function_context ();
1394 if (!start_function (specs
, declarator
, all_prefix_attrs
))
1396 /* This can appear in many cases looking nothing like a
1397 function definition, so we don't give a more specific
1398 error suggesting there was one. */
1399 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1400 "or %<__attribute__%>");
1402 pop_function_context ();
1405 /* Parse old-style parameter declarations. ??? Attributes are
1406 not allowed to start declaration specifiers here because of a
1407 syntax conflict between a function declaration with attribute
1408 suffix and a function definition with an attribute prefix on
1409 first old-style parameter declaration. Following the old
1410 parser, they are not accepted on subsequent old-style
1411 parameter declarations either. However, there is no
1412 ambiguity after the first declaration, nor indeed on the
1413 first as long as we don't allow postfix attributes after a
1414 declarator with a nonempty identifier list in a definition;
1415 and postfix attributes have never been accepted here in
1416 function definitions either. */
1417 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
1418 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
1419 c_parser_declaration_or_fndef (parser
, false, false, true, false);
1420 DECL_SOURCE_LOCATION (current_function_decl
)
1421 = c_parser_peek_token (parser
)->location
;
1422 store_parm_decls ();
1423 fnbody
= c_parser_compound_statement (parser
);
1426 tree decl
= current_function_decl
;
1429 pop_function_context ();
1430 add_stmt (build_stmt (DECL_EXPR
, decl
));
1441 /* Parse an asm-definition (asm() outside a function body). This is a
1449 c_parser_asm_definition (c_parser
*parser
)
1451 tree asm_str
= c_parser_simple_asm_expr (parser
);
1453 cgraph_add_asm_node (asm_str
);
1454 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
1457 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
1458 6.7), adding them to SPECS (which may already include some).
1459 Storage class specifiers are accepted iff SCSPEC_OK; type
1460 specifiers are accepted iff TYPESPEC_OK; attributes are accepted at
1461 the start iff START_ATTR_OK.
1463 declaration-specifiers:
1464 storage-class-specifier declaration-specifiers[opt]
1465 type-specifier declaration-specifiers[opt]
1466 type-qualifier declaration-specifiers[opt]
1467 function-specifier declaration-specifiers[opt]
1469 Function specifiers (inline) are from C99, and are currently
1470 handled as storage class specifiers, as is __thread.
1472 C90 6.5.1, C99 6.7.1:
1473 storage-class-specifier:
1484 C90 6.5.2, C99 6.7.2:
1497 [_Imaginary removed in C99 TC2]
1498 struct-or-union-specifier
1502 (_Bool and _Complex are new in C99.)
1504 C90 6.5.3, C99 6.7.3:
1511 (restrict is new in C99.)
1515 declaration-specifiers:
1516 attributes declaration-specifiers[opt]
1518 storage-class-specifier:
1530 class-name objc-protocol-refs[opt]
1531 typedef-name objc-protocol-refs
1536 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
1537 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
)
1539 bool attrs_ok
= start_attr_ok
;
1540 bool seen_type
= specs
->type_seen_p
;
1541 while (c_parser_next_token_is (parser
, CPP_NAME
)
1542 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
1543 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
1545 struct c_typespec t
;
1547 if (c_parser_next_token_is (parser
, CPP_NAME
))
1549 tree value
= c_parser_peek_token (parser
)->value
;
1550 c_id_kind kind
= c_parser_peek_token (parser
)->id_kind
;
1551 /* This finishes the specifiers unless a type name is OK, it
1552 is declared as a type name and a type name hasn't yet
1554 if (!typespec_ok
|| seen_type
1555 || (kind
!= C_ID_TYPENAME
&& kind
!= C_ID_CLASSNAME
))
1557 c_parser_consume_token (parser
);
1560 if (kind
== C_ID_TYPENAME
1561 && (!c_dialect_objc ()
1562 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
1564 t
.kind
= ctsk_typedef
;
1565 /* For a typedef name, record the meaning, not the name.
1566 In case of 'foo foo, bar;'. */
1567 t
.spec
= lookup_name (value
);
1571 tree proto
= NULL_TREE
;
1572 gcc_assert (c_dialect_objc ());
1574 if (c_parser_next_token_is (parser
, CPP_LESS
))
1575 proto
= c_parser_objc_protocol_refs (parser
);
1576 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
1578 declspecs_add_type (specs
, t
);
1581 if (c_parser_next_token_is (parser
, CPP_LESS
))
1583 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
1584 nisse@lysator.liu.se. */
1586 gcc_assert (c_dialect_objc ());
1587 if (!typespec_ok
|| seen_type
)
1589 proto
= c_parser_objc_protocol_refs (parser
);
1591 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
1592 declspecs_add_type (specs
, t
);
1595 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
1596 switch (c_parser_peek_token (parser
)->keyword
)
1608 /* TODO: Distinguish between function specifiers (inline)
1609 and storage class specifiers, either here or in
1610 declspecs_add_scspec. */
1611 declspecs_add_scspec (specs
, c_parser_peek_token (parser
)->value
);
1612 c_parser_consume_token (parser
);
1632 OBJC_NEED_RAW_IDENTIFIER (1);
1633 t
.kind
= ctsk_resword
;
1634 t
.spec
= c_parser_peek_token (parser
)->value
;
1635 declspecs_add_type (specs
, t
);
1636 c_parser_consume_token (parser
);
1643 t
= c_parser_enum_specifier (parser
);
1644 declspecs_add_type (specs
, t
);
1652 t
= c_parser_struct_or_union_specifier (parser
);
1653 declspecs_add_type (specs
, t
);
1656 /* ??? The old parser rejected typeof after other type
1657 specifiers, but is a syntax error the best way of
1659 if (!typespec_ok
|| seen_type
)
1663 t
= c_parser_typeof_specifier (parser
);
1664 declspecs_add_type (specs
, t
);
1670 declspecs_add_qual (specs
, c_parser_peek_token (parser
)->value
);
1671 c_parser_consume_token (parser
);
1676 attrs
= c_parser_attributes (parser
);
1677 declspecs_add_attrs (specs
, attrs
);
1686 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
1689 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
1690 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
1691 enum attributes[opt] identifier
1693 The form with trailing comma is new in C99. The forms with
1694 attributes are GNU extensions. In GNU C, we accept any expression
1695 without commas in the syntax (assignment expressions, not just
1696 conditional expressions); assignment expressions will be diagnosed
1701 enumerator-list , enumerator
1704 enumeration-constant
1705 enumeration-constant = constant-expression
1708 static struct c_typespec
1709 c_parser_enum_specifier (c_parser
*parser
)
1711 struct c_typespec ret
;
1713 tree ident
= NULL_TREE
;
1714 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
1715 c_parser_consume_token (parser
);
1716 attrs
= c_parser_attributes (parser
);
1717 if (c_parser_next_token_is (parser
, CPP_NAME
))
1719 ident
= c_parser_peek_token (parser
)->value
;
1720 c_parser_consume_token (parser
);
1722 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1724 /* Parse an enum definition. */
1725 tree type
= start_enum (ident
);
1727 /* We chain the enumerators in reverse order, then put them in
1728 forward order at the end. */
1729 tree values
= NULL_TREE
;
1730 c_parser_consume_token (parser
);
1737 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
1739 c_parser_error (parser
, "expected identifier");
1740 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1741 values
= error_mark_node
;
1744 enum_id
= c_parser_peek_token (parser
)->value
;
1745 c_parser_consume_token (parser
);
1746 if (c_parser_next_token_is (parser
, CPP_EQ
))
1748 c_parser_consume_token (parser
);
1749 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
1752 enum_value
= NULL_TREE
;
1753 enum_decl
= build_enumerator (enum_id
, enum_value
);
1754 TREE_CHAIN (enum_decl
) = values
;
1757 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1760 c_parser_consume_token (parser
);
1762 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1764 if (seen_comma
&& pedantic
&& !flag_isoc99
)
1765 pedwarn ("comma at end of enumerator list");
1766 c_parser_consume_token (parser
);
1771 c_parser_error (parser
, "expected %<,%> or %<}%>");
1772 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1773 values
= error_mark_node
;
1777 postfix_attrs
= c_parser_attributes (parser
);
1778 ret
.spec
= finish_enum (type
, nreverse (values
),
1779 chainon (attrs
, postfix_attrs
));
1780 ret
.kind
= ctsk_tagdef
;
1785 c_parser_error (parser
, "expected %<{%>");
1786 ret
.spec
= error_mark_node
;
1787 ret
.kind
= ctsk_tagref
;
1790 ret
= parser_xref_tag (ENUMERAL_TYPE
, ident
);
1791 /* In ISO C, enumerated types can be referred to only if already
1793 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
1794 pedwarn ("ISO C forbids forward references to %<enum%> types");
1798 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
1800 struct-or-union-specifier:
1801 struct-or-union attributes[opt] identifier[opt]
1802 { struct-contents } attributes[opt]
1803 struct-or-union attributes[opt] identifier
1806 struct-declaration-list
1808 struct-declaration-list:
1809 struct-declaration ;
1810 struct-declaration-list struct-declaration ;
1817 struct-declaration-list struct-declaration
1819 struct-declaration-list:
1820 struct-declaration-list ;
1823 (Note that in the syntax here, unlike that in ISO C, the semicolons
1824 are included here rather than in struct-declaration, in order to
1825 describe the syntax with extra semicolons and missing semicolon at
1830 struct-declaration-list:
1831 @defs ( class-name )
1833 (Note this does not include a trailing semicolon, but can be
1834 followed by further declarations, and gets a pedwarn-if-pedantic
1835 when followed by a semicolon.) */
1837 static struct c_typespec
1838 c_parser_struct_or_union_specifier (c_parser
*parser
)
1840 struct c_typespec ret
;
1842 tree ident
= NULL_TREE
;
1843 enum tree_code code
;
1844 switch (c_parser_peek_token (parser
)->keyword
)
1855 c_parser_consume_token (parser
);
1856 attrs
= c_parser_attributes (parser
);
1857 if (c_parser_next_token_is (parser
, CPP_NAME
))
1859 ident
= c_parser_peek_token (parser
)->value
;
1860 c_parser_consume_token (parser
);
1862 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1864 /* Parse a struct or union definition. Start the scope of the
1865 tag before parsing components. */
1866 tree type
= start_struct (code
, ident
);
1868 /* We chain the components in reverse order, then put them in
1869 forward order at the end. Each struct-declaration may
1870 declare multiple components (comma-separated), so we must use
1871 chainon to join them, although when parsing each
1872 struct-declaration we can use TREE_CHAIN directly.
1874 The theory behind all this is that there will be more
1875 semicolon separated fields than comma separated fields, and
1876 so we'll be minimizing the number of node traversals required
1878 tree contents
= NULL_TREE
;
1879 c_parser_consume_token (parser
);
1880 /* Handle the Objective-C @defs construct,
1881 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
1882 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
1885 gcc_assert (c_dialect_objc ());
1886 c_parser_consume_token (parser
);
1887 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1889 if (c_parser_next_token_is (parser
, CPP_NAME
)
1890 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
1892 name
= c_parser_peek_token (parser
)->value
;
1893 c_parser_consume_token (parser
);
1897 c_parser_error (parser
, "expected class name");
1898 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
1901 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1903 contents
= nreverse (objc_get_class_ivars (name
));
1906 /* Parse the struct-declarations and semicolons. Problems with
1907 semicolons are diagnosed here; empty structures are diagnosed
1912 /* Parse any stray semicolon. */
1913 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1916 pedwarn ("extra semicolon in struct or union specified");
1917 c_parser_consume_token (parser
);
1920 /* Stop if at the end of the struct or union contents. */
1921 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1923 c_parser_consume_token (parser
);
1926 /* Accept #pragmas at struct scope. */
1927 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
1929 c_parser_pragma (parser
, pragma_external
);
1932 /* Parse some comma-separated declarations, but not the
1933 trailing semicolon if any. */
1934 decls
= c_parser_struct_declaration (parser
);
1935 contents
= chainon (decls
, contents
);
1936 /* If no semicolon follows, either we have a parse error or
1937 are at the end of the struct or union and should
1939 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1940 c_parser_consume_token (parser
);
1943 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
1944 pedwarn ("no semicolon at end of struct or union");
1947 c_parser_error (parser
, "expected %<;%>");
1948 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
1953 postfix_attrs
= c_parser_attributes (parser
);
1954 ret
.spec
= finish_struct (type
, nreverse (contents
),
1955 chainon (attrs
, postfix_attrs
));
1956 ret
.kind
= ctsk_tagdef
;
1961 c_parser_error (parser
, "expected %<{%>");
1962 ret
.spec
= error_mark_node
;
1963 ret
.kind
= ctsk_tagref
;
1966 ret
= parser_xref_tag (code
, ident
);
1970 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
1971 the trailing semicolon.
1974 specifier-qualifier-list struct-declarator-list
1976 specifier-qualifier-list:
1977 type-specifier specifier-qualifier-list[opt]
1978 type-qualifier specifier-qualifier-list[opt]
1979 attributes specifier-qualifier-list[opt]
1981 struct-declarator-list:
1983 struct-declarator-list , attributes[opt] struct-declarator
1986 declarator attributes[opt]
1987 declarator[opt] : constant-expression attributes[opt]
1992 __extension__ struct-declaration
1993 specifier-qualifier-list
1995 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
1996 of attributes where shown is a GNU extension. In GNU C, we accept
1997 any expression without commas in the syntax (assignment
1998 expressions, not just conditional expressions); assignment
1999 expressions will be diagnosed as non-constant. */
2002 c_parser_struct_declaration (c_parser
*parser
)
2004 struct c_declspecs
*specs
;
2006 tree all_prefix_attrs
;
2008 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
2012 ext
= disable_extension_diagnostics ();
2013 c_parser_consume_token (parser
);
2014 decl
= c_parser_struct_declaration (parser
);
2015 restore_extension_diagnostics (ext
);
2018 specs
= build_null_declspecs ();
2019 c_parser_declspecs (parser
, specs
, false, true, true);
2022 if (!specs
->declspecs_seen_p
)
2024 c_parser_error (parser
, "expected specifier-qualifier-list");
2027 finish_declspecs (specs
);
2028 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2031 if (!specs
->type_seen_p
)
2034 pedwarn ("ISO C forbids member declarations with no members");
2035 shadow_tag_warned (specs
, pedantic
);
2040 /* Support for unnamed structs or unions as members of
2041 structs or unions (which is [a] useful and [b] supports
2043 ret
= grokfield (build_id_declarator (NULL_TREE
), specs
, NULL_TREE
);
2047 pending_xref_error ();
2048 prefix_attrs
= specs
->attrs
;
2049 all_prefix_attrs
= prefix_attrs
;
2050 specs
->attrs
= NULL_TREE
;
2054 /* Declaring one or more declarators or un-named bit-fields. */
2055 struct c_declarator
*declarator
;
2057 if (c_parser_next_token_is (parser
, CPP_COLON
))
2058 declarator
= build_id_declarator (NULL_TREE
);
2060 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2061 C_DTR_NORMAL
, &dummy
);
2062 if (declarator
== NULL
)
2064 c_parser_skip_to_end_of_block_or_statement (parser
);
2067 if (c_parser_next_token_is (parser
, CPP_COLON
)
2068 || c_parser_next_token_is (parser
, CPP_COMMA
)
2069 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2070 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2071 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2073 tree postfix_attrs
= NULL_TREE
;
2074 tree width
= NULL_TREE
;
2076 if (c_parser_next_token_is (parser
, CPP_COLON
))
2078 c_parser_consume_token (parser
);
2079 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
2081 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2082 postfix_attrs
= c_parser_attributes (parser
);
2083 d
= grokfield (declarator
, specs
, width
);
2084 decl_attributes (&d
, chainon (postfix_attrs
,
2085 all_prefix_attrs
), 0);
2086 TREE_CHAIN (d
) = decls
;
2088 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2089 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2092 all_prefix_attrs
= prefix_attrs
;
2093 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2094 c_parser_consume_token (parser
);
2095 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2096 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2098 /* Semicolon consumed in caller. */
2103 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
2109 c_parser_error (parser
,
2110 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
2111 "%<__attribute__%>");
2118 /* Parse a typeof specifier (a GNU extension).
2121 typeof ( expression )
2122 typeof ( type-name )
2125 static struct c_typespec
2126 c_parser_typeof_specifier (c_parser
*parser
)
2128 struct c_typespec ret
;
2129 ret
.kind
= ctsk_typeof
;
2130 ret
.spec
= error_mark_node
;
2131 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
2132 c_parser_consume_token (parser
);
2135 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2141 if (c_parser_next_token_starts_typename (parser
))
2143 struct c_type_name
*type
= c_parser_type_name (parser
);
2148 ret
.spec
= groktypename (type
);
2149 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
2155 struct c_expr expr
= c_parser_expression (parser
);
2158 if (TREE_CODE (expr
.value
) == COMPONENT_REF
2159 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
2160 error ("%<typeof%> applied to a bit-field");
2161 ret
.spec
= TREE_TYPE (expr
.value
);
2162 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
2163 /* This should be returned with the type so that when the type
2164 is evaluated, this can be evaluated. For now, we avoid
2165 evaluation when the context might. */
2166 if (!skip_evaluation
&& was_vm
)
2167 c_finish_expr_stmt (expr
.value
);
2168 pop_maybe_used (was_vm
);
2170 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2174 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2175 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2176 be redeclared; otherwise it may not. KIND indicates which kind of
2177 declarator is wanted. Returns a valid declarator except in the
2178 case of a syntax error in which case NULL is returned. *SEEN_ID is
2179 set to true if an identifier being declared is seen; this is used
2180 to diagnose bad forms of abstract array declarators and to
2181 determine whether an identifier list is syntactically permitted.
2184 pointer[opt] direct-declarator
2188 ( attributes[opt] declarator )
2189 direct-declarator array-declarator
2190 direct-declarator ( parameter-type-list )
2191 direct-declarator ( identifier-list[opt] )
2194 * type-qualifier-list[opt]
2195 * type-qualifier-list[opt] pointer
2197 type-qualifier-list:
2200 type-qualifier-list type-qualifier
2201 type-qualifier-list attributes
2203 parameter-type-list:
2205 parameter-list , ...
2208 parameter-declaration
2209 parameter-list , parameter-declaration
2211 parameter-declaration:
2212 declaration-specifiers declarator attributes[opt]
2213 declaration-specifiers abstract-declarator[opt] attributes[opt]
2217 identifier-list , identifier
2219 abstract-declarator:
2221 pointer[opt] direct-abstract-declarator
2223 direct-abstract-declarator:
2224 ( attributes[opt] abstract-declarator )
2225 direct-abstract-declarator[opt] array-declarator
2226 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2231 direct-declarator ( parameter-forward-declarations
2232 parameter-type-list[opt] )
2234 direct-abstract-declarator:
2235 direct-abstract-declarator[opt] ( parameter-forward-declarations
2236 parameter-type-list[opt] )
2238 parameter-forward-declarations:
2240 parameter-forward-declarations parameter-list ;
2242 The uses of attributes shown above are GNU extensions.
2244 Some forms of array declarator are not included in C99 in the
2245 syntax for abstract declarators; these are disallowed elsewhere.
2246 This may be a defect (DR#289).
2248 This function also accepts an omitted abstract declarator as being
2249 an abstract declarator, although not part of the formal syntax. */
2251 static struct c_declarator
*
2252 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2255 /* Parse any initial pointer part. */
2256 if (c_parser_next_token_is (parser
, CPP_MULT
))
2258 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2259 struct c_declarator
*inner
;
2260 c_parser_consume_token (parser
);
2261 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2262 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2266 return make_pointer_declarator (quals_attrs
, inner
);
2268 /* Now we have a direct declarator, direct abstract declarator or
2269 nothing (which counts as a direct abstract declarator here). */
2270 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2273 /* Parse a direct declarator or direct abstract declarator; arguments
2274 as c_parser_declarator. */
2276 static struct c_declarator
*
2277 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2280 /* The direct declarator must start with an identifier (possibly
2281 omitted) or a parenthesized declarator (possibly abstract). In
2282 an ordinary declarator, initial parentheses must start a
2283 parenthesized declarator. In an abstract declarator or parameter
2284 declarator, they could start a parenthesized declarator or a
2285 parameter list. To tell which, the open parenthesis and any
2286 following attributes must be read. If a declaration specifier
2287 follows, then it is a parameter list; if the specifier is a
2288 typedef name, there might be an ambiguity about redeclaring it,
2289 which is resolved in the direction of treating it as a typedef
2290 name. If a close parenthesis follows, it is also an empty
2291 parameter list, as the syntax does not permit empty abstract
2292 declarators. Otherwise, it is a parenthesized declarator (in
2293 which case the analysis may be repeated inside it, recursively).
2295 ??? There is an ambiguity in a parameter declaration "int
2296 (__attribute__((foo)) x)", where x is not a typedef name: it
2297 could be an abstract declarator for a function, or declare x with
2298 parentheses. The proper resolution of this ambiguity needs
2299 documenting. At present we follow an accident of the old
2300 parser's implementation, whereby the first parameter must have
2301 some declaration specifiers other than just attributes. Thus as
2302 a parameter declaration it is treated as a parenthesized
2303 parameter named x, and as an abstract declarator it is
2306 ??? Also following the old parser, attributes inside an empty
2307 parameter list are ignored, making it a list not yielding a
2308 prototype, rather than giving an error or making it have one
2309 parameter with implicit type int.
2311 ??? Also following the old parser, typedef names may be
2312 redeclared in declarators, but not Objective-C class names. */
2314 if (kind
!= C_DTR_ABSTRACT
2315 && c_parser_next_token_is (parser
, CPP_NAME
)
2317 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2318 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2320 struct c_declarator
*inner
2321 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2323 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2324 c_parser_consume_token (parser
);
2325 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2328 if (kind
!= C_DTR_NORMAL
2329 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2331 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2332 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2335 /* Either we are at the end of an abstract declarator, or we have
2338 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2341 struct c_declarator
*inner
;
2342 c_parser_consume_token (parser
);
2343 attrs
= c_parser_attributes (parser
);
2344 if (kind
!= C_DTR_NORMAL
2345 && (c_parser_next_token_starts_declspecs (parser
)
2346 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2348 struct c_arg_info
*args
2349 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2356 = build_function_declarator (args
,
2357 build_id_declarator (NULL_TREE
));
2358 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2362 /* A parenthesized declarator. */
2363 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2364 if (inner
!= NULL
&& attrs
!= NULL
)
2365 inner
= build_attrs_declarator (attrs
, inner
);
2366 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2368 c_parser_consume_token (parser
);
2372 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2376 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2383 if (kind
== C_DTR_NORMAL
)
2385 c_parser_error (parser
, "expected identifier or %<(%>");
2389 return build_id_declarator (NULL_TREE
);
2393 /* Parse part of a direct declarator or direct abstract declarator,
2394 given that some (in INNER) has already been parsed; ID_PRESENT is
2395 true if an identifier is present, false for an abstract
2398 static struct c_declarator
*
2399 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2400 struct c_declarator
*inner
)
2402 /* Parse a sequence of array declarators and parameter lists. */
2403 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2405 struct c_declarator
*declarator
;
2406 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2410 c_parser_consume_token (parser
);
2411 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2412 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2414 c_parser_consume_token (parser
);
2415 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2416 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2417 if (!quals_attrs
->declspecs_seen_p
)
2419 /* If "static" is present, there must be an array dimension.
2420 Otherwise, there may be a dimension, "*", or no
2425 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2429 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2434 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2436 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2440 c_parser_consume_token (parser
);
2445 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2451 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2454 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2455 c_parser_consume_token (parser
);
2458 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2462 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2464 if (declarator
== NULL
)
2466 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2467 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2469 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2472 struct c_arg_info
*args
;
2473 c_parser_consume_token (parser
);
2474 attrs
= c_parser_attributes (parser
);
2475 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2480 inner
= build_function_declarator (args
, inner
);
2481 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2487 /* Parse a parameter list or identifier list, including the closing
2488 parenthesis but not the opening one. ATTRS are the attributes at
2489 the start of the list. ID_LIST_OK is true if an identifier list is
2490 acceptable; such a list must not have attributes at the start. */
2492 static struct c_arg_info
*
2493 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2496 declare_parm_level ();
2497 /* If the list starts with an identifier, it is an identifier list.
2498 Otherwise, it is either a prototype list or an empty list. */
2501 && c_parser_next_token_is (parser
, CPP_NAME
)
2502 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2504 tree list
= NULL_TREE
, *nextp
= &list
;
2505 while (c_parser_next_token_is (parser
, CPP_NAME
)
2506 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2508 *nextp
= build_tree_list (NULL_TREE
,
2509 c_parser_peek_token (parser
)->value
);
2510 nextp
= & TREE_CHAIN (*nextp
);
2511 c_parser_consume_token (parser
);
2512 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2514 c_parser_consume_token (parser
);
2515 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2517 c_parser_error (parser
, "expected identifier");
2521 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2523 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2528 ret
->had_vla_unspec
= 0;
2529 c_parser_consume_token (parser
);
2535 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2543 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2549 /* Parse a parameter list (possibly empty), including the closing
2550 parenthesis but not the opening one. ATTRS are the attributes at
2551 the start of the list. */
2553 static struct c_arg_info
*
2554 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2556 bool good_parm
= false;
2557 /* ??? Following the old parser, forward parameter declarations may
2558 use abstract declarators, and if no real parameter declarations
2559 follow the forward declarations then this is not diagnosed. Also
2560 note as above that attributes are ignored as the only contents of
2561 the parentheses, or as the only contents after forward
2563 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2565 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2570 ret
->had_vla_unspec
= 0;
2571 c_parser_consume_token (parser
);
2574 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2576 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2580 ret
->had_vla_unspec
= 0;
2581 /* Suppress -Wold-style-definition for this case. */
2582 ret
->types
= error_mark_node
;
2583 error ("ISO C requires a named argument before %<...%>");
2584 c_parser_consume_token (parser
);
2585 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2587 c_parser_consume_token (parser
);
2592 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2597 /* Nonempty list of parameters, either terminated with semicolon
2598 (forward declarations; recurse) or with close parenthesis (normal
2599 function) or with ", ... )" (variadic function). */
2602 /* Parse a parameter. */
2603 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2608 push_parm_decl (parm
);
2610 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2613 c_parser_consume_token (parser
);
2614 mark_forward_parm_decls ();
2615 new_attrs
= c_parser_attributes (parser
);
2616 return c_parser_parms_list_declarator (parser
, new_attrs
);
2618 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2620 c_parser_consume_token (parser
);
2622 return get_parm_info (false);
2625 struct c_arg_info
*ret
2626 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2631 ret
->had_vla_unspec
= 0;
2635 if (!c_parser_require (parser
, CPP_COMMA
,
2636 "expected %<;%>, %<,%> or %<)%>"))
2638 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2641 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2643 c_parser_consume_token (parser
);
2644 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2646 c_parser_consume_token (parser
);
2648 return get_parm_info (true);
2651 struct c_arg_info
*ret
2652 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2657 ret
->had_vla_unspec
= 0;
2663 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2671 /* Parse a parameter declaration. ATTRS are the attributes at the
2672 start of the declaration if it is the first parameter. */
2674 static struct c_parm
*
2675 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2677 struct c_declspecs
*specs
;
2678 struct c_declarator
*declarator
;
2680 tree postfix_attrs
= NULL_TREE
;
2682 if (!c_parser_next_token_starts_declspecs (parser
))
2684 /* ??? In some Objective-C cases '...' isn't applicable so there
2685 should be a different message. */
2686 c_parser_error (parser
,
2687 "expected declaration specifiers or %<...%>");
2688 c_parser_skip_to_end_of_parameter (parser
);
2691 specs
= build_null_declspecs ();
2694 declspecs_add_attrs (specs
, attrs
);
2697 c_parser_declspecs (parser
, specs
, true, true, true);
2698 finish_declspecs (specs
);
2699 pending_xref_error ();
2700 prefix_attrs
= specs
->attrs
;
2701 specs
->attrs
= NULL_TREE
;
2702 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2703 C_DTR_PARM
, &dummy
);
2704 if (declarator
== NULL
)
2706 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2709 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2710 postfix_attrs
= c_parser_attributes (parser
);
2711 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2715 /* Parse a string literal in an asm expression. It should not be
2716 translated, and wide string literals are an error although
2717 permitted by the syntax. This is a GNU extension.
2722 ??? At present, following the old parser, the caller needs to have
2723 set c_lex_string_translate to 0. It would be better to follow the
2724 C++ parser rather than using the c_lex_string_translate kludge. */
2727 c_parser_asm_string_literal (c_parser
*parser
)
2730 if (c_parser_next_token_is (parser
, CPP_STRING
))
2732 str
= c_parser_peek_token (parser
)->value
;
2733 c_parser_consume_token (parser
);
2735 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2737 error ("wide string literal in %<asm%>");
2738 str
= build_string (1, "");
2739 c_parser_consume_token (parser
);
2743 c_parser_error (parser
, "expected string literal");
2749 /* Parse a simple asm expression. This is used in restricted
2750 contexts, where a full expression with inputs and outputs does not
2751 make sense. This is a GNU extension.
2754 asm ( asm-string-literal )
2758 c_parser_simple_asm_expr (c_parser
*parser
)
2761 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2762 /* ??? Follow the C++ parser rather than using the
2763 c_lex_string_translate kludge. */
2764 c_lex_string_translate
= 0;
2765 c_parser_consume_token (parser
);
2766 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2768 c_lex_string_translate
= 1;
2771 str
= c_parser_asm_string_literal (parser
);
2772 c_lex_string_translate
= 1;
2773 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2775 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2781 /* Parse (possibly empty) attributes. This is a GNU extension.
2785 attributes attribute
2788 __attribute__ ( ( attribute-list ) )
2792 attribute_list , attrib
2797 any-word ( identifier )
2798 any-word ( identifier , nonempty-expr-list )
2799 any-word ( expr-list )
2801 where the "identifier" must not be declared as a type, and
2802 "any-word" may be any identifier (including one declared as a
2803 type), a reserved word storage class specifier, type specifier or
2804 type qualifier. ??? This still leaves out most reserved keywords
2805 (following the old parser), shouldn't we include them, and why not
2806 allow identifiers declared as types to start the arguments? */
2809 c_parser_attributes (c_parser
*parser
)
2811 tree attrs
= NULL_TREE
;
2812 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2814 /* ??? Follow the C++ parser rather than using the
2815 c_lex_string_translate kludge. */
2816 c_lex_string_translate
= 0;
2817 c_parser_consume_token (parser
);
2818 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2820 c_lex_string_translate
= 1;
2823 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2825 c_lex_string_translate
= 1;
2826 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2829 /* Parse the attribute list. */
2830 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2831 || c_parser_next_token_is (parser
, CPP_NAME
)
2832 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2834 tree attr
, attr_name
, attr_args
;
2835 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2837 c_parser_consume_token (parser
);
2840 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2842 /* ??? See comment above about what keywords are
2845 switch (c_parser_peek_token (parser
)->keyword
)
2880 attr_name
= c_parser_peek_token (parser
)->value
;
2881 c_parser_consume_token (parser
);
2882 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2884 attr
= build_tree_list (attr_name
, NULL_TREE
);
2885 attrs
= chainon (attrs
, attr
);
2888 c_parser_consume_token (parser
);
2889 /* Parse the attribute contents. If they start with an
2890 identifier which is followed by a comma or close
2891 parenthesis, then the arguments start with that
2892 identifier; otherwise they are an expression list. */
2893 if (c_parser_next_token_is (parser
, CPP_NAME
)
2894 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2895 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2896 || (c_parser_peek_2nd_token (parser
)->type
2897 == CPP_CLOSE_PAREN
)))
2899 tree arg1
= c_parser_peek_token (parser
)->value
;
2900 c_parser_consume_token (parser
);
2901 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2902 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2905 c_parser_consume_token (parser
);
2906 attr_args
= tree_cons (NULL_TREE
, arg1
,
2907 c_parser_expr_list (parser
, false));
2912 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2913 attr_args
= NULL_TREE
;
2915 attr_args
= c_parser_expr_list (parser
, false);
2917 attr
= build_tree_list (attr_name
, attr_args
);
2918 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2919 c_parser_consume_token (parser
);
2922 c_lex_string_translate
= 1;
2923 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2927 attrs
= chainon (attrs
, attr
);
2929 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2930 c_parser_consume_token (parser
);
2933 c_lex_string_translate
= 1;
2934 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2938 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2939 c_parser_consume_token (parser
);
2942 c_lex_string_translate
= 1;
2943 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2947 c_lex_string_translate
= 1;
2952 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2955 specifier-qualifier-list abstract-declarator[opt]
2958 static struct c_type_name
*
2959 c_parser_type_name (c_parser
*parser
)
2961 struct c_declspecs
*specs
= build_null_declspecs ();
2962 struct c_declarator
*declarator
;
2963 struct c_type_name
*ret
;
2965 c_parser_declspecs (parser
, specs
, false, true, true);
2966 if (!specs
->declspecs_seen_p
)
2968 c_parser_error (parser
, "expected specifier-qualifier-list");
2971 pending_xref_error ();
2972 finish_declspecs (specs
);
2973 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2974 C_DTR_ABSTRACT
, &dummy
);
2975 if (declarator
== NULL
)
2977 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2979 ret
->declarator
= declarator
;
2983 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
2986 assignment-expression
2987 { initializer-list }
2988 { initializer-list , }
2991 designation[opt] initializer
2992 initializer-list , designation[opt] initializer
2999 designator-list designator
3006 [ constant-expression ]
3018 [ constant-expression ... constant-expression ]
3020 Any expression without commas is accepted in the syntax for the
3021 constant-expressions, with non-constant expressions rejected later.
3023 This function is only used for top-level initializers; for nested
3024 ones, see c_parser_initval. */
3026 static struct c_expr
3027 c_parser_initializer (c_parser
*parser
)
3029 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3030 return c_parser_braced_init (parser
, NULL_TREE
, false);
3034 ret
= c_parser_expr_no_commas (parser
, NULL
);
3035 if (TREE_CODE (ret
.value
) != STRING_CST
3036 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3037 ret
= default_function_array_conversion (ret
);
3042 /* Parse a braced initializer list. TYPE is the type specified for a
3043 compound literal, and NULL_TREE for other initializers and for
3044 nested braced lists. NESTED_P is true for nested braced lists,
3045 false for the list of a compound literal or the list that is the
3046 top-level initializer in a declaration. */
3048 static struct c_expr
3049 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3051 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3052 c_parser_consume_token (parser
);
3054 push_init_level (0);
3056 really_start_incremental_init (type
);
3057 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3060 pedwarn ("ISO C forbids empty initializer braces");
3064 /* Parse a non-empty initializer list, possibly with a trailing
3068 c_parser_initelt (parser
);
3071 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3072 c_parser_consume_token (parser
);
3075 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3079 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3082 ret
.value
= error_mark_node
;
3083 ret
.original_code
= ERROR_MARK
;
3084 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3087 c_parser_consume_token (parser
);
3088 return pop_init_level (0);
3091 /* Parse a nested initializer, including designators. */
3094 c_parser_initelt (c_parser
*parser
)
3096 /* Parse any designator or designator list. A single array
3097 designator may have the subsequent "=" omitted in GNU C, but a
3098 longer list or a structure member designator may not. */
3099 if (c_parser_next_token_is (parser
, CPP_NAME
)
3100 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3102 /* Old-style structure member designator. */
3103 set_init_label (c_parser_peek_token (parser
)->value
);
3105 pedwarn ("obsolete use of designated initializer with %<:%>");
3106 c_parser_consume_token (parser
);
3107 c_parser_consume_token (parser
);
3111 /* des_seen is 0 if there have been no designators, 1 if there
3112 has been a single array designator and 2 otherwise. */
3114 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3115 || c_parser_next_token_is (parser
, CPP_DOT
))
3117 int des_prev
= des_seen
;
3120 if (c_parser_next_token_is (parser
, CPP_DOT
))
3123 c_parser_consume_token (parser
);
3124 if (c_parser_next_token_is (parser
, CPP_NAME
))
3126 set_init_label (c_parser_peek_token (parser
)->value
);
3127 c_parser_consume_token (parser
);
3132 init
.value
= error_mark_node
;
3133 init
.original_code
= ERROR_MARK
;
3134 c_parser_error (parser
, "expected identifier");
3135 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3136 process_init_element (init
);
3143 /* ??? Following the old parser, [ objc-receiver
3144 objc-message-args ] is accepted as an initializer,
3145 being distinguished from a designator by what follows
3146 the first assignment expression inside the square
3147 brackets, but after a first array designator a
3148 subsequent square bracket is for Objective-C taken to
3149 start an expression, using the obsolete form of
3150 designated initializer without '=', rather than
3151 possibly being a second level of designation: in LALR
3152 terms, the '[' is shifted rather than reducing
3153 designator to designator-list. */
3154 if (des_prev
== 1 && c_dialect_objc ())
3156 des_seen
= des_prev
;
3159 if (des_prev
== 0 && c_dialect_objc ())
3161 /* This might be an array designator or an
3162 Objective-C message expression. If the former,
3163 continue parsing here; if the latter, parse the
3164 remainder of the initializer given the starting
3165 primary-expression. ??? It might make sense to
3166 distinguish when des_prev == 1 as well; see
3167 previous comment. */
3169 struct c_expr mexpr
;
3170 c_parser_consume_token (parser
);
3171 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3172 && ((c_parser_peek_token (parser
)->id_kind
3174 || (c_parser_peek_token (parser
)->id_kind
3175 == C_ID_CLASSNAME
)))
3177 /* Type name receiver. */
3178 tree id
= c_parser_peek_token (parser
)->value
;
3179 c_parser_consume_token (parser
);
3180 rec
= objc_get_class_reference (id
);
3181 goto parse_message_args
;
3183 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3184 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3185 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3186 goto array_desig_after_first
;
3187 /* Expression receiver. So far only one part
3188 without commas has been parsed; there might be
3189 more of the expression. */
3191 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3194 c_parser_consume_token (parser
);
3195 next
= c_parser_expr_no_commas (parser
, NULL
);
3196 next
= default_function_array_conversion (next
);
3197 rec
= build_compound_expr (rec
, next
.value
);
3200 /* Now parse the objc-message-args. */
3201 args
= c_parser_objc_message_args (parser
);
3202 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3205 = objc_build_message_expr (build_tree_list (rec
, args
));
3206 mexpr
.original_code
= ERROR_MARK
;
3207 /* Now parse and process the remainder of the
3208 initializer, starting with this message
3209 expression as a primary-expression. */
3210 c_parser_initval (parser
, &mexpr
);
3213 c_parser_consume_token (parser
);
3214 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3215 array_desig_after_first
:
3216 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3218 c_parser_consume_token (parser
);
3219 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3223 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3225 c_parser_consume_token (parser
);
3226 set_init_index (first
, second
);
3227 if (pedantic
&& second
)
3228 pedwarn ("ISO C forbids specifying range of "
3229 "elements to initialize");
3232 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3238 if (c_parser_next_token_is (parser
, CPP_EQ
))
3240 if (pedantic
&& !flag_isoc99
)
3241 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3242 c_parser_consume_token (parser
);
3249 pedwarn ("obsolete use of designated initializer "
3255 init
.value
= error_mark_node
;
3256 init
.original_code
= ERROR_MARK
;
3257 c_parser_error (parser
, "expected %<=%>");
3258 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3259 process_init_element (init
);
3265 c_parser_initval (parser
, NULL
);
3268 /* Parse a nested initializer; as c_parser_initializer but parses
3269 initializers within braced lists, after any designators have been
3270 applied. If AFTER is not NULL then it is an Objective-C message
3271 expression which is the primary-expression starting the
3275 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3278 gcc_assert (!after
|| c_dialect_objc ());
3279 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3280 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3283 init
= c_parser_expr_no_commas (parser
, after
);
3284 if (init
.value
!= NULL_TREE
3285 && TREE_CODE (init
.value
) != STRING_CST
3286 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3287 init
= default_function_array_conversion (init
);
3289 process_init_element (init
);
3292 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3296 { block-item-list[opt] }
3297 { label-declarations block-item-list }
3301 block-item-list block-item
3313 { label-declarations block-item-list }
3316 __extension__ nested-declaration
3317 nested-function-definition
3321 label-declarations label-declaration
3324 __label__ identifier-list ;
3326 Allowing the mixing of declarations and code is new in C99. The
3327 GNU syntax also permits (not shown above) labels at the end of
3328 compound statements, which yield an error. We don't allow labels
3329 on declarations; this might seem like a natural extension, but
3330 there would be a conflict between attributes on the label and
3331 prefix attributes on the declaration. ??? The syntax follows the
3332 old parser in requiring something after label declarations.
3333 Although they are erroneous if the labels declared aren't defined,
3334 is it useful for the syntax to be this way?
3346 c_parser_compound_statement (c_parser
*parser
)
3349 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3350 return error_mark_node
;
3351 stmt
= c_begin_compound_stmt (true);
3352 c_parser_compound_statement_nostart (parser
);
3353 return c_end_compound_stmt (stmt
, true);
3356 /* Parse a compound statement except for the opening brace. This is
3357 used for parsing both compound statements and statement expressions
3358 (which follow different paths to handling the opening). */
3361 c_parser_compound_statement_nostart (c_parser
*parser
)
3363 bool last_stmt
= false;
3364 bool last_label
= false;
3365 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3367 c_parser_consume_token (parser
);
3370 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3372 /* Read zero or more forward-declarations for labels that nested
3373 functions can jump to. */
3374 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3376 c_parser_consume_token (parser
);
3377 /* Any identifiers, including those declared as type names,
3382 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3384 c_parser_error (parser
, "expected identifier");
3388 = declare_label (c_parser_peek_token (parser
)->value
);
3389 C_DECLARED_LABEL_FLAG (label
) = 1;
3390 add_stmt (build_stmt (DECL_EXPR
, label
));
3391 c_parser_consume_token (parser
);
3392 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3393 c_parser_consume_token (parser
);
3397 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3399 /* ??? Locating this diagnostic on the token after the
3400 declarations end follows the old parser, but it might be
3401 better to locate it where the declarations start instead. */
3403 pedwarn ("ISO C forbids label declarations");
3405 /* We must now have at least one statement, label or declaration. */
3406 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3408 c_parser_error (parser
, "expected declaration or statement");
3409 c_parser_consume_token (parser
);
3412 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3414 location_t loc
= c_parser_peek_token (parser
)->location
;
3415 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3416 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3417 || (c_parser_next_token_is (parser
, CPP_NAME
)
3418 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3422 c_parser_label (parser
);
3424 else if (!last_label
3425 && c_parser_next_token_starts_declspecs (parser
))
3428 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3430 && ((pedantic
&& !flag_isoc99
)
3431 || warn_declaration_after_statement
))
3432 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3436 else if (!last_label
3437 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3439 /* __extension__ can start a declaration, but is also an
3440 unary operator that can start an expression. Consume all
3441 but the last of a possible series of __extension__ to
3443 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3444 && (c_parser_peek_2nd_token (parser
)->keyword
3446 c_parser_consume_token (parser
);
3447 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3450 ext
= disable_extension_diagnostics ();
3451 c_parser_consume_token (parser
);
3453 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3454 /* Following the old parser, __extension__ does not
3455 disable this diagnostic. */
3456 restore_extension_diagnostics (ext
);
3458 && ((pedantic
&& !flag_isoc99
)
3459 || warn_declaration_after_statement
))
3460 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3467 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3469 /* External pragmas, and some omp pragmas, are not associated
3470 with regular c code, and so are not to be considered statements
3471 syntactically. This ensures that the user doesn't put them
3472 places that would turn into syntax errors if the directive
3474 if (c_parser_pragma (parser
, pragma_compound
))
3475 last_label
= false, last_stmt
= true;
3477 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3479 c_parser_error (parser
, "expected declaration or statement");
3487 c_parser_statement_after_labels (parser
);
3491 error ("label at end of compound statement");
3492 c_parser_consume_token (parser
);
3495 /* Parse a label (C90 6.6.1, C99 6.8.1).
3498 identifier : attributes[opt]
3499 case constant-expression :
3505 case constant-expression ... constant-expression :
3507 The use of attributes on labels is a GNU extension. The syntax in
3508 GNU C accepts any expressions without commas, non-constant
3509 expressions being rejected later. */
3512 c_parser_label (c_parser
*parser
)
3514 location_t loc1
= c_parser_peek_token (parser
)->location
;
3515 tree label
= NULL_TREE
;
3516 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3519 c_parser_consume_token (parser
);
3520 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3521 if (c_parser_next_token_is (parser
, CPP_COLON
))
3523 c_parser_consume_token (parser
);
3524 label
= do_case (exp1
, NULL_TREE
);
3526 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3528 c_parser_consume_token (parser
);
3529 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3530 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3531 label
= do_case (exp1
, exp2
);
3534 c_parser_error (parser
, "expected %<:%> or %<...%>");
3536 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3538 c_parser_consume_token (parser
);
3539 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3540 label
= do_case (NULL_TREE
, NULL_TREE
);
3544 tree name
= c_parser_peek_token (parser
)->value
;
3548 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3549 c_parser_consume_token (parser
);
3550 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3551 loc2
= c_parser_peek_token (parser
)->location
;
3552 c_parser_consume_token (parser
);
3553 attrs
= c_parser_attributes (parser
);
3554 tlab
= define_label (loc2
, name
);
3557 decl_attributes (&tlab
, attrs
, 0);
3558 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3562 SET_EXPR_LOCATION (label
, loc1
);
3565 /* Parse a statement (C90 6.6, C99 6.8).
3570 expression-statement
3578 expression-statement:
3581 selection-statement:
3585 iteration-statement:
3594 return expression[opt] ;
3607 objc-throw-statement
3608 objc-try-catch-statement
3609 objc-synchronized-statement
3611 objc-throw-statement:
3625 parallel-for-construct
3626 parallel-sections-construct
3633 parallel-directive structured-block
3636 for-directive iteration-statement
3639 sections-directive section-scope
3642 single-directive structured-block
3644 parallel-for-construct:
3645 parallel-for-directive iteration-statement
3647 parallel-sections-construct:
3648 parallel-sections-directive section-scope
3651 master-directive structured-block
3654 critical-directive structured-block
3657 atomic-directive expression-statement
3660 ordered-directive structured-block */
3663 c_parser_statement (c_parser
*parser
)
3665 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3666 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3667 || (c_parser_next_token_is (parser
, CPP_NAME
)
3668 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3669 c_parser_label (parser
);
3670 c_parser_statement_after_labels (parser
);
3673 /* Parse a statement, other than a labeled statement. */
3676 c_parser_statement_after_labels (c_parser
*parser
)
3678 location_t loc
= c_parser_peek_token (parser
)->location
;
3679 tree stmt
= NULL_TREE
;
3680 switch (c_parser_peek_token (parser
)->type
)
3682 case CPP_OPEN_BRACE
:
3683 add_stmt (c_parser_compound_statement (parser
));
3686 switch (c_parser_peek_token (parser
)->keyword
)
3689 c_parser_if_statement (parser
);
3692 c_parser_switch_statement (parser
);
3695 c_parser_while_statement (parser
);
3698 c_parser_do_statement (parser
);
3701 c_parser_for_statement (parser
);
3704 c_parser_consume_token (parser
);
3705 if (c_parser_next_token_is (parser
, CPP_NAME
))
3707 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3708 c_parser_consume_token (parser
);
3710 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3712 c_parser_consume_token (parser
);
3713 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3716 c_parser_error (parser
, "expected identifier or %<*%>");
3717 goto expect_semicolon
;
3719 c_parser_consume_token (parser
);
3720 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3721 goto expect_semicolon
;
3723 c_parser_consume_token (parser
);
3724 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3725 goto expect_semicolon
;
3727 c_parser_consume_token (parser
);
3728 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3730 stmt
= c_finish_return (NULL_TREE
);
3731 c_parser_consume_token (parser
);
3735 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3736 goto expect_semicolon
;
3740 stmt
= c_parser_asm_statement (parser
);
3743 gcc_assert (c_dialect_objc ());
3744 c_parser_consume_token (parser
);
3745 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3747 stmt
= objc_build_throw_stmt (NULL_TREE
);
3748 c_parser_consume_token (parser
);
3753 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3754 goto expect_semicolon
;
3758 gcc_assert (c_dialect_objc ());
3759 c_parser_objc_try_catch_statement (parser
);
3761 case RID_AT_SYNCHRONIZED
:
3762 gcc_assert (c_dialect_objc ());
3763 c_parser_objc_synchronized_statement (parser
);
3770 c_parser_consume_token (parser
);
3772 case CPP_CLOSE_PAREN
:
3773 case CPP_CLOSE_SQUARE
:
3774 /* Avoid infinite loop in error recovery:
3775 c_parser_skip_until_found stops at a closing nesting
3776 delimiter without consuming it, but here we need to consume
3777 it to proceed further. */
3778 c_parser_error (parser
, "expected statement");
3779 c_parser_consume_token (parser
);
3782 c_parser_pragma (parser
, pragma_stmt
);
3786 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3788 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3791 /* Two cases cannot and do not have line numbers associated: If stmt
3792 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3793 cannot hold line numbers. But that's OK because the statement
3794 will either be changed to a MODIFY_EXPR during gimplification of
3795 the statement expr, or discarded. If stmt was compound, but
3796 without new variables, we will have skipped the creation of a
3797 BIND and will have a bare STATEMENT_LIST. But that's OK because
3798 (recursively) all of the component statements should already have
3799 line numbers assigned. ??? Can we discard no-op statements
3801 if (stmt
&& EXPR_P (stmt
))
3802 SET_EXPR_LOCATION (stmt
, loc
);
3805 /* Parse a parenthesized condition from an if, do or while statement.
3811 c_parser_paren_condition (c_parser
*parser
)
3815 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3816 return error_mark_node
;
3817 loc
= c_parser_peek_token (parser
)->location
;
3818 cond
= c_objc_common_truthvalue_conversion
3819 (c_parser_expression_conv (parser
).value
);
3821 SET_EXPR_LOCATION (cond
, loc
);
3822 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3826 /* Parse a statement which is a block in C99. */
3829 c_parser_c99_block_statement (c_parser
*parser
)
3831 tree block
= c_begin_compound_stmt (flag_isoc99
);
3832 c_parser_statement (parser
);
3833 return c_end_compound_stmt (block
, flag_isoc99
);
3836 /* Parse the body of an if statement or the else half thereof. This
3837 is just parsing a statement but (a) it is a block in C99, (b) we
3838 track whether the body is an if statement for the sake of
3839 -Wparentheses warnings, (c) we handle an empty body specially for
3840 the sake of -Wextra warnings. */
3843 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3845 tree block
= c_begin_compound_stmt (flag_isoc99
);
3846 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3847 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3848 || (c_parser_next_token_is (parser
, CPP_NAME
)
3849 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3850 c_parser_label (parser
);
3851 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3852 if (extra_warnings
&& c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3853 add_stmt (build_empty_stmt ());
3854 c_parser_statement_after_labels (parser
);
3855 return c_end_compound_stmt (block
, flag_isoc99
);
3858 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3861 if ( expression ) statement
3862 if ( expression ) statement else statement
3866 c_parser_if_statement (c_parser
*parser
)
3871 bool first_if
= false, second_if
= false;
3872 tree first_body
, second_body
;
3873 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3874 c_parser_consume_token (parser
);
3875 block
= c_begin_compound_stmt (flag_isoc99
);
3876 loc
= c_parser_peek_token (parser
)->location
;
3877 cond
= c_parser_paren_condition (parser
);
3878 first_body
= c_parser_if_body (parser
, &first_if
);
3879 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3881 c_parser_consume_token (parser
);
3882 second_body
= c_parser_if_body (parser
, &second_if
);
3885 second_body
= NULL_TREE
;
3886 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3887 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3890 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3893 switch (expression) statement
3897 c_parser_switch_statement (c_parser
*parser
)
3899 tree block
, expr
, body
, save_break
;
3900 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3901 c_parser_consume_token (parser
);
3902 block
= c_begin_compound_stmt (flag_isoc99
);
3903 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3905 expr
= c_parser_expression (parser
).value
;
3906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3909 expr
= error_mark_node
;
3910 c_start_case (expr
);
3911 save_break
= c_break_label
;
3912 c_break_label
= NULL_TREE
;
3913 body
= c_parser_c99_block_statement (parser
);
3914 c_finish_case (body
);
3916 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3917 c_break_label
= save_break
;
3918 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3921 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3924 while (expression) statement
3928 c_parser_while_statement (c_parser
*parser
)
3930 tree block
, cond
, body
, save_break
, save_cont
;
3932 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3933 c_parser_consume_token (parser
);
3934 block
= c_begin_compound_stmt (flag_isoc99
);
3935 loc
= c_parser_peek_token (parser
)->location
;
3936 cond
= c_parser_paren_condition (parser
);
3937 save_break
= c_break_label
;
3938 c_break_label
= NULL_TREE
;
3939 save_cont
= c_cont_label
;
3940 c_cont_label
= NULL_TREE
;
3941 body
= c_parser_c99_block_statement (parser
);
3942 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3943 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3944 c_break_label
= save_break
;
3945 c_cont_label
= save_cont
;
3948 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3951 do statement while ( expression ) ;
3955 c_parser_do_statement (c_parser
*parser
)
3957 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3959 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3960 c_parser_consume_token (parser
);
3961 block
= c_begin_compound_stmt (flag_isoc99
);
3962 loc
= c_parser_peek_token (parser
)->location
;
3963 save_break
= c_break_label
;
3964 c_break_label
= NULL_TREE
;
3965 save_cont
= c_cont_label
;
3966 c_cont_label
= NULL_TREE
;
3967 body
= c_parser_c99_block_statement (parser
);
3968 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
3969 new_break
= c_break_label
;
3970 c_break_label
= save_break
;
3971 new_cont
= c_cont_label
;
3972 c_cont_label
= save_cont
;
3973 cond
= c_parser_paren_condition (parser
);
3974 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3975 c_parser_skip_to_end_of_block_or_statement (parser
);
3976 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
3977 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3980 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
3983 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
3984 for ( nested-declaration expression[opt] ; expression[opt] ) statement
3986 The form with a declaration is new in C99.
3988 ??? In accordance with the old parser, the declaration may be a
3989 nested function, which is then rejected in check_for_loop_decls,
3990 but does it make any sense for this to be included in the grammar?
3991 Note in particular that the nested function does not include a
3992 trailing ';', whereas the "declaration" production includes one.
3993 Also, can we reject bad declarations earlier and cheaper than
3994 check_for_loop_decls? */
3997 c_parser_for_statement (c_parser
*parser
)
3999 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4001 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4002 loc
= c_parser_peek_token (parser
)->location
;
4003 c_parser_consume_token (parser
);
4004 block
= c_begin_compound_stmt (flag_isoc99
);
4005 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4007 /* Parse the initialization declaration or expression. */
4008 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4010 c_parser_consume_token (parser
);
4011 c_finish_expr_stmt (NULL_TREE
);
4013 else if (c_parser_next_token_starts_declspecs (parser
))
4015 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4016 check_for_loop_decls ();
4018 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4020 /* __extension__ can start a declaration, but is also an
4021 unary operator that can start an expression. Consume all
4022 but the last of a possible series of __extension__ to
4024 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4025 && (c_parser_peek_2nd_token (parser
)->keyword
4027 c_parser_consume_token (parser
);
4028 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4031 ext
= disable_extension_diagnostics ();
4032 c_parser_consume_token (parser
);
4033 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4034 restore_extension_diagnostics (ext
);
4035 check_for_loop_decls ();
4043 c_finish_expr_stmt (c_parser_expression (parser
).value
);
4044 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4046 /* Parse the loop condition. */
4047 loc
= c_parser_peek_token (parser
)->location
;
4048 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4050 c_parser_consume_token (parser
);
4055 tree ocond
= c_parser_expression_conv (parser
).value
;
4056 cond
= c_objc_common_truthvalue_conversion (ocond
);
4058 SET_EXPR_LOCATION (cond
, loc
);
4059 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4061 /* Parse the increment expression. */
4062 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4063 incr
= c_process_expr_stmt (NULL_TREE
);
4065 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
4066 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4070 cond
= error_mark_node
;
4071 incr
= error_mark_node
;
4073 save_break
= c_break_label
;
4074 c_break_label
= NULL_TREE
;
4075 save_cont
= c_cont_label
;
4076 c_cont_label
= NULL_TREE
;
4077 body
= c_parser_c99_block_statement (parser
);
4078 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4079 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4080 c_break_label
= save_break
;
4081 c_cont_label
= save_cont
;
4084 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4085 statement with inputs, outputs, clobbers, and volatile tag
4089 asm type-qualifier[opt] ( asm-argument ) ;
4093 asm-string-literal : asm-operands[opt]
4094 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4095 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4097 Qualifiers other than volatile are accepted in the syntax but
4101 c_parser_asm_statement (c_parser
*parser
)
4103 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
4105 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4106 c_parser_consume_token (parser
);
4107 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4109 quals
= c_parser_peek_token (parser
)->value
;
4110 c_parser_consume_token (parser
);
4112 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4113 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4115 warning (0, "%E qualifier ignored on asm",
4116 c_parser_peek_token (parser
)->value
);
4118 c_parser_consume_token (parser
);
4122 /* ??? Follow the C++ parser rather than using the
4123 c_lex_string_translate kludge. */
4124 c_lex_string_translate
= 0;
4125 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4127 c_lex_string_translate
= 1;
4130 str
= c_parser_asm_string_literal (parser
);
4131 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4134 outputs
= NULL_TREE
;
4136 clobbers
= NULL_TREE
;
4139 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4141 c_lex_string_translate
= 1;
4142 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4146 /* Parse outputs. */
4147 if (c_parser_next_token_is (parser
, CPP_COLON
)
4148 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4149 outputs
= NULL_TREE
;
4151 outputs
= c_parser_asm_operands (parser
, false);
4152 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4155 clobbers
= NULL_TREE
;
4158 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4160 c_lex_string_translate
= 1;
4161 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4165 if (c_parser_next_token_is (parser
, CPP_COLON
)
4166 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4169 inputs
= c_parser_asm_operands (parser
, true);
4170 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4172 clobbers
= NULL_TREE
;
4175 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4177 c_lex_string_translate
= 1;
4178 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4181 /* Parse clobbers. */
4182 clobbers
= c_parser_asm_clobbers (parser
);
4184 c_lex_string_translate
= 1;
4185 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4187 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4190 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4191 c_parser_skip_to_end_of_block_or_statement (parser
);
4192 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4197 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4198 not outputs), apply the default conversion of functions and arrays
4203 asm-operands , asm-operand
4206 asm-string-literal ( expression )
4207 [ identifier ] asm-string-literal ( expression )
4211 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4213 tree list
= NULL_TREE
;
4218 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4220 c_parser_consume_token (parser
);
4221 if (c_parser_next_token_is (parser
, CPP_NAME
))
4223 tree id
= c_parser_peek_token (parser
)->value
;
4224 c_parser_consume_token (parser
);
4225 name
= build_string (IDENTIFIER_LENGTH (id
),
4226 IDENTIFIER_POINTER (id
));
4230 c_parser_error (parser
, "expected identifier");
4231 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4234 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4239 str
= c_parser_asm_string_literal (parser
);
4240 if (str
== NULL_TREE
)
4242 c_lex_string_translate
= 1;
4243 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4245 c_lex_string_translate
= 0;
4248 expr
= c_parser_expression (parser
);
4250 expr
= default_function_array_conversion (expr
);
4251 c_lex_string_translate
= 0;
4252 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4254 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4257 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4259 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4260 c_parser_consume_token (parser
);
4267 /* Parse asm clobbers, a GNU extension.
4271 asm-clobbers , asm-string-literal
4275 c_parser_asm_clobbers (c_parser
*parser
)
4277 tree list
= NULL_TREE
;
4280 tree str
= c_parser_asm_string_literal (parser
);
4282 list
= tree_cons (NULL_TREE
, str
, list
);
4285 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4286 c_parser_consume_token (parser
);
4293 /* Parse an expression other than a compound expression; that is, an
4294 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4295 NULL then it is an Objective-C message expression which is the
4296 primary-expression starting the expression as an initializer.
4298 assignment-expression:
4299 conditional-expression
4300 unary-expression assignment-operator assignment-expression
4302 assignment-operator: one of
4303 = *= /= %= += -= <<= >>= &= ^= |=
4305 In GNU C we accept any conditional expression on the LHS and
4306 diagnose the invalid lvalue rather than producing a syntax
4309 static struct c_expr
4310 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4312 struct c_expr lhs
, rhs
, ret
;
4313 enum tree_code code
;
4314 gcc_assert (!after
|| c_dialect_objc ());
4315 lhs
= c_parser_conditional_expression (parser
, after
);
4316 switch (c_parser_peek_token (parser
)->type
)
4325 code
= TRUNC_DIV_EXPR
;
4328 code
= TRUNC_MOD_EXPR
;
4343 code
= BIT_AND_EXPR
;
4346 code
= BIT_XOR_EXPR
;
4349 code
= BIT_IOR_EXPR
;
4354 c_parser_consume_token (parser
);
4355 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4356 rhs
= default_function_array_conversion (rhs
);
4357 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4358 if (code
== NOP_EXPR
)
4359 ret
.original_code
= MODIFY_EXPR
;
4362 TREE_NO_WARNING (ret
.value
) = 1;
4363 ret
.original_code
= ERROR_MARK
;
4368 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4369 is not NULL then it is an Objective-C message expression which is
4370 the primary-expression starting the expression as an initializer.
4372 conditional-expression:
4373 logical-OR-expression
4374 logical-OR-expression ? expression : conditional-expression
4378 conditional-expression:
4379 logical-OR-expression ? : conditional-expression
4382 static struct c_expr
4383 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4385 struct c_expr cond
, exp1
, exp2
, ret
;
4386 gcc_assert (!after
|| c_dialect_objc ());
4387 cond
= c_parser_binary_expression (parser
, after
);
4388 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4390 cond
= default_function_array_conversion (cond
);
4391 c_parser_consume_token (parser
);
4392 if (c_parser_next_token_is (parser
, CPP_COLON
))
4395 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4396 /* Make sure first operand is calculated only once. */
4397 exp1
.value
= save_expr (default_conversion (cond
.value
));
4398 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4399 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4404 = c_objc_common_truthvalue_conversion
4405 (default_conversion (cond
.value
));
4406 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4407 exp1
= c_parser_expression_conv (parser
);
4408 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4409 - (cond
.value
== truthvalue_false_node
));
4411 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4413 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4414 ret
.value
= error_mark_node
;
4415 ret
.original_code
= ERROR_MARK
;
4418 exp2
= c_parser_conditional_expression (parser
, NULL
);
4419 exp2
= default_function_array_conversion (exp2
);
4420 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4421 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4422 ret
.original_code
= ERROR_MARK
;
4426 /* Parse a binary expression; that is, a logical-OR-expression (C90
4427 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4428 an Objective-C message expression which is the primary-expression
4429 starting the expression as an initializer.
4431 multiplicative-expression:
4433 multiplicative-expression * cast-expression
4434 multiplicative-expression / cast-expression
4435 multiplicative-expression % cast-expression
4437 additive-expression:
4438 multiplicative-expression
4439 additive-expression + multiplicative-expression
4440 additive-expression - multiplicative-expression
4444 shift-expression << additive-expression
4445 shift-expression >> additive-expression
4447 relational-expression:
4449 relational-expression < shift-expression
4450 relational-expression > shift-expression
4451 relational-expression <= shift-expression
4452 relational-expression >= shift-expression
4454 equality-expression:
4455 relational-expression
4456 equality-expression == relational-expression
4457 equality-expression != relational-expression
4461 AND-expression & equality-expression
4463 exclusive-OR-expression:
4465 exclusive-OR-expression ^ AND-expression
4467 inclusive-OR-expression:
4468 exclusive-OR-expression
4469 inclusive-OR-expression | exclusive-OR-expression
4471 logical-AND-expression:
4472 inclusive-OR-expression
4473 logical-AND-expression && inclusive-OR-expression
4475 logical-OR-expression:
4476 logical-AND-expression
4477 logical-OR-expression || logical-AND-expression
4480 static struct c_expr
4481 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4483 /* A binary expression is parsed using operator-precedence parsing,
4484 with the operands being cast expressions. All the binary
4485 operators are left-associative. Thus a binary expression is of
4488 E0 op1 E1 op2 E2 ...
4490 which we represent on a stack. On the stack, the precedence
4491 levels are strictly increasing. When a new operator is
4492 encountered of higher precedence than that at the top of the
4493 stack, it is pushed; its LHS is the top expression, and its RHS
4494 is everything parsed until it is popped. When a new operator is
4495 encountered with precedence less than or equal to that at the top
4496 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4497 by the result of the operation until the operator at the top of
4498 the stack has lower precedence than the new operator or there is
4499 only one element on the stack; then the top expression is the LHS
4500 of the new operator. In the case of logical AND and OR
4501 expressions, we also need to adjust skip_evaluation as
4502 appropriate when the operators are pushed and popped. */
4504 /* The precedence levels, where 0 is a dummy lowest level used for
4505 the bottom of the stack. */
4521 /* The expression at this stack level. */
4523 /* The precedence of the operator on its left, PREC_NONE at the
4524 bottom of the stack. */
4526 /* The operation on its left. */
4532 switch (stack[sp].op) \
4534 case TRUTH_ANDIF_EXPR: \
4535 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4537 case TRUTH_ORIF_EXPR: \
4538 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4543 stack[sp - 1].expr \
4544 = default_function_array_conversion (stack[sp - 1].expr); \
4546 = default_function_array_conversion (stack[sp].expr); \
4547 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4548 stack[sp - 1].expr, \
4552 gcc_assert (!after
|| c_dialect_objc ());
4553 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4554 stack
[0].prec
= PREC_NONE
;
4559 enum tree_code ocode
;
4562 switch (c_parser_peek_token (parser
)->type
)
4570 ocode
= TRUNC_DIV_EXPR
;
4574 ocode
= TRUNC_MOD_EXPR
;
4586 ocode
= LSHIFT_EXPR
;
4590 ocode
= RSHIFT_EXPR
;
4604 case CPP_GREATER_EQ
:
4617 oprec
= PREC_BITAND
;
4618 ocode
= BIT_AND_EXPR
;
4621 oprec
= PREC_BITXOR
;
4622 ocode
= BIT_XOR_EXPR
;
4626 ocode
= BIT_IOR_EXPR
;
4629 oprec
= PREC_LOGAND
;
4630 ocode
= TRUTH_ANDIF_EXPR
;
4634 ocode
= TRUTH_ORIF_EXPR
;
4637 /* Not a binary operator, so end of the binary
4641 c_parser_consume_token (parser
);
4642 while (oprec
<= stack
[sp
].prec
)
4646 case TRUTH_ANDIF_EXPR
:
4648 = default_function_array_conversion (stack
[sp
].expr
);
4649 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4650 (default_conversion (stack
[sp
].expr
.value
));
4651 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4653 case TRUTH_ORIF_EXPR
:
4655 = default_function_array_conversion (stack
[sp
].expr
);
4656 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4657 (default_conversion (stack
[sp
].expr
.value
));
4658 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4664 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4665 stack
[sp
].prec
= oprec
;
4666 stack
[sp
].op
= ocode
;
4671 return stack
[0].expr
;
4675 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4676 NULL then it is an Objective-C message expression which is the
4677 primary-expression starting the expression as an initializer.
4681 ( type-name ) unary-expression
4684 static struct c_expr
4685 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4687 gcc_assert (!after
|| c_dialect_objc ());
4689 return c_parser_postfix_expression_after_primary (parser
, *after
);
4690 /* If the expression begins with a parenthesized type name, it may
4691 be either a cast or a compound literal; we need to see whether
4692 the next character is '{' to tell the difference. If not, it is
4693 an unary expression. */
4694 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4695 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4697 struct c_type_name
*type_name
;
4700 c_parser_consume_token (parser
);
4701 type_name
= c_parser_type_name (parser
);
4702 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4703 if (type_name
== NULL
)
4705 ret
.value
= error_mark_node
;
4706 ret
.original_code
= ERROR_MARK
;
4710 /* Save casted types in the function's used types hash table. */
4711 used_types_insert (type_name
->specs
->type
);
4713 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4714 return c_parser_postfix_expression_after_paren_type (parser
,
4716 expr
= c_parser_cast_expression (parser
, NULL
);
4717 expr
= default_function_array_conversion (expr
);
4718 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4719 ret
.original_code
= ERROR_MARK
;
4723 return c_parser_unary_expression (parser
);
4726 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4732 unary-operator cast-expression
4733 sizeof unary-expression
4734 sizeof ( type-name )
4736 unary-operator: one of
4742 __alignof__ unary-expression
4743 __alignof__ ( type-name )
4746 unary-operator: one of
4747 __extension__ __real__ __imag__
4749 In addition, the GNU syntax treats ++ and -- as unary operators, so
4750 they may be applied to cast expressions with errors for non-lvalues
4753 static struct c_expr
4754 c_parser_unary_expression (c_parser
*parser
)
4757 struct c_expr ret
, op
;
4758 switch (c_parser_peek_token (parser
)->type
)
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 (PREINCREMENT_EXPR
, op
);
4765 case CPP_MINUS_MINUS
:
4766 c_parser_consume_token (parser
);
4767 op
= c_parser_cast_expression (parser
, NULL
);
4768 op
= default_function_array_conversion (op
);
4769 return parser_build_unary_op (PREDECREMENT_EXPR
, op
);
4771 c_parser_consume_token (parser
);
4772 return parser_build_unary_op (ADDR_EXPR
,
4773 c_parser_cast_expression (parser
, NULL
));
4775 c_parser_consume_token (parser
);
4776 op
= c_parser_cast_expression (parser
, NULL
);
4777 op
= default_function_array_conversion (op
);
4778 ret
.value
= build_indirect_ref (op
.value
, "unary *");
4779 ret
.original_code
= ERROR_MARK
;
4782 c_parser_consume_token (parser
);
4783 if (!c_dialect_objc () && !in_system_header
)
4784 warning (OPT_Wtraditional
,
4785 "traditional C rejects the unary plus operator");
4786 op
= c_parser_cast_expression (parser
, NULL
);
4787 op
= default_function_array_conversion (op
);
4788 return parser_build_unary_op (CONVERT_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 (NEGATE_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 (BIT_NOT_EXPR
, op
);
4800 c_parser_consume_token (parser
);
4801 op
= c_parser_cast_expression (parser
, NULL
);
4802 op
= default_function_array_conversion (op
);
4803 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
);
4805 /* Refer to the address of a label as a pointer. */
4806 c_parser_consume_token (parser
);
4807 if (c_parser_next_token_is (parser
, CPP_NAME
))
4809 ret
.value
= finish_label_address_expr
4810 (c_parser_peek_token (parser
)->value
);
4811 c_parser_consume_token (parser
);
4815 c_parser_error (parser
, "expected identifier");
4816 ret
.value
= error_mark_node
;
4818 ret
.original_code
= ERROR_MARK
;
4821 switch (c_parser_peek_token (parser
)->keyword
)
4824 return c_parser_sizeof_expression (parser
);
4826 return c_parser_alignof_expression (parser
);
4828 c_parser_consume_token (parser
);
4829 ext
= disable_extension_diagnostics ();
4830 ret
= c_parser_cast_expression (parser
, NULL
);
4831 restore_extension_diagnostics (ext
);
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 (REALPART_EXPR
, op
);
4839 c_parser_consume_token (parser
);
4840 op
= c_parser_cast_expression (parser
, NULL
);
4841 op
= default_function_array_conversion (op
);
4842 return parser_build_unary_op (IMAGPART_EXPR
, op
);
4844 return c_parser_postfix_expression (parser
);
4847 return c_parser_postfix_expression (parser
);
4851 /* Parse a sizeof expression. */
4853 static struct c_expr
4854 c_parser_sizeof_expression (c_parser
*parser
)
4857 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4858 c_parser_consume_token (parser
);
4861 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4862 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4864 /* Either sizeof ( type-name ) or sizeof unary-expression
4865 starting with a compound literal. */
4866 struct c_type_name
*type_name
;
4867 c_parser_consume_token (parser
);
4868 type_name
= c_parser_type_name (parser
);
4869 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4870 if (type_name
== NULL
)
4875 ret
.value
= error_mark_node
;
4876 ret
.original_code
= ERROR_MARK
;
4879 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4881 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4885 /* sizeof ( type-name ). */
4888 if (type_name
->declarator
->kind
== cdk_array
4889 && type_name
->declarator
->u
.array
.vla_unspec_p
)
4892 error ("%<[*]%> not allowed in other than a declaration");
4894 return c_expr_sizeof_type (type_name
);
4898 expr
= c_parser_unary_expression (parser
);
4902 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4903 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4904 error ("%<sizeof%> applied to a bit-field");
4905 return c_expr_sizeof_expr (expr
);
4909 /* Parse an alignof expression. */
4911 static struct c_expr
4912 c_parser_alignof_expression (c_parser
*parser
)
4915 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4916 c_parser_consume_token (parser
);
4919 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4920 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4922 /* Either __alignof__ ( type-name ) or __alignof__
4923 unary-expression starting with a compound literal. */
4924 struct c_type_name
*type_name
;
4926 c_parser_consume_token (parser
);
4927 type_name
= c_parser_type_name (parser
);
4928 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4929 if (type_name
== NULL
)
4934 ret
.value
= error_mark_node
;
4935 ret
.original_code
= ERROR_MARK
;
4938 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4940 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4944 /* alignof ( type-name ). */
4947 ret
.value
= c_alignof (groktypename (type_name
));
4948 ret
.original_code
= ERROR_MARK
;
4954 expr
= c_parser_unary_expression (parser
);
4958 ret
.value
= c_alignof_expr (expr
.value
);
4959 ret
.original_code
= ERROR_MARK
;
4964 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4968 postfix-expression [ expression ]
4969 postfix-expression ( argument-expression-list[opt] )
4970 postfix-expression . identifier
4971 postfix-expression -> identifier
4972 postfix-expression ++
4973 postfix-expression --
4974 ( type-name ) { initializer-list }
4975 ( type-name ) { initializer-list , }
4977 argument-expression-list:
4979 argument-expression-list , argument-expression
4991 (treated as a keyword in GNU C)
4994 ( compound-statement )
4995 __builtin_va_arg ( assignment-expression , type-name )
4996 __builtin_offsetof ( type-name , offsetof-member-designator )
4997 __builtin_choose_expr ( assignment-expression ,
4998 assignment-expression ,
4999 assignment-expression )
5000 __builtin_types_compatible_p ( type-name , type-name )
5002 offsetof-member-designator:
5004 offsetof-member-designator . identifier
5005 offsetof-member-designator [ expression ]
5010 [ objc-receiver objc-message-args ]
5011 @selector ( objc-selector-arg )
5012 @protocol ( identifier )
5013 @encode ( type-name )
5017 static struct c_expr
5018 c_parser_postfix_expression (c_parser
*parser
)
5020 struct c_expr expr
, e1
, e2
, e3
;
5021 struct c_type_name
*t1
, *t2
;
5022 switch (c_parser_peek_token (parser
)->type
)
5027 expr
.value
= c_parser_peek_token (parser
)->value
;
5028 expr
.original_code
= ERROR_MARK
;
5029 c_parser_consume_token (parser
);
5033 expr
.value
= c_parser_peek_token (parser
)->value
;
5034 expr
.original_code
= STRING_CST
;
5035 c_parser_consume_token (parser
);
5037 case CPP_OBJC_STRING
:
5038 gcc_assert (c_dialect_objc ());
5040 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5041 expr
.original_code
= ERROR_MARK
;
5042 c_parser_consume_token (parser
);
5045 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5047 c_parser_error (parser
, "expected expression");
5048 expr
.value
= error_mark_node
;
5049 expr
.original_code
= ERROR_MARK
;
5053 tree id
= c_parser_peek_token (parser
)->value
;
5054 location_t loc
= c_parser_peek_token (parser
)->location
;
5055 c_parser_consume_token (parser
);
5056 expr
.value
= build_external_ref (id
,
5057 (c_parser_peek_token (parser
)->type
5058 == CPP_OPEN_PAREN
), loc
);
5059 expr
.original_code
= ERROR_MARK
;
5062 case CPP_OPEN_PAREN
:
5063 /* A parenthesized expression, statement expression or compound
5065 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5067 /* A statement expression. */
5069 c_parser_consume_token (parser
);
5070 c_parser_consume_token (parser
);
5071 if (cur_stmt_list
== NULL
)
5073 error ("braced-group within expression allowed "
5074 "only inside a function");
5075 parser
->error
= true;
5076 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5077 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5078 expr
.value
= error_mark_node
;
5079 expr
.original_code
= ERROR_MARK
;
5082 stmt
= c_begin_stmt_expr ();
5083 c_parser_compound_statement_nostart (parser
);
5084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5087 pedwarn ("ISO C forbids braced-groups within expressions");
5088 expr
.value
= c_finish_stmt_expr (stmt
);
5089 expr
.original_code
= ERROR_MARK
;
5091 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5093 /* A compound literal. ??? Can we actually get here rather
5094 than going directly to
5095 c_parser_postfix_expression_after_paren_type from
5097 struct c_type_name
*type_name
;
5098 c_parser_consume_token (parser
);
5099 type_name
= c_parser_type_name (parser
);
5100 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5102 if (type_name
== NULL
)
5104 expr
.value
= error_mark_node
;
5105 expr
.original_code
= ERROR_MARK
;
5108 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5113 /* A parenthesized expression. */
5114 c_parser_consume_token (parser
);
5115 expr
= c_parser_expression (parser
);
5116 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5117 TREE_NO_WARNING (expr
.value
) = 1;
5118 expr
.original_code
= ERROR_MARK
;
5119 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5124 switch (c_parser_peek_token (parser
)->keyword
)
5126 case RID_FUNCTION_NAME
:
5127 case RID_PRETTY_FUNCTION_NAME
:
5128 case RID_C99_FUNCTION_NAME
:
5129 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
5130 c_parser_peek_token (parser
)->value
);
5131 expr
.original_code
= ERROR_MARK
;
5132 c_parser_consume_token (parser
);
5135 c_parser_consume_token (parser
);
5136 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5138 expr
.value
= error_mark_node
;
5139 expr
.original_code
= ERROR_MARK
;
5142 e1
= c_parser_expr_no_commas (parser
, NULL
);
5143 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5145 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5146 expr
.value
= error_mark_node
;
5147 expr
.original_code
= ERROR_MARK
;
5150 t1
= c_parser_type_name (parser
);
5151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5155 expr
.value
= error_mark_node
;
5156 expr
.original_code
= ERROR_MARK
;
5160 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
5161 expr
.original_code
= ERROR_MARK
;
5165 c_parser_consume_token (parser
);
5166 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5168 expr
.value
= error_mark_node
;
5169 expr
.original_code
= ERROR_MARK
;
5172 t1
= c_parser_type_name (parser
);
5175 expr
.value
= error_mark_node
;
5176 expr
.original_code
= ERROR_MARK
;
5179 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5181 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5182 expr
.value
= error_mark_node
;
5183 expr
.original_code
= ERROR_MARK
;
5187 tree type
= groktypename (t1
);
5189 if (type
== error_mark_node
)
5190 offsetof_ref
= error_mark_node
;
5192 offsetof_ref
= build1 (INDIRECT_REF
, type
, NULL
);
5193 /* Parse the second argument to __builtin_offsetof. We
5194 must have one identifier, and beyond that we want to
5195 accept sub structure and sub array references. */
5196 if (c_parser_next_token_is (parser
, CPP_NAME
))
5198 offsetof_ref
= build_component_ref
5199 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5200 c_parser_consume_token (parser
);
5201 while (c_parser_next_token_is (parser
, CPP_DOT
)
5202 || c_parser_next_token_is (parser
,
5205 if (c_parser_next_token_is (parser
, CPP_DOT
))
5207 c_parser_consume_token (parser
);
5208 if (c_parser_next_token_is_not (parser
,
5211 c_parser_error (parser
, "expected identifier");
5214 offsetof_ref
= build_component_ref
5216 c_parser_peek_token (parser
)->value
);
5217 c_parser_consume_token (parser
);
5222 c_parser_consume_token (parser
);
5223 idx
= c_parser_expression (parser
).value
;
5224 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5226 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
5231 c_parser_error (parser
, "expected identifier");
5232 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5234 expr
.value
= fold_offsetof (offsetof_ref
);
5235 expr
.original_code
= ERROR_MARK
;
5238 case RID_CHOOSE_EXPR
:
5239 c_parser_consume_token (parser
);
5240 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5242 expr
.value
= error_mark_node
;
5243 expr
.original_code
= ERROR_MARK
;
5246 e1
= c_parser_expr_no_commas (parser
, NULL
);
5247 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5249 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5250 expr
.value
= error_mark_node
;
5251 expr
.original_code
= ERROR_MARK
;
5254 e2
= c_parser_expr_no_commas (parser
, NULL
);
5255 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5257 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5258 expr
.value
= error_mark_node
;
5259 expr
.original_code
= ERROR_MARK
;
5262 e3
= c_parser_expr_no_commas (parser
, NULL
);
5263 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5268 c
= fold (e1
.value
);
5269 if (TREE_CODE (c
) != INTEGER_CST
)
5270 error ("first argument to %<__builtin_choose_expr%> not"
5272 expr
= integer_zerop (c
) ? e3
: e2
;
5275 case RID_TYPES_COMPATIBLE_P
:
5276 c_parser_consume_token (parser
);
5277 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5279 expr
.value
= error_mark_node
;
5280 expr
.original_code
= ERROR_MARK
;
5283 t1
= c_parser_type_name (parser
);
5286 expr
.value
= error_mark_node
;
5287 expr
.original_code
= ERROR_MARK
;
5290 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5292 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5293 expr
.value
= error_mark_node
;
5294 expr
.original_code
= ERROR_MARK
;
5297 t2
= c_parser_type_name (parser
);
5300 expr
.value
= error_mark_node
;
5301 expr
.original_code
= ERROR_MARK
;
5304 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5309 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5310 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5312 expr
.value
= comptypes (e1
, e2
)
5313 ? build_int_cst (NULL_TREE
, 1)
5314 : build_int_cst (NULL_TREE
, 0);
5315 expr
.original_code
= ERROR_MARK
;
5318 case RID_AT_SELECTOR
:
5319 gcc_assert (c_dialect_objc ());
5320 c_parser_consume_token (parser
);
5321 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5323 expr
.value
= error_mark_node
;
5324 expr
.original_code
= ERROR_MARK
;
5328 tree sel
= c_parser_objc_selector_arg (parser
);
5329 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5331 expr
.value
= objc_build_selector_expr (sel
);
5332 expr
.original_code
= ERROR_MARK
;
5335 case RID_AT_PROTOCOL
:
5336 gcc_assert (c_dialect_objc ());
5337 c_parser_consume_token (parser
);
5338 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5340 expr
.value
= error_mark_node
;
5341 expr
.original_code
= ERROR_MARK
;
5344 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5346 c_parser_error (parser
, "expected identifier");
5347 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5348 expr
.value
= error_mark_node
;
5349 expr
.original_code
= ERROR_MARK
;
5353 tree id
= c_parser_peek_token (parser
)->value
;
5354 c_parser_consume_token (parser
);
5355 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5357 expr
.value
= objc_build_protocol_expr (id
);
5358 expr
.original_code
= ERROR_MARK
;
5362 /* Extension to support C-structures in the archiver. */
5363 gcc_assert (c_dialect_objc ());
5364 c_parser_consume_token (parser
);
5365 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5367 expr
.value
= error_mark_node
;
5368 expr
.original_code
= ERROR_MARK
;
5371 t1
= c_parser_type_name (parser
);
5374 expr
.value
= error_mark_node
;
5375 expr
.original_code
= ERROR_MARK
;
5376 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5379 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5382 tree type
= groktypename (t1
);
5383 expr
.value
= objc_build_encode_expr (type
);
5384 expr
.original_code
= ERROR_MARK
;
5388 c_parser_error (parser
, "expected expression");
5389 expr
.value
= error_mark_node
;
5390 expr
.original_code
= ERROR_MARK
;
5394 case CPP_OPEN_SQUARE
:
5395 if (c_dialect_objc ())
5397 tree receiver
, args
;
5398 c_parser_consume_token (parser
);
5399 receiver
= c_parser_objc_receiver (parser
);
5400 args
= c_parser_objc_message_args (parser
);
5401 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5403 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5405 expr
.original_code
= ERROR_MARK
;
5408 /* Else fall through to report error. */
5410 c_parser_error (parser
, "expected expression");
5411 expr
.value
= error_mark_node
;
5412 expr
.original_code
= ERROR_MARK
;
5415 return c_parser_postfix_expression_after_primary (parser
, expr
);
5418 /* Parse a postfix expression after a parenthesized type name: the
5419 brace-enclosed initializer of a compound literal, possibly followed
5420 by some postfix operators. This is separate because it is not
5421 possible to tell until after the type name whether a cast
5422 expression has a cast or a compound literal, or whether the operand
5423 of sizeof is a parenthesized type name or starts with a compound
5426 static struct c_expr
5427 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5428 struct c_type_name
*type_name
)
5433 start_init (NULL_TREE
, NULL
, 0);
5434 type
= groktypename (type_name
);
5435 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5437 error ("compound literal has variable size");
5438 type
= error_mark_node
;
5440 init
= c_parser_braced_init (parser
, type
, false);
5442 maybe_warn_string_init (type
, init
);
5444 if (pedantic
&& !flag_isoc99
)
5445 pedwarn ("ISO C90 forbids compound literals");
5446 expr
.value
= build_compound_literal (type
, init
.value
);
5447 expr
.original_code
= ERROR_MARK
;
5448 return c_parser_postfix_expression_after_primary (parser
, expr
);
5451 /* Parse a postfix expression after the initial primary or compound
5452 literal; that is, parse a series of postfix operators. */
5454 static struct c_expr
5455 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5458 tree ident
, idx
, exprlist
;
5461 switch (c_parser_peek_token (parser
)->type
)
5463 case CPP_OPEN_SQUARE
:
5464 /* Array reference. */
5465 c_parser_consume_token (parser
);
5466 idx
= c_parser_expression (parser
).value
;
5467 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5469 expr
.value
= build_array_ref (expr
.value
, idx
);
5470 expr
.original_code
= ERROR_MARK
;
5472 case CPP_OPEN_PAREN
:
5473 /* Function call. */
5474 c_parser_consume_token (parser
);
5475 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5476 exprlist
= NULL_TREE
;
5478 exprlist
= c_parser_expr_list (parser
, true);
5479 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5481 expr
.value
= build_function_call (expr
.value
, exprlist
);
5482 expr
.original_code
= ERROR_MARK
;
5485 /* Structure element reference. */
5486 c_parser_consume_token (parser
);
5487 expr
= default_function_array_conversion (expr
);
5488 if (c_parser_next_token_is (parser
, CPP_NAME
))
5489 ident
= c_parser_peek_token (parser
)->value
;
5492 c_parser_error (parser
, "expected identifier");
5493 expr
.value
= error_mark_node
;
5494 expr
.original_code
= ERROR_MARK
;
5497 c_parser_consume_token (parser
);
5498 expr
.value
= build_component_ref (expr
.value
, ident
);
5499 expr
.original_code
= ERROR_MARK
;
5502 /* Structure element reference. */
5503 c_parser_consume_token (parser
);
5504 expr
= default_function_array_conversion (expr
);
5505 if (c_parser_next_token_is (parser
, CPP_NAME
))
5506 ident
= c_parser_peek_token (parser
)->value
;
5509 c_parser_error (parser
, "expected identifier");
5510 expr
.value
= error_mark_node
;
5511 expr
.original_code
= ERROR_MARK
;
5514 c_parser_consume_token (parser
);
5515 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5517 expr
.original_code
= ERROR_MARK
;
5520 /* Postincrement. */
5521 c_parser_consume_token (parser
);
5522 expr
= default_function_array_conversion (expr
);
5523 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5524 expr
.original_code
= ERROR_MARK
;
5526 case CPP_MINUS_MINUS
:
5527 /* Postdecrement. */
5528 c_parser_consume_token (parser
);
5529 expr
= default_function_array_conversion (expr
);
5530 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5531 expr
.original_code
= ERROR_MARK
;
5539 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5542 assignment-expression
5543 expression , assignment-expression
5546 static struct c_expr
5547 c_parser_expression (c_parser
*parser
)
5550 expr
= c_parser_expr_no_commas (parser
, NULL
);
5551 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5554 c_parser_consume_token (parser
);
5555 next
= c_parser_expr_no_commas (parser
, NULL
);
5556 next
= default_function_array_conversion (next
);
5557 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5558 expr
.original_code
= COMPOUND_EXPR
;
5563 /* Parse an expression and convert functions or arrays to
5566 static struct c_expr
5567 c_parser_expression_conv (c_parser
*parser
)
5570 expr
= c_parser_expression (parser
);
5571 expr
= default_function_array_conversion (expr
);
5575 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5576 functions and arrays to pointers.
5579 assignment-expression
5580 nonempty-expr-list , assignment-expression
5584 c_parser_expr_list (c_parser
*parser
, bool convert_p
)
5588 expr
= c_parser_expr_no_commas (parser
, NULL
);
5590 expr
= default_function_array_conversion (expr
);
5591 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5592 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5594 c_parser_consume_token (parser
);
5595 expr
= c_parser_expr_no_commas (parser
, NULL
);
5597 expr
= default_function_array_conversion (expr
);
5598 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5604 /* Parse Objective-C-specific constructs. */
5606 /* Parse an objc-class-definition.
5608 objc-class-definition:
5609 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5610 objc-class-instance-variables[opt] objc-methodprotolist @end
5611 @implementation identifier objc-superclass[opt]
5612 objc-class-instance-variables[opt]
5613 @interface identifier ( identifier ) objc-protocol-refs[opt]
5614 objc-methodprotolist @end
5615 @implementation identifier ( identifier )
5620 "@interface identifier (" must start "@interface identifier (
5621 identifier ) ...": objc-methodprotolist in the first production may
5622 not start with a parenthesized identifier as a declarator of a data
5623 definition with no declaration specifiers if the objc-superclass,
5624 objc-protocol-refs and objc-class-instance-variables are omitted. */
5627 c_parser_objc_class_definition (c_parser
*parser
)
5632 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5634 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5638 c_parser_consume_token (parser
);
5639 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5641 c_parser_error (parser
, "expected identifier");
5644 id1
= c_parser_peek_token (parser
)->value
;
5645 c_parser_consume_token (parser
);
5646 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5649 tree proto
= NULL_TREE
;
5650 c_parser_consume_token (parser
);
5651 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5653 c_parser_error (parser
, "expected identifier");
5654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5657 id2
= c_parser_peek_token (parser
)->value
;
5658 c_parser_consume_token (parser
);
5659 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5662 objc_start_category_implementation (id1
, id2
);
5665 if (c_parser_next_token_is (parser
, CPP_LESS
))
5666 proto
= c_parser_objc_protocol_refs (parser
);
5667 objc_start_category_interface (id1
, id2
, proto
);
5668 c_parser_objc_methodprotolist (parser
);
5669 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5670 objc_finish_interface ();
5673 if (c_parser_next_token_is (parser
, CPP_COLON
))
5675 c_parser_consume_token (parser
);
5676 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5678 c_parser_error (parser
, "expected identifier");
5681 superclass
= c_parser_peek_token (parser
)->value
;
5682 c_parser_consume_token (parser
);
5685 superclass
= NULL_TREE
;
5688 tree proto
= NULL_TREE
;
5689 if (c_parser_next_token_is (parser
, CPP_LESS
))
5690 proto
= c_parser_objc_protocol_refs (parser
);
5691 objc_start_class_interface (id1
, superclass
, proto
);
5694 objc_start_class_implementation (id1
, superclass
);
5695 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5696 c_parser_objc_class_instance_variables (parser
);
5699 objc_continue_interface ();
5700 c_parser_objc_methodprotolist (parser
);
5701 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5702 objc_finish_interface ();
5706 objc_continue_implementation ();
5711 /* Parse objc-class-instance-variables.
5713 objc-class-instance-variables:
5714 { objc-instance-variable-decl-list[opt] }
5716 objc-instance-variable-decl-list:
5717 objc-visibility-spec
5718 objc-instance-variable-decl ;
5720 objc-instance-variable-decl-list objc-visibility-spec
5721 objc-instance-variable-decl-list objc-instance-variable-decl ;
5722 objc-instance-variable-decl-list ;
5724 objc-visibility-spec:
5729 objc-instance-variable-decl:
5734 c_parser_objc_class_instance_variables (c_parser
*parser
)
5736 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5737 c_parser_consume_token (parser
);
5738 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5741 /* Parse any stray semicolon. */
5742 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5745 pedwarn ("extra semicolon in struct or union specified");
5746 c_parser_consume_token (parser
);
5749 /* Stop if at the end of the instance variables. */
5750 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5752 c_parser_consume_token (parser
);
5755 /* Parse any objc-visibility-spec. */
5756 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5758 c_parser_consume_token (parser
);
5759 objc_set_visibility (2);
5762 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5764 c_parser_consume_token (parser
);
5765 objc_set_visibility (0);
5768 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5770 c_parser_consume_token (parser
);
5771 objc_set_visibility (1);
5774 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5776 c_parser_pragma (parser
, pragma_external
);
5780 /* Parse some comma-separated declarations. */
5781 decls
= c_parser_struct_declaration (parser
);
5783 /* Comma-separated instance variables are chained together in
5784 reverse order; add them one by one. */
5785 tree ivar
= nreverse (decls
);
5786 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5787 objc_add_instance_variable (copy_node (ivar
));
5789 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5793 /* Parse an objc-class-declaration.
5795 objc-class-declaration:
5796 @class identifier-list ;
5800 c_parser_objc_class_declaration (c_parser
*parser
)
5802 tree list
= NULL_TREE
;
5803 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5804 c_parser_consume_token (parser
);
5805 /* Any identifiers, including those declared as type names, are OK
5810 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5812 c_parser_error (parser
, "expected identifier");
5815 id
= c_parser_peek_token (parser
)->value
;
5816 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5817 c_parser_consume_token (parser
);
5818 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5819 c_parser_consume_token (parser
);
5823 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5824 objc_declare_class (list
);
5827 /* Parse an objc-alias-declaration.
5829 objc-alias-declaration:
5830 @compatibility_alias identifier identifier ;
5834 c_parser_objc_alias_declaration (c_parser
*parser
)
5837 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5838 c_parser_consume_token (parser
);
5839 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5841 c_parser_error (parser
, "expected identifier");
5842 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5845 id1
= c_parser_peek_token (parser
)->value
;
5846 c_parser_consume_token (parser
);
5847 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5849 c_parser_error (parser
, "expected identifier");
5850 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5853 id2
= c_parser_peek_token (parser
)->value
;
5854 c_parser_consume_token (parser
);
5855 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5856 objc_declare_alias (id1
, id2
);
5859 /* Parse an objc-protocol-definition.
5861 objc-protocol-definition:
5862 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5863 @protocol identifier-list ;
5865 "@protocol identifier ;" should be resolved as "@protocol
5866 identifier-list ;": objc-methodprotolist may not start with a
5867 semicolon in the first alternative if objc-protocol-refs are
5871 c_parser_objc_protocol_definition (c_parser
*parser
)
5873 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5874 c_parser_consume_token (parser
);
5875 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5877 c_parser_error (parser
, "expected identifier");
5880 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5881 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5883 tree list
= NULL_TREE
;
5884 /* Any identifiers, including those declared as type names, are
5889 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5891 c_parser_error (parser
, "expected identifier");
5894 id
= c_parser_peek_token (parser
)->value
;
5895 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5896 c_parser_consume_token (parser
);
5897 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5898 c_parser_consume_token (parser
);
5902 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5903 objc_declare_protocols (list
);
5907 tree id
= c_parser_peek_token (parser
)->value
;
5908 tree proto
= NULL_TREE
;
5909 c_parser_consume_token (parser
);
5910 if (c_parser_next_token_is (parser
, CPP_LESS
))
5911 proto
= c_parser_objc_protocol_refs (parser
);
5912 objc_pq_context
= 1;
5913 objc_start_protocol (id
, proto
);
5914 c_parser_objc_methodprotolist (parser
);
5915 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5916 objc_pq_context
= 0;
5917 objc_finish_interface ();
5921 /* Parse an objc-method-type.
5928 static enum tree_code
5929 c_parser_objc_method_type (c_parser
*parser
)
5931 switch (c_parser_peek_token (parser
)->type
)
5934 c_parser_consume_token (parser
);
5937 c_parser_consume_token (parser
);
5944 /* Parse an objc-method-definition.
5946 objc-method-definition:
5947 objc-method-type objc-method-decl ;[opt] compound-statement
5951 c_parser_objc_method_definition (c_parser
*parser
)
5953 enum tree_code type
= c_parser_objc_method_type (parser
);
5955 objc_set_method_type (type
);
5956 objc_pq_context
= 1;
5957 decl
= c_parser_objc_method_decl (parser
);
5958 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5960 c_parser_consume_token (parser
);
5962 pedwarn ("extra semicolon in method definition specified");
5964 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5966 c_parser_error (parser
, "expected %<{%>");
5969 objc_pq_context
= 0;
5970 objc_start_method_definition (decl
);
5971 add_stmt (c_parser_compound_statement (parser
));
5972 objc_finish_method_definition (current_function_decl
);
5975 /* Parse an objc-methodprotolist.
5977 objc-methodprotolist:
5979 objc-methodprotolist objc-methodproto
5980 objc-methodprotolist declaration
5981 objc-methodprotolist ;
5983 The declaration is a data definition, which may be missing
5984 declaration specifiers under the same rules and diagnostics as
5985 other data definitions outside functions, and the stray semicolon
5986 is diagnosed the same way as a stray semicolon outside a
5990 c_parser_objc_methodprotolist (c_parser
*parser
)
5994 /* The list is terminated by @end. */
5995 switch (c_parser_peek_token (parser
)->type
)
5999 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
6000 c_parser_consume_token (parser
);
6004 c_parser_objc_methodproto (parser
);
6007 c_parser_pragma (parser
, pragma_external
);
6012 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6014 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6020 /* Parse an objc-methodproto.
6023 objc-method-type objc-method-decl ;
6027 c_parser_objc_methodproto (c_parser
*parser
)
6029 enum tree_code type
= c_parser_objc_method_type (parser
);
6031 objc_set_method_type (type
);
6032 /* Remember protocol qualifiers in prototypes. */
6033 objc_pq_context
= 1;
6034 decl
= c_parser_objc_method_decl (parser
);
6035 /* Forget protocol qualifiers here. */
6036 objc_pq_context
= 0;
6037 objc_add_method_declaration (decl
);
6038 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6041 /* Parse an objc-method-decl.
6044 ( objc-type-name ) objc-selector
6046 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6047 objc-keyword-selector objc-optparmlist
6049 objc-keyword-selector:
6051 objc-keyword-selector objc-keyword-decl
6054 objc-selector : ( objc-type-name ) identifier
6055 objc-selector : identifier
6056 : ( objc-type-name ) identifier
6060 objc-optparms objc-optellipsis
6064 objc-opt-parms , parameter-declaration
6072 c_parser_objc_method_decl (c_parser
*parser
)
6074 tree type
= NULL_TREE
;
6076 tree parms
= NULL_TREE
;
6077 bool ellipsis
= false;
6079 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6081 c_parser_consume_token (parser
);
6082 type
= c_parser_objc_type_name (parser
);
6083 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6085 sel
= c_parser_objc_selector (parser
);
6086 /* If there is no selector, or a colon follows, we have an
6087 objc-keyword-selector. If there is a selector, and a colon does
6088 not follow, that selector ends the objc-method-decl. */
6089 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6092 tree list
= NULL_TREE
;
6095 tree atype
= NULL_TREE
, id
, keyworddecl
;
6096 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6098 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6100 c_parser_consume_token (parser
);
6101 atype
= c_parser_objc_type_name (parser
);
6102 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6105 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6107 c_parser_error (parser
, "expected identifier");
6108 return error_mark_node
;
6110 id
= c_parser_peek_token (parser
)->value
;
6111 c_parser_consume_token (parser
);
6112 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6113 list
= chainon (list
, keyworddecl
);
6114 tsel
= c_parser_objc_selector (parser
);
6115 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6118 /* Parse the optional parameter list. Optional Objective-C
6119 method parameters follow the C syntax, and may include '...'
6120 to denote a variable number of arguments. */
6121 parms
= make_node (TREE_LIST
);
6122 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6124 struct c_parm
*parm
;
6125 c_parser_consume_token (parser
);
6126 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6129 c_parser_consume_token (parser
);
6132 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6135 parms
= chainon (parms
,
6136 build_tree_list (NULL_TREE
, grokparm (parm
)));
6140 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6143 /* Parse an objc-type-name.
6146 objc-type-qualifiers[opt] type-name
6147 objc-type-qualifiers[opt]
6149 objc-type-qualifiers:
6151 objc-type-qualifiers objc-type-qualifier
6153 objc-type-qualifier: one of
6154 in out inout bycopy byref oneway
6158 c_parser_objc_type_name (c_parser
*parser
)
6160 tree quals
= NULL_TREE
;
6161 struct c_type_name
*typename
= NULL
;
6162 tree type
= NULL_TREE
;
6165 c_token
*token
= c_parser_peek_token (parser
);
6166 if (token
->type
== CPP_KEYWORD
6167 && (token
->keyword
== RID_IN
6168 || token
->keyword
== RID_OUT
6169 || token
->keyword
== RID_INOUT
6170 || token
->keyword
== RID_BYCOPY
6171 || token
->keyword
== RID_BYREF
6172 || token
->keyword
== RID_ONEWAY
))
6174 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6175 c_parser_consume_token (parser
);
6180 if (c_parser_next_token_starts_typename (parser
))
6181 typename
= c_parser_type_name (parser
);
6183 type
= groktypename (typename
);
6184 return build_tree_list (quals
, type
);
6187 /* Parse objc-protocol-refs.
6194 c_parser_objc_protocol_refs (c_parser
*parser
)
6196 tree list
= NULL_TREE
;
6197 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6198 c_parser_consume_token (parser
);
6199 /* Any identifiers, including those declared as type names, are OK
6204 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6206 c_parser_error (parser
, "expected identifier");
6209 id
= c_parser_peek_token (parser
)->value
;
6210 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6211 c_parser_consume_token (parser
);
6212 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6213 c_parser_consume_token (parser
);
6217 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6221 /* Parse an objc-try-catch-statement.
6223 objc-try-catch-statement:
6224 @try compound-statement objc-catch-list[opt]
6225 @try compound-statement objc-catch-list[opt] @finally compound-statement
6228 @catch ( parameter-declaration ) compound-statement
6229 objc-catch-list @catch ( parameter-declaration ) compound-statement
6233 c_parser_objc_try_catch_statement (c_parser
*parser
)
6237 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
6238 c_parser_consume_token (parser
);
6239 loc
= c_parser_peek_token (parser
)->location
;
6240 stmt
= c_parser_compound_statement (parser
);
6241 objc_begin_try_stmt (loc
, stmt
);
6242 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
6244 struct c_parm
*parm
;
6245 c_parser_consume_token (parser
);
6246 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6248 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6251 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6254 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6255 objc_begin_catch_clause (grokparm (parm
));
6256 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6257 c_parser_compound_statement_nostart (parser
);
6258 objc_finish_catch_clause ();
6260 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6264 c_parser_consume_token (parser
);
6265 finloc
= c_parser_peek_token (parser
)->location
;
6266 finstmt
= c_parser_compound_statement (parser
);
6267 objc_build_finally_clause (finloc
, finstmt
);
6269 objc_finish_try_stmt ();
6272 /* Parse an objc-synchronized-statement.
6274 objc-synchronized-statement:
6275 @synchronized ( expression ) compound-statement
6279 c_parser_objc_synchronized_statement (c_parser
*parser
)
6283 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6284 c_parser_consume_token (parser
);
6285 loc
= c_parser_peek_token (parser
)->location
;
6286 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6288 expr
= c_parser_expression (parser
).value
;
6289 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6292 expr
= error_mark_node
;
6293 stmt
= c_parser_compound_statement (parser
);
6294 objc_build_synchronized (loc
, expr
, stmt
);
6297 /* Parse an objc-selector; return NULL_TREE without an error if the
6298 next token is not an objc-selector.
6303 enum struct union if else while do for switch case default
6304 break continue return goto asm sizeof typeof __alignof
6305 unsigned long const short volatile signed restrict _Complex
6306 in out inout bycopy byref oneway int char float double void _Bool
6308 ??? Why this selection of keywords but not, for example, storage
6309 class specifiers? */
6312 c_parser_objc_selector (c_parser
*parser
)
6314 c_token
*token
= c_parser_peek_token (parser
);
6315 tree value
= token
->value
;
6316 if (token
->type
== CPP_NAME
)
6318 c_parser_consume_token (parser
);
6321 if (token
->type
!= CPP_KEYWORD
)
6323 switch (token
->keyword
)
6364 c_parser_consume_token (parser
);
6371 /* Parse an objc-selector-arg.
6375 objc-keywordname-list
6377 objc-keywordname-list:
6379 objc-keywordname-list objc-keywordname
6387 c_parser_objc_selector_arg (c_parser
*parser
)
6389 tree sel
= c_parser_objc_selector (parser
);
6390 tree list
= NULL_TREE
;
6391 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6395 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6397 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6398 sel
= c_parser_objc_selector (parser
);
6399 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6405 /* Parse an objc-receiver.
6414 c_parser_objc_receiver (c_parser
*parser
)
6416 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6417 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6418 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6420 tree id
= c_parser_peek_token (parser
)->value
;
6421 c_parser_consume_token (parser
);
6422 return objc_get_class_reference (id
);
6424 return c_parser_expression (parser
).value
;
6427 /* Parse objc-message-args.
6431 objc-keywordarg-list
6433 objc-keywordarg-list:
6435 objc-keywordarg-list objc-keywordarg
6438 objc-selector : objc-keywordexpr
6443 c_parser_objc_message_args (c_parser
*parser
)
6445 tree sel
= c_parser_objc_selector (parser
);
6446 tree list
= NULL_TREE
;
6447 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6452 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6454 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6455 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6456 sel
= c_parser_objc_selector (parser
);
6457 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6463 /* Parse an objc-keywordexpr.
6470 c_parser_objc_keywordexpr (c_parser
*parser
)
6472 tree list
= c_parser_expr_list (parser
, true);
6473 if (TREE_CHAIN (list
) == NULL_TREE
)
6475 /* Just return the expression, remove a level of
6477 return TREE_VALUE (list
);
6481 /* We have a comma expression, we will collapse later. */
6487 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6488 should be considered, statements. ALLOW_STMT is true if we're within
6489 the context of a function and such pragmas are to be allowed. Returns
6490 true if we actually parsed such a pragma. */
6493 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6497 id
= c_parser_peek_token (parser
)->pragma_kind
;
6498 gcc_assert (id
!= PRAGMA_NONE
);
6502 case PRAGMA_OMP_BARRIER
:
6503 if (context
!= pragma_compound
)
6505 if (context
== pragma_stmt
)
6506 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6507 "used in compound statements");
6510 c_parser_omp_barrier (parser
);
6513 case PRAGMA_OMP_FLUSH
:
6514 if (context
!= pragma_compound
)
6516 if (context
== pragma_stmt
)
6517 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6518 "used in compound statements");
6521 c_parser_omp_flush (parser
);
6524 case PRAGMA_OMP_THREADPRIVATE
:
6525 c_parser_omp_threadprivate (parser
);
6528 case PRAGMA_OMP_SECTION
:
6529 error ("%<#pragma omp section%> may only be used in "
6530 "%<#pragma omp sections%> construct");
6531 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6534 case PRAGMA_GCC_PCH_PREPROCESS
:
6535 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6536 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6540 if (id
< PRAGMA_FIRST_EXTERNAL
)
6542 if (context
== pragma_external
)
6545 c_parser_error (parser
, "expected declaration specifiers");
6546 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6549 c_parser_omp_construct (parser
);
6555 c_parser_consume_pragma (parser
);
6556 c_invoke_pragma_handler (id
);
6558 /* Skip to EOL, but suppress any error message. Those will have been
6559 generated by the handler routine through calling error, as opposed
6560 to calling c_parser_error. */
6561 parser
->error
= true;
6562 c_parser_skip_to_pragma_eol (parser
);
6567 /* The interface the pragma parsers have to the lexer. */
6570 pragma_lex (tree
*value
)
6572 c_token
*tok
= c_parser_peek_token (the_parser
);
6573 enum cpp_ttype ret
= tok
->type
;
6575 *value
= tok
->value
;
6576 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6580 if (ret
== CPP_KEYWORD
)
6582 c_parser_consume_token (the_parser
);
6589 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6593 c_parser_consume_pragma (parser
);
6594 if (c_parser_next_token_is (parser
, CPP_STRING
))
6596 name
= c_parser_peek_token (parser
)->value
;
6597 c_parser_consume_token (parser
);
6600 c_parser_error (parser
, "expected string literal");
6601 c_parser_skip_to_pragma_eol (parser
);
6604 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6607 /* OpenMP 2.5 parsing routines. */
6609 /* Returns name of the next clause.
6610 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6611 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6612 returned and the token is consumed. */
6614 static pragma_omp_clause
6615 c_parser_omp_clause_name (c_parser
*parser
)
6617 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
6619 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
6620 result
= PRAGMA_OMP_CLAUSE_IF
;
6621 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
6622 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
6623 else if (c_parser_next_token_is (parser
, CPP_NAME
))
6625 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6630 if (!strcmp ("copyin", p
))
6631 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
6632 else if (!strcmp ("copyprivate", p
))
6633 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
6636 if (!strcmp ("firstprivate", p
))
6637 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
6640 if (!strcmp ("lastprivate", p
))
6641 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
6644 if (!strcmp ("nowait", p
))
6645 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
6646 else if (!strcmp ("num_threads", p
))
6647 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
6650 if (!strcmp ("ordered", p
))
6651 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
6654 if (!strcmp ("private", p
))
6655 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
6658 if (!strcmp ("reduction", p
))
6659 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
6662 if (!strcmp ("schedule", p
))
6663 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
6664 else if (!strcmp ("shared", p
))
6665 result
= PRAGMA_OMP_CLAUSE_SHARED
;
6670 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
6671 c_parser_consume_token (parser
);
6676 /* Validate that a clause of the given type does not already exist. */
6679 check_no_duplicate_clause (tree clauses
, enum tree_code code
, const char *name
)
6683 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6684 if (OMP_CLAUSE_CODE (c
) == code
)
6686 error ("too many %qs clauses", name
);
6694 variable-list , identifier
6696 If KIND is nonzero, create the appropriate node and install the decl
6697 in OMP_CLAUSE_DECL and add the node to the head of the list.
6699 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6700 return the list created. */
6703 c_parser_omp_variable_list (c_parser
*parser
, enum omp_clause_code kind
,
6706 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
6707 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
6708 c_parser_error (parser
, "expected identifier");
6710 while (c_parser_next_token_is (parser
, CPP_NAME
)
6711 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
6713 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
6716 undeclared_variable (c_parser_peek_token (parser
)->value
,
6717 c_parser_peek_token (parser
)->location
);
6718 else if (t
== error_mark_node
)
6722 tree u
= build_omp_clause (kind
);
6723 OMP_CLAUSE_DECL (u
) = t
;
6724 OMP_CLAUSE_CHAIN (u
) = list
;
6728 list
= tree_cons (t
, NULL_TREE
, list
);
6730 c_parser_consume_token (parser
);
6732 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
6735 c_parser_consume_token (parser
);
6741 /* Similarly, but expect leading and trailing parenthesis. This is a very
6742 common case for omp clauses. */
6745 c_parser_omp_var_list_parens (c_parser
*parser
, enum tree_code kind
, tree list
)
6747 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6749 list
= c_parser_omp_variable_list (parser
, kind
, list
);
6750 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6756 copyin ( variable-list ) */
6759 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
6761 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
6765 copyprivate ( variable-list ) */
6768 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
6770 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
6774 default ( shared | none ) */
6777 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
6779 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
6782 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6784 if (c_parser_next_token_is (parser
, CPP_NAME
))
6786 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6791 if (strcmp ("none", p
) != 0)
6793 kind
= OMP_CLAUSE_DEFAULT_NONE
;
6797 if (strcmp ("shared", p
) != 0)
6799 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
6806 c_parser_consume_token (parser
);
6811 c_parser_error (parser
, "expected %<none%> or %<shared%>");
6813 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6815 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
6818 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
6819 c
= build_omp_clause (OMP_CLAUSE_DEFAULT
);
6820 OMP_CLAUSE_CHAIN (c
) = list
;
6821 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
6827 firstprivate ( variable-list ) */
6830 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
6832 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
6836 if ( expression ) */
6839 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
6841 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6843 tree t
= c_parser_paren_condition (parser
);
6846 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
6848 c
= build_omp_clause (OMP_CLAUSE_IF
);
6849 OMP_CLAUSE_IF_EXPR (c
) = t
;
6850 OMP_CLAUSE_CHAIN (c
) = list
;
6854 c_parser_error (parser
, "expected %<(%>");
6860 lastprivate ( variable-list ) */
6863 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
6865 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
6872 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
6876 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
6878 c
= build_omp_clause (OMP_CLAUSE_NOWAIT
);
6879 OMP_CLAUSE_CHAIN (c
) = list
;
6884 num_threads ( expression ) */
6887 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
6889 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6891 tree c
, t
= c_parser_expression (parser
).value
;
6893 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6895 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6897 c_parser_error (parser
, "expected integer expression");
6901 /* Attempt to statically determine when the number isn't positive. */
6902 c
= fold_build2 (LE_EXPR
, boolean_type_node
, t
,
6903 build_int_cst (TREE_TYPE (t
), 0));
6904 if (c
== boolean_true_node
)
6906 warning (0, "%<num_threads%> value must be positive");
6907 t
= integer_one_node
;
6910 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
6912 c
= build_omp_clause (OMP_CLAUSE_NUM_THREADS
);
6913 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
6914 OMP_CLAUSE_CHAIN (c
) = list
;
6925 c_parser_omp_clause_ordered (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
6929 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
6931 c
= build_omp_clause (OMP_CLAUSE_ORDERED
);
6932 OMP_CLAUSE_CHAIN (c
) = list
;
6937 private ( variable-list ) */
6940 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
6942 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
6946 reduction ( reduction-operator : variable-list )
6949 One of: + * - & ^ | && || */
6952 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
6954 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6956 enum tree_code code
;
6958 switch (c_parser_peek_token (parser
)->type
)
6970 code
= BIT_AND_EXPR
;
6973 code
= BIT_XOR_EXPR
;
6976 code
= BIT_IOR_EXPR
;
6979 code
= TRUTH_ANDIF_EXPR
;
6982 code
= TRUTH_ORIF_EXPR
;
6985 c_parser_error (parser
,
6986 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
6987 "%<^%>, %<|%>, %<&&%>, or %<||%>");
6988 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
6991 c_parser_consume_token (parser
);
6992 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6996 nl
= c_parser_omp_variable_list (parser
, OMP_CLAUSE_REDUCTION
, list
);
6997 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
6998 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7002 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7008 schedule ( schedule-kind )
7009 schedule ( schedule-kind , expression )
7012 static | dynamic | guided | runtime
7016 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7020 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7023 c
= build_omp_clause (OMP_CLAUSE_SCHEDULE
);
7025 if (c_parser_next_token_is (parser
, CPP_NAME
))
7027 tree kind
= c_parser_peek_token (parser
)->value
;
7028 const char *p
= IDENTIFIER_POINTER (kind
);
7033 if (strcmp ("dynamic", p
) != 0)
7035 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7039 if (strcmp ("guided", p
) != 0)
7041 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7045 if (strcmp ("runtime", p
) != 0)
7047 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7054 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7055 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7059 c_parser_consume_token (parser
);
7060 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7062 c_parser_consume_token (parser
);
7064 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7066 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7067 error ("schedule %<runtime%> does not take "
7068 "a %<chunk_size%> parameter");
7069 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7070 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7072 c_parser_error (parser
, "expected integer expression");
7074 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7077 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7078 "expected %<,%> or %<)%>");
7080 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7081 OMP_CLAUSE_CHAIN (c
) = list
;
7085 c_parser_error (parser
, "invalid schedule kind");
7086 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7091 shared ( variable-list ) */
7094 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7096 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7099 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7100 is a bitmask in MASK. Return the list of clauses found; the result
7101 of clause default goes in *pdefault. */
7104 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7107 tree clauses
= NULL
;
7109 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7111 const pragma_omp_clause c_kind
= c_parser_omp_clause_name (parser
);
7113 tree prev
= clauses
;
7117 case PRAGMA_OMP_CLAUSE_COPYIN
:
7118 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7121 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7122 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7123 c_name
= "copyprivate";
7125 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7126 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7129 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7130 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7131 c_name
= "firstprivate";
7133 case PRAGMA_OMP_CLAUSE_IF
:
7134 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7137 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7138 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7139 c_name
= "lastprivate";
7141 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7142 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7145 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7146 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7147 c_name
= "num_threads";
7149 case PRAGMA_OMP_CLAUSE_ORDERED
:
7150 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7153 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7154 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7157 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7158 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7159 c_name
= "reduction";
7161 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7162 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7163 c_name
= "schedule";
7165 case PRAGMA_OMP_CLAUSE_SHARED
:
7166 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7170 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7174 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7176 /* Remove the invalid clause(s) from the list to avoid
7177 confusing the rest of the compiler. */
7179 error ("%qs is not valid for %qs", c_name
, where
);
7184 c_parser_skip_to_pragma_eol (parser
);
7186 return c_finish_omp_clauses (clauses
);
7193 In practice, we're also interested in adding the statement to an
7194 outer node. So it is convenient if we work around the fact that
7195 c_parser_statement calls add_stmt. */
7198 c_parser_omp_structured_block (c_parser
*parser
)
7200 tree stmt
= push_stmt_list ();
7201 c_parser_statement (parser
);
7202 return pop_stmt_list (stmt
);
7206 # pragma omp atomic new-line
7210 x binop= expr | x++ | ++x | x-- | --x
7212 +, *, -, /, &, ^, |, <<, >>
7214 where x is an lvalue expression with scalar type. */
7217 c_parser_omp_atomic (c_parser
*parser
)
7221 enum tree_code code
;
7223 c_parser_skip_to_pragma_eol (parser
);
7225 lhs
= c_parser_unary_expression (parser
).value
;
7226 switch (TREE_CODE (lhs
))
7230 c_parser_skip_to_end_of_block_or_statement (parser
);
7233 case PREINCREMENT_EXPR
:
7234 case POSTINCREMENT_EXPR
:
7235 lhs
= TREE_OPERAND (lhs
, 0);
7237 rhs
= integer_one_node
;
7240 case PREDECREMENT_EXPR
:
7241 case POSTDECREMENT_EXPR
:
7242 lhs
= TREE_OPERAND (lhs
, 0);
7244 rhs
= integer_one_node
;
7248 switch (c_parser_peek_token (parser
)->type
)
7254 code
= TRUNC_DIV_EXPR
;
7269 code
= BIT_AND_EXPR
;
7272 code
= BIT_IOR_EXPR
;
7275 code
= BIT_XOR_EXPR
;
7278 c_parser_error (parser
,
7279 "invalid operator for %<#pragma omp atomic%>");
7283 c_parser_consume_token (parser
);
7284 rhs
= c_parser_expression (parser
).value
;
7287 stmt
= c_finish_omp_atomic (code
, lhs
, rhs
);
7288 if (stmt
!= error_mark_node
)
7290 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7295 # pragma omp barrier new-line
7299 c_parser_omp_barrier (c_parser
*parser
)
7301 c_parser_consume_pragma (parser
);
7302 c_parser_skip_to_pragma_eol (parser
);
7304 c_finish_omp_barrier ();
7308 # pragma omp critical [(name)] new-line
7313 c_parser_omp_critical (c_parser
*parser
)
7315 tree stmt
, name
= NULL
;
7317 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7319 c_parser_consume_token (parser
);
7320 if (c_parser_next_token_is (parser
, CPP_NAME
))
7322 name
= c_parser_peek_token (parser
)->value
;
7323 c_parser_consume_token (parser
);
7324 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7327 c_parser_error (parser
, "expected identifier");
7329 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7330 c_parser_error (parser
, "expected %<(%> or end of line");
7331 c_parser_skip_to_pragma_eol (parser
);
7333 stmt
= c_parser_omp_structured_block (parser
);
7334 return c_finish_omp_critical (stmt
, name
);
7338 # pragma omp flush flush-vars[opt] new-line
7341 ( variable-list ) */
7344 c_parser_omp_flush (c_parser
*parser
)
7346 c_parser_consume_pragma (parser
);
7347 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7348 c_parser_omp_var_list_parens (parser
, 0, NULL
);
7349 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7350 c_parser_error (parser
, "expected %<(%> or end of line");
7351 c_parser_skip_to_pragma_eol (parser
);
7353 c_finish_omp_flush ();
7356 /* Parse the restricted form of the for statment allowed by OpenMP.
7357 The real trick here is to determine the loop control variable early
7358 so that we can push a new decl if necessary to make it private. */
7361 c_parser_omp_for_loop (c_parser
*parser
)
7363 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
;
7366 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7368 c_parser_error (parser
, "for statement expected");
7371 loc
= c_parser_peek_token (parser
)->location
;
7372 c_parser_consume_token (parser
);
7374 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7377 /* Parse the initialization declaration or expression. */
7378 if (c_parser_next_token_starts_declspecs (parser
))
7380 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7381 decl
= check_for_loop_decls ();
7386 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7387 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7389 decl
= c_parser_postfix_expression (parser
).value
;
7391 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7393 init
= c_parser_expr_no_commas (parser
, NULL
).value
;
7394 init
= build_modify_expr (decl
, NOP_EXPR
, init
);
7395 init
= c_process_expr_stmt (init
);
7397 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7402 /* Parse the loop condition. */
7404 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7406 cond
= c_parser_expression_conv (parser
).value
;
7407 cond
= c_objc_common_truthvalue_conversion (cond
);
7409 SET_EXPR_LOCATION (cond
, input_location
);
7411 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7413 /* Parse the increment expression. */
7415 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7416 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
7417 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7420 save_break
= c_break_label
;
7421 c_break_label
= size_one_node
;
7422 save_cont
= c_cont_label
;
7423 c_cont_label
= NULL_TREE
;
7424 body
= push_stmt_list ();
7426 add_stmt (c_parser_c99_block_statement (parser
));
7428 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_cont_label
));
7430 body
= pop_stmt_list (body
);
7431 c_break_label
= save_break
;
7432 c_cont_label
= save_cont
;
7434 /* Only bother calling c_finish_omp_for if we havn't already generated
7435 an error from the initialization parsing. */
7436 if (decl
!= NULL
&& decl
!= error_mark_node
&& init
!= error_mark_node
)
7437 return c_finish_omp_for (loc
, decl
, init
, cond
, incr
, body
, NULL
);
7441 c_parser_error (parser
, "expected iteration declaration or initialization");
7442 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7443 decl
= init
= cond
= incr
= NULL_TREE
;
7448 #pragma omp for for-clause[optseq] new-line
7452 #define OMP_FOR_CLAUSE_MASK \
7453 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7454 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7455 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7456 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7457 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7458 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7459 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7462 c_parser_omp_for (c_parser
*parser
)
7464 tree block
, clauses
, ret
;
7466 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
7469 block
= c_begin_compound_stmt (true);
7470 ret
= c_parser_omp_for_loop (parser
);
7472 OMP_FOR_CLAUSES (ret
) = clauses
;
7473 block
= c_end_compound_stmt (block
, true);
7480 # pragma omp master new-line
7485 c_parser_omp_master (c_parser
*parser
)
7487 c_parser_skip_to_pragma_eol (parser
);
7488 return c_finish_omp_master (c_parser_omp_structured_block (parser
));
7492 # pragma omp ordered new-line
7497 c_parser_omp_ordered (c_parser
*parser
)
7499 c_parser_skip_to_pragma_eol (parser
);
7500 return c_finish_omp_ordered (c_parser_omp_structured_block (parser
));
7506 { section-sequence }
7509 section-directive[opt] structured-block
7510 section-sequence section-directive structured-block */
7513 c_parser_omp_sections_scope (c_parser
*parser
)
7516 bool error_suppress
= false;
7519 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7521 /* Avoid skipping until the end of the block. */
7522 parser
->error
= false;
7526 stmt
= push_stmt_list ();
7528 loc
= c_parser_peek_token (parser
)->location
;
7529 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
7531 substmt
= push_stmt_list ();
7535 c_parser_statement (parser
);
7537 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7539 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7541 if (c_parser_next_token_is (parser
, CPP_EOF
))
7545 substmt
= pop_stmt_list (substmt
);
7546 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7547 SET_EXPR_LOCATION (substmt
, loc
);
7553 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7555 if (c_parser_next_token_is (parser
, CPP_EOF
))
7558 loc
= c_parser_peek_token (parser
)->location
;
7559 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7561 c_parser_consume_pragma (parser
);
7562 c_parser_skip_to_pragma_eol (parser
);
7563 error_suppress
= false;
7565 else if (!error_suppress
)
7567 error ("expected %<#pragma omp section%> or %<}%>");
7568 error_suppress
= true;
7571 substmt
= c_parser_omp_structured_block (parser
);
7572 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7573 SET_EXPR_LOCATION (substmt
, loc
);
7576 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
7577 "expected %<#pragma omp section%> or %<}%>");
7579 substmt
= pop_stmt_list (stmt
);
7581 stmt
= make_node (OMP_SECTIONS
);
7582 TREE_TYPE (stmt
) = void_type_node
;
7583 OMP_SECTIONS_BODY (stmt
) = substmt
;
7585 return add_stmt (stmt
);
7589 # pragma omp sections sections-clause[optseq] newline
7593 #define OMP_SECTIONS_CLAUSE_MASK \
7594 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7595 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7596 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7597 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7598 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7601 c_parser_omp_sections (c_parser
*parser
)
7603 tree block
, clauses
, ret
;
7605 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
7606 "#pragma omp sections");
7608 block
= c_begin_compound_stmt (true);
7609 ret
= c_parser_omp_sections_scope (parser
);
7611 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
7612 block
= c_end_compound_stmt (block
, true);
7619 # pragma parallel parallel-clause new-line
7620 # pragma parallel for parallel-for-clause new-line
7621 # pragma parallel sections parallel-sections-clause new-line
7624 #define OMP_PARALLEL_CLAUSE_MASK \
7625 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7626 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7627 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7628 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7629 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7630 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7631 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7632 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7635 c_parser_omp_parallel (c_parser
*parser
)
7637 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
7638 const char *p_name
= "#pragma omp parallel";
7639 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
7640 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
7642 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7644 c_parser_consume_token (parser
);
7645 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
7646 p_name
= "#pragma omp parallel for";
7647 mask
|= OMP_FOR_CLAUSE_MASK
;
7648 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
7650 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7652 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7653 if (strcmp (p
, "sections") == 0)
7655 c_parser_consume_token (parser
);
7656 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
7657 p_name
= "#pragma omp parallel sections";
7658 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
7659 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
7663 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
7667 case PRAGMA_OMP_PARALLEL
:
7668 block
= c_begin_omp_parallel ();
7669 c_parser_statement (parser
);
7670 stmt
= c_finish_omp_parallel (clauses
, block
);
7673 case PRAGMA_OMP_PARALLEL_FOR
:
7674 block
= c_begin_omp_parallel ();
7675 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
7676 stmt
= c_parser_omp_for_loop (parser
);
7678 OMP_FOR_CLAUSES (stmt
) = ws_clause
;
7679 stmt
= c_finish_omp_parallel (par_clause
, block
);
7680 OMP_PARALLEL_COMBINED (stmt
) = 1;
7683 case PRAGMA_OMP_PARALLEL_SECTIONS
:
7684 block
= c_begin_omp_parallel ();
7685 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
7686 stmt
= c_parser_omp_sections_scope (parser
);
7688 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
7689 stmt
= c_finish_omp_parallel (par_clause
, block
);
7690 OMP_PARALLEL_COMBINED (stmt
) = 1;
7701 # pragma omp single single-clause[optseq] new-line
7705 #define OMP_SINGLE_CLAUSE_MASK \
7706 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7707 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7708 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
7709 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7712 c_parser_omp_single (c_parser
*parser
)
7714 tree stmt
= make_node (OMP_SINGLE
);
7715 TREE_TYPE (stmt
) = void_type_node
;
7717 OMP_SINGLE_CLAUSES (stmt
)
7718 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
7719 "#pragma omp single");
7720 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
7722 return add_stmt (stmt
);
7726 /* Main entry point to parsing most OpenMP pragmas. */
7729 c_parser_omp_construct (c_parser
*parser
)
7731 enum pragma_kind p_kind
;
7735 loc
= c_parser_peek_token (parser
)->location
;
7736 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
7737 c_parser_consume_pragma (parser
);
7741 case PRAGMA_OMP_ATOMIC
:
7742 c_parser_omp_atomic (parser
);
7744 case PRAGMA_OMP_CRITICAL
:
7745 stmt
= c_parser_omp_critical (parser
);
7747 case PRAGMA_OMP_FOR
:
7748 stmt
= c_parser_omp_for (parser
);
7750 case PRAGMA_OMP_MASTER
:
7751 stmt
= c_parser_omp_master (parser
);
7753 case PRAGMA_OMP_ORDERED
:
7754 stmt
= c_parser_omp_ordered (parser
);
7756 case PRAGMA_OMP_PARALLEL
:
7757 stmt
= c_parser_omp_parallel (parser
);
7759 case PRAGMA_OMP_SECTIONS
:
7760 stmt
= c_parser_omp_sections (parser
);
7762 case PRAGMA_OMP_SINGLE
:
7763 stmt
= c_parser_omp_single (parser
);
7770 SET_EXPR_LOCATION (stmt
, loc
);
7775 # pragma omp threadprivate (variable-list) */
7778 c_parser_omp_threadprivate (c_parser
*parser
)
7782 c_parser_consume_pragma (parser
);
7783 vars
= c_parser_omp_var_list_parens (parser
, 0, NULL
);
7785 if (!targetm
.have_tls
)
7786 sorry ("threadprivate variables not supported in this target");
7788 /* Mark every variable in VARS to be assigned thread local storage. */
7789 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
7791 tree v
= TREE_PURPOSE (t
);
7793 /* If V had already been marked threadprivate, it doesn't matter
7794 whether it had been used prior to this point. */
7795 if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
7796 error ("%qE declared %<threadprivate%> after first use", v
);
7797 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
7798 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
7799 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
7800 error ("%<threadprivate%> %qE has incomplete type", v
);
7803 if (! DECL_THREAD_LOCAL_P (v
))
7805 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
7806 /* If rtl has been already set for this var, call
7807 make_decl_rtl once again, so that encode_section_info
7808 has a chance to look at the new decl flags. */
7809 if (DECL_RTL_SET_P (v
))
7812 C_DECL_THREADPRIVATE_P (v
) = 1;
7816 c_parser_skip_to_pragma_eol (parser
);
7820 /* Parse a single source file. */
7825 /* Use local storage to begin. If the first token is a pragma, parse it.
7826 If it is #pragma GCC pch_preprocess, then this will load a PCH file
7827 which will cause garbage collection. */
7830 memset (&tparser
, 0, sizeof tparser
);
7831 the_parser
= &tparser
;
7833 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
7834 c_parser_pragma_pch_preprocess (&tparser
);
7836 the_parser
= GGC_NEW (c_parser
);
7837 *the_parser
= tparser
;
7839 c_parser_translation_unit (the_parser
);
7843 #include "gt-c-parser.h"