OSDN Git Service

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