62nd Cygnus<->FSF merge
[gcc.git] / gcc / cp / decl2.c
1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1995 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 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
25
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
28
29 #include "config.h"
30 #include <stdio.h>
31 #include "tree.h"
32 #include "rtl.h"
33 #include "flags.h"
34 #include "cp-tree.h"
35 #include "decl.h"
36 #include "lex.h"
37
38 extern tree grokdeclarator ();
39 extern tree get_file_function_name ();
40 extern tree cleanups_this_call;
41 static void grok_function_init ();
42
43 /* A list of virtual function tables we must make sure to write out. */
44 tree pending_vtables;
45
46 /* A list of static class variables. This is needed, because a
47 static class variable can be declared inside the class without
48 an initializer, and then initialized, staticly, outside the class. */
49 tree pending_statics;
50
51 /* A list of functions which were declared inline, but which we
52 may need to emit outline anyway. */
53 static tree saved_inlines;
54
55 /* Used to help generate temporary names which are unique within
56 a function. Reset to 0 by start_function. */
57
58 int temp_name_counter;
59
60 /* Same, but not reset. Local temp variables and global temp variables
61 can have the same name. */
62 static int global_temp_name_counter;
63
64 /* Flag used when debugging spew.c */
65
66 extern int spew_debug;
67
68 /* Functions called along with real static constructors and destructors. */
69
70 tree static_ctors, static_dtors;
71 \f
72 /* C (and C++) language-specific option variables. */
73
74 /* Nonzero means allow type mismatches in conditional expressions;
75 just make their values `void'. */
76
77 int flag_cond_mismatch;
78
79 /* Nonzero means give `double' the same size as `float'. */
80
81 int flag_short_double;
82
83 /* Nonzero means don't recognize the keyword `asm'. */
84
85 int flag_no_asm;
86
87 /* Nonzero means don't recognize any extension keywords. */
88
89 int flag_no_gnu_keywords;
90
91 /* Nonzero means don't recognize the non-ANSI builtin functions. */
92
93 int flag_no_builtin;
94
95 /* Nonzero means don't recognize the non-ANSI builtin functions.
96 -ansi sets this. */
97
98 int flag_no_nonansi_builtin;
99
100 /* Nonzero means do some things the same way PCC does. */
101
102 int flag_traditional;
103
104 /* Nonzero means to treat bitfields as unsigned unless they say `signed'. */
105
106 int flag_signed_bitfields = 1;
107
108 /* Nonzero means handle `#ident' directives. 0 means ignore them. */
109
110 int flag_no_ident;
111
112 /* Nonzero means enable obscure ANSI features and disable GNU extensions
113 that might cause ANSI-compliant code to be miscompiled. */
114
115 int flag_ansi;
116
117 /* Nonzero means do emit exported implementations of functions even if
118 they can be inlined. */
119
120 int flag_implement_inlines = 1;
121
122 /* Nonzero means do emit exported implementations of templates, instead of
123 multiple static copies in each file that needs a definition. */
124
125 int flag_external_templates;
126
127 /* Nonzero means that the decision to emit or not emit the implementation of a
128 template depends on where the template is instantiated, rather than where
129 it is defined. */
130
131 int flag_alt_external_templates;
132
133 /* Nonzero means that implicit instantiations will be emitted if needed. */
134
135 int flag_implicit_templates = 1;
136
137 /* Nonzero means warn about implicit declarations. */
138
139 int warn_implicit = 1;
140
141 /* Nonzero means warn when all ctors or dtors are private, and the class
142 has no friends. */
143
144 int warn_ctor_dtor_privacy = 1;
145
146 /* True if we want to implement vtbvales using "thunks".
147 The default is off now, but will be on later. */
148
149 int flag_vtable_thunks;
150
151 /* True if we want to deal with repository information. */
152
153 int flag_use_repository;
154
155 /* Nonzero means give string constants the type `const char *'
156 to get extra warnings from them. These warnings will be too numerous
157 to be useful, except in thoroughly ANSIfied programs. */
158
159 int warn_write_strings;
160
161 /* Nonzero means warn about pointer casts that can drop a type qualifier
162 from the pointer target type. */
163
164 int warn_cast_qual;
165
166 /* Nonzero means warn that dbx info for template class methods isn't fully
167 supported yet. */
168
169 int warn_template_debugging;
170
171 /* Warn about traditional constructs whose meanings changed in ANSI C. */
172
173 int warn_traditional;
174
175 /* Nonzero means warn about sizeof(function) or addition/subtraction
176 of function pointers. */
177
178 int warn_pointer_arith;
179
180 /* Nonzero means warn for non-prototype function decls
181 or non-prototyped defs without previous prototype. */
182
183 int warn_strict_prototypes;
184
185 /* Nonzero means warn for any function def without prototype decl. */
186
187 int warn_missing_prototypes;
188
189 /* Nonzero means warn about multiple (redundant) decls for the same single
190 variable or function. */
191
192 int warn_redundant_decls;
193
194 /* Warn if initializer is not completely bracketed. */
195
196 int warn_missing_braces;
197
198 /* Warn about *printf or *scanf format/argument anomalies. */
199
200 int warn_format;
201
202 /* Warn about a subscript that has type char. */
203
204 int warn_char_subscripts;
205
206 /* Warn if a type conversion is done that might have confusing results. */
207
208 int warn_conversion;
209
210 /* Warn if adding () is suggested. */
211
212 int warn_parentheses;
213
214 /* Non-zero means warn in function declared in derived class has the
215 same name as a virtual in the base class, but fails to match the
216 type signature of any virtual function in the base class. */
217 int warn_overloaded_virtual;
218
219 /* Non-zero means warn when declaring a class that has a non virtual
220 destructor, when it really ought to have a virtual one. */
221 int warn_nonvdtor;
222
223 /* Non-zero means warn when a function is declared extern and later inline. */
224 int warn_extern_inline;
225
226 /* Non-zero means warn when the compiler will reorder code. */
227 int warn_reorder;
228
229 /* Non-zero means warn when sysnthesis behavior differs from Cfront's. */
230 int warn_synth;
231
232 /* Nonzero means `$' can be in an identifier.
233 See cccp.c for reasons why this breaks some obscure ANSI C programs. */
234
235 #ifndef DOLLARS_IN_IDENTIFIERS
236 #define DOLLARS_IN_IDENTIFIERS 1
237 #endif
238 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
239
240 /* Nonzero for -fno-strict-prototype switch: do not consider empty
241 argument prototype to mean function takes no arguments. */
242
243 int flag_strict_prototype = 2;
244 int strict_prototype = 1;
245 int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
246
247 /* Nonzero means that labels can be used as first-class objects */
248
249 int flag_labels_ok;
250
251 /* Non-zero means to collect statistics which might be expensive
252 and to print them when we are done. */
253 int flag_detailed_statistics;
254
255 /* C++ specific flags. */
256 /* Nonzero for -fall-virtual: make every member function (except
257 constructors) lay down in the virtual function table. Calls
258 can then either go through the virtual function table or not,
259 depending. */
260
261 int flag_all_virtual;
262
263 /* Zero means that `this' is a *const. This gives nice behavior in the
264 2.0 world. 1 gives 1.2-compatible behavior. 2 gives Spring behavior.
265 -2 means we're constructing an object and it has fixed type. */
266
267 int flag_this_is_variable;
268
269 /* Nonzero means memoize our member lookups. */
270
271 int flag_memoize_lookups; int flag_save_memoized_contexts;
272
273 /* 3 means write out only virtuals function tables `defined'
274 in this implementation file.
275 2 means write out only specific virtual function tables
276 and give them (C) public access.
277 1 means write out virtual function tables and give them
278 (C) public access.
279 0 means write out virtual function tables and give them
280 (C) static access (default).
281 -1 means declare virtual function tables extern. */
282
283 int write_virtuals;
284
285 /* Nonzero means we should attempt to elide constructors when possible. */
286
287 int flag_elide_constructors;
288
289 /* Nonzero means recognize and handle exception handling constructs.
290 Use ansi syntax and semantics. WORK IN PROGRESS! */
291
292 int flag_handle_exceptions;
293
294 /* Nonzero means recognize and handle signature language constructs. */
295
296 int flag_handle_signatures;
297
298 /* Nonzero means that member functions defined in class scope are
299 inline by default. */
300
301 int flag_default_inline = 1;
302
303 /* Controls whether enums and ints freely convert.
304 1 means with complete freedom.
305 0 means enums can convert to ints, but not vice-versa. */
306 int flag_int_enum_equivalence;
307
308 /* Controls whether compiler is operating under LUCID's Cadillac
309 system. 1 means yes, 0 means no. */
310 int flag_cadillac;
311
312 /* Controls whether compiler generates code to build objects
313 that can be collected when they become garbage. */
314 int flag_gc;
315
316 /* Controls whether compiler generates 'type descriptor' that give
317 run-time type information. */
318 int flag_rtti;
319
320 /* Nonzero if we wish to output cross-referencing information
321 for the GNU class browser. */
322 extern int flag_gnu_xref;
323
324 /* Nonzero if compiler can make `reasonable' assumptions about
325 references and objects. For example, the compiler must be
326 conservative about the following and not assume that `a' is nonnull:
327
328 obj &a = g ();
329 a.f (2);
330
331 In general, it is `reasonable' to assume that for many programs,
332 and better code can be generated in that case. */
333
334 int flag_assume_nonnull_objects = 1;
335
336 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
337 objects. */
338
339 int flag_huge_objects;
340
341 /* Nonzero if we want to conserve space in the .o files. We do this
342 by putting uninitialized data and runtime initialized data into
343 .common instead of .data at the expense of not flaging multiple
344 definitions. */
345
346 int flag_conserve_space;
347
348 /* Nonzero if we want to obey access control semantics. */
349
350 int flag_access_control = 1;
351
352 /* Nonzero if we want to understand the operator names, i.e. 'bitand'. */
353
354 int flag_operator_names;
355
356 /* Nonzero if we want to check the return value of new and avoid calling
357 constructors if it is a null pointer. */
358
359 int flag_check_new;
360
361 /* Table of language-dependent -f options.
362 STRING is the option name. VARIABLE is the address of the variable.
363 ON_VALUE is the value to store in VARIABLE
364 if `-fSTRING' is seen as an option.
365 (If `-fno-STRING' is seen as an option, the opposite value is stored.) */
366
367 static struct { char *string; int *variable; int on_value;} lang_f_options[] =
368 {
369 {"signed-char", &flag_signed_char, 1},
370 {"unsigned-char", &flag_signed_char, 0},
371 {"signed-bitfields", &flag_signed_bitfields, 1},
372 {"unsigned-bitfields", &flag_signed_bitfields, 0},
373 {"short-enums", &flag_short_enums, 1},
374 {"short-double", &flag_short_double, 1},
375 {"cond-mismatch", &flag_cond_mismatch, 1},
376 {"asm", &flag_no_asm, 0},
377 {"builtin", &flag_no_builtin, 0},
378 {"ident", &flag_no_ident, 0},
379 {"labels-ok", &flag_labels_ok, 1},
380 {"stats", &flag_detailed_statistics, 1},
381 {"this-is-variable", &flag_this_is_variable, 1},
382 {"strict-prototype", &flag_strict_prototype, 1},
383 {"all-virtual", &flag_all_virtual, 1},
384 {"memoize-lookups", &flag_memoize_lookups, 1},
385 {"elide-constructors", &flag_elide_constructors, 1},
386 {"handle-exceptions", &flag_handle_exceptions, 1},
387 {"handle-signatures", &flag_handle_signatures, 1},
388 {"default-inline", &flag_default_inline, 1},
389 {"dollars-in-identifiers", &dollars_in_ident, 1},
390 {"enum-int-equiv", &flag_int_enum_equivalence, 1},
391 {"gc", &flag_gc, 1},
392 {"rtti", &flag_rtti, 1},
393 {"xref", &flag_gnu_xref, 1},
394 {"nonnull-objects", &flag_assume_nonnull_objects, 1},
395 {"implement-inlines", &flag_implement_inlines, 1},
396 {"external-templates", &flag_external_templates, 1},
397 {"implicit-templates", &flag_implicit_templates, 1},
398 {"huge-objects", &flag_huge_objects, 1},
399 {"conserve-space", &flag_conserve_space, 1},
400 {"vtable-thunks", &flag_vtable_thunks, 1},
401 {"short-temps", &flag_short_temps, 1},
402 {"access-control", &flag_access_control, 1},
403 {"nonansi-builtins", &flag_no_nonansi_builtin, 0},
404 {"gnu-keywords", &flag_no_gnu_keywords, 0},
405 {"operator-names", &flag_operator_names, 1},
406 {"check-new", &flag_check_new, 1},
407 {"repo", &flag_use_repository, 1}
408 };
409
410 /* Decode the string P as a language-specific option.
411 Return 1 if it is recognized (and handle it);
412 return 0 if not recognized. */
413
414 int
415 lang_decode_option (p)
416 char *p;
417 {
418 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
419 flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
420 flag_this_is_variable = 1;
421 /* The +e options are for cfront compatibility. They come in as
422 `-+eN', to kludge around gcc.c's argument handling. */
423 else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
424 {
425 int old_write_virtuals = write_virtuals;
426 if (p[3] == '1')
427 write_virtuals = 1;
428 else if (p[3] == '0')
429 write_virtuals = -1;
430 else if (p[3] == '2')
431 write_virtuals = 2;
432 else error ("invalid +e option");
433 if (old_write_virtuals != 0
434 && write_virtuals != old_write_virtuals)
435 error ("conflicting +e options given");
436 }
437 else if (p[0] == '-' && p[1] == 'f')
438 {
439 /* Some kind of -f option.
440 P's value is the option sans `-f'.
441 Search for it in the table of options. */
442 int found = 0, j;
443
444 p += 2;
445 /* Try special -f options. */
446
447 if (!strcmp (p, "save-memoized"))
448 {
449 flag_memoize_lookups = 1;
450 flag_save_memoized_contexts = 1;
451 found = 1;
452 }
453 if (!strcmp (p, "no-save-memoized"))
454 {
455 flag_memoize_lookups = 0;
456 flag_save_memoized_contexts = 0;
457 found = 1;
458 }
459 else if (! strncmp (p, "cadillac", 8))
460 {
461 flag_cadillac = atoi (p+9);
462 found = 1;
463 }
464 else if (! strncmp (p, "no-cadillac", 11))
465 {
466 flag_cadillac = 0;
467 found = 1;
468 }
469 else if (! strcmp (p, "gc"))
470 {
471 flag_gc = 1;
472 /* This must come along for the ride. */
473 flag_rtti = 1;
474 found = 1;
475 }
476 else if (! strcmp (p, "no-gc"))
477 {
478 flag_gc = 0;
479 /* This must come along for the ride. */
480 flag_rtti = 0;
481 found = 1;
482 }
483 else if (! strcmp (p, "alt-external-templates"))
484 {
485 flag_external_templates = 1;
486 flag_alt_external_templates = 1;
487 found = 1;
488 }
489 else if (! strcmp (p, "no-alt-external-templates"))
490 {
491 flag_alt_external_templates = 0;
492 found = 1;
493 }
494 else if (!strcmp (p, "ansi-overloading"))
495 {
496 warning ("-fansi-overloading is no longer meaningful");
497 }
498 else for (j = 0;
499 !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
500 j++)
501 {
502 if (!strcmp (p, lang_f_options[j].string))
503 {
504 *lang_f_options[j].variable = lang_f_options[j].on_value;
505 /* A goto here would be cleaner,
506 but breaks the vax pcc. */
507 found = 1;
508 }
509 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
510 && ! strcmp (p+3, lang_f_options[j].string))
511 {
512 *lang_f_options[j].variable = ! lang_f_options[j].on_value;
513 found = 1;
514 }
515 }
516 return found;
517 }
518 else if (p[0] == '-' && p[1] == 'W')
519 {
520 int setting = 1;
521
522 /* The -W options control the warning behavior of the compiler. */
523 p += 2;
524
525 if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
526 setting = 0, p += 3;
527
528 if (!strcmp (p, "implicit"))
529 warn_implicit = setting;
530 else if (!strcmp (p, "return-type"))
531 warn_return_type = setting;
532 else if (!strcmp (p, "ctor-dtor-privacy"))
533 warn_ctor_dtor_privacy = setting;
534 else if (!strcmp (p, "write-strings"))
535 warn_write_strings = setting;
536 else if (!strcmp (p, "cast-qual"))
537 warn_cast_qual = setting;
538 else if (!strcmp (p, "traditional"))
539 warn_traditional = setting;
540 else if (!strcmp (p, "char-subscripts"))
541 warn_char_subscripts = setting;
542 else if (!strcmp (p, "pointer-arith"))
543 warn_pointer_arith = setting;
544 else if (!strcmp (p, "strict-prototypes"))
545 warn_strict_prototypes = setting;
546 else if (!strcmp (p, "missing-prototypes"))
547 warn_missing_prototypes = setting;
548 else if (!strcmp (p, "redundant-decls"))
549 warn_redundant_decls = setting;
550 else if (!strcmp (p, "missing-braces"))
551 warn_missing_braces = setting;
552 else if (!strcmp (p, "format"))
553 warn_format = setting;
554 else if (!strcmp (p, "conversion"))
555 warn_conversion = setting;
556 else if (!strcmp (p, "parentheses"))
557 warn_parentheses = setting;
558 else if (!strcmp (p, "non-virtual-dtor"))
559 warn_nonvdtor = setting;
560 else if (!strcmp (p, "extern-inline"))
561 warn_extern_inline = setting;
562 else if (!strcmp (p, "reorder"))
563 warn_reorder = setting;
564 else if (!strcmp (p, "synth"))
565 warn_synth = setting;
566 else if (!strcmp (p, "comment"))
567 ; /* cpp handles this one. */
568 else if (!strcmp (p, "comments"))
569 ; /* cpp handles this one. */
570 else if (!strcmp (p, "trigraphs"))
571 ; /* cpp handles this one. */
572 else if (!strcmp (p, "import"))
573 ; /* cpp handles this one. */
574 else if (!strcmp (p, "all"))
575 {
576 extra_warnings = setting;
577 warn_return_type = setting;
578 warn_unused = setting;
579 warn_implicit = setting;
580 warn_ctor_dtor_privacy = setting;
581 warn_switch = setting;
582 warn_format = setting;
583 warn_parentheses = setting;
584 warn_missing_braces = setting;
585 warn_extern_inline = setting;
586 warn_nonvdtor = setting;
587 /* We save the value of warn_uninitialized, since if they put
588 -Wuninitialized on the command line, we need to generate a
589 warning about not using it without also specifying -O. */
590 if (warn_uninitialized != 1)
591 warn_uninitialized = (setting ? 2 : 0);
592 warn_template_debugging = setting;
593 warn_reorder = setting;
594 }
595
596 else if (!strcmp (p, "overloaded-virtual"))
597 warn_overloaded_virtual = setting;
598 else return 0;
599 }
600 else if (!strcmp (p, "-ansi"))
601 dollars_in_ident = 0, flag_no_nonansi_builtin = 1, flag_ansi = 1,
602 flag_no_gnu_keywords = 1, flag_operator_names = 1;
603 #ifdef SPEW_DEBUG
604 /* Undocumented, only ever used when you're invoking cc1plus by hand, since
605 it's probably safe to assume no sane person would ever want to use this
606 under normal circumstances. */
607 else if (!strcmp (p, "-spew-debug"))
608 spew_debug = 1;
609 #endif
610 else
611 return 0;
612
613 return 1;
614 }
615 \f
616 /* Incorporate `const' and `volatile' qualifiers for member functions.
617 FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
618 QUALS is a list of qualifiers. */
619 tree
620 grok_method_quals (ctype, function, quals)
621 tree ctype, function, quals;
622 {
623 tree fntype = TREE_TYPE (function);
624 tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
625
626 do
627 {
628 extern tree ridpointers[];
629
630 if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
631 {
632 if (TYPE_READONLY (ctype))
633 error ("duplicate `%s' %s",
634 IDENTIFIER_POINTER (TREE_VALUE (quals)),
635 (TREE_CODE (function) == FUNCTION_DECL
636 ? "for member function" : "in type declaration"));
637 ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
638 build_pointer_type (ctype);
639 }
640 else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
641 {
642 if (TYPE_VOLATILE (ctype))
643 error ("duplicate `%s' %s",
644 IDENTIFIER_POINTER (TREE_VALUE (quals)),
645 (TREE_CODE (function) == FUNCTION_DECL
646 ? "for member function" : "in type declaration"));
647 ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
648 build_pointer_type (ctype);
649 }
650 else
651 my_friendly_abort (20);
652 quals = TREE_CHAIN (quals);
653 }
654 while (quals);
655 fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
656 (TREE_CODE (fntype) == METHOD_TYPE
657 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
658 : TYPE_ARG_TYPES (fntype)));
659 if (raises)
660 fntype = build_exception_variant (ctype, fntype, raises);
661
662 TREE_TYPE (function) = fntype;
663 return ctype;
664 }
665
666 #if 0 /* Not used. */
667 /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
668 It leaves DECL_ASSEMBLER_NAMEs with the correct value. */
669 /* This does not yet work with user defined conversion operators
670 It should. */
671 static void
672 substitute_nice_name (decl)
673 tree decl;
674 {
675 if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
676 {
677 char *n = decl_as_string (DECL_NAME (decl), 1);
678 if (n[strlen (n) - 1] == ' ')
679 n[strlen (n) - 1] = 0;
680 DECL_NAME (decl) = get_identifier (n);
681 }
682 }
683 #endif
684
685 /* Warn when -fexternal-templates is used and #pragma
686 interface/implementation is not used all the times it should be,
687 inform the user. */
688 void
689 warn_if_unknown_interface (decl)
690 tree decl;
691 {
692 static int already_warned = 0;
693 if (already_warned++)
694 return;
695
696 if (flag_alt_external_templates)
697 {
698 struct tinst_level *til = tinst_for_decl ();
699 int sl = lineno;
700 char *sf = input_filename;
701
702 lineno = til->line;
703 input_filename = til->file;
704 cp_warning ("template `%#D' instantiated in file without #pragma interface",
705 decl);
706 lineno = sl;
707 input_filename = sf;
708 }
709 else
710 cp_warning_at ("template `%#D' defined in file without #pragma interface",
711 decl);
712 }
713
714 /* A subroutine of the parser, to handle a component list. */
715 tree
716 grok_x_components (specs, components)
717 tree specs, components;
718 {
719 register tree t, x, tcode;
720
721 /* We just got some friends. They have been recorded elsewhere. */
722 if (components == void_type_node)
723 return NULL_TREE;
724
725 if (components == NULL_TREE)
726 {
727 t = groktypename (build_decl_list (specs, NULL_TREE));
728
729 if (t == NULL_TREE)
730 {
731 error ("error in component specification");
732 return NULL_TREE;
733 }
734
735 switch (TREE_CODE (t))
736 {
737 case VAR_DECL:
738 /* Static anonymous unions come out as VAR_DECLs. */
739 if (TREE_CODE (TREE_TYPE (t)) == UNION_TYPE
740 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (t))))
741 return t;
742
743 /* We return SPECS here, because in the parser it was ending
744 up with not doing anything to $$, which is what SPECS
745 represents. */
746 return specs;
747 break;
748
749 case RECORD_TYPE:
750 /* This code may be needed for UNION_TYPEs as
751 well. */
752 tcode = record_type_node;
753 if (CLASSTYPE_DECLARED_CLASS(t))
754 tcode = class_type_node;
755 else if (IS_SIGNATURE(t))
756 tcode = signature_type_node;
757
758 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
759 if (TYPE_CONTEXT(t))
760 CLASSTYPE_NO_GLOBALIZE(t) = 1;
761 return NULL_TREE;
762 break;
763
764 case UNION_TYPE:
765 case ENUMERAL_TYPE:
766 if (TREE_CODE(t) == UNION_TYPE)
767 tcode = union_type_node;
768 else
769 tcode = enum_type_node;
770
771 t = xref_tag (tcode, TYPE_IDENTIFIER (t), NULL_TREE, 0);
772 if (TREE_CODE(t) == UNION_TYPE && TYPE_CONTEXT(t))
773 CLASSTYPE_NO_GLOBALIZE(t) = 1;
774 if (TREE_CODE (t) == UNION_TYPE
775 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
776 {
777 struct pending_inline **p;
778 x = build_lang_field_decl (FIELD_DECL, NULL_TREE, t);
779
780 /* Wipe out memory of synthesized methods */
781 TYPE_HAS_CONSTRUCTOR (t) = 0;
782 TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
783 TYPE_HAS_INIT_REF (t) = 0;
784 TYPE_HAS_CONST_INIT_REF (t) = 0;
785 TYPE_HAS_ASSIGN_REF (t) = 0;
786 TYPE_HAS_ASSIGNMENT (t) = 0;
787 TYPE_HAS_CONST_ASSIGN_REF (t) = 0;
788
789 p = &pending_inlines;
790 for (; *p; *p = (*p)->next)
791 if (DECL_CONTEXT ((*p)->fndecl) != t)
792 break;
793 }
794 else if (TREE_CODE (t) == ENUMERAL_TYPE)
795 x = grok_enum_decls (t, NULL_TREE);
796 else
797 x = NULL_TREE;
798 return x;
799 break;
800
801 default:
802 if (t != void_type_node)
803 error ("empty component declaration");
804 return NULL_TREE;
805 }
806 }
807 else
808 {
809 t = TREE_TYPE (components);
810 if (TREE_CODE (t) == ENUMERAL_TYPE && TREE_NONLOCAL_FLAG (t))
811 return grok_enum_decls (t, components);
812 else
813 return components;
814 }
815 }
816
817 /* Classes overload their constituent function names automatically.
818 When a function name is declared in a record structure,
819 its name is changed to it overloaded name. Since names for
820 constructors and destructors can conflict, we place a leading
821 '$' for destructors.
822
823 CNAME is the name of the class we are grokking for.
824
825 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
826
827 FLAGS contains bits saying what's special about today's
828 arguments. 1 == DESTRUCTOR. 2 == OPERATOR.
829
830 If FUNCTION is a destructor, then we must add the `auto-delete' field
831 as a second parameter. There is some hair associated with the fact
832 that we must "declare" this variable in the manner consistent with the
833 way the rest of the arguments were declared.
834
835 QUALS are the qualifiers for the this pointer. */
836
837 void
838 grokclassfn (ctype, cname, function, flags, quals)
839 tree ctype, cname, function;
840 enum overload_flags flags;
841 tree quals;
842 {
843 tree fn_name = DECL_NAME (function);
844 tree arg_types;
845 tree parm;
846 tree qualtype;
847
848 if (fn_name == NULL_TREE)
849 {
850 error ("name missing for member function");
851 fn_name = get_identifier ("<anonymous>");
852 DECL_NAME (function) = fn_name;
853 }
854
855 if (quals)
856 qualtype = grok_method_quals (ctype, function, quals);
857 else
858 qualtype = ctype;
859
860 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
861 if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
862 {
863 /* Must add the class instance variable up front. */
864 /* Right now we just make this a pointer. But later
865 we may wish to make it special. */
866 tree type = TREE_VALUE (arg_types);
867
868 if ((flag_this_is_variable > 0)
869 && (flags == DTOR_FLAG || DECL_CONSTRUCTOR_P (function)))
870 type = TYPE_MAIN_VARIANT (type);
871
872 if (DECL_CONSTRUCTOR_P (function))
873 {
874 if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
875 {
876 DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
877 /* In this case we need "in-charge" flag saying whether
878 this constructor is responsible for initialization
879 of virtual baseclasses or not. */
880 parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
881 /* Mark the artificial `__in_chrg' parameter as "artificial". */
882 SET_DECL_ARTIFICIAL (parm);
883 DECL_ARG_TYPE (parm) = integer_type_node;
884 DECL_REGISTER (parm) = 1;
885 TREE_CHAIN (parm) = last_function_parms;
886 last_function_parms = parm;
887 }
888 }
889
890 parm = build_decl (PARM_DECL, this_identifier, type);
891 /* Mark the artificial `this' parameter as "artificial". */
892 SET_DECL_ARTIFICIAL (parm);
893 DECL_ARG_TYPE (parm) = type;
894 /* We can make this a register, so long as we don't
895 accidentally complain if someone tries to take its address. */
896 DECL_REGISTER (parm) = 1;
897 if (TYPE_READONLY (type))
898 TREE_READONLY (parm) = 1;
899 TREE_CHAIN (parm) = last_function_parms;
900 last_function_parms = parm;
901 }
902
903 if (flags == DTOR_FLAG)
904 {
905 char *buf, *dbuf;
906 tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
907 int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
908
909 arg_types = hash_tree_chain (const_integer_type, void_list_node);
910 TREE_SIDE_EFFECTS (arg_types) = 1;
911 /* Build the overload name. It will look like `7Example'. */
912 if (IDENTIFIER_TYPE_VALUE (cname))
913 dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
914 else if (IDENTIFIER_LOCAL_VALUE (cname))
915 dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
916 else
917 /* Using ctype fixes the `X::Y::~Y()' crash. The cname has no type when
918 it's defined out of the class definition, since poplevel_class wipes
919 it out. This used to be internal error 346. */
920 dbuf = build_overload_name (ctype, 1, 1);
921 buf = (char *) alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
922 bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
923 buf[len] = '\0';
924 strcat (buf, dbuf);
925 DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
926 parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type);
927 /* Mark the artificial `__in_chrg' parameter as "artificial". */
928 SET_DECL_ARTIFICIAL (parm);
929 TREE_USED (parm) = 1;
930 #if 0
931 /* We don't need to mark the __in_chrg parameter itself as `const'
932 since its type is already `const int'. In fact we MUST NOT mark
933 it as `const' cuz that will screw up the debug info (causing it
934 to say that the type of __in_chrg is `const const int'). */
935 TREE_READONLY (parm) = 1;
936 #endif
937 DECL_ARG_TYPE (parm) = const_integer_type;
938 /* This is the same chain as DECL_ARGUMENTS (...). */
939 TREE_CHAIN (last_function_parms) = parm;
940
941 TREE_TYPE (function) = build_cplus_method_type (qualtype, void_type_node,
942 arg_types);
943 TYPE_HAS_DESTRUCTOR (ctype) = 1;
944 }
945 else
946 {
947 tree these_arg_types;
948
949 if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
950 {
951 arg_types = hash_tree_chain (integer_type_node,
952 TREE_CHAIN (arg_types));
953 TREE_TYPE (function)
954 = build_cplus_method_type (qualtype,
955 TREE_TYPE (TREE_TYPE (function)),
956 arg_types);
957 arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
958 }
959
960 these_arg_types = arg_types;
961
962 if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
963 /* Only true for static member functions. */
964 these_arg_types = hash_tree_chain (TYPE_POINTER_TO (qualtype),
965 arg_types);
966
967 DECL_ASSEMBLER_NAME (function)
968 = build_decl_overload (fn_name, these_arg_types,
969 1 + DECL_CONSTRUCTOR_P (function));
970
971 #if 0
972 /* This code is going into the compiler, but currently, it makes
973 libg++/src/Interger.cc not compile. The problem is that the nice name
974 winds up going into the symbol table, and conversion operations look
975 for the manged name. */
976 substitute_nice_name (function);
977 #endif
978 }
979
980 DECL_ARGUMENTS (function) = last_function_parms;
981 /* First approximations. */
982 DECL_CONTEXT (function) = ctype;
983 DECL_CLASS_CONTEXT (function) = ctype;
984 }
985
986 /* Work on the expr used by alignof (this is only called by the parser). */
987 tree
988 grok_alignof (expr)
989 tree expr;
990 {
991 tree best, t;
992 int bestalign;
993
994 if (TREE_CODE (expr) == COMPONENT_REF
995 && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
996 error ("`__alignof__' applied to a bit-field");
997
998 if (TREE_CODE (expr) == INDIRECT_REF)
999 {
1000 best = t = TREE_OPERAND (expr, 0);
1001 bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1002
1003 while (TREE_CODE (t) == NOP_EXPR
1004 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
1005 {
1006 int thisalign;
1007 t = TREE_OPERAND (t, 0);
1008 thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
1009 if (thisalign > bestalign)
1010 best = t, bestalign = thisalign;
1011 }
1012 return c_alignof (TREE_TYPE (TREE_TYPE (best)));
1013 }
1014 else
1015 {
1016 /* ANSI says arrays and fns are converted inside comma.
1017 But we can't convert them in build_compound_expr
1018 because that would break commas in lvalues.
1019 So do the conversion here if operand was a comma. */
1020 if (TREE_CODE (expr) == COMPOUND_EXPR
1021 && (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
1022 || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE))
1023 expr = default_conversion (expr);
1024 return c_alignof (TREE_TYPE (expr));
1025 }
1026 }
1027
1028 /* Create an ARRAY_REF, checking for the user doing things backwards
1029 along the way. */
1030 tree
1031 grok_array_decl (array_expr, index_exp)
1032 tree array_expr, index_exp;
1033 {
1034 tree type = TREE_TYPE (array_expr);
1035 tree p1, p2, i1, i2;
1036
1037 if (type == error_mark_node || index_exp == error_mark_node)
1038 return error_mark_node;
1039 if (type == NULL_TREE)
1040 {
1041 /* Something has gone very wrong. Assume we are mistakenly reducing
1042 an expression instead of a declaration. */
1043 error ("parser may be lost: is there a '{' missing somewhere?");
1044 return NULL_TREE;
1045 }
1046
1047 if (TREE_CODE (type) == OFFSET_TYPE
1048 || TREE_CODE (type) == REFERENCE_TYPE)
1049 type = TREE_TYPE (type);
1050
1051 /* If they have an `operator[]', use that. */
1052 if (TYPE_LANG_SPECIFIC (type)
1053 && TYPE_OVERLOADS_ARRAY_REF (type))
1054 return build_opfncall (ARRAY_REF, LOOKUP_NORMAL,
1055 array_expr, index_exp, NULL_TREE);
1056
1057 /* Otherwise, create an ARRAY_REF for a pointer or array type. */
1058
1059 if (TREE_CODE (type) == ARRAY_TYPE)
1060 p1 = array_expr;
1061 else
1062 p1 = build_expr_type_conversion (WANT_POINTER, array_expr, 0);
1063
1064 if (TREE_CODE (TREE_TYPE (index_exp)) == ARRAY_TYPE)
1065 p2 = index_exp;
1066 else
1067 p2 = build_expr_type_conversion (WANT_POINTER, index_exp, 0);
1068
1069 i1 = build_expr_type_conversion (WANT_INT | WANT_ENUM, array_expr, 0);
1070 i2 = build_expr_type_conversion (WANT_INT | WANT_ENUM, index_exp, 0);
1071
1072 if ((p1 && i2) && (i1 && p2))
1073 error ("ambiguous conversion for array subscript");
1074
1075 if (p1 && i2)
1076 array_expr = p1, index_exp = i2;
1077 else if (i1 && p2)
1078 array_expr = p2, index_exp = i1;
1079 else
1080 {
1081 cp_error ("invalid types `%T[%T]' for array subscript",
1082 type, TREE_TYPE (index_exp));
1083 return error_mark_node;
1084 }
1085
1086 if (array_expr == error_mark_node || index_exp == error_mark_node)
1087 error ("ambiguous conversion for array subscript");
1088
1089 return build_array_ref (array_expr, index_exp);
1090 }
1091
1092 /* Given the cast expression EXP, checking out its validity. Either return
1093 an error_mark_node if there was an unavoidable error, return a cast to
1094 void for trying to delete a pointer w/ the value 0, or return the
1095 call to delete. If DOING_VEC is 1, we handle things differently
1096 for doing an array delete. If DOING_VEC is 2, they gave us the
1097 array size as an argument to delete.
1098 Implements ARM $5.3.4. This is called from the parser. */
1099 tree
1100 delete_sanity (exp, size, doing_vec, use_global_delete)
1101 tree exp, size;
1102 int doing_vec, use_global_delete;
1103 {
1104 tree t = stabilize_reference (convert_from_reference (exp));
1105 tree type = TREE_TYPE (t);
1106 enum tree_code code = TREE_CODE (type);
1107 /* For a regular vector delete (aka, no size argument) we will pass
1108 this down as a NULL_TREE into build_vec_delete. */
1109 tree maxindex = NULL_TREE;
1110 /* This is used for deleting arrays. */
1111 tree elt_size;
1112
1113 switch (doing_vec)
1114 {
1115 case 2:
1116 maxindex = build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
1117 if (! flag_traditional)
1118 pedwarn ("anachronistic use of array size in vector delete");
1119 /* Fall through. */
1120 case 1:
1121 elt_size = c_sizeof (type);
1122 break;
1123 default:
1124 if (code != POINTER_TYPE)
1125 {
1126 cp_error ("type `%#T' argument given to `delete', expected pointer",
1127 type);
1128 return error_mark_node;
1129 }
1130
1131 /* Deleting a pointer with the value zero is valid and has no effect. */
1132 if (integer_zerop (t))
1133 return build1 (NOP_EXPR, void_type_node, t);
1134 }
1135
1136 if (code == POINTER_TYPE)
1137 {
1138 #if 0
1139 /* As of Valley Forge, you can delete a pointer to constant. */
1140 /* You can't delete a pointer to constant. */
1141 if (TREE_READONLY (TREE_TYPE (type)))
1142 {
1143 error ("`const *' cannot be deleted");
1144 return error_mark_node;
1145 }
1146 #endif
1147 /* You also can't delete functions. */
1148 if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
1149 {
1150 error ("cannot delete a function");
1151 return error_mark_node;
1152 }
1153 }
1154
1155 #if 0
1156 /* If the type has no destructor, then we should build a regular
1157 delete, instead of a vector delete. Otherwise, we would end
1158 up passing a bogus offset into __builtin_delete, which is
1159 not expecting it. */
1160 if (doing_vec
1161 && TREE_CODE (type) == POINTER_TYPE
1162 && !TYPE_HAS_DESTRUCTOR (TREE_TYPE (type)))
1163 {
1164 doing_vec = 0;
1165 use_global_delete = 1;
1166 }
1167 #endif
1168
1169 if (doing_vec)
1170 return build_vec_delete (t, maxindex, elt_size, integer_one_node,
1171 integer_two_node, use_global_delete);
1172 else
1173 return build_delete (type, t, integer_three_node,
1174 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE,
1175 use_global_delete);
1176 }
1177
1178 /* Sanity check: report error if this function FUNCTION is not
1179 really a member of the class (CTYPE) it is supposed to belong to.
1180 CNAME is the same here as it is for grokclassfn above. */
1181
1182 void
1183 check_classfn (ctype, cname, function)
1184 tree ctype, cname, function;
1185 {
1186 tree fn_name = DECL_NAME (function);
1187 tree fndecl;
1188 tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
1189 tree *methods = 0;
1190 tree *end = 0;
1191
1192 if (method_vec != 0)
1193 {
1194 methods = &TREE_VEC_ELT (method_vec, 0);
1195 end = TREE_VEC_END (method_vec);
1196
1197 /* First suss out ctors and dtors. */
1198 if (*methods
1199 && (fn_name == cname || fn_name == DECL_NAME (*methods)))
1200 goto got_it;
1201
1202 while (++methods != end)
1203 {
1204 if (fn_name == DECL_NAME (*methods))
1205 {
1206 got_it:
1207 fndecl = *methods;
1208 while (fndecl)
1209 {
1210 if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
1211 return;
1212 #if 0
1213 /* This should work, but causes libg++ to fail
1214 make check-tFix. */
1215 /* We have to do more extensive argument checking here, as
1216 the name may have been changed by asm("new_name"). */
1217 if (decls_match (function, fndecl))
1218 return;
1219 #else
1220 if (DECL_NAME (function) == DECL_NAME (fndecl))
1221 {
1222 tree p1 = TYPE_ARG_TYPES (TREE_TYPE (function));
1223 tree p2 = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1224
1225 /* Get rid of the this parameter on functions that become
1226 static. */
1227 if (DECL_STATIC_FUNCTION_P (fndecl)
1228 && TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
1229 p1 = TREE_CHAIN (p1);
1230
1231 if (comptypes (TREE_TYPE (TREE_TYPE (function)),
1232 TREE_TYPE (TREE_TYPE (fndecl)), 1)
1233 && compparms (p1, p2, 3))
1234 return;
1235 }
1236 #endif
1237 fndecl = DECL_CHAIN (fndecl);
1238 }
1239 break; /* loser */
1240 }
1241 }
1242 }
1243
1244 if (methods != end)
1245 cp_error ("argument list for `%#D' does not match any in class `%T'",
1246 function, ctype);
1247 else
1248 {
1249 methods = 0;
1250 cp_error ("no `%#D' member function declared in class `%T'",
1251 function, ctype);
1252 }
1253
1254 /* If we did not find the method in the class, add it to
1255 avoid spurious errors. */
1256 add_method (ctype, methods, function);
1257 }
1258
1259 /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
1260 of a structure component, returning a FIELD_DECL node.
1261 QUALS is a list of type qualifiers for this decl (such as for declaring
1262 const member functions).
1263
1264 This is done during the parsing of the struct declaration.
1265 The FIELD_DECL nodes are chained together and the lot of them
1266 are ultimately passed to `build_struct' to make the RECORD_TYPE node.
1267
1268 C++:
1269
1270 If class A defines that certain functions in class B are friends, then
1271 the way I have set things up, it is B who is interested in permission
1272 granted by A. However, it is in A's context that these declarations
1273 are parsed. By returning a void_type_node, class A does not attempt
1274 to incorporate the declarations of the friends within its structure.
1275
1276 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
1277 CHANGES TO CODE IN `start_method'. */
1278
1279 tree
1280 grokfield (declarator, declspecs, raises, init, asmspec_tree)
1281 tree declarator, declspecs, raises, init, asmspec_tree;
1282 {
1283 register tree value;
1284 char *asmspec = 0;
1285 int flags = LOOKUP_ONLYCONVERTING;
1286
1287 /* Convert () initializers to = initializers. */
1288 if (init == NULL_TREE && declarator != NULL_TREE
1289 && TREE_CODE (declarator) == CALL_EXPR
1290 && TREE_OPERAND (declarator, 0)
1291 && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
1292 || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
1293 && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
1294 {
1295 init = TREE_OPERAND (declarator, 1);
1296 declarator = TREE_OPERAND (declarator, 0);
1297 flags = 0;
1298 }
1299
1300 if (init
1301 && TREE_CODE (init) == TREE_LIST
1302 && TREE_VALUE (init) == error_mark_node
1303 && TREE_CHAIN (init) == NULL_TREE)
1304 init = NULL_TREE;
1305
1306 value = grokdeclarator (declarator, declspecs, FIELD, init != 0, raises);
1307 if (! value)
1308 return value; /* friend or constructor went bad. */
1309
1310 /* Pass friendly classes back. */
1311 if (TREE_CODE (value) == VOID_TYPE)
1312 return void_type_node;
1313
1314 if (DECL_NAME (value) != NULL_TREE
1315 && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
1316 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
1317 cp_error ("member `%D' conflicts with virtual function table field name", value);
1318
1319 /* Stash away type declarations. */
1320 if (TREE_CODE (value) == TYPE_DECL)
1321 {
1322 DECL_NONLOCAL (value) = 1;
1323 DECL_CONTEXT (value) = current_class_type;
1324 DECL_CLASS_CONTEXT (value) = current_class_type;
1325 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1326
1327 /* If we declare a typedef name for something that has no name,
1328 the typedef name is used for linkage. See 7.1.3 p4 94/0158. */
1329 if (TYPE_NAME (TREE_TYPE (value))
1330 && TREE_CODE (TYPE_NAME (TREE_TYPE (value))) == TYPE_DECL
1331 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_TYPE (value))))
1332 {
1333 TYPE_NAME (TREE_TYPE (value)) = value;
1334 TYPE_STUB_DECL (TREE_TYPE (value)) = value;
1335 }
1336
1337 pushdecl_class_level (value);
1338 return value;
1339 }
1340
1341 if (IS_SIGNATURE (current_class_type)
1342 && TREE_CODE (value) != FUNCTION_DECL)
1343 {
1344 error ("field declaration not allowed in signature");
1345 return void_type_node;
1346 }
1347
1348 if (DECL_IN_AGGR_P (value))
1349 {
1350 cp_error ("`%D' is already defined in the class %T", value,
1351 DECL_CONTEXT (value));
1352 return void_type_node;
1353 }
1354
1355 if (flag_cadillac)
1356 cadillac_start_decl (value);
1357
1358 if (asmspec_tree)
1359 asmspec = TREE_STRING_POINTER (asmspec_tree);
1360
1361 if (init)
1362 {
1363 if (IS_SIGNATURE (current_class_type)
1364 && TREE_CODE (value) == FUNCTION_DECL)
1365 {
1366 error ("function declarations cannot have initializers in signature");
1367 init = NULL_TREE;
1368 }
1369 else if (TREE_CODE (value) == FUNCTION_DECL)
1370 {
1371 grok_function_init (value, init);
1372 init = NULL_TREE;
1373 }
1374 else if (pedantic && TREE_CODE (value) != VAR_DECL)
1375 /* Already complained in grokdeclarator. */
1376 init = NULL_TREE;
1377 else
1378 {
1379 /* We allow initializers to become parameters to base
1380 initializers. */
1381 if (TREE_CODE (init) == TREE_LIST)
1382 {
1383 if (TREE_CHAIN (init) == NULL_TREE)
1384 init = TREE_VALUE (init);
1385 else
1386 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1387 }
1388
1389 if (TREE_CODE (init) == CONST_DECL)
1390 init = DECL_INITIAL (init);
1391 else if (TREE_READONLY_DECL_P (init))
1392 init = decl_constant_value (init);
1393 else if (TREE_CODE (init) == CONSTRUCTOR)
1394 init = digest_init (TREE_TYPE (value), init, (tree *)0);
1395 my_friendly_assert (TREE_PERMANENT (init), 192);
1396 if (init == error_mark_node)
1397 /* We must make this look different than `error_mark_node'
1398 because `decl_const_value' would mis-interpret it
1399 as only meaning that this VAR_DECL is defined. */
1400 init = build1 (NOP_EXPR, TREE_TYPE (value), init);
1401 else if (! TREE_CONSTANT (init))
1402 {
1403 /* We can allow references to things that are effectively
1404 static, since references are initialized with the address. */
1405 if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
1406 || (TREE_STATIC (init) == 0
1407 && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1408 || DECL_EXTERNAL (init) == 0)))
1409 {
1410 error ("field initializer is not constant");
1411 init = error_mark_node;
1412 }
1413 }
1414 }
1415 }
1416
1417 /* The corresponding pop_obstacks is in finish_decl. */
1418 push_obstacks_nochange ();
1419
1420 if (TREE_CODE (value) == VAR_DECL)
1421 {
1422 /* We cannot call pushdecl here, because that would
1423 fill in the value of our TREE_CHAIN. Instead, we
1424 modify finish_decl to do the right thing, namely, to
1425 put this decl out straight away. */
1426 if (TREE_PUBLIC (value))
1427 {
1428 /* current_class_type can be NULL_TREE in case of error. */
1429 if (asmspec == 0 && current_class_type)
1430 {
1431 TREE_PUBLIC (value) = 1;
1432 DECL_INITIAL (value) = error_mark_node;
1433 DECL_ASSEMBLER_NAME (value)
1434 = build_static_name (current_class_type, DECL_NAME (value));
1435 }
1436 pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
1437
1438 /* Static consts need not be initialized in the class definition. */
1439 if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
1440 {
1441 static int explanation = 0;
1442
1443 error ("initializer invalid for static member with constructor");
1444 if (explanation++ == 0)
1445 error ("(you really want to initialize it separately)");
1446 init = 0;
1447 }
1448 /* Force the compiler to know when an uninitialized static
1449 const member is being used. */
1450 if (TYPE_READONLY (value) && init == 0)
1451 TREE_USED (value) = 1;
1452 }
1453 DECL_INITIAL (value) = init;
1454 DECL_IN_AGGR_P (value) = 1;
1455
1456 finish_decl (value, init, asmspec_tree, 1, flags);
1457 pushdecl_class_level (value);
1458 return value;
1459 }
1460 if (TREE_CODE (value) == FIELD_DECL)
1461 {
1462 if (asmspec)
1463 {
1464 /* This must override the asm specifier which was placed
1465 by grokclassfn. Lay this out fresh. */
1466 DECL_RTL (value) = NULL_RTX;
1467 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1468 }
1469 if (DECL_INITIAL (value) == error_mark_node)
1470 init = error_mark_node;
1471 finish_decl (value, init, asmspec_tree, 1, flags);
1472 DECL_INITIAL (value) = init;
1473 DECL_IN_AGGR_P (value) = 1;
1474 return value;
1475 }
1476 if (TREE_CODE (value) == FUNCTION_DECL)
1477 {
1478 if (DECL_CHAIN (value) != NULL_TREE)
1479 {
1480 /* Need a fresh node here so that we don't get circularity
1481 when we link these together. */
1482 value = copy_node (value);
1483 /* When does this happen? */
1484 my_friendly_assert (init == NULL_TREE, 193);
1485 }
1486 if (asmspec)
1487 {
1488 /* This must override the asm specifier which was placed
1489 by grokclassfn. Lay this out fresh. */
1490 DECL_RTL (value) = NULL_RTX;
1491 DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
1492 }
1493 finish_decl (value, init, asmspec_tree, 1, flags);
1494
1495 /* Pass friends back this way. */
1496 if (DECL_FRIEND_P (value))
1497 return void_type_node;
1498
1499 #if 0 /* Just because a fn is declared doesn't mean we'll try to define it. */
1500 if (current_function_decl && ! IS_SIGNATURE (current_class_type))
1501 cp_error ("method `%#D' of local class must be defined in class body",
1502 value);
1503 #endif
1504
1505 DECL_IN_AGGR_P (value) = 1;
1506 return value;
1507 }
1508 my_friendly_abort (21);
1509 /* NOTREACHED */
1510 return NULL_TREE;
1511 }
1512
1513 /* Like `grokfield', but for bitfields.
1514 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1515
1516 tree
1517 grokbitfield (declarator, declspecs, width)
1518 tree declarator, declspecs, width;
1519 {
1520 register tree value = grokdeclarator (declarator, declspecs, BITFIELD, 0, NULL_TREE);
1521
1522 if (! value) return NULL_TREE; /* friends went bad. */
1523
1524 /* Pass friendly classes back. */
1525 if (TREE_CODE (value) == VOID_TYPE)
1526 return void_type_node;
1527
1528 if (TREE_CODE (value) == TYPE_DECL)
1529 {
1530 cp_error ("cannot declare `%D' to be a bitfield type", value);
1531 return NULL_TREE;
1532 }
1533
1534 if (IS_SIGNATURE (current_class_type))
1535 {
1536 error ("field declaration not allowed in signature");
1537 return void_type_node;
1538 }
1539
1540 if (DECL_IN_AGGR_P (value))
1541 {
1542 cp_error ("`%D' is already defined in the class %T", value,
1543 DECL_CONTEXT (value));
1544 return void_type_node;
1545 }
1546
1547 GNU_xref_member (current_class_name, value);
1548
1549 if (TREE_STATIC (value))
1550 {
1551 cp_error ("static member `%D' cannot be a bitfield", value);
1552 return NULL_TREE;
1553 }
1554 finish_decl (value, NULL_TREE, NULL_TREE, 0, 0);
1555
1556 if (width != error_mark_node)
1557 {
1558 /* detect invalid field size. */
1559 if (TREE_CODE (width) == CONST_DECL)
1560 width = DECL_INITIAL (width);
1561 else if (TREE_READONLY_DECL_P (width))
1562 width = decl_constant_value (width);
1563 if (TREE_CODE (width) != INTEGER_CST)
1564 {
1565 cp_error ("structure field `%D' width not an integer constant",
1566 value);
1567 DECL_INITIAL (value) = NULL_TREE;
1568 }
1569 else
1570 {
1571 constant_expression_warning (width);
1572 DECL_INITIAL (value) = width;
1573 DECL_BIT_FIELD (value) = 1;
1574 }
1575 }
1576
1577 DECL_IN_AGGR_P (value) = 1;
1578 return value;
1579 }
1580
1581 #if 0
1582 /* Like GROKFIELD, except that the declarator has been
1583 buried in DECLSPECS. Find the declarator, and
1584 return something that looks like it came from
1585 GROKFIELD. */
1586 tree
1587 groktypefield (declspecs, parmlist)
1588 tree declspecs;
1589 tree parmlist;
1590 {
1591 tree spec = declspecs;
1592 tree prev = NULL_TREE;
1593
1594 tree type_id = NULL_TREE;
1595 tree quals = NULL_TREE;
1596 tree lengths = NULL_TREE;
1597 tree decl = NULL_TREE;
1598
1599 while (spec)
1600 {
1601 register tree id = TREE_VALUE (spec);
1602
1603 if (TREE_CODE (spec) != TREE_LIST)
1604 /* Certain parse errors slip through. For example,
1605 `int class ();' is not caught by the parser. Try
1606 weakly to recover here. */
1607 return NULL_TREE;
1608
1609 if (TREE_CODE (id) == TYPE_DECL
1610 || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
1611 {
1612 /* We have a constructor/destructor or
1613 conversion operator. Use it. */
1614 if (prev)
1615 TREE_CHAIN (prev) = TREE_CHAIN (spec);
1616 else
1617 declspecs = TREE_CHAIN (spec);
1618
1619 type_id = id;
1620 goto found;
1621 }
1622 prev = spec;
1623 spec = TREE_CHAIN (spec);
1624 }
1625
1626 /* Nope, we have a conversion operator to a scalar type or something
1627 else, that includes things like constructor declarations for
1628 templates. */
1629 spec = declspecs;
1630 while (spec)
1631 {
1632 tree id = TREE_VALUE (spec);
1633
1634 if (TREE_CODE (id) == IDENTIFIER_NODE)
1635 {
1636 if (id == ridpointers[(int)RID_INT]
1637 || id == ridpointers[(int)RID_DOUBLE]
1638 || id == ridpointers[(int)RID_FLOAT]
1639 || id == ridpointers[(int)RID_WCHAR])
1640 {
1641 if (type_id)
1642 error ("extra `%s' ignored",
1643 IDENTIFIER_POINTER (id));
1644 else
1645 type_id = id;
1646 }
1647 else if (id == ridpointers[(int)RID_LONG]
1648 || id == ridpointers[(int)RID_SHORT]
1649 || id == ridpointers[(int)RID_CHAR])
1650 {
1651 lengths = tree_cons (NULL_TREE, id, lengths);
1652 }
1653 else if (id == ridpointers[(int)RID_VOID])
1654 {
1655 if (type_id)
1656 error ("spurious `void' type ignored");
1657 else
1658 error ("conversion to `void' type invalid");
1659 }
1660 else if (id == ridpointers[(int)RID_AUTO]
1661 || id == ridpointers[(int)RID_REGISTER]
1662 || id == ridpointers[(int)RID_TYPEDEF]
1663 || id == ridpointers[(int)RID_CONST]
1664 || id == ridpointers[(int)RID_VOLATILE])
1665 {
1666 error ("type specifier `%s' used invalidly",
1667 IDENTIFIER_POINTER (id));
1668 }
1669 else if (id == ridpointers[(int)RID_FRIEND]
1670 || id == ridpointers[(int)RID_VIRTUAL]
1671 || id == ridpointers[(int)RID_INLINE]
1672 || id == ridpointers[(int)RID_UNSIGNED]
1673 || id == ridpointers[(int)RID_SIGNED]
1674 || id == ridpointers[(int)RID_STATIC]
1675 || id == ridpointers[(int)RID_EXTERN])
1676 {
1677 quals = tree_cons (NULL_TREE, id, quals);
1678 }
1679 else
1680 {
1681 /* Happens when we have a global typedef
1682 and a class-local member function with
1683 the same name. */
1684 type_id = id;
1685 goto found;
1686 }
1687 }
1688 else if (TREE_CODE (id) == RECORD_TYPE)
1689 {
1690 type_id = TYPE_NAME (id);
1691 if (TREE_CODE (type_id) == TYPE_DECL)
1692 type_id = DECL_NAME (type_id);
1693 if (type_id == NULL_TREE)
1694 error ("identifier for aggregate type conversion omitted");
1695 }
1696 else if (TREE_CODE_CLASS (TREE_CODE (id)) == 't')
1697 error ("`operator' missing on conversion operator or tag missing from type");
1698 else
1699 my_friendly_abort (194);
1700 spec = TREE_CHAIN (spec);
1701 }
1702
1703 if (type_id)
1704 declspecs = chainon (lengths, quals);
1705 else if (lengths)
1706 {
1707 if (TREE_CHAIN (lengths))
1708 error ("multiple length specifiers");
1709 type_id = ridpointers[(int)RID_INT];
1710 declspecs = chainon (lengths, quals);
1711 }
1712 else if (quals)
1713 {
1714 error ("no type given, defaulting to `operator int ...'");
1715 type_id = ridpointers[(int)RID_INT];
1716 declspecs = quals;
1717 }
1718 else
1719 return NULL_TREE;
1720
1721 found:
1722 decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
1723 declspecs, FIELD, 0, NULL_TREE);
1724 if (decl == NULL_TREE)
1725 return NULL_TREE;
1726
1727 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CHAIN (decl) != NULL_TREE)
1728 {
1729 /* Need a fresh node here so that we don't get circularity
1730 when we link these together. */
1731 decl = copy_node (decl);
1732 }
1733
1734 if (decl == void_type_node
1735 || (TREE_CODE (decl) == FUNCTION_DECL
1736 && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
1737 /* bunch of friends. */
1738 return decl;
1739
1740 if (DECL_IN_AGGR_P (decl))
1741 {
1742 cp_error ("`%D' already defined in the class ", decl);
1743 return void_type_node;
1744 }
1745
1746 finish_decl (decl, NULL_TREE, NULL_TREE, 0, 0);
1747
1748 /* If this declaration is common to another declaration
1749 complain about such redundancy, and return NULL_TREE
1750 so that we don't build a circular list. */
1751 if (DECL_CHAIN (decl))
1752 {
1753 cp_error ("function `%D' declared twice in class %T", decl,
1754 DECL_CONTEXT (decl));
1755 return NULL_TREE;
1756 }
1757 DECL_IN_AGGR_P (decl) = 1;
1758 return decl;
1759 }
1760 #endif
1761
1762 tree
1763 grokoptypename (declspecs, declarator)
1764 tree declspecs, declarator;
1765 {
1766 tree t = grokdeclarator (declarator, declspecs, TYPENAME, 0, NULL_TREE);
1767 return build_typename_overload (t);
1768 }
1769
1770 /* When a function is declared with an initializer,
1771 do the right thing. Currently, there are two possibilities:
1772
1773 class B
1774 {
1775 public:
1776 // initialization possibility #1.
1777 virtual void f () = 0;
1778 int g ();
1779 };
1780
1781 class D1 : B
1782 {
1783 public:
1784 int d1;
1785 // error, no f ();
1786 };
1787
1788 class D2 : B
1789 {
1790 public:
1791 int d2;
1792 void f ();
1793 };
1794
1795 class D3 : B
1796 {
1797 public:
1798 int d3;
1799 // initialization possibility #2
1800 void f () = B::f;
1801 };
1802
1803 */
1804
1805 int
1806 copy_assignment_arg_p (parmtype, virtualp)
1807 tree parmtype;
1808 int virtualp;
1809 {
1810 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
1811 parmtype = TREE_TYPE (parmtype);
1812
1813 if ((TYPE_MAIN_VARIANT (parmtype) == current_class_type)
1814 || (virtualp && DERIVED_FROM_P (parmtype, current_class_type)))
1815 return 1;
1816
1817 return 0;
1818 }
1819
1820 static void
1821 grok_function_init (decl, init)
1822 tree decl;
1823 tree init;
1824 {
1825 /* An initializer for a function tells how this function should
1826 be inherited. */
1827 tree type = TREE_TYPE (decl);
1828
1829 if (TREE_CODE (type) == FUNCTION_TYPE)
1830 cp_error ("initializer specified for non-member function `%D'", decl);
1831 else if (DECL_VINDEX (decl) == NULL_TREE)
1832 cp_error ("initializer specified for non-virtual method `%D'", decl);
1833 else if (integer_zerop (init))
1834 {
1835 #if 0
1836 /* Mark this function as being "defined". */
1837 DECL_INITIAL (decl) = error_mark_node;
1838 /* pure virtual destructors must be defined. */
1839 /* pure virtual needs to be defined (as abort) only when put in
1840 vtbl. For wellformed call, it should be itself. pr4737 */
1841 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
1842 {
1843 extern tree abort_fndecl;
1844 /* Give this node rtl from `abort'. */
1845 DECL_RTL (decl) = DECL_RTL (abort_fndecl);
1846 }
1847 #endif
1848 DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
1849 if (DECL_NAME (decl) == ansi_opname [(int) MODIFY_EXPR])
1850 {
1851 tree parmtype
1852 = TREE_VALUE (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))));
1853
1854 if (copy_assignment_arg_p (parmtype, 1))
1855 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
1856 }
1857 }
1858 else if (TREE_CODE (init) == OFFSET_REF
1859 && TREE_OPERAND (init, 0) == NULL_TREE
1860 && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
1861 {
1862 tree basetype = DECL_CLASS_CONTEXT (init);
1863 tree basefn = TREE_OPERAND (init, 1);
1864 if (TREE_CODE (basefn) != FUNCTION_DECL)
1865 cp_error ("non-method initializer invalid for method `%D'", decl);
1866 else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
1867 sorry ("base member function from other than first base class");
1868 else
1869 {
1870 tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
1871 if (binfo == error_mark_node)
1872 ;
1873 else if (binfo == 0)
1874 error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
1875 TYPE_METHOD_BASETYPE (type));
1876 else
1877 {
1878 /* Mark this function as being defined,
1879 and give it new rtl. */
1880 DECL_INITIAL (decl) = error_mark_node;
1881 DECL_RTL (decl) = DECL_RTL (basefn);
1882 }
1883 }
1884 }
1885 else
1886 cp_error ("invalid initializer for virtual method `%D'", decl);
1887 }
1888 \f
1889 /* When we get a declaration of the form
1890
1891 type cname::fname ...
1892
1893 the node for `cname::fname' gets built here in a special way.
1894 Namely, we push into `cname's scope. When this declaration is
1895 processed, we pop back out. */
1896 tree
1897 build_push_scope (cname, name)
1898 tree cname;
1899 tree name;
1900 {
1901 extern int current_class_depth;
1902 tree ctype, rval;
1903 int is_ttp = 0;
1904
1905 if (cname == error_mark_node)
1906 return error_mark_node;
1907
1908 ctype = IDENTIFIER_TYPE_VALUE (cname);
1909
1910 if (TREE_CODE (ctype) == TEMPLATE_TYPE_PARM)
1911 is_ttp = 1;
1912 else if (ctype == NULL_TREE || ! IS_AGGR_TYPE (ctype))
1913 {
1914 cp_error ("`%T' not defined as aggregate type", cname);
1915 return name;
1916 }
1917 else if (IS_SIGNATURE (ctype))
1918 {
1919 error ("cannot push into signature scope, scope resolution operator ignored");
1920 return name;
1921 }
1922
1923 rval = build_parse_node (SCOPE_REF, cname, name);
1924
1925 /* Don't need to push the scope if we're already in it.
1926 We also don't need to push the scope for a ptr-to-member/method. */
1927
1928 if (ctype == current_class_type || TREE_CODE (name) != IDENTIFIER_NODE
1929 || is_ttp)
1930 return rval;
1931
1932 /* We do need to push the scope in this case, since CTYPE helps
1933 determine subsequent intializers (i.e., Foo::Bar x = foo_enum_1;). */
1934
1935 push_nested_class (ctype, 3);
1936 TREE_COMPLEXITY (rval) = current_class_depth;
1937 return rval;
1938 }
1939
1940 void
1941 cplus_decl_attributes (decl, attributes, prefix_attributes)
1942 tree decl, attributes, prefix_attributes;
1943 {
1944 if (decl && decl != void_type_node)
1945 decl_attributes (decl, attributes, prefix_attributes);
1946 }
1947 \f
1948 /* CONSTRUCTOR_NAME:
1949 Return the name for the constructor (or destructor) for the
1950 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1951 IDENTIFIER_NODE. When given a template, this routine doesn't
1952 lose the specialization. */
1953 tree
1954 constructor_name_full (thing)
1955 tree thing;
1956 {
1957 if (TREE_CODE (thing) == UNINSTANTIATED_P_TYPE)
1958 return DECL_NAME (UPT_TEMPLATE (thing));
1959 if (IS_AGGR_TYPE_CODE (TREE_CODE (thing)))
1960 {
1961 if (TYPE_WAS_ANONYMOUS (thing) && TYPE_HAS_CONSTRUCTOR (thing))
1962 thing = DECL_NAME (TREE_VEC_ELT (TYPE_METHODS (thing), 0));
1963 else
1964 thing = TYPE_NAME (thing);
1965 }
1966 if (TREE_CODE (thing) == TYPE_DECL
1967 || (TREE_CODE (thing) == TEMPLATE_DECL
1968 && DECL_TEMPLATE_IS_CLASS (thing)))
1969 thing = DECL_NAME (thing);
1970 my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
1971 return thing;
1972 }
1973
1974 /* CONSTRUCTOR_NAME:
1975 Return the name for the constructor (or destructor) for the
1976 specified class. Argument can be RECORD_TYPE, TYPE_DECL, or
1977 IDENTIFIER_NODE. When given a template, return the plain
1978 unspecialized name. */
1979 tree
1980 constructor_name (thing)
1981 tree thing;
1982 {
1983 tree t;
1984 thing = constructor_name_full (thing);
1985 t = IDENTIFIER_TEMPLATE (thing);
1986 if (!t)
1987 return thing;
1988 t = TREE_PURPOSE (t);
1989 return DECL_NAME (t);
1990 }
1991 \f
1992 /* Cache the value of this class's main virtual function table pointer
1993 in a register variable. This will save one indirection if a
1994 more than one virtual function call is made this function. */
1995 void
1996 setup_vtbl_ptr ()
1997 {
1998 extern rtx base_init_insns;
1999
2000 if (base_init_insns == 0
2001 && DECL_CONSTRUCTOR_P (current_function_decl))
2002 emit_base_init (current_class_type, 0);
2003
2004 #if 0
2005 /* This has something a little wrong with it.
2006
2007 On a sun4, code like:
2008
2009 be L6
2010 ld [%i0],%o1
2011
2012 is generated, when the below is used when -O4 is given. The delay
2013 slot it filled with an instruction that is safe, when this isn't
2014 used, like in:
2015
2016 be L6
2017 sethi %hi(LC1),%o0
2018 ld [%i0],%o1
2019
2020 on code like:
2021
2022 struct A {
2023 virtual void print() { printf("xxx"); }
2024 void f();
2025 };
2026
2027 void A::f() {
2028 if (this) {
2029 print();
2030 } else {
2031 printf("0");
2032 }
2033 }
2034
2035 And that is why this is disabled for now. (mrs)
2036 */
2037
2038 if ((flag_this_is_variable & 1) == 0
2039 && optimize
2040 && current_class_type
2041 && CLASSTYPE_VSIZE (current_class_type)
2042 && ! DECL_STATIC_FUNCTION_P (current_function_decl))
2043 {
2044 tree vfield = build_vfield_ref (C_C_D, current_class_type);
2045 current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type);
2046 DECL_RTL (current_vtable_decl) = 0;
2047 DECL_INITIAL (current_vtable_decl) = error_mark_node;
2048 /* Have to cast the initializer, since it may have come from a
2049 more base class then we ascribe CURRENT_VTABLE_DECL to be. */
2050 finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield, 0), NULL_TREE, 0, 0);
2051 current_vtable_decl = build_indirect_ref (current_vtable_decl, NULL_PTR);
2052 }
2053 else
2054 #endif
2055 current_vtable_decl = NULL_TREE;
2056 }
2057
2058 /* Record the existence of an addressable inline function. */
2059 void
2060 mark_inline_for_output (decl)
2061 tree decl;
2062 {
2063 decl = DECL_MAIN_VARIANT (decl);
2064 if (DECL_SAVED_INLINE (decl))
2065 return;
2066 my_friendly_assert (TREE_PERMANENT (decl), 363);
2067 DECL_SAVED_INLINE (decl) = 1;
2068 if (DECL_PENDING_INLINE_INFO (decl) != 0
2069 && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
2070 {
2071 struct pending_inline *t = pending_inlines;
2072 my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
2073 while (t)
2074 {
2075 if (t == DECL_PENDING_INLINE_INFO (decl))
2076 break;
2077 t = t->next;
2078 }
2079 if (t == 0)
2080 {
2081 t = DECL_PENDING_INLINE_INFO (decl);
2082 t->next = pending_inlines;
2083 pending_inlines = t;
2084 }
2085 DECL_PENDING_INLINE_INFO (decl) = 0;
2086 }
2087 saved_inlines = perm_tree_cons (NULL_TREE, decl, saved_inlines);
2088 }
2089
2090 void
2091 clear_temp_name ()
2092 {
2093 temp_name_counter = 0;
2094 }
2095
2096 /* Hand off a unique name which can be used for variable we don't really
2097 want to know about anyway, for example, the anonymous variables which
2098 are needed to make references work. Declare this thing so we can use it.
2099 The variable created will be of type TYPE.
2100
2101 STATICP is nonzero if this variable should be static. */
2102
2103 tree
2104 get_temp_name (type, staticp)
2105 tree type;
2106 int staticp;
2107 {
2108 char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
2109 tree decl;
2110 int toplev = global_bindings_p ();
2111
2112 push_obstacks_nochange ();
2113 if (toplev || staticp)
2114 {
2115 end_temporary_allocation ();
2116 sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
2117 decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
2118 }
2119 else
2120 {
2121 sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
2122 decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
2123 }
2124 TREE_USED (decl) = 1;
2125 TREE_STATIC (decl) = staticp;
2126
2127 /* If this is a local variable, then lay out its rtl now.
2128 Otherwise, callers of this function are responsible for dealing
2129 with this variable's rtl. */
2130 if (! toplev)
2131 {
2132 expand_decl (decl);
2133 expand_decl_init (decl);
2134 }
2135 pop_obstacks ();
2136
2137 return decl;
2138 }
2139
2140 /* Get a variable which we can use for multiple assignments.
2141 It is not entered into current_binding_level, because
2142 that breaks things when it comes time to do final cleanups
2143 (which take place "outside" the binding contour of the function). */
2144 tree
2145 get_temp_regvar (type, init)
2146 tree type, init;
2147 {
2148 static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
2149 tree decl;
2150
2151 sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
2152 decl = build_decl (VAR_DECL, get_identifier (buf), type);
2153 TREE_USED (decl) = 1;
2154 DECL_REGISTER (decl) = 1;
2155
2156 if (init)
2157 store_init_value (decl, init);
2158
2159 /* We can expand these without fear, since they cannot need
2160 constructors or destructors. */
2161 expand_decl (decl);
2162 expand_decl_init (decl);
2163
2164 if (type_needs_gc_entry (type))
2165 DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
2166
2167 return decl;
2168 }
2169
2170 /* Make the macro TEMP_NAME_P available to units which do not
2171 include c-tree.h. */
2172 int
2173 temp_name_p (decl)
2174 tree decl;
2175 {
2176 return TEMP_NAME_P (decl);
2177 }
2178
2179 /* Finish off the processing of a UNION_TYPE structure.
2180 If there are static members, then all members are
2181 static, and must be laid out together. If the
2182 union is an anonymous union, we arrange for that
2183 as well. PUBLIC_P is nonzero if this union is
2184 not declared static. */
2185 void
2186 finish_anon_union (anon_union_decl)
2187 tree anon_union_decl;
2188 {
2189 tree type = TREE_TYPE (anon_union_decl);
2190 tree field, main_decl = NULL_TREE;
2191 tree elems = NULL_TREE;
2192 int public_p = TREE_PUBLIC (anon_union_decl);
2193 int static_p = TREE_STATIC (anon_union_decl);
2194 int external_p = DECL_EXTERNAL (anon_union_decl);
2195
2196 if ((field = TYPE_FIELDS (type)) == NULL_TREE)
2197 return;
2198
2199 if (public_p)
2200 {
2201 error ("global anonymous unions must be declared static");
2202 return;
2203 }
2204
2205 for (; field; field = TREE_CHAIN (field))
2206 {
2207 tree decl;
2208 if (TREE_CODE (field) != FIELD_DECL)
2209 continue;
2210
2211 decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
2212 /* tell `pushdecl' that this is not tentative. */
2213 DECL_INITIAL (decl) = error_mark_node;
2214 TREE_PUBLIC (decl) = public_p;
2215 TREE_STATIC (decl) = static_p;
2216 DECL_EXTERNAL (decl) = external_p;
2217 decl = pushdecl (decl);
2218
2219 /* Only write out one anon union element--choose the one that
2220 can hold them all. */
2221 if (main_decl == NULL_TREE
2222 && simple_cst_equal (DECL_SIZE (decl), DECL_SIZE (anon_union_decl)))
2223 {
2224 main_decl = decl;
2225 }
2226 else
2227 {
2228 /* ??? This causes there to be no debug info written out
2229 about this decl. */
2230 TREE_ASM_WRITTEN (decl) = 1;
2231 }
2232
2233 DECL_INITIAL (decl) = NULL_TREE;
2234 /* If there's a cleanup to do, it belongs in the
2235 TREE_PURPOSE of the following TREE_LIST. */
2236 elems = tree_cons (NULL_TREE, decl, elems);
2237 TREE_TYPE (elems) = type;
2238 }
2239 if (static_p)
2240 {
2241 if (main_decl)
2242 {
2243 make_decl_rtl (main_decl, 0, global_bindings_p ());
2244 DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
2245 }
2246 else
2247 {
2248 warning ("anonymous union with no members");
2249 return;
2250 }
2251 }
2252
2253 /* The following call assumes that there are never any cleanups
2254 for anonymous unions--a reasonable assumption. */
2255 expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
2256
2257 if (flag_cadillac)
2258 cadillac_finish_anon_union (anon_union_decl);
2259 }
2260
2261 /* Finish and output a table which is generated by the compiler.
2262 NAME is the name to give the table.
2263 TYPE is the type of the table entry.
2264 INIT is all the elements in the table.
2265 PUBLICP is non-zero if this table should be given external access. */
2266 tree
2267 finish_table (name, type, init, publicp)
2268 tree name, type, init;
2269 int publicp;
2270 {
2271 tree itype, atype, decl;
2272 static tree empty_table;
2273 int is_empty = 0;
2274 tree asmspec;
2275
2276 itype = build_index_type (size_int (list_length (init) - 1));
2277 atype = build_cplus_array_type (type, itype);
2278 layout_type (atype);
2279
2280 if (TREE_VALUE (init) == integer_zero_node
2281 && TREE_CHAIN (init) == NULL_TREE)
2282 {
2283 #if 0
2284 if (empty_table == NULL_TREE)
2285 #endif
2286 {
2287 empty_table = get_temp_name (atype, 1);
2288 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2289 TREE_CONSTANT (init) = 1;
2290 TREE_STATIC (init) = 1;
2291 DECL_INITIAL (empty_table) = init;
2292 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2293 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2294 finish_decl (empty_table, init, asmspec, 0, 0);
2295 }
2296 is_empty = 1;
2297 }
2298
2299 if (name == NULL_TREE)
2300 {
2301 if (is_empty)
2302 return empty_table;
2303 decl = get_temp_name (atype, 1);
2304 }
2305 else
2306 {
2307 decl = build_decl (VAR_DECL, name, atype);
2308 decl = pushdecl (decl);
2309 TREE_STATIC (decl) = 1;
2310 }
2311
2312 if (is_empty == 0)
2313 {
2314 TREE_PUBLIC (decl) = publicp;
2315 init = build (CONSTRUCTOR, atype, NULL_TREE, init);
2316 TREE_CONSTANT (init) = 1;
2317 TREE_STATIC (init) = 1;
2318 DECL_INITIAL (decl) = init;
2319 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
2320 IDENTIFIER_POINTER (DECL_NAME (decl)));
2321 }
2322 else
2323 {
2324 /* This will cause DECL to point to EMPTY_TABLE in rtl-land. */
2325 DECL_EXTERNAL (decl) = 1;
2326 TREE_STATIC (decl) = 0;
2327 init = 0;
2328 asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
2329 IDENTIFIER_POINTER (DECL_NAME (empty_table)));
2330 }
2331
2332 finish_decl (decl, init, asmspec, 0, 0);
2333 return decl;
2334 }
2335
2336 /* Finish processing a builtin type TYPE. It's name is NAME,
2337 its fields are in the array FIELDS. LEN is the number of elements
2338 in FIELDS minus one, or put another way, it is the maximum subscript
2339 used in FIELDS.
2340
2341 It is given the same alignment as ALIGN_TYPE. */
2342 void
2343 finish_builtin_type (type, name, fields, len, align_type)
2344 tree type;
2345 char *name;
2346 tree fields[];
2347 int len;
2348 tree align_type;
2349 {
2350 register int i;
2351
2352 TYPE_FIELDS (type) = fields[0];
2353 for (i = 0; i < len; i++)
2354 {
2355 layout_type (TREE_TYPE (fields[i]));
2356 DECL_FIELD_CONTEXT (fields[i]) = type;
2357 TREE_CHAIN (fields[i]) = fields[i+1];
2358 }
2359 DECL_FIELD_CONTEXT (fields[i]) = type;
2360 DECL_CLASS_CONTEXT (fields[i]) = type;
2361 TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
2362 layout_type (type);
2363 #if 0 /* not yet, should get fixed properly later */
2364 TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
2365 #else
2366 TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
2367 #endif
2368 layout_decl (TYPE_NAME (type), 0);
2369 }
2370 \f
2371 /* Auxiliary functions to make type signatures for
2372 `operator new' and `operator delete' correspond to
2373 what compiler will be expecting. */
2374
2375 extern tree sizetype;
2376
2377 tree
2378 coerce_new_type (type)
2379 tree type;
2380 {
2381 int e1 = 0, e2 = 0;
2382
2383 if (TREE_CODE (type) == METHOD_TYPE)
2384 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
2385 if (TREE_TYPE (type) != ptr_type_node)
2386 e1 = 1, error ("`operator new' must return type `void *'");
2387
2388 /* Technically the type must be `size_t', but we may not know
2389 what that is. */
2390 if (TYPE_ARG_TYPES (type) == NULL_TREE)
2391 e1 = 1, error ("`operator new' takes type `size_t' parameter");
2392 else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
2393 || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
2394 e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
2395 if (e2)
2396 type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
2397 else if (e1)
2398 type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
2399 return type;
2400 }
2401
2402 tree
2403 coerce_delete_type (type)
2404 tree type;
2405 {
2406 int e1 = 0, e2 = 0, e3 = 0;
2407 tree arg_types = TYPE_ARG_TYPES (type);
2408
2409 if (TREE_CODE (type) == METHOD_TYPE)
2410 {
2411 type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
2412 arg_types = TREE_CHAIN (arg_types);
2413 }
2414 if (TREE_TYPE (type) != void_type_node)
2415 e1 = 1, error ("`operator delete' must return type `void'");
2416 if (arg_types == NULL_TREE
2417 || TREE_VALUE (arg_types) != ptr_type_node)
2418 e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
2419
2420 if (arg_types
2421 && TREE_CHAIN (arg_types)
2422 && TREE_CHAIN (arg_types) != void_list_node)
2423 {
2424 /* Again, technically this argument must be `size_t', but again
2425 we may not know what that is. */
2426 tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
2427 if (TREE_CODE (t2) != INTEGER_TYPE
2428 || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
2429 e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
2430 else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
2431 {
2432 e3 = 1;
2433 if (TREE_CHAIN (TREE_CHAIN (arg_types)))
2434 error ("too many arguments in declaration of `operator delete'");
2435 else
2436 error ("`...' invalid in specification of `operator delete'");
2437 }
2438 }
2439 if (e3)
2440 arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
2441 else if (e3 |= e2)
2442 {
2443 if (arg_types == NULL_TREE)
2444 arg_types = tree_cons (NULL_TREE, ptr_type_node, void_list_node);
2445 else
2446 arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
2447 }
2448 else e3 |= e1;
2449
2450 if (e3)
2451 type = build_function_type (void_type_node, arg_types);
2452
2453 return type;
2454 }
2455 \f
2456 static void
2457 mark_vtable_entries (decl)
2458 tree decl;
2459 {
2460 tree entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)));
2461
2462 for (; entries; entries = TREE_CHAIN (entries))
2463 {
2464 tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries));
2465 tree fn = TREE_OPERAND (fnaddr, 0);
2466 TREE_ADDRESSABLE (fn) = 1;
2467 if (DECL_ABSTRACT_VIRTUAL_P (fn))
2468 {
2469 extern tree abort_fndecl;
2470 if (flag_vtable_thunks)
2471 fnaddr = TREE_VALUE (entries);
2472 TREE_OPERAND (fnaddr, 0) = fn = abort_fndecl;
2473 }
2474 assemble_external (fn);
2475 }
2476 }
2477
2478 /* Set TREE_PUBLIC and/or DECL_EXTERN on the vtable DECL,
2479 based on TYPE and other static flags.
2480
2481 Note that anything public is tagged TREE_PUBLIC, whether
2482 it's public in this file or in another one. */
2483
2484 void
2485 import_export_vtable (decl, type, final)
2486 tree decl, type;
2487 int final;
2488 {
2489 if (DECL_INTERFACE_KNOWN (decl))
2490 return;
2491
2492 /* +e0 or +e1 */
2493 if (write_virtuals < 2 && write_virtuals != 0)
2494 {
2495 TREE_PUBLIC (decl) = 1;
2496 if (write_virtuals < 0)
2497 DECL_EXTERNAL (decl) = 1;
2498 DECL_INTERFACE_KNOWN (decl) = 1;
2499 }
2500 else if (CLASSTYPE_INTERFACE_KNOWN (type))
2501 {
2502 TREE_PUBLIC (decl) = 1;
2503 DECL_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
2504 DECL_INTERFACE_KNOWN (decl) = 1;
2505 }
2506 else
2507 {
2508 /* We can only wait to decide if we have real non-inline virtual
2509 functions in our class, or if we come from a template. */
2510
2511 int found = CLASSTYPE_TEMPLATE_INSTANTIATION (type);
2512
2513 if (! found && ! final)
2514 {
2515 tree method;
2516 for (method = CLASSTYPE_METHODS (type); method != NULL_TREE;
2517 method = DECL_NEXT_METHOD (method))
2518 if (DECL_VINDEX (method) != NULL_TREE
2519 && ! DECL_THIS_INLINE (method)
2520 && ! DECL_ABSTRACT_VIRTUAL_P (method))
2521 {
2522 found = 1;
2523 break;
2524 }
2525 }
2526
2527 if (final || ! found)
2528 {
2529 #ifdef ASSEMBLE_EXTERNAL
2530 if (TREE_PUBLIC (decl))
2531 cp_error ("all virtual functions redeclared inline");
2532 #endif
2533 TREE_PUBLIC (decl) = 0;
2534 DECL_EXTERNAL (decl) = 0;
2535 }
2536 else
2537 {
2538 TREE_PUBLIC (decl) = 1;
2539 DECL_EXTERNAL (decl) = 1;
2540 }
2541 }
2542 }
2543
2544 static void
2545 import_export_template (type)
2546 tree type;
2547 {
2548 if (CLASSTYPE_IMPLICIT_INSTANTIATION (type)
2549 && ! flag_implicit_templates
2550 && CLASSTYPE_INTERFACE_UNKNOWN (type))
2551 {
2552 SET_CLASSTYPE_INTERFACE_KNOWN (type);
2553 CLASSTYPE_INTERFACE_ONLY (type) = 1;
2554 CLASSTYPE_VTABLE_NEEDS_WRITING (type) = 0;
2555 }
2556 }
2557
2558 static void
2559 finish_prevtable_vardecl (prev, vars)
2560 tree prev, vars;
2561 {
2562 tree ctype = DECL_CONTEXT (vars);
2563 import_export_template (ctype);
2564
2565 if (CLASSTYPE_INTERFACE_UNKNOWN (ctype) && TYPE_VIRTUAL_P (ctype)
2566 && ! CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
2567 {
2568 tree method;
2569 for (method = CLASSTYPE_METHODS (ctype); method != NULL_TREE;
2570 method = DECL_NEXT_METHOD (method))
2571 {
2572 if (DECL_VINDEX (method) != NULL_TREE
2573 && !DECL_THIS_INLINE (method)
2574 && !DECL_ABSTRACT_VIRTUAL_P (method))
2575 {
2576 SET_CLASSTYPE_INTERFACE_KNOWN (ctype);
2577 CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) = ! DECL_EXTERNAL (method);
2578 CLASSTYPE_INTERFACE_ONLY (ctype) = DECL_EXTERNAL (method);
2579 break;
2580 }
2581 }
2582 }
2583
2584 import_export_vtable (vars, ctype, 1);
2585
2586 /* We cannot use TREE_USED here, as it may be set by the expanding of a
2587 ctor that is used to build a global object. The long term plan is to
2588 make the TD entries statically initialized and move this to
2589 finish_vtable_vardecl time. */
2590 if (flag_rtti && write_virtuals >= 0
2591 && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || 1 || TREE_USED (vars)))
2592 {
2593 /* Kick out the type descriptor before we dump out global
2594 initializers, as they are initialized at run time and
2595 we have to find them when we scan for things that need initialized
2596 at the top level. */
2597 build_t_desc (ctype, 1);
2598 }
2599 }
2600
2601 static void
2602 finish_vtable_vardecl (prev, vars)
2603 tree prev, vars;
2604 {
2605 if (write_virtuals >= 0
2606 && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars)))
2607 {
2608 #if 0
2609 /* The long term plan it to make the TD entries statically initialized,
2610 have the entries built and emitted here. When that happens, this
2611 can be enabled, and the other call to build_t_desc removed. */
2612 /* Kick out the type descriptor before writing out the vtable. */
2613 if (flag_rtti)
2614 build_t_desc (DECL_CONTEXT (vars), 1);
2615 #endif
2616
2617 /* Write it out. */
2618 mark_vtable_entries (vars);
2619 if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
2620 store_init_value (vars, DECL_INITIAL (vars));
2621
2622 #ifdef DWARF_DEBUGGING_INFO
2623 if (write_symbols == DWARF_DEBUG)
2624 {
2625 /* Mark the VAR_DECL node representing the vtable itself as a
2626 "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2627 It is rather important that such things be ignored because
2628 any effort to actually generate DWARF for them will run
2629 into trouble when/if we encounter code like:
2630
2631 #pragma interface
2632 struct S { virtual void member (); };
2633
2634 because the artificial declaration of the vtable itself (as
2635 manufactured by the g++ front end) will say that the vtable
2636 is a static member of `S' but only *after* the debug output
2637 for the definition of `S' has already been output. This causes
2638 grief because the DWARF entry for the definition of the vtable
2639 will try to refer back to an earlier *declaration* of the
2640 vtable as a static member of `S' and there won't be one.
2641 We might be able to arrange to have the "vtable static member"
2642 attached to the member list for `S' before the debug info for
2643 `S' get written (which would solve the problem) but that would
2644 require more intrusive changes to the g++ front end. */
2645
2646 DECL_IGNORED_P (vars) = 1;
2647 }
2648 #endif /* DWARF_DEBUGGING_INFO */
2649
2650 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2651 }
2652 else if (! TREE_USED (vars))
2653 /* We don't know what to do with this one yet. */
2654 return;
2655
2656 /* We know that PREV must be non-zero here. */
2657 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2658 }
2659
2660 static void
2661 prune_vtable_vardecl (prev, vars)
2662 tree prev, vars;
2663 {
2664 /* We know that PREV must be non-zero here. */
2665 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2666 }
2667
2668 void
2669 walk_vtables (typedecl_fn, vardecl_fn)
2670 register void (*typedecl_fn)();
2671 register void (*vardecl_fn)();
2672 {
2673 tree prev, vars;
2674
2675 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2676 {
2677 register tree type = TREE_TYPE (vars);
2678
2679 if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2680 {
2681 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2682
2683 if (prev && TREE_CHAIN (prev) != vars)
2684 continue;
2685 }
2686 else if (TREE_CODE (vars) == TYPE_DECL
2687 && type != error_mark_node
2688 && TYPE_LANG_SPECIFIC (type)
2689 && CLASSTYPE_VSIZE (type))
2690 {
2691 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2692 }
2693
2694 prev = vars;
2695 }
2696 }
2697
2698 static void
2699 finish_sigtable_vardecl (prev, vars)
2700 tree prev, vars;
2701 {
2702 /* We don't need to mark sigtable entries as addressable here as is done
2703 for vtables. Since sigtables, unlike vtables, are always written out,
2704 that was already done in build_signature_table_constructor. */
2705
2706 rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2707
2708 /* We know that PREV must be non-zero here. */
2709 TREE_CHAIN (prev) = TREE_CHAIN (vars);
2710 }
2711
2712 void
2713 walk_sigtables (typedecl_fn, vardecl_fn)
2714 register void (*typedecl_fn)();
2715 register void (*vardecl_fn)();
2716 {
2717 tree prev, vars;
2718
2719 for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2720 {
2721 register tree type = TREE_TYPE (vars);
2722
2723 if (TREE_CODE (vars) == TYPE_DECL
2724 && type != error_mark_node
2725 && IS_SIGNATURE (type))
2726 {
2727 if (typedecl_fn) (*typedecl_fn) (prev, vars);
2728 }
2729 else if (TREE_CODE (vars) == VAR_DECL
2730 && TREE_TYPE (vars) != error_mark_node
2731 && IS_SIGNATURE (TREE_TYPE (vars)))
2732 {
2733 if (vardecl_fn) (*vardecl_fn) (prev, vars);
2734 }
2735 else
2736 prev = vars;
2737 }
2738 }
2739
2740 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2741 inline function at end-of-file. */
2742
2743 void
2744 import_export_inline (decl)
2745 tree decl;
2746 {
2747 if (DECL_INTERFACE_KNOWN (decl))
2748 return;
2749
2750 if (DECL_TEMPLATE_INSTANTIATION (decl))
2751 {
2752 if (DECL_IMPLICIT_INSTANTIATION (decl) && flag_implicit_templates)
2753 TREE_PUBLIC (decl) = 0;
2754 else
2755 DECL_NOT_REALLY_EXTERN (decl) = 0;
2756 }
2757 else if (DECL_FUNCTION_MEMBER_P (decl))
2758 {
2759 tree ctype = DECL_CLASS_CONTEXT (decl);
2760 if (CLASSTYPE_INTERFACE_KNOWN (ctype))
2761 {
2762 DECL_NOT_REALLY_EXTERN (decl)
2763 = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2764 || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2765 }
2766 else
2767 TREE_PUBLIC (decl) = 0;
2768 }
2769 else
2770 TREE_PUBLIC (decl) = 0;
2771 }
2772
2773 extern int parse_time, varconst_time;
2774
2775 #define TIMEVAR(VAR, BODY) \
2776 do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
2777
2778 /* This routine is called from the last rule in yyparse ().
2779 Its job is to create all the code needed to initialize and
2780 destroy the global aggregates. We do the destruction
2781 first, since that way we only need to reverse the decls once. */
2782
2783 void
2784 finish_file ()
2785 {
2786 extern int lineno;
2787 int start_time, this_time;
2788
2789 tree fnname;
2790 tree vars = static_aggregates;
2791 int needs_cleaning = 0, needs_messing_up = 0;
2792
2793 if (flag_detailed_statistics)
2794 dump_tree_statistics ();
2795
2796 /* Bad parse errors. Just forget about it. */
2797 if (! global_bindings_p () || current_class_type)
2798 return;
2799
2800 start_time = get_run_time ();
2801
2802 /* Push into C language context, because that's all
2803 we'll need here. */
2804 push_lang_context (lang_name_c);
2805
2806 if (static_ctors || vars || might_have_exceptions_p ())
2807 needs_messing_up = 1;
2808 if (static_dtors)
2809 needs_cleaning = 1;
2810
2811 /* See if we really need the hassle. */
2812 while (vars && needs_cleaning == 0)
2813 {
2814 tree decl = TREE_VALUE (vars);
2815 tree type = TREE_TYPE (decl);
2816 if (TYPE_NEEDS_DESTRUCTOR (type))
2817 {
2818 needs_cleaning = 1;
2819 needs_messing_up = 1;
2820 break;
2821 }
2822 else
2823 needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type);
2824 vars = TREE_CHAIN (vars);
2825 }
2826
2827 /* Otherwise, GDB can get confused, because in only knows
2828 about source for LINENO-1 lines. */
2829 lineno -= 1;
2830
2831 interface_unknown = 1;
2832 interface_only = 0;
2833
2834 #if 1
2835 /* The reason for pushing garbage onto the global_binding_level is to
2836 ensure that we can slice out _DECLs which pertain to virtual function
2837 tables. If the last thing pushed onto the global_binding_level was a
2838 virtual function table, then slicing it out would slice away all the
2839 decls (i.e., we lose the head of the chain).
2840
2841 There are several ways of getting the same effect, from changing the
2842 way that iterators over the chain treat the elements that pertain to
2843 virtual function tables, moving the implementation of this code to
2844 decl.c (where we can manipulate global_binding_level directly),
2845 popping the garbage after pushing it and slicing away the vtable
2846 stuff, or just leaving it alone. */
2847
2848 /* Make last thing in global scope not be a virtual function table. */
2849 #if 0 /* not yet, should get fixed properly later */
2850 vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2851 #else
2852 vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2853 #endif
2854 DECL_IGNORED_P (vars) = 1;
2855 SET_DECL_ARTIFICIAL (vars);
2856 pushdecl (vars);
2857 #endif
2858
2859 /* Walk to mark the inline functions we need, then output them so
2860 that we can pick up any other tdecls that those routines need. */
2861 walk_vtables ((void (*)())0, finish_prevtable_vardecl);
2862
2863 if (needs_cleaning == 0)
2864 goto mess_up;
2865
2866 fnname = get_file_function_name ('D');
2867 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2868 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2869 store_parm_decls ();
2870
2871 pushlevel (0);
2872 clear_last_expr ();
2873 push_momentary ();
2874 expand_start_bindings (0);
2875
2876 /* These must be done in backward order to destroy,
2877 in which they happen to be! */
2878 for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2879 {
2880 tree decl = TREE_VALUE (vars);
2881 tree type = TREE_TYPE (decl);
2882 tree temp = TREE_PURPOSE (vars);
2883
2884 if (TYPE_NEEDS_DESTRUCTOR (type))
2885 {
2886 if (TREE_STATIC (vars))
2887 expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node, 1), 0);
2888 if (TREE_CODE (type) == ARRAY_TYPE)
2889 temp = decl;
2890 else
2891 {
2892 mark_addressable (decl);
2893 temp = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
2894 }
2895 temp = build_delete (TREE_TYPE (temp), temp,
2896 integer_two_node, LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2897 expand_expr_stmt (temp);
2898
2899 if (TREE_STATIC (vars))
2900 expand_end_cond ();
2901 }
2902 }
2903
2904 for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
2905 expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
2906 NULL_TREE));
2907
2908 expand_end_bindings (getdecls(), 1, 0);
2909 poplevel (1, 0, 0);
2910 pop_momentary ();
2911
2912 finish_function (lineno, 0, 0);
2913
2914 assemble_destructor (IDENTIFIER_POINTER (fnname));
2915
2916 /* if it needed cleaning, then it will need messing up: drop through */
2917
2918 mess_up:
2919 /* Must do this while we think we are at the top level. */
2920 vars = nreverse (static_aggregates);
2921 if (needs_messing_up)
2922 {
2923 fnname = get_file_function_name ('I');
2924 start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
2925 fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2926 store_parm_decls ();
2927
2928 pushlevel (0);
2929 clear_last_expr ();
2930 push_momentary ();
2931 expand_start_bindings (0);
2932
2933 if (might_have_exceptions_p ())
2934 register_exception_table ();
2935
2936 while (vars)
2937 {
2938 tree decl = TREE_VALUE (vars);
2939 tree init = TREE_PURPOSE (vars);
2940 tree old_cleanups = cleanups_this_call;
2941
2942 /* If this was a static attribute within some function's scope,
2943 then don't initialize it here. Also, don't bother
2944 with initializers that contain errors. */
2945 if (TREE_STATIC (vars)
2946 || (init && TREE_CODE (init) == TREE_LIST
2947 && value_member (error_mark_node, init)))
2948 {
2949 vars = TREE_CHAIN (vars);
2950 continue;
2951 }
2952
2953 if (TREE_CODE (decl) == VAR_DECL)
2954 {
2955 /* Set these global variables so that GDB at least puts
2956 us near the declaration which required the initialization. */
2957 input_filename = DECL_SOURCE_FILE (decl);
2958 lineno = DECL_SOURCE_LINE (decl);
2959 emit_note (input_filename, lineno);
2960
2961 /* 9.5p5: The initializer of a static member of a class has
2962 the same acess rights as a member function. */
2963 DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2964 DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
2965
2966 #if 0
2967 if (init)
2968 {
2969 if (TREE_CODE (init) == VAR_DECL)
2970 {
2971 /* This behavior results when there are
2972 multiple declarations of an aggregate,
2973 the last of which defines it. */
2974 if (DECL_RTL (init) == DECL_RTL (decl))
2975 {
2976 my_friendly_assert (DECL_INITIAL (decl) == error_mark_node
2977 || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
2978 && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE),
2979 199);
2980 init = DECL_INITIAL (init);
2981 if (TREE_CODE (init) == CONSTRUCTOR
2982 && CONSTRUCTOR_ELTS (init) == NULL_TREE)
2983 init = NULL_TREE;
2984 }
2985 else if (TREE_TYPE (decl) == TREE_TYPE (init))
2986 {
2987 #if 1
2988 my_friendly_abort (200);
2989 #else
2990 /* point to real decl's rtl anyway. */
2991 DECL_RTL (init) = DECL_RTL (decl);
2992 my_friendly_assert (DECL_INITIAL (decl) == error_mark_node,
2993 201);
2994 init = DECL_INITIAL (init);
2995 #endif /* 1 */
2996 }
2997 }
2998 }
2999 #endif /* 0 */
3000 if (IS_AGGR_TYPE (TREE_TYPE (decl))
3001 || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
3002 expand_aggr_init (decl, init, 0, 0);
3003 else if (TREE_CODE (init) == TREE_VEC)
3004 {
3005 expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
3006 TREE_VEC_ELT (init, 1),
3007 TREE_VEC_ELT (init, 2), 0),
3008 const0_rtx, VOIDmode, 0);
3009 free_temp_slots ();
3010 }
3011 else
3012 expand_assignment (decl, init, 0, 0);
3013
3014 DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
3015 }
3016 else if (TREE_CODE (decl) == SAVE_EXPR)
3017 {
3018 if (! PARM_DECL_EXPR (decl))
3019 {
3020 /* a `new' expression at top level. */
3021 expand_expr (decl, const0_rtx, VOIDmode, 0);
3022 free_temp_slots ();
3023 expand_aggr_init (build_indirect_ref (decl, NULL_PTR), init, 0, 0);
3024 }
3025 }
3026 else if (decl == error_mark_node)
3027 ;
3028 else my_friendly_abort (22);
3029 vars = TREE_CHAIN (vars);
3030 /* Cleanup any temporaries needed for the initial value. */
3031 expand_cleanups_to (old_cleanups);
3032 }
3033
3034 for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
3035 expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
3036 NULL_TREE));
3037
3038 expand_end_bindings (getdecls(), 1, 0);
3039 poplevel (1, 0, 0);
3040 pop_momentary ();
3041
3042 finish_function (lineno, 0, 0);
3043 assemble_constructor (IDENTIFIER_POINTER (fnname));
3044 }
3045
3046 permanent_allocation (1);
3047
3048 /* Done with C language context needs. */
3049 pop_lang_context ();
3050
3051 /* Now write out any static class variables (which may have since
3052 learned how to be initialized). */
3053 while (pending_statics)
3054 {
3055 tree decl = TREE_VALUE (pending_statics);
3056 if (TREE_USED (decl) == 1
3057 || TREE_READONLY (decl) == 0
3058 || DECL_INITIAL (decl) == 0)
3059 rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
3060 pending_statics = TREE_CHAIN (pending_statics);
3061 }
3062
3063 this_time = get_run_time ();
3064 parse_time -= this_time - start_time;
3065 varconst_time += this_time - start_time;
3066
3067 start_time = get_run_time ();
3068
3069 if (flag_handle_signatures)
3070 walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
3071
3072 for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3073 import_export_inline (TREE_VALUE (fnname));
3074
3075 /* Now write out inline functions which had their addresses taken and
3076 which were not declared virtual and which were not declared `extern
3077 inline'. */
3078 {
3079 int reconsider = 1; /* More may be referenced; check again */
3080 saved_inlines = tree_cons (NULL_TREE, NULL_TREE, saved_inlines);
3081
3082 while (reconsider)
3083 {
3084 tree last = saved_inlines;
3085 tree place = TREE_CHAIN (saved_inlines);
3086 reconsider = 0;
3087
3088 walk_vtables ((void (*)())0, finish_vtable_vardecl);
3089
3090 for (; place; place = TREE_CHAIN (place))
3091 {
3092 tree decl = TREE_VALUE (place);
3093
3094 if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl))
3095 {
3096 if (TREE_USED (decl)
3097 || (TREE_PUBLIC (decl) && ! DECL_EXTERNAL (decl)))
3098 synthesize_method (decl);
3099 else
3100 {
3101 last = place;
3102 continue;
3103 }
3104 }
3105
3106 if (TREE_ASM_WRITTEN (decl) || DECL_SAVED_INSNS (decl) == 0)
3107 {
3108 TREE_CHAIN (last) = TREE_CHAIN (place);
3109 continue;
3110 }
3111
3112 if (TREE_PUBLIC (decl)
3113 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3114 || flag_keep_inline_functions)
3115 {
3116 TREE_CHAIN (last) = TREE_CHAIN (place);
3117
3118 if (DECL_NOT_REALLY_EXTERN (decl))
3119 {
3120 DECL_EXTERNAL (decl) = 0;
3121 reconsider = 1;
3122 temporary_allocation ();
3123 output_inline_function (decl);
3124 permanent_allocation (1);
3125 }
3126
3127 continue;
3128 }
3129
3130 last = place;
3131 }
3132 }
3133 }
3134
3135 /* Now delete from the chain of variables all virtual function tables.
3136 We output them all ourselves, because each will be treated specially. */
3137
3138 walk_vtables ((void (*)())0, prune_vtable_vardecl);
3139
3140 for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
3141 {
3142 if (TREE_CODE (vars) == THUNK_DECL)
3143 emit_thunk (vars);
3144 else if (TREE_CODE (vars) == FUNCTION_DECL
3145 && ! DECL_INTERFACE_KNOWN (vars)
3146 && DECL_C_STATIC (vars))
3147 TREE_PUBLIC (vars) = 0;
3148 }
3149
3150 if (might_have_exceptions_p ())
3151 emit_exception_table ();
3152
3153 if (write_virtuals == 2)
3154 {
3155 /* Now complain about an virtual function tables promised
3156 but not delivered. */
3157 while (pending_vtables)
3158 {
3159 if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3160 error ("virtual function table for `%s' not defined",
3161 IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3162 pending_vtables = TREE_CHAIN (pending_vtables);
3163 }
3164 }
3165
3166 finish_repo ();
3167
3168 this_time = get_run_time ();
3169 parse_time -= this_time - start_time;
3170 varconst_time += this_time - start_time;
3171
3172 if (flag_detailed_statistics)
3173 dump_time_statistics ();
3174 }
3175
3176 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3177 expr. Since it was parsed like a type, we need to wade through and fix
3178 that. Unfortunately, since operator() is left-associative, we can't use
3179 tail recursion. In the above example, TYPE is `A', and DECL is
3180 `()()()()()'.
3181
3182 Maybe this shouldn't be recursive, but how often will it actually be
3183 used? (jason) */
3184 tree
3185 reparse_absdcl_as_expr (type, decl)
3186 tree type, decl;
3187 {
3188 /* do build_functional_cast (type, NULL_TREE) at bottom */
3189 if (TREE_OPERAND (decl, 0) == NULL_TREE)
3190 return build_functional_cast (type, NULL_TREE);
3191
3192 /* recurse */
3193 decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3194
3195 decl = build_x_function_call (decl, NULL_TREE, current_class_decl);
3196
3197 if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3198 decl = require_complete_type (decl);
3199
3200 return decl;
3201 }
3202
3203 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3204 out to be an expr. Since it was parsed like a type, we need to wade
3205 through and fix that. Since casts are right-associative, we are
3206 reversing the order, so we don't have to recurse.
3207
3208 In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3209 `1'. */
3210 tree
3211 reparse_absdcl_as_casts (decl, expr)
3212 tree decl, expr;
3213 {
3214 tree type;
3215
3216 if (TREE_CODE (expr) == CONSTRUCTOR)
3217 {
3218 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3219 decl = TREE_OPERAND (decl, 0);
3220
3221 if (IS_SIGNATURE (type))
3222 {
3223 error ("cast specifies signature type");
3224 return error_mark_node;
3225 }
3226
3227 expr = digest_init (type, expr, (tree *) 0);
3228 if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3229 {
3230 int failure = complete_array_type (type, expr, 1);
3231 if (failure)
3232 my_friendly_abort (78);
3233 }
3234 }
3235
3236 while (decl)
3237 {
3238 type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3239 decl = TREE_OPERAND (decl, 0);
3240 expr = build_c_cast (type, expr, 0);
3241 }
3242
3243 return expr;
3244 }
3245
3246 /* Recursive helper function for reparse_decl_as_expr. It may be a good
3247 idea to reimplement this using an explicit stack, rather than recursion. */
3248 static tree
3249 reparse_decl_as_expr1 (decl)
3250 tree decl;
3251 {
3252 switch (TREE_CODE (decl))
3253 {
3254 case IDENTIFIER_NODE:
3255 return do_identifier (decl);
3256 case INDIRECT_REF:
3257 return build_x_indirect_ref
3258 (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)), "unary *");
3259 case ADDR_EXPR:
3260 return build_x_unary_op (ADDR_EXPR,
3261 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
3262 case BIT_NOT_EXPR:
3263 return build_x_unary_op (BIT_NOT_EXPR,
3264 reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)));
3265 case SCOPE_REF:
3266 return build_offset_ref (TREE_OPERAND (decl, 0), TREE_OPERAND (decl, 1));
3267 case ARRAY_REF:
3268 return grok_array_decl (reparse_decl_as_expr1 (TREE_OPERAND (decl, 0)),
3269 TREE_OPERAND (decl, 1));
3270 default:
3271 my_friendly_abort (5);
3272 return NULL_TREE;
3273 }
3274 }
3275
3276 /* This is something of the form `int (*a)++' that has turned out to be an
3277 expr. It was only converted into parse nodes, so we need to go through
3278 and build up the semantics. Most of the work is done by
3279 reparse_decl_as_expr1, above.
3280
3281 In the above example, TYPE is `int' and DECL is `*a'. */
3282 tree
3283 reparse_decl_as_expr (type, decl)
3284 tree type, decl;
3285 {
3286 decl = reparse_decl_as_expr1 (decl);
3287 if (type)
3288 return build_functional_cast (type, build_tree_list (NULL_TREE, decl));
3289 else
3290 return decl;
3291 }
3292
3293 /* This is something of the form `int (*a)' that has turned out to be a
3294 decl. It was only converted into parse nodes, so we need to do the
3295 checking that make_{pointer,reference}_declarator do. */
3296
3297 tree
3298 finish_decl_parsing (decl)
3299 tree decl;
3300 {
3301 extern int current_class_depth;
3302
3303 switch (TREE_CODE (decl))
3304 {
3305 case IDENTIFIER_NODE:
3306 return decl;
3307 case INDIRECT_REF:
3308 return make_pointer_declarator
3309 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3310 case ADDR_EXPR:
3311 return make_reference_declarator
3312 (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3313 case BIT_NOT_EXPR:
3314 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3315 return decl;
3316 case SCOPE_REF:
3317 push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3318 TREE_COMPLEXITY (decl) = current_class_depth;
3319 return decl;
3320 case ARRAY_REF:
3321 TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3322 return decl;
3323 default:
3324 my_friendly_abort (5);
3325 return NULL_TREE;
3326 }
3327 }
3328
3329 tree
3330 check_cp_case_value (value)
3331 tree value;
3332 {
3333 if (value == NULL_TREE)
3334 return value;
3335
3336 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3337 Strip such NOP_EXPRs. */
3338 if (TREE_CODE (value) == NOP_EXPR
3339 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
3340 value = TREE_OPERAND (value, 0);
3341
3342 if (TREE_READONLY_DECL_P (value))
3343 {
3344 value = decl_constant_value (value);
3345 /* build_c_cast puts on a NOP_EXPR to make a non-lvalue.
3346 Strip such NOP_EXPRs. */
3347 if (TREE_CODE (value) == NOP_EXPR
3348 && TREE_TYPE (value) == TREE_TYPE (TREE_OPERAND (value, 0)))
3349 value = TREE_OPERAND (value, 0);
3350 }
3351 value = fold (value);
3352
3353 if (TREE_CODE (value) != INTEGER_CST
3354 && value != error_mark_node)
3355 {
3356 cp_error ("case label `%E' does not reduce to an integer constant",
3357 value);
3358 value = error_mark_node;
3359 }
3360 else
3361 /* Promote char or short to int. */
3362 value = default_conversion (value);
3363
3364 constant_expression_warning (value);
3365
3366 return value;
3367 }
3368
3369 static tree current_namespace;
3370
3371 /* Get the inner part of a namespace id. It doesn't have any prefix, nor
3372 postfix. Returns 0 if in global namespace. */
3373 tree
3374 get_namespace_id ()
3375 {
3376 tree x = current_namespace;
3377 if (x)
3378 x = TREE_PURPOSE (x);
3379 return x;
3380 }
3381
3382 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace. */
3383 tree
3384 current_namespace_id (name)
3385 tree name;
3386 {
3387 tree old_id = get_namespace_id ();
3388 char *buf;
3389
3390 /* Global names retain old encoding. */
3391 if (! old_id)
3392 return name;
3393
3394 buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id)
3395 + IDENTIFIER_LENGTH (name));
3396 sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id),
3397 IDENTIFIER_POINTER (name));
3398 return get_identifier (buf);
3399 }
3400
3401 /* Push into the scopre of the NAME namespace. */
3402 void
3403 push_namespace (name)
3404 tree name;
3405 {
3406 tree old_id = get_namespace_id ();
3407 char *buf;
3408
3409 current_namespace = tree_cons (NULL_TREE, name, current_namespace);
3410 buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0)
3411 + IDENTIFIER_LENGTH (name));
3412 sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "",
3413 IDENTIFIER_POINTER (name));
3414 TREE_PURPOSE (current_namespace) = get_identifier (buf);
3415 }
3416
3417 /* Pop from the scope of the current namespace. */
3418 void
3419 pop_namespace ()
3420 {
3421 current_namespace = TREE_CHAIN (current_namespace);
3422 }
3423
3424 void
3425 do_namespace_alias (alias, namespace)
3426 tree alias, namespace;
3427 {
3428 }
3429
3430 tree
3431 do_using_decl (decl)
3432 tree decl;
3433 {
3434 return error_mark_node;
3435 }
3436
3437 void
3438 do_using_directive (namespace)
3439 tree namespace;
3440 {
3441 }