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