c-parse.in (initelt): Give appropriate pedantic warnings...
[gcc.git] / gcc / c-parse.in
1 /* YACC parser for C syntax and for Objective C. -*-c-*-
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996,
3 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 /* This file defines the grammar of C and that of Objective C.
23 ifobjc ... end ifobjc conditionals contain code for Objective C only.
24 ifc ... end ifc conditionals contain code for C only.
25 Sed commands in Makefile.in are used to convert this file into
26 c-parse.y and into objc-parse.y. */
27
28 /* To whomever it may concern: I have heard that such a thing was once
29 written by AT&T, but I have never seen it. */
30
31 ifobjc
32 %expect 74
33 end ifobjc
34 ifc
35 %expect 53
36 end ifc
37
38 %{
39 #include "config.h"
40 #include "system.h"
41 #include <setjmp.h>
42 #include "tree.h"
43 #include "input.h"
44 #include "cpplib.h"
45 #include "intl.h"
46 #include "timevar.h"
47 #include "c-lex.h"
48 #include "c-tree.h"
49 #include "c-pragma.h"
50 #include "flags.h"
51 #include "output.h"
52 #include "toplev.h"
53 #include "ggc.h"
54
55 #ifdef MULTIBYTE_CHARS
56 #include <locale.h>
57 #endif
58
59 ifobjc
60 #include "objc-act.h"
61 end ifobjc
62
63 /* Since parsers are distinct for each language, put the language string
64 definition here. */
65 ifobjc
66 const char * const language_string = "GNU Objective-C";
67 end ifobjc
68 ifc
69 const char * const language_string = "GNU C";
70 end ifc
71
72 /* Like YYERROR but do call yyerror. */
73 #define YYERROR1 { yyerror ("syntax error"); YYERROR; }
74
75 /* Cause the `yydebug' variable to be defined. */
76 #define YYDEBUG 1
77 %}
78
79 %start program
80
81 %union {long itype; tree ttype; enum tree_code code;
82 const char *filename; int lineno; int ends_in_label; }
83
84 /* All identifiers that are not reserved words
85 and are not declared typedefs in the current block */
86 %token IDENTIFIER
87
88 /* All identifiers that are declared typedefs in the current block.
89 In some contexts, they are treated just like IDENTIFIER,
90 but they can also serve as typespecs in declarations. */
91 %token TYPENAME
92
93 /* Reserved words that specify storage class.
94 yylval contains an IDENTIFIER_NODE which indicates which one. */
95 %token SCSPEC
96
97 /* Reserved words that specify type.
98 yylval contains an IDENTIFIER_NODE which indicates which one. */
99 %token TYPESPEC
100
101 /* Reserved words that qualify type: "const", "volatile", or "restrict".
102 yylval contains an IDENTIFIER_NODE which indicates which one. */
103 %token TYPE_QUAL
104
105 /* Character or numeric constants.
106 yylval is the node for the constant. */
107 %token CONSTANT
108
109 /* String constants in raw form.
110 yylval is a STRING_CST node. */
111 %token STRING
112
113 /* "...", used for functions with variable arglists. */
114 %token ELLIPSIS
115
116 /* the reserved words */
117 /* SCO include files test "ASM", so use something else. */
118 %token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
119 %token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF
120 %token ATTRIBUTE EXTENSION LABEL
121 %token REALPART IMAGPART VA_ARG
122 %token PTR_VALUE PTR_BASE PTR_EXTENT
123
124 /* Add precedence rules to solve dangling else s/r conflict */
125 %nonassoc IF
126 %nonassoc ELSE
127
128 /* Define the operator tokens and their precedences.
129 The value is an integer because, if used, it is the tree code
130 to use in the expression made from the operator. */
131
132 %right <code> ASSIGN '='
133 %right <code> '?' ':'
134 %left <code> OROR
135 %left <code> ANDAND
136 %left <code> '|'
137 %left <code> '^'
138 %left <code> '&'
139 %left <code> EQCOMPARE
140 %left <code> ARITHCOMPARE
141 %left <code> LSHIFT RSHIFT
142 %left <code> '+' '-'
143 %left <code> '*' '/' '%'
144 %right <code> UNARY PLUSPLUS MINUSMINUS
145 %left HYPERUNARY
146 %left <code> POINTSAT '.' '(' '['
147
148 /* The Objective-C keywords. These are included in C and in
149 Objective C, so that the token codes are the same in both. */
150 %token INTERFACE IMPLEMENTATION END SELECTOR DEFS ENCODE
151 %token CLASSNAME PUBLIC PRIVATE PROTECTED PROTOCOL OBJECTNAME CLASS ALIAS
152
153 /* Objective-C string constants in raw form.
154 yylval is an STRING_CST node. */
155 %token OBJC_STRING
156
157
158 %type <code> unop
159 %type <ttype> ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
160 %type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF
161
162 %type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist exprlist
163 %type <ttype> expr_no_commas cast_expr unary_expr primary string STRING
164 %type <ttype> typed_declspecs reserved_declspecs
165 %type <ttype> typed_typespecs reserved_typespecquals
166 %type <ttype> declmods typespec typespecqual_reserved
167 %type <ttype> typed_declspecs_no_prefix_attr reserved_declspecs_no_prefix_attr
168 %type <ttype> declmods_no_prefix_attr
169 %type <ttype> SCSPEC TYPESPEC TYPE_QUAL nonempty_type_quals maybe_type_qual
170 %type <ttype> initdecls notype_initdecls initdcl notype_initdcl
171 %type <ttype> init maybeasm
172 %type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
173 %type <ttype> maybe_attribute attributes attribute attribute_list attrib
174 %type <ttype> any_word extension
175
176 %type <ttype> compstmt compstmt_start compstmt_nostart compstmt_primary_start
177 %type <ttype> do_stmt_start poplevel
178
179 %type <ttype> declarator
180 %type <ttype> notype_declarator after_type_declarator
181 %type <ttype> parm_declarator
182
183 %type <ttype> structsp component_decl_list component_decl_list2
184 %type <ttype> component_decl components component_declarator
185 %type <ttype> enumlist enumerator
186 %type <ttype> struct_head union_head enum_head
187 %type <ttype> typename absdcl absdcl1 type_quals
188 %type <ttype> xexpr parms parm identifiers
189
190 %type <ttype> parmlist parmlist_1 parmlist_2
191 %type <ttype> parmlist_or_identifiers parmlist_or_identifiers_1
192 %type <ttype> identifiers_or_typenames
193
194 %type <itype> setspecs
195
196 %type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
197
198 %type <filename> save_filename
199 %type <lineno> save_lineno
200 \f
201 ifobjc
202 /* the Objective-C nonterminals */
203
204 %type <ttype> ivar_decl_list ivar_decls ivar_decl ivars ivar_declarator
205 %type <ttype> methoddecl unaryselector keywordselector selector
206 %type <ttype> keyworddecl receiver objcmessageexpr messageargs
207 %type <ttype> keywordexpr keywordarglist keywordarg
208 %type <ttype> myparms myparm optparmlist reservedwords objcselectorexpr
209 %type <ttype> selectorarg keywordnamelist keywordname objcencodeexpr
210 %type <ttype> objc_string non_empty_protocolrefs protocolrefs identifier_list objcprotocolexpr
211
212 %type <ttype> CLASSNAME OBJC_STRING OBJECTNAME
213 end ifobjc
214 \f
215 %{
216 /* Number of statements (loosely speaking) and compound statements
217 seen so far. */
218 static int stmt_count;
219 static int compstmt_count;
220
221 /* Input file and line number of the end of the body of last simple_if;
222 used by the stmt-rule immediately after simple_if returns. */
223 static const char *if_stmt_file;
224 static int if_stmt_line;
225
226 /* List of types and structure classes of the current declaration. */
227 static tree current_declspecs = NULL_TREE;
228 static tree prefix_attributes = NULL_TREE;
229
230 /* Stack of saved values of current_declspecs and prefix_attributes. */
231 static tree declspec_stack;
232
233 /* For __extension__, save/restore the warning flags which are
234 controlled by __extension__. */
235 #define SAVE_WARN_FLAGS() \
236 size_int (pedantic | (warn_pointer_arith << 1))
237 #define RESTORE_WARN_FLAGS(tval) \
238 do { \
239 int val = tree_low_cst (tval, 0); \
240 pedantic = val & 1; \
241 warn_pointer_arith = (val >> 1) & 1; \
242 } while (0)
243
244 ifobjc
245 /* Objective-C specific information */
246
247 tree objc_interface_context;
248 tree objc_implementation_context;
249 tree objc_method_context;
250 tree objc_ivar_chain;
251 tree objc_ivar_context;
252 enum tree_code objc_inherit_code;
253 int objc_receiver_context;
254 int objc_public_flag;
255
256 end ifobjc
257
258 /* Tell yyparse how to print a token's value, if yydebug is set. */
259
260 #define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)
261
262 static void yyprint PARAMS ((FILE *, int, YYSTYPE));
263 static void yyerror PARAMS ((const char *));
264 static inline int _yylex PARAMS ((void));
265 static int yylex PARAMS ((void));
266 static void init_reswords PARAMS ((void));
267
268 /* Add GC roots for variables local to this file. */
269 void
270 c_parse_init ()
271 {
272 ggc_add_tree_root (&declspec_stack, 1);
273 ggc_add_tree_root (&current_declspecs, 1);
274 ggc_add_tree_root (&prefix_attributes, 1);
275 ifobjc
276 ggc_add_tree_root (&objc_interface_context, 1);
277 ggc_add_tree_root (&objc_implementation_context, 1);
278 ggc_add_tree_root (&objc_method_context, 1);
279 ggc_add_tree_root (&objc_ivar_chain, 1);
280 ggc_add_tree_root (&objc_ivar_context, 1);
281 end ifobjc
282 }
283
284 %}
285 \f
286 %%
287 program: /* empty */
288 { if (pedantic)
289 pedwarn ("ISO C forbids an empty source file");
290 finish_file ();
291 }
292 | extdefs
293 {
294 /* In case there were missing closebraces,
295 get us back to the global binding level. */
296 while (! global_bindings_p ())
297 poplevel (0, 0, 0);
298 finish_file ();
299 }
300 ;
301
302 /* the reason for the strange actions in this rule
303 is so that notype_initdecls when reached via datadef
304 can find a valid list of type and sc specs in $0. */
305
306 extdefs:
307 {$<ttype>$ = NULL_TREE; } extdef
308 | extdefs {$<ttype>$ = NULL_TREE; ggc_collect(); } extdef
309 ;
310
311 extdef:
312 fndef
313 | datadef
314 ifobjc
315 | objcdef
316 end ifobjc
317 | ASM_KEYWORD '(' expr ')' ';'
318 { STRIP_NOPS ($3);
319 if ((TREE_CODE ($3) == ADDR_EXPR
320 && TREE_CODE (TREE_OPERAND ($3, 0)) == STRING_CST)
321 || TREE_CODE ($3) == STRING_CST)
322 assemble_asm ($3);
323 else
324 error ("argument of `asm' is not a constant string"); }
325 | extension extdef
326 { RESTORE_WARN_FLAGS ($1); }
327 ;
328
329 datadef:
330 setspecs notype_initdecls ';'
331 { if (pedantic)
332 error ("ISO C forbids data definition with no type or storage class");
333 else if (!flag_traditional)
334 warning ("data definition has no type or storage class");
335
336 current_declspecs = TREE_VALUE (declspec_stack);
337 prefix_attributes = TREE_PURPOSE (declspec_stack);
338 declspec_stack = TREE_CHAIN (declspec_stack); }
339 | declmods setspecs notype_initdecls ';'
340 { current_declspecs = TREE_VALUE (declspec_stack);
341 prefix_attributes = TREE_PURPOSE (declspec_stack);
342 declspec_stack = TREE_CHAIN (declspec_stack); }
343 | typed_declspecs setspecs initdecls ';'
344 { current_declspecs = TREE_VALUE (declspec_stack);
345 prefix_attributes = TREE_PURPOSE (declspec_stack);
346 declspec_stack = TREE_CHAIN (declspec_stack); }
347 | declmods ';'
348 { pedwarn ("empty declaration"); }
349 | typed_declspecs ';'
350 { shadow_tag ($1); }
351 | error ';'
352 | error '}'
353 | ';'
354 { if (pedantic)
355 pedwarn ("ISO C does not allow extra `;' outside of a function"); }
356 ;
357 \f
358 fndef:
359 typed_declspecs setspecs declarator
360 { if (! start_function (current_declspecs, $3,
361 prefix_attributes, NULL_TREE))
362 YYERROR1;
363 }
364 old_style_parm_decls
365 { store_parm_decls (); }
366 compstmt_or_error
367 { finish_function (0);
368 current_declspecs = TREE_VALUE (declspec_stack);
369 prefix_attributes = TREE_PURPOSE (declspec_stack);
370 declspec_stack = TREE_CHAIN (declspec_stack); }
371 | typed_declspecs setspecs declarator error
372 { current_declspecs = TREE_VALUE (declspec_stack);
373 prefix_attributes = TREE_PURPOSE (declspec_stack);
374 declspec_stack = TREE_CHAIN (declspec_stack); }
375 | declmods setspecs notype_declarator
376 { if (! start_function (current_declspecs, $3,
377 prefix_attributes, NULL_TREE))
378 YYERROR1;
379 }
380 old_style_parm_decls
381 { store_parm_decls (); }
382 compstmt_or_error
383 { finish_function (0);
384 current_declspecs = TREE_VALUE (declspec_stack);
385 prefix_attributes = TREE_PURPOSE (declspec_stack);
386 declspec_stack = TREE_CHAIN (declspec_stack); }
387 | declmods setspecs notype_declarator error
388 { current_declspecs = TREE_VALUE (declspec_stack);
389 prefix_attributes = TREE_PURPOSE (declspec_stack);
390 declspec_stack = TREE_CHAIN (declspec_stack); }
391 | setspecs notype_declarator
392 { if (! start_function (NULL_TREE, $2,
393 prefix_attributes, NULL_TREE))
394 YYERROR1;
395 }
396 old_style_parm_decls
397 { store_parm_decls (); }
398 compstmt_or_error
399 { finish_function (0);
400 current_declspecs = TREE_VALUE (declspec_stack);
401 prefix_attributes = TREE_PURPOSE (declspec_stack);
402 declspec_stack = TREE_CHAIN (declspec_stack); }
403 | setspecs notype_declarator error
404 { current_declspecs = TREE_VALUE (declspec_stack);
405 prefix_attributes = TREE_PURPOSE (declspec_stack);
406 declspec_stack = TREE_CHAIN (declspec_stack); }
407 ;
408
409 identifier:
410 IDENTIFIER
411 | TYPENAME
412 ifobjc
413 | OBJECTNAME
414 | CLASSNAME
415 end ifobjc
416 ;
417
418 unop: '&'
419 { $$ = ADDR_EXPR; }
420 | '-'
421 { $$ = NEGATE_EXPR; }
422 | '+'
423 { $$ = CONVERT_EXPR;
424 ifc
425 if (warn_traditional && !in_system_header)
426 warning ("traditional C rejects the unary plus operator");
427 end ifc
428 }
429 | PLUSPLUS
430 { $$ = PREINCREMENT_EXPR; }
431 | MINUSMINUS
432 { $$ = PREDECREMENT_EXPR; }
433 | '~'
434 { $$ = BIT_NOT_EXPR; }
435 | '!'
436 { $$ = TRUTH_NOT_EXPR; }
437 ;
438
439 expr: nonnull_exprlist
440 { $$ = build_compound_expr ($1); }
441 ;
442
443 exprlist:
444 /* empty */
445 { $$ = NULL_TREE; }
446 | nonnull_exprlist
447 ;
448
449 nonnull_exprlist:
450 expr_no_commas
451 { $$ = build_tree_list (NULL_TREE, $1); }
452 | nonnull_exprlist ',' expr_no_commas
453 { chainon ($1, build_tree_list (NULL_TREE, $3)); }
454 ;
455
456 unary_expr:
457 primary
458 | '*' cast_expr %prec UNARY
459 { $$ = build_indirect_ref ($2, "unary *"); }
460 /* __extension__ turns off -pedantic for following primary. */
461 | extension cast_expr %prec UNARY
462 { $$ = $2;
463 RESTORE_WARN_FLAGS ($1); }
464 | unop cast_expr %prec UNARY
465 { $$ = build_unary_op ($1, $2, 0);
466 overflow_warning ($$); }
467 /* Refer to the address of a label as a pointer. */
468 | ANDAND identifier
469 { tree label = lookup_label ($2);
470 if (pedantic)
471 pedwarn ("ISO C forbids `&&'");
472 if (label == 0)
473 $$ = null_pointer_node;
474 else
475 {
476 TREE_USED (label) = 1;
477 $$ = build1 (ADDR_EXPR, ptr_type_node, label);
478 TREE_CONSTANT ($$) = 1;
479 }
480 }
481 /* This seems to be impossible on some machines, so let's turn it off.
482 You can use __builtin_next_arg to find the anonymous stack args.
483 | '&' ELLIPSIS
484 { tree types = TYPE_ARG_TYPES (TREE_TYPE (current_function_decl));
485 $$ = error_mark_node;
486 if (TREE_VALUE (tree_last (types)) == void_type_node)
487 error ("`&...' used in function with fixed number of arguments");
488 else
489 {
490 if (pedantic)
491 pedwarn ("ISO C forbids `&...'");
492 $$ = tree_last (DECL_ARGUMENTS (current_function_decl));
493 $$ = build_unary_op (ADDR_EXPR, $$, 0);
494 } }
495 */
496 | sizeof unary_expr %prec UNARY
497 { skip_evaluation--;
498 if (TREE_CODE ($2) == COMPONENT_REF
499 && DECL_C_BIT_FIELD (TREE_OPERAND ($2, 1)))
500 error ("`sizeof' applied to a bit-field");
501 $$ = c_sizeof (TREE_TYPE ($2)); }
502 | sizeof '(' typename ')' %prec HYPERUNARY
503 { skip_evaluation--;
504 $$ = c_sizeof (groktypename ($3)); }
505 | alignof unary_expr %prec UNARY
506 { skip_evaluation--;
507 $$ = c_alignof_expr ($2); }
508 | alignof '(' typename ')' %prec HYPERUNARY
509 { skip_evaluation--;
510 $$ = c_alignof (groktypename ($3)); }
511 | REALPART cast_expr %prec UNARY
512 { $$ = build_unary_op (REALPART_EXPR, $2, 0); }
513 | IMAGPART cast_expr %prec UNARY
514 { $$ = build_unary_op (IMAGPART_EXPR, $2, 0); }
515 | VA_ARG '(' expr_no_commas ',' typename ')'
516 { $$ = build_va_arg ($3, groktypename ($5)); }
517 ;
518
519 sizeof:
520 SIZEOF { skip_evaluation++; }
521 ;
522
523 alignof:
524 ALIGNOF { skip_evaluation++; }
525 ;
526
527 cast_expr:
528 unary_expr
529 | '(' typename ')' cast_expr %prec UNARY
530 { tree type;
531 int SAVED_warn_strict_prototypes = warn_strict_prototypes;
532 /* This avoids warnings about unprototyped casts on
533 integers. E.g. "#define SIG_DFL (void(*)())0". */
534 if (TREE_CODE ($4) == INTEGER_CST)
535 warn_strict_prototypes = 0;
536 type = groktypename ($2);
537 warn_strict_prototypes = SAVED_warn_strict_prototypes;
538 $$ = build_c_cast (type, $4); }
539 | '(' typename ')' '{'
540 { start_init (NULL_TREE, NULL, 0);
541 $2 = groktypename ($2);
542 really_start_incremental_init ($2); }
543 initlist_maybe_comma '}' %prec UNARY
544 { const char *name;
545 tree result = pop_init_level (0);
546 tree type = $2;
547 finish_init ();
548
549 if (pedantic && ! flag_isoc99)
550 pedwarn ("ISO C89 forbids constructor expressions");
551 if (TYPE_NAME (type) != 0)
552 {
553 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
554 name = IDENTIFIER_POINTER (TYPE_NAME (type));
555 else
556 name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
557 }
558 else
559 name = "";
560 $$ = result;
561 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type))
562 {
563 int failure = complete_array_type (type, $$, 1);
564 if (failure)
565 abort ();
566 }
567 }
568 ;
569
570 expr_no_commas:
571 cast_expr
572 | expr_no_commas '+' expr_no_commas
573 { $$ = parser_build_binary_op ($2, $1, $3); }
574 | expr_no_commas '-' expr_no_commas
575 { $$ = parser_build_binary_op ($2, $1, $3); }
576 | expr_no_commas '*' expr_no_commas
577 { $$ = parser_build_binary_op ($2, $1, $3); }
578 | expr_no_commas '/' expr_no_commas
579 { $$ = parser_build_binary_op ($2, $1, $3); }
580 | expr_no_commas '%' expr_no_commas
581 { $$ = parser_build_binary_op ($2, $1, $3); }
582 | expr_no_commas LSHIFT expr_no_commas
583 { $$ = parser_build_binary_op ($2, $1, $3); }
584 | expr_no_commas RSHIFT expr_no_commas
585 { $$ = parser_build_binary_op ($2, $1, $3); }
586 | expr_no_commas ARITHCOMPARE expr_no_commas
587 { $$ = parser_build_binary_op ($2, $1, $3); }
588 | expr_no_commas EQCOMPARE expr_no_commas
589 { $$ = parser_build_binary_op ($2, $1, $3); }
590 | expr_no_commas '&' expr_no_commas
591 { $$ = parser_build_binary_op ($2, $1, $3); }
592 | expr_no_commas '|' expr_no_commas
593 { $$ = parser_build_binary_op ($2, $1, $3); }
594 | expr_no_commas '^' expr_no_commas
595 { $$ = parser_build_binary_op ($2, $1, $3); }
596 | expr_no_commas ANDAND
597 { $1 = truthvalue_conversion (default_conversion ($1));
598 skip_evaluation += $1 == boolean_false_node; }
599 expr_no_commas
600 { skip_evaluation -= $1 == boolean_false_node;
601 $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
602 | expr_no_commas OROR
603 { $1 = truthvalue_conversion (default_conversion ($1));
604 skip_evaluation += $1 == boolean_true_node; }
605 expr_no_commas
606 { skip_evaluation -= $1 == boolean_true_node;
607 $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
608 | expr_no_commas '?'
609 { $1 = truthvalue_conversion (default_conversion ($1));
610 skip_evaluation += $1 == boolean_false_node; }
611 expr ':'
612 { skip_evaluation += (($1 == boolean_true_node)
613 - ($1 == boolean_false_node)); }
614 expr_no_commas
615 { skip_evaluation -= $1 == boolean_true_node;
616 $$ = build_conditional_expr ($1, $4, $7); }
617 | expr_no_commas '?'
618 { if (pedantic)
619 pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
620 /* Make sure first operand is calculated only once. */
621 $<ttype>2 = save_expr ($1);
622 $1 = truthvalue_conversion (default_conversion ($<ttype>2));
623 skip_evaluation += $1 == boolean_true_node; }
624 ':' expr_no_commas
625 { skip_evaluation -= $1 == boolean_true_node;
626 $$ = build_conditional_expr ($1, $<ttype>2, $5); }
627 | expr_no_commas '=' expr_no_commas
628 { char class;
629 $$ = build_modify_expr ($1, NOP_EXPR, $3);
630 class = TREE_CODE_CLASS (TREE_CODE ($$));
631 if (class == 'e' || class == '1'
632 || class == '2' || class == '<')
633 C_SET_EXP_ORIGINAL_CODE ($$, MODIFY_EXPR);
634 }
635 | expr_no_commas ASSIGN expr_no_commas
636 { char class;
637 $$ = build_modify_expr ($1, $2, $3);
638 /* This inhibits warnings in truthvalue_conversion. */
639 class = TREE_CODE_CLASS (TREE_CODE ($$));
640 if (class == 'e' || class == '1'
641 || class == '2' || class == '<')
642 C_SET_EXP_ORIGINAL_CODE ($$, ERROR_MARK);
643 }
644 ;
645
646 primary:
647 IDENTIFIER
648 {
649 if (yychar == YYEMPTY)
650 yychar = YYLEX;
651 $$ = build_external_ref ($1, yychar == '(');
652 }
653 | CONSTANT
654 | string
655 { $$ = combine_strings ($1); }
656 | '(' expr ')'
657 { char class = TREE_CODE_CLASS (TREE_CODE ($2));
658 if (class == 'e' || class == '1'
659 || class == '2' || class == '<')
660 C_SET_EXP_ORIGINAL_CODE ($2, ERROR_MARK);
661 $$ = $2; }
662 | '(' error ')'
663 { $$ = error_mark_node; }
664 | compstmt_primary_start compstmt_nostart ')'
665 { tree saved_last_tree;
666
667 if (pedantic)
668 pedwarn ("ISO C forbids braced-groups within expressions");
669 pop_label_level ();
670
671 saved_last_tree = COMPOUND_BODY ($1);
672 RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
673 last_tree = saved_last_tree;
674 TREE_CHAIN (last_tree) = NULL_TREE;
675 if (!last_expr_type)
676 last_expr_type = void_type_node;
677 $$ = build1 (STMT_EXPR, last_expr_type, $1);
678 TREE_SIDE_EFFECTS ($$) = 1;
679 }
680 | compstmt_primary_start error ')'
681 {
682 pop_label_level ();
683 last_tree = COMPOUND_BODY ($1);
684 TREE_CHAIN (last_tree) = NULL_TREE;
685 $$ = error_mark_node;
686 }
687 | primary '(' exprlist ')' %prec '.'
688 { $$ = build_function_call ($1, $3); }
689 | primary '[' expr ']' %prec '.'
690 { $$ = build_array_ref ($1, $3); }
691 | primary '.' identifier
692 {
693 ifobjc
694 if (doing_objc_thang)
695 {
696 if (is_public ($1, $3))
697 $$ = build_component_ref ($1, $3);
698 else
699 $$ = error_mark_node;
700 }
701 else
702 end ifobjc
703 $$ = build_component_ref ($1, $3);
704 }
705 | primary POINTSAT identifier
706 {
707 tree expr = build_indirect_ref ($1, "->");
708
709 ifobjc
710 if (doing_objc_thang)
711 {
712 if (is_public (expr, $3))
713 $$ = build_component_ref (expr, $3);
714 else
715 $$ = error_mark_node;
716 }
717 else
718 end ifobjc
719 $$ = build_component_ref (expr, $3);
720 }
721 | primary PLUSPLUS
722 { $$ = build_unary_op (POSTINCREMENT_EXPR, $1, 0); }
723 | primary MINUSMINUS
724 { $$ = build_unary_op (POSTDECREMENT_EXPR, $1, 0); }
725 ifobjc
726 | objcmessageexpr
727 { $$ = build_message_expr ($1); }
728 | objcselectorexpr
729 { $$ = build_selector_expr ($1); }
730 | objcprotocolexpr
731 { $$ = build_protocol_expr ($1); }
732 | objcencodeexpr
733 { $$ = build_encode_expr ($1); }
734 | objc_string
735 { $$ = build_objc_string_object ($1); }
736 end ifobjc
737 ;
738
739 /* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
740 string:
741 STRING
742 | string STRING
743 {
744 ifc
745 static int last_lineno = 0;
746 static const char *last_input_filename = 0;
747 end ifc
748 $$ = chainon ($1, $2);
749 ifc
750 if (warn_traditional && !in_system_header
751 && (lineno != last_lineno || !last_input_filename ||
752 strcmp (last_input_filename, input_filename)))
753 {
754 warning ("traditional C rejects string concatenation");
755 last_lineno = lineno;
756 last_input_filename = input_filename;
757 }
758 end ifc
759 }
760 ;
761
762 ifobjc
763 /* Produces an STRING_CST with perhaps more STRING_CSTs chained
764 onto it, which is to be read as an ObjC string object. */
765 objc_string:
766 OBJC_STRING
767 | objc_string OBJC_STRING
768 { $$ = chainon ($1, $2); }
769 ;
770 end ifobjc
771
772 old_style_parm_decls:
773 /* empty */
774 | datadecls
775 | datadecls ELLIPSIS
776 /* ... is used here to indicate a varargs function. */
777 { c_mark_varargs ();
778 if (pedantic)
779 pedwarn ("ISO C does not permit use of `varargs.h'"); }
780 ;
781
782 /* The following are analogous to lineno_decl, decls and decl
783 except that they do not allow nested functions.
784 They are used for old-style parm decls. */
785 lineno_datadecl:
786 save_filename save_lineno datadecl
787 { }
788 ;
789
790 datadecls:
791 lineno_datadecl
792 | errstmt
793 | datadecls lineno_datadecl
794 | lineno_datadecl errstmt
795 ;
796
797 /* We don't allow prefix attributes here because they cause reduce/reduce
798 conflicts: we can't know whether we're parsing a function decl with
799 attribute suffix, or function defn with attribute prefix on first old
800 style parm. */
801 datadecl:
802 typed_declspecs_no_prefix_attr setspecs initdecls ';'
803 { current_declspecs = TREE_VALUE (declspec_stack);
804 prefix_attributes = TREE_PURPOSE (declspec_stack);
805 declspec_stack = TREE_CHAIN (declspec_stack); }
806 | declmods_no_prefix_attr setspecs notype_initdecls ';'
807 { current_declspecs = TREE_VALUE (declspec_stack);
808 prefix_attributes = TREE_PURPOSE (declspec_stack);
809 declspec_stack = TREE_CHAIN (declspec_stack); }
810 | typed_declspecs_no_prefix_attr ';'
811 { shadow_tag_warned ($1, 1);
812 pedwarn ("empty declaration"); }
813 | declmods_no_prefix_attr ';'
814 { pedwarn ("empty declaration"); }
815 ;
816
817 /* This combination which saves a lineno before a decl
818 is the normal thing to use, rather than decl itself.
819 This is to avoid shift/reduce conflicts in contexts
820 where statement labels are allowed. */
821 lineno_decl:
822 save_filename save_lineno decl
823 { }
824 ;
825
826 decls:
827 lineno_decl
828 | errstmt
829 | decls lineno_decl
830 | lineno_decl errstmt
831 ;
832
833 /* records the type and storage class specs to use for processing
834 the declarators that follow.
835 Maintains a stack of outer-level values of current_declspecs,
836 for the sake of parm declarations nested in function declarators. */
837 setspecs: /* empty */
838 { pending_xref_error ();
839 declspec_stack = tree_cons (prefix_attributes,
840 current_declspecs,
841 declspec_stack);
842 split_specs_attrs ($<ttype>0,
843 &current_declspecs, &prefix_attributes); }
844 ;
845
846 /* ??? Yuck. See after_type_declarator. */
847 setattrs: /* empty */
848 { prefix_attributes = chainon (prefix_attributes, $<ttype>0); }
849 ;
850
851 decl:
852 typed_declspecs setspecs initdecls ';'
853 { current_declspecs = TREE_VALUE (declspec_stack);
854 prefix_attributes = TREE_PURPOSE (declspec_stack);
855 declspec_stack = TREE_CHAIN (declspec_stack); }
856 | declmods setspecs notype_initdecls ';'
857 { current_declspecs = TREE_VALUE (declspec_stack);
858 prefix_attributes = TREE_PURPOSE (declspec_stack);
859 declspec_stack = TREE_CHAIN (declspec_stack); }
860 | typed_declspecs setspecs nested_function
861 { current_declspecs = TREE_VALUE (declspec_stack);
862 prefix_attributes = TREE_PURPOSE (declspec_stack);
863 declspec_stack = TREE_CHAIN (declspec_stack); }
864 | declmods setspecs notype_nested_function
865 { current_declspecs = TREE_VALUE (declspec_stack);
866 prefix_attributes = TREE_PURPOSE (declspec_stack);
867 declspec_stack = TREE_CHAIN (declspec_stack); }
868 | typed_declspecs ';'
869 { shadow_tag ($1); }
870 | declmods ';'
871 { pedwarn ("empty declaration"); }
872 | extension decl
873 { RESTORE_WARN_FLAGS ($1); }
874 ;
875
876 /* Declspecs which contain at least one type specifier or typedef name.
877 (Just `const' or `volatile' is not enough.)
878 A typedef'd name following these is taken as a name to be declared.
879 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
880
881 typed_declspecs:
882 typespec reserved_declspecs
883 { $$ = tree_cons (NULL_TREE, $1, $2); }
884 | declmods typespec reserved_declspecs
885 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
886 ;
887
888 reserved_declspecs: /* empty */
889 { $$ = NULL_TREE; }
890 | reserved_declspecs typespecqual_reserved
891 { $$ = tree_cons (NULL_TREE, $2, $1); }
892 | reserved_declspecs SCSPEC
893 { if (extra_warnings)
894 warning ("`%s' is not at beginning of declaration",
895 IDENTIFIER_POINTER ($2));
896 $$ = tree_cons (NULL_TREE, $2, $1); }
897 | reserved_declspecs attributes
898 { $$ = tree_cons ($2, NULL_TREE, $1); }
899 ;
900
901 typed_declspecs_no_prefix_attr:
902 typespec reserved_declspecs_no_prefix_attr
903 { $$ = tree_cons (NULL_TREE, $1, $2); }
904 | declmods_no_prefix_attr typespec reserved_declspecs_no_prefix_attr
905 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
906 ;
907
908 reserved_declspecs_no_prefix_attr:
909 /* empty */
910 { $$ = NULL_TREE; }
911 | reserved_declspecs_no_prefix_attr typespecqual_reserved
912 { $$ = tree_cons (NULL_TREE, $2, $1); }
913 | reserved_declspecs_no_prefix_attr SCSPEC
914 { if (extra_warnings)
915 warning ("`%s' is not at beginning of declaration",
916 IDENTIFIER_POINTER ($2));
917 $$ = tree_cons (NULL_TREE, $2, $1); }
918 ;
919
920 /* List of just storage classes, type modifiers, and prefix attributes.
921 A declaration can start with just this, but then it cannot be used
922 to redeclare a typedef-name.
923 Declspecs have a non-NULL TREE_VALUE, attributes do not. */
924
925 declmods:
926 declmods_no_prefix_attr
927 { $$ = $1; }
928 | attributes
929 { $$ = tree_cons ($1, NULL_TREE, NULL_TREE); }
930 | declmods declmods_no_prefix_attr
931 { $$ = chainon ($2, $1); }
932 | declmods attributes
933 { $$ = tree_cons ($2, NULL_TREE, $1); }
934 ;
935
936 declmods_no_prefix_attr:
937 TYPE_QUAL
938 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE);
939 TREE_STATIC ($$) = 1; }
940 | SCSPEC
941 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
942 | declmods_no_prefix_attr TYPE_QUAL
943 { $$ = tree_cons (NULL_TREE, $2, $1);
944 TREE_STATIC ($$) = 1; }
945 | declmods_no_prefix_attr SCSPEC
946 { if (extra_warnings && TREE_STATIC ($1))
947 warning ("`%s' is not at beginning of declaration",
948 IDENTIFIER_POINTER ($2));
949 $$ = tree_cons (NULL_TREE, $2, $1);
950 TREE_STATIC ($$) = TREE_STATIC ($1); }
951 ;
952
953
954 /* Used instead of declspecs where storage classes are not allowed
955 (that is, for typenames and structure components).
956 Don't accept a typedef-name if anything but a modifier precedes it. */
957
958 typed_typespecs:
959 typespec reserved_typespecquals
960 { $$ = tree_cons (NULL_TREE, $1, $2); }
961 | nonempty_type_quals typespec reserved_typespecquals
962 { $$ = chainon ($3, tree_cons (NULL_TREE, $2, $1)); }
963 ;
964
965 reserved_typespecquals: /* empty */
966 { $$ = NULL_TREE; }
967 | reserved_typespecquals typespecqual_reserved
968 { $$ = tree_cons (NULL_TREE, $2, $1); }
969 ;
970
971 /* A typespec (but not a type qualifier).
972 Once we have seen one of these in a declaration,
973 if a typedef name appears then it is being redeclared. */
974
975 typespec: TYPESPEC
976 | structsp
977 | TYPENAME
978 { /* For a typedef name, record the meaning, not the name.
979 In case of `foo foo, bar;'. */
980 $$ = lookup_name ($1); }
981 ifobjc
982 | CLASSNAME protocolrefs
983 { $$ = get_static_reference ($1, $2); }
984 | OBJECTNAME protocolrefs
985 { $$ = get_object_reference ($2); }
986
987 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>"
988 - nisse@lysator.liu.se */
989 | non_empty_protocolrefs
990 { $$ = get_object_reference ($1); }
991 end ifobjc
992 | TYPEOF '(' expr ')'
993 { $$ = TREE_TYPE ($3); }
994 | TYPEOF '(' typename ')'
995 { $$ = groktypename ($3); }
996 ;
997
998 /* A typespec that is a reserved word, or a type qualifier. */
999
1000 typespecqual_reserved: TYPESPEC
1001 | TYPE_QUAL
1002 | structsp
1003 ;
1004
1005 initdecls:
1006 initdcl
1007 | initdecls ',' initdcl
1008 ;
1009
1010 notype_initdecls:
1011 notype_initdcl
1012 | notype_initdecls ',' initdcl
1013 ;
1014
1015 maybeasm:
1016 /* empty */
1017 { $$ = NULL_TREE; }
1018 | ASM_KEYWORD '(' string ')'
1019 { if (TREE_CHAIN ($3)) $3 = combine_strings ($3);
1020 $$ = $3;
1021 }
1022 ;
1023
1024 initdcl:
1025 declarator maybeasm maybe_attribute '='
1026 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1027 $3, prefix_attributes);
1028 start_init ($<ttype>$, $2, global_bindings_p ()); }
1029 init
1030 /* Note how the declaration of the variable is in effect while its init is parsed! */
1031 { finish_init ();
1032 finish_decl ($<ttype>5, $6, $2); }
1033 | declarator maybeasm maybe_attribute
1034 { tree d = start_decl ($1, current_declspecs, 0,
1035 $3, prefix_attributes);
1036 finish_decl (d, NULL_TREE, $2);
1037 }
1038 ;
1039
1040 notype_initdcl:
1041 notype_declarator maybeasm maybe_attribute '='
1042 { $<ttype>$ = start_decl ($1, current_declspecs, 1,
1043 $3, prefix_attributes);
1044 start_init ($<ttype>$, $2, global_bindings_p ()); }
1045 init
1046 /* Note how the declaration of the variable is in effect while its init is parsed! */
1047 { finish_init ();
1048 decl_attributes ($<ttype>5, $3, prefix_attributes);
1049 finish_decl ($<ttype>5, $6, $2); }
1050 | notype_declarator maybeasm maybe_attribute
1051 { tree d = start_decl ($1, current_declspecs, 0,
1052 $3, prefix_attributes);
1053 finish_decl (d, NULL_TREE, $2); }
1054 ;
1055 /* the * rules are dummies to accept the Apollo extended syntax
1056 so that the header files compile. */
1057 maybe_attribute:
1058 /* empty */
1059 { $$ = NULL_TREE; }
1060 | attributes
1061 { $$ = $1; }
1062 ;
1063
1064 attributes:
1065 attribute
1066 { $$ = $1; }
1067 | attributes attribute
1068 { $$ = chainon ($1, $2); }
1069 ;
1070
1071 attribute:
1072 ATTRIBUTE '(' '(' attribute_list ')' ')'
1073 { $$ = $4; }
1074 ;
1075
1076 attribute_list:
1077 attrib
1078 { $$ = $1; }
1079 | attribute_list ',' attrib
1080 { $$ = chainon ($1, $3); }
1081 ;
1082
1083 attrib:
1084 /* empty */
1085 { $$ = NULL_TREE; }
1086 | any_word
1087 { $$ = build_tree_list ($1, NULL_TREE); }
1088 | any_word '(' IDENTIFIER ')'
1089 { $$ = build_tree_list ($1, build_tree_list (NULL_TREE, $3)); }
1090 | any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
1091 { $$ = build_tree_list ($1, tree_cons (NULL_TREE, $3, $5)); }
1092 | any_word '(' exprlist ')'
1093 { $$ = build_tree_list ($1, $3); }
1094 ;
1095
1096 /* This still leaves out most reserved keywords,
1097 shouldn't we include them? */
1098
1099 any_word:
1100 identifier
1101 | SCSPEC
1102 | TYPESPEC
1103 | TYPE_QUAL
1104 ;
1105 \f
1106 /* Initializers. `init' is the entry point. */
1107
1108 init:
1109 expr_no_commas
1110 | '{'
1111 { really_start_incremental_init (NULL_TREE); }
1112 initlist_maybe_comma '}'
1113 { $$ = pop_init_level (0); }
1114 | error
1115 { $$ = error_mark_node; }
1116 ;
1117
1118 /* `initlist_maybe_comma' is the guts of an initializer in braces. */
1119 initlist_maybe_comma:
1120 /* empty */
1121 { if (pedantic)
1122 pedwarn ("ISO C forbids empty initializer braces"); }
1123 | initlist1 maybecomma
1124 ;
1125
1126 initlist1:
1127 initelt
1128 | initlist1 ',' initelt
1129 ;
1130
1131 /* `initelt' is a single element of an initializer.
1132 It may use braces. */
1133 initelt:
1134 designator_list '=' initval
1135 { if (pedantic && ! flag_isoc99)
1136 pedwarn ("ISO C89 forbids specifying subobject to initialize"); }
1137 | designator initval
1138 { if (pedantic)
1139 pedwarn ("obsolete use of designated initializer without `='"); }
1140 | identifier ':'
1141 { set_init_label ($1);
1142 if (pedantic)
1143 pedwarn ("obsolete use of designated initializer with `:'"); }
1144 initval
1145 | initval
1146 ;
1147
1148 initval:
1149 '{'
1150 { push_init_level (0); }
1151 initlist_maybe_comma '}'
1152 { process_init_element (pop_init_level (0)); }
1153 | expr_no_commas
1154 { process_init_element ($1); }
1155 | error
1156 ;
1157
1158 designator_list:
1159 designator
1160 | designator_list designator
1161 ;
1162
1163 designator:
1164 '.' identifier
1165 { set_init_label ($2); }
1166 /* These are for labeled elements. The syntax for an array element
1167 initializer conflicts with the syntax for an Objective-C message,
1168 so don't include these productions in the Objective-C grammar. */
1169 ifc
1170 | '[' expr_no_commas ELLIPSIS expr_no_commas ']'
1171 { set_init_index ($2, $4);
1172 if (pedantic)
1173 pedwarn ("ISO C forbids specifying range of elements to initialize"); }
1174 | '[' expr_no_commas ']'
1175 { set_init_index ($2, NULL_TREE); }
1176 end ifc
1177 ;
1178 \f
1179 nested_function:
1180 declarator
1181 { if (pedantic)
1182 pedwarn ("ISO C forbids nested functions");
1183
1184 push_function_context ();
1185 if (! start_function (current_declspecs, $1,
1186 prefix_attributes, NULL_TREE))
1187 {
1188 pop_function_context ();
1189 YYERROR1;
1190 }
1191 }
1192 old_style_parm_decls
1193 { store_parm_decls (); }
1194 /* This used to use compstmt_or_error.
1195 That caused a bug with input `f(g) int g {}',
1196 where the use of YYERROR1 above caused an error
1197 which then was handled by compstmt_or_error.
1198 There followed a repeated execution of that same rule,
1199 which called YYERROR1 again, and so on. */
1200 compstmt
1201 { tree decl = current_function_decl;
1202 finish_function (1);
1203 pop_function_context ();
1204 add_decl_stmt (decl); }
1205 ;
1206
1207 notype_nested_function:
1208 notype_declarator
1209 { if (pedantic)
1210 pedwarn ("ISO C forbids nested functions");
1211
1212 push_function_context ();
1213 if (! start_function (current_declspecs, $1,
1214 prefix_attributes, NULL_TREE))
1215 {
1216 pop_function_context ();
1217 YYERROR1;
1218 }
1219 }
1220 old_style_parm_decls
1221 { store_parm_decls (); }
1222 /* This used to use compstmt_or_error.
1223 That caused a bug with input `f(g) int g {}',
1224 where the use of YYERROR1 above caused an error
1225 which then was handled by compstmt_or_error.
1226 There followed a repeated execution of that same rule,
1227 which called YYERROR1 again, and so on. */
1228 compstmt
1229 { tree decl = current_function_decl;
1230 finish_function (1);
1231 pop_function_context ();
1232 add_decl_stmt (decl); }
1233 ;
1234
1235 /* Any kind of declarator (thus, all declarators allowed
1236 after an explicit typespec). */
1237
1238 declarator:
1239 after_type_declarator
1240 | notype_declarator
1241 ;
1242
1243 /* A declarator that is allowed only after an explicit typespec. */
1244
1245 after_type_declarator:
1246 '(' after_type_declarator ')'
1247 { $$ = $2; }
1248 | after_type_declarator '(' parmlist_or_identifiers %prec '.'
1249 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1250 /* | after_type_declarator '(' error ')' %prec '.'
1251 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1252 poplevel (0, 0, 0); } */
1253 | after_type_declarator '[' expr ']' %prec '.'
1254 { $$ = build_nt (ARRAY_REF, $1, $3); }
1255 | after_type_declarator '[' ']' %prec '.'
1256 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1257 | '*' type_quals after_type_declarator %prec UNARY
1258 { $$ = make_pointer_declarator ($2, $3); }
1259 /* ??? Yuck. setattrs is a quick hack. We can't use
1260 prefix_attributes because $1 only applies to this
1261 declarator. We assume setspecs has already been done.
1262 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1263 attributes could be recognized here or in `attributes'). */
1264 | attributes setattrs after_type_declarator
1265 { $$ = $3; }
1266 | TYPENAME
1267 ifobjc
1268 | OBJECTNAME
1269 end ifobjc
1270 ;
1271
1272 /* Kinds of declarator that can appear in a parameter list
1273 in addition to notype_declarator. This is like after_type_declarator
1274 but does not allow a typedef name in parentheses as an identifier
1275 (because it would conflict with a function with that typedef as arg). */
1276
1277 parm_declarator:
1278 parm_declarator '(' parmlist_or_identifiers %prec '.'
1279 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1280 /* | parm_declarator '(' error ')' %prec '.'
1281 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1282 poplevel (0, 0, 0); } */
1283 ifc
1284 | parm_declarator '[' '*' ']' %prec '.'
1285 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1286 if (! flag_isoc99)
1287 error ("`[*]' in parameter declaration only allowed in ISO C 99");
1288 }
1289 end ifc
1290 | parm_declarator '[' expr ']' %prec '.'
1291 { $$ = build_nt (ARRAY_REF, $1, $3); }
1292 | parm_declarator '[' ']' %prec '.'
1293 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1294 | '*' type_quals parm_declarator %prec UNARY
1295 { $$ = make_pointer_declarator ($2, $3); }
1296 /* ??? Yuck. setattrs is a quick hack. We can't use
1297 prefix_attributes because $1 only applies to this
1298 declarator. We assume setspecs has already been done.
1299 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1300 attributes could be recognized here or in `attributes'). */
1301 | attributes setattrs parm_declarator
1302 { $$ = $3; }
1303 | TYPENAME
1304 ;
1305
1306 /* A declarator allowed whether or not there has been
1307 an explicit typespec. These cannot redeclare a typedef-name. */
1308
1309 notype_declarator:
1310 notype_declarator '(' parmlist_or_identifiers %prec '.'
1311 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1312 /* | notype_declarator '(' error ')' %prec '.'
1313 { $$ = build_nt (CALL_EXPR, $1, NULL_TREE, NULL_TREE);
1314 poplevel (0, 0, 0); } */
1315 | '(' notype_declarator ')'
1316 { $$ = $2; }
1317 | '*' type_quals notype_declarator %prec UNARY
1318 { $$ = make_pointer_declarator ($2, $3); }
1319 ifc
1320 | notype_declarator '[' '*' ']' %prec '.'
1321 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE);
1322 if (! flag_isoc99)
1323 error ("`[*]' in parameter declaration only allowed in ISO C 99");
1324 }
1325 end ifc
1326 | notype_declarator '[' expr ']' %prec '.'
1327 { $$ = build_nt (ARRAY_REF, $1, $3); }
1328 | notype_declarator '[' ']' %prec '.'
1329 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1330 /* ??? Yuck. setattrs is a quick hack. We can't use
1331 prefix_attributes because $1 only applies to this
1332 declarator. We assume setspecs has already been done.
1333 setattrs also avoids 5 reduce/reduce conflicts (otherwise multiple
1334 attributes could be recognized here or in `attributes'). */
1335 | attributes setattrs notype_declarator
1336 { $$ = $3; }
1337 | IDENTIFIER
1338 ;
1339
1340 struct_head:
1341 STRUCT
1342 { $$ = NULL_TREE; }
1343 | STRUCT attributes
1344 { $$ = $2; }
1345 ;
1346
1347 union_head:
1348 UNION
1349 { $$ = NULL_TREE; }
1350 | UNION attributes
1351 { $$ = $2; }
1352 ;
1353
1354 enum_head:
1355 ENUM
1356 { $$ = NULL_TREE; }
1357 | ENUM attributes
1358 { $$ = $2; }
1359 ;
1360
1361 structsp:
1362 struct_head identifier '{'
1363 { $$ = start_struct (RECORD_TYPE, $2);
1364 /* Start scope of tag before parsing components. */
1365 }
1366 component_decl_list '}' maybe_attribute
1367 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1368 | struct_head '{' component_decl_list '}' maybe_attribute
1369 { $$ = finish_struct (start_struct (RECORD_TYPE, NULL_TREE),
1370 $3, chainon ($1, $5));
1371 }
1372 | struct_head identifier
1373 { $$ = xref_tag (RECORD_TYPE, $2); }
1374 | union_head identifier '{'
1375 { $$ = start_struct (UNION_TYPE, $2); }
1376 component_decl_list '}' maybe_attribute
1377 { $$ = finish_struct ($<ttype>4, $5, chainon ($1, $7)); }
1378 | union_head '{' component_decl_list '}' maybe_attribute
1379 { $$ = finish_struct (start_struct (UNION_TYPE, NULL_TREE),
1380 $3, chainon ($1, $5));
1381 }
1382 | union_head identifier
1383 { $$ = xref_tag (UNION_TYPE, $2); }
1384 | enum_head identifier '{'
1385 { $$ = start_enum ($2); }
1386 enumlist maybecomma_warn '}' maybe_attribute
1387 { $$ = finish_enum ($<ttype>4, nreverse ($5),
1388 chainon ($1, $8)); }
1389 | enum_head '{'
1390 { $$ = start_enum (NULL_TREE); }
1391 enumlist maybecomma_warn '}' maybe_attribute
1392 { $$ = finish_enum ($<ttype>3, nreverse ($4),
1393 chainon ($1, $7)); }
1394 | enum_head identifier
1395 { $$ = xref_tag (ENUMERAL_TYPE, $2); }
1396 ;
1397
1398 maybecomma:
1399 /* empty */
1400 | ','
1401 ;
1402
1403 maybecomma_warn:
1404 /* empty */
1405 | ','
1406 { if (pedantic && ! flag_isoc99)
1407 pedwarn ("comma at end of enumerator list"); }
1408 ;
1409
1410 component_decl_list:
1411 component_decl_list2
1412 { $$ = $1; }
1413 | component_decl_list2 component_decl
1414 { $$ = chainon ($1, $2);
1415 pedwarn ("no semicolon at end of struct or union"); }
1416 ;
1417
1418 component_decl_list2: /* empty */
1419 { $$ = NULL_TREE; }
1420 | component_decl_list2 component_decl ';'
1421 { $$ = chainon ($1, $2); }
1422 | component_decl_list2 ';'
1423 { if (pedantic)
1424 pedwarn ("extra semicolon in struct or union specified"); }
1425 ifobjc
1426 /* foo(sizeof(struct{ @defs(ClassName)})); */
1427 | DEFS '(' CLASSNAME ')'
1428 {
1429 tree interface = lookup_interface ($3);
1430
1431 if (interface)
1432 $$ = get_class_ivars (interface);
1433 else
1434 {
1435 error ("Cannot find interface declaration for `%s'",
1436 IDENTIFIER_POINTER ($3));
1437 $$ = NULL_TREE;
1438 }
1439 }
1440 end ifobjc
1441 ;
1442
1443 /* There is a shift-reduce conflict here, because `components' may
1444 start with a `typename'. It happens that shifting (the default resolution)
1445 does the right thing, because it treats the `typename' as part of
1446 a `typed_typespecs'.
1447
1448 It is possible that this same technique would allow the distinction
1449 between `notype_initdecls' and `initdecls' to be eliminated.
1450 But I am being cautious and not trying it. */
1451
1452 component_decl:
1453 typed_typespecs setspecs components
1454 { $$ = $3;
1455 current_declspecs = TREE_VALUE (declspec_stack);
1456 prefix_attributes = TREE_PURPOSE (declspec_stack);
1457 declspec_stack = TREE_CHAIN (declspec_stack); }
1458 | typed_typespecs setspecs save_filename save_lineno maybe_attribute
1459 {
1460 /* Support for unnamed structs or unions as members of
1461 structs or unions (which is [a] useful and [b] supports
1462 MS P-SDK). */
1463 if (pedantic)
1464 pedwarn ("ISO C doesn't support unnamed structs/unions");
1465
1466 $$ = grokfield($3, $4, NULL, current_declspecs, NULL_TREE);
1467 current_declspecs = TREE_VALUE (declspec_stack);
1468 prefix_attributes = TREE_PURPOSE (declspec_stack);
1469 declspec_stack = TREE_CHAIN (declspec_stack);
1470 }
1471 | nonempty_type_quals setspecs components
1472 { $$ = $3;
1473 current_declspecs = TREE_VALUE (declspec_stack);
1474 prefix_attributes = TREE_PURPOSE (declspec_stack);
1475 declspec_stack = TREE_CHAIN (declspec_stack); }
1476 | nonempty_type_quals
1477 { if (pedantic)
1478 pedwarn ("ISO C forbids member declarations with no members");
1479 shadow_tag($1);
1480 $$ = NULL_TREE; }
1481 | error
1482 { $$ = NULL_TREE; }
1483 | extension component_decl
1484 { $$ = $2;
1485 RESTORE_WARN_FLAGS ($1); }
1486 ;
1487
1488 components:
1489 component_declarator
1490 | components ',' component_declarator
1491 { $$ = chainon ($1, $3); }
1492 ;
1493
1494 component_declarator:
1495 save_filename save_lineno declarator maybe_attribute
1496 { $$ = grokfield ($1, $2, $3, current_declspecs, NULL_TREE);
1497 decl_attributes ($$, $4, prefix_attributes); }
1498 | save_filename save_lineno
1499 declarator ':' expr_no_commas maybe_attribute
1500 { $$ = grokfield ($1, $2, $3, current_declspecs, $5);
1501 decl_attributes ($$, $6, prefix_attributes); }
1502 | save_filename save_lineno ':' expr_no_commas maybe_attribute
1503 { $$ = grokfield ($1, $2, NULL_TREE, current_declspecs, $4);
1504 decl_attributes ($$, $5, prefix_attributes); }
1505 ;
1506
1507 /* We chain the enumerators in reverse order.
1508 They are put in forward order where enumlist is used.
1509 (The order used to be significant, but no longer is so.
1510 However, we still maintain the order, just to be clean.) */
1511
1512 enumlist:
1513 enumerator
1514 | enumlist ',' enumerator
1515 { if ($1 == error_mark_node)
1516 $$ = $1;
1517 else
1518 $$ = chainon ($3, $1); }
1519 | error
1520 { $$ = error_mark_node; }
1521 ;
1522
1523
1524 enumerator:
1525 identifier
1526 { $$ = build_enumerator ($1, NULL_TREE); }
1527 | identifier '=' expr_no_commas
1528 { $$ = build_enumerator ($1, $3); }
1529 ;
1530
1531 typename:
1532 typed_typespecs absdcl
1533 { $$ = build_tree_list ($1, $2); }
1534 | nonempty_type_quals absdcl
1535 { $$ = build_tree_list ($1, $2); }
1536 ;
1537
1538 absdcl: /* an absolute declarator */
1539 /* empty */
1540 { $$ = NULL_TREE; }
1541 | absdcl1
1542 ;
1543
1544 nonempty_type_quals:
1545 TYPE_QUAL
1546 { $$ = tree_cons (NULL_TREE, $1, NULL_TREE); }
1547 | nonempty_type_quals TYPE_QUAL
1548 { $$ = tree_cons (NULL_TREE, $2, $1); }
1549 ;
1550
1551 type_quals:
1552 /* empty */
1553 { $$ = NULL_TREE; }
1554 | type_quals TYPE_QUAL
1555 { $$ = tree_cons (NULL_TREE, $2, $1); }
1556 ;
1557
1558 absdcl1: /* a nonempty absolute declarator */
1559 '(' absdcl1 ')'
1560 { $$ = $2; }
1561 /* `(typedef)1' is `int'. */
1562 | '*' type_quals absdcl1 %prec UNARY
1563 { $$ = make_pointer_declarator ($2, $3); }
1564 | '*' type_quals %prec UNARY
1565 { $$ = make_pointer_declarator ($2, NULL_TREE); }
1566 | absdcl1 '(' parmlist %prec '.'
1567 { $$ = build_nt (CALL_EXPR, $1, $3, NULL_TREE); }
1568 | absdcl1 '[' expr ']' %prec '.'
1569 { $$ = build_nt (ARRAY_REF, $1, $3); }
1570 | absdcl1 '[' ']' %prec '.'
1571 { $$ = build_nt (ARRAY_REF, $1, NULL_TREE); }
1572 | '(' parmlist %prec '.'
1573 { $$ = build_nt (CALL_EXPR, NULL_TREE, $2, NULL_TREE); }
1574 | '[' expr ']' %prec '.'
1575 { $$ = build_nt (ARRAY_REF, NULL_TREE, $2); }
1576 | '[' ']' %prec '.'
1577 { $$ = build_nt (ARRAY_REF, NULL_TREE, NULL_TREE); }
1578 /* ??? It appears we have to support attributes here, however
1579 using prefix_attributes is wrong. */
1580 | attributes setattrs absdcl1
1581 { $$ = $3; }
1582 ;
1583
1584 /* at least one statement, the first of which parses without error. */
1585 /* stmts is used only after decls, so an invalid first statement
1586 is actually regarded as an invalid decl and part of the decls. */
1587
1588 stmts:
1589 lineno_stmt_or_labels
1590 {
1591 if (pedantic && $1)
1592 pedwarn ("ISO C forbids label at end of compound statement");
1593 }
1594 ;
1595
1596 lineno_stmt_or_labels:
1597 lineno_stmt_or_label
1598 | lineno_stmt_or_labels lineno_stmt_or_label
1599 { $$ = $2; }
1600 | lineno_stmt_or_labels errstmt
1601 { $$ = 0; }
1602 ;
1603
1604 xstmts:
1605 /* empty */
1606 | stmts
1607 ;
1608
1609 errstmt: error ';'
1610 ;
1611
1612 pushlevel: /* empty */
1613 { pushlevel (0);
1614 clear_last_expr ();
1615 add_scope_stmt (/*begin_p=*/1, /*partial_p=*/0);
1616 ifobjc
1617 if (objc_method_context)
1618 add_objc_decls ();
1619 end ifobjc
1620 }
1621 ;
1622
1623 poplevel: /* empty */
1624 { $$ = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0); }
1625
1626 /* Read zero or more forward-declarations for labels
1627 that nested functions can jump to. */
1628 maybe_label_decls:
1629 /* empty */
1630 | label_decls
1631 { if (pedantic)
1632 pedwarn ("ISO C forbids label declarations"); }
1633 ;
1634
1635 label_decls:
1636 label_decl
1637 | label_decls label_decl
1638 ;
1639
1640 label_decl:
1641 LABEL identifiers_or_typenames ';'
1642 { tree link;
1643 for (link = $2; link; link = TREE_CHAIN (link))
1644 {
1645 tree label = shadow_label (TREE_VALUE (link));
1646 C_DECLARED_LABEL_FLAG (label) = 1;
1647 add_decl_stmt (label);
1648 }
1649 }
1650 ;
1651
1652 /* This is the body of a function definition.
1653 It causes syntax errors to ignore to the next openbrace. */
1654 compstmt_or_error:
1655 compstmt
1656 {}
1657 | error compstmt
1658 ;
1659
1660 compstmt_start: '{' { compstmt_count++;
1661 $$ = c_begin_compound_stmt (); }
1662
1663 compstmt_nostart: '}'
1664 { $$ = convert (void_type_node, integer_zero_node); }
1665 | pushlevel maybe_label_decls decls xstmts '}' poplevel
1666 { $$ = poplevel (1, 1, 0);
1667 SCOPE_STMT_BLOCK (TREE_PURPOSE ($6))
1668 = SCOPE_STMT_BLOCK (TREE_VALUE ($6))
1669 = $$; }
1670 | pushlevel maybe_label_decls error '}' poplevel
1671 { $$ = poplevel (kept_level_p (), 0, 0);
1672 SCOPE_STMT_BLOCK (TREE_PURPOSE ($5))
1673 = SCOPE_STMT_BLOCK (TREE_VALUE ($5))
1674 = $$; }
1675 | pushlevel maybe_label_decls stmts '}' poplevel
1676 { $$ = poplevel (kept_level_p (), 0, 0);
1677 SCOPE_STMT_BLOCK (TREE_PURPOSE ($5))
1678 = SCOPE_STMT_BLOCK (TREE_VALUE ($5))
1679 = $$; }
1680 ;
1681
1682 compstmt_primary_start:
1683 '(' '{'
1684 { if (current_function_decl == 0)
1685 {
1686 error ("braced-group within expression allowed only inside a function");
1687 YYERROR;
1688 }
1689 /* We must force a BLOCK for this level
1690 so that, if it is not expanded later,
1691 there is a way to turn off the entire subtree of blocks
1692 that are contained in it. */
1693 keep_next_level ();
1694 push_label_level ();
1695 compstmt_count++;
1696 $$ = add_stmt (build_stmt (COMPOUND_STMT, last_tree));
1697 }
1698
1699 compstmt: compstmt_start compstmt_nostart
1700 { RECHAIN_STMTS ($1, COMPOUND_BODY ($1));
1701 $$ = $2; }
1702 ;
1703
1704 /* Value is number of statements counted as of the closeparen. */
1705 simple_if:
1706 if_prefix lineno_labeled_stmt
1707 { c_finish_then (); }
1708 /* Make sure c_expand_end_cond is run once
1709 for each call to c_expand_start_cond.
1710 Otherwise a crash is likely. */
1711 | if_prefix error
1712 ;
1713
1714 if_prefix:
1715 IF '(' expr ')'
1716 { c_expand_start_cond (truthvalue_conversion ($3),
1717 compstmt_count);
1718 $<itype>$ = stmt_count;
1719 if_stmt_file = $<filename>-1;
1720 if_stmt_line = $<lineno>0; }
1721 ;
1722
1723 /* This is a subroutine of stmt.
1724 It is used twice, once for valid DO statements
1725 and once for catching errors in parsing the end test. */
1726 do_stmt_start:
1727 DO
1728 { stmt_count++;
1729 compstmt_count++;
1730 $<ttype>$
1731 = add_stmt (build_stmt (DO_STMT, NULL_TREE,
1732 NULL_TREE));
1733 /* In the event that a parse error prevents
1734 parsing the complete do-statement, set the
1735 condition now. Otherwise, we can get crashes at
1736 RTL-generation time. */
1737 DO_COND ($<ttype>$) = error_mark_node; }
1738 lineno_labeled_stmt WHILE
1739 { $$ = $<ttype>2;
1740 RECHAIN_STMTS ($$, DO_BODY ($$)); }
1741 ;
1742
1743 /* The forced readahead in here is because we might be at the end of a
1744 line, and the line and file won't be bumped until yylex absorbs the
1745 first token on the next line. */
1746 save_filename:
1747 { if (yychar == YYEMPTY)
1748 yychar = YYLEX;
1749 $$ = input_filename; }
1750 ;
1751
1752 save_lineno:
1753 { if (yychar == YYEMPTY)
1754 yychar = YYLEX;
1755 $$ = lineno; }
1756 ;
1757
1758 lineno_labeled_stmt:
1759 save_filename save_lineno stmt
1760 { }
1761 /* | save_filename save_lineno error
1762 { }
1763 */
1764 | save_filename save_lineno label lineno_labeled_stmt
1765 { }
1766 ;
1767
1768 lineno_stmt_or_label:
1769 save_filename save_lineno stmt_or_label
1770 { $$ = $3; }
1771 ;
1772
1773 stmt_or_label:
1774 stmt
1775 { $$ = 0; }
1776 | label
1777 { $$ = 1; }
1778 ;
1779
1780 /* Parse a single real statement, not including any labels. */
1781 stmt:
1782 compstmt
1783 { stmt_count++; }
1784 | expr ';'
1785 { stmt_count++;
1786 c_expand_expr_stmt ($1); }
1787 | simple_if ELSE
1788 { c_expand_start_else ();
1789 $<itype>1 = stmt_count; }
1790 lineno_labeled_stmt
1791 { c_finish_else ();
1792 c_expand_end_cond ();
1793 if (extra_warnings && stmt_count == $<itype>1)
1794 warning ("empty body in an else-statement"); }
1795 | simple_if %prec IF
1796 { c_expand_end_cond ();
1797 /* This warning is here instead of in simple_if, because we
1798 do not want a warning if an empty if is followed by an
1799 else statement. Increment stmt_count so we don't
1800 give a second error if this is a nested `if'. */
1801 if (extra_warnings && stmt_count++ == $<itype>1)
1802 warning_with_file_and_line (if_stmt_file, if_stmt_line,
1803 "empty body in an if-statement"); }
1804 /* Make sure c_expand_end_cond is run once
1805 for each call to c_expand_start_cond.
1806 Otherwise a crash is likely. */
1807 | simple_if ELSE error
1808 { c_expand_end_cond (); }
1809 | WHILE
1810 { stmt_count++; }
1811 '(' expr ')'
1812 { $4 = truthvalue_conversion ($4);
1813 $<ttype>$
1814 = add_stmt (build_stmt (WHILE_STMT, $4, NULL_TREE)); }
1815 lineno_labeled_stmt
1816 { RECHAIN_STMTS ($<ttype>6, WHILE_BODY ($<ttype>6)); }
1817 | do_stmt_start
1818 '(' expr ')' ';'
1819 { DO_COND ($1) = truthvalue_conversion ($3); }
1820 | do_stmt_start error
1821 { }
1822 | FOR
1823 '(' xexpr ';'
1824 { stmt_count++;
1825 $3 = build_stmt (EXPR_STMT, $3);
1826 $<ttype>$ = build_stmt (FOR_STMT, $3, NULL_TREE,
1827 NULL_TREE, NULL_TREE);
1828 add_stmt ($<ttype>$);
1829 }
1830 xexpr ';'
1831 { FOR_COND ($<ttype>5) = $6; }
1832 xexpr ')'
1833 { FOR_EXPR ($<ttype>5) = $9; }
1834 lineno_labeled_stmt
1835 { RECHAIN_STMTS ($<ttype>5, FOR_BODY ($<ttype>5)); }
1836 | SWITCH '(' expr ')'
1837 { stmt_count++;
1838 $<ttype>$ = c_start_case ($3); }
1839 lineno_labeled_stmt
1840 { c_finish_case (); }
1841 | BREAK ';'
1842 { stmt_count++;
1843 add_stmt (build_break_stmt ()); }
1844 | CONTINUE ';'
1845 { stmt_count++;
1846 add_stmt (build_continue_stmt ()); }
1847 | RETURN ';'
1848 { stmt_count++;
1849 c_expand_return (NULL_TREE); }
1850 | RETURN expr ';'
1851 { stmt_count++;
1852 c_expand_return ($2); }
1853 | ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
1854 { stmt_count++;
1855 STRIP_NOPS ($4);
1856 if ((TREE_CODE ($4) == ADDR_EXPR
1857 && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
1858 || TREE_CODE ($4) == STRING_CST)
1859 {
1860 if (TREE_CODE ($4) == ADDR_EXPR)
1861 $4 = TREE_OPERAND ($4, 0);
1862 if (TREE_CHAIN ($4))
1863 $4 = combine_strings ($4);
1864 add_stmt (build_stmt (ASM_STMT, NULL_TREE, $4,
1865 NULL_TREE, NULL_TREE, NULL_TREE));
1866 }
1867 else
1868 error ("argument of `asm' is not a constant string"); }
1869 /* This is the case with just output operands. */
1870 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
1871 { stmt_count++;
1872 c_expand_asm_operands ($4, $6, NULL_TREE, NULL_TREE,
1873 $2 == ridpointers[(int)RID_VOLATILE],
1874 input_filename, lineno); }
1875 /* This is the case with input operands as well. */
1876 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':' asm_operands ')' ';'
1877 { stmt_count++;
1878 c_expand_asm_operands ($4, $6, $8, NULL_TREE,
1879 $2 == ridpointers[(int)RID_VOLATILE],
1880 input_filename, lineno); }
1881 /* This is the case with clobbered registers as well. */
1882 | ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ':'
1883 asm_operands ':' asm_clobbers ')' ';'
1884 { stmt_count++;
1885 c_expand_asm_operands ($4, $6, $8, $10,
1886 $2 == ridpointers[(int)RID_VOLATILE],
1887 input_filename, lineno); }
1888 | GOTO identifier ';'
1889 { tree decl;
1890 stmt_count++;
1891 decl = lookup_label ($2);
1892 if (decl != 0)
1893 {
1894 TREE_USED (decl) = 1;
1895 add_stmt (build_stmt (GOTO_STMT, decl));
1896 }
1897 }
1898 | GOTO '*' expr ';'
1899 { if (pedantic)
1900 pedwarn ("ISO C forbids `goto *expr;'");
1901 stmt_count++;
1902 $3 = convert (ptr_type_node, $3);
1903 add_stmt (build_stmt (GOTO_STMT, $3)); }
1904 | ';'
1905 ;
1906
1907 /* Any kind of label, including jump labels and case labels.
1908 ANSI C accepts labels only before statements, but we allow them
1909 also at the end of a compound statement. */
1910
1911 label: CASE expr_no_commas ':'
1912 { stmt_count++;
1913 do_case ($2, NULL_TREE); }
1914 | CASE expr_no_commas ELLIPSIS expr_no_commas ':'
1915 { stmt_count++;
1916 do_case ($2, $4); }
1917 | DEFAULT ':'
1918 { stmt_count++;
1919 do_case (NULL_TREE, NULL_TREE); }
1920 | identifier save_filename save_lineno ':' maybe_attribute
1921 { tree label = define_label ($2, $3, $1);
1922 stmt_count++;
1923 if (label)
1924 {
1925 decl_attributes (label, $5, NULL_TREE);
1926 add_stmt (build_stmt (LABEL_STMT, label));
1927 }
1928 }
1929 ;
1930
1931 /* Either a type-qualifier or nothing. First thing in an `asm' statement. */
1932
1933 maybe_type_qual:
1934 /* empty */
1935 { emit_line_note (input_filename, lineno);
1936 $$ = NULL_TREE; }
1937 | TYPE_QUAL
1938 { emit_line_note (input_filename, lineno); }
1939 ;
1940
1941 xexpr:
1942 /* empty */
1943 { $$ = NULL_TREE; }
1944 | expr
1945 ;
1946
1947 /* These are the operands other than the first string and colon
1948 in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
1949 asm_operands: /* empty */
1950 { $$ = NULL_TREE; }
1951 | nonnull_asm_operands
1952 ;
1953
1954 nonnull_asm_operands:
1955 asm_operand
1956 | nonnull_asm_operands ',' asm_operand
1957 { $$ = chainon ($1, $3); }
1958 ;
1959
1960 asm_operand:
1961 STRING '(' expr ')'
1962 { $$ = build_tree_list ($1, $3); }
1963 ;
1964
1965 asm_clobbers:
1966 string
1967 { $$ = tree_cons (NULL_TREE, combine_strings ($1), NULL_TREE); }
1968 | asm_clobbers ',' string
1969 { $$ = tree_cons (NULL_TREE, combine_strings ($3), $1); }
1970 ;
1971 \f
1972 /* This is what appears inside the parens in a function declarator.
1973 Its value is a list of ..._TYPE nodes. */
1974 parmlist:
1975 { pushlevel (0);
1976 clear_parm_order ();
1977 declare_parm_level (0); }
1978 parmlist_1
1979 { $$ = $2;
1980 parmlist_tags_warning ();
1981 poplevel (0, 0, 0); }
1982 ;
1983
1984 parmlist_1:
1985 parmlist_2 ')'
1986 | parms ';'
1987 { tree parm;
1988 if (pedantic)
1989 pedwarn ("ISO C forbids forward parameter declarations");
1990 /* Mark the forward decls as such. */
1991 for (parm = getdecls (); parm; parm = TREE_CHAIN (parm))
1992 TREE_ASM_WRITTEN (parm) = 1;
1993 clear_parm_order (); }
1994 parmlist_1
1995 { $$ = $4; }
1996 | error ')'
1997 { $$ = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); }
1998 ;
1999
2000 /* This is what appears inside the parens in a function declarator.
2001 Is value is represented in the format that grokdeclarator expects. */
2002 parmlist_2: /* empty */
2003 { $$ = get_parm_info (0); }
2004 | ELLIPSIS
2005 { $$ = get_parm_info (0);
2006 /* Gcc used to allow this as an extension. However, it does
2007 not work for all targets, and thus has been disabled.
2008 Also, since func (...) and func () are indistinguishable,
2009 it caused problems with the code in expand_builtin which
2010 tries to verify that BUILT_IN_NEXT_ARG is being used
2011 correctly. */
2012 error ("ISO C requires a named argument before `...'");
2013 }
2014 | parms
2015 { $$ = get_parm_info (1); }
2016 | parms ',' ELLIPSIS
2017 { $$ = get_parm_info (0); }
2018 ;
2019
2020 parms:
2021 parm
2022 { push_parm_decl ($1); }
2023 | parms ',' parm
2024 { push_parm_decl ($3); }
2025 ;
2026
2027 /* A single parameter declaration or parameter type name,
2028 as found in a parmlist. */
2029 parm:
2030 typed_declspecs setspecs parm_declarator maybe_attribute
2031 { $$ = build_tree_list (build_tree_list (current_declspecs,
2032 $3),
2033 build_tree_list (prefix_attributes,
2034 $4));
2035 current_declspecs = TREE_VALUE (declspec_stack);
2036 prefix_attributes = TREE_PURPOSE (declspec_stack);
2037 declspec_stack = TREE_CHAIN (declspec_stack); }
2038 | typed_declspecs setspecs notype_declarator maybe_attribute
2039 { $$ = build_tree_list (build_tree_list (current_declspecs,
2040 $3),
2041 build_tree_list (prefix_attributes,
2042 $4));
2043 current_declspecs = TREE_VALUE (declspec_stack);
2044 prefix_attributes = TREE_PURPOSE (declspec_stack);
2045 declspec_stack = TREE_CHAIN (declspec_stack); }
2046 | typed_declspecs setspecs absdcl maybe_attribute
2047 { $$ = build_tree_list (build_tree_list (current_declspecs,
2048 $3),
2049 build_tree_list (prefix_attributes,
2050 $4));
2051 current_declspecs = TREE_VALUE (declspec_stack);
2052 prefix_attributes = TREE_PURPOSE (declspec_stack);
2053 declspec_stack = TREE_CHAIN (declspec_stack); }
2054 | declmods setspecs notype_declarator maybe_attribute
2055 { $$ = build_tree_list (build_tree_list (current_declspecs,
2056 $3),
2057 build_tree_list (prefix_attributes,
2058 $4));
2059 current_declspecs = TREE_VALUE (declspec_stack);
2060 prefix_attributes = TREE_PURPOSE (declspec_stack);
2061 declspec_stack = TREE_CHAIN (declspec_stack); }
2062
2063 | declmods setspecs absdcl maybe_attribute
2064 { $$ = build_tree_list (build_tree_list (current_declspecs,
2065 $3),
2066 build_tree_list (prefix_attributes,
2067 $4));
2068 current_declspecs = TREE_VALUE (declspec_stack);
2069 prefix_attributes = TREE_PURPOSE (declspec_stack);
2070 declspec_stack = TREE_CHAIN (declspec_stack); }
2071 ;
2072
2073 /* This is used in a function definition
2074 where either a parmlist or an identifier list is ok.
2075 Its value is a list of ..._TYPE nodes or a list of identifiers. */
2076 parmlist_or_identifiers:
2077 { pushlevel (0);
2078 clear_parm_order ();
2079 declare_parm_level (1); }
2080 parmlist_or_identifiers_1
2081 { $$ = $2;
2082 parmlist_tags_warning ();
2083 poplevel (0, 0, 0); }
2084 ;
2085
2086 parmlist_or_identifiers_1:
2087 parmlist_1
2088 | identifiers ')'
2089 { tree t;
2090 for (t = $1; t; t = TREE_CHAIN (t))
2091 if (TREE_VALUE (t) == NULL_TREE)
2092 error ("`...' in old-style identifier list");
2093 $$ = tree_cons (NULL_TREE, NULL_TREE, $1); }
2094 ;
2095
2096 /* A nonempty list of identifiers. */
2097 identifiers:
2098 IDENTIFIER
2099 { $$ = build_tree_list (NULL_TREE, $1); }
2100 | identifiers ',' IDENTIFIER
2101 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2102 ;
2103
2104 /* A nonempty list of identifiers, including typenames. */
2105 identifiers_or_typenames:
2106 identifier
2107 { $$ = build_tree_list (NULL_TREE, $1); }
2108 | identifiers_or_typenames ',' identifier
2109 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2110 ;
2111
2112 extension:
2113 EXTENSION
2114 { $$ = SAVE_WARN_FLAGS();
2115 pedantic = 0;
2116 warn_pointer_arith = 0; }
2117 ;
2118 \f
2119 ifobjc
2120 /* Objective-C productions. */
2121
2122 objcdef:
2123 classdef
2124 | classdecl
2125 | aliasdecl
2126 | protocoldef
2127 | methoddef
2128 | END
2129 {
2130 if (objc_implementation_context)
2131 {
2132 finish_class (objc_implementation_context);
2133 objc_ivar_chain = NULL_TREE;
2134 objc_implementation_context = NULL_TREE;
2135 }
2136 else
2137 warning ("`@end' must appear in an implementation context");
2138 }
2139 ;
2140
2141 /* A nonempty list of identifiers. */
2142 identifier_list:
2143 identifier
2144 { $$ = build_tree_list (NULL_TREE, $1); }
2145 | identifier_list ',' identifier
2146 { $$ = chainon ($1, build_tree_list (NULL_TREE, $3)); }
2147 ;
2148
2149 classdecl:
2150 CLASS identifier_list ';'
2151 {
2152 objc_declare_class ($2);
2153 }
2154
2155 aliasdecl:
2156 ALIAS identifier identifier ';'
2157 {
2158 objc_declare_alias ($2, $3);
2159 }
2160
2161 classdef:
2162 INTERFACE identifier protocolrefs '{'
2163 {
2164 objc_interface_context = objc_ivar_context
2165 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2166 objc_public_flag = 0;
2167 }
2168 ivar_decl_list '}'
2169 {
2170 continue_class (objc_interface_context);
2171 }
2172 methodprotolist
2173 END
2174 {
2175 finish_class (objc_interface_context);
2176 objc_interface_context = NULL_TREE;
2177 }
2178
2179 | INTERFACE identifier protocolrefs
2180 {
2181 objc_interface_context
2182 = start_class (CLASS_INTERFACE_TYPE, $2, NULL_TREE, $3);
2183 continue_class (objc_interface_context);
2184 }
2185 methodprotolist
2186 END
2187 {
2188 finish_class (objc_interface_context);
2189 objc_interface_context = NULL_TREE;
2190 }
2191
2192 | INTERFACE identifier ':' identifier protocolrefs '{'
2193 {
2194 objc_interface_context = objc_ivar_context
2195 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2196 objc_public_flag = 0;
2197 }
2198 ivar_decl_list '}'
2199 {
2200 continue_class (objc_interface_context);
2201 }
2202 methodprotolist
2203 END
2204 {
2205 finish_class (objc_interface_context);
2206 objc_interface_context = NULL_TREE;
2207 }
2208
2209 | INTERFACE identifier ':' identifier protocolrefs
2210 {
2211 objc_interface_context
2212 = start_class (CLASS_INTERFACE_TYPE, $2, $4, $5);
2213 continue_class (objc_interface_context);
2214 }
2215 methodprotolist
2216 END
2217 {
2218 finish_class (objc_interface_context);
2219 objc_interface_context = NULL_TREE;
2220 }
2221
2222 | IMPLEMENTATION identifier '{'
2223 {
2224 objc_implementation_context = objc_ivar_context
2225 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2226 objc_public_flag = 0;
2227 }
2228 ivar_decl_list '}'
2229 {
2230 objc_ivar_chain
2231 = continue_class (objc_implementation_context);
2232 }
2233
2234 | IMPLEMENTATION identifier
2235 {
2236 objc_implementation_context
2237 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, NULL_TREE, NULL_TREE);
2238 objc_ivar_chain
2239 = continue_class (objc_implementation_context);
2240 }
2241
2242 | IMPLEMENTATION identifier ':' identifier '{'
2243 {
2244 objc_implementation_context = objc_ivar_context
2245 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2246 objc_public_flag = 0;
2247 }
2248 ivar_decl_list '}'
2249 {
2250 objc_ivar_chain
2251 = continue_class (objc_implementation_context);
2252 }
2253
2254 | IMPLEMENTATION identifier ':' identifier
2255 {
2256 objc_implementation_context
2257 = start_class (CLASS_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2258 objc_ivar_chain
2259 = continue_class (objc_implementation_context);
2260 }
2261
2262 | INTERFACE identifier '(' identifier ')' protocolrefs
2263 {
2264 objc_interface_context
2265 = start_class (CATEGORY_INTERFACE_TYPE, $2, $4, $6);
2266 continue_class (objc_interface_context);
2267 }
2268 methodprotolist
2269 END
2270 {
2271 finish_class (objc_interface_context);
2272 objc_interface_context = NULL_TREE;
2273 }
2274
2275 | IMPLEMENTATION identifier '(' identifier ')'
2276 {
2277 objc_implementation_context
2278 = start_class (CATEGORY_IMPLEMENTATION_TYPE, $2, $4, NULL_TREE);
2279 objc_ivar_chain
2280 = continue_class (objc_implementation_context);
2281 }
2282 ;
2283
2284 protocoldef:
2285 PROTOCOL identifier protocolrefs
2286 {
2287 remember_protocol_qualifiers ();
2288 objc_interface_context
2289 = start_protocol(PROTOCOL_INTERFACE_TYPE, $2, $3);
2290 }
2291 methodprotolist END
2292 {
2293 forget_protocol_qualifiers();
2294 finish_protocol(objc_interface_context);
2295 objc_interface_context = NULL_TREE;
2296 }
2297 ;
2298
2299 protocolrefs:
2300 /* empty */
2301 {
2302 $$ = NULL_TREE;
2303 }
2304 | non_empty_protocolrefs
2305 ;
2306
2307 non_empty_protocolrefs:
2308 ARITHCOMPARE identifier_list ARITHCOMPARE
2309 {
2310 if ($1 == LT_EXPR && $3 == GT_EXPR)
2311 $$ = $2;
2312 else
2313 YYERROR1;
2314 }
2315 ;
2316
2317 ivar_decl_list:
2318 ivar_decl_list visibility_spec ivar_decls
2319 | ivar_decls
2320 ;
2321
2322 visibility_spec:
2323 PRIVATE { objc_public_flag = 2; }
2324 | PROTECTED { objc_public_flag = 0; }
2325 | PUBLIC { objc_public_flag = 1; }
2326 ;
2327
2328 ivar_decls:
2329 /* empty */
2330 {
2331 $$ = NULL_TREE;
2332 }
2333 | ivar_decls ivar_decl ';'
2334 | ivar_decls ';'
2335 {
2336 if (pedantic)
2337 pedwarn ("extra semicolon in struct or union specified");
2338 }
2339 ;
2340
2341
2342 /* There is a shift-reduce conflict here, because `components' may
2343 start with a `typename'. It happens that shifting (the default resolution)
2344 does the right thing, because it treats the `typename' as part of
2345 a `typed_typespecs'.
2346
2347 It is possible that this same technique would allow the distinction
2348 between `notype_initdecls' and `initdecls' to be eliminated.
2349 But I am being cautious and not trying it. */
2350
2351 ivar_decl:
2352 typed_typespecs setspecs ivars
2353 { $$ = $3;
2354 current_declspecs = TREE_VALUE (declspec_stack);
2355 prefix_attributes = TREE_PURPOSE (declspec_stack);
2356 declspec_stack = TREE_CHAIN (declspec_stack); }
2357 | nonempty_type_quals setspecs ivars
2358 { $$ = $3;
2359 current_declspecs = TREE_VALUE (declspec_stack);
2360 prefix_attributes = TREE_PURPOSE (declspec_stack);
2361 declspec_stack = TREE_CHAIN (declspec_stack); }
2362 | error
2363 { $$ = NULL_TREE; }
2364 ;
2365
2366 ivars:
2367 /* empty */
2368 { $$ = NULL_TREE; }
2369 | ivar_declarator
2370 | ivars ',' ivar_declarator
2371 ;
2372
2373 ivar_declarator:
2374 declarator
2375 {
2376 $$ = add_instance_variable (objc_ivar_context,
2377 objc_public_flag,
2378 $1, current_declspecs,
2379 NULL_TREE);
2380 }
2381 | declarator ':' expr_no_commas
2382 {
2383 $$ = add_instance_variable (objc_ivar_context,
2384 objc_public_flag,
2385 $1, current_declspecs, $3);
2386 }
2387 | ':' expr_no_commas
2388 {
2389 $$ = add_instance_variable (objc_ivar_context,
2390 objc_public_flag,
2391 NULL_TREE,
2392 current_declspecs, $2);
2393 }
2394 ;
2395
2396 methoddef:
2397 '+'
2398 {
2399 remember_protocol_qualifiers ();
2400 if (objc_implementation_context)
2401 objc_inherit_code = CLASS_METHOD_DECL;
2402 else
2403 fatal ("method definition not in class context");
2404 }
2405 methoddecl
2406 {
2407 forget_protocol_qualifiers ();
2408 add_class_method (objc_implementation_context, $3);
2409 start_method_def ($3);
2410 objc_method_context = $3;
2411 }
2412 optarglist
2413 {
2414 continue_method_def ();
2415 }
2416 compstmt_or_error
2417 {
2418 finish_method_def ();
2419 objc_method_context = NULL_TREE;
2420 }
2421
2422 | '-'
2423 {
2424 remember_protocol_qualifiers ();
2425 if (objc_implementation_context)
2426 objc_inherit_code = INSTANCE_METHOD_DECL;
2427 else
2428 fatal ("method definition not in class context");
2429 }
2430 methoddecl
2431 {
2432 forget_protocol_qualifiers ();
2433 add_instance_method (objc_implementation_context, $3);
2434 start_method_def ($3);
2435 objc_method_context = $3;
2436 }
2437 optarglist
2438 {
2439 continue_method_def ();
2440 }
2441 compstmt_or_error
2442 {
2443 finish_method_def ();
2444 objc_method_context = NULL_TREE;
2445 }
2446 ;
2447
2448 /* the reason for the strange actions in this rule
2449 is so that notype_initdecls when reached via datadef
2450 can find a valid list of type and sc specs in $0. */
2451
2452 methodprotolist:
2453 /* empty */
2454 | {$<ttype>$ = NULL_TREE; } methodprotolist2
2455 ;
2456
2457 methodprotolist2: /* eliminates a shift/reduce conflict */
2458 methodproto
2459 | datadef
2460 | methodprotolist2 methodproto
2461 | methodprotolist2 {$<ttype>$ = NULL_TREE; } datadef
2462 ;
2463
2464 semi_or_error:
2465 ';'
2466 | error
2467 ;
2468
2469 methodproto:
2470 '+'
2471 {
2472 /* Remember protocol qualifiers in prototypes. */
2473 remember_protocol_qualifiers ();
2474 objc_inherit_code = CLASS_METHOD_DECL;
2475 }
2476 methoddecl
2477 {
2478 /* Forget protocol qualifiers here. */
2479 forget_protocol_qualifiers ();
2480 add_class_method (objc_interface_context, $3);
2481 }
2482 semi_or_error
2483
2484 | '-'
2485 {
2486 /* Remember protocol qualifiers in prototypes. */
2487 remember_protocol_qualifiers ();
2488 objc_inherit_code = INSTANCE_METHOD_DECL;
2489 }
2490 methoddecl
2491 {
2492 /* Forget protocol qualifiers here. */
2493 forget_protocol_qualifiers ();
2494 add_instance_method (objc_interface_context, $3);
2495 }
2496 semi_or_error
2497 ;
2498
2499 methoddecl:
2500 '(' typename ')' unaryselector
2501 {
2502 $$ = build_method_decl (objc_inherit_code, $2, $4, NULL_TREE);
2503 }
2504
2505 | unaryselector
2506 {
2507 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, NULL_TREE);
2508 }
2509
2510 | '(' typename ')' keywordselector optparmlist
2511 {
2512 $$ = build_method_decl (objc_inherit_code, $2, $4, $5);
2513 }
2514
2515 | keywordselector optparmlist
2516 {
2517 $$ = build_method_decl (objc_inherit_code, NULL_TREE, $1, $2);
2518 }
2519 ;
2520
2521 /* "optarglist" assumes that start_method_def has already been called...
2522 if it is not, the "xdecls" will not be placed in the proper scope */
2523
2524 optarglist:
2525 /* empty */
2526 | ';' myxdecls
2527 ;
2528
2529 /* to get around the following situation: "int foo (int a) int b; {}" that
2530 is synthesized when parsing "- a:a b:b; id c; id d; { ... }" */
2531
2532 myxdecls:
2533 /* empty */
2534 | mydecls
2535 ;
2536
2537 mydecls:
2538 mydecl
2539 | errstmt
2540 | mydecls mydecl
2541 | mydecl errstmt
2542 ;
2543
2544 mydecl:
2545 typed_declspecs setspecs myparms ';'
2546 { current_declspecs = TREE_VALUE (declspec_stack);
2547 prefix_attributes = TREE_PURPOSE (declspec_stack);
2548 declspec_stack = TREE_CHAIN (declspec_stack); }
2549 | typed_declspecs ';'
2550 { shadow_tag ($1); }
2551 | declmods ';'
2552 { pedwarn ("empty declaration"); }
2553 ;
2554
2555 myparms:
2556 myparm
2557 { push_parm_decl ($1); }
2558 | myparms ',' myparm
2559 { push_parm_decl ($3); }
2560 ;
2561
2562 /* A single parameter declaration or parameter type name,
2563 as found in a parmlist. DOES NOT ALLOW AN INITIALIZER OR ASMSPEC */
2564
2565 myparm:
2566 parm_declarator maybe_attribute
2567 { $$ = build_tree_list (build_tree_list (current_declspecs,
2568 $1),
2569 build_tree_list (prefix_attributes,
2570 $2)); }
2571 | notype_declarator maybe_attribute
2572 { $$ = build_tree_list (build_tree_list (current_declspecs,
2573 $1),
2574 build_tree_list (prefix_attributes,
2575 $2)); }
2576 | absdcl maybe_attribute
2577 { $$ = build_tree_list (build_tree_list (current_declspecs,
2578 $1),
2579 build_tree_list (prefix_attributes,
2580 $2)); }
2581 ;
2582
2583 optparmlist:
2584 /* empty */
2585 {
2586 $$ = NULL_TREE;
2587 }
2588 | ',' ELLIPSIS
2589 {
2590 /* oh what a kludge! */
2591 $$ = objc_ellipsis_node;
2592 }
2593 | ','
2594 {
2595 pushlevel (0);
2596 }
2597 parmlist_2
2598 {
2599 /* returns a tree list node generated by get_parm_info */
2600 $$ = $3;
2601 poplevel (0, 0, 0);
2602 }
2603 ;
2604
2605 unaryselector:
2606 selector
2607 ;
2608
2609 keywordselector:
2610 keyworddecl
2611
2612 | keywordselector keyworddecl
2613 {
2614 $$ = chainon ($1, $2);
2615 }
2616 ;
2617
2618 selector:
2619 IDENTIFIER
2620 | TYPENAME
2621 | OBJECTNAME
2622 | reservedwords
2623 ;
2624
2625 reservedwords:
2626 ENUM | STRUCT | UNION | IF | ELSE | WHILE | DO | FOR
2627 | SWITCH | CASE | DEFAULT | BREAK | CONTINUE | RETURN
2628 | GOTO | ASM_KEYWORD | SIZEOF | TYPEOF | ALIGNOF
2629 | TYPESPEC | TYPE_QUAL
2630 ;
2631
2632 keyworddecl:
2633 selector ':' '(' typename ')' identifier
2634 {
2635 $$ = build_keyword_decl ($1, $4, $6);
2636 }
2637
2638 | selector ':' identifier
2639 {
2640 $$ = build_keyword_decl ($1, NULL_TREE, $3);
2641 }
2642
2643 | ':' '(' typename ')' identifier
2644 {
2645 $$ = build_keyword_decl (NULL_TREE, $3, $5);
2646 }
2647
2648 | ':' identifier
2649 {
2650 $$ = build_keyword_decl (NULL_TREE, NULL_TREE, $2);
2651 }
2652 ;
2653
2654 messageargs:
2655 selector
2656 | keywordarglist
2657 ;
2658
2659 keywordarglist:
2660 keywordarg
2661 | keywordarglist keywordarg
2662 {
2663 $$ = chainon ($1, $2);
2664 }
2665 ;
2666
2667
2668 keywordexpr:
2669 nonnull_exprlist
2670 {
2671 if (TREE_CHAIN ($1) == NULL_TREE)
2672 /* just return the expr., remove a level of indirection */
2673 $$ = TREE_VALUE ($1);
2674 else
2675 /* we have a comma expr., we will collapse later */
2676 $$ = $1;
2677 }
2678 ;
2679
2680 keywordarg:
2681 selector ':' keywordexpr
2682 {
2683 $$ = build_tree_list ($1, $3);
2684 }
2685 | ':' keywordexpr
2686 {
2687 $$ = build_tree_list (NULL_TREE, $2);
2688 }
2689 ;
2690
2691 receiver:
2692 expr
2693 | CLASSNAME
2694 {
2695 $$ = get_class_reference ($1);
2696 }
2697 ;
2698
2699 objcmessageexpr:
2700 '['
2701 { objc_receiver_context = 1; }
2702 receiver
2703 { objc_receiver_context = 0; }
2704 messageargs ']'
2705 {
2706 $$ = build_tree_list ($3, $5);
2707 }
2708 ;
2709
2710 selectorarg:
2711 selector
2712 | keywordnamelist
2713 ;
2714
2715 keywordnamelist:
2716 keywordname
2717 | keywordnamelist keywordname
2718 {
2719 $$ = chainon ($1, $2);
2720 }
2721 ;
2722
2723 keywordname:
2724 selector ':'
2725 {
2726 $$ = build_tree_list ($1, NULL_TREE);
2727 }
2728 | ':'
2729 {
2730 $$ = build_tree_list (NULL_TREE, NULL_TREE);
2731 }
2732 ;
2733
2734 objcselectorexpr:
2735 SELECTOR '(' selectorarg ')'
2736 {
2737 $$ = $3;
2738 }
2739 ;
2740
2741 objcprotocolexpr:
2742 PROTOCOL '(' identifier ')'
2743 {
2744 $$ = $3;
2745 }
2746 ;
2747
2748 /* extension to support C-structures in the archiver */
2749
2750 objcencodeexpr:
2751 ENCODE '(' typename ')'
2752 {
2753 $$ = groktypename ($3);
2754 }
2755 ;
2756
2757 end ifobjc
2758 %%
2759
2760 /* yylex() is a thin wrapper around c_lex(), all it does is translate
2761 cpplib.h's token codes into yacc's token codes. */
2762
2763 static enum cpp_ttype last_token;
2764 #if USE_CPPLIB
2765 extern cpp_reader parse_in;
2766 #endif
2767
2768 /* The reserved keyword table. */
2769 struct resword
2770 {
2771 const char *word;
2772 ENUM_BITFIELD(rid) rid : 16;
2773 unsigned int disable : 16;
2774 };
2775
2776 /* Disable mask. Keywords are disabled if (reswords[i].disable & mask) is
2777 _true_. */
2778 #define D_TRAD 0x01 /* not in traditional C */
2779 #define D_C89 0x02 /* not in C89 */
2780 #define D_EXT 0x04 /* GCC extension */
2781 #define D_EXT89 0x08 /* GCC extension incorporated in C99 */
2782 #define D_OBJC 0x10 /* Objective C only */
2783 #define D_YES 0x20 /* always starts disabled */
2784
2785 static const struct resword reswords[] =
2786 {
2787 { "_Complex", RID_COMPLEX, 0 },
2788 { "__alignof", RID_ALIGNOF, 0 },
2789 { "__alignof__", RID_ALIGNOF, 0 },
2790 { "__asm", RID_ASM, 0 },
2791 { "__asm__", RID_ASM, 0 },
2792 { "__attribute", RID_ATTRIBUTE, 0 },
2793 { "__attribute__", RID_ATTRIBUTE, 0 },
2794 { "__bounded", RID_BOUNDED, 0 },
2795 { "__bounded__", RID_BOUNDED, 0 },
2796 { "__builtin_va_arg", RID_VA_ARG, 0 },
2797 { "__complex", RID_COMPLEX, 0 },
2798 { "__complex__", RID_COMPLEX, 0 },
2799 { "__const", RID_CONST, 0 },
2800 { "__const__", RID_CONST, 0 },
2801 { "__extension__", RID_EXTENSION, 0 },
2802 { "__imag", RID_IMAGPART, 0 },
2803 { "__imag__", RID_IMAGPART, 0 },
2804 { "__inline", RID_INLINE, 0 },
2805 { "__inline__", RID_INLINE, 0 },
2806 { "__label__", RID_LABEL, 0 },
2807 { "__ptrbase", RID_PTRBASE, 0 },
2808 { "__ptrbase__", RID_PTRBASE, 0 },
2809 { "__ptrextent", RID_PTREXTENT, 0 },
2810 { "__ptrextent__", RID_PTREXTENT, 0 },
2811 { "__ptrvalue", RID_PTRVALUE, 0 },
2812 { "__ptrvalue__", RID_PTRVALUE, 0 },
2813 { "__real", RID_REALPART, 0 },
2814 { "__real__", RID_REALPART, 0 },
2815 { "__restrict", RID_RESTRICT, 0 },
2816 { "__restrict__", RID_RESTRICT, 0 },
2817 { "__signed", RID_SIGNED, 0 },
2818 { "__signed__", RID_SIGNED, 0 },
2819 { "__typeof", RID_TYPEOF, 0 },
2820 { "__typeof__", RID_TYPEOF, 0 },
2821 { "__unbounded", RID_UNBOUNDED, 0 },
2822 { "__unbounded__", RID_UNBOUNDED, 0 },
2823 { "__volatile", RID_VOLATILE, 0 },
2824 { "__volatile__", RID_VOLATILE, 0 },
2825 { "asm", RID_ASM, D_EXT },
2826 { "auto", RID_AUTO, 0 },
2827 { "break", RID_BREAK, 0 },
2828 { "case", RID_CASE, 0 },
2829 { "char", RID_CHAR, 0 },
2830 { "const", RID_CONST, D_TRAD },
2831 { "continue", RID_CONTINUE, 0 },
2832 { "default", RID_DEFAULT, 0 },
2833 { "do", RID_DO, 0 },
2834 { "double", RID_DOUBLE, 0 },
2835 { "else", RID_ELSE, 0 },
2836 { "enum", RID_ENUM, 0 },
2837 { "extern", RID_EXTERN, 0 },
2838 { "float", RID_FLOAT, 0 },
2839 { "for", RID_FOR, 0 },
2840 { "goto", RID_GOTO, 0 },
2841 { "if", RID_IF, 0 },
2842 { "inline", RID_INLINE, D_TRAD|D_EXT89 },
2843 { "int", RID_INT, 0 },
2844 { "long", RID_LONG, 0 },
2845 { "register", RID_REGISTER, 0 },
2846 { "restrict", RID_RESTRICT, D_TRAD|D_C89 },
2847 { "return", RID_RETURN, 0 },
2848 { "short", RID_SHORT, 0 },
2849 { "signed", RID_SIGNED, D_TRAD },
2850 { "sizeof", RID_SIZEOF, 0 },
2851 { "static", RID_STATIC, 0 },
2852 { "struct", RID_STRUCT, 0 },
2853 { "switch", RID_SWITCH, 0 },
2854 { "typedef", RID_TYPEDEF, 0 },
2855 { "typeof", RID_TYPEOF, D_TRAD|D_EXT },
2856 { "union", RID_UNION, 0 },
2857 { "unsigned", RID_UNSIGNED, 0 },
2858 { "void", RID_VOID, 0 },
2859 { "volatile", RID_VOLATILE, D_TRAD },
2860 { "while", RID_WHILE, 0 },
2861 ifobjc
2862 { "@class", RID_AT_CLASS, D_OBJC },
2863 { "@compatibility_alias", RID_AT_ALIAS, D_OBJC },
2864 { "@defs", RID_AT_DEFS, D_OBJC },
2865 { "@encode", RID_AT_ENCODE, D_OBJC },
2866 { "@end", RID_AT_END, D_OBJC },
2867 { "@implementation", RID_AT_IMPLEMENTATION, D_OBJC },
2868 { "@interface", RID_AT_INTERFACE, D_OBJC },
2869 { "@private", RID_AT_PRIVATE, D_OBJC },
2870 { "@protected", RID_AT_PROTECTED, D_OBJC },
2871 { "@protocol", RID_AT_PROTOCOL, D_OBJC },
2872 { "@public", RID_AT_PUBLIC, D_OBJC },
2873 { "@selector", RID_AT_SELECTOR, D_OBJC },
2874 { "id", RID_ID, D_OBJC },
2875 { "bycopy", RID_BYCOPY, D_OBJC|D_YES },
2876 { "byref", RID_BYREF, D_OBJC|D_YES },
2877 { "in", RID_IN, D_OBJC|D_YES },
2878 { "inout", RID_INOUT, D_OBJC|D_YES },
2879 { "oneway", RID_ONEWAY, D_OBJC|D_YES },
2880 { "out", RID_OUT, D_OBJC|D_YES },
2881 end ifobjc
2882 };
2883 #define N_reswords (sizeof reswords / sizeof (struct resword))
2884
2885 /* Table mapping from RID_* constants to yacc token numbers.
2886 Unfortunately we have to have entries for all the keywords in all
2887 three languages. */
2888 static const short rid_to_yy[RID_MAX] =
2889 {
2890 /* RID_STATIC */ SCSPEC,
2891 /* RID_UNSIGNED */ TYPESPEC,
2892 /* RID_LONG */ TYPESPEC,
2893 /* RID_CONST */ TYPE_QUAL,
2894 /* RID_EXTERN */ SCSPEC,
2895 /* RID_REGISTER */ SCSPEC,
2896 /* RID_TYPEDEF */ SCSPEC,
2897 /* RID_SHORT */ TYPESPEC,
2898 /* RID_INLINE */ SCSPEC,
2899 /* RID_VOLATILE */ TYPE_QUAL,
2900 /* RID_SIGNED */ TYPESPEC,
2901 /* RID_AUTO */ SCSPEC,
2902 /* RID_RESTRICT */ TYPE_QUAL,
2903
2904 /* C extensions */
2905 /* RID_BOUNDED */ TYPE_QUAL,
2906 /* RID_UNBOUNDED */ TYPE_QUAL,
2907 /* RID_COMPLEX */ TYPESPEC,
2908
2909 /* C++ */
2910 /* RID_FRIEND */ 0,
2911 /* RID_VIRTUAL */ 0,
2912 /* RID_EXPLICIT */ 0,
2913 /* RID_EXPORT */ 0,
2914 /* RID_MUTABLE */ 0,
2915
2916 /* ObjC */
2917 /* RID_IN */ TYPE_QUAL,
2918 /* RID_OUT */ TYPE_QUAL,
2919 /* RID_INOUT */ TYPE_QUAL,
2920 /* RID_BYCOPY */ TYPE_QUAL,
2921 /* RID_BYREF */ TYPE_QUAL,
2922 /* RID_ONEWAY */ TYPE_QUAL,
2923
2924 /* C */
2925 /* RID_INT */ TYPESPEC,
2926 /* RID_CHAR */ TYPESPEC,
2927 /* RID_FLOAT */ TYPESPEC,
2928 /* RID_DOUBLE */ TYPESPEC,
2929 /* RID_VOID */ TYPESPEC,
2930 /* RID_ENUM */ ENUM,
2931 /* RID_STRUCT */ STRUCT,
2932 /* RID_UNION */ UNION,
2933 /* RID_IF */ IF,
2934 /* RID_ELSE */ ELSE,
2935 /* RID_WHILE */ WHILE,
2936 /* RID_DO */ DO,
2937 /* RID_FOR */ FOR,
2938 /* RID_SWITCH */ SWITCH,
2939 /* RID_CASE */ CASE,
2940 /* RID_DEFAULT */ DEFAULT,
2941 /* RID_BREAK */ BREAK,
2942 /* RID_CONTINUE */ CONTINUE,
2943 /* RID_RETURN */ RETURN,
2944 /* RID_GOTO */ GOTO,
2945 /* RID_SIZEOF */ SIZEOF,
2946
2947 /* C extensions */
2948 /* RID_ASM */ ASM_KEYWORD,
2949 /* RID_TYPEOF */ TYPEOF,
2950 /* RID_ALIGNOF */ ALIGNOF,
2951 /* RID_ATTRIBUTE */ ATTRIBUTE,
2952 /* RID_VA_ARG */ VA_ARG,
2953 /* RID_EXTENSION */ EXTENSION,
2954 /* RID_IMAGPART */ IMAGPART,
2955 /* RID_REALPART */ REALPART,
2956 /* RID_LABEL */ LABEL,
2957 /* RID_PTRBASE */ PTR_BASE,
2958 /* RID_PTREXTENT */ PTR_EXTENT,
2959 /* RID_PTRVALUE */ PTR_VALUE,
2960
2961 /* C++ */
2962 /* RID_BOOL */ 0,
2963 /* RID_WCHAR */ 0,
2964 /* RID_CLASS */ 0,
2965 /* RID_PUBLIC */ 0,
2966 /* RID_PRIVATE */ 0,
2967 /* RID_PROTECTED */ 0,
2968 /* RID_TEMPLATE */ 0,
2969 /* RID_NULL */ 0,
2970 /* RID_CATCH */ 0,
2971 /* RID_DELETE */ 0,
2972 /* RID_FALSE */ 0,
2973 /* RID_NAMESPACE */ 0,
2974 /* RID_NEW */ 0,
2975 /* RID_OPERATOR */ 0,
2976 /* RID_THIS */ 0,
2977 /* RID_THROW */ 0,
2978 /* RID_TRUE */ 0,
2979 /* RID_TRY */ 0,
2980 /* RID_TYPENAME */ 0,
2981 /* RID_TYPEID */ 0,
2982 /* RID_USING */ 0,
2983
2984 /* casts */
2985 /* RID_CONSTCAST */ 0,
2986 /* RID_DYNCAST */ 0,
2987 /* RID_REINTCAST */ 0,
2988 /* RID_STATCAST */ 0,
2989
2990 /* alternate spellings */
2991 /* RID_AND */ 0,
2992 /* RID_AND_EQ */ 0,
2993 /* RID_NOT */ 0,
2994 /* RID_NOT_EQ */ 0,
2995 /* RID_OR */ 0,
2996 /* RID_OR_EQ */ 0,
2997 /* RID_XOR */ 0,
2998 /* RID_XOR_EQ */ 0,
2999 /* RID_BITAND */ 0,
3000 /* RID_BITOR */ 0,
3001 /* RID_COMPL */ 0,
3002
3003 /* Objective C */
3004 /* RID_ID */ OBJECTNAME,
3005 /* RID_AT_ENCODE */ ENCODE,
3006 /* RID_AT_END */ END,
3007 /* RID_AT_CLASS */ CLASS,
3008 /* RID_AT_ALIAS */ ALIAS,
3009 /* RID_AT_DEFS */ DEFS,
3010 /* RID_AT_PRIVATE */ PRIVATE,
3011 /* RID_AT_PROTECTED */ PROTECTED,
3012 /* RID_AT_PUBLIC */ PUBLIC,
3013 /* RID_AT_PROTOCOL */ PROTOCOL,
3014 /* RID_AT_SELECTOR */ SELECTOR,
3015 /* RID_AT_INTERFACE */ INTERFACE,
3016 /* RID_AT_IMPLEMENTATION */ IMPLEMENTATION
3017 };
3018
3019 static void
3020 init_reswords ()
3021 {
3022 unsigned int i;
3023 tree id;
3024 int mask = ((doing_objc_thang ? 0 : D_OBJC)
3025 | (flag_isoc99 ? 0 : D_C89)
3026 | (flag_traditional ? D_TRAD : 0)
3027 | (flag_no_asm ? (flag_isoc99 ? D_EXT : D_EXT|D_EXT89) : 0));
3028
3029 /* It is not necessary to register ridpointers as a GC root, because
3030 all the trees it points to are permanently interned in the
3031 get_identifier hash anyway. */
3032 ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
3033 for (i = 0; i < N_reswords; i++)
3034 {
3035 /* If a keyword is disabled, do not enter it into the table
3036 and so create a canonical spelling that isn't a keyword. */
3037 if (reswords[i].disable & mask)
3038 continue;
3039
3040 id = get_identifier (reswords[i].word);
3041 C_RID_CODE (id) = reswords[i].rid;
3042 ridpointers [(int) reswords[i].rid] = id;
3043
3044 /* Objective C does tricky things with enabling and disabling
3045 keywords. So these we must not elide in the test above, but
3046 wait and not mark them reserved now. */
3047 if (! (reswords[i].disable & D_YES))
3048 C_IS_RESERVED_WORD (id) = 1;
3049 }
3050 }
3051
3052 const char *
3053 init_parse (filename)
3054 const char *filename;
3055 {
3056 add_c_tree_codes ();
3057
3058 /* Make identifier nodes long enough for the language-specific slots. */
3059 set_identifier_size (sizeof (struct lang_identifier));
3060
3061 init_reswords ();
3062 init_pragma ();
3063
3064 return init_c_lex (filename);
3065 }
3066
3067 void
3068 finish_parse ()
3069 {
3070 #if USE_CPPLIB
3071 cpp_finish (&parse_in);
3072 errorcount += parse_in.errors;
3073 #else
3074 fclose (finput);
3075 #endif
3076 }
3077
3078 #if USE_CPPLIB
3079 #define NAME(type) cpp_type2name (type)
3080 #else
3081 /* Bleah */
3082 #include "symcat.h"
3083 #define OP(e, s) s,
3084 #define TK(e, s) STRINGX(e),
3085
3086 static const char *type2name[N_TTYPES] = { TTYPE_TABLE };
3087 #define NAME(type) type2name[type]
3088 #endif
3089
3090 static void
3091 yyerror (msgid)
3092 const char *msgid;
3093 {
3094 const char *string = _(msgid);
3095
3096 if (last_token == CPP_EOF)
3097 error ("%s at end of input", string);
3098 else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
3099 {
3100 unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
3101 const char *ell = (last_token == CPP_CHAR) ? "" : "L";
3102 if (val <= UCHAR_MAX && ISGRAPH (val))
3103 error ("%s before %s'%c'", string, ell, val);
3104 else
3105 error ("%s before %s'\\x%x'", string, ell, val);
3106 }
3107 else if (last_token == CPP_STRING
3108 || last_token == CPP_WSTRING
3109 || last_token == CPP_OSTRING)
3110 error ("%s before string constant", string);
3111 else if (last_token == CPP_NUMBER
3112 || last_token == CPP_INT
3113 || last_token == CPP_FLOAT)
3114 error ("%s before numeric constant", string);
3115 else if (last_token == CPP_NAME)
3116 error ("%s before \"%s\"", string, IDENTIFIER_POINTER (yylval.ttype));
3117 else
3118 error ("%s before '%s' token", string, NAME(last_token));
3119 }
3120
3121 static inline int
3122 _yylex ()
3123 {
3124 retry:
3125 last_token = c_lex (&yylval.ttype);
3126
3127 switch (last_token)
3128 {
3129 case CPP_EQ: return '=';
3130 case CPP_NOT: return '!';
3131 case CPP_GREATER: yylval.code = GT_EXPR; return ARITHCOMPARE;
3132 case CPP_LESS: yylval.code = LT_EXPR; return ARITHCOMPARE;
3133 case CPP_PLUS: yylval.code = PLUS_EXPR; return '+';
3134 case CPP_MINUS: yylval.code = MINUS_EXPR; return '-';
3135 case CPP_MULT: yylval.code = MULT_EXPR; return '*';
3136 case CPP_DIV: yylval.code = TRUNC_DIV_EXPR; return '/';
3137 case CPP_MOD: yylval.code = TRUNC_MOD_EXPR; return '%';
3138 case CPP_AND: yylval.code = BIT_AND_EXPR; return '&';
3139 case CPP_OR: yylval.code = BIT_IOR_EXPR; return '|';
3140 case CPP_XOR: yylval.code = BIT_XOR_EXPR; return '^';
3141 case CPP_RSHIFT: yylval.code = RSHIFT_EXPR; return RSHIFT;
3142 case CPP_LSHIFT: yylval.code = LSHIFT_EXPR; return LSHIFT;
3143
3144 case CPP_COMPL: return '~';
3145 case CPP_AND_AND: return ANDAND;
3146 case CPP_OR_OR: return OROR;
3147 case CPP_QUERY: return '?';
3148 case CPP_COLON: return ':';
3149 case CPP_COMMA: return ',';
3150 case CPP_OPEN_PAREN: return '(';
3151 case CPP_CLOSE_PAREN: return ')';
3152 case CPP_EQ_EQ: yylval.code = EQ_EXPR; return EQCOMPARE;
3153 case CPP_NOT_EQ: yylval.code = NE_EXPR; return EQCOMPARE;
3154 case CPP_GREATER_EQ:yylval.code = GE_EXPR; return ARITHCOMPARE;
3155 case CPP_LESS_EQ: yylval.code = LE_EXPR; return ARITHCOMPARE;
3156
3157 case CPP_PLUS_EQ: yylval.code = PLUS_EXPR; return ASSIGN;
3158 case CPP_MINUS_EQ: yylval.code = MINUS_EXPR; return ASSIGN;
3159 case CPP_MULT_EQ: yylval.code = MULT_EXPR; return ASSIGN;
3160 case CPP_DIV_EQ: yylval.code = TRUNC_DIV_EXPR; return ASSIGN;
3161 case CPP_MOD_EQ: yylval.code = TRUNC_MOD_EXPR; return ASSIGN;
3162 case CPP_AND_EQ: yylval.code = BIT_AND_EXPR; return ASSIGN;
3163 case CPP_OR_EQ: yylval.code = BIT_IOR_EXPR; return ASSIGN;
3164 case CPP_XOR_EQ: yylval.code = BIT_XOR_EXPR; return ASSIGN;
3165 case CPP_RSHIFT_EQ: yylval.code = RSHIFT_EXPR; return ASSIGN;
3166 case CPP_LSHIFT_EQ: yylval.code = LSHIFT_EXPR; return ASSIGN;
3167
3168 case CPP_OPEN_SQUARE: return '[';
3169 case CPP_CLOSE_SQUARE: return ']';
3170 case CPP_OPEN_BRACE: return '{';
3171 case CPP_CLOSE_BRACE: return '}';
3172 case CPP_SEMICOLON: return ';';
3173 case CPP_ELLIPSIS: return ELLIPSIS;
3174
3175 case CPP_PLUS_PLUS: return PLUSPLUS;
3176 case CPP_MINUS_MINUS: return MINUSMINUS;
3177 case CPP_DEREF: return POINTSAT;
3178 case CPP_DOT: return '.';
3179
3180 case CPP_EOF:
3181 #if USE_CPPLIB
3182 cpp_pop_buffer (&parse_in);
3183 if (! CPP_BUFFER (&parse_in))
3184 #endif
3185 return 0;
3186 goto retry;
3187
3188 case CPP_NAME:
3189 if (C_IS_RESERVED_WORD (yylval.ttype))
3190 {
3191 enum rid rid_code = C_RID_CODE (yylval.ttype);
3192 /* Return the canonical spelling for this keyword. */
3193 yylval.ttype = ridpointers[(int) rid_code];
3194 return rid_to_yy[(int) rid_code];
3195 }
3196
3197 if (IDENTIFIER_POINTER (yylval.ttype)[0] == '@')
3198 {
3199 error ("invalid identifier `%s'", IDENTIFIER_POINTER (yylval.ttype));
3200 return IDENTIFIER;
3201 }
3202
3203 {
3204 tree decl;
3205
3206 decl = lookup_name (yylval.ttype);
3207
3208 if (decl)
3209 {
3210 if (TREE_CODE (decl) == TYPE_DECL)
3211 return TYPENAME;
3212 /* A user-invisible read-only initialized variable
3213 should be replaced by its value.
3214 We handle only strings since that's the only case used in C. */
3215 else if (TREE_CODE (decl) == VAR_DECL
3216 && DECL_IGNORED_P (decl)
3217 && TREE_READONLY (decl)
3218 && DECL_INITIAL (decl) != 0
3219 && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
3220 {
3221 tree stringval = DECL_INITIAL (decl);
3222
3223 /* Copy the string value so that we won't clobber anything
3224 if we put something in the TREE_CHAIN of this one. */
3225 yylval.ttype = build_string (TREE_STRING_LENGTH (stringval),
3226 TREE_STRING_POINTER (stringval));
3227 return STRING;
3228 }
3229 }
3230 else if (doing_objc_thang)
3231 {
3232 tree objc_interface_decl = is_class_name (yylval.ttype);
3233
3234 if (objc_interface_decl)
3235 {
3236 yylval.ttype = objc_interface_decl;
3237 return CLASSNAME;
3238 }
3239 }
3240
3241 return IDENTIFIER;
3242 }
3243
3244 case CPP_INT:
3245 case CPP_FLOAT:
3246 case CPP_NUMBER:
3247 case CPP_CHAR:
3248 case CPP_WCHAR:
3249 return CONSTANT;
3250
3251 case CPP_STRING:
3252 case CPP_WSTRING:
3253 return STRING;
3254
3255 case CPP_OSTRING:
3256 return OBJC_STRING;
3257
3258 /* These tokens are C++ specific (and will not be generated
3259 in C mode, but let's be cautious). */
3260 case CPP_SCOPE:
3261 case CPP_DEREF_STAR:
3262 case CPP_DOT_STAR:
3263 case CPP_MIN_EQ:
3264 case CPP_MAX_EQ:
3265 case CPP_MIN:
3266 case CPP_MAX:
3267 /* These tokens should not survive translation phase 4. */
3268 case CPP_HASH:
3269 case CPP_PASTE:
3270 error ("syntax error before '%s' token", NAME(last_token));
3271 goto retry;
3272
3273 default:
3274 abort ();
3275 }
3276
3277 /* NOTREACHED */
3278 }
3279
3280 static int
3281 yylex()
3282 {
3283 int r;
3284 timevar_push (TV_LEX);
3285 r = _yylex();
3286 timevar_pop (TV_LEX);
3287 return r;
3288 }
3289
3290 /* Sets the value of the 'yydebug' variable to VALUE.
3291 This is a function so we don't have to have YYDEBUG defined
3292 in order to build the compiler. */
3293
3294 void
3295 set_yydebug (value)
3296 int value;
3297 {
3298 #if YYDEBUG != 0
3299 yydebug = value;
3300 #else
3301 warning ("YYDEBUG not defined.");
3302 #endif
3303 }
3304
3305 /* Function used when yydebug is set, to print a token in more detail. */
3306
3307 static void
3308 yyprint (file, yychar, yyl)
3309 FILE *file;
3310 int yychar;
3311 YYSTYPE yyl;
3312 {
3313 tree t = yyl.ttype;
3314
3315 fprintf (file, " [%s]", NAME(last_token));
3316
3317 switch (yychar)
3318 {
3319 case IDENTIFIER:
3320 case TYPENAME:
3321 case OBJECTNAME:
3322 case TYPESPEC:
3323 case TYPE_QUAL:
3324 case SCSPEC:
3325 if (IDENTIFIER_POINTER (t))
3326 fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
3327 break;
3328
3329 case CONSTANT:
3330 fprintf (file, " %s", GET_MODE_NAME (TYPE_MODE (TREE_TYPE (t))));
3331 if (TREE_CODE (t) == INTEGER_CST)
3332 fprintf (file,
3333 #if HOST_BITS_PER_WIDE_INT == 64
3334 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
3335 " 0x%x%016x",
3336 #else
3337 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
3338 " 0x%lx%016lx",
3339 #else
3340 " 0x%llx%016llx",
3341 #endif
3342 #endif
3343 #else
3344 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
3345 " 0x%lx%08lx",
3346 #else
3347 " 0x%x%08x",
3348 #endif
3349 #endif
3350 TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
3351 break;
3352 }
3353 }
3354 \f
3355 /* This is not the ideal place to put these, but we have to get them out
3356 of c-lex.c because cp/lex.c has its own versions. */
3357
3358 /* Return something to represent absolute declarators containing a *.
3359 TARGET is the absolute declarator that the * contains.
3360 TYPE_QUALS is a list of modifiers such as const or volatile
3361 to apply to the pointer type, represented as identifiers.
3362
3363 We return an INDIRECT_REF whose "contents" are TARGET
3364 and whose type is the modifier list. */
3365
3366 tree
3367 make_pointer_declarator (type_quals, target)
3368 tree type_quals, target;
3369 {
3370 return build1 (INDIRECT_REF, type_quals, target);
3371 }