OSDN Git Service

86th Cygnus<->FSF quick merge
[pf3gnuchains/gcc-fork.git] / gcc / cp / lex.c
1 /* Separate lexical analyzer for GNU C++.
2    Copyright (C) 1987, 89, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3    Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 /* This file is the lexical analyzer for GNU C++.  */
24
25 /* Cause the `yydebug' variable to be defined.  */
26 #define YYDEBUG 1
27
28 #include <sys/types.h>
29 #include <stdio.h>
30 #include <errno.h>
31 #include <setjmp.h>
32 #include "config.h"
33 #include "input.h"
34 #include "tree.h"
35 #include "lex.h"
36 #include "parse.h"
37 #include "cp-tree.h"
38 #include "flags.h"
39 #include "obstack.h"
40 #include "c-pragma.h"
41
42 #ifdef MULTIBYTE_CHARS
43 #include <stdlib.h>
44 #include <locale.h>
45 #endif
46
47 #ifndef errno
48 extern int errno;               /* needed for VAX.  */
49 #endif
50
51 #define obstack_chunk_alloc xmalloc
52 #define obstack_chunk_free free
53
54 extern struct obstack permanent_obstack;
55 extern struct obstack *current_obstack, *saveable_obstack;
56
57 extern double atof ();
58
59 extern char *get_directive_line ();     /* In c-common.c */
60
61 /* Given a file name X, return the nondirectory portion.
62    Keep in mind that X can be computed more than once.  */
63 #ifndef FILE_NAME_NONDIRECTORY
64 #define FILE_NAME_NONDIRECTORY(X)               \
65  (rindex (X, '/') != 0 ? rindex (X, '/') + 1 : X)
66 #endif
67
68 extern char *index ();
69 extern char *rindex ();
70 void yyerror ();
71
72 /* This obstack is needed to hold text.  It is not safe to use
73    TOKEN_BUFFER because `check_newline' calls `yylex'.  */
74 struct obstack inline_text_obstack;
75
76 int end_of_file;
77
78 /* Pending language change.
79    Positive is push count, negative is pop count.  */
80 int pending_lang_change = 0;
81
82 /* Wrap the current header file in extern "C".  */
83 static int c_header_level = 0;
84
85 extern int first_token;
86 extern struct obstack token_obstack;
87
88 /* ??? Don't really know where this goes yet.  */
89 #if 1
90 #include "input.c"
91 #else
92 extern void put_back (/* int */);
93 extern int input_redirected ();
94 extern void feed_input (/* char *, int, struct obstack * */);
95 #endif
96
97 /* Holds translations from TREE_CODEs to operator name strings,
98    i.e., opname_tab[PLUS_EXPR] == "+".  */
99 char **opname_tab;
100 char **assignop_tab;
101 \f
102 extern int yychar;              /*  the lookahead symbol                */
103 extern YYSTYPE yylval;          /*  the semantic value of the           */
104                                 /*  lookahead symbol                    */
105
106 #if 0
107 YYLTYPE yylloc;                 /*  location data for the lookahead     */
108                                 /*  symbol                              */
109 #endif
110
111
112 /* the declaration found for the last IDENTIFIER token read in.
113    yylex must look this up to detect typedefs, which get token type TYPENAME,
114    so it is left around in case the identifier is not a typedef but is
115    used in a context which makes it a reference to a variable.  */
116 tree lastiddecl;
117
118 /* The elements of `ridpointers' are identifier nodes
119    for the reserved type names and storage classes.
120    It is indexed by a RID_... value.  */
121 tree ridpointers[(int) RID_MAX];
122
123 /* We may keep statistics about how long which files took to compile.  */
124 static int header_time, body_time;
125 static tree get_time_identifier ();
126 static tree filename_times;
127 static tree this_filename_time;
128
129 /* Array for holding counts of the numbers of tokens seen.  */
130 extern int *token_count;
131 \f
132 /* Return something to represent absolute declarators containing a *.
133    TARGET is the absolute declarator that the * contains.
134    TYPE_QUALS is a list of modifiers such as const or volatile
135    to apply to the pointer type, represented as identifiers.
136
137    We return an INDIRECT_REF whose "contents" are TARGET
138    and whose type is the modifier list.  */
139
140 tree
141 make_pointer_declarator (type_quals, target)
142      tree type_quals, target;
143 {
144   if (target && TREE_CODE (target) == IDENTIFIER_NODE
145       && ANON_AGGRNAME_P (target))
146     error ("type name expected before `*'");
147   target = build_parse_node (INDIRECT_REF, target);
148   TREE_TYPE (target) = type_quals;
149   return target;
150 }
151
152 /* Return something to represent absolute declarators containing a &.
153    TARGET is the absolute declarator that the & contains.
154    TYPE_QUALS is a list of modifiers such as const or volatile
155    to apply to the reference type, represented as identifiers.
156
157    We return an ADDR_EXPR whose "contents" are TARGET
158    and whose type is the modifier list.  */
159    
160 tree
161 make_reference_declarator (type_quals, target)
162      tree type_quals, target;
163 {
164   if (target)
165     {
166       if (TREE_CODE (target) == ADDR_EXPR)
167         {
168           error ("cannot declare references to references");
169           return target;
170         }
171       if (TREE_CODE (target) == INDIRECT_REF)
172         {
173           error ("cannot declare pointers to references");
174           return target;
175         }
176       if (TREE_CODE (target) == IDENTIFIER_NODE && ANON_AGGRNAME_P (target))
177           error ("type name expected before `&'");
178     }
179   target = build_parse_node (ADDR_EXPR, target);
180   TREE_TYPE (target) = type_quals;
181   return target;
182 }
183 \f
184 /* Build names and nodes for overloaded operators.  */
185
186 tree ansi_opname[LAST_CPLUS_TREE_CODE];
187 tree ansi_assopname[LAST_CPLUS_TREE_CODE];
188
189 char *
190 operator_name_string (name)
191      tree name;
192 {
193   char *opname = IDENTIFIER_POINTER (name) + 2;
194   tree *opname_table;
195   int i, assign;
196
197   /* Works for builtin and user defined types.  */
198   if (IDENTIFIER_GLOBAL_VALUE (name)
199       && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == TYPE_DECL)
200     return IDENTIFIER_POINTER (name);
201
202   if (opname[0] == 'a' && opname[2] != '\0' && opname[2] != '_')
203     {
204       opname += 1;
205       assign = 1;
206       opname_table = ansi_assopname;
207     }
208   else
209     {
210       assign = 0;
211       opname_table = ansi_opname;
212     }
213
214   for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
215     {
216       if (opname[0] == IDENTIFIER_POINTER (opname_table[i])[2+assign]
217           && opname[1] == IDENTIFIER_POINTER (opname_table[i])[3+assign])
218         break;
219     }
220
221   if (i == LAST_CPLUS_TREE_CODE)
222     return "<invalid operator>";
223
224   if (assign)
225     return assignop_tab[i];
226   else
227     return opname_tab[i];
228 }
229 \f
230 int interface_only;             /* whether or not current file is only for
231                                    interface definitions.  */
232 int interface_unknown;          /* whether or not we know this class
233                                    to behave according to #pragma interface.  */
234
235 /* lexical analyzer */
236
237 /* File used for outputting assembler code.  */
238 extern FILE *asm_out_file;
239
240 #ifndef WCHAR_TYPE_SIZE
241 #ifdef INT_TYPE_SIZE
242 #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
243 #else
244 #define WCHAR_TYPE_SIZE BITS_PER_WORD
245 #endif
246 #endif
247
248 /* Number of bytes in a wide character.  */
249 #define WCHAR_BYTES (WCHAR_TYPE_SIZE / BITS_PER_UNIT)
250
251 static int maxtoken;            /* Current nominal length of token buffer.  */
252 char *token_buffer;             /* Pointer to token buffer.
253                                    Actual allocated length is maxtoken + 2.  */
254
255 #include "hash.h"
256 \f
257 int check_newline ();
258
259 /* Nonzero tells yylex to ignore \ in string constants.  */
260 static int ignore_escape_flag = 0;
261
262 static int skip_white_space ();
263
264 static tree
265 get_time_identifier (name)
266      char *name;
267 {
268   tree time_identifier;
269   int len = strlen (name);
270   char *buf = (char *) alloca (len + 6);
271   strcpy (buf, "file ");
272   bcopy (name, buf+5, len);
273   buf[len+5] = '\0';
274   time_identifier = get_identifier (buf);
275   if (IDENTIFIER_LOCAL_VALUE (time_identifier) == NULL_TREE)
276     {
277       push_obstacks_nochange ();
278       end_temporary_allocation ();
279       IDENTIFIER_LOCAL_VALUE (time_identifier) = build_int_2 (0, 0);
280       IDENTIFIER_CLASS_VALUE (time_identifier) = build_int_2 (0, 1);
281       IDENTIFIER_GLOBAL_VALUE (time_identifier) = filename_times;
282       filename_times = time_identifier;
283       pop_obstacks ();
284     }
285   return time_identifier;
286 }
287
288 #ifdef __GNUC__
289 __inline
290 #endif
291 static int
292 my_get_run_time ()
293 {
294   int old_quiet_flag = quiet_flag;
295   int this_time;
296   quiet_flag = 0;
297   this_time = get_run_time ();
298   quiet_flag = old_quiet_flag;
299   return this_time;
300 }
301 \f
302 /* Table indexed by tree code giving a string containing a character
303    classifying the tree code.  Possibilities are
304    t, d, s, c, r, <, 1 and 2.  See cp/tree.def for details.  */
305
306 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
307
308 char *cplus_tree_code_type[] = {
309   "x",
310 #include "tree.def"
311 };
312 #undef DEFTREECODE
313
314 /* Table indexed by tree code giving number of expression
315    operands beyond the fixed part of the node structure.
316    Not used for types or decls.  */
317
318 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
319
320 int cplus_tree_code_length[] = {
321   0,
322 #include "tree.def"
323 };
324 #undef DEFTREECODE
325
326 /* Names of tree components.
327    Used for printing out the tree and error messages.  */
328 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
329
330 char *cplus_tree_code_name[] = {
331   "@@dummy",
332 #include "tree.def"
333 };
334 #undef DEFTREECODE
335 \f
336 /* toplev.c needs to call these.  */
337
338 void
339 lang_init ()
340 {
341   /* the beginning of the file is a new line; check for # */
342   /* With luck, we discover the real source file's name from that
343      and put it in input_filename.  */
344   put_back (check_newline ());
345   if (flag_gnu_xref) GNU_xref_begin (input_filename);
346   init_repo (input_filename);
347 }
348
349 void
350 lang_finish ()
351 {
352   extern int errorcount, sorrycount;
353   if (flag_gnu_xref) GNU_xref_end (errorcount+sorrycount);
354 }
355
356 char *
357 lang_identify ()
358 {
359   return "cplusplus";
360 }
361
362 void
363 init_filename_times ()
364 {
365   this_filename_time = get_time_identifier ("<top level>");
366   if (flag_detailed_statistics)
367     {
368       header_time = 0;
369       body_time = my_get_run_time ();
370       TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time)) = body_time;
371     }
372 }
373
374 /* Change by Bryan Boreham, Kewill, Thu Jul 27 09:46:05 1989.
375    Stuck this hack in to get the files open correctly; this is called
376    in place of init_lex if we are an unexec'd binary.    */
377 void
378 reinit_lang_specific ()
379 {
380   init_filename_times ();
381   reinit_search_statistics ();
382 }
383
384 int *init_parse ();
385
386 void
387 init_lex ()
388 {
389   extern char *(*decl_printable_name) ();
390   extern int flag_no_gnu_keywords;
391   extern int flag_operator_names;
392
393   int i;
394
395   /* Initialize the lookahead machinery.  */
396   init_spew ();
397
398   /* Make identifier nodes long enough for the language-specific slots.  */
399   set_identifier_size (sizeof (struct lang_identifier));
400   decl_printable_name = lang_printable_name;
401
402   init_cplus_expand ();
403
404   tree_code_type
405     = (char **) realloc (tree_code_type,
406                          sizeof (char *) * LAST_CPLUS_TREE_CODE);
407   tree_code_length
408     = (int *) realloc (tree_code_length,
409                        sizeof (int) * LAST_CPLUS_TREE_CODE);
410   tree_code_name
411     = (char **) realloc (tree_code_name,
412                          sizeof (char *) * LAST_CPLUS_TREE_CODE);
413   bcopy ((char *)cplus_tree_code_type,
414          (char *)(tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE),
415          (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
416   bcopy ((char *)cplus_tree_code_length,
417          (char *)(tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE),
418          (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (int));
419   bcopy ((char *)cplus_tree_code_name,
420          (char *)(tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE),
421          (LAST_CPLUS_TREE_CODE - (int)LAST_AND_UNUSED_TREE_CODE) * sizeof (char *));
422
423   opname_tab = (char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
424   bzero ((char *)opname_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
425   assignop_tab = (char **)oballoc ((int)LAST_CPLUS_TREE_CODE * sizeof (char *));
426   bzero ((char *)assignop_tab, (int)LAST_CPLUS_TREE_CODE * sizeof (char *));
427
428   ansi_opname[0] = get_identifier ("<invalid operator>");
429   for (i = 0; i < (int) LAST_CPLUS_TREE_CODE; i++)
430     {
431       ansi_opname[i] = ansi_opname[0];
432       ansi_assopname[i] = ansi_opname[0];
433     }
434
435   ansi_opname[(int) MULT_EXPR] = get_identifier ("__ml");
436   IDENTIFIER_OPNAME_P (ansi_opname[(int) MULT_EXPR]) = 1;
437   ansi_opname[(int) INDIRECT_REF] = ansi_opname[(int) MULT_EXPR];
438   ansi_assopname[(int) MULT_EXPR] = get_identifier ("__aml");
439   IDENTIFIER_OPNAME_P (ansi_assopname[(int) MULT_EXPR]) = 1;
440   ansi_assopname[(int) INDIRECT_REF] = ansi_assopname[(int) MULT_EXPR];
441   ansi_opname[(int) TRUNC_MOD_EXPR] = get_identifier ("__md");
442   IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUNC_MOD_EXPR]) = 1;
443   ansi_assopname[(int) TRUNC_MOD_EXPR] = get_identifier ("__amd");
444   IDENTIFIER_OPNAME_P (ansi_assopname[(int) TRUNC_MOD_EXPR]) = 1;
445   ansi_opname[(int) CEIL_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
446   ansi_opname[(int) FLOOR_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
447   ansi_opname[(int) ROUND_MOD_EXPR] = ansi_opname[(int) TRUNC_MOD_EXPR];
448   ansi_opname[(int) MINUS_EXPR] = get_identifier ("__mi");
449   IDENTIFIER_OPNAME_P (ansi_opname[(int) MINUS_EXPR]) = 1;
450   ansi_opname[(int) NEGATE_EXPR] = ansi_opname[(int) MINUS_EXPR];
451   ansi_assopname[(int) MINUS_EXPR] = get_identifier ("__ami");
452   IDENTIFIER_OPNAME_P (ansi_assopname[(int) MINUS_EXPR]) = 1;
453   ansi_assopname[(int) NEGATE_EXPR] = ansi_assopname[(int) MINUS_EXPR];
454   ansi_opname[(int) RSHIFT_EXPR] = get_identifier ("__rs");
455   IDENTIFIER_OPNAME_P (ansi_opname[(int) RSHIFT_EXPR]) = 1;
456   ansi_assopname[(int) RSHIFT_EXPR] = get_identifier ("__ars");
457   IDENTIFIER_OPNAME_P (ansi_assopname[(int) RSHIFT_EXPR]) = 1;
458   ansi_opname[(int) NE_EXPR] = get_identifier ("__ne");
459   IDENTIFIER_OPNAME_P (ansi_opname[(int) NE_EXPR]) = 1;
460   ansi_opname[(int) GT_EXPR] = get_identifier ("__gt");
461   IDENTIFIER_OPNAME_P (ansi_opname[(int) GT_EXPR]) = 1;
462   ansi_opname[(int) GE_EXPR] = get_identifier ("__ge");
463   IDENTIFIER_OPNAME_P (ansi_opname[(int) GE_EXPR]) = 1;
464   ansi_opname[(int) BIT_IOR_EXPR] = get_identifier ("__or");
465   IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_IOR_EXPR]) = 1;
466   ansi_assopname[(int) BIT_IOR_EXPR] = get_identifier ("__aor");
467   IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_IOR_EXPR]) = 1;
468   ansi_opname[(int) TRUTH_ANDIF_EXPR] = get_identifier ("__aa");
469   IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ANDIF_EXPR]) = 1;
470   ansi_opname[(int) TRUTH_NOT_EXPR] = get_identifier ("__nt");
471   IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_NOT_EXPR]) = 1;
472   ansi_opname[(int) PREINCREMENT_EXPR] = get_identifier ("__pp");
473   IDENTIFIER_OPNAME_P (ansi_opname[(int) PREINCREMENT_EXPR]) = 1;
474   ansi_opname[(int) POSTINCREMENT_EXPR] = ansi_opname[(int) PREINCREMENT_EXPR];
475   ansi_opname[(int) MODIFY_EXPR] = get_identifier ("__as");
476   IDENTIFIER_OPNAME_P (ansi_opname[(int) MODIFY_EXPR]) = 1;
477   ansi_assopname[(int) NOP_EXPR] = ansi_opname[(int) MODIFY_EXPR];
478   ansi_opname[(int) COMPOUND_EXPR] = get_identifier ("__cm");
479   IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPOUND_EXPR]) = 1;
480   ansi_opname[(int) EXACT_DIV_EXPR] = get_identifier ("__dv");
481   IDENTIFIER_OPNAME_P (ansi_opname[(int) EXACT_DIV_EXPR]) = 1;
482   ansi_assopname[(int) EXACT_DIV_EXPR] = get_identifier ("__adv");
483   IDENTIFIER_OPNAME_P (ansi_assopname[(int) EXACT_DIV_EXPR]) = 1;
484   ansi_opname[(int) TRUNC_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
485   ansi_opname[(int) CEIL_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
486   ansi_opname[(int) FLOOR_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
487   ansi_opname[(int) ROUND_DIV_EXPR] = ansi_opname[(int) EXACT_DIV_EXPR];
488   ansi_opname[(int) PLUS_EXPR] = get_identifier ("__pl");
489   ansi_assopname[(int) TRUNC_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
490   ansi_assopname[(int) CEIL_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
491   ansi_assopname[(int) FLOOR_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
492   ansi_assopname[(int) ROUND_DIV_EXPR] = ansi_assopname[(int) EXACT_DIV_EXPR];
493   IDENTIFIER_OPNAME_P (ansi_opname[(int) PLUS_EXPR]) = 1;
494   ansi_assopname[(int) PLUS_EXPR] = get_identifier ("__apl");
495   IDENTIFIER_OPNAME_P (ansi_assopname[(int) PLUS_EXPR]) = 1;
496   ansi_opname[(int) CONVERT_EXPR] = ansi_opname[(int) PLUS_EXPR];
497   ansi_assopname[(int) CONVERT_EXPR] = ansi_assopname[(int) PLUS_EXPR];
498   ansi_opname[(int) LSHIFT_EXPR] = get_identifier ("__ls");
499   IDENTIFIER_OPNAME_P (ansi_opname[(int) LSHIFT_EXPR]) = 1;
500   ansi_assopname[(int) LSHIFT_EXPR] = get_identifier ("__als");
501   IDENTIFIER_OPNAME_P (ansi_assopname[(int) LSHIFT_EXPR]) = 1;
502   ansi_opname[(int) EQ_EXPR] = get_identifier ("__eq");
503   IDENTIFIER_OPNAME_P (ansi_opname[(int) EQ_EXPR]) = 1;
504   ansi_opname[(int) LT_EXPR] = get_identifier ("__lt");
505   IDENTIFIER_OPNAME_P (ansi_opname[(int) LT_EXPR]) = 1;
506   ansi_opname[(int) LE_EXPR] = get_identifier ("__le");
507   IDENTIFIER_OPNAME_P (ansi_opname[(int) LE_EXPR]) = 1;
508   ansi_opname[(int) BIT_AND_EXPR] = get_identifier ("__ad");
509   IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_AND_EXPR]) = 1;
510   ansi_assopname[(int) BIT_AND_EXPR] = get_identifier ("__aad");
511   IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_AND_EXPR]) = 1;
512   ansi_opname[(int) ADDR_EXPR] = ansi_opname[(int) BIT_AND_EXPR];
513   ansi_assopname[(int) ADDR_EXPR] = ansi_assopname[(int) BIT_AND_EXPR];
514   ansi_opname[(int) BIT_XOR_EXPR] = get_identifier ("__er");
515   IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_XOR_EXPR]) = 1;
516   ansi_assopname[(int) BIT_XOR_EXPR] = get_identifier ("__aer");
517   IDENTIFIER_OPNAME_P (ansi_assopname[(int) BIT_XOR_EXPR]) = 1;
518   ansi_opname[(int) TRUTH_ORIF_EXPR] = get_identifier ("__oo");
519   IDENTIFIER_OPNAME_P (ansi_opname[(int) TRUTH_ORIF_EXPR]) = 1;
520   ansi_opname[(int) BIT_NOT_EXPR] = get_identifier ("__co");
521   IDENTIFIER_OPNAME_P (ansi_opname[(int) BIT_NOT_EXPR]) = 1;
522   ansi_opname[(int) PREDECREMENT_EXPR] = get_identifier ("__mm");
523   IDENTIFIER_OPNAME_P (ansi_opname[(int) PREDECREMENT_EXPR]) = 1;
524   ansi_opname[(int) POSTDECREMENT_EXPR] = ansi_opname[(int) PREDECREMENT_EXPR];
525   ansi_opname[(int) COMPONENT_REF] = get_identifier ("__rf");
526   IDENTIFIER_OPNAME_P (ansi_opname[(int) COMPONENT_REF]) = 1;
527   ansi_opname[(int) MEMBER_REF] = get_identifier ("__rm");
528   IDENTIFIER_OPNAME_P (ansi_opname[(int) MEMBER_REF]) = 1;
529   ansi_opname[(int) CALL_EXPR] = get_identifier ("__cl");
530   IDENTIFIER_OPNAME_P (ansi_opname[(int) CALL_EXPR]) = 1;
531   ansi_opname[(int) ARRAY_REF] = get_identifier ("__vc");
532   IDENTIFIER_OPNAME_P (ansi_opname[(int) ARRAY_REF]) = 1;
533   ansi_opname[(int) NEW_EXPR] = get_identifier ("__nw");
534   IDENTIFIER_OPNAME_P (ansi_opname[(int) NEW_EXPR]) = 1;
535   ansi_opname[(int) DELETE_EXPR] = get_identifier ("__dl");
536   IDENTIFIER_OPNAME_P (ansi_opname[(int) DELETE_EXPR]) = 1;
537   ansi_opname[(int) VEC_NEW_EXPR] = get_identifier ("__vn");
538   IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_NEW_EXPR]) = 1;
539   ansi_opname[(int) VEC_DELETE_EXPR] = get_identifier ("__vd");
540   IDENTIFIER_OPNAME_P (ansi_opname[(int) VEC_DELETE_EXPR]) = 1;
541   ansi_opname[(int) TYPE_EXPR] = get_identifier ("__op");
542   IDENTIFIER_OPNAME_P (ansi_opname[(int) TYPE_EXPR]) = 1;
543
544   /* This is not true: these operators are not defined in ANSI,
545      but we need them anyway.  */
546   ansi_opname[(int) MIN_EXPR] = get_identifier ("__mn");
547   IDENTIFIER_OPNAME_P (ansi_opname[(int) MIN_EXPR]) = 1;
548   ansi_opname[(int) MAX_EXPR] = get_identifier ("__mx");
549   IDENTIFIER_OPNAME_P (ansi_opname[(int) MAX_EXPR]) = 1;
550   ansi_opname[(int) COND_EXPR] = get_identifier ("__cn");
551   IDENTIFIER_OPNAME_P (ansi_opname[(int) COND_EXPR]) = 1;
552   ansi_opname[(int) METHOD_CALL_EXPR] = get_identifier ("__wr");
553   IDENTIFIER_OPNAME_P (ansi_opname[(int) METHOD_CALL_EXPR]) = 1;
554
555   init_method ();
556   init_error ();
557   gcc_obstack_init (&inline_text_obstack);
558
559   /* Start it at 0, because check_newline is called at the very beginning
560      and will increment it to 1.  */
561   lineno = 0;
562   input_filename = "<internal>";
563   current_function_decl = NULL;
564
565   maxtoken = 40;
566   token_buffer = (char *) xmalloc (maxtoken + 2);
567
568   ridpointers[(int) RID_INT] = get_identifier ("int");
569   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_INT],
570                           build_tree_list (NULL_TREE, ridpointers[(int) RID_INT]));
571   ridpointers[(int) RID_BOOL] = get_identifier ("bool");
572   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_BOOL],
573                           build_tree_list (NULL_TREE, ridpointers[(int) RID_BOOL]));
574   ridpointers[(int) RID_CHAR] = get_identifier ("char");
575   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_CHAR],
576                           build_tree_list (NULL_TREE, ridpointers[(int) RID_CHAR]));
577   ridpointers[(int) RID_VOID] = get_identifier ("void");
578   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VOID],
579                           build_tree_list (NULL_TREE, ridpointers[(int) RID_VOID]));
580   ridpointers[(int) RID_FLOAT] = get_identifier ("float");
581   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_FLOAT],
582                           build_tree_list (NULL_TREE, ridpointers[(int) RID_FLOAT]));
583   ridpointers[(int) RID_DOUBLE] = get_identifier ("double");
584   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_DOUBLE],
585                           build_tree_list (NULL_TREE, ridpointers[(int) RID_DOUBLE]));
586   ridpointers[(int) RID_SHORT] = get_identifier ("short");
587   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_SHORT],
588                           build_tree_list (NULL_TREE, ridpointers[(int) RID_SHORT]));
589   ridpointers[(int) RID_LONG] = get_identifier ("long");
590   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_LONG],
591                           build_tree_list (NULL_TREE, ridpointers[(int) RID_LONG]));
592   ridpointers[(int) RID_UNSIGNED] = get_identifier ("unsigned");
593   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_UNSIGNED],
594                           build_tree_list (NULL_TREE, ridpointers[(int) RID_UNSIGNED]));
595   ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
596   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_SIGNED],
597                           build_tree_list (NULL_TREE, ridpointers[(int) RID_SIGNED]));
598   ridpointers[(int) RID_INLINE] = get_identifier ("inline");
599   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_INLINE],
600                           build_tree_list (NULL_TREE, ridpointers[(int) RID_INLINE]));
601   ridpointers[(int) RID_CONST] = get_identifier ("const");
602   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_CONST],
603                           build_tree_list (NULL_TREE, ridpointers[(int) RID_CONST]));
604   ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
605   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VOLATILE],
606                           build_tree_list (NULL_TREE, ridpointers[(int) RID_VOLATILE]));
607   ridpointers[(int) RID_AUTO] = get_identifier ("auto");
608   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_AUTO],
609                           build_tree_list (NULL_TREE, ridpointers[(int) RID_AUTO]));
610   ridpointers[(int) RID_STATIC] = get_identifier ("static");
611   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_STATIC],
612                           build_tree_list (NULL_TREE, ridpointers[(int) RID_STATIC]));
613   ridpointers[(int) RID_EXTERN] = get_identifier ("extern");
614   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_EXTERN],
615                           build_tree_list (NULL_TREE, ridpointers[(int) RID_EXTERN]));
616   ridpointers[(int) RID_TYPEDEF] = get_identifier ("typedef");
617   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_TYPEDEF],
618                           build_tree_list (NULL_TREE, ridpointers[(int) RID_TYPEDEF]));
619   ridpointers[(int) RID_REGISTER] = get_identifier ("register");
620   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_REGISTER],
621                           build_tree_list (NULL_TREE, ridpointers[(int) RID_REGISTER]));
622
623   /* C++ extensions. These are probably not correctly named. */
624   ridpointers[(int) RID_WCHAR] = get_identifier ("__wchar_t");
625   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_WCHAR],
626                           build_tree_list (NULL_TREE, ridpointers[(int) RID_WCHAR]));
627   class_type_node = build_int_2 (class_type, 0);
628   TREE_TYPE (class_type_node) = class_type_node;
629   ridpointers[(int) RID_CLASS] = class_type_node;
630
631   record_type_node = build_int_2 (record_type, 0);
632   TREE_TYPE (record_type_node) = record_type_node;
633   ridpointers[(int) RID_RECORD] = record_type_node;
634
635   union_type_node = build_int_2 (union_type, 0);
636   TREE_TYPE (union_type_node) = union_type_node;
637   ridpointers[(int) RID_UNION] = union_type_node;
638
639   enum_type_node = build_int_2 (enum_type, 0);
640   TREE_TYPE (enum_type_node) = enum_type_node;
641   ridpointers[(int) RID_ENUM] = enum_type_node;
642
643   ridpointers[(int) RID_VIRTUAL] = get_identifier ("virtual");
644   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_VIRTUAL],
645                           build_tree_list (NULL_TREE, ridpointers[(int) RID_VIRTUAL]));
646   ridpointers[(int) RID_EXPLICIT] = get_identifier ("explicit");
647   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_EXPLICIT],
648                           build_tree_list (NULL_TREE, ridpointers[(int) RID_EXPLICIT]));
649   ridpointers[(int) RID_FRIEND] = get_identifier ("friend");
650   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_FRIEND],
651                           build_tree_list (NULL_TREE, ridpointers[(int) RID_FRIEND]));
652
653   ridpointers[(int) RID_PUBLIC] = get_identifier ("public");
654   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PUBLIC],
655                           build_tree_list (NULL_TREE, ridpointers[(int) RID_PUBLIC]));
656   ridpointers[(int) RID_PRIVATE] = get_identifier ("private");
657   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PRIVATE],
658                           build_tree_list (NULL_TREE, ridpointers[(int) RID_PRIVATE]));
659   ridpointers[(int) RID_PROTECTED] = get_identifier ("protected");
660   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_PROTECTED],
661                           build_tree_list (NULL_TREE, ridpointers[(int) RID_PROTECTED]));
662   ridpointers[(int) RID_TEMPLATE] = get_identifier ("template");
663   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_TEMPLATE],
664                           build_tree_list (NULL_TREE, ridpointers[(int) RID_TEMPLATE]));
665   /* This is for ANSI C++. */
666   ridpointers[(int) RID_MUTABLE] = get_identifier ("mutable");
667   SET_IDENTIFIER_AS_LIST (ridpointers[(int) RID_MUTABLE],
668                           build_tree_list (NULL_TREE, ridpointers[(int) RID_MUTABLE]));
669
670   /* Signature handling extensions.  */
671   signature_type_node = build_int_2 (signature_type, 0);
672   TREE_TYPE (signature_type_node) = signature_type_node;
673   ridpointers[(int) RID_SIGNATURE] = signature_type_node;
674
675   opname_tab[(int) COMPONENT_REF] = "->";
676   opname_tab[(int) MEMBER_REF] = "->*";
677   opname_tab[(int) METHOD_CALL_EXPR] = "->()";
678   opname_tab[(int) INDIRECT_REF] = "(unary *)";
679   opname_tab[(int) ARRAY_REF] = "[]";
680   opname_tab[(int) MODIFY_EXPR] = "=";
681   opname_tab[(int) NEW_EXPR] = "new";
682   opname_tab[(int) DELETE_EXPR] = "delete";
683   opname_tab[(int) VEC_NEW_EXPR] = "new []";
684   opname_tab[(int) VEC_DELETE_EXPR] = "delete []";
685   opname_tab[(int) COND_EXPR] = "... ? ... : ...";
686   opname_tab[(int) CALL_EXPR] = "()";
687   opname_tab[(int) PLUS_EXPR] = "+";
688   opname_tab[(int) MINUS_EXPR] = "-";
689   opname_tab[(int) MULT_EXPR] = "*";
690   opname_tab[(int) TRUNC_DIV_EXPR] = "/";
691   opname_tab[(int) CEIL_DIV_EXPR] = "(ceiling /)";
692   opname_tab[(int) FLOOR_DIV_EXPR] = "(floor /)";
693   opname_tab[(int) ROUND_DIV_EXPR] = "(round /)";
694   opname_tab[(int) TRUNC_MOD_EXPR] = "%";
695   opname_tab[(int) CEIL_MOD_EXPR] = "(ceiling %)";
696   opname_tab[(int) FLOOR_MOD_EXPR] = "(floor %)";
697   opname_tab[(int) ROUND_MOD_EXPR] = "(round %)";
698   opname_tab[(int) NEGATE_EXPR] = "-";
699   opname_tab[(int) MIN_EXPR] = "<?";
700   opname_tab[(int) MAX_EXPR] = ">?";
701   opname_tab[(int) ABS_EXPR] = "abs";
702   opname_tab[(int) FFS_EXPR] = "ffs";
703   opname_tab[(int) LSHIFT_EXPR] = "<<";
704   opname_tab[(int) RSHIFT_EXPR] = ">>";
705   opname_tab[(int) BIT_IOR_EXPR] = "|";
706   opname_tab[(int) BIT_XOR_EXPR] = "^";
707   opname_tab[(int) BIT_AND_EXPR] = "&";
708   opname_tab[(int) BIT_ANDTC_EXPR] = "&~";
709   opname_tab[(int) BIT_NOT_EXPR] = "~";
710   opname_tab[(int) TRUTH_ANDIF_EXPR] = "&&";
711   opname_tab[(int) TRUTH_ORIF_EXPR] = "||";
712   opname_tab[(int) TRUTH_AND_EXPR] = "strict &&";
713   opname_tab[(int) TRUTH_OR_EXPR] = "strict ||";
714   opname_tab[(int) TRUTH_NOT_EXPR] = "!";
715   opname_tab[(int) LT_EXPR] = "<";
716   opname_tab[(int) LE_EXPR] = "<=";
717   opname_tab[(int) GT_EXPR] = ">";
718   opname_tab[(int) GE_EXPR] = ">=";
719   opname_tab[(int) EQ_EXPR] = "==";
720   opname_tab[(int) NE_EXPR] = "!=";
721   opname_tab[(int) IN_EXPR] = "in";
722   opname_tab[(int) RANGE_EXPR] = "..";
723   opname_tab[(int) CONVERT_EXPR] = "(unary +)";
724   opname_tab[(int) ADDR_EXPR] = "(unary &)";
725   opname_tab[(int) PREDECREMENT_EXPR] = "--";
726   opname_tab[(int) PREINCREMENT_EXPR] = "++";
727   opname_tab[(int) POSTDECREMENT_EXPR] = "--";
728   opname_tab[(int) POSTINCREMENT_EXPR] = "++";
729   opname_tab[(int) COMPOUND_EXPR] = ",";
730
731   assignop_tab[(int) NOP_EXPR] = "=";
732   assignop_tab[(int) PLUS_EXPR] =  "+=";
733   assignop_tab[(int) CONVERT_EXPR] =  "+=";
734   assignop_tab[(int) MINUS_EXPR] = "-=";
735   assignop_tab[(int) NEGATE_EXPR] = "-=";
736   assignop_tab[(int) MULT_EXPR] = "*=";
737   assignop_tab[(int) INDIRECT_REF] = "*=";
738   assignop_tab[(int) TRUNC_DIV_EXPR] = "/=";
739   assignop_tab[(int) EXACT_DIV_EXPR] = "(exact /=)";
740   assignop_tab[(int) CEIL_DIV_EXPR] = "(ceiling /=)";
741   assignop_tab[(int) FLOOR_DIV_EXPR] = "(floor /=)";
742   assignop_tab[(int) ROUND_DIV_EXPR] = "(round /=)";
743   assignop_tab[(int) TRUNC_MOD_EXPR] = "%=";
744   assignop_tab[(int) CEIL_MOD_EXPR] = "(ceiling %=)";
745   assignop_tab[(int) FLOOR_MOD_EXPR] = "(floor %=)";
746   assignop_tab[(int) ROUND_MOD_EXPR] = "(round %=)";
747   assignop_tab[(int) MIN_EXPR] = "<?=";
748   assignop_tab[(int) MAX_EXPR] = ">?=";
749   assignop_tab[(int) LSHIFT_EXPR] = "<<=";
750   assignop_tab[(int) RSHIFT_EXPR] = ">>=";
751   assignop_tab[(int) BIT_IOR_EXPR] = "|=";
752   assignop_tab[(int) BIT_XOR_EXPR] = "^=";
753   assignop_tab[(int) BIT_AND_EXPR] = "&=";
754   assignop_tab[(int) ADDR_EXPR] = "&=";
755
756   init_filename_times ();
757
758   /* Some options inhibit certain reserved words.
759      Clear those words out of the hash table so they won't be recognized.  */
760 #define UNSET_RESERVED_WORD(STRING) \
761   do { struct resword *s = is_reserved_word (STRING, sizeof (STRING) - 1); \
762        if (s) s->name = ""; } while (0)
763
764 #if 0
765   /* let's parse things, and if they use it, then give them an error.  */
766   if (!flag_handle_exceptions)
767     {
768       UNSET_RESERVED_WORD ("throw");
769       UNSET_RESERVED_WORD ("try");
770       UNSET_RESERVED_WORD ("catch");
771     }
772 #endif
773
774   if (!flag_rtti || flag_no_gnu_keywords)
775     {
776       UNSET_RESERVED_WORD ("classof");
777       UNSET_RESERVED_WORD ("headof");
778     }
779   if (! flag_handle_signatures || flag_no_gnu_keywords)
780     {
781       /* Easiest way to not recognize signature
782          handling extensions...  */
783       UNSET_RESERVED_WORD ("signature");
784       UNSET_RESERVED_WORD ("sigof");
785     }
786   if (flag_no_asm || flag_no_gnu_keywords)
787     UNSET_RESERVED_WORD ("typeof");
788   if (! flag_operator_names)
789     {
790       /* These are new ANSI keywords that may break code.  */
791       UNSET_RESERVED_WORD ("and");
792       UNSET_RESERVED_WORD ("and_eq");
793       UNSET_RESERVED_WORD ("bitand");
794       UNSET_RESERVED_WORD ("bitor");
795       UNSET_RESERVED_WORD ("compl");
796       UNSET_RESERVED_WORD ("not");
797       UNSET_RESERVED_WORD ("not_eq");
798       UNSET_RESERVED_WORD ("or");
799       UNSET_RESERVED_WORD ("or_eq");
800       UNSET_RESERVED_WORD ("xor");
801       UNSET_RESERVED_WORD ("xor_eq");
802     }
803   if (! flag_traditional)
804     UNSET_RESERVED_WORD ("overload");
805
806   token_count = init_parse ();
807   interface_unknown = 1;
808 }
809
810 void
811 reinit_parse_for_function ()
812 {
813   current_base_init_list = NULL_TREE;
814   current_member_init_list = NULL_TREE;
815 }
816 \f
817 #ifdef __GNUC__
818 __inline
819 #endif
820 void
821 yyprint (file, yychar, yylval)
822      FILE *file;
823      int yychar;
824      YYSTYPE yylval;
825 {
826   tree t;
827   switch (yychar)
828     {
829     case IDENTIFIER:
830     case TYPENAME:
831     case TYPESPEC:
832     case PTYPENAME:
833     case IDENTIFIER_DEFN:
834     case TYPENAME_DEFN:
835     case PTYPENAME_DEFN:
836     case TYPENAME_ELLIPSIS:
837     case SCSPEC:
838     case PRE_PARSED_CLASS_DECL:
839       t = yylval.ttype;
840       if (TREE_CODE (t) == TYPE_DECL)
841         {
842           fprintf (file, " `%s'", DECL_NAME (t));
843           break;
844         }
845       my_friendly_assert (TREE_CODE (t) == IDENTIFIER_NODE, 224);
846       if (IDENTIFIER_POINTER (t))
847           fprintf (file, " `%s'", IDENTIFIER_POINTER (t));
848       break;
849     case AGGR:
850       if (yylval.ttype == class_type_node)
851         fprintf (file, " `class'");
852       else if (yylval.ttype == record_type_node)
853         fprintf (file, " `struct'");
854       else if (yylval.ttype == union_type_node)
855         fprintf (file, " `union'");
856       else if (yylval.ttype == enum_type_node)
857         fprintf (file, " `enum'");
858       else if (yylval.ttype == signature_type_node)
859         fprintf (file, " `signature'");
860       else
861         my_friendly_abort (80);
862       break;
863     }
864 }
865
866 #if defined(GATHER_STATISTICS) && defined(REDUCE_LENGTH)
867 static int *reduce_count;
868 #endif
869
870 int *token_count;
871
872 #if 0
873 #define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
874 #define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
875 #endif
876
877 int *
878 init_parse ()
879 {
880 #ifdef GATHER_STATISTICS
881 #ifdef REDUCE_LENGTH
882   reduce_count = (int *)malloc (sizeof (int) * (REDUCE_LENGTH + 1));
883   bzero (reduce_count, sizeof (int) * (REDUCE_LENGTH + 1));
884   reduce_count += 1;
885   token_count = (int *)malloc (sizeof (int) * (TOKEN_LENGTH + 1));
886   bzero (token_count, sizeof (int) * (TOKEN_LENGTH + 1));
887   token_count += 1;
888 #endif
889 #endif
890   return token_count;
891 }
892
893 #ifdef GATHER_STATISTICS
894 #ifdef REDUCE_LENGTH
895 void
896 yyhook (yyn)
897      int yyn;
898 {
899   reduce_count[yyn] += 1;
900 }
901
902 static int
903 reduce_cmp (p, q)
904      int *p, *q;
905 {
906   return reduce_count[*q] - reduce_count[*p];
907 }
908
909 static int
910 token_cmp (p, q)
911      int *p, *q;
912 {
913   return token_count[*q] - token_count[*p];
914 }
915 #endif
916 #endif
917
918 void
919 print_parse_statistics ()
920 {
921 #ifdef GATHER_STATISTICS
922 #ifdef REDUCE_LENGTH
923 #if YYDEBUG != 0
924   int i;
925   int maxlen = REDUCE_LENGTH;
926   unsigned *sorted;
927   
928   if (reduce_count[-1] == 0)
929     return;
930
931   if (TOKEN_LENGTH > REDUCE_LENGTH)
932     maxlen = TOKEN_LENGTH;
933   sorted = (unsigned *) alloca (sizeof (int) * maxlen);
934
935   for (i = 0; i < TOKEN_LENGTH; i++)
936     sorted[i] = i;
937   qsort (sorted, TOKEN_LENGTH, sizeof (int), token_cmp);
938   for (i = 0; i < TOKEN_LENGTH; i++)
939     {
940       int index = sorted[i];
941       if (token_count[index] == 0)
942         break;
943       if (token_count[index] < token_count[-1])
944         break;
945       fprintf (stderr, "token %d, `%s', count = %d\n",
946                index, yytname[YYTRANSLATE (index)], token_count[index]);
947     }
948   fprintf (stderr, "\n");
949   for (i = 0; i < REDUCE_LENGTH; i++)
950     sorted[i] = i;
951   qsort (sorted, REDUCE_LENGTH, sizeof (int), reduce_cmp);
952   for (i = 0; i < REDUCE_LENGTH; i++)
953     {
954       int index = sorted[i];
955       if (reduce_count[index] == 0)
956         break;
957       if (reduce_count[index] < reduce_count[-1])
958         break;
959       fprintf (stderr, "rule %d, line %d, count = %d\n",
960                index, yyrline[index], reduce_count[index]);
961     }
962   fprintf (stderr, "\n");
963 #endif
964 #endif
965 #endif
966 }
967
968 /* Sets the value of the 'yydebug' variable to VALUE.
969    This is a function so we don't have to have YYDEBUG defined
970    in order to build the compiler.  */
971 void
972 set_yydebug (value)
973      int value;
974 {
975 #if YYDEBUG != 0
976   extern int yydebug;
977   yydebug = value;
978 #else
979   warning ("YYDEBUG not defined.");
980 #endif
981 }
982
983 \f
984 /* Functions and data structures for #pragma interface.
985
986    `#pragma implementation' means that the main file being compiled
987    is considered to implement (provide) the classes that appear in
988    its main body.  I.e., if this is file "foo.cc", and class `bar'
989    is defined in "foo.cc", then we say that "foo.cc implements bar".
990
991    All main input files "implement" themselves automagically.
992
993    `#pragma interface' means that unless this file (of the form "foo.h"
994    is not presently being included by file "foo.cc", the
995    CLASSTYPE_INTERFACE_ONLY bit gets set.  The effect is that none
996    of the vtables nor any of the inline functions defined in foo.h
997    will ever be output.
998
999    There are cases when we want to link files such as "defs.h" and
1000    "main.cc".  In this case, we give "defs.h" a `#pragma interface',
1001    and "main.cc" has `#pragma implementation "defs.h"'.  */
1002
1003 struct impl_files
1004 {
1005   char *filename;
1006   struct impl_files *next;
1007 };
1008
1009 static struct impl_files *impl_file_chain;
1010
1011 /* Helper function to load global variables with interface
1012    information.  */
1013 void
1014 extract_interface_info ()
1015 {
1016   tree fileinfo = 0;
1017
1018   if (flag_alt_external_templates)
1019     {
1020       struct tinst_level *til = tinst_for_decl ();
1021   
1022       if (til)
1023         fileinfo = get_time_identifier (til->file);
1024     }
1025   if (!fileinfo)
1026     fileinfo = get_time_identifier (input_filename);
1027   fileinfo = IDENTIFIER_CLASS_VALUE (fileinfo);
1028   interface_only = TREE_INT_CST_LOW (fileinfo);
1029   interface_unknown = TREE_INT_CST_HIGH (fileinfo);
1030 }
1031
1032 /* Return nonzero if S is not considered part of an
1033    INTERFACE/IMPLEMENTATION pair.  Otherwise, return 0.  */
1034 static int
1035 interface_strcmp (s)
1036      char *s;
1037 {
1038   /* Set the interface/implementation bits for this scope.  */
1039   struct impl_files *ifiles;
1040   char *s1;
1041
1042   for (ifiles = impl_file_chain; ifiles; ifiles = ifiles->next)
1043     {
1044       char *t1 = ifiles->filename;
1045       s1 = s;
1046
1047       if (*s1 != *t1 || *s1 == 0)
1048         continue;
1049
1050       while (*s1 == *t1 && *s1 != 0)
1051         s1++, t1++;
1052
1053       /* A match.  */
1054       if (*s1 == *t1)
1055         return 0;
1056
1057       /* Don't get faked out by xxx.yyy.cc vs xxx.zzz.cc.  */
1058       if (index (s1, '.') || index (t1, '.'))
1059         continue;
1060
1061       if (*s1 == '\0' || s1[-1] != '.' || t1[-1] != '.')
1062         continue;
1063
1064       /* A match.  */
1065       return 0;
1066     }
1067
1068   /* No matches.  */
1069   return 1;
1070 }
1071
1072 void
1073 set_typedecl_interface_info (prev, vars)
1074      tree prev, vars;
1075 {
1076   tree id = get_time_identifier (DECL_SOURCE_FILE (vars));
1077   tree fileinfo = IDENTIFIER_CLASS_VALUE (id);
1078   tree type = TREE_TYPE (vars);
1079
1080   CLASSTYPE_INTERFACE_ONLY (type) = TREE_INT_CST_LOW (fileinfo)
1081     = interface_strcmp (FILE_NAME_NONDIRECTORY (DECL_SOURCE_FILE (vars)));
1082 }
1083
1084 int
1085 set_vardecl_interface_info (prev, vars)
1086      tree prev, vars;
1087 {
1088   tree type = DECL_CONTEXT (vars);
1089
1090   if (CLASSTYPE_INTERFACE_KNOWN (type))
1091     {
1092       if (CLASSTYPE_INTERFACE_ONLY (type))
1093         set_typedecl_interface_info (prev, TYPE_NAME (type));
1094       else
1095         CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 1;
1096       DECL_EXTERNAL (vars) = CLASSTYPE_INTERFACE_ONLY (type);
1097       TREE_PUBLIC (vars) = 1;
1098       return 1;
1099     }
1100   return 0;
1101 }
1102 \f
1103 /* Called from the top level: if there are any pending inlines to
1104    do, set up to process them now.  This function sets up the first function
1105    to be parsed; after it has been, the rule for fndef in parse.y will
1106    call process_next_inline to start working on the next one.  */
1107 void
1108 do_pending_inlines ()
1109 {
1110   struct pending_inline *t;
1111   tree context;
1112
1113   /* Oops, we're still dealing with the last batch.  */
1114   if (yychar == PRE_PARSED_FUNCTION_DECL)
1115     return;
1116
1117   /* Reverse the pending inline functions, since
1118      they were cons'd instead of appended.  */
1119   {
1120     struct pending_inline *prev = 0, *tail;
1121     t = pending_inlines;
1122     pending_inlines = 0;
1123
1124     for (; t; t = tail)
1125       {
1126         tail = t->next;
1127         t->next = prev;
1128         t->deja_vu = 1;
1129         prev = t;
1130       }
1131     t = prev;
1132   }
1133
1134   if (t == 0)
1135     return;
1136             
1137   /* Now start processing the first inline function.  */
1138   context = hack_decl_function_context (t->fndecl);
1139   if (context)
1140     push_cp_function_context (context);
1141   if (t->len > 0)
1142     {
1143       feed_input (t->buf, t->len, t->can_free ? &inline_text_obstack : 0);
1144       lineno = t->lineno;
1145 #if 0
1146       if (input_filename != t->filename)
1147         {
1148           input_filename = t->filename;
1149           /* Get interface/implementation back in sync.  */
1150           extract_interface_info ();
1151         }
1152 #else
1153       input_filename = t->filename;
1154       interface_unknown = t->interface == 1;
1155       interface_only = t->interface == 0;
1156 #endif
1157       yychar = PRE_PARSED_FUNCTION_DECL;
1158     }
1159   /* Pass back a handle on the rest of the inline functions, so that they
1160      can be processed later.  */
1161   yylval.ttype = build_tree_list ((tree) t, t->fndecl);
1162   DECL_PENDING_INLINE_INFO (t->fndecl) = 0;
1163 }
1164
1165 extern struct pending_input *to_be_restored;
1166 static int nextchar = -1;
1167
1168 /* Called from the fndecl rule in the parser when the function just parsed
1169    was declared using a PRE_PARSED_FUNCTION_DECL (i.e. came from
1170    do_pending_inlines).  */
1171 void
1172 process_next_inline (t)
1173      tree t;
1174 {
1175   tree context;
1176   struct pending_inline *i = (struct pending_inline *) TREE_PURPOSE (t);
1177   context = hack_decl_function_context (i->fndecl);
1178   if (context)
1179     pop_cp_function_context (context);
1180   i = i->next;
1181   if (yychar == YYEMPTY)
1182     yychar = yylex ();
1183   if (yychar != END_OF_SAVED_INPUT)
1184     {
1185       error ("parse error at end of saved function text");
1186       /* restore_pending_input will abort unless yychar is either
1187        * END_OF_SAVED_INPUT or YYEMPTY; since we already know we're
1188        * hosed, feed back YYEMPTY.
1189        *  We also need to discard nextchar, since that may have gotten
1190        * set as well.
1191        */
1192       nextchar = -1;
1193     }
1194   yychar = YYEMPTY;
1195   if (to_be_restored == 0)
1196     my_friendly_abort (123);
1197   restore_pending_input (to_be_restored);
1198   to_be_restored = 0;
1199   if (i && i->fndecl != NULL_TREE)
1200     {
1201       context = hack_decl_function_context (i->fndecl);
1202       if (context)
1203         push_cp_function_context (context);
1204       feed_input (i->buf, i->len, i->can_free ? &inline_text_obstack : 0);
1205       lineno = i->lineno;
1206       input_filename = i->filename;
1207       yychar = PRE_PARSED_FUNCTION_DECL;
1208       yylval.ttype = build_tree_list ((tree) i, i->fndecl);
1209       DECL_PENDING_INLINE_INFO (i->fndecl) = 0;
1210     }
1211   if (i)
1212     {
1213       interface_unknown = i->interface == 1;
1214       interface_only = i->interface == 0;
1215     }
1216   else
1217     extract_interface_info ();
1218 }
1219
1220 /* Since inline methods can refer to text which has not yet been seen,
1221    we store the text of the method in a structure which is placed in the
1222    DECL_PENDING_INLINE_INFO field of the FUNCTION_DECL.
1223    After parsing the body of the class definition, the FUNCTION_DECL's are
1224    scanned to see which ones have this field set.  Those are then digested
1225    one at a time.
1226
1227    This function's FUNCTION_DECL will have a bit set in its common so
1228    that we know to watch out for it.  */
1229
1230 static void
1231 consume_string (this_obstack, matching_char)
1232      register struct obstack *this_obstack;
1233      int matching_char;
1234 {
1235   register int c;
1236   int starting_lineno = lineno;
1237   do
1238     {
1239       c = getch ();
1240       if (c == EOF)
1241         {
1242           int save_lineno = lineno;
1243           lineno = starting_lineno;
1244           if (matching_char == '"')
1245             error ("end of file encountered inside string constant");
1246           else
1247             error ("end of file encountered inside character constant");
1248           lineno = save_lineno;
1249           return;
1250         }
1251       if (c == '\\')
1252         {
1253           obstack_1grow (this_obstack, c);
1254           c = getch ();
1255           obstack_1grow (this_obstack, c);
1256
1257           /* Make sure we continue the loop */
1258           c = 0;
1259           continue;
1260         }
1261       if (c == '\n')
1262         {
1263           if (pedantic)
1264             pedwarn ("ANSI C++ forbids newline in string constant");
1265           lineno++;
1266         }
1267       obstack_1grow (this_obstack, c);
1268     }
1269   while (c != matching_char);
1270 }
1271
1272 static int nextyychar = YYEMPTY;
1273 static YYSTYPE nextyylval;
1274
1275 struct pending_input {
1276   int nextchar, yychar, nextyychar, eof;
1277   YYSTYPE yylval, nextyylval;
1278   struct obstack token_obstack;
1279   int first_token;
1280 };
1281
1282 struct pending_input *
1283 save_pending_input ()
1284 {
1285   struct pending_input *p;
1286   p = (struct pending_input *) xmalloc (sizeof (struct pending_input));
1287   p->nextchar = nextchar;
1288   p->yychar = yychar;
1289   p->nextyychar = nextyychar;
1290   p->yylval = yylval;
1291   p->nextyylval = nextyylval;
1292   p->eof = end_of_file;
1293   yychar = nextyychar = YYEMPTY;
1294   nextchar = -1;
1295   p->first_token = first_token;
1296   p->token_obstack = token_obstack;
1297
1298   first_token = 0;
1299   gcc_obstack_init (&token_obstack);
1300   end_of_file = 0;
1301   return p;
1302 }
1303
1304 void
1305 restore_pending_input (p)
1306      struct pending_input *p;
1307 {
1308   my_friendly_assert (nextchar == -1, 229);
1309   nextchar = p->nextchar;
1310   my_friendly_assert (yychar == YYEMPTY || yychar == END_OF_SAVED_INPUT, 230);
1311   yychar = p->yychar;
1312   my_friendly_assert (nextyychar == YYEMPTY, 231);
1313   nextyychar = p->nextyychar;
1314   yylval = p->yylval;
1315   nextyylval = p->nextyylval;
1316   first_token = p->first_token;
1317   obstack_free (&token_obstack, (char *) 0);
1318   token_obstack = p->token_obstack;
1319   end_of_file = p->eof;
1320   free (p);
1321 }
1322
1323 /* Return next non-whitespace input character, which may come
1324    from `finput', or from `nextchar'.  */
1325 static int
1326 yynextch ()
1327 {
1328   int c;
1329
1330   if (nextchar >= 0)
1331     {
1332       c = nextchar;
1333       nextchar = -1;
1334     }
1335   else c = getch ();
1336   return skip_white_space (c);
1337 }
1338
1339 /* Unget character CH from the input stream.
1340    If RESCAN is non-zero, then we want to `see' this
1341    character as the next input token.  */
1342 void
1343 yyungetc (ch, rescan)
1344      int ch;
1345      int rescan;
1346 {
1347   /* Unget a character from the input stream.  */
1348   if (yychar == YYEMPTY || rescan == 0)
1349     {
1350       if (nextchar >= 0)
1351         put_back (nextchar);
1352       nextchar = ch;
1353     }
1354   else
1355     {
1356       my_friendly_assert (nextyychar == YYEMPTY, 232);
1357       nextyychar = yychar;
1358       nextyylval = yylval;
1359       yychar = ch;
1360     }
1361 }
1362
1363 /* This function stores away the text for an inline function that should
1364    be processed later.  It decides how much later, and may need to move
1365    the info between obstacks; therefore, the caller should not refer to
1366    the T parameter after calling this function.  */
1367
1368 static void
1369 store_pending_inline (decl, t)
1370      tree decl;
1371      struct pending_inline *t;
1372 {
1373   t->fndecl = decl;
1374   DECL_PENDING_INLINE_INFO (decl) = t;
1375
1376   /* Because we use obstacks, we must process these in precise order.  */
1377   t->next = pending_inlines;
1378   pending_inlines = t;
1379 }
1380
1381 void reinit_parse_for_block ();
1382
1383 void
1384 reinit_parse_for_method (yychar, decl)
1385      int yychar;
1386      tree decl;
1387 {
1388   int len;
1389   int starting_lineno = lineno;
1390   char *starting_filename = input_filename;
1391
1392   reinit_parse_for_block (yychar, &inline_text_obstack);
1393
1394   len = obstack_object_size (&inline_text_obstack);
1395   current_base_init_list = NULL_TREE;
1396   current_member_init_list = NULL_TREE;
1397   if (decl == void_type_node
1398       || (current_class_type && TYPE_REDEFINED (current_class_type)))
1399     {
1400       /* Happens when we get two declarations of the same
1401          function in the same scope.  */
1402       char *buf = obstack_finish (&inline_text_obstack);
1403       obstack_free (&inline_text_obstack, buf);
1404       return;
1405     }
1406   else
1407     {
1408       struct pending_inline *t;
1409       char *buf = obstack_finish (&inline_text_obstack);
1410
1411       t = (struct pending_inline *) obstack_alloc (&inline_text_obstack,
1412                                                    sizeof (struct pending_inline));
1413       t->lineno = starting_lineno;
1414       t->filename = starting_filename;
1415       t->token = YYEMPTY;
1416       t->token_value = 0;
1417       t->buf = buf;
1418       t->len = len;
1419       t->can_free = 1;
1420       t->deja_vu = 0;
1421 #if 0
1422       if (interface_unknown && processing_template_defn && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
1423         warn_if_unknown_interface (decl);
1424 #endif
1425       t->interface = (interface_unknown ? 1 : (interface_only ? 0 : 2));
1426       store_pending_inline (decl, t);
1427     }
1428 }
1429
1430 /* Consume a block -- actually, a method beginning
1431    with `:' or `{' -- and save it away on the specified obstack.  */
1432
1433 void
1434 reinit_parse_for_block (pyychar, obstackp)
1435      int pyychar;
1436      struct obstack *obstackp;
1437 {
1438   register int c = 0;
1439   int blev = 1;
1440   int starting_lineno = lineno;
1441   char *starting_filename = input_filename;
1442   int len;
1443   int look_for_semicolon = 0;
1444   int look_for_lbrac = 0;
1445
1446   if (pyychar == '{')
1447     obstack_1grow (obstackp, '{');
1448   else if (pyychar == '=')
1449     look_for_semicolon = 1;
1450   else if (pyychar == ':')
1451     {
1452       obstack_1grow (obstackp, pyychar);
1453       look_for_lbrac = 1;
1454       blev = 0;
1455     }
1456   else if (pyychar == RETURN)
1457     {
1458       obstack_grow (obstackp, "return", 6);
1459       look_for_lbrac = 1;
1460       blev = 0;
1461     }
1462   else if (pyychar == TRY)
1463     {
1464       obstack_grow (obstackp, "try", 3);
1465       look_for_lbrac = 1;
1466       blev = 0;
1467     }
1468   else
1469     {
1470       yyerror ("parse error in method specification");
1471       obstack_1grow (obstackp, '{');
1472     }
1473
1474   if (nextchar != EOF)
1475     {
1476       c = nextchar;
1477       nextchar = EOF;
1478     }
1479   else
1480     c = getch ();
1481   
1482   while (c != EOF)
1483     {
1484       int this_lineno = lineno;
1485
1486       c = skip_white_space (c);
1487
1488       /* Don't lose our cool if there are lots of comments.  */
1489       if (lineno == this_lineno + 1)
1490         obstack_1grow (obstackp, '\n');
1491       else if (lineno == this_lineno)
1492         ;
1493       else if (lineno - this_lineno < 10)
1494         {
1495           int i;
1496           for (i = lineno - this_lineno; i > 0; i--)
1497             obstack_1grow (obstackp, '\n');
1498         }
1499       else
1500         {
1501           char buf[16];
1502           sprintf (buf, "\n# %d \"", lineno);
1503           len = strlen (buf);
1504           obstack_grow (obstackp, buf, len);
1505
1506           len = strlen (input_filename);
1507           obstack_grow (obstackp, input_filename, len);
1508           obstack_1grow (obstackp, '\"');
1509           obstack_1grow (obstackp, '\n');
1510         }
1511
1512       while (c > ' ')           /* ASCII dependent...  */
1513         {
1514           obstack_1grow (obstackp, c);
1515           if (c == '{')
1516             {
1517               look_for_lbrac = 0;
1518               blev++;
1519             }
1520           else if (c == '}')
1521             {
1522               blev--;
1523               if (blev == 0 && !look_for_semicolon)
1524                 {
1525                   if (pyychar == TRY)
1526                     {
1527                       if (peekyylex () == CATCH)
1528                         {
1529                           yylex ();
1530                           obstack_grow (obstackp, " catch ", 7);
1531                           look_for_lbrac = 1;
1532                         }
1533                       else
1534                         {
1535                           yychar = '{';
1536                           goto done;
1537                         }
1538                     }
1539                   else
1540                     {
1541                       goto done;
1542                     }
1543                 }
1544             }
1545           else if (c == '\\')
1546             {
1547               /* Don't act on the next character...e.g, doing an escaped
1548                  double-quote.  */
1549               c = getch ();
1550               if (c == EOF)
1551                 {
1552                   error_with_file_and_line (starting_filename,
1553                                             starting_lineno,
1554                                             "end of file read inside definition");
1555                   goto done;
1556                 }
1557               obstack_1grow (obstackp, c);
1558             }
1559           else if (c == '\"')
1560             consume_string (obstackp, c);
1561           else if (c == '\'')
1562             consume_string (obstackp, c);
1563           else if (c == ';')
1564             {
1565               if (look_for_lbrac)
1566                 {
1567                   error ("function body for constructor missing");
1568                   obstack_1grow (obstackp, '{');
1569                   obstack_1grow (obstackp, '}');
1570                   len += 2;
1571                   goto done;
1572                 }
1573               else if (look_for_semicolon && blev == 0)
1574                 goto done;
1575             }
1576           c = getch ();
1577         }
1578
1579       if (c == EOF)
1580         {
1581           error_with_file_and_line (starting_filename,
1582                                     starting_lineno,
1583                                     "end of file read inside definition");
1584           goto done;
1585         }
1586       else if (c != '\n')
1587         {
1588           obstack_1grow (obstackp, c);
1589           c = getch ();
1590         }
1591     }
1592  done:
1593   obstack_1grow (obstackp, '\0');
1594 }
1595
1596 /* Build a default function named NAME for type TYPE.
1597    KIND says what to build.
1598
1599    When KIND == 0, build default destructor.
1600    When KIND == 1, build virtual destructor.
1601    When KIND == 2, build default constructor.
1602    When KIND == 3, build default X(const X&) constructor.
1603    When KIND == 4, build default X(X&) constructor.
1604    When KIND == 5, build default operator = (const X&).
1605    When KIND == 6, build default operator = (X&).  */
1606
1607 tree
1608 cons_up_default_function (type, full_name, kind)
1609      tree type, full_name;
1610      int kind;
1611 {
1612   extern tree void_list_node;
1613   tree declspecs = NULL_TREE;
1614   tree fn, args;
1615   tree argtype;
1616   int retref = 0;
1617   tree name = constructor_name (full_name);
1618
1619   switch (kind)
1620     {
1621       /* Destructors.  */
1622     case 1:
1623       declspecs = build_decl_list (NULL_TREE, ridpointers [(int) RID_VIRTUAL]);
1624       /* Fall through...  */
1625     case 0:
1626       name = build_parse_node (BIT_NOT_EXPR, name);
1627       args = void_list_node;
1628       break;
1629
1630     case 2:
1631       /* Default constructor.  */
1632       args = void_list_node;
1633       break;
1634
1635     case 3:
1636       type = build_type_variant (type, 1, 0);
1637       /* Fall through...  */
1638     case 4:
1639       /* According to ARM $12.8, the default copy ctor will be declared, but
1640          not defined, unless it's needed.  */
1641       argtype = build_reference_type (type);
1642       args = tree_cons (NULL_TREE,
1643                         build_tree_list (hash_tree_chain (argtype, NULL_TREE),
1644                                          get_identifier ("_ctor_arg")),
1645                         void_list_node);
1646       break;
1647
1648     case 5:
1649       type = build_type_variant (type, 1, 0);
1650       /* Fall through...  */
1651     case 6:
1652       retref = 1;
1653       declspecs = build_decl_list (NULL_TREE, type);
1654
1655       name = ansi_opname [(int) MODIFY_EXPR];
1656
1657       argtype = build_reference_type (type);
1658       args = tree_cons (NULL_TREE,
1659                         build_tree_list (hash_tree_chain (argtype, NULL_TREE),
1660                                          get_identifier ("_ctor_arg")),
1661                         void_list_node);
1662       break;
1663
1664     default:
1665       my_friendly_abort (59);
1666     }
1667
1668   declspecs = decl_tree_cons (NULL_TREE, ridpointers [(int) RID_INLINE],
1669                               declspecs);
1670
1671   TREE_PARMLIST (args) = 1;
1672
1673   {
1674     tree declarator = build_parse_node (CALL_EXPR, name, args, NULL_TREE);
1675     if (retref)
1676       declarator = build_parse_node (ADDR_EXPR, declarator);
1677     
1678     fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE,
1679                     NULL_TREE, NULL_TREE);
1680   }
1681   
1682   if (fn == void_type_node)
1683     return fn;
1684
1685 #if 0
1686   if (processing_template_defn)
1687     {
1688       SET_DECL_IMPLICIT_INSTANTIATION (fn);
1689       repo_template_used (fn);
1690     }
1691 #endif
1692
1693 #if 0
1694   if (CLASSTYPE_INTERFACE_KNOWN (type))
1695     {
1696       DECL_INTERFACE_KNOWN (fn) = 1;
1697       DECL_NOT_REALLY_EXTERN (fn) = (!CLASSTYPE_INTERFACE_ONLY (type)
1698                                      && flag_implement_inlines);
1699     }
1700   else
1701 #endif
1702     DECL_NOT_REALLY_EXTERN (fn) = 1;
1703
1704   mark_inline_for_output (fn);
1705
1706 #ifdef DEBUG_DEFAULT_FUNCTIONS
1707   { char *fn_type = NULL;
1708     tree t = name;
1709     switch (kind)
1710       {
1711       case 0: fn_type = "default destructor"; break;
1712       case 1: fn_type = "virtual destructor"; break;
1713       case 2: fn_type = "default constructor"; break;
1714       case 3: fn_type = "default X(const X&)"; break;
1715       case 4: fn_type = "default X(X&)"; break;
1716       }
1717     if (fn_type)
1718       {
1719         if (TREE_CODE (name) == BIT_NOT_EXPR)
1720           t = TREE_OPERAND (name, 0);
1721         fprintf (stderr, "[[[[ %s for %s:\n%s]]]]\n", fn_type,
1722                  IDENTIFIER_POINTER (t), func_buf);
1723       }
1724   }
1725 #endif /* DEBUG_DEFAULT_FUNCTIONS */
1726
1727   /* Show that this function was generated by the compiler.  */
1728   SET_DECL_ARTIFICIAL (fn);
1729   
1730   return fn;
1731 }
1732
1733 /* Heuristic to tell whether the user is missing a semicolon
1734    after a struct or enum declaration.  Emit an error message
1735    if we know the user has blown it.  */
1736 void
1737 check_for_missing_semicolon (type)
1738      tree type;
1739 {
1740   if (yychar < 0)
1741     yychar = yylex ();
1742
1743   if ((yychar > 255
1744        && yychar != SCSPEC
1745        && yychar != IDENTIFIER
1746        && yychar != TYPENAME
1747        && yychar != SELFNAME)
1748       || end_of_file)
1749     {
1750       if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
1751         error ("semicolon missing after %s declaration",
1752                TREE_CODE (type) == ENUMERAL_TYPE ? "enum" : "struct");
1753       else
1754         cp_error ("semicolon missing after declaration of `%T'", type);
1755       shadow_tag (build_tree_list (0, type));
1756     }
1757   /* Could probably also hack cases where class { ... } f (); appears.  */
1758   clear_anon_tags ();
1759 }
1760
1761 void
1762 note_got_semicolon (type)
1763      tree type;
1764 {
1765   if (TREE_CODE_CLASS (TREE_CODE (type)) != 't')
1766     my_friendly_abort (60);
1767   if (IS_AGGR_TYPE (type))
1768     CLASSTYPE_GOT_SEMICOLON (type) = 1;
1769 }
1770
1771 void
1772 note_list_got_semicolon (declspecs)
1773      tree declspecs;
1774 {
1775   tree link;
1776
1777   for (link = declspecs; link; link = TREE_CHAIN (link))
1778     {
1779       tree type = TREE_VALUE (link);
1780       if (TREE_CODE_CLASS (TREE_CODE (type)) == 't')
1781         note_got_semicolon (type);
1782     }
1783   clear_anon_tags ();
1784 }
1785 \f
1786 /* If C is not whitespace, return C.
1787    Otherwise skip whitespace and return first nonwhite char read.  */
1788
1789 static int
1790 skip_white_space (c)
1791      register int c;
1792 {
1793   for (;;)
1794     {
1795       switch (c)
1796         {
1797         case '\n':
1798           c = check_newline ();
1799           break;
1800
1801         case ' ':
1802         case '\t':
1803         case '\f':
1804         case '\r':
1805         case '\v':
1806         case '\b':
1807           do
1808             c = getch ();
1809           while (c == ' ' || c == '\t');
1810           break;
1811
1812         case '\\':
1813           c = getch ();
1814           if (c == '\n')
1815             lineno++;
1816           else
1817             error ("stray '\\' in program");
1818           c = getch ();
1819           break;
1820
1821         default:
1822           return (c);
1823         }
1824     }
1825 }
1826
1827
1828
1829 /* Make the token buffer longer, preserving the data in it.
1830    P should point to just beyond the last valid character in the old buffer.
1831    The value we return is a pointer to the new buffer
1832    at a place corresponding to P.  */
1833
1834 static char *
1835 extend_token_buffer (p)
1836      char *p;
1837 {
1838   int offset = p - token_buffer;
1839
1840   maxtoken = maxtoken * 2 + 10;
1841   token_buffer = (char *) xrealloc (token_buffer, maxtoken + 2);
1842
1843   return token_buffer + offset;
1844 }
1845 \f
1846 static int
1847 get_last_nonwhite_on_line ()
1848 {
1849   register int c;
1850
1851   /* Is this the last nonwhite stuff on the line?  */
1852   if (nextchar >= 0)
1853     c = nextchar, nextchar = -1;
1854   else
1855     c = getch ();
1856
1857   while (c == ' ' || c == '\t')
1858     c = getch ();
1859   return c;
1860 }
1861
1862 /* At the beginning of a line, increment the line number
1863    and process any #-directive on this line.
1864    If the line is a #-directive, read the entire line and return a newline.
1865    Otherwise, return the line's first non-whitespace character.  */
1866
1867 int linemode;
1868
1869 int handle_cp_pragma ();
1870
1871 int
1872 check_newline ()
1873 {
1874   register int c;
1875   register int token;
1876
1877   /* Read first nonwhite char on the line.  Do this before incrementing the
1878      line number, in case we're at the end of saved text.  */
1879
1880   do
1881     c = getch ();
1882   while (c == ' ' || c == '\t');
1883
1884   lineno++;
1885
1886   if (c != '#')
1887     {
1888       /* If not #, return it so caller will use it.  */
1889       return c;
1890     }
1891
1892   /* Don't read beyond this line.  */
1893   linemode = 1;
1894   
1895   /* Read first nonwhite char after the `#'.  */
1896
1897   do
1898     c = getch ();
1899   while (c == ' ' || c == '\t');
1900
1901   /* If a letter follows, then if the word here is `line', skip
1902      it and ignore it; otherwise, ignore the line, with an error
1903      if the word isn't `pragma'.  */
1904
1905   if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
1906     {
1907       if (c == 'p')
1908         {
1909           if (getch () == 'r'
1910               && getch () == 'a'
1911               && getch () == 'g'
1912               && getch () == 'm'
1913               && getch () == 'a')
1914             {
1915               token = real_yylex ();
1916               if (token == IDENTIFIER
1917                   && TREE_CODE (yylval.ttype) == IDENTIFIER_NODE)
1918                 {
1919                   /* If this is 1, we handled it; if it's -1, it was one we
1920                      wanted but had something wrong with it.  Only if it's
1921                      0 was it not handled.  */
1922                   if (handle_cp_pragma (IDENTIFIER_POINTER (yylval.ttype)))
1923                     goto skipline;
1924                 }
1925               else if (token == END_OF_LINE)
1926                 goto skipline;
1927
1928 #ifdef HANDLE_SYSV_PRAGMA
1929               if (handle_sysv_pragma (finput, token))
1930                 goto skipline;
1931 #else
1932 #ifdef HANDLE_PRAGMA
1933               if (HANDLE_PRAGMA (finput, yylval.ttype))
1934                 goto skipline;
1935 #endif
1936 #endif
1937             }
1938           goto skipline;
1939         }
1940       else if (c == 'd')
1941         {
1942           if (getch () == 'e'
1943               && getch () == 'f'
1944               && getch () == 'i'
1945               && getch () == 'n'
1946               && getch () == 'e'
1947               && ((c = getch ()) == ' ' || c == '\t'))
1948             {
1949 #ifdef DWARF_DEBUGGING_INFO
1950               if ((debug_info_level == DINFO_LEVEL_VERBOSE)
1951                   && (write_symbols == DWARF_DEBUG))
1952                 dwarfout_define (lineno, get_directive_line (finput));
1953 #endif /* DWARF_DEBUGGING_INFO */
1954               goto skipline;
1955             }
1956         }
1957       else if (c == 'u')
1958         {
1959           if (getch () == 'n'
1960               && getch () == 'd'
1961               && getch () == 'e'
1962               && getch () == 'f'
1963               && ((c = getch ()) == ' ' || c == '\t'))
1964             {
1965 #ifdef DWARF_DEBUGGING_INFO
1966               if ((debug_info_level == DINFO_LEVEL_VERBOSE)
1967                   && (write_symbols == DWARF_DEBUG))
1968                 dwarfout_undef (lineno, get_directive_line (finput));
1969 #endif /* DWARF_DEBUGGING_INFO */
1970               goto skipline;
1971             }
1972         }
1973       else if (c == 'l')
1974         {
1975           if (getch () == 'i'
1976               && getch () == 'n'
1977               && getch () == 'e'
1978               && ((c = getch ()) == ' ' || c == '\t'))
1979             goto linenum;
1980         }
1981       else if (c == 'i')
1982         {
1983           if (getch () == 'd'
1984               && getch () == 'e'
1985               && getch () == 'n'
1986               && getch () == 't'
1987               && ((c = getch ()) == ' ' || c == '\t'))
1988             {
1989 #ifdef ASM_OUTPUT_IDENT
1990               extern FILE *asm_out_file;
1991 #endif
1992               /* #ident.  The pedantic warning is now in cccp.c.  */
1993
1994               /* Here we have just seen `#ident '.
1995                  A string constant should follow.  */
1996
1997               token = real_yylex ();
1998               if (token == END_OF_LINE)
1999                 goto skipline;
2000               if (token != STRING
2001                   || TREE_CODE (yylval.ttype) != STRING_CST)
2002                 {
2003                   error ("invalid #ident");
2004                   goto skipline;
2005                 }
2006
2007               if (! flag_no_ident)
2008                 {
2009 #ifdef ASM_OUTPUT_IDENT
2010                   ASM_OUTPUT_IDENT (asm_out_file,
2011                                     TREE_STRING_POINTER (yylval.ttype));
2012 #endif
2013                 }
2014
2015               /* Skip the rest of this line.  */
2016               goto skipline;
2017             }
2018         }
2019       else if (c == 'n')
2020         {
2021           if (getch () == 'e'
2022               && getch () == 'w'
2023               && getch () == 'w'
2024               && getch () == 'o'
2025               && getch () == 'r'
2026               && getch () == 'l'
2027               && getch () == 'd'
2028               && ((c = getch ()) == ' ' || c == '\t'))
2029             {
2030               /* Used to test incremental compilation.  */
2031               sorry ("#pragma newworld");
2032               goto skipline;
2033             }
2034         }
2035       error ("undefined or invalid # directive");
2036       goto skipline;
2037     }
2038
2039 linenum:
2040   /* Here we have either `#line' or `# <nonletter>'.
2041      In either case, it should be a line number; a digit should follow.  */
2042
2043   while (c == ' ' || c == '\t')
2044     c = getch ();
2045
2046   /* If the # is the only nonwhite char on the line,
2047      just ignore it.  Check the new newline.  */
2048   if (c == EOF)
2049     goto skipline;
2050
2051   /* Something follows the #; read a token.  */
2052
2053   put_back (c);
2054   token = real_yylex ();
2055
2056   if (token == CONSTANT
2057       && TREE_CODE (yylval.ttype) == INTEGER_CST)
2058     {
2059       int old_lineno = lineno;
2060       enum { act_none, act_push, act_pop } action = act_none;
2061       int entering_system_header = 0;
2062       int entering_c_header = 0;
2063
2064       /* subtract one, because it is the following line that
2065          gets the specified number */
2066
2067       int l = TREE_INT_CST_LOW (yylval.ttype) - 1;
2068       c = get_last_nonwhite_on_line ();
2069       if (c == EOF)
2070         {
2071           /* No more: store the line number and check following line.  */
2072           lineno = l;
2073           goto skipline;
2074         }
2075       put_back (c);
2076
2077       /* More follows: it must be a string constant (filename).  */
2078
2079       /* Read the string constant, but don't treat \ as special.  */
2080       ignore_escape_flag = 1;
2081       token = real_yylex ();
2082       ignore_escape_flag = 0;
2083
2084       if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
2085         {
2086           error ("invalid #line");
2087           goto skipline;
2088         }
2089
2090       /* Changing files again.  This means currently collected time
2091          is charged against header time, and body time starts back
2092          at 0.  */
2093       if (flag_detailed_statistics)
2094         {
2095           int this_time = my_get_run_time ();
2096           tree time_identifier = get_time_identifier (TREE_STRING_POINTER (yylval.ttype));
2097           header_time += this_time - body_time;
2098           TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time))
2099             += this_time - body_time;
2100           this_filename_time = time_identifier;
2101           body_time = this_time;
2102         }
2103
2104       input_filename
2105         = (char *) permalloc (TREE_STRING_LENGTH (yylval.ttype) + 1);
2106       strcpy (input_filename, TREE_STRING_POINTER (yylval.ttype));
2107       lineno = l;
2108       GNU_xref_file (input_filename);
2109       
2110       if (main_input_filename == 0)
2111         {
2112           struct impl_files *ifiles = impl_file_chain;
2113
2114           if (ifiles)
2115             {
2116               while (ifiles->next)
2117                 ifiles = ifiles->next;
2118               ifiles->filename = FILE_NAME_NONDIRECTORY (input_filename);
2119             }
2120
2121           main_input_filename = input_filename;
2122           if (write_virtuals == 3)
2123             walk_vtables (set_typedecl_interface_info, set_vardecl_interface_info);
2124         }
2125
2126       extract_interface_info ();
2127
2128       c = get_last_nonwhite_on_line ();
2129       if (c == EOF)
2130         {
2131           /* Update the name in the top element of input_file_stack.  */
2132           if (input_file_stack)
2133             input_file_stack->name = input_filename;
2134         }
2135       else
2136         {
2137           put_back (c);
2138
2139           token = real_yylex ();
2140
2141           /* `1' after file name means entering new file.
2142              `2' after file name means just left a file.  */
2143
2144           if (token == CONSTANT
2145               && TREE_CODE (yylval.ttype) == INTEGER_CST)
2146             {
2147               if (TREE_INT_CST_LOW (yylval.ttype) == 1)
2148                 action = act_push;
2149               else if (TREE_INT_CST_LOW (yylval.ttype) == 2)
2150                 action = act_pop;
2151
2152               if (action)
2153                 {
2154                   c = get_last_nonwhite_on_line ();
2155                   if (c != EOF)
2156                     {
2157                       put_back (c);
2158                       token = real_yylex ();
2159                     }
2160                 }
2161             }
2162
2163           /* `3' after file name means this is a system header file.  */
2164
2165           if (token == CONSTANT
2166               && TREE_CODE (yylval.ttype) == INTEGER_CST
2167               && TREE_INT_CST_LOW (yylval.ttype) == 3)
2168             {
2169               entering_system_header = 1;
2170
2171               c = get_last_nonwhite_on_line ();
2172               if (c != EOF)
2173                 {
2174                   put_back (c);
2175                   token = real_yylex ();
2176                 }
2177             }
2178
2179           /* `4' after file name means this is a C header file.  */
2180
2181           if (token == CONSTANT
2182               && TREE_CODE (yylval.ttype) == INTEGER_CST
2183               && TREE_INT_CST_LOW (yylval.ttype) == 4)
2184             {
2185               entering_c_header = 1;
2186
2187               c = get_last_nonwhite_on_line ();
2188               if (c != EOF)
2189                 {
2190                   put_back (c);
2191                   token = real_yylex ();
2192                 }
2193             }
2194
2195           /* Do the actions implied by the preceding numbers.  */
2196
2197           if (action == act_push)
2198             {
2199               /* Pushing to a new file.  */
2200               struct file_stack *p;
2201
2202               p = (struct file_stack *) xmalloc (sizeof (struct file_stack));
2203               input_file_stack->line = old_lineno;
2204               p->next = input_file_stack;
2205               p->name = input_filename;
2206               input_file_stack = p;
2207               input_file_stack_tick++;
2208 #ifdef DBX_DEBUGGING_INFO
2209               if (write_symbols == DBX_DEBUG)
2210                 dbxout_start_new_source_file (input_filename);
2211 #endif
2212 #ifdef DWARF_DEBUGGING_INFO
2213               if (debug_info_level == DINFO_LEVEL_VERBOSE
2214                   && write_symbols == DWARF_DEBUG)
2215                 dwarfout_start_new_source_file (input_filename);
2216 #endif /* DWARF_DEBUGGING_INFO */
2217               in_system_header = entering_system_header;
2218               if (c_header_level)
2219                 ++c_header_level;
2220               else if (entering_c_header)
2221                 {
2222                   c_header_level = 1;
2223                   ++pending_lang_change;
2224                 }
2225             }
2226           else if (action == act_pop)
2227             {
2228               /* Popping out of a file.  */
2229               if (input_file_stack->next)
2230                 {
2231                   struct file_stack *p;
2232
2233                   if (c_header_level && --c_header_level == 0)
2234                     {
2235                       if (entering_c_header)
2236                         warning ("badly nested C headers from preprocessor");
2237                       --pending_lang_change;
2238                     }
2239                   in_system_header = entering_system_header;
2240
2241                   p = input_file_stack;
2242                   input_file_stack = p->next;
2243                   free (p);
2244                   input_file_stack_tick++;
2245 #ifdef DBX_DEBUGGING_INFO
2246                   if (write_symbols == DBX_DEBUG)
2247                     dbxout_resume_previous_source_file ();
2248 #endif
2249 #ifdef DWARF_DEBUGGING_INFO
2250                   if (debug_info_level == DINFO_LEVEL_VERBOSE
2251                       && write_symbols == DWARF_DEBUG)
2252                     dwarfout_resume_previous_source_file (input_file_stack->line);
2253 #endif /* DWARF_DEBUGGING_INFO */
2254                 }
2255               else
2256                 error ("#-lines for entering and leaving files don't match");
2257             }
2258           else
2259             in_system_header = entering_system_header;
2260         }
2261
2262       /* If NEXTCHAR is not end of line, we don't care what it is.  */
2263       if (nextchar == EOF)
2264         c = EOF;
2265     }
2266   else
2267     error ("invalid #-line");
2268
2269   /* skip the rest of this line.  */
2270  skipline:
2271   linemode = 0;
2272   end_of_file = 0;
2273   nextchar = -1;
2274   while ((c = getch ()) != EOF && c != '\n');
2275   return c;
2276 }
2277
2278 void
2279 do_pending_lang_change ()
2280 {
2281   for (; pending_lang_change > 0; --pending_lang_change)
2282     push_lang_context (lang_name_c);
2283   for (; pending_lang_change < 0; ++pending_lang_change)
2284     pop_lang_context ();
2285 }
2286 \f
2287 #if 0
2288 #define isalnum(char) (char >= 'a' ? char <= 'z' : char >= '0' ? char <= '9' || (char >= 'A' && char <= 'Z') : 0)
2289 #define isdigit(char) (char >= '0' && char <= '9')
2290 #else
2291 #include <ctype.h>
2292 #endif
2293
2294 #define ENDFILE -1  /* token that represents end-of-file */
2295
2296 /* Read an escape sequence, returning its equivalent as a character,
2297    or store 1 in *ignore_ptr if it is backslash-newline.  */
2298
2299 static int
2300 readescape (ignore_ptr)
2301      int *ignore_ptr;
2302 {
2303   register int c = getch ();
2304   register int code;
2305   register unsigned count;
2306   unsigned firstdig;
2307   int nonnull;
2308
2309   switch (c)
2310     {
2311     case 'x':
2312       if (warn_traditional)
2313         warning ("the meaning of `\\x' varies with -traditional");
2314
2315       if (flag_traditional)
2316         return c;
2317
2318       code = 0;
2319       count = 0;
2320       nonnull = 0;
2321       while (1)
2322         {
2323           c = getch ();
2324           if (! isxdigit (c))
2325             {
2326               put_back (c);
2327               break;
2328             }
2329           code *= 16;
2330           if (c >= 'a' && c <= 'f')
2331             code += c - 'a' + 10;
2332           if (c >= 'A' && c <= 'F')
2333             code += c - 'A' + 10;
2334           if (c >= '0' && c <= '9')
2335             code += c - '0';
2336           if (code != 0 || count != 0)
2337             {
2338               if (count == 0)
2339                 firstdig = code;
2340               count++;
2341             }
2342           nonnull = 1;
2343         }
2344       if (! nonnull)
2345         error ("\\x used with no following hex digits");
2346       else if (count == 0)
2347         /* Digits are all 0's.  Ok.  */
2348         ;
2349       else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
2350                || (count > 1
2351                    && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
2352                        <= firstdig)))
2353         pedwarn ("hex escape out of range");
2354       return code;
2355
2356     case '0':  case '1':  case '2':  case '3':  case '4':
2357     case '5':  case '6':  case '7':
2358       code = 0;
2359       count = 0;
2360       while ((c <= '7') && (c >= '0') && (count++ < 3))
2361         {
2362           code = (code * 8) + (c - '0');
2363           c = getch ();
2364         }
2365       put_back (c);
2366       return code;
2367
2368     case '\\': case '\'': case '"':
2369       return c;
2370
2371     case '\n':
2372       lineno++;
2373       *ignore_ptr = 1;
2374       return 0;
2375
2376     case 'n':
2377       return TARGET_NEWLINE;
2378
2379     case 't':
2380       return TARGET_TAB;
2381
2382     case 'r':
2383       return TARGET_CR;
2384
2385     case 'f':
2386       return TARGET_FF;
2387
2388     case 'b':
2389       return TARGET_BS;
2390
2391     case 'a':
2392       if (warn_traditional)
2393         warning ("the meaning of `\\a' varies with -traditional");
2394
2395       if (flag_traditional)
2396         return c;
2397       return TARGET_BELL;
2398
2399     case 'v':
2400       return TARGET_VT;
2401
2402     case 'e':
2403     case 'E':
2404       if (pedantic)
2405         pedwarn ("non-ANSI-standard escape sequence, `\\%c'", c);
2406       return 033;
2407
2408     case '?':
2409       return c;
2410
2411       /* `\(', etc, are used at beginning of line to avoid confusing Emacs.  */
2412     case '(':
2413     case '{':
2414     case '[':
2415       /* `\%' is used to prevent SCCS from getting confused.  */
2416     case '%':
2417       if (pedantic)
2418         pedwarn ("unknown escape sequence `\\%c'", c);
2419       return c;
2420     }
2421   if (c >= 040 && c < 0177)
2422     pedwarn ("unknown escape sequence `\\%c'", c);
2423   else
2424     pedwarn ("unknown escape sequence: `\\' followed by char code 0x%x", c);
2425   return c;
2426 }
2427
2428 /* Value is 1 (or 2) if we should try to make the next identifier look like
2429    a typename (when it may be a local variable or a class variable).
2430    Value is 0 if we treat this name in a default fashion.  */
2431 int looking_for_typename = 0;
2432
2433 #if 0
2434 /* NO LONGER USED: Value is -1 if we must not see a type name.  */
2435 void
2436 dont_see_typename ()
2437 {
2438   looking_for_typename = -1;
2439   if (yychar == TYPENAME || yychar == PTYPENAME)
2440     {
2441       yychar = IDENTIFIER;
2442       lastiddecl = 0;
2443     }
2444 }
2445 #endif
2446
2447 #ifdef __GNUC__
2448 extern __inline int identifier_type ();
2449 __inline
2450 #endif
2451 int
2452 identifier_type (decl)
2453      tree decl;
2454 {
2455   if (TREE_CODE (decl) == TEMPLATE_DECL)
2456     {
2457       if (TREE_CODE (DECL_RESULT (decl)) == TYPE_DECL)
2458         return PTYPENAME;
2459     }
2460   if (TREE_CODE (decl) == NAMESPACE_DECL)
2461     return NSNAME;
2462   if (TREE_CODE (decl) != TYPE_DECL)
2463     return IDENTIFIER;
2464   if (((got_scope && TREE_TYPE (decl) == got_scope)
2465        || TREE_TYPE (decl) == current_class_type)
2466       && DECL_ARTIFICIAL (decl))
2467     return SELFNAME;
2468   return TYPENAME;
2469 }
2470
2471 void
2472 see_typename ()
2473 {
2474   looking_for_typename = 1;
2475   if (yychar < 0)
2476     if ((yychar = yylex ()) < 0) yychar = 0;
2477   looking_for_typename = 0;
2478   if (yychar == IDENTIFIER)
2479     {
2480       lastiddecl = lookup_name (yylval.ttype, -2);
2481       if (lastiddecl == 0)
2482         {
2483           if (flag_labels_ok)
2484             lastiddecl = IDENTIFIER_LABEL_VALUE (yylval.ttype);
2485         }
2486       else
2487         yychar = identifier_type (lastiddecl);
2488     }
2489 }
2490
2491 tree
2492 do_identifier (token, parsing)
2493      register tree token;
2494      int parsing;
2495 {
2496   register tree id;
2497
2498   if (! parsing || IDENTIFIER_OPNAME_P (token))
2499     id = lookup_name (token, 0);
2500   else
2501     id = lastiddecl;
2502
2503   if (parsing && yychar == YYEMPTY)
2504     yychar = yylex ();
2505   /* Scope class declarations before global
2506      declarations.  */
2507   if (id == IDENTIFIER_GLOBAL_VALUE (token)
2508       && current_class_type != 0
2509       && TYPE_SIZE (current_class_type) == 0)
2510     {
2511       /* Could be from one of the base classes.  */
2512       tree field = lookup_field (current_class_type, token, 1, 0);
2513       if (field == 0)
2514         ;
2515       else if (field == error_mark_node)
2516         /* We have already generated the error message.
2517            But we still want to return this value.  */
2518         id = lookup_field (current_class_type, token, 0, 0);
2519       else if (TREE_CODE (field) == VAR_DECL
2520                || TREE_CODE (field) == CONST_DECL)
2521         id = field;
2522       else if (TREE_CODE (field) != FIELD_DECL)
2523         my_friendly_abort (61);
2524       else
2525         {
2526           cp_error ("invalid use of member `%D' from base class `%T'", field,
2527                       DECL_FIELD_CONTEXT (field));
2528           id = error_mark_node;
2529           return id;
2530         }
2531     }
2532
2533   /* Remember that this name has been used in the class definition, as per
2534      [class.scope0] */
2535   if (id && current_class_type && parsing
2536       && TYPE_BEING_DEFINED (current_class_type)
2537       && ! IDENTIFIER_CLASS_VALUE (token))
2538     pushdecl_class_level (id);
2539     
2540   if (!id || id == error_mark_node)
2541     {
2542       if (id == error_mark_node && current_class_type != NULL_TREE)
2543         {
2544           id = lookup_nested_field (token, 1);
2545           /* In lookup_nested_field(), we marked this so we can gracefully
2546              leave this whole mess.  */
2547           if (id && id != error_mark_node && TREE_TYPE (id) == error_mark_node)
2548             return id;
2549         }
2550
2551       if (current_template_parms)
2552         return build_min_nt (LOOKUP_EXPR, token, NULL_TREE);
2553       else if (IDENTIFIER_OPNAME_P (token))
2554         {
2555           if (token != ansi_opname[ERROR_MARK])
2556             cp_error ("operator %O not defined", token);
2557           id = error_mark_node;
2558         }
2559       else if (parsing && (yychar == '(' || yychar == LEFT_RIGHT))
2560         {
2561           id = implicitly_declare (token);
2562         }
2563       else if (current_function_decl == 0)
2564         {
2565           cp_error ("`%D' was not declared in this scope", token);
2566           id = error_mark_node;
2567         }
2568       else
2569         {
2570           if (IDENTIFIER_GLOBAL_VALUE (token) != error_mark_node
2571               || IDENTIFIER_ERROR_LOCUS (token) != current_function_decl)
2572             {
2573               static int undeclared_variable_notice;
2574
2575               cp_error ("`%D' undeclared (first use this function)", token);
2576
2577               if (! undeclared_variable_notice)
2578                 {
2579                   error ("(Each undeclared identifier is reported only once");
2580                   error ("for each function it appears in.)");
2581                   undeclared_variable_notice = 1;
2582                 }
2583             }
2584           id = error_mark_node;
2585           /* Prevent repeated error messages.  */
2586           IDENTIFIER_GLOBAL_VALUE (token) = error_mark_node;
2587           SET_IDENTIFIER_ERROR_LOCUS (token, current_function_decl);
2588         }
2589     }
2590
2591   if (TREE_CODE (id) == VAR_DECL && DECL_DEAD_FOR_LOCAL (id))
2592     {
2593       tree shadowed = DECL_SHADOWED_FOR_VAR (id);
2594       while (shadowed != NULL_TREE && TREE_CODE (shadowed) == VAR_DECL
2595              && DECL_DEAD_FOR_LOCAL (shadowed))
2596         shadowed = DECL_SHADOWED_FOR_VAR (shadowed);
2597       if (!shadowed)
2598         shadowed = IDENTIFIER_GLOBAL_VALUE (DECL_NAME (id));
2599       if (shadowed)
2600         {
2601           if (!DECL_ERROR_REPORTED (id))
2602             {
2603               warning ("name lookup of `%s' changed",
2604                        IDENTIFIER_POINTER (token));
2605               cp_warning_at ("  matches this `%D' under current ANSI rules",
2606                              shadowed);
2607               cp_warning_at ("  matches this `%D' under old rules", id);
2608               DECL_ERROR_REPORTED (id) = 1;
2609             }
2610           id = shadowed;
2611         }
2612       else if (!DECL_ERROR_REPORTED (id))
2613         {
2614           static char msg[]
2615             = "name lookup of `%s' changed for new ANSI `for' scoping";
2616           DECL_ERROR_REPORTED (id) = 1;
2617           if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (id)))
2618             {
2619               error (msg, IDENTIFIER_POINTER (token));
2620               cp_error_at ("  cannot use obsolete binding at `%D' because it has a destructor", id);
2621               id = error_mark_node;
2622             }
2623           else
2624             {
2625               pedwarn (msg, IDENTIFIER_POINTER (token));
2626               cp_pedwarn_at ("  using obsolete binding at `%D'", id);
2627             }
2628         }
2629     }
2630   /* TREE_USED is set in `hack_identifier'.  */
2631   if (TREE_CODE (id) == CONST_DECL)
2632     {
2633       if (IDENTIFIER_CLASS_VALUE (token) == id)
2634         {
2635           /* Check access.  */
2636           tree access = compute_access (TYPE_BINFO (current_class_type), id);
2637           if (access == access_private_node)
2638             cp_error ("enum `%D' is private", id);
2639           /* protected is OK, since it's an enum of `this'.  */
2640         }
2641       if (! current_template_parms
2642           || (DECL_INITIAL (id)
2643               && TREE_CODE (DECL_INITIAL (id)) == TEMPLATE_CONST_PARM))
2644         id = DECL_INITIAL (id);
2645     }
2646   else
2647     id = hack_identifier (id, token);
2648
2649   if (current_template_parms)
2650     {
2651       if (is_overloaded_fn (id))
2652         {
2653           tree t = build_min (LOOKUP_EXPR, unknown_type_node,
2654                               token, get_first_fn (id));
2655           if (id != IDENTIFIER_GLOBAL_VALUE (token))
2656             TREE_OPERAND (t, 1) = error_mark_node;
2657           id = t;
2658         }
2659       else if (! TREE_PERMANENT (id) || TREE_CODE (id) == PARM_DECL
2660                || TREE_CODE (id) == USING_DECL)
2661         id = build_min (LOOKUP_EXPR, TREE_TYPE (id), token, error_mark_node);
2662       /* else just use the decl */
2663     }
2664       
2665   return id;
2666 }
2667
2668 tree
2669 do_scoped_id (token, parsing)
2670      tree token;
2671      int parsing;
2672 {
2673   tree id = IDENTIFIER_GLOBAL_VALUE (token);
2674   if (parsing && yychar == YYEMPTY)
2675     yychar = yylex ();
2676   if (! id)
2677     {
2678       if (current_template_parms)
2679         {
2680           id = build_min_nt (LOOKUP_EXPR, token, NULL_TREE);
2681           LOOKUP_EXPR_GLOBAL (id) = 1;
2682           return id;
2683         }
2684       if (parsing && yychar == '(' || yychar == LEFT_RIGHT)
2685         id = implicitly_declare (token);
2686       else
2687         {
2688           if (IDENTIFIER_GLOBAL_VALUE (token) != error_mark_node)
2689             error ("undeclared variable `%s' (first use here)",
2690                    IDENTIFIER_POINTER (token));
2691           id = error_mark_node;
2692           /* Prevent repeated error messages.  */
2693           IDENTIFIER_GLOBAL_VALUE (token) = error_mark_node;
2694         }
2695     }
2696   else
2697     {
2698       if (TREE_CODE (id) == ADDR_EXPR)
2699         mark_used (TREE_OPERAND (id, 0));
2700       else if (TREE_CODE (id) != TREE_LIST)
2701         mark_used (id);
2702     }
2703   if (TREE_CODE (id) == CONST_DECL && ! current_template_parms)
2704     {
2705       /* XXX CHS - should we set TREE_USED of the constant? */
2706       id = DECL_INITIAL (id);
2707       /* This is to prevent an enum whose value is 0
2708          from being considered a null pointer constant.  */
2709       id = build1 (NOP_EXPR, TREE_TYPE (id), id);
2710       TREE_CONSTANT (id) = 1;
2711     }
2712
2713   if (current_template_parms)
2714     {
2715       if (is_overloaded_fn (id))
2716         {
2717           id = build_min (LOOKUP_EXPR, unknown_type_node,
2718                           token, get_first_fn (id));
2719           LOOKUP_EXPR_GLOBAL (id) = 1;
2720         }
2721       /* else just use the decl */
2722     }
2723   return id;
2724 }
2725
2726 tree
2727 identifier_typedecl_value (node)
2728      tree node;
2729 {
2730   tree t, type;
2731   type = IDENTIFIER_TYPE_VALUE (node);
2732   if (type == NULL_TREE)
2733     return NULL_TREE;
2734 #define do(X) \
2735   { \
2736     t = (X); \
2737     if (t && TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) == type) \
2738       return t; \
2739   }
2740   do (IDENTIFIER_LOCAL_VALUE (node));
2741   do (IDENTIFIER_CLASS_VALUE (node));
2742   do (IDENTIFIER_GLOBAL_VALUE (node));
2743 #undef do
2744   /* Will this one ever happen?  */
2745   if (TYPE_NAME (type))
2746     return TYPE_NAME (type);
2747
2748   /* We used to do an internal error of 62 here, but instead we will
2749      handle the return of a null appropriately in the callers.  */
2750   return NULL_TREE;
2751 }
2752
2753 struct try_type
2754 {
2755   tree *node_var;
2756   char unsigned_flag;
2757   char long_flag;
2758   char long_long_flag;
2759 };
2760
2761 struct try_type type_sequence[] = 
2762 {
2763   { &integer_type_node, 0, 0, 0},
2764   { &unsigned_type_node, 1, 0, 0},
2765   { &long_integer_type_node, 0, 1, 0},
2766   { &long_unsigned_type_node, 1, 1, 0},
2767   { &long_long_integer_type_node, 0, 1, 1},
2768   { &long_long_unsigned_type_node, 1, 1, 1}
2769 };
2770
2771 int
2772 real_yylex ()
2773 {
2774   register int c;
2775   register int value;
2776   int wide_flag = 0;
2777   int dollar_seen = 0;
2778   int i;
2779
2780   if (nextchar >= 0)
2781     c = nextchar, nextchar = -1;
2782   else
2783     c = getch ();
2784
2785   /* Effectively do c = skip_white_space (c)
2786      but do it faster in the usual cases.  */
2787   while (1)
2788     switch (c)
2789       {
2790       case ' ':
2791       case '\t':
2792       case '\f':
2793       case '\v':
2794       case '\b':
2795         c = getch ();
2796         break;
2797
2798       case '\r':
2799         /* Call skip_white_space so we can warn if appropriate.  */
2800
2801       case '\n':
2802       case '/':
2803       case '\\':
2804         c = skip_white_space (c);
2805       default:
2806         goto found_nonwhite;
2807       }
2808  found_nonwhite:
2809
2810   token_buffer[0] = c;
2811   token_buffer[1] = 0;
2812
2813 /*  yylloc.first_line = lineno; */
2814
2815   switch (c)
2816     {
2817     case EOF:
2818       token_buffer[0] = '\0';
2819       end_of_file = 1;
2820       if (input_redirected ())
2821         value = END_OF_SAVED_INPUT;
2822       else if (linemode)
2823         value = END_OF_LINE;
2824       else
2825         value = ENDFILE;
2826       break;
2827
2828     case '$':
2829       if (dollars_in_ident)
2830         {
2831           dollar_seen = 1;
2832           goto letter;
2833         }
2834       value = '$';
2835       goto done;
2836
2837     case 'L':
2838       /* Capital L may start a wide-string or wide-character constant.  */
2839       {
2840         register int c = getch ();
2841         if (c == '\'')
2842           {
2843             wide_flag = 1;
2844             goto char_constant;
2845           }
2846         if (c == '"')
2847           {
2848             wide_flag = 1;
2849             goto string_constant;
2850           }
2851         put_back (c);
2852       }
2853
2854     case 'A':  case 'B':  case 'C':  case 'D':  case 'E':
2855     case 'F':  case 'G':  case 'H':  case 'I':  case 'J':
2856     case 'K':             case 'M':  case 'N':  case 'O':
2857     case 'P':  case 'Q':  case 'R':  case 'S':  case 'T':
2858     case 'U':  case 'V':  case 'W':  case 'X':  case 'Y':
2859     case 'Z':
2860     case 'a':  case 'b':  case 'c':  case 'd':  case 'e':
2861     case 'f':  case 'g':  case 'h':  case 'i':  case 'j':
2862     case 'k':  case 'l':  case 'm':  case 'n':  case 'o':
2863     case 'p':  case 'q':  case 'r':  case 's':  case 't':
2864     case 'u':  case 'v':  case 'w':  case 'x':  case 'y':
2865     case 'z':
2866     case '_':
2867     letter:
2868       {
2869         register char *p;
2870
2871         p = token_buffer;
2872         if (input == 0)
2873           {
2874             /* We know that `token_buffer' can hold at least on char,
2875                so we install C immediately.
2876                We may have to read the value in `putback_char', so call
2877                `getch' once.  */
2878             *p++ = c;
2879             c = getch ();
2880
2881             /* Make this run fast.  We know that we are reading straight
2882                from FINPUT in this case (since identifiers cannot straddle
2883                input sources.  */
2884             while (isalnum (c) || (c == '_') || c == '$')
2885               {
2886                 if (c == '$' && ! dollars_in_ident)
2887                   break;
2888                 if (p >= token_buffer + maxtoken)
2889                   p = extend_token_buffer (p);
2890
2891                 *p++ = c;
2892                 c = getc (finput);
2893               }
2894
2895             if (linemode && c == '\n')
2896               {
2897                 put_back (c);
2898                 c = EOF;
2899               }
2900           }
2901         else
2902           {
2903             /* We know that `token_buffer' can hold at least on char,
2904                so we install C immediately.  */
2905             *p++ = c;
2906             c = getch ();
2907
2908             while (isalnum (c) || (c == '_') || c == '$')
2909               {
2910                 if (c == '$' && ! dollars_in_ident)
2911                   break;
2912                 if (p >= token_buffer + maxtoken)
2913                   p = extend_token_buffer (p);
2914
2915                 *p++ = c;
2916                 c = getch ();
2917               }
2918           }
2919
2920         *p = 0;
2921         nextchar = c;
2922
2923         value = IDENTIFIER;
2924         yylval.itype = 0;
2925
2926       /* Try to recognize a keyword.  Uses minimum-perfect hash function */
2927
2928         {
2929           register struct resword *ptr;
2930
2931           if (ptr = is_reserved_word (token_buffer, p - token_buffer))
2932             {
2933               if (ptr->rid)
2934                 {
2935                   tree old_ttype = ridpointers[(int) ptr->rid];
2936
2937                   /* If this provides a type for us, then revert lexical
2938                      state to standard state.  */
2939                   if (TREE_CODE (old_ttype) == IDENTIFIER_NODE
2940                       && IDENTIFIER_GLOBAL_VALUE (old_ttype) != 0
2941                       && TREE_CODE (IDENTIFIER_GLOBAL_VALUE (old_ttype)) == TYPE_DECL)
2942                     looking_for_typename = 0;
2943                   else if (ptr->token == AGGR || ptr->token == ENUM)
2944                     looking_for_typename = 1;
2945
2946                   /* Check if this is a language-type declaration.
2947                      Just glimpse the next non-white character.  */
2948                   nextchar = skip_white_space (nextchar);
2949                   if (nextchar == '"')
2950                     {
2951                       /* We are looking at a string.  Complain
2952                          if the token before the string is no `extern'.
2953                          
2954                          Could cheat some memory by placing this string
2955                          on the temporary_, instead of the saveable_
2956                          obstack.  */
2957
2958                       if (ptr->rid != RID_EXTERN)
2959                         error ("invalid modifier `%s' for language string",
2960                                ptr->name);
2961                       real_yylex ();
2962                       value = EXTERN_LANG_STRING;
2963                       yylval.ttype = get_identifier (TREE_STRING_POINTER (yylval.ttype));
2964                       break;
2965                     }
2966                   if (ptr->token == VISSPEC)
2967                     {
2968                       switch (ptr->rid)
2969                         {
2970                         case RID_PUBLIC:
2971                           yylval.ttype = access_public_node;
2972                           break;
2973                         case RID_PRIVATE:
2974                           yylval.ttype = access_private_node;
2975                           break;
2976                         case RID_PROTECTED:
2977                           yylval.ttype = access_protected_node;
2978                           break;
2979                         default:
2980                           my_friendly_abort (63);
2981                         }
2982                     }
2983                   else
2984                     yylval.ttype = old_ttype;
2985                 }
2986               else if (ptr->token == EQCOMPARE)
2987                 {
2988                   yylval.code = NE_EXPR;
2989                   token_buffer[0] = '!';
2990                   token_buffer[1] = '=';
2991                   token_buffer[2] = 0;
2992                 }
2993               else if (ptr->token == ASSIGN)
2994                 {
2995                   if (strcmp ("and_eq", token_buffer) == 0)
2996                     {
2997                       yylval.code = BIT_AND_EXPR;
2998                       token_buffer[0] = '&';
2999                     }
3000                   else if (strcmp ("or_eq", token_buffer) == 0)
3001                     {
3002                       yylval.code = BIT_IOR_EXPR;
3003                       token_buffer[0] = '|';
3004                     }
3005                   else if (strcmp ("xor_eq", token_buffer) == 0)
3006                     {
3007                       yylval.code = BIT_XOR_EXPR;
3008                       token_buffer[0] = '^';
3009                     }
3010                   token_buffer[1] = '=';
3011                   token_buffer[2] = 0;
3012                 }
3013               else if (ptr->token == '&')
3014                 {
3015                   yylval.code = BIT_AND_EXPR;
3016                   token_buffer[0] = '&';
3017                   token_buffer[1] = 0;
3018                 }
3019               else if (ptr->token == '|')
3020                 {
3021                   yylval.code = BIT_IOR_EXPR;
3022                   token_buffer[0] = '|';
3023                   token_buffer[1] = 0;
3024                 }
3025               else if (ptr->token == '^')
3026                 {
3027                   yylval.code = BIT_XOR_EXPR;
3028                   token_buffer[0] = '^';
3029                   token_buffer[1] = 0;
3030                 }
3031               else if (ptr->token == NAMESPACE)
3032                 {
3033                   static int warned;
3034                   if (! warned)
3035                     warning ("namespaces are mostly broken in this version of g++");
3036
3037                   warned = 1;
3038                 }
3039
3040               value = (int) ptr->token;
3041             }
3042         }
3043
3044         /* If we did not find a keyword, look for an identifier
3045            (or a typename).  */
3046
3047         if (strcmp ("catch", token_buffer) == 0
3048             || strcmp ("throw", token_buffer) == 0
3049             || strcmp ("try", token_buffer) == 0)
3050           {
3051             static int did_warn = 0;
3052             if (! did_warn  && ! flag_handle_exceptions)
3053               {
3054                 pedwarn ("`catch', `throw', and `try' are all C++ reserved words");
3055                 did_warn = 1;
3056               }
3057           }
3058
3059         if (value == IDENTIFIER || value == TYPESPEC)
3060           GNU_xref_ref (current_function_decl, token_buffer);
3061
3062         if (value == IDENTIFIER)
3063           {
3064             register tree tmp = get_identifier (token_buffer);
3065
3066 #if !defined(VMS) && defined(JOINER)
3067             /* Make sure that user does not collide with our internal
3068                naming scheme.  */
3069             if (JOINER == '$'
3070                 && dollar_seen
3071                 && (THIS_NAME_P (tmp)
3072                     || VPTR_NAME_P (tmp)
3073                     || DESTRUCTOR_NAME_P (tmp)
3074                     || VTABLE_NAME_P (tmp)
3075                     || TEMP_NAME_P (tmp)
3076                     || ANON_AGGRNAME_P (tmp)
3077                     || ANON_PARMNAME_P (tmp)))
3078               warning ("identifier name `%s' conflicts with GNU C++ internal naming strategy",
3079                        token_buffer);
3080 #endif
3081
3082             yylval.ttype = tmp;
3083
3084             /* A user-invisible read-only initialized variable
3085                should be replaced by its value.  We only handle strings
3086                since that's the only case used in C (and C++).  */
3087             /* Note we go right after the local value for the identifier
3088                (e.g., __FUNCTION__ or __PRETTY_FUNCTION__).  We used to
3089                call lookup_name, but that could result in an error about
3090                ambiguities.  */
3091             tmp = IDENTIFIER_LOCAL_VALUE (yylval.ttype);
3092             if (tmp != NULL_TREE
3093                 && TREE_CODE (tmp) == VAR_DECL
3094                 && DECL_IGNORED_P (tmp)
3095                 && TREE_READONLY (tmp)
3096                 && DECL_INITIAL (tmp) != NULL_TREE
3097                 && TREE_CODE (DECL_INITIAL (tmp)) == STRING_CST)
3098               {
3099                 yylval.ttype = DECL_INITIAL (tmp);
3100                 value = STRING;
3101               }
3102           }
3103         if (value == NEW && ! global_bindings_p ())
3104           {
3105             value = NEW;
3106             goto done;
3107           }
3108       }
3109       break;
3110
3111     case '.':
3112       {
3113         register int c1 = getch ();
3114         token_buffer[0] = c;
3115         token_buffer[1] = c1;
3116         if (c1 == '*')
3117           {
3118             value = DOT_STAR;
3119             token_buffer[2] = 0;
3120             goto done;
3121           }
3122         if (c1 == '.')
3123           {
3124             c1 = getch ();
3125             if (c1 == '.')
3126               {
3127                 token_buffer[2] = c1;
3128                 token_buffer[3] = 0;
3129                 value = ELLIPSIS;
3130                 goto done;
3131               }
3132             error ("parse error at `..'");
3133           }
3134         if (isdigit (c1))
3135           {
3136             put_back (c1);
3137             goto resume_numerical_scan;
3138           }
3139         nextchar = c1;
3140         value = '.';
3141         token_buffer[1] = 0;
3142         goto done;
3143       }
3144     case '0':  case '1':
3145         /* Optimize for most frequent case.  */
3146       {
3147         register int c1 = getch ();
3148         if (! isalnum (c1) && c1 != '.')
3149           {
3150             /* Terminate string.  */
3151             token_buffer[0] = c;
3152             token_buffer[1] = 0;
3153             if (c == '0')
3154               yylval.ttype = integer_zero_node;
3155             else
3156               yylval.ttype = integer_one_node;
3157             nextchar = c1;
3158             value = CONSTANT;
3159             goto done;
3160           }
3161         put_back (c1);
3162       }
3163       /* fall through... */
3164                           case '2':  case '3':  case '4':
3165     case '5':  case '6':  case '7':  case '8':  case '9':
3166     resume_numerical_scan:
3167       {
3168         register char *p;
3169         int base = 10;
3170         int count = 0;
3171         int largest_digit = 0;
3172         int numdigits = 0;
3173         /* for multi-precision arithmetic,
3174            we actually store only HOST_BITS_PER_CHAR bits in each part.
3175            The number of parts is chosen so as to be sufficient to hold
3176            the enough bits to fit into the two HOST_WIDE_INTs that contain
3177            the integer value (this is always at least as many bits as are
3178            in a target `long long' value, but may be wider).  */
3179 #define TOTAL_PARTS ((HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR) * 2 + 2)
3180         int parts[TOTAL_PARTS];
3181         int overflow = 0;
3182
3183         enum anon1 { NOT_FLOAT, AFTER_POINT, TOO_MANY_POINTS} floatflag
3184           = NOT_FLOAT;
3185
3186         p = token_buffer;
3187         *p++ = c;
3188
3189         for (count = 0; count < TOTAL_PARTS; count++)
3190           parts[count] = 0;
3191
3192         if (c == '0')
3193           {
3194             *p++ = (c = getch ());
3195             if ((c == 'x') || (c == 'X'))
3196               {
3197                 base = 16;
3198                 *p++ = (c = getch ());
3199               }
3200             /* Leading 0 forces octal unless the 0 is the only digit.  */
3201             else if (c >= '0' && c <= '9')
3202               {
3203                 base = 8;
3204                 numdigits++;
3205               }
3206             else
3207               numdigits++;
3208           }
3209
3210         /* Read all the digits-and-decimal-points.  */
3211
3212         while (c == '.'
3213                || (isalnum (c) && (c != 'l') && (c != 'L')
3214                    && (c != 'u') && (c != 'U')
3215                    && (floatflag == NOT_FLOAT || ((c != 'f') && (c != 'F')))))
3216           {
3217             if (c == '.')
3218               {
3219                 if (base == 16)
3220                   error ("floating constant may not be in radix 16");
3221                 if (floatflag == AFTER_POINT)
3222                   {
3223                     error ("malformed floating constant");
3224                     floatflag = TOO_MANY_POINTS;
3225                   }
3226                 else
3227                   floatflag = AFTER_POINT;
3228
3229                 base = 10;
3230                 *p++ = c = getch ();
3231                 /* Accept '.' as the start of a floating-point number
3232                    only when it is followed by a digit.
3233                    Otherwise, unread the following non-digit
3234                    and use the '.' as a structural token.  */
3235                 if (p == token_buffer + 2 && !isdigit (c))
3236                   {
3237                     if (c == '.')
3238                       {
3239                         c = getch ();
3240                         if (c == '.')
3241                           {
3242                             *p++ = '.';
3243                             *p = '\0';
3244                             value = ELLIPSIS;
3245                             goto done;
3246                           }
3247                         error ("parse error at `..'");
3248                       }
3249                     nextchar = c;
3250                     token_buffer[1] = '\0';
3251                     value = '.';
3252                     goto done;
3253                   }
3254               }
3255             else
3256               {
3257                 /* It is not a decimal point.
3258                    It should be a digit (perhaps a hex digit).  */
3259
3260                 if (isdigit (c))
3261                   {
3262                     c = c - '0';
3263                   }
3264                 else if (base <= 10)
3265                   {
3266                     if (c == 'e' || c == 'E')
3267                       {
3268                         base = 10;
3269                         floatflag = AFTER_POINT;
3270                         break;   /* start of exponent */
3271                       }
3272                     error ("nondigits in number and not hexadecimal");
3273                     c = 0;
3274                   }
3275                 else if (c >= 'a')
3276                   {
3277                     c = c - 'a' + 10;
3278                   }
3279                 else
3280                   {
3281                     c = c - 'A' + 10;
3282                   }
3283                 if (c >= largest_digit)
3284                   largest_digit = c;
3285                 numdigits++;
3286
3287                 for (count = 0; count < TOTAL_PARTS; count++)
3288                   {
3289                     parts[count] *= base;
3290                     if (count)
3291                       {
3292                         parts[count]
3293                           += (parts[count-1] >> HOST_BITS_PER_CHAR);
3294                         parts[count-1]
3295                           &= (1 << HOST_BITS_PER_CHAR) - 1;
3296                       }
3297                     else
3298                       parts[0] += c;
3299                   }
3300
3301                 /* If the extra highest-order part ever gets anything in it,
3302                    the number is certainly too big.  */
3303                 if (parts[TOTAL_PARTS - 1] != 0)
3304                   overflow = 1;
3305
3306                 if (p >= token_buffer + maxtoken - 3)
3307                   p = extend_token_buffer (p);
3308                 *p++ = (c = getch ());
3309               }
3310           }
3311
3312         if (numdigits == 0)
3313           error ("numeric constant with no digits");
3314
3315         if (largest_digit >= base)
3316           error ("numeric constant contains digits beyond the radix");
3317
3318         /* Remove terminating char from the token buffer and delimit the string */
3319         *--p = 0;
3320
3321         if (floatflag != NOT_FLOAT)
3322           {
3323             tree type = double_type_node;
3324             char f_seen = 0;
3325             char l_seen = 0;
3326             int garbage_chars = 0;
3327             REAL_VALUE_TYPE value;
3328             jmp_buf handler;
3329
3330             /* Read explicit exponent if any, and put it in tokenbuf.  */
3331
3332             if ((c == 'e') || (c == 'E'))
3333               {
3334                 if (p >= token_buffer + maxtoken - 3)
3335                   p = extend_token_buffer (p);
3336                 *p++ = c;
3337                 c = getch ();
3338                 if ((c == '+') || (c == '-'))
3339                   {
3340                     *p++ = c;
3341                     c = getch ();
3342                   }
3343                 if (! isdigit (c))
3344                   error ("floating constant exponent has no digits");
3345                 while (isdigit (c))
3346                   {
3347                     if (p >= token_buffer + maxtoken - 3)
3348                       p = extend_token_buffer (p);
3349                     *p++ = c;
3350                     c = getch ();
3351                   }
3352               }
3353
3354             *p = 0;
3355             errno = 0;
3356
3357             /* Convert string to a double, checking for overflow.  */
3358             if (setjmp (handler))
3359               {
3360                 error ("floating constant out of range");
3361                 value = dconst0;
3362               }
3363             else
3364               {
3365                 set_float_handler (handler);
3366                 /*  The second argument, machine_mode, of REAL_VALUE_ATOF
3367                     tells the desired precision of the binary result of
3368                     decimal-to-binary conversion. */
3369
3370                 /* Read the suffixes to choose a data type.  */
3371                 switch (c)
3372                   {
3373                   case 'f': case 'F':
3374                     type = float_type_node;
3375                     value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type));
3376                     garbage_chars = -1;
3377                     break;
3378
3379                   case 'l': case 'L':
3380                     type = long_double_type_node;
3381                     value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type));
3382                     garbage_chars = -1;
3383                     break;
3384
3385                   default:
3386                     value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type));
3387                   }
3388                 set_float_handler (NULL_PTR);
3389               }
3390             if (pedantic
3391                 && (REAL_VALUE_ISINF (value)
3392 #ifdef ERANGE
3393                     || (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
3394                         && errno == ERANGE
3395                         /* ERANGE is also reported for underflow, so test the
3396                            value to distinguish overflow from that.  */
3397                         && (REAL_VALUES_LESS (dconst1, value)
3398                             || REAL_VALUES_LESS (value, dconstm1)))
3399 #endif
3400                     ))
3401               {
3402                 pedwarn ("floating point number exceeds range of `%s'",
3403                          IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
3404               }
3405             /* Note: garbage_chars is -1 if first char is *not* garbage.  */
3406             while (isalnum (c))
3407               {
3408                 if (c == 'f' || c == 'F')
3409                   {
3410                     if (f_seen)
3411                       error ("two `f's in floating constant");
3412                     f_seen = 1;
3413                   }
3414                 if (c == 'l' || c == 'L')
3415                   {
3416                     if (l_seen)
3417                       error ("two `l's in floating constant");
3418                     l_seen = 1;
3419                   }
3420                 if (p >= token_buffer + maxtoken - 3)
3421                   p = extend_token_buffer (p);
3422                 *p++ = c;
3423                 c = getch ();
3424                 garbage_chars++;
3425               }
3426
3427             if (garbage_chars > 0)
3428               error ("garbage at end of number");
3429
3430             /* Create a node with determined type and value.  */
3431             yylval.ttype = build_real (type, value);
3432
3433             put_back (c);
3434             *p = 0;
3435           }
3436         else
3437           {
3438             tree type;
3439             HOST_WIDE_INT high, low;
3440             int spec_unsigned = 0;
3441             int spec_long = 0;
3442             int spec_long_long = 0;
3443             int bytes, warn;
3444
3445             while (1)
3446               {
3447                 if (c == 'u' || c == 'U')
3448                   {
3449                     if (spec_unsigned)
3450                       error ("two `u's in integer constant");
3451                     spec_unsigned = 1;
3452                   }
3453                 else if (c == 'l' || c == 'L')
3454                   {
3455                     if (spec_long)
3456                       {
3457                         if (spec_long_long)
3458                           error ("three `l's in integer constant");
3459                         else if (pedantic)
3460                           pedwarn ("ANSI C++ forbids long long integer constants");
3461                         spec_long_long = 1;
3462                       }
3463                     spec_long = 1;
3464                   }
3465                 else
3466                   {
3467                     if (isalnum (c))
3468                       {
3469                         error ("garbage at end of number");
3470                         while (isalnum (c))
3471                           {
3472                             if (p >= token_buffer + maxtoken - 3)
3473                               p = extend_token_buffer (p);
3474                             *p++ = c;
3475                             c = getch ();
3476                           }
3477                       }
3478                     break;
3479                   }
3480                 if (p >= token_buffer + maxtoken - 3)
3481                   p = extend_token_buffer (p);
3482                 *p++ = c;
3483                 c = getch ();
3484               }
3485
3486             put_back (c);
3487
3488             /* If the constant is not long long and it won't fit in an
3489                unsigned long, or if the constant is long long and won't fit
3490                in an unsigned long long, then warn that the constant is out
3491                of range.  */
3492
3493             /* ??? This assumes that long long and long integer types are
3494                a multiple of 8 bits.  This better than the original code
3495                though which assumed that long was exactly 32 bits and long
3496                long was exactly 64 bits.  */
3497
3498             if (spec_long_long)
3499               bytes = TYPE_PRECISION (long_long_integer_type_node) / 8;
3500             else
3501               bytes = TYPE_PRECISION (long_integer_type_node) / 8;
3502
3503             warn = overflow;
3504             for (i = bytes; i < TOTAL_PARTS; i++)
3505               if (parts[i])
3506                 warn = 1;
3507             if (warn)
3508               pedwarn ("integer constant out of range");
3509
3510             /* This is simplified by the fact that our constant
3511                is always positive.  */
3512             high = low = 0;
3513
3514             for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR; i++)
3515               {
3516                 high |= ((HOST_WIDE_INT) parts[i + (HOST_BITS_PER_WIDE_INT
3517                                                     / HOST_BITS_PER_CHAR)]
3518                          << (i * HOST_BITS_PER_CHAR));
3519                 low |= (HOST_WIDE_INT) parts[i] << (i * HOST_BITS_PER_CHAR);
3520               }
3521             
3522             
3523             yylval.ttype = build_int_2 (low, high);
3524             TREE_TYPE (yylval.ttype) = long_long_unsigned_type_node;
3525
3526 #if 0
3527             /* Find the first allowable type that the value fits in.  */
3528             type = 0;
3529             for (i = 0; i < sizeof (type_sequence) / sizeof (type_sequence[0]);
3530                  i++)
3531               if (!(spec_long && !type_sequence[i].long_flag)
3532                   && !(spec_long_long && !type_sequence[i].long_long_flag)
3533                   && !(spec_unsigned && !type_sequence[i].unsigned_flag)
3534                   /* A hex or octal constant traditionally is unsigned.  */
3535                   && !(base != 10 && flag_traditional
3536                        && !type_sequence[i].unsigned_flag)
3537                   /* A decimal constant can't be unsigned int
3538                      unless explicitly specified.  */
3539                   && !(base == 10 && !spec_unsigned
3540                        && *type_sequence[i].node_var == unsigned_type_node))
3541                 if (int_fits_type_p (yylval.ttype, *type_sequence[i].node_var))
3542                   {
3543                     type = *type_sequence[i].node_var;
3544                     break;
3545                   }
3546             if (flag_traditional && type == long_unsigned_type_node
3547                 && !spec_unsigned)
3548               type = long_integer_type_node;
3549               
3550             if (type == 0)
3551               {
3552                 type = long_long_integer_type_node;
3553                 warning ("integer constant out of range");
3554               }
3555
3556             /* Warn about some cases where the type of a given constant
3557                changes from traditional C to ANSI C.  */
3558             if (warn_traditional)
3559               {
3560                 tree other_type = 0;
3561
3562                 /* This computation is the same as the previous one
3563                    except that flag_traditional is used backwards.  */
3564                 for (i = 0; i < sizeof (type_sequence) / sizeof (type_sequence[0]);
3565                      i++)
3566                   if (!(spec_long && !type_sequence[i].long_flag)
3567                       && !(spec_long_long && !type_sequence[i].long_long_flag)
3568                       && !(spec_unsigned && !type_sequence[i].unsigned_flag)
3569                       /* A hex or octal constant traditionally is unsigned.  */
3570                       && !(base != 10 && !flag_traditional
3571                            && !type_sequence[i].unsigned_flag)
3572                       /* A decimal constant can't be unsigned int
3573                          unless explicitly specified.  */
3574                       && !(base == 10 && !spec_unsigned
3575                            && *type_sequence[i].node_var == unsigned_type_node))
3576                     if (int_fits_type_p (yylval.ttype, *type_sequence[i].node_var))
3577                       {
3578                         other_type = *type_sequence[i].node_var;
3579                         break;
3580                       }
3581                 if (!flag_traditional && type == long_unsigned_type_node
3582                     && !spec_unsigned)
3583                   type = long_integer_type_node;
3584               
3585                 if (other_type != 0 && other_type != type)
3586                   {
3587                     if (flag_traditional)
3588                       warning ("type of integer constant would be different without -traditional");
3589                     else
3590                       warning ("type of integer constant would be different with -traditional");
3591                   }
3592               }
3593
3594 #else /* 1 */
3595             if (!spec_long && !spec_unsigned
3596                 && !(flag_traditional && base != 10)
3597                 && int_fits_type_p (yylval.ttype, integer_type_node))
3598               {
3599 #if 0
3600                 if (warn_traditional && base != 10)
3601                   warning ("small nondecimal constant becomes signed in ANSI C++");
3602 #endif
3603                 type = integer_type_node;
3604               }
3605             else if (!spec_long && (base != 10 || spec_unsigned)
3606                      && int_fits_type_p (yylval.ttype, unsigned_type_node))
3607               {
3608                 /* Nondecimal constants try unsigned even in traditional C.  */
3609                 type = unsigned_type_node;
3610               }
3611
3612             else if (!spec_unsigned && !spec_long_long
3613                      && int_fits_type_p (yylval.ttype, long_integer_type_node))
3614               type = long_integer_type_node;
3615
3616             else if (! spec_long_long
3617                      && int_fits_type_p (yylval.ttype,
3618                                          long_unsigned_type_node))
3619               {
3620 #if 0
3621                 if (warn_traditional && !spec_unsigned)
3622                   warning ("large integer constant becomes unsigned in ANSI C++");
3623 #endif
3624                 if (flag_traditional && !spec_unsigned)
3625                   type = long_integer_type_node;
3626                 else
3627                   type = long_unsigned_type_node;
3628               }
3629
3630             else if (! spec_unsigned
3631                      /* Verify value does not overflow into sign bit.  */
3632                      && TREE_INT_CST_HIGH (yylval.ttype) >= 0
3633                      && int_fits_type_p (yylval.ttype,
3634                                          long_long_integer_type_node))
3635               type = long_long_integer_type_node;
3636
3637             else if (int_fits_type_p (yylval.ttype,
3638                                       long_long_unsigned_type_node))
3639               {
3640 #if 0
3641                 if (warn_traditional && !spec_unsigned)
3642                   warning ("large nondecimal constant is unsigned in ANSI C++");
3643 #endif
3644
3645                 if (flag_traditional && !spec_unsigned)
3646                   type = long_long_integer_type_node;
3647                 else
3648                   type = long_long_unsigned_type_node;
3649               }
3650
3651             else
3652               {
3653                 type = long_long_integer_type_node;
3654                 warning ("integer constant out of range");
3655
3656                 if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
3657                   warning ("decimal integer constant is so large that it is unsigned");
3658               }
3659 #endif
3660
3661             TREE_TYPE (yylval.ttype) = type;
3662             *p = 0;
3663           }
3664
3665         value = CONSTANT; break;
3666       }
3667
3668     case '\'':
3669     char_constant:
3670       {
3671         register int result = 0;
3672         register int num_chars = 0;
3673         unsigned width = TYPE_PRECISION (char_type_node);
3674         int max_chars;
3675
3676         if (wide_flag)
3677           {
3678             width = WCHAR_TYPE_SIZE;
3679 #ifdef MULTIBYTE_CHARS
3680             max_chars = MB_CUR_MAX;
3681 #else
3682             max_chars = 1;
3683 #endif
3684           }
3685         else
3686           max_chars = TYPE_PRECISION (integer_type_node) / width;
3687
3688         while (1)
3689           {
3690           tryagain:
3691
3692             c = getch ();
3693
3694             if (c == '\'' || c == EOF)
3695               break;
3696
3697             if (c == '\\')
3698               {
3699                 int ignore = 0;
3700                 c = readescape (&ignore);
3701                 if (ignore)
3702                   goto tryagain;
3703                 if (width < HOST_BITS_PER_INT
3704                     && (unsigned) c >= (1 << width))
3705                   warning ("escape sequence out of range for character");
3706 #ifdef MAP_CHARACTER
3707                 if (isprint (c))
3708                   c = MAP_CHARACTER (c);
3709 #endif
3710               }
3711             else if (c == '\n')
3712               {
3713                 if (pedantic)
3714                   pedwarn ("ANSI C++ forbids newline in character constant");
3715                 lineno++;
3716               }
3717 #ifdef MAP_CHARACTER
3718             else
3719               c = MAP_CHARACTER (c);
3720 #endif
3721
3722             num_chars++;
3723             if (num_chars > maxtoken - 4)
3724               extend_token_buffer (token_buffer);
3725
3726             token_buffer[num_chars] = c;
3727
3728             /* Merge character into result; ignore excess chars.  */
3729             if (num_chars < max_chars + 1)
3730               {
3731                 if (width < HOST_BITS_PER_INT)
3732                   result = (result << width) | (c & ((1 << width) - 1));
3733                 else
3734                   result = c;
3735               }
3736           }
3737
3738         token_buffer[num_chars + 1] = '\'';
3739         token_buffer[num_chars + 2] = 0;
3740
3741         if (c != '\'')
3742           error ("malformatted character constant");
3743         else if (num_chars == 0)
3744           error ("empty character constant");
3745         else if (num_chars > max_chars)
3746           {
3747             num_chars = max_chars;
3748             error ("character constant too long");
3749           }
3750         else if (num_chars != 1 && ! flag_traditional)
3751           warning ("multi-character character constant");
3752
3753         /* If char type is signed, sign-extend the constant.  */
3754         if (! wide_flag)
3755           {
3756             int num_bits = num_chars * width;
3757             if (num_bits == 0)
3758               /* We already got an error; avoid invalid shift.  */
3759               yylval.ttype = build_int_2 (0, 0);
3760             else if (TREE_UNSIGNED (char_type_node)
3761                      || ((result >> (num_bits - 1)) & 1) == 0)
3762               yylval.ttype
3763                 = build_int_2 (result & ((unsigned HOST_WIDE_INT) ~0
3764                                          >> (HOST_BITS_PER_WIDE_INT - num_bits)),
3765                                0);
3766             else
3767               yylval.ttype
3768                 = build_int_2 (result | ~((unsigned HOST_WIDE_INT) ~0
3769                                           >> (HOST_BITS_PER_WIDE_INT - num_bits)),
3770                                -1);
3771             if (num_chars<=1)
3772               TREE_TYPE (yylval.ttype) = char_type_node;
3773             else
3774               TREE_TYPE (yylval.ttype) = integer_type_node;
3775           }
3776         else
3777           {
3778 #ifdef MULTIBYTE_CHARS
3779             /* Set the initial shift state and convert the next sequence.  */
3780             result = 0;
3781             /* In all locales L'\0' is zero and mbtowc will return zero,
3782                so don't use it.  */
3783             if (num_chars > 1
3784                 || (num_chars == 1 && token_buffer[1] != '\0'))
3785               {
3786                 wchar_t wc;
3787                 (void) mbtowc (NULL, NULL, 0);
3788                 if (mbtowc (& wc, token_buffer + 1, num_chars) == num_chars)
3789                   result = wc;
3790                 else
3791                   warning ("Ignoring invalid multibyte character");
3792               }
3793 #endif
3794             yylval.ttype = build_int_2 (result, 0);
3795             TREE_TYPE (yylval.ttype) = wchar_type_node;
3796           }
3797
3798         value = CONSTANT;
3799         break;
3800       }
3801
3802     case '"':
3803     string_constant:
3804       {
3805         register char *p;
3806
3807         c = getch ();
3808         p = token_buffer + 1;
3809
3810         while (c != '"' && c >= 0)
3811           {
3812             /* ignore_escape_flag is set for reading the filename in #line.  */
3813             if (!ignore_escape_flag && c == '\\')
3814               {
3815                 int ignore = 0;
3816                 c = readescape (&ignore);
3817                 if (ignore)
3818                   goto skipnewline;
3819                 if (!wide_flag
3820                     && TYPE_PRECISION (char_type_node) < HOST_BITS_PER_INT
3821                     && c >= ((unsigned) 1 << TYPE_PRECISION (char_type_node)))
3822                   warning ("escape sequence out of range for character");
3823               }
3824             else if (c == '\n')
3825               {
3826                 if (pedantic)
3827                   pedwarn ("ANSI C++ forbids newline in string constant");
3828                 lineno++;
3829               }
3830
3831             if (p == token_buffer + maxtoken)
3832               p = extend_token_buffer (p);
3833             *p++ = c;
3834
3835           skipnewline:
3836             c = getch ();
3837             if (c == EOF) {
3838                 error ("Unterminated string");
3839                 break;
3840             }
3841           }
3842         *p = 0;
3843
3844         /* We have read the entire constant.
3845            Construct a STRING_CST for the result.  */
3846
3847         if (wide_flag)
3848           {
3849             /* If this is a L"..." wide-string, convert the multibyte string
3850                to a wide character string.  */
3851             char *widep = (char *) alloca ((p - token_buffer) * WCHAR_BYTES);
3852             int len;
3853
3854 #ifdef MULTIBYTE_CHARS
3855             len = mbstowcs ((wchar_t *) widep, token_buffer + 1, p - token_buffer);
3856             if (len < 0 || len >= (p - token_buffer))
3857               {
3858                 warning ("Ignoring invalid multibyte string");
3859                 len = 0;
3860               }
3861             bzero (widep + (len * WCHAR_BYTES), WCHAR_BYTES);
3862 #else
3863             {
3864               union { long l; char c[sizeof (long)]; } u;
3865               int big_endian;
3866               char *wp, *cp;
3867
3868               /* Determine whether host is little or big endian.  */
3869               u.l = 1;
3870               big_endian = u.c[sizeof (long) - 1];
3871               wp = widep + (big_endian ? WCHAR_BYTES - 1 : 0);
3872
3873               bzero (widep, (p - token_buffer) * WCHAR_BYTES);
3874               for (cp = token_buffer + 1; cp < p; cp++)
3875                 *wp = *cp, wp += WCHAR_BYTES;
3876               len = p - token_buffer - 1;
3877             }
3878 #endif
3879             if (current_template_parms)
3880               push_obstacks (&permanent_obstack, &permanent_obstack);
3881             yylval.ttype = build_string ((len + 1) * WCHAR_BYTES, widep);
3882             if (current_template_parms)
3883               pop_obstacks ();
3884             TREE_TYPE (yylval.ttype) = wchar_array_type_node;
3885           }
3886         else
3887           {
3888             if (current_template_parms)
3889               push_obstacks (&permanent_obstack, &permanent_obstack);
3890             yylval.ttype = build_string (p - token_buffer, token_buffer + 1);
3891             if (current_template_parms)
3892               pop_obstacks ();
3893             TREE_TYPE (yylval.ttype) = char_array_type_node;
3894           }
3895
3896         *p++ = '"';
3897         *p = 0;
3898
3899         value = STRING; break;
3900       }
3901
3902     case '+':
3903     case '-':
3904     case '&':
3905     case '|':
3906     case '<':
3907     case '>':
3908     case '*':
3909     case '/':
3910     case '%':
3911     case '^':
3912     case '!':
3913     case '=':
3914       {
3915         register int c1;
3916
3917       combine:
3918
3919         switch (c)
3920           {
3921           case '+':
3922             yylval.code = PLUS_EXPR; break;
3923           case '-':
3924             yylval.code = MINUS_EXPR; break;
3925           case '&':
3926             yylval.code = BIT_AND_EXPR; break;
3927           case '|':
3928             yylval.code = BIT_IOR_EXPR; break;
3929           case '*':
3930             yylval.code = MULT_EXPR; break;
3931           case '/':
3932             yylval.code = TRUNC_DIV_EXPR; break;
3933           case '%':
3934             yylval.code = TRUNC_MOD_EXPR; break;
3935           case '^':
3936             yylval.code = BIT_XOR_EXPR; break;
3937           case LSHIFT:
3938             yylval.code = LSHIFT_EXPR; break;
3939           case RSHIFT:
3940             yylval.code = RSHIFT_EXPR; break;
3941           case '<':
3942             yylval.code = LT_EXPR; break;
3943           case '>':
3944             yylval.code = GT_EXPR; break;
3945           }
3946
3947         token_buffer[1] = c1 = getch ();
3948         token_buffer[2] = 0;
3949
3950         if (c1 == '=')
3951           {
3952             switch (c)
3953               {
3954               case '<':
3955                 value = ARITHCOMPARE; yylval.code = LE_EXPR; goto done;
3956               case '>':
3957                 value = ARITHCOMPARE; yylval.code = GE_EXPR; goto done;
3958               case '!':
3959                 value = EQCOMPARE; yylval.code = NE_EXPR; goto done;
3960               case '=':
3961                 value = EQCOMPARE; yylval.code = EQ_EXPR; goto done;
3962               }
3963             value = ASSIGN; goto done;
3964           }
3965         else if (c == c1)
3966           switch (c)
3967             {
3968             case '+':
3969               value = PLUSPLUS; goto done;
3970             case '-':
3971               value = MINUSMINUS; goto done;
3972             case '&':
3973               value = ANDAND; goto done;
3974             case '|':
3975               value = OROR; goto done;
3976             case '<':
3977               c = LSHIFT;
3978               goto combine;
3979             case '>':
3980               c = RSHIFT;
3981               goto combine;
3982             }
3983         else if ((c == '-') && (c1 == '>'))
3984           {
3985             nextchar = getch ();
3986             if (nextchar == '*')
3987               {
3988                 nextchar = -1;
3989                 value = POINTSAT_STAR;
3990               }
3991             else
3992               value = POINTSAT;
3993             goto done;
3994           }
3995         else if (c1 == '?' && (c == '<' || c == '>'))
3996           {
3997             token_buffer[3] = 0;
3998
3999             c1 = getch ();
4000             yylval.code = (c == '<' ? MIN_EXPR : MAX_EXPR);
4001             if (c1 == '=')
4002               {
4003                 /* <?= or >?= expression.  */
4004                 token_buffer[2] = c1;
4005                 value = ASSIGN;
4006               }
4007             else
4008               {
4009                 value = MIN_MAX;
4010                 nextchar = c1;
4011               }
4012             if (pedantic)
4013               pedwarn ("use of `operator %s' is not standard C++",
4014                        token_buffer);
4015             goto done;
4016           }
4017         /* digraphs */
4018         else if (c == '<' && c1 == '%')
4019           { value = '{'; goto done; }
4020         else if (c == '<' && c1 == ':')
4021           { value = '['; goto done; }
4022         else if (c == '%' && c1 == '>')
4023           { value = '}'; goto done; }
4024         else if (c == '%' && c1 == ':')
4025           { value = '#'; goto done; }
4026
4027         nextchar = c1;
4028         token_buffer[1] = 0;
4029
4030         value = c;
4031         goto done;
4032       }
4033
4034     case ':':
4035       c = getch ();
4036       if (c == ':')
4037         {
4038           token_buffer[1] = ':';
4039           token_buffer[2] = '\0';
4040           value = SCOPE;
4041           yylval.itype = 1;
4042         }
4043       else if (c == '>')
4044         {
4045           value = ']';
4046           goto done;
4047         }
4048       else
4049         {
4050           nextchar = c;
4051           value = ':';
4052         }
4053       break;
4054
4055     case 0:
4056       /* Don't make yyparse think this is eof.  */
4057       value = 1;
4058       break;
4059
4060     case '(':
4061       /* try, weakly, to handle casts to pointers to functions.  */
4062       nextchar = skip_white_space (getch ());
4063       if (nextchar == '*')
4064         {
4065           int next_c = skip_white_space (getch ());
4066           if (next_c == ')')
4067             {
4068               nextchar = -1;
4069               yylval.ttype = build1 (INDIRECT_REF, 0, 0);
4070               value = PAREN_STAR_PAREN;
4071             }
4072           else
4073             {
4074               put_back (next_c);
4075               value = c;
4076             }
4077         }
4078       else if (nextchar == ')')
4079         {
4080           nextchar = -1;
4081           yylval.ttype = NULL_TREE;
4082           value = LEFT_RIGHT;
4083         }
4084       else value = c;
4085       break;
4086
4087     default:
4088       value = c;
4089     }
4090
4091 done:
4092 /*  yylloc.last_line = lineno; */
4093 #ifdef GATHER_STATISTICS
4094 #ifdef REDUCE_LENGTH
4095   token_count[value] += 1;
4096 #endif
4097 #endif
4098
4099   return value;
4100 }
4101
4102 int
4103 is_rid (t)
4104      tree t;
4105 {
4106   return !!is_reserved_word (IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
4107 }
4108
4109 #ifdef GATHER_STATISTICS
4110 extern int tree_node_counts[];
4111 extern int tree_node_sizes[];
4112 #endif
4113
4114 /* Place to save freed lang_decls which were allocated on the
4115    permanent_obstack.  @@ Not currently used.  */
4116 tree free_lang_decl_chain;
4117
4118 tree
4119 build_lang_decl (code, name, type)
4120      enum tree_code code;
4121      tree name;
4122      tree type;
4123 {
4124   register tree t = build_decl (code, name, type);
4125   struct obstack *obstack = current_obstack;
4126   register int i = sizeof (struct lang_decl) / sizeof (int);
4127   register int *pi;
4128
4129   if (! TREE_PERMANENT (t))
4130     obstack = saveable_obstack;
4131   else
4132     /* Could be that saveable is permanent and current is not.  */
4133     obstack = &permanent_obstack;
4134
4135   if (free_lang_decl_chain && obstack == &permanent_obstack)
4136     {
4137       pi = (int *)free_lang_decl_chain;
4138       free_lang_decl_chain = TREE_CHAIN (free_lang_decl_chain);
4139     }
4140   else
4141     pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl));
4142
4143   while (i > 0)
4144     pi[--i] = 0;
4145
4146   DECL_LANG_SPECIFIC (t) = (struct lang_decl *) pi;
4147   LANG_DECL_PERMANENT ((struct lang_decl *) pi)
4148     = obstack == &permanent_obstack;
4149   my_friendly_assert (LANG_DECL_PERMANENT ((struct lang_decl *) pi)
4150           == TREE_PERMANENT  (t), 234);
4151   DECL_MAIN_VARIANT (t) = t;
4152   if (current_lang_name == lang_name_cplusplus)
4153     {
4154       DECL_LANGUAGE (t) = lang_cplusplus;
4155 #if 0
4156 #ifndef NO_AUTO_OVERLOAD
4157       if (code == FUNCTION_DECL && name != 0
4158           && ! (IDENTIFIER_LENGTH (name) == 4
4159                 && IDENTIFIER_POINTER (name)[0] == 'm'
4160                 && strcmp (IDENTIFIER_POINTER (name), "main") == 0)
4161           && ! (IDENTIFIER_LENGTH (name) > 10
4162                 && IDENTIFIER_POINTER (name)[0] == '_'
4163                 && IDENTIFIER_POINTER (name)[1] == '_'
4164                 && strncmp (IDENTIFIER_POINTER (name)+2, "builtin_", 8) == 0))
4165         TREE_OVERLOADED (name) = 1;
4166 #endif
4167 #endif
4168     }
4169   else if (current_lang_name == lang_name_c)
4170     DECL_LANGUAGE (t) = lang_c;
4171   else my_friendly_abort (64);
4172
4173 #if 0 /* not yet, should get fixed properly later */
4174   if (code == TYPE_DECL)
4175     {
4176       tree id;
4177       id = get_identifier (build_overload_name (type, 1, 1));
4178       DECL_ASSEMBLER_NAME (t) = id;
4179     }
4180
4181 #endif
4182 #ifdef GATHER_STATISTICS
4183   tree_node_counts[(int)lang_decl] += 1;
4184   tree_node_sizes[(int)lang_decl] += sizeof (struct lang_decl);
4185 #endif
4186
4187   return t;
4188 }
4189
4190 tree
4191 build_lang_field_decl (code, name, type)
4192      enum tree_code code;
4193      tree name;
4194      tree type;
4195 {
4196   extern struct obstack *current_obstack, *saveable_obstack;
4197   register tree t = build_decl (code, name, type);
4198   struct obstack *obstack = current_obstack;
4199   register int i = sizeof (struct lang_decl_flags) / sizeof (int);
4200   register int *pi;
4201 #if 0 /* not yet, should get fixed properly later */
4202
4203   if (code == TYPE_DECL)
4204     {
4205       tree id;
4206       id = get_identifier (build_overload_name (type, 1, 1));
4207       DECL_ASSEMBLER_NAME (t) = id;
4208     }
4209 #endif
4210
4211   if (! TREE_PERMANENT (t))
4212     obstack = saveable_obstack;
4213   else
4214     my_friendly_assert (obstack == &permanent_obstack, 235);
4215
4216   pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl_flags));
4217   while (i > 0)
4218     pi[--i] = 0;
4219
4220   DECL_LANG_SPECIFIC (t) = (struct lang_decl *) pi;
4221   return t;
4222 }
4223
4224 void
4225 copy_lang_decl (node)
4226      tree node;
4227 {
4228   int size;
4229   int *pi;
4230
4231   if (! DECL_LANG_SPECIFIC (node))
4232     return;
4233
4234   if (TREE_CODE (node) == FIELD_DECL)
4235     size = sizeof (struct lang_decl_flags);
4236   else
4237     size = sizeof (struct lang_decl);
4238   pi = (int *)obstack_alloc (&permanent_obstack, size);
4239   bcopy ((char *)DECL_LANG_SPECIFIC (node), (char *)pi, size);
4240   DECL_LANG_SPECIFIC (node) = (struct lang_decl *)pi;
4241 }
4242
4243 tree
4244 make_lang_type (code)
4245      enum tree_code code;
4246 {
4247   extern struct obstack *current_obstack, *saveable_obstack;
4248   register tree t = make_node (code);
4249   struct obstack *obstack = current_obstack;
4250   register int i = sizeof (struct lang_type) / sizeof (int);
4251   register int *pi;
4252
4253   /* Set up some flags that give proper default behavior.  */
4254   IS_AGGR_TYPE (t) = 1;
4255
4256   if (! TREE_PERMANENT (t))
4257     obstack = saveable_obstack;
4258   else
4259     my_friendly_assert (obstack == &permanent_obstack, 236);
4260
4261   pi = (int *) obstack_alloc (obstack, sizeof (struct lang_type));
4262   while (i > 0)
4263     pi[--i] = 0;
4264
4265   TYPE_LANG_SPECIFIC (t) = (struct lang_type *) pi;
4266   CLASSTYPE_AS_LIST (t) = build_tree_list (NULL_TREE, t);
4267   SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
4268   CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
4269   CLASSTYPE_VBASE_SIZE (t) = integer_zero_node;
4270   TYPE_BINFO (t) = make_binfo (integer_zero_node, t, NULL_TREE, NULL_TREE,
4271                                NULL_TREE);
4272   CLASSTYPE_BINFO_AS_LIST (t) = build_tree_list (NULL_TREE, TYPE_BINFO (t));
4273
4274   /* Make sure this is laid out, for ease of use later.
4275      In the presence of parse errors, the normal was of assuring
4276      this might not ever get executed, so we lay it out *immediately*.  */
4277   build_pointer_type (t);
4278
4279 #ifdef GATHER_STATISTICS
4280   tree_node_counts[(int)lang_type] += 1;
4281   tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
4282 #endif
4283
4284   return t;
4285 }
4286
4287 void
4288 copy_decl_lang_specific (decl)
4289      tree decl;
4290 {
4291   extern struct obstack *current_obstack, *saveable_obstack;
4292   register int *old = (int *)DECL_LANG_SPECIFIC (decl);
4293   struct obstack *obstack = current_obstack;
4294   register int i = sizeof (struct lang_decl) / sizeof (int);
4295   register int *pi;
4296
4297   if (! TREE_PERMANENT (decl))
4298     obstack = saveable_obstack;
4299   else
4300     my_friendly_assert (obstack == &permanent_obstack, 237);
4301
4302   pi = (int *) obstack_alloc (obstack, sizeof (struct lang_decl));
4303   while (i-- > 0)
4304     pi[i] = old[i];
4305
4306   DECL_LANG_SPECIFIC (decl) = (struct lang_decl *) pi;
4307
4308 #ifdef GATHER_STATISTICS
4309   tree_node_counts[(int)lang_decl] += 1;
4310   tree_node_sizes[(int)lang_decl] += sizeof (struct lang_decl);
4311 #endif
4312 }
4313
4314 void
4315 dump_time_statistics ()
4316 {
4317   register tree prev = 0, decl, next;
4318   int this_time = my_get_run_time ();
4319   TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (this_filename_time))
4320     += this_time - body_time;
4321
4322   fprintf (stderr, "\n******\n");
4323   print_time ("header files (total)", header_time);
4324   print_time ("main file (total)", this_time - body_time);
4325   fprintf (stderr, "ratio = %g : 1\n",
4326            (double)header_time / (double)(this_time - body_time));
4327   fprintf (stderr, "\n******\n");
4328
4329   for (decl = filename_times; decl; decl = next)
4330     {
4331       next = IDENTIFIER_GLOBAL_VALUE (decl);
4332       IDENTIFIER_GLOBAL_VALUE (decl) = prev;
4333       prev = decl;
4334     }
4335
4336   for (decl = prev; decl; decl = IDENTIFIER_GLOBAL_VALUE (decl))
4337     print_time (IDENTIFIER_POINTER (decl),
4338                 TREE_INT_CST_LOW (IDENTIFIER_LOCAL_VALUE (decl)));
4339 }
4340
4341 void
4342 compiler_error (s, v, v2)
4343      char *s;
4344      HOST_WIDE_INT v, v2;                       /* @@also used as pointer */
4345 {
4346   char buf[1024];
4347   sprintf (buf, s, v, v2);
4348   error_with_file_and_line (input_filename, lineno, "%s (compiler error)", buf);
4349 }
4350 \f
4351 void
4352 yyerror (string)
4353      char *string;
4354 {
4355   extern int end_of_file;
4356   char buf[200];
4357
4358   strcpy (buf, string);
4359
4360   /* We can't print string and character constants well
4361      because the token_buffer contains the result of processing escapes.  */
4362   if (end_of_file)
4363     strcat (buf, input_redirected ()
4364             ? " at end of saved text"
4365             : " at end of input");
4366   else if (token_buffer[0] == 0)
4367     strcat (buf, " at null character");
4368   else if (token_buffer[0] == '"')
4369     strcat (buf, " before string constant");
4370   else if (token_buffer[0] == '\'')
4371     strcat (buf, " before character constant");
4372   else if (token_buffer[0] < 040 || (unsigned char) token_buffer[0] >= 0177)
4373     sprintf (buf + strlen (buf), " before character 0%o",
4374              (unsigned char) token_buffer[0]);
4375   else
4376     strcat (buf, " before `%s'");
4377
4378   error (buf, token_buffer);
4379 }
4380 \f
4381 int
4382 handle_cp_pragma (pname)
4383      char *pname;
4384 {
4385   register int token;
4386
4387   if (! strcmp (pname, "vtable"))
4388     {
4389       extern tree pending_vtables;
4390
4391       /* More follows: it must be a string constant (class name).  */
4392       token = real_yylex ();
4393       if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
4394         {
4395           error ("invalid #pragma vtable");
4396           return -1;
4397         }
4398
4399       if (write_virtuals != 2)
4400         {
4401           warning ("use `+e2' option to enable #pragma vtable");
4402           return -1;
4403         }
4404       pending_vtables
4405         = perm_tree_cons (NULL_TREE,
4406                           get_identifier (TREE_STRING_POINTER (yylval.ttype)),
4407                           pending_vtables);
4408       token = real_yylex ();
4409       if (token != END_OF_LINE)
4410         warning ("trailing characters ignored");
4411       return 1;
4412     }
4413   else if (! strcmp (pname, "unit"))
4414     {
4415       /* More follows: it must be a string constant (unit name).  */
4416       token = real_yylex ();
4417       if (token != STRING || TREE_CODE (yylval.ttype) != STRING_CST)
4418         {
4419           error ("invalid #pragma unit");
4420           return -1;
4421         }
4422       token = real_yylex ();
4423       if (token != END_OF_LINE)
4424         warning ("trailing characters ignored");
4425       return 1;
4426     }
4427   else if (! strcmp (pname, "interface"))
4428     {
4429       tree fileinfo = IDENTIFIER_CLASS_VALUE (get_time_identifier (input_filename));
4430       int warned_already = 0;
4431       char *main_filename = input_filename;
4432
4433       main_filename = FILE_NAME_NONDIRECTORY (main_filename);
4434
4435       token = real_yylex ();
4436       
4437       if (token != END_OF_LINE)
4438         {
4439           if (token != STRING
4440               || TREE_CODE (yylval.ttype) != STRING_CST)
4441             {
4442               error ("invalid `#pragma interface'");
4443               return -1;
4444             }
4445           main_filename = TREE_STRING_POINTER (yylval.ttype);
4446         }
4447       
4448       while (token != END_OF_LINE)
4449         {
4450           if (!warned_already && extra_warnings)
4451             {
4452               warning ("garbage after `#pragma interface' ignored");
4453               warned_already = 1;
4454             }
4455           token = real_yylex ();
4456         }
4457
4458       write_virtuals = 3;
4459
4460       if (impl_file_chain == 0)
4461         {
4462           /* If this is zero at this point, then we are
4463              auto-implementing.  */
4464           if (main_input_filename == 0)
4465             main_input_filename = input_filename;
4466
4467 #ifdef AUTO_IMPLEMENT
4468           filename = FILE_NAME_NONDIRECTORY (main_input_filename);
4469           fi = get_time_identifier (filename);
4470           fi = IDENTIFIER_CLASS_VALUE (fi);
4471           TREE_INT_CST_LOW (fi) = 0;
4472           TREE_INT_CST_HIGH (fi) = 1;
4473           /* Get default.  */
4474           impl_file_chain = (struct impl_files *)permalloc (sizeof (struct impl_files));
4475           impl_file_chain->filename = filename;
4476           impl_file_chain->next = 0;
4477 #endif
4478         }
4479
4480       interface_only = interface_strcmp (main_filename);
4481       interface_unknown = 0;
4482       TREE_INT_CST_LOW (fileinfo) = interface_only;
4483       TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
4484
4485       return 1;
4486     }
4487   else if (! strcmp (pname, "implementation"))
4488     {
4489       tree fileinfo = IDENTIFIER_CLASS_VALUE (get_time_identifier (input_filename));
4490       int warned_already = 0;
4491       char *main_filename = main_input_filename ? main_input_filename : input_filename;
4492
4493       main_filename = FILE_NAME_NONDIRECTORY (main_filename);
4494       token = real_yylex ();
4495       if (token != END_OF_LINE)
4496         {
4497           if (token != STRING
4498               || TREE_CODE (yylval.ttype) != STRING_CST)
4499             {
4500               error ("invalid `#pragma implementation'");
4501               return -1;
4502             }
4503           main_filename = TREE_STRING_POINTER (yylval.ttype);
4504         }
4505
4506       while (token != END_OF_LINE)
4507         {
4508           if (!warned_already && extra_warnings)
4509             {
4510               warning ("garbage after `#pragma implementation' ignored");
4511               warned_already = 1;
4512             }
4513           token = real_yylex ();
4514         }
4515
4516       if (write_virtuals == 3)
4517         {
4518           struct impl_files *ifiles = impl_file_chain;
4519           while (ifiles)
4520             {
4521               if (! strcmp (ifiles->filename, main_filename))
4522                 break;
4523               ifiles = ifiles->next;
4524             }
4525           if (ifiles == 0)
4526             {
4527               ifiles = (struct impl_files*) permalloc (sizeof (struct impl_files));
4528               ifiles->filename = main_filename;
4529               ifiles->next = impl_file_chain;
4530               impl_file_chain = ifiles;
4531             }
4532         }
4533       else if ((main_input_filename != 0
4534                 && ! strcmp (main_input_filename, input_filename))
4535                || ! strcmp (input_filename, main_filename))
4536         {
4537           write_virtuals = 3;
4538           if (impl_file_chain == 0)
4539             {
4540               impl_file_chain = (struct impl_files*) permalloc (sizeof (struct impl_files));
4541               impl_file_chain->filename = main_filename;
4542               impl_file_chain->next = 0;
4543             }
4544         }
4545       else
4546         error ("`#pragma implementation' can only appear at top-level");
4547       interface_only = 0;
4548 #if 1
4549       /* We make this non-zero so that we infer decl linkage
4550          in the impl file only for variables first declared
4551          in the interface file.  */
4552       interface_unknown = 1;
4553 #else
4554       /* We make this zero so that templates in the impl
4555          file will be emitted properly. */
4556       interface_unknown = 0;
4557 #endif
4558       TREE_INT_CST_LOW (fileinfo) = interface_only;
4559       TREE_INT_CST_HIGH (fileinfo) = interface_unknown;
4560       return 1;
4561     }
4562
4563   return 0;
4564 }
4565 \f
4566 #ifdef HANDLE_SYSV_PRAGMA
4567
4568 /* Handle a #pragma directive.  INPUT is the current input stream,
4569    and C is a character to reread.  Processes the entire input line
4570    and returns a character for the caller to reread: either \n or EOF.  */
4571
4572 /* This function has to be in this file, in order to get at
4573    the token types.  */
4574 int
4575 handle_sysv_pragma (finput, token)
4576      FILE *finput;
4577      register int token;
4578 {
4579   for (;;)
4580     {
4581       switch (token)
4582         {
4583         case IDENTIFIER:
4584         case TYPENAME:
4585         case STRING:
4586         case CONSTANT:
4587           handle_pragma_token ("ignored", yylval.ttype);
4588           break;
4589         case '(':
4590           handle_pragma_token ("(", NULL_TREE);
4591           break;
4592         case ')':
4593           handle_pragma_token (")", NULL_TREE);
4594           break;
4595         case ',':
4596           handle_pragma_token (",", NULL_TREE);
4597           break;
4598         case '=':
4599           handle_pragma_token ("=", NULL_TREE);
4600           break;
4601         case LEFT_RIGHT:
4602           handle_pragma_token ("(", NULL_TREE);
4603           handle_pragma_token (")", NULL_TREE);
4604           break;
4605         case END_OF_LINE:
4606         default:
4607           handle_pragma_token (NULL_PTR, NULL_TREE);
4608           return 1;
4609         }
4610       token = real_yylex ();
4611     }
4612 }
4613 #endif /* HANDLE_SYSV_PRAGMA */