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