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