OSDN Git Service

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