OSDN Git Service

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