OSDN Git Service

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