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