OSDN Git Service

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