OSDN Git Service

* decl.c (lookup_name_real): Set the complain flag if we're
[pf3gnuchains/gcc-fork.git] / gcc / cp / lex.c
1 /* Separate lexical analyzer for GNU C++.
2    Copyright (C) 1987, 89, 92-98, 1999 Free Software Foundation, Inc.
3    Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 /* This file is the lexical analyzer for GNU C++.  */
24
25 /* Cause the `yydebug' variable to be defined.  */
26 #define YYDEBUG 1
27
28 #include "config.h"
29 #include "system.h"
30 #include "input.h"
31 #include "tree.h"
32 #include "lex.h"
33 #include "cp-tree.h"
34 #include "parse.h"
35 #include "flags.h"
36 #include "obstack.h"
37 #include "c-pragma.h"
38 #include "toplev.h"
39 #include "output.h"
40
41 #ifdef MULTIBYTE_CHARS
42 #include "mbchar.h"
43 #include <locale.h>
44 #endif
45
46 #define obstack_chunk_alloc xmalloc
47 #define obstack_chunk_free free
48
49 #ifndef DIR_SEPARATOR
50 #define DIR_SEPARATOR '/'
51 #endif
52
53 extern struct obstack permanent_obstack;
54 extern struct obstack *current_obstack, *saveable_obstack;
55
56 extern void yyprint PROTO((FILE *, int, YYSTYPE));
57
58 static tree get_time_identifier PROTO((const char *));
59 static int check_newline PROTO((void));
60 static int whitespace_cr                PROTO((int));
61 static int skip_white_space PROTO((int));
62 static void finish_defarg PROTO((void));
63 static int my_get_run_time PROTO((void));
64 static int interface_strcmp PROTO((const char *));
65 static int readescape PROTO((int *));
66 static char *extend_token_buffer PROTO((const char *));
67 static void consume_string PROTO((struct obstack *, int));
68 static void feed_defarg PROTO((tree, tree));
69 static void store_pending_inline PROTO((tree, struct pending_inline *));
70 static void reinit_parse_for_expr PROTO((struct obstack *));
71 static int *init_cpp_parse PROTO((void));
72 static void cp_pragma_interface PROTO((char *));
73 static void cp_pragma_implementation PROTO ((char *));
74 static int handle_cp_pragma PROTO((const char *));
75 #ifdef HANDLE_GENERIC_PRAGMAS
76 static int handle_generic_pragma PROTO((int));
77 #endif
78 #ifdef GATHER_STATISTICS
79 #ifdef REDUCE_LENGTH
80 static int reduce_cmp PROTO((int *, int *));
81 static int token_cmp PROTO((int *, int *));
82 #endif
83 #endif
84 static void begin_definition_of_inclass_inline PROTO((struct pending_inline*));
85 static void parse_float PROTO((PTR));
86 static int is_global PROTO((tree));
87 static void init_filename_times PROTO((void));
88
89 /* Given a file name X, return the nondirectory portion.
90    Keep in mind that X can be computed more than once.  */
91 char *
92 file_name_nondirectory (x)
93      const char *x;
94 {
95   char *tmp = (char *) rindex (x, '/');
96   if (DIR_SEPARATOR != '/' && ! tmp)
97     tmp = (char *) rindex (x, DIR_SEPARATOR);
98   if (tmp)
99     return (char *) (tmp + 1);
100   else
101     return (char *) x;
102 }
103
104 /* This obstack is needed to hold text.  It is not safe to use
105    TOKEN_BUFFER because `check_newline' calls `yylex'.  */
106 struct obstack inline_text_obstack;
107 char *inline_text_firstobj;
108
109 #if USE_CPPLIB
110 #include "cpplib.h"
111 extern cpp_reader  parse_in;
112 extern cpp_options parse_options;
113 extern unsigned char *yy_cur, *yy_lim;
114 extern enum cpp_token cpp_token;
115 #else
116 FILE *finput;
117 #endif
118 int end_of_file;
119
120 int linemode;
121
122 /* Pending language change.
123    Positive is push count, negative is pop count.  */
124 int pending_lang_change = 0;
125
126 /* Wrap the current header file in extern "C".  */
127 static int c_header_level = 0;
128
129 extern int first_token;
130 extern struct obstack token_obstack;
131
132 /* ??? Don't really know where this goes yet.  */
133 #include "input.c"
134
135 /* Holds translations from TREE_CODEs to operator name strings,
136    i.e., opname_tab[PLUS_EXPR] == "+".  */
137 char **opname_tab;
138 char **assignop_tab;
139 \f
140 extern int yychar;              /*  the lookahead symbol                */
141 extern YYSTYPE yylval;          /*  the semantic value of the           */
142                                 /*  lookahead symbol                    */
143
144 #if 0
145 YYLTYPE yylloc;                 /*  location data for the lookahead     */
146                                 /*  symbol                              */
147 #endif
148
149
150 /* the declaration found for the last IDENTIFIER token read in.
151    yylex must look this up to detect typedefs, which get token type TYPENAME,
152    so it is left around in case the identifier is not a typedef but is
153    used in a context which makes it a reference to a variable.  */
154 tree lastiddecl;
155
156 /* The elements of `ridpointers' are identifier nodes
157    for the reserved type names and storage classes.
158    It is indexed by a RID_... value.  */
159 tree ridpointers[(int) RID_MAX];
160
161 /* We may keep statistics about how long which files took to compile.  */
162 static int header_time, body_time;
163 static tree filename_times;
164 static tree this_filename_time;
165
166 /* Array for holding counts of the numbers of tokens seen.  */
167 extern int *token_count;
168 \f
169 /* Return something to represent absolute declarators containing a *.
170    TARGET is the absolute declarator that the * contains.
171    CV_QUALIFIERS is a list of modifiers such as const or volatile
172    to apply to the pointer type, represented as identifiers.
173
174    We return an INDIRECT_REF whose "contents" are TARGET
175    and whose type is the modifier list.  */
176
177 tree
178 make_pointer_declarator (cv_qualifiers, target)
179      tree cv_qualifiers, target;
180 {
181   if (target && TREE_CODE (target) == IDENTIFIER_NODE
182       && ANON_AGGRNAME_P (target))
183     error ("type name expected before `*'");
184   target = build_parse_node (INDIRECT_REF, target);
185   TREE_TYPE (target) = cv_qualifiers;
186   return target;
187 }
188
189 /* Return something to represent absolute declarators containing a &.
190    TARGET is the absolute declarator that the & contains.
191    CV_QUALIFIERS is a list of modifiers such as const or volatile
192    to apply to the reference type, represented as identifiers.
193
194    We return an ADDR_EXPR whose "contents" are TARGET
195    and whose type is the modifier list.  */
196    
197 tree
198 make_reference_declarator (cv_qualifiers, target)
199      tree cv_qualifiers, target;
200 {
201   if (target)
202     {
203       if (TREE_CODE (target) == ADDR_EXPR)
204         {
205           error ("cannot declare references to references");
206           return target;
207         }
208       if (TREE_CODE (target) == INDIRECT_REF)
209         {
210           error ("cannot declare pointers to references");
211           return target;
212         }
213       if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target))
214           error ("type name expected before `&'");
215     }
216   target = build_parse_node (ADDR_EXPR, target);
217   TREE_TYPE (target) = cv_qualifiers;
218   return target;
219 }
220
221 tree
222 make_call_declarator (target, parms, cv_qualifiers, exception_specification)
223      tree target, parms, cv_qualifiers, exception_specification;
224 {
225   target = build_parse_node (CALL_EXPR, target, parms, cv_qualifiers);
226   TREE_TYPE (target) = exception_specification;
227   return target;
228 }
229
230 void
231 set_quals_and_spec (call_declarator, cv_qualifiers, exception_specification)
232      tree call_declarator, cv_qualifiers, exception_specification;
233 {
234   TREE_OPERAND (call_declarator, 2) = cv_qualifiers;
235   TREE_TYPE (call_declarator) = exception_specification;
236 }
237 \f
238 /* Build names and nodes for overloaded operators.  */
239
240 tree ansi_opname[LAST_CPLUS_TREE_CODE];
241 tree ansi_assopname[LAST_CPLUS_TREE_CODE];
242
243 char *
244 operator_name_string (name)
245      tree name;
246 {
247   char *opname = IDENTIFIER_POINTER (name) + 2;
248   tree *opname_table;
249   int i, assign;
250
251   /* Works for builtin and user defined types.  */
252   if (IDENTIFIER_GLOBAL_VALUE (name)
253       && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == TYPE_DECL)
254     return IDENTIFIER_POINTER (name);
255
256   if (opname[0] == 'a' && opname[2] != '\0' && opname[2] != '_')
257     {
258       opname += 1;
259       assign = 1;
260       opname_table = ansi_assopname;
261     }
262   else
263     {
264       assign = 0;
265       opname_table = ansi_opname;
266     }
267
268   for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
269     {
270       if (opname[0] == IDENTIFIER_POINTER (opname_table[i])[2+assign]
271           && opname[1] == IDENTIFIER_POINTER (opname_table[i])[3+assign])
272         break;
273     }
274
275   if (i == LAST_CPLUS_TREE_CODE)
276     return "<invalid operator>";
277
278   if (assign)
279     return assignop_tab[i];
280   else
281     return opname_tab[i];
282 }
283 \f
284 int interface_only;             /* whether or not current file is only for
285                                    interface definitions.  */
286 int interface_unknown;          /* whether or not we know this class
287                                    to behave according to #pragma interface.  */
288
289 /* lexical analyzer */
290
291 #ifndef WCHAR_TYPE_SIZE
292 #ifdef INT_TYPE_SIZE
293 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
294 #else
295 #define WCHAR_TYPE_SIZE BITS_PER_WORD
296 #endif
297 #endif
298
299 /* Number of bytes in a wide character.  */
300 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
301
302 static int maxtoken;            /* Current nominal length of token buffer.  */
303 char *token_buffer;             /* Pointer to token buffer.
304                                    Actual allocated length is maxtoken + 2.  */
305
306 static int indent_level;        /* Number of { minus number of }. */
307
308 #include "hash.h"
309 \f
310
311 /* Nonzero tells yylex to ignore \ in string constants.  */
312 static int ignore_escape_flag;
313
314 static tree
315 get_time_identifier (name)
316      const char *name;
317 {
318   tree time_identifier;
319   int len = strlen (name);
320   char *buf = (char *) alloca (len + 6);
321   strcpy (buf, "file ");
322   bcopy (name, buf+5, len);
323   buf[len+5] = '\0';
324   time_identifier = get_identifier (buf);
325   if (TIME_IDENTIFIER_TIME (time_identifier) == NULL_TREE)
326     {
327       push_obstacks_nochange ();
328       end_temporary_allocation ();
329       TIME_IDENTIFIER_TIME (time_identifier) = build_int_2 (0, 0);
330       TIME_IDENTIFIER_FILEINFO (time_identifier) 
331         = build_int_2 (0, 1);
332       SET_IDENTIFIER_GLOBAL_VALUE (time_identifier, filename_times);
333       filename_times = time_identifier;
334       pop_obstacks ();
335     }
336   return time_identifier;
337 }
338
339 #ifdef __GNUC__
340 __inline
341 #endif
342 static int
343 my_get_run_time ()
344 {
345   int old_quiet_flag = quiet_flag;
346   int this_time;
347   quiet_flag = 0;
348   this_time = get_run_time ();
349   quiet_flag = old_quiet_flag;
350   return this_time;
351 }
352 \f
353 /* Table indexed by tree code giving a string containing a character
354    classifying the tree code.  Possibilities are
355    t, d, s, c, r, <, 1 and 2.  See cp/cp-tree.def for details.  */
356
357 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
358
359 char cplus_tree_code_type[] = {
360   'x',
361 #include "cp-tree.def"
362 };
363 #undef DEFTREECODE
364
365 /* Table indexed by tree code giving number of expression
366    operands beyond the fixed part of the node structure.
367    Not used for types or decls.  */
368
369 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
370
371 int cplus_tree_code_length[] = {
372   0,
373 #include "cp-tree.def"
374 };
375 #undef DEFTREECODE
376
377 /* Names of tree components.
378    Used for printing out the tree and error messages.  */
379 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
380
381 const char *cplus_tree_code_name[] = {
382   "@@dummy",
383 #include "cp-tree.def"
384 };
385 #undef DEFTREECODE
386 \f
387 /* toplev.c needs to call these.  */
388
389 void
390 lang_init_options ()
391 {
392 #if USE_CPPLIB
393   cpp_reader_init (&parse_in);
394   parse_in.opts = &parse_options;
395   cpp_options_init (&parse_options);
396   parse_options.cplusplus = 1;
397 #endif
398
399   /* Default exceptions on.  */
400   flag_exceptions = 1;
401 }
402
403 void
404 lang_init ()
405 {
406   /* the beginning of the file is a new line; check for # */
407   /* With luck, we discover the real source file's name from that
408      and put it in input_filename.  */
409   put_back (check_newline ());
410   if (flag_gnu_xref) GNU_xref_begin (input_filename);
411   init_repo (input_filename);
412 }
413
414 void
415 lang_finish ()
416 {
417   if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount);
418 }
419
420 char *
421 lang_identify ()
422 {
423   return "cplusplus";
424 }
425
426 static void
427 init_filename_times ()
428 {
429   this_filename_time = get_time_identifier ("<top level>");
430   if (flag_detailed_statistics)
431     {
432       header_time = 0;
433       body_time = my_get_run_time ();
434       TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time)) 
435         = body_time;
436     }
437 }
438
439 /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989.
440    Stuck this hack in to get the files open correctly; this is called
441    in place of init_parse if we are an unexec'd binary.    */
442
443 #if 0
444 void
445 reinit_lang_specific ()
446 {
447   init_filename_times ();
448   reinit_search_statistics ();
449 }
450 #endif
451
452 static int *
453 init_cpp_parse ()
454 {
455 #ifdef GATHER_STATISTICS
456 #ifdef REDUCE_LENGTH
457   reduce_count = (int *)malloc (sizeof (int) * (REDUCE_LENGTH + 1));
458   bzero (reduce_count, sizeof (int) * (REDUCE_LENGTH + 1));
459   reduce_count += 1;
460   token_count = (int *)malloc (sizeof (int) * (TOKEN_LENGTH + 1));
461   bzero (token_count, sizeof (int) * (TOKEN_LENGTH + 1));
462   token_count += 1;
463 #endif
464 #endif
465   return token_count;
466 }
467
468 char *
469 init_parse (filename)
470      char *filename;
471 {
472   extern int flag_no_gnu_keywords;
473   extern int flag_operator_names;
474
475   int i;
476
477 #ifdef MULTIBYTE_CHARS
478   /* Change to the native locale for multibyte conversions.  */
479   setlocale (LC_CTYPE, "");
480   literal_codeset = getenv ("LANG");
481 #endif
482
483 #if !USE_CPPLIB
484   /* Open input file.  */
485   if (filename == 0 || !strcmp (filename, "-"))
486     {
487       finput = stdin;
488       filename = "stdin";
489     }
490   else
491     finput = fopen (filename, "r");
492   if (finput == 0)
493     pfatal_with_name (filename);
494
495 #ifdef IO_BUFFER_SIZE
496   setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
497 #endif
498 #else /* !USE_CPPLIB */
499   parse_in.show_column = 1;
500   if (! cpp_start_read (&parse_in, filename))
501     abort ();
502
503   if (filename == 0 || !strcmp (filename, "-"))
504     filename = "stdin";
505
506   /* cpp_start_read always puts at least one line directive into the
507      token buffer.  We must arrange to read it out here. */
508   yy_cur = parse_in.token_buffer;
509   yy_lim = CPP_PWRITTEN (&parse_in);
510   cpp_token = CPP_DIRECTIVE;
511
512 #endif /* !USE_CPPLIB */
513
514   /* Initialize the lookahead machinery.  */
515   init_spew ();
516
517   /* Make identifier nodes long enough for the language-specific slots.  */
518   set_identifier_size (sizeof (struct lang_identifier));
519   decl_printable_name = lang_printable_name;
520
521   init_cplus_expand ();
522
523   bcopy (cplus_tree_code_type,
524          tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
525          (int)LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE);
526   bcopy ((char *)cplus_tree_code_length,
527          (char *)(tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE),
528          (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
529   bcopy ((char *)cplus_tree_code_name,
530          (char *)(tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE),
531          (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
532
533   opname_tab = (char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
534   bzero ((char *)opname_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
535   assignop_tab = (char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
536   bzero ((char *)assignop_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
537
538   ansi_opname[0] = get_identifier ("<invalid operator>");
539   for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
540     {
541       ansi_opname[i] = ansi_opname[0];
542       ansi_assopname[i] = ansi_opname[0];
543     }
544
545   ansi_opname[(int) MULT_EXPR] = get_identifier ("__ml");
546   IDENTIFIER_OPNAME_P (ansi_opname[(int) MULT_EXPR]) = 1;
547   ansi_opname[(int) INDIRECT_REF] = ansi_opname[(int) MULT_EXPR];
548   ansi_assopname[(int) MULT_EXPR] = get_identifier ("__aml");
549   IDENTIFIER_OPNAME_P (ansi_assopname[(int) MULT_EXPR]) = 1;
550   ansi_assopname[(int) INDIRECT_REF] = ansi_assopname[(int) MULT_EXPR];
551   ansi_opname[(int) TRUNC_MOD_EXPR] = get_identifier ("__md");
552   IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUNC_MOD_EXPR]) = 1;
553   ansi_assopname[(int) TRUNC_MOD_EXPR] = get_identifier ("__amd");
554   IDENTIFIER_OPNAME_P (ansi_assopname[(int) TRUNC_MOD_EXPR]) = 1;
555   ansi_opname[(int) CEIL_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
556   ansi_opname[(int) FLOOR_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
557   ansi_opname[(int) ROUND_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
558   ansi_opname[(int) MINUS_EXPR] = get_identifier ("__mi");
559   IDENTIFIER_OPNAME_P (ansi_opname[(int) MINUS_EXPR]) = 1;
560   ansi_opname[(int) NEGATE_EXPR] = ansi_opname[(int) MINUS_EXPR];
561   ansi_assopname[(int) MINUS_EXPR] = get_identifier ("__ami");
562   IDENTIFIER_OPNAME_P (ansi_assopname[(int) MINUS_EXPR]) = 1;
563   ansi_assopname[(int) NEGATE_EXPR] = ansi_assopname[(int) MINUS_EXPR];
564   ansi_opname[(int) RSHIFT_EXPR] = get_identifier ("__rs");
565   IDENTIFIER_OPNAME_P (ansi_opname[(int) RSHIFT_EXPR]) = 1;
566   ansi_assopname[(int) RSHIFT_EXPR] = get_identifier ("__ars");
567   IDENTIFIER_OPNAME_P (ansi_assopname[(int) RSHIFT_EXPR]) = 1;
568   ansi_opname[(int) NE_EXPR] = get_identifier ("__ne");
569   IDENTIFIER_OPNAME_P (ansi_opname[(int) NE_EXPR]) = 1;
570   ansi_opname[(int) GT_EXPR] = get_identifier ("__gt");
571   IDENTIFIER_OPNAME_P (ansi_opname[(int) GT_EXPR]) = 1;
572   ansi_opname[(int) GE_EXPR] = get_identifier ("__ge");
573   IDENTIFIER_OPNAME_P (ansi_opname[(int) GE_EXPR]) = 1;
574   ansi_opname[(int) BIT_IOR_EXPR] = get_identifier ("__or");
575   IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_IOR_EXPR]) = 1;
576   ansi_assopname[(int) BIT_IOR_EXPR] = get_identifier ("__aor");
577   IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_IOR_EXPR]) = 1;
578   ansi_opname[(int) TRUTH_ANDIF_EXPR] = get_identifier ("__aa");
579   IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ANDIF_EXPR]) = 1;
580   ansi_opname[(int) TRUTH_NOT_EXPR] = get_identifier ("__nt");
581   IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_NOT_EXPR]) = 1;
582   ansi_opname[(int) PREINCREMENT_EXPR] = get_identifier ("__pp");
583   IDENTIFIER_OPNAME_P (ansi_opname[(int) PREINCREMENT_EXPR]) = 1;
584   ansi_opname[(int) POSTINCREMENT_EXPR] = ansi_opname[(int) PREINCREMENT_EXPR];
585   ansi_opname[(int) MODIFY_EXPR] = get_identifier ("__as");
586   IDENTIFIER_OPNAME_P (ansi_opname[(int) MODIFY_EXPR]) = 1;
587   ansi_assopname[(int) NOP_EXPR] = ansi_opname[(int) MODIFY_EXPR];
588   ansi_opname[(int) COMPOUND_EXPR] = get_identifier ("__cm");
589   IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPOUND_EXPR]) = 1;
590   ansi_opname[(int) EXACT_DIV_EXPR] = get_identifier ("__dv");
591   IDENTIFIER_OPNAME_P (ansi_opname[(int) EXACT_DIV_EXPR]) = 1;
592   ansi_assopname[(int) EXACT_DIV_EXPR] = get_identifier ("__adv");
593   IDENTIFIER_OPNAME_P (ansi_assopname[(int) EXACT_DIV_EXPR]) = 1;
594   ansi_opname[(int) TRUNC_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
595   ansi_opname[(int) CEIL_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
596   ansi_opname[(int) FLOOR_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
597   ansi_opname[(int) ROUND_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
598   ansi_opname[(int) PLUS_EXPR] = get_identifier ("__pl");
599   ansi_assopname[(int) TRUNC_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
600   ansi_assopname[(int) CEIL_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
601   ansi_assopname[(int) FLOOR_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
602   ansi_assopname[(int) ROUND_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
603   IDENTIFIER_OPNAME_P (ansi_opname[(int) PLUS_EXPR]) = 1;
604   ansi_assopname[(int) PLUS_EXPR] = get_identifier ("__apl");
605   IDENTIFIER_OPNAME_P (ansi_assopname[(int) PLUS_EXPR]) = 1;
606   ansi_opname[(int) CONVERT_EXPR] = ansi_opname[(int) PLUS_EXPR];
607   ansi_assopname[(int) CONVERT_EXPR] = ansi_assopname[(int) PLUS_EXPR];
608   ansi_opname[(int) LSHIFT_EXPR] = get_identifier ("__ls");
609   IDENTIFIER_OPNAME_P (ansi_opname[(int) LSHIFT_EXPR]) = 1;
610   ansi_assopname[(int) LSHIFT_EXPR] = get_identifier ("__als");
611   IDENTIFIER_OPNAME_P (ansi_assopname[(int) LSHIFT_EXPR]) = 1;
612   ansi_opname[(int) EQ_EXPR] = get_identifier ("__eq");
613   IDENTIFIER_OPNAME_P (ansi_opname[(int) EQ_EXPR]) = 1;
614   ansi_opname[(int) LT_EXPR] = get_identifier ("__lt");
615   IDENTIFIER_OPNAME_P (ansi_opname[(int) LT_EXPR]) = 1;
616   ansi_opname[(int) LE_EXPR] = get_identifier ("__le");
617   IDENTIFIER_OPNAME_P (ansi_opname[(int) LE_EXPR]) = 1;
618   ansi_opname[(int) BIT_AND_EXPR] = get_identifier ("__ad");
619   IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_AND_EXPR]) = 1;
620   ansi_assopname[(int) BIT_AND_EXPR] = get_identifier ("__aad");
621   IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_AND_EXPR]) = 1;
622   ansi_opname[(int) ADDR_EXPR] = ansi_opname[(int) BIT_AND_EXPR];
623   ansi_assopname[(int) ADDR_EXPR] = ansi_assopname[(int) BIT_AND_EXPR];
624   ansi_opname[(int) BIT_XOR_EXPR] = get_identifier ("__er");
625   IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_XOR_EXPR]) = 1;
626   ansi_assopname[(int) BIT_XOR_EXPR] = get_identifier ("__aer");
627   IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_XOR_EXPR]) = 1;
628   ansi_opname[(int) TRUTH_ORIF_EXPR] = get_identifier ("__oo");
629   IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ORIF_EXPR]) = 1;
630   ansi_opname[(int) BIT_NOT_EXPR] = get_identifier ("__co");
631   IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_NOT_EXPR]) = 1;
632   ansi_opname[(int) PREDECREMENT_EXPR] = get_identifier ("__mm");
633   IDENTIFIER_OPNAME_P (ansi_opname[(int) PREDECREMENT_EXPR]) = 1;
634   ansi_opname[(int) POSTDECREMENT_EXPR] = ansi_opname[(int) PREDECREMENT_EXPR];
635   ansi_opname[(int) COMPONENT_REF] = get_identifier ("__rf");
636   IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPONENT_REF]) = 1;
637   ansi_opname[(int) MEMBER_REF] = get_identifier ("__rm");
638   IDENTIFIER_OPNAME_P (ansi_opname[(int) MEMBER_REF]) = 1;
639   ansi_opname[(int) CALL_EXPR] = get_identifier ("__cl");
640   IDENTIFIER_OPNAME_P (ansi_opname[(int) CALL_EXPR]) = 1;
641   ansi_opname[(int) ARRAY_REF] = get_identifier ("__vc");
642   IDENTIFIER_OPNAME_P (ansi_opname[(int) ARRAY_REF]) = 1;
643   ansi_opname[(int) NEW_EXPR] = get_identifier ("__nw");
644   IDENTIFIER_OPNAME_P (ansi_opname[(int) NEW_EXPR]) = 1;
645   ansi_opname[(int) DELETE_EXPR] = get_identifier ("__dl");
646   IDENTIFIER_OPNAME_P (ansi_opname[(int) DELETE_EXPR]) = 1;
647   ansi_opname[(int) VEC_NEW_EXPR] = get_identifier ("__vn");
648   IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_NEW_EXPR]) = 1;
649   ansi_opname[(int) VEC_DELETE_EXPR] = get_identifier ("__vd");
650   IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_DELETE_EXPR]) = 1;
651   ansi_opname[(int) TYPE_EXPR] = get_identifier (OPERATOR_TYPENAME_FORMAT);
652   IDENTIFIER_OPNAME_P (ansi_opname[(int) TYPE_EXPR]) = 1;
653
654   /* This is not true: these operators are not defined in ANSI,
655      but we need them anyway.  */
656   ansi_opname[(int) MIN_EXPR] = get_identifier ("__mn");
657   IDENTIFIER_OPNAME_P (ansi_opname[(int) MIN_EXPR]) = 1;
658   ansi_opname[(int) MAX_EXPR] = get_identifier ("__mx");
659   IDENTIFIER_OPNAME_P (ansi_opname[(int) MAX_EXPR]) = 1;
660   ansi_opname[(int) COND_EXPR] = get_identifier ("__cn");
661   IDENTIFIER_OPNAME_P (ansi_opname[(int) COND_EXPR]) = 1;
662   ansi_opname[(int) SIZEOF_EXPR] = get_identifier ("__sz");
663   IDENTIFIER_OPNAME_P (ansi_opname[(int) SIZEOF_EXPR]) = 1;
664
665   init_method ();
666   init_error ();
667   gcc_obstack_init (&inline_text_obstack);
668   inline_text_firstobj = (char *) obstack_alloc (&inline_text_obstack, 0);
669
670   /* Start it at 0, because check_newline is called at the very beginning
671      and will increment it to 1.  */
672   lineno = 0;
673   input_filename = "<internal>";
674   current_function_decl = NULL;
675
676   maxtoken = 40;
677   token_buffer = (char *) xmalloc (maxtoken + 2);
678
679   ridpointers[(int) RID_INT] = get_identifier ("int");
680   ridpointers[(int) RID_BOOL] = get_identifier ("bool");
681   ridpointers[(int) RID_CHAR] = get_identifier ("char");
682   ridpointers[(int) RID_VOID] = get_identifier ("void");
683   ridpointers[(int) RID_FLOAT] = get_identifier ("float");
684   ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
685   ridpointers[(int) RID_SHORT] = get_identifier ("short");
686   ridpointers[(int) RID_LONG] = get_identifier ("long");
687   ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
688   ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
689   ridpointers[(int) RID_INLINE] = get_identifier ("inline");
690   ridpointers[(int) RID_CONST] = get_identifier ("const");
691   ridpointers[(int) RID_RESTRICT] = get_identifier ("__restrict");
692   ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
693   ridpointers[(int) RID_AUTO] = get_identifier ("auto");
694   ridpointers[(int) RID_STATIC] = get_identifier ("static");
695   ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
696   ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
697   ridpointers[(int) RID_REGISTER] = get_identifier ("register");
698   ridpointers[(int) RID_COMPLEX] = get_identifier ("__complex");
699
700   /* C++ extensions. These are probably not correctly named.  */
701   ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t");
702   class_type_node = build_int_2 (class_type, 0);
703   TREE_TYPE (class_type_node) = class_type_node;
704   ridpointers[(int) RID_CLASS] = class_type_node;
705
706   record_type_node = build_int_2 (record_type, 0);
707   TREE_TYPE (record_type_node) = record_type_node;
708   ridpointers[(int) RID_RECORD] = record_type_node;
709
710   union_type_node = build_int_2 (union_type, 0);
711   TREE_TYPE (union_type_node) = union_type_node;
712   ridpointers[(int) RID_UNION] = union_type_node;
713
714   enum_type_node = build_int_2 (enum_type, 0);
715   TREE_TYPE (enum_type_node) = enum_type_node;
716   ridpointers[(int) RID_ENUM] = enum_type_node;
717
718   ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual");
719   ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit");
720   ridpointers[(int) RID_EXPORT] = get_identifier ("export");
721   ridpointers[(int) RID_FRIEND] = get_identifier ("friend");
722
723   ridpointers[(int) RID_PUBLIC] = get_identifier ("public");
724   ridpointers[(int) RID_PRIVATE] = get_identifier ("private");
725   ridpointers[(int) RID_PROTECTED] = get_identifier ("protected");
726   ridpointers[(int) RID_TEMPLATE] = get_identifier ("template");
727   /* This is for ANSI C++.  */
728   ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable");
729
730   /* Signature handling extensions.  */
731   signature_type_node = build_int_2 (signature_type, 0);
732   TREE_TYPE (signature_type_node) = signature_type_node;
733   ridpointers[(int) RID_SIGNATURE] = signature_type_node;
734
735   /* Create the built-in __null node.  Note that we can't yet call for
736      type_for_size here because integer_type_node and so forth are not
737      set up.  Therefore, we don't set the type of these nodes until
738      init_decl_processing.  */
739   null_node = build_int_2 (0, 0);
740   ridpointers[RID_NULL] = null_node;
741
742   opname_tab[(int) COMPONENT_REF] = "->";
743   opname_tab[(int) MEMBER_REF] = "->*";
744   opname_tab[(int) INDIRECT_REF] = "*";
745   opname_tab[(int) ARRAY_REF] = "[]";
746   opname_tab[(int) MODIFY_EXPR] = "=";
747   opname_tab[(int) NEW_EXPR] = "new";
748   opname_tab[(int) DELETE_EXPR] = "delete";
749   opname_tab[(int) VEC_NEW_EXPR] = "new []";
750   opname_tab[(int) VEC_DELETE_EXPR] = "delete []";
751   opname_tab[(int) COND_EXPR] = "?:";
752   opname_tab[(int) CALL_EXPR] = "()";
753   opname_tab[(int) PLUS_EXPR] = "+";
754   opname_tab[(int) MINUS_EXPR] = "-";
755   opname_tab[(int) MULT_EXPR] = "*";
756   opname_tab[(int) TRUNC_DIV_EXPR] = "/";
757   opname_tab[(int) CEIL_DIV_EXPR] = "(ceiling /)";
758   opname_tab[(int) FLOOR_DIV_EXPR] = "(floor /)";
759   opname_tab[(int) ROUND_DIV_EXPR] = "(round /)";
760   opname_tab[(int) TRUNC_MOD_EXPR] = "%";
761   opname_tab[(int) CEIL_MOD_EXPR] = "(ceiling %)";
762   opname_tab[(int) FLOOR_MOD_EXPR] = "(floor %)";
763   opname_tab[(int) ROUND_MOD_EXPR] = "(round %)";
764   opname_tab[(int) EXACT_DIV_EXPR] = "/";
765   opname_tab[(int) NEGATE_EXPR] = "-";
766   opname_tab[(int) MIN_EXPR] = "<?";
767   opname_tab[(int) MAX_EXPR] = ">?";
768   opname_tab[(int) ABS_EXPR] = "abs";
769   opname_tab[(int) FFS_EXPR] = "ffs";
770   opname_tab[(int) LSHIFT_EXPR] = "<<";
771   opname_tab[(int) RSHIFT_EXPR] = ">>";
772   opname_tab[(int) BIT_IOR_EXPR] = "|";
773   opname_tab[(int) BIT_XOR_EXPR] = "^";
774   opname_tab[(int) BIT_AND_EXPR] = "&";
775   opname_tab[(int) BIT_ANDTC_EXPR] = "&~";
776   opname_tab[(int) BIT_NOT_EXPR] = "~";
777   opname_tab[(int) TRUTH_ANDIF_EXPR] = "&&";
778   opname_tab[(int) TRUTH_ORIF_EXPR] = "||";
779   opname_tab[(int) TRUTH_AND_EXPR] = "strict &&";
780   opname_tab[(int) TRUTH_OR_EXPR] = "strict ||";
781   opname_tab[(int) TRUTH_NOT_EXPR] = "!";
782   opname_tab[(int) LT_EXPR] = "<";
783   opname_tab[(int) LE_EXPR] = "<=";
784   opname_tab[(int) GT_EXPR] = ">";
785   opname_tab[(int) GE_EXPR] = ">=";
786   opname_tab[(int) EQ_EXPR] = "==";
787   opname_tab[(int) NE_EXPR] = "!=";
788   opname_tab[(int) IN_EXPR] = "in";
789   opname_tab[(int) RANGE_EXPR] = "...";
790   opname_tab[(int) CONVERT_EXPR] = "+";
791   opname_tab[(int) ADDR_EXPR] = "&";
792   opname_tab[(int) PREDECREMENT_EXPR] = "--";
793   opname_tab[(int) PREINCREMENT_EXPR] = "++";
794   opname_tab[(int) POSTDECREMENT_EXPR] = "--";
795   opname_tab[(int) POSTINCREMENT_EXPR] = "++";
796   opname_tab[(int) COMPOUND_EXPR] = ",";
797
798   assignop_tab[(int) NOP_EXPR] = "=";
799   assignop_tab[(int) PLUS_EXPR] =  "+=";
800   assignop_tab[(int) CONVERT_EXPR] =  "+=";
801   assignop_tab[(int) MINUS_EXPR] = "-=";
802   assignop_tab[(int) NEGATE_EXPR] = "-=";
803   assignop_tab[(int) MULT_EXPR] = "*=";
804   assignop_tab[(int) INDIRECT_REF] = "*=";
805   assignop_tab[(int) TRUNC_DIV_EXPR] = "/=";
806   assignop_tab[(int) EXACT_DIV_EXPR] = "(exact /=)";
807   assignop_tab[(int) CEIL_DIV_EXPR] = "(ceiling /=)";
808   assignop_tab[(int) FLOOR_DIV_EXPR] = "(floor /=)";
809   assignop_tab[(int) ROUND_DIV_EXPR] = "(round /=)";
810   assignop_tab[(int) TRUNC_MOD_EXPR] = "%=";
811   assignop_tab[(int) CEIL_MOD_EXPR] = "(ceiling %=)";
812   assignop_tab[(int) FLOOR_MOD_EXPR] = "(floor %=)";
813   assignop_tab[(int) ROUND_MOD_EXPR] = "(round %=)";
814   assignop_tab[(int) MIN_EXPR] = "<?=";
815   assignop_tab[(int) MAX_EXPR] = ">?=";
816   assignop_tab[(int) LSHIFT_EXPR] = "<<=";
817   assignop_tab[(int) RSHIFT_EXPR] = ">>=";
818   assignop_tab[(int) BIT_IOR_EXPR] = "|=";
819   assignop_tab[(int) BIT_XOR_EXPR] = "^=";
820   assignop_tab[(int) BIT_AND_EXPR] = "&=";
821   assignop_tab[(int) ADDR_EXPR] = "&=";
822
823   init_filename_times ();
824
825   /* Some options inhibit certain reserved words.
826      Clear those words out of the hash table so they won't be recognized.  */
827 #define UNSET_RESERVED_WORD(STRING) \
828   do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
829        if (s) s->name = ""; } while (0)
830
831 #if 0
832   /* let's parse things, and if they use it, then give them an error.  */
833   if (!flag_exceptions)
834     {
835       UNSET_RESERVED_WORD ("throw");
836       UNSET_RESERVED_WORD ("try");
837       UNSET_RESERVED_WORD ("catch");
838     }
839 #endif
840
841   if (!flag_rtti || flag_no_gnu_keywords)
842     {
843       UNSET_RESERVED_WORD ("classof");
844       UNSET_RESERVED_WORD ("headof");
845     }
846
847   if (! flag_handle_signatures || flag_no_gnu_keywords)
848     {
849       /* Easiest way to not recognize signature
850          handling extensions...  */
851       UNSET_RESERVED_WORD ("signature");
852       UNSET_RESERVED_WORD ("sigof");
853     }
854   if (flag_no_asm || flag_no_gnu_keywords)
855     UNSET_RESERVED_WORD ("typeof");
856   if (! flag_operator_names)
857     {
858       /* These are new ANSI keywords that may break code.  */
859       UNSET_RESERVED_WORD ("and");
860       UNSET_RESERVED_WORD ("and_eq");
861       UNSET_RESERVED_WORD ("bitand");
862       UNSET_RESERVED_WORD ("bitor");
863       UNSET_RESERVED_WORD ("compl");
864       UNSET_RESERVED_WORD ("not");
865       UNSET_RESERVED_WORD ("not_eq");
866       UNSET_RESERVED_WORD ("or");
867       UNSET_RESERVED_WORD ("or_eq");
868       UNSET_RESERVED_WORD ("xor");
869       UNSET_RESERVED_WORD ("xor_eq");
870     }
871
872   token_count = init_cpp_parse ();
873   interface_unknown = 1;
874
875   return filename;
876 }
877
878 void
879 finish_parse ()
880 {
881 #if USE_CPPLIB
882   cpp_finish (&parse_in);
883   errorcount += parse_in.errors;
884 #else
885   fclose (finput);
886 #endif
887 }
888
889 void
890 reinit_parse_for_function ()
891 {
892   current_base_init_list = NULL_TREE;
893   current_member_init_list = NULL_TREE;
894 }
895 \f
896 #ifdef __GNUC__
897 __inline
898 #endif
899 void
900 yyprint (file, yychar, yylval)
901      FILE *file;
902      int yychar;
903      YYSTYPE yylval;
904 {
905   tree t;
906   switch (yychar)
907     {
908     case IDENTIFIER:
909     case TYPENAME:
910     case TYPESPEC:
911     case PTYPENAME:
912     case PFUNCNAME:
913     case IDENTIFIER_DEFN:
914     case TYPENAME_DEFN:
915     case PTYPENAME_DEFN:
916     case SCSPEC:
917     case PRE_PARSED_CLASS_DECL:
918       t = yylval.ttype;
919       if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (t) == TEMPLATE_DECL)
920         {
921           fprintf (file, " `%s'", IDENTIFIER_POINTER (DECL_NAME (t)));
922           break;
923         }
924       my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224);
925       if (IDENTIFIER_POINTER (t))
926           fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
927       break;
928
929     case AGGR:
930       if (yylval.ttype == class_type_node)
931         fprintf (file, " `class'");
932       else if (yylval.ttype == record_type_node)
933         fprintf (file, " `struct'");
934       else if (yylval.ttype == union_type_node)
935         fprintf (file, " `union'");
936       else if (yylval.ttype == enum_type_node)
937         fprintf (file, " `enum'");
938       else if (yylval.ttype == signature_type_node)
939         fprintf (file, " `signature'");
940       else
941         my_friendly_abort (80);
942       break;
943
944     case CONSTANT:
945       t = yylval.ttype;
946       if (TREE_CODE (t) == INTEGER_CST)
947         fprintf (file,
948 #if HOST_BITS_PER_WIDE_INT == 64
949 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
950                  " 0x%x%016x",
951 #else
952 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
953                  " 0x%lx%016lx",
954 #else
955                  " 0x%llx%016llx",
956 #endif
957 #endif
958 #else
959 #if HOST_BITS_PER_WIDE_INT != HOST_BITS_PER_INT
960                  " 0x%lx%08lx",
961 #else
962                  " 0x%x%08x",
963 #endif
964 #endif
965                  TREE_INT_CST_HIGH (t), TREE_INT_CST_LOW (t));
966       break;
967     }
968 }
969
970 #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH)
971 static int *reduce_count;
972 #endif
973
974 int *token_count;
975
976 #if 0
977 #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
978 #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
979 #endif
980
981 #ifdef GATHER_STATISTICS
982 #ifdef REDUCE_LENGTH
983 void
984 yyhook (yyn)
985      int yyn;
986 {
987   reduce_count[yyn] += 1;
988 }
989
990 static int
991 reduce_cmp (p, q)
992      int *p, *q;
993 {
994   return reduce_count[*q] - reduce_count[*p];
995 }
996
997 static int
998 token_cmp (p, q)
999      int *p, *q;
1000 {
1001   return token_count[*q] - token_count[*p];
1002 }
1003 #endif
1004 #endif
1005
1006 void
1007 print_parse_statistics ()
1008 {
1009 #ifdef GATHER_STATISTICS
1010 #ifdef REDUCE_LENGTH
1011 #if YYDEBUG != 0
1012   int i;
1013   int maxlen = REDUCE_LENGTH;
1014   unsigned *sorted;
1015   
1016   if (reduce_count[-1] == 0)
1017     return;
1018
1019   if (TOKEN_LENGTH > REDUCE_LENGTH)
1020     maxlen = TOKEN_LENGTH;
1021   sorted = (unsigned *) alloca (sizeof (int) * maxlen);
1022
1023   for (i = 0; i < TOKEN_LENGTH; i++)
1024     sorted[i] = i;
1025   qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
1026   for (i = 0; i < TOKEN_LENGTH; i++)
1027     {
1028       int idx = sorted[i];
1029       if (token_count[idx] == 0)
1030         break;
1031       if (token_count[idx] < token_count[-1])
1032         break;
1033       fprintf (stderr, "token %d, `%s', count = %d\n",
1034                idx, yytname[YYTRANSLATE (idx)], token_count[idx]);
1035     }
1036   fprintf (stderr, "\n");
1037   for (i = 0; i < REDUCE_LENGTH; i++)
1038     sorted[i] = i;
1039   qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
1040   for (i = 0; i < REDUCE_LENGTH; i++)
1041     {
1042       int idx = sorted[i];
1043       if (reduce_count[idx] == 0)
1044         break;
1045       if (reduce_count[idx] < reduce_count[-1])
1046         break;
1047       fprintf (stderr, "rule %d, line %d, count = %d\n",
1048                idx, yyrline[idx], reduce_count[idx]);
1049     }
1050   fprintf (stderr, "\n");
1051 #endif
1052 #endif
1053 #endif
1054 }
1055
1056 /* Sets the value of the 'yydebug' variable to VALUE.
1057    This is a function so we don't have to have YYDEBUG defined
1058    in order to build the compiler.  */
1059
1060 void
1061 set_yydebug (value)
1062      int value;
1063 {
1064 #if YYDEBUG != 0
1065   extern int yydebug;
1066   yydebug = value;
1067 #else
1068   warning ("YYDEBUG not defined.");
1069 #endif
1070 }
1071
1072 \f
1073 /* Functions and data structures for #pragma interface.
1074
1075    `#pragma implementation' means that the main file being compiled
1076    is considered to implement (provide) the classes that appear in
1077    its main body.  I.e., if this is file "foo.cc", and class `bar'
1078    is defined in "foo.cc", then we say that "foo.cc implements bar".
1079
1080    All main input files "implement" themselves automagically.
1081
1082    `#pragma interface' means that unless this file (of the form "foo.h"
1083    is not presently being included by file "foo.cc", the
1084    CLASSTYPE_INTERFACE_ONLY bit gets set.  The effect is that none
1085    of the vtables nor any of the inline functions defined in foo.h
1086    will ever be output.
1087
1088    There are cases when we want to link files such as "defs.h" and
1089    "main.cc".  In this case, we give "defs.h" a `#pragma interface',
1090    and "main.cc" has `#pragma implementation "defs.h"'.  */
1091
1092 struct impl_files
1093 {
1094   char *filename;
1095   struct impl_files *next;
1096 };
1097
1098 static struct impl_files *impl_file_chain;
1099
1100 /* Helper function to load global variables with interface
1101    information.  */
1102
1103 void
1104 extract_interface_info ()
1105 {
1106   tree fileinfo = 0;
1107
1108   if (flag_alt_external_templates)
1109     {
1110       struct tinst_level *til = tinst_for_decl ();
1111   
1112       if (til)
1113         fileinfo = get_time_identifier (til->file);
1114     }
1115   if (!fileinfo)
1116     fileinfo = get_time_identifier (input_filename);
1117   fileinfo = TIME_IDENTIFIER_FILEINFO (fileinfo);
1118   interface_only = TREE_INT_CST_LOW (fileinfo);
1119   interface_unknown = TREE_INT_CST_HIGH (fileinfo);
1120 }
1121
1122 /* Return nonzero if S is not considered part of an
1123    INTERFACE/IMPLEMENTATION pair.  Otherwise, return 0.  */
1124
1125 static int
1126 interface_strcmp (s)
1127      const char *s;
1128 {
1129   /* Set the interface/implementation bits for this scope.  */
1130   struct impl_files *ifiles;
1131   const char *s1;
1132
1133   for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
1134     {
1135       const char *t1 = ifiles->filename;
1136       s1 = s;
1137
1138       if (*s1 != *t1 || *s1 == 0)
1139         continue;
1140
1141       while (*s1 == *t1 && *s1 != 0)
1142         s1++, t1++;
1143
1144       /* A match.  */
1145       if (*s1 == *t1)
1146         return 0;
1147
1148       /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc.  */
1149       if (index (s1, '.') || index (t1, '.'))
1150         continue;
1151
1152       if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
1153         continue;
1154
1155       /* A match.  */
1156       return 0;
1157     }
1158
1159   /* No matches.  */
1160   return 1;
1161 }
1162
1163 static void
1164 cp_pragma_interface (main_filename)
1165      char *main_filename;
1166 {
1167   tree fileinfo 
1168     = TIME_IDENTIFIER_FILEINFO (get_time_identifier (input_filename));
1169
1170   if (impl_file_chain == 0)
1171     {
1172       /* If this is zero at this point, then we are
1173          auto-implementing.  */
1174       if (main_input_filename == 0)
1175         main_input_filename = input_filename;
1176
1177 #ifdef AUTO_IMPLEMENT
1178       filename = file_name_nondirectory (main_input_filename);
1179       fi = get_time_identifier (filename);
1180       fi = TIME_IDENTIFIER_FILEINFO (fi);
1181       TREE_INT_CST_LOW (fi) = 0;
1182       TREE_INT_CST_HIGH (fi) = 1;
1183       /* Get default.  */
1184       impl_file_chain = (struct impl_files *)permalloc (sizeof (struct impl_files));
1185       impl_file_chain->filename = filename;
1186       impl_file_chain->next = 0;
1187 #endif
1188     }
1189
1190   interface_only = interface_strcmp (main_filename);
1191 #ifdef MULTIPLE_SYMBOL_SPACES
1192   if (! interface_only)
1193     interface_unknown = 0;
1194 #else /* MULTIPLE_SYMBOL_SPACES */
1195   interface_unknown = 0;
1196 #endif /* MULTIPLE_SYMBOL_SPACES */
1197   TREE_INT_CST_LOW (fileinfo) = interface_only;
1198   TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
1199 }
1200
1201 static void
1202 cp_pragma_implementation (main_filename)
1203      char *main_filename;
1204 {
1205   tree fileinfo 
1206     = TIME_IDENTIFIER_FILEINFO (get_time_identifier (input_filename));
1207
1208   if (impl_file_chain)
1209     {
1210       struct impl_files *ifiles = impl_file_chain;
1211       while (ifiles)
1212         {
1213           if (! strcmp (ifiles->filename, main_filename))
1214             break;
1215           ifiles = ifiles->next;
1216         }
1217       if (ifiles == 0)
1218         {
1219           ifiles = (struct impl_files*) permalloc (sizeof (struct impl_files));
1220           ifiles->filename = main_filename;
1221           ifiles->next = impl_file_chain;
1222           impl_file_chain = ifiles;
1223         }
1224     }
1225   else if ((main_input_filename != 0
1226             && ! strcmp (main_input_filename, input_filename))
1227            || ! strcmp (main_filename, input_filename))
1228     {
1229       impl_file_chain = (struct impl_files*) permalloc (sizeof (struct impl_files));
1230       impl_file_chain->filename = main_filename;
1231       impl_file_chain->next = 0;
1232     }
1233   else
1234     error ("`#pragma implementation' can only appear at top-level");
1235   interface_only = 0;
1236 #if 1
1237   /* We make this non-zero so that we infer decl linkage
1238      in the impl file only for variables first declared
1239      in the interface file.  */
1240   interface_unknown = 1;
1241 #else
1242   /* We make this zero so that templates in the impl
1243      file will be emitted properly.  */
1244   interface_unknown = 0;
1245 #endif
1246   TREE_INT_CST_LOW (fileinfo) = interface_only;
1247   TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
1248 }
1249 \f
1250 /* Set up the state required to correctly handle the definition of the
1251    inline function whose preparsed state has been saved in PI.  */
1252
1253 static void
1254 begin_definition_of_inclass_inline (pi)
1255      struct pending_inline* pi;
1256 {
1257   tree context;
1258
1259   if (!pi->fndecl)
1260     return;
1261
1262   /* If this is an inline function in a local class, we must make sure
1263      that we save all pertinent information about the function
1264      surrounding the local class.  */
1265   context = hack_decl_function_context (pi->fndecl);
1266   if (context)
1267     push_cp_function_context (context);
1268
1269   feed_input (pi->buf, pi->len, pi->filename, pi->lineno);
1270   yychar = PRE_PARSED_FUNCTION_DECL;
1271   yylval.ttype = build_tree_list ((tree) pi, pi->fndecl);
1272   /* Pass back a handle to the rest of the inline functions, so that they
1273      can be processed later.  */
1274   DECL_PENDING_INLINE_INFO (pi->fndecl) = 0;
1275   interface_unknown = pi->interface == 1;
1276   interface_only  = pi->interface == 0;
1277 }
1278
1279 /* Called from the top level: if there are any pending inlines to
1280    do, set up to process them now.  This function sets up the first function
1281    to be parsed; after it has been, the rule for fndef in parse.y will
1282    call process_next_inline to start working on the next one.  */
1283
1284 void
1285 do_pending_inlines ()
1286 {
1287   struct pending_inline *t;
1288
1289   /* Oops, we're still dealing with the last batch.  */
1290   if (yychar == PRE_PARSED_FUNCTION_DECL)
1291     return;
1292
1293   /* Reverse the pending inline functions, since
1294      they were cons'd instead of appended.  */
1295   {
1296     struct pending_inline *prev = 0, *tail;
1297     t = pending_inlines;
1298     pending_inlines = 0;
1299
1300     for (; t; t = tail)
1301       {
1302         tail = t->next;
1303         t->next = prev;
1304         t->deja_vu = 1;
1305         prev = t;
1306       }
1307     t = prev;
1308   }
1309
1310   if (t == 0)
1311     return;
1312             
1313   /* Now start processing the first inline function.  */
1314   begin_definition_of_inclass_inline (t);
1315 }
1316
1317 /* Called from the fndecl rule in the parser when the function just parsed
1318    was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from
1319    do_pending_inlines).  */
1320
1321 void
1322 process_next_inline (t)
1323      tree t;
1324 {
1325   tree context;
1326   struct pending_inline *i = (struct pending_inline *) TREE_PURPOSE (t);
1327   context = hack_decl_function_context (i->fndecl);  
1328   if (context)
1329     pop_cp_function_context (context);
1330   i = i->next;
1331   if (yychar == YYEMPTY)
1332     yychar = yylex ();
1333   if (yychar != END_OF_SAVED_INPUT)
1334     {
1335       error ("parse error at end of saved function text");
1336
1337       /* restore_pending_input will abort unless yychar is either
1338          END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1339          hosed, feed back YYEMPTY.  */
1340     }
1341   yychar = YYEMPTY;
1342   end_input ();
1343   if (i)
1344     begin_definition_of_inclass_inline (i);
1345   else
1346     extract_interface_info ();
1347 }
1348
1349 /* Since inline methods can refer to text which has not yet been seen,
1350    we store the text of the method in a structure which is placed in the
1351    DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL.
1352    After parsing the body of the class definition, the FUNCTION_DECL's are
1353    scanned to see which ones have this field set.  Those are then digested
1354    one at a time.
1355
1356    This function's FUNCTION_DECL will have a bit set in its common so
1357    that we know to watch out for it.  */
1358
1359 static void
1360 consume_string (this_obstack, matching_char)
1361      register struct obstack *this_obstack;
1362      int matching_char;
1363 {
1364   register int c;
1365   int starting_lineno;
1366
1367 #if USE_CPPLIB
1368   if (cpp_token == CPP_STRING)
1369     {
1370       /* The C preprocessor will warn about newlines in strings.  */
1371       obstack_grow (this_obstack, yy_cur, (yy_lim - yy_cur));
1372       yy_cur = yy_lim;
1373       lineno = parse_in.lineno;
1374       return;
1375     }
1376 #endif
1377
1378   starting_lineno = lineno;
1379   do
1380     {
1381       c = getch ();
1382       if (c == EOF)
1383         {
1384           int save_lineno = lineno;
1385           lineno = starting_lineno;
1386           if (matching_char == '"')
1387             error ("end of file encountered inside string constant");
1388           else
1389             error ("end of file encountered inside character constant");
1390           lineno = save_lineno;
1391           return;
1392         }
1393       if (c == '\\')
1394         {
1395           obstack_1grow (this_obstack, c);
1396           c = getch ();
1397           obstack_1grow (this_obstack, c);
1398
1399           /* Make sure we continue the loop */
1400           c = 0;
1401           continue;
1402         }
1403       if (c == '\n')
1404         {
1405           if (pedantic)
1406             pedwarn ("ANSI C++ forbids newline in string constant");
1407           lineno++;
1408         }
1409       obstack_1grow (this_obstack, c);
1410     }
1411   while (c != matching_char);
1412 }
1413
1414 struct pending_input {
1415   int yychar, eof;
1416   YYSTYPE yylval;
1417   struct obstack token_obstack;
1418   int first_token;
1419 };
1420
1421 struct pending_input *
1422 save_pending_input ()
1423 {
1424   struct pending_input *p;
1425   p = (struct pending_input *) xmalloc (sizeof (struct pending_input));
1426   p->yychar = yychar;
1427   p->yylval = yylval;
1428   p->eof = end_of_file;
1429   yychar = YYEMPTY;
1430   p->first_token = first_token;
1431   p->token_obstack = token_obstack;
1432
1433   first_token = 0;
1434   gcc_obstack_init (&token_obstack);
1435   end_of_file = 0;
1436   return p;
1437 }
1438
1439 void
1440 restore_pending_input (p)
1441      struct pending_input *p;
1442 {
1443   my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230);
1444   yychar = p->yychar;
1445   yylval = p->yylval;
1446   first_token = p->first_token;
1447   obstack_free (&token_obstack, (char *) 0);
1448   token_obstack = p->token_obstack;
1449   end_of_file = p->eof;
1450   free (p);
1451 }
1452
1453 /* Unget character CH from the input stream.
1454    If RESCAN is non-zero, then we want to `see' this
1455    character as the next input token.  */
1456
1457 void
1458 yyungetc (ch, rescan)
1459      int ch;
1460      int rescan;
1461 {
1462   /* Unget a character from the input stream.  */
1463   if (yychar == YYEMPTY || rescan == 0)
1464     {
1465       /* If we're putting back a brace, undo the change in indent_level
1466          from the first time we saw it.  */
1467       if (ch == '{')
1468         indent_level--;
1469       else if (ch == '}')
1470         indent_level++;
1471
1472       put_back (ch);
1473     }
1474   else
1475     {
1476       yychar = ch;
1477     }
1478 }
1479
1480 void
1481 clear_inline_text_obstack ()
1482 {
1483   obstack_free (&inline_text_obstack, inline_text_firstobj);
1484 }
1485
1486 /* This function stores away the text for an inline function that should
1487    be processed later.  It decides how much later, and may need to move
1488    the info between obstacks; therefore, the caller should not refer to
1489    the T parameter after calling this function.  */
1490
1491 static void
1492 store_pending_inline (decl, t)
1493      tree decl;
1494      struct pending_inline *t;
1495 {
1496   t->fndecl = decl;
1497   DECL_PENDING_INLINE_INFO (decl) = t;
1498
1499   /* Because we use obstacks, we must process these in precise order.  */
1500   t->next = pending_inlines;
1501   pending_inlines = t;
1502 }
1503
1504 void
1505 reinit_parse_for_method (yychar, decl)
1506      int yychar;
1507      tree decl;
1508 {
1509   int len;
1510   int starting_lineno = lineno;
1511   char *starting_filename = input_filename;
1512
1513   reinit_parse_for_block (yychar, &inline_text_obstack);
1514
1515   len = obstack_object_size (&inline_text_obstack);
1516   current_base_init_list = NULL_TREE;
1517   current_member_init_list = NULL_TREE;
1518   if (decl == void_type_node
1519       || (current_class_type && TYPE_REDEFINED (current_class_type)))
1520     {
1521       /* Happens when we get two declarations of the same
1522          function in the same scope.  */
1523       char *buf = obstack_finish (&inline_text_obstack);
1524       obstack_free (&inline_text_obstack, buf);
1525       return;
1526     }
1527   else
1528     {
1529       struct pending_inline *t;
1530       char *buf = obstack_finish (&inline_text_obstack);
1531
1532       t = (struct pending_inline *) obstack_alloc (&inline_text_obstack,
1533                                                    sizeof (struct pending_inline));
1534       t->lineno = starting_lineno;
1535       t->filename = starting_filename;
1536       t->token = YYEMPTY;
1537       t->token_value = 0;
1538       t->buf = buf;
1539       t->len = len;
1540       t->deja_vu = 0;
1541 #if 0
1542       if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
1543         warn_if_unknown_interface (decl);
1544 #endif
1545       t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2));
1546       store_pending_inline (decl, t);
1547     }
1548 }
1549
1550 /* Consume a block -- actually, a method beginning
1551    with `:' or `{' -- and save it away on the specified obstack.  */
1552
1553 void
1554 reinit_parse_for_block (pyychar, obstackp)
1555      int pyychar;
1556      struct obstack *obstackp;
1557 {
1558   register int c;
1559   int blev = 1;
1560   int starting_lineno = lineno;
1561   char *starting_filename = input_filename;
1562   int len;
1563   int look_for_semicolon = 0;
1564   int look_for_lbrac = 0;
1565
1566   if (pyychar == '{')
1567     {
1568       obstack_1grow (obstackp, '{');
1569       /* We incremented indent_level in yylex; undo that.  */
1570       indent_level--;
1571     }
1572   else if (pyychar == '=')
1573     look_for_semicolon = 1;
1574   else if (pyychar == ':')
1575     {
1576       obstack_1grow (obstackp, pyychar);
1577       /* Add a space so we don't get confused by ': ::A(20)'.  */
1578       obstack_1grow (obstackp, ' ');
1579       look_for_lbrac = 1;
1580       blev = 0;
1581     }
1582   else if (pyychar == RETURN_KEYWORD)
1583     {
1584       obstack_grow (obstackp, "return", 6);
1585       look_for_lbrac = 1;
1586       blev = 0;
1587     }
1588   else if (pyychar == TRY)
1589     {
1590       obstack_grow (obstackp, "try", 3);
1591       look_for_lbrac = 1;
1592       blev = 0;
1593     }
1594   else
1595     {
1596       yyerror ("parse error in method specification");
1597       obstack_1grow (obstackp, '{');
1598     }
1599
1600   c = getch ();
1601
1602   while (c != EOF)
1603     {
1604       int this_lineno = lineno;
1605
1606       c = skip_white_space (c);
1607
1608       /* Don't lose our cool if there are lots of comments.  */
1609       if (lineno == this_lineno + 1)
1610         obstack_1grow (obstackp, '\n');
1611       else if (lineno == this_lineno)
1612         ;
1613       else if (lineno - this_lineno < 10)
1614         {
1615           int i;
1616           for (i = lineno - this_lineno; i > 0; i--)
1617             obstack_1grow (obstackp, '\n');
1618         }
1619       else
1620         {
1621           char buf[16];
1622           sprintf (buf, "\n# %d \"", lineno);
1623           len = strlen (buf);
1624           obstack_grow (obstackp, buf, len);
1625
1626           len = strlen (input_filename);
1627           obstack_grow (obstackp, input_filename, len);
1628           obstack_1grow (obstackp, '\"');
1629           obstack_1grow (obstackp, '\n');
1630         }
1631
1632       while (c > ' ')           /* ASCII dependent...  */
1633         {
1634           obstack_1grow (obstackp, c);
1635           if (c == '{')
1636             {
1637               look_for_lbrac = 0;
1638               blev++;
1639             }
1640           else if (c == '}')
1641             {
1642               blev--;
1643               if (blev == 0 && !look_for_semicolon)
1644                 {
1645                   if (pyychar == TRY)
1646                     {
1647                       if (peekyylex () == CATCH)
1648                         {
1649                           yylex ();
1650                           obstack_grow (obstackp, " catch ", 7);
1651                           look_for_lbrac = 1;
1652                         }
1653                       else
1654                         {
1655                           yychar = '{';
1656                           goto done;
1657                         }
1658                     }
1659                   else
1660                     {
1661                       goto done;
1662                     }
1663                 }
1664             }
1665           else if (c == '\\')
1666             {
1667               /* Don't act on the next character...e.g, doing an escaped
1668                  double-quote.  */
1669               c = getch ();
1670               if (c == EOF)
1671                 {
1672                   error_with_file_and_line (starting_filename,
1673                                             starting_lineno,
1674                                             "end of file read inside definition");
1675                   goto done;
1676                 }
1677               obstack_1grow (obstackp, c);
1678             }
1679           else if (c == '\"')
1680             consume_string (obstackp, c);
1681           else if (c == '\'')
1682             consume_string (obstackp, c);
1683           else if (c == ';')
1684             {
1685               if (look_for_lbrac)
1686                 {
1687                   error ("function body for constructor missing");
1688                   obstack_1grow (obstackp, '{');
1689                   obstack_1grow (obstackp, '}');
1690                   len += 2;
1691                   goto done;
1692                 }
1693               else if (look_for_semicolon && blev == 0)
1694                 goto done;
1695             }
1696           c = getch ();
1697         }
1698
1699       if (c == EOF)
1700         {
1701           error_with_file_and_line (starting_filename,
1702                                     starting_lineno,
1703                                     "end of file read inside definition");
1704           goto done;
1705         }
1706       else if (c != '\n')
1707         {
1708           obstack_1grow (obstackp, c);
1709           c = getch ();
1710         }
1711     }
1712  done:
1713   obstack_1grow (obstackp, '\0');
1714 }
1715
1716 /* Consume a no-commas expression -- actually, a default argument -- and
1717    save it away on the specified obstack.  */
1718
1719 static void
1720 reinit_parse_for_expr (obstackp)
1721      struct obstack *obstackp;
1722 {
1723   register int c;
1724   int starting_lineno = lineno;
1725   char *starting_filename = input_filename;
1726   int len;
1727   int plev = 0;
1728
1729   c = getch ();
1730
1731   while (c != EOF)
1732     {
1733       int this_lineno = lineno;
1734
1735       c = skip_white_space (c);
1736
1737       /* Don't lose our cool if there are lots of comments.  */
1738       if (lineno == this_lineno + 1)
1739         obstack_1grow (obstackp, '\n');
1740       else if (lineno == this_lineno)
1741         ;
1742       else if (lineno - this_lineno < 10)
1743         {
1744           int i;
1745           for (i = lineno - this_lineno; i > 0; --i)
1746             obstack_1grow (obstackp, '\n');
1747         }
1748       else
1749         {
1750           char buf[16];
1751           sprintf (buf, "\n# %d \"", lineno);
1752           len = strlen (buf);
1753           obstack_grow (obstackp, buf, len);
1754
1755           len = strlen (input_filename);
1756           obstack_grow (obstackp, input_filename, len);
1757           obstack_1grow (obstackp, '\"');
1758           obstack_1grow (obstackp, '\n');
1759         }
1760
1761       while (c > ' ')           /* ASCII dependent...  */
1762         {
1763           if (plev <= 0 && (c == ')' || c == ','))
1764             {
1765               put_back (c);
1766               goto done;
1767             }
1768           obstack_1grow (obstackp, c);
1769           if (c == '(' || c == '[')
1770             ++plev;
1771           else if (c == ']' || c == ')')
1772             --plev;
1773           else if (c == '\\')
1774             {
1775               /* Don't act on the next character...e.g, doing an escaped
1776                  double-quote.  */
1777               c = getch ();
1778               if (c == EOF)
1779                 {
1780                   error_with_file_and_line (starting_filename,
1781                                             starting_lineno,
1782                                             "end of file read inside definition");
1783                   goto done;
1784                 }
1785               obstack_1grow (obstackp, c);
1786             }
1787           else if (c == '\"')
1788             consume_string (obstackp, c);
1789           else if (c == '\'')
1790             consume_string (obstackp, c);
1791           c = getch ();
1792         }
1793
1794       if (c == EOF)
1795         {
1796           error_with_file_and_line (starting_filename,
1797                                     starting_lineno,
1798                                     "end of file read inside definition");
1799           goto done;
1800         }
1801       else if (c != '\n')
1802         {
1803           obstack_1grow (obstackp, c);
1804           c = getch ();
1805         }
1806     }
1807  done:
1808   obstack_1grow (obstackp, '\0');
1809 }
1810
1811 int do_snarf_defarg;
1812
1813 /* Decide whether the default argument we are about to see should be
1814    gobbled up as text for later parsing.  */
1815
1816 void
1817 maybe_snarf_defarg ()
1818 {
1819   if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
1820     do_snarf_defarg = 1;
1821 }
1822
1823 /* When we see a default argument in a method declaration, we snarf it as
1824    text using snarf_defarg.  When we get up to namespace scope, we then go
1825    through and parse all of them using do_pending_defargs.  Since yacc
1826    parsers are not reentrant, we retain defargs state in these two
1827    variables so that subsequent calls to do_pending_defargs can resume
1828    where the previous call left off.  */
1829
1830 tree defarg_fns;
1831 tree defarg_parm;
1832
1833 tree
1834 snarf_defarg ()
1835 {
1836   int len;
1837   char *buf;
1838   tree arg;
1839
1840   reinit_parse_for_expr (&inline_text_obstack);
1841   len = obstack_object_size (&inline_text_obstack);
1842   buf = obstack_finish (&inline_text_obstack);
1843
1844   push_obstacks (&inline_text_obstack, &inline_text_obstack);
1845   arg = make_node (DEFAULT_ARG);
1846   DEFARG_LENGTH (arg) = len - 1;
1847   DEFARG_POINTER (arg) = buf;
1848   pop_obstacks ();
1849
1850   return arg;
1851 }
1852
1853 /* Called from grokfndecl to note a function decl with unparsed default
1854    arguments for later processing.  Also called from grokdeclarator
1855    for function types with unparsed defargs; the call from grokfndecl
1856    will always come second, so we can overwrite the entry from the type.  */
1857
1858 void
1859 add_defarg_fn (decl)
1860      tree decl;
1861 {
1862   if (TREE_CODE (decl) == FUNCTION_DECL)
1863     TREE_VALUE (defarg_fns) = decl;
1864   else
1865     {
1866       push_obstacks (&inline_text_obstack, &inline_text_obstack);
1867       defarg_fns = tree_cons (current_class_type, decl, defarg_fns);  
1868       pop_obstacks ();
1869     }
1870 }
1871
1872 /* Helper for do_pending_defargs.  Starts the parsing of a default arg.  */
1873
1874 static void
1875 feed_defarg (f, p)
1876      tree f, p;
1877 {
1878   tree d = TREE_PURPOSE (p);
1879   char *file;
1880   int line;
1881   if (TREE_CODE (f) == FUNCTION_DECL)
1882     {
1883       line = DECL_SOURCE_LINE (f);
1884       file = DECL_SOURCE_FILE (f);
1885     }
1886   else
1887     {
1888       line = lineno;
1889       file = input_filename;
1890     }
1891
1892   feed_input (DEFARG_POINTER (d), DEFARG_LENGTH (d), file, line);
1893   yychar = DEFARG_MARKER;
1894   yylval.ttype = p;
1895 }
1896
1897 /* Helper for do_pending_defargs.  Ends the parsing of a default arg.  */
1898
1899 static void
1900 finish_defarg ()
1901 {
1902   if (yychar == YYEMPTY)
1903     yychar = yylex ();
1904   if (yychar != END_OF_SAVED_INPUT)
1905     {
1906       error ("parse error at end of saved function text");
1907
1908       /* restore_pending_input will abort unless yychar is either
1909          END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1910          hosed, feed back YYEMPTY.  */
1911     }
1912   yychar = YYEMPTY;
1913   end_input ();
1914 }  
1915
1916 /* Main function for deferred parsing of default arguments.  Called from
1917    the parser.  */
1918
1919 void
1920 do_pending_defargs ()
1921 {
1922   if (defarg_parm)
1923     finish_defarg ();
1924
1925   for (; defarg_fns; defarg_fns = TREE_CHAIN (defarg_fns))
1926     {
1927       tree defarg_fn = TREE_VALUE (defarg_fns);
1928       if (defarg_parm == NULL_TREE)
1929         {
1930           push_nested_class (TREE_PURPOSE (defarg_fns), 1);
1931           pushlevel (0);
1932           if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1933             maybe_begin_member_template_processing (defarg_fn);
1934
1935           if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1936             {
1937 #if 0
1938               tree p;
1939               for (p = DECL_ARGUMENTS (defarg_fn); p; p = TREE_CHAIN (p))
1940                 pushdecl (copy_node (p));
1941 #endif
1942               defarg_parm = TYPE_ARG_TYPES (TREE_TYPE (defarg_fn));
1943             }
1944           else
1945             defarg_parm = TYPE_ARG_TYPES (defarg_fn);
1946         }
1947       else
1948         defarg_parm = TREE_CHAIN (defarg_parm);
1949
1950       for (; defarg_parm; defarg_parm = TREE_CHAIN (defarg_parm))
1951         if (TREE_PURPOSE (defarg_parm)
1952             && TREE_CODE (TREE_PURPOSE (defarg_parm)) == DEFAULT_ARG)
1953           {
1954             feed_defarg (defarg_fn, defarg_parm);
1955
1956             /* Return to the parser, which will process this defarg
1957                and call us again.  */
1958             return;
1959           }
1960
1961       if (TREE_CODE (defarg_fn) == FUNCTION_DECL)
1962         {
1963           maybe_end_member_template_processing ();
1964           check_default_args (defarg_fn);
1965         }
1966
1967       poplevel (0, 0, 0);
1968       pop_nested_class ();
1969     }
1970 }
1971
1972 /* Build a default function named NAME for type TYPE.
1973    KIND says what to build.
1974
1975    When KIND == 0, build default destructor.
1976    When KIND == 1, build virtual destructor.
1977    When KIND == 2, build default constructor.
1978    When KIND == 3, build default X(const X&) constructor.
1979    When KIND == 4, build default X(X&) constructor.
1980    When KIND == 5, build default operator = (const X&).
1981    When KIND == 6, build default operator = (X&).  */
1982
1983 tree
1984 cons_up_default_function (type, full_name, kind)
1985      tree type, full_name;
1986      int kind;
1987 {
1988   tree declspecs = NULL_TREE;
1989   tree fn, args = NULL_TREE;
1990   tree argtype;
1991   int retref = 0;
1992   tree name = constructor_name (full_name);
1993
1994   switch (kind)
1995     {
1996       /* Destructors.  */
1997     case 1:
1998       declspecs = build_decl_list (NULL_TREE, ridpointers [(int) RID_VIRTUAL]);
1999       /* Fall through...  */
2000     case 0:
2001       name = build_parse_node (BIT_NOT_EXPR, name);
2002       args = void_list_node;
2003       break;
2004
2005     case 2:
2006       /* Default constructor.  */
2007       args = void_list_node;
2008       break;
2009
2010     case 3:
2011       type = build_qualified_type (type, TYPE_QUAL_CONST);
2012       /* Fall through...  */
2013     case 4:
2014       /* According to ARM $12.8, the default copy ctor will be declared, but
2015          not defined, unless it's needed.  */
2016       argtype = build_reference_type (type);
2017       args = tree_cons (NULL_TREE,
2018                         build_tree_list (hash_tree_chain (argtype, NULL_TREE),
2019                                          get_identifier ("_ctor_arg")),
2020                         void_list_node);
2021       break;
2022
2023     case 5:
2024     case 6:
2025       retref = 1;
2026       declspecs = build_decl_list (NULL_TREE, type);
2027
2028       if (kind == 5)
2029         type = build_qualified_type (type, TYPE_QUAL_CONST);
2030
2031       name = ansi_opname [(int) MODIFY_EXPR];
2032
2033       argtype = build_reference_type (type);
2034       args = tree_cons (NULL_TREE,
2035                         build_tree_list (hash_tree_chain (argtype, NULL_TREE),
2036                                          get_identifier ("_ctor_arg")),
2037                         void_list_node);
2038       break;
2039
2040     default:
2041       my_friendly_abort (59);
2042     }
2043
2044   declspecs = decl_tree_cons (NULL_TREE, ridpointers [(int) RID_INLINE],
2045                               declspecs);
2046
2047   TREE_PARMLIST (args) = 1;
2048
2049   {
2050     tree declarator = make_call_declarator (name, args, NULL_TREE, NULL_TREE);
2051     if (retref)
2052       declarator = build_parse_node (ADDR_EXPR, declarator);
2053
2054     fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE);
2055   }
2056   
2057   if (fn == void_type_node)
2058     return fn;
2059
2060   if (kind > 2)
2061     SET_DECL_ARTIFICIAL (TREE_CHAIN (DECL_ARGUMENTS (fn)));
2062
2063 #if 0
2064   if (processing_template_defn)
2065     {
2066       SET_DECL_IMPLICIT_INSTANTIATION (fn);
2067       repo_template_used (fn);
2068     }
2069 #endif
2070
2071 #if 0
2072   if (CLASSTYPE_INTERFACE_KNOWN (type))
2073     {
2074       DECL_INTERFACE_KNOWN (fn) = 1;
2075       DECL_NOT_REALLY_EXTERN (fn) = (!CLASSTYPE_INTERFACE_ONLY (type)
2076                                      && flag_implement_inlines);
2077     }
2078   else
2079 #endif
2080     DECL_NOT_REALLY_EXTERN (fn) = 1;
2081
2082   mark_inline_for_output (fn);
2083
2084 #ifdef DEBUG_DEFAULT_FUNCTIONS
2085   { char *fn_type = NULL;
2086     tree t = name;
2087     switch (kind)
2088       {
2089       case 0: fn_type = "default destructor"; break;
2090       case 1: fn_type = "virtual destructor"; break;
2091       case 2: fn_type = "default constructor"; break;
2092       case 3: fn_type = "default X(const X&)"; break;
2093       case 4: fn_type = "default X(X&)"; break;
2094       }
2095     if (fn_type)
2096       {
2097         if (TREE_CODE (name) == BIT_NOT_EXPR)
2098           t = TREE_OPERAND (name, 0);
2099         fprintf (stderr, "[[[[ %s for %s:\n%s]]]]\n", fn_type,
2100                  IDENTIFIER_POINTER (t), func_buf);
2101       }
2102   }
2103 #endif /* DEBUG_DEFAULT_FUNCTIONS */
2104
2105   /* Show that this function was generated by the compiler.  */
2106   SET_DECL_ARTIFICIAL (fn);
2107   
2108   return fn;
2109 }
2110
2111 /* Heuristic to tell whether the user is missing a semicolon
2112    after a struct or enum declaration.  Emit an error message
2113    if we know the user has blown it.  */
2114
2115 void
2116 check_for_missing_semicolon (type)
2117      tree type;
2118 {
2119   if (yychar < 0)
2120     yychar = yylex ();
2121
2122   if ((yychar > 255
2123        && yychar != SCSPEC
2124        && yychar != IDENTIFIER
2125        && yychar != TYPENAME
2126        && yychar != CV_QUALIFIER
2127        && yychar != SELFNAME)
2128       || end_of_file)
2129     {
2130       if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
2131         error ("semicolon missing after %s declaration",
2132                TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct");
2133       else
2134         cp_error ("semicolon missing after declaration of `%T'", type);
2135       shadow_tag (build_tree_list (0, type));
2136     }
2137   /* Could probably also hack cases where class { ... } f (); appears.  */
2138   clear_anon_tags ();
2139 }
2140
2141 void
2142 note_got_semicolon (type)
2143      tree type;
2144 {
2145   if (TREE_CODE_CLASS (TREE_CODE (type)) != 't')
2146     my_friendly_abort (60);
2147   if (CLASS_TYPE_P (type))
2148     CLASSTYPE_GOT_SEMICOLON (type) = 1;
2149 }
2150
2151 void
2152 note_list_got_semicolon (declspecs)
2153      tree declspecs;
2154 {
2155   tree link;
2156
2157   for (link = declspecs; link; link = TREE_CHAIN (link))
2158     {
2159       tree type = TREE_VALUE (link);
2160       if (TREE_CODE_CLASS (TREE_CODE (type)) == 't')
2161         note_got_semicolon (type);
2162     }
2163   clear_anon_tags ();
2164 }
2165 \f
2166 /* Iff C is a carriage return, warn about it - if appropriate -
2167    and return nonzero.  */
2168 static int
2169 whitespace_cr (c)
2170      int c;
2171 {
2172   static int newline_warning = 0;
2173
2174   if (c == '\r')
2175     {
2176       /* ANSI C says the effects of a carriage return in a source file
2177          are undefined.  */
2178       if (pedantic && !newline_warning)
2179         {
2180           warning ("carriage return in source file");
2181           warning ("(we only warn about the first carriage return)");
2182           newline_warning = 1;
2183         }
2184       return 1;
2185     }
2186   return 0;
2187 }
2188
2189 /* If C is not whitespace, return C.
2190    Otherwise skip whitespace and return first nonwhite char read.  */
2191
2192 static int
2193 skip_white_space (c)
2194      register int c;
2195 {
2196   for (;;)
2197     {
2198       switch (c)
2199         {
2200           /* We don't recognize comments here, because
2201              cpp output can include / and * consecutively as operators.
2202              Also, there's no need, since cpp removes all comments.  */
2203
2204         case '\n':
2205           if (linemode)
2206             {
2207               put_back (c);
2208               return EOF;
2209             }
2210           c = check_newline ();
2211           break;
2212
2213         case ' ':
2214         case '\t':
2215         case '\f':
2216         case '\v':
2217         case '\b':
2218 #if USE_CPPLIB
2219           /* While processing a # directive we don't get CPP_HSPACE
2220              tokens, so we also need to handle whitespace the normal way.  */
2221           if (cpp_token == CPP_HSPACE)
2222             c = yy_get_token ();
2223           else
2224 #endif
2225             c = getch ();
2226           break;
2227
2228         case '\r':
2229           whitespace_cr (c);
2230           c = getch ();
2231           break;
2232
2233         case '\\':
2234           c = getch ();
2235           if (c == '\n')
2236             lineno++;
2237           else
2238             error ("stray '\\' in program");
2239           c = getch ();
2240           break;
2241
2242         default:
2243           return (c);
2244         }
2245     }
2246 }
2247
2248 /* Make the token buffer longer, preserving the data in it.
2249    P should point to just beyond the last valid character in the old buffer.
2250    The value we return is a pointer to the new buffer
2251    at a place corresponding to P.  */
2252
2253 static void
2254 extend_token_buffer_to (size)
2255      int size;
2256 {
2257   do
2258     maxtoken = maxtoken * 2 + 10;
2259   while (maxtoken < size);
2260   token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
2261 }
2262
2263 static char *
2264 extend_token_buffer (p)
2265      const char *p;
2266 {
2267   int offset = p - token_buffer;
2268   extend_token_buffer_to (offset);
2269   return token_buffer + offset;
2270 }
2271 \f
2272 #if defined HANDLE_PRAGMA
2273 /* Local versions of these macros, that can be passed as function pointers.  */
2274 static int
2275 pragma_getc ()
2276 {
2277   return getch ();
2278 }
2279
2280 static void
2281 pragma_ungetc (arg)
2282      int arg;
2283 {
2284   put_back (arg);
2285 }
2286 #endif
2287
2288 static int
2289 read_line_number (num)
2290      int *num;
2291 {
2292   register int token = real_yylex ();
2293
2294   if (token == CONSTANT
2295       && TREE_CODE (yylval.ttype) == INTEGER_CST)
2296     {
2297       *num = TREE_INT_CST_LOW (yylval.ttype);
2298       return 1;
2299     }
2300   else
2301     {
2302       if (token != END_OF_LINE)
2303         error ("invalid #-line");
2304       return 0;
2305     }
2306 }
2307
2308 /* At the beginning of a line, increment the line number
2309    and process any #-directive on this line.
2310    If the line is a #-directive, read the entire line and return a newline.
2311    Otherwise, return the line's first non-whitespace character.
2312
2313    Note that in the case of USE_CPPLIB, we get the whole line as one
2314    CPP_DIRECTIVE token.  */
2315
2316 static int
2317 check_newline ()
2318 {
2319   register int c;
2320   register int token;
2321   int saw_line;
2322   enum { act_none, act_push, act_pop } action;
2323   int old_lineno, action_number, l;
2324   int entering_c_header;
2325
2326  restart:
2327   /* Read first nonwhite char on the line.  Do this before incrementing the
2328      line number, in case we're at the end of saved text.  */
2329
2330 #ifdef USE_CPPLIB
2331   c = getch ();
2332   /* In some cases where we're leaving an include file, we can get multiple
2333      CPP_HSPACE tokens in a row, so we need to loop.  */
2334   while (cpp_token == CPP_HSPACE)
2335     c = yy_get_token ();
2336 #else
2337   do
2338     c = getch ();
2339   while (c == ' ' || c == '\t');
2340 #endif
2341
2342   lineno++;
2343
2344   if (c != '#')
2345     {
2346       /* Sequences of multiple newlines are very common; optimize them.  */
2347       if (c == '\n')
2348         goto restart;
2349
2350       /* If not #, return it so caller will use it.  */
2351       return c;
2352     }
2353
2354   /* Don't read beyond this line.  */
2355   saw_line = 0;
2356   linemode = 1;
2357   
2358 #if USE_CPPLIB
2359   if (cpp_token == CPP_VSPACE)
2360     {
2361       /* Format is "<space> <line number> <filename> <newline>".
2362          Only the line number is interesting, and even that
2363          we can get more efficiently than scanning the line.  */
2364       yy_cur = yy_lim - 1;
2365       lineno = parse_in.lineno - 1;
2366       goto skipline;
2367     }
2368 #endif
2369
2370   token = real_yylex ();
2371
2372   if (token == IDENTIFIER)
2373     {
2374       /* If a letter follows, then if the word here is `line', skip
2375          it and ignore it; otherwise, ignore the line, with an error
2376          if the word isn't `pragma'.  */
2377
2378       const char *name = IDENTIFIER_POINTER (yylval.ttype);
2379
2380       if (!strcmp (name, "pragma"))
2381         {
2382           token = real_yylex ();
2383           if (token != IDENTIFIER
2384               || TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
2385             goto skipline;
2386           
2387           /* If this is 1, we handled it; if it's -1, it was one we
2388              wanted but had something wrong with it.  Only if it's
2389              0 was it not handled.  */
2390           if (handle_cp_pragma (IDENTIFIER_POINTER (yylval.ttype)))
2391             goto skipline;
2392
2393 #ifdef HANDLE_PRAGMA
2394           /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS
2395              (if both are defined), in order to give the back
2396              end a chance to override the interpretation of
2397              SYSV style pragmas.  */
2398           if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
2399                              IDENTIFIER_POINTER (yylval.ttype)))
2400             goto skipline;
2401 #endif /* HANDLE_PRAGMA */
2402               
2403 #ifdef HANDLE_GENERIC_PRAGMAS
2404           if (handle_generic_pragma (token))
2405             goto skipline;
2406 #endif /* HANDLE_GENERIC_PRAGMAS */
2407
2408           /* Issue a warning message if we have been asked to do so.
2409              Ignoring unknown pragmas in system header file unless
2410              an explcit -Wunknown-pragmas has been given. */
2411           if (warn_unknown_pragmas > 1
2412               || (warn_unknown_pragmas && ! in_system_header))
2413             warning ("ignoring pragma: %s", token_buffer);
2414
2415           goto skipline;
2416         }
2417       else if (!strcmp (name, "define"))
2418         {
2419           debug_define (lineno, GET_DIRECTIVE_LINE ());
2420           goto skipline;
2421         }
2422       else if (!strcmp (name, "undef"))
2423         {
2424           debug_undef (lineno, GET_DIRECTIVE_LINE ());
2425           goto skipline;
2426         }
2427       else if (!strcmp (name, "line"))
2428         {
2429           saw_line = 1;
2430           token = real_yylex ();
2431           goto linenum;
2432         }
2433       else if (!strcmp (name, "ident"))
2434         {
2435           /* #ident.  The pedantic warning is now in cccp.c.  */
2436
2437           /* Here we have just seen `#ident '.
2438              A string constant should follow.  */
2439
2440           token = real_yylex ();
2441           if (token == END_OF_LINE)
2442             goto skipline;
2443           if (token != STRING
2444               || TREE_CODE (yylval.ttype) != STRING_CST)
2445             {
2446               error ("invalid #ident");
2447               goto skipline;
2448             }
2449
2450           if (! flag_no_ident)
2451             {
2452 #ifdef ASM_OUTPUT_IDENT
2453               ASM_OUTPUT_IDENT (asm_out_file,
2454                                 TREE_STRING_POINTER (yylval.ttype));
2455 #endif
2456             }
2457
2458           /* Skip the rest of this line.  */
2459           goto skipline;
2460         }
2461
2462       error ("undefined or invalid # directive `%s'", name);
2463       goto skipline;
2464     }
2465
2466   /* If the # is the only nonwhite char on the line,
2467      just ignore it.  Check the new newline.  */
2468   if (token == END_OF_LINE)
2469     goto skipline;
2470
2471 linenum:
2472   /* Here we have either `#line' or `# <nonletter>'.
2473      In either case, it should be a line number; a digit should follow.  */
2474
2475   if (token != CONSTANT
2476       || TREE_CODE (yylval.ttype) != INTEGER_CST)
2477     {
2478       error ("invalid #-line");
2479       goto skipline;
2480     }
2481
2482   /* subtract one, because it is the following line that
2483      gets the specified number */
2484
2485   l = TREE_INT_CST_LOW (yylval.ttype) - 1;
2486
2487   /* More follows: it must be a string constant (filename).
2488      It would be neat to use cpplib to quickly process the string, but
2489      (1) we don't have a handy tokenization of the string, and
2490      (2) I don't know how well that would work in the presense
2491      of filenames that contain wide characters.  */
2492
2493   if (saw_line)
2494     {
2495       /* Don't treat \ as special if we are processing #line 1 "...".
2496          If you want it to be treated specially, use # 1 "...".  */
2497       ignore_escape_flag = 1;
2498     }
2499
2500   /* Read the string constant.  */
2501   token = real_yylex ();
2502
2503   ignore_escape_flag = 0;
2504
2505   if (token == END_OF_LINE)
2506     {
2507       /* No more: store the line number and check following line.  */
2508       lineno = l;
2509       goto skipline;
2510     }
2511
2512   if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2513     {
2514       error ("invalid #line");
2515       goto skipline;
2516     }
2517
2518   /* Changing files again.  This means currently collected time
2519      is charged against header time, and body time starts back at 0.  */
2520   if (flag_detailed_statistics)
2521     {
2522       int this_time = my_get_run_time ();
2523       tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype));
2524       header_time += this_time - body_time;
2525       TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
2526         += this_time - body_time;
2527       this_filename_time = time_identifier;
2528       body_time = this_time;
2529     }
2530
2531   if (!TREE_PERMANENT (yylval.ttype))
2532     {
2533       input_filename
2534         = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
2535       strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
2536     }
2537   else
2538     input_filename = TREE_STRING_POINTER (yylval.ttype);
2539
2540   GNU_xref_file (input_filename);
2541       
2542   if (main_input_filename == 0)
2543     {
2544       struct impl_files *ifiles = impl_file_chain;
2545
2546       if (ifiles)
2547         {
2548           while (ifiles->next)
2549             ifiles = ifiles->next;
2550           ifiles->filename = file_name_nondirectory (input_filename);
2551         }
2552
2553       main_input_filename = input_filename;
2554     }
2555
2556   extract_interface_info ();
2557
2558   old_lineno = lineno;
2559   action = act_none;
2560   action_number = 0;
2561   lineno = l;
2562
2563   /* Each change of file name
2564      reinitializes whether we are now in a system header.  */
2565   in_system_header = 0;
2566   entering_c_header = 0;
2567
2568   if (!read_line_number (&action_number))
2569     {
2570       /* Update the name in the top element of input_file_stack.  */
2571       if (input_file_stack)
2572         input_file_stack->name = input_filename;
2573     }
2574
2575   /* `1' after file name means entering new file.
2576      `2' after file name means just left a file.  */
2577
2578   if (action_number == 1)
2579     {
2580       action = act_push;
2581       read_line_number (&action_number);
2582     }
2583   else if (action_number == 2)
2584     {
2585       action = act_pop;
2586       read_line_number (&action_number);
2587     }
2588   if (action_number == 3)
2589     {
2590       /* `3' after file name means this is a system header file.  */
2591       in_system_header = 1;
2592       read_line_number (&action_number);
2593     }
2594   if (action_number == 4)
2595     {
2596       /* `4' after file name means this is a C header file.  */
2597       entering_c_header = 1;
2598       read_line_number (&action_number);
2599     }
2600
2601   /* Do the actions implied by the preceding numbers.  */
2602
2603   if (action == act_push)
2604     {
2605       /* Pushing to a new file.  */
2606       struct file_stack *p
2607         = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2608       input_file_stack->line = old_lineno;
2609       p->next = input_file_stack;
2610       p->name = input_filename;
2611       p->indent_level = indent_level;
2612       input_file_stack = p;
2613       input_file_stack_tick++;
2614       debug_start_source_file (input_filename);
2615       if (c_header_level)
2616         ++c_header_level;
2617       else if (entering_c_header)
2618         {
2619           c_header_level = 1;
2620           ++pending_lang_change;
2621         }
2622     }
2623   else if (action == act_pop)
2624     {
2625       /* Popping out of a file.  */
2626       if (input_file_stack->next)
2627         {
2628           struct file_stack *p = input_file_stack;
2629
2630           if (c_header_level && --c_header_level == 0)
2631             {
2632               if (entering_c_header)
2633                 warning ("badly nested C headers from preprocessor");
2634               --pending_lang_change;
2635             }
2636
2637           if (indent_level != p->indent_level)
2638             {
2639               warning_with_file_and_line
2640                 (p->name, old_lineno,
2641                  "This file contains more `%c's than `%c's.",
2642                  indent_level > p->indent_level ? '{' : '}',
2643                  indent_level > p->indent_level ? '}' : '{');
2644             }
2645           input_file_stack = p->next;
2646           free (p);
2647           input_file_stack_tick++;
2648           debug_end_source_file (input_file_stack->line);
2649         }
2650       else
2651         error ("#-lines for entering and leaving files don't match");
2652     }
2653
2654   /* Now that we've pushed or popped the input stack,
2655      update the name in the top element.  */
2656   if (input_file_stack)
2657     input_file_stack->name = input_filename;
2658
2659   /* skip the rest of this line.  */
2660  skipline:
2661   linemode = 0;
2662   end_of_file = 0;
2663
2664   do
2665     c = getch ();
2666   while (c != '\n' && c != EOF);
2667   return c;
2668 }
2669 \f
2670 #ifdef HANDLE_GENERIC_PRAGMAS
2671
2672 /* Handle a #pragma directive.
2673    TOKEN is the token we read after `#pragma'.  Processes the entire input
2674    line and return non-zero iff the pragma has been successfully parsed.  */
2675
2676 /* This function has to be in this file, in order to get at
2677    the token types.  */
2678
2679 static int
2680 handle_generic_pragma (token)
2681      register int token;
2682 {
2683   for (;;)
2684     {
2685       switch (token)
2686         {
2687         case IDENTIFIER:
2688         case TYPENAME:
2689         case STRING:
2690         case CONSTANT:
2691           handle_pragma_token (token_buffer, yylval.ttype);
2692           break;
2693
2694         case LEFT_RIGHT:
2695           handle_pragma_token ("(", NULL_TREE);
2696           handle_pragma_token (")", NULL_TREE);
2697           break;
2698
2699         case END_OF_LINE:
2700           return handle_pragma_token (NULL_PTR, NULL_TREE);
2701
2702         default:
2703           handle_pragma_token (token_buffer, NULL_TREE);
2704         }
2705       
2706       token = real_yylex ();
2707     }
2708 }
2709 #endif /* HANDLE_GENERIC_PRAGMAS */
2710
2711 static int
2712 handle_cp_pragma (pname)
2713      const char *pname;
2714 {
2715   register int token;
2716
2717   if (! strcmp (pname, "vtable"))
2718     {
2719       extern tree pending_vtables;
2720
2721       /* More follows: it must be a string constant (class name).  */
2722       token = real_yylex ();
2723       if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2724         {
2725           error ("invalid #pragma vtable");
2726           return -1;
2727         }
2728
2729       pending_vtables
2730         = perm_tree_cons (NULL_TREE,
2731                           get_identifier (TREE_STRING_POINTER (yylval.ttype)),
2732                           pending_vtables);
2733       token = real_yylex ();
2734       if (token != END_OF_LINE)
2735         warning ("trailing characters ignored");
2736       return 1;
2737     }
2738   else if (! strcmp (pname, "unit"))
2739     {
2740       /* More follows: it must be a string constant (unit name).  */
2741       token = real_yylex ();
2742       if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2743         {
2744           error ("invalid #pragma unit");
2745           return -1;
2746         }
2747       token = real_yylex ();
2748       if (token != END_OF_LINE)
2749         warning ("trailing characters ignored");
2750       return 1;
2751     }
2752   else if (! strcmp (pname, "interface"))
2753     {
2754       char *main_filename = input_filename;
2755
2756       main_filename = file_name_nondirectory (main_filename);
2757
2758       token = real_yylex ();
2759       
2760       if (token != END_OF_LINE)
2761         {
2762           if (token != STRING
2763               || TREE_CODE (yylval.ttype) != STRING_CST)
2764             {
2765               error ("invalid `#pragma interface'");
2766               return -1;
2767             }
2768           main_filename = TREE_STRING_POINTER (yylval.ttype);
2769           token = real_yylex ();
2770         }
2771
2772       if (token != END_OF_LINE)
2773         warning ("garbage after `#pragma interface' ignored");
2774
2775       cp_pragma_interface (main_filename);
2776
2777       return 1;
2778     }
2779   else if (! strcmp (pname, "implementation"))
2780     {
2781       char *main_filename = main_input_filename ? main_input_filename : input_filename;
2782
2783       main_filename = file_name_nondirectory (main_filename);
2784
2785       token = real_yylex ();
2786
2787       if (token != END_OF_LINE)
2788         {
2789           if (token != STRING
2790               || TREE_CODE (yylval.ttype) != STRING_CST)
2791             {
2792               error ("invalid `#pragma implementation'");
2793               return -1;
2794             }
2795           main_filename = TREE_STRING_POINTER (yylval.ttype);
2796           token = real_yylex ();
2797         }
2798
2799       if (token != END_OF_LINE)
2800         warning ("garbage after `#pragma implementation' ignored");
2801
2802       cp_pragma_implementation (main_filename);
2803
2804       return 1;
2805     }
2806
2807   return 0;
2808 }
2809 \f
2810 void
2811 do_pending_lang_change ()
2812 {
2813   for (; pending_lang_change > 0; --pending_lang_change)
2814     push_lang_context (lang_name_c);
2815   for (; pending_lang_change < 0; ++pending_lang_change)
2816     pop_lang_context ();
2817 }
2818 \f
2819 #define ENDFILE -1  /* token that represents end-of-file */
2820
2821 /* Read an escape sequence, returning its equivalent as a character,
2822    or store 1 in *ignore_ptr if it is backslash-newline.  */
2823
2824 static int
2825 readescape (ignore_ptr)
2826      int *ignore_ptr;
2827 {
2828   register int c = getch ();
2829   register int code;
2830   register unsigned count;
2831   unsigned firstdig = 0;
2832   int nonnull;
2833
2834   switch (c)
2835     {
2836     case 'x':
2837       code = 0;
2838       count = 0;
2839       nonnull = 0;
2840       while (1)
2841         {
2842           c = getch ();
2843           if (! ISXDIGIT (c))
2844             {
2845               put_back (c);
2846               break;
2847             }
2848           code *= 16;
2849           if (c >= 'a' && c <= 'f')
2850             code += c - 'a' + 10;
2851           if (c >= 'A' && c <= 'F')
2852             code += c - 'A' + 10;
2853           if (c >= '0' && c <= '9')
2854             code += c - '0';
2855           if (code != 0 || count != 0)
2856             {
2857               if (count == 0)
2858                 firstdig = code;
2859               count++;
2860             }
2861           nonnull = 1;
2862         }
2863       if (! nonnull)
2864         error ("\\x used with no following hex digits");
2865       else if (count == 0)
2866         /* Digits are all 0's.  Ok.  */
2867         ;
2868       else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
2869                || (count > 1
2870                    && (((unsigned)1
2871                         << (TYPE_PRECISION (integer_type_node)
2872                             - (count - 1) * 4))
2873                        <= firstdig)))
2874         pedwarn ("hex escape out of range");
2875       return code;
2876
2877     case '0':  case '1':  case '2':  case '3':  case '4':
2878     case '5':  case '6':  case '7':
2879       code = 0;
2880       count = 0;
2881       while ((c <= '7') && (c >= '0') && (count++ < 3))
2882         {
2883           code = (code * 8) + (c - '0');
2884           c = getch ();
2885         }
2886       put_back (c);
2887       return code;
2888
2889     case '\\': case '\'': case '"':
2890       return c;
2891
2892     case '\n':
2893       lineno++;
2894       *ignore_ptr = 1;
2895       return 0;
2896
2897     case 'n':
2898       return TARGET_NEWLINE;
2899
2900     case 't':
2901       return TARGET_TAB;
2902
2903     case 'r':
2904       return TARGET_CR;
2905
2906     case 'f':
2907       return TARGET_FF;
2908
2909     case 'b':
2910       return TARGET_BS;
2911
2912     case 'a':
2913       return TARGET_BELL;
2914
2915     case 'v':
2916       return TARGET_VT;
2917
2918     case 'e':
2919     case 'E':
2920       if (pedantic)
2921         pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
2922       return 033;
2923
2924     case '?':
2925       return c;
2926
2927       /* `\(', etc, are used at beginning of line to avoid confusing Emacs.  */
2928     case '(':
2929     case '{':
2930     case '[':
2931       /* `\%' is used to prevent SCCS from getting confused.  */
2932     case '%':
2933       if (pedantic)
2934         pedwarn ("unknown escape sequence `\\%c'", c);
2935       return c;
2936     }
2937   if (ISGRAPH (c))
2938     pedwarn ("unknown escape sequence `\\%c'", c);
2939   else
2940     pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
2941   return c;
2942 }
2943 \f
2944 void
2945 yyerror (string)
2946      const char *string;
2947 {
2948   extern int end_of_file;
2949   char buf[200];
2950
2951   strcpy (buf, string);
2952
2953   /* We can't print string and character constants well
2954      because the token_buffer contains the result of processing escapes.  */
2955   if (end_of_file)
2956     strcat (buf, input_redirected ()
2957             ? " at end of saved text"
2958             : " at end of input");
2959   else if (token_buffer[0] == 0)
2960     strcat (buf, " at null character");
2961   else if (token_buffer[0] == '"')
2962     strcat (buf, " before string constant");
2963   else if (token_buffer[0] == '\'')
2964     strcat (buf, " before character constant");
2965   else if (!ISGRAPH ((unsigned char)token_buffer[0]))
2966     sprintf (buf + strlen (buf), " before character 0%o",
2967              (unsigned char) token_buffer[0]);
2968   else
2969     strcat (buf, " before `%s'");
2970
2971   error (buf, token_buffer);
2972 }
2973 \f
2974 /* Value is 1 (or 2) if we should try to make the next identifier look like
2975    a typename (when it may be a local variable or a class variable).
2976    Value is 0 if we treat this name in a default fashion.  */
2977 int looking_for_typename;
2978
2979 #ifdef __GNUC__
2980 __inline
2981 #endif
2982 int
2983 identifier_type (decl)
2984      tree decl;
2985 {
2986   tree t;
2987   if (TREE_CODE (decl) == TEMPLATE_DECL)
2988     {
2989       if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL)
2990         return PTYPENAME;
2991       else if (looking_for_template) 
2992         return PFUNCNAME;
2993     }
2994   if (looking_for_template && really_overloaded_fn (decl))
2995     {
2996       /* See through a baselink.  */
2997       if (TREE_CODE (decl) == TREE_LIST)
2998         decl = TREE_VALUE (decl);
2999
3000       for (t = decl; t != NULL_TREE; t = OVL_CHAIN (t))
3001         if (DECL_FUNCTION_TEMPLATE_P (OVL_FUNCTION (t))) 
3002           return PFUNCNAME;
3003     }
3004   if (TREE_CODE (decl) == NAMESPACE_DECL)
3005     return NSNAME;
3006   if (TREE_CODE (decl) != TYPE_DECL)
3007     return IDENTIFIER;
3008   if (DECL_ARTIFICIAL (decl) && TREE_TYPE (decl) == current_class_type)
3009     return SELFNAME;
3010
3011   /* A constructor declarator for a template type will get here as an
3012      implicit typename, a TYPENAME_TYPE with a type.  */
3013   t = got_scope;
3014   if (t && TREE_CODE (t) == TYPENAME_TYPE)
3015     t = TREE_TYPE (t);
3016   decl = TREE_TYPE (decl);
3017   if (TREE_CODE (decl) == TYPENAME_TYPE)
3018     decl = TREE_TYPE (decl);
3019   if (t && t == decl)
3020     return SELFNAME;
3021
3022   return TYPENAME;
3023 }
3024
3025 void
3026 see_typename ()
3027 {
3028   /* Only types expected, not even namespaces. */
3029   looking_for_typename = 2;
3030   if (yychar < 0)
3031     if ((yychar = yylex ()) < 0) yychar = 0;
3032   looking_for_typename = 0;
3033   if (yychar == IDENTIFIER)
3034     {
3035       lastiddecl = lookup_name (yylval.ttype, -2);
3036       if (lastiddecl == 0)
3037         {
3038           if (flag_labels_ok)
3039             lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype);
3040         }
3041       else
3042         yychar = identifier_type (lastiddecl);
3043     }
3044 }
3045
3046 /* Return true if d is in a global scope. */
3047
3048 static int
3049 is_global (d)
3050   tree d;
3051 {
3052   while (1)
3053     switch (TREE_CODE (d))
3054       {
3055       case ERROR_MARK:
3056         return 1;
3057
3058       case OVERLOAD: d = OVL_FUNCTION (d); continue;
3059       case TREE_LIST: d = TREE_VALUE (d); continue;
3060       default:
3061         my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (d)) == 'd', 980629);
3062
3063         /* A template parameter is not really global, even though it
3064            has no enclosing scope.  */
3065         if (DECL_TEMPLATE_PARM_P (d))
3066           return 0;
3067
3068         d = CP_DECL_CONTEXT (d);
3069         return TREE_CODE (d) == NAMESPACE_DECL;
3070       }
3071 }
3072
3073 tree
3074 do_identifier (token, parsing, args)
3075      register tree token;
3076      int parsing;
3077      tree args;
3078 {
3079   register tree id;
3080   int lexing = (parsing == 1);
3081   int in_call = (parsing == 2);
3082
3083   if (! lexing || IDENTIFIER_OPNAME_P (token))
3084     id = lookup_name (token, 0);
3085   else
3086     id = lastiddecl;
3087
3088   /* Scope class declarations before global
3089      declarations.  */
3090   if ((!id || is_global (id))
3091       && current_class_type != 0
3092       && TYPE_SIZE (current_class_type) == 0)
3093     {
3094       /* Could be from one of the base classes.  */
3095       tree field = lookup_field (current_class_type, token, 1, 0);
3096       if (field == 0)
3097         ;
3098       else if (field == error_mark_node)
3099         /* We have already generated the error message.
3100            But we still want to return this value.  */
3101         id = lookup_field (current_class_type, token, 0, 0);
3102       else if (TREE_CODE (field) == VAR_DECL
3103                || TREE_CODE (field) == CONST_DECL
3104                || TREE_CODE (field) == TEMPLATE_DECL)
3105         id = field;
3106       else if (TREE_CODE (field) != FIELD_DECL)
3107         my_friendly_abort (61);
3108       else
3109         {
3110           cp_error ("invalid use of member `%D'", field);
3111           id = error_mark_node;
3112           return id;
3113         }
3114     }
3115
3116   /* Do Koenig lookup if appropriate (inside templates we build lookup
3117      expressions instead).  */
3118   if (args && !current_template_parms && (!id || is_global (id)))
3119     /* If we have arguments and we only found global names, do Koenig
3120        lookup. */
3121     id = lookup_arg_dependent (token, id, args);
3122
3123   /* Remember that this name has been used in the class definition, as per
3124      [class.scope0] */
3125   if (id && parsing
3126       /* Avoid breaking if we get called for a default argument that
3127          refers to an overloaded method.  Eventually this will not be
3128          necessary, since default arguments shouldn't be parsed until
3129          after the class is complete.  (jason 3/12/97) */
3130       && TREE_CODE (id) != OVERLOAD)
3131     maybe_note_name_used_in_class (token, id);
3132
3133   if (id == error_mark_node)
3134     {
3135       /* lookup_name quietly returns error_mark_node if we're parsing,
3136          as we don't want to complain about an identifier that ends up
3137          being used as a declarator.  So we call it again to get the error
3138          message.  */
3139       id = lookup_name (token, 0);
3140       return error_mark_node;
3141     }
3142       
3143   if (!id)
3144     {
3145       if (current_template_parms)
3146         return build_min_nt (LOOKUP_EXPR, token);
3147       else if (IDENTIFIER_OPNAME_P (token))
3148         {
3149           if (token != ansi_opname[ERROR_MARK])
3150             cp_error ("`%D' not defined", token);
3151           id = error_mark_node;
3152         }
3153       else if (in_call && ! flag_strict_prototype)
3154         {
3155           id = implicitly_declare (token);
3156         }
3157       else if (current_function_decl == 0)
3158         {
3159           cp_error ("`%D' was not declared in this scope", token);
3160           id = error_mark_node;
3161         }
3162       else
3163         {
3164           if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node
3165               || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl)
3166             {
3167               static int undeclared_variable_notice;
3168
3169               cp_error ("`%D' undeclared (first use this function)", token);
3170
3171               if (! undeclared_variable_notice)
3172                 {
3173                   error ("(Each undeclared identifier is reported only once");
3174                   error ("for each function it appears in.)");
3175                   undeclared_variable_notice = 1;
3176                 }
3177             }
3178           id = error_mark_node;
3179           /* Prevent repeated error messages.  */
3180           SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
3181           SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl);
3182         }
3183     }
3184
3185   if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id))
3186     {
3187       tree shadowed = DECL_SHADOWED_FOR_VAR (id);
3188       while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
3189              && DECL_DEAD_FOR_LOCAL (shadowed))
3190         shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
3191       if (!shadowed)
3192         shadowed = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (id));
3193       if (shadowed)
3194         {
3195           if (!DECL_ERROR_REPORTED (id))
3196             {
3197               warning ("name lookup of `%s' changed",
3198                        IDENTIFIER_POINTER (token));
3199               cp_warning_at ("  matches this `%D' under current ANSI rules",
3200                              shadowed);
3201               cp_warning_at ("  matches this `%D' under old rules", id);
3202               DECL_ERROR_REPORTED (id) = 1;
3203             }
3204           id = shadowed;
3205         }
3206       else if (!DECL_ERROR_REPORTED (id))
3207         {
3208           static char msg[]
3209             = "name lookup of `%s' changed for new ANSI `for' scoping";
3210           DECL_ERROR_REPORTED (id) = 1;
3211           if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (id)))
3212             {
3213               error (msg, IDENTIFIER_POINTER (token));
3214               cp_error_at ("  cannot use obsolete binding at `%D' because it has a destructor", id);
3215               id = error_mark_node;
3216             }
3217           else
3218             {
3219               pedwarn (msg, IDENTIFIER_POINTER (token));
3220               cp_pedwarn_at ("  using obsolete binding at `%D'", id);
3221             }
3222         }
3223     }
3224   /* TREE_USED is set in `hack_identifier'.  */
3225   if (TREE_CODE (id) == CONST_DECL)
3226     {
3227       /* Check access.  */
3228       if (IDENTIFIER_CLASS_VALUE (token) == id)
3229         enforce_access (DECL_REAL_CONTEXT(id), id);
3230       if (!processing_template_decl || DECL_TEMPLATE_PARM_P (id))
3231         id = DECL_INITIAL (id);
3232     }
3233   else
3234     id = hack_identifier (id, token);
3235
3236   /* We must look up dependent names when the template is
3237      instantiated, not while parsing it.  For now, we don't
3238      distinguish between dependent and independent names.  So, for
3239      example, we look up all overloaded functions at
3240      instantiation-time, even though in some cases we should just use
3241      the DECL we have here.  We also use LOOKUP_EXPRs to find things
3242      like local variables, rather than creating TEMPLATE_DECLs for the
3243      local variables and then finding matching instantiations.  */
3244   if (current_template_parms
3245       && (is_overloaded_fn (id) 
3246           /* If it's not going to be around at instantiation time, we
3247              look it up then.  This is a hack, and should go when we
3248              really get dependent/independent name lookup right.  */
3249           || !TREE_PERMANENT (id)
3250           /* Some local VAR_DECLs (such as those for local variables
3251              in member functions of local classes) are built on the
3252              permanent obstack.  */
3253           || (TREE_CODE (id) == VAR_DECL 
3254               && CP_DECL_CONTEXT (id)
3255               && TREE_CODE (CP_DECL_CONTEXT (id)) == FUNCTION_DECL)
3256           || TREE_CODE (id) == PARM_DECL
3257           || TREE_CODE (id) == RESULT_DECL
3258           || TREE_CODE (id) == USING_DECL))
3259     id = build_min_nt (LOOKUP_EXPR, token);
3260       
3261   return id;
3262 }
3263
3264 tree
3265 do_scoped_id (token, parsing)
3266      tree token;
3267      int parsing;
3268 {
3269   tree id;
3270   /* during parsing, this is ::name. Otherwise, it is black magic. */
3271   if (parsing)
3272     {
3273       struct tree_binding _b;
3274       id = binding_init (&_b);
3275       if (!qualified_lookup_using_namespace (token, global_namespace, id, 0))
3276         id = NULL_TREE;
3277       else
3278         id = BINDING_VALUE (id);
3279     } 
3280   else
3281     id = IDENTIFIER_GLOBAL_VALUE (token);
3282   if (parsing && yychar == YYEMPTY)
3283     yychar = yylex ();
3284   if (! id)
3285     {
3286       if (processing_template_decl)
3287         {
3288           id = build_min_nt (LOOKUP_EXPR, token);
3289           LOOKUP_EXPR_GLOBAL (id) = 1;
3290           return id;
3291         }
3292       if (parsing && (yychar == '(' || yychar == LEFT_RIGHT)
3293           && ! flag_strict_prototype)
3294         id = implicitly_declare (token);
3295       else
3296         {
3297           if (IDENTIFIER_NAMESPACE_VALUE (token) != error_mark_node)
3298             cp_error ("`::%D' undeclared (first use here)", token);
3299           id = error_mark_node;
3300           /* Prevent repeated error messages.  */
3301           SET_IDENTIFIER_NAMESPACE_VALUE (token, error_mark_node);
3302         }
3303     }
3304   else
3305     {
3306       if (TREE_CODE (id) == ADDR_EXPR)
3307         mark_used (TREE_OPERAND (id, 0));
3308       else if (TREE_CODE (id) != OVERLOAD)
3309         mark_used (id);
3310     }
3311   if (TREE_CODE (id) == CONST_DECL && ! processing_template_decl)
3312     {
3313       /* XXX CHS - should we set TREE_USED of the constant? */
3314       id = DECL_INITIAL (id);
3315       /* This is to prevent an enum whose value is 0
3316          from being considered a null pointer constant.  */
3317       id = build1 (NOP_EXPR, TREE_TYPE (id), id);
3318       TREE_CONSTANT (id) = 1;
3319     }
3320
3321   if (processing_template_decl)
3322     {
3323       if (is_overloaded_fn (id))
3324         {
3325           id = build_min_nt (LOOKUP_EXPR, token);
3326           LOOKUP_EXPR_GLOBAL (id) = 1;
3327           return id;
3328         }
3329       /* else just use the decl */
3330     }
3331   return convert_from_reference (id);
3332 }
3333
3334 tree
3335 identifier_typedecl_value (node)
3336      tree node;
3337 {
3338   tree t, type;
3339   type = IDENTIFIER_TYPE_VALUE (node);
3340   if (type == NULL_TREE)
3341     return NULL_TREE;
3342
3343   if (IDENTIFIER_BINDING (node))
3344     {
3345       t = IDENTIFIER_VALUE (node);
3346       if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
3347         return t;
3348     }
3349   if (IDENTIFIER_NAMESPACE_VALUE (node))
3350     {
3351       t = IDENTIFIER_NAMESPACE_VALUE (node);
3352       if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type)
3353         return t;
3354     }
3355
3356   /* Will this one ever happen?  */
3357   if (TYPE_MAIN_DECL (type))
3358     return TYPE_MAIN_DECL (type);
3359
3360   /* We used to do an internal error of 62 here, but instead we will
3361      handle the return of a null appropriately in the callers.  */
3362   return NULL_TREE;
3363 }
3364
3365 struct pf_args
3366 {
3367   /* Input */
3368   int base;
3369   char * p;
3370   /* I/O */
3371   int c;
3372   /* Output */
3373   int imag;
3374   tree type;
3375   int conversion_errno;
3376   REAL_VALUE_TYPE value;
3377 };
3378
3379 static void
3380 parse_float (data)
3381      PTR data;
3382 {
3383   struct pf_args * args = (struct pf_args *) data;
3384   int fflag = 0, lflag = 0;
3385   /* Copy token_buffer now, while it has just the number
3386      and not the suffixes; once we add `f' or `i',
3387      REAL_VALUE_ATOF may not work any more.  */
3388   char *copy = (char *) alloca (args->p - token_buffer + 1);
3389   bcopy (token_buffer, copy, args->p - token_buffer + 1);
3390   args->imag = 0;
3391   args->conversion_errno = 0;
3392   args->type = double_type_node;
3393
3394   while (1)
3395     {
3396       int lose = 0;
3397
3398       /* Read the suffixes to choose a data type.  */
3399       switch (args->c)
3400         {
3401         case 'f': case 'F':
3402           if (fflag)
3403             error ("more than one `f' in numeric constant");
3404           fflag = 1;
3405           break;
3406
3407         case 'l': case 'L':
3408           if (lflag)
3409             error ("more than one `l' in numeric constant");
3410           lflag = 1;
3411           break;
3412
3413         case 'i': case 'I':
3414           if (args->imag)
3415             error ("more than one `i' or `j' in numeric constant");
3416           else if (pedantic)
3417             pedwarn ("ANSI C++ forbids imaginary numeric constants");
3418           args->imag = 1;
3419           break;
3420
3421         default:
3422           lose = 1;
3423         }
3424
3425       if (lose)
3426         break;
3427
3428       if (args->p >= token_buffer + maxtoken - 3)
3429         args->p = extend_token_buffer (args->p);
3430       *(args->p++) = args->c;
3431       *(args->p) = 0;
3432       args->c = getch ();
3433     }
3434
3435   /* The second argument, machine_mode, of REAL_VALUE_ATOF
3436      tells the desired precision of the binary result
3437      of decimal-to-binary conversion.  */
3438
3439   if (fflag)
3440     {
3441       if (lflag)
3442         error ("both `f' and `l' in floating constant");
3443
3444       args->type = float_type_node;
3445       errno = 0;
3446       if (args->base == 16)
3447         args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3448       else
3449         args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3450       args->conversion_errno = errno;
3451       /* A diagnostic is required here by some ANSI C testsuites.
3452          This is not pedwarn, because some people don't want
3453          an error for this.  */
3454       if (REAL_VALUE_ISINF (args->value) && pedantic)
3455         warning ("floating point number exceeds range of `float'");
3456     }
3457   else if (lflag)
3458     {
3459       args->type = long_double_type_node;
3460       errno = 0;
3461       if (args->base == 16)
3462         args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3463       else
3464         args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3465       args->conversion_errno = errno;
3466       if (REAL_VALUE_ISINF (args->value) && pedantic)
3467         warning ("floating point number exceeds range of `long double'");
3468     }
3469   else
3470     {
3471       errno = 0;
3472       if (args->base == 16)
3473         args->value = REAL_VALUE_HTOF (copy, TYPE_MODE (args->type));
3474       else
3475         args->value = REAL_VALUE_ATOF (copy, TYPE_MODE (args->type));
3476       args->conversion_errno = errno;
3477       if (REAL_VALUE_ISINF (args->value) && pedantic)
3478         warning ("floating point number exceeds range of `double'");
3479     }
3480 }
3481
3482 /* Get the next character, staying within the current token if possible.
3483    If we're lexing a token, we don't want to look beyond the end of the
3484    token cpplib has prepared for us; otherwise, we end up reading in the
3485    next token, which screws up feed_input.  So just return a null
3486    character.  */
3487
3488 inline int
3489 token_getch ()
3490 {
3491 #if USE_CPPLIB
3492   if (yy_cur == yy_lim)
3493     return '\0';
3494 #endif
3495   return getch ();
3496 }
3497
3498 inline void
3499 token_put_back (ch)
3500      int ch;
3501 {
3502 #if USE_CPPLIB
3503   if (ch == '\0')
3504     return;
3505 #endif
3506   put_back (ch);
3507 }
3508
3509 /* Read a single token from the input stream, and assign it lexical
3510    semantics.
3511
3512    Note: We used to do token pasting here, to produce compound tokens like
3513    LEFT_RIGHT and EXTERN_LANG_STRING.  That's now handled in spew.c, along
3514    with symbol table interaction and other context-sensitivity.  */
3515
3516 int
3517 real_yylex ()
3518 {
3519   register int c;
3520   register char *p;
3521   register int value;
3522   int wide_flag = 0;
3523
3524   c = getch ();
3525
3526   /* Effectively do c = skip_white_space (c)
3527      but do it faster in the usual cases.  */
3528   while (1)
3529     switch (c)
3530       {
3531       case ' ':
3532       case '\t':
3533       case '\f':
3534       case '\v':
3535       case '\b':
3536 #if USE_CPPLIB
3537         if (cpp_token == CPP_HSPACE)
3538           c = yy_get_token ();
3539         else
3540 #endif
3541           c = getch ();
3542         break;
3543
3544       case '\r':
3545         /* Call skip_white_space so we can warn if appropriate.  */
3546
3547       case '\n':
3548       case '/':
3549       case '\\':
3550         c = skip_white_space (c);
3551       default:
3552         goto found_nonwhite;
3553       }
3554  found_nonwhite:
3555
3556   token_buffer[0] = c;
3557   token_buffer[1] = 0;
3558
3559 /*  yylloc.first_line = lineno; */
3560
3561   switch (c)
3562     {
3563     case EOF:
3564       end_of_file = 1;
3565       token_buffer[0] = 0;
3566       if (linemode)
3567         value = END_OF_LINE;
3568       else if (input_redirected ())
3569         value = END_OF_SAVED_INPUT;
3570       else
3571         value = ENDFILE;
3572       break;
3573
3574     case 'L':
3575 #if USE_CPPLIB
3576       if (cpp_token == CPP_NAME)
3577         goto letter;
3578 #endif
3579       /* Capital L may start a wide-string or wide-character constant.  */
3580       {
3581         register int c = token_getch ();
3582         if (c == '\'')
3583           {
3584             wide_flag = 1;
3585             goto char_constant;
3586           }
3587         if (c == '"')
3588           {
3589             wide_flag = 1;
3590             goto string_constant;
3591           }
3592         token_put_back (c);
3593       }
3594       
3595     case 'A':  case 'B':  case 'C':  case 'D':  case 'E':
3596     case 'F':  case 'G':  case 'H':  case 'I':  case 'J':
3597     case 'K':             case 'M':  case 'N':  case 'O':
3598     case 'P':  case 'Q':  case 'R':  case 'S':  case 'T':
3599     case 'U':  case 'V':  case 'W':  case 'X':  case 'Y':
3600     case 'Z':
3601     case 'a':  case 'b':  case 'c':  case 'd':  case 'e':
3602     case 'f':  case 'g':  case 'h':  case 'i':  case 'j':
3603     case 'k':  case 'l':  case 'm':  case 'n':  case 'o':
3604     case 'p':  case 'q':  case 'r':  case 's':  case 't':
3605     case 'u':  case 'v':  case 'w':  case 'x':  case 'y':
3606     case 'z':
3607     case '_':
3608     case '$':
3609     letter:
3610 #if USE_CPPLIB
3611       if (cpp_token == CPP_NAME)
3612         {
3613           /* Note that one character has already been read from
3614              yy_cur into token_buffer.  Also, cpplib complains about
3615              $ in identifiers, so we don't have to.  */
3616
3617           int len = yy_lim - yy_cur + 1;
3618           if (len >= maxtoken)
3619             extend_token_buffer_to (len + 1);
3620           memcpy (token_buffer + 1, yy_cur, len);
3621           p = token_buffer + len;
3622           yy_cur = yy_lim;
3623         }
3624       else
3625 #endif
3626         {
3627           p = token_buffer;
3628           while (ISALNUM (c) || (c == '_') || c == '$')
3629             {
3630               /* Make sure this char really belongs in an identifier.  */
3631               if (c == '$')
3632                 {
3633                   if (! dollars_in_ident)
3634                     error ("`$' in identifier");
3635                   else if (pedantic)
3636                     pedwarn ("`$' in identifier");
3637                 }
3638
3639               if (p >= token_buffer + maxtoken)
3640                 p = extend_token_buffer (p);
3641
3642               *p++ = c;
3643               c = token_getch ();
3644             }
3645
3646           *p = 0;
3647           token_put_back (c);
3648         }
3649
3650       value = IDENTIFIER;
3651       yylval.itype = 0;
3652
3653       /* Try to recognize a keyword.  Uses minimum-perfect hash function */
3654
3655       {
3656         register struct resword *ptr;
3657
3658         if ((ptr = is_reserved_word (token_buffer, p - token_buffer)))
3659           {
3660             if (ptr->rid)
3661               {
3662                 if (ptr->token == VISSPEC)
3663                   {
3664                     switch (ptr->rid)
3665                       {
3666                       case RID_PUBLIC:
3667                         yylval.ttype = access_public_node;
3668                         break;
3669                       case RID_PRIVATE:
3670                         yylval.ttype = access_private_node;
3671                         break;
3672                       case RID_PROTECTED:
3673                         yylval.ttype = access_protected_node;
3674                         break;
3675                       default:
3676                         my_friendly_abort (63);
3677                       }
3678                   }
3679                 else
3680                   yylval.ttype = ridpointers[(int) ptr->rid];
3681               }
3682             else switch (ptr->token)
3683               {
3684               case EQCOMPARE:
3685                 yylval.code = NE_EXPR;
3686                 token_buffer[0] = '!';
3687                 token_buffer[1] = '=';
3688                 token_buffer[2] = 0;
3689                 break;
3690
3691               case ASSIGN:
3692                 if (strcmp ("and_eq", token_buffer) == 0)
3693                   {
3694                     yylval.code = BIT_AND_EXPR;
3695                     token_buffer[0] = '&';
3696                   }
3697                 else if (strcmp ("or_eq", token_buffer) == 0)
3698                   {
3699                     yylval.code = BIT_IOR_EXPR;
3700                     token_buffer[0] = '|';
3701                   }
3702                 else if (strcmp ("xor_eq", token_buffer) == 0)
3703                   {
3704                     yylval.code = BIT_XOR_EXPR;
3705                     token_buffer[0] = '^';
3706                   }
3707                 token_buffer[1] = '=';
3708                 token_buffer[2] = 0;
3709                 break;
3710
3711               case '&':
3712                 yylval.code = BIT_AND_EXPR;
3713                 token_buffer[0] = '&';
3714                 token_buffer[1] = 0;
3715                 break;
3716
3717               case '|':
3718                 yylval.code = BIT_IOR_EXPR;
3719                 token_buffer[0] = '|';
3720                 token_buffer[1] = 0;
3721                 break;
3722
3723               case '^':
3724                 yylval.code = BIT_XOR_EXPR;
3725                 token_buffer[0] = '^';
3726                 token_buffer[1] = 0;
3727                 break;
3728               }
3729
3730             value = (int) ptr->token;
3731           }
3732       }
3733
3734       /* If we did not find a keyword, look for an identifier
3735          (or a typename).  */
3736
3737       if (value == IDENTIFIER || value == TYPESPEC)
3738         GNU_xref_ref (current_function_decl, token_buffer);
3739
3740       if (value == IDENTIFIER)
3741         {
3742           register tree tmp = get_identifier (token_buffer);
3743
3744 #if !defined(VMS) && defined(JOINER)
3745           /* Make sure that user does not collide with our internal
3746              naming scheme.  */
3747           if (JOINER == '$'
3748               && (THIS_NAME_P (tmp)
3749                   || VPTR_NAME_P (tmp)
3750                   || DESTRUCTOR_NAME_P (tmp)
3751                   || VTABLE_NAME_P (tmp)
3752                   || TEMP_NAME_P (tmp)
3753                   || ANON_AGGRNAME_P (tmp)
3754                   || ANON_PARMNAME_P (tmp)))
3755             warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy",
3756                      token_buffer);
3757 #endif
3758
3759           yylval.ttype = tmp;
3760         }
3761       if (value == NEW && ! global_bindings_p ())
3762         {
3763           value = NEW;
3764           goto done;
3765         }
3766       break;
3767
3768     case '.':
3769 #if USE_CPPLIB
3770       if (yy_cur < yy_lim)
3771 #endif
3772         {
3773           /* It's hard to preserve tokenization on '.' because
3774              it could be a symbol by itself, or it could be the
3775              start of a floating point number and cpp won't tell us.  */
3776           register int c1 = token_getch ();
3777           token_buffer[1] = c1;
3778           if (c1 == '*')
3779             {
3780               value = DOT_STAR;
3781               token_buffer[2] = 0;
3782               goto done;
3783             }
3784           if (c1 == '.')
3785             {
3786               c1 = token_getch ();
3787               if (c1 == '.')
3788                 {
3789                   token_buffer[2] = c1;
3790                   token_buffer[3] = 0;
3791                   value = ELLIPSIS;
3792                   goto done;
3793                 }
3794               error ("parse error at `..'");
3795             }
3796           if (ISDIGIT (c1))
3797             {
3798               token_put_back (c1);
3799               goto number;
3800             }
3801           token_put_back (c1);
3802         }
3803       value = '.';
3804       token_buffer[1] = 0;
3805       break;
3806
3807     case '0':  case '1':
3808       /* Optimize for most frequent case.  */
3809       {
3810         register int cond;
3811
3812 #if USE_CPPLIB
3813         cond = (yy_cur == yy_lim);
3814 #else
3815         register int c1 = token_getch ();
3816         token_put_back (c1);
3817         cond = (! ISALNUM (c1) && c1 != '.');
3818 #endif
3819         if (cond)
3820           {
3821             yylval.ttype = (c == '0') ? integer_zero_node : integer_one_node;
3822             value = CONSTANT;
3823             break;
3824           }
3825         /*FALLTHRU*/
3826       }
3827     case '2':  case '3':  case '4':
3828     case '5':  case '6':  case '7':  case '8':  case '9':
3829     number:
3830       {
3831         int base = 10;
3832         int count = 0;
3833         int largest_digit = 0;
3834         int numdigits = 0;
3835         int overflow = 0;
3836
3837         /* We actually store only HOST_BITS_PER_CHAR bits in each part.
3838            The code below which fills the parts array assumes that a host
3839            int is at least twice as wide as a host char, and that 
3840            HOST_BITS_PER_WIDE_INT is an even multiple of HOST_BITS_PER_CHAR.
3841            Two HOST_WIDE_INTs is the largest int literal we can store.
3842            In order to detect overflow below, the number of parts (TOTAL_PARTS)
3843            must be exactly the number of parts needed to hold the bits
3844            of two HOST_WIDE_INTs. */
3845 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2)
3846         unsigned int parts[TOTAL_PARTS];
3847
3848         enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS, AFTER_EXPON }
3849           floatflag = NOT_FLOAT;
3850
3851         for (count = 0; count < TOTAL_PARTS; count++)
3852           parts[count] = 0;
3853
3854         p = token_buffer;
3855         *p++ = c;
3856
3857         if (c == '0')
3858           {
3859             *p++ = (c = token_getch ());
3860             if ((c == 'x') || (c == 'X'))
3861               {
3862                 base = 16;
3863                 *p++ = (c = token_getch ());
3864               }
3865             /* Leading 0 forces octal unless the 0 is the only digit.  */
3866             else if (c >= '0' && c <= '9')
3867               {
3868                 base = 8;
3869                 numdigits++;
3870               }
3871             else
3872               numdigits++;
3873           }
3874
3875         /* Read all the digits-and-decimal-points.  */
3876
3877         while (c == '.'
3878                || (ISALNUM (c) && c != 'l' && c != 'L'
3879                    && c != 'u' && c != 'U'
3880                    && c != 'i' && c != 'I' && c != 'j' && c != 'J'
3881                    && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
3882           {
3883             if (c == '.')
3884               {
3885                 if (base == 16 && pedantic)
3886                   pedwarn ("floating constant may not be in radix 16");
3887                 if (floatflag == TOO_MANY_POINTS)
3888                   /* We have already emitted an error.  Don't need another.  */
3889                   ;
3890                 else if (floatflag == AFTER_POINT || floatflag == AFTER_EXPON)
3891                   {
3892                     error ("malformed floating constant");
3893                     floatflag = TOO_MANY_POINTS;
3894                     /* Avoid another error from atof by forcing all characters
3895                        from here on to be ignored.  */
3896                     p[-1] = '\0';
3897                   }
3898                 else
3899                   floatflag = AFTER_POINT;
3900
3901                 if (base == 8)
3902                   base = 10;
3903                 *p++ = c = token_getch ();
3904                 /* Accept '.' as the start of a floating-point number
3905                    only when it is followed by a digit.  */
3906                 if (p == token_buffer + 2 && !ISDIGIT (c))
3907                   my_friendly_abort (990710);
3908               }
3909             else
3910               {
3911                 /* It is not a decimal point.
3912                    It should be a digit (perhaps a hex digit).  */
3913
3914                 if (ISDIGIT (c))
3915                   {
3916                     c = c - '0';
3917                   }
3918                 else if (base <= 10)
3919                   {
3920                     if (c == 'e' || c == 'E')
3921                       {
3922                         base = 10;
3923                         floatflag = AFTER_EXPON;
3924                         break;   /* start of exponent */
3925                       }
3926                     error ("nondigits in number and not hexadecimal");
3927                     c = 0;
3928                   }
3929                 else if (base == 16 && (c == 'p' || c == 'P'))
3930                   {
3931                     floatflag = AFTER_EXPON;
3932                     break;   /* start of exponent */
3933                   }
3934                 else if (c >= 'a')
3935                   {
3936                     c = c - 'a' + 10;
3937                   }
3938                 else
3939                   {
3940                     c = c - 'A' + 10;
3941                   }
3942                 if (c >= largest_digit)
3943                   largest_digit = c;
3944                 numdigits++;
3945
3946                 for (count = 0; count < TOTAL_PARTS; count++)
3947                   {
3948                     parts[count] *= base;
3949                     if (count)
3950                       {
3951                         parts[count]
3952                           += (parts[count-1] >> HOST_BITS_PER_CHAR);
3953                         parts[count-1]
3954                           &= (1 << HOST_BITS_PER_CHAR) - 1;
3955                       }
3956                     else
3957                       parts[0] += c;
3958                   }
3959
3960                 /* If the highest-order part overflows (gets larger than
3961                    a host char will hold) then the whole number has 
3962                    overflowed.  Record this and truncate the highest-order
3963                    part. */
3964                 if (parts[TOTAL_PARTS - 1] >> HOST_BITS_PER_CHAR)
3965                   {
3966                     overflow = 1;
3967                     parts[TOTAL_PARTS - 1] &= (1 << HOST_BITS_PER_CHAR) - 1;
3968                   }
3969
3970                 if (p >= token_buffer + maxtoken - 3)
3971                   p = extend_token_buffer (p);
3972                 *p++ = (c = token_getch ());
3973               }
3974           }
3975
3976         /* This can happen on input like `int i = 0x;' */
3977         if (numdigits == 0)
3978           error ("numeric constant with no digits");
3979
3980         if (largest_digit >= base)
3981           error ("numeric constant contains digits beyond the radix");
3982
3983         /* Remove terminating char from the token buffer and delimit the
3984            string.  */
3985         *--p = 0;
3986
3987         if (floatflag != NOT_FLOAT)
3988           {
3989             tree type;
3990             int imag, conversion_errno;
3991             REAL_VALUE_TYPE value;
3992             struct pf_args args;
3993
3994             /* Read explicit exponent if any, and put it in tokenbuf.  */
3995
3996             if ((base == 10 && ((c == 'e') || (c == 'E')))
3997                 || (base == 16 && (c == 'p' || c == 'P')))
3998               {
3999                 if (p >= token_buffer + maxtoken - 3)
4000                   p = extend_token_buffer (p);
4001                 *p++ = c;
4002                 c = token_getch ();
4003                 if ((c == '+') || (c == '-'))
4004                   {
4005                     *p++ = c;
4006                     c = token_getch ();
4007                   }
4008                 /* Exponent is decimal, even if string is a hex float.  */
4009                 if (! ISDIGIT (c))
4010                   error ("floating constant exponent has no digits");
4011                 while (ISDIGIT (c))
4012                   {
4013                     if (p >= token_buffer + maxtoken - 3)
4014                       p = extend_token_buffer (p);
4015                     *p++ = c;
4016                     c = token_getch ();
4017                   }
4018               }
4019             if (base == 16 && floatflag != AFTER_EXPON)
4020               error ("hexadecimal floating constant has no exponent");
4021
4022             *p = 0;
4023
4024             /* Setup input for parse_float() */
4025             args.base = base;
4026             args.p = p;
4027             args.c = c;
4028
4029             /* Convert string to a double, checking for overflow.  */
4030             if (do_float_handler (parse_float, (PTR) &args))
4031               {
4032                 /* Receive output from parse_float() */
4033                 value = args.value;
4034               }
4035             else
4036               {
4037                 /* We got an exception from parse_float() */
4038                 error ("floating constant out of range");
4039                 value = dconst0;
4040               }
4041
4042             /* Receive output from parse_float() */
4043             c = args.c;
4044             imag = args.imag;
4045             type = args.type;
4046             conversion_errno = args.conversion_errno;
4047             
4048 #ifdef ERANGE
4049             /* ERANGE is also reported for underflow,
4050                so test the value to distinguish overflow from that.  */
4051             if (conversion_errno == ERANGE && pedantic
4052                 && (REAL_VALUES_LESS (dconst1, value)
4053                     || REAL_VALUES_LESS (value, dconstm1)))
4054               warning ("floating point number exceeds range of `double'");
4055 #endif
4056
4057             /* If the result is not a number, assume it must have been
4058                due to some error message above, so silently convert
4059                it to a zero.  */
4060             if (REAL_VALUE_ISNAN (value))
4061               value = dconst0;
4062
4063             /* Create a node with determined type and value.  */
4064             if (imag)
4065               yylval.ttype = build_complex (NULL_TREE,
4066                                             convert (type, integer_zero_node),
4067                                             build_real (type, value));
4068             else
4069               yylval.ttype = build_real (type, value);
4070           }
4071         else
4072           {
4073             tree type;
4074             HOST_WIDE_INT high, low;
4075             int spec_unsigned = 0;
4076             int spec_long = 0;
4077             int spec_long_long = 0;
4078             int spec_imag = 0;
4079             int warn = 0;
4080             int i;
4081
4082             while (1)
4083               {
4084                 if (c == 'u' || c == 'U')
4085                   {
4086                     if (spec_unsigned)
4087                       error ("two `u's in integer constant");
4088                     spec_unsigned = 1;
4089                   }
4090                 else if (c == 'l' || c == 'L')
4091                   {
4092                     if (spec_long)
4093                       {
4094                         if (spec_long_long)
4095                           error ("three `l's in integer constant");
4096                         else if (pedantic && ! in_system_header && warn_long_long)
4097                           pedwarn ("ANSI C++ forbids long long integer constants");
4098                         spec_long_long = 1;
4099                       }
4100                     spec_long = 1;
4101                   }
4102                 else if (c == 'i' || c == 'j' || c == 'I' || c == 'J')
4103                   {
4104                     if (spec_imag)
4105                       error ("more than one `i' or `j' in numeric constant");
4106                     else if (pedantic)
4107                       pedwarn ("ANSI C++ forbids imaginary numeric constants");
4108                     spec_imag = 1;
4109                   }
4110                 else
4111                   break;
4112                 if (p >= token_buffer + maxtoken - 3)
4113                   p = extend_token_buffer (p);
4114                 *p++ = c;
4115                 c = token_getch ();
4116               }
4117
4118             /* If the literal overflowed, pedwarn about it now. */
4119             if (overflow)
4120               {
4121                 warn = 1;
4122                 pedwarn ("integer constant is too large for this configuration of the compiler - truncated to %d bits", HOST_BITS_PER_WIDE_INT * 2);
4123               }
4124
4125             /* This is simplified by the fact that our constant
4126                is always positive.  */
4127
4128             high = low = 0;
4129
4130             for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
4131               {
4132                 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
4133                                                     / HOST_BITS_PER_CHAR)]
4134                          << (i * HOST_BITS_PER_CHAR));
4135                 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
4136               }
4137
4138             yylval.ttype = build_int_2 (low, high);
4139             TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
4140
4141             /* Calculate the ANSI type.  */
4142             if (! spec_long && ! spec_unsigned
4143                 && int_fits_type_p (yylval.ttype, integer_type_node))
4144               type = integer_type_node;
4145             else if (! spec_long && (base != 10 || spec_unsigned)
4146                      && int_fits_type_p (yylval.ttype, unsigned_type_node))
4147               type = unsigned_type_node;
4148             else if (! spec_unsigned && !spec_long_long
4149                      && int_fits_type_p (yylval.ttype, long_integer_type_node))
4150               type = long_integer_type_node;
4151             else if (! spec_long_long
4152                      && int_fits_type_p (yylval.ttype,
4153                                          long_unsigned_type_node))
4154               type = long_unsigned_type_node;
4155             else if (! spec_unsigned
4156                      && int_fits_type_p (yylval.ttype,
4157                                          long_long_integer_type_node))
4158               type = long_long_integer_type_node;
4159             else if (int_fits_type_p (yylval.ttype,
4160                                       long_long_unsigned_type_node))
4161               type = long_long_unsigned_type_node;
4162             else if (! spec_unsigned
4163                      && int_fits_type_p (yylval.ttype,
4164                                          widest_integer_literal_type_node))
4165               type = widest_integer_literal_type_node;
4166             else
4167               type = widest_unsigned_literal_type_node;
4168
4169             if (pedantic && !spec_long_long && !warn
4170                 && (TYPE_PRECISION (long_integer_type_node)
4171                     < TYPE_PRECISION (type)))
4172               {
4173                 warn = 1;
4174                 pedwarn ("integer constant larger than the maximum value of an unsigned long int");
4175               }
4176
4177             if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
4178               warning ("decimal constant is so large that it is unsigned");
4179
4180             if (spec_imag)
4181               {
4182                 if (TYPE_PRECISION (type)
4183                     <= TYPE_PRECISION (integer_type_node))
4184                   yylval.ttype
4185                     = build_complex (NULL_TREE, integer_zero_node,
4186                                      convert (integer_type_node,
4187                                               yylval.ttype));
4188                 else
4189                   error ("complex integer constant is too wide for `__complex int'");
4190               }
4191             else
4192               TREE_TYPE (yylval.ttype) = type;
4193
4194
4195             /* If it's still an integer (not a complex), and it doesn't
4196                fit in the type we choose for it, then pedwarn. */
4197
4198             if (! warn
4199                 && TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE
4200                 && ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype)))
4201               pedwarn ("integer constant is larger than the maximum value for its type");
4202           }
4203
4204         token_put_back (c);
4205         *p = 0;
4206
4207         if (ISALNUM (c) || c == '.' || c == '_' || c == '$'
4208             || ((c == '-' || c == '+')
4209                 && (p[-1] == 'e' || p[-1] == 'E')))
4210           error ("missing white space after number `%s'", token_buffer);
4211
4212         value = CONSTANT; break;
4213       }
4214
4215     case '\'':
4216     char_constant:
4217       {
4218         register int result = 0;
4219         register int num_chars = 0;
4220         int chars_seen = 0;
4221         unsigned width = TYPE_PRECISION (char_type_node);
4222         int max_chars;
4223 #ifdef MULTIBYTE_CHARS
4224         int longest_char = local_mb_cur_max ();
4225         local_mbtowc (NULL_PTR, NULL_PTR, 0);
4226 #endif
4227
4228         max_chars = TYPE_PRECISION (integer_type_node) / width;
4229         if (wide_flag)
4230           width = WCHAR_TYPE_SIZE;
4231
4232         while (1)
4233           {
4234           tryagain:
4235             c = token_getch ();
4236
4237             if (c == '\'' || c == EOF)
4238               break;
4239
4240             ++chars_seen;
4241             if (c == '\\')
4242               {
4243                 int ignore = 0;
4244                 c = readescape (&ignore);
4245                 if (ignore)
4246                   goto tryagain;
4247                 if (width < HOST_BITS_PER_INT
4248                     && (unsigned) c >= ((unsigned)1 << width))
4249                   pedwarn ("escape sequence out of range for character");
4250 #ifdef MAP_CHARACTER
4251                 if (ISPRINT (c))
4252                   c = MAP_CHARACTER (c);
4253 #endif
4254               }
4255             else if (c == '\n')
4256               {
4257                 if (pedantic)
4258                   pedwarn ("ANSI C forbids newline in character constant");
4259                 lineno++;
4260               }
4261             else
4262               {
4263 #ifdef MULTIBYTE_CHARS
4264                 wchar_t wc;
4265                 int i;
4266                 int char_len = -1;
4267                 for (i = 1; i <= longest_char; ++i)
4268                   {
4269                     if (i > maxtoken - 4)
4270                       extend_token_buffer (token_buffer);
4271
4272                     token_buffer[i] = c;
4273                     char_len = local_mbtowc (& wc,
4274                                              token_buffer + 1,
4275                                              i);
4276                     if (char_len != -1)
4277                       break;
4278                     c = token_getch ();
4279                   }
4280                 if (char_len > 1)
4281                   {
4282                     /* mbtowc sometimes needs an extra char before accepting */
4283                     if (char_len < i)
4284                       token_put_back (c);
4285                     if (! wide_flag)
4286                       {
4287                         /* Merge character into result; ignore excess chars.  */
4288                         for (i = 1; i <= char_len; ++i)
4289                           {
4290                             if (i > max_chars)
4291                               break;
4292                             if (width < HOST_BITS_PER_INT)
4293                               result = (result << width)
4294                                 | (token_buffer[i]
4295                                    & ((1 << width) - 1));
4296                             else
4297                               result = token_buffer[i];
4298                           }
4299                         num_chars += char_len;
4300                         goto tryagain;
4301                       }
4302                     c = wc;
4303                   }
4304                 else
4305                   {
4306                     if (char_len == -1)
4307                       {
4308                         warning ("Ignoring invalid multibyte character");
4309                         /* Replace all but the first byte.  */
4310                         for (--i; i > 1; --i)
4311                           token_put_back (token_buffer[i]);
4312                         wc = token_buffer[1];
4313                       }
4314 #ifdef MAP_CHARACTER
4315                       c = MAP_CHARACTER (wc);
4316 #else
4317                       c = wc;
4318 #endif
4319                   }
4320 #else /* ! MULTIBYTE_CHARS */
4321 #ifdef MAP_CHARACTER
4322                 c = MAP_CHARACTER (c);
4323 #endif
4324 #endif /* ! MULTIBYTE_CHARS */
4325               }
4326
4327             if (wide_flag)
4328               {
4329                 if (chars_seen == 1) /* only keep the first one */
4330                   result = c;
4331                 goto tryagain;
4332               }
4333
4334             /* Merge character into result; ignore excess chars.  */
4335             num_chars += (width / TYPE_PRECISION (char_type_node));
4336             if (num_chars < max_chars + 1)
4337               {
4338                 if (width < HOST_BITS_PER_INT)
4339                   result = (result << width) | (c & ((1 << width) - 1));
4340                 else
4341                   result = c;
4342               }
4343           }
4344
4345         if (c != '\'')
4346           error ("malformatted character constant");
4347         else if (chars_seen == 0)
4348           error ("empty character constant");
4349         else if (num_chars > max_chars)
4350           {
4351             num_chars = max_chars;
4352             error ("character constant too long");
4353           }
4354         else if (chars_seen != 1 && warn_multichar)
4355           warning ("multi-character character constant");
4356
4357         /* If char type is signed, sign-extend the constant.  */
4358         if (! wide_flag)
4359           {
4360             int num_bits = num_chars * width;
4361             if (num_bits == 0)
4362               /* We already got an error; avoid invalid shift.  */
4363               yylval.ttype = build_int_2 (0, 0);
4364             else if (TREE_UNSIGNED (char_type_node)
4365                      || ((result >> (num_bits - 1)) & 1) == 0)
4366               yylval.ttype
4367                 = build_int_2 (result & (~(unsigned HOST_WIDE_INT) 0
4368                                          >> (HOST_BITS_PER_WIDE_INT - num_bits)),
4369                                0);
4370             else
4371               yylval.ttype
4372                 = build_int_2 (result | ~(~(unsigned HOST_WIDE_INT) 0
4373                                           >> (HOST_BITS_PER_WIDE_INT - num_bits)),
4374                                -1);
4375             /* In C, a character constant has type 'int'; in C++, 'char'.  */
4376             if (chars_seen <= 1)
4377               TREE_TYPE (yylval.ttype) = char_type_node;
4378             else
4379               TREE_TYPE (yylval.ttype) = integer_type_node;
4380           }
4381         else
4382           {
4383             yylval.ttype = build_int_2 (result, 0);
4384             TREE_TYPE (yylval.ttype) = wchar_type_node;
4385           }
4386
4387         value = CONSTANT;
4388         break;
4389       }
4390
4391     case '"':
4392     string_constant:
4393       {
4394         unsigned width = wide_flag ? WCHAR_TYPE_SIZE
4395                                    : TYPE_PRECISION (char_type_node);
4396 #ifdef MULTIBYTE_CHARS
4397         int longest_char = local_mb_cur_max ();
4398         local_mbtowc (NULL_PTR, NULL_PTR, 0);
4399 #endif
4400
4401         c = token_getch ();
4402         p = token_buffer + 1;
4403
4404         while (c != '"' && c != EOF)
4405           {
4406             /* ignore_escape_flag is set for reading the filename in #line.  */
4407             if (!ignore_escape_flag && c == '\\')
4408               {
4409                 int ignore = 0;
4410                 c = readescape (&ignore);
4411                 if (ignore)
4412                   goto skipnewline;
4413                 if (width < HOST_BITS_PER_INT
4414                     && (unsigned) c >= ((unsigned)1 << width))
4415                   pedwarn ("escape sequence out of range for character");
4416               }
4417             else if (c == '\n')
4418               {
4419                 if (pedantic)
4420                   pedwarn ("ANSI C++ forbids newline in string constant");
4421                 lineno++;
4422               }
4423             else
4424               {
4425 #ifdef MULTIBYTE_CHARS
4426                 wchar_t wc;
4427                 int i;
4428                 int char_len = -1;
4429                 for (i = 0; i < longest_char; ++i)
4430                   {
4431                     if (p + i >= token_buffer + maxtoken)
4432                       p = extend_token_buffer (p);
4433                     p[i] = c;
4434
4435                     char_len = local_mbtowc (& wc, p, i + 1);
4436                     if (char_len != -1)
4437                       break;
4438                     c = token_getch ();
4439                   }
4440                 if (char_len == -1)
4441                   {
4442                     warning ("Ignoring invalid multibyte character");
4443                     /* Replace all except the first byte.  */
4444                     token_put_back (c);
4445                     for (--i; i > 0; --i)
4446                       token_put_back (p[i]);
4447                     char_len = 1;
4448                   }
4449                 /* mbtowc sometimes needs an extra char before accepting */
4450                 if (char_len <= i)
4451                   token_put_back (c);
4452                 if (! wide_flag)
4453                   {
4454                     p += (i + 1);
4455                     c = token_getch ();
4456                     continue;
4457                   }
4458                 c = wc;
4459 #endif /* MULTIBYTE_CHARS */
4460               }
4461
4462             /* Add this single character into the buffer either as a wchar_t
4463                or as a single byte.  */
4464             if (wide_flag)
4465               {
4466                 unsigned width = TYPE_PRECISION (char_type_node);
4467                 unsigned bytemask = (1 << width) - 1;
4468                 int byte;
4469
4470                 if (p + WCHAR_BYTES > token_buffer + maxtoken)
4471                   p = extend_token_buffer (p);
4472
4473                 for (byte = 0; byte < WCHAR_BYTES; ++byte)
4474                   {
4475                     int value;
4476                     if (byte >= (int) sizeof (c))
4477                       value = 0;
4478                     else
4479                       value = (c >> (byte * width)) & bytemask;
4480                     if (BYTES_BIG_ENDIAN)
4481                       p[WCHAR_BYTES - byte - 1] = value;
4482                     else
4483                       p[byte] = value;
4484                   }
4485                 p += WCHAR_BYTES;
4486               }
4487             else
4488               {
4489                 if (p >= token_buffer + maxtoken)
4490                   p = extend_token_buffer (p);
4491                 *p++ = c;
4492               }
4493
4494           skipnewline:
4495             c = token_getch ();
4496           }
4497
4498         /* Terminate the string value, either with a single byte zero
4499            or with a wide zero.  */
4500         if (wide_flag)
4501           {
4502             if (p + WCHAR_BYTES > token_buffer + maxtoken)
4503               p = extend_token_buffer (p);
4504             bzero (p, WCHAR_BYTES);
4505             p += WCHAR_BYTES;
4506           }
4507         else
4508           {
4509             if (p >= token_buffer + maxtoken)
4510               p = extend_token_buffer (p);
4511             *p++ = 0;
4512           }
4513
4514         if (c == EOF)
4515           error ("Unterminated string constant");
4516
4517         /* We have read the entire constant.
4518            Construct a STRING_CST for the result.  */
4519
4520         if (processing_template_decl)
4521           push_obstacks (&permanent_obstack, &permanent_obstack);
4522         yylval.ttype = build_string (p - (token_buffer + 1), token_buffer + 1);
4523         if (processing_template_decl)
4524           pop_obstacks ();
4525
4526         if (wide_flag)
4527           TREE_TYPE (yylval.ttype) = wchar_array_type_node;
4528         else
4529           TREE_TYPE (yylval.ttype) = char_array_type_node;
4530
4531         value = STRING; break;
4532       }
4533
4534     case '+':
4535     case '-':
4536     case '&':
4537     case '|':
4538     case ':':
4539     case '<':
4540     case '>':
4541     case '*':
4542     case '/':
4543     case '%':
4544     case '^':
4545     case '!':
4546     case '=':
4547       {
4548         register int c1;
4549
4550       combine:
4551
4552         switch (c)
4553           {
4554           case '+':
4555             yylval.code = PLUS_EXPR; break;
4556           case '-':
4557             yylval.code = MINUS_EXPR; break;
4558           case '&':
4559             yylval.code = BIT_AND_EXPR; break;
4560           case '|':
4561             yylval.code = BIT_IOR_EXPR; break;
4562           case '*':
4563             yylval.code = MULT_EXPR; break;
4564           case '/':
4565             yylval.code = TRUNC_DIV_EXPR; break;
4566           case '%':
4567             yylval.code = TRUNC_MOD_EXPR; break;
4568           case '^':
4569             yylval.code = BIT_XOR_EXPR; break;
4570           case LSHIFT:
4571             yylval.code = LSHIFT_EXPR; break;
4572           case RSHIFT:
4573             yylval.code = RSHIFT_EXPR; break;
4574           case '<':
4575             yylval.code = LT_EXPR; break;
4576           case '>':
4577             yylval.code = GT_EXPR; break;
4578           }
4579
4580         token_buffer[1] = c1 = token_getch ();
4581         token_buffer[2] = 0;
4582
4583         if (c1 == '=')
4584           {
4585             switch (c)
4586               {
4587               case '<':
4588                 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
4589               case '>':
4590                 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
4591               case '!':
4592                 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
4593               case '=':
4594                 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
4595               }
4596             value = ASSIGN; goto done;
4597           }
4598         else if (c == c1)
4599           switch (c)
4600             {
4601             case '+':
4602               value = PLUSPLUS; goto done;
4603             case '-':
4604               value = MINUSMINUS; goto done;
4605             case '&':
4606               value = ANDAND; goto done;
4607             case '|':
4608               value = OROR; goto done;
4609             case '<':
4610               c = LSHIFT;
4611               goto combine;
4612             case '>':
4613               c = RSHIFT;
4614               goto combine;
4615             case ':':
4616               value = SCOPE;
4617               yylval.itype = 1;
4618               goto done;
4619             }
4620         else if (c1 == '?' && (c == '<' || c == '>'))
4621           {
4622             token_buffer[3] = 0;
4623
4624             c1 = token_getch ();
4625             yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR);
4626             if (c1 == '=')
4627               {
4628                 /* <?= or >?= expression.  */
4629                 token_buffer[2] = c1;
4630                 value = ASSIGN;
4631               }
4632             else
4633               {
4634                 value = MIN_MAX;
4635                 token_put_back (c1);
4636               }
4637             if (pedantic)
4638               pedwarn ("use of `operator %s' is not standard C++",
4639                        token_buffer);
4640             goto done;
4641           }
4642         else
4643           switch (c)
4644             {
4645             case '-':
4646               if (c1 == '>')
4647                 {
4648                   c1 = token_getch ();
4649                   if (c1 == '*')
4650                     value = POINTSAT_STAR;
4651                   else
4652                     {
4653                       token_put_back (c1);
4654                       value = POINTSAT;
4655                     }
4656                   goto done;
4657                 }
4658               break;
4659
4660               /* digraphs */
4661             case ':':
4662               if (c1 == '>')
4663                 { value = ']'; goto done; }
4664               break;
4665             case '<':
4666               if (c1 == '%')
4667                 { value = '{'; indent_level++; goto done; }
4668               if (c1 == ':')
4669                 { value = '['; goto done; }
4670               break;
4671             case '%':
4672               if (c1 == '>')
4673                 { value = '}'; indent_level--; goto done; }
4674               break;
4675             }
4676
4677         token_put_back (c1);
4678         token_buffer[1] = 0;
4679
4680         /* Here the C frontend changes < and > to ARITHCOMPARE.  We don't
4681            do that because of templates.  */
4682
4683         value = c;
4684         break;
4685       }
4686
4687     case 0:
4688       /* Don't make yyparse think this is eof.  */
4689       value = 1;
4690       break;
4691
4692     case '{':
4693       indent_level++;
4694       value = c;
4695       break;
4696
4697     case '}':
4698       indent_level--;
4699       value = c;
4700       break;
4701
4702     default:
4703       value = c;
4704     }
4705
4706 done:
4707 /*  yylloc.last_line = lineno; */
4708 #ifdef GATHER_STATISTICS
4709 #ifdef REDUCE_LENGTH
4710   token_count[value] += 1;
4711 #endif
4712 #endif
4713
4714   return value;
4715 }
4716
4717 int
4718 is_rid (t)
4719      tree t;
4720 {
4721   return !!is_reserved_word (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
4722 }
4723
4724 #ifdef GATHER_STATISTICS
4725 /* The original for tree_node_kind is in the toplevel tree.c; changes there
4726    need to be brought into here, unless this were actually put into a header
4727    instead.  */
4728 /* Statistics-gathering stuff.  */
4729 typedef enum
4730 {
4731   d_kind,
4732   t_kind,
4733   b_kind,
4734   s_kind,
4735   r_kind,
4736   e_kind,
4737   c_kind,
4738   id_kind,
4739   op_id_kind,
4740   perm_list_kind,
4741   temp_list_kind,
4742   vec_kind,
4743   x_kind,
4744   lang_decl,
4745   lang_type,
4746   all_kinds
4747 } tree_node_kind;
4748
4749 extern int tree_node_counts[];
4750 extern int tree_node_sizes[];
4751 #endif
4752
4753 /* Place to save freed lang_decls which were allocated on the
4754    permanent_obstack.  @@ Not currently used.  */
4755 tree free_lang_decl_chain;
4756
4757 tree
4758 build_lang_decl (code, name, type)
4759      enum tree_code code;
4760      tree name;
4761      tree type;
4762 {
4763   register tree t = build_decl (code, name, type);
4764   retrofit_lang_decl (t);
4765   return t;
4766 }
4767
4768 /* Add DECL_LANG_SPECIFIC info to T.  Called from build_lang_decl
4769    and pushdecl (for functions generated by the backend).  */
4770
4771 void
4772 retrofit_lang_decl (t)
4773      tree t;
4774 {
4775   struct obstack *obstack = current_obstack;
4776   register int i = sizeof (struct lang_decl) / sizeof (int);
4777   register int *pi;
4778
4779   if (! TREE_PERMANENT (t))
4780     obstack = saveable_obstack;
4781   else
4782     /* Could be that saveable is permanent and current is not.  */
4783     obstack = &permanent_obstack;
4784
4785   if (free_lang_decl_chain && obstack == &permanent_obstack)
4786     {
4787       pi = (int *)free_lang_decl_chain;
4788       free_lang_decl_chain = TREE_CHAIN (free_lang_decl_chain);
4789     }
4790   else
4791     pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl));
4792
4793   while (i > 0)
4794     pi[--i] = 0;
4795
4796   DECL_LANG_SPECIFIC (t) = (struct lang_decl *) pi;
4797   LANG_DECL_PERMANENT ((struct lang_decl *) pi)
4798     = obstack == &permanent_obstack;
4799   my_friendly_assert (LANG_DECL_PERMANENT ((struct lang_decl *) pi)
4800           == TREE_PERMANENT  (t), 234);
4801   DECL_MAIN_VARIANT (t) = t;
4802   if (current_lang_name == lang_name_cplusplus)
4803     DECL_LANGUAGE (t) = lang_cplusplus;
4804   else if (current_lang_name == lang_name_c)
4805     DECL_LANGUAGE (t) = lang_c;
4806   else if (current_lang_name == lang_name_java)
4807     DECL_LANGUAGE (t) = lang_java;
4808   else my_friendly_abort (64);
4809
4810 #if 0 /* not yet, should get fixed properly later */
4811   if (code == TYPE_DECL)
4812     {
4813       tree id;
4814       id = get_identifier (build_overload_name (type, 1, 1));
4815       DECL_ASSEMBLER_NAME (t) = id;
4816     }
4817
4818 #endif
4819 #ifdef GATHER_STATISTICS
4820   tree_node_counts[(int)lang_decl] += 1;
4821   tree_node_sizes[(int)lang_decl] += sizeof (struct lang_decl);
4822 #endif
4823 }
4824
4825 tree
4826 build_lang_field_decl (code, name, type)
4827      enum tree_code code;
4828      tree name;
4829      tree type;
4830 {
4831   extern struct obstack *current_obstack, *saveable_obstack;
4832   register tree t = build_decl (code, name, type);
4833   struct obstack *obstack = current_obstack;
4834   register int i = sizeof (struct lang_decl_flags) / sizeof (int);
4835   register int *pi;
4836 #if 0 /* not yet, should get fixed properly later */
4837
4838   if (code == TYPE_DECL)
4839     {
4840       tree id;
4841       id = get_identifier (build_overload_name (type, 1, 1));
4842       DECL_ASSEMBLER_NAME (t) = id;
4843     }
4844 #endif
4845
4846   if (! TREE_PERMANENT (t))
4847     obstack = saveable_obstack;
4848   else
4849     my_friendly_assert (obstack == &permanent_obstack, 235);
4850
4851   pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl_flags));
4852   while (i > 0)
4853     pi[--i] = 0;
4854
4855   DECL_LANG_SPECIFIC (t) = (struct lang_decl *) pi;
4856   return t;
4857 }
4858
4859 void
4860 copy_lang_decl (node)
4861      tree node;
4862 {
4863   int size;
4864   int *pi;
4865
4866   if (! DECL_LANG_SPECIFIC (node))
4867     return;
4868
4869   if (TREE_CODE (node) == FIELD_DECL)
4870     size = sizeof (struct lang_decl_flags);
4871   else
4872     size = sizeof (struct lang_decl);
4873   pi = (int *)obstack_alloc (&permanent_obstack, size);
4874   bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)pi, size);
4875   DECL_LANG_SPECIFIC (node) = (struct lang_decl *)pi;
4876 }
4877
4878 tree
4879 make_lang_type (code)
4880      enum tree_code code;
4881 {
4882   extern struct obstack *current_obstack, *saveable_obstack;
4883   register tree t = make_node (code);
4884
4885   /* Set up some flags that give proper default behavior.  */
4886   if (IS_AGGR_TYPE_CODE (code))
4887     {
4888       struct obstack *obstack = current_obstack;
4889       struct lang_type *pi;
4890
4891       SET_IS_AGGR_TYPE (t, 1);
4892
4893       if (! TREE_PERMANENT (t))
4894         obstack = saveable_obstack;
4895       else
4896         my_friendly_assert (obstack == &permanent_obstack, 236);
4897
4898       pi = (struct lang_type *) obstack_alloc (obstack, sizeof (struct lang_type));
4899       bzero ((char *) pi, (int) sizeof (struct lang_type));
4900
4901       TYPE_LANG_SPECIFIC (t) = pi;
4902       SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
4903       CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
4904
4905       /* Make sure this is laid out, for ease of use later.  In the
4906          presence of parse errors, the normal was of assuring this
4907          might not ever get executed, so we lay it out *immediately*.  */
4908       build_pointer_type (t);
4909
4910 #ifdef GATHER_STATISTICS
4911       tree_node_counts[(int)lang_type] += 1;
4912       tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
4913 #endif
4914     }
4915   else
4916     /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits.  But,
4917        TYPE_ALIAS_SET is initialized to -1 by default, so we must
4918        clear it here.  */
4919     TYPE_ALIAS_SET (t) = 0;
4920
4921   /* We need to allocate a TYPE_BINFO even for TEMPALTE_TYPE_PARMs
4922      since they can be virtual base types, and we then need a
4923      canonical binfo for them.  Ideally, this would be done lazily for
4924      all types.  */
4925   if (IS_AGGR_TYPE_CODE (code) || code == TEMPLATE_TYPE_PARM)
4926     TYPE_BINFO (t) = make_binfo (integer_zero_node, t, NULL_TREE, NULL_TREE);
4927
4928   return t;
4929 }
4930
4931 void
4932 dump_time_statistics ()
4933 {
4934   register tree prev = 0, decl, next;
4935   int this_time = my_get_run_time ();
4936   TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (this_filename_time))
4937     += this_time - body_time;
4938
4939   fprintf (stderr, "\n******\n");
4940   print_time ("header files (total)", header_time);
4941   print_time ("main file (total)", this_time - body_time);
4942   fprintf (stderr, "ratio = %g : 1\n",
4943            (double)header_time / (double)(this_time - body_time));
4944   fprintf (stderr, "\n******\n");
4945
4946   for (decl = filename_times; decl; decl = next)
4947     {
4948       next = IDENTIFIER_GLOBAL_VALUE (decl);
4949       SET_IDENTIFIER_GLOBAL_VALUE (decl, prev);
4950       prev = decl;
4951     }
4952
4953   for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl))
4954     print_time (IDENTIFIER_POINTER (decl),
4955                 TREE_INT_CST_LOW (TIME_IDENTIFIER_TIME (decl)));
4956 }
4957
4958 void
4959 compiler_error VPROTO ((const char *msg, ...))
4960 {
4961 #ifndef ANSI_PROTOTYPES
4962   const char *msg;
4963 #endif
4964   char buf[1024];
4965   va_list ap;
4966   
4967   VA_START (ap, msg);
4968   
4969 #ifndef ANSI_PROTOTYPES
4970   msg = va_arg (ap, const char *);
4971 #endif
4972
4973   vsprintf (buf, msg, ap);
4974   error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf);
4975 }
4976 \f
4977 /* Return the type-qualifier corresponding to the identifier given by
4978    RID.  */
4979
4980 int
4981 cp_type_qual_from_rid (rid)
4982      tree rid;
4983 {
4984   if (rid == ridpointers[(int) RID_CONST])
4985     return TYPE_QUAL_CONST;
4986   else if (rid == ridpointers[(int) RID_VOLATILE])
4987     return TYPE_QUAL_VOLATILE;
4988   else if (rid == ridpointers[(int) RID_RESTRICT])
4989     return TYPE_QUAL_RESTRICT;
4990
4991   my_friendly_abort (0);
4992   return TYPE_UNQUALIFIED;
4993 }