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