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