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