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