OSDN Git Service

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