OSDN Git Service

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