OSDN Git Service

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