OSDN Git Service

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