spew.c (struct uinparsed_test): Replace 'filename' and 'lineno' members with 'locus'.
[gcc.git] / gcc / cp / spew.c
1 /* Type Analyzer for GNU C++.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 Hacked... nay, bludgeoned... by Mark Eichin (eichin@cygnus.com)
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 /* This file is the type analyzer for GNU C++. To debug it, define SPEW_DEBUG
24 when compiling parse.c and spew.c. */
25
26 #include "config.h"
27 #include "system.h"
28 #include "input.h"
29 #include "tree.h"
30 #include "cp-tree.h"
31 #include "cpplib.h"
32 #include "c-pragma.h"
33 #include "lex.h"
34 #include "parse.h"
35 #include "flags.h"
36 #include "obstack.h"
37 #include "toplev.h"
38 #include "ggc.h"
39 #include "intl.h"
40 #include "timevar.h"
41
42 #ifdef SPEW_DEBUG
43 #define SPEW_INLINE
44 #else
45 #define SPEW_INLINE inline
46 #endif
47
48 /* This takes a token stream that hasn't decided much about types and
49 tries to figure out as much as it can, with excessive lookahead and
50 backtracking. */
51
52 /* fifo of tokens recognized and available to parser. */
53 struct token GTY(())
54 {
55 /* The values for YYCHAR will fit in a short. */
56 short yychar;
57 unsigned int lineno;
58 YYSTYPE GTY ((desc ("%1.yychar"))) yylval;
59 };
60
61 /* Since inline methods can refer to text which has not yet been seen,
62 we store the text of the method in a structure which is placed in the
63 DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL.
64 After parsing the body of the class definition, the FUNCTION_DECL's are
65 scanned to see which ones have this field set. Those are then digested
66 one at a time.
67
68 This function's FUNCTION_DECL will have a bit set in its common so
69 that we know to watch out for it. */
70
71 #define TOKEN_CHUNK_SIZE 20
72 struct token_chunk GTY(())
73 {
74 struct token_chunk *next;
75 struct token toks[TOKEN_CHUNK_SIZE];
76 };
77
78 struct unparsed_text GTY(())
79 {
80 struct unparsed_text *next; /* process this one next */
81 tree decl; /* associated declaration */
82 location_t locus; /* location we got the text from */
83 int interface; /* remembering interface_unknown and interface_only */
84
85 struct token_chunk * tokens; /* Start of the token list. */
86
87 struct token_chunk *last_chunk; /* End of the token list. */
88 short last_pos; /* Number of tokens used in the last chunk of
89 TOKENS. */
90
91 short cur_pos; /* Current token in 'cur_chunk', when rescanning. */
92 struct token_chunk *cur_chunk; /* Current chunk, when rescanning. */
93 };
94
95 /* Stack of state saved off when we return to an inline method or
96 default argument that has been stored for later parsing. */
97 struct feed GTY(())
98 {
99 struct unparsed_text *input;
100 location_t locus;
101 int yychar;
102 YYSTYPE GTY ((desc ("%1.yychar"))) yylval;
103 int first_token;
104 struct obstack GTY ((skip (""))) token_obstack;
105 struct feed *next;
106 };
107
108 static GTY(()) struct feed *feed;
109
110 static SPEW_INLINE void do_aggr PARAMS ((void));
111 static SPEW_INLINE int identifier_type PARAMS ((tree));
112 static void scan_tokens PARAMS ((int));
113 static void feed_defarg PARAMS ((tree));
114 static void finish_defarg PARAMS ((void));
115 static void yylexstring PARAMS ((struct token *));
116 static int read_token PARAMS ((struct token *));
117
118 static SPEW_INLINE int num_tokens PARAMS ((void));
119 static SPEW_INLINE struct token *nth_token PARAMS ((int));
120 static SPEW_INLINE int next_token PARAMS ((struct token *));
121 static SPEW_INLINE int shift_token PARAMS ((void));
122 static SPEW_INLINE void push_token PARAMS ((struct token *));
123 static SPEW_INLINE void consume_token PARAMS ((void));
124 static SPEW_INLINE int read_process_identifier PARAMS ((YYSTYPE *));
125
126 static SPEW_INLINE void feed_input PARAMS ((struct unparsed_text *));
127 static SPEW_INLINE struct token * space_for_token
128 PARAMS ((struct unparsed_text *t));
129 static SPEW_INLINE struct token * remove_last_token
130 PARAMS ((struct unparsed_text *t));
131 static struct unparsed_text * alloc_unparsed_text
132 PARAMS ((const location_t *, tree decl, int interface));
133
134 static void snarf_block PARAMS ((struct unparsed_text *t));
135 static tree snarf_defarg PARAMS ((void));
136 static int frob_id PARAMS ((int, int, tree *));
137
138 /* The list of inline functions being held off until we reach the end of
139 the current class declaration. */
140 static GTY(()) struct unparsed_text *pending_inlines;
141 static GTY(()) struct unparsed_text *pending_inlines_tail;
142
143 /* The list of previously-deferred inline functions currently being parsed.
144 This exists solely to be a GC root. */
145 static GTY(()) struct unparsed_text *processing_these_inlines;
146
147 static void begin_parsing_inclass_inline PARAMS ((struct unparsed_text *));
148
149 #ifdef SPEW_DEBUG
150 int spew_debug = 0;
151 static unsigned int yylex_ctr = 0;
152
153 static void debug_yychar PARAMS ((int));
154
155 /* In parse.y: */
156 extern char *debug_yytranslate PARAMS ((int));
157 #endif
158 static enum cpp_ttype last_token;
159 static tree last_token_id;
160
161 /* From lex.c: */
162 /* the declaration found for the last IDENTIFIER token read in. yylex
163 must look this up to detect typedefs, which get token type
164 tTYPENAME, so it is left around in case the identifier is not a
165 typedef but is used in a context which makes it a reference to a
166 variable. */
167 extern tree lastiddecl; /* let our brains leak out here too */
168 extern int yychar; /* the lookahead symbol */
169 extern YYSTYPE yylval; /* the semantic value of the */
170 /* lookahead symbol */
171 /* The token fifo lives in this obstack. */
172 static struct obstack token_obstack;
173 static int first_token;
174
175 /* When we see a default argument in a method declaration, we snarf it as
176 text using snarf_defarg. When we get up to namespace scope, we then go
177 through and parse all of them using do_pending_defargs. Since yacc
178 parsers are not reentrant, we retain defargs state in these two
179 variables so that subsequent calls to do_pending_defargs can resume
180 where the previous call left off. DEFARG_FNS is a tree_list where
181 the TREE_TYPE is the current_class_type, TREE_VALUE is the FUNCTION_DECL,
182 and TREE_PURPOSE is the list unprocessed dependent functions. */
183
184 /* list of functions with unprocessed defargs */
185 static GTY(()) tree defarg_fns;
186 /* current default parameter */
187 static GTY(()) tree defarg_parm;
188 /* list of unprocessed fns met during current fn. */
189 static GTY(()) tree defarg_depfns;
190 /* list of fns with circular defargs */
191 static GTY(()) tree defarg_fnsdone;
192
193 /* Initialize obstacks. Called once, from cxx_init. */
194
195 void
196 init_spew ()
197 {
198 gcc_obstack_init (&token_obstack);
199 }
200
201 /* Subroutine of read_token. */
202 static SPEW_INLINE int
203 read_process_identifier (pyylval)
204 YYSTYPE *pyylval;
205 {
206 tree id = pyylval->ttype;
207
208 if (C_IS_RESERVED_WORD (id))
209 {
210 /* Possibly replace the IDENTIFIER_NODE with a magic cookie.
211 Can't put yylval.code numbers in ridpointers[]. Bleah. */
212
213 switch (C_RID_CODE (id))
214 {
215 case RID_BITAND: pyylval->code = BIT_AND_EXPR; return '&';
216 case RID_AND_EQ: pyylval->code = BIT_AND_EXPR; return ASSIGN;
217 case RID_BITOR: pyylval->code = BIT_IOR_EXPR; return '|';
218 case RID_OR_EQ: pyylval->code = BIT_IOR_EXPR; return ASSIGN;
219 case RID_XOR: pyylval->code = BIT_XOR_EXPR; return '^';
220 case RID_XOR_EQ: pyylval->code = BIT_XOR_EXPR; return ASSIGN;
221 case RID_NOT_EQ: pyylval->code = NE_EXPR; return EQCOMPARE;
222
223 default:
224 pyylval->ttype = ridpointers[C_RID_CODE (id)];
225 return C_RID_YYCODE (id);
226 }
227 }
228
229 /* Make sure that user does not collide with our internal naming
230 scheme. This is not necessary if '.' is used to remove them from
231 the user's namespace, but is if '$' or double underscores are. */
232
233 #if !defined(JOINER) || JOINER == '$'
234 if (VPTR_NAME_P (id)
235 || VTABLE_NAME_P (id)
236 || TEMP_NAME_P (id)
237 || ANON_AGGRNAME_P (id))
238 warning (
239 "identifier name `%s' conflicts with GNU C++ internal naming strategy",
240 IDENTIFIER_POINTER (id));
241 #endif
242 return IDENTIFIER;
243 }
244
245 /* Concatenate strings before returning them to the parser. This isn't quite
246 as good as having it done in the lexer, but it's better than nothing. */
247
248 static void
249 yylexstring (t)
250 struct token *t;
251 {
252 enum cpp_ttype next_type;
253 tree next;
254
255 next_type = c_lex (&next);
256 if (next_type == CPP_STRING || next_type == CPP_WSTRING)
257 {
258 varray_type strings;
259
260 VARRAY_TREE_INIT (strings, 32, "strings");
261 VARRAY_PUSH_TREE (strings, t->yylval.ttype);
262
263 do
264 {
265 VARRAY_PUSH_TREE (strings, next);
266 next_type = c_lex (&next);
267 }
268 while (next_type == CPP_STRING || next_type == CPP_WSTRING);
269
270 t->yylval.ttype = combine_strings (strings);
271 last_token_id = t->yylval.ttype;
272 }
273
274 /* We will have always read one token too many. */
275 _cpp_backup_tokens (parse_in, 1);
276
277 t->yychar = STRING;
278 }
279
280 /* Read the next token from the input file. The token is written into
281 T, and its type number is returned. */
282 static int
283 read_token (t)
284 struct token *t;
285 {
286 retry:
287
288 last_token = c_lex (&last_token_id);
289 t->yylval.ttype = last_token_id;
290
291 switch (last_token)
292 {
293 #define YYCHAR(YY) t->yychar = (YY); break;
294 #define YYCODE(C) t->yylval.code = (C);
295
296 case CPP_EQ: YYCHAR('=');
297 case CPP_NOT: YYCHAR('!');
298 case CPP_GREATER: YYCODE(GT_EXPR); YYCHAR('>');
299 case CPP_LESS: YYCODE(LT_EXPR); YYCHAR('<');
300 case CPP_PLUS: YYCODE(PLUS_EXPR); YYCHAR('+');
301 case CPP_MINUS: YYCODE(MINUS_EXPR); YYCHAR('-');
302 case CPP_MULT: YYCODE(MULT_EXPR); YYCHAR('*');
303 case CPP_DIV: YYCODE(TRUNC_DIV_EXPR); YYCHAR('/');
304 case CPP_MOD: YYCODE(TRUNC_MOD_EXPR); YYCHAR('%');
305 case CPP_AND: YYCODE(BIT_AND_EXPR); YYCHAR('&');
306 case CPP_OR: YYCODE(BIT_IOR_EXPR); YYCHAR('|');
307 case CPP_XOR: YYCODE(BIT_XOR_EXPR); YYCHAR('^');
308 case CPP_RSHIFT: YYCODE(RSHIFT_EXPR); YYCHAR(RSHIFT);
309 case CPP_LSHIFT: YYCODE(LSHIFT_EXPR); YYCHAR(LSHIFT);
310
311 case CPP_COMPL: YYCHAR('~');
312 case CPP_AND_AND: YYCHAR(ANDAND);
313 case CPP_OR_OR: YYCHAR(OROR);
314 case CPP_QUERY: YYCHAR('?');
315 case CPP_COLON: YYCHAR(':');
316 case CPP_COMMA: YYCHAR(',');
317 case CPP_OPEN_PAREN: YYCHAR('(');
318 case CPP_CLOSE_PAREN: YYCHAR(')');
319 case CPP_EQ_EQ: YYCODE(EQ_EXPR); YYCHAR(EQCOMPARE);
320 case CPP_NOT_EQ: YYCODE(NE_EXPR); YYCHAR(EQCOMPARE);
321 case CPP_GREATER_EQ:YYCODE(GE_EXPR); YYCHAR(ARITHCOMPARE);
322 case CPP_LESS_EQ: YYCODE(LE_EXPR); YYCHAR(ARITHCOMPARE);
323
324 case CPP_PLUS_EQ: YYCODE(PLUS_EXPR); YYCHAR(ASSIGN);
325 case CPP_MINUS_EQ: YYCODE(MINUS_EXPR); YYCHAR(ASSIGN);
326 case CPP_MULT_EQ: YYCODE(MULT_EXPR); YYCHAR(ASSIGN);
327 case CPP_DIV_EQ: YYCODE(TRUNC_DIV_EXPR); YYCHAR(ASSIGN);
328 case CPP_MOD_EQ: YYCODE(TRUNC_MOD_EXPR); YYCHAR(ASSIGN);
329 case CPP_AND_EQ: YYCODE(BIT_AND_EXPR); YYCHAR(ASSIGN);
330 case CPP_OR_EQ: YYCODE(BIT_IOR_EXPR); YYCHAR(ASSIGN);
331 case CPP_XOR_EQ: YYCODE(BIT_XOR_EXPR); YYCHAR(ASSIGN);
332 case CPP_RSHIFT_EQ: YYCODE(RSHIFT_EXPR); YYCHAR(ASSIGN);
333 case CPP_LSHIFT_EQ: YYCODE(LSHIFT_EXPR); YYCHAR(ASSIGN);
334
335 case CPP_OPEN_SQUARE: YYCHAR('[');
336 case CPP_CLOSE_SQUARE: YYCHAR(']');
337 case CPP_OPEN_BRACE: YYCHAR('{');
338 case CPP_CLOSE_BRACE: YYCHAR('}');
339 case CPP_SEMICOLON: YYCHAR(';');
340 case CPP_ELLIPSIS: YYCHAR(ELLIPSIS);
341
342 case CPP_PLUS_PLUS: YYCHAR(PLUSPLUS);
343 case CPP_MINUS_MINUS: YYCHAR(MINUSMINUS);
344 case CPP_DEREF: YYCHAR(POINTSAT);
345 case CPP_DOT: YYCHAR('.');
346
347 /* These tokens are C++ specific. */
348 case CPP_SCOPE: YYCHAR(SCOPE);
349 case CPP_DEREF_STAR: YYCHAR(POINTSAT_STAR);
350 case CPP_DOT_STAR: YYCHAR(DOT_STAR);
351 case CPP_MIN_EQ: YYCODE(MIN_EXPR); YYCHAR(ASSIGN);
352 case CPP_MAX_EQ: YYCODE(MAX_EXPR); YYCHAR(ASSIGN);
353 case CPP_MIN: YYCODE(MIN_EXPR); YYCHAR(MIN_MAX);
354 case CPP_MAX: YYCODE(MAX_EXPR); YYCHAR(MIN_MAX);
355 #undef YYCHAR
356 #undef YYCODE
357
358 case CPP_EOF:
359 t->yychar = 0;
360 break;
361
362 case CPP_NAME:
363 t->yychar = read_process_identifier (&t->yylval);
364 break;
365
366 case CPP_NUMBER:
367 case CPP_CHAR:
368 case CPP_WCHAR:
369 t->yychar = CONSTANT;
370 break;
371
372 case CPP_STRING:
373 case CPP_WSTRING:
374 yylexstring (t);
375 break;
376
377 default:
378 yyerror ("parse error");
379 goto retry;
380 }
381
382 t->lineno = lineno;
383 return t->yychar;
384 }
385
386 static void
387 feed_input (input)
388 struct unparsed_text *input;
389 {
390 struct feed *f;
391 #if 0
392 if (feed)
393 abort ();
394 #endif
395
396 f = ggc_alloc (sizeof (struct feed));
397
398 input->cur_chunk = input->tokens;
399 input->cur_pos = 0;
400
401 #ifdef SPEW_DEBUG
402 if (spew_debug)
403 fprintf (stderr, "\tfeeding %s:%d [%d tokens]\n",
404 input->locus.file, input->locus.line, input->limit - input->pos);
405 #endif
406
407 f->input = input;
408 f->locus.file = input_filename;
409 f->locus.line = lineno;
410 f->yychar = yychar;
411 f->yylval = yylval;
412 f->first_token = first_token;
413 f->token_obstack = token_obstack;
414 f->next = feed;
415
416 input_filename = input->locus.file;
417 lineno = input->locus.line;
418 yychar = YYEMPTY;
419 yylval.ttype = NULL_TREE;
420 first_token = 0;
421 gcc_obstack_init (&token_obstack);
422 feed = f;
423 }
424
425 void
426 end_input ()
427 {
428 struct feed *f = feed;
429
430 input_filename = f->locus.file;
431 lineno = f->locus.line;
432 yychar = f->yychar;
433 yylval = f->yylval;
434 first_token = f->first_token;
435 obstack_free (&token_obstack, 0);
436 token_obstack = f->token_obstack;
437 feed = f->next;
438
439 #ifdef SPEW_DEBUG
440 if (spew_debug)
441 fprintf (stderr, "\treturning to %s:%d\n", input_filename, lineno);
442 #endif
443 }
444
445 /* Token queue management. */
446
447 /* Return the number of tokens available on the fifo. */
448 static SPEW_INLINE int
449 num_tokens ()
450 {
451 return (obstack_object_size (&token_obstack) / sizeof (struct token))
452 - first_token;
453 }
454
455 /* Fetch the token N down the line from the head of the fifo. */
456
457 static SPEW_INLINE struct token*
458 nth_token (n)
459 int n;
460 {
461 #ifdef ENABLE_CHECKING
462 /* could just have this do slurp_ implicitly, but this way is easier
463 to debug... */
464 my_friendly_assert (n >= 0 && n < num_tokens (), 298);
465 #endif
466 return ((struct token*)obstack_base (&token_obstack)) + n + first_token;
467 }
468
469 static const struct token Teosi = { END_OF_SAVED_INPUT, 0 UNION_INIT_ZERO };
470 static const struct token Tpad = { EMPTY, 0 UNION_INIT_ZERO };
471
472 /* Copy the next token into T and return its value. */
473 static SPEW_INLINE int
474 next_token (t)
475 struct token *t;
476 {
477 if (!feed)
478 return read_token (t);
479
480 if (feed->input->cur_chunk != feed->input->last_chunk
481 || feed->input->cur_pos != feed->input->last_pos)
482 {
483 if (feed->input->cur_pos == TOKEN_CHUNK_SIZE)
484 {
485 feed->input->cur_chunk = feed->input->cur_chunk->next;
486 feed->input->cur_pos = 0;
487 }
488 memcpy (t, feed->input->cur_chunk->toks + feed->input->cur_pos,
489 sizeof (struct token));
490 feed->input->cur_pos++;
491 return t->yychar;
492 }
493
494 memcpy (t, &Teosi, sizeof (struct token));
495 return END_OF_SAVED_INPUT;
496 }
497
498 /* Shift the next token onto the fifo. */
499 static SPEW_INLINE int
500 shift_token ()
501 {
502 size_t point = obstack_object_size (&token_obstack);
503 obstack_blank (&token_obstack, sizeof (struct token));
504 return next_token ((struct token *) (obstack_base (&token_obstack) + point));
505 }
506
507 /* Consume the next token out of the fifo. */
508
509 static SPEW_INLINE void
510 consume_token ()
511 {
512 if (num_tokens () == 1)
513 {
514 obstack_free (&token_obstack, obstack_base (&token_obstack));
515 first_token = 0;
516 }
517 else
518 first_token++;
519 }
520
521 /* Push a token at the head of the queue; it will be the next token read. */
522 static SPEW_INLINE void
523 push_token (t)
524 struct token *t;
525 {
526 if (first_token == 0) /* We hope this doesn't happen often. */
527 {
528 size_t active = obstack_object_size (&token_obstack);
529 obstack_blank (&token_obstack, sizeof (struct token));
530 if (active)
531 memmove (obstack_base (&token_obstack) + sizeof (struct token),
532 obstack_base (&token_obstack), active);
533 first_token++;
534 }
535 first_token--;
536 memcpy (nth_token (0), t, sizeof (struct token));
537 }
538
539
540 /* Pull in enough tokens that the queue is N long beyond the current
541 token. */
542
543 static void
544 scan_tokens (n)
545 int n;
546 {
547 int i;
548 int num = num_tokens ();
549 int yychar;
550
551 /* First, prune any empty tokens at the end. */
552 i = num;
553 while (i > 0 && nth_token (i - 1)->yychar == EMPTY)
554 i--;
555 if (i < num)
556 {
557 obstack_blank (&token_obstack, -((num - i) * sizeof (struct token)));
558 num = i;
559 }
560
561 /* Now, if we already have enough tokens, return. */
562 if (num > n)
563 return;
564
565 /* Never read past these characters: they might separate
566 the current input stream from one we save away later. */
567 for (i = 0; i < num; i++)
568 {
569 yychar = nth_token (i)->yychar;
570 if (yychar == '{' || yychar == ':' || yychar == ';')
571 goto pad_tokens;
572 }
573
574 while (num_tokens () <= n)
575 {
576 yychar = shift_token ();
577 if (yychar == '{' || yychar == ':' || yychar == ';')
578 goto pad_tokens;
579 }
580 return;
581
582 pad_tokens:
583 while (num_tokens () <= n)
584 obstack_grow (&token_obstack, &Tpad, sizeof (struct token));
585 }
586
587 int looking_for_typename;
588 int looking_for_template;
589
590 static int after_friend;
591 static int after_new;
592 static int do_snarf_defarg;
593
594 tree got_scope;
595 tree got_object;
596
597 static SPEW_INLINE int
598 identifier_type (decl)
599 tree decl;
600 {
601 tree t;
602
603 if (TREE_CODE (decl) == TEMPLATE_DECL)
604 {
605 if (TREE_CODE (DECL_TEMPLATE_RESULT (decl)) == TYPE_DECL)
606 return PTYPENAME;
607 else if (looking_for_template)
608 return PFUNCNAME;
609 }
610 if (looking_for_template && really_overloaded_fn (decl))
611 {
612 /* See through a baselink. */
613 if (TREE_CODE (decl) == TREE_LIST)
614 decl = TREE_VALUE (decl);
615
616 for (t = decl; t != NULL_TREE; t = OVL_CHAIN (t))
617 if (DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (t)))
618 return PFUNCNAME;
619 }
620 if (TREE_CODE (decl) == NAMESPACE_DECL)
621 return NSNAME;
622 if (TREE_CODE (decl) != TYPE_DECL)
623 return IDENTIFIER;
624 if (DECL_ARTIFICIAL (decl) && TREE_TYPE (decl) == current_class_type)
625 return SELFNAME;
626
627 /* A constructor declarator for a template type will get here as an
628 implicit typename, a TYPENAME_TYPE with a type. */
629 t = got_scope;
630 if (t && TREE_CODE (t) == TYPENAME_TYPE)
631 t = TREE_TYPE (t);
632 decl = TREE_TYPE (decl);
633 if (TREE_CODE (decl) == TYPENAME_TYPE)
634 decl = TREE_TYPE (decl);
635 if (t && t == decl)
636 return SELFNAME;
637
638 return tTYPENAME;
639 }
640
641 /* token[0] == AGGR (struct/union/enum)
642 Thus, token[1] is either a tTYPENAME or a TYPENAME_DEFN.
643 If token[2] == '{' or ':' then it's TYPENAME_DEFN.
644 It's also a definition if it's a forward declaration (as in 'struct Foo;')
645 which we can tell if token[2] == ';' *and* token[-1] != FRIEND or NEW. */
646
647 static SPEW_INLINE void
648 do_aggr ()
649 {
650 int yc1, yc2;
651
652 scan_tokens (2);
653 yc1 = nth_token (1)->yychar;
654 if (yc1 != tTYPENAME && yc1 != IDENTIFIER && yc1 != PTYPENAME)
655 return;
656 yc2 = nth_token (2)->yychar;
657 if (yc2 == ';')
658 {
659 /* It's a forward declaration iff we were not preceded by
660 'friend' or `new'. */
661 if (after_friend || after_new)
662 return;
663 }
664 else if (yc2 != '{' && yc2 != ':')
665 return;
666
667 switch (yc1)
668 {
669 case tTYPENAME:
670 nth_token (1)->yychar = TYPENAME_DEFN;
671 break;
672 case PTYPENAME:
673 nth_token (1)->yychar = PTYPENAME_DEFN;
674 break;
675 case IDENTIFIER:
676 nth_token (1)->yychar = IDENTIFIER_DEFN;
677 break;
678 default:
679 abort ();
680 }
681 }
682
683 void
684 see_typename ()
685 {
686 /* Only types expected, not even namespaces. */
687 looking_for_typename = 2;
688 if (yychar < 0)
689 if ((yychar = yylex ()) < 0) yychar = 0;
690 looking_for_typename = 0;
691 if (yychar == IDENTIFIER)
692 {
693 lastiddecl = lookup_name (yylval.ttype, -2);
694 if (lastiddecl)
695 yychar = identifier_type (lastiddecl);
696 }
697 }
698
699 int
700 yylex ()
701 {
702 int yychr;
703 int old_looking_for_typename = 0;
704 int just_saw_new = 0;
705 int just_saw_friend = 0;
706
707 timevar_push (TV_LEX);
708
709 retry:
710 #ifdef SPEW_DEBUG
711 if (spew_debug)
712 {
713 yylex_ctr ++;
714 fprintf (stderr, "\t\t## %d @%d ", yylex_ctr, lineno);
715 }
716 #endif
717
718 if (do_snarf_defarg)
719 {
720 do_snarf_defarg = 0;
721 yylval.ttype = snarf_defarg ();
722 yychar = DEFARG;
723 got_object = NULL_TREE;
724 timevar_pop (TV_LEX);
725 return DEFARG;
726 }
727
728 /* if we've got tokens, send them */
729 else if (num_tokens ())
730 yychr = nth_token (0)->yychar;
731 else
732 yychr = shift_token ();
733
734 /* many tokens just need to be returned. At first glance, all we
735 have to do is send them back up, but some of them are needed to
736 figure out local context. */
737 switch (yychr)
738 {
739 case EMPTY:
740 /* This is a lexical no-op. */
741 #ifdef SPEW_DEBUG
742 if (spew_debug)
743 debug_yychar (yychr);
744 #endif
745 consume_token ();
746 goto retry;
747
748 case '(':
749 scan_tokens (1);
750 if (nth_token (1)->yychar == ')')
751 {
752 consume_token ();
753 yychr = LEFT_RIGHT;
754 }
755 break;
756
757 case IDENTIFIER:
758 {
759 int peek;
760
761 scan_tokens (1);
762 peek = nth_token (1)->yychar;
763 yychr = frob_id (yychr, peek, &nth_token (0)->yylval.ttype);
764 break;
765 }
766 case IDENTIFIER_DEFN:
767 case tTYPENAME:
768 case TYPENAME_DEFN:
769 case PTYPENAME:
770 case PTYPENAME_DEFN:
771 /* If we see a SCOPE next, restore the old value.
772 Otherwise, we got what we want. */
773 looking_for_typename = old_looking_for_typename;
774 looking_for_template = 0;
775 break;
776
777 case SCSPEC:
778 if (nth_token (0)->yylval.ttype == ridpointers[RID_EXTERN])
779 {
780 scan_tokens (1);
781 if (nth_token (1)->yychar == STRING)
782 {
783 yychr = EXTERN_LANG_STRING;
784 nth_token (1)->yylval.ttype = get_identifier
785 (TREE_STRING_POINTER (nth_token (1)->yylval.ttype));
786 consume_token ();
787 }
788 }
789 /* do_aggr needs to know if the previous token was `friend'. */
790 else if (nth_token (0)->yylval.ttype == ridpointers[RID_FRIEND])
791 just_saw_friend = 1;
792
793 break;
794
795 case NEW:
796 /* do_aggr needs to know if the previous token was `new'. */
797 just_saw_new = 1;
798 break;
799
800 case TYPESPEC:
801 case '{':
802 case ':':
803 case ';':
804 /* If this provides a type for us, then revert lexical
805 state to standard state. */
806 looking_for_typename = 0;
807 break;
808
809 case AGGR:
810 do_aggr ();
811 break;
812
813 case ENUM:
814 /* Set this again, in case we are rescanning. */
815 looking_for_typename = 2;
816 break;
817
818 default:
819 break;
820 }
821
822 after_friend = just_saw_friend;
823 after_new = just_saw_new;
824
825 /* class member lookup only applies to the first token after the object
826 expression, except for explicit destructor calls. */
827 if (yychr != '~')
828 got_object = NULL_TREE;
829
830 yychar = yychr;
831 {
832 struct token *tok = nth_token (0);
833
834 yylval = tok->yylval;
835 if (tok->lineno)
836 lineno = tok->lineno;
837 }
838
839 #ifdef SPEW_DEBUG
840 if (spew_debug)
841 debug_yychar (yychr);
842 #endif
843 consume_token ();
844
845 timevar_pop (TV_LEX);
846 return yychr;
847 }
848
849 /* Unget character CH from the input stream.
850 If RESCAN is non-zero, then we want to `see' this
851 character as the next input token. */
852
853 void
854 yyungetc (ch, rescan)
855 int ch;
856 int rescan;
857 {
858 /* Unget a character from the input stream. */
859 if (yychar == YYEMPTY || rescan == 0)
860 {
861 struct token fake;
862
863 fake.yychar = ch;
864 fake.yylval.ttype = 0;
865 fake.lineno = lineno;
866
867 push_token (&fake);
868 }
869 else
870 {
871 yychar = ch;
872 }
873 }
874
875 /* Lexer hackery to determine what *IDP really is. */
876
877 static int
878 frob_id (yyc, peek, idp)
879 int yyc;
880 int peek;
881 tree *idp;
882 {
883 tree trrr;
884 int old_looking_for_typename = 0;
885
886 if (peek == SCOPE)
887 {
888 /* Don't interfere with the setting from an 'aggr' prefix. */
889 old_looking_for_typename = looking_for_typename;
890 looking_for_typename = 1;
891 }
892 else if (peek == '<')
893 looking_for_template = 1;
894 trrr = lookup_name (*idp, -2);
895 if (trrr)
896 {
897 yyc = identifier_type (trrr);
898 switch(yyc)
899 {
900 case tTYPENAME:
901 case SELFNAME:
902 case NSNAME:
903 case PTYPENAME:
904 /* If this got special lookup, remember it. In these
905 cases, we know it can't be a declarator-id. */
906 if (got_scope || got_object)
907 *idp = trrr;
908 /* FALLTHROUGH */
909 case PFUNCNAME:
910 case IDENTIFIER:
911 lastiddecl = trrr;
912 break;
913 default:
914 abort ();
915 }
916 }
917 else
918 lastiddecl = NULL_TREE;
919 got_scope = NULL_TREE;
920 looking_for_typename = old_looking_for_typename;
921 looking_for_template = 0;
922 return yyc;
923 }
924
925 /* ID is an operator name. Duplicate the hackery in yylex to determine what
926 it really is. */
927
928 tree frob_opname (id)
929 tree id;
930 {
931 scan_tokens (0);
932 frob_id (0, nth_token (0)->yychar, &id);
933 got_object = NULL_TREE;
934 return id;
935 }
936
937 /* Set up the state required to correctly handle the definition of the
938 inline function whose preparsed state has been saved in PI. */
939
940 static void
941 begin_parsing_inclass_inline (pi)
942 struct unparsed_text *pi;
943 {
944 tree context;
945
946 /* Record that we are processing the chain of inlines starting at
947 PI for GC. */
948 if (cfun)
949 cp_function_chain->unparsed_inlines = pi;
950 else
951 processing_these_inlines = pi;
952
953 ggc_collect ();
954
955 /* If this is an inline function in a local class, we must make sure
956 that we save all pertinent information about the function
957 surrounding the local class. */
958 context = decl_function_context (pi->decl);
959 if (context)
960 push_function_context_to (context);
961
962 feed_input (pi);
963 interface_unknown = pi->interface == 1;
964 interface_only = pi->interface == 0;
965 DECL_PENDING_INLINE_P (pi->decl) = 0;
966 DECL_PENDING_INLINE_INFO (pi->decl) = 0;
967
968 /* Pass back a handle to the rest of the inline functions, so that they
969 can be processed later. */
970 yychar = PRE_PARSED_FUNCTION_DECL;
971 yylval.pi = pi;
972
973 start_function (NULL_TREE, pi->decl, NULL_TREE,
974 (SF_DEFAULT | SF_PRE_PARSED | SF_INCLASS_INLINE));
975 }
976
977 /* Called from the top level: if there are any pending inlines to
978 do, set up to process them now. This function sets up the first function
979 to be parsed; after it has been, the rule for fndef in parse.y will
980 call process_next_inline to start working on the next one. */
981
982 void
983 do_pending_inlines ()
984 {
985 /* Oops, we're still dealing with the last batch. */
986 if (yychar == PRE_PARSED_FUNCTION_DECL)
987 return;
988
989 if (pending_inlines)
990 {
991 /* Clear the chain, so that any inlines nested inside the batch
992 we're to process now don't refer to this batch. See e.g.
993 g++.other/lookup6.C. */
994 struct unparsed_text *first = pending_inlines;
995 pending_inlines = pending_inlines_tail = 0;
996
997 begin_parsing_inclass_inline (first);
998 }
999 }
1000
1001 /* Called from the fndecl rule in the parser when the function just parsed
1002 was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from
1003 do_pending_inlines). */
1004
1005 void
1006 process_next_inline (i)
1007 struct unparsed_text *i;
1008 {
1009 tree decl = i->decl;
1010 tree context = decl_function_context (decl);
1011
1012 if (context)
1013 pop_function_context_from (context);
1014 if (yychar == YYEMPTY)
1015 yychar = yylex ();
1016 if (yychar != END_OF_SAVED_INPUT)
1017 error ("parse error at end of saved function text");
1018 end_input ();
1019
1020 i = i->next;
1021 if (i)
1022 begin_parsing_inclass_inline (i);
1023 else
1024 {
1025 if (cfun)
1026 cp_function_chain->unparsed_inlines = 0;
1027 else
1028 processing_these_inlines = 0;
1029 extract_interface_info ();
1030 }
1031 }
1032 \f
1033 /* Create a new token at the end of the token list in T. */
1034 static SPEW_INLINE struct token *
1035 space_for_token (t)
1036 struct unparsed_text *t;
1037 {
1038 if (t->last_pos != TOKEN_CHUNK_SIZE)
1039 return t->last_chunk->toks + (t->last_pos++);
1040
1041 t->last_chunk->next = ggc_alloc (sizeof (*t->last_chunk->next));
1042 t->last_chunk = t->last_chunk->next;
1043 t->last_chunk->next = NULL;
1044
1045 t->last_pos = 1;
1046 return t->last_chunk->toks;
1047 }
1048
1049 /* Shrink the token list in T by one token. */
1050 static SPEW_INLINE struct token *
1051 remove_last_token (t)
1052 struct unparsed_text *t;
1053 {
1054 struct token *result = t->last_chunk->toks + t->last_pos - 1;
1055 if (t->last_pos == 0)
1056 abort ();
1057 t->last_pos--;
1058 if (t->last_pos == 0 && t->last_chunk != t->tokens)
1059 {
1060 struct token_chunk **tc;
1061 for (tc = &t->tokens; (*tc)->next != NULL; tc = &(*tc)->next)
1062 ;
1063 *tc = NULL;
1064 t->last_pos = ARRAY_SIZE ((*tc)->toks);
1065 }
1066 return result;
1067 }
1068
1069 /* Allocate an 'unparsed_text' structure, ready to use space_for_token. */
1070 static struct unparsed_text *
1071 alloc_unparsed_text (locus, decl, interface)
1072 const location_t *locus;
1073 tree decl;
1074 int interface;
1075 {
1076 struct unparsed_text *r;
1077 r = ggc_alloc_cleared (sizeof (*r));
1078 r->decl = decl;
1079 r->locus = *locus;
1080 r->interface = interface;
1081 r->tokens = r->last_chunk = ggc_alloc_cleared (sizeof (*r->tokens));
1082 return r;
1083 }
1084
1085 /* Subroutine of snarf_method, deals with actual absorption of the block. */
1086
1087 static void
1088 snarf_block (t)
1089 struct unparsed_text *t;
1090 {
1091 int blev = 1;
1092 int look_for_semicolon = 0;
1093 int look_for_lbrac = 0;
1094 int look_for_catch = 0;
1095 int yyc;
1096 struct token *current;
1097
1098 if (yychar == '{')
1099 ;
1100 else if (yychar == '=')
1101 look_for_semicolon = 1;
1102 else if (yychar == ':' || yychar == RETURN_KEYWORD || yychar == TRY)
1103 {
1104 if (yychar == TRY)
1105 look_for_catch = 1;
1106 look_for_lbrac = 1;
1107 blev = 0;
1108 }
1109 else
1110 yyerror ("parse error in method specification");
1111
1112 /* The current token is the first one to be recorded. */
1113 current = space_for_token (t);
1114 current->yychar = yychar;
1115 current->yylval = yylval;
1116 current->lineno = lineno;
1117
1118 for (;;)
1119 {
1120 yyc = next_token (space_for_token (t));
1121
1122 if (yyc == '{')
1123 {
1124 look_for_lbrac = 0;
1125 blev++;
1126 }
1127 else if (yyc == '}')
1128 {
1129 blev--;
1130 if (blev == 0 && !look_for_semicolon)
1131 {
1132 if (!look_for_catch)
1133 break;
1134
1135 if (next_token (space_for_token (t)) != CATCH)
1136 {
1137 push_token (remove_last_token (t));
1138 break;
1139 }
1140
1141 look_for_lbrac = 1;
1142 }
1143 }
1144 else if (yyc == ';')
1145 {
1146 if (look_for_lbrac)
1147 {
1148 struct token *fake;
1149
1150 error ("function body for constructor missing");
1151 /* fake a { } to avoid further errors */
1152 fake = space_for_token (t);
1153 fake->yylval.ttype = 0;
1154 fake->yychar = '{';
1155 fake = space_for_token (t);
1156 fake->yylval.ttype = 0;
1157 fake->yychar = '}';
1158 break;
1159 }
1160 else if (look_for_semicolon && blev == 0)
1161 break;
1162 }
1163 else if (yyc == 0)
1164 {
1165 error ("%Hend of file read inside definition", &t->locus);
1166 break;
1167 }
1168 }
1169 }
1170
1171 /* This function stores away the text for an inline function that should
1172 be processed later (by do_pending_inlines). */
1173 void
1174 snarf_method (decl)
1175 tree decl;
1176 {
1177 struct unparsed_text *meth;
1178 location_t starting;
1179 starting.file = input_filename;
1180 starting.line = lineno;
1181
1182 meth = alloc_unparsed_text (&starting, decl, (interface_unknown ? 1
1183 : (interface_only ? 0 : 2)));
1184
1185 snarf_block (meth);
1186
1187 /* Happens when we get two declarations of the same function in the
1188 same scope. */
1189 if (decl == void_type_node
1190 || (current_class_type && TYPE_REDEFINED (current_class_type)))
1191 return;
1192
1193 #ifdef SPEW_DEBUG
1194 if (spew_debug)
1195 fprintf (stderr, "\tsaved method of %d tokens from %s:%d\n",
1196 meth->limit, starting.file, starting.line);
1197 #endif
1198
1199 DECL_PENDING_INLINE_INFO (decl) = meth;
1200 DECL_PENDING_INLINE_P (decl) = 1;
1201
1202 if (pending_inlines_tail)
1203 pending_inlines_tail->next = meth;
1204 else
1205 pending_inlines = meth;
1206 pending_inlines_tail = meth;
1207 }
1208
1209 /* Consume a no-commas expression - a default argument - and return
1210 a DEFAULT_ARG tree node. */
1211
1212 static tree
1213 snarf_defarg ()
1214 {
1215 int yyc;
1216 int plev = 0;
1217 struct unparsed_text *buf;
1218 tree arg;
1219 location_t starting;
1220 starting.file = input_filename;
1221 starting.line = lineno;
1222
1223 buf = alloc_unparsed_text (&starting, 0, 0);
1224
1225 for (;;)
1226 {
1227 yyc = next_token (space_for_token (buf));
1228
1229 if (plev <= 0 && (yyc == ')' || yyc == ','))
1230 break;
1231 else if (yyc == '(' || yyc == '[')
1232 ++plev;
1233 else if (yyc == ']' || yyc == ')')
1234 --plev;
1235 else if (yyc == 0)
1236 {
1237 error ("%Hend of file read inside default argument", &starting);
1238 goto done;
1239 }
1240 }
1241
1242 /* Unget the last token. */
1243 push_token (remove_last_token (buf));
1244
1245 done:
1246 #ifdef SPEW_DEBUG
1247 if (spew_debug)
1248 fprintf (stderr, "\tsaved defarg of %d tokens from %s:%d\n",
1249 buf->limit, starting.file, starting.line);
1250 #endif
1251
1252 arg = make_node (DEFAULT_ARG);
1253 DEFARG_POINTER (arg) = (char *)buf;
1254
1255 return arg;
1256 }
1257
1258 /* Decide whether the default argument we are about to see should be
1259 gobbled up as text for later parsing. */
1260
1261 void
1262 maybe_snarf_defarg ()
1263 {
1264 if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
1265 do_snarf_defarg = 1;
1266 }
1267
1268 /* Called from grokfndecl to note a function decl with unparsed default
1269 arguments for later processing. Also called from grokdeclarator
1270 for function types with unparsed defargs; the call from grokfndecl
1271 will always come second, so we can overwrite the entry from the type. */
1272
1273 void
1274 add_defarg_fn (decl)
1275 tree decl;
1276 {
1277 if (TREE_CODE (decl) == FUNCTION_DECL)
1278 TREE_VALUE (defarg_fns) = decl;
1279 else
1280 {
1281 defarg_fns = tree_cons (NULL_TREE, decl, defarg_fns);
1282 TREE_TYPE (defarg_fns) = current_class_type;
1283 }
1284 }
1285
1286 /* Helper for do_pending_defargs. Starts the parsing of a default arg. */
1287
1288 static void
1289 feed_defarg (p)
1290 tree p;
1291 {
1292 tree d = TREE_PURPOSE (p);
1293
1294 feed_input ((struct unparsed_text *)DEFARG_POINTER (d));
1295 yychar = DEFARG_MARKER;
1296 yylval.ttype = p;
1297 }
1298
1299 /* Helper for do_pending_defargs. Ends the parsing of a default arg. */
1300
1301 static void
1302 finish_defarg ()
1303 {
1304 if (yychar == YYEMPTY)
1305 yychar = yylex ();
1306 if (yychar != END_OF_SAVED_INPUT)
1307 error ("parse error at end of saved function text");
1308
1309 end_input ();
1310 }
1311
1312 /* Main function for deferred parsing of default arguments. Called from
1313 the parser. */
1314
1315 void
1316 do_pending_defargs ()
1317 {
1318 if (defarg_parm)
1319 finish_defarg ();
1320
1321 for (; defarg_fns;)
1322 {
1323 tree current = defarg_fns;
1324
1325 tree defarg_fn = TREE_VALUE (defarg_fns);
1326 if (defarg_parm == NULL_TREE)
1327 {
1328 push_nested_class (TREE_TYPE (defarg_fns), 1);
1329 pushlevel (0);
1330 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1331 maybe_begin_member_template_processing (defarg_fn);
1332
1333 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1334 defarg_parm = TYPE_ARG_TYPES (TREE_TYPE (defarg_fn));
1335 else
1336 defarg_parm = TYPE_ARG_TYPES (defarg_fn);
1337 }
1338 else
1339 defarg_parm = TREE_CHAIN (defarg_parm);
1340
1341 for (; defarg_parm; defarg_parm = TREE_CHAIN (defarg_parm))
1342 if (!TREE_PURPOSE (defarg_parm)
1343 || TREE_CODE (TREE_PURPOSE (defarg_parm)) != DEFAULT_ARG)
1344 ;/* OK */
1345 else if (TREE_PURPOSE (current) == error_mark_node)
1346 DEFARG_POINTER (TREE_PURPOSE (defarg_parm)) = NULL;
1347 else
1348 {
1349 feed_defarg (defarg_parm);
1350
1351 /* Return to the parser, which will process this defarg
1352 and call us again. */
1353 return;
1354 }
1355
1356 if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1357 {
1358 maybe_end_member_template_processing ();
1359 check_default_args (defarg_fn);
1360 }
1361
1362 poplevel (0, 0, 0);
1363 pop_nested_class ();
1364
1365 defarg_fns = TREE_CHAIN (defarg_fns);
1366 if (defarg_depfns)
1367 {
1368 /* This function's default args depend on unprocessed default args
1369 of defarg_fns. We will need to reprocess this function, and
1370 check for circular dependencies. */
1371 tree a, b;
1372
1373 for (a = defarg_depfns, b = TREE_PURPOSE (current); a && b;
1374 a = TREE_CHAIN (a), b = TREE_CHAIN (b))
1375 if (TREE_VALUE (a) != TREE_VALUE (b))
1376 goto different;
1377 if (a || b)
1378 {
1379 different:;
1380 TREE_CHAIN (current) = NULL_TREE;
1381 defarg_fns = chainon (defarg_fns, current);
1382 TREE_PURPOSE (current) = defarg_depfns;
1383 }
1384 else
1385 {
1386 cp_warning_at ("circular dependency in default args of `%#D'", defarg_fn);
1387 /* No need to say what else is dependent, as they will be
1388 picked up in another pass. */
1389
1390 /* Immediately repeat, but marked so that we break the loop. */
1391 defarg_fns = current;
1392 TREE_PURPOSE (current) = error_mark_node;
1393 }
1394 defarg_depfns = NULL_TREE;
1395 }
1396 else if (TREE_PURPOSE (current) == error_mark_node)
1397 defarg_fnsdone = tree_cons (NULL_TREE, defarg_fn, defarg_fnsdone);
1398 }
1399 }
1400
1401 /* After parsing all the default arguments, we must clear any that remain,
1402 which will be part of a circular dependency. */
1403 void
1404 done_pending_defargs ()
1405 {
1406 for (; defarg_fnsdone; defarg_fnsdone = TREE_CHAIN (defarg_fnsdone))
1407 {
1408 tree fn = TREE_VALUE (defarg_fnsdone);
1409 tree parms;
1410
1411 if (TREE_CODE (fn) == FUNCTION_DECL)
1412 parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
1413 else
1414 parms = TYPE_ARG_TYPES (fn);
1415 for (; parms; parms = TREE_CHAIN (parms))
1416 if (TREE_PURPOSE (parms)
1417 && TREE_CODE (TREE_PURPOSE (parms)) == DEFAULT_ARG)
1418 {
1419 my_friendly_assert (!DEFARG_POINTER (TREE_PURPOSE (parms)), 20010107);
1420 TREE_PURPOSE (parms) = NULL_TREE;
1421 }
1422 }
1423 }
1424
1425 /* In processing the current default arg, we called FN, but that call
1426 required a default argument of FN, and that had not yet been processed.
1427 Remember FN. */
1428
1429 void
1430 unprocessed_defarg_fn (fn)
1431 tree fn;
1432 {
1433 defarg_depfns = tree_cons (NULL_TREE, fn, defarg_depfns);
1434 }
1435
1436 /* Called from the parser to update an element of TYPE_ARG_TYPES for some
1437 FUNCTION_TYPE with the newly parsed version of its default argument, which
1438 was previously digested as text. */
1439
1440 void
1441 replace_defarg (arg, init)
1442 tree arg, init;
1443 {
1444 if (init == error_mark_node)
1445 TREE_PURPOSE (arg) = error_mark_node;
1446 else
1447 {
1448 if (! processing_template_decl
1449 && ! can_convert_arg (TREE_VALUE (arg), TREE_TYPE (init), init))
1450 pedwarn ("invalid type `%T' for default argument to `%T'",
1451 TREE_TYPE (init), TREE_VALUE (arg));
1452 if (!defarg_depfns)
1453 TREE_PURPOSE (arg) = init;
1454 }
1455 }
1456
1457 #ifdef SPEW_DEBUG
1458 /* debug_yychar takes a yychar (token number) value and prints its name. */
1459
1460 static void
1461 debug_yychar (yy)
1462 int yy;
1463 {
1464 if (yy<256)
1465 fprintf (stderr, "->%d < %c >\n", lineno, yy);
1466 else if (yy == IDENTIFIER || yy == tTYPENAME)
1467 {
1468 const char *id;
1469 if (TREE_CODE (yylval.ttype) == IDENTIFIER_NODE)
1470 id = IDENTIFIER_POINTER (yylval.ttype);
1471 else if (TREE_CODE_CLASS (TREE_CODE (yylval.ttype)) == 'd')
1472 id = IDENTIFIER_POINTER (DECL_NAME (yylval.ttype));
1473 else
1474 id = "";
1475 fprintf (stderr, "->%d <%s `%s'>\n", lineno, debug_yytranslate (yy), id);
1476 }
1477 else
1478 fprintf (stderr, "->%d <%s>\n", lineno, debug_yytranslate (yy));
1479 }
1480
1481 #endif
1482
1483 #define NAME(TYPE) cpp_type2name (TYPE)
1484
1485 void
1486 yyerror (msgid)
1487 const char *msgid;
1488 {
1489 const char *string = _(msgid);
1490
1491 if (last_token == CPP_EOF)
1492 error ("%s at end of input", string);
1493 else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
1494 {
1495 unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
1496 const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
1497 if (val <= UCHAR_MAX && ISGRAPH (val))
1498 error ("%s before %s'%c'", string, ell, val);
1499 else
1500 error ("%s before %s'\\x%x'", string, ell, val);
1501 }
1502 else if (last_token == CPP_STRING
1503 || last_token == CPP_WSTRING)
1504 error ("%s before string constant", string);
1505 else if (last_token == CPP_NUMBER)
1506 error ("%s before numeric constant", string);
1507 else if (last_token == CPP_NAME)
1508 {
1509 if (TREE_CODE (last_token_id) == IDENTIFIER_NODE)
1510 error ("%s before `%s'", string, IDENTIFIER_POINTER (last_token_id));
1511 else if (ISGRAPH (yychar))
1512 error ("%s before `%c'", string, yychar);
1513 else
1514 error ("%s before `\%o'", string, yychar);
1515 }
1516 else
1517 error ("%s before `%s' token", string, NAME (last_token));
1518 }
1519
1520 #include "gt-cp-spew.h"