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