OSDN Git Service

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