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