OSDN Git Service

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