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