OSDN Git Service

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