OSDN Git Service

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