OSDN Git Service

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