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