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
)
2168 tree e
= expr
.value
;
2170 /* If the expression is not of a type to which we cannot assign a line
2171 number, wrap the thing in a no-op NOP_EXPR. */
2172 if (DECL_P (e
) || CONSTANT_CLASS_P (e
))
2173 e
= build1 (NOP_EXPR
, void_type_node
, e
);
2176 SET_EXPR_LOCATION (e
, input_location
);
2180 pop_maybe_used (was_vm
);
2182 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2186 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
2187 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
2188 be redeclared; otherwise it may not. KIND indicates which kind of
2189 declarator is wanted. Returns a valid declarator except in the
2190 case of a syntax error in which case NULL is returned. *SEEN_ID is
2191 set to true if an identifier being declared is seen; this is used
2192 to diagnose bad forms of abstract array declarators and to
2193 determine whether an identifier list is syntactically permitted.
2196 pointer[opt] direct-declarator
2200 ( attributes[opt] declarator )
2201 direct-declarator array-declarator
2202 direct-declarator ( parameter-type-list )
2203 direct-declarator ( identifier-list[opt] )
2206 * type-qualifier-list[opt]
2207 * type-qualifier-list[opt] pointer
2209 type-qualifier-list:
2212 type-qualifier-list type-qualifier
2213 type-qualifier-list attributes
2215 parameter-type-list:
2217 parameter-list , ...
2220 parameter-declaration
2221 parameter-list , parameter-declaration
2223 parameter-declaration:
2224 declaration-specifiers declarator attributes[opt]
2225 declaration-specifiers abstract-declarator[opt] attributes[opt]
2229 identifier-list , identifier
2231 abstract-declarator:
2233 pointer[opt] direct-abstract-declarator
2235 direct-abstract-declarator:
2236 ( attributes[opt] abstract-declarator )
2237 direct-abstract-declarator[opt] array-declarator
2238 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
2243 direct-declarator ( parameter-forward-declarations
2244 parameter-type-list[opt] )
2246 direct-abstract-declarator:
2247 direct-abstract-declarator[opt] ( parameter-forward-declarations
2248 parameter-type-list[opt] )
2250 parameter-forward-declarations:
2252 parameter-forward-declarations parameter-list ;
2254 The uses of attributes shown above are GNU extensions.
2256 Some forms of array declarator are not included in C99 in the
2257 syntax for abstract declarators; these are disallowed elsewhere.
2258 This may be a defect (DR#289).
2260 This function also accepts an omitted abstract declarator as being
2261 an abstract declarator, although not part of the formal syntax. */
2263 static struct c_declarator
*
2264 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2267 /* Parse any initial pointer part. */
2268 if (c_parser_next_token_is (parser
, CPP_MULT
))
2270 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2271 struct c_declarator
*inner
;
2272 c_parser_consume_token (parser
);
2273 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2274 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2278 return make_pointer_declarator (quals_attrs
, inner
);
2280 /* Now we have a direct declarator, direct abstract declarator or
2281 nothing (which counts as a direct abstract declarator here). */
2282 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
2285 /* Parse a direct declarator or direct abstract declarator; arguments
2286 as c_parser_declarator. */
2288 static struct c_declarator
*
2289 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
2292 /* The direct declarator must start with an identifier (possibly
2293 omitted) or a parenthesized declarator (possibly abstract). In
2294 an ordinary declarator, initial parentheses must start a
2295 parenthesized declarator. In an abstract declarator or parameter
2296 declarator, they could start a parenthesized declarator or a
2297 parameter list. To tell which, the open parenthesis and any
2298 following attributes must be read. If a declaration specifier
2299 follows, then it is a parameter list; if the specifier is a
2300 typedef name, there might be an ambiguity about redeclaring it,
2301 which is resolved in the direction of treating it as a typedef
2302 name. If a close parenthesis follows, it is also an empty
2303 parameter list, as the syntax does not permit empty abstract
2304 declarators. Otherwise, it is a parenthesized declarator (in
2305 which case the analysis may be repeated inside it, recursively).
2307 ??? There is an ambiguity in a parameter declaration "int
2308 (__attribute__((foo)) x)", where x is not a typedef name: it
2309 could be an abstract declarator for a function, or declare x with
2310 parentheses. The proper resolution of this ambiguity needs
2311 documenting. At present we follow an accident of the old
2312 parser's implementation, whereby the first parameter must have
2313 some declaration specifiers other than just attributes. Thus as
2314 a parameter declaration it is treated as a parenthesized
2315 parameter named x, and as an abstract declarator it is
2318 ??? Also following the old parser, attributes inside an empty
2319 parameter list are ignored, making it a list not yielding a
2320 prototype, rather than giving an error or making it have one
2321 parameter with implicit type int.
2323 ??? Also following the old parser, typedef names may be
2324 redeclared in declarators, but not Objective-C class names. */
2326 if (kind
!= C_DTR_ABSTRACT
2327 && c_parser_next_token_is (parser
, CPP_NAME
)
2329 && c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
)
2330 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
2332 struct c_declarator
*inner
2333 = build_id_declarator (c_parser_peek_token (parser
)->value
);
2335 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
2336 c_parser_consume_token (parser
);
2337 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2340 if (kind
!= C_DTR_NORMAL
2341 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2343 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
2344 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2347 /* Either we are at the end of an abstract declarator, or we have
2350 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2353 struct c_declarator
*inner
;
2354 c_parser_consume_token (parser
);
2355 attrs
= c_parser_attributes (parser
);
2356 if (kind
!= C_DTR_NORMAL
2357 && (c_parser_next_token_starts_declspecs (parser
)
2358 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
2360 struct c_arg_info
*args
2361 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
2368 = build_function_declarator (args
,
2369 build_id_declarator (NULL_TREE
));
2370 return c_parser_direct_declarator_inner (parser
, *seen_id
,
2374 /* A parenthesized declarator. */
2375 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
2376 if (inner
!= NULL
&& attrs
!= NULL
)
2377 inner
= build_attrs_declarator (attrs
, inner
);
2378 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2380 c_parser_consume_token (parser
);
2384 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
2388 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2395 if (kind
== C_DTR_NORMAL
)
2397 c_parser_error (parser
, "expected identifier or %<(%>");
2401 return build_id_declarator (NULL_TREE
);
2405 /* Parse part of a direct declarator or direct abstract declarator,
2406 given that some (in INNER) has already been parsed; ID_PRESENT is
2407 true if an identifier is present, false for an abstract
2410 static struct c_declarator
*
2411 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
2412 struct c_declarator
*inner
)
2414 /* Parse a sequence of array declarators and parameter lists. */
2415 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
2417 struct c_declarator
*declarator
;
2418 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
2422 c_parser_consume_token (parser
);
2423 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2424 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
2426 c_parser_consume_token (parser
);
2427 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
2428 c_parser_declspecs (parser
, quals_attrs
, false, false, true);
2429 if (!quals_attrs
->declspecs_seen_p
)
2431 /* If "static" is present, there must be an array dimension.
2432 Otherwise, there may be a dimension, "*", or no
2437 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2441 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2446 else if (c_parser_next_token_is (parser
, CPP_MULT
))
2448 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
2452 c_parser_consume_token (parser
);
2457 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2463 dimen
= c_parser_expr_no_commas (parser
, NULL
).value
;
2466 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
2467 c_parser_consume_token (parser
);
2470 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
2474 declarator
= build_array_declarator (dimen
, quals_attrs
, static_seen
,
2476 if (declarator
== NULL
)
2478 inner
= set_array_declarator_inner (declarator
, inner
, !id_present
);
2479 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2481 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2484 struct c_arg_info
*args
;
2485 c_parser_consume_token (parser
);
2486 attrs
= c_parser_attributes (parser
);
2487 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
2492 inner
= build_function_declarator (args
, inner
);
2493 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
2499 /* Parse a parameter list or identifier list, including the closing
2500 parenthesis but not the opening one. ATTRS are the attributes at
2501 the start of the list. ID_LIST_OK is true if an identifier list is
2502 acceptable; such a list must not have attributes at the start. */
2504 static struct c_arg_info
*
2505 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
2508 declare_parm_level ();
2509 /* If the list starts with an identifier, it is an identifier list.
2510 Otherwise, it is either a prototype list or an empty list. */
2513 && c_parser_next_token_is (parser
, CPP_NAME
)
2514 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2516 tree list
= NULL_TREE
, *nextp
= &list
;
2517 while (c_parser_next_token_is (parser
, CPP_NAME
)
2518 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
2520 *nextp
= build_tree_list (NULL_TREE
,
2521 c_parser_peek_token (parser
)->value
);
2522 nextp
= & TREE_CHAIN (*nextp
);
2523 c_parser_consume_token (parser
);
2524 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
2526 c_parser_consume_token (parser
);
2527 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2529 c_parser_error (parser
, "expected identifier");
2533 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2535 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2540 ret
->pending_sizes
= 0;
2541 ret
->had_vla_unspec
= 0;
2542 c_parser_consume_token (parser
);
2548 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2556 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
);
2562 /* Parse a parameter list (possibly empty), including the closing
2563 parenthesis but not the opening one. ATTRS are the attributes at
2564 the start of the list. */
2566 static struct c_arg_info
*
2567 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
)
2569 bool good_parm
= false;
2570 /* ??? Following the old parser, forward parameter declarations may
2571 use abstract declarators, and if no real parameter declarations
2572 follow the forward declarations then this is not diagnosed. Also
2573 note as above that attributes are ignored as the only contents of
2574 the parentheses, or as the only contents after forward
2576 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2578 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2583 ret
->pending_sizes
= 0;
2584 ret
->had_vla_unspec
= 0;
2585 c_parser_consume_token (parser
);
2588 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2590 struct c_arg_info
*ret
= XOBNEW (&parser_obstack
, struct c_arg_info
);
2594 ret
->pending_sizes
= 0;
2595 ret
->had_vla_unspec
= 0;
2596 /* Suppress -Wold-style-definition for this case. */
2597 ret
->types
= error_mark_node
;
2598 error ("ISO C requires a named argument before %<...%>");
2599 c_parser_consume_token (parser
);
2600 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2602 c_parser_consume_token (parser
);
2607 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2612 /* Nonempty list of parameters, either terminated with semicolon
2613 (forward declarations; recurse) or with close parenthesis (normal
2614 function) or with ", ... )" (variadic function). */
2617 /* Parse a parameter. */
2618 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
2623 push_parm_decl (parm
);
2625 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2628 c_parser_consume_token (parser
);
2629 mark_forward_parm_decls ();
2630 new_attrs
= c_parser_attributes (parser
);
2631 return c_parser_parms_list_declarator (parser
, new_attrs
);
2633 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2635 c_parser_consume_token (parser
);
2637 return get_parm_info (false);
2640 struct c_arg_info
*ret
2641 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2646 ret
->pending_sizes
= 0;
2647 ret
->had_vla_unspec
= 0;
2651 if (!c_parser_require (parser
, CPP_COMMA
,
2652 "expected %<;%>, %<,%> or %<)%>"))
2654 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2657 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
2659 c_parser_consume_token (parser
);
2660 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2662 c_parser_consume_token (parser
);
2664 return get_parm_info (true);
2667 struct c_arg_info
*ret
2668 = XOBNEW (&parser_obstack
, struct c_arg_info
);
2673 ret
->pending_sizes
= 0;
2674 ret
->had_vla_unspec
= 0;
2680 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2688 /* Parse a parameter declaration. ATTRS are the attributes at the
2689 start of the declaration if it is the first parameter. */
2691 static struct c_parm
*
2692 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
2694 struct c_declspecs
*specs
;
2695 struct c_declarator
*declarator
;
2697 tree postfix_attrs
= NULL_TREE
;
2699 if (!c_parser_next_token_starts_declspecs (parser
))
2701 /* ??? In some Objective-C cases '...' isn't applicable so there
2702 should be a different message. */
2703 c_parser_error (parser
,
2704 "expected declaration specifiers or %<...%>");
2705 c_parser_skip_to_end_of_parameter (parser
);
2708 specs
= build_null_declspecs ();
2711 declspecs_add_attrs (specs
, attrs
);
2714 c_parser_declspecs (parser
, specs
, true, true, true);
2715 finish_declspecs (specs
);
2716 pending_xref_error ();
2717 prefix_attrs
= specs
->attrs
;
2718 specs
->attrs
= NULL_TREE
;
2719 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2720 C_DTR_PARM
, &dummy
);
2721 if (declarator
== NULL
)
2723 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
2726 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2727 postfix_attrs
= c_parser_attributes (parser
);
2728 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
2732 /* Parse a string literal in an asm expression. It should not be
2733 translated, and wide string literals are an error although
2734 permitted by the syntax. This is a GNU extension.
2739 ??? At present, following the old parser, the caller needs to have
2740 set c_lex_string_translate to 0. It would be better to follow the
2741 C++ parser rather than using the c_lex_string_translate kludge. */
2744 c_parser_asm_string_literal (c_parser
*parser
)
2747 if (c_parser_next_token_is (parser
, CPP_STRING
))
2749 str
= c_parser_peek_token (parser
)->value
;
2750 c_parser_consume_token (parser
);
2752 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
2754 error ("wide string literal in %<asm%>");
2755 str
= build_string (1, "");
2756 c_parser_consume_token (parser
);
2760 c_parser_error (parser
, "expected string literal");
2766 /* Parse a simple asm expression. This is used in restricted
2767 contexts, where a full expression with inputs and outputs does not
2768 make sense. This is a GNU extension.
2771 asm ( asm-string-literal )
2775 c_parser_simple_asm_expr (c_parser
*parser
)
2778 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
2779 /* ??? Follow the C++ parser rather than using the
2780 c_lex_string_translate kludge. */
2781 c_lex_string_translate
= 0;
2782 c_parser_consume_token (parser
);
2783 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2785 c_lex_string_translate
= 1;
2788 str
= c_parser_asm_string_literal (parser
);
2789 c_lex_string_translate
= 1;
2790 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
2792 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2798 /* Parse (possibly empty) attributes. This is a GNU extension.
2802 attributes attribute
2805 __attribute__ ( ( attribute-list ) )
2809 attribute_list , attrib
2814 any-word ( identifier )
2815 any-word ( identifier , nonempty-expr-list )
2816 any-word ( expr-list )
2818 where the "identifier" must not be declared as a type, and
2819 "any-word" may be any identifier (including one declared as a
2820 type), a reserved word storage class specifier, type specifier or
2821 type qualifier. ??? This still leaves out most reserved keywords
2822 (following the old parser), shouldn't we include them, and why not
2823 allow identifiers declared as types to start the arguments? */
2826 c_parser_attributes (c_parser
*parser
)
2828 tree attrs
= NULL_TREE
;
2829 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2831 /* ??? Follow the C++ parser rather than using the
2832 c_lex_string_translate kludge. */
2833 c_lex_string_translate
= 0;
2834 c_parser_consume_token (parser
);
2835 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2837 c_lex_string_translate
= 1;
2840 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2842 c_lex_string_translate
= 1;
2843 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2846 /* Parse the attribute list. */
2847 while (c_parser_next_token_is (parser
, CPP_COMMA
)
2848 || c_parser_next_token_is (parser
, CPP_NAME
)
2849 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
2851 tree attr
, attr_name
, attr_args
;
2852 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2854 c_parser_consume_token (parser
);
2857 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
2859 /* ??? See comment above about what keywords are
2862 switch (c_parser_peek_token (parser
)->keyword
)
2897 attr_name
= c_parser_peek_token (parser
)->value
;
2898 c_parser_consume_token (parser
);
2899 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
2901 attr
= build_tree_list (attr_name
, NULL_TREE
);
2902 attrs
= chainon (attrs
, attr
);
2905 c_parser_consume_token (parser
);
2906 /* Parse the attribute contents. If they start with an
2907 identifier which is followed by a comma or close
2908 parenthesis, then the arguments start with that
2909 identifier; otherwise they are an expression list. */
2910 if (c_parser_next_token_is (parser
, CPP_NAME
)
2911 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
2912 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
2913 || (c_parser_peek_2nd_token (parser
)->type
2914 == CPP_CLOSE_PAREN
)))
2916 tree arg1
= c_parser_peek_token (parser
)->value
;
2917 c_parser_consume_token (parser
);
2918 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2919 attr_args
= build_tree_list (NULL_TREE
, arg1
);
2922 c_parser_consume_token (parser
);
2923 attr_args
= tree_cons (NULL_TREE
, arg1
,
2924 c_parser_expr_list (parser
, false));
2929 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2930 attr_args
= NULL_TREE
;
2932 attr_args
= c_parser_expr_list (parser
, false);
2934 attr
= build_tree_list (attr_name
, attr_args
);
2935 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2936 c_parser_consume_token (parser
);
2939 c_lex_string_translate
= 1;
2940 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2944 attrs
= chainon (attrs
, attr
);
2946 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2947 c_parser_consume_token (parser
);
2950 c_lex_string_translate
= 1;
2951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2955 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
2956 c_parser_consume_token (parser
);
2959 c_lex_string_translate
= 1;
2960 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2964 c_lex_string_translate
= 1;
2969 /* Parse a type name (C90 6.5.5, C99 6.7.6).
2972 specifier-qualifier-list abstract-declarator[opt]
2975 static struct c_type_name
*
2976 c_parser_type_name (c_parser
*parser
)
2978 struct c_declspecs
*specs
= build_null_declspecs ();
2979 struct c_declarator
*declarator
;
2980 struct c_type_name
*ret
;
2982 c_parser_declspecs (parser
, specs
, false, true, true);
2983 if (!specs
->declspecs_seen_p
)
2985 c_parser_error (parser
, "expected specifier-qualifier-list");
2988 pending_xref_error ();
2989 finish_declspecs (specs
);
2990 declarator
= c_parser_declarator (parser
, specs
->type_seen_p
,
2991 C_DTR_ABSTRACT
, &dummy
);
2992 if (declarator
== NULL
)
2994 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
2996 ret
->declarator
= declarator
;
3000 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
3003 assignment-expression
3004 { initializer-list }
3005 { initializer-list , }
3008 designation[opt] initializer
3009 initializer-list , designation[opt] initializer
3016 designator-list designator
3023 [ constant-expression ]
3035 [ constant-expression ... constant-expression ]
3037 Any expression without commas is accepted in the syntax for the
3038 constant-expressions, with non-constant expressions rejected later.
3040 This function is only used for top-level initializers; for nested
3041 ones, see c_parser_initval. */
3043 static struct c_expr
3044 c_parser_initializer (c_parser
*parser
)
3046 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3047 return c_parser_braced_init (parser
, NULL_TREE
, false);
3051 ret
= c_parser_expr_no_commas (parser
, NULL
);
3052 if (TREE_CODE (ret
.value
) != STRING_CST
3053 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
3054 ret
= default_function_array_conversion (ret
);
3059 /* Parse a braced initializer list. TYPE is the type specified for a
3060 compound literal, and NULL_TREE for other initializers and for
3061 nested braced lists. NESTED_P is true for nested braced lists,
3062 false for the list of a compound literal or the list that is the
3063 top-level initializer in a declaration. */
3065 static struct c_expr
3066 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
)
3068 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
3069 c_parser_consume_token (parser
);
3071 push_init_level (0);
3073 really_start_incremental_init (type
);
3074 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3077 pedwarn ("ISO C forbids empty initializer braces");
3081 /* Parse a non-empty initializer list, possibly with a trailing
3085 c_parser_initelt (parser
);
3088 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3089 c_parser_consume_token (parser
);
3092 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3096 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3099 ret
.value
= error_mark_node
;
3100 ret
.original_code
= ERROR_MARK
;
3101 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
3104 c_parser_consume_token (parser
);
3105 return pop_init_level (0);
3108 /* Parse a nested initializer, including designators. */
3111 c_parser_initelt (c_parser
*parser
)
3113 /* Parse any designator or designator list. A single array
3114 designator may have the subsequent "=" omitted in GNU C, but a
3115 longer list or a structure member designator may not. */
3116 if (c_parser_next_token_is (parser
, CPP_NAME
)
3117 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
3119 /* Old-style structure member designator. */
3120 set_init_label (c_parser_peek_token (parser
)->value
);
3122 pedwarn ("obsolete use of designated initializer with %<:%>");
3123 c_parser_consume_token (parser
);
3124 c_parser_consume_token (parser
);
3128 /* des_seen is 0 if there have been no designators, 1 if there
3129 has been a single array designator and 2 otherwise. */
3131 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
3132 || c_parser_next_token_is (parser
, CPP_DOT
))
3134 int des_prev
= des_seen
;
3137 if (c_parser_next_token_is (parser
, CPP_DOT
))
3140 c_parser_consume_token (parser
);
3141 if (c_parser_next_token_is (parser
, CPP_NAME
))
3143 set_init_label (c_parser_peek_token (parser
)->value
);
3144 c_parser_consume_token (parser
);
3149 init
.value
= error_mark_node
;
3150 init
.original_code
= ERROR_MARK
;
3151 c_parser_error (parser
, "expected identifier");
3152 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3153 process_init_element (init
);
3160 /* ??? Following the old parser, [ objc-receiver
3161 objc-message-args ] is accepted as an initializer,
3162 being distinguished from a designator by what follows
3163 the first assignment expression inside the square
3164 brackets, but after a first array designator a
3165 subsequent square bracket is for Objective-C taken to
3166 start an expression, using the obsolete form of
3167 designated initializer without '=', rather than
3168 possibly being a second level of designation: in LALR
3169 terms, the '[' is shifted rather than reducing
3170 designator to designator-list. */
3171 if (des_prev
== 1 && c_dialect_objc ())
3173 des_seen
= des_prev
;
3176 if (des_prev
== 0 && c_dialect_objc ())
3178 /* This might be an array designator or an
3179 Objective-C message expression. If the former,
3180 continue parsing here; if the latter, parse the
3181 remainder of the initializer given the starting
3182 primary-expression. ??? It might make sense to
3183 distinguish when des_prev == 1 as well; see
3184 previous comment. */
3186 struct c_expr mexpr
;
3187 c_parser_consume_token (parser
);
3188 if (c_parser_peek_token (parser
)->type
== CPP_NAME
3189 && ((c_parser_peek_token (parser
)->id_kind
3191 || (c_parser_peek_token (parser
)->id_kind
3192 == C_ID_CLASSNAME
)))
3194 /* Type name receiver. */
3195 tree id
= c_parser_peek_token (parser
)->value
;
3196 c_parser_consume_token (parser
);
3197 rec
= objc_get_class_reference (id
);
3198 goto parse_message_args
;
3200 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3201 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
3202 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3203 goto array_desig_after_first
;
3204 /* Expression receiver. So far only one part
3205 without commas has been parsed; there might be
3206 more of the expression. */
3208 while (c_parser_next_token_is (parser
, CPP_COMMA
))
3211 c_parser_consume_token (parser
);
3212 next
= c_parser_expr_no_commas (parser
, NULL
);
3213 next
= default_function_array_conversion (next
);
3214 rec
= build_compound_expr (rec
, next
.value
);
3217 /* Now parse the objc-message-args. */
3218 args
= c_parser_objc_message_args (parser
);
3219 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3222 = objc_build_message_expr (build_tree_list (rec
, args
));
3223 mexpr
.original_code
= ERROR_MARK
;
3224 /* Now parse and process the remainder of the
3225 initializer, starting with this message
3226 expression as a primary-expression. */
3227 c_parser_initval (parser
, &mexpr
);
3230 c_parser_consume_token (parser
);
3231 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
3232 array_desig_after_first
:
3233 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3235 c_parser_consume_token (parser
);
3236 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
3240 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3242 c_parser_consume_token (parser
);
3243 set_init_index (first
, second
);
3244 if (pedantic
&& second
)
3245 pedwarn ("ISO C forbids specifying range of "
3246 "elements to initialize");
3249 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3255 if (c_parser_next_token_is (parser
, CPP_EQ
))
3257 if (pedantic
&& !flag_isoc99
)
3258 pedwarn ("ISO C90 forbids specifying subobject to initialize");
3259 c_parser_consume_token (parser
);
3266 pedwarn ("obsolete use of designated initializer "
3272 init
.value
= error_mark_node
;
3273 init
.original_code
= ERROR_MARK
;
3274 c_parser_error (parser
, "expected %<=%>");
3275 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3276 process_init_element (init
);
3282 c_parser_initval (parser
, NULL
);
3285 /* Parse a nested initializer; as c_parser_initializer but parses
3286 initializers within braced lists, after any designators have been
3287 applied. If AFTER is not NULL then it is an Objective-C message
3288 expression which is the primary-expression starting the
3292 c_parser_initval (c_parser
*parser
, struct c_expr
*after
)
3295 gcc_assert (!after
|| c_dialect_objc ());
3296 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
3297 init
= c_parser_braced_init (parser
, NULL_TREE
, true);
3300 init
= c_parser_expr_no_commas (parser
, after
);
3301 if (init
.value
!= NULL_TREE
3302 && TREE_CODE (init
.value
) != STRING_CST
3303 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
3304 init
= default_function_array_conversion (init
);
3306 process_init_element (init
);
3309 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
3313 { block-item-list[opt] }
3314 { label-declarations block-item-list }
3318 block-item-list block-item
3330 { label-declarations block-item-list }
3333 __extension__ nested-declaration
3334 nested-function-definition
3338 label-declarations label-declaration
3341 __label__ identifier-list ;
3343 Allowing the mixing of declarations and code is new in C99. The
3344 GNU syntax also permits (not shown above) labels at the end of
3345 compound statements, which yield an error. We don't allow labels
3346 on declarations; this might seem like a natural extension, but
3347 there would be a conflict between attributes on the label and
3348 prefix attributes on the declaration. ??? The syntax follows the
3349 old parser in requiring something after label declarations.
3350 Although they are erroneous if the labels declared aren't defined,
3351 is it useful for the syntax to be this way?
3363 c_parser_compound_statement (c_parser
*parser
)
3366 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
3367 return error_mark_node
;
3368 stmt
= c_begin_compound_stmt (true);
3369 c_parser_compound_statement_nostart (parser
);
3370 return c_end_compound_stmt (stmt
, true);
3373 /* Parse a compound statement except for the opening brace. This is
3374 used for parsing both compound statements and statement expressions
3375 (which follow different paths to handling the opening). */
3378 c_parser_compound_statement_nostart (c_parser
*parser
)
3380 bool last_stmt
= false;
3381 bool last_label
= false;
3382 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3384 c_parser_consume_token (parser
);
3387 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3389 /* Read zero or more forward-declarations for labels that nested
3390 functions can jump to. */
3391 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
3393 c_parser_consume_token (parser
);
3394 /* Any identifiers, including those declared as type names,
3399 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
3401 c_parser_error (parser
, "expected identifier");
3405 = declare_label (c_parser_peek_token (parser
)->value
);
3406 C_DECLARED_LABEL_FLAG (label
) = 1;
3407 add_stmt (build_stmt (DECL_EXPR
, label
));
3408 c_parser_consume_token (parser
);
3409 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3410 c_parser_consume_token (parser
);
3414 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3416 /* ??? Locating this diagnostic on the token after the
3417 declarations end follows the old parser, but it might be
3418 better to locate it where the declarations start instead. */
3420 pedwarn ("ISO C forbids label declarations");
3422 /* We must now have at least one statement, label or declaration. */
3423 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3425 c_parser_error (parser
, "expected declaration or statement");
3426 c_parser_consume_token (parser
);
3429 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
3431 location_t loc
= c_parser_peek_token (parser
)->location
;
3432 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3433 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3434 || (c_parser_next_token_is (parser
, CPP_NAME
)
3435 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3439 c_parser_label (parser
);
3441 else if (!last_label
3442 && c_parser_next_token_starts_declspecs (parser
))
3445 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3447 && ((pedantic
&& !flag_isoc99
)
3448 || warn_declaration_after_statement
))
3449 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3453 else if (!last_label
3454 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3456 /* __extension__ can start a declaration, but is also an
3457 unary operator that can start an expression. Consume all
3458 but the last of a possible series of __extension__ to
3460 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
3461 && (c_parser_peek_2nd_token (parser
)->keyword
3463 c_parser_consume_token (parser
);
3464 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
3467 ext
= disable_extension_diagnostics ();
3468 c_parser_consume_token (parser
);
3470 c_parser_declaration_or_fndef (parser
, true, true, true, true);
3471 /* Following the old parser, __extension__ does not
3472 disable this diagnostic. */
3473 restore_extension_diagnostics (ext
);
3475 && ((pedantic
&& !flag_isoc99
)
3476 || warn_declaration_after_statement
))
3477 pedwarn_c90 ("%HISO C90 forbids mixed declarations and code",
3484 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3486 /* External pragmas, and some omp pragmas, are not associated
3487 with regular c code, and so are not to be considered statements
3488 syntactically. This ensures that the user doesn't put them
3489 places that would turn into syntax errors if the directive
3491 if (c_parser_pragma (parser
, pragma_compound
))
3492 last_label
= false, last_stmt
= true;
3494 else if (c_parser_next_token_is (parser
, CPP_EOF
))
3496 c_parser_error (parser
, "expected declaration or statement");
3504 c_parser_statement_after_labels (parser
);
3507 parser
->error
= false;
3510 error ("label at end of compound statement");
3511 c_parser_consume_token (parser
);
3514 /* Parse a label (C90 6.6.1, C99 6.8.1).
3517 identifier : attributes[opt]
3518 case constant-expression :
3524 case constant-expression ... constant-expression :
3526 The use of attributes on labels is a GNU extension. The syntax in
3527 GNU C accepts any expressions without commas, non-constant
3528 expressions being rejected later. */
3531 c_parser_label (c_parser
*parser
)
3533 location_t loc1
= c_parser_peek_token (parser
)->location
;
3534 tree label
= NULL_TREE
;
3535 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
3538 c_parser_consume_token (parser
);
3539 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
3540 if (c_parser_next_token_is (parser
, CPP_COLON
))
3542 c_parser_consume_token (parser
);
3543 label
= do_case (exp1
, NULL_TREE
);
3545 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3547 c_parser_consume_token (parser
);
3548 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
3549 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3550 label
= do_case (exp1
, exp2
);
3553 c_parser_error (parser
, "expected %<:%> or %<...%>");
3555 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
3557 c_parser_consume_token (parser
);
3558 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
3559 label
= do_case (NULL_TREE
, NULL_TREE
);
3563 tree name
= c_parser_peek_token (parser
)->value
;
3567 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
3568 c_parser_consume_token (parser
);
3569 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
3570 loc2
= c_parser_peek_token (parser
)->location
;
3571 c_parser_consume_token (parser
);
3572 attrs
= c_parser_attributes (parser
);
3573 tlab
= define_label (loc2
, name
);
3576 decl_attributes (&tlab
, attrs
, 0);
3577 label
= add_stmt (build_stmt (LABEL_EXPR
, tlab
));
3581 SET_EXPR_LOCATION (label
, loc1
);
3584 /* Parse a statement (C90 6.6, C99 6.8).
3589 expression-statement
3597 expression-statement:
3600 selection-statement:
3604 iteration-statement:
3613 return expression[opt] ;
3626 objc-throw-statement
3627 objc-try-catch-statement
3628 objc-synchronized-statement
3630 objc-throw-statement:
3644 parallel-for-construct
3645 parallel-sections-construct
3652 parallel-directive structured-block
3655 for-directive iteration-statement
3658 sections-directive section-scope
3661 single-directive structured-block
3663 parallel-for-construct:
3664 parallel-for-directive iteration-statement
3666 parallel-sections-construct:
3667 parallel-sections-directive section-scope
3670 master-directive structured-block
3673 critical-directive structured-block
3676 atomic-directive expression-statement
3679 ordered-directive structured-block */
3682 c_parser_statement (c_parser
*parser
)
3684 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3685 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3686 || (c_parser_next_token_is (parser
, CPP_NAME
)
3687 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3688 c_parser_label (parser
);
3689 c_parser_statement_after_labels (parser
);
3692 /* Parse a statement, other than a labeled statement. */
3695 c_parser_statement_after_labels (c_parser
*parser
)
3697 location_t loc
= c_parser_peek_token (parser
)->location
;
3698 tree stmt
= NULL_TREE
;
3699 switch (c_parser_peek_token (parser
)->type
)
3701 case CPP_OPEN_BRACE
:
3702 add_stmt (c_parser_compound_statement (parser
));
3705 switch (c_parser_peek_token (parser
)->keyword
)
3708 c_parser_if_statement (parser
);
3711 c_parser_switch_statement (parser
);
3714 c_parser_while_statement (parser
);
3717 c_parser_do_statement (parser
);
3720 c_parser_for_statement (parser
);
3723 c_parser_consume_token (parser
);
3724 if (c_parser_next_token_is (parser
, CPP_NAME
))
3726 stmt
= c_finish_goto_label (c_parser_peek_token (parser
)->value
);
3727 c_parser_consume_token (parser
);
3729 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3731 c_parser_consume_token (parser
);
3732 stmt
= c_finish_goto_ptr (c_parser_expression (parser
).value
);
3735 c_parser_error (parser
, "expected identifier or %<*%>");
3736 goto expect_semicolon
;
3738 c_parser_consume_token (parser
);
3739 stmt
= c_finish_bc_stmt (&c_cont_label
, false);
3740 goto expect_semicolon
;
3742 c_parser_consume_token (parser
);
3743 stmt
= c_finish_bc_stmt (&c_break_label
, true);
3744 goto expect_semicolon
;
3746 c_parser_consume_token (parser
);
3747 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3749 stmt
= c_finish_return (NULL_TREE
);
3750 c_parser_consume_token (parser
);
3754 stmt
= c_finish_return (c_parser_expression_conv (parser
).value
);
3755 goto expect_semicolon
;
3759 stmt
= c_parser_asm_statement (parser
);
3762 gcc_assert (c_dialect_objc ());
3763 c_parser_consume_token (parser
);
3764 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3766 stmt
= objc_build_throw_stmt (NULL_TREE
);
3767 c_parser_consume_token (parser
);
3772 = objc_build_throw_stmt (c_parser_expression (parser
).value
);
3773 goto expect_semicolon
;
3777 gcc_assert (c_dialect_objc ());
3778 c_parser_objc_try_catch_statement (parser
);
3780 case RID_AT_SYNCHRONIZED
:
3781 gcc_assert (c_dialect_objc ());
3782 c_parser_objc_synchronized_statement (parser
);
3789 c_parser_consume_token (parser
);
3791 case CPP_CLOSE_PAREN
:
3792 case CPP_CLOSE_SQUARE
:
3793 /* Avoid infinite loop in error recovery:
3794 c_parser_skip_until_found stops at a closing nesting
3795 delimiter without consuming it, but here we need to consume
3796 it to proceed further. */
3797 c_parser_error (parser
, "expected statement");
3798 c_parser_consume_token (parser
);
3801 c_parser_pragma (parser
, pragma_stmt
);
3805 stmt
= c_finish_expr_stmt (c_parser_expression_conv (parser
).value
);
3807 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
3810 /* Two cases cannot and do not have line numbers associated: If stmt
3811 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
3812 cannot hold line numbers. But that's OK because the statement
3813 will either be changed to a MODIFY_EXPR during gimplification of
3814 the statement expr, or discarded. If stmt was compound, but
3815 without new variables, we will have skipped the creation of a
3816 BIND and will have a bare STATEMENT_LIST. But that's OK because
3817 (recursively) all of the component statements should already have
3818 line numbers assigned. ??? Can we discard no-op statements
3820 if (stmt
&& EXPR_P (stmt
))
3821 SET_EXPR_LOCATION (stmt
, loc
);
3824 /* Parse a parenthesized condition from an if, do or while statement.
3830 c_parser_paren_condition (c_parser
*parser
)
3834 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3835 return error_mark_node
;
3836 loc
= c_parser_peek_token (parser
)->location
;
3837 cond
= c_objc_common_truthvalue_conversion
3838 (c_parser_expression_conv (parser
).value
);
3840 SET_EXPR_LOCATION (cond
, loc
);
3841 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3845 /* Parse a statement which is a block in C99. */
3848 c_parser_c99_block_statement (c_parser
*parser
)
3850 tree block
= c_begin_compound_stmt (flag_isoc99
);
3851 c_parser_statement (parser
);
3852 return c_end_compound_stmt (block
, flag_isoc99
);
3855 /* Parse the body of an if statement or the else half thereof. This
3856 is just parsing a statement but (a) it is a block in C99, (b) we
3857 track whether the body is an if statement for the sake of
3858 -Wparentheses warnings, (c) we handle an empty body specially for
3859 the sake of -Wextra warnings. */
3862 c_parser_if_body (c_parser
*parser
, bool *if_p
)
3864 tree block
= c_begin_compound_stmt (flag_isoc99
);
3865 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
3866 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
3867 || (c_parser_next_token_is (parser
, CPP_NAME
)
3868 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
3869 c_parser_label (parser
);
3870 *if_p
= c_parser_next_token_is_keyword (parser
, RID_IF
);
3871 if (extra_warnings
&& c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3872 add_stmt (build_empty_stmt ());
3873 c_parser_statement_after_labels (parser
);
3874 return c_end_compound_stmt (block
, flag_isoc99
);
3877 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
3880 if ( expression ) statement
3881 if ( expression ) statement else statement
3885 c_parser_if_statement (c_parser
*parser
)
3890 bool first_if
= false, second_if
= false;
3891 tree first_body
, second_body
;
3892 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
3893 c_parser_consume_token (parser
);
3894 block
= c_begin_compound_stmt (flag_isoc99
);
3895 loc
= c_parser_peek_token (parser
)->location
;
3896 cond
= c_parser_paren_condition (parser
);
3897 first_body
= c_parser_if_body (parser
, &first_if
);
3898 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
3900 c_parser_consume_token (parser
);
3901 second_body
= c_parser_if_body (parser
, &second_if
);
3904 second_body
= NULL_TREE
;
3905 c_finish_if_stmt (loc
, cond
, first_body
, second_body
, first_if
);
3906 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3909 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
3912 switch (expression) statement
3916 c_parser_switch_statement (c_parser
*parser
)
3918 tree block
, expr
, body
, save_break
;
3919 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
3920 c_parser_consume_token (parser
);
3921 block
= c_begin_compound_stmt (flag_isoc99
);
3922 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3924 expr
= c_parser_expression (parser
).value
;
3925 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3928 expr
= error_mark_node
;
3929 c_start_case (expr
);
3930 save_break
= c_break_label
;
3931 c_break_label
= NULL_TREE
;
3932 body
= c_parser_c99_block_statement (parser
);
3933 c_finish_case (body
);
3935 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_break_label
));
3936 c_break_label
= save_break
;
3937 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3940 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
3943 while (expression) statement
3947 c_parser_while_statement (c_parser
*parser
)
3949 tree block
, cond
, body
, save_break
, save_cont
;
3951 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
3952 c_parser_consume_token (parser
);
3953 block
= c_begin_compound_stmt (flag_isoc99
);
3954 loc
= c_parser_peek_token (parser
)->location
;
3955 cond
= c_parser_paren_condition (parser
);
3956 save_break
= c_break_label
;
3957 c_break_label
= NULL_TREE
;
3958 save_cont
= c_cont_label
;
3959 c_cont_label
= NULL_TREE
;
3960 body
= c_parser_c99_block_statement (parser
);
3961 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
3962 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3963 c_break_label
= save_break
;
3964 c_cont_label
= save_cont
;
3967 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
3970 do statement while ( expression ) ;
3974 c_parser_do_statement (c_parser
*parser
)
3976 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
3978 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
3979 c_parser_consume_token (parser
);
3980 block
= c_begin_compound_stmt (flag_isoc99
);
3981 loc
= c_parser_peek_token (parser
)->location
;
3982 save_break
= c_break_label
;
3983 c_break_label
= NULL_TREE
;
3984 save_cont
= c_cont_label
;
3985 c_cont_label
= NULL_TREE
;
3986 body
= c_parser_c99_block_statement (parser
);
3987 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
3988 new_break
= c_break_label
;
3989 c_break_label
= save_break
;
3990 new_cont
= c_cont_label
;
3991 c_cont_label
= save_cont
;
3992 cond
= c_parser_paren_condition (parser
);
3993 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
3994 c_parser_skip_to_end_of_block_or_statement (parser
);
3995 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
3996 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
3999 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
4002 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
4003 for ( nested-declaration expression[opt] ; expression[opt] ) statement
4005 The form with a declaration is new in C99.
4007 ??? In accordance with the old parser, the declaration may be a
4008 nested function, which is then rejected in check_for_loop_decls,
4009 but does it make any sense for this to be included in the grammar?
4010 Note in particular that the nested function does not include a
4011 trailing ';', whereas the "declaration" production includes one.
4012 Also, can we reject bad declarations earlier and cheaper than
4013 check_for_loop_decls? */
4016 c_parser_for_statement (c_parser
*parser
)
4018 tree block
, cond
, incr
, save_break
, save_cont
, body
;
4020 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
4021 loc
= c_parser_peek_token (parser
)->location
;
4022 c_parser_consume_token (parser
);
4023 block
= c_begin_compound_stmt (flag_isoc99
);
4024 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4026 /* Parse the initialization declaration or expression. */
4027 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4029 c_parser_consume_token (parser
);
4030 c_finish_expr_stmt (NULL_TREE
);
4032 else if (c_parser_next_token_starts_declspecs (parser
))
4034 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4035 check_for_loop_decls ();
4037 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4039 /* __extension__ can start a declaration, but is also an
4040 unary operator that can start an expression. Consume all
4041 but the last of a possible series of __extension__ to
4043 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4044 && (c_parser_peek_2nd_token (parser
)->keyword
4046 c_parser_consume_token (parser
);
4047 if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser
)))
4050 ext
= disable_extension_diagnostics ();
4051 c_parser_consume_token (parser
);
4052 c_parser_declaration_or_fndef (parser
, true, true, true, true);
4053 restore_extension_diagnostics (ext
);
4054 check_for_loop_decls ();
4062 c_finish_expr_stmt (c_parser_expression (parser
).value
);
4063 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4065 /* Parse the loop condition. */
4066 loc
= c_parser_peek_token (parser
)->location
;
4067 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4069 c_parser_consume_token (parser
);
4074 tree ocond
= c_parser_expression_conv (parser
).value
;
4075 cond
= c_objc_common_truthvalue_conversion (ocond
);
4077 SET_EXPR_LOCATION (cond
, loc
);
4078 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4080 /* Parse the increment expression. */
4081 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4082 incr
= c_process_expr_stmt (NULL_TREE
);
4084 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
4085 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4089 cond
= error_mark_node
;
4090 incr
= error_mark_node
;
4092 save_break
= c_break_label
;
4093 c_break_label
= NULL_TREE
;
4094 save_cont
= c_cont_label
;
4095 c_cont_label
= NULL_TREE
;
4096 body
= c_parser_c99_block_statement (parser
);
4097 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
4098 add_stmt (c_end_compound_stmt (block
, flag_isoc99
));
4099 c_break_label
= save_break
;
4100 c_cont_label
= save_cont
;
4103 /* Parse an asm statement, a GNU extension. This is a full-blown asm
4104 statement with inputs, outputs, clobbers, and volatile tag
4108 asm type-qualifier[opt] ( asm-argument ) ;
4112 asm-string-literal : asm-operands[opt]
4113 asm-string-literal : asm-operands[opt] : asm-operands[opt]
4114 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers
4116 Qualifiers other than volatile are accepted in the syntax but
4120 c_parser_asm_statement (c_parser
*parser
)
4122 tree quals
, str
, outputs
, inputs
, clobbers
, ret
;
4124 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4125 c_parser_consume_token (parser
);
4126 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
4128 quals
= c_parser_peek_token (parser
)->value
;
4129 c_parser_consume_token (parser
);
4131 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
4132 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
4134 warning (0, "%E qualifier ignored on asm",
4135 c_parser_peek_token (parser
)->value
);
4137 c_parser_consume_token (parser
);
4141 /* ??? Follow the C++ parser rather than using the
4142 c_lex_string_translate kludge. */
4143 c_lex_string_translate
= 0;
4144 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4146 c_lex_string_translate
= 1;
4149 str
= c_parser_asm_string_literal (parser
);
4150 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4153 outputs
= NULL_TREE
;
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 /* Parse outputs. */
4166 if (c_parser_next_token_is (parser
, CPP_COLON
)
4167 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4168 outputs
= NULL_TREE
;
4170 outputs
= c_parser_asm_operands (parser
, false);
4171 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4174 clobbers
= NULL_TREE
;
4177 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4179 c_lex_string_translate
= 1;
4180 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4184 if (c_parser_next_token_is (parser
, CPP_COLON
)
4185 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4188 inputs
= c_parser_asm_operands (parser
, true);
4189 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4191 clobbers
= NULL_TREE
;
4194 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%> or %<)%>"))
4196 c_lex_string_translate
= 1;
4197 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4200 /* Parse clobbers. */
4201 clobbers
= c_parser_asm_clobbers (parser
);
4203 c_lex_string_translate
= 1;
4204 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4206 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4209 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
4210 c_parser_skip_to_end_of_block_or_statement (parser
);
4211 ret
= build_asm_stmt (quals
, build_asm_expr (str
, outputs
, inputs
,
4216 /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but
4217 not outputs), apply the default conversion of functions and arrays
4222 asm-operands , asm-operand
4225 asm-string-literal ( expression )
4226 [ identifier ] asm-string-literal ( expression )
4230 c_parser_asm_operands (c_parser
*parser
, bool convert_p
)
4232 tree list
= NULL_TREE
;
4237 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
4239 c_parser_consume_token (parser
);
4240 if (c_parser_next_token_is (parser
, CPP_NAME
))
4242 tree id
= c_parser_peek_token (parser
)->value
;
4243 c_parser_consume_token (parser
);
4244 name
= build_string (IDENTIFIER_LENGTH (id
),
4245 IDENTIFIER_POINTER (id
));
4249 c_parser_error (parser
, "expected identifier");
4250 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
4253 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4258 str
= c_parser_asm_string_literal (parser
);
4259 if (str
== NULL_TREE
)
4261 c_lex_string_translate
= 1;
4262 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4264 c_lex_string_translate
= 0;
4267 expr
= c_parser_expression (parser
);
4269 expr
= default_function_array_conversion (expr
);
4270 c_lex_string_translate
= 0;
4271 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
4273 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4276 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
4278 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4279 c_parser_consume_token (parser
);
4286 /* Parse asm clobbers, a GNU extension.
4290 asm-clobbers , asm-string-literal
4294 c_parser_asm_clobbers (c_parser
*parser
)
4296 tree list
= NULL_TREE
;
4299 tree str
= c_parser_asm_string_literal (parser
);
4301 list
= tree_cons (NULL_TREE
, str
, list
);
4304 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4305 c_parser_consume_token (parser
);
4312 /* Parse an expression other than a compound expression; that is, an
4313 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
4314 NULL then it is an Objective-C message expression which is the
4315 primary-expression starting the expression as an initializer.
4317 assignment-expression:
4318 conditional-expression
4319 unary-expression assignment-operator assignment-expression
4321 assignment-operator: one of
4322 = *= /= %= += -= <<= >>= &= ^= |=
4324 In GNU C we accept any conditional expression on the LHS and
4325 diagnose the invalid lvalue rather than producing a syntax
4328 static struct c_expr
4329 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
)
4331 struct c_expr lhs
, rhs
, ret
;
4332 enum tree_code code
;
4333 gcc_assert (!after
|| c_dialect_objc ());
4334 lhs
= c_parser_conditional_expression (parser
, after
);
4335 switch (c_parser_peek_token (parser
)->type
)
4344 code
= TRUNC_DIV_EXPR
;
4347 code
= TRUNC_MOD_EXPR
;
4362 code
= BIT_AND_EXPR
;
4365 code
= BIT_XOR_EXPR
;
4368 code
= BIT_IOR_EXPR
;
4373 c_parser_consume_token (parser
);
4374 rhs
= c_parser_expr_no_commas (parser
, NULL
);
4375 rhs
= default_function_array_conversion (rhs
);
4376 ret
.value
= build_modify_expr (lhs
.value
, code
, rhs
.value
);
4377 if (code
== NOP_EXPR
)
4378 ret
.original_code
= MODIFY_EXPR
;
4381 TREE_NO_WARNING (ret
.value
) = 1;
4382 ret
.original_code
= ERROR_MARK
;
4387 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
4388 is not NULL then it is an Objective-C message expression which is
4389 the primary-expression starting the expression as an initializer.
4391 conditional-expression:
4392 logical-OR-expression
4393 logical-OR-expression ? expression : conditional-expression
4397 conditional-expression:
4398 logical-OR-expression ? : conditional-expression
4401 static struct c_expr
4402 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
)
4404 struct c_expr cond
, exp1
, exp2
, ret
;
4405 gcc_assert (!after
|| c_dialect_objc ());
4406 cond
= c_parser_binary_expression (parser
, after
);
4407 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
4409 cond
= default_function_array_conversion (cond
);
4410 c_parser_consume_token (parser
);
4411 if (c_parser_next_token_is (parser
, CPP_COLON
))
4414 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
4415 /* Make sure first operand is calculated only once. */
4416 exp1
.value
= save_expr (default_conversion (cond
.value
));
4417 cond
.value
= c_objc_common_truthvalue_conversion (exp1
.value
);
4418 skip_evaluation
+= cond
.value
== truthvalue_true_node
;
4423 = c_objc_common_truthvalue_conversion
4424 (default_conversion (cond
.value
));
4425 skip_evaluation
+= cond
.value
== truthvalue_false_node
;
4426 exp1
= c_parser_expression_conv (parser
);
4427 skip_evaluation
+= ((cond
.value
== truthvalue_true_node
)
4428 - (cond
.value
== truthvalue_false_node
));
4430 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4432 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4433 ret
.value
= error_mark_node
;
4434 ret
.original_code
= ERROR_MARK
;
4437 exp2
= c_parser_conditional_expression (parser
, NULL
);
4438 exp2
= default_function_array_conversion (exp2
);
4439 skip_evaluation
-= cond
.value
== truthvalue_true_node
;
4440 ret
.value
= build_conditional_expr (cond
.value
, exp1
.value
, exp2
.value
);
4441 ret
.original_code
= ERROR_MARK
;
4445 /* Parse a binary expression; that is, a logical-OR-expression (C90
4446 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
4447 an Objective-C message expression which is the primary-expression
4448 starting the expression as an initializer.
4450 multiplicative-expression:
4452 multiplicative-expression * cast-expression
4453 multiplicative-expression / cast-expression
4454 multiplicative-expression % cast-expression
4456 additive-expression:
4457 multiplicative-expression
4458 additive-expression + multiplicative-expression
4459 additive-expression - multiplicative-expression
4463 shift-expression << additive-expression
4464 shift-expression >> additive-expression
4466 relational-expression:
4468 relational-expression < shift-expression
4469 relational-expression > shift-expression
4470 relational-expression <= shift-expression
4471 relational-expression >= shift-expression
4473 equality-expression:
4474 relational-expression
4475 equality-expression == relational-expression
4476 equality-expression != relational-expression
4480 AND-expression & equality-expression
4482 exclusive-OR-expression:
4484 exclusive-OR-expression ^ AND-expression
4486 inclusive-OR-expression:
4487 exclusive-OR-expression
4488 inclusive-OR-expression | exclusive-OR-expression
4490 logical-AND-expression:
4491 inclusive-OR-expression
4492 logical-AND-expression && inclusive-OR-expression
4494 logical-OR-expression:
4495 logical-AND-expression
4496 logical-OR-expression || logical-AND-expression
4499 static struct c_expr
4500 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
)
4502 /* A binary expression is parsed using operator-precedence parsing,
4503 with the operands being cast expressions. All the binary
4504 operators are left-associative. Thus a binary expression is of
4507 E0 op1 E1 op2 E2 ...
4509 which we represent on a stack. On the stack, the precedence
4510 levels are strictly increasing. When a new operator is
4511 encountered of higher precedence than that at the top of the
4512 stack, it is pushed; its LHS is the top expression, and its RHS
4513 is everything parsed until it is popped. When a new operator is
4514 encountered with precedence less than or equal to that at the top
4515 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
4516 by the result of the operation until the operator at the top of
4517 the stack has lower precedence than the new operator or there is
4518 only one element on the stack; then the top expression is the LHS
4519 of the new operator. In the case of logical AND and OR
4520 expressions, we also need to adjust skip_evaluation as
4521 appropriate when the operators are pushed and popped. */
4523 /* The precedence levels, where 0 is a dummy lowest level used for
4524 the bottom of the stack. */
4540 /* The expression at this stack level. */
4542 /* The precedence of the operator on its left, PREC_NONE at the
4543 bottom of the stack. */
4545 /* The operation on its left. */
4551 switch (stack[sp].op) \
4553 case TRUTH_ANDIF_EXPR: \
4554 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
4556 case TRUTH_ORIF_EXPR: \
4557 skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
4562 stack[sp - 1].expr \
4563 = default_function_array_conversion (stack[sp - 1].expr); \
4565 = default_function_array_conversion (stack[sp].expr); \
4566 stack[sp - 1].expr = parser_build_binary_op (stack[sp].op, \
4567 stack[sp - 1].expr, \
4571 gcc_assert (!after
|| c_dialect_objc ());
4572 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
4573 stack
[0].prec
= PREC_NONE
;
4578 enum tree_code ocode
;
4581 switch (c_parser_peek_token (parser
)->type
)
4589 ocode
= TRUNC_DIV_EXPR
;
4593 ocode
= TRUNC_MOD_EXPR
;
4605 ocode
= LSHIFT_EXPR
;
4609 ocode
= RSHIFT_EXPR
;
4623 case CPP_GREATER_EQ
:
4636 oprec
= PREC_BITAND
;
4637 ocode
= BIT_AND_EXPR
;
4640 oprec
= PREC_BITXOR
;
4641 ocode
= BIT_XOR_EXPR
;
4645 ocode
= BIT_IOR_EXPR
;
4648 oprec
= PREC_LOGAND
;
4649 ocode
= TRUTH_ANDIF_EXPR
;
4653 ocode
= TRUTH_ORIF_EXPR
;
4656 /* Not a binary operator, so end of the binary
4660 c_parser_consume_token (parser
);
4661 while (oprec
<= stack
[sp
].prec
)
4665 case TRUTH_ANDIF_EXPR
:
4667 = default_function_array_conversion (stack
[sp
].expr
);
4668 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4669 (default_conversion (stack
[sp
].expr
.value
));
4670 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_false_node
;
4672 case TRUTH_ORIF_EXPR
:
4674 = default_function_array_conversion (stack
[sp
].expr
);
4675 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
4676 (default_conversion (stack
[sp
].expr
.value
));
4677 skip_evaluation
+= stack
[sp
].expr
.value
== truthvalue_true_node
;
4683 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
4684 stack
[sp
].prec
= oprec
;
4685 stack
[sp
].op
= ocode
;
4690 return stack
[0].expr
;
4694 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
4695 NULL then it is an Objective-C message expression which is the
4696 primary-expression starting the expression as an initializer.
4700 ( type-name ) unary-expression
4703 static struct c_expr
4704 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
4706 gcc_assert (!after
|| c_dialect_objc ());
4708 return c_parser_postfix_expression_after_primary (parser
, *after
);
4709 /* If the expression begins with a parenthesized type name, it may
4710 be either a cast or a compound literal; we need to see whether
4711 the next character is '{' to tell the difference. If not, it is
4712 an unary expression. */
4713 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4714 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4716 struct c_type_name
*type_name
;
4719 c_parser_consume_token (parser
);
4720 type_name
= c_parser_type_name (parser
);
4721 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4722 if (type_name
== NULL
)
4724 ret
.value
= error_mark_node
;
4725 ret
.original_code
= ERROR_MARK
;
4729 /* Save casted types in the function's used types hash table. */
4730 used_types_insert (type_name
->specs
->type
);
4732 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4733 return c_parser_postfix_expression_after_paren_type (parser
,
4735 expr
= c_parser_cast_expression (parser
, NULL
);
4736 expr
= default_function_array_conversion (expr
);
4737 ret
.value
= c_cast_expr (type_name
, expr
.value
);
4738 ret
.original_code
= ERROR_MARK
;
4742 return c_parser_unary_expression (parser
);
4745 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
4751 unary-operator cast-expression
4752 sizeof unary-expression
4753 sizeof ( type-name )
4755 unary-operator: one of
4761 __alignof__ unary-expression
4762 __alignof__ ( type-name )
4765 unary-operator: one of
4766 __extension__ __real__ __imag__
4768 In addition, the GNU syntax treats ++ and -- as unary operators, so
4769 they may be applied to cast expressions with errors for non-lvalues
4772 static struct c_expr
4773 c_parser_unary_expression (c_parser
*parser
)
4776 struct c_expr ret
, op
;
4777 switch (c_parser_peek_token (parser
)->type
)
4780 c_parser_consume_token (parser
);
4781 op
= c_parser_cast_expression (parser
, NULL
);
4782 op
= default_function_array_conversion (op
);
4783 return parser_build_unary_op (PREINCREMENT_EXPR
, op
);
4784 case CPP_MINUS_MINUS
:
4785 c_parser_consume_token (parser
);
4786 op
= c_parser_cast_expression (parser
, NULL
);
4787 op
= default_function_array_conversion (op
);
4788 return parser_build_unary_op (PREDECREMENT_EXPR
, op
);
4790 c_parser_consume_token (parser
);
4791 return parser_build_unary_op (ADDR_EXPR
,
4792 c_parser_cast_expression (parser
, NULL
));
4794 c_parser_consume_token (parser
);
4795 op
= c_parser_cast_expression (parser
, NULL
);
4796 op
= default_function_array_conversion (op
);
4797 ret
.value
= build_indirect_ref (op
.value
, "unary *");
4798 ret
.original_code
= ERROR_MARK
;
4801 c_parser_consume_token (parser
);
4802 if (!c_dialect_objc () && !in_system_header
)
4803 warning (OPT_Wtraditional
,
4804 "traditional C rejects the unary plus operator");
4805 op
= c_parser_cast_expression (parser
, NULL
);
4806 op
= default_function_array_conversion (op
);
4807 return parser_build_unary_op (CONVERT_EXPR
, op
);
4809 c_parser_consume_token (parser
);
4810 op
= c_parser_cast_expression (parser
, NULL
);
4811 op
= default_function_array_conversion (op
);
4812 return parser_build_unary_op (NEGATE_EXPR
, op
);
4814 c_parser_consume_token (parser
);
4815 op
= c_parser_cast_expression (parser
, NULL
);
4816 op
= default_function_array_conversion (op
);
4817 return parser_build_unary_op (BIT_NOT_EXPR
, op
);
4819 c_parser_consume_token (parser
);
4820 op
= c_parser_cast_expression (parser
, NULL
);
4821 op
= default_function_array_conversion (op
);
4822 return parser_build_unary_op (TRUTH_NOT_EXPR
, op
);
4824 /* Refer to the address of a label as a pointer. */
4825 c_parser_consume_token (parser
);
4826 if (c_parser_next_token_is (parser
, CPP_NAME
))
4828 ret
.value
= finish_label_address_expr
4829 (c_parser_peek_token (parser
)->value
);
4830 c_parser_consume_token (parser
);
4834 c_parser_error (parser
, "expected identifier");
4835 ret
.value
= error_mark_node
;
4837 ret
.original_code
= ERROR_MARK
;
4840 switch (c_parser_peek_token (parser
)->keyword
)
4843 return c_parser_sizeof_expression (parser
);
4845 return c_parser_alignof_expression (parser
);
4847 c_parser_consume_token (parser
);
4848 ext
= disable_extension_diagnostics ();
4849 ret
= c_parser_cast_expression (parser
, NULL
);
4850 restore_extension_diagnostics (ext
);
4853 c_parser_consume_token (parser
);
4854 op
= c_parser_cast_expression (parser
, NULL
);
4855 op
= default_function_array_conversion (op
);
4856 return parser_build_unary_op (REALPART_EXPR
, op
);
4858 c_parser_consume_token (parser
);
4859 op
= c_parser_cast_expression (parser
, NULL
);
4860 op
= default_function_array_conversion (op
);
4861 return parser_build_unary_op (IMAGPART_EXPR
, op
);
4863 return c_parser_postfix_expression (parser
);
4866 return c_parser_postfix_expression (parser
);
4870 /* Parse a sizeof expression. */
4872 static struct c_expr
4873 c_parser_sizeof_expression (c_parser
*parser
)
4876 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
4877 c_parser_consume_token (parser
);
4880 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4881 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4883 /* Either sizeof ( type-name ) or sizeof unary-expression
4884 starting with a compound literal. */
4885 struct c_type_name
*type_name
;
4886 c_parser_consume_token (parser
);
4887 type_name
= c_parser_type_name (parser
);
4888 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4889 if (type_name
== NULL
)
4894 ret
.value
= error_mark_node
;
4895 ret
.original_code
= ERROR_MARK
;
4898 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4900 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4904 /* sizeof ( type-name ). */
4907 if (type_name
->declarator
->kind
== cdk_array
4908 && type_name
->declarator
->u
.array
.vla_unspec_p
)
4911 error ("%<[*]%> not allowed in other than a declaration");
4913 return c_expr_sizeof_type (type_name
);
4917 expr
= c_parser_unary_expression (parser
);
4921 if (TREE_CODE (expr
.value
) == COMPONENT_REF
4922 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
4923 error ("%<sizeof%> applied to a bit-field");
4924 return c_expr_sizeof_expr (expr
);
4928 /* Parse an alignof expression. */
4930 static struct c_expr
4931 c_parser_alignof_expression (c_parser
*parser
)
4934 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
4935 c_parser_consume_token (parser
);
4938 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
4939 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
4941 /* Either __alignof__ ( type-name ) or __alignof__
4942 unary-expression starting with a compound literal. */
4943 struct c_type_name
*type_name
;
4945 c_parser_consume_token (parser
);
4946 type_name
= c_parser_type_name (parser
);
4947 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
4948 if (type_name
== NULL
)
4953 ret
.value
= error_mark_node
;
4954 ret
.original_code
= ERROR_MARK
;
4957 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4959 expr
= c_parser_postfix_expression_after_paren_type (parser
,
4963 /* alignof ( type-name ). */
4966 ret
.value
= c_alignof (groktypename (type_name
));
4967 ret
.original_code
= ERROR_MARK
;
4973 expr
= c_parser_unary_expression (parser
);
4977 ret
.value
= c_alignof_expr (expr
.value
);
4978 ret
.original_code
= ERROR_MARK
;
4983 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
4987 postfix-expression [ expression ]
4988 postfix-expression ( argument-expression-list[opt] )
4989 postfix-expression . identifier
4990 postfix-expression -> identifier
4991 postfix-expression ++
4992 postfix-expression --
4993 ( type-name ) { initializer-list }
4994 ( type-name ) { initializer-list , }
4996 argument-expression-list:
4998 argument-expression-list , argument-expression
5010 (treated as a keyword in GNU C)
5013 ( compound-statement )
5014 __builtin_va_arg ( assignment-expression , type-name )
5015 __builtin_offsetof ( type-name , offsetof-member-designator )
5016 __builtin_choose_expr ( assignment-expression ,
5017 assignment-expression ,
5018 assignment-expression )
5019 __builtin_types_compatible_p ( type-name , type-name )
5021 offsetof-member-designator:
5023 offsetof-member-designator . identifier
5024 offsetof-member-designator [ expression ]
5029 [ objc-receiver objc-message-args ]
5030 @selector ( objc-selector-arg )
5031 @protocol ( identifier )
5032 @encode ( type-name )
5036 static struct c_expr
5037 c_parser_postfix_expression (c_parser
*parser
)
5039 struct c_expr expr
, e1
, e2
, e3
;
5040 struct c_type_name
*t1
, *t2
;
5041 switch (c_parser_peek_token (parser
)->type
)
5046 expr
.value
= c_parser_peek_token (parser
)->value
;
5047 expr
.original_code
= ERROR_MARK
;
5048 c_parser_consume_token (parser
);
5052 expr
.value
= c_parser_peek_token (parser
)->value
;
5053 expr
.original_code
= STRING_CST
;
5054 c_parser_consume_token (parser
);
5056 case CPP_OBJC_STRING
:
5057 gcc_assert (c_dialect_objc ());
5059 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
5060 expr
.original_code
= ERROR_MARK
;
5061 c_parser_consume_token (parser
);
5064 if (c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
5066 c_parser_error (parser
, "expected expression");
5067 expr
.value
= error_mark_node
;
5068 expr
.original_code
= ERROR_MARK
;
5072 tree id
= c_parser_peek_token (parser
)->value
;
5073 location_t loc
= c_parser_peek_token (parser
)->location
;
5074 c_parser_consume_token (parser
);
5075 expr
.value
= build_external_ref (id
,
5076 (c_parser_peek_token (parser
)->type
5077 == CPP_OPEN_PAREN
), loc
);
5078 expr
.original_code
= ERROR_MARK
;
5081 case CPP_OPEN_PAREN
:
5082 /* A parenthesized expression, statement expression or compound
5084 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
5086 /* A statement expression. */
5088 c_parser_consume_token (parser
);
5089 c_parser_consume_token (parser
);
5090 if (cur_stmt_list
== NULL
)
5092 error ("braced-group within expression allowed "
5093 "only inside a function");
5094 parser
->error
= true;
5095 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
5096 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5097 expr
.value
= error_mark_node
;
5098 expr
.original_code
= ERROR_MARK
;
5101 stmt
= c_begin_stmt_expr ();
5102 c_parser_compound_statement_nostart (parser
);
5103 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5106 pedwarn ("ISO C forbids braced-groups within expressions");
5107 expr
.value
= c_finish_stmt_expr (stmt
);
5108 expr
.original_code
= ERROR_MARK
;
5110 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5112 /* A compound literal. ??? Can we actually get here rather
5113 than going directly to
5114 c_parser_postfix_expression_after_paren_type from
5116 struct c_type_name
*type_name
;
5117 c_parser_consume_token (parser
);
5118 type_name
= c_parser_type_name (parser
);
5119 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5121 if (type_name
== NULL
)
5123 expr
.value
= error_mark_node
;
5124 expr
.original_code
= ERROR_MARK
;
5127 expr
= c_parser_postfix_expression_after_paren_type (parser
,
5132 /* A parenthesized expression. */
5133 c_parser_consume_token (parser
);
5134 expr
= c_parser_expression (parser
);
5135 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
5136 TREE_NO_WARNING (expr
.value
) = 1;
5137 expr
.original_code
= ERROR_MARK
;
5138 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5143 switch (c_parser_peek_token (parser
)->keyword
)
5145 case RID_FUNCTION_NAME
:
5146 case RID_PRETTY_FUNCTION_NAME
:
5147 case RID_C99_FUNCTION_NAME
:
5148 expr
.value
= fname_decl (c_parser_peek_token (parser
)->keyword
,
5149 c_parser_peek_token (parser
)->value
);
5150 expr
.original_code
= ERROR_MARK
;
5151 c_parser_consume_token (parser
);
5154 c_parser_consume_token (parser
);
5155 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5157 expr
.value
= error_mark_node
;
5158 expr
.original_code
= ERROR_MARK
;
5161 e1
= c_parser_expr_no_commas (parser
, NULL
);
5162 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5164 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5165 expr
.value
= error_mark_node
;
5166 expr
.original_code
= ERROR_MARK
;
5169 t1
= c_parser_type_name (parser
);
5170 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5174 expr
.value
= error_mark_node
;
5175 expr
.original_code
= ERROR_MARK
;
5179 expr
.value
= build_va_arg (e1
.value
, groktypename (t1
));
5180 expr
.original_code
= ERROR_MARK
;
5184 c_parser_consume_token (parser
);
5185 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5187 expr
.value
= error_mark_node
;
5188 expr
.original_code
= ERROR_MARK
;
5191 t1
= c_parser_type_name (parser
);
5194 expr
.value
= error_mark_node
;
5195 expr
.original_code
= ERROR_MARK
;
5198 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5200 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5201 expr
.value
= error_mark_node
;
5202 expr
.original_code
= ERROR_MARK
;
5206 tree type
= groktypename (t1
);
5208 if (type
== error_mark_node
)
5209 offsetof_ref
= error_mark_node
;
5211 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
5212 /* Parse the second argument to __builtin_offsetof. We
5213 must have one identifier, and beyond that we want to
5214 accept sub structure and sub array references. */
5215 if (c_parser_next_token_is (parser
, CPP_NAME
))
5217 offsetof_ref
= build_component_ref
5218 (offsetof_ref
, c_parser_peek_token (parser
)->value
);
5219 c_parser_consume_token (parser
);
5220 while (c_parser_next_token_is (parser
, CPP_DOT
)
5221 || c_parser_next_token_is (parser
,
5224 if (c_parser_next_token_is (parser
, CPP_DOT
))
5226 c_parser_consume_token (parser
);
5227 if (c_parser_next_token_is_not (parser
,
5230 c_parser_error (parser
, "expected identifier");
5233 offsetof_ref
= build_component_ref
5235 c_parser_peek_token (parser
)->value
);
5236 c_parser_consume_token (parser
);
5241 c_parser_consume_token (parser
);
5242 idx
= c_parser_expression (parser
).value
;
5243 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5245 offsetof_ref
= build_array_ref (offsetof_ref
, idx
);
5250 c_parser_error (parser
, "expected identifier");
5251 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5253 expr
.value
= fold_offsetof (offsetof_ref
, NULL_TREE
);
5254 expr
.original_code
= ERROR_MARK
;
5257 case RID_CHOOSE_EXPR
:
5258 c_parser_consume_token (parser
);
5259 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5261 expr
.value
= error_mark_node
;
5262 expr
.original_code
= ERROR_MARK
;
5265 e1
= c_parser_expr_no_commas (parser
, NULL
);
5266 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5268 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5269 expr
.value
= error_mark_node
;
5270 expr
.original_code
= ERROR_MARK
;
5273 e2
= c_parser_expr_no_commas (parser
, NULL
);
5274 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5276 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5277 expr
.value
= error_mark_node
;
5278 expr
.original_code
= ERROR_MARK
;
5281 e3
= c_parser_expr_no_commas (parser
, NULL
);
5282 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5287 c
= fold (e1
.value
);
5288 if (TREE_CODE (c
) != INTEGER_CST
)
5289 error ("first argument to %<__builtin_choose_expr%> not"
5291 expr
= integer_zerop (c
) ? e3
: e2
;
5294 case RID_TYPES_COMPATIBLE_P
:
5295 c_parser_consume_token (parser
);
5296 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5298 expr
.value
= error_mark_node
;
5299 expr
.original_code
= ERROR_MARK
;
5302 t1
= c_parser_type_name (parser
);
5305 expr
.value
= error_mark_node
;
5306 expr
.original_code
= ERROR_MARK
;
5309 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
5311 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5312 expr
.value
= error_mark_node
;
5313 expr
.original_code
= ERROR_MARK
;
5316 t2
= c_parser_type_name (parser
);
5319 expr
.value
= error_mark_node
;
5320 expr
.original_code
= ERROR_MARK
;
5323 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5328 e1
= TYPE_MAIN_VARIANT (groktypename (t1
));
5329 e2
= TYPE_MAIN_VARIANT (groktypename (t2
));
5331 expr
.value
= comptypes (e1
, e2
)
5332 ? build_int_cst (NULL_TREE
, 1)
5333 : build_int_cst (NULL_TREE
, 0);
5334 expr
.original_code
= ERROR_MARK
;
5337 case RID_AT_SELECTOR
:
5338 gcc_assert (c_dialect_objc ());
5339 c_parser_consume_token (parser
);
5340 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5342 expr
.value
= error_mark_node
;
5343 expr
.original_code
= ERROR_MARK
;
5347 tree sel
= c_parser_objc_selector_arg (parser
);
5348 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5350 expr
.value
= objc_build_selector_expr (sel
);
5351 expr
.original_code
= ERROR_MARK
;
5354 case RID_AT_PROTOCOL
:
5355 gcc_assert (c_dialect_objc ());
5356 c_parser_consume_token (parser
);
5357 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5359 expr
.value
= error_mark_node
;
5360 expr
.original_code
= ERROR_MARK
;
5363 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5365 c_parser_error (parser
, "expected identifier");
5366 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5367 expr
.value
= error_mark_node
;
5368 expr
.original_code
= ERROR_MARK
;
5372 tree id
= c_parser_peek_token (parser
)->value
;
5373 c_parser_consume_token (parser
);
5374 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5376 expr
.value
= objc_build_protocol_expr (id
);
5377 expr
.original_code
= ERROR_MARK
;
5381 /* Extension to support C-structures in the archiver. */
5382 gcc_assert (c_dialect_objc ());
5383 c_parser_consume_token (parser
);
5384 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5386 expr
.value
= error_mark_node
;
5387 expr
.original_code
= ERROR_MARK
;
5390 t1
= c_parser_type_name (parser
);
5393 expr
.value
= error_mark_node
;
5394 expr
.original_code
= ERROR_MARK
;
5395 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5398 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5401 tree type
= groktypename (t1
);
5402 expr
.value
= objc_build_encode_expr (type
);
5403 expr
.original_code
= ERROR_MARK
;
5407 c_parser_error (parser
, "expected expression");
5408 expr
.value
= error_mark_node
;
5409 expr
.original_code
= ERROR_MARK
;
5413 case CPP_OPEN_SQUARE
:
5414 if (c_dialect_objc ())
5416 tree receiver
, args
;
5417 c_parser_consume_token (parser
);
5418 receiver
= c_parser_objc_receiver (parser
);
5419 args
= c_parser_objc_message_args (parser
);
5420 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5422 expr
.value
= objc_build_message_expr (build_tree_list (receiver
,
5424 expr
.original_code
= ERROR_MARK
;
5427 /* Else fall through to report error. */
5429 c_parser_error (parser
, "expected expression");
5430 expr
.value
= error_mark_node
;
5431 expr
.original_code
= ERROR_MARK
;
5434 return c_parser_postfix_expression_after_primary (parser
, expr
);
5437 /* Parse a postfix expression after a parenthesized type name: the
5438 brace-enclosed initializer of a compound literal, possibly followed
5439 by some postfix operators. This is separate because it is not
5440 possible to tell until after the type name whether a cast
5441 expression has a cast or a compound literal, or whether the operand
5442 of sizeof is a parenthesized type name or starts with a compound
5445 static struct c_expr
5446 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
5447 struct c_type_name
*type_name
)
5452 start_init (NULL_TREE
, NULL
, 0);
5453 type
= groktypename (type_name
);
5454 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
5456 error ("compound literal has variable size");
5457 type
= error_mark_node
;
5459 init
= c_parser_braced_init (parser
, type
, false);
5461 maybe_warn_string_init (type
, init
);
5463 if (pedantic
&& !flag_isoc99
)
5464 pedwarn ("ISO C90 forbids compound literals");
5465 expr
.value
= build_compound_literal (type
, init
.value
);
5466 expr
.original_code
= ERROR_MARK
;
5467 return c_parser_postfix_expression_after_primary (parser
, expr
);
5470 /* Parse a postfix expression after the initial primary or compound
5471 literal; that is, parse a series of postfix operators. */
5473 static struct c_expr
5474 c_parser_postfix_expression_after_primary (c_parser
*parser
,
5477 tree ident
, idx
, exprlist
;
5480 switch (c_parser_peek_token (parser
)->type
)
5482 case CPP_OPEN_SQUARE
:
5483 /* Array reference. */
5484 c_parser_consume_token (parser
);
5485 idx
= c_parser_expression (parser
).value
;
5486 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
5488 expr
.value
= build_array_ref (expr
.value
, idx
);
5489 expr
.original_code
= ERROR_MARK
;
5491 case CPP_OPEN_PAREN
:
5492 /* Function call. */
5493 c_parser_consume_token (parser
);
5494 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5495 exprlist
= NULL_TREE
;
5497 exprlist
= c_parser_expr_list (parser
, true);
5498 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
5500 expr
.value
= build_function_call (expr
.value
, exprlist
);
5501 expr
.original_code
= ERROR_MARK
;
5504 /* Structure element reference. */
5505 c_parser_consume_token (parser
);
5506 expr
= default_function_array_conversion (expr
);
5507 if (c_parser_next_token_is (parser
, CPP_NAME
))
5508 ident
= c_parser_peek_token (parser
)->value
;
5511 c_parser_error (parser
, "expected identifier");
5512 expr
.value
= error_mark_node
;
5513 expr
.original_code
= ERROR_MARK
;
5516 c_parser_consume_token (parser
);
5517 expr
.value
= build_component_ref (expr
.value
, ident
);
5518 expr
.original_code
= ERROR_MARK
;
5521 /* Structure element reference. */
5522 c_parser_consume_token (parser
);
5523 expr
= default_function_array_conversion (expr
);
5524 if (c_parser_next_token_is (parser
, CPP_NAME
))
5525 ident
= c_parser_peek_token (parser
)->value
;
5528 c_parser_error (parser
, "expected identifier");
5529 expr
.value
= error_mark_node
;
5530 expr
.original_code
= ERROR_MARK
;
5533 c_parser_consume_token (parser
);
5534 expr
.value
= build_component_ref (build_indirect_ref (expr
.value
,
5536 expr
.original_code
= ERROR_MARK
;
5539 /* Postincrement. */
5540 c_parser_consume_token (parser
);
5541 expr
= default_function_array_conversion (expr
);
5542 expr
.value
= build_unary_op (POSTINCREMENT_EXPR
, expr
.value
, 0);
5543 expr
.original_code
= ERROR_MARK
;
5545 case CPP_MINUS_MINUS
:
5546 /* Postdecrement. */
5547 c_parser_consume_token (parser
);
5548 expr
= default_function_array_conversion (expr
);
5549 expr
.value
= build_unary_op (POSTDECREMENT_EXPR
, expr
.value
, 0);
5550 expr
.original_code
= ERROR_MARK
;
5558 /* Parse an expression (C90 6.3.17, C99 6.5.17).
5561 assignment-expression
5562 expression , assignment-expression
5565 static struct c_expr
5566 c_parser_expression (c_parser
*parser
)
5569 expr
= c_parser_expr_no_commas (parser
, NULL
);
5570 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5573 c_parser_consume_token (parser
);
5574 next
= c_parser_expr_no_commas (parser
, NULL
);
5575 next
= default_function_array_conversion (next
);
5576 expr
.value
= build_compound_expr (expr
.value
, next
.value
);
5577 expr
.original_code
= COMPOUND_EXPR
;
5582 /* Parse an expression and convert functions or arrays to
5585 static struct c_expr
5586 c_parser_expression_conv (c_parser
*parser
)
5589 expr
= c_parser_expression (parser
);
5590 expr
= default_function_array_conversion (expr
);
5594 /* Parse a non-empty list of expressions. If CONVERT_P, convert
5595 functions and arrays to pointers.
5598 assignment-expression
5599 nonempty-expr-list , assignment-expression
5603 c_parser_expr_list (c_parser
*parser
, bool convert_p
)
5607 expr
= c_parser_expr_no_commas (parser
, NULL
);
5609 expr
= default_function_array_conversion (expr
);
5610 ret
= cur
= build_tree_list (NULL_TREE
, expr
.value
);
5611 while (c_parser_next_token_is (parser
, CPP_COMMA
))
5613 c_parser_consume_token (parser
);
5614 expr
= c_parser_expr_no_commas (parser
, NULL
);
5616 expr
= default_function_array_conversion (expr
);
5617 cur
= TREE_CHAIN (cur
) = build_tree_list (NULL_TREE
, expr
.value
);
5623 /* Parse Objective-C-specific constructs. */
5625 /* Parse an objc-class-definition.
5627 objc-class-definition:
5628 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
5629 objc-class-instance-variables[opt] objc-methodprotolist @end
5630 @implementation identifier objc-superclass[opt]
5631 objc-class-instance-variables[opt]
5632 @interface identifier ( identifier ) objc-protocol-refs[opt]
5633 objc-methodprotolist @end
5634 @implementation identifier ( identifier )
5639 "@interface identifier (" must start "@interface identifier (
5640 identifier ) ...": objc-methodprotolist in the first production may
5641 not start with a parenthesized identifier as a declarator of a data
5642 definition with no declaration specifiers if the objc-superclass,
5643 objc-protocol-refs and objc-class-instance-variables are omitted. */
5646 c_parser_objc_class_definition (c_parser
*parser
)
5651 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
5653 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
5657 c_parser_consume_token (parser
);
5658 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5660 c_parser_error (parser
, "expected identifier");
5663 id1
= c_parser_peek_token (parser
)->value
;
5664 c_parser_consume_token (parser
);
5665 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
5668 tree proto
= NULL_TREE
;
5669 c_parser_consume_token (parser
);
5670 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5672 c_parser_error (parser
, "expected identifier");
5673 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
5676 id2
= c_parser_peek_token (parser
)->value
;
5677 c_parser_consume_token (parser
);
5678 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5681 objc_start_category_implementation (id1
, id2
);
5684 if (c_parser_next_token_is (parser
, CPP_LESS
))
5685 proto
= c_parser_objc_protocol_refs (parser
);
5686 objc_start_category_interface (id1
, id2
, proto
);
5687 c_parser_objc_methodprotolist (parser
);
5688 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5689 objc_finish_interface ();
5692 if (c_parser_next_token_is (parser
, CPP_COLON
))
5694 c_parser_consume_token (parser
);
5695 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5697 c_parser_error (parser
, "expected identifier");
5700 superclass
= c_parser_peek_token (parser
)->value
;
5701 c_parser_consume_token (parser
);
5704 superclass
= NULL_TREE
;
5707 tree proto
= NULL_TREE
;
5708 if (c_parser_next_token_is (parser
, CPP_LESS
))
5709 proto
= c_parser_objc_protocol_refs (parser
);
5710 objc_start_class_interface (id1
, superclass
, proto
);
5713 objc_start_class_implementation (id1
, superclass
);
5714 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5715 c_parser_objc_class_instance_variables (parser
);
5718 objc_continue_interface ();
5719 c_parser_objc_methodprotolist (parser
);
5720 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5721 objc_finish_interface ();
5725 objc_continue_implementation ();
5730 /* Parse objc-class-instance-variables.
5732 objc-class-instance-variables:
5733 { objc-instance-variable-decl-list[opt] }
5735 objc-instance-variable-decl-list:
5736 objc-visibility-spec
5737 objc-instance-variable-decl ;
5739 objc-instance-variable-decl-list objc-visibility-spec
5740 objc-instance-variable-decl-list objc-instance-variable-decl ;
5741 objc-instance-variable-decl-list ;
5743 objc-visibility-spec:
5748 objc-instance-variable-decl:
5753 c_parser_objc_class_instance_variables (c_parser
*parser
)
5755 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
5756 c_parser_consume_token (parser
);
5757 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
5760 /* Parse any stray semicolon. */
5761 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5764 pedwarn ("extra semicolon in struct or union specified");
5765 c_parser_consume_token (parser
);
5768 /* Stop if at the end of the instance variables. */
5769 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
5771 c_parser_consume_token (parser
);
5774 /* Parse any objc-visibility-spec. */
5775 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
5777 c_parser_consume_token (parser
);
5778 objc_set_visibility (2);
5781 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
5783 c_parser_consume_token (parser
);
5784 objc_set_visibility (0);
5787 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
5789 c_parser_consume_token (parser
);
5790 objc_set_visibility (1);
5793 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5795 c_parser_pragma (parser
, pragma_external
);
5799 /* Parse some comma-separated declarations. */
5800 decls
= c_parser_struct_declaration (parser
);
5802 /* Comma-separated instance variables are chained together in
5803 reverse order; add them one by one. */
5804 tree ivar
= nreverse (decls
);
5805 for (; ivar
; ivar
= TREE_CHAIN (ivar
))
5806 objc_add_instance_variable (copy_node (ivar
));
5808 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5812 /* Parse an objc-class-declaration.
5814 objc-class-declaration:
5815 @class identifier-list ;
5819 c_parser_objc_class_declaration (c_parser
*parser
)
5821 tree list
= NULL_TREE
;
5822 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
5823 c_parser_consume_token (parser
);
5824 /* Any identifiers, including those declared as type names, are OK
5829 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5831 c_parser_error (parser
, "expected identifier");
5834 id
= c_parser_peek_token (parser
)->value
;
5835 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5836 c_parser_consume_token (parser
);
5837 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5838 c_parser_consume_token (parser
);
5842 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5843 objc_declare_class (list
);
5846 /* Parse an objc-alias-declaration.
5848 objc-alias-declaration:
5849 @compatibility_alias identifier identifier ;
5853 c_parser_objc_alias_declaration (c_parser
*parser
)
5856 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
5857 c_parser_consume_token (parser
);
5858 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5860 c_parser_error (parser
, "expected identifier");
5861 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5864 id1
= c_parser_peek_token (parser
)->value
;
5865 c_parser_consume_token (parser
);
5866 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5868 c_parser_error (parser
, "expected identifier");
5869 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
5872 id2
= c_parser_peek_token (parser
)->value
;
5873 c_parser_consume_token (parser
);
5874 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5875 objc_declare_alias (id1
, id2
);
5878 /* Parse an objc-protocol-definition.
5880 objc-protocol-definition:
5881 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
5882 @protocol identifier-list ;
5884 "@protocol identifier ;" should be resolved as "@protocol
5885 identifier-list ;": objc-methodprotolist may not start with a
5886 semicolon in the first alternative if objc-protocol-refs are
5890 c_parser_objc_protocol_definition (c_parser
*parser
)
5892 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
5893 c_parser_consume_token (parser
);
5894 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5896 c_parser_error (parser
, "expected identifier");
5899 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
5900 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
5902 tree list
= NULL_TREE
;
5903 /* Any identifiers, including those declared as type names, are
5908 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
5910 c_parser_error (parser
, "expected identifier");
5913 id
= c_parser_peek_token (parser
)->value
;
5914 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
5915 c_parser_consume_token (parser
);
5916 if (c_parser_next_token_is (parser
, CPP_COMMA
))
5917 c_parser_consume_token (parser
);
5921 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5922 objc_declare_protocols (list
);
5926 tree id
= c_parser_peek_token (parser
)->value
;
5927 tree proto
= NULL_TREE
;
5928 c_parser_consume_token (parser
);
5929 if (c_parser_next_token_is (parser
, CPP_LESS
))
5930 proto
= c_parser_objc_protocol_refs (parser
);
5931 objc_pq_context
= 1;
5932 objc_start_protocol (id
, proto
);
5933 c_parser_objc_methodprotolist (parser
);
5934 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
5935 objc_pq_context
= 0;
5936 objc_finish_interface ();
5940 /* Parse an objc-method-type.
5947 static enum tree_code
5948 c_parser_objc_method_type (c_parser
*parser
)
5950 switch (c_parser_peek_token (parser
)->type
)
5953 c_parser_consume_token (parser
);
5956 c_parser_consume_token (parser
);
5963 /* Parse an objc-method-definition.
5965 objc-method-definition:
5966 objc-method-type objc-method-decl ;[opt] compound-statement
5970 c_parser_objc_method_definition (c_parser
*parser
)
5972 enum tree_code type
= c_parser_objc_method_type (parser
);
5974 objc_set_method_type (type
);
5975 objc_pq_context
= 1;
5976 decl
= c_parser_objc_method_decl (parser
);
5977 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5979 c_parser_consume_token (parser
);
5981 pedwarn ("extra semicolon in method definition specified");
5983 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5985 c_parser_error (parser
, "expected %<{%>");
5988 objc_pq_context
= 0;
5989 objc_start_method_definition (decl
);
5990 add_stmt (c_parser_compound_statement (parser
));
5991 objc_finish_method_definition (current_function_decl
);
5994 /* Parse an objc-methodprotolist.
5996 objc-methodprotolist:
5998 objc-methodprotolist objc-methodproto
5999 objc-methodprotolist declaration
6000 objc-methodprotolist ;
6002 The declaration is a data definition, which may be missing
6003 declaration specifiers under the same rules and diagnostics as
6004 other data definitions outside functions, and the stray semicolon
6005 is diagnosed the same way as a stray semicolon outside a
6009 c_parser_objc_methodprotolist (c_parser
*parser
)
6013 /* The list is terminated by @end. */
6014 switch (c_parser_peek_token (parser
)->type
)
6018 pedwarn ("ISO C does not allow extra %<;%> outside of a function");
6019 c_parser_consume_token (parser
);
6023 c_parser_objc_methodproto (parser
);
6026 c_parser_pragma (parser
, pragma_external
);
6031 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
6033 c_parser_declaration_or_fndef (parser
, false, true, false, true);
6039 /* Parse an objc-methodproto.
6042 objc-method-type objc-method-decl ;
6046 c_parser_objc_methodproto (c_parser
*parser
)
6048 enum tree_code type
= c_parser_objc_method_type (parser
);
6050 objc_set_method_type (type
);
6051 /* Remember protocol qualifiers in prototypes. */
6052 objc_pq_context
= 1;
6053 decl
= c_parser_objc_method_decl (parser
);
6054 /* Forget protocol qualifiers here. */
6055 objc_pq_context
= 0;
6056 objc_add_method_declaration (decl
);
6057 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6060 /* Parse an objc-method-decl.
6063 ( objc-type-name ) objc-selector
6065 ( objc-type-name ) objc-keyword-selector objc-optparmlist
6066 objc-keyword-selector objc-optparmlist
6068 objc-keyword-selector:
6070 objc-keyword-selector objc-keyword-decl
6073 objc-selector : ( objc-type-name ) identifier
6074 objc-selector : identifier
6075 : ( objc-type-name ) identifier
6079 objc-optparms objc-optellipsis
6083 objc-opt-parms , parameter-declaration
6091 c_parser_objc_method_decl (c_parser
*parser
)
6093 tree type
= NULL_TREE
;
6095 tree parms
= NULL_TREE
;
6096 bool ellipsis
= false;
6098 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6100 c_parser_consume_token (parser
);
6101 type
= c_parser_objc_type_name (parser
);
6102 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6104 sel
= c_parser_objc_selector (parser
);
6105 /* If there is no selector, or a colon follows, we have an
6106 objc-keyword-selector. If there is a selector, and a colon does
6107 not follow, that selector ends the objc-method-decl. */
6108 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
6111 tree list
= NULL_TREE
;
6114 tree atype
= NULL_TREE
, id
, keyworddecl
;
6115 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6117 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6119 c_parser_consume_token (parser
);
6120 atype
= c_parser_objc_type_name (parser
);
6121 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
6124 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6126 c_parser_error (parser
, "expected identifier");
6127 return error_mark_node
;
6129 id
= c_parser_peek_token (parser
)->value
;
6130 c_parser_consume_token (parser
);
6131 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
);
6132 list
= chainon (list
, keyworddecl
);
6133 tsel
= c_parser_objc_selector (parser
);
6134 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6137 /* Parse the optional parameter list. Optional Objective-C
6138 method parameters follow the C syntax, and may include '...'
6139 to denote a variable number of arguments. */
6140 parms
= make_node (TREE_LIST
);
6141 while (c_parser_next_token_is (parser
, CPP_COMMA
))
6143 struct c_parm
*parm
;
6144 c_parser_consume_token (parser
);
6145 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
6148 c_parser_consume_token (parser
);
6151 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6154 parms
= chainon (parms
,
6155 build_tree_list (NULL_TREE
, grokparm (parm
)));
6159 return objc_build_method_signature (type
, sel
, parms
, ellipsis
);
6162 /* Parse an objc-type-name.
6165 objc-type-qualifiers[opt] type-name
6166 objc-type-qualifiers[opt]
6168 objc-type-qualifiers:
6170 objc-type-qualifiers objc-type-qualifier
6172 objc-type-qualifier: one of
6173 in out inout bycopy byref oneway
6177 c_parser_objc_type_name (c_parser
*parser
)
6179 tree quals
= NULL_TREE
;
6180 struct c_type_name
*typename
= NULL
;
6181 tree type
= NULL_TREE
;
6184 c_token
*token
= c_parser_peek_token (parser
);
6185 if (token
->type
== CPP_KEYWORD
6186 && (token
->keyword
== RID_IN
6187 || token
->keyword
== RID_OUT
6188 || token
->keyword
== RID_INOUT
6189 || token
->keyword
== RID_BYCOPY
6190 || token
->keyword
== RID_BYREF
6191 || token
->keyword
== RID_ONEWAY
))
6193 quals
= chainon (quals
, build_tree_list (NULL_TREE
, token
->value
));
6194 c_parser_consume_token (parser
);
6199 if (c_parser_next_token_starts_typename (parser
))
6200 typename
= c_parser_type_name (parser
);
6202 type
= groktypename (typename
);
6203 return build_tree_list (quals
, type
);
6206 /* Parse objc-protocol-refs.
6213 c_parser_objc_protocol_refs (c_parser
*parser
)
6215 tree list
= NULL_TREE
;
6216 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
6217 c_parser_consume_token (parser
);
6218 /* Any identifiers, including those declared as type names, are OK
6223 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
6225 c_parser_error (parser
, "expected identifier");
6228 id
= c_parser_peek_token (parser
)->value
;
6229 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
6230 c_parser_consume_token (parser
);
6231 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6232 c_parser_consume_token (parser
);
6236 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
6240 /* Parse an objc-try-catch-statement.
6242 objc-try-catch-statement:
6243 @try compound-statement objc-catch-list[opt]
6244 @try compound-statement objc-catch-list[opt] @finally compound-statement
6247 @catch ( parameter-declaration ) compound-statement
6248 objc-catch-list @catch ( parameter-declaration ) compound-statement
6252 c_parser_objc_try_catch_statement (c_parser
*parser
)
6256 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
6257 c_parser_consume_token (parser
);
6258 loc
= c_parser_peek_token (parser
)->location
;
6259 stmt
= c_parser_compound_statement (parser
);
6260 objc_begin_try_stmt (loc
, stmt
);
6261 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
6263 struct c_parm
*parm
;
6264 c_parser_consume_token (parser
);
6265 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6267 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
6270 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6273 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6274 objc_begin_catch_clause (grokparm (parm
));
6275 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
6276 c_parser_compound_statement_nostart (parser
);
6277 objc_finish_catch_clause ();
6279 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
6283 c_parser_consume_token (parser
);
6284 finloc
= c_parser_peek_token (parser
)->location
;
6285 finstmt
= c_parser_compound_statement (parser
);
6286 objc_build_finally_clause (finloc
, finstmt
);
6288 objc_finish_try_stmt ();
6291 /* Parse an objc-synchronized-statement.
6293 objc-synchronized-statement:
6294 @synchronized ( expression ) compound-statement
6298 c_parser_objc_synchronized_statement (c_parser
*parser
)
6302 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
6303 c_parser_consume_token (parser
);
6304 loc
= c_parser_peek_token (parser
)->location
;
6305 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6307 expr
= c_parser_expression (parser
).value
;
6308 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6311 expr
= error_mark_node
;
6312 stmt
= c_parser_compound_statement (parser
);
6313 objc_build_synchronized (loc
, expr
, stmt
);
6316 /* Parse an objc-selector; return NULL_TREE without an error if the
6317 next token is not an objc-selector.
6322 enum struct union if else while do for switch case default
6323 break continue return goto asm sizeof typeof __alignof
6324 unsigned long const short volatile signed restrict _Complex
6325 in out inout bycopy byref oneway int char float double void _Bool
6327 ??? Why this selection of keywords but not, for example, storage
6328 class specifiers? */
6331 c_parser_objc_selector (c_parser
*parser
)
6333 c_token
*token
= c_parser_peek_token (parser
);
6334 tree value
= token
->value
;
6335 if (token
->type
== CPP_NAME
)
6337 c_parser_consume_token (parser
);
6340 if (token
->type
!= CPP_KEYWORD
)
6342 switch (token
->keyword
)
6383 c_parser_consume_token (parser
);
6390 /* Parse an objc-selector-arg.
6394 objc-keywordname-list
6396 objc-keywordname-list:
6398 objc-keywordname-list objc-keywordname
6406 c_parser_objc_selector_arg (c_parser
*parser
)
6408 tree sel
= c_parser_objc_selector (parser
);
6409 tree list
= NULL_TREE
;
6410 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6414 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6416 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
6417 sel
= c_parser_objc_selector (parser
);
6418 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6424 /* Parse an objc-receiver.
6433 c_parser_objc_receiver (c_parser
*parser
)
6435 if (c_parser_peek_token (parser
)->type
== CPP_NAME
6436 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
6437 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
6439 tree id
= c_parser_peek_token (parser
)->value
;
6440 c_parser_consume_token (parser
);
6441 return objc_get_class_reference (id
);
6443 return c_parser_expression (parser
).value
;
6446 /* Parse objc-message-args.
6450 objc-keywordarg-list
6452 objc-keywordarg-list:
6454 objc-keywordarg-list objc-keywordarg
6457 objc-selector : objc-keywordexpr
6462 c_parser_objc_message_args (c_parser
*parser
)
6464 tree sel
= c_parser_objc_selector (parser
);
6465 tree list
= NULL_TREE
;
6466 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6471 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6473 keywordexpr
= c_parser_objc_keywordexpr (parser
);
6474 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
6475 sel
= c_parser_objc_selector (parser
);
6476 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
6482 /* Parse an objc-keywordexpr.
6489 c_parser_objc_keywordexpr (c_parser
*parser
)
6491 tree list
= c_parser_expr_list (parser
, true);
6492 if (TREE_CHAIN (list
) == NULL_TREE
)
6494 /* Just return the expression, remove a level of
6496 return TREE_VALUE (list
);
6500 /* We have a comma expression, we will collapse later. */
6506 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
6507 should be considered, statements. ALLOW_STMT is true if we're within
6508 the context of a function and such pragmas are to be allowed. Returns
6509 true if we actually parsed such a pragma. */
6512 c_parser_pragma (c_parser
*parser
, enum pragma_context context
)
6516 id
= c_parser_peek_token (parser
)->pragma_kind
;
6517 gcc_assert (id
!= PRAGMA_NONE
);
6521 case PRAGMA_OMP_BARRIER
:
6522 if (context
!= pragma_compound
)
6524 if (context
== pragma_stmt
)
6525 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
6526 "used in compound statements");
6529 c_parser_omp_barrier (parser
);
6532 case PRAGMA_OMP_FLUSH
:
6533 if (context
!= pragma_compound
)
6535 if (context
== pragma_stmt
)
6536 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
6537 "used in compound statements");
6540 c_parser_omp_flush (parser
);
6543 case PRAGMA_OMP_THREADPRIVATE
:
6544 c_parser_omp_threadprivate (parser
);
6547 case PRAGMA_OMP_SECTION
:
6548 error ("%<#pragma omp section%> may only be used in "
6549 "%<#pragma omp sections%> construct");
6550 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6553 case PRAGMA_GCC_PCH_PREPROCESS
:
6554 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
6555 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6559 if (id
< PRAGMA_FIRST_EXTERNAL
)
6561 if (context
== pragma_external
)
6564 c_parser_error (parser
, "expected declaration specifiers");
6565 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
6568 c_parser_omp_construct (parser
);
6574 c_parser_consume_pragma (parser
);
6575 c_invoke_pragma_handler (id
);
6577 /* Skip to EOL, but suppress any error message. Those will have been
6578 generated by the handler routine through calling error, as opposed
6579 to calling c_parser_error. */
6580 parser
->error
= true;
6581 c_parser_skip_to_pragma_eol (parser
);
6586 /* The interface the pragma parsers have to the lexer. */
6589 pragma_lex (tree
*value
)
6591 c_token
*tok
= c_parser_peek_token (the_parser
);
6592 enum cpp_ttype ret
= tok
->type
;
6594 *value
= tok
->value
;
6595 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
6599 if (ret
== CPP_KEYWORD
)
6601 c_parser_consume_token (the_parser
);
6608 c_parser_pragma_pch_preprocess (c_parser
*parser
)
6612 c_parser_consume_pragma (parser
);
6613 if (c_parser_next_token_is (parser
, CPP_STRING
))
6615 name
= c_parser_peek_token (parser
)->value
;
6616 c_parser_consume_token (parser
);
6619 c_parser_error (parser
, "expected string literal");
6620 c_parser_skip_to_pragma_eol (parser
);
6623 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
6626 /* OpenMP 2.5 parsing routines. */
6628 /* Returns name of the next clause.
6629 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
6630 the token is not consumed. Otherwise appropriate pragma_omp_clause is
6631 returned and the token is consumed. */
6633 static pragma_omp_clause
6634 c_parser_omp_clause_name (c_parser
*parser
)
6636 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
6638 if (c_parser_next_token_is_keyword (parser
, RID_IF
))
6639 result
= PRAGMA_OMP_CLAUSE_IF
;
6640 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
6641 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
6642 else if (c_parser_next_token_is (parser
, CPP_NAME
))
6644 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6649 if (!strcmp ("copyin", p
))
6650 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
6651 else if (!strcmp ("copyprivate", p
))
6652 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
6655 if (!strcmp ("firstprivate", p
))
6656 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
6659 if (!strcmp ("lastprivate", p
))
6660 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
6663 if (!strcmp ("nowait", p
))
6664 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
6665 else if (!strcmp ("num_threads", p
))
6666 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
6669 if (!strcmp ("ordered", p
))
6670 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
6673 if (!strcmp ("private", p
))
6674 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
6677 if (!strcmp ("reduction", p
))
6678 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
6681 if (!strcmp ("schedule", p
))
6682 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
6683 else if (!strcmp ("shared", p
))
6684 result
= PRAGMA_OMP_CLAUSE_SHARED
;
6689 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
6690 c_parser_consume_token (parser
);
6695 /* Validate that a clause of the given type does not already exist. */
6698 check_no_duplicate_clause (tree clauses
, enum tree_code code
, const char *name
)
6702 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6703 if (OMP_CLAUSE_CODE (c
) == code
)
6705 error ("too many %qs clauses", name
);
6713 variable-list , identifier
6715 If KIND is nonzero, create the appropriate node and install the decl
6716 in OMP_CLAUSE_DECL and add the node to the head of the list.
6718 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
6719 return the list created. */
6722 c_parser_omp_variable_list (c_parser
*parser
, enum omp_clause_code kind
,
6725 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
6726 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
6727 c_parser_error (parser
, "expected identifier");
6729 while (c_parser_next_token_is (parser
, CPP_NAME
)
6730 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
6732 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
6735 undeclared_variable (c_parser_peek_token (parser
)->value
,
6736 c_parser_peek_token (parser
)->location
);
6737 else if (t
== error_mark_node
)
6741 tree u
= build_omp_clause (kind
);
6742 OMP_CLAUSE_DECL (u
) = t
;
6743 OMP_CLAUSE_CHAIN (u
) = list
;
6747 list
= tree_cons (t
, NULL_TREE
, list
);
6749 c_parser_consume_token (parser
);
6751 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
6754 c_parser_consume_token (parser
);
6760 /* Similarly, but expect leading and trailing parenthesis. This is a very
6761 common case for omp clauses. */
6764 c_parser_omp_var_list_parens (c_parser
*parser
, enum tree_code kind
, tree list
)
6766 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6768 list
= c_parser_omp_variable_list (parser
, kind
, list
);
6769 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6775 copyin ( variable-list ) */
6778 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
6780 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
6784 copyprivate ( variable-list ) */
6787 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
6789 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
6793 default ( shared | none ) */
6796 c_parser_omp_clause_default (c_parser
*parser
, tree list
)
6798 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
6801 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6803 if (c_parser_next_token_is (parser
, CPP_NAME
))
6805 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
6810 if (strcmp ("none", p
) != 0)
6812 kind
= OMP_CLAUSE_DEFAULT_NONE
;
6816 if (strcmp ("shared", p
) != 0)
6818 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
6825 c_parser_consume_token (parser
);
6830 c_parser_error (parser
, "expected %<none%> or %<shared%>");
6832 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6834 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
6837 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
6838 c
= build_omp_clause (OMP_CLAUSE_DEFAULT
);
6839 OMP_CLAUSE_CHAIN (c
) = list
;
6840 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
6846 firstprivate ( variable-list ) */
6849 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
6851 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
6855 if ( expression ) */
6858 c_parser_omp_clause_if (c_parser
*parser
, tree list
)
6860 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
6862 tree t
= c_parser_paren_condition (parser
);
6865 check_no_duplicate_clause (list
, OMP_CLAUSE_IF
, "if");
6867 c
= build_omp_clause (OMP_CLAUSE_IF
);
6868 OMP_CLAUSE_IF_EXPR (c
) = t
;
6869 OMP_CLAUSE_CHAIN (c
) = list
;
6873 c_parser_error (parser
, "expected %<(%>");
6879 lastprivate ( variable-list ) */
6882 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
6884 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
6891 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
6895 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
6897 c
= build_omp_clause (OMP_CLAUSE_NOWAIT
);
6898 OMP_CLAUSE_CHAIN (c
) = list
;
6903 num_threads ( expression ) */
6906 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
6908 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6910 tree c
, t
= c_parser_expression (parser
).value
;
6912 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6914 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6916 c_parser_error (parser
, "expected integer expression");
6920 /* Attempt to statically determine when the number isn't positive. */
6921 c
= fold_build2 (LE_EXPR
, boolean_type_node
, t
,
6922 build_int_cst (TREE_TYPE (t
), 0));
6923 if (c
== boolean_true_node
)
6925 warning (0, "%<num_threads%> value must be positive");
6926 t
= integer_one_node
;
6929 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
6931 c
= build_omp_clause (OMP_CLAUSE_NUM_THREADS
);
6932 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
6933 OMP_CLAUSE_CHAIN (c
) = list
;
6944 c_parser_omp_clause_ordered (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
6948 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
6950 c
= build_omp_clause (OMP_CLAUSE_ORDERED
);
6951 OMP_CLAUSE_CHAIN (c
) = list
;
6956 private ( variable-list ) */
6959 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
6961 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
6965 reduction ( reduction-operator : variable-list )
6968 One of: + * - & ^ | && || */
6971 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
6973 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6975 enum tree_code code
;
6977 switch (c_parser_peek_token (parser
)->type
)
6989 code
= BIT_AND_EXPR
;
6992 code
= BIT_XOR_EXPR
;
6995 code
= BIT_IOR_EXPR
;
6998 code
= TRUTH_ANDIF_EXPR
;
7001 code
= TRUTH_ORIF_EXPR
;
7004 c_parser_error (parser
,
7005 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
7006 "%<^%>, %<|%>, %<&&%>, or %<||%>");
7007 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7010 c_parser_consume_token (parser
);
7011 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7015 nl
= c_parser_omp_variable_list (parser
, OMP_CLAUSE_REDUCTION
, list
);
7016 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
7017 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
7021 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7027 schedule ( schedule-kind )
7028 schedule ( schedule-kind , expression )
7031 static | dynamic | guided | runtime
7035 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
7039 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7042 c
= build_omp_clause (OMP_CLAUSE_SCHEDULE
);
7044 if (c_parser_next_token_is (parser
, CPP_NAME
))
7046 tree kind
= c_parser_peek_token (parser
)->value
;
7047 const char *p
= IDENTIFIER_POINTER (kind
);
7052 if (strcmp ("dynamic", p
) != 0)
7054 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
7058 if (strcmp ("guided", p
) != 0)
7060 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
7064 if (strcmp ("runtime", p
) != 0)
7066 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
7073 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
7074 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
7078 c_parser_consume_token (parser
);
7079 if (c_parser_next_token_is (parser
, CPP_COMMA
))
7081 c_parser_consume_token (parser
);
7083 t
= c_parser_expr_no_commas (parser
, NULL
).value
;
7085 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
7086 error ("schedule %<runtime%> does not take "
7087 "a %<chunk_size%> parameter");
7088 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
7089 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7091 c_parser_error (parser
, "expected integer expression");
7093 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7096 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7097 "expected %<,%> or %<)%>");
7099 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
7100 OMP_CLAUSE_CHAIN (c
) = list
;
7104 c_parser_error (parser
, "invalid schedule kind");
7105 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
7110 shared ( variable-list ) */
7113 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
7115 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
7118 /* Parse all OpenMP clauses. The set clauses allowed by the directive
7119 is a bitmask in MASK. Return the list of clauses found; the result
7120 of clause default goes in *pdefault. */
7123 c_parser_omp_all_clauses (c_parser
*parser
, unsigned int mask
,
7126 tree clauses
= NULL
;
7128 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7130 const pragma_omp_clause c_kind
= c_parser_omp_clause_name (parser
);
7132 tree prev
= clauses
;
7136 case PRAGMA_OMP_CLAUSE_COPYIN
:
7137 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
7140 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
7141 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
7142 c_name
= "copyprivate";
7144 case PRAGMA_OMP_CLAUSE_DEFAULT
:
7145 clauses
= c_parser_omp_clause_default (parser
, clauses
);
7148 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
7149 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
7150 c_name
= "firstprivate";
7152 case PRAGMA_OMP_CLAUSE_IF
:
7153 clauses
= c_parser_omp_clause_if (parser
, clauses
);
7156 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
7157 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
7158 c_name
= "lastprivate";
7160 case PRAGMA_OMP_CLAUSE_NOWAIT
:
7161 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
7164 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
7165 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
7166 c_name
= "num_threads";
7168 case PRAGMA_OMP_CLAUSE_ORDERED
:
7169 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
7172 case PRAGMA_OMP_CLAUSE_PRIVATE
:
7173 clauses
= c_parser_omp_clause_private (parser
, clauses
);
7176 case PRAGMA_OMP_CLAUSE_REDUCTION
:
7177 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
7178 c_name
= "reduction";
7180 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
7181 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
7182 c_name
= "schedule";
7184 case PRAGMA_OMP_CLAUSE_SHARED
:
7185 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
7189 c_parser_error (parser
, "expected %<#pragma omp%> clause");
7193 if (((mask
>> c_kind
) & 1) == 0 && !parser
->error
)
7195 /* Remove the invalid clause(s) from the list to avoid
7196 confusing the rest of the compiler. */
7198 error ("%qs is not valid for %qs", c_name
, where
);
7203 c_parser_skip_to_pragma_eol (parser
);
7205 return c_finish_omp_clauses (clauses
);
7212 In practice, we're also interested in adding the statement to an
7213 outer node. So it is convenient if we work around the fact that
7214 c_parser_statement calls add_stmt. */
7217 c_parser_omp_structured_block (c_parser
*parser
)
7219 tree stmt
= push_stmt_list ();
7220 c_parser_statement (parser
);
7221 return pop_stmt_list (stmt
);
7225 # pragma omp atomic new-line
7229 x binop= expr | x++ | ++x | x-- | --x
7231 +, *, -, /, &, ^, |, <<, >>
7233 where x is an lvalue expression with scalar type. */
7236 c_parser_omp_atomic (c_parser
*parser
)
7240 enum tree_code code
;
7242 c_parser_skip_to_pragma_eol (parser
);
7244 lhs
= c_parser_unary_expression (parser
).value
;
7245 switch (TREE_CODE (lhs
))
7249 c_parser_skip_to_end_of_block_or_statement (parser
);
7252 case PREINCREMENT_EXPR
:
7253 case POSTINCREMENT_EXPR
:
7254 lhs
= TREE_OPERAND (lhs
, 0);
7256 rhs
= integer_one_node
;
7259 case PREDECREMENT_EXPR
:
7260 case POSTDECREMENT_EXPR
:
7261 lhs
= TREE_OPERAND (lhs
, 0);
7263 rhs
= integer_one_node
;
7267 switch (c_parser_peek_token (parser
)->type
)
7273 code
= TRUNC_DIV_EXPR
;
7288 code
= BIT_AND_EXPR
;
7291 code
= BIT_IOR_EXPR
;
7294 code
= BIT_XOR_EXPR
;
7297 c_parser_error (parser
,
7298 "invalid operator for %<#pragma omp atomic%>");
7302 c_parser_consume_token (parser
);
7303 rhs
= c_parser_expression (parser
).value
;
7306 stmt
= c_finish_omp_atomic (code
, lhs
, rhs
);
7307 if (stmt
!= error_mark_node
)
7309 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7314 # pragma omp barrier new-line
7318 c_parser_omp_barrier (c_parser
*parser
)
7320 c_parser_consume_pragma (parser
);
7321 c_parser_skip_to_pragma_eol (parser
);
7323 c_finish_omp_barrier ();
7327 # pragma omp critical [(name)] new-line
7332 c_parser_omp_critical (c_parser
*parser
)
7334 tree stmt
, name
= NULL
;
7336 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7338 c_parser_consume_token (parser
);
7339 if (c_parser_next_token_is (parser
, CPP_NAME
))
7341 name
= c_parser_peek_token (parser
)->value
;
7342 c_parser_consume_token (parser
);
7343 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7346 c_parser_error (parser
, "expected identifier");
7348 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7349 c_parser_error (parser
, "expected %<(%> or end of line");
7350 c_parser_skip_to_pragma_eol (parser
);
7352 stmt
= c_parser_omp_structured_block (parser
);
7353 return c_finish_omp_critical (stmt
, name
);
7357 # pragma omp flush flush-vars[opt] new-line
7360 ( variable-list ) */
7363 c_parser_omp_flush (c_parser
*parser
)
7365 c_parser_consume_pragma (parser
);
7366 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
7367 c_parser_omp_var_list_parens (parser
, 0, NULL
);
7368 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
7369 c_parser_error (parser
, "expected %<(%> or end of line");
7370 c_parser_skip_to_pragma_eol (parser
);
7372 c_finish_omp_flush ();
7375 /* Parse the restricted form of the for statment allowed by OpenMP.
7376 The real trick here is to determine the loop control variable early
7377 so that we can push a new decl if necessary to make it private. */
7380 c_parser_omp_for_loop (c_parser
*parser
)
7382 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
;
7385 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
7387 c_parser_error (parser
, "for statement expected");
7390 loc
= c_parser_peek_token (parser
)->location
;
7391 c_parser_consume_token (parser
);
7393 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7396 /* Parse the initialization declaration or expression. */
7397 if (c_parser_next_token_starts_declspecs (parser
))
7399 c_parser_declaration_or_fndef (parser
, true, true, true, true);
7400 decl
= check_for_loop_decls ();
7405 else if (c_parser_next_token_is (parser
, CPP_NAME
)
7406 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
7408 decl
= c_parser_postfix_expression (parser
).value
;
7410 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
7412 init
= c_parser_expr_no_commas (parser
, NULL
).value
;
7413 init
= build_modify_expr (decl
, NOP_EXPR
, init
);
7414 init
= c_process_expr_stmt (init
);
7416 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7421 /* Parse the loop condition. */
7423 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
7425 cond
= c_parser_expression_conv (parser
).value
;
7426 cond
= c_objc_common_truthvalue_conversion (cond
);
7428 SET_EXPR_LOCATION (cond
, input_location
);
7430 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
7432 /* Parse the increment expression. */
7434 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
7435 incr
= c_process_expr_stmt (c_parser_expression (parser
).value
);
7436 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7439 save_break
= c_break_label
;
7440 c_break_label
= size_one_node
;
7441 save_cont
= c_cont_label
;
7442 c_cont_label
= NULL_TREE
;
7443 body
= push_stmt_list ();
7445 add_stmt (c_parser_c99_block_statement (parser
));
7447 add_stmt (build1 (LABEL_EXPR
, void_type_node
, c_cont_label
));
7449 body
= pop_stmt_list (body
);
7450 c_break_label
= save_break
;
7451 c_cont_label
= save_cont
;
7453 /* Only bother calling c_finish_omp_for if we havn't already generated
7454 an error from the initialization parsing. */
7455 if (decl
!= NULL
&& decl
!= error_mark_node
&& init
!= error_mark_node
)
7456 return c_finish_omp_for (loc
, decl
, init
, cond
, incr
, body
, NULL
);
7460 c_parser_error (parser
, "expected iteration declaration or initialization");
7461 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7462 decl
= init
= cond
= incr
= NULL_TREE
;
7467 #pragma omp for for-clause[optseq] new-line
7471 #define OMP_FOR_CLAUSE_MASK \
7472 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7473 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7474 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7475 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7476 | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \
7477 | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \
7478 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7481 c_parser_omp_for (c_parser
*parser
)
7483 tree block
, clauses
, ret
;
7485 clauses
= c_parser_omp_all_clauses (parser
, OMP_FOR_CLAUSE_MASK
,
7488 block
= c_begin_compound_stmt (true);
7489 ret
= c_parser_omp_for_loop (parser
);
7491 OMP_FOR_CLAUSES (ret
) = clauses
;
7492 block
= c_end_compound_stmt (block
, true);
7499 # pragma omp master new-line
7504 c_parser_omp_master (c_parser
*parser
)
7506 c_parser_skip_to_pragma_eol (parser
);
7507 return c_finish_omp_master (c_parser_omp_structured_block (parser
));
7511 # pragma omp ordered new-line
7516 c_parser_omp_ordered (c_parser
*parser
)
7518 c_parser_skip_to_pragma_eol (parser
);
7519 return c_finish_omp_ordered (c_parser_omp_structured_block (parser
));
7525 { section-sequence }
7528 section-directive[opt] structured-block
7529 section-sequence section-directive structured-block */
7532 c_parser_omp_sections_scope (c_parser
*parser
)
7535 bool error_suppress
= false;
7538 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
7540 /* Avoid skipping until the end of the block. */
7541 parser
->error
= false;
7545 stmt
= push_stmt_list ();
7547 loc
= c_parser_peek_token (parser
)->location
;
7548 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
7550 substmt
= push_stmt_list ();
7554 c_parser_statement (parser
);
7556 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7558 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7560 if (c_parser_next_token_is (parser
, CPP_EOF
))
7564 substmt
= pop_stmt_list (substmt
);
7565 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7566 SET_EXPR_LOCATION (substmt
, loc
);
7572 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
7574 if (c_parser_next_token_is (parser
, CPP_EOF
))
7577 loc
= c_parser_peek_token (parser
)->location
;
7578 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
7580 c_parser_consume_pragma (parser
);
7581 c_parser_skip_to_pragma_eol (parser
);
7582 error_suppress
= false;
7584 else if (!error_suppress
)
7586 error ("expected %<#pragma omp section%> or %<}%>");
7587 error_suppress
= true;
7590 substmt
= c_parser_omp_structured_block (parser
);
7591 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
7592 SET_EXPR_LOCATION (substmt
, loc
);
7595 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
7596 "expected %<#pragma omp section%> or %<}%>");
7598 substmt
= pop_stmt_list (stmt
);
7600 stmt
= make_node (OMP_SECTIONS
);
7601 TREE_TYPE (stmt
) = void_type_node
;
7602 OMP_SECTIONS_BODY (stmt
) = substmt
;
7604 return add_stmt (stmt
);
7608 # pragma omp sections sections-clause[optseq] newline
7612 #define OMP_SECTIONS_CLAUSE_MASK \
7613 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7614 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7615 | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
7616 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7617 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7620 c_parser_omp_sections (c_parser
*parser
)
7622 tree block
, clauses
, ret
;
7624 clauses
= c_parser_omp_all_clauses (parser
, OMP_SECTIONS_CLAUSE_MASK
,
7625 "#pragma omp sections");
7627 block
= c_begin_compound_stmt (true);
7628 ret
= c_parser_omp_sections_scope (parser
);
7630 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
7631 block
= c_end_compound_stmt (block
, true);
7638 # pragma parallel parallel-clause new-line
7639 # pragma parallel for parallel-for-clause new-line
7640 # pragma parallel sections parallel-sections-clause new-line
7643 #define OMP_PARALLEL_CLAUSE_MASK \
7644 ( (1u << PRAGMA_OMP_CLAUSE_IF) \
7645 | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7646 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7647 | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \
7648 | (1u << PRAGMA_OMP_CLAUSE_SHARED) \
7649 | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \
7650 | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \
7651 | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS))
7654 c_parser_omp_parallel (c_parser
*parser
)
7656 enum pragma_kind p_kind
= PRAGMA_OMP_PARALLEL
;
7657 const char *p_name
= "#pragma omp parallel";
7658 tree stmt
, clauses
, par_clause
, ws_clause
, block
;
7659 unsigned int mask
= OMP_PARALLEL_CLAUSE_MASK
;
7661 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
7663 c_parser_consume_token (parser
);
7664 p_kind
= PRAGMA_OMP_PARALLEL_FOR
;
7665 p_name
= "#pragma omp parallel for";
7666 mask
|= OMP_FOR_CLAUSE_MASK
;
7667 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
7669 else if (c_parser_next_token_is (parser
, CPP_NAME
))
7671 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
7672 if (strcmp (p
, "sections") == 0)
7674 c_parser_consume_token (parser
);
7675 p_kind
= PRAGMA_OMP_PARALLEL_SECTIONS
;
7676 p_name
= "#pragma omp parallel sections";
7677 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
7678 mask
&= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT
);
7682 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
);
7686 case PRAGMA_OMP_PARALLEL
:
7687 block
= c_begin_omp_parallel ();
7688 c_parser_statement (parser
);
7689 stmt
= c_finish_omp_parallel (clauses
, block
);
7692 case PRAGMA_OMP_PARALLEL_FOR
:
7693 block
= c_begin_omp_parallel ();
7694 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
7695 stmt
= c_parser_omp_for_loop (parser
);
7697 OMP_FOR_CLAUSES (stmt
) = ws_clause
;
7698 stmt
= c_finish_omp_parallel (par_clause
, block
);
7699 OMP_PARALLEL_COMBINED (stmt
) = 1;
7702 case PRAGMA_OMP_PARALLEL_SECTIONS
:
7703 block
= c_begin_omp_parallel ();
7704 c_split_parallel_clauses (clauses
, &par_clause
, &ws_clause
);
7705 stmt
= c_parser_omp_sections_scope (parser
);
7707 OMP_SECTIONS_CLAUSES (stmt
) = ws_clause
;
7708 stmt
= c_finish_omp_parallel (par_clause
, block
);
7709 OMP_PARALLEL_COMBINED (stmt
) = 1;
7720 # pragma omp single single-clause[optseq] new-line
7724 #define OMP_SINGLE_CLAUSE_MASK \
7725 ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \
7726 | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
7727 | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
7728 | (1u << PRAGMA_OMP_CLAUSE_NOWAIT))
7731 c_parser_omp_single (c_parser
*parser
)
7733 tree stmt
= make_node (OMP_SINGLE
);
7734 TREE_TYPE (stmt
) = void_type_node
;
7736 OMP_SINGLE_CLAUSES (stmt
)
7737 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
7738 "#pragma omp single");
7739 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
);
7741 return add_stmt (stmt
);
7745 /* Main entry point to parsing most OpenMP pragmas. */
7748 c_parser_omp_construct (c_parser
*parser
)
7750 enum pragma_kind p_kind
;
7754 loc
= c_parser_peek_token (parser
)->location
;
7755 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
7756 c_parser_consume_pragma (parser
);
7760 case PRAGMA_OMP_ATOMIC
:
7761 c_parser_omp_atomic (parser
);
7763 case PRAGMA_OMP_CRITICAL
:
7764 stmt
= c_parser_omp_critical (parser
);
7766 case PRAGMA_OMP_FOR
:
7767 stmt
= c_parser_omp_for (parser
);
7769 case PRAGMA_OMP_MASTER
:
7770 stmt
= c_parser_omp_master (parser
);
7772 case PRAGMA_OMP_ORDERED
:
7773 stmt
= c_parser_omp_ordered (parser
);
7775 case PRAGMA_OMP_PARALLEL
:
7776 stmt
= c_parser_omp_parallel (parser
);
7778 case PRAGMA_OMP_SECTIONS
:
7779 stmt
= c_parser_omp_sections (parser
);
7781 case PRAGMA_OMP_SINGLE
:
7782 stmt
= c_parser_omp_single (parser
);
7789 SET_EXPR_LOCATION (stmt
, loc
);
7794 # pragma omp threadprivate (variable-list) */
7797 c_parser_omp_threadprivate (c_parser
*parser
)
7801 c_parser_consume_pragma (parser
);
7802 vars
= c_parser_omp_var_list_parens (parser
, 0, NULL
);
7804 if (!targetm
.have_tls
)
7805 sorry ("threadprivate variables not supported in this target");
7807 /* Mark every variable in VARS to be assigned thread local storage. */
7808 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
7810 tree v
= TREE_PURPOSE (t
);
7812 /* If V had already been marked threadprivate, it doesn't matter
7813 whether it had been used prior to this point. */
7814 if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
7815 error ("%qE declared %<threadprivate%> after first use", v
);
7816 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
7817 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
7818 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
7819 error ("%<threadprivate%> %qE has incomplete type", v
);
7822 if (! DECL_THREAD_LOCAL_P (v
))
7824 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
7825 /* If rtl has been already set for this var, call
7826 make_decl_rtl once again, so that encode_section_info
7827 has a chance to look at the new decl flags. */
7828 if (DECL_RTL_SET_P (v
))
7831 C_DECL_THREADPRIVATE_P (v
) = 1;
7835 c_parser_skip_to_pragma_eol (parser
);
7839 /* Parse a single source file. */
7844 /* Use local storage to begin. If the first token is a pragma, parse it.
7845 If it is #pragma GCC pch_preprocess, then this will load a PCH file
7846 which will cause garbage collection. */
7849 memset (&tparser
, 0, sizeof tparser
);
7850 the_parser
= &tparser
;
7852 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
7853 c_parser_pragma_pch_preprocess (&tparser
);
7855 the_parser
= GGC_NEW (c_parser
);
7856 *the_parser
= tparser
;
7858 c_parser_translation_unit (the_parser
);
7862 #include "gt-c-parser.h"