OSDN Git Service

(handle_braces): Rework last change.
[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 #ifdef DWARF_DEBUGGING_INFO
2427       if (write_symbols == DWARF_DEBUG)
2428         {
2429           /* Mark the VAR_DECL node representing the vtable itself as a
2430              "gratuitous" one, thereby forcing dwarfout.c to ignore it.
2431              It is rather important that such things be ignored because
2432              any effort to actually generate DWARF for them will run
2433              into trouble when/if we encounter code like:
2434
2435                 #pragma interface
2436                 struct S { virtual void member (); };
2437
2438               because the artificial declaration of the vtable itself (as
2439               manufactured by the g++ front end) will say that the vtable
2440               is a static member of `S' but only *after* the debug output
2441               for the definition of `S' has already been output.  This causes
2442               grief because the DWARF entry for the definition of the vtable
2443               will try to refer back to an earlier *declaration* of the
2444               vtable as a static member of `S' and there won't be one.
2445               We might be able to arrange to have the "vtable static member"
2446               attached to the member list for `S' before the debug info for
2447               `S' get written (which would solve the problem) but that would
2448               require more intrusive changes to the g++ front end.  */
2449
2450           DECL_IGNORED_P (vars) = 1;
2451         }
2452 #endif /* DWARF_DEBUGGING_INFO */
2453
2454       rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2455       return 1;
2456     }
2457   else if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (vars)))
2458     /* We don't know what to do with this one yet.  */
2459     return 0;
2460
2461   /* We know that PREV must be non-zero here.  */
2462   TREE_CHAIN (prev) = TREE_CHAIN (vars);
2463   return 0;
2464 }
2465
2466 static int
2467 prune_vtable_vardecl (prev, vars)
2468      tree prev, vars;
2469 {
2470   /* We know that PREV must be non-zero here.  */
2471   TREE_CHAIN (prev) = TREE_CHAIN (vars);
2472   return 1;
2473 }
2474
2475 int
2476 walk_vtables (typedecl_fn, vardecl_fn)
2477      register void (*typedecl_fn)();
2478      register int (*vardecl_fn)();
2479 {
2480   tree prev, vars;
2481   int flag = 0;
2482
2483   for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2484     {
2485       register tree type = TREE_TYPE (vars);
2486
2487       if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
2488         {
2489           if (vardecl_fn)
2490             flag |= (*vardecl_fn) (prev, vars);
2491
2492           if (prev && TREE_CHAIN (prev) != vars)
2493             continue;
2494         }
2495       else if (TREE_CODE (vars) == TYPE_DECL
2496                && type != error_mark_node
2497                && TYPE_LANG_SPECIFIC (type)
2498                && CLASSTYPE_VSIZE (type))
2499         {
2500           if (typedecl_fn) (*typedecl_fn) (prev, vars);
2501         }
2502
2503       prev = vars;
2504     }
2505
2506   return flag;
2507 }
2508
2509 static void
2510 finish_sigtable_vardecl (prev, vars)
2511      tree prev, vars;
2512 {
2513   /* We don't need to mark sigtable entries as addressable here as is done
2514      for vtables.  Since sigtables, unlike vtables, are always written out,
2515      that was already done in build_signature_table_constructor.  */
2516
2517   rest_of_decl_compilation (vars, NULL_PTR, 1, 1);
2518
2519   /* We know that PREV must be non-zero here.  */
2520   TREE_CHAIN (prev) = TREE_CHAIN (vars);
2521 }
2522
2523 void
2524 walk_sigtables (typedecl_fn, vardecl_fn)
2525      register void (*typedecl_fn)();
2526      register void (*vardecl_fn)();
2527 {
2528   tree prev, vars;
2529
2530   for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
2531     {
2532       register tree type = TREE_TYPE (vars);
2533
2534       if (TREE_CODE (vars) == TYPE_DECL
2535           && type != error_mark_node
2536           && IS_SIGNATURE (type))
2537         {
2538           if (typedecl_fn) (*typedecl_fn) (prev, vars);
2539         }
2540       else if (TREE_CODE (vars) == VAR_DECL
2541                && TREE_TYPE (vars) != error_mark_node
2542                && IS_SIGNATURE (TREE_TYPE (vars)))
2543         {
2544           if (vardecl_fn) (*vardecl_fn) (prev, vars);
2545         }
2546       else
2547         prev = vars;
2548     }
2549 }
2550
2551 /* Determines the proper settings of TREE_PUBLIC and DECL_EXTERNAL for an
2552    inline function or template instantiation at end-of-file.  */
2553
2554 void
2555 import_export_decl (decl)
2556      tree decl;
2557 {
2558   if (DECL_INTERFACE_KNOWN (decl))
2559     return;
2560
2561   if (DECL_TEMPLATE_INSTANTIATION (decl))
2562     {
2563       DECL_NOT_REALLY_EXTERN (decl) = 1;
2564       if (DECL_IMPLICIT_INSTANTIATION (decl)
2565           && (flag_implicit_templates || DECL_THIS_INLINE (decl)))
2566         {
2567           if (TREE_CODE (decl) == FUNCTION_DECL)
2568             comdat_linkage (decl);
2569           /* Dynamically initialized vars go into common.  */
2570           else if (DECL_INITIAL (decl) == NULL_TREE
2571                    || DECL_INITIAL (decl) == error_mark_node)
2572             DECL_COMMON (decl) = 1;
2573           else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
2574             {
2575               DECL_COMMON (decl) = 1;
2576               DECL_INITIAL (decl) = error_mark_node;
2577             }
2578           else
2579             {
2580               /* Statically initialized vars are weak or comdat, if
2581                  supported.  */
2582               if (flag_weak)
2583                 make_decl_one_only (decl);
2584               /* else leave vars public so multiple defs will break.  */
2585             }
2586         }
2587       else
2588         DECL_NOT_REALLY_EXTERN (decl) = 0;
2589     }
2590   else if (DECL_FUNCTION_MEMBER_P (decl))
2591     {
2592       tree ctype = DECL_CLASS_CONTEXT (decl);
2593       if (CLASSTYPE_INTERFACE_KNOWN (ctype) && ! DECL_ARTIFICIAL (decl))
2594         {
2595           DECL_NOT_REALLY_EXTERN (decl)
2596             = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2597                  || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2598         }
2599       else
2600         comdat_linkage (decl);
2601     }
2602   /* tinfo function */
2603   else if (DECL_ARTIFICIAL (decl) && DECL_MUTABLE_P (decl))
2604     {
2605       tree ctype = TREE_TYPE (DECL_NAME (decl));
2606       if (IS_AGGR_TYPE (ctype) && CLASSTYPE_INTERFACE_KNOWN (ctype)
2607           && TYPE_VIRTUAL_P (ctype))
2608         {
2609           DECL_NOT_REALLY_EXTERN (decl)
2610             = ! (CLASSTYPE_INTERFACE_ONLY (ctype)
2611                  || (DECL_THIS_INLINE (decl) && ! flag_implement_inlines));
2612         }
2613       else if (TYPE_BUILT_IN (ctype) && ctype == TYPE_MAIN_VARIANT (ctype))
2614         DECL_NOT_REALLY_EXTERN (decl) = 0;
2615       else
2616         comdat_linkage (decl);
2617     } 
2618   else if (DECL_C_STATIC (decl))
2619     TREE_PUBLIC (decl) = 0;
2620   else
2621     comdat_linkage (decl);
2622
2623   DECL_INTERFACE_KNOWN (decl) = 1;
2624 }
2625
2626 tree
2627 build_cleanup (decl)
2628      tree decl;
2629 {
2630   tree temp;
2631   tree type = TREE_TYPE (decl);
2632
2633   if (TREE_CODE (type) == ARRAY_TYPE)
2634     temp = decl;
2635   else
2636     {
2637       mark_addressable (decl);
2638       temp = build1 (ADDR_EXPR, build_pointer_type (type), decl);
2639     }
2640   temp = build_delete (TREE_TYPE (temp), temp,
2641                        integer_two_node,
2642                        LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
2643   return temp;
2644 }
2645
2646 extern int parse_time, varconst_time;
2647 extern tree pending_templates;
2648 extern tree maybe_templates;
2649
2650 extern struct obstack permanent_obstack;
2651 extern tree get_id_2 ();
2652
2653 tree
2654 get_sentry (base)
2655      tree base;
2656 {
2657   tree sname = get_id_2 ("__sn", base);
2658   tree sentry = IDENTIFIER_GLOBAL_VALUE (sname);
2659   if (! sentry)
2660     {
2661       push_obstacks (&permanent_obstack, &permanent_obstack);
2662       sentry = build_decl (VAR_DECL, sname, integer_type_node);
2663       TREE_PUBLIC (sentry) = 1;
2664       DECL_ARTIFICIAL (sentry) = 1;
2665       TREE_STATIC (sentry) = 1;
2666       TREE_USED (sentry) = 1;
2667       DECL_COMMON (sentry) = 1;
2668       pushdecl_top_level (sentry);
2669       cp_finish_decl (sentry, NULL_TREE, NULL_TREE, 0, 0);
2670       pop_obstacks ();
2671     }
2672   return sentry;
2673 }
2674
2675 /* This routine is called from the last rule in yyparse ().
2676    Its job is to create all the code needed to initialize and
2677    destroy the global aggregates.  We do the destruction
2678    first, since that way we only need to reverse the decls once.  */
2679
2680 void
2681 finish_file ()
2682 {
2683   extern int lineno;
2684   int start_time, this_time;
2685
2686   tree fnname;
2687   tree vars;
2688   int needs_cleaning = 0, needs_messing_up = 0;
2689
2690   at_eof = 1;
2691
2692   if (flag_detailed_statistics)
2693     dump_tree_statistics ();
2694
2695   /* Bad parse errors.  Just forget about it.  */
2696   if (! global_bindings_p () || current_class_type)
2697     return;
2698
2699   start_time = get_run_time ();
2700
2701   /* Otherwise, GDB can get confused, because in only knows
2702      about source for LINENO-1 lines.  */
2703   lineno -= 1;
2704
2705   interface_unknown = 1;
2706   interface_only = 0;
2707
2708   for (fnname = pending_templates; fnname; fnname = TREE_CHAIN (fnname))
2709     {
2710       tree decl = TREE_VALUE (fnname);
2711       if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
2712         {
2713           instantiate_class_template (decl);
2714           if (CLASSTYPE_TEMPLATE_INSTANTIATION (decl))
2715             for (vars = TYPE_METHODS (decl); vars; vars = TREE_CHAIN (vars))
2716               if (! DECL_ARTIFICIAL (vars))
2717                 instantiate_decl (vars);
2718         }
2719       else
2720         instantiate_decl (decl);
2721     }
2722
2723   for (fnname = maybe_templates; fnname; fnname = TREE_CHAIN (fnname))
2724     {
2725       tree *args, fn, decl = TREE_VALUE (fnname);
2726
2727       if (DECL_INITIAL (decl))
2728         continue;
2729
2730       fn = TREE_PURPOSE (fnname);
2731       args = get_bindings (fn, decl);
2732       fn = instantiate_template (fn, args);
2733       free (args);
2734       instantiate_decl (fn);
2735     }
2736
2737   /* Push into C language context, because that's all
2738      we'll need here.  */
2739   push_lang_context (lang_name_c);
2740
2741 #if 1
2742   /* The reason for pushing garbage onto the global_binding_level is to
2743      ensure that we can slice out _DECLs which pertain to virtual function
2744      tables.  If the last thing pushed onto the global_binding_level was a
2745      virtual function table, then slicing it out would slice away all the
2746      decls (i.e., we lose the head of the chain).
2747
2748      There are several ways of getting the same effect, from changing the
2749      way that iterators over the chain treat the elements that pertain to
2750      virtual function tables, moving the implementation of this code to
2751      decl.c (where we can manipulate global_binding_level directly),
2752      popping the garbage after pushing it and slicing away the vtable
2753      stuff, or just leaving it alone.  */
2754
2755   /* Make last thing in global scope not be a virtual function table.  */
2756 #if 0 /* not yet, should get fixed properly later */
2757   vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
2758 #else
2759   vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
2760 #endif
2761   DECL_IGNORED_P (vars) = 1;
2762   SET_DECL_ARTIFICIAL (vars);
2763   pushdecl (vars);
2764 #endif
2765
2766   /* Walk to mark the inline functions we need, then output them so
2767      that we can pick up any other tdecls that those routines need.  */
2768   walk_vtables ((void (*)())0, finish_prevtable_vardecl);
2769
2770   for (vars = pending_statics; vars; vars = TREE_CHAIN (vars))
2771     {
2772       tree decl = TREE_VALUE (vars);
2773
2774       if (DECL_TEMPLATE_INSTANTIATION (decl)
2775           && ! DECL_IN_AGGR_P (decl))
2776         {
2777           import_export_decl (decl);
2778           DECL_EXTERNAL (decl) = ! DECL_NOT_REALLY_EXTERN (decl);
2779         }
2780     }
2781
2782   for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2783     if (! TREE_ASM_WRITTEN (TREE_VALUE (vars)))
2784       rest_of_decl_compilation (TREE_VALUE (vars), 0, 1, 1);
2785   vars = static_aggregates;
2786
2787   if (static_ctors || vars || exception_table_p ())
2788     needs_messing_up = 1;
2789   if (static_dtors)
2790     needs_cleaning = 1;
2791
2792   /* See if we really need the hassle.  */
2793   while (vars && needs_cleaning == 0)
2794     {
2795       tree decl = TREE_VALUE (vars);
2796       tree type = TREE_TYPE (decl);
2797       if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars))
2798         {
2799           needs_cleaning = 1;
2800           break;
2801         }
2802
2803       vars = TREE_CHAIN (vars);
2804     }
2805
2806   if (needs_cleaning == 0)
2807     goto mess_up;
2808
2809   fnname = get_file_function_name ('D');
2810   start_function (void_list_node,
2811                   make_call_declarator (fnname, void_list_node, NULL_TREE,
2812                                         NULL_TREE),
2813                   NULL_TREE, 0);
2814   fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2815   store_parm_decls ();
2816
2817   pushlevel (0);
2818   clear_last_expr ();
2819   push_momentary ();
2820   expand_start_bindings (0);
2821
2822   /* These must be done in backward order to destroy,
2823      in which they happen to be!  */
2824   for (vars = static_aggregates; vars; vars = TREE_CHAIN (vars))
2825     {
2826       tree decl = TREE_VALUE (vars);
2827       tree type = TREE_TYPE (decl);
2828       tree temp = TREE_PURPOSE (vars);
2829
2830       if (TYPE_NEEDS_DESTRUCTOR (type) && ! TREE_STATIC (vars)
2831           && ! DECL_EXTERNAL (decl))
2832         {
2833           int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2834                                                 || DECL_ONE_ONLY (decl)
2835                                                 || DECL_WEAK (decl)));
2836
2837           temp = build_cleanup (decl);
2838
2839           if (protect)
2840             {
2841               tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2842               sentry = build_unary_op (PREDECREMENT_EXPR, sentry, 0);
2843               sentry = build_binary_op (EQ_EXPR, sentry, integer_zero_node, 1);
2844               expand_start_cond (sentry, 0);
2845             }
2846
2847           expand_expr_stmt (temp);
2848
2849           if (protect)
2850             expand_end_cond ();
2851         }
2852     }
2853
2854   for (; static_dtors; static_dtors = TREE_CHAIN (static_dtors))
2855     expand_expr_stmt (build_function_call (TREE_VALUE (static_dtors),
2856                                            NULL_TREE));
2857       
2858   expand_end_bindings (getdecls (), 1, 0);
2859   poplevel (1, 0, 0);
2860   pop_momentary ();
2861
2862   finish_function (lineno, 0, 0);
2863
2864   assemble_destructor (IDENTIFIER_POINTER (fnname));
2865
2866   /* if it needed cleaning, then it will need messing up: drop through  */
2867
2868  mess_up:
2869   /* Must do this while we think we are at the top level.  */
2870   vars = nreverse (static_aggregates);
2871   if (needs_messing_up)
2872     {
2873       fnname = get_file_function_name ('I');
2874       start_function (void_list_node,
2875                       make_call_declarator (fnname, void_list_node, NULL_TREE,
2876                                             NULL_TREE),
2877                       NULL_TREE, 0);
2878       fnname = DECL_ASSEMBLER_NAME (current_function_decl);
2879       store_parm_decls ();
2880
2881       pushlevel (0);
2882       clear_last_expr ();
2883       push_momentary ();
2884       expand_start_bindings (0);
2885
2886       if (exception_table_p ())
2887         register_exception_table ();
2888
2889       while (vars)
2890         {
2891           extern int temp_slot_level;
2892           extern int target_temp_slot_level; 
2893           tree decl = TREE_VALUE (vars);
2894           tree init = TREE_PURPOSE (vars);
2895           tree old_cleanups = cleanups_this_call;
2896           int old_temp_level = target_temp_slot_level;
2897           push_temp_slots ();
2898           push_temp_slots ();
2899           target_temp_slot_level = temp_slot_level;
2900
2901           /* If this was a static attribute within some function's scope,
2902              then don't initialize it here.  Also, don't bother
2903              with initializers that contain errors.  */
2904           if (TREE_STATIC (vars)
2905               || DECL_EXTERNAL (decl)
2906               || (init && TREE_CODE (init) == TREE_LIST
2907                   && value_member (error_mark_node, init)))
2908             goto next_mess;
2909
2910           if (TREE_CODE (decl) == VAR_DECL)
2911             {
2912           int protect = (TREE_PUBLIC (decl) && (DECL_COMMON (decl)
2913                                                 || DECL_ONE_ONLY (decl)
2914                                                 || DECL_WEAK (decl)));
2915
2916               /* Set these global variables so that GDB at least puts
2917                  us near the declaration which required the initialization.  */
2918               input_filename = DECL_SOURCE_FILE (decl);
2919               lineno = DECL_SOURCE_LINE (decl);
2920               emit_note (input_filename, lineno);
2921
2922               /* 9.5p5: The initializer of a static member of a class has
2923                  the same access rights as a member function.  */
2924               DECL_CLASS_CONTEXT (current_function_decl) = DECL_CONTEXT (decl);
2925               DECL_STATIC_FUNCTION_P (current_function_decl) = 1;
2926
2927               if (protect)
2928                 {
2929                   tree sentry = get_sentry (DECL_ASSEMBLER_NAME (decl));
2930                   sentry = build_unary_op (PREINCREMENT_EXPR, sentry, 0);
2931                   sentry = build_binary_op
2932                     (EQ_EXPR, sentry, integer_one_node, 1);
2933                   expand_start_cond (sentry, 0);
2934                 }
2935
2936               if (IS_AGGR_TYPE (TREE_TYPE (decl))
2937                   || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
2938                 expand_aggr_init (decl, init, 0, 0);
2939               else if (TREE_CODE (init) == TREE_VEC)
2940                 {
2941                   expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
2942                                                 TREE_VEC_ELT (init, 1),
2943                                                 TREE_VEC_ELT (init, 2), 0),
2944                                const0_rtx, VOIDmode, 0);
2945                 }
2946               else
2947                 expand_assignment (decl, init, 0, 0);
2948
2949               if (protect)
2950                 expand_end_cond ();
2951
2952               DECL_CLASS_CONTEXT (current_function_decl) = NULL_TREE;
2953               DECL_STATIC_FUNCTION_P (current_function_decl) = 0;
2954             }
2955           else if (decl == error_mark_node)
2956             ;
2957           else my_friendly_abort (22);
2958
2959           /* Cleanup any temporaries needed for the initial value.  */
2960           expand_cleanups_to (old_cleanups);
2961         next_mess:
2962           pop_temp_slots ();
2963           pop_temp_slots ();
2964           target_temp_slot_level = old_temp_level;
2965
2966           vars = TREE_CHAIN (vars);
2967         }
2968
2969       for (; static_ctors; static_ctors = TREE_CHAIN (static_ctors))
2970         expand_expr_stmt (build_function_call (TREE_VALUE (static_ctors),
2971                                                NULL_TREE));
2972       
2973       expand_end_bindings (getdecls (), 1, 0);
2974       poplevel (1, 0, 0);
2975       pop_momentary ();
2976
2977       finish_function (lineno, 0, 0);
2978       assemble_constructor (IDENTIFIER_POINTER (fnname));
2979     }
2980
2981   expand_builtin_throw ();
2982
2983   permanent_allocation (1);
2984
2985   /* Done with C language context needs.  */
2986   pop_lang_context ();
2987
2988   /* Now write out any static class variables (which may have since
2989      learned how to be initialized).  */
2990   while (pending_statics)
2991     {
2992       tree decl = TREE_VALUE (pending_statics);
2993
2994       if (TREE_USED (decl) == 1
2995           || TREE_READONLY (decl) == 0
2996           || DECL_INITIAL (decl) == 0)
2997         {
2998           DECL_DEFER_OUTPUT (decl) = 0;
2999           rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
3000         }
3001       pending_statics = TREE_CHAIN (pending_statics);
3002     }
3003
3004   this_time = get_run_time ();
3005   parse_time -= this_time - start_time;
3006   varconst_time += this_time - start_time;
3007
3008   start_time = get_run_time ();
3009
3010   if (flag_handle_signatures)
3011     walk_sigtables ((void (*)())0, finish_sigtable_vardecl);
3012
3013   for (fnname = saved_inlines; fnname; fnname = TREE_CHAIN (fnname))
3014     {
3015       tree decl = TREE_VALUE (fnname);
3016       import_export_decl (decl);
3017     }
3018
3019   /* Now write out inline functions which had their addresses taken and
3020      which were not declared virtual and which were not declared `extern
3021      inline'.  */
3022   {
3023     int reconsider = 1;         /* More may be referenced; check again */
3024
3025     while (reconsider)
3026       {
3027         tree *p = &saved_inlines;
3028         reconsider = 0;
3029
3030         /* We need to do this each time so that newly completed template
3031            types don't wind up at the front of the list.  Sigh.  */
3032         vars = build_decl (TYPE_DECL, make_anon_name (), integer_type_node);
3033         DECL_IGNORED_P (vars) = 1;
3034         SET_DECL_ARTIFICIAL (vars);
3035         pushdecl (vars);
3036
3037         reconsider |= walk_vtables ((void (*)())0, finish_vtable_vardecl);
3038
3039         while (*p)
3040           {
3041             tree decl = TREE_VALUE (*p);
3042
3043             if (DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3044                 && TREE_USED (decl)
3045                 && (! DECL_REALLY_EXTERN (decl) || DECL_INLINE (decl)))
3046               {
3047                 if (DECL_MUTABLE_P (decl))
3048                   synthesize_tinfo_fn (decl);
3049                 else
3050                   synthesize_method (decl);
3051                 reconsider = 1;
3052               }
3053
3054             /* Catch new template instantiations.  */
3055             if (decl != TREE_VALUE (*p))
3056               continue;
3057
3058             if (TREE_ASM_WRITTEN (decl)
3059                 || (DECL_SAVED_INSNS (decl) == 0 && ! DECL_ARTIFICIAL (decl)))
3060               *p = TREE_CHAIN (*p);
3061             else if (DECL_INITIAL (decl) == 0)
3062               p = &TREE_CHAIN (*p);
3063             else if ((TREE_PUBLIC (decl) && ! DECL_WEAK (decl)
3064                       && ! DECL_ONE_ONLY (decl))
3065                      || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
3066                      || flag_keep_inline_functions)
3067               {
3068                 if (DECL_NOT_REALLY_EXTERN (decl))
3069                   {
3070                     DECL_EXTERNAL (decl) = 0;
3071                     reconsider = 1;
3072                     /* We can't inline this function after it's been
3073                        emitted, so just disable inlining.  We want a
3074                        variant of output_inline_function that doesn't
3075                        prevent subsequent integration...  */
3076                     flag_no_inline = 1;
3077                     temporary_allocation ();
3078                     output_inline_function (decl);
3079                     permanent_allocation (1);
3080                   }
3081
3082                 *p = TREE_CHAIN (*p);
3083               }
3084             else
3085               p = &TREE_CHAIN (*p);
3086           }
3087       }
3088   }
3089
3090   /* Now delete from the chain of variables all virtual function tables.
3091      We output them all ourselves, because each will be treated specially.  */
3092
3093   walk_vtables ((void (*)())0, prune_vtable_vardecl);
3094
3095   for (vars = getdecls (); vars; vars = TREE_CHAIN (vars))
3096     {
3097       if (TREE_CODE (vars) == FUNCTION_DECL
3098           && ! DECL_INTERFACE_KNOWN (vars)
3099           && DECL_C_STATIC (vars))
3100         TREE_PUBLIC (vars) = 0;
3101     }
3102
3103   if (write_virtuals == 2)
3104     {
3105       /* Now complain about an virtual function tables promised
3106          but not delivered.  */
3107       while (pending_vtables)
3108         {
3109           if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
3110             error ("virtual function table for `%s' not defined",
3111                    IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
3112           pending_vtables = TREE_CHAIN (pending_vtables);
3113         }
3114     }
3115
3116   finish_repo ();
3117
3118   this_time = get_run_time ();
3119   parse_time -= this_time - start_time;
3120   varconst_time += this_time - start_time;
3121
3122   if (flag_detailed_statistics)
3123     dump_time_statistics ();
3124 }
3125
3126 /* This is something of the form 'A()()()()()+1' that has turned out to be an
3127    expr.  Since it was parsed like a type, we need to wade through and fix
3128    that.  Unfortunately, since operator() is left-associative, we can't use
3129    tail recursion.  In the above example, TYPE is `A', and DECL is
3130    `()()()()()'.
3131
3132    Maybe this shouldn't be recursive, but how often will it actually be
3133    used?  (jason) */
3134
3135 tree
3136 reparse_absdcl_as_expr (type, decl)
3137      tree type, decl;
3138 {
3139   /* do build_functional_cast (type, NULL_TREE) at bottom */
3140   if (TREE_OPERAND (decl, 0) == NULL_TREE)
3141     return build_functional_cast (type, NULL_TREE);
3142
3143   /* recurse */
3144   decl = reparse_decl_as_expr (type, TREE_OPERAND (decl, 0));
3145
3146   decl = build_x_function_call (decl, NULL_TREE, current_class_ref);
3147
3148   if (TREE_CODE (decl) == CALL_EXPR && TREE_TYPE (decl) != void_type_node)
3149     decl = require_complete_type (decl);
3150
3151   return decl;
3152 }
3153
3154 /* This is something of the form `int ((int)(int)(int)1)' that has turned
3155    out to be an expr.  Since it was parsed like a type, we need to wade
3156    through and fix that.  Since casts are right-associative, we are
3157    reversing the order, so we don't have to recurse.
3158
3159    In the above example, DECL is the `(int)(int)(int)', and EXPR is the
3160    `1'.  */
3161
3162 tree
3163 reparse_absdcl_as_casts (decl, expr)
3164      tree decl, expr;
3165 {
3166   tree type;
3167   
3168   if (TREE_CODE (expr) == CONSTRUCTOR
3169       && TREE_TYPE (expr) == 0)
3170     {
3171       type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3172       decl = TREE_OPERAND (decl, 0);
3173
3174       if (IS_SIGNATURE (type))
3175         {
3176           error ("cast specifies signature type");
3177           return error_mark_node;
3178         }
3179
3180       expr = digest_init (type, expr, (tree *) 0);
3181       if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (type) == 0)
3182         {
3183           int failure = complete_array_type (type, expr, 1);
3184           if (failure)
3185             my_friendly_abort (78);
3186         }
3187     }
3188
3189   while (decl)
3190     {
3191       type = groktypename (TREE_VALUE (TREE_OPERAND (decl, 1)));
3192       decl = TREE_OPERAND (decl, 0);
3193       expr = build_c_cast (type, expr, 0);
3194     }
3195
3196   return expr;
3197 }
3198
3199 /* Given plain tree nodes for an expression, build up the full semantics.  */
3200
3201 tree
3202 build_expr_from_tree (t)
3203      tree t;
3204 {
3205   if (t == NULL_TREE || t == error_mark_node)
3206     return t;
3207
3208   switch (TREE_CODE (t))
3209     {
3210     case IDENTIFIER_NODE:
3211       return do_identifier (t, 0);
3212
3213     case LOOKUP_EXPR:
3214       if (LOOKUP_EXPR_GLOBAL (t))
3215         return do_scoped_id (TREE_OPERAND (t, 0), 0);
3216       else
3217         return do_identifier (TREE_OPERAND (t, 0), 0);
3218
3219     case INDIRECT_REF:
3220       return build_x_indirect_ref
3221         (build_expr_from_tree (TREE_OPERAND (t, 0)), "unary *");
3222
3223     case CAST_EXPR:
3224       return build_functional_cast
3225         (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3226
3227     case REINTERPRET_CAST_EXPR:
3228       return build_reinterpret_cast
3229         (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3230
3231     case CONST_CAST_EXPR:
3232       return build_const_cast
3233         (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3234
3235     case DYNAMIC_CAST_EXPR:
3236       return build_dynamic_cast
3237         (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3238
3239     case STATIC_CAST_EXPR:
3240       return build_static_cast
3241         (TREE_TYPE (t), build_expr_from_tree (TREE_OPERAND (t, 0)));
3242
3243     case PREDECREMENT_EXPR:
3244     case PREINCREMENT_EXPR:
3245     case POSTDECREMENT_EXPR:
3246     case POSTINCREMENT_EXPR:
3247     case NEGATE_EXPR:
3248     case BIT_NOT_EXPR:
3249     case ABS_EXPR:
3250     case TRUTH_NOT_EXPR:
3251     case ADDR_EXPR:
3252     case CONVERT_EXPR:      /* Unary + */
3253       if (TREE_TYPE (t))
3254         return t;
3255       return build_x_unary_op (TREE_CODE (t),
3256                                build_expr_from_tree (TREE_OPERAND (t, 0)));
3257
3258     case PLUS_EXPR:
3259     case MINUS_EXPR:
3260     case MULT_EXPR:
3261     case TRUNC_DIV_EXPR:
3262     case CEIL_DIV_EXPR:
3263     case FLOOR_DIV_EXPR:
3264     case ROUND_DIV_EXPR:
3265     case EXACT_DIV_EXPR:
3266     case BIT_AND_EXPR:
3267     case BIT_ANDTC_EXPR:
3268     case BIT_IOR_EXPR:
3269     case BIT_XOR_EXPR:
3270     case TRUNC_MOD_EXPR:
3271     case FLOOR_MOD_EXPR:
3272     case TRUTH_ANDIF_EXPR:
3273     case TRUTH_ORIF_EXPR:
3274     case TRUTH_AND_EXPR:
3275     case TRUTH_OR_EXPR:
3276     case RSHIFT_EXPR:
3277     case LSHIFT_EXPR:
3278     case RROTATE_EXPR:
3279     case LROTATE_EXPR:
3280     case EQ_EXPR:
3281     case NE_EXPR:
3282     case MAX_EXPR:
3283     case MIN_EXPR:
3284     case LE_EXPR:
3285     case GE_EXPR:
3286     case LT_EXPR:
3287     case GT_EXPR:
3288     case MEMBER_REF:
3289       return build_x_binary_op
3290         (TREE_CODE (t), 
3291          build_expr_from_tree (TREE_OPERAND (t, 0)),
3292          build_expr_from_tree (TREE_OPERAND (t, 1)));
3293
3294     case DOTSTAR_EXPR:
3295       return build_m_component_ref
3296         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3297          build_expr_from_tree (TREE_OPERAND (t, 1)));
3298
3299     case SCOPE_REF:
3300       return build_offset_ref (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1));
3301
3302     case ARRAY_REF:
3303       if (TREE_OPERAND (t, 0) == NULL_TREE)
3304         /* new-type-id */
3305         return build_parse_node (ARRAY_REF, NULL_TREE,
3306                                  build_expr_from_tree (TREE_OPERAND (t, 1)));
3307       return grok_array_decl (build_expr_from_tree (TREE_OPERAND (t, 0)),
3308                               build_expr_from_tree (TREE_OPERAND (t, 1)));
3309
3310     case SIZEOF_EXPR:
3311       {
3312         tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
3313         if (TREE_CODE_CLASS (TREE_CODE (r)) != 't')
3314           r = TREE_TYPE (r);
3315         return c_sizeof (r);
3316       }
3317
3318     case MODOP_EXPR:
3319       return build_x_modify_expr
3320         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3321          TREE_CODE (TREE_OPERAND (t, 1)),
3322          build_expr_from_tree (TREE_OPERAND (t, 2)));
3323
3324     case ARROW_EXPR:
3325       return build_x_arrow
3326         (build_expr_from_tree (TREE_OPERAND (t, 0)));
3327
3328     case NEW_EXPR:
3329       return build_new
3330         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3331          build_expr_from_tree (TREE_OPERAND (t, 1)),
3332          build_expr_from_tree (TREE_OPERAND (t, 2)),
3333          NEW_EXPR_USE_GLOBAL (t));
3334
3335     case DELETE_EXPR:
3336       return delete_sanity
3337         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3338          build_expr_from_tree (TREE_OPERAND (t, 1)),
3339          DELETE_EXPR_USE_VEC (t), DELETE_EXPR_USE_GLOBAL (t));
3340
3341     case COMPOUND_EXPR:
3342       if (TREE_OPERAND (t, 1) == NULL_TREE)
3343         return build_x_compound_expr
3344           (build_expr_from_tree (TREE_OPERAND (t, 0)));
3345       else
3346         my_friendly_abort (42);
3347
3348     case METHOD_CALL_EXPR:
3349       if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3350         {
3351           tree ref = TREE_OPERAND (t, 0);
3352           return build_scoped_method_call
3353             (build_expr_from_tree (TREE_OPERAND (t, 1)),
3354              build_expr_from_tree (TREE_OPERAND (ref, 0)),
3355              TREE_OPERAND (ref, 1),
3356              build_expr_from_tree (TREE_OPERAND (t, 2)));
3357         }
3358       return build_method_call
3359         (build_expr_from_tree (TREE_OPERAND (t, 1)),
3360          TREE_OPERAND (t, 0),
3361          build_expr_from_tree (TREE_OPERAND (t, 2)),
3362          NULL_TREE, LOOKUP_NORMAL);
3363
3364     case CALL_EXPR:
3365       if (TREE_CODE (TREE_OPERAND (t, 0)) == SCOPE_REF)
3366         {
3367           tree ref = TREE_OPERAND (t, 0);
3368           return build_member_call
3369             (build_expr_from_tree (TREE_OPERAND (ref, 0)),
3370              TREE_OPERAND (ref, 1),
3371              build_expr_from_tree (TREE_OPERAND (t, 1)));
3372         }
3373       else
3374         {
3375           tree name = TREE_OPERAND (t, 0);
3376           if (! really_overloaded_fn (name))
3377             name = build_expr_from_tree (name);
3378           return build_x_function_call
3379             (name, build_expr_from_tree (TREE_OPERAND (t, 1)),
3380              current_class_ref);
3381         }
3382
3383     case COND_EXPR:
3384       return build_x_conditional_expr
3385         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3386          build_expr_from_tree (TREE_OPERAND (t, 1)),
3387          build_expr_from_tree (TREE_OPERAND (t, 2)));
3388
3389     case TREE_LIST:
3390       {
3391         tree purpose, value, chain;
3392
3393         if (t == void_list_node)
3394           return t;
3395
3396         purpose = TREE_PURPOSE (t);
3397         if (purpose)
3398           purpose = build_expr_from_tree (purpose);
3399         value = TREE_VALUE (t);
3400         if (value)
3401           value = build_expr_from_tree (value);
3402         chain = TREE_CHAIN (t);
3403         if (chain && chain != void_type_node)
3404           chain = build_expr_from_tree (chain);
3405         return tree_cons (purpose, value, chain);
3406       }
3407
3408     case COMPONENT_REF:
3409       return build_x_component_ref
3410         (build_expr_from_tree (TREE_OPERAND (t, 0)),
3411          TREE_OPERAND (t, 1), NULL_TREE, 1);
3412
3413     case THROW_EXPR:
3414       return build_throw (build_expr_from_tree (TREE_OPERAND (t, 0)));
3415
3416     case CONSTRUCTOR:
3417       {
3418         tree r = build_nt (CONSTRUCTOR, NULL_TREE,
3419                            build_expr_from_tree (CONSTRUCTOR_ELTS (t)));
3420
3421         if (TREE_TYPE (t))
3422           return digest_init (TREE_TYPE (t), r, 0);
3423         return r;
3424       }
3425
3426     case TYPEID_EXPR:
3427       return build_x_typeid (build_expr_from_tree (TREE_OPERAND (t, 0)));
3428
3429     case VAR_DECL:
3430       return convert_from_reference (t);
3431
3432     default:
3433       return t;
3434     }
3435 }
3436
3437 /* This is something of the form `int (*a)++' that has turned out to be an
3438    expr.  It was only converted into parse nodes, so we need to go through
3439    and build up the semantics.  Most of the work is done by
3440    build_expr_from_tree, above.
3441
3442    In the above example, TYPE is `int' and DECL is `*a'.  */
3443
3444 tree
3445 reparse_decl_as_expr (type, decl)
3446      tree type, decl;
3447 {
3448   decl = build_expr_from_tree (decl);
3449   if (type)
3450     return build_functional_cast (type, build_tree_list (NULL_TREE, decl));
3451   else
3452     return decl;
3453 }
3454
3455 /* This is something of the form `int (*a)' that has turned out to be a
3456    decl.  It was only converted into parse nodes, so we need to do the
3457    checking that make_{pointer,reference}_declarator do.  */
3458
3459 tree
3460 finish_decl_parsing (decl)
3461      tree decl;
3462 {
3463   extern int current_class_depth;
3464   
3465   switch (TREE_CODE (decl))
3466     {
3467     case IDENTIFIER_NODE:
3468       return decl;
3469     case INDIRECT_REF:
3470       return make_pointer_declarator
3471         (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3472     case ADDR_EXPR:
3473       return make_reference_declarator
3474         (NULL_TREE, finish_decl_parsing (TREE_OPERAND (decl, 0)));
3475     case BIT_NOT_EXPR:
3476       TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3477       return decl;
3478     case SCOPE_REF:
3479       push_nested_class (TREE_TYPE (TREE_OPERAND (decl, 0)), 3);
3480       TREE_COMPLEXITY (decl) = current_class_depth;
3481       return decl;
3482     case ARRAY_REF:
3483       TREE_OPERAND (decl, 0) = finish_decl_parsing (TREE_OPERAND (decl, 0));
3484       return decl;
3485     default:
3486       my_friendly_abort (5);
3487       return NULL_TREE;
3488     }
3489 }
3490
3491 tree
3492 check_cp_case_value (value)
3493      tree value;
3494 {
3495   if (value == NULL_TREE)
3496     return value;
3497
3498   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
3499   STRIP_TYPE_NOPS (value);
3500
3501   if (TREE_READONLY_DECL_P (value))
3502     {
3503       value = decl_constant_value (value);
3504       STRIP_TYPE_NOPS (value);
3505     }
3506   value = fold (value);
3507
3508   if (TREE_CODE (value) != INTEGER_CST
3509       && value != error_mark_node)
3510     {
3511       cp_error ("case label `%E' does not reduce to an integer constant",
3512                 value);
3513       value = error_mark_node;
3514     }
3515   else
3516     /* Promote char or short to int.  */
3517     value = default_conversion (value);
3518
3519   constant_expression_warning (value);
3520
3521   return value;
3522 }
3523
3524 tree current_namespace;
3525
3526 /* Get the inner part of a namespace id.  It doesn't have any prefix, nor
3527    postfix.  Returns 0 if in global namespace.  */
3528
3529 tree
3530 get_namespace_id ()
3531 {
3532   tree x = current_namespace;
3533   if (x)
3534     x = TREE_PURPOSE (x);
3535   return x;
3536 }
3537
3538 /* Build up a DECL_ASSEMBLER_NAME for NAME in the current namespace.  */
3539
3540 tree
3541 current_namespace_id (name)
3542      tree name;
3543 {
3544   tree old_id = get_namespace_id ();
3545   char *buf;
3546
3547   /* Global names retain old encoding.  */
3548   if (! old_id)
3549     return name;
3550
3551   buf = (char *) alloca (8 + IDENTIFIER_LENGTH (old_id)
3552                          + IDENTIFIER_LENGTH (name));
3553   sprintf (buf, "__ns_%s_%s", IDENTIFIER_POINTER (old_id),
3554            IDENTIFIER_POINTER (name));
3555   return get_identifier (buf);
3556 }
3557
3558 void
3559 do_namespace_alias (alias, namespace)
3560      tree alias, namespace;
3561 {
3562   sorry ("namespace alias");
3563 }
3564
3565 void
3566 do_toplevel_using_decl (decl)
3567      tree decl;
3568 {
3569   if (decl == NULL_TREE || decl == error_mark_node)
3570     return;
3571
3572   if (TREE_CODE (decl) == SCOPE_REF)
3573     decl = resolve_scope_to_name (NULL_TREE, decl);
3574
3575   /* Is this the right way to do an id list? */
3576   if (TREE_CODE (decl) != TREE_LIST)
3577     {
3578       pushdecl (decl);
3579     }
3580   else
3581     while (decl)
3582       {
3583         pushdecl (TREE_VALUE (decl));
3584         decl = TREE_CHAIN (decl);
3585       }
3586 }
3587
3588 tree
3589 do_class_using_decl (decl)
3590      tree decl;
3591 {
3592   tree name, value;
3593
3594   if (TREE_CODE (decl) != SCOPE_REF)
3595     {
3596       cp_error ("using-declaration for non-member at class scope");
3597       return NULL_TREE;
3598     }
3599   name = TREE_OPERAND (decl, 1);
3600   if (TREE_CODE (name) == BIT_NOT_EXPR)
3601     {
3602       cp_error ("using-declaration for destructor");
3603       return NULL_TREE;
3604     }
3605
3606   value = build_lang_field_decl (USING_DECL, name, void_type_node);
3607   DECL_INITIAL (value) = TREE_OPERAND (decl, 0);
3608   return value;
3609 }
3610
3611 void
3612 do_using_directive (namespace)
3613      tree namespace;
3614 {
3615   sorry ("using directive");
3616 }
3617
3618 void
3619 check_default_args (x)
3620      tree x;
3621 {
3622   tree arg = TYPE_ARG_TYPES (TREE_TYPE (x));
3623   int saw_def = 0, i = 0 - (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE);
3624   for (; arg && arg != void_list_node; arg = TREE_CHAIN (arg), ++i)
3625     {
3626       if (TREE_PURPOSE (arg))
3627         saw_def = 1;
3628       else if (saw_def)
3629         {
3630           cp_error ("default argument missing for parameter %P of `%#D'",
3631                     i, x);
3632           break;
3633         }
3634     }
3635 }
3636
3637 void
3638 mark_used (decl)
3639      tree decl;
3640 {
3641   TREE_USED (decl) = 1;
3642   if (processing_template_decl)
3643     return;
3644   assemble_external (decl);
3645   /* Is it a synthesized method that needs to be synthesized?  */
3646   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CLASS_CONTEXT (decl)
3647       && DECL_ARTIFICIAL (decl) && ! DECL_INITIAL (decl)
3648       /* Kludge: don't synthesize for default args.  */
3649       && current_function_decl)
3650     synthesize_method (decl);
3651   if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
3652     instantiate_decl (decl);
3653 }