OSDN Git Service

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