(init_decl_processing): Change builtin_next_arg type so
[platform/upstream/gcc.git] / gcc / cp / decl.c
1 /* Process declarations and variables for C compiler.
2    Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
3    Hacked by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
20
21
22 /* Process declarations and symbol lookup for C front end.
23    Also constructs types; the standard scalar types at initialization,
24    and structure, union, array and enum types when they are declared.  */
25
26 /* ??? not all decl nodes are given the most useful possible
27    line numbers.  For example, the CONST_DECLs for enum values.  */
28
29 #include <stdio.h>
30 #include "config.h"
31 #include "tree.h"
32 #include "rtl.h"
33 #include "flags.h"
34 #include "cp-tree.h"
35 #include "decl.h"
36 #include "lex.h"
37 #include <sys/types.h>
38 #include <signal.h>
39 #include "obstack.h"
40
41 #define obstack_chunk_alloc xmalloc
42 #define obstack_chunk_free free
43
44 extern struct obstack permanent_obstack;
45
46 extern int current_class_depth;
47
48 /* Stack of places to restore the search obstack back to.  */
49    
50 /* Obstack used for remembering local class declarations (like
51    enums and static (const) members.  */
52 #include "stack.h"
53 static struct obstack decl_obstack;
54 static struct stack_level *decl_stack;
55
56 #ifndef CHAR_TYPE_SIZE
57 #define CHAR_TYPE_SIZE BITS_PER_UNIT
58 #endif
59
60 #ifndef SHORT_TYPE_SIZE
61 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
62 #endif
63
64 #ifndef INT_TYPE_SIZE
65 #define INT_TYPE_SIZE BITS_PER_WORD
66 #endif
67
68 #ifndef LONG_TYPE_SIZE
69 #define LONG_TYPE_SIZE BITS_PER_WORD
70 #endif
71
72 #ifndef LONG_LONG_TYPE_SIZE
73 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
74 #endif
75
76 #ifndef WCHAR_UNSIGNED
77 #define WCHAR_UNSIGNED 0
78 #endif
79
80 #ifndef FLOAT_TYPE_SIZE
81 #define FLOAT_TYPE_SIZE BITS_PER_WORD
82 #endif
83
84 #ifndef DOUBLE_TYPE_SIZE
85 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
86 #endif
87
88 #ifndef LONG_DOUBLE_TYPE_SIZE
89 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
90 #endif
91
92 /* We let tm.h override the types used here, to handle trivial differences
93    such as the choice of unsigned int or long unsigned int for size_t.
94    When machines start needing nontrivial differences in the size type,
95    it would be best to do something here to figure out automatically
96    from other information what type to use.  */
97
98 #ifndef SIZE_TYPE
99 #define SIZE_TYPE "long unsigned int"
100 #endif
101
102 #ifndef PTRDIFF_TYPE
103 #define PTRDIFF_TYPE "long int"
104 #endif
105
106 #ifndef WCHAR_TYPE
107 #define WCHAR_TYPE "int"
108 #endif
109
110 #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
111   define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
112 #define auto_function(NAME, TYPE, CODE) \
113   do {                                  \
114     tree __name = NAME;         \
115     tree __type = TYPE;                 \
116     define_function (IDENTIFIER_POINTER (__name), __type, CODE, \
117                      (void (*)())push_overloaded_decl_1,        \
118                      IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\
119   } while (0)
120
121 static tree grokparms                           PROTO((tree, int));
122 static tree lookup_nested_type                  PROTO((tree, tree));
123 static char *redeclaration_error_message        PROTO((tree, tree));
124 static void grok_op_properties                  PROTO((tree, int, int));
125 static void deactivate_exception_cleanups       PROTO((void));
126
127 tree define_function            
128         PROTO((char *, tree, enum built_in_function, void (*)(), char *));
129
130 /* a node which has tree code ERROR_MARK, and whose type is itself.
131    All erroneous expressions are replaced with this node.  All functions
132    that accept nodes as arguments should avoid generating error messages
133    if this node is one of the arguments, since it is undesirable to get
134    multiple error messages from one error in the input.  */
135
136 tree error_mark_node;
137
138 /* Erroneous argument lists can use this *IFF* they do not modify it.  */
139 tree error_mark_list;
140
141 /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
142
143 tree short_integer_type_node;
144 tree integer_type_node;
145 tree long_integer_type_node;
146 tree long_long_integer_type_node;
147
148 tree short_unsigned_type_node;
149 tree unsigned_type_node;
150 tree long_unsigned_type_node;
151 tree long_long_unsigned_type_node;
152
153 tree ptrdiff_type_node;
154
155 tree unsigned_char_type_node;
156 tree signed_char_type_node;
157 tree char_type_node;
158 tree wchar_type_node;
159 tree signed_wchar_type_node;
160 tree unsigned_wchar_type_node;
161
162 tree float_type_node;
163 tree double_type_node;
164 tree long_double_type_node;
165
166 tree intQI_type_node;
167 tree intHI_type_node;
168 tree intSI_type_node;
169 tree intDI_type_node;
170
171 tree unsigned_intQI_type_node;
172 tree unsigned_intHI_type_node;
173 tree unsigned_intSI_type_node;
174 tree unsigned_intDI_type_node;
175
176 /* a VOID_TYPE node, and the same, packaged in a TREE_LIST.  */
177
178 tree void_type_node, void_list_node;
179 tree void_zero_node;
180
181 /* Nodes for types `void *' and `const void *'.  */
182
183 tree ptr_type_node, const_ptr_type_node;
184
185 /* Nodes for types `char *' and `const char *'.  */
186
187 tree string_type_node, const_string_type_node;
188
189 /* Type `char[256]' or something like it.
190    Used when an array of char is needed and the size is irrelevant.  */
191
192 tree char_array_type_node;
193
194 /* Type `int[256]' or something like it.
195    Used when an array of int needed and the size is irrelevant.  */
196
197 tree int_array_type_node;
198
199 /* Type `wchar_t[256]' or something like it.
200    Used when a wide string literal is created.  */
201
202 tree wchar_array_type_node;
203
204 /* type `int ()' -- used for implicit declaration of functions.  */
205
206 tree default_function_type;
207
208 /* function types `double (double)' and `double (double, double)', etc.  */
209
210 tree double_ftype_double, double_ftype_double_double;
211 tree int_ftype_int, long_ftype_long;
212
213 /* Function type `void (void *, void *, int)' and similar ones.  */
214
215 tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
216
217 /* Function type `char *(char *, char *)' and similar ones */
218 tree string_ftype_ptr_ptr, int_ftype_string_string;
219
220 /* Function type `size_t (const char *)' */
221 tree sizet_ftype_string;
222
223 /* Function type `int (const void *, const void *, size_t)' */
224 tree int_ftype_cptr_cptr_sizet;
225
226 /* C++ extensions */
227 tree vtable_entry_type;
228 tree delta_type_node;
229 tree __t_desc_type_node, __i_desc_type_node, __m_desc_type_node;
230 tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
231 tree class_star_type_node;
232 tree class_type_node, record_type_node, union_type_node, enum_type_node;
233 tree exception_type_node, unknown_type_node;
234 tree opaque_type_node, signature_type_node;
235 tree sigtable_entry_type;
236 tree maybe_gc_cleanup;
237
238 /* Used for virtual function tables.  */
239 tree vtbl_mask;
240
241 /* Array type `vtable_entry_type[]' */
242 tree vtbl_type_node;
243
244 /* Static decls which do not have static initializers have no
245    initializers as far as GNU C is concerned.  EMPTY_INIT_NODE
246    is a static initializer which makes varasm code place the decl
247    in data rather than in bss space.  Such gymnastics are necessary
248    to avoid the problem that the linker will not include a library
249    file if all the library appears to contribute are bss variables.  */
250
251 tree empty_init_node;
252
253 /* In a destructor, the point at which all derived class destroying
254    has been done, just before any base class destroying will be done.  */
255
256 tree dtor_label;
257
258 /* In a constructor, the point at which we are ready to return
259    the pointer to the initialized object.  */
260
261 tree ctor_label;
262
263 /* A FUNCTION_DECL which can call `unhandled_exception'.
264    Not necessarily the one that the user will declare,
265    but sufficient to be called by routines that want to abort the program.  */
266
267 tree unhandled_exception_fndecl;
268
269 /* A FUNCTION_DECL which can call `abort'.  Not necessarily the
270    one that the user will declare, but sufficient to be called
271    by routines that want to abort the program.  */
272
273 tree abort_fndecl;
274
275 extern rtx cleanup_label, return_label;
276
277 /* If original DECL_RESULT of current function was a register,
278    but due to being an addressable named return value, would up
279    on the stack, this variable holds the named return value's
280    original location.  */
281 rtx original_result_rtx;
282
283 /* Sequence of insns which represents base initialization.  */
284 rtx base_init_insns;
285
286 /* C++: Keep these around to reduce calls to `get_identifier'.
287    Identifiers for `this' in member functions and the auto-delete
288    parameter for destructors.  */
289 tree this_identifier, in_charge_identifier;
290 /* Used in pointer to member functions, and in vtables. */
291 tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
292 tree pfn_or_delta2_identifier;
293
294 /* A list (chain of TREE_LIST nodes) of named label uses.
295    The TREE_PURPOSE field is the list of variables defined
296    the the label's scope defined at the point of use.
297    The TREE_VALUE field is the LABEL_DECL used.
298    The TREE_TYPE field holds `current_binding_level' at the
299    point of the label's use.
300
301    Used only for jumps to as-yet undefined labels, since
302    jumps to defined labels can have their validity checked
303    by stmt.c.  */
304
305 static tree named_label_uses;
306
307 /* A list of objects which have constructors or destructors
308    which reside in the global scope.  The decl is stored in
309    the TREE_VALUE slot and the initializer is stored
310    in the TREE_PURPOSE slot.  */
311 tree static_aggregates;
312
313 /* A list of functions which were declared inline, but later had their
314    address taken.  Used only for non-virtual member functions, since we can
315    find other functions easily enough.  */
316 tree pending_addressable_inlines;
317
318 /* A list of overloaded functions which we should forget ever
319    existed, such as functions declared in a function's scope,
320    once we leave that function's scope.  */
321 static tree overloads_to_forget;
322
323 /* -- end of C++ */
324
325 /* Two expressions that are constants with value zero.
326    The first is of type `int', the second of type `void *'.  */
327
328 tree integer_zero_node;
329 tree null_pointer_node;
330
331 /* A node for the integer constants 1, 2, and 3.  */
332
333 tree integer_one_node, integer_two_node, integer_three_node;
334
335 /* Nonzero if we have seen an invalid cross reference
336    to a struct, union, or enum, but not yet printed the message.  */
337
338 tree pending_invalid_xref;
339 /* File and line to appear in the eventual error message.  */
340 char *pending_invalid_xref_file;
341 int pending_invalid_xref_line;
342
343 /* While defining an enum type, this is 1 plus the last enumerator
344    constant value.  */
345
346 static tree enum_next_value;
347
348 /* Parsing a function declarator leaves a list of parameter names
349    or a chain or parameter decls here.  */
350
351 tree last_function_parms;
352
353 /* Parsing a function declarator leaves here a chain of structure
354    and enum types declared in the parmlist.  */
355
356 static tree last_function_parm_tags;
357
358 /* After parsing the declarator that starts a function definition,
359    `start_function' puts here the list of parameter names or chain of decls.
360    `store_parm_decls' finds it here.  */
361
362 static tree current_function_parms;
363
364 /* Similar, for last_function_parm_tags.  */
365 static tree current_function_parm_tags;
366
367 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
368    that have names.  Here so we can clear out their names' definitions
369    at the end of the function.  */
370
371 static tree named_labels;
372
373 /* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
374
375 static tree shadowed_labels;
376
377 #if 0 /* Not needed by C++ */
378 /* Nonzero when store_parm_decls is called indicates a varargs function.
379    Value not meaningful after store_parm_decls.  */
380
381 static int c_function_varargs;
382 #endif
383
384 /* The FUNCTION_DECL for the function currently being compiled,
385    or 0 if between functions.  */
386 tree current_function_decl;
387
388 /* Set to 0 at beginning of a function definition, set to 1 if
389    a return statement that specifies a return value is seen.  */
390
391 int current_function_returns_value;
392
393 /* Set to 0 at beginning of a function definition, set to 1 if
394    a return statement with no argument is seen.  */
395
396 int current_function_returns_null;
397
398 /* Set to 0 at beginning of a function definition, and whenever
399    a label (case or named) is defined.  Set to value of expression
400    returned from function when that value can be transformed into
401    a named return value.  */
402
403 tree current_function_return_value;
404
405 /* Set to nonzero by `grokdeclarator' for a function
406    whose return type is defaulted, if warnings for this are desired.  */
407
408 static int warn_about_return_type;
409
410 /* Nonzero when starting a function declared `extern inline'.  */
411
412 static int current_extern_inline;
413
414 /* Nonzero means give `double' the same size as `float'.  */
415
416 extern int flag_short_double;
417
418 /* Nonzero means don't recognize any builtin functions.  */
419
420 extern int flag_no_builtin;
421
422 /* Nonzero means do emit exported implementations of functions even if
423    they can be inlined.  */
424
425 extern int flag_implement_inlines;
426
427 /* Nonzero means handle things in ANSI, instead of GNU fashion.  This
428    flag should be tested for language behavior that's different between
429    ANSI and GNU, but not so horrible as to merit a PEDANTIC label.  */
430
431 extern int flag_ansi;
432
433 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
434    objects. */
435 extern int flag_huge_objects;
436
437 /* Nonzero if we want to conserve space in the .o files.  We do this
438    by putting uninitialized data and runtime initialized data into
439    .common instead of .data at the expense of not flaging multiple
440    definitions.  */
441 extern int flag_conserve_space;
442
443 /* Pointers to the base and current top of the language name stack.  */
444
445 extern tree *current_lang_base, *current_lang_stack;
446 \f
447 /* C and C++ flags are in cp-decl2.c.  */
448
449 /* Set to 0 at beginning of a constructor, set to 1
450    if that function does an allocation before referencing its
451    instance variable.  */
452 int current_function_assigns_this;
453 int current_function_just_assigned_this;
454
455 /* Set to 0 at beginning of a function.  Set non-zero when
456    store_parm_decls is called.  Don't call store_parm_decls
457    if this flag is non-zero!  */
458 int current_function_parms_stored;
459
460 /* Current end of entries in the gc obstack for stack pointer variables.  */
461
462 int current_function_obstack_index;
463
464 /* Flag saying whether we have used the obstack in this function or not.  */
465
466 int current_function_obstack_usage;
467
468 /* Flag used when debugging cp-spew.c */
469
470 extern int spew_debug;
471
472 /* This is a copy of the class_shadowed list of the previous class binding
473    contour when at global scope.  It's used to reset IDENTIFIER_CLASS_VALUEs
474    when entering another class scope (i.e. a cache miss).  */
475 extern tree previous_class_values;
476
477 \f
478 /* Allocate a level of searching.  */
479 struct stack_level *
480 push_decl_level (stack, obstack)
481      struct stack_level *stack;
482      struct obstack *obstack;
483 {
484   struct stack_level tem;
485   tem.prev = stack;
486
487   return push_stack_level (obstack, (char *)&tem, sizeof (tem));
488 }
489 \f
490 /* For each binding contour we allocate a binding_level structure
491  * which records the names defined in that contour.
492  * Contours include:
493  *  0) the global one
494  *  1) one for each function definition,
495  *     where internal declarations of the parameters appear.
496  *  2) one for each compound statement,
497  *     to record its declarations.
498  *
499  * The current meaning of a name can be found by searching the levels from
500  * the current one out to the global one.
501  *
502  * Off to the side, may be the class_binding_level.  This exists
503  * only to catch class-local declarations.  It is otherwise
504  * nonexistent.
505  * 
506  * Also there may be binding levels that catch cleanups that
507  * must be run when exceptions occur.
508  */
509
510 /* Note that the information in the `names' component of the global contour
511    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
512
513 struct binding_level
514   {
515     /* A chain of _DECL nodes for all variables, constants, functions,
516      * and typedef types.  These are in the reverse of the order supplied.
517      */
518     tree names;
519
520     /* A list of structure, union and enum definitions,
521      * for looking up tag names.
522      * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
523      * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
524      * or ENUMERAL_TYPE node.
525      *
526      * C++: the TREE_VALUE nodes can be simple types for component_bindings.
527      *
528      */
529     tree tags;
530
531     /* For each level, a list of shadowed outer-level local definitions
532        to be restored when this level is popped.
533        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
534        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
535     tree shadowed;
536
537     /* Same, for IDENTIFIER_CLASS_VALUE.  */
538     tree class_shadowed;
539
540     /* Same, for IDENTIFIER_TYPE_VALUE.  */
541     tree type_shadowed;
542
543     /* For each level (except not the global one),
544        a chain of BLOCK nodes for all the levels
545        that were entered and exited one level down.  */
546     tree blocks;
547
548     /* The BLOCK node for this level, if one has been preallocated.
549        If 0, the BLOCK is allocated (if needed) when the level is popped.  */
550     tree this_block;
551
552     /* The binding level which this one is contained in (inherits from).  */
553     struct binding_level *level_chain;
554
555     /* Number of decls in `names' that have incomplete 
556        structure or union types.  */
557     unsigned short n_incomplete;
558
559     /* 1 for the level that holds the parameters of a function.
560        2 for the level that holds a class declaration.
561        3 for levels that hold parameter declarations.  */
562     unsigned parm_flag : 4;
563
564     /* 1 means make a BLOCK for this level regardless of all else.
565        2 for temporary binding contours created by the compiler.  */
566     unsigned keep : 3;
567
568     /* Nonzero if this level "doesn't exist" for tags.  */
569     unsigned tag_transparent : 1;
570
571     /* Nonzero if this level can safely have additional
572        cleanup-needing variables added to it.  */
573     unsigned more_cleanups_ok : 1;
574     unsigned have_cleanups : 1;
575
576     /* Nonzero if this level can safely have additional
577        exception-raising statements added to it.  */
578     unsigned more_exceptions_ok : 1;
579     unsigned have_exceptions : 1;
580
581     /* Nonzero if we should accept any name as an identifier in
582        this scope.  This happens in some template definitions.  */
583     unsigned accept_any : 1;
584
585     /* Nonzero if this level is for completing a template class definition
586        inside a binding level that temporarily binds the parameters.  This
587        means that definitions here should not be popped off when unwinding
588        this binding level.  (Not actually implemented this way,
589        unfortunately.)  */
590     unsigned pseudo_global : 1;
591
592     /* Two bits left for this word.  */
593
594 #if defined(DEBUG_CP_BINDING_LEVELS)
595     /* Binding depth at which this level began.  */
596     unsigned binding_depth;
597 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
598   };
599
600 #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
601   
602 /* The (non-class) binding level currently in effect.  */
603
604 static struct binding_level *current_binding_level;
605
606 /* The binding level of the current class, if any.  */
607
608 static struct binding_level *class_binding_level;
609
610 /* The current (class or non-class) binding level currently in effect.  */
611
612 #define inner_binding_level \
613   (class_binding_level ? class_binding_level : current_binding_level)
614
615 /* A chain of binding_level structures awaiting reuse.  */
616
617 static struct binding_level *free_binding_level;
618
619 /* The outermost binding level, for names of file scope.
620    This is created when the compiler is started and exists
621    through the entire run.  */
622
623 static struct binding_level *global_binding_level;
624
625 /* Binding level structures are initialized by copying this one.  */
626
627 static struct binding_level clear_binding_level;
628
629 /* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
630
631 static int keep_next_level_flag;
632
633 #if defined(DEBUG_CP_BINDING_LEVELS)
634 static int binding_depth = 0;
635 static int is_class_level = 0;
636
637 static void
638 indent ()
639 {
640   register unsigned i;
641
642   for (i = 0; i < binding_depth*2; i++)
643     putc (' ', stderr);
644 }
645 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
646
647 static tree pushdecl_with_scope PROTO((tree, struct binding_level *));
648
649 static void
650 push_binding_level (newlevel, tag_transparent, keep)
651      struct binding_level *newlevel;
652      int tag_transparent, keep;
653 {
654   /* Add this level to the front of the chain (stack) of levels that
655      are active.  */
656   *newlevel = clear_binding_level;
657   if (class_binding_level)
658     {
659       newlevel->level_chain = class_binding_level;
660       class_binding_level = (struct binding_level *)0;
661     }
662   else
663     {
664       newlevel->level_chain = current_binding_level;
665     }
666   current_binding_level = newlevel;
667   newlevel->tag_transparent = tag_transparent;
668   newlevel->more_cleanups_ok = 1;
669   newlevel->more_exceptions_ok = 1;
670   newlevel->keep = keep;
671 #if defined(DEBUG_CP_BINDING_LEVELS)
672   newlevel->binding_depth = binding_depth;
673   indent ();
674   fprintf (stderr, "push %s level 0x%08x line %d\n",
675            (is_class_level) ? "class" : "block", newlevel, lineno);
676   is_class_level = 0;
677   binding_depth++;
678 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
679 }
680
681 static void
682 pop_binding_level ()
683 {
684   if (class_binding_level)
685     current_binding_level = class_binding_level;
686
687   if (global_binding_level)
688     {
689       /* cannot pop a level, if there are none left to pop. */
690       if (current_binding_level == global_binding_level)
691         my_friendly_abort (123);
692     }
693   /* Pop the current level, and free the structure for reuse.  */
694 #if defined(DEBUG_CP_BINDING_LEVELS)
695   binding_depth--;
696   indent ();
697   fprintf (stderr, "pop  %s level 0x%08x line %d\n",
698           (is_class_level) ? "class" : "block",
699           current_binding_level, lineno);
700   if (is_class_level != (current_binding_level == class_binding_level))
701 #if 0 /* XXX Don't abort when we're watching how things are being managed.  */
702     abort ();
703 #else
704   {
705     indent ();
706     fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
707   }
708 #endif
709   is_class_level = 0;
710 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
711   {
712     register struct binding_level *level = current_binding_level;
713     current_binding_level = current_binding_level->level_chain;
714     level->level_chain = free_binding_level;
715 #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
716     if (level->binding_depth != binding_depth)
717       abort ();
718 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
719       free_binding_level = level;
720
721     class_binding_level = current_binding_level;
722     if (class_binding_level->parm_flag != 2)
723       class_binding_level = 0;
724     while (current_binding_level->parm_flag == 2)
725       current_binding_level = current_binding_level->level_chain;
726   }
727 }
728 \f
729 /* Nonzero if we are currently in the global binding level.  */
730
731 int
732 global_bindings_p ()
733 {
734   return current_binding_level == global_binding_level;
735 }
736
737 void
738 keep_next_level ()
739 {
740   keep_next_level_flag = 1;
741 }
742
743 /* Nonzero if the current level needs to have a BLOCK made.  */
744
745 int
746 kept_level_p ()
747 {
748   return (current_binding_level->blocks != NULL_TREE
749           || current_binding_level->keep
750           || current_binding_level->names != NULL_TREE
751           || (current_binding_level->tags != NULL_TREE
752               && !current_binding_level->tag_transparent));
753 }
754
755 /* Identify this binding level as a level of parameters.  */
756
757 void
758 declare_parm_level ()
759 {
760   current_binding_level->parm_flag = 1;
761 }
762
763 /* Identify this binding level as a level of a default exception handler.  */
764
765 void
766 declare_implicit_exception ()
767 {
768   current_binding_level->parm_flag = 3;
769 }
770
771 /* Nonzero if current binding contour contains expressions
772    that might raise exceptions.  */
773
774 int
775 have_exceptions_p ()
776 {
777   return current_binding_level->have_exceptions;
778 }
779
780 void
781 declare_uninstantiated_type_level ()
782 {
783   current_binding_level->accept_any = 1;
784 }
785
786 int
787 uninstantiated_type_level_p ()
788 {
789   return current_binding_level->accept_any;
790 }
791
792 void
793 declare_pseudo_global_level ()
794 {
795   current_binding_level->pseudo_global = 1;
796 }
797
798 int
799 pseudo_global_level_p ()
800 {
801   return current_binding_level->pseudo_global;
802 }
803
804 void
805 set_class_shadows (shadows)
806      tree shadows;
807 {
808   class_binding_level->class_shadowed = shadows;
809 }
810
811 /* Enter a new binding level.
812    If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
813    not for that of tags.  */
814
815 void
816 pushlevel (tag_transparent)
817      int tag_transparent;
818 {
819   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
820
821   /* If this is the top level of a function,
822      just make sure that NAMED_LABELS is 0.
823      They should have been set to 0 at the end of the previous function.  */
824
825   if (current_binding_level == global_binding_level)
826     my_friendly_assert (named_labels == NULL_TREE, 134);
827
828   /* Reuse or create a struct for this binding level.  */
829
830 #if defined(DEBUG_CP_BINDING_LEVELS)
831   if (0)
832 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
833   if (free_binding_level)
834 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
835     {
836       newlevel = free_binding_level;
837       free_binding_level = free_binding_level->level_chain;
838     }
839   else
840     {
841       /* Create a new `struct binding_level'.  */
842       newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
843     }
844   push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
845   GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
846   keep_next_level_flag = 0;
847 }
848
849 void
850 pushlevel_temporary (tag_transparent)
851      int tag_transparent;
852 {
853   pushlevel (tag_transparent);
854   current_binding_level->keep = 2;
855   clear_last_expr ();
856
857   /* Note we don't call push_momentary() here.  Otherwise, it would cause
858      cleanups to be allocated on the momentary obstack, and they will be
859      overwritten by the next statement.  */
860
861   expand_start_bindings (0);
862 }
863
864 /* Exit a binding level.
865    Pop the level off, and restore the state of the identifier-decl mappings
866    that were in effect when this level was entered.
867
868    If KEEP == 1, this level had explicit declarations, so
869    and create a "block" (a BLOCK node) for the level
870    to record its declarations and subblocks for symbol table output.
871
872    If KEEP == 2, this level's subblocks go to the front,
873    not the back of the current binding level.  This happens,
874    for instance, when code for constructors and destructors
875    need to generate code at the end of a function which must
876    be moved up to the front of the function.
877
878    If FUNCTIONBODY is nonzero, this level is the body of a function,
879    so create a block as if KEEP were set and also clear out all
880    label names.
881
882    If REVERSE is nonzero, reverse the order of decls before putting
883    them into the BLOCK.  */
884
885 tree
886 poplevel (keep, reverse, functionbody)
887      int keep;
888      int reverse;
889      int functionbody;
890 {
891   register tree link;
892   /* The chain of decls was accumulated in reverse order.
893      Put it into forward order, just for cleanliness.  */
894   tree decls;
895   int tmp = functionbody;
896   int implicit_try_block = current_binding_level->parm_flag == 3;
897   int real_functionbody = current_binding_level->keep == 2
898     ? ((functionbody = 0), tmp) : functionbody;
899   tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
900   tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
901   tree block = NULL_TREE;
902   tree decl;
903   int block_previously_created;
904
905   GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
906                       (HOST_WIDE_INT) current_binding_level->level_chain,
907                       current_binding_level->parm_flag,
908                       current_binding_level->keep,
909                       current_binding_level->tag_transparent);
910
911   if (current_binding_level->keep == 1)
912     keep = 1;
913
914   /* This warning is turned off because it causes warnings for
915      declarations like `extern struct foo *x'.  */
916 #if 0
917   /* Warn about incomplete structure types in this level.  */
918   for (link = tags; link; link = TREE_CHAIN (link))
919     if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE)
920       {
921         tree type = TREE_VALUE (link);
922         char *errmsg;
923         switch (TREE_CODE (type))
924           {
925           case RECORD_TYPE:
926             errmsg = "`struct %s' incomplete in scope ending here";
927             break;
928           case UNION_TYPE:
929             errmsg = "`union %s' incomplete in scope ending here";
930             break;
931           case ENUMERAL_TYPE:
932             errmsg = "`enum %s' incomplete in scope ending here";
933             break;
934           }
935         if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
936           error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
937         else
938           /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
939           error (errmsg, TYPE_NAME_STRING (type));
940       }
941 #endif /* 0 */
942
943   /* Get the decls in the order they were written.
944      Usually current_binding_level->names is in reverse order.
945      But parameter decls were previously put in forward order.  */
946
947   if (reverse)
948     current_binding_level->names
949       = decls = nreverse (current_binding_level->names);
950   else
951     decls = current_binding_level->names;
952
953   /* Output any nested inline functions within this block
954      if they weren't already output.  */
955
956   for (decl = decls; decl; decl = TREE_CHAIN (decl))
957     if (TREE_CODE (decl) == FUNCTION_DECL
958         && ! TREE_ASM_WRITTEN (decl)
959         && DECL_INITIAL (decl) != NULL_TREE
960         && TREE_ADDRESSABLE (decl))
961       {
962         /* If this decl was copied from a file-scope decl
963            on account of a block-scope extern decl,
964            propagate TREE_ADDRESSABLE to the file-scope decl.  */
965         if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
966           TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
967         else
968           {
969             push_function_context ();
970             output_inline_function (decl);
971             pop_function_context ();
972           }
973       }
974
975   /* If there were any declarations or structure tags in that level,
976      or if this level is a function body,
977      create a BLOCK to record them for the life of this function.  */
978
979   block = NULL_TREE;
980   block_previously_created = (current_binding_level->this_block != NULL_TREE);
981   if (block_previously_created)
982     block = current_binding_level->this_block;
983   else if (keep == 1 || functionbody)
984     block = make_node (BLOCK);
985   if (block != NULL_TREE)
986     {
987       BLOCK_VARS (block) = decls;
988       BLOCK_TYPE_TAGS (block) = tags;
989       BLOCK_SUBBLOCKS (block) = subblocks;
990       /* If we created the block earlier on, and we are just diddling it now,
991          then it already should have a proper BLOCK_END_NOTE value associated
992          with it, so avoid trashing that.  Otherwise, for a new block, install
993          a new BLOCK_END_NOTE value.  */
994       if (! block_previously_created)
995         remember_end_note (block);
996     }
997
998   /* In each subblock, record that this is its superior.  */
999
1000   if (keep >= 0)
1001     for (link = subblocks; link; link = TREE_CHAIN (link))
1002       BLOCK_SUPERCONTEXT (link) = block;
1003
1004   /* Clear out the meanings of the local variables of this level.  */
1005
1006   for (link = decls; link; link = TREE_CHAIN (link))
1007     {
1008       if (DECL_NAME (link) != NULL_TREE)
1009         {
1010           /* If the ident. was used or addressed via a local extern decl,
1011              don't forget that fact.  */
1012           if (DECL_EXTERNAL (link))
1013             {
1014               if (TREE_USED (link))
1015                 TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
1016               if (TREE_ADDRESSABLE (link))
1017                 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1018             }
1019           IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
1020         }
1021     }
1022
1023   /* Restore all name-meanings of the outer levels
1024      that were shadowed by this level.  */
1025
1026   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1027     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1028   for (link = current_binding_level->class_shadowed;
1029        link; link = TREE_CHAIN (link))
1030     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1031   for (link = current_binding_level->type_shadowed;
1032        link; link = TREE_CHAIN (link))
1033     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1034
1035   /* If the level being exited is the top level of a function,
1036      check over all the labels.  */
1037
1038   if (functionbody)
1039     {
1040       /* If this is the top level block of a function,
1041          the vars are the function's parameters.
1042          Don't leave them in the BLOCK because they are
1043          found in the FUNCTION_DECL instead.  */
1044
1045       BLOCK_VARS (block) = 0;
1046
1047       /* Clear out the definitions of all label names,
1048          since their scopes end here.  */
1049
1050       for (link = named_labels; link; link = TREE_CHAIN (link))
1051         {
1052           register tree label = TREE_VALUE (link);
1053
1054           if (DECL_INITIAL (label) == NULL_TREE)
1055             {
1056               cp_error_at ("label `%D' used but not defined", label);
1057               /* Avoid crashing later.  */
1058               define_label (input_filename, 1, DECL_NAME (label));
1059             }
1060           else if (warn_unused && !TREE_USED (label))
1061             cp_warning_at ("label `%D' defined but not used", label);
1062           SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
1063
1064           /* Put the labels into the "variables" of the
1065              top-level block, so debugger can see them.  */
1066           TREE_CHAIN (label) = BLOCK_VARS (block);
1067           BLOCK_VARS (block) = label;
1068         }
1069
1070       named_labels = NULL_TREE;
1071     }
1072
1073   /* Any uses of undefined labels now operate under constraints
1074      of next binding contour.  */
1075   {
1076     struct binding_level *level_chain;
1077     level_chain = current_binding_level->level_chain;
1078     if (level_chain)
1079       {
1080         tree labels;
1081         for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
1082           if (TREE_TYPE (labels) == (tree)current_binding_level)
1083             {
1084               TREE_TYPE (labels) = (tree)level_chain;
1085               TREE_PURPOSE (labels) = level_chain->names;
1086             }
1087       }
1088   }
1089
1090   tmp = current_binding_level->keep;
1091
1092   pop_binding_level ();
1093   if (functionbody)
1094     DECL_INITIAL (current_function_decl) = block;
1095   else if (block)
1096     {
1097       if (!block_previously_created)
1098         current_binding_level->blocks
1099           = chainon (current_binding_level->blocks, block);
1100     }
1101   /* If we did not make a block for the level just exited,
1102      any blocks made for inner levels
1103      (since they cannot be recorded as subblocks in that level)
1104      must be carried forward so they will later become subblocks
1105      of something else.  */
1106   else if (subblocks)
1107     {
1108       if (keep == 2)
1109         current_binding_level->blocks
1110           = chainon (subblocks, current_binding_level->blocks);
1111       else
1112         current_binding_level->blocks
1113           = chainon (current_binding_level->blocks, subblocks);
1114     }
1115
1116   /* Take care of compiler's internal binding structures.  */
1117   if (tmp == 2 && !implicit_try_block)
1118     {
1119 #if 0
1120       /* We did not call push_momentary for this
1121          binding contour, so there is nothing to pop.  */
1122       pop_momentary ();
1123 #endif
1124       expand_end_bindings (getdecls (), keep, 1);
1125       /* Each and every BLOCK node created here in `poplevel' is important
1126          (e.g. for proper debugging information) so if we created one
1127          earlier, mark it as "used".  */
1128       if (block)
1129         TREE_USED (block) = 1;
1130       block = poplevel (keep, reverse, real_functionbody);
1131     }
1132
1133   /* Each and every BLOCK node created here in `poplevel' is important
1134      (e.g. for proper debugging information) so if we created one
1135      earlier, mark it as "used".  */
1136   if (block)
1137     TREE_USED (block) = 1;
1138   return block;
1139 }
1140
1141 /* Delete the node BLOCK from the current binding level.
1142    This is used for the block inside a stmt expr ({...})
1143    so that the block can be reinserted where appropriate.  */
1144
1145 void
1146 delete_block (block)
1147      tree block;
1148 {
1149   tree t;
1150   if (current_binding_level->blocks == block)
1151     current_binding_level->blocks = TREE_CHAIN (block);
1152   for (t = current_binding_level->blocks; t;)
1153     {
1154       if (TREE_CHAIN (t) == block)
1155         TREE_CHAIN (t) = TREE_CHAIN (block);
1156       else
1157         t = TREE_CHAIN (t);
1158     }
1159   TREE_CHAIN (block) = NULL_TREE;
1160   /* Clear TREE_USED which is always set by poplevel.
1161      The flag is set again if insert_block is called.  */
1162   TREE_USED (block) = 0;
1163 }
1164
1165 /* Insert BLOCK at the end of the list of subblocks of the
1166    current binding level.  This is used when a BIND_EXPR is expanded,
1167    to handle the BLOCK node inside the BIND_EXPR.  */
1168
1169 void
1170 insert_block (block)
1171      tree block;
1172 {
1173   TREE_USED (block) = 1;
1174   current_binding_level->blocks
1175     = chainon (current_binding_level->blocks, block);
1176 }
1177
1178 /* Add BLOCK to the current list of blocks for this binding contour.  */
1179 void
1180 add_block_current_level (block)
1181      tree block;
1182 {
1183   current_binding_level->blocks
1184     = chainon (current_binding_level->blocks, block);
1185 }
1186
1187 /* Set the BLOCK node for the innermost scope
1188    (the one we are currently in).  */
1189
1190 void
1191 set_block (block)
1192     register tree block;
1193 {
1194   current_binding_level->this_block = block;
1195 }
1196
1197 /* Do a pushlevel for class declarations.  */
1198 void
1199 pushlevel_class ()
1200 {
1201   register struct binding_level *newlevel;
1202
1203   /* Reuse or create a struct for this binding level.  */
1204 #if defined(DEBUG_CP_BINDING_LEVELS)
1205   if (0)
1206 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
1207   if (free_binding_level)
1208 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
1209     {
1210       newlevel = free_binding_level;
1211       free_binding_level = free_binding_level->level_chain;
1212     }
1213   else
1214     {
1215       /* Create a new `struct binding_level'.  */
1216       newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
1217     }
1218
1219 #if defined(DEBUG_CP_BINDING_LEVELS)
1220   is_class_level = 1;
1221 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1222
1223   push_binding_level (newlevel, 0, 0);
1224
1225   decl_stack = push_decl_level (decl_stack, &decl_obstack);
1226   class_binding_level = current_binding_level;
1227   class_binding_level->parm_flag = 2;
1228   /* We have just pushed into a new binding level.  Now, fake out the rest
1229      of the compiler.  Set the `current_binding_level' back to point to
1230      the most closely containing non-class binding level.  */
1231   do
1232     {
1233       current_binding_level = current_binding_level->level_chain;
1234     }
1235   while (current_binding_level->parm_flag == 2);
1236 }
1237
1238 /* ...and a poplevel for class declarations.  */
1239 tree
1240 poplevel_class ()
1241 {
1242   register struct binding_level *level = class_binding_level;
1243   tree block = NULL_TREE;
1244   tree shadowed;
1245
1246   my_friendly_assert (level != 0, 354);
1247   
1248   decl_stack = pop_stack_level (decl_stack);
1249   for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1250     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1251   /* If we're leaving a toplevel class, don't bother to do the setting
1252      of IDENTIFER_CLASS_VALUE to NULL_TREE, since first of all this slot
1253      shouldn't even be used when current_class_type isn't set, and second,
1254      if we don't touch it here, we're able to use the caching effect if the
1255      next time we're entering a class scope, it is the same class.  */
1256   if (current_class_depth != 1)
1257     for (shadowed = level->class_shadowed;
1258          shadowed;
1259          shadowed = TREE_CHAIN (shadowed))
1260       IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1261   else
1262     /* Remember to save what IDENTIFIER's were bound in this scope so we
1263        can recover from cache misses.  */
1264     previous_class_values = class_binding_level->class_shadowed;
1265   for (shadowed = level->type_shadowed;
1266        shadowed;
1267        shadowed = TREE_CHAIN (shadowed))
1268     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1269
1270   GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
1271                       (HOST_WIDE_INT) class_binding_level->level_chain,
1272                       class_binding_level->parm_flag,
1273                       class_binding_level->keep,
1274                       class_binding_level->tag_transparent);
1275
1276   if (class_binding_level->parm_flag != 2)
1277     class_binding_level = (struct binding_level *)0;
1278
1279   /* Now, pop out of the the binding level which we created up in the
1280      `pushlevel_class' routine.  */
1281 #if defined(DEBUG_CP_BINDING_LEVELS)
1282   is_class_level = 1;
1283 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1284
1285   pop_binding_level ();
1286
1287   return block;
1288 }
1289 \f
1290 /* For debugging.  */
1291 int no_print_functions = 0;
1292 int no_print_builtins = 0;
1293
1294 void
1295 print_binding_level (lvl)
1296      struct binding_level *lvl;
1297 {
1298   tree t;
1299   int i = 0, len;
1300   fprintf (stderr, " blocks=");
1301   fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
1302   fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
1303            lvl->n_incomplete, lvl->parm_flag, lvl->keep);
1304   if (lvl->tag_transparent)
1305     fprintf (stderr, " tag-transparent");
1306   if (lvl->more_cleanups_ok)
1307     fprintf (stderr, " more-cleanups-ok");
1308   if (lvl->have_cleanups)
1309     fprintf (stderr, " have-cleanups");
1310   if (lvl->more_exceptions_ok)
1311     fprintf (stderr, " more-exceptions-ok");
1312   if (lvl->have_exceptions)
1313     fprintf (stderr, " have-exceptions");
1314   fprintf (stderr, "\n");
1315   if (lvl->names)
1316     {
1317       fprintf (stderr, " names:\t");
1318       /* We can probably fit 3 names to a line?  */
1319       for (t = lvl->names; t; t = TREE_CHAIN (t))
1320         {
1321           if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL)) 
1322             continue;
1323           if (no_print_builtins
1324               && (TREE_CODE(t) == TYPE_DECL)
1325               && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
1326             continue;
1327
1328           /* Function decls tend to have longer names.  */
1329           if (TREE_CODE (t) == FUNCTION_DECL)
1330             len = 3;
1331           else
1332             len = 2;
1333           i += len;
1334           if (i > 6)
1335             {
1336               fprintf (stderr, "\n\t");
1337               i = len;
1338             }
1339           print_node_brief (stderr, "", t, 0);
1340           if (TREE_CODE (t) == ERROR_MARK)
1341             break;
1342         }
1343       if (i)
1344         fprintf (stderr, "\n");
1345     }
1346   if (lvl->tags)
1347     {
1348       fprintf (stderr, " tags:\t");
1349       i = 0;
1350       for (t = lvl->tags; t; t = TREE_CHAIN (t))
1351         {
1352           if (TREE_PURPOSE (t) == NULL_TREE)
1353             len = 3;
1354           else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1355             len = 2;
1356           else
1357             len = 4;
1358           i += len;
1359           if (i > 5)
1360             {
1361               fprintf (stderr, "\n\t");
1362               i = len;
1363             }
1364           if (TREE_PURPOSE (t) == NULL_TREE)
1365             {
1366               print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
1367               fprintf (stderr, ">");
1368             }
1369           else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1370             print_node_brief (stderr, "", TREE_VALUE (t), 0);
1371           else
1372             {
1373               print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
1374               print_node_brief (stderr, "", TREE_VALUE (t), 0);
1375               fprintf (stderr, ">");
1376             }
1377         }
1378       if (i)
1379         fprintf (stderr, "\n");
1380     }
1381   if (lvl->shadowed)
1382     {
1383       fprintf (stderr, " shadowed:");
1384       for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
1385         {
1386           fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1387         }
1388       fprintf (stderr, "\n");
1389     }
1390   if (lvl->class_shadowed)
1391     {
1392       fprintf (stderr, " class-shadowed:");
1393       for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
1394         {
1395           fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1396         }
1397       fprintf (stderr, "\n");
1398     }
1399   if (lvl->type_shadowed)
1400     {
1401       fprintf (stderr, " type-shadowed:");
1402       for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
1403         {
1404 #if 0
1405           fprintf (stderr, "\n\t");
1406           print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
1407           if (TREE_VALUE (t))
1408             print_node_brief (stderr, " ", TREE_VALUE (t), 0);
1409           else
1410             fprintf (stderr, " (none)");
1411           fprintf (stderr, ">");
1412 #else
1413           fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1414 #endif
1415         }
1416       fprintf (stderr, "\n");
1417     }
1418 }
1419
1420 void
1421 print_other_binding_stack (stack)
1422      struct binding_level *stack;
1423 {
1424   struct binding_level *level;
1425   for (level = stack; level != global_binding_level; level = level->level_chain)
1426     {
1427       fprintf (stderr, "binding level ");
1428       fprintf (stderr, HOST_PTR_PRINTF, level);
1429       fprintf (stderr, "\n");
1430       print_binding_level (level);
1431     }
1432 }
1433
1434 void
1435 print_binding_stack ()
1436 {
1437   struct binding_level *b;
1438   fprintf (stderr, "current_binding_level=");
1439   fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
1440   fprintf (stderr, "\nclass_binding_level=");
1441   fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
1442   fprintf (stderr, "\nglobal_binding_level=");
1443   fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
1444   fprintf (stderr, "\n");
1445   if (class_binding_level)
1446     {
1447       for (b = class_binding_level; b; b = b->level_chain)
1448         if (b == current_binding_level)
1449           break;
1450       if (b)
1451         b = class_binding_level;
1452       else
1453         b = current_binding_level;
1454     }
1455   else
1456     b = current_binding_level;
1457   print_other_binding_stack (b);
1458   fprintf (stderr, "global:\n");
1459   print_binding_level (global_binding_level);
1460 }
1461 \f
1462 /* Subroutines for reverting temporarily to top-level for instantiation
1463    of templates and such.  We actually need to clear out the class- and
1464    local-value slots of all identifiers, so that only the global values
1465    are at all visible.  Simply setting current_binding_level to the global
1466    scope isn't enough, because more binding levels may be pushed.  */
1467 struct saved_scope {
1468   struct binding_level *old_binding_level;
1469   tree old_bindings;
1470   struct saved_scope *prev;
1471   tree class_name, class_type, class_decl, function_decl;
1472   struct binding_level *class_bindings;
1473   tree previous_class_type;
1474 };
1475 static struct saved_scope *current_saved_scope;
1476 extern tree prev_class_type;
1477
1478 void
1479 push_to_top_level ()
1480 {
1481   struct saved_scope *s =
1482     (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
1483   struct binding_level *b = current_binding_level;
1484   tree old_bindings = NULL_TREE;
1485
1486   /* Have to include global_binding_level, because class-level decls
1487      aren't listed anywhere useful.  */
1488   for (; b; b = b->level_chain)
1489     {
1490       tree t;
1491
1492       if (b == global_binding_level)
1493         continue;
1494       
1495       for (t = b->names; t; t = TREE_CHAIN (t))
1496         {
1497           tree binding, t1, t2 = t;
1498           tree id = DECL_ASSEMBLER_NAME (t2);
1499
1500           if (!id
1501               || (!IDENTIFIER_LOCAL_VALUE (id)
1502                   && !IDENTIFIER_CLASS_VALUE (id)))
1503             continue;
1504
1505           for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
1506             if (TREE_VEC_ELT (t1, 0) == id)
1507               goto skip_it;
1508             
1509           binding = make_tree_vec (4);
1510           if (id)
1511             {
1512               my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
1513               TREE_VEC_ELT (binding, 0) = id;
1514               TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
1515               TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
1516               TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
1517               IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
1518               IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
1519             }
1520           TREE_CHAIN (binding) = old_bindings;
1521           old_bindings = binding;
1522         skip_it:
1523           ;
1524         }
1525       /* Unwind type-value slots back to top level.  */
1526       for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
1527         SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
1528     }
1529   /* Clear out class-level bindings cache.  */
1530   if (current_binding_level == global_binding_level
1531       && previous_class_type != NULL_TREE)
1532     {
1533       popclass (-1);
1534       previous_class_type = NULL_TREE;
1535     }
1536
1537   s->old_binding_level = current_binding_level;
1538   current_binding_level = global_binding_level;
1539
1540   s->class_name = current_class_name;
1541   s->class_type = current_class_type;
1542   s->class_decl = current_class_decl;
1543   s->function_decl = current_function_decl;
1544   s->class_bindings = class_binding_level;
1545   s->previous_class_type = previous_class_type;
1546   current_class_name = current_class_type = current_class_decl = NULL_TREE;
1547   current_function_decl = NULL_TREE;
1548   class_binding_level = (struct binding_level *)0;
1549   previous_class_type = NULL_TREE;
1550
1551   s->prev = current_saved_scope;
1552   s->old_bindings = old_bindings;
1553   current_saved_scope = s;
1554 }
1555
1556 void
1557 pop_from_top_level ()
1558 {
1559   struct saved_scope *s = current_saved_scope;
1560   tree t;
1561
1562   if (previous_class_type)
1563     previous_class_type = NULL_TREE;
1564
1565   current_binding_level = s->old_binding_level;
1566   current_saved_scope = s->prev;
1567   for (t = s->old_bindings; t; t = TREE_CHAIN (t))
1568     {
1569       tree id = TREE_VEC_ELT (t, 0);
1570       if (id)
1571         {
1572           IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
1573           IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
1574           IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
1575         }
1576     }
1577   current_class_name = s->class_name;
1578   current_class_type = s->class_type;
1579   current_class_decl = s->class_decl;
1580   if (current_class_type)
1581     C_C_D = CLASSTYPE_INST_VAR (current_class_type);
1582   else
1583     C_C_D = NULL_TREE;
1584   current_function_decl = s->function_decl;
1585   class_binding_level = s->class_bindings;
1586   previous_class_type = s->previous_class_type;
1587   free (s);
1588 }
1589 \f
1590 /* Push a definition of struct, union or enum tag "name".
1591    into binding_level "b".   "type" should be the type node, 
1592    We assume that the tag "name" is not already defined.
1593
1594    Note that the definition may really be just a forward reference.
1595    In that case, the TYPE_SIZE will be a NULL_TREE.
1596
1597    C++ gratuitously puts all these tags in the name space. */
1598
1599 /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
1600    record the shadowed value for this binding contour.  TYPE is
1601    the type that ID maps to.  */
1602
1603 static void
1604 set_identifier_type_value_with_scope (id, type, b)
1605      tree id;
1606      tree type;
1607      struct binding_level *b;
1608 {
1609   if (b != global_binding_level)
1610     {
1611       tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
1612       b->type_shadowed
1613         = tree_cons (id, old_type_value, b->type_shadowed);
1614     }
1615   SET_IDENTIFIER_TYPE_VALUE (id, type);
1616 }
1617
1618 /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
1619
1620 void
1621 set_identifier_type_value (id, type)
1622      tree id;
1623      tree type;
1624 {
1625   set_identifier_type_value_with_scope (id, type, inner_binding_level);
1626 }
1627
1628 /* Subroutine "set_nested_typename" builds the nested-typename of
1629    the type decl in question.  (Argument CLASSNAME can actually be
1630    a function as well, if that's the smallest containing scope.)  */
1631
1632 static void
1633 set_nested_typename (decl, classname, name, type)
1634      tree decl, classname, name, type;
1635 {
1636   my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
1637   if (classname != NULL_TREE)
1638     {
1639       char *buf;
1640       my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
1641       my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
1642       buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
1643                              + IDENTIFIER_LENGTH (name));
1644       sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
1645                IDENTIFIER_POINTER (name));
1646       DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
1647
1648       /* This is a special usage of IDENTIFIER_TYPE_VALUE which have no
1649          correspondence in any binding_level.  This is ok since the
1650          DECL_NESTED_TYPENAME is just a convenience identifier whose
1651          IDENTIFIER_TYPE_VALUE will remain constant from now on.  */
1652       SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type);
1653     }
1654   else
1655     DECL_NESTED_TYPENAME (decl) = name;
1656 }
1657
1658 #if 0 /* not yet, should get fixed properly later */
1659 /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
1660    Other routines shouldn't use build_decl directly; they'll produce
1661    incorrect results with `-g' unless they duplicate this code.
1662
1663    This is currently needed mainly for dbxout.c, but we can make
1664    use of it in cp-method.c later as well.  */
1665 tree
1666 make_type_decl (name, type)
1667      tree name, type;
1668 {
1669   tree decl, id;
1670   decl = build_decl (TYPE_DECL, name, type);
1671   if (TYPE_NAME (type) == name)
1672     /* Class/union/enum definition, or a redundant typedef for same.  */
1673     {
1674       id = get_identifier (build_overload_name (type, 1, 1));
1675       DECL_ASSEMBLER_NAME (decl) = id;
1676     }
1677   else if (TYPE_NAME (type) != NULL_TREE)
1678     /* Explicit typedef, or implicit typedef for template expansion.  */
1679     DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
1680   else
1681     {
1682       /* XXX: Typedef for unnamed struct; some other situations.
1683          TYPE_NAME is null; what's right here?  */
1684     }
1685   return decl;
1686 }
1687 #endif
1688
1689 /* Push a tag name NAME for struct/class/union/enum type TYPE.
1690    Normally put into into the inner-most non-tag-tranparent scope,
1691    but if GLOBALIZE is true, put it in the inner-most non-class scope.
1692    The latter is needed for implicit declarations. */
1693
1694 void
1695 pushtag (name, type, globalize)
1696      tree name, type;
1697      int globalize;
1698 {
1699   register struct binding_level *b;
1700   tree t_context = 0;
1701
1702   b = inner_binding_level;
1703   while (b->tag_transparent
1704          || (globalize && b->parm_flag == 2))
1705     b = b->level_chain;
1706
1707   if (b == global_binding_level)
1708     b->tags = perm_tree_cons (name, type, b->tags);
1709   else
1710     b->tags = saveable_tree_cons (name, type, b->tags);
1711
1712   if (name)
1713     {
1714       t_context = type ? TYPE_CONTEXT(type) : NULL_TREE;
1715       if (!t_context && !globalize)
1716         t_context = current_class_type;
1717
1718       /* Record the identifier as the type's name if it has none.  */
1719       if (TYPE_NAME (type) == NULL_TREE)
1720         TYPE_NAME (type) = name;
1721       
1722       /* Do C++ gratuitous typedefing.  */
1723       if (IDENTIFIER_TYPE_VALUE (name) != type
1724           && (TREE_CODE (type) != RECORD_TYPE
1725               || b->parm_flag != 2
1726               || !CLASSTYPE_DECLARED_EXCEPTION (type)))
1727         {
1728           register tree d;
1729           int newdecl = 0;
1730           
1731           if (b->parm_flag != 2
1732               || TYPE_SIZE (current_class_type) != NULL_TREE)
1733             {
1734               if (current_lang_name == lang_name_cplusplus)
1735                 d = lookup_nested_type (type, 
1736                         t_context ? TYPE_NAME (t_context) : NULL_TREE);
1737               else
1738                 d = NULL_TREE;
1739
1740               if (d == NULL_TREE)
1741                 {
1742                   newdecl = 1;
1743 #if 0 /* not yet, should get fixed properly later */
1744                   d = make_type_decl (name, type);
1745 #else
1746                   d = build_decl (TYPE_DECL, name, type);
1747 #endif
1748 #ifdef DWARF_DEBUGGING_INFO
1749                   if (write_symbols == DWARF_DEBUG)
1750                     {
1751                       /* Mark the TYPE_DECL node we created just above as an
1752                          gratuitous one.  We need to do this so that dwarfout.c
1753                          will understand that it is not supposed to output a
1754                          TAG_typedef DIE  for it. */
1755                       DECL_IGNORED_P (d) = 1;
1756                     }
1757 #endif /* DWARF_DEBUGGING_INFO */
1758                   set_identifier_type_value_with_scope (name, type, b);
1759                 }
1760               else
1761                 d = TYPE_NAME (d);
1762
1763               /* If it is anonymous, then we are called from pushdecl,
1764                  and we don't want to infinitely recurse.  Also, if the
1765                  name is already in scope, we don't want to push it
1766                  again--pushdecl is only for pushing new decls.  */
1767               if (! ANON_AGGRNAME_P (name)
1768                   && TYPE_NAME (type)
1769                   && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
1770                       || lookup_name (name, 1) != TYPE_NAME (type)))
1771                 {
1772                   if (b->parm_flag == 2)
1773                     d = pushdecl_class_level (d);
1774                   else
1775                     d = pushdecl_with_scope (d, b);
1776                 }
1777             }
1778           else
1779             {
1780               /* Make nested declarations go into class-level scope.  */
1781               newdecl = 1;
1782               d = build_lang_field_decl (TYPE_DECL, name, type);
1783 #ifdef DWARF_DEBUGGING_INFO
1784               if (write_symbols == DWARF_DEBUG)
1785                 {
1786                   /* Mark the TYPE_DECL node we created just above as an
1787                      gratuitous one.  We need to do this so that dwarfout.c
1788                      will understand that it is not supposed to output a
1789                      TAG_typedef DIE  for it. */
1790                   DECL_IGNORED_P (d) = 1;
1791                 }
1792 #endif /* DWARF_DEBUGGING_INFO */
1793               /* Make sure we're in this type's scope when we push the
1794                  decl for a template, otherwise class_binding_level will
1795                  be NULL and we'll end up dying inside of
1796                  push_class_level_binding.  */
1797               if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
1798                 pushclass (type, 0);
1799               d = pushdecl_class_level (d);
1800               if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
1801                 popclass (0);
1802             }
1803           if (write_symbols != DWARF_DEBUG)
1804             {
1805               if (ANON_AGGRNAME_P (name))
1806                 DECL_IGNORED_P (d) = 1;
1807             }
1808           TYPE_NAME (type) = d;
1809
1810           if ((t_context == NULL_TREE
1811                && current_function_decl == NULL_TREE)
1812               || current_lang_name != lang_name_cplusplus)
1813             /* Non-nested class.  */
1814             DECL_NESTED_TYPENAME (d) = name;
1815           else if (current_function_decl != NULL_TREE)
1816             {
1817               /* Function-nested class.  */
1818               set_nested_typename (d, 
1819                 DECL_ASSEMBLER_NAME (current_function_decl), name, type);
1820               /* This builds the links for classes nested in fn scope.  */
1821               DECL_CONTEXT (d) = current_function_decl;
1822             }
1823 /*        else if (TYPE_SIZE (current_class_type) == NULL_TREE)
1824 */
1825           else if (t_context && TREE_CODE (t_context) == RECORD_TYPE)
1826             {
1827               /* Class-nested class.  */
1828               set_nested_typename (d, 
1829                 DECL_NESTED_TYPENAME (TYPE_NAME (t_context)), name, type);
1830               /* This builds the links for classes nested in type scope.  */
1831               DECL_CONTEXT (d) = t_context;
1832               DECL_CLASS_CONTEXT (d) = t_context;
1833             }
1834           TYPE_CONTEXT (type) = DECL_CONTEXT (d);
1835           if (newdecl)
1836             DECL_ASSEMBLER_NAME (d)
1837               = get_identifier (build_overload_name (type, 1, 1));
1838         }
1839       if (b->parm_flag == 2)
1840         {
1841           TREE_NONLOCAL_FLAG (type) = 1;
1842           if (TYPE_SIZE (current_class_type) == NULL_TREE)
1843             CLASSTYPE_TAGS (current_class_type) = b->tags;
1844         }
1845     }
1846
1847   if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1848     /* Use the canonical TYPE_DECL for this node.  */
1849     TYPE_STUB_DECL (type) = TYPE_NAME (type);
1850   else
1851     {
1852       /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
1853          will be the tagged type we just added to the current
1854          binding level.  This fake NULL-named TYPE_DECL node helps
1855          dwarfout.c to know when it needs to output a
1856          representation of a tagged type, and it also gives us a
1857          convenient place to record the "scope start" address for
1858          the tagged type.  */
1859
1860 #if 0 /* not yet, should get fixed properly later */
1861       tree d = make_type_decl (NULL_TREE, type);
1862 #else
1863       tree d = build_decl (TYPE_DECL, NULL_TREE, type);
1864 #endif
1865       TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
1866     }
1867 }
1868
1869 /* Counter used to create anonymous type names.  */
1870 static int anon_cnt = 0;
1871
1872 /* Return an IDENTIFIER which can be used as a name for
1873    anonymous structs and unions.  */
1874 tree
1875 make_anon_name ()
1876 {
1877   char buf[32];
1878
1879   sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
1880   return get_identifier (buf);
1881 }
1882
1883 /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
1884    This keeps dbxout from getting confused.  */
1885 void
1886 clear_anon_tags ()
1887 {
1888   register struct binding_level *b;
1889   register tree tags;
1890   static int last_cnt = 0;
1891
1892   /* Fast out if no new anon names were declared.  */
1893   if (last_cnt == anon_cnt)
1894     return;
1895
1896   b = current_binding_level;
1897   while (b->tag_transparent)
1898     b = b->level_chain;
1899   tags = b->tags;
1900   while (tags)
1901     {
1902       /* A NULL purpose means we have already processed all tags
1903          from here to the end of the list.  */
1904       if (TREE_PURPOSE (tags) == NULL_TREE)
1905         break;
1906       if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
1907         TREE_PURPOSE (tags) = NULL_TREE;
1908       tags = TREE_CHAIN (tags);
1909     }
1910   last_cnt = anon_cnt;
1911 }
1912 \f
1913 /* Subroutine of duplicate_decls: return truthvalue of whether
1914    or not types of these decls match.
1915
1916    For C++, we must compare the parameter list so that `int' can match
1917    `int&' in a parameter position, but `int&' is not confused with
1918    `const int&'.  */
1919 static int
1920 decls_match (newdecl, olddecl)
1921      tree newdecl, olddecl;
1922 {
1923   int types_match;
1924
1925   if (TREE_CODE (newdecl) == FUNCTION_DECL && TREE_CODE (olddecl) == FUNCTION_DECL)
1926     {
1927       tree f1 = TREE_TYPE (newdecl);
1928       tree f2 = TREE_TYPE (olddecl);
1929       tree p1 = TYPE_ARG_TYPES (f1);
1930       tree p2 = TYPE_ARG_TYPES (f2);
1931
1932       /* When we parse a static member function definition,
1933          we put together a FUNCTION_DECL which thinks its type
1934          is METHOD_TYPE.  Change that to FUNCTION_TYPE, and
1935          proceed.  */
1936       if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
1937         revert_static_member_fn (&f1, &newdecl, &p1);
1938       else if (TREE_CODE (f2) == METHOD_TYPE
1939                && DECL_STATIC_FUNCTION_P (newdecl))
1940         revert_static_member_fn (&f2, &olddecl, &p2);
1941
1942       /* Here we must take care of the case where new default
1943          parameters are specified.  Also, warn if an old
1944          declaration becomes ambiguous because default
1945          parameters may cause the two to be ambiguous.  */
1946       if (TREE_CODE (f1) != TREE_CODE (f2))
1947         {
1948           if (TREE_CODE (f1) == OFFSET_TYPE)
1949             cp_compiler_error ("`%D' redeclared as member function", newdecl);
1950           else
1951             cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
1952           return 0;
1953         }
1954
1955       if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (f1)),
1956                      TYPE_MAIN_VARIANT (TREE_TYPE (f2)), 2))
1957         types_match = compparms (p1, p2, 2);
1958       else
1959         types_match = 0;
1960     }
1961   else
1962     {
1963       if (TREE_TYPE (newdecl) == error_mark_node)
1964         types_match = TREE_TYPE (olddecl) == error_mark_node;
1965       else if (TREE_TYPE (olddecl) == NULL_TREE)
1966         types_match = TREE_TYPE (newdecl) == NULL_TREE;
1967       else
1968         types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
1969     }
1970
1971   return types_match;
1972 }
1973
1974 /* If NEWDECL is `static' and an `extern' was seen previously,
1975    warn about it.  (OLDDECL may be NULL_TREE; NAME contains
1976    information about previous usage as an `extern'.)
1977
1978    Note that this does not apply to the C++ case of declaring
1979    a variable `extern const' and then later `const'.
1980
1981    Don't complain if -traditional, since traditional compilers
1982    don't complain.
1983
1984    Don't complain about built-in functions, since they are beyond
1985    the user's control.  */
1986
1987 static void
1988 warn_extern_redeclared_static (newdecl, olddecl)
1989      tree newdecl, olddecl;
1990 {
1991   tree name;
1992
1993   static char *explicit_extern_static_warning
1994     = "`%D' was declared `extern' and later `static'";
1995   static char *implicit_extern_static_warning
1996     = "`%D' was declared implicitly `extern' and later `static'";
1997
1998   if (flag_traditional
1999       || TREE_CODE (newdecl) == TYPE_DECL
2000       || (! warn_extern_inline
2001           && DECL_INLINE (newdecl)))
2002     return;
2003
2004   name = DECL_ASSEMBLER_NAME (newdecl);
2005   if (TREE_PUBLIC (name) && ! TREE_PUBLIC (newdecl))
2006     {
2007       /* It's okay to redeclare an ANSI built-in function as static,
2008          or to declare a non-ANSI built-in function as anything.  */
2009       if (! (TREE_CODE (newdecl) == FUNCTION_DECL
2010              && olddecl != NULL_TREE
2011              && TREE_CODE (olddecl) == FUNCTION_DECL
2012              && (DECL_BUILT_IN (olddecl)
2013                  || DECL_BUILT_IN_NONANSI (olddecl))))
2014         {
2015           cp_warning (IDENTIFIER_IMPLICIT_DECL (name)
2016                       ? implicit_extern_static_warning
2017                       : explicit_extern_static_warning, newdecl);
2018           if (olddecl != NULL_TREE)
2019             cp_warning_at ("previous declaration of `%D'", olddecl);
2020         }
2021     }
2022 }
2023
2024 /* Handle when a new declaration NEWDECL has the same name as an old
2025    one OLDDECL in the same binding contour.  Prints an error message
2026    if appropriate.
2027
2028    If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
2029    Otherwise, return 0.  */
2030
2031 static int
2032 duplicate_decls (newdecl, olddecl)
2033      register tree newdecl, olddecl;
2034 {
2035   extern struct obstack permanent_obstack;
2036   unsigned olddecl_uid = DECL_UID (olddecl);
2037   int olddecl_friend = 0, types_match = 0;
2038   int new_defines_function;
2039   tree previous_c_decl = NULL_TREE;
2040
2041   if (TREE_CODE (newdecl) == FUNCTION_DECL
2042       && is_overloaded_fn (olddecl))
2043     {
2044       olddecl = get_first_fn (olddecl);
2045
2046       while (olddecl)
2047         {
2048           if (DECL_LANGUAGE (olddecl) == lang_c)
2049             previous_c_decl = olddecl;
2050
2051           /* Redeclaration.  */
2052           if (decls_match (newdecl, olddecl))
2053             {
2054               types_match = 1;
2055               break;
2056             }
2057           /* Ambiguous overload.  */
2058           else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2059                               TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 2))
2060             break;
2061
2062           /* Attempt to define multiple C-binding fns.  */
2063           if (previous_c_decl)
2064             break;
2065           
2066           olddecl = DECL_CHAIN (olddecl);
2067         }
2068       if (!olddecl)
2069         {
2070           /* If we found no match, make this join the other
2071              overloaded decls.  */
2072           DECL_OVERLOADED (newdecl) = 1;
2073           return 1;
2074         }
2075     }
2076   else
2077     types_match = decls_match (newdecl, olddecl);
2078
2079   if (TREE_CODE (olddecl) != TREE_LIST)
2080     olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
2081
2082   /* If either the type of the new decl or the type of the old decl is an
2083      error_mark_node, then that implies that we have already issued an
2084      error (earlier) for some bogus type specification, and in that case,
2085      it is rather pointless to harass the user with yet more error message
2086      about the same declaration, so well just pretent the types match here.  */
2087   if ((TREE_TYPE (newdecl)
2088        && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
2089       || (TREE_TYPE (olddecl)
2090           && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
2091     types_match = 1;
2092
2093   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2094     {
2095       cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
2096       if (TREE_CODE (olddecl) == TREE_LIST)
2097         olddecl = TREE_VALUE (olddecl);
2098       cp_error_at ("previous declaration of `%#D'", olddecl);
2099
2100       /* New decl is completely inconsistent with the old one =>
2101          tell caller to replace the old one.  */
2102
2103       return 0;
2104     }
2105
2106   if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
2107       && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
2108     /* If -traditional, avoid error for redeclaring fcn
2109        after implicit decl.  */
2110     ;
2111   else if (TREE_CODE (olddecl) == FUNCTION_DECL
2112            && (DECL_BUILT_IN (olddecl)
2113                || DECL_BUILT_IN_NONANSI (olddecl)))
2114     {
2115       /* If you declare a built-in or predefined function name as static,
2116          the old definition is overridden,
2117          but optionally warn this was a bad choice of name.  */
2118       if (! TREE_PUBLIC (newdecl))
2119         {
2120           if (warn_shadow)
2121             cp_warning ("shadowing %s function `%#D'",
2122                         DECL_BUILT_IN (olddecl) ? "built-in" : "library",
2123                         newdecl);
2124           /* Discard the old built-in function.  */
2125           return 0;
2126         }
2127       /* Likewise, if the built-in is not ansi, then programs can
2128          override it even globally without an error.  */
2129       else if (! DECL_BUILT_IN (olddecl))
2130         cp_warning ("library function `%#D' declared as non-function",
2131                     newdecl);
2132
2133       if (!types_match)
2134         {
2135           cp_warning ("declaration of `%#D'", newdecl);
2136           cp_warning ("conflicts with built-in declaration `%#D'",
2137                       olddecl);
2138           return 0;
2139         }
2140     }
2141   else if (!types_match && previous_c_decl
2142            && DECL_LANGUAGE (newdecl) == lang_c)
2143     {
2144       cp_error ("declaration of C function `%#D' conflicts with", newdecl);
2145       cp_error_at ("previous declaration `%#D' here", previous_c_decl);
2146     }
2147   else if (!types_match)
2148     {
2149       tree oldtype = TREE_TYPE (olddecl);
2150       tree newtype = TREE_TYPE (newdecl);
2151       int give_error = 0;
2152
2153       /* Already complained about this, so don't do so again.  */
2154       if (current_class_type == NULL_TREE
2155           || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
2156         {
2157           give_error = 1;
2158
2159           /* Since we're doing this before finish_struct can set the
2160              line number on NEWDECL, we just do a regular error here.  */
2161           if (DECL_SOURCE_LINE (newdecl) == 0)
2162             cp_error ("conflicting types for `%#D'", newdecl);
2163           else
2164             cp_error_at ("conflicting types for `%#D'", newdecl);
2165         }
2166
2167       /* Check for function type mismatch
2168          involving an empty arglist vs a nonempty one.  */
2169       if (TREE_CODE (olddecl) == FUNCTION_DECL
2170           && comptypes (TREE_TYPE (oldtype),
2171                         TREE_TYPE (newtype), 1)
2172           && ((TYPE_ARG_TYPES (oldtype) == NULL_TREE
2173                && DECL_INITIAL (olddecl) == NULL_TREE)
2174               || (TYPE_ARG_TYPES (newtype) == NULL_TREE
2175                   && DECL_INITIAL (newdecl) == NULL_TREE)))
2176         {
2177           /* Classify the problem further.  */
2178           register tree t = TYPE_ARG_TYPES (oldtype);
2179
2180           if (t == NULL_TREE)
2181             t = TYPE_ARG_TYPES (newtype);
2182           for (; t; t = TREE_CHAIN (t))
2183             {
2184               register tree type = TREE_VALUE (t);
2185
2186               if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node)
2187                 {
2188                   give_error = 1;
2189                   error ("A parameter list with an ellipsis can't match");
2190                   error ("an empty parameter name list declaration.");
2191                   break;
2192                 }
2193
2194               if (TYPE_MAIN_VARIANT (type) == float_type_node
2195                   || C_PROMOTING_INTEGER_TYPE_P (type))
2196                 {
2197                   give_error = 1;
2198                   error ("An argument type that has a default promotion");
2199                   error ("can't match an empty parameter name list declaration.");
2200                   break;
2201                 }
2202             }
2203         }
2204       if (give_error)
2205         cp_error_at ("previous declaration as `%#D'", olddecl);
2206
2207       /* There is one thing GNU C++ cannot tolerate: a constructor
2208          which takes the type of object being constructed.
2209          Farm that case out here.  */
2210       if (TREE_CODE (newdecl) == FUNCTION_DECL
2211           && DECL_CONSTRUCTOR_P (newdecl))
2212         {
2213           tree tmp = TREE_CHAIN (TYPE_ARG_TYPES (newtype));
2214
2215           if (tmp != NULL_TREE
2216               && (TYPE_MAIN_VARIANT (TREE_VALUE (tmp))
2217                   == TYPE_METHOD_BASETYPE (newtype)))
2218             {
2219               tree parm = TREE_CHAIN (DECL_ARGUMENTS (newdecl));
2220               tree argtypes
2221                 = hash_tree_chain (build_reference_type (TREE_VALUE (tmp)),
2222                                    TREE_CHAIN (tmp));
2223
2224               DECL_ARG_TYPE (parm)
2225                 = TREE_TYPE (parm)
2226                   = TYPE_REFERENCE_TO (TREE_VALUE (tmp));
2227
2228               TREE_TYPE (newdecl) = newtype
2229                 = build_cplus_method_type (TYPE_METHOD_BASETYPE (newtype),
2230                                            TREE_TYPE (newtype), argtypes);
2231               error ("constructor cannot take as argument the type being constructed");
2232               SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl), current_class_type);
2233             }
2234         }
2235     }
2236   else
2237     {
2238       char *errmsg = redeclaration_error_message (newdecl, olddecl);
2239       if (errmsg)
2240         {
2241           error_with_decl (newdecl, errmsg);
2242           if (DECL_NAME (olddecl) != NULL_TREE)
2243             cp_error_at ((DECL_INITIAL (olddecl)
2244                           && current_binding_level == global_binding_level)
2245                          ? "`%#D' previously defined here"
2246                          : "`%#D' previously declared here", olddecl);
2247         }
2248       else if (TREE_CODE (olddecl) == FUNCTION_DECL
2249                && DECL_INITIAL (olddecl) != NULL_TREE
2250                && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
2251                && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
2252         {
2253           /* Prototype decl follows defn w/o prototype.  */
2254           cp_warning_at ("prototype for `%#D'", newdecl);
2255           cp_warning_at ("follows non-prototype definition here", olddecl);
2256         }
2257       else if (TREE_CODE (olddecl) == FUNCTION_DECL
2258                && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2259         /* extern "C" int foo ();
2260            int foo () { bar (); }
2261            is OK.  */
2262         if (current_lang_stack == current_lang_base)
2263           DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2264         else
2265           {
2266             cp_error_at ("previous declaration of `%#D' with %L linkage",
2267                          olddecl, DECL_LANGUAGE (olddecl));
2268             cp_error ("conflicts with new declaration with %L linkage",
2269                       DECL_LANGUAGE (newdecl));
2270           }
2271
2272       /* These bits are logically part of the type.  */
2273       if (pedantic
2274           && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
2275               || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
2276         cp_error_at ("type qualifiers for `%D' conflict with previous decl", newdecl);
2277     }
2278
2279   /* If new decl is `static' and an `extern' was seen previously,
2280      warn about it.  */
2281   warn_extern_redeclared_static (newdecl, olddecl);
2282
2283   /* We have committed to returning 1 at this point. */
2284   if (TREE_CODE (newdecl) == FUNCTION_DECL)
2285     {
2286       /* Now that functions must hold information normally held
2287          by field decls, there is extra work to do so that
2288          declaration information does not get destroyed during
2289          definition.  */
2290       if (DECL_VINDEX (olddecl))
2291         DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2292       if (DECL_CONTEXT (olddecl))
2293         DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2294       if (DECL_CLASS_CONTEXT (olddecl))
2295         DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
2296       if (DECL_CHAIN (newdecl) == NULL_TREE)
2297         DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2298       if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
2299         DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
2300     }
2301
2302   /* Deal with C++: must preserve virtual function table size.  */
2303   if (TREE_CODE (olddecl) == TYPE_DECL)
2304     {
2305       register tree newtype = TREE_TYPE (newdecl);
2306       register tree oldtype = TREE_TYPE (olddecl);
2307
2308       if (newtype != error_mark_node && oldtype != error_mark_node
2309           && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2310         {
2311           CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
2312           CLASSTYPE_FRIEND_CLASSES (newtype)
2313             = CLASSTYPE_FRIEND_CLASSES (oldtype);
2314         }
2315       /* why assert here?  Just because debugging information is
2316          messed up? (mrs) */
2317       /* it happens on something like:
2318                 typedef struct Thing {
2319                         Thing();
2320                         int     x;
2321                 } Thing;
2322       */
2323 #if 0
2324       my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl), 139);
2325 #endif
2326     }
2327
2328   /* Special handling ensues if new decl is a function definition.  */
2329   new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
2330                           && DECL_INITIAL (newdecl) != NULL_TREE);
2331
2332   /* Optionally warn about more than one declaration for the same name,
2333      but don't warn about a function declaration followed by a definition.  */
2334   if (warn_redundant_decls
2335       && DECL_SOURCE_LINE (olddecl) != 0
2336       && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2337       /* Don't warn about extern decl followed by (tentative) definition.  */
2338       && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
2339     {
2340       cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
2341       cp_warning ("previous declaration of `%D'", olddecl);
2342     }
2343
2344   /* Copy all the DECL_... slots specified in the new decl
2345      except for any that we copy here from the old type.  */
2346
2347   if (types_match)
2348     {
2349       /* Automatically handles default parameters.  */
2350       tree oldtype = TREE_TYPE (olddecl);
2351       /* Merge the data types specified in the two decls.  */
2352       tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2353
2354       if (TREE_CODE (newdecl) == VAR_DECL)
2355         DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2356       /* Do this after calling `common_type' so that default
2357          parameters don't confuse us.  */
2358       else if (TREE_CODE (newdecl) == FUNCTION_DECL
2359           && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
2360               != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
2361         {
2362           tree ctype = NULL_TREE;
2363           ctype = DECL_CLASS_CONTEXT (newdecl);
2364           TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype,
2365                                                          TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
2366           TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype,
2367                                                          TYPE_RAISES_EXCEPTIONS (oldtype));
2368
2369           if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE(olddecl), 0))
2370             {
2371               cp_error ("declaration of `%D' raises different exceptions...", newdecl);
2372               cp_error_at ("...from previous declaration here", olddecl);
2373             }
2374         }
2375       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2376
2377       /* Lay the type out, unless already done.  */
2378       if (oldtype != TREE_TYPE (newdecl))
2379         {
2380           if (TREE_TYPE (newdecl) != error_mark_node)
2381             layout_type (TREE_TYPE (newdecl));
2382           if (TREE_CODE (newdecl) != FUNCTION_DECL
2383               && TREE_CODE (newdecl) != TYPE_DECL
2384               && TREE_CODE (newdecl) != CONST_DECL)
2385             layout_decl (newdecl, 0);
2386         }
2387       else
2388         {
2389           /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
2390           DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
2391         }
2392
2393       /* Merge the type qualifiers.  */
2394       if (TREE_READONLY (newdecl))
2395         TREE_READONLY (olddecl) = 1;
2396       if (TREE_THIS_VOLATILE (newdecl))
2397         TREE_THIS_VOLATILE (olddecl) = 1;
2398
2399       /* Merge the initialization information.  */
2400       if (DECL_INITIAL (newdecl) == NULL_TREE)
2401         DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2402       /* Keep the old rtl since we can safely use it, unless it's the
2403          call to abort() used for abstract virtuals.  */
2404       if ((DECL_LANG_SPECIFIC (olddecl)
2405            && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
2406           || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
2407         DECL_RTL (newdecl) = DECL_RTL (olddecl);
2408     }
2409   /* If cannot merge, then use the new type and qualifiers,
2410      and don't preserve the old rtl.  */
2411   else
2412     {
2413       /* Clean out any memory we had of the old declaration.  */
2414       tree oldstatic = value_member (olddecl, static_aggregates);
2415       if (oldstatic)
2416         TREE_VALUE (oldstatic) = error_mark_node;
2417
2418       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2419       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2420       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2421       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2422     }
2423
2424   /* Merge the storage class information.  */
2425   if (DECL_EXTERNAL (newdecl))
2426     {
2427       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
2428       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
2429
2430       /* For functions, static overrides non-static.  */
2431       if (TREE_CODE (newdecl) == FUNCTION_DECL)
2432         {
2433           TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
2434           /* This is since we don't automatically
2435              copy the attributes of NEWDECL into OLDDECL.  */
2436           TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2437           /* If this clears `static', clear it in the identifier too.  */
2438           if (! TREE_PUBLIC (olddecl))
2439             TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl)) = 0;
2440         }
2441       else
2442         TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2443     }
2444   else
2445     {
2446       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
2447       /* A `const' which was not declared `extern' and is
2448          in static storage is invisible.  */
2449       if (TREE_CODE (newdecl) == VAR_DECL
2450           && TREE_READONLY (newdecl) && TREE_STATIC (newdecl)
2451           && ! DECL_THIS_EXTERN (newdecl))
2452         TREE_PUBLIC (newdecl) = 0;
2453       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2454     }
2455
2456   /* If either decl says `inline', this fn is inline,
2457      unless its definition was passed already.  */
2458   if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
2459     DECL_INLINE (olddecl) = 1;
2460   DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
2461
2462   if (TREE_CODE (newdecl) == FUNCTION_DECL)
2463     {
2464       if (new_defines_function)
2465         /* If defining a function declared with other language
2466            linkage, use the previously declared language linkage.  */
2467         DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2468       else
2469         {
2470           /* If redeclaring a builtin function, and not a definition,
2471              it stays built in.  */
2472           if (DECL_BUILT_IN (olddecl))
2473             {
2474               DECL_BUILT_IN (newdecl) = 1;
2475               DECL_SET_FUNCTION_CODE (newdecl, DECL_FUNCTION_CODE (olddecl));
2476               /* If we're keeping the built-in definition, keep the rtl,
2477                  regardless of declaration matches.  */
2478               DECL_RTL (newdecl) = DECL_RTL (olddecl);
2479             }
2480           else
2481             DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2482
2483           DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2484           if (DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))
2485             /* Previously saved insns go together with
2486                the function's previous definition.  */
2487             DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2488           /* Don't clear out the arguments if we're redefining a function.  */
2489           if (DECL_ARGUMENTS (olddecl))
2490             DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2491         }
2492     }
2493
2494   /* Now preserve various other info from the definition.  */
2495   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2496   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2497   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2498
2499   /* Don't really know how much of the language-specific
2500      values we should copy from old to new.  */
2501   if (DECL_LANG_SPECIFIC (olddecl))
2502     {
2503       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
2504       DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
2505     }
2506
2507   if (TREE_CODE (newdecl) == FUNCTION_DECL)
2508     {
2509       int function_size;
2510       struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
2511       struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
2512
2513       function_size = sizeof (struct tree_decl);
2514
2515       bcopy ((char *) newdecl + sizeof (struct tree_common),
2516              (char *) olddecl + sizeof (struct tree_common),
2517              function_size - sizeof (struct tree_common));
2518
2519       /* Can we safely free the storage used by newdecl?  */
2520
2521 #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
2522                   & ~ obstack_alignment_mask (&permanent_obstack))
2523
2524       if ((char *)newdecl + ROUND (function_size)
2525           + ROUND (sizeof (struct lang_decl))
2526           == obstack_next_free (&permanent_obstack))
2527         {
2528           DECL_MAIN_VARIANT (newdecl) = olddecl;
2529           DECL_LANG_SPECIFIC (olddecl) = ol;
2530           bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
2531
2532           obstack_free (&permanent_obstack, newdecl);
2533         }
2534       else if (LANG_DECL_PERMANENT (ol))
2535         {
2536           if (DECL_MAIN_VARIANT (olddecl) == olddecl)
2537             {
2538               /* Save these lang_decls that would otherwise be lost.  */
2539               extern tree free_lang_decl_chain;
2540               tree free_lang_decl = (tree) ol;
2541               TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
2542               free_lang_decl_chain = free_lang_decl;
2543             }
2544           else
2545             {
2546               /* Storage leak.  */
2547             }
2548         }
2549     }
2550   else
2551     {
2552       bcopy ((char *) newdecl + sizeof (struct tree_common),
2553              (char *) olddecl + sizeof (struct tree_common),
2554              sizeof (struct tree_decl) - sizeof (struct tree_common)
2555              + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
2556     }
2557
2558   DECL_UID (olddecl) = olddecl_uid;
2559   if (olddecl_friend)
2560     DECL_FRIEND_P (olddecl) = 1;
2561
2562   return 1;
2563 }
2564
2565 /* Record a decl-node X as belonging to the current lexical scope.
2566    Check for errors (such as an incompatible declaration for the same
2567    name already seen in the same scope).
2568
2569    Returns either X or an old decl for the same name.
2570    If an old decl is returned, it may have been smashed
2571    to agree with what X says.  */
2572
2573 tree
2574 pushdecl (x)
2575      tree x;
2576 {
2577   register tree t;
2578 #if 0 /* not yet, should get fixed properly later */
2579   register tree name;
2580 #else
2581   register tree name = DECL_ASSEMBLER_NAME (x);
2582 #endif
2583   register struct binding_level *b = current_binding_level;
2584
2585 #if 0
2586   static int nglobals; int len;
2587
2588   len = list_length (global_binding_level->names);
2589   if (len < nglobals)
2590     my_friendly_abort (8);
2591   else if (len > nglobals)
2592     nglobals = len;
2593 #endif
2594
2595   /* Don't change DECL_CONTEXT of virtual methods.  */
2596   if (x != current_function_decl
2597       && (TREE_CODE (x) != FUNCTION_DECL
2598           || !DECL_VIRTUAL_P (x))
2599       && ! DECL_CONTEXT (x))
2600     DECL_CONTEXT (x) = current_function_decl;
2601   /* A local declaration for a function doesn't constitute nesting.  */
2602   if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
2603     DECL_CONTEXT (x) = 0;
2604
2605 #if 0 /* not yet, should get fixed properly later */
2606   /* For functions and class static data, we currently look up the encoded
2607      form of the name.  For types, we want the real name.  The former will
2608      probably be changed soon, according to MDT.  */
2609   if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
2610     name = DECL_ASSEMBLER_NAME (x);
2611   else
2612     name = DECL_NAME (x);
2613 #else
2614   /* Type are looked up using the DECL_NAME, as that is what the rest of the
2615      compiler wants to use. */
2616   if (TREE_CODE (x) == TYPE_DECL)
2617     name = DECL_NAME (x);
2618 #endif
2619
2620   if (name)
2621     {
2622       char *file;
2623       int line;
2624
2625       t = lookup_name_current_level (name);
2626       if (t == error_mark_node)
2627         {
2628           /* error_mark_node is 0 for a while during initialization!  */
2629           t = NULL_TREE;
2630           cp_error_at ("`%#D' used prior to declaration", x);
2631         }
2632
2633       if (t != NULL_TREE)
2634         {
2635           if (TREE_CODE (t) == PARM_DECL)
2636             {
2637               if (DECL_CONTEXT (t) == NULL_TREE)
2638                 fatal ("parse errors have confused me too much");
2639             }
2640           file = DECL_SOURCE_FILE (t);
2641           line = DECL_SOURCE_LINE (t);
2642         }
2643
2644       if (t != NULL_TREE
2645           && (TREE_CODE (t) != TREE_CODE (x) || is_overloaded_fn (t)))
2646         {
2647           if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (x) == TYPE_DECL)
2648             {
2649               /* We do nothing special here, because C++ does such nasty
2650                  things with TYPE_DECLs.  Instead, just let the TYPE_DECL
2651                  get shadowed, and know that if we need to find a TYPE_DECL
2652                  for a given name, we can look in the IDENTIFIER_TYPE_VALUE
2653                  slot of the identifier.  */
2654               ;
2655             }
2656           else if (duplicate_decls (x, t))
2657             return t;
2658         }
2659       else if (t != NULL_TREE && duplicate_decls (x, t))
2660         {
2661 #if 0
2662           /* This is turned off until I have time to do it right (bpk).  */
2663
2664           /* Also warn if they did a prototype with `static' on it, but
2665              then later left the `static' off.  */
2666           else if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
2667             {
2668               if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
2669                 return t;
2670
2671               if (extra_warnings)
2672                 {
2673                   cp_warning ("`static' missing from declaration of `%D'", t);
2674                   warning_with_file_and_line (file, line,
2675                                               "previous declaration of `%s'",
2676                                               decl_as_string (t, 0));
2677                 }
2678
2679               /* Now fix things so it'll do what they expect.  */
2680               if (current_function_decl)
2681                 TREE_PUBLIC (current_function_decl) = 0;
2682             }
2683 #endif
2684
2685           /* Due to interference in memory reclamation (X may be
2686              obstack-deallocated at this point), we must guard against
2687              one really special case.  */
2688           if (current_function_decl == x)
2689             current_function_decl = t;
2690
2691           return t;
2692         }
2693
2694       /* If declaring a type as a typedef, and the type has no known
2695          typedef name, install this TYPE_DECL as its typedef name.  */
2696       if (TREE_CODE (x) == TYPE_DECL)
2697         {
2698           tree type = TREE_TYPE (x);
2699           tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
2700
2701           if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
2702             {
2703               /* If these are different names, and we're at the global
2704                  binding level, make two equivalent definitions.  */
2705               name = x;
2706               if (global_bindings_p ())
2707                 TYPE_NAME (type) = x;
2708             }
2709           else
2710             {
2711               tree tname = DECL_NAME (name);
2712
2713               if (global_bindings_p () && ANON_AGGRNAME_P (tname))
2714                 {
2715                   /* do gratuitous C++ typedefing, and make sure that
2716                      we access this type either through TREE_TYPE field
2717                      or via the tags list.  */
2718                   TYPE_NAME (TREE_TYPE (x)) = x;
2719                   pushtag (tname, TREE_TYPE (x), 0);
2720                 }
2721             }
2722           my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
2723
2724           if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name))
2725             set_nested_typename (x, current_class_name,
2726                                  DECL_NAME (name), type);
2727
2728           if (type != error_mark_node
2729               && TYPE_NAME (type)
2730               && TYPE_IDENTIFIER (type))
2731             set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
2732         }
2733
2734       /* Multiple external decls of the same identifier ought to match.
2735
2736          We get warnings about inline functions where they are defined.
2737          Avoid duplicate warnings where they are used.  */
2738       if (TREE_PUBLIC (x) && !DECL_INLINE (x))
2739         {
2740           tree decl;
2741
2742           if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
2743               && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
2744                   || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
2745             decl = IDENTIFIER_GLOBAL_VALUE (name);
2746           else
2747             decl = NULL_TREE;
2748
2749           if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1)
2750               /* If different sort of thing, we already gave an error.  */
2751               && TREE_CODE (decl) == TREE_CODE (x)
2752               /* If old decl is built-in, we already warned if we should.  */
2753               && !DECL_BUILT_IN (decl))
2754             {
2755               cp_pedwarn ("type mismatch with previous external decl", x);
2756               cp_pedwarn_at ("previous external decl of `%D'", decl);
2757             }
2758         }
2759
2760       /* In PCC-compatibility mode, extern decls of vars with no current decl
2761          take effect at top level no matter where they are.  */
2762       if (flag_traditional && DECL_EXTERNAL (x)
2763           && lookup_name (name, 0) == NULL_TREE)
2764         b = global_binding_level;
2765
2766       /* This name is new in its binding level.
2767          Install the new declaration and return it.  */
2768       if (b == global_binding_level)
2769         {
2770           /* Install a global value.  */
2771
2772           /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
2773              A `const' which was not declared `extern' is invisible.  */
2774           if (TREE_CODE (x) == VAR_DECL
2775               && TREE_READONLY (x) && ! DECL_THIS_EXTERN (x))
2776             TREE_PUBLIC (x) = 0;
2777
2778           /* If the first global decl has external linkage,
2779              warn if we later see static one.  */
2780           if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x))
2781             TREE_PUBLIC (name) = 1;
2782
2783           /* Don't install a TYPE_DECL if we already have another
2784              sort of _DECL with that name.  */
2785           if (TREE_CODE (x) != TYPE_DECL
2786               || t == NULL_TREE
2787               || TREE_CODE (t) == TYPE_DECL)
2788             IDENTIFIER_GLOBAL_VALUE (name) = x;
2789
2790           /* Don't forget if the function was used via an implicit decl.  */
2791           if (IDENTIFIER_IMPLICIT_DECL (name)
2792               && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
2793             TREE_USED (x) = 1;
2794
2795           /* Don't forget if its address was taken in that way.  */
2796           if (IDENTIFIER_IMPLICIT_DECL (name)
2797               && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
2798             TREE_ADDRESSABLE (x) = 1;
2799
2800           /* Warn about mismatches against previous implicit decl.  */
2801           if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
2802               /* If this real decl matches the implicit, don't complain.  */
2803               && ! (TREE_CODE (x) == FUNCTION_DECL
2804                     && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
2805             cp_warning
2806               ("`%D' was previously implicitly declared to return `int'", x);
2807
2808           /* If new decl is `static' and an `extern' was seen previously,
2809              warn about it.  */
2810           warn_extern_redeclared_static (x, t);
2811         }
2812       else
2813         {
2814           /* Here to install a non-global value.  */
2815           tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
2816           tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
2817
2818           b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2819           IDENTIFIER_LOCAL_VALUE (name) = x;
2820
2821           /* If this is a TYPE_DECL, push it into the type value slot.  */
2822           if (TREE_CODE (x) == TYPE_DECL)
2823             set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
2824
2825           /* If this is an extern function declaration, see if we
2826              have a global definition or declaration for the function.  */
2827           if (oldlocal == NULL_TREE
2828               && DECL_EXTERNAL (x) && !DECL_INLINE (x)
2829               && oldglobal != NULL_TREE
2830               && TREE_CODE (x) == FUNCTION_DECL
2831               && TREE_CODE (oldglobal) == FUNCTION_DECL)
2832             {
2833               /* We have one.  Their types must agree.  */
2834               if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1))
2835                 {
2836                   cp_warning ("extern declaration of `%#D' doesn't match", x);
2837                   cp_warning_at ("global declaration `%#D'", oldglobal);
2838                 }
2839               else
2840                 {
2841                   /* Inner extern decl is inline if global one is.
2842                      Copy enough to really inline it.  */
2843                   if (DECL_INLINE (oldglobal))
2844                     {
2845                       DECL_INLINE (x) = DECL_INLINE (oldglobal);
2846                       DECL_INITIAL (x) = (current_function_decl == oldglobal
2847                                           ? NULL_TREE : DECL_INITIAL (oldglobal));
2848                       DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
2849                       DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal);
2850                       DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
2851                       DECL_RESULT (x) = DECL_RESULT (oldglobal);
2852                       TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
2853                       DECL_ABSTRACT_ORIGIN (x) = oldglobal;
2854                     }
2855                   /* Inner extern decl is built-in if global one is.  */
2856                   if (DECL_BUILT_IN (oldglobal))
2857                     {
2858                       DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal);
2859                       DECL_SET_FUNCTION_CODE (x, DECL_FUNCTION_CODE (oldglobal));
2860                     }
2861                   /* Keep the arg types from a file-scope fcn defn.  */
2862                   if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != NULL_TREE
2863                       && DECL_INITIAL (oldglobal)
2864                       && TYPE_ARG_TYPES (TREE_TYPE (x)) == NULL_TREE)
2865                     TREE_TYPE (x) = TREE_TYPE (oldglobal);
2866                 }
2867             }
2868           /* If we have a local external declaration,
2869              and no file-scope declaration has yet been seen,
2870              then if we later have a file-scope decl it must not be static.  */
2871           if (oldlocal == NULL_TREE
2872               && oldglobal == NULL_TREE
2873               && DECL_EXTERNAL (x)
2874               && TREE_PUBLIC (x))
2875             {
2876               TREE_PUBLIC (name) = 1;
2877             }
2878
2879           if (DECL_FROM_INLINE (x))
2880             /* Inline decls shadow nothing.  */;
2881
2882           /* Warn if shadowing an argument at the top level of the body.  */
2883           else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
2884               && TREE_CODE (oldlocal) == PARM_DECL
2885               && TREE_CODE (x) != PARM_DECL)
2886             {
2887               /* Go to where the parms should be and see if we
2888                  find them there.  */
2889               struct binding_level *b = current_binding_level->level_chain;
2890
2891               if (cleanup_label)
2892                 b = b->level_chain;
2893
2894               /* ARM $8.3 */
2895               if (b->parm_flag == 1)
2896                 cp_error ("declaration of `%#D' shadows a parameter", name);
2897             }
2898           /* Maybe warn if shadowing something else.  */
2899           else if (warn_shadow && !DECL_EXTERNAL (x)
2900                    /* No shadow warnings for internally generated vars.  */
2901                    && DECL_SOURCE_LINE (x) != 0
2902                    /* No shadow warnings for vars made for inlining.  */
2903                    && ! DECL_FROM_INLINE (x))
2904             {
2905               char *warnstring = NULL;
2906
2907               if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
2908                 warnstring = "declaration of `%s' shadows a parameter";
2909               else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
2910                        && !TREE_STATIC (name))
2911                 warnstring = "declaration of `%s' shadows a member of `this'";
2912               else if (oldlocal != NULL_TREE)
2913                 warnstring = "declaration of `%s' shadows previous local";
2914               else if (oldglobal != NULL_TREE)
2915                 warnstring = "declaration of `%s' shadows global declaration";
2916
2917               if (warnstring)
2918                 warning (warnstring, IDENTIFIER_POINTER (name));
2919             }
2920
2921           /* If storing a local value, there may already be one (inherited).
2922              If so, record it for restoration when this binding level ends.  */
2923           if (oldlocal != NULL_TREE)
2924             b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2925         }
2926
2927       /* Keep count of variables in this level with incomplete type.  */
2928       if (TREE_CODE (x) != TEMPLATE_DECL
2929           && TREE_CODE (x) != CPLUS_CATCH_DECL
2930           && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
2931           && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
2932         {
2933           if (++b->n_incomplete == 0)
2934             error ("too many incomplete variables at this point");
2935         }
2936     }
2937
2938   if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE)
2939     {
2940       if (current_class_name)
2941         {
2942           if (!DECL_NESTED_TYPENAME (x))
2943             set_nested_typename (x, current_class_name, DECL_NAME (x),
2944                                  TREE_TYPE (x));
2945         }
2946     }
2947
2948   /* Put decls on list in reverse order.
2949      We will reverse them later if necessary.  */
2950   TREE_CHAIN (x) = b->names;
2951   b->names = x;
2952   if (! (b != global_binding_level || TREE_PERMANENT (x)))
2953     my_friendly_abort (124);
2954
2955   return x;
2956 }
2957
2958 /* Same as pushdecl, but define X in binding-level LEVEL. */
2959
2960 static tree
2961 pushdecl_with_scope (x, level)
2962      tree x;
2963      struct binding_level *level;
2964 {
2965   register struct binding_level *b = current_binding_level;
2966
2967   current_binding_level = level;
2968   x = pushdecl (x);
2969   current_binding_level = b;
2970   return x;
2971 }
2972
2973 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
2974    if appropriate.  */
2975 tree
2976 pushdecl_top_level (x)
2977      tree x;
2978 {
2979   register struct binding_level *b = inner_binding_level;
2980   register tree t = pushdecl_with_scope (x, global_binding_level);
2981
2982   /* Now, the type_shadowed stack may screw us.  Munge it so it does
2983      what we want.  */
2984   if (TREE_CODE (x) == TYPE_DECL)
2985     {
2986       tree name = DECL_NAME (x);
2987       tree newval;
2988       tree *ptr = (tree *)0;
2989       for (; b != global_binding_level; b = b->level_chain)
2990         {
2991           tree shadowed = b->type_shadowed;
2992           for (; shadowed; shadowed = TREE_CHAIN (shadowed))
2993             if (TREE_PURPOSE (shadowed) == name)
2994               {
2995                 ptr = &TREE_VALUE (shadowed);
2996                 /* Can't break out of the loop here because sometimes
2997                    a binding level will have duplicate bindings for
2998                    PT names.  It's gross, but I haven't time to fix it.  */
2999               }
3000         }
3001       newval = TREE_TYPE (x);
3002       if (ptr == (tree *)0)
3003         {
3004           /* @@ This shouldn't be needed.  My test case "zstring.cc" trips
3005              up here if this is changed to an assertion.  --KR  */
3006           SET_IDENTIFIER_TYPE_VALUE (name, newval);
3007         }
3008       else
3009         {
3010 #if 0
3011           /* Disabled this 11/10/92, since there are many cases which
3012              behave just fine when *ptr doesn't satisfy either of these.
3013              For example, nested classes declared as friends of their enclosing
3014              class will not meet this criteria.  (bpk) */
3015           my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141);
3016 #endif
3017           *ptr = newval;
3018         }
3019     }
3020   return t;
3021 }
3022
3023 /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
3024    if appropriate.  */
3025 void
3026 push_overloaded_decl_top_level (x, forget)
3027      tree x;
3028      int forget;
3029 {
3030   struct binding_level *b = current_binding_level;
3031
3032   current_binding_level = global_binding_level;
3033   push_overloaded_decl (x, forget);
3034   current_binding_level = b;
3035 }
3036
3037 /* Make the declaration of X appear in CLASS scope.  */
3038 tree
3039 pushdecl_class_level (x)
3040      tree x;
3041 {
3042   /* Don't use DECL_ASSEMBLER_NAME here!  Everything that looks in class
3043      scope looks for the pre-mangled name.  */
3044   register tree name = DECL_NAME (x);
3045
3046   if (name)
3047     {
3048       push_class_level_binding (name, x);
3049       if (TREE_CODE (x) == TYPE_DECL)
3050         {
3051           set_identifier_type_value (name, TREE_TYPE (x));
3052           if (!DECL_NESTED_TYPENAME (x))
3053             set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
3054         }
3055     }
3056   return x;
3057 }
3058
3059 /* Make the declaration(s) of X appear in CLASS scope
3060    under the name NAME.  */
3061 void
3062 push_class_level_binding (name, x)
3063      tree name;
3064      tree x;
3065 {
3066   maybe_push_cache_obstack ();
3067   class_binding_level->class_shadowed
3068       = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
3069                    class_binding_level->class_shadowed);
3070   pop_obstacks ();
3071   IDENTIFIER_CLASS_VALUE (name) = x;
3072   obstack_ptr_grow (&decl_obstack, x);
3073 }
3074
3075 /* Tell caller how to interpret a TREE_LIST which contains
3076    chains of FUNCTION_DECLS.  */
3077 int
3078 overloaded_globals_p (list)
3079      tree list;
3080 {
3081   my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
3082
3083   /* Don't commit caller to seeing them as globals.  */
3084   if (TREE_NONLOCAL_FLAG (list))
3085     return -1;
3086   /* Do commit caller to seeing them as globals.  */
3087   if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
3088     return 1;
3089   /* Do commit caller to not seeing them as globals.  */
3090   return 0;
3091 }
3092
3093 /* DECL is a FUNCTION_DECL which may have other definitions already in place.
3094    We get around this by making IDENTIFIER_GLOBAL_VALUE (DECL_NAME (DECL))
3095    point to a list of all the things that want to be referenced by that name.
3096    It is then up to the users of that name to decide what to do with that
3097    list.
3098
3099    DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
3100    slot.  It is dealt with the same way.
3101
3102    The value returned may be a previous declaration if we guessed wrong
3103    about what language DECL should belong to (C or C++).  Otherwise,
3104    it's always DECL (and never something that's not a _DECL).  */
3105 tree
3106 push_overloaded_decl (decl, forgettable)
3107      tree decl;
3108      int forgettable;
3109 {
3110   tree orig_name = DECL_NAME (decl);
3111   tree glob = IDENTIFIER_GLOBAL_VALUE (orig_name);
3112
3113   DECL_OVERLOADED (decl) = 1;
3114
3115   if (forgettable
3116       && ! flag_traditional
3117       && (glob == NULL_TREE || TREE_PERMANENT (glob) == 1)
3118       && !global_bindings_p ()
3119       && !pseudo_global_level_p ())
3120     overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
3121
3122   if (glob)
3123     {
3124       if (DECL_LANGUAGE (decl) == lang_c)
3125         {
3126           tree decls = get_first_fn (glob);
3127           while (decls && DECL_LANGUAGE (decls) == lang_cplusplus)
3128             decls = DECL_CHAIN (decls);
3129           if (decls)
3130             {
3131               cp_error_at ("C-language function `%#D'", decls);
3132               cp_error ("overloaded as `%#D'", decl);
3133             }
3134         }
3135
3136       /* We cache the value of builtin functions as ADDR_EXPRs
3137          in the name space.  Convert it to some kind of _DECL after
3138          remembering what to forget.  */
3139       if (TREE_CODE (glob) == ADDR_EXPR)
3140         glob = TREE_OPERAND (glob, 0);
3141
3142       else if (TREE_CODE (decl) == TEMPLATE_DECL)
3143         {
3144           tree tmp;
3145
3146           for (tmp = get_first_fn (glob); tmp; tmp = DECL_CHAIN (tmp))
3147             if (decl == tmp)
3148               return decl;
3149         }
3150       else if (TREE_CODE (glob) == VAR_DECL)
3151         {
3152           cp_error_at ("previous non-function declaration `%#D'", glob);
3153           cp_error ("conflicts with function declaration `%#D'", decl);
3154           return error_mark_node;
3155         }
3156       else if (is_overloaded_fn (glob))
3157         {
3158           tree name = DECL_ASSEMBLER_NAME (decl);
3159           tree tmp;
3160           
3161           for (tmp = get_first_fn (glob); tmp; tmp = DECL_CHAIN (tmp))
3162             {
3163               if (TREE_CODE (tmp) == FUNCTION_DECL
3164                   && comptypes (TREE_TYPE (tmp), TREE_TYPE (decl), 2))
3165                 {
3166                   if (DECL_LANGUAGE (tmp) != DECL_LANGUAGE (decl))
3167                     {
3168                       if (current_lang_stack == current_lang_base)
3169                         {
3170                           DECL_LANGUAGE (decl) = DECL_LANGUAGE (tmp);
3171                           return tmp;
3172                         }
3173                       cp_error_at ("previous declaration of `%#D' with %L linkage",
3174                                    tmp, DECL_LANGUAGE (tmp));
3175                       cp_error ("conflicts with new %L-language declaration",
3176                                    DECL_LANGUAGE (decl));
3177                     }
3178                   else if (TREE_CODE (tmp) != TEMPLATE_DECL
3179                            && DECL_ASSEMBLER_NAME (tmp) != name)
3180                     {
3181                       cp_error ("new declaration `%#D'", decl);
3182                       cp_error_at ("ambiguates old declaration `%#D'", tmp);
3183                     }
3184                 }
3185               /* If we really have seen this before, then if it ambiguates
3186                  something, we've already given an error before.  */
3187               if (TREE_CODE (tmp) != TEMPLATE_DECL
3188                   && DECL_ASSEMBLER_NAME (tmp) == name)
3189                 return decl;
3190             }
3191         }
3192     }
3193   if (glob || TREE_CODE (decl) == TEMPLATE_DECL)
3194     {
3195       if (glob && is_overloaded_fn (glob))
3196         DECL_CHAIN (decl) = get_first_fn (glob);
3197       else
3198         DECL_CHAIN (decl) = NULL_TREE;
3199       glob = tree_cons (orig_name, decl, NULL_TREE);
3200       TREE_TYPE (glob) = unknown_type_node;
3201     }
3202   else
3203     /* orig_name is not ambiguous.  */
3204     glob = decl;
3205   
3206   IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
3207   return decl;
3208 }
3209 \f
3210 /* Generate an implicit declaration for identifier FUNCTIONID
3211    as a function of type int ().  Print a warning if appropriate.  */
3212
3213 tree
3214 implicitly_declare (functionid)
3215      tree functionid;
3216 {
3217   register tree decl;
3218   int temp = allocation_temporary_p ();
3219
3220   push_obstacks_nochange ();
3221
3222   /* Save the decl permanently so we can warn if definition follows.
3223      In ANSI C, warn_implicit is usually false, so the saves little space.
3224      But in C++, it's usually true, hence the extra code.  */
3225   if (temp && (flag_traditional || !warn_implicit
3226                || current_binding_level == global_binding_level))
3227     end_temporary_allocation ();
3228
3229   /* We used to reuse an old implicit decl here,
3230      but this loses with inline functions because it can clobber
3231      the saved decl chains.  */
3232   decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
3233
3234   DECL_EXTERNAL (decl) = 1;
3235   TREE_PUBLIC (decl) = 1;
3236
3237   /* ANSI standard says implicit declarations are in the innermost block.
3238      So we record the decl in the standard fashion.
3239      If flag_traditional is set, pushdecl does it top-level.  */
3240   pushdecl (decl);
3241   rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
3242
3243   if (warn_implicit
3244       /* Only one warning per identifier.  */
3245       && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
3246     {
3247       cp_pedwarn ("implicit declaration of function `%#D'", decl);
3248     }
3249
3250   SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
3251
3252   pop_obstacks ();
3253
3254   return decl;
3255 }
3256
3257 /* Return zero if the declaration NEWDECL is valid
3258    when the declaration OLDDECL (assumed to be for the same name)
3259    has already been seen.
3260    Otherwise return an error message format string with a %s
3261    where the identifier should go.  */
3262
3263 static char *
3264 redeclaration_error_message (newdecl, olddecl)
3265      tree newdecl, olddecl;
3266 {
3267   if (TREE_CODE (newdecl) == TYPE_DECL)
3268     {
3269       /* Because C++ can put things into name space for free,
3270          constructs like "typedef struct foo { ... } foo"
3271          would look like an erroneous redeclaration.  */
3272       if (comptypes (newdecl, olddecl, 0))
3273         return 0;
3274       else
3275         return "redefinition of `%s'";
3276     }
3277   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3278     {
3279       /* If this is a pure function, its olddecl will actually be
3280          the original initialization to `0' (which we force to call
3281          abort()).  Don't complain about redefinition in this case.  */
3282       if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
3283         return 0;
3284
3285       /* Declarations of functions can insist on internal linkage
3286          but they can't be inconsistent with internal linkage,
3287          so there can be no error on that account.
3288          However defining the same name twice is no good.  */
3289       if (DECL_INITIAL (olddecl) != NULL_TREE
3290           && DECL_INITIAL (newdecl) != NULL_TREE
3291           /* However, defining once as extern inline and a second
3292              time in another way is ok.  */
3293           && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
3294                && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
3295         {
3296           if (DECL_NAME (olddecl) == NULL_TREE)
3297             return "`%s' not declared in class";
3298           else
3299             return "redefinition of `%s'";
3300         }
3301       return 0;
3302     }
3303   else if (current_binding_level == global_binding_level)
3304     {
3305       /* Objects declared at top level:  */
3306       /* If at least one is a reference, it's ok.  */
3307       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3308         return 0;
3309       /* Reject two definitions.  */
3310       if (DECL_INITIAL (olddecl) != NULL_TREE
3311           && DECL_INITIAL (newdecl) != NULL_TREE)
3312         return "redefinition of `%s'";
3313       /* Now we have two tentative defs, or one tentative and one real def.  */
3314       /* Insist that the linkage match.  */
3315       if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
3316         return "conflicting declarations of `%s'";
3317       return 0;
3318     }
3319   else
3320     {
3321       /* Objects declared with block scope:  */
3322       /* Reject two definitions, and reject a definition
3323          together with an external reference.  */
3324       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3325         return "redeclaration of `%s'";
3326       return 0;
3327     }
3328 }
3329 \f
3330 /* Get the LABEL_DECL corresponding to identifier ID as a label.
3331    Create one if none exists so far for the current function.
3332    This function is called for both label definitions and label references.  */
3333
3334 tree
3335 lookup_label (id)
3336      tree id;
3337 {
3338   register tree decl = IDENTIFIER_LABEL_VALUE (id);
3339
3340   if (current_function_decl == NULL_TREE)
3341     {
3342       error ("label `%s' referenced outside of any function",
3343              IDENTIFIER_POINTER (id));
3344       return NULL_TREE;
3345     }
3346
3347   if ((decl == NULL_TREE
3348       || DECL_SOURCE_LINE (decl) == 0)
3349       && (named_label_uses == NULL_TREE
3350           || TREE_PURPOSE (named_label_uses) != current_binding_level->names
3351           || TREE_VALUE (named_label_uses) != decl))
3352     {
3353       named_label_uses
3354         = tree_cons (current_binding_level->names, decl, named_label_uses);
3355       TREE_TYPE (named_label_uses) = (tree)current_binding_level;
3356     }
3357
3358   /* Use a label already defined or ref'd with this name.  */
3359   if (decl != NULL_TREE)
3360     {
3361       /* But not if it is inherited and wasn't declared to be inheritable.  */
3362       if (DECL_CONTEXT (decl) != current_function_decl
3363           && ! C_DECLARED_LABEL_FLAG (decl))
3364         return shadow_label (id);
3365       return decl;
3366     }
3367
3368   decl = build_decl (LABEL_DECL, id, void_type_node);
3369
3370   /* A label not explicitly declared must be local to where it's ref'd.  */
3371   DECL_CONTEXT (decl) = current_function_decl;
3372
3373   DECL_MODE (decl) = VOIDmode;
3374
3375   /* Say where one reference is to the label,
3376      for the sake of the error if it is not defined.  */
3377   DECL_SOURCE_LINE (decl) = lineno;
3378   DECL_SOURCE_FILE (decl) = input_filename;
3379
3380   SET_IDENTIFIER_LABEL_VALUE (id, decl);
3381
3382   named_labels = tree_cons (NULL_TREE, decl, named_labels);
3383   TREE_VALUE (named_label_uses) = decl;
3384
3385   return decl;
3386 }
3387
3388 /* Make a label named NAME in the current function,
3389    shadowing silently any that may be inherited from containing functions
3390    or containing scopes.
3391
3392    Note that valid use, if the label being shadowed
3393    comes from another scope in the same function,
3394    requires calling declare_nonlocal_label right away.  */
3395
3396 tree
3397 shadow_label (name)
3398      tree name;
3399 {
3400   register tree decl = IDENTIFIER_LABEL_VALUE (name);
3401
3402   if (decl != NULL_TREE)
3403     {
3404       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3405       SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3406       SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
3407     }
3408
3409   return lookup_label (name);
3410 }
3411
3412 /* Define a label, specifying the location in the source file.
3413    Return the LABEL_DECL node for the label, if the definition is valid.
3414    Otherwise return 0.  */
3415
3416 tree
3417 define_label (filename, line, name)
3418      char *filename;
3419      int line;
3420      tree name;
3421 {
3422   tree decl = lookup_label (name);
3423
3424   /* After labels, make any new cleanups go into their
3425      own new (temporary) binding contour.  */
3426   current_binding_level->more_cleanups_ok = 0;
3427
3428   /* If label with this name is known from an outer context, shadow it.  */
3429   if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
3430     {
3431       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3432       SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3433       decl = lookup_label (name);
3434     }
3435
3436   if (DECL_INITIAL (decl) != NULL_TREE)
3437     {
3438       cp_error ("duplicate label `%D'", decl);
3439       return 0;
3440     }
3441   else
3442     {
3443       tree uses, prev;
3444
3445       /* Mark label as having been defined.  */
3446       DECL_INITIAL (decl) = error_mark_node;
3447       /* Say where in the source.  */
3448       DECL_SOURCE_FILE (decl) = filename;
3449       DECL_SOURCE_LINE (decl) = line;
3450
3451       for (prev = NULL_TREE, uses = named_label_uses;
3452            uses;
3453            prev = uses, uses = TREE_CHAIN (uses))
3454         if (TREE_VALUE (uses) == decl)
3455           {
3456             struct binding_level *b = current_binding_level;
3457             while (b)
3458               {
3459                 tree new_decls = b->names;
3460                 tree old_decls = ((tree)b == TREE_TYPE (uses)
3461                                   ? TREE_PURPOSE (uses) : NULL_TREE);
3462                 while (new_decls != old_decls)
3463                   {
3464                     if (TREE_CODE (new_decls) == VAR_DECL
3465                         /* Don't complain about crossing initialization
3466                            of internal entities.  They can't be accessed,
3467                            and they should be cleaned up
3468                            by the time we get to the label.  */
3469                         && DECL_SOURCE_LINE (new_decls) != 0
3470                         && ((DECL_INITIAL (new_decls) != NULL_TREE
3471                              && DECL_INITIAL (new_decls) != error_mark_node)
3472                             || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
3473                       {
3474                         if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE)
3475                           cp_error ("invalid jump to label `%D'", decl);
3476                         SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl);
3477                         cp_error ("crosses initialization of `%D'", new_decls);
3478                       }
3479                     new_decls = TREE_CHAIN (new_decls);
3480                   }
3481                 if ((tree)b == TREE_TYPE (uses))
3482                   break;
3483                 b = b->level_chain;
3484               }
3485
3486             if (prev)
3487               TREE_CHAIN (prev) = TREE_CHAIN (uses);
3488             else
3489               named_label_uses = TREE_CHAIN (uses);
3490           }
3491       current_function_return_value = NULL_TREE;
3492       return decl;
3493     }
3494 }
3495
3496 /* Same, but for CASE labels.  If DECL is NULL_TREE, it's the default.  */
3497 /* XXX Note decl is never actually used. (bpk) */
3498 void
3499 define_case_label (decl)
3500      tree decl;
3501 {
3502   tree cleanup = last_cleanup_this_contour ();
3503   if (cleanup)
3504     {
3505       static int explained = 0;
3506       cp_error_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
3507       error ("where case label appears here");
3508       if (!explained)
3509         {
3510           error ("(enclose actions of previous case statements requiring");
3511           error ("destructors in their own binding contours.)");
3512           explained = 1;
3513         }
3514     }
3515
3516   /* After labels, make any new cleanups go into their
3517      own new (temporary) binding contour.  */
3518
3519   current_binding_level->more_cleanups_ok = 0;
3520   current_function_return_value = NULL_TREE;
3521 }
3522 \f
3523 /* Return the list of declarations of the current level.
3524    Note that this list is in reverse order unless/until
3525    you nreverse it; and when you do nreverse it, you must
3526    store the result back using `storedecls' or you will lose.  */
3527
3528 tree
3529 getdecls ()
3530 {
3531   return current_binding_level->names;
3532 }
3533
3534 /* Return the list of type-tags (for structs, etc) of the current level.  */
3535
3536 tree
3537 gettags ()
3538 {
3539   return current_binding_level->tags;
3540 }
3541
3542 /* Store the list of declarations of the current level.
3543    This is done for the parameter declarations of a function being defined,
3544    after they are modified in the light of any missing parameters.  */
3545
3546 static void
3547 storedecls (decls)
3548      tree decls;
3549 {
3550   current_binding_level->names = decls;
3551 }
3552
3553 /* Similarly, store the list of tags of the current level.  */
3554
3555 static void
3556 storetags (tags)
3557      tree tags;
3558 {
3559   current_binding_level->tags = tags;
3560 }
3561 \f
3562 /* Given NAME, an IDENTIFIER_NODE,
3563    return the structure (or union or enum) definition for that name.
3564    Searches binding levels from BINDING_LEVEL up to the global level.
3565    If THISLEVEL_ONLY is nonzero, searches only the specified context
3566    (but skips any tag-transparent contexts to find one that is
3567    meaningful for tags).
3568    FORM says which kind of type the caller wants;
3569    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
3570    If the wrong kind of type is found, and it's not a template, an error is
3571    reported.  */
3572
3573 static tree
3574 lookup_tag (form, name, binding_level, thislevel_only)
3575      enum tree_code form;
3576      struct binding_level *binding_level;
3577      tree name;
3578      int thislevel_only;
3579 {
3580   register struct binding_level *level;
3581
3582   for (level = binding_level; level; level = level->level_chain)
3583     {
3584       register tree tail;
3585       if (ANON_AGGRNAME_P (name))
3586         for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3587           {
3588             /* There's no need for error checking here, because
3589                anon names are unique throughout the compilation.  */
3590             if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
3591               return TREE_VALUE (tail);
3592           }
3593       else
3594         for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3595           {
3596             if (TREE_PURPOSE (tail) == name)
3597               {
3598                 enum tree_code code = TREE_CODE (TREE_VALUE (tail));
3599                 /* Should tighten this up; it'll probably permit
3600                    UNION_TYPE and a struct template, for example.  */
3601                 if (code != form
3602                     && !(form != ENUMERAL_TYPE
3603                          && (code == TEMPLATE_DECL
3604                              || code == UNINSTANTIATED_P_TYPE)))
3605                            
3606                   {
3607                     /* Definition isn't the kind we were looking for.  */
3608                     cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
3609                               form);
3610                   }
3611                 return TREE_VALUE (tail);
3612               }
3613           }
3614       if (thislevel_only && ! level->tag_transparent)
3615         return NULL_TREE;
3616       if (current_class_type && level->level_chain == global_binding_level)
3617         {
3618           /* Try looking in this class's tags before heading into
3619              global binding level.  */
3620           tree context = current_class_type;
3621           while (context)
3622             {
3623               switch (TREE_CODE_CLASS (TREE_CODE (context)))
3624                 {
3625                 tree these_tags;
3626                 case 't':
3627                     these_tags = CLASSTYPE_TAGS (context);
3628                     if (ANON_AGGRNAME_P (name))
3629                       while (these_tags)
3630                         {
3631                           if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
3632                               == name)
3633                             return TREE_VALUE (tail);
3634                           these_tags = TREE_CHAIN (these_tags);
3635                         }
3636                     else
3637                       while (these_tags)
3638                         {
3639                           if (TREE_PURPOSE (these_tags) == name)
3640                             {
3641                               if (TREE_CODE (TREE_VALUE (these_tags)) != form)
3642                                 {
3643                                   cp_error ("`%#D' redeclared as %C in class scope",
3644                                             TREE_VALUE (tail), form);
3645                                 }
3646                               return TREE_VALUE (tail);
3647                             }
3648                           these_tags = TREE_CHAIN (these_tags);
3649                         }
3650                     /* If this type is not yet complete, then don't
3651                        look at its context.  */
3652                     if (TYPE_SIZE (context) == NULL_TREE)
3653                       goto no_context;
3654                     /* Go to next enclosing type, if any.  */
3655                     context = DECL_CONTEXT (TYPE_NAME (context));
3656                     break;
3657                 case 'd':
3658                     context = DECL_CONTEXT (context);
3659                     break;
3660                 default:
3661                     my_friendly_abort (10);
3662                 }
3663               continue;
3664               no_context:
3665               break;
3666             }
3667         }
3668     }
3669   return NULL_TREE;
3670 }
3671
3672 void
3673 set_current_level_tags_transparency (tags_transparent)
3674      int tags_transparent;
3675 {
3676   current_binding_level->tag_transparent = tags_transparent;
3677 }
3678
3679 /* Given a type, find the tag that was defined for it and return the tag name.
3680    Otherwise return 0.  However, the value can never be 0
3681    in the cases in which this is used.
3682
3683    C++: If NAME is non-zero, this is the new name to install.  This is
3684    done when replacing anonymous tags with real tag names.  */
3685
3686 static tree
3687 lookup_tag_reverse (type, name)
3688      tree type;
3689      tree name;
3690 {
3691   register struct binding_level *level;
3692
3693   for (level = current_binding_level; level; level = level->level_chain)
3694     {
3695       register tree tail;
3696       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3697         {
3698           if (TREE_VALUE (tail) == type)
3699             {
3700               if (name)
3701                 TREE_PURPOSE (tail) = name;
3702               return TREE_PURPOSE (tail);
3703             }
3704         }
3705     }
3706   return NULL_TREE;
3707 }
3708
3709 /* Given type TYPE which was not declared in C++ language context,
3710    attempt to find a name by which it is referred.  */
3711 tree
3712 typedecl_for_tag (tag)
3713      tree tag;
3714 {
3715   struct binding_level *b = current_binding_level;
3716
3717   if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
3718     return TYPE_NAME (tag);
3719
3720   while (b)
3721     {
3722       tree decls = b->names;
3723       while (decls)
3724         {
3725           if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
3726             break;
3727           decls = TREE_CHAIN (decls);
3728         }
3729       if (decls)
3730         return decls;
3731       b = b->level_chain;
3732     }
3733   return NULL_TREE;
3734 }
3735 \f
3736 /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
3737    Return the type value, or NULL_TREE if not found.  */
3738 static tree
3739 lookup_nested_type (type, context)
3740      tree type;
3741      tree context;
3742 {
3743   if (context == NULL_TREE)
3744     return NULL_TREE;
3745   while (context)
3746     {
3747       switch (TREE_CODE (context))
3748         {
3749         case TYPE_DECL:
3750           {
3751             tree ctype = TREE_TYPE (context);
3752             tree match = value_member (type, CLASSTYPE_TAGS (ctype));
3753             if (match)
3754               return TREE_VALUE (match);
3755             context = DECL_CONTEXT (context);
3756
3757             /* When we have a nested class whose member functions have
3758                local types (e.g., a set of enums), we'll arrive here
3759                with the DECL_CONTEXT as the actual RECORD_TYPE node for
3760                the enclosing class.  Instead, we want to make sure we
3761                come back in here with the TYPE_DECL, not the RECORD_TYPE.  */
3762             if (context && TREE_CODE (context) == RECORD_TYPE)
3763               context = TREE_CHAIN (context);
3764           }
3765           break;
3766         case FUNCTION_DECL:
3767           return TYPE_IDENTIFIER (type) ? lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE;
3768           break;
3769         default:
3770           my_friendly_abort (12);
3771         }
3772     }
3773   return NULL_TREE;
3774 }
3775
3776 /* Look up NAME in the current binding level and its superiors in the
3777    namespace of variables, functions and typedefs.  Return a ..._DECL
3778    node of some kind representing its definition if there is only one
3779    such declaration, or return a TREE_LIST with all the overloaded
3780    definitions if there are many, or return 0 if it is undefined.
3781
3782    If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
3783    If PREFER_TYPE is = 0, we prefer non-TYPE_DECLs.
3784    If PREFER_TYPE is < 0, we arbitrate according to lexical context.  */
3785
3786 tree
3787 lookup_name (name, prefer_type)
3788      tree name;
3789      int prefer_type;
3790 {
3791   register tree val;
3792
3793   if (current_binding_level != global_binding_level
3794       && IDENTIFIER_LOCAL_VALUE (name))
3795     val = IDENTIFIER_LOCAL_VALUE (name);
3796   /* In C++ class fields are between local and global scope,
3797      just before the global scope.  */
3798   else if (current_class_type)
3799     {
3800       val = IDENTIFIER_CLASS_VALUE (name);
3801       if (val == NULL_TREE
3802           && TYPE_SIZE (current_class_type) == NULL_TREE
3803           && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
3804         {
3805           /* Try to find values from base classes
3806              if we are presently defining a type.
3807              We are presently only interested in TYPE_DECLs.  */
3808           val = lookup_field (current_class_type, name, 0, prefer_type < 0);
3809           if (val == error_mark_node)
3810             return val;
3811           if (val && TREE_CODE (val) != TYPE_DECL)
3812             val = NULL_TREE;
3813         }
3814
3815       /* yylex() calls this with -2, since we should never start digging for
3816          the nested name at the point where we haven't even, for example,
3817          created the COMPONENT_REF or anything like that.  */
3818       if (val == NULL_TREE)
3819         val = lookup_nested_field (name, prefer_type != -2);
3820
3821       if (val == NULL_TREE)
3822         val = IDENTIFIER_GLOBAL_VALUE (name);
3823     }
3824   else
3825     val = IDENTIFIER_GLOBAL_VALUE (name);
3826
3827   if (val)
3828     {
3829       extern int looking_for_typename;
3830
3831       /* Arbitrate between finding a TYPE_DECL and finding
3832          other kinds of _DECLs.  */
3833       if (TREE_CODE (val) == TYPE_DECL || looking_for_typename < 0)
3834         return val;
3835
3836       if (IDENTIFIER_HAS_TYPE_VALUE (name))
3837         {
3838           register tree val_as_type = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
3839
3840           if (val == val_as_type || prefer_type > 0
3841               || looking_for_typename > 0)
3842             return val_as_type;
3843           if (prefer_type == 0)
3844             return val;
3845           return arbitrate_lookup (name, val, val_as_type);
3846         }
3847       if (TREE_TYPE (val) == error_mark_node)
3848         return error_mark_node;
3849     }
3850
3851   return val;
3852 }
3853
3854 /* Similar to `lookup_name' but look only at current binding level.  */
3855
3856 tree
3857 lookup_name_current_level (name)
3858      tree name;
3859 {
3860   register tree t = NULL_TREE;
3861
3862   if (current_binding_level == global_binding_level)
3863     {
3864       t = IDENTIFIER_GLOBAL_VALUE (name);
3865
3866       /* extern "C" function() */
3867       if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
3868         t = TREE_VALUE (t);
3869     }
3870   else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
3871     {
3872       for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
3873         if (DECL_NAME (t) == name)
3874           break;
3875     }
3876
3877   return t;
3878 }
3879 \f
3880 /* Arrange for the user to get a source line number, even when the
3881    compiler is going down in flames, so that she at least has a
3882    chance of working around problems in the compiler.  We used to
3883    call error(), but that let the segmentation fault continue
3884    through; now, it's much more passive by asking them to send the
3885    maintainers mail about the problem.  */
3886
3887 static void
3888 signal_catch (sig)
3889      int sig;
3890 {
3891   signal (SIGSEGV, SIG_DFL);
3892 #ifdef SIGIOT
3893   signal (SIGIOT, SIG_DFL);
3894 #endif
3895 #ifdef SIGILL
3896   signal (SIGILL, SIG_DFL);
3897 #endif
3898 #ifdef SIGABRT
3899   signal (SIGABRT, SIG_DFL);
3900 #endif
3901 #ifdef SIGBUS
3902   signal (SIGBUS, SIG_DFL);
3903 #endif
3904   my_friendly_abort (0);
3905 }
3906
3907 /* Array for holding types considered "built-in".  These types
3908    are output in the module in which `main' is defined.  */
3909 static tree *builtin_type_tdescs_arr;
3910 static int builtin_type_tdescs_len, builtin_type_tdescs_max;
3911
3912 /* Push the declarations of builtin types into the namespace.
3913    RID_INDEX, if < RID_MAX is the index of the builtin type
3914    in the array RID_POINTERS.  NAME is the name used when looking
3915    up the builtin type.  TYPE is the _TYPE node for the builtin type.  */
3916
3917 static void
3918 record_builtin_type (rid_index, name, type)
3919      enum rid rid_index;
3920      char *name;
3921      tree type;
3922 {
3923   tree rname = NULL_TREE, tname = NULL_TREE;
3924   tree tdecl;
3925
3926   if ((int) rid_index < (int) RID_MAX)
3927     rname = ridpointers[(int) rid_index];
3928   if (name)
3929     tname = get_identifier (name);
3930
3931   TYPE_BUILT_IN (type) = 1;
3932   
3933   if (tname)
3934     {
3935 #if 0 /* not yet, should get fixed properly later */
3936       tdecl = pushdecl (make_type_decl (tname, type));
3937 #else
3938       tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
3939 #endif
3940       set_identifier_type_value (tname, NULL_TREE);
3941       if ((int) rid_index < (int) RID_MAX)
3942         IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
3943     }
3944   if (rname != NULL_TREE)
3945     {
3946       if (tname != NULL_TREE)
3947         {
3948           set_identifier_type_value (rname, NULL_TREE);
3949           IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
3950         }
3951       else
3952         {
3953 #if 0 /* not yet, should get fixed properly later */
3954           tdecl = pushdecl (make_type_decl (rname, type));
3955 #else
3956           tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
3957 #endif
3958           set_identifier_type_value (rname, NULL_TREE);
3959         }
3960     }
3961
3962   if (flag_dossier)
3963     {
3964       if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
3965         {
3966           builtin_type_tdescs_max *= 2;
3967           builtin_type_tdescs_arr
3968             = (tree *)xrealloc (builtin_type_tdescs_arr,
3969                                 builtin_type_tdescs_max * sizeof (tree));
3970         }
3971       builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
3972       if (TREE_CODE (type) != POINTER_TYPE)
3973         {
3974           builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3975             = build_pointer_type (type);
3976           builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3977             = build_type_variant (TYPE_POINTER_TO (type), 1, 0);
3978         }
3979       if (TREE_CODE (type) != VOID_TYPE)
3980         {
3981           builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3982             = build_reference_type (type);
3983           builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3984             = build_type_variant (TYPE_REFERENCE_TO (type), 1, 0);
3985         }
3986     }
3987 }
3988
3989 static void
3990 output_builtin_tdesc_entries ()
3991 {
3992   extern struct obstack permanent_obstack;
3993
3994   /* If there's more than one main in this file, don't crash.  */
3995   if (builtin_type_tdescs_arr == 0)
3996     return;
3997
3998   push_obstacks (&permanent_obstack, &permanent_obstack);
3999   while (builtin_type_tdescs_len > 0)
4000     {
4001       tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
4002       tree tdesc = build_t_desc (type, 0);
4003       TREE_ASM_WRITTEN (tdesc) = 0;
4004       build_t_desc (type, 2);
4005     }
4006   free (builtin_type_tdescs_arr);
4007   builtin_type_tdescs_arr = 0;
4008   pop_obstacks ();
4009 }
4010
4011 /* Push overloaded decl, in global scope, with one argument so it
4012    can be used as a callback from define_function.  */
4013 static void
4014 push_overloaded_decl_1 (x)
4015      tree x;
4016 {
4017   push_overloaded_decl (x, 0);
4018 }
4019
4020 /* Create the predefined scalar types of C,
4021    and some nodes representing standard constants (0, 1, (void *)0).
4022    Initialize the global binding level.
4023    Make definitions for built-in primitive functions.  */
4024
4025 void
4026 init_decl_processing ()
4027 {
4028   tree decl;
4029   register tree endlink, int_endlink, double_endlink, ptr_endlink;
4030   tree fields[20];
4031   /* Either char* or void*.  */
4032   tree traditional_ptr_type_node;
4033   /* Data type of memcpy.  */
4034   tree memcpy_ftype;
4035 #if 0 /* Not yet.  */
4036   /* Data type of strncpy.  */
4037   tree strncpy_ftype;
4038 #endif
4039   int wchar_type_size;
4040   tree temp;
4041   tree array_domain_type;
4042
4043   /* Have to make these distinct before we try using them.  */
4044   lang_name_cplusplus = get_identifier ("C++");
4045   lang_name_c = get_identifier ("C");
4046
4047   /* Initially, C.  */
4048   current_lang_name = lang_name_c;
4049
4050   current_function_decl = NULL_TREE;
4051   named_labels = NULL_TREE;
4052   named_label_uses = NULL_TREE;
4053   current_binding_level = NULL_BINDING_LEVEL;
4054   free_binding_level = NULL_BINDING_LEVEL;
4055
4056   /* Because most segmentation signals can be traced back into user
4057      code, catch them and at least give the user a chance of working
4058      around compiler bugs. */
4059   signal (SIGSEGV, signal_catch);
4060
4061   /* We will also catch aborts in the back-end through signal_catch and
4062      give the user a chance to see where the error might be, and to defeat
4063      aborts in the back-end when there have been errors previously in their
4064      code. */
4065 #ifdef SIGIOT
4066   signal (SIGIOT, signal_catch);
4067 #endif
4068 #ifdef SIGILL
4069   signal (SIGILL, signal_catch);
4070 #endif
4071 #ifdef SIGABRT
4072   signal (SIGABRT, signal_catch);
4073 #endif
4074 #ifdef SIGBUS
4075   signal (SIGBUS, signal_catch);
4076 #endif
4077
4078   gcc_obstack_init (&decl_obstack);
4079   if (flag_dossier)
4080     {
4081       builtin_type_tdescs_max = 100;
4082       builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
4083     }
4084
4085   /* Must lay these out before anything else gets laid out.  */
4086   error_mark_node = make_node (ERROR_MARK);
4087   TREE_PERMANENT (error_mark_node) = 1;
4088   TREE_TYPE (error_mark_node) = error_mark_node;
4089   error_mark_list = build_tree_list (error_mark_node, error_mark_node);
4090   TREE_TYPE (error_mark_list) = error_mark_node;
4091
4092   pushlevel (0);        /* make the binding_level structure for global names.  */
4093   global_binding_level = current_binding_level;
4094
4095   this_identifier = get_identifier (THIS_NAME);
4096   in_charge_identifier = get_identifier (IN_CHARGE_NAME);
4097   pfn_identifier = get_identifier (VTABLE_PFN_NAME);
4098   index_identifier = get_identifier (VTABLE_INDEX_NAME);
4099   delta_identifier = get_identifier (VTABLE_DELTA_NAME);
4100   delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
4101   pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
4102
4103   /* Define `int' and `char' first so that dbx will output them first.  */
4104
4105   integer_type_node = make_signed_type (INT_TYPE_SIZE);
4106   record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
4107
4108   /* Define `char', which is like either `signed char' or `unsigned char'
4109      but not the same as either.  */
4110
4111   char_type_node =
4112     (flag_signed_char
4113      ? make_signed_type (CHAR_TYPE_SIZE)
4114      : make_unsigned_type (CHAR_TYPE_SIZE));
4115   record_builtin_type (RID_CHAR, "char", char_type_node);
4116
4117   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4118   record_builtin_type (RID_LONG, "long int", long_integer_type_node);
4119
4120   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4121   record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
4122
4123   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4124   record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
4125   record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
4126
4127   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4128   record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
4129
4130   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4131   record_builtin_type (RID_MAX, "long long unsigned int",
4132                        long_long_unsigned_type_node);
4133   record_builtin_type (RID_MAX, "long long unsigned",
4134                        long_long_unsigned_type_node);
4135
4136   /* `unsigned long' is the standard type for sizeof.
4137      Traditionally, use a signed type.
4138      Note that stddef.h uses `unsigned long',
4139      and this must agree, even of long and int are the same size.  */
4140   sizetype
4141     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
4142   if (flag_traditional && TREE_UNSIGNED (sizetype))
4143     sizetype = signed_type (sizetype);
4144
4145   ptrdiff_type_node
4146     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
4147
4148   TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
4149   TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
4150   TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
4151   TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
4152   TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
4153   TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
4154   TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
4155
4156   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4157   record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
4158   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4159   record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
4160   record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
4161
4162   /* Define both `signed char' and `unsigned char'.  */
4163   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4164   record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
4165   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4166   record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
4167
4168   /* These are types that type_for_size and type_for_mode use.  */
4169   intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4170   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
4171   intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4172   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
4173   intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4174   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
4175   intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4176   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
4177   unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4178   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
4179   unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4180   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
4181   unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4182   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
4183   unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4184   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
4185
4186   float_type_node = make_node (REAL_TYPE);
4187   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4188   record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
4189   layout_type (float_type_node);
4190
4191   double_type_node = make_node (REAL_TYPE);
4192   if (flag_short_double)
4193     TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4194   else
4195     TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4196   record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
4197   layout_type (double_type_node);
4198
4199   long_double_type_node = make_node (REAL_TYPE);
4200   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4201   record_builtin_type (RID_MAX, "long double", long_double_type_node);
4202   layout_type (long_double_type_node);
4203
4204   integer_zero_node = build_int_2 (0, 0);
4205   TREE_TYPE (integer_zero_node) = integer_type_node;
4206   integer_one_node = build_int_2 (1, 0);
4207   TREE_TYPE (integer_one_node) = integer_type_node;
4208   integer_two_node = build_int_2 (2, 0);
4209   TREE_TYPE (integer_two_node) = integer_type_node;
4210   integer_three_node = build_int_2 (3, 0);
4211   TREE_TYPE (integer_three_node) = integer_type_node;
4212   empty_init_node = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
4213
4214   /* These are needed by stor-layout.c.  */
4215   size_zero_node = size_int (0);
4216   size_one_node = size_int (1);
4217
4218   void_type_node = make_node (VOID_TYPE);
4219   record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
4220   layout_type (void_type_node); /* Uses integer_zero_node.  */
4221   void_list_node = build_tree_list (NULL_TREE, void_type_node);
4222   TREE_PARMLIST (void_list_node) = 1;
4223
4224   null_pointer_node = build_int_2 (0, 0);
4225   TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4226   layout_type (TREE_TYPE (null_pointer_node));
4227
4228   /* Used for expressions that do nothing, but are not errors.  */
4229   void_zero_node = build_int_2 (0, 0);
4230   TREE_TYPE (void_zero_node) = void_type_node;
4231
4232   string_type_node = build_pointer_type (char_type_node);
4233   const_string_type_node = build_pointer_type (build_type_variant (char_type_node, 1, 0));
4234   record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
4235
4236   /* Make a type to be the domain of a few array types
4237      whose domains don't really matter.
4238      200 is small enough that it always fits in size_t
4239      and large enough that it can hold most function names for the
4240      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
4241   array_domain_type = build_index_type (build_int_2 (200, 0));
4242
4243   /* make a type for arrays of characters.
4244      With luck nothing will ever really depend on the length of this
4245      array type.  */
4246   char_array_type_node
4247     = build_array_type (char_type_node, array_domain_type);
4248   /* Likewise for arrays of ints.  */
4249   int_array_type_node
4250     = build_array_type (integer_type_node, array_domain_type);
4251
4252   /* This is just some anonymous class type.  Nobody should ever
4253      need to look inside this envelope.  */
4254   class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
4255
4256   default_function_type
4257     = build_function_type (integer_type_node, NULL_TREE);
4258   build_pointer_type (default_function_type);
4259
4260   ptr_type_node = build_pointer_type (void_type_node);
4261   const_ptr_type_node = build_pointer_type (build_type_variant (void_type_node, 1, 0));
4262   record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
4263   endlink = void_list_node;
4264   int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
4265   double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
4266   ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
4267
4268   double_ftype_double
4269     = build_function_type (double_type_node, double_endlink);
4270
4271   double_ftype_double_double
4272     = build_function_type (double_type_node,
4273                            tree_cons (NULL_TREE, double_type_node, double_endlink));
4274
4275   int_ftype_int
4276     = build_function_type (integer_type_node, int_endlink);
4277
4278   long_ftype_long
4279     = build_function_type (long_integer_type_node,
4280                            tree_cons (NULL_TREE, long_integer_type_node, endlink));
4281
4282   void_ftype_ptr_ptr_int
4283     = build_function_type (void_type_node,
4284                            tree_cons (NULL_TREE, ptr_type_node,
4285                                       tree_cons (NULL_TREE, ptr_type_node,
4286                                                  int_endlink)));
4287
4288   int_ftype_cptr_cptr_sizet
4289     = build_function_type (integer_type_node,
4290                            tree_cons (NULL_TREE, const_ptr_type_node,
4291                                       tree_cons (NULL_TREE, const_ptr_type_node,
4292                                                  tree_cons (NULL_TREE,
4293                                                             sizetype,
4294                                                             endlink))));
4295
4296   void_ftype_ptr_int_int
4297     = build_function_type (void_type_node,
4298                            tree_cons (NULL_TREE, ptr_type_node,
4299                                       tree_cons (NULL_TREE, integer_type_node,
4300                                                  int_endlink)));
4301
4302   string_ftype_ptr_ptr          /* strcpy prototype */
4303     = build_function_type (string_type_node,
4304                            tree_cons (NULL_TREE, string_type_node,
4305                                       tree_cons (NULL_TREE,
4306                                                  const_string_type_node,
4307                                                  endlink)));
4308
4309 #if 0
4310   /* Not yet.  */
4311   strncpy_ftype                 /* strncpy prototype */
4312     = build_function_type (string_type_node,
4313                            tree_cons (NULL_TREE, string_type_node,
4314                                       tree_cons (NULL_TREE, const_string_type_node,
4315                                                  tree_cons (NULL_TREE,
4316                                                             sizetype,
4317                                                             endlink))));
4318 #endif
4319
4320   int_ftype_string_string       /* strcmp prototype */
4321     = build_function_type (integer_type_node,
4322                            tree_cons (NULL_TREE, const_string_type_node,
4323                                       tree_cons (NULL_TREE,
4324                                                  const_string_type_node,
4325                                                  endlink)));
4326
4327   sizet_ftype_string            /* strlen prototype */
4328     = build_function_type (sizetype,
4329                            tree_cons (NULL_TREE, const_string_type_node,
4330                                       endlink));
4331
4332   traditional_ptr_type_node
4333     = (flag_traditional ? string_type_node : ptr_type_node);
4334
4335   memcpy_ftype  /* memcpy prototype */
4336     = build_function_type (traditional_ptr_type_node,
4337                            tree_cons (NULL_TREE, ptr_type_node,
4338                                       tree_cons (NULL_TREE, const_ptr_type_node,
4339                                                  tree_cons (NULL_TREE,
4340                                                             sizetype,
4341                                                             endlink))));
4342
4343   if (flag_huge_objects)
4344     delta_type_node = long_integer_type_node;
4345   else
4346     delta_type_node = short_integer_type_node;
4347
4348   builtin_function ("__builtin_constant_p", int_ftype_int,
4349                     BUILT_IN_CONSTANT_P, NULL_PTR);
4350
4351   builtin_function ("__builtin_alloca",
4352                     build_function_type (ptr_type_node,
4353                                          tree_cons (NULL_TREE,
4354                                                     sizetype,
4355                                                     endlink)),
4356                     BUILT_IN_ALLOCA, "alloca");
4357 #if 0
4358   builtin_function ("alloca",
4359                     build_function_type (ptr_type_node,
4360                                          tree_cons (NULL_TREE,
4361                                                     sizetype,
4362                                                     endlink)),
4363                     BUILT_IN_ALLOCA, NULL_PTR);
4364 #endif
4365
4366   builtin_function ("__builtin_abs", int_ftype_int,
4367                     BUILT_IN_ABS, NULL_PTR);
4368   builtin_function ("__builtin_fabs", double_ftype_double,
4369                     BUILT_IN_FABS, NULL_PTR);
4370   builtin_function ("__builtin_labs", long_ftype_long,
4371                     BUILT_IN_LABS, NULL_PTR);
4372   builtin_function ("__builtin_ffs", int_ftype_int,
4373                     BUILT_IN_FFS, NULL_PTR);
4374   builtin_function ("__builtin_fsqrt", double_ftype_double,
4375                     BUILT_IN_FSQRT, NULL_PTR);
4376   builtin_function ("__builtin_sin", double_ftype_double, 
4377                     BUILT_IN_SIN, "sin");
4378   builtin_function ("__builtin_cos", double_ftype_double, 
4379                     BUILT_IN_COS, "cos");
4380   builtin_function ("__builtin_saveregs",
4381                     build_function_type (ptr_type_node, NULL_TREE),
4382                     BUILT_IN_SAVEREGS, NULL_PTR);
4383 /* EXPAND_BUILTIN_VARARGS is obsolete.  */
4384 #if 0
4385   builtin_function ("__builtin_varargs",
4386                     build_function_type (ptr_type_node,
4387                                          tree_cons (NULL_TREE,
4388                                                     integer_type_node,
4389                                                     endlink)),
4390                     BUILT_IN_VARARGS, NULL_PTR);
4391 #endif
4392   builtin_function ("__builtin_classify_type", default_function_type,
4393                     BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
4394   builtin_function ("__builtin_next_arg",
4395                     build_function_type (ptr_type_node, NULL_TREE),
4396                     BUILT_IN_NEXT_ARG, NULL_PTR);
4397   builtin_function ("__builtin_args_info",
4398                     build_function_type (integer_type_node,
4399                                          tree_cons (NULL_TREE,
4400                                                     integer_type_node,
4401                                                     endlink)),
4402                     BUILT_IN_ARGS_INFO, NULL_PTR);
4403
4404   /* Untyped call and return.  */
4405   builtin_function ("__builtin_apply_args",
4406                     build_function_type (ptr_type_node, NULL_TREE),
4407                     BUILT_IN_APPLY_ARGS, NULL_PTR);
4408
4409   temp = tree_cons (NULL_TREE,
4410                     build_pointer_type (build_function_type (void_type_node,
4411                                                              NULL_TREE)),
4412                     tree_cons (NULL_TREE,
4413                                ptr_type_node,
4414                                tree_cons (NULL_TREE,
4415                                           sizetype,
4416                                           endlink)));
4417   builtin_function ("__builtin_apply",
4418                     build_function_type (ptr_type_node, temp),
4419                     BUILT_IN_APPLY, NULL_PTR);
4420   builtin_function ("__builtin_return",
4421                     build_function_type (void_type_node,
4422                                          tree_cons (NULL_TREE,
4423                                                     ptr_type_node,
4424                                                     endlink)),
4425                     BUILT_IN_RETURN, NULL_PTR);
4426
4427   /* Currently under experimentation.  */
4428   builtin_function ("__builtin_memcpy", memcpy_ftype,
4429                     BUILT_IN_MEMCPY, "memcpy");
4430   builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
4431                     BUILT_IN_MEMCMP, "memcmp");
4432   builtin_function ("__builtin_strcmp", int_ftype_string_string,
4433                     BUILT_IN_STRCMP, "strcmp");
4434   builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
4435                     BUILT_IN_STRCPY, "strcpy");
4436 #if 0
4437   /* Not yet.  */
4438   builtin_function ("__builtin_strncpy", strncpy_ftype,
4439                     BUILT_IN_STRNCPY, "strncpy");
4440 #endif
4441   builtin_function ("__builtin_strlen", sizet_ftype_string,
4442                     BUILT_IN_STRLEN, "strlen");
4443
4444   if (!flag_no_builtin)
4445     {
4446 #if 0 /* These do not work well with libg++.  */
4447       builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
4448       builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
4449       builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
4450 #endif
4451       builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
4452       builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
4453                         NULL_PTR);
4454       builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR);
4455       builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, NULL_PTR);
4456 #if 0
4457       /* Not yet.  */
4458       builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR);
4459 #endif
4460       builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR);
4461       builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
4462       builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
4463     }
4464
4465 #if 0
4466   /* Support for these has not been written in either expand_builtin
4467      or build_function_call.  */
4468   builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
4469   builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
4470   builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, 0);
4471   builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
4472   builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD, 0);
4473   builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM, 0);
4474   builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, 0);
4475   builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, 0);
4476   builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, 0);
4477 #endif
4478
4479   /* C++ extensions */
4480
4481   unknown_type_node = make_node (UNKNOWN_TYPE);
4482 #if 0 /* not yet, should get fixed properly later */
4483   pushdecl (make_type_decl (get_identifier ("unknown type"),
4484                        unknown_type_node));
4485 #else
4486   decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
4487                         unknown_type_node));
4488   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
4489   DECL_IGNORED_P (decl) = 1;
4490 #endif
4491   TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
4492   TYPE_ALIGN (unknown_type_node) = 1;
4493   TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
4494   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
4495   TREE_TYPE (unknown_type_node) = unknown_type_node;
4496   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result.  */
4497   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
4498   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
4499
4500   /* This is for handling opaque types in signatures.  */
4501   opaque_type_node = copy_node (ptr_type_node);
4502   TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
4503   record_builtin_type (RID_MAX, 0, opaque_type_node);
4504
4505   /* This is special for C++ so functions can be overloaded. */
4506   wchar_type_node
4507     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
4508   wchar_type_size = TYPE_PRECISION (wchar_type_node);
4509   signed_wchar_type_node = make_signed_type (wchar_type_size);
4510   unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
4511   wchar_type_node
4512     = TREE_UNSIGNED (wchar_type_node)
4513       ? unsigned_wchar_type_node
4514       : signed_wchar_type_node;
4515   record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
4516
4517   /* This is for wide string constants.  */
4518   wchar_array_type_node
4519     = build_array_type (wchar_type_node, array_domain_type);
4520
4521   /* This is a hack that should go away when we deliver the
4522      real gc code.  */
4523   if (flag_gc)
4524     {
4525       builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
4526       pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
4527     }
4528
4529   /* Simplify life by making a "vtable_entry_type".  Give its
4530      fields names so that the debugger can use them.  */
4531
4532   vtable_entry_type = make_lang_type (RECORD_TYPE);
4533   fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, delta_type_node);
4534   fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, delta_type_node);
4535   fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, ptr_type_node);
4536   finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
4537                        double_type_node);
4538
4539   /* Make this part of an invisible union.  */
4540   fields[3] = copy_node (fields[2]);
4541   TREE_TYPE (fields[3]) = delta_type_node;
4542   DECL_NAME (fields[3]) = delta2_identifier;
4543   DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
4544   DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
4545   TREE_UNSIGNED (fields[3]) = 0;
4546   TREE_CHAIN (fields[2]) = fields[3];
4547   vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
4548   record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
4549
4550 #ifdef VTABLE_USES_MASK
4551   /* This is primarily for virtual function definition.  We
4552      declare an array of `void *', which can later be
4553      converted to the appropriate function pointer type.
4554      To do pointers to members, we need a mask which can
4555      distinguish an index value into a virtual function table
4556      from an address.  */
4557   vtbl_mask = build_int_2 (~((HOST_WIDE_INT) VINDEX_MAX - 1), -1);
4558 #endif
4559
4560   vtbl_type_node
4561     = build_array_type (vtable_entry_type, NULL_TREE);
4562   layout_type (vtbl_type_node);
4563   vtbl_type_node = build_type_variant (vtbl_type_node, 1, 0);
4564   record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
4565
4566   /* Simplify life by making a "sigtable_entry_type".  Give its
4567      fields names so that the debugger can use them.  */
4568
4569   if (flag_handle_signatures)
4570     {
4571       sigtable_entry_type = make_lang_type (RECORD_TYPE);
4572       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_CODE_NAME), short_integer_type_node);
4573       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_OFFSET_NAME), short_integer_type_node);
4574       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_PFN_NAME), ptr_type_node);
4575       finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 2,
4576                            double_type_node);
4577       sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
4578       record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
4579     }
4580
4581   if (flag_dossier)
4582     {
4583       /* Must build __t_desc type.  Currently, type descriptors look like this:
4584
4585          struct __t_desc
4586          {
4587            const char *name;
4588            int size;
4589            int bits;
4590            struct __t_desc *points_to;
4591            int ivars_count, meths_count;
4592            struct __i_desc *ivars[];
4593            struct __m_desc *meths[];
4594            struct __t_desc *parents[];
4595            struct __t_desc *vbases[];
4596            int offsets[];
4597          };
4598
4599          ...as per Linton's paper.  */
4600
4601       __t_desc_type_node = make_lang_type (RECORD_TYPE);
4602       __i_desc_type_node = make_lang_type (RECORD_TYPE);
4603       __m_desc_type_node = make_lang_type (RECORD_TYPE);
4604       __t_desc_array_type = build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE);
4605       __i_desc_array_type = build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE);
4606       __m_desc_array_type = build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE);
4607
4608       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4609                                          string_type_node);
4610       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
4611                                          unsigned_type_node);
4612       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
4613                                          unsigned_type_node);
4614       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("points_to"),
4615                                          TYPE_POINTER_TO (__t_desc_type_node));
4616       fields[4] = build_lang_field_decl (FIELD_DECL,
4617                                          get_identifier ("ivars_count"),
4618                                          integer_type_node);
4619       fields[5] = build_lang_field_decl (FIELD_DECL,
4620                                          get_identifier ("meths_count"),
4621                                          integer_type_node);
4622       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
4623                                          build_pointer_type (__i_desc_array_type));
4624       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
4625                                          build_pointer_type (__m_desc_array_type));
4626       fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
4627                                          build_pointer_type (__t_desc_array_type));
4628       fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
4629                                          build_pointer_type (__t_desc_array_type));
4630       fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
4631                                          build_pointer_type (integer_type_node));
4632       finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
4633
4634       /* ivar descriptors look like this:
4635
4636          struct __i_desc
4637          {
4638            const char *name;
4639            int offset;
4640            struct __t_desc *type;
4641          };
4642       */
4643
4644       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4645                                          string_type_node);
4646       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
4647                                          integer_type_node);
4648       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
4649                                          TYPE_POINTER_TO (__t_desc_type_node));
4650       finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, integer_type_node);
4651
4652       /* method descriptors look like this:
4653
4654          struct __m_desc
4655          {
4656            const char *name;
4657            int vindex;
4658            struct __t_desc *vcontext;
4659            struct __t_desc *return_type;
4660            void (*address)();
4661            short parm_count;
4662            short required_parms;
4663            struct __t_desc *parm_types[];
4664          };
4665       */
4666
4667       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4668                                          string_type_node);
4669       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
4670                                          integer_type_node);
4671       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
4672                                          TYPE_POINTER_TO (__t_desc_type_node));
4673       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
4674                                          TYPE_POINTER_TO (__t_desc_type_node));
4675       fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
4676                                          build_pointer_type (default_function_type));
4677       fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
4678                                          short_integer_type_node);
4679       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
4680                                          short_integer_type_node);
4681       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
4682                                          build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE)));
4683       finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, integer_type_node);
4684     }
4685
4686   /* Now, C++.  */
4687   current_lang_name = lang_name_cplusplus;
4688   if (flag_dossier)
4689     {
4690       int i = builtin_type_tdescs_len;
4691       while (i > 0)
4692         {
4693           tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
4694           TREE_ASM_WRITTEN (tdesc) = 1;
4695           TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
4696         }
4697     }
4698
4699   auto_function (ansi_opname[(int) NEW_EXPR],
4700                  build_function_type (ptr_type_node,
4701                                       tree_cons (NULL_TREE, sizetype,
4702                                                  void_list_node)),
4703                  NOT_BUILT_IN);
4704   auto_function (ansi_opname[(int) DELETE_EXPR],
4705                  build_function_type (void_type_node,
4706                                       tree_cons (NULL_TREE, ptr_type_node,
4707                                                  void_list_node)),
4708                  NOT_BUILT_IN);
4709
4710   abort_fndecl
4711     = define_function ("abort",
4712                        build_function_type (void_type_node, void_list_node),
4713                        NOT_BUILT_IN, 0, 0);
4714
4715   unhandled_exception_fndecl
4716     = define_function ("__unhandled_exception",
4717                        build_function_type (void_type_node, NULL_TREE),
4718                        NOT_BUILT_IN, 0, 0);
4719
4720   /* Perform other language dependent initializations.  */
4721   init_class_processing ();
4722   init_init_processing ();
4723   init_search_processing ();
4724
4725   if (flag_handle_exceptions)
4726     {
4727       if (flag_handle_exceptions == 2)
4728         /* Too much trouble to inline all the trys needed for this.  */
4729         flag_this_is_variable = 2;
4730       init_exception_processing ();
4731     }
4732   if (flag_gc)
4733     init_gc_processing ();
4734   if (flag_no_inline)
4735     {
4736       flag_inline_functions = 0;
4737 #if 0
4738       /* This causes uneccessary emission of inline functions.  */
4739       flag_default_inline = 0;
4740 #endif
4741     }
4742   if (flag_cadillac)
4743     init_cadillac ();
4744
4745   /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__.  */
4746   declare_function_name ();
4747
4748   /* Prepare to check format strings against argument lists.  */
4749   init_function_format_info ();
4750 }
4751
4752 /* Make a definition for a builtin function named NAME and whose data type
4753    is TYPE.  TYPE should be a function type with argument types.
4754    FUNCTION_CODE tells later passes how to compile calls to this function.
4755    See tree.h for its possible values.
4756
4757    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
4758    the name to be called if we can't opencode the function.  */
4759
4760 tree
4761 define_function (name, type, function_code, pfn, library_name)
4762      char *name;
4763      tree type;
4764      enum built_in_function function_code;
4765      void (*pfn)();
4766      char *library_name;
4767 {
4768   tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
4769   DECL_EXTERNAL (decl) = 1;
4770   TREE_PUBLIC (decl) = 1;
4771
4772   /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
4773      we cannot change DECL_ASSEMBLER_NAME until we have installed this
4774      function in the namespace.  */
4775   if (pfn) (*pfn) (decl);
4776   if (library_name)
4777     DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
4778   make_function_rtl (decl);
4779   if (function_code != NOT_BUILT_IN)
4780     {
4781       DECL_BUILT_IN (decl) = 1;
4782       DECL_SET_FUNCTION_CODE (decl, function_code);
4783     }
4784   return decl;
4785 }
4786 \f
4787 /* Called when a declaration is seen that contains no names to declare.
4788    If its type is a reference to a structure, union or enum inherited
4789    from a containing scope, shadow that tag name for the current scope
4790    with a forward reference.
4791    If its type defines a new named structure or union
4792    or defines an enum, it is valid but we need not do anything here.
4793    Otherwise, it is an error.
4794
4795    C++: may have to grok the declspecs to learn about static,
4796    complain for anonymous unions.  */
4797
4798 void
4799 shadow_tag (declspecs)
4800      tree declspecs;
4801 {
4802   int found_tag = 0;
4803   int warned = 0;
4804   int static_or_extern = 0;
4805   register tree link;
4806   register enum tree_code code, ok_code = ERROR_MARK;
4807   register tree t = NULL_TREE;
4808
4809   for (link = declspecs; link; link = TREE_CHAIN (link))
4810     {
4811       register tree value = TREE_VALUE (link);
4812
4813       code = TREE_CODE (value);
4814       if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
4815         /* Used to test also that TYPE_SIZE (value) != 0.
4816            That caused warning for `struct foo;' at top level in the file.  */
4817         {
4818           register tree name = TYPE_NAME (value);
4819
4820           if (name == NULL_TREE)
4821             name = lookup_tag_reverse (value, NULL_TREE);
4822
4823           if (name && TREE_CODE (name) == TYPE_DECL)
4824             name = DECL_NAME (name);
4825
4826           t = lookup_tag (code, name, inner_binding_level, 1);
4827
4828           if (t == NULL_TREE)
4829             {
4830               push_obstacks (&permanent_obstack, &permanent_obstack);
4831               if (IS_AGGR_TYPE_CODE (code))
4832                 t = make_lang_type (code);
4833               else
4834                 t = make_node (code);
4835               pushtag (name, t, 0);
4836               pop_obstacks ();
4837               ok_code = code;
4838               break;
4839             }
4840           else if (name != NULL_TREE || code == ENUMERAL_TYPE)
4841             ok_code = code;
4842
4843           if (ok_code != ERROR_MARK)
4844             found_tag++;
4845           else
4846             {
4847               if (!warned)
4848                 pedwarn ("useless keyword or type name in declaration");
4849               warned = 1;
4850             }
4851         }
4852       else if (value == ridpointers[(int) RID_STATIC]
4853                || value == ridpointers[(int) RID_EXTERN])
4854         static_or_extern = 1;
4855     }
4856
4857   /* This is where the variables in an anonymous union are
4858      declared.  An anonymous union declaration looks like:
4859      union { ... } ;
4860      because there is no declarator after the union, the parser
4861      sends that declaration here.  */
4862   if (ok_code == UNION_TYPE
4863       && t != NULL_TREE
4864       && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
4865            && ANON_AGGRNAME_P (TYPE_NAME (t)))
4866           || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
4867               && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
4868     {
4869       /* ANSI C++ June 5 1992 WP 9.5.3.  Anonymous unions may not have
4870          function members.  */
4871       if (TYPE_FIELDS (t))
4872         {
4873           tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, NULL_TREE);
4874           finish_anon_union (decl);
4875         }
4876       else
4877         error ("anonymous union cannot have a function member");
4878     }
4879   else
4880     {
4881       /* Anonymous unions are objects, that's why we only check for
4882          static/extern specifiers in this branch.  */
4883       if (static_or_extern)
4884         error ("static/extern can only be specified for objects and functions");
4885
4886       if (ok_code == RECORD_TYPE
4887           && found_tag == 1
4888           && TYPE_LANG_SPECIFIC (t)
4889           && CLASSTYPE_DECLARED_EXCEPTION (t))
4890         {
4891           if (TYPE_SIZE (t))
4892             cp_error ("redeclaration of exception `%T'", t);
4893           else
4894             {
4895               tree ename, decl;
4896
4897               push_obstacks (&permanent_obstack, &permanent_obstack);
4898
4899               pushclass (t, 0);
4900               finish_exception (t, NULL_TREE);
4901
4902               ename = TYPE_NAME (t);
4903               if (TREE_CODE (ename) == TYPE_DECL)
4904                 ename = DECL_NAME (ename);
4905               decl = build_lang_field_decl (VAR_DECL, ename, t);
4906               finish_exception_decl (current_class_name, decl);
4907               end_exception_decls ();
4908
4909               pop_obstacks ();
4910             }
4911         }
4912       else if (!warned && found_tag > 1)
4913         warning ("multiple types in one declaration");
4914     }
4915 }
4916 \f
4917 /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
4918
4919 tree
4920 groktypename (typename)
4921      tree typename;
4922 {
4923   if (TREE_CODE (typename) != TREE_LIST)
4924     return typename;
4925   return grokdeclarator (TREE_VALUE (typename),
4926                          TREE_PURPOSE (typename),
4927                          TYPENAME, 0, NULL_TREE);
4928 }
4929
4930 /* Decode a declarator in an ordinary declaration or data definition.
4931    This is called as soon as the type information and variable name
4932    have been parsed, before parsing the initializer if any.
4933    Here we create the ..._DECL node, fill in its type,
4934    and put it on the list of decls for the current context.
4935    The ..._DECL node is returned as the value.
4936
4937    Exception: for arrays where the length is not specified,
4938    the type is left null, to be filled in by `finish_decl'.
4939
4940    Function definitions do not come here; they go to start_function
4941    instead.  However, external and forward declarations of functions
4942    do go through here.  Structure field declarations are done by
4943    grokfield and not through here.  */
4944
4945 /* Set this to zero to debug not using the temporary obstack
4946    to parse initializers.  */
4947 int debug_temp_inits = 1;
4948
4949 tree
4950 start_decl (declarator, declspecs, initialized, raises)
4951      tree declarator, declspecs;
4952      int initialized;
4953      tree raises;
4954 {
4955   register tree decl;
4956   register tree type, tem;
4957   tree context;
4958   extern int have_extern_spec;
4959   extern int used_extern_spec;
4960
4961   int init_written = initialized;
4962
4963   /* This should only be done once on the top most decl. */
4964   if (have_extern_spec && !used_extern_spec)
4965     {
4966       declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
4967       used_extern_spec = 1;
4968     }
4969
4970   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises);
4971   if (decl == NULL_TREE || decl == void_type_node)
4972     return NULL_TREE;
4973
4974   type = TREE_TYPE (decl);
4975
4976   /* Don't lose if destructors must be executed at file-level.  */
4977   if (TREE_STATIC (decl)
4978       && TYPE_NEEDS_DESTRUCTOR (type)
4979       && !TREE_PERMANENT (decl))
4980     {
4981       push_obstacks (&permanent_obstack, &permanent_obstack);
4982       decl = copy_node (decl);
4983       if (TREE_CODE (type) == ARRAY_TYPE)
4984         {
4985           tree itype = TYPE_DOMAIN (type);
4986           if (itype && ! TREE_PERMANENT (itype))
4987             {
4988               itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
4989               type = build_cplus_array_type (TREE_TYPE (type), itype);
4990               TREE_TYPE (decl) = type;
4991             }
4992         }
4993       pop_obstacks ();
4994     }
4995
4996   /* Interesting work for this is done in `finish_exception_decl'.  */
4997   if (TREE_CODE (type) == RECORD_TYPE
4998       && CLASSTYPE_DECLARED_EXCEPTION (type))
4999     return decl;
5000
5001   /* Corresponding pop_obstacks is done in `finish_decl'.  */
5002   push_obstacks_nochange ();
5003
5004   context
5005     = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
5006       ? DECL_CLASS_CONTEXT (decl)
5007       : DECL_CONTEXT (decl);
5008
5009   if (processing_template_decl)
5010     {
5011       tree d;
5012       if (TREE_CODE (decl) == FUNCTION_DECL)
5013         {
5014           /* Declarator is a call_expr; extract arguments from it, since
5015              grokdeclarator didn't do it.  */
5016           tree args;
5017           args = copy_to_permanent (last_function_parms);
5018           if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
5019             {
5020               tree t = TREE_TYPE (decl);
5021               
5022               t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
5023               if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE)
5024                 {
5025                   t = build_pointer_type (t); /* base type of `this' */
5026 #if 1
5027                   /* I suspect this is wrong. */
5028                   t = build_type_variant (t, flag_this_is_variable <= 0,
5029                                           0); /* type of `this' */
5030 #else
5031                   t = build_type_variant (t, 0, 0); /* type of `this' */
5032 #endif
5033                   t = build (PARM_DECL, t, this_identifier);
5034                   TREE_CHAIN (t) = args;
5035                   args = t;
5036                 }
5037             }
5038           DECL_ARGUMENTS (decl) = args;
5039         }
5040       d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
5041       if (interface_unknown && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
5042         warn_if_unknown_interface ();
5043       TREE_PUBLIC (d) = TREE_PUBLIC (decl) = flag_external_templates && !interface_unknown;
5044       TREE_STATIC (d) = TREE_STATIC (decl);
5045       DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl)
5046                            && !(context && !DECL_THIS_EXTERN (decl)));
5047       DECL_TEMPLATE_RESULT (d) = decl;
5048       DECL_OVERLOADED (d) = 1;
5049       decl = d;
5050     }
5051
5052   if (context && TYPE_SIZE (context) != NULL_TREE)
5053     {
5054       /* If it was not explicitly declared `extern',
5055          revoke any previous claims of DECL_EXTERNAL.  */
5056       if (DECL_THIS_EXTERN (decl) == 0)
5057         DECL_EXTERNAL (decl) = 0;
5058       if (DECL_LANG_SPECIFIC (decl))
5059         DECL_IN_AGGR_P (decl) = 0;
5060       pushclass (context, 2);
5061     }
5062
5063   /* If this type of object needs a cleanup, and control may
5064      jump past it, make a new binding level so that it is cleaned
5065      up only when it is initialized first.  */
5066   if (TYPE_NEEDS_DESTRUCTOR (type)
5067       && current_binding_level->more_cleanups_ok == 0)
5068     pushlevel_temporary (1);
5069
5070   if (initialized)
5071     /* Is it valid for this decl to have an initializer at all?
5072        If not, set INITIALIZED to zero, which will indirectly
5073        tell `finish_decl' to ignore the initializer once it is parsed.  */
5074     switch (TREE_CODE (decl))
5075       {
5076       case TYPE_DECL:
5077         /* typedef foo = bar  means give foo the same type as bar.
5078            We haven't parsed bar yet, so `finish_decl' will fix that up.
5079            Any other case of an initialization in a TYPE_DECL is an error.  */
5080         if (pedantic || list_length (declspecs) > 1)
5081           {
5082             cp_error ("typedef `%D' is initialized", decl);
5083             initialized = 0;
5084           }
5085         break;
5086
5087       case FUNCTION_DECL:
5088         cp_error ("function `%#D' is initialized like a variable", decl);
5089         initialized = 0;
5090         break;
5091
5092       default:
5093         /* Don't allow initializations for incomplete types except for
5094            arrays which might be completed by the initialization.  */
5095         if (TYPE_SIZE (type) != NULL_TREE)
5096           ;                     /* A complete type is ok.  */
5097         else if (TREE_CODE (type) != ARRAY_TYPE)
5098           {
5099             cp_error ("variable `%#D' has initializer but incomplete type",
5100                       decl);
5101             initialized = 0;
5102           }
5103         else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE)
5104           {
5105             cp_error ("elements of array `%#D' have incomplete type", decl);
5106             initialized = 0;
5107           }
5108       }
5109
5110   if (!initialized
5111       && TREE_CODE (decl) != TYPE_DECL
5112       && TREE_CODE (decl) != TEMPLATE_DECL
5113       && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
5114     {
5115       if (TYPE_SIZE (type) == NULL_TREE)
5116         {
5117           cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
5118                  decl);
5119           /* Change the type so that assemble_variable will give
5120              DECL an rtl we can live with: (mem (const_int 0)).  */
5121           TREE_TYPE (decl) = error_mark_node;
5122           type = error_mark_node;
5123         }
5124       else
5125         {
5126           /* If any base type in the hierarchy of TYPE needs a constructor,
5127              then we set initialized to 1.  This way any nodes which are
5128              created for the purposes of initializing this aggregate
5129              will live as long as it does.  This is necessary for global
5130              aggregates which do not have their initializers processed until
5131              the end of the file.  */
5132           initialized = TYPE_NEEDS_CONSTRUCTING (type);
5133         }
5134     }
5135
5136   if (initialized)
5137     {
5138       if (current_binding_level != global_binding_level
5139           && DECL_EXTERNAL (decl))
5140         cp_warning ("declaration of `%#D' has `extern' and is initialized",
5141                     decl);
5142       DECL_EXTERNAL (decl) = 0;
5143       if (current_binding_level == global_binding_level)
5144         TREE_STATIC (decl) = 1;
5145
5146       /* Tell `pushdecl' this is an initialized decl
5147          even though we don't yet have the initializer expression.
5148          Also tell `finish_decl' it may store the real initializer.  */
5149       DECL_INITIAL (decl) = error_mark_node;
5150     }
5151
5152   /* Add this decl to the current binding level, but not if it
5153      comes from another scope, e.g. a static member variable.
5154      TEM may equal DECL or it may be a previous decl of the same name.  */
5155   if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
5156       || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
5157       || TREE_CODE (type) == LANG_TYPE)
5158     tem = decl;
5159   else
5160     {
5161       tem = pushdecl (decl);
5162       if (is_overloaded_fn (tem))
5163         {
5164           tree tem2;
5165           tem = get_first_fn (tem);
5166           tem2 = decl_value_member (decl, tem);
5167           
5168           if (tem2 != NULL_TREE)
5169             tem = tem2;
5170           else
5171             {
5172               while (tem && ! decls_match (decl, tem))
5173                 tem = DECL_CHAIN (tem);
5174               if (tem == NULL_TREE)
5175                 tem = decl;
5176             }
5177         }
5178     }
5179              
5180   /* Tell the back-end to use or not use .common as appropriate.  */
5181   DECL_COMMON (tem) = flag_conserve_space;
5182
5183 #if 0
5184   /* We don't do this yet for GNU C++.  */
5185   /* For a local variable, define the RTL now.  */
5186   if (current_binding_level != global_binding_level
5187       /* But not if this is a duplicate decl
5188          and we preserved the rtl from the previous one
5189          (which may or may not happen).  */
5190       && DECL_RTL (tem) == NULL_RTX)
5191     {
5192       if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
5193         expand_decl (tem);
5194       else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
5195                && DECL_INITIAL (tem) != NULL_TREE)
5196         expand_decl (tem);
5197     }
5198 #endif
5199
5200   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_OVERLOADED (decl))
5201     /* @@ Also done in start_function.  */
5202     tem = push_overloaded_decl (tem, 1);
5203   else if (TREE_CODE (decl) == TEMPLATE_DECL)
5204     {
5205       tree result = DECL_TEMPLATE_RESULT (decl);
5206       if (DECL_CONTEXT (result) != NULL_TREE)
5207         {
5208           tree type;
5209           type = DECL_CONTEXT (result);
5210
5211           if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE)
5212             {
5213               cp_error ("declaration of `%D' in non-template type `%T'",
5214                         decl, type);
5215               return NULL_TREE;
5216             }
5217
5218           if (/* TREE_CODE (result) == VAR_DECL */ 1)
5219             {
5220 #if 0
5221               tree tmpl = UPT_TEMPLATE (type);
5222               
5223               fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
5224               print_node_brief (stderr, "", DECL_NAME (tem), 0);
5225               fprintf (stderr, " to class %s\n",
5226                        IDENTIFIER_POINTER (DECL_NAME (tmpl)));
5227               DECL_TEMPLATE_MEMBERS (tmpl)
5228                 = perm_tree_cons (DECL_NAME (tem), tem,
5229                                   DECL_TEMPLATE_MEMBERS (tmpl));
5230 #endif
5231               return tem;
5232             }
5233           my_friendly_abort (13);
5234         }
5235       else if (TREE_CODE (result) == FUNCTION_DECL)
5236         tem = push_overloaded_decl (tem, 0);
5237       else if (TREE_CODE (result) == VAR_DECL
5238                || TREE_CODE (result) == TYPE_DECL)
5239         {
5240           cp_error ("invalid template `%#D'", result);
5241           return NULL_TREE;
5242         }
5243       else
5244         my_friendly_abort (14);
5245     }
5246
5247   if (init_written
5248       && ! (TREE_CODE (tem) == PARM_DECL
5249             || (TREE_READONLY (tem)
5250                 && (TREE_CODE (tem) == VAR_DECL
5251                     || TREE_CODE (tem) == FIELD_DECL))))
5252     {
5253       /* When parsing and digesting the initializer,
5254          use temporary storage.  Do this even if we will ignore the value.  */
5255       if (current_binding_level == global_binding_level && debug_temp_inits)
5256         {
5257           if (TYPE_NEEDS_CONSTRUCTING (type) || TREE_CODE (type) == REFERENCE_TYPE)
5258             /* In this case, the initializer must lay down in permanent
5259                storage, since it will be saved until `finish_file' is run.   */
5260             ;
5261           else
5262             temporary_allocation ();
5263         }
5264     }
5265
5266   if (flag_cadillac)
5267     cadillac_start_decl (tem);
5268
5269   return tem;
5270 }
5271
5272 static void
5273 make_temporary_for_reference (decl, ctor_call, init, cleanupp)
5274      tree decl, ctor_call, init;
5275      tree *cleanupp;
5276 {
5277   tree type = TREE_TYPE (decl);
5278   tree target_type = TREE_TYPE (type);
5279   tree tmp, tmp_addr;
5280
5281   if (ctor_call)
5282     {
5283       tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
5284       if (TREE_CODE (tmp_addr) == NOP_EXPR)
5285         tmp_addr = TREE_OPERAND (tmp_addr, 0);
5286       my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146);
5287       tmp = TREE_OPERAND (tmp_addr, 0);
5288     }
5289   else
5290     {
5291       tmp = get_temp_name (target_type,
5292                            current_binding_level == global_binding_level);
5293       tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
5294     }
5295
5296   TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
5297   DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr);
5298   TREE_TYPE (DECL_INITIAL (decl)) = type;
5299   if (TYPE_NEEDS_CONSTRUCTING (target_type))
5300     {
5301       if (current_binding_level == global_binding_level)
5302         {
5303           /* lay this variable out now.  Otherwise `output_addressed_constants'
5304              gets confused by its initializer.  */
5305           make_decl_rtl (tmp, NULL_PTR, 1);
5306           static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
5307         }
5308       else
5309         {
5310           if (ctor_call != NULL_TREE)
5311             init = ctor_call;
5312           else
5313             init = build_method_call (tmp, constructor_name_full (target_type),
5314                                       build_tree_list (NULL_TREE, init),
5315                                       NULL_TREE, LOOKUP_NORMAL);
5316           DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
5317                                        DECL_INITIAL (decl));
5318           *cleanupp = maybe_build_cleanup (tmp);
5319         }
5320     }
5321   else
5322     {
5323       DECL_INITIAL (tmp) = init;
5324       TREE_STATIC (tmp) = current_binding_level == global_binding_level;
5325       finish_decl (tmp, init, 0, 0);
5326     }
5327   if (TREE_STATIC (tmp))
5328     preserve_initializer ();
5329 }
5330
5331 /* Handle initialization of references.
5332    These three arguments from from `finish_decl', and have the
5333    same meaning here that they do there.  */
5334 /* quotes on semantics can be found in ARM 8.4.3. */
5335 static void
5336 grok_reference_init (decl, type, init, cleanupp)
5337      tree decl, type, init;
5338      tree *cleanupp;
5339 {
5340   char *errstr = NULL;
5341   int is_reference;
5342   tree tmp;
5343   tree this_ptr_type, actual_init = NULL_TREE;
5344
5345   if (init == NULL_TREE)
5346     {
5347       if (DECL_LANG_SPECIFIC (decl) == 0
5348           || DECL_IN_AGGR_P (decl) == 0)
5349         {
5350           cp_error ("`%D' declared as reference but not initialized", decl);
5351           if (TREE_CODE (decl) == VAR_DECL)
5352             SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
5353         }
5354       return;
5355     }
5356
5357   if (init == error_mark_node)
5358     return;
5359
5360   if (TREE_CODE (type) == REFERENCE_TYPE
5361       && TREE_CODE (init) == CONSTRUCTOR)
5362     {
5363       cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
5364       return;
5365     }
5366
5367   if (TREE_CODE (init) == TREE_LIST)
5368     init = build_compound_expr (init);
5369   is_reference = TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE;
5370   tmp = is_reference ? convert_from_reference (init) : init;
5371
5372   if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
5373       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
5374     {
5375       /* Note: default conversion is only called in very
5376          special cases.  */
5377       init = default_conversion (init);
5378     }
5379
5380   /* Can we just enreference this lvalue?  */
5381   if ((is_reference || lvalue_p (init)
5382        || (actual_init = unary_complex_lvalue (ADDR_EXPR, init)))
5383       && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
5384                     TYPE_MAIN_VARIANT (TREE_TYPE (tmp)), 0))
5385     {
5386       /* This section implements ANSI C++ June 5 1992 WP 8.4.3.5. */
5387
5388       /* A reference to a volatile T cannot be initialized with
5389          a const T, and vice-versa.  */
5390       if (TYPE_VOLATILE (TREE_TYPE (type)) && TREE_READONLY (init))
5391         errstr = "cannot initialize a reference to a volatile `%T' with a const `%T'";
5392       else if (TYPE_READONLY (TREE_TYPE (type)) && TREE_THIS_VOLATILE (init))
5393         errstr = "cannot initialize a reference to a const `%T' with a volatile `%T'";
5394       /* A reference to a plain T can be initialized only with a plain T. */
5395       else if (!TYPE_VOLATILE (TREE_TYPE (type))
5396                && !TYPE_READONLY (TREE_TYPE (type)))
5397         {
5398           if (TREE_READONLY (init))
5399             errstr = "cannot initialize a reference to `%T' with a const `%T'";
5400           else if (TREE_THIS_VOLATILE (init))
5401             errstr = "cannot initialize a reference to `%T' with a volatile `%T'";
5402         }
5403       if (errstr)
5404         {
5405           cp_error (errstr, TREE_TYPE (type), TREE_TYPE (tmp));
5406           goto fail;
5407         }
5408     }
5409   /* OK, can we generate a reference then?  */
5410   else if ((actual_init = convert_to_reference
5411             (decl, type, init, 0, 0, "initialization", 0,
5412              LOOKUP_SPECULATIVELY|LOOKUP_NORMAL)))
5413     {
5414       if (actual_init == error_mark_node)
5415         goto fail;
5416
5417       init = actual_init;
5418       is_reference = 1;
5419     }
5420   /* OK, try going through a temporary.  */
5421   else if ((actual_init = convert_to_reference
5422             (error_mark_node, type, init, 0, 0, "initialization",
5423              0, LOOKUP_NORMAL)))
5424     {
5425       if (actual_init == error_mark_node)
5426         goto fail;
5427       
5428       init = actual_init;
5429       is_reference = 1;
5430
5431       if (TREE_CODE (init) == WITH_CLEANUP_EXPR)
5432         {
5433           /* Associate the cleanup with the reference so that we
5434              don't get burned by "aggressive" cleanup policy.  */
5435           *cleanupp = TREE_OPERAND (init, 2);
5436           TREE_OPERAND (init, 2) = error_mark_node;
5437         }
5438     }
5439   else
5440     {
5441       cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
5442       goto fail;
5443     }
5444
5445   /* In the case of initialization, it is permissible
5446      to assign one reference to another.  */
5447   this_ptr_type = build_pointer_type (TREE_TYPE (type));
5448
5449   if (is_reference)
5450     {
5451       if (TREE_SIDE_EFFECTS (init))
5452         DECL_INITIAL (decl) = save_expr (init);
5453       else
5454         DECL_INITIAL (decl) = init;
5455     }
5456   else if (lvalue_p (init))
5457     {
5458       tmp = build_unary_op (ADDR_EXPR, init, 0);
5459       if (TREE_CODE (tmp) == ADDR_EXPR
5460           && TREE_CODE (TREE_OPERAND (tmp, 0)) == WITH_CLEANUP_EXPR)
5461         {
5462           if (*cleanupp) my_friendly_abort (1);
5463           *cleanupp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 2);
5464           TREE_OPERAND (TREE_OPERAND (tmp, 0), 2) = error_mark_node;
5465         }
5466       if (IS_AGGR_TYPE (TREE_TYPE (this_ptr_type)))
5467         DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), tmp);
5468       else
5469         DECL_INITIAL (decl) = convert (this_ptr_type, tmp);
5470
5471       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
5472       if (DECL_INITIAL (decl) == current_class_decl)
5473         DECL_INITIAL (decl) = copy_node (current_class_decl);
5474       TREE_TYPE (DECL_INITIAL (decl)) = type;
5475     }
5476   /* If actual_init is set here, it is set from the first check above.  */
5477   else if (actual_init)
5478     {
5479       /* The initializer for this decl goes into its
5480          DECL_REFERENCE_SLOT.  Make sure that we can handle
5481          multiple evaluations without ill effect.  */
5482       if (TREE_CODE (actual_init) == ADDR_EXPR
5483           && TREE_CODE (TREE_OPERAND (actual_init, 0)) == TARGET_EXPR)
5484         actual_init = save_expr (actual_init);
5485       DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), actual_init);
5486       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
5487       TREE_TYPE (DECL_INITIAL (decl)) = type;
5488     }
5489   else
5490     my_friendly_abort (1);
5491
5492  done:
5493   /* ?? Can this be optimized in some cases to
5494      hand back the DECL_INITIAL slot??  */
5495   if (TYPE_SIZE (TREE_TYPE (type)))
5496     {
5497       init = convert_from_reference (decl);
5498       if (TREE_PERMANENT (decl))
5499         init = copy_to_permanent (init);
5500       SET_DECL_REFERENCE_SLOT (decl, init);
5501     }
5502
5503   if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
5504     {
5505       expand_static_init (decl, DECL_INITIAL (decl));
5506       DECL_INITIAL (decl) = NULL_TREE;
5507     }
5508   return;
5509
5510  fail:
5511   if (TREE_CODE (decl) == VAR_DECL)
5512     SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
5513   return;
5514 }
5515
5516 /* Finish processing of a declaration;
5517    install its line number and initial value.
5518    If the length of an array type is not known before,
5519    it must be determined now, from the initial value, or it is an error.
5520
5521    Call `pop_obstacks' iff NEED_POP is nonzero.
5522
5523    For C++, `finish_decl' must be fairly evasive:  it must keep initializers
5524    for aggregates that have constructors alive on the permanent obstack,
5525    so that the global initializing functions can be written at the end.
5526
5527    INIT0 holds the value of an initializer that should be allowed to escape
5528    the normal rules.
5529
5530    For functions that take default parameters, DECL points to its
5531    "maximal" instantiation.  `finish_decl' must then also declared its
5532    subsequently lower and lower forms of instantiation, checking for
5533    ambiguity as it goes.  This can be sped up later.  */
5534
5535 void
5536 finish_decl (decl, init, asmspec_tree, need_pop)
5537      tree decl, init;
5538      tree asmspec_tree;
5539      int need_pop;
5540 {
5541   register tree type;
5542   tree cleanup = NULL_TREE, ttype;
5543   int was_incomplete;
5544   int temporary = allocation_temporary_p ();
5545   char *asmspec = NULL;
5546   int was_readonly = 0;
5547
5548   /* If this is 0, then we did not change obstacks.  */
5549   if (! decl)
5550     {
5551       if (init)
5552         error ("assignment (not initialization) in declaration");
5553       return;
5554     }
5555
5556   if (asmspec_tree)
5557     {
5558       asmspec = TREE_STRING_POINTER (asmspec_tree);
5559       /* Zero out old RTL, since we will rewrite it.  */
5560       DECL_RTL (decl) = NULL_RTX;
5561     }
5562
5563   /* If the type of the thing we are declaring either has
5564      a constructor, or has a virtual function table pointer,
5565      AND its initialization was accepted by `start_decl',
5566      then we stayed on the permanent obstack through the
5567      declaration, otherwise, changed obstacks as GCC would.  */
5568
5569   type = TREE_TYPE (decl);
5570
5571   was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
5572
5573   /* Take care of TYPE_DECLs up front.  */
5574   if (TREE_CODE (decl) == TYPE_DECL)
5575     {
5576       if (init && DECL_INITIAL (decl))
5577         {
5578           /* typedef foo = bar; store the type of bar as the type of foo.  */
5579           TREE_TYPE (decl) = type = TREE_TYPE (init);
5580           DECL_INITIAL (decl) = init = NULL_TREE;
5581         }
5582       if (IS_AGGR_TYPE (type) && DECL_NAME (decl))
5583         {
5584           if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
5585             cp_warning ("shadowing previous type declaration of `%#D'", decl);
5586           set_identifier_type_value (DECL_NAME (decl), type);
5587           CLASSTYPE_GOT_SEMICOLON (type) = 1;
5588         }
5589       GNU_xref_decl (current_function_decl, decl);
5590       rest_of_decl_compilation (decl, NULL_PTR,
5591                                 DECL_CONTEXT (decl) == NULL_TREE, 0);
5592       goto finish_end;
5593     }
5594   if (type != error_mark_node && IS_AGGR_TYPE (type)
5595       && CLASSTYPE_DECLARED_EXCEPTION (type))
5596     {
5597       finish_exception_decl (NULL_TREE, decl);
5598       CLASSTYPE_GOT_SEMICOLON (type) = 1;
5599       goto finish_end;
5600     }
5601   if (TREE_CODE (decl) != FUNCTION_DECL)
5602     {
5603       ttype = target_type (type);
5604 #if 0 /* WTF?  -KR
5605          Leave this out until we can figure out why it was
5606          needed/desirable in the first place.  Then put a comment
5607          here explaining why.  Or just delete the code if no ill
5608          effects arise.  */
5609       if (TYPE_NAME (ttype)
5610           && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
5611           && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
5612         {
5613           tree old_id = TYPE_IDENTIFIER (ttype);
5614           char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
5615           /* Need to preserve template data for UPT nodes.  */
5616           tree old_template = IDENTIFIER_TEMPLATE (old_id);
5617           newname[0] = '_';
5618           bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
5619                  IDENTIFIER_LENGTH (old_id) + 1);
5620           old_id = get_identifier (newname);
5621           lookup_tag_reverse (ttype, old_id);
5622           TYPE_IDENTIFIER (ttype) = old_id;
5623           IDENTIFIER_TEMPLATE (old_id) = old_template;
5624         }
5625 #endif
5626     }
5627
5628   if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
5629       && TYPE_NEEDS_CONSTRUCTING (type))
5630     {
5631
5632       /* Currently, GNU C++ puts constants in text space, making them
5633          impossible to initialize.  In the future, one would hope for
5634          an operating system which understood the difference between
5635          initialization and the running of a program.  */
5636       was_readonly = 1;
5637       TREE_READONLY (decl) = 0;
5638     }
5639
5640   if (TREE_CODE (decl) == FIELD_DECL)
5641     {
5642       if (init && init != error_mark_node)
5643         my_friendly_assert (TREE_PERMANENT (init), 147);
5644
5645       if (asmspec)
5646         {
5647           /* This must override the asm specifier which was placed
5648              by grokclassfn.  Lay this out fresh.
5649              
5650              @@ Should emit an error if this redefines an asm-specified
5651              @@ name, or if we have already used the function's name.  */
5652           DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
5653           DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
5654           make_decl_rtl (decl, asmspec, 0);
5655         }
5656     }
5657   /* If `start_decl' didn't like having an initialization, ignore it now.  */
5658   else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
5659     init = NULL_TREE;
5660   else if (DECL_EXTERNAL (decl))
5661     ;
5662   else if (TREE_CODE (type) == REFERENCE_TYPE
5663            || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
5664     {
5665       grok_reference_init (decl, type, init, &cleanup);
5666       init = NULL_TREE;
5667     }
5668
5669   GNU_xref_decl (current_function_decl, decl);
5670
5671   if (TREE_CODE (decl) == FIELD_DECL || DECL_EXTERNAL (decl))
5672     ;
5673   else if (TREE_CODE (decl) == CONST_DECL)
5674     {
5675       my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
5676
5677       DECL_INITIAL (decl) = init;
5678
5679       /* This will keep us from needing to worry about our obstacks.  */
5680       my_friendly_assert (init != NULL_TREE, 149);
5681       init = NULL_TREE;
5682     }
5683   else if (init)
5684     {
5685       if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
5686         {
5687           if (TREE_CODE (type) == ARRAY_TYPE)
5688             init = digest_init (type, init, (tree *) 0);
5689           else if (TREE_CODE (init) == CONSTRUCTOR
5690                    && CONSTRUCTOR_ELTS (init) != NULL_TREE)
5691             {
5692               if (TYPE_NEEDS_CONSTRUCTING (type))
5693                 {
5694                   cp_error ("`%D' must be initialized by constructor, not by `{...}'", decl);
5695                   init = error_mark_node;
5696                 }
5697               else
5698                 goto dont_use_constructor;
5699             }
5700 #if 0
5701           /* fix this in `build_functional_cast' instead.
5702              Here's the trigger code:
5703
5704                 struct ostream
5705                 {
5706                   ostream ();
5707                   ostream (int, char *);
5708                   ostream (char *);
5709                   operator char *();
5710                   ostream (void *);
5711                   operator void *();
5712                   operator << (int);
5713                 };
5714                 int buf_size = 1024;
5715                 static char buf[buf_size];
5716                 const char *debug(int i) {
5717                   char *b = &buf[0];
5718                   ostream o = ostream(buf_size, b);
5719                   o << i;
5720                   return buf;
5721                 }
5722                 */
5723
5724           else if (TREE_CODE (init) == TARGET_EXPR
5725                    && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR))
5726             {
5727               /* User wrote something like `foo x = foo (args)'  */
5728               my_friendly_assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL, 150);
5729               my_friendly_assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE, 151);
5730
5731               /* User wrote exactly `foo x = foo (args)'  */
5732               if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init))
5733                 {
5734                   init = build (CALL_EXPR, TREE_TYPE (init),
5735                                 TREE_OPERAND (TREE_OPERAND (init, 1), 0),
5736                                 TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0);
5737                   TREE_SIDE_EFFECTS (init) = 1;
5738                 }
5739             }
5740 #endif
5741
5742           /* We must hide the initializer so that expand_decl
5743              won't try to do something it does not understand.  */
5744           if (current_binding_level == global_binding_level)
5745             {
5746               tree value;
5747               if (flag_conserve_space)
5748                 /* If we say -fconserve-space, we want this to save
5749                    space, at the expense of wrong semantics. */
5750                 /* Should this be a NULL_TREE? */
5751                 value = error_mark_node;
5752               else
5753                 /* If we say -fno-conserve-space, we want this to
5754                    produce errors about redefs, to do this we make it
5755                    go in the data space */
5756                 value = digest_init (type, empty_init_node, (tree *) 0);
5757               DECL_INITIAL (decl) = value;
5758             }
5759           else
5760             DECL_INITIAL (decl) = error_mark_node;
5761         }
5762       else
5763         {
5764         dont_use_constructor:
5765           if (TREE_CODE (init) != TREE_VEC)
5766             init = store_init_value (decl, init);
5767
5768           if (init)
5769             /* Don't let anyone try to initialize this variable
5770                until we are ready to do so.  */
5771             DECL_INITIAL (decl) = error_mark_node;
5772         }
5773     }
5774   else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
5775            && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
5776     {
5777       tree ctype = type;
5778       while (TREE_CODE (ctype) == ARRAY_TYPE)
5779         ctype = TREE_TYPE (ctype);
5780       if (! TYPE_NEEDS_CONSTRUCTING (ctype))
5781         {
5782           if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
5783             cp_error ("structure `%D' with uninitialized const members", decl);
5784           if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
5785             cp_error ("structure `%D' with uninitialized reference members", decl);
5786         }
5787
5788       if (TREE_CODE (decl) == VAR_DECL
5789           && !DECL_INITIAL (decl)
5790           && !TYPE_NEEDS_CONSTRUCTING (type)
5791           && (TYPE_READONLY (type) || TREE_READONLY (decl)))
5792         cp_error ("uninitialized const `%D'", decl);
5793
5794       /* Initialize variables in need of static initialization
5795          with `empty_init_node' to keep assemble_variable from putting them
5796          in the wrong program space.  (Common storage is okay for non-public
5797          uninitialized data; the linker can't match it with storage from other
5798          files, and we may save some disk space.)  */
5799       if (flag_pic == 0
5800           && TREE_STATIC (decl)
5801           && TREE_PUBLIC (decl)
5802           && ! DECL_EXTERNAL (decl)
5803           && TREE_CODE (decl) == VAR_DECL
5804           && TYPE_NEEDS_CONSTRUCTING (type)
5805           && (DECL_INITIAL (decl) == NULL_TREE
5806               || DECL_INITIAL (decl) == error_mark_node)
5807           /* If we say -fconserve-space, we want this to save space,
5808              at the expense of wrong semantics. */
5809           && ! flag_conserve_space)
5810         {
5811           tree value = digest_init (type, empty_init_node, (tree *) 0);
5812           DECL_INITIAL (decl) = value;
5813         }
5814     }
5815   else if (TREE_CODE (decl) == VAR_DECL
5816            && TREE_CODE (type) != REFERENCE_TYPE
5817            && (TYPE_READONLY (type) || TREE_READONLY (decl)))
5818     {
5819       /* ``Unless explicitly declared extern, a const object does not have
5820          external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
5821          However, if it's `const int foo = 1; const int foo;', don't complain
5822          about the second decl, since it does have an initializer before.
5823          We deliberately don't complain about arrays, because they're
5824          supposed to be initialized by a constructor.  */
5825       if (! DECL_INITIAL (decl)
5826           && TREE_CODE (type) != ARRAY_TYPE
5827           && (!pedantic || !current_class_type))
5828         cp_error ("uninitialized const `%#D'", decl);
5829     }
5830
5831   /* For top-level declaration, the initial value was read in
5832      the temporary obstack.  MAXINDEX, rtl, etc. to be made below
5833      must go in the permanent obstack; but don't discard the
5834      temporary data yet.  */
5835
5836   if (current_binding_level == global_binding_level && temporary)
5837     end_temporary_allocation ();
5838
5839   /* Deduce size of array from initialization, if not already known.  */
5840
5841   if (TREE_CODE (type) == ARRAY_TYPE
5842       && TYPE_DOMAIN (type) == NULL_TREE
5843       && TREE_CODE (decl) != TYPE_DECL)
5844     {
5845       int do_default
5846         = (TREE_STATIC (decl)
5847            /* Even if pedantic, an external linkage array
5848               may have incomplete type at first.  */
5849            ? pedantic && ! DECL_EXTERNAL (decl)
5850            : !DECL_EXTERNAL (decl));
5851       tree initializer = init ? init : DECL_INITIAL (decl);
5852       int failure = complete_array_type (type, initializer, do_default);
5853
5854       if (failure == 1)
5855         cp_error ("initializer fails to determine size of `%D'", decl);
5856
5857       if (failure == 2)
5858         {
5859           if (do_default)
5860             cp_error ("array size missing in `%D'", decl);
5861           /* If a `static' var's size isn't known, make it extern as
5862              well as static, so it does not get allocated.  If it's not
5863              `static', then don't mark it extern; finish_incomplete_decl
5864              will give it a default size and it will get allocated.  */
5865           else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
5866             DECL_EXTERNAL (decl) = 1;
5867         }
5868
5869       if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
5870           && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
5871                               integer_zero_node))
5872         cp_error ("zero-size array `%D'", decl);
5873
5874       layout_decl (decl, 0);
5875     }
5876
5877   if (TREE_CODE (decl) == VAR_DECL)
5878     {
5879       if (DECL_SIZE (decl) == NULL_TREE
5880           && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
5881         layout_decl (decl, 0);
5882
5883       if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
5884         {
5885           /* A static variable with an incomplete type:
5886              that is an error if it is initialized.
5887              Otherwise, let it through, but if it is not `extern'
5888              then it may cause an error message later.  */
5889           if (DECL_INITIAL (decl) != NULL_TREE)
5890             cp_error ("storage size of `%D' isn't known", decl);
5891           init = NULL_TREE;
5892         }
5893       else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
5894         {
5895           /* An automatic variable with an incomplete type: that is an error.
5896              Don't talk about array types here, since we took care of that
5897              message in grokdeclarator.  */
5898           cp_error ("storage size of `%D' isn't known", decl);
5899           TREE_TYPE (decl) = error_mark_node;
5900         }
5901       else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
5902         /* Let debugger know it should output info for this type.  */
5903         note_debug_info_needed (ttype);
5904
5905       if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
5906           && DECL_SIZE (decl) != NULL_TREE
5907           && ! TREE_CONSTANT (DECL_SIZE (decl)))
5908         {
5909           if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
5910             constant_expression_warning (DECL_SIZE (decl));
5911           else
5912             cp_error ("storage size of `%D' isn't constant", decl);
5913         }
5914
5915       if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
5916         {
5917           int yes = suspend_momentary ();
5918
5919           /* If INIT comes from a functional cast, use the cleanup
5920              we built for that.  Otherwise, make our own cleanup.  */
5921           if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
5922               && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
5923             {
5924               cleanup = TREE_OPERAND (init, 2);
5925               init = TREE_OPERAND (init, 0);
5926               current_binding_level->have_cleanups = 1;
5927               current_binding_level->more_exceptions_ok = 0;
5928             }
5929           else
5930             cleanup = maybe_build_cleanup (decl);
5931           resume_momentary (yes);
5932         }
5933     }
5934   /* PARM_DECLs get cleanups, too.  */
5935   else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
5936     {
5937       if (temporary)
5938         end_temporary_allocation ();
5939       cleanup = maybe_build_cleanup (decl);
5940       if (temporary)
5941         resume_temporary_allocation ();
5942     }
5943
5944   /* Output the assembler code and/or RTL code for variables and functions,
5945      unless the type is an undefined structure or union.
5946      If not, it will get done when the type is completed.  */
5947
5948   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
5949       || TREE_CODE (decl) == RESULT_DECL)
5950     {
5951       /* ??? FIXME: What about nested classes?  */
5952       int toplev = (current_binding_level == global_binding_level
5953                     || pseudo_global_level_p ());
5954       int was_temp
5955         = ((flag_traditional
5956             || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
5957            && allocation_temporary_p ());
5958
5959       if (was_temp)
5960         end_temporary_allocation ();
5961
5962       /* If we are in need of a cleanup, get out of any implicit
5963          handlers that have been established so far.  */
5964       if (cleanup && current_binding_level->parm_flag == 3)
5965         {
5966           pop_implicit_try_blocks (decl);
5967           current_binding_level->more_exceptions_ok = 0;
5968         }
5969
5970       if (TREE_CODE (decl) == VAR_DECL
5971           && current_binding_level != global_binding_level
5972           && ! TREE_STATIC (decl)
5973           && type_needs_gc_entry (type))
5974         DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
5975
5976       if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
5977         make_decl_rtl (decl, NULL_PTR, toplev);
5978       else if (TREE_CODE (decl) == VAR_DECL
5979                && TREE_READONLY (decl)
5980                && DECL_INITIAL (decl) != NULL_TREE
5981                && DECL_INITIAL (decl) != error_mark_node
5982                && DECL_INITIAL (decl) != empty_init_node)
5983         {
5984           DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
5985
5986           if (asmspec)
5987             DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
5988
5989           if (! toplev
5990               && TREE_STATIC (decl)
5991               && ! TREE_SIDE_EFFECTS (decl)
5992               && ! TREE_PUBLIC (decl)
5993               && ! DECL_EXTERNAL (decl)
5994               && ! TYPE_NEEDS_DESTRUCTOR (type)
5995               && DECL_MODE (decl) != BLKmode)
5996             {
5997               /* If this variable is really a constant, then fill its DECL_RTL
5998                  slot with something which won't take up storage.
5999                  If something later should take its address, we can always give
6000                  it legitimate RTL at that time.  */
6001               DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
6002               store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
6003               TREE_ASM_WRITTEN (decl) = 1;
6004             }
6005           else if (toplev)
6006             {
6007               /* Keep GCC from complaining that this variable
6008                  is defined but never used.  */
6009               TREE_USED (decl) = 1;
6010               /* If this is a static const, change its apparent linkage
6011                  if it belongs to a #pragma interface.  */
6012               if (TREE_STATIC (decl) && !interface_unknown)
6013                 {
6014                   TREE_PUBLIC (decl) = 1;
6015                   DECL_EXTERNAL (decl) = interface_only;
6016                 }
6017               make_decl_rtl (decl, asmspec, toplev);
6018             }
6019           else
6020             rest_of_decl_compilation (decl, asmspec, toplev, 0);
6021         }
6022       else if (TREE_CODE (decl) == VAR_DECL
6023                && DECL_LANG_SPECIFIC (decl)
6024                && DECL_IN_AGGR_P (decl))
6025         {
6026           if (TREE_STATIC (decl))
6027             {
6028               if (init == NULL_TREE
6029 #ifdef DEFAULT_STATIC_DEFS
6030                   /* If this code is dead, then users must
6031                      explicitly declare static member variables
6032                      outside the class def'n as well.  */
6033                   && TYPE_NEEDS_CONSTRUCTING (type)
6034 #endif
6035                   )
6036                 {
6037                   DECL_EXTERNAL (decl) = 1;
6038                   make_decl_rtl (decl, asmspec, 1);
6039                 }
6040               else
6041                 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6042             }
6043           else
6044             /* Just a constant field.  Should not need any rtl.  */
6045             goto finish_end0;
6046         }
6047       else
6048         rest_of_decl_compilation (decl, asmspec, toplev, 0);
6049
6050       if (was_temp)
6051         resume_temporary_allocation ();
6052
6053       if (type != error_mark_node
6054           && TYPE_LANG_SPECIFIC (type)
6055           && CLASSTYPE_ABSTRACT_VIRTUALS (type))
6056         abstract_virtuals_error (decl, type);
6057       else if ((TREE_CODE (type) == FUNCTION_TYPE
6058                 || TREE_CODE (type) == METHOD_TYPE)
6059                && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6060                && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
6061         abstract_virtuals_error (decl, TREE_TYPE (type));
6062
6063       if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
6064         signature_error (decl, type);
6065       else if ((TREE_CODE (type) == FUNCTION_TYPE
6066                 || TREE_CODE (type) == METHOD_TYPE)
6067                && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6068                && IS_SIGNATURE (TREE_TYPE (type)))
6069         signature_error (decl, TREE_TYPE (type));
6070
6071       if (TREE_CODE (decl) == FUNCTION_DECL)
6072         {
6073           /* C++: Handle overloaded functions with default parameters.  */
6074           if (DECL_OVERLOADED (decl))
6075             {
6076               tree parmtypes = TYPE_ARG_TYPES (type);
6077               tree prev = NULL_TREE;
6078               tree original_name = DECL_NAME (decl);
6079               struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl);
6080               /* All variants will share an uncollectible lang_decl.  */
6081               copy_decl_lang_specific (decl);
6082
6083               while (parmtypes && parmtypes != void_list_node)
6084                 {
6085                   /* The default value for the parameter in parmtypes is
6086                      stored in the TREE_PURPOSE of the TREE_LIST.  */ 
6087                   if (TREE_PURPOSE (parmtypes))
6088                     {
6089                       tree fnname, fndecl;
6090                       tree *argp;
6091
6092                       argp = prev ? & TREE_CHAIN (prev)
6093                         : & TYPE_ARG_TYPES (type);
6094
6095                       *argp = NULL_TREE;
6096                       fnname = build_decl_overload (original_name, TYPE_ARG_TYPES (type), 0);
6097                       *argp = parmtypes;
6098                       fndecl = build_decl (FUNCTION_DECL, fnname, type);
6099                       DECL_EXTERNAL (fndecl) = DECL_EXTERNAL (decl);
6100                       TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl);
6101                       DECL_INLINE (fndecl) = DECL_INLINE (decl);
6102                       /* Keep G++ from thinking this function is unused.
6103                          It is only used to speed up search in name space.  */
6104                       TREE_USED (fndecl) = 1;
6105                       TREE_ASM_WRITTEN (fndecl) = 1;
6106                       DECL_INITIAL (fndecl) = NULL_TREE;
6107                       DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl);
6108                       fndecl = pushdecl (fndecl);
6109                       DECL_INITIAL (fndecl) = error_mark_node;
6110                       DECL_RTL (fndecl) = DECL_RTL (decl);
6111                     }
6112                   prev = parmtypes;
6113                   parmtypes = TREE_CHAIN (parmtypes);
6114                 }
6115               DECL_LANG_SPECIFIC (decl) = tmp_lang_decl;
6116             }
6117         }
6118       else if (DECL_EXTERNAL (decl))
6119         ;
6120       else if (TREE_STATIC (decl) && type != error_mark_node)
6121         {
6122           /* Cleanups for static variables are handled by `finish_file'.  */
6123           if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE)
6124             expand_static_init (decl, init);
6125           else if (TYPE_NEEDS_DESTRUCTOR (type))
6126             static_aggregates = perm_tree_cons (NULL_TREE, decl,
6127                                                 static_aggregates);
6128
6129           /* Make entry in appropriate vector.  */
6130           if (flag_gc && type_needs_gc_entry (type))
6131             build_static_gc_entry (decl, type);
6132         }
6133       else if (! toplev)
6134         {
6135           /* This is a declared decl which must live until the
6136              end of the binding contour.  It may need a cleanup.  */
6137
6138           /* Recompute the RTL of a local array now
6139              if it used to be an incomplete type.  */
6140           if (was_incomplete && ! TREE_STATIC (decl))
6141             {
6142               /* If we used it already as memory, it must stay in memory.  */
6143               TREE_ADDRESSABLE (decl) = TREE_USED (decl);
6144               /* If it's still incomplete now, no init will save it.  */
6145               if (DECL_SIZE (decl) == NULL_TREE)
6146                 DECL_INITIAL (decl) = NULL_TREE;
6147               expand_decl (decl);
6148             }
6149           else if (! TREE_ASM_WRITTEN (decl)
6150                    && (TYPE_SIZE (type) != NULL_TREE
6151                        || TREE_CODE (type) == ARRAY_TYPE))
6152             {
6153               /* Do this here, because we did not expand this decl's
6154                  rtl in start_decl.  */
6155               if (DECL_RTL (decl) == NULL_RTX)
6156                 expand_decl (decl);
6157               else if (cleanup)
6158                 {
6159                   expand_decl_cleanup (NULL_TREE, cleanup);
6160                   /* Cleanup used up here.  */
6161                   cleanup = NULL_TREE;
6162                 }
6163             }
6164
6165           if (DECL_SIZE (decl) && type != error_mark_node)
6166             {
6167               /* Compute and store the initial value.  */
6168               expand_decl_init (decl);
6169
6170               if (init || TYPE_NEEDS_CONSTRUCTING (type))
6171                 {
6172                   emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
6173                   expand_aggr_init (decl, init, 0);
6174                 }
6175
6176               /* Set this to 0 so we can tell whether an aggregate
6177                  which was initialized was ever used.  */
6178               if (TYPE_NEEDS_CONSTRUCTING (type))
6179                 TREE_USED (decl) = 0;
6180
6181               /* Store the cleanup, if there was one.  */
6182               if (cleanup)
6183                 {
6184                   if (! expand_decl_cleanup (decl, cleanup))
6185                     cp_error ("parser lost in parsing declaration of `%D'", decl);
6186                 }
6187             }
6188         }
6189     finish_end0:
6190
6191       /* Undo call to `pushclass' that was done in `start_decl'
6192          due to initialization of qualified member variable.
6193          I.e., Foo::x = 10;  */
6194       {
6195         tree context = DECL_CONTEXT (decl);
6196         if (context
6197             && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
6198             && (TREE_CODE (decl) == VAR_DECL
6199                 /* We also have a pushclass done that we need to undo here
6200                    if we're at top level and declare a method.  */
6201                 || (TREE_CODE (decl) == FUNCTION_DECL
6202                     /* If size hasn't been set, we're still defining it,
6203                        and therefore inside the class body; don't pop
6204                        the binding level..  */
6205                     && TYPE_SIZE (context) != NULL_TREE
6206                     /* The binding level gets popped elsewhere for a
6207                        friend declaration inside another class.  */
6208                     /*
6209                     && TYPE_IDENTIFIER (context) == current_class_name
6210                     */
6211                     && context == current_class_type
6212                     )))
6213           popclass (1);
6214       }
6215     }
6216
6217  finish_end:
6218
6219   if (need_pop)
6220     {
6221       /* Resume permanent allocation, if not within a function.  */
6222       /* The corresponding push_obstacks_nochange is in start_decl,
6223          start_method, groktypename, and in grokfield.  */
6224       pop_obstacks ();
6225     }
6226
6227   if (was_readonly)
6228     TREE_READONLY (decl) = 1;
6229
6230   if (flag_cadillac)
6231     cadillac_finish_decl (decl);
6232 }
6233
6234 void
6235 expand_static_init (decl, init)
6236      tree decl;
6237      tree init;
6238 {
6239   tree oldstatic = value_member (decl, static_aggregates);
6240   if (oldstatic)
6241     {
6242       if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
6243         cp_error ("multiple initializations given for `%D'", decl);
6244     }
6245   else if (current_binding_level != global_binding_level)
6246     {
6247       /* Emit code to perform this initialization but once.  */
6248       tree temp;
6249
6250       /* Remember this information until end of file. */
6251       push_obstacks (&permanent_obstack, &permanent_obstack);
6252
6253       /* Emit code to perform this initialization but once.  */
6254       temp = get_temp_name (integer_type_node, 1);
6255       rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
6256       expand_start_cond (build_binary_op (EQ_EXPR, temp,
6257                                           integer_zero_node, 1), 0);
6258       expand_assignment (temp, integer_one_node, 0, 0);
6259       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6260         {
6261           expand_aggr_init (decl, init, 0);
6262           do_pending_stack_adjust ();
6263         }
6264       else
6265         expand_assignment (decl, init, 0, 0);
6266       expand_end_cond ();
6267       if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
6268         {
6269           static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
6270           TREE_STATIC (static_aggregates) = 1;
6271         }
6272
6273       /* Resume old (possibly temporary) allocation. */
6274       pop_obstacks ();
6275     }
6276   else
6277     {
6278       /* This code takes into account memory allocation
6279          policy of `start_decl'.  Namely, if TYPE_NEEDS_CONSTRUCTING
6280          does not hold for this object, then we must make permanent
6281          the storage currently in the temporary obstack.  */
6282       if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6283         preserve_initializer ();
6284       static_aggregates = perm_tree_cons (init, decl, static_aggregates);
6285     }
6286 }
6287 \f
6288 /* Make TYPE a complete type based on INITIAL_VALUE.
6289    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
6290    2 if there was no information (in which case assume 1 if DO_DEFAULT).  */
6291
6292 int
6293 complete_array_type (type, initial_value, do_default)
6294      tree type, initial_value;
6295      int do_default;
6296 {
6297   register tree maxindex = NULL_TREE;
6298   int value = 0;
6299
6300   if (initial_value)
6301     {
6302       /* Note MAXINDEX  is really the maximum index,
6303          one less than the size.  */
6304       if (TREE_CODE (initial_value) == STRING_CST)
6305         maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
6306       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
6307         {
6308           register int nelts
6309             = list_length (CONSTRUCTOR_ELTS (initial_value));
6310           maxindex = build_int_2 (nelts - 1, - (nelts == 0));
6311         }
6312       else
6313         {
6314           /* Make an error message unless that happened already.  */
6315           if (initial_value != error_mark_node)
6316             value = 1;
6317
6318           /* Prevent further error messages.  */
6319           maxindex = build_int_2 (0, 0);
6320         }
6321     }
6322
6323   if (!maxindex)
6324     {
6325       if (do_default)
6326         maxindex = build_int_2 (0, 0);
6327       value = 2;
6328     }
6329
6330   if (maxindex)
6331     {
6332       TYPE_DOMAIN (type) = build_index_type (maxindex);
6333       if (!TREE_TYPE (maxindex))
6334         TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
6335     }
6336
6337   /* Lay out the type now that we can get the real answer.  */
6338
6339   layout_type (type);
6340
6341   return value;
6342 }
6343 \f
6344 /* Return zero if something is declared to be a member of type
6345    CTYPE when in the context of CUR_TYPE.  STRING is the error
6346    message to print in that case.  Otherwise, quietly return 1.  */
6347 static int
6348 member_function_or_else (ctype, cur_type, string)
6349      tree ctype, cur_type;
6350      char *string;
6351 {
6352   if (ctype && ctype != cur_type)
6353     {
6354       error (string, TYPE_NAME_STRING (ctype));
6355       return 0;
6356     }
6357   return 1;
6358 }
6359 \f
6360 /* Subroutine of `grokdeclarator'.  */
6361
6362 /* Generate errors possibly applicable for a given set of specifiers.
6363    This is for ARM $7.1.2.  */
6364 static void
6365 bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
6366      tree object;
6367      char *type;
6368      int virtualp, quals, friendp, raises, inlinep;
6369 {
6370   if (virtualp)
6371     cp_error ("`%D' declared as a `virtual' %s", object, type);
6372   if (inlinep)
6373     cp_error ("`%D' declared as an `inline' %s", object, type);
6374   if (quals)
6375     cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", object, type);
6376   if (friendp)
6377     cp_error_at ("invalid friend declaration", object);
6378   if (raises)
6379     cp_error_at ("invalid raises declaration", object);
6380 }
6381
6382 /* CTYPE is class type, or null if non-class.
6383    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
6384    or METHOD_TYPE.
6385    DECLARATOR is the function's name.
6386    VIRTUALP is truthvalue of whether the function is virtual or not.
6387    FLAGS are to be passed through to `grokclassfn'.
6388    QUALS are qualifiers indicating whether the function is `const'
6389    or `volatile'.
6390    RAISES is a list of exceptions that this function can raise.
6391    CHECK is 1 if we must find this method in CTYPE, 0 if we should
6392    not look, and -1 if we should not call `grokclassfn' at all.  */
6393 static tree
6394 grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, check, publicp)
6395      tree ctype, type;
6396      tree declarator;
6397      int virtualp;
6398      enum overload_flags flags;
6399      tree quals, raises;
6400      int check, publicp;
6401 {
6402   tree cname, decl;
6403   int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
6404
6405   if (ctype)
6406     cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
6407       ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
6408   else
6409     cname = NULL_TREE;
6410
6411   if (raises)
6412     {
6413       type = build_exception_variant (ctype, type, raises);
6414       raises = TYPE_RAISES_EXCEPTIONS (type);
6415     }
6416   decl = build_lang_decl (FUNCTION_DECL, declarator, type);
6417   /* propagate volatile out from type to decl */
6418   if (TYPE_VOLATILE (type))
6419       TREE_THIS_VOLATILE (decl) = 1;
6420
6421   /* Should probably propagate const out from type to decl I bet (mrs).  */
6422   if (staticp)
6423     {
6424       DECL_STATIC_FUNCTION_P (decl) = 1;
6425       DECL_CONTEXT (decl) = ctype;
6426       DECL_CLASS_CONTEXT (decl) = ctype;
6427     }
6428
6429   if (publicp)
6430     TREE_PUBLIC (decl) = 1;
6431
6432   DECL_EXTERNAL (decl) = 1;
6433   if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
6434     {
6435       cp_error ("%smember function `%D' cannot have `%T' method qualifier",
6436                 (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
6437       quals = NULL_TREE;
6438     }
6439
6440   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
6441     grok_op_properties (decl, virtualp, check < 0);
6442
6443   /* Caller will do the rest of this.  */
6444   if (check < 0)
6445     return decl;
6446
6447   if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
6448     {
6449       tree tmp;
6450       /* Just handle constructors here.  We could do this
6451          inside the following if stmt, but I think
6452          that the code is more legible by breaking this
6453          case out.  See comments below for what each of
6454          the following calls is supposed to do.  */
6455       DECL_CONSTRUCTOR_P (decl) = 1;
6456
6457       grokclassfn (ctype, declarator, decl, flags, quals);
6458       if (check)
6459         check_classfn (ctype, declarator, decl);
6460       grok_ctor_properties (ctype, decl);
6461       if (check == 0)
6462         {
6463           /* FIXME: this should only need to look at IDENTIFIER_GLOBAL_VALUE.  */
6464           tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
6465           if (tmp == NULL_TREE)
6466             IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
6467           else if (TREE_CODE (tmp) != TREE_CODE (decl))
6468             cp_error ("inconsistent declarations for `%D'", decl);
6469           else
6470             {
6471               duplicate_decls (decl, tmp);
6472               decl = tmp;
6473               /* avoid creating circularities.  */
6474               DECL_CHAIN (decl) = NULL_TREE;
6475             }
6476           make_decl_rtl (decl, NULL_PTR, 1);
6477         }
6478     }
6479   else
6480     {
6481       tree tmp;
6482
6483       /* Function gets the ugly name, field gets the nice one.
6484          This call may change the type of the function (because
6485          of default parameters)!  */
6486       if (ctype != NULL_TREE)
6487         grokclassfn (ctype, cname, decl, flags, quals);
6488
6489       if (ctype != NULL_TREE && check)
6490         check_classfn (ctype, cname, decl);
6491
6492       if (ctype == NULL_TREE || check)
6493         return decl;
6494
6495       /* Now install the declaration of this function so that
6496          others may find it (esp. its DECL_FRIENDLIST).
6497          Pretend we are at top level, we will get true
6498          reference later, perhaps.
6499
6500          FIXME: This should only need to look at IDENTIFIER_GLOBAL_VALUE.  */
6501       tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
6502       if (tmp == NULL_TREE)
6503         IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
6504       else if (TREE_CODE (tmp) != TREE_CODE (decl))
6505         cp_error ("inconsistent declarations for `%D'", decl);
6506       else
6507         {
6508           duplicate_decls (decl, tmp);
6509           decl = tmp;
6510           /* avoid creating circularities.  */
6511           DECL_CHAIN (decl) = NULL_TREE;
6512         }
6513       make_decl_rtl (decl, NULL_PTR, 1);
6514
6515       /* If this declaration supersedes the declaration of
6516          a method declared virtual in the base class, then
6517          mark this field as being virtual as well.  */
6518       {
6519         tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
6520         int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
6521
6522         for (i = 0; i < n_baselinks; i++)
6523           {
6524             tree base_binfo = TREE_VEC_ELT (binfos, i);
6525             if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)) || flag_all_virtual == 1)
6526               {
6527                 tmp = get_first_matching_virtual (base_binfo, decl,
6528                                                   flags == DTOR_FLAG);
6529                 if (tmp)
6530                   {
6531                     /* If this function overrides some virtual in some base
6532                        class, then the function itself is also necessarily
6533                        virtual, even if the user didn't explicitly say so.  */
6534                     DECL_VIRTUAL_P (decl) = 1;
6535
6536                     /* The TMP we really want is the one from the deepest
6537                        baseclass on this path, taking care not to
6538                        duplicate if we have already found it (via another
6539                        path to its virtual baseclass.  */
6540                     if (staticp)
6541                       {
6542                         cp_error ("method `%D' may not be declared static", decl);
6543                         cp_error_at ("(since `%D' declared virtual in base class.)", tmp);
6544                         break;
6545                       }
6546                     virtualp = 1;
6547
6548 #if 0
6549                     /* Disable this as we want the most recent fndecl, not the most
6550                        base fndecl. */
6551                     if ((TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (base_binfo))
6552                          || TYPE_USES_MULTIPLE_INHERITANCE (ctype))
6553                         && BINFO_TYPE (base_binfo) != DECL_CONTEXT (tmp))
6554                       tmp = get_first_matching_virtual (TYPE_BINFO (DECL_CONTEXT (tmp)),
6555                                                         decl, flags == DTOR_FLAG);
6556 #endif
6557                     if (value_member (tmp, DECL_VINDEX (decl)) == NULL_TREE)
6558                       {
6559                         /* The argument types may have changed... */
6560                         tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
6561                         tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
6562
6563                         argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
6564                                                 TREE_CHAIN (argtypes));
6565                         /* But the return type has not.  */
6566                         type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
6567                         if (raises)
6568                           {
6569                             type = build_exception_variant (ctype, type, raises);
6570                             raises = TYPE_RAISES_EXCEPTIONS (type);
6571                           }
6572                         TREE_TYPE (decl) = type;
6573                         DECL_VINDEX (decl)
6574                           = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
6575                       }
6576                   }
6577               }
6578           }
6579       }
6580       if (virtualp)
6581         {
6582           if (DECL_VINDEX (decl) == NULL_TREE)
6583             DECL_VINDEX (decl) = error_mark_node;
6584           IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
6585           if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
6586               /* If this function is derived from a template, don't
6587                  make it public.  This shouldn't be here, but there's
6588                  no good way to override the interface pragmas for one
6589                  function or class only.  Bletch.  */
6590               && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE
6591               && (write_virtuals == 2
6592                   || (write_virtuals == 3
6593                       && CLASSTYPE_INTERFACE_KNOWN (ctype))))
6594             TREE_PUBLIC (decl) = 1;
6595         }
6596     }
6597   return decl;
6598 }
6599
6600 static tree
6601 grokvardecl (type, declarator, specbits, initialized)
6602      tree type;
6603      tree declarator;
6604      RID_BIT_TYPE specbits;
6605      int initialized;
6606 {
6607   tree decl;
6608
6609   if (TREE_CODE (type) == OFFSET_TYPE)
6610     {
6611       /* If you declare a static member so that it
6612          can be initialized, the code will reach here.  */
6613       tree field = lookup_field (TYPE_OFFSET_BASETYPE (type),
6614                                  declarator, 0, 0);
6615       if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
6616         {
6617           tree basetype = TYPE_OFFSET_BASETYPE (type);
6618           error ("`%s' is not a static member of class `%s'",
6619                  IDENTIFIER_POINTER (declarator),
6620                  TYPE_NAME_STRING (basetype));
6621           type = TREE_TYPE (type);
6622           decl = build_lang_field_decl (VAR_DECL, declarator, type);
6623           DECL_CONTEXT (decl) = basetype;
6624           DECL_CLASS_CONTEXT (decl) = basetype;
6625         }
6626       else
6627         {
6628           tree f_type = TREE_TYPE (field);
6629           tree o_type = TREE_TYPE (type);
6630
6631           if (TYPE_SIZE (f_type) == NULL_TREE)
6632             {
6633               if (TREE_CODE (f_type) != TREE_CODE (o_type)
6634                   || (TREE_CODE (f_type) == ARRAY_TYPE
6635                       && TREE_TYPE (f_type) != TREE_TYPE (o_type)))
6636                 error ("redeclaration of type for `%s'",
6637                        IDENTIFIER_POINTER (declarator));
6638               else if (TYPE_SIZE (o_type) != NULL_TREE)
6639                 TREE_TYPE (field) = type;
6640             }
6641           else if (f_type != o_type)
6642             error ("redeclaration of type for `%s'",
6643                    IDENTIFIER_POINTER (declarator));
6644           decl = field;
6645           if (initialized && DECL_INITIAL (decl)
6646               /* Complain about multiply-initialized
6647                  member variables, but don't be faked
6648                  out if initializer is faked up from `empty_init_node'.  */
6649               && (TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
6650                   || CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) != NULL_TREE))
6651             error_with_aggr_type (DECL_CONTEXT (decl),
6652                                   "multiple initializations of static member `%s::%s'",
6653                                   IDENTIFIER_POINTER (DECL_NAME (decl)));
6654         }
6655     }
6656   else
6657     decl = build_decl (VAR_DECL, declarator, type);
6658
6659   if (RIDBIT_SETP (RID_EXTERN, specbits))
6660     {
6661       DECL_THIS_EXTERN (decl) = 1;
6662       DECL_EXTERNAL (decl) = !initialized;
6663     }
6664
6665   /* In class context, static means one per class,
6666      public access, and static storage.  */
6667   if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
6668       && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
6669     {
6670       TREE_PUBLIC (decl) = 1;
6671       TREE_STATIC (decl) = 1;
6672       DECL_EXTERNAL (decl) = !initialized;
6673     }
6674   /* At top level, either `static' or no s.c. makes a definition
6675      (perhaps tentative), and absence of `static' makes it public.  */
6676   else if (current_binding_level == global_binding_level)
6677     {
6678       TREE_PUBLIC (decl) = RIDBIT_NOTSETP (RID_STATIC, specbits);
6679       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
6680     }
6681   /* Not at top level, only `static' makes a static definition.  */
6682   else
6683     {
6684       TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
6685       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
6686     }
6687   return decl;
6688 }
6689
6690 /* Create a canonical pointer to member function type. */
6691
6692 tree
6693 build_ptrmemfunc_type (type)
6694      tree type;
6695 {
6696   tree fields[4];
6697   tree t;
6698   tree u;
6699
6700   /* If a canonical type already exists for this type, use it.  We use
6701      this method instead of type_hash_canon, because it only does a
6702      simple equality check on the list of field members.  */
6703
6704   if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
6705     return t;
6706
6707   push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
6708
6709   u = make_lang_type (UNION_TYPE);
6710   fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
6711   fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, delta_type_node);
6712   finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
6713   TYPE_NAME (u) = NULL_TREE;
6714
6715   t = make_lang_type (RECORD_TYPE);
6716
6717   /* Let the front-end know this is a pointer to member function. */
6718   TYPE_PTRMEMFUNC_FLAG(t) = 1;
6719
6720   fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, delta_type_node);
6721   fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, delta_type_node);
6722   fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
6723   finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
6724
6725   pop_obstacks ();
6726
6727   /* Zap out the name so that the back-end will give us the debugging
6728      information for this anonymous RECORD_TYPE.  */
6729   TYPE_NAME (t) = NULL_TREE;
6730
6731   TYPE_SET_PTRMEMFUNC_TYPE (type, t);
6732
6733   /* Seems to be wanted. */
6734   CLASSTYPE_GOT_SEMICOLON (t) = 1;
6735   return t;
6736 }
6737
6738 /* Given declspecs and a declarator,
6739    determine the name and type of the object declared
6740    and construct a ..._DECL node for it.
6741    (In one case we can return a ..._TYPE node instead.
6742     For invalid input we sometimes return 0.)
6743
6744    DECLSPECS is a chain of tree_list nodes whose value fields
6745     are the storage classes and type specifiers.
6746
6747    DECL_CONTEXT says which syntactic context this declaration is in:
6748      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
6749      FUNCDEF for a function definition.  Like NORMAL but a few different
6750       error messages in each case.  Return value may be zero meaning
6751       this definition is too screwy to try to parse.
6752      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
6753       handle member functions (which have FIELD context).
6754       Return value may be zero meaning this definition is too screwy to
6755       try to parse.
6756      PARM for a parameter declaration (either within a function prototype
6757       or before a function body).  Make a PARM_DECL, or return void_type_node.
6758      TYPENAME if for a typename (in a cast or sizeof).
6759       Don't make a DECL node; just return the ..._TYPE node.
6760      FIELD for a struct or union field; make a FIELD_DECL.
6761      BITFIELD for a field with specified width.
6762    INITIALIZED is 1 if the decl has an initializer.
6763
6764    In the TYPENAME case, DECLARATOR is really an absolute declarator.
6765    It may also be so in the PARM case, for a prototype where the
6766    argument type is specified but not the name.
6767
6768    This function is where the complicated C meanings of `static'
6769    and `extern' are interpreted.
6770
6771    For C++, if there is any monkey business to do, the function which
6772    calls this one must do it, i.e., prepending instance variables,
6773    renaming overloaded function names, etc.
6774
6775    Note that for this C++, it is an error to define a method within a class
6776    which does not belong to that class.
6777
6778    Except in the case where SCOPE_REFs are implicitly known (such as
6779    methods within a class being redundantly qualified),
6780    declarations which involve SCOPE_REFs are returned as SCOPE_REFs
6781    (class_name::decl_name).  The caller must also deal with this.
6782
6783    If a constructor or destructor is seen, and the context is FIELD,
6784    then the type gains the attribute TREE_HAS_x.  If such a declaration
6785    is erroneous, NULL_TREE is returned.
6786
6787    QUALS is used only for FUNCDEF and MEMFUNCDEF cases.  For a member
6788    function, these are the qualifiers to give to the `this' pointer.
6789
6790    May return void_type_node if the declarator turned out to be a friend.
6791    See grokfield for details.  */
6792
6793 enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
6794
6795 tree
6796 grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
6797      tree declspecs;
6798      tree declarator;
6799      enum decl_context decl_context;
6800      int initialized;
6801      tree raises;
6802 {
6803   RID_BIT_TYPE specbits;
6804   int nclasses = 0;
6805   tree spec;
6806   tree type = NULL_TREE;
6807   int longlong = 0;
6808   int constp;
6809   int volatilep;
6810   int virtualp, friendp, inlinep, staticp;
6811   int explicit_int = 0;
6812   int explicit_char = 0;
6813   int opaque_typedef = 0;
6814   tree typedef_decl = NULL_TREE;
6815   char *name;
6816   tree typedef_type = NULL_TREE;
6817   int funcdef_flag = 0;
6818   enum tree_code innermost_code = ERROR_MARK;
6819   int bitfield = 0;
6820   int size_varies = 0;
6821   /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
6822      All FIELD_DECLs we build here have `init' put into their DECL_INITIAL.  */
6823   tree init = NULL_TREE;
6824
6825   /* Keep track of what sort of function is being processed
6826      so that we can warn about default return values, or explicit
6827      return values which do not match prescribed defaults.  */
6828   enum return_types return_type = return_normal;
6829
6830   tree dname = NULL_TREE;
6831   tree ctype = current_class_type;
6832   tree ctor_return_type = NULL_TREE;
6833   enum overload_flags flags = NO_SPECIAL;
6834   int seen_scope_ref = 0;
6835   tree quals = NULL_TREE;
6836
6837   RIDBIT_RESET_ALL (specbits);
6838   if (decl_context == FUNCDEF)
6839     funcdef_flag = 1, decl_context = NORMAL;
6840   else if (decl_context == MEMFUNCDEF)
6841     funcdef_flag = -1, decl_context = FIELD;
6842   else if (decl_context == BITFIELD)
6843     bitfield = 1, decl_context = FIELD;
6844
6845   if (flag_traditional && allocation_temporary_p ())
6846     end_temporary_allocation ();
6847
6848   /* Look inside a declarator for the name being declared
6849      and get it as a string, for an error message.  */
6850   {
6851     tree type, last = NULL_TREE;
6852     register tree decl = declarator;
6853     name = NULL;
6854
6855     while (decl)
6856       switch (TREE_CODE (decl))
6857         {
6858         case COND_EXPR:
6859           ctype = NULL_TREE;
6860           decl = TREE_OPERAND (decl, 0);
6861           break;
6862
6863         case BIT_NOT_EXPR:      /* for C++ destructors!  */
6864           {
6865             tree name = TREE_OPERAND (decl, 0);
6866             tree rename = NULL_TREE;
6867
6868             my_friendly_assert (flags == NO_SPECIAL, 152);
6869             flags = DTOR_FLAG;
6870             return_type = return_dtor;
6871             my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
6872             if (ctype == NULL_TREE)
6873               {
6874                 if (current_class_type == NULL_TREE)
6875                   {
6876                     error ("destructors must be member functions");
6877                     flags = NO_SPECIAL;
6878                   }
6879                 else
6880                   {
6881                     tree t = constructor_name (current_class_name);
6882                     if (t != name)
6883                       rename = t;
6884                   }
6885               }
6886             else
6887               {
6888                 tree t = constructor_name (ctype);
6889                 if (t != name)
6890                   rename = t;
6891               }
6892
6893             if (rename)
6894               {
6895                 error ("destructor `%s' must match class name `%s'",
6896                        IDENTIFIER_POINTER (name),
6897                        IDENTIFIER_POINTER (rename));
6898                 TREE_OPERAND (decl, 0) = rename;
6899               }
6900             decl = name;
6901           }
6902           break;
6903
6904         case ADDR_EXPR:         /* C++ reference declaration */
6905           /* fall through */
6906         case ARRAY_REF:
6907         case INDIRECT_REF:
6908           ctype = NULL_TREE;
6909           innermost_code = TREE_CODE (decl);
6910           last = decl;
6911           decl = TREE_OPERAND (decl, 0);
6912           break;
6913
6914         case CALL_EXPR:
6915           if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
6916             {
6917               /* This is actually a variable declaration using constructor
6918                  syntax.  We need to call start_decl and finish_decl so we
6919                  can get the variable initialized...  */
6920
6921               if (last)
6922                 /* We need to insinuate ourselves into the declarator in place
6923                    of the CALL_EXPR.  */
6924                 TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
6925               else
6926                 declarator = TREE_OPERAND (decl, 0);
6927
6928               init = TREE_OPERAND (decl, 1);
6929
6930               decl = start_decl (declarator, declspecs, 1, NULL_TREE);
6931               finish_decl (decl, init, NULL_TREE, 1);
6932               return 0;
6933             }
6934           innermost_code = TREE_CODE (decl);
6935           decl = TREE_OPERAND (decl, 0);
6936           if (decl_context == FIELD && ctype == NULL_TREE)
6937             ctype = current_class_type;
6938           if (ctype != NULL_TREE
6939               && decl != NULL_TREE && flags != DTOR_FLAG
6940               && decl == constructor_name (ctype))
6941             {
6942               return_type = return_ctor;
6943               ctor_return_type = ctype;
6944             }
6945           ctype = NULL_TREE;
6946           break;
6947
6948         case IDENTIFIER_NODE:
6949           dname = decl;
6950           name = IDENTIFIER_POINTER (decl);
6951           decl = NULL_TREE;
6952           break;
6953
6954         case RECORD_TYPE:
6955         case UNION_TYPE:
6956         case ENUMERAL_TYPE:
6957           /* Parse error puts this typespec where
6958              a declarator should go.  */
6959           error ("declarator name missing");
6960           dname = TYPE_NAME (decl);
6961           if (dname && TREE_CODE (dname) == TYPE_DECL)
6962             dname = DECL_NAME (dname);
6963           name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
6964           declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
6965           decl = NULL_TREE;
6966           break;
6967
6968         case TYPE_EXPR:
6969           my_friendly_assert (flags == NO_SPECIAL, 154);
6970           flags = TYPENAME_FLAG;
6971           name = "operator <typename>"; /* We don't know the type yet.  */
6972           /* Go to the absdcl.  */
6973           decl = TREE_OPERAND (decl, 0);
6974           return_type = return_conversion;
6975           break;
6976
6977           /* C++ extension */
6978         case SCOPE_REF:
6979 /*
6980           if (seen_scope_ref == 1)
6981             error ("multiple `::' terms in declarator invalid");
6982 */
6983           seen_scope_ref += 1;
6984           {
6985             /* Perform error checking, and convert class names to types.
6986                We may call grokdeclarator multiple times for the same
6987                tree structure, so only do the conversion once.  In this
6988                case, we have exactly what we want for `ctype'.  */
6989             tree cname = TREE_OPERAND (decl, 0);
6990             if (cname == NULL_TREE)
6991               ctype = NULL_TREE;
6992             /* Can't use IS_AGGR_TYPE because CNAME might not be a type.  */
6993             else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname))
6994                      || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE)
6995               ctype = cname;
6996             else if (! is_aggr_typedef (cname, 1))
6997               {
6998                 TREE_OPERAND (decl, 0) = NULL_TREE;
6999               }
7000             /* Must test TREE_OPERAND (decl, 1), in case user gives
7001                us `typedef (class::memfunc)(int); memfunc *memfuncptr;'  */
7002             else if (TREE_OPERAND (decl, 1)
7003                      && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
7004               {
7005                 TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
7006               }
7007             else if (ctype == NULL_TREE)
7008               {
7009                 ctype = IDENTIFIER_TYPE_VALUE (cname);
7010                 TREE_OPERAND (decl, 0) = ctype;
7011               }
7012             else if (TREE_COMPLEXITY (decl) == current_class_depth)
7013               TREE_OPERAND (decl, 0) = ctype;
7014             else
7015               {
7016                 if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname),
7017                                                ctype))
7018                   {
7019                     cp_error ("type `%T' is not derived from type `%T'",
7020                               IDENTIFIER_TYPE_VALUE (cname), ctype);
7021                     TREE_OPERAND (decl, 0) = NULL_TREE;
7022                   }
7023                 else
7024                   {
7025                     ctype = IDENTIFIER_TYPE_VALUE (cname);
7026                     TREE_OPERAND (decl, 0) = ctype;
7027                   }
7028               }
7029
7030             decl = TREE_OPERAND (decl, 1);
7031             if (ctype)
7032               {
7033                 if (TREE_CODE (decl) == IDENTIFIER_NODE
7034                     && constructor_name (ctype) == decl)
7035                   {
7036                     return_type = return_ctor;
7037                     ctor_return_type = ctype;
7038                   }
7039                 else if (TREE_CODE (decl) == BIT_NOT_EXPR
7040                          && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
7041                          && constructor_name (ctype) == TREE_OPERAND (decl, 0))
7042                   {
7043                     return_type = return_dtor;
7044                     ctor_return_type = ctype;
7045                     flags = DTOR_FLAG;
7046                     decl = TREE_OPERAND (decl, 0);
7047                   }
7048               }
7049           }
7050           break;
7051
7052         case ERROR_MARK:
7053           decl = NULL_TREE;
7054           break;
7055
7056         default:
7057           return 0; /* We used to do a 155 abort here.  */
7058         }
7059     if (name == NULL)
7060       name = "type name";
7061   }
7062
7063   /* A function definition's declarator must have the form of
7064      a function declarator.  */
7065
7066   if (funcdef_flag && innermost_code != CALL_EXPR)
7067     return 0;
7068
7069   /* Anything declared one level down from the top level
7070      must be one of the parameters of a function
7071      (because the body is at least two levels down).  */
7072
7073   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
7074      by not allowing C++ class definitions to specify their parameters
7075      with xdecls (must be spec.d in the parmlist).
7076
7077      Since we now wait to push a class scope until we are sure that
7078      we are in a legitimate method context, we must set oldcname
7079      explicitly (since current_class_name is not yet alive).  */
7080
7081   if (decl_context == NORMAL
7082       && current_binding_level->level_chain == global_binding_level)
7083     decl_context = PARM;
7084
7085   /* Look through the decl specs and record which ones appear.
7086      Some typespecs are defined as built-in typenames.
7087      Others, the ones that are modifiers of other types,
7088      are represented by bits in SPECBITS: set the bits for
7089      the modifiers that appear.  Storage class keywords are also in SPECBITS.
7090
7091      If there is a typedef name or a type, store the type in TYPE.
7092      This includes builtin typedefs such as `int'.
7093
7094      Set EXPLICIT_INT if the type is `int' or `char' and did not
7095      come from a user typedef.
7096
7097      Set LONGLONG if `long' is mentioned twice.
7098
7099      For C++, constructors and destructors have their own fast treatment.  */
7100
7101   for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
7102     {
7103       register int i;
7104       register tree id;
7105
7106       /* Certain parse errors slip through.  For example,
7107          `int class;' is not caught by the parser. Try
7108          weakly to recover here.  */
7109       if (TREE_CODE (spec) != TREE_LIST)
7110         return 0;
7111
7112       id = TREE_VALUE (spec);
7113
7114       if (TREE_CODE (id) == IDENTIFIER_NODE)
7115         {
7116           if (id == ridpointers[(int) RID_INT])
7117             {
7118               if (type)
7119                 error ("extraneous `int' ignored");
7120               else
7121                 {
7122                   explicit_int = 1;
7123                   type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7124                 }
7125               goto found;
7126             }
7127           if (id == ridpointers[(int) RID_CHAR])
7128             {
7129               if (type)
7130                 error ("extraneous `char' ignored");
7131               else
7132                 {
7133                   explicit_char = 1;
7134                   type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7135                 }
7136               goto found;
7137             }
7138           if (id == ridpointers[(int) RID_WCHAR])
7139             {
7140               if (type)
7141                 error ("extraneous `__wchar_t' ignored");
7142               else
7143                 {
7144                   type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7145                 }
7146               goto found;
7147             }
7148           /* C++ aggregate types. */
7149           if (IDENTIFIER_HAS_TYPE_VALUE (id))
7150             {
7151               if (type)
7152                 cp_error ("multiple declarations `%T' and `%T'", type, id);
7153               else
7154                 type = IDENTIFIER_TYPE_VALUE (id);
7155               goto found;
7156             }
7157
7158           for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
7159             {
7160               if (ridpointers[i] == id)
7161                 {
7162                   if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
7163                     {
7164 #if 0
7165                       if (pedantic)
7166                         pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
7167                       else
7168 #endif
7169                         if (longlong)
7170                         error ("`long long long' is too long for GCC");
7171                       else
7172                         longlong = 1;
7173                     }
7174                   else if (RIDBIT_SETP (i, specbits))
7175                     warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
7176                   RIDBIT_SET (i, specbits);
7177                   goto found;
7178                 }
7179             }
7180         }
7181       if (type)
7182         error ("two or more data types in declaration of `%s'", name);
7183       else if (TREE_CODE (id) == IDENTIFIER_NODE)
7184         {
7185           register tree t = lookup_name (id, 1);
7186           if (!t || TREE_CODE (t) != TYPE_DECL)
7187             error ("`%s' fails to be a typedef or built in type",
7188                    IDENTIFIER_POINTER (id));
7189           else
7190             {
7191               type = TREE_TYPE (t);
7192               typedef_decl = t;
7193             }
7194         }
7195       else if (TREE_CODE (id) != ERROR_MARK)
7196         /* Can't change CLASS nodes into RECORD nodes here!  */
7197         type = id;
7198
7199     found: ;
7200     }
7201
7202   typedef_type = type;
7203
7204   /* No type at all: default to `int', and set EXPLICIT_INT
7205      because it was not a user-defined typedef.
7206      Except when we have a `typedef' inside a signature, in
7207      which case the type defaults to `unknown type' and is
7208      instantiated when assigning to a signature pointer or ref.  */
7209
7210   if (type == NULL_TREE)
7211     {
7212       explicit_int = -1;
7213       if (return_type == return_dtor)
7214         type = void_type_node;
7215       else if (return_type == return_ctor)
7216         type = TYPE_POINTER_TO (ctor_return_type);
7217       else if (current_class_type
7218                && IS_SIGNATURE (current_class_type)
7219                && (RIDBIT_SETP (RID_TYPEDEF, specbits)
7220                    || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7221                && (decl_context == FIELD || decl_context == NORMAL))
7222         {
7223           explicit_int = 0;
7224           opaque_typedef = 1;
7225           type = copy_node (opaque_type_node);
7226         }
7227       else
7228         {
7229           if (funcdef_flag && warn_return_type
7230               && return_type == return_normal
7231               && ! (RIDBIT_SETP (RID_SIGNED, specbits)
7232                     || RIDBIT_SETP (RID_UNSIGNED, specbits)
7233                     || RIDBIT_SETP (RID_LONG, specbits)
7234                     || RIDBIT_SETP (RID_SHORT, specbits)))
7235             warn_about_return_type = 1;
7236           /* Save warning until we know what is really going on.  */
7237           type = integer_type_node;
7238         }
7239     }
7240   else if (return_type == return_dtor)
7241     {
7242       error ("return type specification for destructor invalid");
7243       type = void_type_node;
7244     }
7245   else if (return_type == return_ctor)
7246     {
7247       error ("return type specification for constructor invalid");
7248       type = TYPE_POINTER_TO (ctor_return_type);
7249     }
7250
7251   ctype = NULL_TREE;
7252
7253   /* Now process the modifiers that were specified
7254      and check for invalid combinations.  */
7255
7256   /* Long double is a special combination.  */
7257
7258   if (RIDBIT_SETP (RID_LONG, specbits)
7259       && TYPE_MAIN_VARIANT (type) == double_type_node)
7260     {
7261       RIDBIT_RESET (RID_LONG, specbits);
7262       type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
7263                                  TYPE_VOLATILE (type));
7264     }
7265
7266   /* Check all other uses of type modifiers.  */
7267
7268   if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7269       || RIDBIT_SETP (RID_SIGNED, specbits)
7270       || RIDBIT_SETP (RID_LONG, specbits)
7271       || RIDBIT_SETP (RID_SHORT, specbits))
7272     {
7273       int ok = 0;
7274
7275       if (TREE_CODE (type) == REAL_TYPE)
7276         error ("short, signed or unsigned invalid for `%s'", name);
7277       else if (TREE_CODE (type) != INTEGER_TYPE || type == wchar_type_node)
7278         error ("long, short, signed or unsigned invalid for `%s'", name);
7279       else if (RIDBIT_SETP (RID_LONG, specbits)
7280                && RIDBIT_SETP (RID_SHORT, specbits))
7281         error ("long and short specified together for `%s'", name);
7282       else if ((RIDBIT_SETP (RID_LONG, specbits)
7283                 || RIDBIT_SETP (RID_SHORT, specbits))
7284                && explicit_char)
7285         error ("long or short specified with char for `%s'", name);
7286       else if ((RIDBIT_SETP (RID_LONG, specbits)
7287                 || RIDBIT_SETP (RID_SHORT, specbits))
7288                && TREE_CODE (type) == REAL_TYPE)
7289         error ("long or short specified with floating type for `%s'", name);
7290       else if (RIDBIT_SETP (RID_SIGNED, specbits)
7291                && RIDBIT_SETP (RID_UNSIGNED, specbits))
7292         error ("signed and unsigned given together for `%s'", name);
7293       else
7294         {
7295           ok = 1;
7296           if (!explicit_int && !explicit_char && pedantic)
7297             {
7298               pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
7299                        name);
7300               if (flag_pedantic_errors)
7301                 ok = 0;
7302             }
7303         }
7304
7305       /* Discard the type modifiers if they are invalid.  */
7306       if (! ok)
7307         {
7308           RIDBIT_RESET (RID_UNSIGNED, specbits);
7309           RIDBIT_RESET (RID_SIGNED, specbits);
7310           RIDBIT_RESET (RID_LONG, specbits);
7311           RIDBIT_RESET (RID_SHORT, specbits);
7312           longlong = 0;
7313         }
7314     }
7315
7316   /* Decide whether an integer type is signed or not.
7317      Optionally treat bitfields as signed by default.  */
7318   if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7319       /* Traditionally, all bitfields are unsigned.  */
7320       || (bitfield && flag_traditional)
7321       || (bitfield && ! flag_signed_bitfields
7322           && (explicit_int || explicit_char
7323               /* A typedef for plain `int' without `signed'
7324                  can be controlled just like plain `int'.  */
7325               || ! (typedef_decl != NULL_TREE
7326                     && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
7327           && TREE_CODE (type) != ENUMERAL_TYPE
7328           && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
7329     {
7330       if (longlong)
7331         type = long_long_unsigned_type_node;
7332       else if (RIDBIT_SETP (RID_LONG, specbits))
7333         type = long_unsigned_type_node;
7334       else if (RIDBIT_SETP (RID_SHORT, specbits))
7335         type = short_unsigned_type_node;
7336       else if (type == char_type_node)
7337         type = unsigned_char_type_node;
7338       else if (typedef_decl)
7339         type = unsigned_type (type);
7340       else
7341         type = unsigned_type_node;
7342     }
7343   else if (RIDBIT_SETP (RID_SIGNED, specbits)
7344            && type == char_type_node)
7345     type = signed_char_type_node;
7346   else if (longlong)
7347     type = long_long_integer_type_node;
7348   else if (RIDBIT_SETP (RID_LONG, specbits))
7349     type = long_integer_type_node;
7350   else if (RIDBIT_SETP (RID_SHORT, specbits))
7351     type = short_integer_type_node;
7352
7353   /* Set CONSTP if this declaration is `const', whether by
7354      explicit specification or via a typedef.
7355      Likewise for VOLATILEP.  */
7356
7357   constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
7358   volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
7359   staticp = 0;
7360   inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
7361   if (constp > 1)
7362     warning ("duplicate `const'");
7363   if (volatilep > 1)
7364     warning ("duplicate `volatile'");
7365   virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
7366
7367   /* operators new and delete are implicitly static.  */
7368   if (RIDBIT_SETP (RID_STATIC, specbits))
7369     staticp = 1 + (decl_context == FIELD);
7370
7371   if (virtualp && staticp == 2)
7372     {
7373       cp_error ("member `%D' cannot be declared both virtual and static",
7374                 dname);
7375       staticp = 0;
7376     }
7377   friendp = RIDBIT_SETP (RID_FRIEND, specbits);
7378   RIDBIT_RESET (RID_VIRTUAL, specbits);
7379   RIDBIT_RESET (RID_FRIEND, specbits);
7380
7381   if (RIDBIT_SETP (RID_MUTABLE, specbits))
7382     {
7383       if (decl_context == PARM)
7384         {
7385           error ("non-member `%s' cannot be declared mutable", name);
7386           RIDBIT_RESET (RID_MUTABLE, specbits);
7387         }
7388       else if (friendp || decl_context == TYPENAME)
7389         {
7390           error ("non-object member `%s' cannot be declared mutable", name);
7391           RIDBIT_RESET (RID_MUTABLE, specbits);
7392         }
7393       else if (staticp)
7394         {
7395           error ("static `%s' cannot be declared mutable", name);
7396           RIDBIT_RESET (RID_MUTABLE, specbits);
7397         }
7398 #if 0
7399       if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7400         {
7401           error ("non-object member `%s' cannot be declared mutable", name);
7402           RIDBIT_RESET (RID_MUTABLE, specbits);
7403         }
7404       /* Because local typedefs are parsed twice, we don't want this
7405          message here. */
7406       else if (decl_context != FIELD)
7407         {
7408           error ("non-member `%s' cannot be declared mutable", name);
7409           RIDBIT_RESET (RID_MUTABLE, specbits);
7410         }
7411 #endif
7412     }
7413
7414   /* Warn if two storage classes are given. Default to `auto'.  */
7415
7416   if (RIDBIT_ANY_SET (specbits))
7417     {
7418       if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
7419       if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
7420       if (decl_context == PARM && nclasses > 0)
7421         error ("storage class specifiers invalid in parameter declarations");
7422       if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7423         {
7424           if (decl_context == PARM)
7425             error ("typedef declaration invalid in parameter declaration");
7426           nclasses++;
7427         }
7428       if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
7429       if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
7430     }
7431
7432   /* Give error if `virtual' is used outside of class declaration.  */
7433   if (virtualp && current_class_name == NULL_TREE)
7434     {
7435       error ("virtual outside class declaration");
7436       virtualp = 0;
7437     }
7438   if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
7439     {
7440       error ("only members can be declared mutable");
7441       RIDBIT_RESET (RID_MUTABLE, specbits);
7442     }
7443
7444   /* Static anonymous unions are dealt with here.  */
7445   if (staticp && decl_context == TYPENAME
7446       && TREE_CODE (declspecs) == TREE_LIST
7447       && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
7448       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
7449     decl_context = FIELD;
7450
7451   /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
7452      is used in a signature member function declaration.  */
7453   if (decl_context == FIELD
7454       && IS_SIGNATURE (current_class_type)
7455       && RIDBIT_NOTSETP(RID_TYPEDEF, specbits)
7456       && !SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7457     {
7458       if (constp)
7459         {
7460           error ("`const' specified for signature member function `%s'", name);
7461           constp = 0;
7462         }
7463       if (volatilep)
7464         {
7465           error ("`volatile' specified for signature member function `%s'", name);
7466           volatilep = 0;
7467         }
7468       if (inlinep)
7469         {
7470           error ("`inline' specified for signature member function `%s'", name);
7471           /* Later, we'll make signature member functions inline.  */
7472           inlinep = 0;
7473         }
7474       if (friendp)
7475         {
7476           error ("`friend' declaration in signature definition");
7477           friendp = 0;
7478         }
7479       if (virtualp)
7480         {
7481           error ("`virtual' specified for signature member function `%s'", name);
7482           /* Later, we'll make signature member functions virtual.  */
7483           virtualp = 0;
7484         }
7485     }
7486
7487   /* Warn about storage classes that are invalid for certain
7488      kinds of declarations (parameters, typenames, etc.).  */
7489
7490   if (nclasses > 1)
7491     error ("multiple storage classes in declaration of `%s'", name);
7492   else if (decl_context != NORMAL && nclasses > 0)
7493     {
7494       if (decl_context == PARM
7495           && (RIDBIT_SETP (RID_REGISTER, specbits)
7496               || RIDBIT_SETP (RID_AUTO, specbits)))
7497         ;
7498       else if (decl_context == FIELD
7499                && RIDBIT_SETP (RID_TYPEDEF, specbits))
7500         {
7501           /* Processing a typedef declaration nested within a class type
7502              definition.  */
7503           register tree scanner;
7504           register tree previous_declspec;
7505           tree loc_typedecl;
7506   
7507           if (initialized)
7508             error ("typedef declaration includes an initializer");
7509   
7510           /* To process a class-local typedef declaration, we descend down
7511              the chain of declspecs looking for the `typedef' spec.  When we
7512              find it, we splice it out of the chain of declspecs, and then
7513              recursively call `grokdeclarator' with the original declarator
7514              and with the newly adjusted declspecs.  This call should return
7515              a FIELD_DECL node with the TREE_TYPE (and other parts) set
7516              appropriately.  We can then just change the TREE_CODE on that
7517              from FIELD_DECL to TYPE_DECL and we're done.  */
7518
7519           for (previous_declspec = NULL_TREE, scanner = declspecs;
7520                scanner;
7521                previous_declspec = scanner, scanner = TREE_CHAIN (scanner))
7522             {
7523               if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF])
7524                 break;
7525             }
7526           if (previous_declspec)
7527             TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner);
7528           else
7529             declspecs = TREE_CHAIN (scanner);
7530   
7531           /* In the recursive call to grokdeclarator we need to know
7532              whether we are working on a signature-local typedef.  */
7533           if (IS_SIGNATURE (current_class_type))
7534             SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1;
7535   
7536           loc_typedecl =
7537             grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE);
7538   
7539           if (loc_typedecl != error_mark_node)
7540             {
7541               register int i = sizeof (struct lang_decl_flags) / sizeof (int);
7542               register int *pi;
7543   
7544               TREE_SET_CODE (loc_typedecl, TYPE_DECL);
7545   
7546               pi = (int *) permalloc (sizeof (struct lang_decl_flags));
7547               while (i > 0)
7548                 pi[--i] = 0;
7549               DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
7550             }
7551   
7552           if (IS_SIGNATURE (current_class_type))
7553             {
7554               SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0;
7555               if (loc_typedecl != error_mark_node && opaque_typedef)
7556                 SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
7557             }
7558
7559           return loc_typedecl;
7560         }
7561       else if (decl_context == FIELD
7562                && (! IS_SIGNATURE (current_class_type))
7563                /* C++ allows static class elements  */
7564                && RIDBIT_SETP (RID_STATIC, specbits))
7565         /* C++ also allows inlines and signed and unsigned elements,
7566            but in those cases we don't come in here.  */
7567         ;
7568       else
7569         {
7570           if (decl_context == FIELD)
7571             {
7572               tree tmp = TREE_OPERAND (declarator, 0);
7573               register int op = IDENTIFIER_OPNAME_P (tmp);
7574               error ("storage class specified for %s `%s'",
7575                      IS_SIGNATURE (current_class_type)
7576                      ? (op
7577                         ? "signature member operator"
7578                         : "signature member function")
7579                      : (op ? "member operator" : "structure field"),
7580                      op ? operator_name_string (tmp) : name);
7581             }
7582           else
7583             error ((decl_context == PARM
7584                     ? "storage class specified for parameter `%s'"
7585                     : "storage class specified for typename"), name);
7586           RIDBIT_RESET (RID_REGISTER, specbits);
7587           RIDBIT_RESET (RID_AUTO, specbits);
7588           RIDBIT_RESET (RID_EXTERN, specbits);
7589
7590           if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
7591             {
7592               RIDBIT_RESET (RID_STATIC, specbits);
7593               staticp = 0;
7594             }
7595         }
7596     }
7597   else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
7598     {
7599       if (current_binding_level == global_binding_level)
7600         {
7601           /* It's common practice (and completely legal) to have a const
7602              be initialized and declared extern.  */
7603           if (! constp)
7604             warning ("`%s' initialized and declared `extern'", name);
7605         }
7606       else
7607         error ("`%s' has both `extern' and initializer", name);
7608     }
7609   else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
7610            && current_binding_level != global_binding_level)
7611     error ("nested function `%s' declared `extern'", name);
7612   else if (current_binding_level == global_binding_level)
7613     {
7614       if (RIDBIT_SETP (RID_AUTO, specbits))
7615         error ("top-level declaration of `%s' specifies `auto'", name);
7616 #if 0
7617       if (RIDBIT_SETP (RID_REGISTER, specbits))
7618         error ("top-level declaration of `%s' specifies `register'", name);
7619 #endif
7620 #if 0
7621       /* I'm not sure under what circumstances we should turn
7622          on the extern bit, and under what circumstances we should
7623          warn if other bits are turned on.  */
7624       if (decl_context == NORMAL
7625           && RIDBIT_NOSETP (RID_EXTERN, specbits)
7626           && ! root_lang_context_p ())
7627         {
7628           RIDBIT_SET (RID_EXTERN, specbits);
7629         }
7630 #endif
7631     }
7632
7633   /* Now figure out the structure of the declarator proper.
7634      Descend through it, creating more complex types, until we reach
7635      the declared identifier (or NULL_TREE, in an absolute declarator).  */
7636
7637   while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
7638     {
7639       /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
7640          an INDIRECT_REF (for *...),
7641          a CALL_EXPR (for ...(...)),
7642          an identifier (for the name being declared)
7643          or a null pointer (for the place in an absolute declarator
7644          where the name was omitted).
7645          For the last two cases, we have just exited the loop.
7646
7647          For C++ it could also be
7648          a SCOPE_REF (for class :: ...).  In this case, we have converted
7649          sensible names to types, and those are the values we use to
7650          qualify the member name.
7651          an ADDR_EXPR (for &...),
7652          a BIT_NOT_EXPR (for destructors)
7653          a TYPE_EXPR (for operator typenames)
7654
7655          At this point, TYPE is the type of elements of an array,
7656          or for a function to return, or for a pointer to point to.
7657          After this sequence of ifs, TYPE is the type of the
7658          array or function or pointer, and DECLARATOR has had its
7659          outermost layer removed.  */
7660
7661       if (TREE_CODE (type) == ERROR_MARK)
7662         {
7663           if (TREE_CODE (declarator) == SCOPE_REF)
7664             declarator = TREE_OPERAND (declarator, 1);
7665           else
7666             declarator = TREE_OPERAND (declarator, 0);
7667           continue;
7668         }
7669       if (quals != NULL_TREE
7670           && (declarator == NULL_TREE
7671               || TREE_CODE (declarator) != SCOPE_REF))
7672         {
7673           if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
7674             ctype = TYPE_METHOD_BASETYPE (type);
7675           if (ctype != NULL_TREE)
7676             {
7677 #if 0 /* not yet, should get fixed properly later */
7678               tree dummy = make_type_decl (NULL_TREE, type);
7679 #else
7680               tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
7681 #endif
7682               ctype = grok_method_quals (ctype, dummy, quals);
7683               type = TREE_TYPE (dummy);
7684               quals = NULL_TREE;
7685             }
7686         }
7687       switch (TREE_CODE (declarator))
7688         {
7689         case ARRAY_REF:
7690           {
7691             register tree itype = NULL_TREE;
7692             register tree size = TREE_OPERAND (declarator, 1);
7693
7694             declarator = TREE_OPERAND (declarator, 0);
7695
7696             /* Check for some types that there cannot be arrays of.  */
7697
7698             if (TYPE_MAIN_VARIANT (type) == void_type_node)
7699               {
7700                 cp_error ("declaration of `%D' as array of voids", dname);
7701                 type = error_mark_node;
7702               }
7703
7704             if (TREE_CODE (type) == FUNCTION_TYPE)
7705               {
7706                 cp_error ("declaration of `%D' as array of functions", dname);
7707                 type = error_mark_node;
7708               }
7709
7710             /* ARM $8.4.3: Since you can't have a pointer to a reference,
7711                you can't have arrays of references.  If we allowed them,
7712                then we'd be saying x[i] is legal for an array x, but
7713                then you'd have to ask: what does `*(x + i)' mean?  */
7714             if (TREE_CODE (type) == REFERENCE_TYPE)
7715               {
7716                 if (decl_context == TYPENAME)
7717                   cp_error ("cannot make arrays of references");
7718                 else
7719                   cp_error ("declaration of `%D' as array of references",
7720                             dname);
7721                 type = error_mark_node;
7722               }
7723
7724             if (TREE_CODE (type) == OFFSET_TYPE)
7725               {
7726                   cp_error ("declaration of `%D' as array of data members",
7727                             dname);
7728                 type = error_mark_node;
7729               }
7730
7731             if (TREE_CODE (type) == METHOD_TYPE)
7732               {
7733                 cp_error ("declaration of `%D' as array of function members",
7734                           dname);
7735                 type = error_mark_node;
7736               }
7737
7738             if (size == error_mark_node)
7739               type = error_mark_node;
7740
7741             if (type == error_mark_node)
7742               continue;
7743
7744             if (size)
7745               {
7746                 /* Must suspend_momentary here because the index
7747                    type may need to live until the end of the function.
7748                    For example, it is used in the declaration of a
7749                    variable which requires destructing at the end of
7750                    the function; then build_vec_delete will need this
7751                    value.  */
7752                 int yes = suspend_momentary ();
7753                 /* might be a cast */
7754                 if (TREE_CODE (size) == NOP_EXPR
7755                     && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
7756                   size = TREE_OPERAND (size, 0);
7757
7758                 /* If this is a template parameter, it'll be constant, but
7759                    we don't know what the value is yet.  */
7760                 if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
7761                   goto dont_grok_size;
7762
7763                 if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
7764                     && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
7765                   {
7766                     cp_error ("size of array `%D' has non-integer type",
7767                               dname);
7768                     size = integer_one_node;
7769                   }
7770                 if (TREE_READONLY_DECL_P (size))
7771                   size = decl_constant_value (size);
7772                 if (pedantic && integer_zerop (size))
7773                   cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
7774                 if (TREE_CONSTANT (size))
7775                   {
7776                     constant_expression_warning (size);
7777                     if (INT_CST_LT (size, integer_zero_node))
7778                       {
7779                         cp_error ("size of array `%D' is negative", dname);
7780                         size = integer_one_node;
7781                       }
7782                     itype = build_index_type (size_binop (MINUS_EXPR, size,
7783                                                           integer_one_node));
7784                   }
7785                 else
7786                   {
7787                     if (pedantic)
7788                       cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", dname);
7789                   dont_grok_size:
7790                     itype =
7791                       build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
7792                     /* Make sure the array size remains visibly nonconstant
7793                        even if it is (eg) a const variable with known value.  */
7794                     size_varies = 1;
7795                     itype = variable_size (itype);
7796                     itype = build_index_type (itype);
7797                   }
7798                 resume_momentary (yes);
7799               }
7800
7801           /* Build the array type itself, then merge any constancy or
7802              volatility into the target type.  We must do it in this order
7803              to ensure that the TYPE_MAIN_VARIANT field of the array type
7804              is set correctly.  */
7805
7806             type = build_cplus_array_type (type, itype);
7807             if (constp || volatilep)
7808               /* Should this be c_build_type_variant? -jason */
7809               type = build_type_variant (type, constp, volatilep);
7810
7811             ctype = NULL_TREE;
7812           }
7813           break;
7814
7815         case CALL_EXPR:
7816           {
7817             tree arg_types;
7818
7819             /* Declaring a function type.
7820                Make sure we have a valid type for the function to return.  */
7821 #if 0
7822             /* Is this an error?  Should they be merged into TYPE here?  */
7823             if (pedantic && (constp || volatilep))
7824               pedwarn ("function declared to return const or volatile result");
7825 #else
7826             /* Merge any constancy or volatility into the target type
7827                for the pointer.  */
7828
7829             if (constp || volatilep)
7830               {
7831                 type = build_type_variant (type, constp, volatilep);
7832                 if (IS_AGGR_TYPE (type))
7833                   build_pointer_type (type);
7834                 constp = 0;
7835                 volatilep = 0;
7836               }
7837 #endif
7838
7839             /* Warn about some types functions can't return.  */
7840
7841             if (TREE_CODE (type) == FUNCTION_TYPE)
7842               {
7843                 error ("`%s' declared as function returning a function", name);
7844                 type = integer_type_node;
7845               }
7846             if (TREE_CODE (type) == ARRAY_TYPE)
7847               {
7848                 error ("`%s' declared as function returning an array", name);
7849                 type = integer_type_node;
7850               }
7851
7852             if (ctype == NULL_TREE
7853                 && decl_context == FIELD
7854                 && (friendp == 0 || dname == current_class_name))
7855               ctype = current_class_type;
7856
7857             if (ctype && flags == TYPENAME_FLAG)
7858               TYPE_HAS_CONVERSION (ctype) = 1;
7859             if (ctype && constructor_name (ctype) == dname)
7860               {
7861                 /* We are within a class's scope. If our declarator name
7862                    is the same as the class name, and we are defining
7863                    a function, then it is a constructor/destructor, and
7864                    therefore returns a void type.  */
7865
7866                 if (flags == DTOR_FLAG)
7867                   {
7868                     /* ANSI C++ June 5 1992 WP 12.4.1.  A destructor may
7869                        not be declared const or volatile.  A destructor
7870                        may not be static.  */
7871                     if (staticp == 2)
7872                       error ("destructor cannot be static member function");
7873                     if (TYPE_READONLY (type))
7874                       {
7875                         error ("destructors cannot be declared `const'");
7876                         return void_type_node;
7877                       }
7878                     if (TYPE_VOLATILE (type))
7879                       {
7880                         error ("destructors cannot be declared `volatile'");
7881                         return void_type_node;
7882                       }
7883                     if (decl_context == FIELD)
7884                       {
7885                         if (! member_function_or_else (ctype, current_class_type,
7886                                                        "destructor for alien class `%s' cannot be a member"))
7887                           return void_type_node;
7888                       }
7889                   }
7890                 else            /* it's a constructor. */
7891                   {
7892                     /* ANSI C++ June 5 1992 WP 12.1.2.  A constructor may
7893                        not be declared const or volatile.  A constructor may
7894                        not be virtual.  A constructor may not be static.  */
7895                     if (staticp == 2)
7896                       error ("constructor cannot be static member function");
7897                     if (virtualp)
7898                       {
7899                         pedwarn ("constructors cannot be declared virtual");
7900                         virtualp = 0;
7901                       }
7902                     if (TYPE_READONLY (type))
7903                       {
7904                         error ("constructors cannot be declared `const'");
7905                         return void_type_node;
7906                       }
7907                     if (TYPE_VOLATILE (type))
7908                       {
7909                         error ("constructors cannot be declared `volatile'");
7910                         return void_type_node;
7911                       }
7912                     {
7913                       int inlinep, staticp;
7914                       inlinep = RIDBIT_SETP (RID_INLINE, specbits);
7915                       staticp = RIDBIT_SETP (RID_STATIC, specbits);
7916                       RIDBIT_RESET (RID_INLINE, specbits);
7917                       RIDBIT_RESET (RID_STATIC, specbits);
7918                       if (RIDBIT_ANY_SET (specbits))
7919                         error ("return value type specifier for constructor ignored");
7920                       if (inlinep)
7921                         RIDBIT_SET (RID_INLINE, specbits);
7922                       if (staticp)
7923                         RIDBIT_SET (RID_STATIC, specbits);
7924                     }
7925                     type = TYPE_POINTER_TO (ctype);
7926                     if (decl_context == FIELD &&
7927                         IS_SIGNATURE (current_class_type))
7928                       {
7929                         error ("constructor not allowed in signature");
7930                         return void_type_node;
7931                       }                   
7932                     else if (decl_context == FIELD)
7933                       {
7934                         if (! member_function_or_else (ctype, current_class_type,
7935                                                        "constructor for alien class `%s' cannot be member"))
7936                           return void_type_node;
7937                         TYPE_HAS_CONSTRUCTOR (ctype) = 1;
7938                         if (return_type != return_ctor)
7939                           return NULL_TREE;
7940                       }
7941                   }
7942                 if (decl_context == FIELD)
7943                   staticp = 0;
7944               }
7945             else if (friendp && virtualp)
7946               {
7947                 /* Cannot be both friend and virtual.  */
7948                 error ("virtual functions cannot be friends");
7949                 RIDBIT_RESET (RID_FRIEND, specbits);
7950                 friendp = 0;
7951               }
7952
7953             if (decl_context == NORMAL && friendp)
7954               error ("friend declaration not in class definition");
7955
7956             /* Pick up type qualifiers which should be applied to `this'.  */
7957             quals = TREE_OPERAND (declarator, 2);
7958
7959             /* Traditionally, declaring return type float means double.  */
7960
7961             if (flag_traditional
7962                 && TYPE_MAIN_VARIANT (type) == float_type_node)
7963               {
7964                 type = build_type_variant (double_type_node,
7965                                            TYPE_READONLY (type),
7966                                            TYPE_VOLATILE (type));
7967               }
7968
7969             /* Construct the function type and go to the next
7970                inner layer of declarator.  */
7971
7972             {
7973               int funcdef_p;
7974               tree inner_parms = TREE_OPERAND (declarator, 1);
7975               tree inner_decl = TREE_OPERAND (declarator, 0);
7976
7977               declarator = TREE_OPERAND (declarator, 0);
7978
7979               if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
7980                 inner_decl = TREE_OPERAND (inner_decl, 1);
7981
7982               /* Say it's a definition only for the CALL_EXPR
7983                  closest to the identifier.  */
7984               funcdef_p =
7985                 (inner_decl &&
7986                  (TREE_CODE (inner_decl) == IDENTIFIER_NODE
7987                   || TREE_CODE (inner_decl) == TYPE_EXPR)) ? funcdef_flag : 0;
7988
7989               /* FIXME: This is where default args should be fully
7990                  processed.  */
7991
7992               arg_types = grokparms (inner_parms, funcdef_p);
7993             }
7994
7995             if (declarator)
7996               {
7997                 /* Get past destructors, etc.
7998                    We know we have one because FLAGS will be non-zero.
7999
8000                    Complain about improper parameter lists here.  */
8001                 if (TREE_CODE (declarator) == BIT_NOT_EXPR)
8002                   {
8003                     declarator = TREE_OPERAND (declarator, 0);
8004
8005                     if (strict_prototype == 0 && arg_types == NULL_TREE)
8006                       arg_types = void_list_node;
8007                     else if (arg_types == NULL_TREE
8008                              || arg_types != void_list_node)
8009                       {
8010                         error ("destructors cannot be specified with parameters");
8011                         arg_types = void_list_node;
8012                       }
8013                   }
8014               }
8015
8016             /* ANSI seems to say that `const int foo ();'
8017                does not make the function foo const.  */
8018             type = build_function_type (type,
8019                                         flag_traditional ? 0 : arg_types);
8020           }
8021           break;
8022
8023         case ADDR_EXPR:
8024         case INDIRECT_REF:
8025           /* Filter out pointers-to-references and references-to-references.
8026              We can get these if a TYPE_DECL is used.  */
8027
8028           if (TREE_CODE (type) == REFERENCE_TYPE)
8029             {
8030               error ("cannot declare %s to references",
8031                      TREE_CODE (declarator) == ADDR_EXPR
8032                      ? "references" : "pointers");
8033               declarator = TREE_OPERAND (declarator, 0);
8034               continue;
8035             }
8036
8037           /* Merge any constancy or volatility into the target type
8038              for the pointer.  */
8039
8040           if (constp || volatilep)
8041             {
8042               /* A const or volatile signature pointer/reference is
8043                  pointing to a const or volatile object, i.e., the
8044                  `optr' is const or volatile, respectively, not the
8045                  signature pointer/reference itself.  */
8046               if (! IS_SIGNATURE (type))
8047                 {
8048                   type = build_type_variant (type, constp, volatilep);
8049                   if (IS_AGGR_TYPE (type))
8050                     build_pointer_type (type);
8051                   constp = 0;
8052                   volatilep = 0;
8053                 }
8054             }
8055
8056           if (IS_SIGNATURE (type))
8057             {
8058               if (TREE_CODE (declarator) == ADDR_EXPR)
8059                 {
8060                   if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE)
8061                     warning ("empty signature `%s' used in signature reference declaration",
8062                              TYPE_NAME_STRING(type));
8063 #if 0
8064                   type = build_signature_reference_type (type,
8065                                                          constp, volatilep);
8066 #else
8067                   sorry ("signature reference");
8068                   return NULL_TREE;
8069 #endif
8070                 }
8071               else
8072                 {
8073                   if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE)
8074                     warning ("empty signature `%s' used in signature pointer declaration",
8075                              TYPE_NAME_STRING(type));
8076                   type = build_signature_pointer_type (type,
8077                                                        constp, volatilep);
8078                 }
8079               constp = 0;
8080               volatilep = 0;
8081             }
8082           else if (TREE_CODE (declarator) == ADDR_EXPR)
8083             {
8084               if (TREE_CODE (type) == FUNCTION_TYPE)
8085                 {
8086                   error ("cannot declare references to functions; use pointer to function instead");
8087                   type = build_pointer_type (type);
8088                 }
8089               else
8090                 {
8091                   if (TYPE_MAIN_VARIANT (type) == void_type_node)
8092                     error ("invalid type: `void &'");
8093                   else
8094                     type = build_reference_type (type);
8095                 }
8096             }
8097           else if (TREE_CODE (type) == METHOD_TYPE)
8098             {
8099               type = build_ptrmemfunc_type (build_pointer_type (type));
8100             }
8101           else
8102             type = build_pointer_type (type);
8103
8104           /* Process a list of type modifier keywords (such as
8105              const or volatile) that were given inside the `*' or `&'.  */
8106
8107           if (TREE_TYPE (declarator))
8108             {
8109               register tree typemodlist;
8110               int erred = 0;
8111               for (typemodlist = TREE_TYPE (declarator); typemodlist;
8112                    typemodlist = TREE_CHAIN (typemodlist))
8113                 {
8114                   if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
8115                     constp++;
8116                   else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
8117                     volatilep++;
8118                   else if (!erred)
8119                     {
8120                       erred = 1;
8121                       error ("invalid type modifier within %s declarator",
8122                              TREE_CODE (declarator) == ADDR_EXPR
8123                              ? "reference" : "pointer");
8124                     }
8125                 }
8126               if (constp > 1)
8127                 warning ("duplicate `const'");
8128               if (volatilep > 1)
8129                 warning ("duplicate `volatile'");
8130             }
8131           declarator = TREE_OPERAND (declarator, 0);
8132           ctype = NULL_TREE;
8133           break;
8134
8135         case SCOPE_REF:
8136           {
8137             /* We have converted type names to NULL_TREE if the
8138                name was bogus, or to a _TYPE node, if not.
8139
8140                The variable CTYPE holds the type we will ultimately
8141                resolve to.  The code here just needs to build
8142                up appropriate member types.  */
8143             tree sname = TREE_OPERAND (declarator, 1);
8144             /* Destructors can have their visibilities changed as well.  */
8145             if (TREE_CODE (sname) == BIT_NOT_EXPR)
8146               sname = TREE_OPERAND (sname, 0);
8147
8148             if (TREE_COMPLEXITY (declarator) == 0)
8149               /* This needs to be here, in case we are called
8150                  multiple times.  */ ;
8151             else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
8152               /* don't fall out into global scope. Hides real bug? --eichin */ ;
8153             else if (TREE_COMPLEXITY (declarator) == current_class_depth)
8154               {
8155                 /* I'm not really sure what pushclass calls this popclass
8156                    corresponds to.  One is in build_push_scope and that has
8157                    been changed to a push_nested_class call, that's why I
8158                    try to use pop_nested_class here instead.
8159                    -niklas@appli.se */
8160                 pop_nested_class (1);
8161                 TREE_COMPLEXITY (declarator) = current_class_depth;
8162               }
8163             else
8164               my_friendly_abort (16);
8165
8166             if (TREE_OPERAND (declarator, 0) == NULL_TREE)
8167               {
8168                 /* We had a reference to a global decl, or
8169                    perhaps we were given a non-aggregate typedef,
8170                    in which case we cleared this out, and should just
8171                    keep going as though it wasn't there.  */
8172                 declarator = sname;
8173                 continue;
8174               }
8175             ctype = TREE_OPERAND (declarator, 0);
8176
8177             if (sname == NULL_TREE)
8178               goto done_scoping;
8179
8180             if (TREE_CODE (sname) == IDENTIFIER_NODE)
8181               {
8182                 /* This is the `standard' use of the scoping operator:
8183                    basetype :: member .  */
8184
8185                 if (TREE_CODE (type) == FUNCTION_TYPE)
8186                   {
8187                     if (current_class_type == NULL_TREE
8188                         || TYPE_MAIN_VARIANT (ctype) == current_class_type
8189                         || friendp)
8190                       type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8191                                                       TREE_TYPE (type), TYPE_ARG_TYPES (type));
8192                     else
8193                       {
8194                         error ("cannot declare member function `%s::%s' within this class",
8195                                TYPE_NAME_STRING (ctype), name);
8196                         return void_type_node;
8197                       }
8198                   }
8199                 else if (TYPE_MAIN_VARIANT (ctype) == current_class_type)
8200                   {
8201                     if (extra_warnings)
8202                       warning ("extra qualification `%s' on member `%s' ignored",
8203                                TYPE_NAME_STRING (ctype), name);
8204                     type = build_offset_type (ctype, type);
8205                   }
8206                 else if (TYPE_SIZE (ctype) != NULL_TREE
8207                          || (RIDBIT_SETP (RID_TYPEDEF, specbits)))
8208                   {
8209                     tree t;
8210                     /* have to move this code elsewhere in this function.
8211                        this code is used for i.e., typedef int A::M; M *pm; */
8212
8213                     if (explicit_int == -1 && decl_context == FIELD
8214                         && funcdef_flag == 0)
8215                       {
8216                         /* The code in here should only be used to build
8217                            stuff that will be grokked as access decls.  */
8218                         t = lookup_field (ctype, sname, 0, 0);
8219                         if (t)
8220                           {
8221                             t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
8222                             DECL_INITIAL (t) = init;
8223                             return t;
8224                           }
8225                         /* No such field, try member functions.  */
8226                         t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
8227                         if (t)
8228                           {
8229                             if (flags == DTOR_FLAG)
8230                               t = TREE_VALUE (t);
8231                             else if (CLASSTYPE_METHOD_VEC (ctype)
8232                                      && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
8233                               {
8234                                 /* Don't include destructor with constructors.  */
8235                                 t = DECL_CHAIN (TREE_VALUE (t));
8236                                 if (t == NULL_TREE)
8237                                   error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname));
8238                                 t = build_tree_list (NULL_TREE, t);
8239                               }
8240                             t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
8241                             DECL_INITIAL (t) = init;
8242                             return t;
8243                           }
8244
8245                         if (flags == TYPENAME_FLAG)
8246                           cp_error ("type conversion is not a member of structure `%T'", ctype);
8247                         else
8248                           cp_error
8249                             ("field `%D' is not a member of structure `%T'",
8250                              sname, ctype);
8251                       }
8252
8253                     if (current_class_type)
8254                       {
8255                         if (TYPE_MAIN_VARIANT (ctype) != current_class_type)
8256                           {
8257                             cp_error ("cannot declare member `%T::%s' within `%T'",
8258                                    ctype, name, current_class_type);
8259                             return void_type_node;
8260                           }
8261                         else if (extra_warnings)
8262                           cp_warning ("extra qualification `%T' on member `%s' ignored",
8263                                    ctype, name);
8264                       }
8265                     type = build_offset_type (ctype, type);
8266                   }
8267                 else if (uses_template_parms (ctype))
8268                   {
8269                     enum tree_code c;
8270                     if (TREE_CODE (type) == FUNCTION_TYPE)
8271                       {
8272                         type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8273                                                         TREE_TYPE (type),
8274                                                         TYPE_ARG_TYPES (type));
8275                         c = FUNCTION_DECL;
8276                       }
8277                   }
8278                 else
8279                   {
8280                     cp_error ("structure `%T' not yet defined", ctype);
8281                     return error_mark_node;
8282                   }
8283
8284                 declarator = sname;
8285               }
8286             else if (TREE_CODE (sname) == TYPE_EXPR)
8287               {
8288                 /* A TYPE_EXPR will change types out from under us.
8289                    So do the TYPE_EXPR now, and make this SCOPE_REF
8290                    inner to the TYPE_EXPR's CALL_EXPR.
8291
8292                    This does not work if we don't get a CALL_EXPR back.
8293                    I did not think about error recovery, hence the
8294                    my_friendly_abort.  */
8295
8296                 /* Get the CALL_EXPR.  */
8297                 sname = grokoptypename (sname, 0);
8298                 my_friendly_assert (TREE_CODE (sname) == CALL_EXPR, 157);
8299                 type = TREE_TYPE (TREE_OPERAND (sname, 0));
8300                 /* Scope the CALL_EXPR's name.  */
8301                 TREE_OPERAND (declarator, 1) = TREE_OPERAND (sname, 0);
8302                 /* Put the SCOPE_EXPR in the CALL_EXPR's innermost position.  */
8303                 TREE_OPERAND (sname, 0) = declarator;
8304                 /* Now work from the CALL_EXPR.  */
8305                 declarator = sname;
8306                 continue;
8307               }
8308             else if (TREE_CODE (sname) == SCOPE_REF)
8309               my_friendly_abort (17);
8310             else
8311               {
8312               done_scoping:
8313                 declarator = TREE_OPERAND (declarator, 1);
8314                 if (declarator && TREE_CODE (declarator) == CALL_EXPR)
8315                   /* In this case, we will deal with it later.  */
8316                   ;
8317                 else
8318                   {
8319                     if (TREE_CODE (type) == FUNCTION_TYPE)
8320                       type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
8321                     else
8322                       type = build_offset_type (ctype, type);
8323                   }
8324               }
8325           }
8326           break;
8327
8328         case BIT_NOT_EXPR:
8329           declarator = TREE_OPERAND (declarator, 0);
8330           break;
8331
8332         case TYPE_EXPR:
8333           declarator = grokoptypename (declarator, 0);
8334           if (explicit_int != -1)
8335             {
8336               tree stype = TREE_TYPE (TREE_OPERAND (declarator, 0));
8337               if (comp_target_types (type, stype, 1) == 0)
8338                 cp_error ("`operator %T' declared to return `%T'", stype,
8339                           type);
8340               else
8341                 cp_pedwarn ("return type specified for `operator %T'", type);
8342             }
8343           dname = declarator;
8344           type = TREE_TYPE (TREE_OPERAND (declarator, 0));
8345           break;
8346
8347         case RECORD_TYPE:
8348         case UNION_TYPE:
8349         case ENUMERAL_TYPE:
8350           declarator = NULL_TREE;
8351           break;
8352
8353         case ERROR_MARK:
8354           declarator = NULL_TREE;
8355           break;
8356
8357         default:
8358           my_friendly_abort (158);
8359         }
8360     }
8361
8362   /* Now TYPE has the actual type.  */
8363
8364   /* If this is declaring a typedef name, return a TYPE_DECL.  */
8365
8366   if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8367     {
8368       tree decl;
8369
8370       /* Note that the grammar rejects storage classes
8371          in typenames, fields or parameters.  */
8372       if (constp || volatilep)
8373         type = build_type_variant (type, constp, volatilep);
8374
8375       /* If the user declares "struct {...} foo" then `foo' will have
8376          an anonymous name.  Fill that name in now.  Nothing can
8377          refer to it, so nothing needs know about the name change.
8378          The TYPE_NAME field was filled in by build_struct_xref.  */
8379       if (type != error_mark_node
8380           && TYPE_NAME (type)
8381           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8382           && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
8383         {
8384           /* replace the anonymous name with the real name everywhere.  */
8385           lookup_tag_reverse (type, declarator);
8386           TYPE_IDENTIFIER (type) = declarator;
8387
8388           if (TYPE_LANG_SPECIFIC (type))
8389             TYPE_WAS_ANONYMOUS (type) = 1;
8390
8391           {
8392             tree d = TYPE_NAME (type), c = DECL_CONTEXT (d);
8393
8394             if (!c)
8395               set_nested_typename (d, 0, declarator, type);
8396             else if (TREE_CODE (c) == FUNCTION_DECL)
8397               set_nested_typename (d, DECL_ASSEMBLER_NAME (c),
8398                                    declarator, type);
8399             else
8400               set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type);
8401           }
8402         }
8403
8404 #if 0 /* not yet, should get fixed properly later */
8405       decl = make_type_decl (declarator, type);
8406 #else
8407       decl = build_decl (TYPE_DECL, declarator, type);
8408 #endif
8409       if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
8410         {
8411           cp_error_at ("typedef name may not be class-qualified", decl);
8412           TREE_TYPE (decl) = error_mark_node;
8413         }
8414       else if (quals)
8415         {
8416           if (ctype == NULL_TREE)
8417             {
8418               if (TREE_CODE (type) != METHOD_TYPE)
8419                 cp_error_at ("invalid type qualifier for non-method type", decl);
8420               else
8421                 ctype = TYPE_METHOD_BASETYPE (type);
8422             }
8423           if (ctype != NULL_TREE)
8424             grok_method_quals (ctype, decl, quals);
8425         }
8426
8427       if (RIDBIT_SETP (RID_SIGNED, specbits)
8428           || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
8429         C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
8430
8431       if (RIDBIT_SETP (RID_MUTABLE, specbits))
8432         {
8433           error ("non-object member `%s' cannot be declared mutable", name);
8434         }
8435
8436       return decl;
8437     }
8438
8439   /* Detect the case of an array type of unspecified size
8440      which came, as such, direct from a typedef name.
8441      We must copy the type, so that each identifier gets
8442      a distinct type, so that each identifier's size can be
8443      controlled separately by its own initializer.  */
8444
8445   if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
8446       && TYPE_DOMAIN (type) == NULL_TREE)
8447     {
8448       type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
8449     }
8450
8451   /* If this is a type name (such as, in a cast or sizeof),
8452      compute the type and return it now.  */
8453
8454   if (decl_context == TYPENAME)
8455     {
8456       /* Note that the grammar rejects storage classes
8457          in typenames, fields or parameters.  */
8458       if (constp || volatilep)
8459         if (IS_SIGNATURE (type))
8460           error ("`const' or `volatile' specified with signature type");
8461         else  
8462           type = build_type_variant (type, constp, volatilep);
8463
8464       /* Special case: "friend class foo" looks like a TYPENAME context.  */
8465       if (friendp)
8466         {
8467           /* A friendly class?  */
8468           if (current_class_type)
8469             make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
8470           else
8471             error("trying to make class `%s' a friend of global scope",
8472                   TYPE_NAME_STRING (type));
8473           type = void_type_node;
8474         }
8475       else if (quals)
8476         {
8477 #if 0 /* not yet, should get fixed properly later */
8478           tree dummy = make_type_decl (declarator, type);
8479 #else
8480           tree dummy = build_decl (TYPE_DECL, declarator, type);
8481 #endif
8482           if (ctype == NULL_TREE)
8483             {
8484               my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
8485               ctype = TYPE_METHOD_BASETYPE (type);
8486             }
8487           grok_method_quals (ctype, dummy, quals);
8488           type = TREE_TYPE (dummy);
8489         }
8490
8491       return type;
8492     }
8493   else if (declarator == NULL_TREE && decl_context != PARM
8494            && TREE_CODE (type) != UNION_TYPE
8495            && ! bitfield)
8496     {
8497       cp_error ("abstract declarator `%T' used as declaration", type);
8498       declarator = make_anon_name ();
8499     }
8500
8501   /* `void' at top level (not within pointer)
8502      is allowed only in typedefs or type names.
8503      We don't complain about parms either, but that is because
8504      a better error message can be made later.  */
8505
8506   if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
8507     {
8508       if (TREE_CODE (declarator) == IDENTIFIER_NODE)
8509         {
8510           if (IDENTIFIER_OPNAME_P (declarator))
8511 #if 0                           /* How could this happen? */
8512             error ("operator `%s' declared void",
8513                    operator_name_string (declarator));
8514 #else
8515             my_friendly_abort (356);
8516 #endif
8517           else
8518             error ("variable or field `%s' declared void", name);
8519         }
8520       else
8521         error ("variable or field declared void");
8522       type = integer_type_node;
8523     }
8524
8525   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
8526      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
8527
8528   {
8529     register tree decl;
8530
8531     if (decl_context == PARM)
8532       {
8533         tree parmtype = type;
8534
8535         if (ctype)
8536           error ("cannot use `::' in parameter declaration");
8537
8538         /* A parameter declared as an array of T is really a pointer to T.
8539            One declared as a function is really a pointer to a function.
8540            One declared as a member is really a pointer to member.
8541
8542            Don't be misled by references.  */
8543
8544         if (TREE_CODE (type) == REFERENCE_TYPE)
8545           type = TREE_TYPE (type);
8546
8547         if (TREE_CODE (type) == ARRAY_TYPE)
8548           {
8549             if (parmtype == type)
8550               {
8551                 /* Transfer const-ness of array into that of type
8552                    pointed to.  */
8553                 type = build_pointer_type
8554                   (build_type_variant (TREE_TYPE (type), constp, volatilep));
8555                 volatilep = constp = 0;
8556               }
8557             else
8558               type = build_pointer_type (TREE_TYPE (type));
8559           }
8560         else if (TREE_CODE (type) == FUNCTION_TYPE)
8561           type = build_pointer_type (type);
8562         else if (TREE_CODE (type) == OFFSET_TYPE)
8563           type = build_pointer_type (type);
8564
8565         if (TREE_CODE (parmtype) == REFERENCE_TYPE)
8566           {
8567             /* Transfer const-ness of reference into that of type pointed to.  */
8568             type = build_type_variant (build_reference_type (type), constp, volatilep);
8569             constp = volatilep = 0;
8570           }
8571
8572         decl = build_decl (PARM_DECL, declarator, type);
8573
8574         bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
8575                         inlinep, friendp, raises != NULL_TREE);
8576         if (current_class_type
8577             && IS_SIGNATURE (current_class_type))
8578           {
8579             if (inlinep)
8580               error ("parameter of signature member function declared `inline'");
8581             if (RIDBIT_SETP (RID_AUTO, specbits))
8582               error ("parameter of signature member function declared `auto'");
8583             if (RIDBIT_SETP (RID_REGISTER, specbits))
8584               error ("parameter of signature member function declared `register'");
8585           }
8586
8587         /* Compute the type actually passed in the parmlist,
8588            for the case where there is no prototype.
8589            (For example, shorts and chars are passed as ints.)
8590            When there is a prototype, this is overridden later.  */
8591
8592         DECL_ARG_TYPE (decl) = type;
8593         if (TYPE_MAIN_VARIANT (type) == float_type_node)
8594           DECL_ARG_TYPE (decl) = build_type_variant (double_type_node,
8595                                                      TYPE_READONLY (type),
8596                                                      TYPE_VOLATILE (type));
8597         else if (C_PROMOTING_INTEGER_TYPE_P (type))
8598           {
8599             tree argtype;
8600
8601             /* Retain unsignedness if traditional or if not really
8602                getting wider.  */
8603             if (TREE_UNSIGNED (type)
8604                 && (flag_traditional
8605                     || TYPE_PRECISION (type)
8606                         == TYPE_PRECISION (integer_type_node)))
8607               argtype = unsigned_type_node;
8608             else
8609               argtype = integer_type_node;
8610             DECL_ARG_TYPE (decl) = build_type_variant (argtype,
8611                                                        TYPE_READONLY (type),
8612                                                        TYPE_VOLATILE (type));
8613           }
8614       }
8615     else if (decl_context == FIELD)
8616       {
8617         if (type == error_mark_node)
8618           {
8619             /* Happens when declaring arrays of sizes which
8620                are error_mark_node, for example.  */
8621             decl = NULL_TREE;
8622           }
8623         else if (TREE_CODE (type) == FUNCTION_TYPE)
8624           {
8625             int publicp = 0;
8626
8627             if (friendp == 0)
8628               {
8629                 if (ctype == NULL_TREE)
8630                   ctype = current_class_type;
8631
8632                 if (ctype == NULL_TREE)
8633                   {
8634                     cp_error ("can't make `%D' into a method -- not in a class",
8635                               declarator);
8636                     return void_type_node;
8637                   }
8638
8639                 /* ``A union may [ ... ] not [ have ] virtual functions.''
8640                    ARM 9.5 */
8641                 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
8642                   {
8643                     cp_error ("function `%D' declared virtual inside a union",
8644                               declarator);
8645                     return void_type_node;
8646                   }
8647
8648                 if (declarator == ansi_opname[(int) NEW_EXPR]
8649                     || declarator == ansi_opname[(int) DELETE_EXPR])
8650                   {
8651                     if (virtualp)
8652                       {
8653                         cp_error ("`%D' cannot be declared virtual, since it is always static",
8654                                   declarator);
8655                         virtualp = 0;
8656                       }
8657                   }
8658                 else if (staticp < 2)
8659                   type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8660                                                   TREE_TYPE (type), TYPE_ARG_TYPES (type));
8661               }
8662
8663             /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
8664             publicp = (RIDBIT_SETP (RID_EXTERN, specbits)
8665                        || (ctype != NULL_TREE && funcdef_flag >= 0)
8666                        || (friendp
8667                            && ! funcdef_flag
8668                            && RIDBIT_NOTSETP (RID_STATIC, specbits)
8669                            && RIDBIT_NOTSETP (RID_INLINE, specbits)));
8670             decl = grokfndecl (ctype, type, declarator,
8671                                virtualp, flags, quals,
8672                                raises, friendp ? -1 : 0, publicp);
8673             DECL_INLINE (decl) = inlinep;
8674           }
8675         else if (TREE_CODE (type) == METHOD_TYPE)
8676           {
8677             /* All method decls are public, so tell grokfndecl to set
8678                TREE_PUBLIC, also.  */
8679             decl = grokfndecl (ctype, type, declarator,
8680                                virtualp, flags, quals,
8681                                raises, friendp ? -1 : 0, 1);
8682             DECL_INLINE (decl) = inlinep;
8683           }
8684         else if (TREE_CODE (type) == RECORD_TYPE
8685                  && CLASSTYPE_DECLARED_EXCEPTION (type))
8686           {
8687             /* Handle a class-local exception declaration.  */
8688             decl = build_lang_field_decl (VAR_DECL, declarator, type);
8689             if (ctype == NULL_TREE)
8690               ctype = current_class_type;
8691             finish_exception_decl (TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
8692                                    ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype), decl);
8693             return void_type_node;
8694           }
8695         else if (TYPE_SIZE (type) == NULL_TREE && !staticp
8696                  && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
8697           {
8698             error ("field `%s' has incomplete type",
8699                    IDENTIFIER_POINTER (declarator));
8700
8701             /* If we're instantiating a template, tell them which
8702                instantiation made the field's type be incomplete.  */
8703             if (current_class_type
8704                 && TYPE_NAME (current_class_type)
8705                 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type)))
8706                 && declspecs && TREE_VALUE (declspecs)
8707                 && TREE_TYPE (TREE_VALUE (declspecs)) == type)
8708               error ("  in instantiation of template `%s'",
8709                      TYPE_NAME_STRING (current_class_type));
8710                 
8711             type = error_mark_node;
8712             decl = NULL_TREE;
8713           }
8714         else
8715           {
8716             if (friendp)
8717               {
8718                 error ("`%s' is neither function nor method; cannot be declared friend",
8719                        IDENTIFIER_POINTER (declarator));
8720                 friendp = 0;
8721               }
8722             decl = NULL_TREE;
8723           }
8724
8725         if (friendp)
8726           {
8727             /* Friends are treated specially.  */
8728             if (ctype == current_class_type)
8729               warning ("member functions are implicitly friends of their class");
8730             else
8731               {
8732                 tree t = NULL_TREE;
8733                 if (decl && DECL_NAME (decl))
8734                   t = do_friend (ctype, declarator, decl,
8735                                  last_function_parms, flags, quals);
8736                 if (t && funcdef_flag)
8737                   return t;
8738                 
8739                 return void_type_node;
8740               }
8741           }
8742
8743         /* Structure field.  It may not be a function, except for C++ */
8744
8745         if (decl == NULL_TREE)
8746           {
8747             /* ANSI C++ June 5 1992 WP 9.2.2 and 9.4.2.  A member-declarator
8748                cannot have an initializer, and a static member declaration must
8749                be defined elsewhere.  */
8750             if (initialized)
8751               {
8752                 if (staticp)
8753                   error ("static member `%s' must be defined separately from its declaration",
8754                           IDENTIFIER_POINTER (declarator));
8755                 /* Note that initialization of const members is prohibited
8756                    by the draft ANSI standard, though it appears to be in
8757                    common practice.  12.6.2: The argument list is used to
8758                    initialize the named nonstatic member....  This (or an
8759                    aggregate) is the only way to initialize nonstatic const
8760                    and reference members.  */
8761                 else
8762                   pedwarn ("ANSI C++ forbids initialization of %s `%s'",
8763                            constp ? "const member" : "member",
8764                            IDENTIFIER_POINTER (declarator));
8765               }
8766
8767             if (staticp || (constp && initialized))
8768               {
8769                 /* C++ allows static class members.
8770                    All other work for this is done by grokfield.
8771                    This VAR_DECL is built by build_lang_field_decl.
8772                    All other VAR_DECLs are built by build_decl.  */
8773                 decl = build_lang_field_decl (VAR_DECL, declarator, type);
8774                 if (staticp || TREE_CODE (type) == ARRAY_TYPE)
8775                   TREE_STATIC (decl) = 1;
8776                 /* In class context, static means public access.  */
8777                 TREE_PUBLIC (decl) = 1;
8778                 DECL_EXTERNAL (decl) = !initialized;
8779               }
8780             else
8781               {
8782                 decl = build_lang_field_decl (FIELD_DECL, declarator, type);
8783                 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8784                   {
8785                     DECL_MUTABLE_P (decl) = 1;
8786                     RIDBIT_RESET (RID_MUTABLE, specbits);
8787                   }
8788               }
8789
8790             bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
8791                             inlinep, friendp, raises != NULL_TREE);
8792           }
8793       }
8794     else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
8795       {
8796         int was_overloaded = 0;
8797         tree original_name = declarator;
8798         int publicp = 0;
8799
8800         if (! declarator)
8801           return NULL_TREE;
8802
8803         if (RIDBIT_SETP (RID_AUTO, specbits)
8804             || RIDBIT_SETP (RID_REGISTER, specbits))
8805           error ("invalid storage class for function `%s'", name);
8806
8807         /* Function declaration not at top level.
8808            Storage classes other than `extern' are not allowed
8809            and `extern' makes no difference.  */
8810         if (current_binding_level != global_binding_level
8811             && (RIDBIT_SETP (RID_STATIC, specbits) || RIDBIT_SETP (RID_INLINE, specbits))
8812             && pedantic)
8813           pedwarn ("invalid storage class for function `%s'", name);
8814
8815         if (ctype == NULL_TREE)
8816           {
8817             if (virtualp)
8818               {
8819                 error ("virtual non-class function `%s'", name);
8820                 virtualp = 0;
8821               }
8822
8823             if (current_lang_name == lang_name_cplusplus
8824                 && ! (IDENTIFIER_LENGTH (original_name) == 4
8825                       && IDENTIFIER_POINTER (original_name)[0] == 'm'
8826                       && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
8827                 && ! (IDENTIFIER_LENGTH (original_name) > 10
8828                       && IDENTIFIER_POINTER (original_name)[0] == '_'
8829                       && IDENTIFIER_POINTER (original_name)[1] == '_'
8830                       && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
8831               {
8832                 /* Plain overloading: will not be grok'd by grokclassfn.  */
8833                 declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
8834                 was_overloaded = 1;
8835               }
8836           }
8837         else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
8838           type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8839                                           TREE_TYPE (type), TYPE_ARG_TYPES (type));
8840
8841         /* Record presence of `static'.  In C++, `inline' is like `static'.
8842            Methods of classes should be public, unless we're dropping them
8843            into some other file, so we don't clear TREE_PUBLIC for them.  */
8844         publicp
8845           = ((ctype
8846               && CLASSTYPE_INTERFACE_KNOWN (ctype)
8847               && ! CLASSTYPE_INTERFACE_ONLY (ctype))
8848              || !(RIDBIT_SETP (RID_STATIC, specbits)
8849                   || RIDBIT_SETP (RID_INLINE, specbits)));
8850
8851         decl = grokfndecl (ctype, type, original_name,
8852                            virtualp, flags, quals,
8853                            raises,
8854                            processing_template_decl ? 0 : friendp ? 2 : 1,
8855                            publicp);
8856
8857         if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
8858           DECL_ASSEMBLER_NAME (decl) = declarator;
8859
8860         if (staticp == 1)
8861           {
8862             int illegal_static = 0;
8863
8864             /* Don't allow a static member function in a class, and forbid
8865                declaring main to be static.  */
8866             if (TREE_CODE (type) == METHOD_TYPE)
8867               {
8868                 cp_error_at ("cannot declare member function `%D' to have static linkage", decl);
8869                 illegal_static = 1;
8870               }
8871             else if (! was_overloaded
8872                      && ! ctype
8873                      && IDENTIFIER_LENGTH (original_name) == 4
8874                      && IDENTIFIER_POINTER (original_name)[0] == 'm'
8875                      && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
8876               {
8877                 error ("cannot declare function `main' to have static linkage");
8878                 illegal_static = 1;
8879               }
8880             else if (current_function_decl)
8881               {
8882                 /* FIXME need arm citation */
8883                 error ("cannot declare static function inside another function");
8884                 illegal_static = 1;
8885               }
8886
8887             if (illegal_static)
8888               {
8889                 staticp = 0;
8890                 RIDBIT_RESET (RID_STATIC, specbits);
8891               }
8892           }
8893
8894         /* Record presence of `inline', if it is reasonable.  */
8895         if (inlinep)
8896           {
8897             tree last = tree_last (TYPE_ARG_TYPES (type));
8898
8899             if (! was_overloaded
8900                 && ! ctype
8901                 && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
8902               error ("cannot inline function `main'");
8903             else if (last && last != void_list_node)
8904               cp_warning ("cannot inline function `%D' which takes `...'", original_name);
8905             else
8906               /* Assume that otherwise the function can be inlined.  */
8907               DECL_INLINE (decl) = 1;
8908
8909             if (RIDBIT_SETP (RID_EXTERN, specbits))
8910               {
8911                 current_extern_inline = 1;
8912                 if (flag_ansi || pedantic || flag_pedantic_errors)
8913                   pedwarn ("ANSI C++ does not permit `extern inline'");
8914               }
8915           }
8916         if (was_overloaded)
8917           DECL_OVERLOADED (decl) = 1;
8918       }
8919     else
8920       {
8921         /* It's a variable.  */
8922
8923         /* An uninitialized decl with `extern' is a reference.  */
8924         decl = grokvardecl (type, declarator, specbits, initialized);
8925         bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
8926                         inlinep, friendp, raises != NULL_TREE);
8927
8928         if (ctype)
8929           {
8930             if (staticp == 1)
8931               {
8932                 cp_error ("static member `%D' re-declared as static",
8933                           decl);
8934                 staticp = 0;
8935                 RIDBIT_RESET (RID_STATIC, specbits);
8936               }
8937             if (RIDBIT_SETP (RID_EXTERN, specbits))
8938               {
8939                 cp_error ("cannot explicitly declare member `%#D' to have extern linkage",
8940                           decl);
8941                 RIDBIT_RESET (RID_EXTERN, specbits);
8942               }
8943           }
8944       }
8945
8946     if (RIDBIT_SETP (RID_MUTABLE, specbits))
8947       {
8948         error ("`%s' cannot be declared mutable", name);
8949       }
8950
8951     /* Record `register' declaration for warnings on &
8952        and in case doing stupid register allocation.  */
8953
8954     if (RIDBIT_SETP (RID_REGISTER, specbits))
8955       DECL_REGISTER (decl) = 1;
8956
8957     /* Record constancy and volatility.  */
8958
8959     if (constp)
8960       TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
8961     if (volatilep)
8962       {
8963         TREE_SIDE_EFFECTS (decl) = 1;
8964         TREE_THIS_VOLATILE (decl) = 1;
8965       }
8966
8967     return decl;
8968   }
8969 }
8970 \f
8971 /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
8972    An empty exprlist is a parmlist.  An exprlist which
8973    contains only identifiers at the global level
8974    is a parmlist.  Otherwise, it is an exprlist.  */
8975 int
8976 parmlist_is_exprlist (exprs)
8977      tree exprs;
8978 {
8979   if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
8980     return 0;
8981
8982   if (current_binding_level == global_binding_level)
8983     {
8984       /* At the global level, if these are all identifiers,
8985          then it is a parmlist.  */
8986       while (exprs)
8987         {
8988           if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
8989             return 1;
8990           exprs = TREE_CHAIN (exprs);
8991         }
8992       return 0;
8993     }
8994   return 1;
8995 }
8996
8997 /* Subroutine of `grokparms'.  In a fcn definition, arg types must
8998    be complete.
8999
9000    C++: also subroutine of `start_function'.  */
9001 static void
9002 require_complete_types_for_parms (parms)
9003      tree parms;
9004 {
9005   while (parms)
9006     {
9007       tree type = TREE_TYPE (parms);
9008       if (TYPE_SIZE (type) == NULL_TREE)
9009         {
9010           if (DECL_NAME (parms))
9011             error ("parameter `%s' has incomplete type",
9012                    IDENTIFIER_POINTER (DECL_NAME (parms)));
9013           else
9014             error ("parameter has incomplete type");
9015           TREE_TYPE (parms) = error_mark_node;
9016         }
9017 #if 0
9018       /* If the arg types are incomplete in a declaration,
9019          they must include undefined tags.
9020          These tags can never be defined in the scope of the declaration,
9021          so the types can never be completed,
9022          and no call can be compiled successfully.  */
9023       /* This is not the right behavior for C++, but not having
9024          it is also probably wrong.  */
9025       else
9026         {
9027           /* Now warn if is a pointer to an incomplete type.  */
9028           while (TREE_CODE (type) == POINTER_TYPE
9029                  || TREE_CODE (type) == REFERENCE_TYPE)
9030             type = TREE_TYPE (type);
9031           type = TYPE_MAIN_VARIANT (type);
9032           if (TYPE_SIZE (type) == NULL_TREE)
9033             {
9034               if (DECL_NAME (parm) != NULL_TREE)
9035                 warning ("parameter `%s' points to incomplete type",
9036                          IDENTIFIER_POINTER (DECL_NAME (parm)));
9037               else
9038                 warning ("parameter points to incomplete type");
9039             }
9040         }
9041 #endif
9042       parms = TREE_CHAIN (parms);
9043     }
9044 }
9045
9046 /* Decode the list of parameter types for a function type.
9047    Given the list of things declared inside the parens,
9048    return a list of types.
9049
9050    The list we receive can have three kinds of elements:
9051    an IDENTIFIER_NODE for names given without types,
9052    a TREE_LIST node for arguments given as typespecs or names with typespecs,
9053    or void_type_node, to mark the end of an argument list
9054    when additional arguments are not permitted (... was not used).
9055
9056    FUNCDEF_FLAG is nonzero for a function definition, 0 for
9057    a mere declaration.  A nonempty identifier-list gets an error message
9058    when FUNCDEF_FLAG is zero.
9059    If FUNCDEF_FLAG is 1, then parameter types must be complete.
9060    If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
9061
9062    If all elements of the input list contain types,
9063    we return a list of the types.
9064    If all elements contain no type (except perhaps a void_type_node
9065    at the end), we return a null list.
9066    If some have types and some do not, it is an error, and we
9067    return a null list.
9068
9069    Also set last_function_parms to either
9070    a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
9071    A list of names is converted to a chain of PARM_DECLs
9072    by store_parm_decls so that ultimately it is always a chain of decls.
9073
9074    Note that in C++, parameters can take default values.  These default
9075    values are in the TREE_PURPOSE field of the TREE_LIST.  It is
9076    an error to specify default values which are followed by parameters
9077    that have no default values, or an ELLIPSES.  For simplicities sake,
9078    only parameters which are specified with their types can take on
9079    default values.  */
9080
9081 static tree
9082 grokparms (first_parm, funcdef_flag)
9083      tree first_parm;
9084      int funcdef_flag;
9085 {
9086   tree result = NULL_TREE;
9087   tree decls = NULL_TREE;
9088
9089   if (first_parm != NULL_TREE
9090       && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
9091     {
9092       if (! funcdef_flag)
9093         pedwarn ("parameter names (without types) in function declaration");
9094       last_function_parms = first_parm;
9095       return NULL_TREE;
9096     }
9097   else if (first_parm != NULL_TREE
9098            && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
9099            && TREE_VALUE (first_parm) != void_type_node)
9100     my_friendly_abort (145);
9101   else
9102     {
9103       /* Types were specified.  This is a list of declarators
9104          each represented as a TREE_LIST node.  */
9105       register tree parm, chain;
9106       int any_init = 0, any_error = 0, saw_void = 0;
9107
9108       if (first_parm != NULL_TREE)
9109         {
9110           tree last_result = NULL_TREE;
9111           tree last_decl = NULL_TREE;
9112
9113           for (parm = first_parm; parm != NULL_TREE; parm = chain)
9114             {
9115               tree type, list_node = parm;
9116               register tree decl = TREE_VALUE (parm);
9117               tree init = TREE_PURPOSE (parm);
9118
9119               chain = TREE_CHAIN (parm);
9120               /* @@ weak defense against parse errors.  */
9121               if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
9122                 {
9123                   /* Give various messages as the need arises.  */
9124                   if (TREE_CODE (decl) == STRING_CST)
9125                     error ("invalid string constant `%s'",
9126                            TREE_STRING_POINTER (decl));
9127                   else if (TREE_CODE (decl) == INTEGER_CST)
9128                     error ("invalid integer constant in parameter list, did you forget to give parameter name?");
9129                   continue;
9130                 }
9131
9132               if (decl != void_type_node)
9133                 {
9134                   /* @@ May need to fetch out a `raises' here.  */
9135                   decl = grokdeclarator (TREE_VALUE (decl),
9136                                          TREE_PURPOSE (decl),
9137                                          PARM, init != NULL_TREE, NULL_TREE);
9138                   if (! decl)
9139                     continue;
9140                   type = TREE_TYPE (decl);
9141                   if (TYPE_MAIN_VARIANT (type) == void_type_node)
9142                     decl = void_type_node;
9143                   else if (TREE_CODE (type) == METHOD_TYPE)
9144                     {
9145                       if (DECL_NAME (decl))
9146                         /* Cannot use `error_with_decl' here because
9147                            we don't have DECL_CONTEXT set up yet.  */
9148                         error ("parameter `%s' invalidly declared method type",
9149                                IDENTIFIER_POINTER (DECL_NAME (decl)));
9150                       else
9151                         error ("parameter invalidly declared method type");
9152                       type = build_pointer_type (type);
9153                       TREE_TYPE (decl) = type;
9154                     }
9155                   else if (TREE_CODE (type) == OFFSET_TYPE)
9156                     {
9157                       if (DECL_NAME (decl))
9158                         error ("parameter `%s' invalidly declared offset type",
9159                                IDENTIFIER_POINTER (DECL_NAME (decl)));
9160                       else
9161                         error ("parameter invalidly declared offset type");
9162                       type = build_pointer_type (type);
9163                       TREE_TYPE (decl) = type;
9164                     }
9165                   else if (TREE_CODE (type) == RECORD_TYPE
9166                            && TYPE_LANG_SPECIFIC (type)
9167                            && CLASSTYPE_ABSTRACT_VIRTUALS (type))
9168                     {
9169                       abstract_virtuals_error (decl, type);
9170                       any_error = 1;  /* seems like a good idea */
9171                     }
9172                   else if (TREE_CODE (type) == RECORD_TYPE
9173                            && TYPE_LANG_SPECIFIC (type)
9174                            && IS_SIGNATURE (type))
9175                     {
9176                       signature_error (decl, type);
9177                       any_error = 1;  /* seems like a good idea */
9178                     }
9179                 }
9180
9181               if (decl == void_type_node)
9182                 {
9183                   if (result == NULL_TREE)
9184                     {
9185                       result = void_list_node;
9186                       last_result = result;
9187                     }
9188                   else
9189                     {
9190                       TREE_CHAIN (last_result) = void_list_node;
9191                       last_result = void_list_node;
9192                     }
9193                   saw_void = 1;
9194                   if (chain
9195                       && (chain != void_list_node || TREE_CHAIN (chain)))
9196                     error ("`void' in parameter list must be entire list");
9197                   break;
9198                 }
9199
9200               /* Since there is a prototype, args are passed in their own types.  */
9201               DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
9202 #ifdef PROMOTE_PROTOTYPES
9203               if ((TREE_CODE (type) == INTEGER_TYPE
9204                    || TREE_CODE (type) == ENUMERAL_TYPE)
9205                   && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
9206                 DECL_ARG_TYPE (decl) = integer_type_node;
9207 #endif
9208               if (!any_error)
9209                 {
9210                   if (init)
9211                     {
9212                       any_init++;
9213                       if (TREE_CODE (init) == SAVE_EXPR)
9214                         PARM_DECL_EXPR (init) = 1;
9215                       else if (TREE_CODE (init) == VAR_DECL)
9216                         {
9217                           if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
9218                             {
9219                               /* ``Local variables may not be used in default
9220                                  argument expressions.'' dpANSI C++ 8.2.6 */
9221                               /* If extern int i; within a function is not
9222                                  considered a local variable, then this code is
9223                                  wrong. */
9224                               cp_error ("local variable `%D' may not be used as a default argument", init);
9225                               any_error = 1;
9226                             }
9227                           else if (TREE_READONLY_DECL_P (init))
9228                             init = decl_constant_value (init);
9229                         }
9230                       else
9231                         init = require_instantiated_type (type, init, integer_zero_node);
9232                     }
9233                   else if (any_init)
9234                     {
9235                       error ("all trailing parameters must have default arguments");
9236                       any_error = 1;
9237                     }
9238                 }
9239               else
9240                 init = NULL_TREE;
9241
9242               if (decls == NULL_TREE)
9243                 {
9244                   decls = decl;
9245                   last_decl = decls;
9246                 }
9247               else
9248                 {
9249                   TREE_CHAIN (last_decl) = decl;
9250                   last_decl = decl;
9251                 }
9252               if (TREE_PERMANENT (list_node))
9253                 {
9254                   TREE_PURPOSE (list_node) = init;
9255                   TREE_VALUE (list_node) = type;
9256                   TREE_CHAIN (list_node) = NULL_TREE;
9257                 }
9258               else
9259                 list_node = saveable_tree_cons (init, type, NULL_TREE);
9260               if (result == NULL_TREE)
9261                 {
9262                   result = list_node;
9263                   last_result = result;
9264                 }
9265               else
9266                 {
9267                   TREE_CHAIN (last_result) = list_node;
9268                   last_result = list_node;
9269                 }
9270             }
9271           if (last_result)
9272             TREE_CHAIN (last_result) = NULL_TREE;
9273           /* If there are no parameters, and the function does not end
9274              with `...', then last_decl will be NULL_TREE.  */
9275           if (last_decl != NULL_TREE)
9276             TREE_CHAIN (last_decl) = NULL_TREE;
9277         }
9278     }
9279
9280   last_function_parms = decls;
9281
9282   /* In a fcn definition, arg types must be complete.  */
9283   if (funcdef_flag > 0)
9284     require_complete_types_for_parms (last_function_parms);
9285
9286   return result;
9287 }
9288 \f
9289 /* These memoizing functions keep track of special properties which
9290    a class may have.  `grok_ctor_properties' notices whether a class
9291    has a constructor of the form X(X&), and also complains
9292    if the class has a constructor of the form X(X).
9293    `grok_op_properties' takes notice of the various forms of
9294    operator= which are defined, as well as what sorts of type conversion
9295    may apply.  Both functions take a FUNCTION_DECL as an argument.  */
9296 void
9297 grok_ctor_properties (ctype, decl)
9298      tree ctype, decl;
9299 {
9300   tree parmtypes = FUNCTION_ARG_CHAIN (decl);
9301   tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
9302
9303   /* When a type has virtual baseclasses, a magical first int argument is
9304      added to any ctor so we can tell if the class has been initialized
9305      yet.  This could screw things up in this function, so we deliberately
9306      ignore the leading int if we're in that situation.  */
9307   if (parmtypes
9308       && TREE_VALUE (parmtypes) == integer_type_node
9309       && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
9310     {
9311       parmtypes = TREE_CHAIN (parmtypes);
9312       parmtype = TREE_VALUE (parmtypes);
9313     }
9314
9315   if (TREE_CODE (parmtype) == REFERENCE_TYPE
9316       && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
9317     {
9318       if (TREE_CHAIN (parmtypes) == NULL_TREE
9319           || TREE_CHAIN (parmtypes) == void_list_node
9320           || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
9321         {
9322           TYPE_HAS_INIT_REF (ctype) = 1;
9323           if (TYPE_READONLY (TREE_TYPE (parmtype)))
9324             TYPE_HAS_CONST_INIT_REF (ctype) = 1;
9325         }
9326       else
9327         TYPE_GETS_INIT_AGGR (ctype) = 1;
9328     }
9329   else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
9330     {
9331       if (TREE_CHAIN (parmtypes) != NULL_TREE
9332           && TREE_CHAIN (parmtypes) == void_list_node)
9333         cp_error ("invalid constructor; you probably meant `%T (%T&)'",
9334                   ctype, ctype);
9335       SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
9336       TYPE_GETS_INIT_AGGR (ctype) = 1;
9337     }
9338   else if (TREE_CODE (parmtype) == VOID_TYPE
9339            || TREE_PURPOSE (parmtypes) != NULL_TREE)
9340     TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
9341 }
9342
9343 /* An operator with this name can be either unary or binary.  */
9344 int ambi_op_p (name)
9345      tree name;
9346 {
9347   return (name == ansi_opname [(int) INDIRECT_REF]
9348           || name == ansi_opname [(int) ADDR_EXPR]
9349           || name == ansi_opname [(int) NEGATE_EXPR]
9350           || name == ansi_opname[(int) POSTINCREMENT_EXPR]
9351           || name == ansi_opname[(int) POSTDECREMENT_EXPR]
9352           || name == ansi_opname [(int) CONVERT_EXPR]);
9353 }
9354
9355 /* An operator with this name can only be unary.  */
9356 int unary_op_p (name)
9357      tree name;
9358 {
9359   return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
9360           || name == ansi_opname [(int) BIT_NOT_EXPR]
9361           || name == ansi_opname [(int) COMPONENT_REF]
9362           || OPERATOR_TYPENAME_P (name));
9363 }
9364
9365 /* Do a little sanity-checking on how they declared their operator.  */
9366 static void
9367 grok_op_properties (decl, virtualp, friendp)
9368      tree decl;
9369      int virtualp, friendp;
9370 {
9371   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
9372   int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
9373   tree name = DECL_NAME (decl);
9374   tree t;
9375
9376   if (! friendp)
9377     for (t = current_class_type; t; t = TYPE_NEXT_VARIANT (t))
9378       {
9379         if (name == ansi_opname[(int) MODIFY_EXPR])
9380           TYPE_HAS_ASSIGNMENT (t) = 1;
9381         else if (name == ansi_opname[(int) CALL_EXPR])
9382           TYPE_OVERLOADS_CALL_EXPR (t) = 1;
9383         else if (name == ansi_opname[(int) ARRAY_REF])
9384           TYPE_OVERLOADS_ARRAY_REF (t) = 1;
9385         else if (name == ansi_opname[(int) COMPONENT_REF]
9386                  || name == ansi_opname[(int) MEMBER_REF])
9387           TYPE_OVERLOADS_ARROW (t) = 1;
9388         else if (name == ansi_opname[(int) NEW_EXPR])
9389           {
9390             if (TREE_CHAIN (argtypes) == void_list_node)
9391               TREE_GETS_NEW (t) = 1;
9392             else
9393               TREE_GETS_PLACED_NEW (t) = 1;
9394           }
9395         else if (name == ansi_opname[(int) DELETE_EXPR])
9396           TREE_GETS_DELETE (t) = 1;
9397 #if 0
9398         else if (name == ansi_opname[(int) VEC_NEW_EXPR])
9399           TREE_GETS_NEW (t) = 1;
9400         else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
9401           TREE_GETS_DELETE (t) = 1;
9402 #endif
9403       }
9404
9405   if (name == ansi_opname[(int) NEW_EXPR])
9406     {
9407 #if 0
9408       /* When the compiler encounters the definition of A::operator new, it
9409          doesn't look at the class declaration to find out if it's static.  */
9410       my_friendly_assert (!methodp, 355);
9411 #endif
9412      
9413       /* Take care of function decl if we had syntax errors.  */
9414       if (argtypes == NULL_TREE)
9415         TREE_TYPE (decl) =
9416           build_function_type (ptr_type_node,
9417                                hash_tree_chain (integer_type_node,
9418                                                 void_list_node));
9419       else
9420         decl = coerce_new_type (TREE_TYPE (decl));
9421     }
9422 #if 0
9423   else if (name == ansi_opname[(int) VEC_NEW_EXPR])
9424     {
9425     }
9426 #endif
9427   else if (name == ansi_opname[(int) DELETE_EXPR])
9428     {
9429 #if 0
9430       my_friendly_assert (!methodp, 355);
9431 #endif
9432      
9433       if (argtypes == NULL_TREE)
9434         TREE_TYPE (decl) =
9435           build_function_type (void_type_node,
9436                                hash_tree_chain (ptr_type_node,
9437                                                 void_list_node));
9438       else
9439         decl = coerce_delete_type (TREE_TYPE (decl));
9440     }
9441 #if 0
9442   else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
9443     {
9444     }
9445 #endif
9446   else
9447     {
9448       /* An operator function must either be a non-static member function
9449          or have at least one parameter of a class, a reference to a class,
9450          an enumeration, or a reference to an enumeration.  13.4.0.6 */
9451       if (! methodp)
9452         {
9453           if (OPERATOR_TYPENAME_P (name)
9454               || name == ansi_opname[(int) CALL_EXPR]
9455               || name == ansi_opname[(int) MODIFY_EXPR]
9456               || name == ansi_opname[(int) COMPONENT_REF]
9457               || name == ansi_opname[(int) ARRAY_REF])
9458             cp_error ("`%D' must be a nonstatic member function", decl);
9459           else
9460             {
9461               tree p = argtypes;
9462
9463               if (p)
9464                 for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
9465                   {
9466                     tree arg = TREE_VALUE (p);
9467                     if (TREE_CODE (arg) == REFERENCE_TYPE)
9468                       arg = TREE_TYPE (arg);
9469
9470                     /* This lets bad template code slip through.  */
9471                     if (IS_AGGR_TYPE (arg)
9472                         || TREE_CODE (arg) == ENUMERAL_TYPE
9473                         || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
9474                       goto foundaggr;
9475                   }
9476               cp_error
9477                 ("`%D' must have an argument of class or enumerated type",
9478                  decl);
9479             foundaggr:
9480               ;
9481             }
9482         }
9483       
9484       if (name == ansi_opname[(int) CALL_EXPR]
9485           || name == ansi_opname[(int) METHOD_CALL_EXPR])
9486         return;                 /* no restrictions on args */
9487
9488       if (name == ansi_opname[(int) MODIFY_EXPR])
9489         {
9490           tree parmtype;
9491
9492           if (list_length (argtypes) != 3 && methodp)
9493             {
9494               cp_error ("`%D' must take exactly one argument", decl);
9495               return;
9496             }
9497           parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
9498
9499           if (TREE_CODE (parmtype) == REFERENCE_TYPE
9500               && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype))
9501               == current_class_type)
9502             {
9503               TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
9504               if (TYPE_READONLY (TREE_TYPE (parmtype)))
9505                 TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
9506             }
9507         }
9508       else if (name == ansi_opname[(int) COND_EXPR])
9509         {
9510           /* 13.4.0.3 */
9511           pedwarn ("ANSI C++ prohibits overloading operator ?:");
9512           if (list_length (argtypes) != 4)
9513             cp_error ("`%D' must take exactly three arguments", decl);
9514         }         
9515       else if (ambi_op_p (name))
9516         {
9517           if (list_length (argtypes) == 2)
9518             /* prefix */;
9519           else if (list_length (argtypes) == 3)
9520             {
9521               if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
9522                    || name == ansi_opname[(int) POSTDECREMENT_EXPR])
9523                   && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
9524                 {
9525                   if (methodp)
9526                     cp_error ("postfix `%D' must take `int' as its argument",
9527                               decl);
9528                   else
9529                     cp_error
9530                       ("postfix `%D' must take `int' as its second argument",
9531                        decl);
9532                 }
9533             }
9534           else
9535             {
9536               if (methodp)
9537                 cp_error ("`%D' must take either zero or one argument", decl);
9538               else
9539                 cp_error ("`%D' must take either one or two arguments", decl);
9540             }
9541         }
9542       else if (unary_op_p (name))
9543         {
9544           if (list_length (argtypes) != 2)
9545             {
9546               if (methodp)
9547                 cp_error ("`%D' must take `void'", decl);
9548               else
9549                 cp_error ("`%D' must take exactly one argument", decl);
9550             }
9551         }
9552       else /* if (binary_op_p (name)) */
9553         {
9554           if (list_length (argtypes) != 3)
9555             {
9556               if (methodp)
9557                 cp_error ("`%D' must take exactly one argument", decl);
9558               else
9559                 cp_error ("`%D' must take exactly two arguments", decl);
9560             }
9561         }
9562
9563       /* 13.4.0.8 */
9564       if (argtypes)
9565         for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
9566           if (TREE_PURPOSE (argtypes))
9567             {
9568               TREE_PURPOSE (argtypes) = NULL_TREE;
9569               if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
9570                   || name == ansi_opname[(int) POSTDECREMENT_EXPR])
9571                 {
9572                   if (pedantic)
9573                     cp_pedwarn ("`%D' cannot have default arguments", decl);
9574                 }
9575               else
9576                 cp_error ("`%D' cannot have default arguments", decl);
9577             }
9578     }
9579 }
9580 \f
9581 /* Get the struct, enum or union (CODE says which) with tag NAME.
9582    Define the tag as a forward-reference if it is not defined.
9583
9584    C++: If a class derivation is given, process it here, and report
9585    an error if multiple derivation declarations are not identical.
9586
9587    If this is a definition, come in through xref_tag and only look in
9588    the current frame for the name (since C++ allows new names in any
9589    scope.)  */
9590
9591 /* avoid rewriting all callers of xref_tag */
9592 static int xref_next_defn = 0;
9593
9594 tree
9595 xref_defn_tag (code_type_node, name, binfo)
9596      tree code_type_node;
9597      tree name, binfo;
9598 {
9599   tree rv, ncp;
9600   xref_next_defn = 1;
9601
9602   if (class_binding_level)
9603     {
9604       tree n1;
9605       char *buf;
9606       /* we need to build a new IDENTIFIER_NODE for name which nukes
9607        * the pieces... */
9608 /*
9609       n1 = IDENTIFIER_LOCAL_VALUE (current_class_name);
9610       if (n1)
9611         n1 = DECL_NAME (n1);
9612       else
9613         n1 = current_class_name;
9614 */
9615       n1 = TYPE_NAME(current_class_type);
9616       if (n1)
9617         n1 = DECL_NESTED_TYPENAME(n1);
9618       else
9619         n1 = current_class_name;
9620       
9621       buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1)
9622                              + IDENTIFIER_LENGTH (name));
9623       
9624       sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1),
9625                IDENTIFIER_POINTER (name));
9626       ncp = get_identifier (buf);
9627 #ifdef SPEW_DEBUG
9628       if (spew_debug)
9629         printf("*** %s ***\n", IDENTIFIER_POINTER (ncp));
9630 #endif
9631 #if 0
9632       IDENTIFIER_LOCAL_VALUE (name) =
9633         build_lang_decl (TYPE_DECL, ncp, NULL_TREE);
9634 #endif
9635       rv = xref_tag (code_type_node, name, binfo, 0);
9636       if (! ANON_AGGRNAME_P (name))
9637       {
9638         register tree type_decl = build_lang_decl (TYPE_DECL, ncp, rv);
9639 #ifdef DWARF_DEBUGGING_INFO
9640         /* Mark the TYPE_DECL node created just above as a gratuitous one
9641            so that dwarfout.c will know not to generate a TAG_typedef DIE
9642            for it.  */
9643         if (write_symbols == DWARF_DEBUG)
9644           DECL_IGNORED_P (type_decl) = 1;
9645 #endif /* DWARF_DEBUGGING_INFO */
9646         pushdecl_top_level (type_decl);
9647       }
9648     }
9649   else
9650     {
9651       rv = xref_tag (code_type_node, name, binfo, 0);
9652     }
9653   xref_next_defn = 0;
9654   return rv;
9655 }
9656
9657 tree
9658 xref_tag (code_type_node, name, binfo, globalize)
9659      tree code_type_node;
9660      tree name, binfo;
9661      int globalize;
9662 {
9663   enum tag_types tag_code;
9664   enum tree_code code;
9665   int temp = 0;
9666   int i, len;
9667   register tree ref, t;
9668   struct binding_level *b = inner_binding_level;
9669
9670   tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
9671   switch (tag_code)
9672     {
9673     case record_type:
9674     case class_type:
9675     case exception_type:
9676     case signature_type:
9677       code = RECORD_TYPE;
9678       len = list_length (binfo);
9679       break;
9680     case union_type:
9681       code = UNION_TYPE;
9682       if (binfo)
9683         {
9684           cp_error ("derived union `%T' invalid", name);
9685           binfo = NULL_TREE;
9686         }
9687       len = 0;
9688       break;
9689     case enum_type:
9690       code = ENUMERAL_TYPE;
9691       break;
9692     default:
9693       my_friendly_abort (18);
9694     }
9695
9696   /* If a cross reference is requested, look up the type
9697      already defined for this tag and return it.  */
9698   if (t = IDENTIFIER_TYPE_VALUE(name))
9699     {
9700        if (TREE_CODE(t) != code) t = NULL_TREE;
9701     }
9702   if (xref_next_defn)
9703     {
9704       /* If we know we are defining this tag, only look it up in this scope
9705        * and don't try to find it as a type. */
9706       xref_next_defn = 0;
9707       if (t && TYPE_CONTEXT(t) && strstr(IDENTIFIER_POINTER(name), "::"))
9708         ref = t;
9709       else
9710         ref = lookup_tag (code, name, b, 1);
9711     }
9712   else
9713     {
9714       if (t)
9715         ref = t;
9716       else
9717         ref = lookup_tag (code, name, b, 0);
9718
9719       if (! ref)
9720         {
9721           /* Try finding it as a type declaration.  If that wins, use it.  */
9722           ref = lookup_name (name, 1);
9723           if (ref && TREE_CODE (ref) == TYPE_DECL
9724               && TREE_CODE (TREE_TYPE (ref)) == code)
9725             ref = TREE_TYPE (ref);
9726           else
9727             ref = NULL_TREE;
9728         }
9729     }
9730
9731   push_obstacks_nochange ();
9732
9733   if (! ref)
9734     {
9735       /* If no such tag is yet defined, create a forward-reference node
9736          and record it as the "definition".
9737          When a real declaration of this type is found,
9738          the forward-reference will be altered into a real type.  */
9739
9740       /* In C++, since these migrate into the global scope, we must
9741          build them on the permanent obstack.  */
9742
9743       temp = allocation_temporary_p ();
9744       if (temp)
9745         end_temporary_allocation ();
9746
9747       if (code == ENUMERAL_TYPE)
9748         {
9749           ref = make_node (ENUMERAL_TYPE);
9750
9751           /* Give the type a default layout like unsigned int
9752              to avoid crashing if it does not get defined.  */
9753           TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
9754           TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
9755           TREE_UNSIGNED (ref) = 1;
9756           TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
9757           TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
9758           TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
9759
9760           /* Enable us to recognize when a type is created in class context.
9761              To do nested classes correctly, this should probably be cleared
9762              out when we leave this classes scope.  Currently this in only
9763              done in `start_enum'.  */
9764
9765           pushtag (name, ref, globalize);
9766           if (flag_cadillac)
9767             cadillac_start_enum (ref);
9768         }
9769       else if (tag_code == exception_type)
9770         {
9771           ref = make_lang_type (code);
9772           /* Enable us to recognize when an exception type is created in
9773              class context.  To do nested classes correctly, this should
9774              probably be cleared out when we leave this class's scope.  */
9775           CLASSTYPE_DECLARED_EXCEPTION (ref) = 1;
9776           pushtag (name, ref, globalize);
9777           if (flag_cadillac)
9778             cadillac_start_struct (ref);
9779         }
9780       else
9781         {
9782           extern tree pending_vtables;
9783           struct binding_level *old_b = class_binding_level;
9784           int needs_writing;
9785
9786           ref = make_lang_type (code);
9787
9788           /* A signature type will contain the fields of the signature
9789              table.  Therefore, it's not only an interface.  */
9790           if (tag_code == signature_type)
9791             {
9792               SET_SIGNATURE (ref);
9793               CLASSTYPE_INTERFACE_ONLY (ref) = 0;
9794               CLASSTYPE_INTERFACE_UNKNOWN (ref) = 0;
9795             }
9796
9797           /* Record how to set the access of this class's
9798              virtual functions.  If write_virtuals == 2 or 3, then
9799              inline virtuals are ``extern inline''.  */
9800           switch (write_virtuals)
9801             {
9802             case 0:
9803             case 1:
9804               needs_writing = 1;
9805               break;
9806             case 2:
9807               needs_writing = !! value_member (name, pending_vtables);
9808               break;
9809             case 3:
9810               needs_writing = ! CLASSTYPE_INTERFACE_ONLY (ref)
9811                 && CLASSTYPE_INTERFACE_KNOWN (ref);
9812               break;
9813             default:
9814               needs_writing = 0;
9815             }
9816
9817           /* Signatures don't have a vtable.  As long as we don't have default
9818              implementations, they behave as if `write_virtuals' were 3.  */
9819           if (tag_code == signature_type)
9820             CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
9821           else
9822             CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing;
9823
9824 #ifdef NONNESTED_CLASSES
9825           /* Class types don't nest the way enums do.  */
9826           class_binding_level = (struct binding_level *)0;
9827 #endif
9828           pushtag (name, ref, globalize);
9829           class_binding_level = old_b;
9830
9831           if (flag_cadillac)
9832             cadillac_start_struct (ref);
9833         }
9834     }
9835   else
9836     {
9837       if (IS_AGGR_TYPE_CODE (code))
9838         {
9839           if (IS_AGGR_TYPE (ref)
9840               && ((tag_code == exception_type)
9841                   != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1)))
9842             {
9843               cp_error ("type `%T' is both exception and aggregate type", ref);
9844               CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type);
9845             }
9846         }
9847
9848       /* If it no longer looks like a nested type, make sure it's
9849          in global scope.  */
9850       if (b == global_binding_level && !class_binding_level
9851           && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
9852         IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
9853
9854       if (binfo)
9855         {
9856           tree tt1 = binfo;
9857           tree tt2 = TYPE_BINFO_BASETYPES (ref);
9858
9859           if (TYPE_BINFO_BASETYPES (ref))
9860             for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
9861               if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
9862                 {
9863                   cp_error ("redeclaration of derivation chain of type `%#T'",
9864                             ref);
9865                   break;
9866                 }
9867
9868           if (tt1 == NULL_TREE)
9869             /* The user told us something we already knew.  */
9870             goto just_return;
9871
9872           /* In C++, since these migrate into the global scope, we must
9873              build them on the permanent obstack.  */
9874           end_temporary_allocation ();
9875         }
9876     }
9877
9878   if (binfo)
9879     {
9880       /* In the declaration `A : X, Y, ... Z' we mark all the types
9881          (A, X, Y, ..., Z) so we can check for duplicates.  */
9882       tree binfos;
9883
9884       SET_CLASSTYPE_MARKED (ref);
9885       BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
9886
9887       for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
9888         {
9889           /* The base of a derived struct is public by default.  */
9890           int via_public
9891             = (TREE_PURPOSE (binfo) == (tree)access_public
9892                || TREE_PURPOSE (binfo) == (tree)access_public_virtual
9893                || (tag_code != class_type
9894                    && (TREE_PURPOSE (binfo) == (tree)access_default
9895                        || TREE_PURPOSE (binfo) == (tree)access_default_virtual)));
9896           int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected;
9897           int via_virtual
9898             = (TREE_PURPOSE (binfo) == (tree)access_private_virtual
9899                || TREE_PURPOSE (binfo) == (tree)access_public_virtual
9900                || TREE_PURPOSE (binfo) == (tree)access_default_virtual);
9901           tree basetype = TREE_TYPE (TREE_VALUE (binfo));
9902           tree base_binfo;
9903
9904           GNU_xref_hier (IDENTIFIER_POINTER (name),
9905                          IDENTIFIER_POINTER (TREE_VALUE (binfo)),
9906                          via_public, via_virtual, 0);
9907
9908           if (basetype && TREE_CODE (basetype) == TYPE_DECL)
9909             basetype = TREE_TYPE (basetype);
9910           if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
9911             {
9912               error ("base type `%s' fails to be a struct or class type",
9913                      IDENTIFIER_POINTER (TREE_VALUE (binfo)));
9914               continue;
9915             }
9916 #if 1
9917           /* This code replaces similar code in layout_basetypes.  */
9918           else if (TYPE_SIZE (basetype) == NULL_TREE)
9919             {
9920               cp_error ("base class `%T' has incomplete type", basetype);
9921               continue;
9922             }
9923 #endif
9924           else
9925             {
9926               if (CLASSTYPE_MARKED (basetype))
9927                 {
9928                   if (basetype == ref)
9929                     cp_error ("recursive type `%T' undefined", basetype);
9930                   else
9931                     cp_error ("duplicate base type `%T' invalid", basetype);
9932                   continue;
9933                 }
9934
9935               /* Note that the BINFO records which describe individual
9936                  inheritances are *not* shared in the lattice!  They
9937                  cannot be shared because a given baseclass may be
9938                  inherited with different `accessibility' by different
9939                  derived classes.  (Each BINFO record describing an
9940                  individual inheritance contains flags which say what
9941                  the `accessibility' of that particular inheritance is.)  */
9942   
9943               base_binfo = make_binfo (integer_zero_node, basetype,
9944                                   TYPE_BINFO_VTABLE (basetype),
9945                                   TYPE_BINFO_VIRTUALS (basetype), 0);
9946  
9947               TREE_VEC_ELT (binfos, i) = base_binfo;
9948               TREE_VIA_PUBLIC (base_binfo) = via_public;
9949               TREE_VIA_PROTECTED (base_binfo) = via_protected;
9950               TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
9951
9952               SET_CLASSTYPE_MARKED (basetype);
9953 #if 0
9954 /* XYZZY TEST VIRTUAL BASECLASSES */
9955 if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE
9956     && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
9957     && via_virtual == 0)
9958   {
9959     warning ("making type `%s' a virtual baseclass",
9960              TYPE_NAME_STRING (basetype));
9961     via_virtual = 1;
9962   }
9963 #endif
9964               /* We are free to modify these bits because they are meaningless
9965                  at top level, and BASETYPE is a top-level type.  */
9966               if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
9967                 {
9968                   TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
9969                   TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
9970                 }
9971
9972               TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
9973               TREE_GETS_NEW (ref) |= TREE_GETS_NEW (basetype);
9974               TREE_GETS_PLACED_NEW (ref) |= TREE_GETS_PLACED_NEW (basetype);
9975               TREE_GETS_DELETE (ref) |= TREE_GETS_DELETE (basetype);
9976               CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
9977               i += 1;
9978             }
9979         }
9980       if (i)
9981         TREE_VEC_LENGTH (binfos) = i;
9982       else
9983         BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
9984
9985       if (i > 1)
9986         TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
9987       else if (i == 1)
9988         TYPE_USES_MULTIPLE_INHERITANCE (ref)
9989           = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
9990       if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
9991         TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
9992
9993       /* Unmark all the types.  */
9994       while (--i >= 0)
9995         CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
9996       CLEAR_CLASSTYPE_MARKED (ref);
9997     }
9998
9999  just_return:
10000
10001   /* Until the type is defined, tentatively accept whatever
10002      structure tag the user hands us.  */
10003   if (TYPE_SIZE (ref) == NULL_TREE
10004       && ref != current_class_type
10005       /* Have to check this, in case we have contradictory tag info.  */
10006       && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
10007     {
10008       if (tag_code == class_type)
10009         CLASSTYPE_DECLARED_CLASS (ref) = 1;
10010       else if (tag_code == record_type || tag_code == signature_type)
10011         CLASSTYPE_DECLARED_CLASS (ref) = 0;
10012     }
10013
10014   pop_obstacks ();
10015
10016   return ref;
10017 }
10018 \f
10019 static tree current_local_enum = NULL_TREE;
10020
10021 /* Begin compiling the definition of an enumeration type.
10022    NAME is its name (or null if anonymous).
10023    Returns the type object, as yet incomplete.
10024    Also records info about it so that build_enumerator
10025    may be used to declare the individual values as they are read.  */
10026
10027 tree
10028 start_enum (name)
10029      tree name;
10030 {
10031   register tree enumtype = NULL_TREE;
10032   struct binding_level *b = inner_binding_level;
10033
10034   /* If this is the real definition for a previous forward reference,
10035      fill in the contents in the same object that used to be the
10036      forward reference.  */
10037
10038   if (name != NULL_TREE)
10039     enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
10040
10041   if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
10042     cp_error ("multiple definition of enum `%T'", enumtype);
10043   else
10044     {
10045       enumtype = make_node (ENUMERAL_TYPE);
10046       pushtag (name, enumtype, 0);
10047     }
10048
10049   if (current_class_type)
10050     TREE_ADDRESSABLE (b->tags) = 1;
10051   current_local_enum = NULL_TREE;
10052
10053   if (TYPE_VALUES (enumtype) != NULL_TREE)
10054     /* Completely replace its old definition.
10055        The old enumerators remain defined, however.  */
10056     TYPE_VALUES (enumtype) = NULL_TREE;
10057
10058   /* Initially, set up this enum as like `int'
10059      so that we can create the enumerators' declarations and values.
10060      Later on, the precision of the type may be changed and
10061      it may be laid out again.  */
10062
10063   TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
10064   TYPE_SIZE (enumtype) = NULL_TREE;
10065   fixup_unsigned_type (enumtype);
10066
10067   /* We copy this value because enumerated type constants
10068      are really of the type of the enumerator, not integer_type_node.  */
10069   enum_next_value = copy_node (integer_zero_node);
10070
10071   GNU_xref_decl (current_function_decl, enumtype);
10072   return enumtype;
10073 }
10074
10075 /* After processing and defining all the values of an enumeration type,
10076    install their decls in the enumeration type and finish it off.
10077    ENUMTYPE is the type object and VALUES a list of name-value pairs.
10078    Returns ENUMTYPE.  */
10079
10080 tree
10081 finish_enum (enumtype, values)
10082      register tree enumtype, values;
10083 {
10084   register tree pair, tem;
10085   register HOST_WIDE_INT maxvalue = 0;
10086   register HOST_WIDE_INT minvalue = 0;
10087   register HOST_WIDE_INT i;
10088
10089   TYPE_VALUES (enumtype) = values;
10090
10091   /* Calculate the maximum value of any enumerator in this type.  */
10092
10093   if (values)
10094     {
10095       /* Speed up the main loop by performing some precalculations */
10096
10097       HOST_WIDE_INT value = TREE_INT_CST_LOW (TREE_VALUE (values));
10098       TREE_TYPE (TREE_VALUE (values)) = enumtype;
10099       minvalue = maxvalue = value;
10100       
10101       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
10102         {
10103           value = TREE_INT_CST_LOW (TREE_VALUE (pair));
10104           if (value > maxvalue)
10105             maxvalue = value;
10106           else if (value < minvalue)
10107             minvalue = value;
10108           TREE_TYPE (TREE_VALUE (pair)) = enumtype;
10109         }
10110     }
10111
10112   if (flag_short_enums)
10113     {
10114       /* Determine the precision this type needs, lay it out, and define it.  */
10115
10116       for (i = maxvalue; i; i >>= 1)
10117         TYPE_PRECISION (enumtype)++;
10118
10119       if (!TYPE_PRECISION (enumtype))
10120         TYPE_PRECISION (enumtype) = 1;
10121
10122       /* Cancel the laying out previously done for the enum type,
10123          so that fixup_unsigned_type will do it over.  */
10124       TYPE_SIZE (enumtype) = NULL_TREE;
10125
10126       fixup_unsigned_type (enumtype);
10127     }
10128
10129   TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue;
10130
10131   /* An enum can have some negative values; then it is signed.  */
10132   if (minvalue < 0)
10133     {
10134       TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue;
10135       TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1;
10136       TREE_UNSIGNED (enumtype) = 0;
10137     }
10138   if (flag_cadillac)
10139     cadillac_finish_enum (enumtype);
10140
10141   /* Fix up all variant types of this enum type.  */
10142   for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
10143     {
10144       TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
10145       TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
10146       TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
10147       TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
10148       TYPE_MODE (tem) = TYPE_MODE (enumtype);
10149       TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
10150       TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
10151       TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
10152     }
10153
10154   /* Finish debugging output for this type.  */
10155 #if 0
10156   /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
10157      information should *not* be generated?  I think not.  */
10158   if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
10159 #endif
10160     rest_of_type_compilation (enumtype, global_bindings_p ());
10161
10162   return enumtype;
10163 }
10164
10165 /* Build and install a CONST_DECL for one value of the
10166    current enumeration type (one that was begun with start_enum).
10167    Return a tree-list containing the name and its value.
10168    Assignment of sequential values by default is handled here.  */
10169
10170 tree
10171 build_enumerator (name, value)
10172      tree name, value;
10173 {
10174   tree decl, result;
10175   /* Change this to zero if we find VALUE is not shareable.  */
10176   int shareable = 1;
10177
10178   /* Remove no-op casts from the value.  */
10179   if (value)
10180     STRIP_TYPE_NOPS (value);
10181
10182   /* Validate and default VALUE.  */
10183   if (value != NULL_TREE)
10184     {
10185       if (TREE_READONLY_DECL_P (value))
10186         {
10187           value = decl_constant_value (value);
10188           shareable = 0;
10189         }
10190
10191       if (TREE_CODE (value) == INTEGER_CST)
10192         {
10193           value = default_conversion (value);
10194           constant_expression_warning (value);
10195         }
10196       else
10197         {
10198           error ("enumerator value for `%s' not integer constant",
10199                  IDENTIFIER_POINTER (name));
10200           value = NULL_TREE;
10201         }
10202     }
10203
10204   /* The order of things is reversed here so that we
10205      can check for possible sharing of enum values,
10206      to keep that from happening.  */
10207   /* Default based on previous value.  */
10208   if (value == NULL_TREE)
10209     value = enum_next_value;
10210
10211   /* Remove no-op casts from the value.  */
10212   if (value)
10213     STRIP_TYPE_NOPS (value);
10214
10215   /* Make up for hacks in cp-lex.c.  */
10216   if (value == integer_zero_node)
10217     value = build_int_2 (0, 0);
10218   else if (value == integer_one_node)
10219     value = build_int_2 (1, 0);
10220   else if (TREE_CODE (value) == INTEGER_CST
10221            && (shareable == 0
10222                || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
10223     {
10224       value = copy_node (value);
10225       TREE_TYPE (value) = integer_type_node;
10226     }
10227
10228   result = saveable_tree_cons (name, value, NULL_TREE);
10229
10230   /* C++ associates enums with global, function, or class declarations.  */
10231
10232   /* There are a number of cases we need to be aware of here:
10233                                 current_class_type      current_function_decl
10234      * global enums             NULL                    NULL
10235      * fn-local enum            NULL                    SET
10236      * class-local enum         SET                     NULL
10237      * class->fn->enum          SET                     SET
10238      * fn->class->enum          SET                     SET
10239
10240      Those last two make life interesting.  If it's a fn-local enum which is
10241      itself inside a class, we need the enum to go into the fn's decls (our
10242      second case below).  But if it's a class-local enum and the class itself
10243      is inside a function, we need that enum to go into the decls for the
10244      class.  To achieve this last goal, we must see if, when both
10245      current_class_decl and current_function_decl are set, the class was
10246      declared inside that function.  If so, we know to put the enum into
10247      the class's scope.  */
10248      
10249   if ((current_class_type && ! current_function_decl)
10250       || (current_class_type && current_function_decl
10251           && TYPE_CONTEXT (current_class_type) == current_function_decl))
10252     {
10253       /* This enum declaration is local to the class, so we must put
10254          it in that class's list of decls.  */
10255       decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
10256       DECL_INITIAL (decl) = value;
10257       TREE_READONLY (decl) = 1;
10258       pushdecl_class_level (decl);
10259       TREE_CHAIN (decl) = current_local_enum;
10260       current_local_enum = decl;
10261     }
10262   else
10263     {
10264       /* It's a global enum, or it's local to a function.  (Note local to
10265          a function could mean local to a class method.  */
10266       decl = build_decl (CONST_DECL, name, integer_type_node);
10267       DECL_INITIAL (decl) = value;
10268
10269       pushdecl (decl);
10270       GNU_xref_decl (current_function_decl, decl);
10271     }
10272
10273   /* Set basis for default for next value.  */
10274   enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
10275                                                integer_one_node, PLUS_EXPR);
10276   if (enum_next_value == integer_one_node)
10277     enum_next_value = copy_node (enum_next_value);
10278
10279   return result;
10280 }
10281
10282 tree
10283 grok_enum_decls (type, decl)
10284      tree type, decl;
10285 {
10286   tree d = current_local_enum;
10287   
10288   if (d == NULL_TREE)
10289     return decl;
10290   
10291   while (1)
10292     {
10293       TREE_TYPE (d) = type;
10294       if (TREE_CHAIN (d) == NULL_TREE)
10295         {
10296           TREE_CHAIN (d) = decl;
10297           break;
10298         }
10299       d = TREE_CHAIN (d);
10300     }
10301
10302   decl = current_local_enum;
10303   current_local_enum = NULL_TREE;
10304   
10305   return decl;
10306 }
10307 \f
10308 /* Create the FUNCTION_DECL for a function definition.
10309    DECLSPECS and DECLARATOR are the parts of the declaration;
10310    they describe the function's name and the type it returns,
10311    but twisted together in a fashion that parallels the syntax of C.
10312
10313    This function creates a binding context for the function body
10314    as well as setting up the FUNCTION_DECL in current_function_decl.
10315
10316    Returns 1 on success.  If the DECLARATOR is not suitable for a function
10317    (it defines a datum instead), we return 0, which tells
10318    yyparse to report a parse error.
10319
10320    For C++, we must first check whether that datum makes any sense.
10321    For example, "class A local_a(1,2);" means that variable local_a
10322    is an aggregate of type A, which should have a constructor
10323    applied to it with the argument list [1, 2].
10324
10325    @@ There is currently no way to retrieve the storage
10326    @@ allocated to FUNCTION (or all of its parms) if we return
10327    @@ something we had previously.  */
10328
10329 int
10330 start_function (declspecs, declarator, raises, pre_parsed_p)
10331      tree declarator, declspecs, raises;
10332      int pre_parsed_p;
10333 {
10334   extern tree EHS_decl;
10335   tree decl1, olddecl;
10336   tree ctype = NULL_TREE;
10337   tree fntype;
10338   tree restype;
10339   extern int have_extern_spec;
10340   extern int used_extern_spec;
10341   int doing_friend = 0;
10342
10343   if (flag_handle_exceptions && EHS_decl == NULL_TREE)
10344     init_exception_processing_1 ();
10345
10346   /* Sanity check.  */
10347   my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
10348   my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
10349
10350   /* Assume, until we see it does. */
10351   current_function_returns_value = 0;
10352   current_function_returns_null = 0;
10353   warn_about_return_type = 0;
10354   current_extern_inline = 0;
10355   current_function_assigns_this = 0;
10356   current_function_just_assigned_this = 0;
10357   current_function_parms_stored = 0;
10358   original_result_rtx = NULL_RTX;
10359   current_function_obstack_index = 0;
10360   current_function_obstack_usage = 0;
10361
10362   clear_temp_name ();
10363
10364   /* This should only be done once on the top most decl. */
10365   if (have_extern_spec && !used_extern_spec)
10366     {
10367       declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
10368       used_extern_spec = 1;
10369     }
10370
10371   if (pre_parsed_p)
10372     {
10373       decl1 = declarator;
10374
10375       if (! DECL_ARGUMENTS (decl1)
10376           && !DECL_STATIC_FUNCTION_P (decl1)
10377           && DECL_CONTEXT (decl1)
10378           && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))
10379           && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))))
10380         {
10381           cp_error ("redeclaration of `%#D'", decl1);
10382           if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
10383             cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
10384           else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
10385             cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
10386         }
10387
10388       last_function_parms = DECL_ARGUMENTS (decl1);
10389       last_function_parm_tags = NULL_TREE;
10390       fntype = TREE_TYPE (decl1);
10391       if (TREE_CODE (fntype) == METHOD_TYPE)
10392         ctype = TYPE_METHOD_BASETYPE (fntype);
10393
10394       /* ANSI C++ June 5 1992 WP 11.4.5.  A friend function defined in a
10395          class is in the (lexical) scope of the class in which it is
10396          defined.  */
10397       if (!ctype && DECL_FRIEND_P (decl1))
10398         {
10399           ctype = DECL_CLASS_CONTEXT (decl1);
10400
10401           /* CTYPE could be null here if we're dealing with a template;
10402              for example, `inline friend float foo()' inside a template
10403              will have no CTYPE set.  */
10404           if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
10405             ctype = NULL_TREE;
10406           else
10407             doing_friend = 1;
10408         }
10409
10410       if ( !(DECL_VINDEX (decl1)
10411              && write_virtuals >= 2
10412              && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)))
10413         current_extern_inline = TREE_PUBLIC (decl1) && DECL_INLINE (decl1);
10414
10415       raises = TYPE_RAISES_EXCEPTIONS (fntype);
10416
10417       /* In a fcn definition, arg types must be complete.  */
10418       require_complete_types_for_parms (last_function_parms);
10419     }
10420   else
10421     {
10422       decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises);
10423       /* If the declarator is not suitable for a function definition,
10424          cause a syntax error.  */
10425       if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
10426
10427       fntype = TREE_TYPE (decl1);
10428
10429       restype = TREE_TYPE (fntype);
10430       if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
10431           && ! CLASSTYPE_GOT_SEMICOLON (restype))
10432         {
10433           cp_error ("semicolon missing after declaration of `%#T'", restype);
10434           shadow_tag (build_tree_list (NULL_TREE, restype));
10435           CLASSTYPE_GOT_SEMICOLON (restype) = 1;
10436           if (TREE_CODE (fntype) == FUNCTION_TYPE)
10437             fntype = build_function_type (integer_type_node,
10438                                           TYPE_ARG_TYPES (fntype));
10439           else
10440             fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
10441                                               integer_type_node,
10442                                               TYPE_ARG_TYPES (fntype));
10443           TREE_TYPE (decl1) = fntype;
10444         }
10445
10446       if (TREE_CODE (fntype) == METHOD_TYPE)
10447         ctype = TYPE_METHOD_BASETYPE (fntype);
10448       else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
10449                && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
10450                && DECL_CONTEXT (decl1) == NULL_TREE)
10451         {
10452           /* If this doesn't return integer_type, complain.  */
10453           if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
10454             {
10455               warning ("return type for `main' changed to integer type");
10456               TREE_TYPE (decl1) = fntype = default_function_type;
10457             }
10458           warn_about_return_type = 0;
10459         }
10460     }
10461
10462   /* Warn if function was previously implicitly declared
10463      (but not if we warned then).  */
10464   if (! warn_implicit
10465       && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
10466     cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
10467
10468   current_function_decl = decl1;
10469
10470   if (flag_cadillac)
10471     cadillac_start_function (decl1);
10472   else
10473     announce_function (decl1);
10474
10475   if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE)
10476     {
10477       if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
10478         error_with_aggr_type (TREE_TYPE (fntype),
10479                               "return-type `%s' is an incomplete type");
10480       else
10481         error ("return-type is an incomplete type");
10482
10483       /* Make it return void instead, but don't change the
10484          type of the DECL_RESULT, in case we have a named return value.  */
10485       if (ctype)
10486         TREE_TYPE (decl1)
10487           = build_cplus_method_type (build_type_variant (ctype,
10488                                                          TREE_READONLY (decl1),
10489                                                          TREE_SIDE_EFFECTS (decl1)),
10490                                      void_type_node,
10491                                      FUNCTION_ARG_CHAIN (decl1));
10492       else
10493         TREE_TYPE (decl1)
10494           = build_function_type (void_type_node,
10495                                  TYPE_ARG_TYPES (TREE_TYPE (decl1)));
10496       DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TREE_TYPE (fntype));
10497     }
10498
10499   if (warn_about_return_type)
10500     warning ("return-type defaults to `int'");
10501
10502   /* Make the init_value nonzero so pushdecl knows this is not tentative.
10503      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
10504   DECL_INITIAL (decl1) = error_mark_node;
10505
10506   /* Didn't get anything from C.  */
10507   olddecl = NULL_TREE;
10508
10509   /* This function exists in static storage.
10510      (This does not mean `static' in the C sense!)  */
10511   TREE_STATIC (decl1) = 1;
10512
10513   /* If this function belongs to an interface, it is public.
10514      If it belongs to someone else's interface, it is also external.
10515      It doesn't matter whether it's inline or not.  */
10516   if (interface_unknown == 0)
10517     {
10518       TREE_PUBLIC (decl1) = 1;
10519       DECL_EXTERNAL (decl1) = (interface_only
10520                                || (DECL_INLINE (decl1)
10521                                    && ! flag_implement_inlines));
10522     }
10523   else
10524     /* This is a definition, not a reference.
10525        So normally clear DECL_EXTERNAL.
10526        However, `extern inline' acts like a declaration except for
10527        defining how to inline.  So set DECL_EXTERNAL in that case.  */
10528     DECL_EXTERNAL (decl1) = current_extern_inline;
10529
10530   /* Now see if this is the implementation of a declared function.  */
10531   if (ctype == NULL_TREE && current_lang_name == lang_name_cplusplus
10532       && !DECL_CONTEXT (decl1))
10533     {
10534       olddecl = lookup_name_current_level (DECL_NAME (decl1));
10535       if (olddecl && TREE_CODE (olddecl) != FUNCTION_DECL)
10536         olddecl = NULL_TREE;
10537       if (olddecl && DECL_NAME (decl1) != DECL_NAME (olddecl))
10538         {
10539           /* Collision between user and internal naming scheme.  */
10540           olddecl = lookup_name_current_level (DECL_ASSEMBLER_NAME (decl1));
10541           if (olddecl == NULL_TREE)
10542             olddecl = decl1;
10543         }
10544       if (olddecl && olddecl != decl1
10545           && DECL_NAME (decl1) == DECL_NAME (olddecl))
10546         {
10547           if (TREE_CODE (olddecl) == FUNCTION_DECL
10548               && decls_match (decl1, olddecl))
10549             {
10550               olddecl = DECL_MAIN_VARIANT (olddecl);
10551               /* The following copy is needed to handle forcing a function's
10552                  linkage to obey the linkage of the original decl.  */
10553               DECL_ASSEMBLER_NAME (decl1) = DECL_ASSEMBLER_NAME (olddecl);
10554               DECL_OVERLOADED (decl1) = DECL_OVERLOADED (olddecl);
10555               if (! DECL_BUILT_IN (olddecl) && DECL_INITIAL (olddecl))
10556                 redeclaration_error_message (decl1, olddecl);
10557               if (duplicate_decls (decl1, olddecl))
10558                 decl1 = olddecl;
10559               else
10560                 olddecl = NULL_TREE;
10561             }
10562           else
10563             olddecl = NULL_TREE;
10564         }
10565     }
10566
10567   /* Record the decl so that the function name is defined.
10568      If we already have a decl for this name, and it is a FUNCTION_DECL,
10569      use the old decl.  */
10570
10571   if (olddecl)
10572     current_function_decl = olddecl;
10573   else if (pre_parsed_p == 0)
10574     {
10575       current_function_decl = pushdecl (decl1);
10576       if (TREE_CODE (current_function_decl) == TREE_LIST)
10577         {
10578           /* @@ revert to modified original declaration.  */
10579           decl1 = DECL_MAIN_VARIANT (decl1);
10580           current_function_decl = decl1;
10581         }
10582       else
10583         {
10584           decl1 = current_function_decl;
10585           DECL_MAIN_VARIANT (decl1) = decl1;
10586         }
10587       fntype = TREE_TYPE (decl1);
10588     }
10589   else
10590     current_function_decl = decl1;
10591
10592   if (DECL_OVERLOADED (decl1))
10593     decl1 = push_overloaded_decl (decl1, 1);
10594
10595   if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
10596     {
10597       if (TREE_CODE (fntype) == METHOD_TYPE)
10598         TREE_TYPE (decl1) = fntype
10599           = build_function_type (TREE_TYPE (fntype),
10600                                  TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
10601       last_function_parms = TREE_CHAIN (last_function_parms);
10602       DECL_ARGUMENTS (decl1) = last_function_parms;
10603       ctype = NULL_TREE;
10604     }
10605   restype = TREE_TYPE (fntype);
10606
10607   pushlevel (0);
10608   current_binding_level->parm_flag = 1;
10609
10610   /* Save the parm names or decls from this function's declarator
10611      where store_parm_decls will find them.  */
10612   current_function_parms = last_function_parms;
10613   current_function_parm_tags = last_function_parm_tags;
10614
10615   GNU_xref_function (decl1, current_function_parms);
10616
10617   make_function_rtl (decl1);
10618
10619   if (ctype)
10620     {
10621       push_nested_class (ctype, 1);
10622
10623       /* If we're compiling a friend function, neither of the variables
10624          current_class_decl nor current_class_type will have values.  */
10625       if (! doing_friend)
10626         {
10627           /* We know that this was set up by `grokclassfn'.
10628              We do not wait until `store_parm_decls', since evil
10629              parse errors may never get us to that point.  Here
10630              we keep the consistency between `current_class_type'
10631              and `current_class_decl'.  */
10632           current_class_decl = last_function_parms;
10633           my_friendly_assert (current_class_decl != NULL_TREE
10634                   && TREE_CODE (current_class_decl) == PARM_DECL, 162);
10635           if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
10636             {
10637               tree variant = TREE_TYPE (TREE_TYPE (current_class_decl));
10638               if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE)
10639                 {
10640                   /* Can't call build_indirect_ref here, because it has special
10641                      logic to return C_C_D given this argument.  */
10642                   C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
10643                   CLASSTYPE_INST_VAR (ctype) = C_C_D;
10644                 }
10645               else
10646                 {
10647                   C_C_D = CLASSTYPE_INST_VAR (ctype);
10648                   /* `current_class_decl' is different for every
10649                      function we compile.  */
10650                   TREE_OPERAND (C_C_D, 0) = current_class_decl;
10651                 }
10652               TREE_READONLY (C_C_D) = TYPE_READONLY (variant);
10653               TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant);
10654               TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant);
10655             }
10656           else
10657             C_C_D = current_class_decl;
10658         }
10659     }
10660   else
10661     {
10662       if (DECL_STATIC_FUNCTION_P (decl1))
10663         push_nested_class (DECL_CONTEXT (decl1), 2);
10664       else
10665         push_memoized_context (0, 1);
10666     }
10667
10668   /* Allocate further tree nodes temporarily during compilation
10669      of this function only.  Tiemann moved up here from bottom of fn.  */
10670   temporary_allocation ();
10671
10672   /* Promote the value to int before returning it.  */
10673   if (C_PROMOTING_INTEGER_TYPE_P (restype))
10674     {
10675       /* It retains unsignedness if traditional or if it isn't
10676          really getting wider.  */
10677       if (TREE_UNSIGNED (restype)
10678           && (flag_traditional
10679               || TYPE_PRECISION (restype)
10680                    == TYPE_PRECISION (integer_type_node)))
10681         restype = unsigned_type_node;
10682       else
10683         restype = integer_type_node;
10684     }
10685   if (DECL_RESULT (decl1) == NULL_TREE)
10686     DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, restype);
10687
10688   if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)))
10689     {
10690       dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10691       ctor_label = NULL_TREE;
10692     }
10693   else
10694     {
10695       dtor_label = NULL_TREE;
10696       if (DECL_CONSTRUCTOR_P (decl1))
10697         ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10698     }
10699
10700   /* If this fcn was already referenced via a block-scope `extern' decl
10701      (or an implicit decl), propagate certain information about the usage.  */
10702   if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
10703     TREE_ADDRESSABLE (decl1) = 1;
10704
10705   return 1;
10706 }
10707 \f
10708 /* Store the parameter declarations into the current function declaration.
10709    This is called after parsing the parameter declarations, before
10710    digesting the body of the function.
10711
10712    Also install to binding contour return value identifier, if any.  */
10713
10714 void
10715 store_parm_decls ()
10716 {
10717   register tree fndecl = current_function_decl;
10718   register tree parm;
10719   int parms_have_cleanups = 0;
10720   tree eh_decl;
10721
10722   /* This is either a chain of PARM_DECLs (when a prototype is used).  */
10723   tree specparms = current_function_parms;
10724
10725   /* This is a list of types declared among parms in a prototype.  */
10726   tree parmtags = current_function_parm_tags;
10727
10728   /* This is a chain of any other decls that came in among the parm
10729      declarations.  If a parm is declared with  enum {foo, bar} x;
10730      then CONST_DECLs for foo and bar are put here.  */
10731   tree nonparms = NULL_TREE;
10732
10733   if (current_binding_level == global_binding_level)
10734     fatal ("parse errors have confused me too much");
10735
10736   /* Initialize RTL machinery.  */
10737   init_function_start (fndecl, input_filename, lineno);
10738
10739   /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function.  */
10740   declare_function_name ();
10741
10742   /* Create a binding level for the parms.  */
10743   expand_start_bindings (0);
10744
10745   /* Prepare to catch raises, if appropriate.  */
10746   if (flag_handle_exceptions)
10747     {
10748       /* Get this cleanup to be run last, since it
10749          is a call to `longjmp'.  */
10750       setup_exception_throw_decl ();
10751       eh_decl = current_binding_level->names;
10752       current_binding_level->names = TREE_CHAIN (current_binding_level->names);
10753     }
10754   if (flag_handle_exceptions)
10755     expand_start_try (integer_one_node, 0, 1);
10756
10757   if (specparms != NULL_TREE)
10758     {
10759       /* This case is when the function was defined with an ANSI prototype.
10760          The parms already have decls, so we need not do anything here
10761          except record them as in effect
10762          and complain if any redundant old-style parm decls were written.  */
10763
10764       register tree next;
10765
10766       /* Must clear this because it might contain TYPE_DECLs declared
10767          at class level.  */
10768       storedecls (NULL_TREE);
10769       for (parm = nreverse (specparms); parm; parm = next)
10770         {
10771           next = TREE_CHAIN (parm);
10772           if (TREE_CODE (parm) == PARM_DECL)
10773             {
10774               tree cleanup = maybe_build_cleanup (parm);
10775               if (DECL_NAME (parm) == NULL_TREE)
10776                 {
10777 #if 0
10778                   cp_error_at ("parameter name omitted", parm);
10779 #else
10780                   /* for C++, this is not an error.  */
10781                   pushdecl (parm);
10782 #endif
10783                 }
10784               else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
10785                 cp_error ("parameter `%D' declared void", parm);
10786               else
10787                 {
10788                   /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
10789                      A parameter is assumed not to have any side effects.
10790                      If this should change for any reason, then this
10791                      will have to wrap the bashed reference type in a save_expr.
10792                      
10793                      Also, if the parameter type is declared to be an X
10794                      and there is an X(X&) constructor, we cannot lay it
10795                      into the stack (any more), so we make this parameter
10796                      look like it is really of reference type.  Functions
10797                      which pass parameters to this function will know to
10798                      create a temporary in their frame, and pass a reference
10799                      to that.  */
10800
10801                   if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
10802                       && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
10803                     SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
10804
10805                   pushdecl (parm);
10806                 }
10807               if (cleanup)
10808                 {
10809                   expand_decl (parm);
10810                   expand_decl_cleanup (parm, cleanup);
10811                   parms_have_cleanups = 1;
10812                 }
10813             }
10814           else
10815             {
10816               /* If we find an enum constant or a type tag,
10817                  put it aside for the moment.  */
10818               TREE_CHAIN (parm) = NULL_TREE;
10819               nonparms = chainon (nonparms, parm);
10820             }
10821         }
10822
10823       /* Get the decls in their original chain order
10824          and record in the function.  This is all and only the
10825          PARM_DECLs that were pushed into scope by the loop above.  */
10826       DECL_ARGUMENTS (fndecl) = getdecls ();
10827
10828       storetags (chainon (parmtags, gettags ()));
10829     }
10830   else
10831     DECL_ARGUMENTS (fndecl) = NULL_TREE;
10832
10833   /* Now store the final chain of decls for the arguments
10834      as the decl-chain of the current lexical scope.
10835      Put the enumerators in as well, at the front so that
10836      DECL_ARGUMENTS is not modified.  */
10837
10838   storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
10839
10840   /* Initialize the RTL code for the function.  */
10841   DECL_SAVED_INSNS (fndecl) = NULL_RTX;
10842   expand_function_start (fndecl, parms_have_cleanups);
10843
10844   if (flag_handle_exceptions)
10845     {
10846       /* Make the throw decl visible at this level, just
10847          not in the way of the parameters.  */
10848       pushdecl (eh_decl);
10849       expand_decl_init (eh_decl);
10850     }
10851
10852   /* Create a binding contour which can be used to catch
10853      cleanup-generated temporaries.  Also, if the return value needs or
10854      has initialization, deal with that now.  */
10855   if (parms_have_cleanups)
10856     {
10857       pushlevel (0);
10858       expand_start_bindings (0);
10859     }
10860
10861   current_function_parms_stored = 1;
10862
10863   if (flag_gc)
10864     {
10865       maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
10866       expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup);
10867     }
10868
10869   /* If this function is `main', emit a call to `__main'
10870      to run global initializers, etc.  */
10871   if (DECL_NAME (fndecl)
10872       && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
10873       && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
10874       && DECL_CONTEXT (fndecl) == NULL_TREE)
10875     {
10876       expand_main_function ();
10877
10878       if (flag_gc)
10879         expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
10880                      0, VOIDmode, 0);
10881
10882       if (flag_dossier)
10883         output_builtin_tdesc_entries ();
10884     }
10885 }
10886
10887 /* Bind a name and initialization to the return value of
10888    the current function.  */
10889 void
10890 store_return_init (return_id, init)
10891      tree return_id, init;
10892 {
10893   tree decl = DECL_RESULT (current_function_decl);
10894
10895   if (pedantic)
10896     /* Give this error as many times as there are occurrences,
10897        so that users can use Emacs compilation buffers to find
10898        and fix all such places.  */
10899     error ("ANSI C++ does not permit named return values");
10900
10901   if (return_id != NULL_TREE)
10902     {
10903       if (DECL_NAME (decl) == NULL_TREE)
10904         {
10905           DECL_NAME (decl) = return_id;
10906           DECL_ASSEMBLER_NAME (decl) = return_id;
10907         }
10908       else
10909         error ("return identifier `%s' already in place",
10910                IDENTIFIER_POINTER (DECL_NAME (decl)));
10911     }
10912
10913   /* Can't let this happen for constructors.  */
10914   if (DECL_CONSTRUCTOR_P (current_function_decl))
10915     {
10916       error ("can't redefine default return value for constructors");
10917       return;
10918     }
10919
10920   /* If we have a named return value, put that in our scope as well.  */
10921   if (DECL_NAME (decl) != NULL_TREE)
10922     {
10923       /* If this named return value comes in a register,
10924          put it in a pseudo-register.  */
10925       if (DECL_REGISTER (decl))
10926         {
10927           original_result_rtx = DECL_RTL (decl);
10928           DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
10929         }
10930
10931       /* Let `finish_decl' know that this initializer is ok.  */
10932       DECL_INITIAL (decl) = init;
10933       pushdecl (decl);
10934       finish_decl (decl, init, 0, 0);
10935     }
10936 }
10937
10938 #if 0
10939 /* Generate code for default X() constructor.  */
10940 static void
10941 build_default_constructor (fndecl)
10942      tree fndecl;
10943 {
10944   int i = CLASSTYPE_N_BASECLASSES (current_class_type);
10945   tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
10946   tree fields = TYPE_FIELDS (current_class_type);
10947   tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
10948
10949   if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
10950     parm = TREE_CHAIN (parm);
10951   parm = DECL_REFERENCE_SLOT (parm);
10952
10953   while (--i >= 0)
10954     {
10955       tree basetype = TREE_VEC_ELT (binfos, i);
10956       if (TYPE_HAS_INIT_REF (basetype))
10957         {
10958           tree name = TYPE_NAME (basetype);
10959           if (TREE_CODE (name) == TYPE_DECL)
10960             name = DECL_NAME (name);
10961           current_base_init_list = tree_cons (name, parm, current_base_init_list);
10962         }
10963     }
10964   for (; fields; fields = TREE_CHAIN (fields))
10965     {
10966       tree name, init;
10967       if (TREE_STATIC (fields))
10968         continue;
10969       if (TREE_CODE (fields) != FIELD_DECL)
10970         continue;
10971       if (DECL_NAME (fields))
10972         {
10973           if (VFIELD_NAME_P (DECL_NAME (fields)))
10974             continue;
10975           if (VBASE_NAME_P (DECL_NAME (fields)))
10976             continue;
10977
10978           /* True for duplicate members.  */
10979           if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields)
10980             continue;
10981         }
10982
10983       init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields);
10984       init = build_tree_list (NULL_TREE, init);
10985
10986       current_member_init_list
10987         = tree_cons (DECL_NAME (fields), init, current_member_init_list);
10988     }
10989 }
10990 #endif
10991 \f
10992 /* Finish up a function declaration and compile that function
10993    all the way to assembler language output.  The free the storage
10994    for the function definition.
10995
10996    This is called after parsing the body of the function definition.
10997    LINENO is the current line number.
10998
10999    C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
11000    (and expand_end_bindings) must be made to take care of the binding
11001    contour for the base initializers.  This is only relevant for
11002    constructors.  */
11003
11004 void
11005 finish_function (lineno, call_poplevel)
11006      int lineno;
11007      int call_poplevel;
11008 {
11009   register tree fndecl = current_function_decl;
11010   tree fntype, ctype = NULL_TREE;
11011   rtx head, last_parm_insn, mark;
11012   extern int sets_exception_throw_decl;
11013   /* Label to use if this function is supposed to return a value.  */
11014   tree no_return_label = NULL_TREE;
11015   tree decls = NULL_TREE;
11016
11017   /* When we get some parse errors, we can end up without a
11018      current_function_decl, so cope.  */
11019   if (fndecl == NULL_TREE)
11020     return;
11021
11022   fntype = TREE_TYPE (fndecl);
11023
11024 /*  TREE_READONLY (fndecl) = 1;
11025     This caused &foo to be of type ptr-to-const-function
11026     which then got a warning when stored in a ptr-to-function variable.  */
11027
11028   /* This happens on strange parse errors.  */
11029   if (! current_function_parms_stored)
11030     {
11031       call_poplevel = 0;
11032       store_parm_decls ();
11033     }
11034
11035   if (write_symbols != NO_DEBUG && TREE_CODE (fntype) != METHOD_TYPE)
11036     {
11037       tree ttype = target_type (fntype);
11038       tree parmdecl;
11039
11040       if (IS_AGGR_TYPE (ttype))
11041         /* Let debugger know it should output info for this type.  */
11042         note_debug_info_needed (ttype);
11043
11044       for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
11045         {
11046           ttype = target_type (TREE_TYPE (parmdecl));
11047           if (IS_AGGR_TYPE (ttype))
11048             /* Let debugger know it should output info for this type.  */
11049             note_debug_info_needed (ttype);
11050         }
11051     }
11052
11053   /* Clean house because we will need to reorder insns here.  */
11054   do_pending_stack_adjust ();
11055
11056   if (dtor_label)
11057     {
11058       tree binfo = TYPE_BINFO (current_class_type);
11059       tree cond = integer_one_node;
11060       tree exprstmt, vfields;
11061       tree in_charge_node = lookup_name (in_charge_identifier, 0);
11062       tree virtual_size;
11063       int ok_to_optimize_dtor = 0;
11064
11065       if (current_function_assigns_this)
11066         cond = build (NE_EXPR, integer_type_node,
11067                       current_class_decl, integer_zero_node);
11068       else
11069         {
11070           int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
11071
11072           /* If this destructor is empty, then we don't need to check
11073              whether `this' is NULL in some cases.  */
11074           mark = get_last_insn ();
11075           last_parm_insn = get_first_nonparm_insn ();
11076
11077           if ((flag_this_is_variable & 1) == 0)
11078             ok_to_optimize_dtor = 1;
11079           else if (mark == last_parm_insn)
11080             ok_to_optimize_dtor
11081               = (n_baseclasses == 0
11082                  || (n_baseclasses == 1
11083                      && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
11084         }
11085
11086       /* These initializations might go inline.  Protect
11087          the binding level of the parms.  */
11088       pushlevel (0);
11089       expand_start_bindings (0);
11090
11091       if (current_function_assigns_this)
11092         {
11093           current_function_assigns_this = 0;
11094           current_function_just_assigned_this = 0;
11095         }
11096
11097       /* Generate the code to call destructor on base class.
11098          If this destructor belongs to a class with virtual
11099          functions, then set the virtual function table
11100          pointer to represent the type of our base class.  */
11101
11102       /* This side-effect makes call to `build_delete' generate the
11103          code we have to have at the end of this destructor.  */
11104       TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
11105
11106       /* These are two cases where we cannot delegate deletion.  */
11107       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
11108           || TREE_GETS_DELETE (current_class_type))
11109         exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
11110                                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11111       else
11112         exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
11113                                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11114
11115       /* If we did not assign to this, then `this' is non-zero at
11116          the end of a destructor.  As a special optimization, don't
11117          emit test if this is an empty destructor.  If it does nothing,
11118          it does nothing.  If it calls a base destructor, the base
11119          destructor will perform the test.  */
11120
11121       if (exprstmt != error_mark_node
11122           && (TREE_CODE (exprstmt) != NOP_EXPR
11123               || TREE_OPERAND (exprstmt, 0) != integer_zero_node
11124               || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
11125         {
11126           expand_label (dtor_label);
11127           if (cond != integer_one_node)
11128             expand_start_cond (cond, 0);
11129           if (exprstmt != void_zero_node)
11130             /* Don't call `expand_expr_stmt' if we're not going to do
11131                anything, since -Wall will give a diagnostic.  */
11132             expand_expr_stmt (exprstmt);
11133
11134           /* Run destructor on all virtual baseclasses.  */
11135           if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11136             {
11137               tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
11138               expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
11139                                         in_charge_node, integer_two_node), 0);
11140               while (vbases)
11141                 {
11142                   if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
11143                     {
11144                       tree ptr = convert_pointer_to_vbase (vbases, current_class_decl);
11145                       expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases)),
11146                                                       ptr, integer_zero_node,
11147                                                       LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
11148                     }
11149                   vbases = TREE_CHAIN (vbases);
11150                 }
11151               expand_end_cond ();
11152             }
11153
11154           do_pending_stack_adjust ();
11155           if (cond != integer_one_node)
11156             expand_end_cond ();
11157         }
11158
11159       TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
11160
11161       virtual_size = c_sizeof (current_class_type);
11162
11163       /* At the end, call delete if that's what's requested.  */
11164       if (TREE_GETS_DELETE (current_class_type))
11165         /* This NOP_EXPR means we are in a static call context.  */
11166         exprstmt =
11167           build_method_call
11168             (build_indirect_ref
11169              (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type),
11170                       error_mark_node),
11171               NULL_PTR),
11172              ansi_opname[(int) DELETE_EXPR],
11173              tree_cons (NULL_TREE, current_class_decl,
11174                         build_tree_list (NULL_TREE, virtual_size)),
11175              NULL_TREE, LOOKUP_NORMAL);
11176       else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11177         exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
11178                                    virtual_size);
11179       else
11180         exprstmt = NULL_TREE;
11181
11182       if (exprstmt)
11183         {
11184           cond = build (BIT_AND_EXPR, integer_type_node,
11185                         in_charge_node, integer_one_node);
11186           expand_start_cond (cond, 0);
11187           expand_expr_stmt (exprstmt);
11188           expand_end_cond ();
11189         }
11190
11191       /* End of destructor.  */
11192       expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0);
11193       poplevel (2, 0, 0); /* XXX change to 1 */
11194
11195       /* Back to the top of destructor.  */
11196       /* Dont execute destructor code if `this' is NULL.  */
11197       mark = get_last_insn ();
11198       last_parm_insn = get_first_nonparm_insn ();
11199       if (last_parm_insn == NULL_RTX)
11200         last_parm_insn = mark;
11201       else
11202         last_parm_insn = previous_insn (last_parm_insn);
11203
11204       /* Make all virtual function table pointers in non-virtual base
11205          classes point to CURRENT_CLASS_TYPE's virtual function
11206          tables.  */
11207       init_vtbl_ptrs (binfo, 1, 0);
11208       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11209         expand_expr_stmt (build_vbase_vtables_init (binfo, binfo,
11210                                                     C_C_D, current_class_decl, 0));
11211       if (! ok_to_optimize_dtor)
11212         {
11213           cond = build_binary_op (NE_EXPR,
11214                                   current_class_decl, integer_zero_node, 1);
11215           expand_start_cond (cond, 0);
11216         }
11217       if (mark != get_last_insn ())
11218         reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
11219       if (! ok_to_optimize_dtor)
11220         expand_end_cond ();
11221     }
11222   else if (current_function_assigns_this)
11223     {
11224       /* Does not need to call emit_base_init, because
11225          that is done (if needed) just after assignment to this
11226          is seen.  */
11227
11228       if (DECL_CONSTRUCTOR_P (current_function_decl))
11229         {
11230           expand_label (ctor_label);
11231           ctor_label = NULL_TREE;
11232
11233           if (call_poplevel)
11234             {
11235               decls = getdecls ();
11236               if (flag_handle_exceptions == 2)
11237                 deactivate_exception_cleanups ();
11238               expand_end_bindings (decls, decls != NULL_TREE, 0);
11239               poplevel (decls != NULL_TREE, 0, 0);
11240             }
11241           c_expand_return (current_class_decl);
11242         }
11243       else if (TYPE_MAIN_VARIANT (TREE_TYPE (
11244                         DECL_RESULT (current_function_decl))) != void_type_node
11245                && return_label != NULL_RTX)
11246         no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11247
11248       current_function_assigns_this = 0;
11249       current_function_just_assigned_this = 0;
11250       base_init_insns = NULL_RTX;
11251     }
11252   else if (DECL_CONSTRUCTOR_P (fndecl))
11253     {
11254       tree allocated_this;
11255       tree cond, thenclause;
11256       /* Allow constructor for a type to get a new instance of the object
11257          using `build_new'.  */
11258       tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
11259       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
11260
11261       DECL_RETURNS_FIRST_ARG (fndecl) = 1;
11262
11263       if (flag_this_is_variable > 0)
11264         {
11265           cond = build_binary_op (EQ_EXPR,
11266                                   current_class_decl, integer_zero_node, 1);
11267           thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
11268                                           build_new (NULL_TREE, current_class_type, void_type_node, 0));
11269           if (flag_handle_exceptions == 2)
11270             {
11271               tree cleanup, cleanup_deallocate;
11272               tree virtual_size;
11273
11274               /* This is the size of the virtual object pointed to by
11275                  allocated_this.  In this case, it is simple.  */
11276               virtual_size = c_sizeof (current_class_type);
11277
11278               allocated_this = build_decl (VAR_DECL, NULL_TREE, ptr_type_node);
11279               DECL_REGISTER (allocated_this) = 1;
11280               DECL_INITIAL (allocated_this) = error_mark_node;
11281               expand_decl (allocated_this);
11282               expand_decl_init (allocated_this);
11283               /* How we cleanup `this' if an exception was raised before
11284                  we are ready to bail out.  */
11285               cleanup = TREE_GETS_DELETE (current_class_type)
11286                 ? build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, allocated_this, virtual_size, NULL_TREE)
11287                   /* The size of allocated_this is wrong, and hence the
11288                      second argument to operator delete will be wrong. */
11289                   : build_delete (TREE_TYPE (allocated_this), allocated_this,
11290                                   integer_three_node,
11291                                   LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 1);
11292               cleanup_deallocate
11293                 = build_modify_expr (current_class_decl, NOP_EXPR, integer_zero_node);
11294               cleanup = tree_cons (NULL_TREE, cleanup,
11295                                    build_tree_list (NULL_TREE, cleanup_deallocate));
11296
11297               expand_decl_cleanup (allocated_this,
11298                                    build (COND_EXPR, integer_type_node,
11299                                           build (NE_EXPR, integer_type_node,
11300                                                  allocated_this, integer_zero_node),
11301                                           build_compound_expr (cleanup),
11302                                           integer_zero_node));
11303             }
11304         }
11305
11306       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
11307
11308       /* must keep the first insn safe.  */
11309       head = get_insns ();
11310
11311       /* this note will come up to the top with us.  */
11312       mark = get_last_insn ();
11313
11314       if (flag_this_is_variable > 0)
11315         {
11316           expand_start_cond (cond, 0);
11317           expand_expr_stmt (thenclause);
11318           if (flag_handle_exceptions == 2)
11319             expand_assignment (allocated_this, current_class_decl, 0, 0);
11320           expand_end_cond ();
11321         }
11322
11323 #if 0
11324       if (DECL_NAME (fndecl) == NULL_TREE
11325           && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
11326         build_default_constructor (fndecl);
11327 #endif
11328
11329       /* Emit insns from `emit_base_init' which sets up virtual
11330          function table pointer(s).  */
11331       emit_insns (base_init_insns);
11332       base_init_insns = NULL_RTX;
11333
11334       /* This is where the body of the constructor begins.
11335          If there were no insns in this function body, then the
11336          last_parm_insn is also the last insn.
11337
11338          If optimization is enabled, last_parm_insn may move, so
11339          we don't hold on to it (across emit_base_init).  */
11340       last_parm_insn = get_first_nonparm_insn ();
11341       if (last_parm_insn == NULL_RTX)
11342         last_parm_insn = mark;
11343       else
11344         last_parm_insn = previous_insn (last_parm_insn);
11345
11346       if (mark != get_last_insn ())
11347         reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
11348
11349       /* This is where the body of the constructor ends.  */
11350       expand_label (ctor_label);
11351       ctor_label = NULL_TREE;
11352       if (flag_handle_exceptions == 2)
11353         {
11354           expand_assignment (allocated_this, integer_zero_node, 0, 0);
11355           if (call_poplevel)
11356             deactivate_exception_cleanups ();
11357         }
11358
11359       pop_implicit_try_blocks (NULL_TREE);
11360
11361       if (call_poplevel)
11362         {
11363           expand_end_bindings (decls = getdecls (), decls != NULL_TREE, 0);
11364           poplevel (decls != NULL_TREE, 1, 0);
11365         }
11366
11367       c_expand_return (current_class_decl);
11368
11369       current_function_assigns_this = 0;
11370       current_function_just_assigned_this = 0;
11371     }
11372   else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
11373            && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
11374            && DECL_CONTEXT (fndecl) == NULL_TREE)
11375     {
11376       /* Make it so that `main' always returns 0 by default.  */
11377 #ifdef VMS
11378       c_expand_return (integer_one_node);
11379 #else
11380       c_expand_return (integer_zero_node);
11381 #endif
11382     }
11383   else if (return_label != NULL_RTX
11384            && current_function_return_value == NULL_TREE
11385            && ! DECL_NAME (DECL_RESULT (current_function_decl)))
11386     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11387
11388   if (flag_gc)
11389     expand_gc_prologue_and_epilogue ();
11390
11391   /* That's the end of the vtable decl's life.  Need to mark it such
11392      if doing stupid register allocation.
11393
11394      Note that current_vtable_decl is really an INDIRECT_REF
11395      on top of a VAR_DECL here.  */
11396   if (obey_regdecls && current_vtable_decl)
11397     use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0)));
11398
11399   /* If this function is supposed to return a value, ensure that
11400      we do not fall into the cleanups by mistake.  The end of our
11401      function will look like this:
11402
11403         user code (may have return stmt somewhere)
11404         goto no_return_label
11405         cleanup_label:
11406         cleanups
11407         goto return_label
11408         no_return_label:
11409         NOTE_INSN_FUNCTION_END
11410         return_label:
11411         things for return
11412
11413      If the user omits a return stmt in the USER CODE section, we
11414      will have a control path which reaches NOTE_INSN_FUNCTION_END.
11415      Otherwise, we won't.  */
11416   if (no_return_label)
11417     {
11418       DECL_CONTEXT (no_return_label) = fndecl;
11419       DECL_INITIAL (no_return_label) = error_mark_node;
11420       DECL_SOURCE_FILE (no_return_label) = input_filename;
11421       DECL_SOURCE_LINE (no_return_label) = lineno;
11422       expand_goto (no_return_label);
11423     }
11424
11425   if (cleanup_label)
11426     {
11427       /* remove the binding contour which is used
11428          to catch cleanup-generated temporaries.  */
11429       expand_end_bindings (0, 0, 0);
11430       poplevel (0, 0, 0);
11431     }
11432
11433   if (cleanup_label)
11434     /* Emit label at beginning of cleanup code for parameters.  */
11435     emit_label (cleanup_label);
11436
11437 #if 1
11438   /* Cheap hack to get better code from GNU C++.  Remove when cse is fixed.  */
11439   if (exception_throw_decl && sets_exception_throw_decl == 0)
11440     expand_assignment (exception_throw_decl, integer_zero_node, 0, 0);
11441 #endif
11442
11443   if (flag_handle_exceptions)
11444     {
11445       expand_end_try ();
11446       expand_start_except (0, 0);
11447       expand_end_except ();
11448     }
11449
11450   /* Get return value into register if that's where it's supposed to be.  */
11451   if (original_result_rtx)
11452     fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
11453
11454   /* Finish building code that will trigger warnings if users forget
11455      to make their functions return values.  */
11456   if (no_return_label || cleanup_label)
11457     emit_jump (return_label);
11458   if (no_return_label)
11459     {
11460       /* We don't need to call `expand_*_return' here because we
11461          don't need any cleanups here--this path of code is only
11462          for error checking purposes.  */
11463       expand_label (no_return_label);
11464     }
11465
11466   /* reset scope for C++: if we were in the scope of a class,
11467      then when we finish this function, we are not longer so.
11468      This cannot be done until we know for sure that no more
11469      class members will ever be referenced in this function
11470      (i.e., calls to destructors).  */
11471   if (current_class_name)
11472     {
11473       ctype = current_class_type;
11474       pop_nested_class (1);
11475     }
11476   else
11477     pop_memoized_context (1);
11478
11479   /* Forget about all overloaded functions defined in
11480      this scope which go away.  */
11481   while (overloads_to_forget)
11482     {
11483       IDENTIFIER_GLOBAL_VALUE (TREE_PURPOSE (overloads_to_forget))
11484         = TREE_VALUE (overloads_to_forget);
11485       overloads_to_forget = TREE_CHAIN (overloads_to_forget);
11486     }
11487
11488   /* Generate rtl for function exit.  */
11489   expand_function_end (input_filename, lineno, 1);
11490
11491   /* This must come after expand_function_end because cleanups might
11492      have declarations (from inline functions) that need to go into
11493      this function's blocks.  */
11494   if (current_binding_level->parm_flag != 1)
11495     my_friendly_abort (122);
11496   poplevel (1, 0, 1);
11497
11498   /* Must mark the RESULT_DECL as being in this function.  */
11499   DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
11500
11501   /* Obey `register' declarations if `setjmp' is called in this fn.  */
11502   if (flag_traditional && current_function_calls_setjmp)
11503     setjmp_protect (DECL_INITIAL (fndecl));
11504
11505   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
11506      to the FUNCTION_DECL node itself.  */
11507   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
11508
11509   /* So we can tell if jump_optimize sets it to 1.  */
11510   can_reach_end = 0;
11511
11512   /* ??? Compensate for Sun brain damage in dealing with data segments
11513      of PIC code.  */
11514   if (flag_pic
11515       && (DECL_CONSTRUCTOR_P (fndecl)
11516           || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
11517       && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype)))
11518     DECL_INLINE (fndecl) = 0;
11519
11520   if (DECL_EXTERNAL (fndecl)
11521       /* This function is just along for the ride.  If we can make
11522          it inline, that's great.  Otherwise, just punt it.  */
11523       && (DECL_INLINE (fndecl) == 0
11524           || flag_no_inline
11525           || function_cannot_inline_p (fndecl)))
11526     {
11527       extern int rtl_dump_and_exit;
11528       int old_rtl_dump_and_exit = rtl_dump_and_exit;
11529       int inline_spec = DECL_INLINE (fndecl);
11530
11531       /* This throws away the code for FNDECL.  */
11532       rtl_dump_and_exit = 1;
11533       /* This throws away the memory of the code for FNDECL.  */
11534       if (flag_no_inline)
11535         DECL_INLINE (fndecl) = 0;
11536       rest_of_compilation (fndecl);
11537       rtl_dump_and_exit = old_rtl_dump_and_exit;
11538       DECL_INLINE (fndecl) = inline_spec;
11539     }
11540   else
11541     {
11542       /* Run the optimizers and output the assembler code for this
11543          function.  */
11544       rest_of_compilation (fndecl);
11545     }
11546
11547   if (ctype && TREE_ASM_WRITTEN (fndecl))
11548     note_debug_info_needed (ctype);
11549
11550   current_function_returns_null |= can_reach_end;
11551
11552   /* Since we don't normally go through c_expand_return for constructors,
11553      this normally gets the wrong value.
11554      Also, named return values have their return codes emitted after
11555      NOTE_INSN_FUNCTION_END, confusing jump.c.  */
11556   if (DECL_CONSTRUCTOR_P (fndecl)
11557       || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
11558     current_function_returns_null = 0;
11559
11560   if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
11561     cp_warning ("`noreturn' function `%D' does return", fndecl);
11562   else if ((warn_return_type || pedantic)
11563            && current_function_returns_null
11564            && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
11565     {
11566       /* If this function returns non-void and control can drop through,
11567          complain.  */
11568       cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
11569     }
11570   /* With just -W, complain only if function returns both with
11571      and without a value.  */
11572   else if (extra_warnings
11573            && current_function_returns_value && current_function_returns_null)
11574     warning ("this function may return with or without a value");
11575
11576   /* Free all the tree nodes making up this function.  */
11577   /* Switch back to allocating nodes permanently
11578      until we start another function.  */
11579   permanent_allocation (1);
11580
11581   if (flag_cadillac)
11582     cadillac_finish_function (fndecl);
11583
11584   if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
11585     {
11586       /* Stop pointing to the local nodes about to be freed.  */
11587       /* But DECL_INITIAL must remain nonzero so we know this
11588          was an actual function definition.  */
11589       DECL_INITIAL (fndecl) = error_mark_node;
11590       if (! DECL_CONSTRUCTOR_P (fndecl)
11591           || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
11592         DECL_ARGUMENTS (fndecl) = NULL_TREE;
11593     }
11594
11595   /* Let the error reporting routines know that we're outside a function.  */
11596   current_function_decl = NULL_TREE;
11597   named_label_uses = NULL_TREE;
11598 }
11599 \f
11600 /* Create the FUNCTION_DECL for a function definition.
11601    LINE1 is the line number that the definition absolutely begins on.
11602    LINE2 is the line number that the name of the function appears on.
11603    DECLSPECS and DECLARATOR are the parts of the declaration;
11604    they describe the return type and the name of the function,
11605    but twisted together in a fashion that parallels the syntax of C.
11606
11607    This function creates a binding context for the function body
11608    as well as setting up the FUNCTION_DECL in current_function_decl.
11609
11610    Returns a FUNCTION_DECL on success.
11611
11612    If the DECLARATOR is not suitable for a function (it defines a datum
11613    instead), we return 0, which tells yyparse to report a parse error.
11614
11615    May return void_type_node indicating that this method is actually
11616    a friend.  See grokfield for more details.
11617
11618    Came here with a `.pushlevel' .
11619
11620    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
11621    CHANGES TO CODE IN `grokfield'.  */
11622 tree
11623 start_method (declspecs, declarator, raises)
11624      tree declarator, declspecs, raises;
11625 {
11626   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises);
11627
11628   /* Something too ugly to handle.  */
11629   if (fndecl == NULL_TREE)
11630     return NULL_TREE;
11631
11632   /* Pass friends other than inline friend functions back.  */
11633   if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
11634     return fndecl;
11635
11636   if (TREE_CODE (fndecl) != FUNCTION_DECL)
11637     /* Not a function, tell parser to report parse error.  */
11638     return NULL_TREE;
11639
11640   if (IS_SIGNATURE (current_class_type))
11641     {
11642       IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
11643       /* In case we need this info later.  */
11644       HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1;
11645     }
11646
11647   if (DECL_IN_AGGR_P (fndecl))
11648     {
11649       if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
11650         {
11651           if (DECL_CONTEXT (fndecl))
11652             cp_error ("`%D' is already defined in class %s", fndecl,
11653                              TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
11654         }
11655       return void_type_node;
11656     }
11657
11658   /* If we're expanding a template, a function must be explicitly declared
11659      inline if we're to compile it now.  If it isn't, we have to wait to see
11660      whether it's needed, and whether an override exists.  */
11661   if (flag_default_inline && !processing_template_defn)
11662     DECL_INLINE (fndecl) = 1;
11663
11664   /* We read in the parameters on the maybepermanent_obstack,
11665      but we won't be getting back to them until after we
11666      may have clobbered them.  So the call to preserve_data
11667      will keep them safe.  */
11668   preserve_data ();
11669
11670   if (! DECL_FRIEND_P (fndecl))
11671     {
11672       if (DECL_CHAIN (fndecl) != NULL_TREE)
11673         {
11674           /* Need a fresh node here so that we don't get circularity
11675              when we link these together.  If FNDECL was a friend, then
11676              `pushdecl' does the right thing, which is nothing wrt its
11677              current value of DECL_CHAIN.  */
11678           fndecl = copy_node (fndecl);
11679         }
11680       if (TREE_CHAIN (fndecl))
11681         {
11682           fndecl = copy_node (fndecl);
11683           TREE_CHAIN (fndecl) = NULL_TREE;
11684         }
11685
11686       if (DECL_CONSTRUCTOR_P (fndecl))
11687         grok_ctor_properties (current_class_type, fndecl);
11688       else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
11689         grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
11690     }
11691
11692   finish_decl (fndecl, NULL_TREE, NULL_TREE, 0);
11693
11694   /* Make a place for the parms */
11695   pushlevel (0);
11696   current_binding_level->parm_flag = 1;
11697   
11698   DECL_IN_AGGR_P (fndecl) = 1;
11699   return fndecl;
11700 }
11701
11702 /* Go through the motions of finishing a function definition.
11703    We don't compile this method until after the whole class has
11704    been processed.
11705
11706    FINISH_METHOD must return something that looks as though it
11707    came from GROKFIELD (since we are defining a method, after all).
11708
11709    This is called after parsing the body of the function definition.
11710    STMTS is the chain of statements that makes up the function body.
11711
11712    DECL is the ..._DECL that `start_method' provided.  */
11713
11714 tree
11715 finish_method (decl)
11716      tree decl;
11717 {
11718   register tree fndecl = decl;
11719   tree old_initial;
11720   tree context = DECL_CONTEXT (fndecl);
11721
11722   register tree link;
11723
11724   if (TYPE_MAIN_VARIANT (decl) == void_type_node)
11725     return decl;
11726
11727   old_initial = DECL_INITIAL (fndecl);
11728
11729   /* Undo the level for the parms (from start_method).
11730      This is like poplevel, but it causes nothing to be
11731      saved.  Saving information here confuses symbol-table
11732      output routines.  Besides, this information will
11733      be correctly output when this method is actually
11734      compiled.  */
11735
11736   /* Clear out the meanings of the local variables of this level;
11737      also record in each decl which block it belongs to.  */
11738
11739   for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
11740     {
11741       if (DECL_NAME (link) != NULL_TREE)
11742         IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
11743       my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
11744       DECL_CONTEXT (link) = NULL_TREE;
11745     }
11746
11747   /* Restore all name-meanings of the outer levels
11748      that were shadowed by this level.  */
11749
11750   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
11751       IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11752   for (link = current_binding_level->class_shadowed;
11753        link; link = TREE_CHAIN (link))
11754     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11755   for (link = current_binding_level->type_shadowed;
11756        link; link = TREE_CHAIN (link))
11757     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11758
11759   GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
11760                       (HOST_WIDE_INT) current_binding_level->level_chain,
11761                       current_binding_level->parm_flag,
11762                       current_binding_level->keep,
11763                       current_binding_level->tag_transparent);
11764
11765   poplevel (0, 0, 0);
11766
11767   DECL_INITIAL (fndecl) = old_initial;
11768
11769   /* We used to check if the context of FNDECL was different from
11770      current_class_type as another way to get inside here.  This didn't work
11771      for String.cc in libg++.  */
11772   if (DECL_FRIEND_P (fndecl))
11773     {
11774       CLASSTYPE_INLINE_FRIENDS (current_class_type)
11775         = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
11776       decl = void_type_node;
11777     }
11778
11779   return decl;
11780 }
11781 \f
11782 /* Called when a new struct TYPE is defined.
11783    If this structure or union completes the type of any previous
11784    variable declaration, lay it out and output its rtl.  */
11785
11786 void
11787 hack_incomplete_structures (type)
11788      tree type;
11789 {
11790   tree decl;
11791
11792   if (current_binding_level->n_incomplete == 0)
11793     return;
11794
11795   if (!type) /* Don't do this for class templates.  */
11796     return;
11797
11798   for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
11799     if (TREE_TYPE (decl) == type
11800         || (TREE_TYPE (decl)
11801             && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
11802             && TREE_TYPE (TREE_TYPE (decl)) == type))
11803       {
11804         if (TREE_CODE (decl) == TYPE_DECL)
11805           layout_type (TREE_TYPE (decl));
11806         else
11807           {
11808             int toplevel = global_binding_level == current_binding_level;
11809             if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
11810                 && TREE_TYPE (TREE_TYPE (decl)) == type)
11811               layout_type (TREE_TYPE (decl));
11812             layout_decl (decl, 0);
11813             rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
11814             if (! toplevel)
11815               {
11816                 expand_decl (decl);
11817                 expand_decl_cleanup (decl, maybe_build_cleanup (decl));
11818                 expand_decl_init (decl);
11819               }
11820           }
11821         my_friendly_assert (current_binding_level->n_incomplete > 0, 164);
11822         --current_binding_level->n_incomplete;
11823       }
11824 }
11825
11826 /* Nonzero if presently building a cleanup.  Needed because
11827    SAVE_EXPRs are not the right things to use inside of cleanups.
11828    They are only ever evaluated once, where the cleanup
11829    might be evaluated several times.  In this case, a later evaluation
11830    of the cleanup might fill in the SAVE_EXPR_RTL, and it will
11831    not be valid for an earlier cleanup.  */
11832
11833 int building_cleanup;
11834
11835 /* If DECL is of a type which needs a cleanup, build that cleanup here.
11836    We don't build cleanups if just going for syntax checking, since
11837    fixup_cleanups does not know how to not handle them.
11838
11839    Don't build these on the momentary obstack; they must live
11840    the life of the binding contour.  */
11841 tree
11842 maybe_build_cleanup (decl)
11843      tree decl;
11844 {
11845   tree type = TREE_TYPE (decl);
11846   if (TYPE_NEEDS_DESTRUCTOR (type))
11847     {
11848       int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
11849       tree rval;
11850       int old_building_cleanup = building_cleanup;
11851       building_cleanup = 1;
11852
11853       if (TREE_CODE (decl) != PARM_DECL)
11854         temp = suspend_momentary ();
11855
11856       if (TREE_CODE (type) == ARRAY_TYPE)
11857         rval = decl;
11858       else
11859         {
11860           mark_addressable (decl);
11861           rval = build_unary_op (ADDR_EXPR, decl, 0);
11862         }
11863
11864       /* Optimize for space over speed here.  */
11865       if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
11866           || flag_expensive_optimizations)
11867         flags |= LOOKUP_NONVIRTUAL;
11868
11869       /* Use TYPE_MAIN_VARIANT so we don't get a warning about
11870          calling delete on a `const' variable.  */
11871       if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval))))
11872         rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval);
11873
11874       rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0);
11875
11876       if (TYPE_USES_VIRTUAL_BASECLASSES (type)
11877           && ! TYPE_HAS_DESTRUCTOR (type))
11878         rval = build_compound_expr (tree_cons (NULL_TREE, rval,
11879                                                build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
11880
11881       current_binding_level->have_cleanups = 1;
11882       current_binding_level->more_exceptions_ok = 0;
11883
11884       if (TREE_CODE (decl) != PARM_DECL)
11885         resume_momentary (temp);
11886
11887       building_cleanup = old_building_cleanup;
11888
11889       return rval;
11890     }
11891   return 0;
11892 }
11893 \f
11894 /* Expand a C++ expression at the statement level.
11895    This is needed to ferret out nodes which have UNKNOWN_TYPE.
11896    The C++ type checker should get all of these out when
11897    expressions are combined with other, type-providing, expressions,
11898    leaving only orphan expressions, such as:
11899
11900    &class::bar;         / / takes its address, but does nothing with it.
11901
11902    */
11903 void
11904 cplus_expand_expr_stmt (exp)
11905      tree exp;
11906 {
11907   if (TREE_TYPE (exp) == unknown_type_node)
11908     {
11909       if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
11910         error ("address of overloaded function with no contextual type information");
11911       else if (TREE_CODE (exp) == COMPONENT_REF)
11912         warning ("useless reference to a member function name, did you forget the ()?");
11913     }
11914   else
11915     {
11916       int remove_implicit_immediately = 0;
11917
11918       if (TREE_CODE (exp) == FUNCTION_DECL)
11919         {
11920           cp_warning ("reference, not call, to function `%D'", exp);
11921           warning ("at this point in file");
11922         }
11923       if (TREE_RAISES (exp))
11924         {
11925           my_friendly_assert (flag_handle_exceptions, 165);
11926           if (flag_handle_exceptions == 2)
11927             {
11928               if (! current_binding_level->more_exceptions_ok)
11929                 {
11930                   extern struct nesting *nesting_stack, *block_stack;
11931
11932                   remove_implicit_immediately
11933                     = (nesting_stack != block_stack);
11934                   cplus_expand_start_try (1);
11935                 }
11936               current_binding_level->have_exceptions = 1;
11937             }
11938         }
11939
11940       expand_expr_stmt (break_out_cleanups (exp));
11941
11942       if (remove_implicit_immediately)
11943         pop_implicit_try_blocks (NULL_TREE);
11944     }
11945
11946   /* Clean up any pending cleanups.  This happens when a function call
11947      returns a cleanup-needing value that nobody uses.  */
11948   expand_cleanups_to (NULL_TREE);
11949 }
11950
11951 /* When a stmt has been parsed, this function is called.
11952
11953    Currently, this function only does something within a
11954    constructor's scope: if a stmt has just assigned to this,
11955    and we are in a derived class, we call `emit_base_init'.  */
11956
11957 void
11958 finish_stmt ()
11959 {
11960   extern struct nesting *cond_stack, *loop_stack, *case_stack;
11961
11962   
11963   if (current_function_assigns_this
11964       || ! current_function_just_assigned_this)
11965     return;
11966   if (DECL_CONSTRUCTOR_P (current_function_decl))
11967     {
11968       /* Constructors must wait until we are out of control
11969          zones before calling base constructors.  */
11970       if (cond_stack || loop_stack || case_stack)
11971         return;
11972       emit_insns (base_init_insns);
11973       check_base_init (current_class_type);
11974     }
11975   current_function_assigns_this = 1;
11976
11977   if (flag_cadillac)
11978     cadillac_finish_stmt ();
11979 }
11980
11981 void
11982 pop_implicit_try_blocks (decl)
11983      tree decl;
11984 {
11985   if (decl)
11986     {
11987       my_friendly_assert (current_binding_level->parm_flag == 3, 166);
11988       current_binding_level->names = TREE_CHAIN (decl);
11989     }
11990
11991   while (current_binding_level->parm_flag == 3)
11992     {
11993       tree name = get_identifier ("(compiler error)");
11994       tree orig_ex_type = current_exception_type;
11995       tree orig_ex_decl = current_exception_decl;
11996       tree orig_ex_obj = current_exception_object;
11997       tree decl = cplus_expand_end_try (2);
11998
11999       /* @@ It would be nice to make all these point
12000          to exactly the same handler.  */
12001       /* Start hidden EXCEPT.  */
12002       cplus_expand_start_except (name, decl);
12003       /* reraise ALL.  */
12004       cplus_expand_reraise (NULL_TREE);
12005       current_exception_type = orig_ex_type;
12006       current_exception_decl = orig_ex_decl;
12007       current_exception_object = orig_ex_obj;
12008       /* This will reraise for us.  */
12009       cplus_expand_end_except (error_mark_node);
12010     }
12011
12012   if (decl)
12013     {
12014       TREE_CHAIN (decl) = current_binding_level->names;
12015       current_binding_level->names = decl;
12016     }
12017 }
12018
12019 /* Push a cleanup onto the current binding contour that will cause
12020    ADDR to be cleaned up, in the case that an exception propagates
12021    through its binding contour.  */
12022
12023 void
12024 push_exception_cleanup (addr)
12025      tree addr;
12026 {
12027   tree decl = build_decl (VAR_DECL, get_identifier (EXCEPTION_CLEANUP_NAME), ptr_type_node);
12028   tree cleanup;
12029
12030   decl = pushdecl (decl);
12031   DECL_REGISTER (decl) = 1;
12032   store_init_value (decl, addr);
12033   expand_decl (decl);
12034   expand_decl_init (decl);
12035
12036   cleanup = build (COND_EXPR, integer_type_node,
12037                    build (NE_EXPR, integer_type_node,
12038                           decl, integer_zero_node),
12039                    build_delete (TREE_TYPE (addr), decl,
12040                                  lookup_name (in_charge_identifier, 0),
12041                                  LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0),
12042                    integer_zero_node);
12043   expand_decl_cleanup (decl, cleanup);
12044 }
12045
12046 /* For each binding contour, emit code that deactivates the
12047    exception cleanups.  All other cleanups are left as they were.  */
12048
12049 static void
12050 deactivate_exception_cleanups ()
12051 {
12052   struct binding_level *b = current_binding_level;
12053   tree xyzzy = get_identifier (EXCEPTION_CLEANUP_NAME);
12054   while (b != class_binding_level)
12055     {
12056       if (b->parm_flag == 3)
12057         {
12058           tree decls = b->names;
12059           while (decls)
12060             {
12061               if (DECL_NAME (decls) == xyzzy)
12062                 expand_assignment (decls, integer_zero_node, 0, 0);
12063               decls = TREE_CHAIN (decls);
12064             }
12065         }
12066       b = b->level_chain;
12067     }
12068 }
12069
12070 /* Change a static member function definition into a FUNCTION_TYPE, instead
12071    of the METHOD_TYPE that we create when it's originally parsed.  */
12072 void
12073 revert_static_member_fn (fn, decl, argtypes)
12074      tree *fn, *decl, *argtypes;
12075 {
12076   tree tmp, function = *fn;
12077
12078   *argtypes = TREE_CHAIN (*argtypes);
12079   tmp = build_function_type (TREE_TYPE (function), *argtypes);
12080   tmp = build_type_variant (tmp, TYPE_READONLY (function),
12081                             TYPE_VOLATILE (function));
12082   tmp = build_exception_variant (TYPE_METHOD_BASETYPE (function), tmp,
12083                                  TYPE_RAISES_EXCEPTIONS (function));
12084   TREE_TYPE (*decl) = tmp;
12085   *fn = tmp;
12086   DECL_STATIC_FUNCTION_P (*decl) = 1;
12087 }