OSDN Git Service

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