1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
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. */
27 /* ??? not all decl nodes are given the most useful possible
28 line numbers. For example, the CONST_DECLs for enum values. */
38 #include <sys/types.h>
45 #define obstack_chunk_alloc xmalloc
46 #define obstack_chunk_free free
48 extern tree builtin_return_address_fndecl
;
50 extern struct obstack permanent_obstack
;
52 extern int current_class_depth
;
54 extern tree static_ctors
, static_dtors
;
56 extern int static_labelno
;
58 /* Stack of places to restore the search obstack back to. */
60 /* Obstack used for remembering local class declarations (like
61 enums and static (const) members. */
63 struct obstack decl_obstack
;
64 static struct stack_level
*decl_stack
;
66 #ifndef CHAR_TYPE_SIZE
67 #define CHAR_TYPE_SIZE BITS_PER_UNIT
70 #ifndef SHORT_TYPE_SIZE
71 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
75 #define INT_TYPE_SIZE BITS_PER_WORD
78 #ifndef LONG_TYPE_SIZE
79 #define LONG_TYPE_SIZE BITS_PER_WORD
82 #ifndef LONG_LONG_TYPE_SIZE
83 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
86 #ifndef WCHAR_UNSIGNED
87 #define WCHAR_UNSIGNED 0
90 #ifndef FLOAT_TYPE_SIZE
91 #define FLOAT_TYPE_SIZE BITS_PER_WORD
94 #ifndef DOUBLE_TYPE_SIZE
95 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
98 #ifndef LONG_DOUBLE_TYPE_SIZE
99 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
102 #ifndef BOOL_TYPE_SIZE
103 #ifdef SLOW_BYTE_ACCESS
104 #define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (POINTER_SIZE) : (CHAR_TYPE_SIZE))
106 #define BOOL_TYPE_SIZE CHAR_TYPE_SIZE
110 /* We let tm.h override the types used here, to handle trivial differences
111 such as the choice of unsigned int or long unsigned int for size_t.
112 When machines start needing nontrivial differences in the size type,
113 it would be best to do something here to figure out automatically
114 from other information what type to use. */
117 #define SIZE_TYPE "long unsigned int"
121 #define PTRDIFF_TYPE "long int"
125 #define WCHAR_TYPE "int"
128 static tree grokparms
PROTO((tree
, int));
129 static tree lookup_nested_type
PROTO((tree
, tree
));
130 static char *redeclaration_error_message
PROTO((tree
, tree
));
131 static void revert_static_member_fn
PROTO((tree
*, tree
*, tree
*));
132 static tree push_overloaded_decl
PROTO((tree
, int));
133 static void push_overloaded_decl_top_level
PROTO((tree
, int));
135 static struct stack_level
*push_decl_level
PROTO((struct stack_level
*,
137 static void push_binding_level
PROTO((struct binding_level
*, int,
139 static void pop_binding_level
PROTO((void));
140 static void suspend_binding_level
PROTO((void));
141 static void resume_binding_level
PROTO((struct binding_level
*));
142 static struct binding_level
*make_binding_level
PROTO((void));
143 static int namespace_bindings_p
PROTO((void));
144 static void declare_namespace_level
PROTO((void));
145 static tree get_unique_name
PROTO((void));
146 static void signal_catch
PROTO((int));
147 static void storedecls
PROTO((tree
));
148 static void storetags
PROTO((tree
));
149 static void require_complete_types_for_parms
PROTO((tree
));
150 static void push_overloaded_decl_1
PROTO((tree
));
151 static int ambi_op_p
PROTO((tree
));
152 static int unary_op_p
PROTO((tree
));
153 static tree store_bindings
PROTO((tree
, tree
));
154 static tree lookup_tag_reverse
PROTO((tree
, tree
));
155 static tree obscure_complex_init
PROTO((tree
, tree
));
156 static tree maybe_build_cleanup_1
PROTO((tree
, tree
));
157 static tree lookup_name_real
PROTO((tree
, int, int));
158 static void warn_extern_redeclared_static
PROTO((tree
, tree
));
159 static void grok_reference_init
PROTO((tree
, tree
, tree
, tree
*));
160 static tree grokfndecl
PROTO((tree
, tree
, tree
, int,
162 tree
, tree
, tree
, int, int, int, int));
163 static tree grokvardecl
PROTO((tree
, tree
, RID_BIT_TYPE
*, int, int));
164 static tree lookup_tag
PROTO((enum tree_code
, tree
,
165 struct binding_level
*, int));
166 static void set_identifier_type_value_with_scope
167 PROTO((tree
, tree
, struct binding_level
*));
168 static void record_builtin_type
PROTO((enum rid
, char *, tree
));
169 static int member_function_or_else
PROTO((tree
, tree
, char *));
170 static void bad_specifiers
PROTO((tree
, char *, int, int, int, int,
173 /* a node which has tree code ERROR_MARK, and whose type is itself.
174 All erroneous expressions are replaced with this node. All functions
175 that accept nodes as arguments should avoid generating error messages
176 if this node is one of the arguments, since it is undesirable to get
177 multiple error messages from one error in the input. */
179 tree error_mark_node
;
181 /* Erroneous argument lists can use this *IFF* they do not modify it. */
182 tree error_mark_list
;
184 /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
186 tree short_integer_type_node
;
187 tree integer_type_node
;
188 tree long_integer_type_node
;
189 tree long_long_integer_type_node
;
191 tree short_unsigned_type_node
;
192 tree unsigned_type_node
;
193 tree long_unsigned_type_node
;
194 tree long_long_unsigned_type_node
;
196 tree ptrdiff_type_node
;
198 tree unsigned_char_type_node
;
199 tree signed_char_type_node
;
201 tree wchar_type_node
;
202 tree signed_wchar_type_node
;
203 tree unsigned_wchar_type_node
;
205 tree wchar_decl_node
;
207 tree float_type_node
;
208 tree double_type_node
;
209 tree long_double_type_node
;
211 tree complex_integer_type_node
;
212 tree complex_float_type_node
;
213 tree complex_double_type_node
;
214 tree complex_long_double_type_node
;
216 tree intQI_type_node
;
217 tree intHI_type_node
;
218 tree intSI_type_node
;
219 tree intDI_type_node
;
221 tree unsigned_intQI_type_node
;
222 tree unsigned_intHI_type_node
;
223 tree unsigned_intSI_type_node
;
224 tree unsigned_intDI_type_node
;
226 /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */
228 tree void_type_node
, void_list_node
;
231 /* Nodes for types `void *' and `const void *'. */
234 static tree const_ptr_type_node
;
236 /* Nodes for types `char *' and `const char *'. */
238 tree string_type_node
, const_string_type_node
;
240 /* Type `char[256]' or something like it.
241 Used when an array of char is needed and the size is irrelevant. */
243 tree char_array_type_node
;
245 /* Type `int[256]' or something like it.
246 Used when an array of int needed and the size is irrelevant. */
248 tree int_array_type_node
;
250 /* Type `wchar_t[256]' or something like it.
251 Used when a wide string literal is created. */
253 tree wchar_array_type_node
;
255 /* The bool data type, and constants */
256 tree boolean_type_node
, boolean_true_node
, boolean_false_node
;
258 /* type `int ()' -- used for implicit declaration of functions. */
260 tree default_function_type
;
262 /* function types `double (double)' and `double (double, double)', etc. */
264 static tree double_ftype_double
, double_ftype_double_double
;
265 static tree int_ftype_int
, long_ftype_long
;
266 static tree float_ftype_float
;
267 static tree ldouble_ftype_ldouble
;
269 /* Function type `int (const void *, const void *, size_t)' */
270 static tree int_ftype_cptr_cptr_sizet
;
273 tree vtable_entry_type
;
274 tree delta_type_node
;
276 /* Old rtti stuff. */
277 tree __baselist_desc_type_node
;
278 tree __i_desc_type_node
, __m_desc_type_node
;
279 tree __t_desc_array_type
, __i_desc_array_type
, __m_desc_array_type
;
281 tree __t_desc_type_node
;
283 tree __tp_desc_type_node
;
285 tree __access_mode_type_node
;
286 tree __bltn_desc_type_node
, __user_desc_type_node
, __class_desc_type_node
;
287 tree __ptr_desc_type_node
, __attr_desc_type_node
, __func_desc_type_node
;
288 tree __ptmf_desc_type_node
, __ptmd_desc_type_node
;
290 /* Not needed yet? May be needed one day? */
291 tree __bltn_desc_array_type
, __user_desc_array_type
, __class_desc_array_type
;
292 tree __ptr_desc_array_type
, __attr_dec_array_type
, __func_desc_array_type
;
293 tree __ptmf_desc_array_type
, __ptmd_desc_array_type
;
296 tree class_star_type_node
;
297 tree class_type_node
, record_type_node
, union_type_node
, enum_type_node
;
298 tree unknown_type_node
;
299 tree opaque_type_node
, signature_type_node
;
300 tree sigtable_entry_type
;
302 /* Array type `vtable_entry_type[]' */
308 /* In a destructor, the point at which all derived class destroying
309 has been done, just before any base class destroying will be done. */
313 /* In a destructor, the last insn emitted after the start of the
314 function and the parms. */
316 static rtx last_dtor_insn
;
318 /* In a constructor, the last insn emitted after the start of the
319 function and the parms, but before the start of the exception
322 static rtx last_parm_cleanup_insn
;
324 /* In a constructor, the point at which we are ready to return
325 the pointer to the initialized object. */
329 /* A FUNCTION_DECL which can call `abort'. Not necessarily the
330 one that the user will declare, but sufficient to be called
331 by routines that want to abort the program. */
335 extern rtx cleanup_label
, return_label
;
337 /* If original DECL_RESULT of current function was a register,
338 but due to being an addressable named return value, would up
339 on the stack, this variable holds the named return value's
340 original location. */
341 static rtx original_result_rtx
;
343 /* Sequence of insns which represents base initialization. */
346 /* C++: Keep these around to reduce calls to `get_identifier'.
347 Identifiers for `this' in member functions and the auto-delete
348 parameter for destructors. */
349 tree this_identifier
, in_charge_identifier
;
350 tree ctor_identifier
, dtor_identifier
;
351 /* Used in pointer to member functions, in vtables, and in sigtables. */
352 tree pfn_identifier
, index_identifier
, delta_identifier
, delta2_identifier
;
353 tree pfn_or_delta2_identifier
, tag_identifier
;
354 tree vt_off_identifier
;
356 struct named_label_list
358 struct binding_level
*binding_level
;
361 char *filename_o_goto
;
363 struct named_label_list
*next
;
366 /* A list (chain of TREE_LIST nodes) of named label uses.
367 The TREE_PURPOSE field is the list of variables defined
368 the the label's scope defined at the point of use.
369 The TREE_VALUE field is the LABEL_DECL used.
370 The TREE_TYPE field holds `current_binding_level' at the
371 point of the label's use.
373 BWAHAHAAHAHahhahahahaah. No, no, no, said the little chicken.
375 Look at the pretty struct named_label_list. See the pretty struct
376 with the pretty named fields that describe what they do. See the
377 pretty lack of gratuitous casts. Notice the code got a lot cleaner.
379 Used only for jumps to as-yet undefined labels, since
380 jumps to defined labels can have their validity checked
383 static struct named_label_list
*named_label_uses
= NULL
;
385 /* A list of objects which have constructors or destructors
386 which reside in the global scope. The decl is stored in
387 the TREE_VALUE slot and the initializer is stored
388 in the TREE_PURPOSE slot. */
389 tree static_aggregates
;
393 /* Two expressions that are constants with value zero.
394 The first is of type `int', the second of type `void *'. */
396 tree integer_zero_node
;
397 tree null_pointer_node
;
399 /* The value for __null (NULL), either of type `void *' or, with -ansi,
400 an integer type of the same size. */
404 /* A node for the integer constants 1, 2, and 3. */
406 tree integer_one_node
, integer_two_node
, integer_three_node
;
408 /* While defining an enum type, this is 1 plus the last enumerator
411 static tree enum_next_value
;
413 /* Nonzero means that there was overflow computing enum_next_value. */
415 static int enum_overflow
;
417 /* Parsing a function declarator leaves a list of parameter names
418 or a chain or parameter decls here. */
420 tree last_function_parms
;
422 /* Parsing a function declarator leaves here a chain of structure
423 and enum types declared in the parmlist. */
425 static tree last_function_parm_tags
;
427 /* After parsing the declarator that starts a function definition,
428 `start_function' puts here the list of parameter names or chain of decls.
429 `store_parm_decls' finds it here. */
431 static tree current_function_parms
;
433 /* Similar, for last_function_parm_tags. */
434 static tree current_function_parm_tags
;
436 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
437 that have names. Here so we can clear out their names' definitions
438 at the end of the function. */
440 static tree named_labels
;
442 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
444 static tree shadowed_labels
;
446 /* The FUNCTION_DECL for the function currently being compiled,
447 or 0 if between functions. */
448 tree current_function_decl
;
450 /* Set to 0 at beginning of a function definition, set to 1 if
451 a return statement that specifies a return value is seen. */
453 int current_function_returns_value
;
455 /* Set to 0 at beginning of a function definition, set to 1 if
456 a return statement with no argument is seen. */
458 int current_function_returns_null
;
460 /* Set to 0 at beginning of a function definition, and whenever
461 a label (case or named) is defined. Set to value of expression
462 returned from function when that value can be transformed into
463 a named return value. */
465 tree current_function_return_value
;
467 /* Set to nonzero by `grokdeclarator' for a function
468 whose return type is defaulted, if warnings for this are desired. */
470 static int warn_about_return_type
;
472 /* Nonzero means give `double' the same size as `float'. */
474 extern int flag_short_double
;
476 /* Nonzero means don't recognize any builtin functions. */
478 extern int flag_no_builtin
;
480 /* Nonzero means don't recognize the non-ANSI builtin functions.
483 extern int flag_no_nonansi_builtin
;
485 /* Nonzero means enable obscure ANSI features and disable GNU extensions
486 that might cause ANSI-compliant code to be miscompiled. */
488 extern int flag_ansi
;
490 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
492 extern int flag_huge_objects
;
494 /* Nonzero if we want to conserve space in the .o files. We do this
495 by putting uninitialized data and runtime initialized data into
496 .common instead of .data at the expense of not flagging multiple
498 extern int flag_conserve_space
;
500 /* Pointers to the base and current top of the language name stack. */
502 extern tree
*current_lang_base
, *current_lang_stack
;
504 /* C and C++ flags are in decl2.c. */
506 /* Set to 0 at beginning of a constructor, set to 1
507 if that function does an allocation before referencing its
508 instance variable. */
509 static int current_function_assigns_this
;
510 int current_function_just_assigned_this
;
512 /* Set to 0 at beginning of a function. Set non-zero when
513 store_parm_decls is called. Don't call store_parm_decls
514 if this flag is non-zero! */
515 int current_function_parms_stored
;
517 /* Flag used when debugging spew.c */
519 extern int spew_debug
;
521 /* This is a copy of the class_shadowed list of the previous class binding
522 contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs
523 when entering another class scope (i.e. a cache miss). */
524 extern tree previous_class_values
;
526 /* A expression of value 0 with the same precision as a sizetype
528 tree signed_size_zero_node
;
531 /* Allocate a level of searching. */
535 push_decl_level (stack
, obstack
)
536 struct stack_level
*stack
;
537 struct obstack
*obstack
;
539 struct stack_level tem
;
542 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
545 /* For each binding contour we allocate a binding_level structure
546 which records the names defined in that contour.
549 1) one for each function definition,
550 where internal declarations of the parameters appear.
551 2) one for each compound statement,
552 to record its declarations.
554 The current meaning of a name can be found by searching the levels
555 from the current one out to the global one.
557 Off to the side, may be the class_binding_level. This exists only
558 to catch class-local declarations. It is otherwise nonexistent.
560 Also there may be binding levels that catch cleanups that must be
561 run when exceptions occur. */
563 /* Note that the information in the `names' component of the global contour
564 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
568 /* A chain of _DECL nodes for all variables, constants, functions,
569 and typedef types. These are in the reverse of the order
573 /* A list of structure, union and enum definitions, for looking up
575 It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
576 or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
577 or ENUMERAL_TYPE node.
579 C++: the TREE_VALUE nodes can be simple types for
580 component_bindings. */
583 /* For each level, a list of shadowed outer-level local definitions
584 to be restored when this level is popped.
585 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
586 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
589 /* Same, for IDENTIFIER_CLASS_VALUE. */
592 /* Same, for IDENTIFIER_TYPE_VALUE. */
595 /* For each level (except not the global one),
596 a chain of BLOCK nodes for all the levels
597 that were entered and exited one level down. */
600 /* The BLOCK node for this level, if one has been preallocated.
601 If 0, the BLOCK is allocated (if needed) when the level is popped. */
604 /* The binding level which this one is contained in (inherits from). */
605 struct binding_level
*level_chain
;
607 /* List of decls in `names' that have incomplete
608 structure or union types. */
611 /* List of VAR_DECLS saved from a previous for statement.
612 These would be dead in ANSI-conforming code, but might
613 be referenced in ARM-era code. */
614 tree dead_vars_from_for
;
616 /* 1 for the level that holds the parameters of a function.
617 2 for the level that holds a class declaration.
618 3 for levels that hold parameter declarations. */
619 unsigned parm_flag
: 4;
621 /* 1 means make a BLOCK for this level regardless of all else.
622 2 for temporary binding contours created by the compiler. */
625 /* Nonzero if this level "doesn't exist" for tags. */
626 unsigned tag_transparent
: 1;
628 /* Nonzero if this level can safely have additional
629 cleanup-needing variables added to it. */
630 unsigned more_cleanups_ok
: 1;
631 unsigned have_cleanups
: 1;
633 /* Nonzero if this level is for storing the decls for template
634 parameters and generic decls; these decls will be discarded and
635 replaced with a TEMPLATE_DECL. */
636 unsigned pseudo_global
: 1;
638 /* This is set for a namespace binding level. */
639 unsigned namespace_p
: 1;
641 /* True if this level is that of a for-statement where we need to
642 worry about ambiguous (ARM or ANSI) scope rules. */
643 unsigned is_for_scope
: 1;
645 /* Two bits left for this word. */
647 #if defined(DEBUG_CP_BINDING_LEVELS)
648 /* Binding depth at which this level began. */
649 unsigned binding_depth
;
650 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
653 #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
655 /* The (non-class) binding level currently in effect. */
657 static struct binding_level
*current_binding_level
;
659 /* The binding level of the current class, if any. */
661 static struct binding_level
*class_binding_level
;
663 /* The current (class or non-class) binding level currently in effect. */
665 #define inner_binding_level \
666 (class_binding_level ? class_binding_level : current_binding_level)
668 /* A chain of binding_level structures awaiting reuse. */
670 static struct binding_level
*free_binding_level
;
672 /* The outermost binding level, for names of file scope.
673 This is created when the compiler is started and exists
674 through the entire run. */
676 static struct binding_level
*global_binding_level
;
678 /* Binding level structures are initialized by copying this one. */
680 static struct binding_level clear_binding_level
;
682 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
684 static int keep_next_level_flag
;
686 #if defined(DEBUG_CP_BINDING_LEVELS)
687 static int binding_depth
= 0;
688 static int is_class_level
= 0;
695 for (i
= 0; i
< binding_depth
*2; i
++)
698 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
700 static tree pushdecl_with_scope
PROTO((tree
, struct binding_level
*));
703 push_binding_level (newlevel
, tag_transparent
, keep
)
704 struct binding_level
*newlevel
;
705 int tag_transparent
, keep
;
707 /* Add this level to the front of the chain (stack) of levels that
709 *newlevel
= clear_binding_level
;
710 if (class_binding_level
)
712 newlevel
->level_chain
= class_binding_level
;
713 class_binding_level
= (struct binding_level
*)0;
717 newlevel
->level_chain
= current_binding_level
;
719 current_binding_level
= newlevel
;
720 newlevel
->tag_transparent
= tag_transparent
;
721 newlevel
->more_cleanups_ok
= 1;
722 newlevel
->keep
= keep
;
723 #if defined(DEBUG_CP_BINDING_LEVELS)
724 newlevel
->binding_depth
= binding_depth
;
726 fprintf (stderr
, "push %s level 0x%08x line %d\n",
727 (is_class_level
) ? "class" : "block", newlevel
, lineno
);
730 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
736 if (class_binding_level
)
737 current_binding_level
= class_binding_level
;
739 if (global_binding_level
)
741 /* cannot pop a level, if there are none left to pop. */
742 if (current_binding_level
== global_binding_level
)
743 my_friendly_abort (123);
745 /* Pop the current level, and free the structure for reuse. */
746 #if defined(DEBUG_CP_BINDING_LEVELS)
749 fprintf (stderr
, "pop %s level 0x%08x line %d\n",
750 (is_class_level
) ? "class" : "block",
751 current_binding_level
, lineno
);
752 if (is_class_level
!= (current_binding_level
== class_binding_level
))
755 fprintf (stderr
, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
758 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
760 register struct binding_level
*level
= current_binding_level
;
761 current_binding_level
= current_binding_level
->level_chain
;
762 level
->level_chain
= free_binding_level
;
763 #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
764 if (level
->binding_depth
!= binding_depth
)
766 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
767 free_binding_level
= level
;
769 class_binding_level
= current_binding_level
;
770 if (class_binding_level
->parm_flag
!= 2)
771 class_binding_level
= 0;
772 while (current_binding_level
->parm_flag
== 2)
773 current_binding_level
= current_binding_level
->level_chain
;
778 suspend_binding_level ()
780 if (class_binding_level
)
781 current_binding_level
= class_binding_level
;
783 if (global_binding_level
)
785 /* cannot suspend a level, if there are none left to suspend. */
786 if (current_binding_level
== global_binding_level
)
787 my_friendly_abort (123);
789 /* Suspend the current level. */
790 #if defined(DEBUG_CP_BINDING_LEVELS)
793 fprintf (stderr
, "suspend %s level 0x%08x line %d\n",
794 (is_class_level
) ? "class" : "block",
795 current_binding_level
, lineno
);
796 if (is_class_level
!= (current_binding_level
== class_binding_level
))
799 fprintf (stderr
, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
802 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
804 current_binding_level
= current_binding_level
->level_chain
;
805 class_binding_level
= current_binding_level
;
806 if (class_binding_level
->parm_flag
!= 2)
807 class_binding_level
= 0;
808 while (current_binding_level
->parm_flag
== 2)
809 current_binding_level
= current_binding_level
->level_chain
;
814 resume_binding_level (b
)
815 struct binding_level
*b
;
817 if (class_binding_level
)
820 /* These are here because we cannot deal with shadows yet. */
821 sorry ("cannot resume a namespace inside class");
824 b
->level_chain
= class_binding_level
;
825 class_binding_level
= (struct binding_level
*)0;
831 /* These are here because we cannot deal with shadows yet. */
832 if (b
->level_chain
!= current_binding_level
)
834 sorry ("cannot resume a namespace inside a different namespace");
838 b
->level_chain
= current_binding_level
;
840 current_binding_level
= b
;
841 #if defined(DEBUG_CP_BINDING_LEVELS)
842 b
->binding_depth
= binding_depth
;
844 fprintf (stderr
, "resume %s level 0x%08x line %d\n",
845 (is_class_level
) ? "class" : "block", b
, lineno
);
848 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
851 /* Create a new `struct binding_level'. */
854 struct binding_level
*
855 make_binding_level ()
858 return (struct binding_level
*) xmalloc (sizeof (struct binding_level
));
861 /* Nonzero if we are currently in the global binding level. */
866 return current_binding_level
== global_binding_level
;
869 /* Nonzero if we are currently in a toplevel binding level. This
870 means either the global binding level or a namespace in a toplevel
874 toplevel_bindings_p ()
876 struct binding_level
*b
= current_binding_level
;
880 if (b
== global_binding_level
)
882 if (b
->pseudo_global
)
884 if (! b
->namespace_p
)
890 /* Nonzero if this is a namespace scope. */
893 namespace_bindings_p ()
895 return current_binding_level
->namespace_p
;
901 keep_next_level_flag
= 1;
904 /* Nonzero if the current level needs to have a BLOCK made. */
909 return (current_binding_level
->blocks
!= NULL_TREE
910 || current_binding_level
->keep
911 || current_binding_level
->names
!= NULL_TREE
912 || (current_binding_level
->tags
!= NULL_TREE
913 && !current_binding_level
->tag_transparent
));
916 /* Identify this binding level as a level of parameters. */
919 declare_parm_level ()
921 current_binding_level
->parm_flag
= 1;
925 declare_pseudo_global_level ()
927 current_binding_level
->pseudo_global
= 1;
931 declare_namespace_level ()
933 current_binding_level
->namespace_p
= 1;
937 pseudo_global_level_p ()
939 return current_binding_level
->pseudo_global
;
943 set_class_shadows (shadows
)
946 class_binding_level
->class_shadowed
= shadows
;
949 /* Enter a new binding level.
950 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
951 not for that of tags. */
954 pushlevel (tag_transparent
)
957 register struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
959 /* If this is the top level of a function,
960 just make sure that NAMED_LABELS is 0.
961 They should have been set to 0 at the end of the previous function. */
963 if (current_binding_level
== global_binding_level
)
964 my_friendly_assert (named_labels
== NULL_TREE
, 134);
966 /* Reuse or create a struct for this binding level. */
968 #if defined(DEBUG_CP_BINDING_LEVELS)
970 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
971 if (free_binding_level
)
972 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
974 newlevel
= free_binding_level
;
975 free_binding_level
= free_binding_level
->level_chain
;
979 newlevel
= make_binding_level ();
982 push_binding_level (newlevel
, tag_transparent
, keep_next_level_flag
);
983 GNU_xref_start_scope ((HOST_WIDE_INT
) newlevel
);
984 keep_next_level_flag
= 0;
988 note_level_for_for ()
990 current_binding_level
->is_for_scope
= 1;
994 pushlevel_temporary (tag_transparent
)
997 pushlevel (tag_transparent
);
998 current_binding_level
->keep
= 2;
1001 /* Note we don't call push_momentary() here. Otherwise, it would cause
1002 cleanups to be allocated on the momentary obstack, and they will be
1003 overwritten by the next statement. */
1005 expand_start_bindings (0);
1008 /* Exit a binding level.
1009 Pop the level off, and restore the state of the identifier-decl mappings
1010 that were in effect when this level was entered.
1012 If KEEP == 1, this level had explicit declarations, so
1013 and create a "block" (a BLOCK node) for the level
1014 to record its declarations and subblocks for symbol table output.
1016 If KEEP == 2, this level's subblocks go to the front,
1017 not the back of the current binding level. This happens,
1018 for instance, when code for constructors and destructors
1019 need to generate code at the end of a function which must
1020 be moved up to the front of the function.
1022 If FUNCTIONBODY is nonzero, this level is the body of a function,
1023 so create a block as if KEEP were set and also clear out all
1026 If REVERSE is nonzero, reverse the order of decls before putting
1027 them into the BLOCK. */
1030 poplevel (keep
, reverse
, functionbody
)
1036 /* The chain of decls was accumulated in reverse order.
1037 Put it into forward order, just for cleanliness. */
1039 int tmp
= functionbody
;
1040 int real_functionbody
= current_binding_level
->keep
== 2
1041 ? ((functionbody
= 0), tmp
) : functionbody
;
1042 tree tags
= functionbody
>= 0 ? current_binding_level
->tags
: 0;
1043 tree subblocks
= functionbody
>= 0 ? current_binding_level
->blocks
: 0;
1044 tree block
= NULL_TREE
;
1046 int block_previously_created
;
1048 GNU_xref_end_scope ((HOST_WIDE_INT
) current_binding_level
,
1049 (HOST_WIDE_INT
) current_binding_level
->level_chain
,
1050 current_binding_level
->parm_flag
,
1051 current_binding_level
->keep
);
1053 if (current_binding_level
->keep
== 1)
1056 /* Get the decls in the order they were written.
1057 Usually current_binding_level->names is in reverse order.
1058 But parameter decls were previously put in forward order. */
1061 current_binding_level
->names
1062 = decls
= nreverse (current_binding_level
->names
);
1064 decls
= current_binding_level
->names
;
1066 /* Output any nested inline functions within this block
1067 if they weren't already output. */
1069 for (decl
= decls
; decl
; decl
= TREE_CHAIN (decl
))
1070 if (TREE_CODE (decl
) == FUNCTION_DECL
1071 && ! TREE_ASM_WRITTEN (decl
)
1072 && DECL_INITIAL (decl
) != NULL_TREE
1073 && TREE_ADDRESSABLE (decl
)
1074 && decl_function_context (decl
) == current_function_decl
)
1076 /* If this decl was copied from a file-scope decl
1077 on account of a block-scope extern decl,
1078 propagate TREE_ADDRESSABLE to the file-scope decl. */
1079 if (DECL_ABSTRACT_ORIGIN (decl
) != NULL_TREE
)
1080 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl
)) = 1;
1083 push_function_context ();
1084 output_inline_function (decl
);
1085 pop_function_context ();
1089 /* If there were any declarations or structure tags in that level,
1090 or if this level is a function body,
1091 create a BLOCK to record them for the life of this function. */
1094 block_previously_created
= (current_binding_level
->this_block
!= NULL_TREE
);
1095 if (block_previously_created
)
1096 block
= current_binding_level
->this_block
;
1097 else if (keep
== 1 || functionbody
)
1098 block
= make_node (BLOCK
);
1099 if (block
!= NULL_TREE
)
1101 if (block_previously_created
)
1103 if (decls
|| tags
|| subblocks
)
1105 if (BLOCK_VARS (block
) || BLOCK_TYPE_TAGS (block
))
1107 warning ("internal compiler error: debugging info corrupted");
1109 BLOCK_VARS (block
) = decls
;
1110 BLOCK_TYPE_TAGS (block
) = tags
;
1112 /* We can have previous subblocks and new subblocks when
1113 doing fixup_gotos with complex cleanups. We chain the new
1114 subblocks onto the end of any pre-existing subblocks. */
1115 BLOCK_SUBBLOCKS (block
) = chainon (BLOCK_SUBBLOCKS (block
),
1118 /* If we created the block earlier on, and we are just
1119 diddling it now, then it already should have a proper
1120 BLOCK_END_NOTE value associated with it. */
1124 BLOCK_VARS (block
) = decls
;
1125 BLOCK_TYPE_TAGS (block
) = tags
;
1126 BLOCK_SUBBLOCKS (block
) = subblocks
;
1127 /* Otherwise, for a new block, install a new BLOCK_END_NOTE value. */
1128 remember_end_note (block
);
1132 /* In each subblock, record that this is its superior. */
1135 for (link
= subblocks
; link
; link
= TREE_CHAIN (link
))
1136 BLOCK_SUPERCONTEXT (link
) = block
;
1138 /* Clear out the meanings of the local variables of this level. */
1140 if (current_binding_level
->is_for_scope
&& flag_new_for_scope
== 1)
1142 struct binding_level
*outer
= current_binding_level
->level_chain
;
1143 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1145 if (TREE_CODE (link
) == VAR_DECL
)
1146 DECL_DEAD_FOR_LOCAL (link
) = 1;
1148 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link
)) = NULL_TREE
;
1151 /* Save declarations made in a 'for' statement so we can support pre-ANSI
1152 'for' scoping semantics. */
1154 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1156 tree id
= TREE_PURPOSE (link
);
1157 tree decl
= IDENTIFIER_LOCAL_VALUE (id
);
1159 if (decl
&& DECL_DEAD_FOR_LOCAL (decl
))
1161 /* In this case keep the dead for-decl visible,
1162 but remember what (if anything) it shadowed. */
1163 DECL_SHADOWED_FOR_VAR (decl
) = TREE_VALUE (link
);
1164 TREE_CHAIN (decl
) = outer
->dead_vars_from_for
;
1165 outer
->dead_vars_from_for
= decl
;
1168 IDENTIFIER_LOCAL_VALUE (id
) = TREE_VALUE (link
);
1171 else /* Not special for scope. */
1173 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1175 if (DECL_NAME (link
) != NULL_TREE
)
1177 /* If the ident. was used or addressed via a local extern decl,
1178 don't forget that fact. */
1179 if (DECL_EXTERNAL (link
))
1181 if (TREE_USED (link
))
1182 TREE_USED (DECL_ASSEMBLER_NAME (link
)) = 1;
1183 if (TREE_ADDRESSABLE (link
))
1184 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1186 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link
)) = NULL_TREE
;
1190 /* Restore all name-meanings of the outer levels
1191 that were shadowed by this level. */
1193 for (link
= current_binding_level
->shadowed
;
1194 link
; link
= TREE_CHAIN (link
))
1195 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1197 /* We first restore the regular decls and *then* the dead_vars_from_for
1198 to handle this case:
1202 for (int i; ; ) { ...} // i#2
1206 In this case, we want remove the binding for i#3, restoring
1207 that of i#2. Then we want to remove the binding for i#2,
1208 and restore that of i#1. */
1210 link
= current_binding_level
->dead_vars_from_for
;
1211 for (; link
!= NULL_TREE
; link
= TREE_CHAIN (link
))
1213 tree id
= DECL_NAME (link
);
1214 if (IDENTIFIER_LOCAL_VALUE (id
) == link
)
1215 IDENTIFIER_LOCAL_VALUE (id
) = DECL_SHADOWED_FOR_VAR (link
);
1218 for (link
= current_binding_level
->class_shadowed
;
1219 link
; link
= TREE_CHAIN (link
))
1220 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1221 for (link
= current_binding_level
->type_shadowed
;
1222 link
; link
= TREE_CHAIN (link
))
1223 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1226 /* If the level being exited is the top level of a function,
1227 check over all the labels. */
1231 /* If this is the top level block of a function,
1232 the vars are the function's parameters.
1233 Don't leave them in the BLOCK because they are
1234 found in the FUNCTION_DECL instead. */
1236 BLOCK_VARS (block
) = 0;
1238 /* Clear out the definitions of all label names,
1239 since their scopes end here. */
1241 for (link
= named_labels
; link
; link
= TREE_CHAIN (link
))
1243 register tree label
= TREE_VALUE (link
);
1245 if (DECL_INITIAL (label
) == NULL_TREE
)
1247 cp_error_at ("label `%D' used but not defined", label
);
1248 /* Avoid crashing later. */
1249 define_label (input_filename
, 1, DECL_NAME (label
));
1251 else if (warn_unused
&& !TREE_USED (label
))
1252 cp_warning_at ("label `%D' defined but not used", label
);
1253 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label
), NULL_TREE
);
1255 /* Put the labels into the "variables" of the
1256 top-level block, so debugger can see them. */
1257 TREE_CHAIN (label
) = BLOCK_VARS (block
);
1258 BLOCK_VARS (block
) = label
;
1261 named_labels
= NULL_TREE
;
1264 /* Any uses of undefined labels now operate under constraints
1265 of next binding contour. */
1267 struct binding_level
*level_chain
;
1268 level_chain
= current_binding_level
->level_chain
;
1271 struct named_label_list
*labels
;
1272 for (labels
= named_label_uses
; labels
; labels
= labels
->next
)
1273 if (labels
->binding_level
== current_binding_level
)
1275 labels
->binding_level
= level_chain
;
1276 labels
->names_in_scope
= level_chain
->names
;
1281 tmp
= current_binding_level
->keep
;
1283 pop_binding_level ();
1285 DECL_INITIAL (current_function_decl
) = block
;
1288 if (!block_previously_created
)
1289 current_binding_level
->blocks
1290 = chainon (current_binding_level
->blocks
, block
);
1292 /* If we did not make a block for the level just exited,
1293 any blocks made for inner levels
1294 (since they cannot be recorded as subblocks in that level)
1295 must be carried forward so they will later become subblocks
1296 of something else. */
1300 current_binding_level
->blocks
1301 = chainon (subblocks
, current_binding_level
->blocks
);
1303 current_binding_level
->blocks
1304 = chainon (current_binding_level
->blocks
, subblocks
);
1307 /* Take care of compiler's internal binding structures. */
1310 expand_end_bindings (getdecls (), keep
, 1);
1311 /* Each and every BLOCK node created here in `poplevel' is important
1312 (e.g. for proper debugging information) so if we created one
1313 earlier, mark it as "used". */
1315 TREE_USED (block
) = 1;
1316 block
= poplevel (keep
, reverse
, real_functionbody
);
1319 /* Each and every BLOCK node created here in `poplevel' is important
1320 (e.g. for proper debugging information) so if we created one
1321 earlier, mark it as "used". */
1323 TREE_USED (block
) = 1;
1327 /* Resume a binding level for a namespace. */
1331 struct binding_level
*b
;
1335 resume_binding_level (b
);
1337 /* Resume the variable caches. */
1338 decls
= current_binding_level
->names
;
1340 /* Restore the meanings of the local variables of this level. */
1342 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1344 /* If it doesn't have a name, there is nothing left to do with it. */
1345 if (DECL_NAME (link
) == NULL_TREE
)
1348 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link
)) = link
;
1350 /* If this is a TYPE_DECL, push it into the type value slot. */
1351 if (TREE_CODE (link
) == TYPE_DECL
)
1352 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link
), TREE_TYPE (link
));
1356 /* Delete the node BLOCK from the current binding level.
1357 This is used for the block inside a stmt expr ({...})
1358 so that the block can be reinserted where appropriate. */
1361 delete_block (block
)
1365 if (current_binding_level
->blocks
== block
)
1366 current_binding_level
->blocks
= TREE_CHAIN (block
);
1367 for (t
= current_binding_level
->blocks
; t
;)
1369 if (TREE_CHAIN (t
) == block
)
1370 TREE_CHAIN (t
) = TREE_CHAIN (block
);
1374 TREE_CHAIN (block
) = NULL_TREE
;
1375 /* Clear TREE_USED which is always set by poplevel.
1376 The flag is set again if insert_block is called. */
1377 TREE_USED (block
) = 0;
1380 /* Insert BLOCK at the end of the list of subblocks of the
1381 current binding level. This is used when a BIND_EXPR is expanded,
1382 to handle the BLOCK node inside the BIND_EXPR. */
1385 insert_block (block
)
1388 TREE_USED (block
) = 1;
1389 current_binding_level
->blocks
1390 = chainon (current_binding_level
->blocks
, block
);
1393 /* Add BLOCK to the current list of blocks for this binding contour. */
1396 add_block_current_level (block
)
1399 current_binding_level
->blocks
1400 = chainon (current_binding_level
->blocks
, block
);
1403 /* Set the BLOCK node for the innermost scope
1404 (the one we are currently in). */
1408 register tree block
;
1410 current_binding_level
->this_block
= block
;
1413 /* Do a pushlevel for class declarations. */
1418 register struct binding_level
*newlevel
;
1420 /* Reuse or create a struct for this binding level. */
1421 #if defined(DEBUG_CP_BINDING_LEVELS)
1423 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
1424 if (free_binding_level
)
1425 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
1427 newlevel
= free_binding_level
;
1428 free_binding_level
= free_binding_level
->level_chain
;
1432 newlevel
= make_binding_level ();
1435 #if defined(DEBUG_CP_BINDING_LEVELS)
1437 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1439 push_binding_level (newlevel
, 0, 0);
1441 decl_stack
= push_decl_level (decl_stack
, &decl_obstack
);
1442 class_binding_level
= current_binding_level
;
1443 class_binding_level
->parm_flag
= 2;
1444 /* We have just pushed into a new binding level. Now, fake out the rest
1445 of the compiler. Set the `current_binding_level' back to point to
1446 the most closely containing non-class binding level. */
1449 current_binding_level
= current_binding_level
->level_chain
;
1451 while (current_binding_level
->parm_flag
== 2);
1454 /* ...and a poplevel for class declarations. FORCE is used to force
1455 clearing out of CLASS_VALUEs after a class definition. */
1458 poplevel_class (force
)
1461 register struct binding_level
*level
= class_binding_level
;
1462 tree block
= NULL_TREE
;
1465 my_friendly_assert (level
!= 0, 354);
1467 decl_stack
= pop_stack_level (decl_stack
);
1468 for (shadowed
= level
->shadowed
; shadowed
; shadowed
= TREE_CHAIN (shadowed
))
1469 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed
)) = TREE_VALUE (shadowed
);
1470 /* If we're leaving a toplevel class, don't bother to do the setting
1471 of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot
1472 shouldn't even be used when current_class_type isn't set, and second,
1473 if we don't touch it here, we're able to use the cache effect if the
1474 next time we're entering a class scope, it is the same class. */
1475 if (current_class_depth
!= 1 || force
)
1476 for (shadowed
= level
->class_shadowed
;
1478 shadowed
= TREE_CHAIN (shadowed
))
1479 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed
)) = TREE_VALUE (shadowed
);
1481 /* Remember to save what IDENTIFIER's were bound in this scope so we
1482 can recover from cache misses. */
1484 previous_class_type
= current_class_type
;
1485 previous_class_values
= class_binding_level
->class_shadowed
;
1487 for (shadowed
= level
->type_shadowed
;
1489 shadowed
= TREE_CHAIN (shadowed
))
1490 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed
)) = TREE_VALUE (shadowed
);
1492 GNU_xref_end_scope ((HOST_WIDE_INT
) class_binding_level
,
1493 (HOST_WIDE_INT
) class_binding_level
->level_chain
,
1494 class_binding_level
->parm_flag
,
1495 class_binding_level
->keep
);
1497 if (class_binding_level
->parm_flag
!= 2)
1498 class_binding_level
= (struct binding_level
*)0;
1500 /* Now, pop out of the the binding level which we created up in the
1501 `pushlevel_class' routine. */
1502 #if defined(DEBUG_CP_BINDING_LEVELS)
1504 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1506 pop_binding_level ();
1511 /* For debugging. */
1512 static int no_print_functions
= 0;
1513 static int no_print_builtins
= 0;
1516 print_binding_level (lvl
)
1517 struct binding_level
*lvl
;
1521 fprintf (stderr
, " blocks=");
1522 fprintf (stderr
, HOST_PTR_PRINTF
, lvl
->blocks
);
1523 fprintf (stderr
, " n_incomplete=%d parm_flag=%d keep=%d",
1524 list_length (lvl
->incomplete
), lvl
->parm_flag
, lvl
->keep
);
1525 if (lvl
->tag_transparent
)
1526 fprintf (stderr
, " tag-transparent");
1527 if (lvl
->more_cleanups_ok
)
1528 fprintf (stderr
, " more-cleanups-ok");
1529 if (lvl
->have_cleanups
)
1530 fprintf (stderr
, " have-cleanups");
1531 fprintf (stderr
, "\n");
1534 fprintf (stderr
, " names:\t");
1535 /* We can probably fit 3 names to a line? */
1536 for (t
= lvl
->names
; t
; t
= TREE_CHAIN (t
))
1538 if (no_print_functions
&& (TREE_CODE (t
) == FUNCTION_DECL
))
1540 if (no_print_builtins
1541 && (TREE_CODE (t
) == TYPE_DECL
)
1542 && (!strcmp (DECL_SOURCE_FILE (t
),"<built-in>")))
1545 /* Function decls tend to have longer names. */
1546 if (TREE_CODE (t
) == FUNCTION_DECL
)
1553 fprintf (stderr
, "\n\t");
1556 print_node_brief (stderr
, "", t
, 0);
1557 if (t
== error_mark_node
)
1561 fprintf (stderr
, "\n");
1565 fprintf (stderr
, " tags:\t");
1567 for (t
= lvl
->tags
; t
; t
= TREE_CHAIN (t
))
1569 if (TREE_PURPOSE (t
) == NULL_TREE
)
1571 else if (TREE_PURPOSE (t
) == TYPE_IDENTIFIER (TREE_VALUE (t
)))
1578 fprintf (stderr
, "\n\t");
1581 if (TREE_PURPOSE (t
) == NULL_TREE
)
1583 print_node_brief (stderr
, "<unnamed-typedef", TREE_VALUE (t
), 0);
1584 fprintf (stderr
, ">");
1586 else if (TREE_PURPOSE (t
) == TYPE_IDENTIFIER (TREE_VALUE (t
)))
1587 print_node_brief (stderr
, "", TREE_VALUE (t
), 0);
1590 print_node_brief (stderr
, "<typedef", TREE_PURPOSE (t
), 0);
1591 print_node_brief (stderr
, "", TREE_VALUE (t
), 0);
1592 fprintf (stderr
, ">");
1596 fprintf (stderr
, "\n");
1600 fprintf (stderr
, " shadowed:");
1601 for (t
= lvl
->shadowed
; t
; t
= TREE_CHAIN (t
))
1603 fprintf (stderr
, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
1605 fprintf (stderr
, "\n");
1607 if (lvl
->class_shadowed
)
1609 fprintf (stderr
, " class-shadowed:");
1610 for (t
= lvl
->class_shadowed
; t
; t
= TREE_CHAIN (t
))
1612 fprintf (stderr
, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
1614 fprintf (stderr
, "\n");
1616 if (lvl
->type_shadowed
)
1618 fprintf (stderr
, " type-shadowed:");
1619 for (t
= lvl
->type_shadowed
; t
; t
= TREE_CHAIN (t
))
1621 fprintf (stderr
, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
1623 fprintf (stderr
, "\n");
1628 print_other_binding_stack (stack
)
1629 struct binding_level
*stack
;
1631 struct binding_level
*level
;
1632 for (level
= stack
; level
!= global_binding_level
; level
= level
->level_chain
)
1634 fprintf (stderr
, "binding level ");
1635 fprintf (stderr
, HOST_PTR_PRINTF
, level
);
1636 fprintf (stderr
, "\n");
1637 print_binding_level (level
);
1642 print_binding_stack ()
1644 struct binding_level
*b
;
1645 fprintf (stderr
, "current_binding_level=");
1646 fprintf (stderr
, HOST_PTR_PRINTF
, current_binding_level
);
1647 fprintf (stderr
, "\nclass_binding_level=");
1648 fprintf (stderr
, HOST_PTR_PRINTF
, class_binding_level
);
1649 fprintf (stderr
, "\nglobal_binding_level=");
1650 fprintf (stderr
, HOST_PTR_PRINTF
, global_binding_level
);
1651 fprintf (stderr
, "\n");
1652 if (class_binding_level
)
1654 for (b
= class_binding_level
; b
; b
= b
->level_chain
)
1655 if (b
== current_binding_level
)
1658 b
= class_binding_level
;
1660 b
= current_binding_level
;
1663 b
= current_binding_level
;
1664 print_other_binding_stack (b
);
1665 fprintf (stderr
, "global:\n");
1666 print_binding_level (global_binding_level
);
1669 extern char * first_global_object_name
;
1671 /* Get a unique name for each call to this routine for unnamed namespaces.
1672 Mostly copied from get_file_function_name. */
1677 static int temp_name_counter
= 0;
1681 if (first_global_object_name
)
1682 p
= first_global_object_name
;
1683 else if (main_input_filename
)
1684 p
= main_input_filename
;
1688 #define UNNAMED_NAMESPACE_FORMAT "__%s_%d"
1690 buf
= (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT
) + strlen (p
));
1692 sprintf (buf
, UNNAMED_NAMESPACE_FORMAT
, p
, temp_name_counter
++);
1694 /* Don't need to pull weird characters out of global names. */
1695 if (p
!= first_global_object_name
)
1697 for (p
= buf
+11; *p
; p
++)
1698 if (! ((*p
>= '0' && *p
<= '9')
1699 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
1702 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
1705 || (*p
>= 'A' && *p
<= 'Z')
1706 || (*p
>= 'a' && *p
<= 'z')))
1710 return get_identifier (buf
);
1713 /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we
1714 select a name that is unique to this compilation unit. */
1717 push_namespace (name
)
1723 sorry ("namespace");
1727 extern tree current_namespace
;
1728 tree old_id
= get_namespace_id ();
1734 /* Create a truly ugly name! */
1735 name
= get_unique_name ();
1738 d
= build_lang_decl (NAMESPACE_DECL
, name
, void_type_node
);
1740 /* Mark them as external, so redeclaration_error_message doesn't think
1741 they are duplicates. */
1743 DECL_EXTERNAL (d
) = 1;
1746 if (NAMESPACE_LEVEL (d
) == 0)
1748 /* This is new for this compilation unit. */
1750 declare_namespace_level ();
1751 NAMESPACE_LEVEL (d
) = current_binding_level
;
1754 resume_level (NAMESPACE_LEVEL (d
));
1756 /* This code is just is bit old now... */
1757 current_namespace
= tree_cons (NULL_TREE
, name
, current_namespace
);
1758 buf
= (char *) alloca (4 + (old_id
? IDENTIFIER_LENGTH (old_id
) : 0)
1759 + IDENTIFIER_LENGTH (name
));
1760 sprintf (buf
, "%s%s", old_id
? IDENTIFIER_POINTER (old_id
) : "",
1761 IDENTIFIER_POINTER (name
));
1762 TREE_PURPOSE (current_namespace
) = get_identifier (buf
);
1766 /* Pop from the scope of the current namespace. */
1772 extern tree current_namespace
;
1774 current_namespace
= TREE_CHAIN (current_namespace
);
1776 /* Just in case we get out of sync. */
1777 if (! namespace_bindings_p ())
1780 decls
= current_binding_level
->names
;
1782 /* Clear out the meanings of the local variables of this level. */
1784 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
1786 if (DECL_NAME (link
) != NULL_TREE
)
1788 /* If the ident. was used or addressed via a local extern decl,
1789 don't forget that fact. */
1790 if (DECL_EXTERNAL (link
))
1792 if (TREE_USED (link
))
1793 TREE_USED (DECL_ASSEMBLER_NAME (link
)) = 1;
1794 if (TREE_ADDRESSABLE (link
))
1795 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
1797 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link
)) = NULL_TREE
;
1801 /* Restore all name-meanings of the outer levels
1802 that were shadowed by this level. */
1804 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
1805 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1806 for (link
= current_binding_level
->class_shadowed
;
1807 link
; link
= TREE_CHAIN (link
))
1808 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1809 for (link
= current_binding_level
->type_shadowed
;
1810 link
; link
= TREE_CHAIN (link
))
1811 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
1813 /* suspend a level. */
1814 suspend_binding_level ();
1818 /* Subroutines for reverting temporarily to top-level for instantiation
1819 of templates and such. We actually need to clear out the class- and
1820 local-value slots of all identifiers, so that only the global values
1821 are at all visible. Simply setting current_binding_level to the global
1822 scope isn't enough, because more binding levels may be pushed. */
1823 struct saved_scope
{
1824 struct binding_level
*old_binding_level
;
1826 struct saved_scope
*prev
;
1827 tree class_name
, class_type
, function_decl
;
1828 struct binding_level
*class_bindings
;
1829 tree
*lang_base
, *lang_stack
, lang_name
;
1831 int minimal_parse_mode
;
1832 tree last_function_parms
;
1833 tree template_parms
;
1834 HOST_WIDE_INT processing_template_decl
;
1835 tree previous_class_type
, previous_class_values
;
1837 static struct saved_scope
*current_saved_scope
;
1840 store_bindings (names
, old_bindings
)
1841 tree names
, old_bindings
;
1844 for (t
= names
; t
; t
= TREE_CHAIN (t
))
1846 tree binding
, t1
, id
;
1848 if (TREE_CODE (t
) == TREE_LIST
)
1849 id
= TREE_PURPOSE (t
);
1854 || (!IDENTIFIER_LOCAL_VALUE (id
)
1855 && !IDENTIFIER_CLASS_VALUE (id
)))
1858 for (t1
= old_bindings
; t1
; t1
= TREE_CHAIN (t1
))
1859 if (TREE_VEC_ELT (t1
, 0) == id
)
1862 binding
= make_tree_vec (4);
1865 my_friendly_assert (TREE_CODE (id
) == IDENTIFIER_NODE
, 135);
1866 TREE_VEC_ELT (binding
, 0) = id
;
1867 TREE_VEC_ELT (binding
, 1) = IDENTIFIER_TYPE_VALUE (id
);
1868 TREE_VEC_ELT (binding
, 2) = IDENTIFIER_LOCAL_VALUE (id
);
1869 TREE_VEC_ELT (binding
, 3) = IDENTIFIER_CLASS_VALUE (id
);
1870 IDENTIFIER_LOCAL_VALUE (id
) = NULL_TREE
;
1871 IDENTIFIER_CLASS_VALUE (id
) = NULL_TREE
;
1873 TREE_CHAIN (binding
) = old_bindings
;
1874 old_bindings
= binding
;
1878 return old_bindings
;
1882 maybe_push_to_top_level (pseudo
)
1885 extern int current_lang_stacksize
;
1886 struct saved_scope
*s
1887 = (struct saved_scope
*) xmalloc (sizeof (struct saved_scope
));
1888 struct binding_level
*b
= inner_binding_level
;
1889 tree old_bindings
= NULL_TREE
;
1891 if (current_function_decl
)
1892 push_cp_function_context (NULL_TREE
);
1894 if (previous_class_type
)
1895 old_bindings
= store_bindings (previous_class_values
, old_bindings
);
1897 /* Have to include global_binding_level, because class-level decls
1898 aren't listed anywhere useful. */
1899 for (; b
; b
= b
->level_chain
)
1903 if (b
== global_binding_level
|| (pseudo
&& b
->pseudo_global
))
1906 old_bindings
= store_bindings (b
->names
, old_bindings
);
1907 /* We also need to check class_shadowed to save class-level type
1908 bindings, since pushclass doesn't fill in b->names. */
1909 if (b
->parm_flag
== 2)
1910 old_bindings
= store_bindings (b
->class_shadowed
, old_bindings
);
1912 /* Unwind type-value slots back to top level. */
1913 for (t
= b
->type_shadowed
; t
; t
= TREE_CHAIN (t
))
1914 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t
), TREE_VALUE (t
));
1917 s
->old_binding_level
= current_binding_level
;
1918 current_binding_level
= b
;
1920 s
->class_name
= current_class_name
;
1921 s
->class_type
= current_class_type
;
1922 s
->function_decl
= current_function_decl
;
1923 s
->class_bindings
= class_binding_level
;
1924 s
->lang_stack
= current_lang_stack
;
1925 s
->lang_base
= current_lang_base
;
1926 s
->lang_stacksize
= current_lang_stacksize
;
1927 s
->lang_name
= current_lang_name
;
1928 s
->minimal_parse_mode
= minimal_parse_mode
;
1929 s
->last_function_parms
= last_function_parms
;
1930 s
->template_parms
= current_template_parms
;
1931 s
->processing_template_decl
= processing_template_decl
;
1932 s
->previous_class_type
= previous_class_type
;
1933 s
->previous_class_values
= previous_class_values
;
1935 current_class_name
= current_class_type
= NULL_TREE
;
1936 current_function_decl
= NULL_TREE
;
1937 class_binding_level
= (struct binding_level
*)0;
1938 current_lang_stacksize
= 10;
1939 current_lang_stack
= current_lang_base
1940 = (tree
*) xmalloc (current_lang_stacksize
* sizeof (tree
));
1941 current_lang_name
= lang_name_cplusplus
;
1942 strict_prototype
= strict_prototypes_lang_cplusplus
;
1943 named_labels
= NULL_TREE
;
1944 minimal_parse_mode
= 0;
1945 previous_class_type
= previous_class_values
= NULL_TREE
;
1948 current_template_parms
= NULL_TREE
;
1949 processing_template_decl
= 0;
1952 s
->prev
= current_saved_scope
;
1953 s
->old_bindings
= old_bindings
;
1954 current_saved_scope
= s
;
1956 push_obstacks (&permanent_obstack
, &permanent_obstack
);
1960 push_to_top_level ()
1962 maybe_push_to_top_level (0);
1966 pop_from_top_level ()
1968 extern int current_lang_stacksize
;
1969 struct saved_scope
*s
= current_saved_scope
;
1972 /* Clear out class-level bindings cache. */
1973 if (previous_class_type
)
1976 previous_class_type
= NULL_TREE
;
1981 current_binding_level
= s
->old_binding_level
;
1982 current_saved_scope
= s
->prev
;
1983 for (t
= s
->old_bindings
; t
; t
= TREE_CHAIN (t
))
1985 tree id
= TREE_VEC_ELT (t
, 0);
1988 IDENTIFIER_TYPE_VALUE (id
) = TREE_VEC_ELT (t
, 1);
1989 IDENTIFIER_LOCAL_VALUE (id
) = TREE_VEC_ELT (t
, 2);
1990 IDENTIFIER_CLASS_VALUE (id
) = TREE_VEC_ELT (t
, 3);
1993 current_class_name
= s
->class_name
;
1994 current_class_type
= s
->class_type
;
1995 current_function_decl
= s
->function_decl
;
1996 class_binding_level
= s
->class_bindings
;
1997 free (current_lang_base
);
1998 current_lang_base
= s
->lang_base
;
1999 current_lang_stack
= s
->lang_stack
;
2000 current_lang_name
= s
->lang_name
;
2001 current_lang_stacksize
= s
->lang_stacksize
;
2002 if (current_lang_name
== lang_name_cplusplus
)
2003 strict_prototype
= strict_prototypes_lang_cplusplus
;
2004 else if (current_lang_name
== lang_name_c
)
2005 strict_prototype
= strict_prototypes_lang_c
;
2006 minimal_parse_mode
= s
->minimal_parse_mode
;
2007 last_function_parms
= s
->last_function_parms
;
2008 current_template_parms
= s
->template_parms
;
2009 processing_template_decl
= s
->processing_template_decl
;
2010 previous_class_type
= s
->previous_class_type
;
2011 previous_class_values
= s
->previous_class_values
;
2015 if (current_function_decl
)
2016 pop_cp_function_context (NULL_TREE
);
2019 /* Push a definition of struct, union or enum tag "name".
2020 into binding_level "b". "type" should be the type node,
2021 We assume that the tag "name" is not already defined.
2023 Note that the definition may really be just a forward reference.
2024 In that case, the TYPE_SIZE will be a NULL_TREE.
2026 C++ gratuitously puts all these tags in the name space. */
2028 /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
2029 record the shadowed value for this binding contour. TYPE is
2030 the type that ID maps to. */
2033 set_identifier_type_value_with_scope (id
, type
, b
)
2036 struct binding_level
*b
;
2038 if (b
!= global_binding_level
)
2040 tree old_type_value
= IDENTIFIER_TYPE_VALUE (id
);
2042 = tree_cons (id
, old_type_value
, b
->type_shadowed
);
2044 SET_IDENTIFIER_TYPE_VALUE (id
, type
);
2047 /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
2050 set_identifier_type_value (id
, type
)
2054 set_identifier_type_value_with_scope (id
, type
, inner_binding_level
);
2057 /* Pop off extraneous binding levels left over due to syntax errors.
2059 We don't pop past namespaces, as they might be valid. */
2064 #ifdef DEBUG_CP_BINDING_LEVELS
2065 fprintf (stderr
, "XXX entering pop_everything ()\n");
2067 while (! toplevel_bindings_p () && ! pseudo_global_level_p ())
2069 if (class_binding_level
)
2070 pop_nested_class (1);
2074 #ifdef DEBUG_CP_BINDING_LEVELS
2075 fprintf (stderr
, "XXX leaving pop_everything ()\n");
2079 /* Push a tag name NAME for struct/class/union/enum type TYPE.
2080 Normally put into into the inner-most non-tag-transparent scope,
2081 but if GLOBALIZE is true, put it in the inner-most non-class scope.
2082 The latter is needed for implicit declarations. */
2085 pushtag (name
, type
, globalize
)
2089 register struct binding_level
*b
;
2093 b
= inner_binding_level
;
2094 while (b
->tag_transparent
2095 || (globalize
&& b
->parm_flag
== 2))
2098 if (toplevel_bindings_p ())
2099 b
->tags
= perm_tree_cons (name
, type
, b
->tags
);
2101 b
->tags
= saveable_tree_cons (name
, type
, b
->tags
);
2105 context
= type
? TYPE_CONTEXT (type
) : NULL_TREE
;
2106 if (! context
&& ! globalize
)
2107 context
= current_scope ();
2109 c_decl
= TREE_CODE (context
) == FUNCTION_DECL
2110 ? context
: TYPE_MAIN_DECL (context
);
2112 /* Do C++ gratuitous typedefing. */
2113 if (IDENTIFIER_TYPE_VALUE (name
) != type
)
2118 if (b
->parm_flag
!= 2
2119 || TYPE_SIZE (current_class_type
) != NULL_TREE
)
2121 d
= lookup_nested_type (type
, c_decl
);
2126 d
= build_decl (TYPE_DECL
, name
, type
);
2127 SET_DECL_ARTIFICIAL (d
);
2128 set_identifier_type_value_with_scope (name
, type
, b
);
2131 d
= TYPE_MAIN_DECL (d
);
2133 TYPE_NAME (type
) = d
;
2134 DECL_CONTEXT (d
) = context
;
2135 if (! globalize
&& processing_template_decl
&& IS_AGGR_TYPE (type
))
2136 push_template_decl (d
);
2138 if (b
->parm_flag
== 2)
2139 d
= pushdecl_class_level (d
);
2141 d
= pushdecl_with_scope (d
, b
);
2145 /* Make nested declarations go into class-level scope. */
2147 d
= build_decl (TYPE_DECL
, name
, type
);
2148 SET_DECL_ARTIFICIAL (d
);
2149 TYPE_NAME (type
) = d
;
2150 DECL_CONTEXT (d
) = context
;
2151 if (! globalize
&& processing_template_decl
&& IS_AGGR_TYPE (type
))
2152 push_template_decl (d
);
2154 d
= pushdecl_class_level (d
);
2158 if (ANON_AGGRNAME_P (name
))
2159 DECL_IGNORED_P (d
) = 1;
2161 TYPE_CONTEXT (type
) = DECL_CONTEXT (d
);
2162 DECL_ASSEMBLER_NAME (d
)
2163 = get_identifier (build_overload_name (type
, 1, 1));
2166 if (b
->parm_flag
== 2)
2168 TREE_NONLOCAL_FLAG (type
) = 1;
2169 if (TYPE_SIZE (current_class_type
) == NULL_TREE
)
2170 CLASSTYPE_TAGS (current_class_type
) = b
->tags
;
2174 if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
)
2175 /* Use the canonical TYPE_DECL for this node. */
2176 TYPE_STUB_DECL (type
) = TYPE_NAME (type
);
2179 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
2180 will be the tagged type we just added to the current
2181 binding level. This fake NULL-named TYPE_DECL node helps
2182 dwarfout.c to know when it needs to output a
2183 representation of a tagged type, and it also gives us a
2184 convenient place to record the "scope start" address for
2187 tree d
= build_decl (TYPE_DECL
, NULL_TREE
, type
);
2188 TYPE_STUB_DECL (type
) = pushdecl_with_scope (d
, b
);
2192 /* Counter used to create anonymous type names. */
2194 static int anon_cnt
= 0;
2196 /* Return an IDENTIFIER which can be used as a name for
2197 anonymous structs and unions. */
2204 sprintf (buf
, ANON_AGGRNAME_FORMAT
, anon_cnt
++);
2205 return get_identifier (buf
);
2208 /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
2209 This keeps dbxout from getting confused. */
2214 register struct binding_level
*b
;
2216 static int last_cnt
= 0;
2218 /* Fast out if no new anon names were declared. */
2219 if (last_cnt
== anon_cnt
)
2222 b
= current_binding_level
;
2223 while (b
->tag_transparent
)
2228 /* A NULL purpose means we have already processed all tags
2229 from here to the end of the list. */
2230 if (TREE_PURPOSE (tags
) == NULL_TREE
)
2232 if (ANON_AGGRNAME_P (TREE_PURPOSE (tags
)))
2233 TREE_PURPOSE (tags
) = NULL_TREE
;
2234 tags
= TREE_CHAIN (tags
);
2236 last_cnt
= anon_cnt
;
2239 /* Subroutine of duplicate_decls: return truthvalue of whether
2240 or not types of these decls match.
2242 For C++, we must compare the parameter list so that `int' can match
2243 `int&' in a parameter position, but `int&' is not confused with
2247 decls_match (newdecl
, olddecl
)
2248 tree newdecl
, olddecl
;
2252 if (TREE_CODE (newdecl
) == FUNCTION_DECL
2253 && TREE_CODE (olddecl
) == FUNCTION_DECL
)
2255 tree f1
= TREE_TYPE (newdecl
);
2256 tree f2
= TREE_TYPE (olddecl
);
2257 tree p1
= TYPE_ARG_TYPES (f1
);
2258 tree p2
= TYPE_ARG_TYPES (f2
);
2260 /* When we parse a static member function definition,
2261 we put together a FUNCTION_DECL which thinks its type
2262 is METHOD_TYPE. Change that to FUNCTION_TYPE, and
2264 if (TREE_CODE (f1
) == METHOD_TYPE
&& DECL_STATIC_FUNCTION_P (olddecl
))
2265 revert_static_member_fn (&newdecl
, &f1
, &p1
);
2266 else if (TREE_CODE (f2
) == METHOD_TYPE
2267 && DECL_STATIC_FUNCTION_P (newdecl
))
2268 revert_static_member_fn (&olddecl
, &f2
, &p2
);
2270 /* Here we must take care of the case where new default
2271 parameters are specified. Also, warn if an old
2272 declaration becomes ambiguous because default
2273 parameters may cause the two to be ambiguous. */
2274 if (TREE_CODE (f1
) != TREE_CODE (f2
))
2276 if (TREE_CODE (f1
) == OFFSET_TYPE
)
2277 cp_compiler_error ("`%D' redeclared as member function", newdecl
);
2279 cp_compiler_error ("`%D' redeclared as non-member function", newdecl
);
2283 if (comptypes (TREE_TYPE (f1
), TREE_TYPE (f2
), 1))
2285 if (! strict_prototypes_lang_c
&& DECL_LANGUAGE (olddecl
) == lang_c
2288 types_match
= self_promoting_args_p (p1
);
2289 if (p1
== void_list_node
)
2290 TREE_TYPE (newdecl
) = TREE_TYPE (olddecl
);
2292 else if (!strict_prototypes_lang_c
&& DECL_LANGUAGE (olddecl
)==lang_c
2293 && DECL_LANGUAGE (newdecl
) == lang_c
&& p1
== NULL_TREE
)
2295 types_match
= self_promoting_args_p (p2
);
2296 TREE_TYPE (newdecl
) = TREE_TYPE (olddecl
);
2299 types_match
= compparms (p1
, p2
, 3);
2304 else if (TREE_CODE (newdecl
) == TEMPLATE_DECL
2305 && TREE_CODE (olddecl
) == TEMPLATE_DECL
)
2307 tree newargs
= DECL_TEMPLATE_PARMS (newdecl
);
2308 tree oldargs
= DECL_TEMPLATE_PARMS (olddecl
);
2311 /* Run through all the levels of template parmaters, checking
2313 while (newargs
&& oldargs
)
2315 int len
= TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS (newargs
));
2317 if (TREE_VEC_LENGTH (INNERMOST_TEMPLATE_PARMS (oldargs
)) != len
)
2320 for (i
= 0; i
< len
; i
++)
2323 TREE_VALUE (TREE_VEC_ELT
2324 (INNERMOST_TEMPLATE_PARMS (newargs
), i
));
2326 TREE_VALUE (TREE_VEC_ELT
2327 (INNERMOST_TEMPLATE_PARMS (oldargs
), i
));
2328 if (TREE_CODE (newarg
) != TREE_CODE (oldarg
))
2330 else if (TREE_CODE (newarg
) == TYPE_DECL
)
2332 else if (! comptypes (TREE_TYPE (newarg
), TREE_TYPE (oldarg
), 1))
2335 newargs
= TREE_CHAIN (newargs
);
2336 oldargs
= TREE_CHAIN (oldargs
);
2339 if ((newargs
== NULL_TREE
) != (oldargs
== NULL_TREE
))
2340 /* One declaration has more levels that the other. */
2343 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl
)) == TYPE_DECL
)
2346 types_match
= decls_match (DECL_TEMPLATE_RESULT (olddecl
),
2347 DECL_TEMPLATE_RESULT (newdecl
));
2351 if (TREE_TYPE (newdecl
) == error_mark_node
)
2352 types_match
= TREE_TYPE (olddecl
) == error_mark_node
;
2353 else if (TREE_TYPE (olddecl
) == NULL_TREE
)
2354 types_match
= TREE_TYPE (newdecl
) == NULL_TREE
;
2355 else if (TREE_TYPE (newdecl
) == NULL_TREE
)
2357 /* Qualifiers must match, and they may be present on either, the type
2359 else if ((TREE_READONLY (newdecl
)
2360 || TYPE_READONLY (TREE_TYPE (newdecl
)))
2361 == (TREE_READONLY (olddecl
)
2362 || TYPE_READONLY (TREE_TYPE (olddecl
)))
2363 && (TREE_THIS_VOLATILE (newdecl
)
2364 || TYPE_VOLATILE (TREE_TYPE (newdecl
)))
2365 == (TREE_THIS_VOLATILE (olddecl
)
2366 || TYPE_VOLATILE (TREE_TYPE (olddecl
))))
2367 types_match
= comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (newdecl
)),
2368 TYPE_MAIN_VARIANT (TREE_TYPE (olddecl
)), 1);
2376 /* If NEWDECL is `static' and an `extern' was seen previously,
2377 warn about it. (OLDDECL may be NULL_TREE; NAME contains
2378 information about previous usage as an `extern'.)
2380 Note that this does not apply to the C++ case of declaring
2381 a variable `extern const' and then later `const'.
2383 Don't complain about built-in functions, since they are beyond
2384 the user's control. */
2387 warn_extern_redeclared_static (newdecl
, olddecl
)
2388 tree newdecl
, olddecl
;
2392 static char *explicit_extern_static_warning
2393 = "`%D' was declared `extern' and later `static'";
2394 static char *implicit_extern_static_warning
2395 = "`%D' was declared implicitly `extern' and later `static'";
2397 if (TREE_CODE (newdecl
) == TYPE_DECL
)
2400 name
= DECL_ASSEMBLER_NAME (newdecl
);
2401 if (TREE_PUBLIC (name
) && DECL_THIS_STATIC (newdecl
))
2403 /* It's okay to redeclare an ANSI built-in function as static,
2404 or to declare a non-ANSI built-in function as anything. */
2405 if (! (TREE_CODE (newdecl
) == FUNCTION_DECL
2406 && olddecl
!= NULL_TREE
2407 && TREE_CODE (olddecl
) == FUNCTION_DECL
2408 && (DECL_BUILT_IN (olddecl
)
2409 || DECL_BUILT_IN_NONANSI (olddecl
))))
2411 cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name
)
2412 ? implicit_extern_static_warning
2413 : explicit_extern_static_warning
, newdecl
);
2414 if (olddecl
!= NULL_TREE
)
2415 cp_pedwarn_at ("previous declaration of `%D'", olddecl
);
2420 /* Handle when a new declaration NEWDECL has the same name as an old
2421 one OLDDECL in the same binding contour. Prints an error message
2424 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
2425 Otherwise, return 0. */
2428 duplicate_decls (newdecl
, olddecl
)
2429 tree newdecl
, olddecl
;
2431 extern struct obstack permanent_obstack
;
2432 unsigned olddecl_uid
= DECL_UID (olddecl
);
2433 int olddecl_friend
= 0, types_match
= 0;
2434 int new_defines_function
;
2436 if (newdecl
== olddecl
)
2439 if (TREE_CODE_CLASS (TREE_CODE (olddecl
)) == 'd')
2440 DECL_MACHINE_ATTRIBUTES (newdecl
) = DECL_MACHINE_ATTRIBUTES (olddecl
);
2442 types_match
= decls_match (newdecl
, olddecl
);
2444 if (TREE_CODE (olddecl
) != TREE_LIST
)
2445 olddecl_friend
= DECL_LANG_SPECIFIC (olddecl
) && DECL_FRIEND_P (olddecl
);
2447 /* If either the type of the new decl or the type of the old decl is an
2448 error_mark_node, then that implies that we have already issued an
2449 error (earlier) for some bogus type specification, and in that case,
2450 it is rather pointless to harass the user with yet more error message
2451 about the same declaration, so well just pretent the types match here. */
2452 if (TREE_TYPE (newdecl
) == error_mark_node
2453 || TREE_TYPE (olddecl
) == error_mark_node
)
2456 if (TREE_CODE (olddecl
) == FUNCTION_DECL
2457 && DECL_ARTIFICIAL (olddecl
)
2458 && (DECL_BUILT_IN (olddecl
) || DECL_BUILT_IN_NONANSI (olddecl
)))
2460 /* If you declare a built-in or predefined function name as static,
2461 the old definition is overridden, but optionally warn this was a
2462 bad choice of name. Ditto for overloads. */
2463 if (! DECL_PUBLIC (newdecl
)
2464 || (TREE_CODE (newdecl
) == FUNCTION_DECL
2465 && DECL_LANGUAGE (newdecl
) != DECL_LANGUAGE (olddecl
)))
2468 cp_warning ("shadowing %s function `%#D'",
2469 DECL_BUILT_IN (olddecl
) ? "built-in" : "library",
2471 /* Discard the old built-in function. */
2474 else if (! types_match
)
2476 if (TREE_CODE (newdecl
) != FUNCTION_DECL
)
2478 /* If the built-in is not ansi, then programs can override
2479 it even globally without an error. */
2480 if (! DECL_BUILT_IN (olddecl
))
2481 cp_warning ("library function `%#D' redeclared as non-function `%#D'",
2485 cp_error ("declaration of `%#D'", newdecl
);
2486 cp_error ("conflicts with built-in declaration `%#D'",
2492 cp_warning ("declaration of `%#D'", newdecl
);
2493 cp_warning ("conflicts with built-in declaration `%#D'",
2497 else if (TREE_CODE (olddecl
) != TREE_CODE (newdecl
))
2499 if ((TREE_CODE (newdecl
) == FUNCTION_DECL
2500 && DECL_FUNCTION_TEMPLATE_P (olddecl
))
2501 || (TREE_CODE (olddecl
) == FUNCTION_DECL
2502 && DECL_FUNCTION_TEMPLATE_P (newdecl
)))
2505 cp_error ("`%#D' redeclared as different kind of symbol", newdecl
);
2506 if (TREE_CODE (olddecl
) == TREE_LIST
)
2507 olddecl
= TREE_VALUE (olddecl
);
2508 cp_error_at ("previous declaration of `%#D'", olddecl
);
2510 /* New decl is completely inconsistent with the old one =>
2511 tell caller to replace the old one. */
2515 else if (!types_match
)
2517 if (TREE_CODE (newdecl
) == TEMPLATE_DECL
)
2519 /* The name of a class template may not be declared to refer to
2520 any other template, class, function, object, namespace, value,
2521 or type in the same scope. */
2522 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl
)) == TYPE_DECL
2523 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl
)) == TYPE_DECL
)
2525 cp_error ("declaration of template `%#D'", newdecl
);
2526 cp_error_at ("conflicts with previous declaration `%#D'",
2529 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl
)) == FUNCTION_DECL
2530 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl
)) == FUNCTION_DECL
2531 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl
))),
2532 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl
))), 3))
2534 cp_error ("new declaration `%#D'", newdecl
);
2535 cp_error_at ("ambiguates old declaration `%#D'", olddecl
);
2539 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
2541 if (DECL_LANGUAGE (newdecl
) == lang_c
2542 && DECL_LANGUAGE (olddecl
) == lang_c
)
2544 cp_error ("declaration of C function `%#D' conflicts with",
2546 cp_error_at ("previous declaration `%#D' here", olddecl
);
2548 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl
)),
2549 TYPE_ARG_TYPES (TREE_TYPE (olddecl
)), 3))
2551 cp_error ("new declaration `%#D'", newdecl
);
2552 cp_error_at ("ambiguates old declaration `%#D'", olddecl
);
2558 /* Already complained about this, so don't do so again. */
2559 else if (current_class_type
== NULL_TREE
2560 || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl
)) != current_class_type
)
2562 cp_error ("conflicting types for `%#D'", newdecl
);
2563 cp_error_at ("previous declaration as `%#D'", olddecl
);
2568 char *errmsg
= redeclaration_error_message (newdecl
, olddecl
);
2571 cp_error (errmsg
, newdecl
);
2572 if (DECL_NAME (olddecl
) != NULL_TREE
)
2573 cp_error_at ((DECL_INITIAL (olddecl
)
2574 && current_binding_level
== global_binding_level
)
2575 ? "`%#D' previously defined here"
2576 : "`%#D' previously declared here", olddecl
);
2578 else if (TREE_CODE (olddecl
) == FUNCTION_DECL
2579 && DECL_INITIAL (olddecl
) != NULL_TREE
2580 && TYPE_ARG_TYPES (TREE_TYPE (olddecl
)) == NULL_TREE
2581 && TYPE_ARG_TYPES (TREE_TYPE (newdecl
)) != NULL_TREE
)
2583 /* Prototype decl follows defn w/o prototype. */
2584 cp_warning_at ("prototype for `%#D'", newdecl
);
2585 cp_warning_at ("follows non-prototype definition here", olddecl
);
2587 else if (TREE_CODE (olddecl
) == FUNCTION_DECL
2588 && DECL_LANGUAGE (newdecl
) != DECL_LANGUAGE (olddecl
))
2590 /* extern "C" int foo ();
2591 int foo () { bar (); }
2593 if (current_lang_stack
== current_lang_base
)
2594 DECL_LANGUAGE (newdecl
) = DECL_LANGUAGE (olddecl
);
2597 cp_error_at ("previous declaration of `%#D' with %L linkage",
2598 olddecl
, DECL_LANGUAGE (olddecl
));
2599 cp_error ("conflicts with new declaration with %L linkage",
2600 DECL_LANGUAGE (newdecl
));
2604 if (TREE_CODE (olddecl
) == FUNCTION_DECL
2605 && ! DECL_USE_TEMPLATE (olddecl
))
2607 tree t1
= TYPE_ARG_TYPES (TREE_TYPE (olddecl
));
2608 tree t2
= TYPE_ARG_TYPES (TREE_TYPE (newdecl
));
2611 if (TREE_CODE (TREE_TYPE (newdecl
)) == METHOD_TYPE
)
2612 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
);
2614 for (; t1
&& t1
!= void_list_node
;
2615 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
), i
++)
2616 if (TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
2618 if (1 == simple_cst_equal (TREE_PURPOSE (t1
),
2623 cp_pedwarn ("default argument given for parameter %d of `%#D'",
2625 cp_pedwarn_at ("after previous specification in `%#D'",
2631 cp_error ("default argument given for parameter %d of `%#D'",
2633 cp_error_at ("after previous specification in `%#D'",
2638 if (DECL_THIS_INLINE (newdecl
) && ! DECL_THIS_INLINE (olddecl
)
2639 && TREE_ADDRESSABLE (olddecl
) && warn_inline
)
2641 cp_warning ("`%#D' was used before it was declared inline",
2643 cp_warning_at ("previous non-inline declaration here",
2647 /* These bits are logically part of the type for non-functions. */
2648 else if (TREE_READONLY (newdecl
) != TREE_READONLY (olddecl
)
2649 || TREE_THIS_VOLATILE (newdecl
) != TREE_THIS_VOLATILE (olddecl
))
2651 cp_pedwarn ("type qualifiers for `%#D'", newdecl
);
2652 cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl
);
2656 /* If new decl is `static' and an `extern' was seen previously,
2658 warn_extern_redeclared_static (newdecl
, olddecl
);
2660 /* We have committed to returning 1 at this point. */
2661 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
2663 /* Now that functions must hold information normally held
2664 by field decls, there is extra work to do so that
2665 declaration information does not get destroyed during
2667 if (DECL_VINDEX (olddecl
))
2668 DECL_VINDEX (newdecl
) = DECL_VINDEX (olddecl
);
2669 if (DECL_CONTEXT (olddecl
))
2670 DECL_CONTEXT (newdecl
) = DECL_CONTEXT (olddecl
);
2671 if (DECL_CLASS_CONTEXT (olddecl
))
2672 DECL_CLASS_CONTEXT (newdecl
) = DECL_CLASS_CONTEXT (olddecl
);
2673 if (DECL_CHAIN (newdecl
) == NULL_TREE
)
2674 DECL_CHAIN (newdecl
) = DECL_CHAIN (olddecl
);
2675 if (DECL_PENDING_INLINE_INFO (newdecl
) == (struct pending_inline
*)0)
2676 DECL_PENDING_INLINE_INFO (newdecl
) = DECL_PENDING_INLINE_INFO (olddecl
);
2677 DECL_STATIC_CONSTRUCTOR (newdecl
) |= DECL_STATIC_CONSTRUCTOR (olddecl
);
2678 DECL_STATIC_DESTRUCTOR (newdecl
) |= DECL_STATIC_DESTRUCTOR (olddecl
);
2679 DECL_ABSTRACT_VIRTUAL_P (newdecl
) |= DECL_ABSTRACT_VIRTUAL_P (olddecl
);
2682 /* Deal with C++: must preserve virtual function table size. */
2683 if (TREE_CODE (olddecl
) == TYPE_DECL
)
2685 register tree newtype
= TREE_TYPE (newdecl
);
2686 register tree oldtype
= TREE_TYPE (olddecl
);
2688 if (newtype
!= error_mark_node
&& oldtype
!= error_mark_node
2689 && TYPE_LANG_SPECIFIC (newtype
) && TYPE_LANG_SPECIFIC (oldtype
))
2691 CLASSTYPE_VSIZE (newtype
) = CLASSTYPE_VSIZE (oldtype
);
2692 CLASSTYPE_FRIEND_CLASSES (newtype
)
2693 = CLASSTYPE_FRIEND_CLASSES (oldtype
);
2697 /* Special handling ensues if new decl is a function definition. */
2698 new_defines_function
= (TREE_CODE (newdecl
) == FUNCTION_DECL
2699 && DECL_INITIAL (newdecl
) != NULL_TREE
);
2701 /* Optionally warn about more than one declaration for the same name,
2702 but don't warn about a function declaration followed by a definition. */
2703 if (warn_redundant_decls
2704 && ! DECL_ARTIFICIAL (olddecl
)
2705 && !(new_defines_function
&& DECL_INITIAL (olddecl
) == NULL_TREE
)
2706 /* Don't warn about extern decl followed by (tentative) definition. */
2707 && !(DECL_EXTERNAL (olddecl
) && ! DECL_EXTERNAL (newdecl
)))
2709 cp_warning ("redundant redeclaration of `%D' in same scope", newdecl
);
2710 cp_warning_at ("previous declaration of `%D'", olddecl
);
2713 /* Copy all the DECL_... slots specified in the new decl
2714 except for any that we copy here from the old type. */
2716 if (TREE_CODE (newdecl
) == TEMPLATE_DECL
)
2718 if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl
)) == NULL_TREE
)
2720 TREE_TYPE (olddecl
) = TREE_TYPE (newdecl
);
2721 DECL_TEMPLATE_RESULT (olddecl
) = DECL_TEMPLATE_RESULT (newdecl
);
2722 DECL_TEMPLATE_PARMS (olddecl
) = DECL_TEMPLATE_PARMS (newdecl
);
2729 /* Automatically handles default parameters. */
2730 tree oldtype
= TREE_TYPE (olddecl
);
2733 /* Make sure we put the new type in the same obstack as the old one. */
2735 push_obstacks (TYPE_OBSTACK (oldtype
), TYPE_OBSTACK (oldtype
));
2738 push_obstacks_nochange ();
2739 end_temporary_allocation ();
2742 /* Merge the data types specified in the two decls. */
2743 newtype
= common_type (TREE_TYPE (newdecl
), TREE_TYPE (olddecl
));
2745 if (TREE_CODE (newdecl
) == VAR_DECL
)
2746 DECL_THIS_EXTERN (newdecl
) |= DECL_THIS_EXTERN (olddecl
);
2747 /* Do this after calling `common_type' so that default
2748 parameters don't confuse us. */
2749 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
2750 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl
))
2751 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl
))))
2753 TREE_TYPE (newdecl
) = build_exception_variant (newtype
,
2754 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl
)));
2755 TREE_TYPE (olddecl
) = build_exception_variant (newtype
,
2756 TYPE_RAISES_EXCEPTIONS (oldtype
));
2758 if ((pedantic
|| ! DECL_IN_SYSTEM_HEADER (olddecl
))
2760 && ! compexcepttypes (TREE_TYPE (newdecl
), TREE_TYPE (olddecl
)))
2762 cp_pedwarn ("declaration of `%D' throws different exceptions",
2764 cp_pedwarn_at ("previous declaration here", olddecl
);
2767 TREE_TYPE (newdecl
) = TREE_TYPE (olddecl
) = newtype
;
2769 /* Lay the type out, unless already done. */
2770 if (oldtype
!= TREE_TYPE (newdecl
)
2771 && TREE_TYPE (newdecl
) != error_mark_node
2772 && !(processing_template_decl
&& uses_template_parms (newdecl
)))
2773 layout_type (TREE_TYPE (newdecl
));
2775 if ((TREE_CODE (newdecl
) == VAR_DECL
2776 || TREE_CODE (newdecl
) == PARM_DECL
2777 || TREE_CODE (newdecl
) == RESULT_DECL
2778 || TREE_CODE (newdecl
) == FIELD_DECL
2779 || TREE_CODE (newdecl
) == TYPE_DECL
)
2780 && !(processing_template_decl
&& uses_template_parms (newdecl
)))
2781 layout_decl (newdecl
, 0);
2783 /* Merge the type qualifiers. */
2784 if (TREE_READONLY (newdecl
))
2785 TREE_READONLY (olddecl
) = 1;
2786 if (TREE_THIS_VOLATILE (newdecl
))
2787 TREE_THIS_VOLATILE (olddecl
) = 1;
2789 /* Merge the initialization information. */
2790 if (DECL_INITIAL (newdecl
) == NULL_TREE
2791 && DECL_INITIAL (olddecl
) != NULL_TREE
)
2793 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
2794 DECL_SOURCE_FILE (newdecl
) = DECL_SOURCE_FILE (olddecl
);
2795 DECL_SOURCE_LINE (newdecl
) = DECL_SOURCE_LINE (olddecl
);
2798 /* Merge the section attribute.
2799 We want to issue an error if the sections conflict but that must be
2800 done later in decl_attributes since we are called before attributes
2802 if (DECL_SECTION_NAME (newdecl
) == NULL_TREE
)
2803 DECL_SECTION_NAME (newdecl
) = DECL_SECTION_NAME (olddecl
);
2805 /* Keep the old rtl since we can safely use it, unless it's the
2806 call to abort() used for abstract virtuals. */
2807 if ((DECL_LANG_SPECIFIC (olddecl
)
2808 && !DECL_ABSTRACT_VIRTUAL_P (olddecl
))
2809 || DECL_RTL (olddecl
) != DECL_RTL (abort_fndecl
))
2810 DECL_RTL (newdecl
) = DECL_RTL (olddecl
);
2814 /* If cannot merge, then use the new type and qualifiers,
2815 and don't preserve the old rtl. */
2818 /* Clean out any memory we had of the old declaration. */
2819 tree oldstatic
= value_member (olddecl
, static_aggregates
);
2821 TREE_VALUE (oldstatic
) = error_mark_node
;
2823 TREE_TYPE (olddecl
) = TREE_TYPE (newdecl
);
2824 TREE_READONLY (olddecl
) = TREE_READONLY (newdecl
);
2825 TREE_THIS_VOLATILE (olddecl
) = TREE_THIS_VOLATILE (newdecl
);
2826 TREE_SIDE_EFFECTS (olddecl
) = TREE_SIDE_EFFECTS (newdecl
);
2829 /* Merge the storage class information. */
2830 DECL_WEAK (newdecl
) |= DECL_WEAK (olddecl
);
2831 DECL_ONE_ONLY (newdecl
) |= DECL_ONE_ONLY (olddecl
);
2832 TREE_PUBLIC (newdecl
) = TREE_PUBLIC (olddecl
);
2833 TREE_STATIC (olddecl
) = TREE_STATIC (newdecl
) |= TREE_STATIC (olddecl
);
2834 if (! DECL_EXTERNAL (olddecl
))
2835 DECL_EXTERNAL (newdecl
) = 0;
2837 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
2838 DECL_C_STATIC (newdecl
) |= DECL_C_STATIC (olddecl
);
2840 if (DECL_LANG_SPECIFIC (newdecl
))
2842 DECL_INTERFACE_KNOWN (newdecl
) |= DECL_INTERFACE_KNOWN (olddecl
);
2843 DECL_NOT_REALLY_EXTERN (newdecl
) |= DECL_NOT_REALLY_EXTERN (olddecl
);
2846 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
2848 DECL_THIS_INLINE (newdecl
) |= DECL_THIS_INLINE (olddecl
);
2850 /* If either decl says `inline', this fn is inline, unless its
2851 definition was passed already. */
2852 if (DECL_INLINE (newdecl
) && DECL_INITIAL (olddecl
) == NULL_TREE
)
2853 DECL_INLINE (olddecl
) = 1;
2854 DECL_INLINE (newdecl
) = DECL_INLINE (olddecl
);
2858 DECL_LANGUAGE (olddecl
) = DECL_LANGUAGE (newdecl
);
2859 DECL_ASSEMBLER_NAME (olddecl
) = DECL_ASSEMBLER_NAME (newdecl
);
2860 DECL_RTL (olddecl
) = DECL_RTL (newdecl
);
2862 if (! types_match
|| new_defines_function
)
2864 /* These need to be copied so that the names are available. */
2865 DECL_ARGUMENTS (olddecl
) = DECL_ARGUMENTS (newdecl
);
2866 DECL_RESULT (olddecl
) = DECL_RESULT (newdecl
);
2868 if (new_defines_function
)
2869 /* If defining a function declared with other language
2870 linkage, use the previously declared language linkage. */
2871 DECL_LANGUAGE (newdecl
) = DECL_LANGUAGE (olddecl
);
2874 /* If redeclaring a builtin function, and not a definition,
2875 it stays built in. */
2876 if (DECL_BUILT_IN (olddecl
))
2878 DECL_BUILT_IN (newdecl
) = 1;
2879 DECL_FUNCTION_CODE (newdecl
) = DECL_FUNCTION_CODE (olddecl
);
2880 /* If we're keeping the built-in definition, keep the rtl,
2881 regardless of declaration matches. */
2882 DECL_RTL (newdecl
) = DECL_RTL (olddecl
);
2885 DECL_FRAME_SIZE (newdecl
) = DECL_FRAME_SIZE (olddecl
);
2887 DECL_RESULT (newdecl
) = DECL_RESULT (olddecl
);
2888 if ((DECL_SAVED_INSNS (newdecl
) = DECL_SAVED_INSNS (olddecl
)))
2889 /* Previously saved insns go together with
2890 the function's previous definition. */
2891 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
2892 /* Don't clear out the arguments if we're redefining a function. */
2893 if (DECL_ARGUMENTS (olddecl
))
2894 DECL_ARGUMENTS (newdecl
) = DECL_ARGUMENTS (olddecl
);
2896 if (DECL_LANG_SPECIFIC (olddecl
))
2897 DECL_MAIN_VARIANT (newdecl
) = DECL_MAIN_VARIANT (olddecl
);
2900 if (TREE_CODE (newdecl
) == NAMESPACE_DECL
)
2902 NAMESPACE_LEVEL (newdecl
) = NAMESPACE_LEVEL (olddecl
);
2905 if (TREE_CODE (newdecl
) == TEMPLATE_DECL
)
2907 DECL_TEMPLATE_INSTANTIATIONS (newdecl
)
2908 = DECL_TEMPLATE_INSTANTIATIONS (olddecl
);
2909 if (DECL_CHAIN (newdecl
) == NULL_TREE
)
2910 DECL_CHAIN (newdecl
) = DECL_CHAIN (olddecl
);
2913 /* Now preserve various other info from the definition. */
2914 TREE_ADDRESSABLE (newdecl
) = TREE_ADDRESSABLE (olddecl
);
2915 TREE_ASM_WRITTEN (newdecl
) = TREE_ASM_WRITTEN (olddecl
);
2916 DECL_COMMON (newdecl
) = DECL_COMMON (olddecl
);
2917 DECL_ASSEMBLER_NAME (newdecl
) = DECL_ASSEMBLER_NAME (olddecl
);
2919 /* Don't really know how much of the language-specific
2920 values we should copy from old to new. */
2921 if (DECL_LANG_SPECIFIC (olddecl
))
2923 DECL_IN_AGGR_P (newdecl
) = DECL_IN_AGGR_P (olddecl
);
2924 DECL_ACCESS (newdecl
) = DECL_ACCESS (olddecl
);
2925 DECL_NONCONVERTING_P (newdecl
) = DECL_NONCONVERTING_P (olddecl
);
2926 if (DECL_TEMPLATE_INFO (newdecl
) == NULL_TREE
)
2928 DECL_TEMPLATE_INFO (newdecl
) = DECL_TEMPLATE_INFO (olddecl
);
2929 DECL_USE_TEMPLATE (newdecl
) = DECL_USE_TEMPLATE (olddecl
);
2933 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
2936 struct lang_decl
*ol
= DECL_LANG_SPECIFIC (olddecl
);
2937 struct lang_decl
*nl
= DECL_LANG_SPECIFIC (newdecl
);
2939 function_size
= sizeof (struct tree_decl
);
2941 bcopy ((char *) newdecl
+ sizeof (struct tree_common
),
2942 (char *) olddecl
+ sizeof (struct tree_common
),
2943 function_size
- sizeof (struct tree_common
));
2945 /* Can we safely free the storage used by newdecl? */
2947 #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
2948 & ~ obstack_alignment_mask (&permanent_obstack))
2950 if ((char *)newdecl
+ ROUND (function_size
)
2951 + ROUND (sizeof (struct lang_decl
))
2952 == obstack_next_free (&permanent_obstack
))
2954 DECL_MAIN_VARIANT (newdecl
) = olddecl
;
2955 DECL_LANG_SPECIFIC (olddecl
) = ol
;
2956 bcopy ((char *)nl
, (char *)ol
, sizeof (struct lang_decl
));
2958 obstack_free (&permanent_obstack
, newdecl
);
2960 else if (LANG_DECL_PERMANENT (ol
) && ol
!= nl
)
2962 if (DECL_MAIN_VARIANT (olddecl
) == olddecl
)
2964 /* Save these lang_decls that would otherwise be lost. */
2965 extern tree free_lang_decl_chain
;
2966 tree free_lang_decl
= (tree
) ol
;
2968 if (DECL_LANG_SPECIFIC (olddecl
) == ol
)
2971 TREE_CHAIN (free_lang_decl
) = free_lang_decl_chain
;
2972 free_lang_decl_chain
= free_lang_decl
;
2976 /* Storage leak. */;
2982 bcopy ((char *) newdecl
+ sizeof (struct tree_common
),
2983 (char *) olddecl
+ sizeof (struct tree_common
),
2984 sizeof (struct tree_decl
) - sizeof (struct tree_common
)
2985 + tree_code_length
[(int)TREE_CODE (newdecl
)] * sizeof (char *));
2988 DECL_UID (olddecl
) = olddecl_uid
;
2990 DECL_FRIEND_P (olddecl
) = 1;
2995 /* Record a decl-node X as belonging to the current lexical scope.
2996 Check for errors (such as an incompatible declaration for the same
2997 name already seen in the same scope).
2999 Returns either X or an old decl for the same name.
3000 If an old decl is returned, it may have been smashed
3001 to agree with what X says. */
3008 register tree name
= DECL_ASSEMBLER_NAME (x
);
3009 register struct binding_level
*b
= current_binding_level
;
3011 if (x
!= current_function_decl
3012 /* Don't change DECL_CONTEXT of virtual methods. */
3013 && (TREE_CODE (x
) != FUNCTION_DECL
|| !DECL_VIRTUAL_P (x
))
3014 && ! DECL_CONTEXT (x
))
3015 DECL_CONTEXT (x
) = current_function_decl
;
3016 /* A local declaration for a function doesn't constitute nesting. */
3017 if (TREE_CODE (x
) == FUNCTION_DECL
&& DECL_INITIAL (x
) == 0)
3018 DECL_CONTEXT (x
) = 0;
3020 /* Type are looked up using the DECL_NAME, as that is what the rest of the
3021 compiler wants to use. */
3022 if (TREE_CODE (x
) == TYPE_DECL
|| TREE_CODE (x
) == VAR_DECL
3023 || TREE_CODE (x
) == NAMESPACE_DECL
|| TREE_CODE (x
) == TEMPLATE_TYPE_PARM
)
3024 name
= DECL_NAME (x
);
3029 /* Not needed...see below. */
3034 t
= lookup_name_current_level (name
);
3035 if (t
== error_mark_node
)
3037 /* error_mark_node is 0 for a while during initialization! */
3039 cp_error_at ("`%#D' used prior to declaration", x
);
3042 else if (t
!= NULL_TREE
)
3045 /* This is turned off until I have time to do it right (bpk). */
3046 /* With the code below that uses it... */
3047 file
= DECL_SOURCE_FILE (t
);
3048 line
= DECL_SOURCE_LINE (t
);
3050 if (TREE_CODE (t
) == PARM_DECL
)
3052 if (DECL_CONTEXT (t
) == NULL_TREE
)
3053 fatal ("parse errors have confused me too much");
3055 /* Check for duplicate params. */
3056 if (duplicate_decls (x
, t
))
3059 else if (((TREE_CODE (x
) == FUNCTION_DECL
&& DECL_LANGUAGE (x
) == lang_c
)
3060 || DECL_FUNCTION_TEMPLATE_P (x
))
3061 && is_overloaded_fn (t
))
3062 /* don't do anything just yet */;
3063 else if (t
== wchar_decl_node
)
3065 if (pedantic
&& ! DECL_IN_SYSTEM_HEADER (x
))
3066 cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x
));
3068 /* Throw away the redeclaration. */
3071 else if (TREE_CODE (t
) != TREE_CODE (x
))
3073 if ((TREE_CODE (t
) == TYPE_DECL
&& DECL_ARTIFICIAL (t
)
3074 && TREE_CODE (x
) != TYPE_DECL
3075 && ! (TREE_CODE (x
) == TEMPLATE_DECL
3076 && TREE_CODE (DECL_TEMPLATE_RESULT (x
)) == TYPE_DECL
))
3077 || (TREE_CODE (x
) == TYPE_DECL
&& DECL_ARTIFICIAL (x
)
3078 && TREE_CODE (t
) != TYPE_DECL
3079 && ! (TREE_CODE (t
) == TEMPLATE_DECL
3080 && (TREE_CODE (DECL_TEMPLATE_RESULT (t
))
3083 /* We do nothing special here, because C++ does such nasty
3084 things with TYPE_DECLs. Instead, just let the TYPE_DECL
3085 get shadowed, and know that if we need to find a TYPE_DECL
3086 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
3087 slot of the identifier. */
3090 else if (duplicate_decls (x
, t
))
3093 else if (duplicate_decls (x
, t
))
3096 /* This is turned off until I have time to do it right (bpk). */
3098 /* Also warn if they did a prototype with `static' on it, but
3099 then later left the `static' off. */
3100 if (! TREE_PUBLIC (name
) && TREE_PUBLIC (x
))
3102 if (DECL_LANG_SPECIFIC (t
) && DECL_FRIEND_P (t
))
3107 cp_warning ("`static' missing from declaration of `%D'",
3109 warning_with_file_and_line (file
, line
,
3110 "previous declaration of `%s'",
3111 decl_as_string (t
, 0));
3114 /* Now fix things so it'll do what they expect. */
3115 if (current_function_decl
)
3116 TREE_PUBLIC (current_function_decl
) = 0;
3118 /* Due to interference in memory reclamation (X may be
3119 obstack-deallocated at this point), we must guard against
3120 one really special case. [jason: This should be handled
3121 by start_function] */
3122 if (current_function_decl
== x
)
3123 current_function_decl
= t
;
3125 if (TREE_CODE (t
) == TYPE_DECL
)
3126 SET_IDENTIFIER_TYPE_VALUE (name
, TREE_TYPE (t
));
3127 else if (TREE_CODE (t
) == FUNCTION_DECL
)
3128 check_default_args (t
);
3134 if (TREE_CODE (x
) == FUNCTION_DECL
&& ! DECL_FUNCTION_MEMBER_P (x
))
3136 t
= push_overloaded_decl (x
, 1);
3137 if (t
!= x
|| DECL_LANGUAGE (x
) == lang_c
)
3140 else if (DECL_FUNCTION_TEMPLATE_P (x
) && DECL_CONTEXT (x
) == NULL_TREE
)
3141 return push_overloaded_decl (x
, 0);
3143 /* If declaring a type as a typedef, and the type has no known
3144 typedef name, install this TYPE_DECL as its typedef name. */
3145 if (TREE_CODE (x
) == TYPE_DECL
)
3147 tree type
= TREE_TYPE (x
);
3148 tree name
= (type
!= error_mark_node
) ? TYPE_NAME (type
) : x
;
3150 if (name
== NULL_TREE
|| TREE_CODE (name
) != TYPE_DECL
)
3152 /* If these are different names, and we're at the global
3153 binding level, make two equivalent definitions. */
3155 if (global_bindings_p ())
3156 TYPE_NAME (type
) = x
;
3158 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 140);
3160 if (type
!= error_mark_node
3162 && TYPE_IDENTIFIER (type
))
3163 set_identifier_type_value_with_scope (DECL_NAME (x
), type
, b
);
3166 /* Multiple external decls of the same identifier ought to match.
3168 We get warnings about inline functions where they are defined.
3169 We get warnings about other functions from push_overloaded_decl.
3171 Avoid duplicate warnings where they are used. */
3172 if (TREE_PUBLIC (x
) && TREE_CODE (x
) != FUNCTION_DECL
)
3176 if (IDENTIFIER_GLOBAL_VALUE (name
) != NULL_TREE
3177 && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name
))
3178 || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name
))))
3179 decl
= IDENTIFIER_GLOBAL_VALUE (name
);
3184 /* If different sort of thing, we already gave an error. */
3185 && TREE_CODE (decl
) == TREE_CODE (x
)
3186 && ! comptypes (TREE_TYPE (x
), TREE_TYPE (decl
), 1))
3188 cp_pedwarn ("type mismatch with previous external decl", x
);
3189 cp_pedwarn_at ("previous external decl of `%#D'", decl
);
3193 /* This name is new in its binding level.
3194 Install the new declaration and return it. */
3195 if (b
== global_binding_level
)
3197 /* Install a global value. */
3199 /* If the first global decl has external linkage,
3200 warn if we later see static one. */
3201 if (IDENTIFIER_GLOBAL_VALUE (name
) == NULL_TREE
&& DECL_PUBLIC (x
))
3202 TREE_PUBLIC (name
) = 1;
3204 /* Don't install an artificial TYPE_DECL if we already have
3205 another _DECL with that name. */
3206 if (TREE_CODE (x
) != TYPE_DECL
3208 || ! DECL_ARTIFICIAL (x
))
3209 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
3211 /* Don't forget if the function was used via an implicit decl. */
3212 if (IDENTIFIER_IMPLICIT_DECL (name
)
3213 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name
)))
3216 /* Don't forget if its address was taken in that way. */
3217 if (IDENTIFIER_IMPLICIT_DECL (name
)
3218 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name
)))
3219 TREE_ADDRESSABLE (x
) = 1;
3221 /* Warn about mismatches against previous implicit decl. */
3222 if (IDENTIFIER_IMPLICIT_DECL (name
) != NULL_TREE
3223 /* If this real decl matches the implicit, don't complain. */
3224 && ! (TREE_CODE (x
) == FUNCTION_DECL
3225 && TREE_TYPE (TREE_TYPE (x
)) == integer_type_node
))
3227 ("`%D' was previously implicitly declared to return `int'", x
);
3229 /* If new decl is `static' and an `extern' was seen previously,
3231 if (x
!= NULL_TREE
&& t
!= NULL_TREE
&& decls_match (x
, t
))
3232 warn_extern_redeclared_static (x
, t
);
3236 /* Here to install a non-global value. */
3237 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
3238 tree oldglobal
= IDENTIFIER_GLOBAL_VALUE (name
);
3240 /* Don't install an artificial TYPE_DECL if we already have
3241 another _DECL with that name. */
3242 if (TREE_CODE (x
) != TYPE_DECL
3244 || ! DECL_ARTIFICIAL (x
))
3246 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
3247 IDENTIFIER_LOCAL_VALUE (name
) = x
;
3250 /* If this is a TYPE_DECL, push it into the type value slot. */
3251 if (TREE_CODE (x
) == TYPE_DECL
)
3252 set_identifier_type_value_with_scope (name
, TREE_TYPE (x
), b
);
3254 /* Clear out any TYPE_DECL shadowed by a namespace so that
3255 we won't think this is a type. The C struct hack doesn't
3256 go through namespaces. */
3257 if (TREE_CODE (x
) == NAMESPACE_DECL
)
3258 set_identifier_type_value_with_scope (name
, NULL_TREE
, b
);
3260 /* If this is an extern function declaration, see if we
3261 have a global definition or declaration for the function. */
3262 if (oldlocal
== NULL_TREE
3263 && DECL_EXTERNAL (x
)
3264 && oldglobal
!= NULL_TREE
3265 && TREE_CODE (x
) == FUNCTION_DECL
3266 && TREE_CODE (oldglobal
) == FUNCTION_DECL
)
3268 /* We have one. Their types must agree. */
3269 if (decls_match (x
, oldglobal
))
3273 cp_warning ("extern declaration of `%#D' doesn't match", x
);
3274 cp_warning_at ("global declaration `%#D'", oldglobal
);
3277 /* If we have a local external declaration,
3278 and no file-scope declaration has yet been seen,
3279 then if we later have a file-scope decl it must not be static. */
3280 if (oldlocal
== NULL_TREE
3281 && oldglobal
== NULL_TREE
3282 && DECL_EXTERNAL (x
)
3285 TREE_PUBLIC (name
) = 1;
3288 if (DECL_FROM_INLINE (x
))
3289 /* Inline decls shadow nothing. */;
3291 /* Warn if shadowing an argument at the top level of the body. */
3292 else if (oldlocal
!= NULL_TREE
&& !DECL_EXTERNAL (x
)
3293 && TREE_CODE (oldlocal
) == PARM_DECL
3294 && TREE_CODE (x
) != PARM_DECL
)
3296 /* Go to where the parms should be and see if we
3298 struct binding_level
*b
= current_binding_level
->level_chain
;
3304 if (b
->parm_flag
== 1)
3305 cp_error ("declaration of `%#D' shadows a parameter", name
);
3307 else if (warn_shadow
&& oldlocal
!= NULL_TREE
&& b
->is_for_scope
3308 && !DECL_DEAD_FOR_LOCAL (oldlocal
))
3310 warning ("variable `%s' shadows local",
3311 IDENTIFIER_POINTER (name
));
3312 cp_warning_at (" this is the shadowed declaration", oldlocal
);
3314 /* Maybe warn if shadowing something else. */
3315 else if (warn_shadow
&& !DECL_EXTERNAL (x
)
3316 /* No shadow warnings for internally generated vars. */
3317 && ! DECL_ARTIFICIAL (x
)
3318 /* No shadow warnings for vars made for inlining. */
3319 && ! DECL_FROM_INLINE (x
))
3321 char *warnstring
= NULL
;
3323 if (oldlocal
!= NULL_TREE
&& TREE_CODE (oldlocal
) == PARM_DECL
)
3324 warnstring
= "declaration of `%s' shadows a parameter";
3325 else if (IDENTIFIER_CLASS_VALUE (name
) != NULL_TREE
3326 && current_class_ptr
3327 && !TREE_STATIC (name
))
3328 warnstring
= "declaration of `%s' shadows a member of `this'";
3329 else if (oldlocal
!= NULL_TREE
)
3330 warnstring
= "declaration of `%s' shadows previous local";
3331 else if (oldglobal
!= NULL_TREE
)
3332 warnstring
= "declaration of `%s' shadows global declaration";
3335 warning (warnstring
, IDENTIFIER_POINTER (name
));
3339 if (TREE_CODE (x
) == FUNCTION_DECL
)
3340 check_default_args (x
);
3342 /* Keep count of variables in this level with incomplete type. */
3343 if (TREE_CODE (x
) == VAR_DECL
3344 && TREE_TYPE (x
) != error_mark_node
3345 && ((TYPE_SIZE (TREE_TYPE (x
)) == NULL_TREE
3346 && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x
), ARRAY_TYPE
))
3347 /* RTTI TD entries are created while defining the type_info. */
3348 || (TYPE_LANG_SPECIFIC (TREE_TYPE (x
))
3349 && TYPE_BEING_DEFINED (TREE_TYPE (x
)))))
3350 b
->incomplete
= tree_cons (NULL_TREE
, x
, b
->incomplete
);
3353 /* Put decls on list in reverse order.
3354 We will reverse them later if necessary. */
3355 TREE_CHAIN (x
) = b
->names
;
3357 if (! (b
!= global_binding_level
|| TREE_PERMANENT (x
)))
3358 my_friendly_abort (124);
3363 /* Same as pushdecl, but define X in binding-level LEVEL. We rely on the
3364 caller to set DECL_CONTEXT properly. */
3367 pushdecl_with_scope (x
, level
)
3369 struct binding_level
*level
;
3371 register struct binding_level
*b
= current_binding_level
;
3372 tree function_decl
= current_function_decl
;
3374 current_function_decl
= NULL_TREE
;
3375 current_binding_level
= level
;
3377 current_binding_level
= b
;
3378 current_function_decl
= function_decl
;
3382 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
3386 pushdecl_top_level (x
)
3389 register struct binding_level
*b
= inner_binding_level
;
3390 register tree t
= pushdecl_with_scope (x
, global_binding_level
);
3392 /* Now, the type_shadowed stack may screw us. Munge it so it does
3394 if (TREE_CODE (x
) == TYPE_DECL
)
3396 tree name
= DECL_NAME (x
);
3398 tree
*ptr
= (tree
*)0;
3399 for (; b
!= global_binding_level
; b
= b
->level_chain
)
3401 tree shadowed
= b
->type_shadowed
;
3402 for (; shadowed
; shadowed
= TREE_CHAIN (shadowed
))
3403 if (TREE_PURPOSE (shadowed
) == name
)
3405 ptr
= &TREE_VALUE (shadowed
);
3406 /* Can't break out of the loop here because sometimes
3407 a binding level will have duplicate bindings for
3408 PT names. It's gross, but I haven't time to fix it. */
3411 newval
= TREE_TYPE (x
);
3412 if (ptr
== (tree
*)0)
3414 /* @@ This shouldn't be needed. My test case "zstring.cc" trips
3415 up here if this is changed to an assertion. --KR */
3416 SET_IDENTIFIER_TYPE_VALUE (name
, newval
);
3426 /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
3430 push_overloaded_decl_top_level (x
, forget
)
3434 struct binding_level
*b
= current_binding_level
;
3436 current_binding_level
= global_binding_level
;
3437 push_overloaded_decl (x
, forget
);
3438 current_binding_level
= b
;
3441 /* Make the declaration of X appear in CLASS scope. */
3444 pushdecl_class_level (x
)
3447 /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class
3448 scope looks for the pre-mangled name. */
3449 register tree name
= DECL_NAME (x
);
3453 if (TYPE_BEING_DEFINED (current_class_type
))
3455 /* Check for inconsistent use of this name in the class body.
3456 Types, enums, and static vars are checked here; other
3457 members are checked in finish_struct. */
3458 tree icv
= IDENTIFIER_CLASS_VALUE (name
);
3461 /* Don't complain about inherited names. */
3462 && id_in_current_class (name
)
3463 /* Or shadowed tags. */
3464 && !(TREE_CODE (icv
) == TYPE_DECL
3465 && DECL_CONTEXT (icv
) == current_class_type
))
3467 cp_error ("declaration of identifier `%D' as `%#D'", name
, x
);
3468 cp_error_at ("conflicts with previous use in class as `%#D'",
3473 push_class_level_binding (name
, x
);
3474 if (TREE_CODE (x
) == TYPE_DECL
)
3476 set_identifier_type_value (name
, TREE_TYPE (x
));
3483 /* This function is used to push the mangled decls for nested types into
3484 the appropriate scope. Previously pushdecl_top_level was used, but that
3485 is incorrect for members of local classes. */
3488 pushdecl_nonclass_level (x
)
3491 struct binding_level
*b
= current_binding_level
;
3493 my_friendly_assert (b
->parm_flag
!= 2, 180);
3496 /* Get out of template binding levels */
3497 while (b
->pseudo_global
)
3501 pushdecl_with_scope (x
, b
);
3505 /* Make the declaration(s) of X appear in CLASS scope
3506 under the name NAME. */
3509 push_class_level_binding (name
, x
)
3513 /* The class_binding_level will be NULL if x is a template
3514 parameter name in a member template. */
3515 if (!class_binding_level
)
3518 if (TREE_CODE (x
) == TYPE_DECL
&& DECL_ARTIFICIAL (x
)
3519 && purpose_member (name
, class_binding_level
->class_shadowed
))
3522 maybe_push_cache_obstack ();
3523 class_binding_level
->class_shadowed
3524 = tree_cons (name
, IDENTIFIER_CLASS_VALUE (name
),
3525 class_binding_level
->class_shadowed
);
3527 IDENTIFIER_CLASS_VALUE (name
) = x
;
3528 obstack_ptr_grow (&decl_obstack
, x
);
3531 /* Tell caller how to interpret a TREE_LIST which contains
3532 chains of FUNCTION_DECLS. */
3535 overloaded_globals_p (list
)
3538 my_friendly_assert (TREE_CODE (list
) == TREE_LIST
, 142);
3540 /* Don't commit caller to seeing them as globals. */
3541 if (TREE_NONLOCAL_FLAG (list
))
3543 /* Do commit caller to not seeing them as globals. */
3544 if (TREE_CODE (TREE_VALUE (list
)) == TREE_LIST
)
3546 /* Do commit caller to seeing them as globals. */
3550 /* DECL is a FUNCTION_DECL which may have other definitions already in
3551 place. We get around this by making the value of the identifier point
3552 to a list of all the things that want to be referenced by that name. It
3553 is then up to the users of that name to decide what to do with that
3556 DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
3557 slot. It is dealt with the same way.
3559 The value returned may be a previous declaration if we guessed wrong
3560 about what language DECL should belong to (C or C++). Otherwise,
3561 it's always DECL (and never something that's not a _DECL). */
3564 push_overloaded_decl (decl
, forgettable
)
3568 tree orig_name
= DECL_NAME (decl
);
3570 int doing_global
= (global_bindings_p () || ! forgettable
);
3574 old
= IDENTIFIER_GLOBAL_VALUE (orig_name
);
3575 if (old
&& TREE_CODE (old
) == FUNCTION_DECL
3576 && DECL_ARTIFICIAL (old
)
3577 && (DECL_BUILT_IN (old
) || DECL_BUILT_IN_NONANSI (old
)))
3579 if (duplicate_decls (decl
, old
))
3586 old
= IDENTIFIER_LOCAL_VALUE (orig_name
);
3588 if (! purpose_member (orig_name
, current_binding_level
->shadowed
))
3590 current_binding_level
->shadowed
3591 = tree_cons (orig_name
, old
, current_binding_level
->shadowed
);
3598 if (TREE_CODE (old
) == TYPE_DECL
&& DECL_ARTIFICIAL (old
))
3600 tree t
= TREE_TYPE (old
);
3601 if (IS_AGGR_TYPE (t
) && warn_shadow
3602 && (! DECL_IN_SYSTEM_HEADER (decl
)
3603 || ! DECL_IN_SYSTEM_HEADER (old
)))
3604 cp_warning ("`%#D' hides constructor for `%#T'", decl
, t
);
3607 else if (is_overloaded_fn (old
))
3611 for (tmp
= get_first_fn (old
); tmp
; tmp
= DECL_CHAIN (tmp
))
3612 if (decl
== tmp
|| duplicate_decls (decl
, tmp
))
3617 cp_error_at ("previous non-function declaration `%#D'", old
);
3618 cp_error ("conflicts with function declaration `%#D'", decl
);
3623 if (old
|| TREE_CODE (decl
) == TEMPLATE_DECL
)
3625 if (old
&& is_overloaded_fn (old
))
3626 DECL_CHAIN (decl
) = get_first_fn (old
);
3628 DECL_CHAIN (decl
) = NULL_TREE
;
3629 old
= tree_cons (orig_name
, decl
, NULL_TREE
);
3630 TREE_TYPE (old
) = unknown_type_node
;
3633 /* orig_name is not ambiguous. */
3637 IDENTIFIER_GLOBAL_VALUE (orig_name
) = old
;
3639 IDENTIFIER_LOCAL_VALUE (orig_name
) = old
;
3644 /* Generate an implicit declaration for identifier FUNCTIONID
3645 as a function of type int (). Print a warning if appropriate. */
3648 implicitly_declare (functionid
)
3652 int temp
= allocation_temporary_p ();
3654 push_obstacks_nochange ();
3656 /* Save the decl permanently so we can warn if definition follows.
3657 In ANSI C, warn_implicit is usually false, so the saves little space.
3658 But in C++, it's usually true, hence the extra code. */
3659 if (temp
&& (! warn_implicit
|| toplevel_bindings_p ()))
3660 end_temporary_allocation ();
3662 /* We used to reuse an old implicit decl here,
3663 but this loses with inline functions because it can clobber
3664 the saved decl chains. */
3665 decl
= build_lang_decl (FUNCTION_DECL
, functionid
, default_function_type
);
3667 DECL_EXTERNAL (decl
) = 1;
3668 TREE_PUBLIC (decl
) = 1;
3670 /* ANSI standard says implicit declarations are in the innermost block.
3671 So we record the decl in the standard fashion. */
3673 rest_of_decl_compilation (decl
, NULL_PTR
, 0, 0);
3676 /* Only one warning per identifier. */
3677 && IDENTIFIER_IMPLICIT_DECL (functionid
) == NULL_TREE
)
3679 cp_pedwarn ("implicit declaration of function `%#D'", decl
);
3682 SET_IDENTIFIER_IMPLICIT_DECL (functionid
, decl
);
3689 /* Return zero if the declaration NEWDECL is valid
3690 when the declaration OLDDECL (assumed to be for the same name)
3691 has already been seen.
3692 Otherwise return an error message format string with a %s
3693 where the identifier should go. */
3696 redeclaration_error_message (newdecl
, olddecl
)
3697 tree newdecl
, olddecl
;
3699 if (TREE_CODE (newdecl
) == TYPE_DECL
)
3701 /* Because C++ can put things into name space for free,
3702 constructs like "typedef struct foo { ... } foo"
3703 would look like an erroneous redeclaration. */
3704 if (comptypes (TREE_TYPE (newdecl
), TREE_TYPE (olddecl
), 0))
3707 return "redefinition of `%#D'";
3709 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
3711 /* If this is a pure function, its olddecl will actually be
3712 the original initialization to `0' (which we force to call
3713 abort()). Don't complain about redefinition in this case. */
3714 if (DECL_LANG_SPECIFIC (olddecl
) && DECL_ABSTRACT_VIRTUAL_P (olddecl
))
3717 /* We'll complain about linkage mismatches in
3718 warn_extern_redeclared_static. */
3720 /* defining the same name twice is no good. */
3721 if (DECL_INITIAL (olddecl
) != NULL_TREE
3722 && DECL_INITIAL (newdecl
) != NULL_TREE
)
3724 if (DECL_NAME (olddecl
) == NULL_TREE
)
3725 return "`%#D' not declared in class";
3727 return "redefinition of `%#D'";
3731 else if (TREE_CODE (newdecl
) == TEMPLATE_DECL
)
3733 if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl
)) == FUNCTION_DECL
3734 && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl
))
3735 && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl
)))
3736 || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl
)) == TYPE_DECL
3737 && TYPE_SIZE (TREE_TYPE (newdecl
))
3738 && TYPE_SIZE (TREE_TYPE (olddecl
))))
3739 return "redefinition of `%#D'";
3742 else if (toplevel_bindings_p ())
3744 /* Objects declared at top level: */
3745 /* If at least one is a reference, it's ok. */
3746 if (DECL_EXTERNAL (newdecl
) || DECL_EXTERNAL (olddecl
))
3748 /* Reject two definitions. */
3749 return "redefinition of `%#D'";
3753 /* Objects declared with block scope: */
3754 /* Reject two definitions, and reject a definition
3755 together with an external reference. */
3756 if (!(DECL_EXTERNAL (newdecl
) && DECL_EXTERNAL (olddecl
)))
3757 return "redeclaration of `%#D'";
3762 /* Get the LABEL_DECL corresponding to identifier ID as a label.
3763 Create one if none exists so far for the current function.
3764 This function is called for both label definitions and label references. */
3770 register tree decl
= IDENTIFIER_LABEL_VALUE (id
);
3772 if (current_function_decl
== NULL_TREE
)
3774 error ("label `%s' referenced outside of any function",
3775 IDENTIFIER_POINTER (id
));
3779 if ((decl
== NULL_TREE
3780 || DECL_SOURCE_LINE (decl
) == 0)
3781 && (named_label_uses
== NULL
3782 || named_label_uses
->names_in_scope
!= current_binding_level
->names
3783 || named_label_uses
->label_decl
!= decl
))
3785 struct named_label_list
*new_ent
;
3787 = (struct named_label_list
*)oballoc (sizeof (struct named_label_list
));
3788 new_ent
->label_decl
= decl
;
3789 new_ent
->names_in_scope
= current_binding_level
->names
;
3790 new_ent
->binding_level
= current_binding_level
;
3791 new_ent
->lineno_o_goto
= lineno
;
3792 new_ent
->filename_o_goto
= input_filename
;
3793 new_ent
->next
= named_label_uses
;
3794 named_label_uses
= new_ent
;
3797 /* Use a label already defined or ref'd with this name. */
3798 if (decl
!= NULL_TREE
)
3800 /* But not if it is inherited and wasn't declared to be inheritable. */
3801 if (DECL_CONTEXT (decl
) != current_function_decl
3802 && ! C_DECLARED_LABEL_FLAG (decl
))
3803 return shadow_label (id
);
3807 decl
= build_decl (LABEL_DECL
, id
, void_type_node
);
3809 /* Make sure every label has an rtx. */
3812 /* A label not explicitly declared must be local to where it's ref'd. */
3813 DECL_CONTEXT (decl
) = current_function_decl
;
3815 DECL_MODE (decl
) = VOIDmode
;
3817 /* Say where one reference is to the label,
3818 for the sake of the error if it is not defined. */
3819 DECL_SOURCE_LINE (decl
) = lineno
;
3820 DECL_SOURCE_FILE (decl
) = input_filename
;
3822 SET_IDENTIFIER_LABEL_VALUE (id
, decl
);
3824 named_labels
= tree_cons (NULL_TREE
, decl
, named_labels
);
3825 named_label_uses
->label_decl
= decl
;
3830 /* Make a label named NAME in the current function,
3831 shadowing silently any that may be inherited from containing functions
3832 or containing scopes.
3834 Note that valid use, if the label being shadowed
3835 comes from another scope in the same function,
3836 requires calling declare_nonlocal_label right away. */
3842 register tree decl
= IDENTIFIER_LABEL_VALUE (name
);
3844 if (decl
!= NULL_TREE
)
3846 shadowed_labels
= tree_cons (NULL_TREE
, decl
, shadowed_labels
);
3847 SET_IDENTIFIER_LABEL_VALUE (name
, NULL_TREE
);
3848 SET_IDENTIFIER_LABEL_VALUE (decl
, NULL_TREE
);
3851 return lookup_label (name
);
3854 /* Define a label, specifying the location in the source file.
3855 Return the LABEL_DECL node for the label, if the definition is valid.
3856 Otherwise return 0. */
3859 define_label (filename
, line
, name
)
3866 if (minimal_parse_mode
)
3868 push_obstacks (&permanent_obstack
, &permanent_obstack
);
3869 decl
= build_decl (LABEL_DECL
, name
, void_type_node
);
3871 DECL_SOURCE_LINE (decl
) = line
;
3872 DECL_SOURCE_FILE (decl
) = filename
;
3877 decl
= lookup_label (name
);
3879 /* After labels, make any new cleanups go into their
3880 own new (temporary) binding contour. */
3881 current_binding_level
->more_cleanups_ok
= 0;
3883 /* If label with this name is known from an outer context, shadow it. */
3884 if (decl
!= NULL_TREE
&& DECL_CONTEXT (decl
) != current_function_decl
)
3886 shadowed_labels
= tree_cons (NULL_TREE
, decl
, shadowed_labels
);
3887 SET_IDENTIFIER_LABEL_VALUE (name
, NULL_TREE
);
3888 decl
= lookup_label (name
);
3891 if (name
== get_identifier ("wchar_t"))
3892 cp_pedwarn ("label named wchar_t");
3894 if (DECL_INITIAL (decl
) != NULL_TREE
)
3896 cp_error ("duplicate label `%D'", decl
);
3901 struct named_label_list
*uses
, *prev
;
3904 /* Mark label as having been defined. */
3905 DECL_INITIAL (decl
) = error_mark_node
;
3906 /* Say where in the source. */
3907 DECL_SOURCE_FILE (decl
) = filename
;
3908 DECL_SOURCE_LINE (decl
) = line
;
3911 uses
= named_label_uses
;
3912 while (uses
!= NULL
)
3913 if (uses
->label_decl
== decl
)
3915 struct binding_level
*b
= current_binding_level
;
3918 tree new_decls
= b
->names
;
3919 tree old_decls
= (b
== uses
->binding_level
)
3920 ? uses
->names_in_scope
: NULL_TREE
;
3921 while (new_decls
!= old_decls
)
3923 if (TREE_CODE (new_decls
) == VAR_DECL
3924 /* Don't complain about crossing initialization
3925 of internal entities. They can't be accessed,
3926 and they should be cleaned up
3927 by the time we get to the label. */
3928 && ! DECL_ARTIFICIAL (new_decls
)
3929 && ((DECL_INITIAL (new_decls
) != NULL_TREE
3930 && DECL_INITIAL (new_decls
) != error_mark_node
)
3931 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls
))))
3935 cp_error ("jump to label `%D'", decl
);
3936 error_with_file_and_line (uses
->filename_o_goto
,
3937 uses
->lineno_o_goto
,
3941 cp_error_at (" crosses initialization of `%#D'",
3944 new_decls
= TREE_CHAIN (new_decls
);
3946 if (b
== uses
->binding_level
)
3952 prev
->next
= uses
->next
;
3954 named_label_uses
= uses
->next
;
3963 current_function_return_value
= NULL_TREE
;
3970 struct binding_level
*level
;
3971 struct cp_switch
*next
;
3974 static struct cp_switch
*switch_stack
;
3980 = (struct cp_switch
*) oballoc (sizeof (struct cp_switch
));
3981 p
->level
= current_binding_level
;
3982 p
->next
= switch_stack
;
3989 switch_stack
= switch_stack
->next
;
3992 /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */
3993 /* XXX Note decl is never actually used. (bpk) */
3996 define_case_label (decl
)
3999 tree cleanup
= last_cleanup_this_contour ();
4000 struct binding_level
*b
= current_binding_level
;
4005 static int explained
= 0;
4006 cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup
));
4007 warning ("where case label appears here");
4010 warning ("(enclose actions of previous case statements requiring");
4011 warning ("destructors in their own binding contours.)");
4016 for (; b
&& b
!= switch_stack
->level
; b
= b
->level_chain
)
4018 tree new_decls
= b
->names
;
4019 for (; new_decls
; new_decls
= TREE_CHAIN (new_decls
))
4021 if (TREE_CODE (new_decls
) == VAR_DECL
4022 /* Don't complain about crossing initialization
4023 of internal entities. They can't be accessed,
4024 and they should be cleaned up
4025 by the time we get to the label. */
4026 && ! DECL_ARTIFICIAL (new_decls
)
4027 && ((DECL_INITIAL (new_decls
) != NULL_TREE
4028 && DECL_INITIAL (new_decls
) != error_mark_node
)
4029 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls
))))
4032 error ("jump to case label");
4034 cp_error_at (" crosses initialization of `%#D'",
4040 /* After labels, make any new cleanups go into their
4041 own new (temporary) binding contour. */
4043 current_binding_level
->more_cleanups_ok
= 0;
4044 current_function_return_value
= NULL_TREE
;
4047 /* Return the list of declarations of the current level.
4048 Note that this list is in reverse order unless/until
4049 you nreverse it; and when you do nreverse it, you must
4050 store the result back using `storedecls' or you will lose. */
4055 return current_binding_level
->names
;
4058 /* Return the list of type-tags (for structs, etc) of the current level. */
4063 return current_binding_level
->tags
;
4066 /* Store the list of declarations of the current level.
4067 This is done for the parameter declarations of a function being defined,
4068 after they are modified in the light of any missing parameters. */
4074 current_binding_level
->names
= decls
;
4077 /* Similarly, store the list of tags of the current level. */
4083 current_binding_level
->tags
= tags
;
4086 /* Given NAME, an IDENTIFIER_NODE,
4087 return the structure (or union or enum) definition for that name.
4088 Searches binding levels from BINDING_LEVEL up to the global level.
4089 If THISLEVEL_ONLY is nonzero, searches only the specified context
4090 (but skips any tag-transparent contexts to find one that is
4091 meaningful for tags).
4092 FORM says which kind of type the caller wants;
4093 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
4094 If the wrong kind of type is found, and it's not a template, an error is
4098 lookup_tag (form
, name
, binding_level
, thislevel_only
)
4099 enum tree_code form
;
4101 struct binding_level
*binding_level
;
4104 register struct binding_level
*level
;
4106 for (level
= binding_level
; level
; level
= level
->level_chain
)
4109 if (ANON_AGGRNAME_P (name
))
4110 for (tail
= level
->tags
; tail
; tail
= TREE_CHAIN (tail
))
4112 /* There's no need for error checking here, because
4113 anon names are unique throughout the compilation. */
4114 if (TYPE_IDENTIFIER (TREE_VALUE (tail
)) == name
)
4115 return TREE_VALUE (tail
);
4118 for (tail
= level
->tags
; tail
; tail
= TREE_CHAIN (tail
))
4120 if (TREE_PURPOSE (tail
) == name
)
4122 enum tree_code code
= TREE_CODE (TREE_VALUE (tail
));
4123 /* Should tighten this up; it'll probably permit
4124 UNION_TYPE and a struct template, for example. */
4126 && !(form
!= ENUMERAL_TYPE
&& code
== TEMPLATE_DECL
))
4128 /* Definition isn't the kind we were looking for. */
4129 cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail
),
4133 return TREE_VALUE (tail
);
4136 if (thislevel_only
&& ! level
->tag_transparent
)
4138 if (level
->pseudo_global
)
4140 tree t
= IDENTIFIER_GLOBAL_VALUE (name
);
4141 if (t
&& TREE_CODE (t
) == TEMPLATE_DECL
4142 && TREE_CODE (DECL_TEMPLATE_RESULT (t
)) == TYPE_DECL
)
4143 return TREE_TYPE (t
);
4147 if (current_class_type
&& level
->level_chain
== global_binding_level
)
4149 /* Try looking in this class's tags before heading into
4150 global binding level. */
4151 tree context
= current_class_type
;
4154 switch (TREE_CODE_CLASS (TREE_CODE (context
)))
4158 these_tags
= CLASSTYPE_TAGS (context
);
4159 if (ANON_AGGRNAME_P (name
))
4162 if (TYPE_IDENTIFIER (TREE_VALUE (these_tags
))
4164 return TREE_VALUE (tail
);
4165 these_tags
= TREE_CHAIN (these_tags
);
4170 if (TREE_PURPOSE (these_tags
) == name
)
4172 if (TREE_CODE (TREE_VALUE (these_tags
)) != form
)
4174 cp_error ("`%#D' redeclared as %C in class scope",
4175 TREE_VALUE (tail
), form
);
4178 return TREE_VALUE (tail
);
4180 these_tags
= TREE_CHAIN (these_tags
);
4182 /* If this type is not yet complete, then don't
4183 look at its context. */
4184 if (TYPE_SIZE (context
) == NULL_TREE
)
4186 /* Go to next enclosing type, if any. */
4187 context
= DECL_CONTEXT (TYPE_MAIN_DECL (context
));
4190 context
= DECL_CONTEXT (context
);
4193 my_friendly_abort (10);
4206 set_current_level_tags_transparency (tags_transparent
)
4207 int tags_transparent
;
4209 current_binding_level
->tag_transparent
= tags_transparent
;
4213 /* Given a type, find the tag that was defined for it and return the tag name.
4214 Otherwise return 0. However, the value can never be 0
4215 in the cases in which this is used.
4217 C++: If NAME is non-zero, this is the new name to install. This is
4218 done when replacing anonymous tags with real tag names. */
4221 lookup_tag_reverse (type
, name
)
4225 register struct binding_level
*level
;
4227 for (level
= current_binding_level
; level
; level
= level
->level_chain
)
4230 for (tail
= level
->tags
; tail
; tail
= TREE_CHAIN (tail
))
4232 if (TREE_VALUE (tail
) == type
)
4235 TREE_PURPOSE (tail
) = name
;
4236 return TREE_PURPOSE (tail
);
4243 /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
4244 Return the type value, or NULL_TREE if not found. */
4247 lookup_nested_type (type
, context
)
4251 if (context
== NULL_TREE
)
4255 switch (TREE_CODE (context
))
4259 tree ctype
= TREE_TYPE (context
);
4260 tree match
= value_member (type
, CLASSTYPE_TAGS (ctype
));
4262 return TREE_VALUE (match
);
4263 context
= DECL_CONTEXT (context
);
4265 /* When we have a nested class whose member functions have
4266 local types (e.g., a set of enums), we'll arrive here
4267 with the DECL_CONTEXT as the actual RECORD_TYPE node for
4268 the enclosing class. Instead, we want to make sure we
4269 come back in here with the TYPE_DECL, not the RECORD_TYPE. */
4270 if (context
&& TREE_CODE (context
) == RECORD_TYPE
)
4271 context
= TREE_CHAIN (context
);
4275 if (TYPE_NAME (type
) && TYPE_IDENTIFIER (type
))
4276 return lookup_name (TYPE_IDENTIFIER (type
), 1);
4279 my_friendly_abort (12);
4285 /* Look up NAME in the NAMESPACE. */
4288 lookup_namespace_name (namespace, name
)
4289 tree
namespace, name
;
4291 struct binding_level
*b
= (struct binding_level
*)NAMESPACE_LEVEL (namespace);
4295 /* This searches just one level. */
4298 for (x
= b
->names
; x
; x
= TREE_CHAIN (x
))
4299 if (DECL_NAME (x
) == name
|| DECL_ASSEMBLER_NAME (x
) == name
)
4303 /* This searches all levels. */
4304 for (; b
&& !x
; b
= b
->level_chain
)
4306 for (x
= b
->names
; x
; x
= TREE_CHAIN (x
))
4307 if (DECL_NAME (x
) == name
|| DECL_ASSEMBLER_NAME (x
) == name
)
4315 make_typename_type (context
, name
)
4320 if (TREE_CODE (name
) == TYPE_DECL
)
4321 name
= DECL_NAME (name
);
4322 else if (TREE_CODE (name
) != IDENTIFIER_NODE
)
4323 my_friendly_abort (2000);
4325 if (! processing_template_decl
4326 || ! uses_template_parms (context
)
4327 || context
== current_class_type
)
4329 t
= lookup_field (context
, name
, 0, 1);
4332 cp_error ("no type named `%#T' in `%#T'", name
, context
);
4333 return error_mark_node
;
4335 return TREE_TYPE (t
);
4338 if (processing_template_decl
)
4339 push_obstacks (&permanent_obstack
, &permanent_obstack
);
4340 t
= make_lang_type (TYPENAME_TYPE
);
4341 d
= build_decl (TYPE_DECL
, name
, t
);
4342 if (processing_template_decl
)
4345 TYPE_CONTEXT (t
) = context
;
4346 TYPE_NAME (TREE_TYPE (d
)) = d
;
4347 TYPE_STUB_DECL (TREE_TYPE (d
)) = d
;
4348 DECL_CONTEXT (d
) = context
;
4349 CLASSTYPE_GOT_SEMICOLON (t
) = 1;
4354 /* Look up NAME in the current binding level and its superiors in the
4355 namespace of variables, functions and typedefs. Return a ..._DECL
4356 node of some kind representing its definition if there is only one
4357 such declaration, or return a TREE_LIST with all the overloaded
4358 definitions if there are many, or return 0 if it is undefined.
4360 If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
4361 If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
4362 Otherwise we prefer non-TYPE_DECLs. */
4365 lookup_name_real (name
, prefer_type
, nonclass
)
4367 int prefer_type
, nonclass
;
4371 tree from_obj
= NULL_TREE
;
4372 tree locval
, classval
;
4374 if (prefer_type
== -2)
4376 extern int looking_for_typename
;
4377 tree type
= NULL_TREE
;
4380 prefer_type
= looking_for_typename
;
4384 else if (got_object
!= error_mark_node
)
4389 if (type
== error_mark_node
)
4390 return error_mark_node
;
4391 if (TREE_CODE (type
) == TYPENAME_TYPE
&& TREE_TYPE (type
))
4392 type
= TREE_TYPE (type
);
4394 type
= complete_type (type
);
4396 if (type
== void_type_node
)
4397 val
= IDENTIFIER_GLOBAL_VALUE (name
);
4398 else if (TREE_CODE (type
) == NAMESPACE_DECL
)
4400 val
= lookup_namespace_name (type
, name
);
4402 else if (! IS_AGGR_TYPE (type
)
4403 || TREE_CODE (type
) == TEMPLATE_TYPE_PARM
4404 || TREE_CODE (type
) == TYPENAME_TYPE
)
4405 /* Someone else will give an error about this if needed. */
4407 else if (TYPE_BEING_DEFINED (type
))
4409 val
= IDENTIFIER_CLASS_VALUE (name
);
4410 if (val
&& DECL_CONTEXT (val
) != type
)
4412 struct binding_level
*b
= class_binding_level
;
4413 for (val
= NULL_TREE
; b
; b
= b
->level_chain
)
4415 tree t
= purpose_member (name
, b
->class_shadowed
);
4416 if (t
&& TREE_VALUE (t
)
4417 && DECL_CONTEXT (TREE_VALUE (t
)) == type
)
4419 val
= TREE_VALUE (t
);
4424 if (val
== NULL_TREE
)
4425 val
= lookup_field (type
, name
, 0, 1);
4427 else if (type
== current_class_type
)
4428 val
= IDENTIFIER_CLASS_VALUE (name
);
4430 val
= lookup_field (type
, name
, 0, prefer_type
);
4436 if (got_scope
&& processing_template_decl
4437 && got_scope
!= current_class_type
4438 && uses_template_parms (got_scope
)
4439 && val
&& TREE_CODE (val
) == TYPE_DECL
4440 && ! DECL_ARTIFICIAL (val
))
4442 tree t
= make_typename_type (got_scope
, DECL_NAME (val
));
4443 TREE_TYPE (t
) = TREE_TYPE (val
);
4444 val
= TYPE_MAIN_DECL (t
);
4450 else if (got_object
&& val
)
4454 locval
= classval
= NULL_TREE
;
4456 if (current_binding_level
!= global_binding_level
4457 && IDENTIFIER_LOCAL_VALUE (name
))
4458 locval
= IDENTIFIER_LOCAL_VALUE (name
);
4460 /* In C++ class fields are between local and global scope,
4461 just before the global scope. */
4462 if (current_class_type
&& ! nonclass
)
4464 classval
= IDENTIFIER_CLASS_VALUE (name
);
4465 if (classval
== NULL_TREE
&& TYPE_BEING_DEFINED (current_class_type
))
4466 /* Try to find values from base classes if we are presently
4467 defining a type. We are presently only interested in
4469 classval
= lookup_field (current_class_type
, name
, 0, 1);
4471 /* yylex() calls this with -2, since we should never start digging for
4472 the nested name at the point where we haven't even, for example,
4473 created the COMPONENT_REF or anything like that. */
4474 if (classval
== NULL_TREE
)
4475 classval
= lookup_nested_field (name
, ! yylex
);
4478 if (locval
&& classval
)
4480 if (current_scope () == current_function_decl
4481 && ! hack_decl_function_context (current_function_decl
))
4482 /* Not in a nested function. */
4486 /* This is incredibly horrible. The whole concept of
4487 IDENTIFIER_LOCAL_VALUE / IDENTIFIER_CLASS_VALUE /
4488 IDENTIFIER_GLOBAL_VALUE needs to be scrapped for local
4490 tree lctx
= hack_decl_function_context (locval
);
4491 tree cctx
= hack_decl_function_context (classval
);
4493 if (lctx
== current_scope ())
4495 else if (lctx
== cctx
)
4498 /* I don't know which is right; let's just guess for now. */
4507 val
= IDENTIFIER_GLOBAL_VALUE (name
);
4512 /* This should only warn about types used in qualified-ids. */
4513 if (from_obj
&& from_obj
!= val
)
4515 if (looking_for_typename
&& TREE_CODE (from_obj
) == TYPE_DECL
4516 && TREE_CODE (val
) == TYPE_DECL
4517 && TREE_TYPE (from_obj
) != TREE_TYPE (val
))
4519 cp_pedwarn ("lookup of `%D' in the scope of `%#T' (`%#T')",
4520 name
, got_object
, TREE_TYPE (from_obj
));
4521 cp_pedwarn (" does not match lookup in the current scope (`%#T')",
4528 if ((TREE_CODE (val
) == TEMPLATE_DECL
&& looking_for_template
)
4529 || TREE_CODE (val
) == TYPE_DECL
|| prefer_type
<= 0)
4531 else if (IDENTIFIER_HAS_TYPE_VALUE (name
))
4532 val
= TYPE_MAIN_DECL (IDENTIFIER_TYPE_VALUE (name
));
4533 else if (TREE_TYPE (val
) == error_mark_node
)
4534 val
= error_mark_node
;
4543 lookup_name_nonclass (name
)
4546 return lookup_name_real (name
, 0, 1);
4550 lookup_name (name
, prefer_type
)
4554 return lookup_name_real (name
, prefer_type
, 0);
4557 /* Similar to `lookup_name' but look only at current binding level. */
4560 lookup_name_current_level (name
)
4563 register tree t
= NULL_TREE
;
4565 if (current_binding_level
== global_binding_level
)
4567 t
= IDENTIFIER_GLOBAL_VALUE (name
);
4569 /* extern "C" function() */
4570 if (t
!= NULL_TREE
&& TREE_CODE (t
) == TREE_LIST
)
4573 else if (IDENTIFIER_LOCAL_VALUE (name
) != NULL_TREE
)
4575 struct binding_level
*b
= current_binding_level
;
4578 for (t
= b
->names
; t
; t
= TREE_CHAIN (t
))
4579 if (DECL_NAME (t
) == name
|| DECL_ASSEMBLER_NAME (t
) == name
)
4593 /* Arrange for the user to get a source line number, even when the
4594 compiler is going down in flames, so that she at least has a
4595 chance of working around problems in the compiler. We used to
4596 call error(), but that let the segmentation fault continue
4597 through; now, it's much more passive by asking them to send the
4598 maintainers mail about the problem. */
4604 signal (SIGSEGV
, SIG_DFL
);
4606 signal (SIGIOT
, SIG_DFL
);
4609 signal (SIGILL
, SIG_DFL
);
4612 signal (SIGABRT
, SIG_DFL
);
4615 signal (SIGBUS
, SIG_DFL
);
4617 my_friendly_abort (0);
4621 /* Unused -- brendan 970107 */
4622 /* Array for holding types considered "built-in". These types
4623 are output in the module in which `main' is defined. */
4624 static tree
*builtin_type_tdescs_arr
;
4625 static int builtin_type_tdescs_len
, builtin_type_tdescs_max
;
4628 /* Push the declarations of builtin types into the namespace.
4629 RID_INDEX, if < RID_MAX is the index of the builtin type
4630 in the array RID_POINTERS. NAME is the name used when looking
4631 up the builtin type. TYPE is the _TYPE node for the builtin type. */
4634 record_builtin_type (rid_index
, name
, type
)
4639 tree rname
= NULL_TREE
, tname
= NULL_TREE
;
4642 if ((int) rid_index
< (int) RID_MAX
)
4643 rname
= ridpointers
[(int) rid_index
];
4645 tname
= get_identifier (name
);
4647 TYPE_BUILT_IN (type
) = 1;
4651 tdecl
= pushdecl (build_decl (TYPE_DECL
, tname
, type
));
4652 set_identifier_type_value (tname
, NULL_TREE
);
4653 if ((int) rid_index
< (int) RID_MAX
)
4654 IDENTIFIER_GLOBAL_VALUE (tname
) = tdecl
;
4656 if (rname
!= NULL_TREE
)
4658 if (tname
!= NULL_TREE
)
4660 set_identifier_type_value (rname
, NULL_TREE
);
4661 IDENTIFIER_GLOBAL_VALUE (rname
) = tdecl
;
4665 tdecl
= pushdecl (build_decl (TYPE_DECL
, rname
, type
));
4666 set_identifier_type_value (rname
, NULL_TREE
);
4671 /* Push overloaded decl, in global scope, with one argument so it
4672 can be used as a callback from define_function. */
4675 push_overloaded_decl_1 (x
)
4678 push_overloaded_decl (x
, 0);
4685 auto_function (name
, type
, code
)
4687 enum built_in_function code
;
4689 return define_function
4690 (IDENTIFIER_POINTER (name
), type
, code
, push_overloaded_decl_1
,
4691 IDENTIFIER_POINTER (build_decl_overload (name
, TYPE_ARG_TYPES (type
),
4695 /* Create the predefined scalar types of C,
4696 and some nodes representing standard constants (0, 1, (void *)0).
4697 Initialize the global binding level.
4698 Make definitions for built-in primitive functions. */
4701 init_decl_processing ()
4704 register tree endlink
, int_endlink
, double_endlink
, unsigned_endlink
;
4706 /* Data type of memcpy. */
4707 tree memcpy_ftype
, strlen_ftype
;
4708 int wchar_type_size
;
4710 tree array_domain_type
;
4711 extern int flag_strict_prototype
;
4712 tree vb_off_identifier
;
4713 /* Function type `char *(char *, char *)' and similar ones */
4714 tree string_ftype_ptr_ptr
, int_ftype_string_string
;
4715 tree sizetype_endlink
;
4716 tree ptr_ftype
, ptr_ftype_unsigned
, ptr_ftype_sizetype
;
4717 tree void_ftype
, void_ftype_int
, void_ftype_ptr
;
4719 /* Have to make these distinct before we try using them. */
4720 lang_name_cplusplus
= get_identifier ("C++");
4721 lang_name_c
= get_identifier ("C");
4723 if (flag_strict_prototype
== 2)
4726 strict_prototypes_lang_c
= strict_prototypes_lang_cplusplus
;
4729 strict_prototypes_lang_c
= flag_strict_prototype
;
4732 current_lang_name
= lang_name_c
;
4734 current_function_decl
= NULL_TREE
;
4735 named_labels
= NULL_TREE
;
4736 named_label_uses
= NULL
;
4737 current_binding_level
= NULL_BINDING_LEVEL
;
4738 free_binding_level
= NULL_BINDING_LEVEL
;
4740 #ifndef __CYGWIN32__
4741 /* Because most segmentation signals can be traced back into user
4742 code, catch them and at least give the user a chance of working
4743 around compiler bugs. */
4744 signal (SIGSEGV
, signal_catch
);
4746 /* We will also catch aborts in the back-end through signal_catch and
4747 give the user a chance to see where the error might be, and to defeat
4748 aborts in the back-end when there have been errors previously in their
4751 signal (SIGIOT
, signal_catch
);
4754 signal (SIGILL
, signal_catch
);
4757 signal (SIGABRT
, signal_catch
);
4760 signal (SIGBUS
, signal_catch
);
4762 #else /* ndef __CYGWIN32__ */
4763 /* Cygwin32 cannot handle catching signals other than
4764 SIGABRT yet. We hope this will cease to be the case soon. */
4766 signal (SIGABRT
, signal_catch
);
4768 #endif /* ndef __CYGWIN32__ */
4770 gcc_obstack_init (&decl_obstack
);
4772 /* Must lay these out before anything else gets laid out. */
4773 error_mark_node
= make_node (ERROR_MARK
);
4774 TREE_PERMANENT (error_mark_node
) = 1;
4775 TREE_TYPE (error_mark_node
) = error_mark_node
;
4776 error_mark_list
= build_tree_list (error_mark_node
, error_mark_node
);
4777 TREE_TYPE (error_mark_list
) = error_mark_node
;
4779 /* Make the binding_level structure for global names. */
4781 global_binding_level
= current_binding_level
;
4783 this_identifier
= get_identifier (THIS_NAME
);
4784 in_charge_identifier
= get_identifier (IN_CHARGE_NAME
);
4785 ctor_identifier
= get_identifier (CTOR_NAME
);
4786 dtor_identifier
= get_identifier (DTOR_NAME
);
4787 pfn_identifier
= get_identifier (VTABLE_PFN_NAME
);
4788 index_identifier
= get_identifier (VTABLE_INDEX_NAME
);
4789 delta_identifier
= get_identifier (VTABLE_DELTA_NAME
);
4790 delta2_identifier
= get_identifier (VTABLE_DELTA2_NAME
);
4791 pfn_or_delta2_identifier
= get_identifier ("__pfn_or_delta2");
4792 if (flag_handle_signatures
)
4794 tag_identifier
= get_identifier (SIGTABLE_TAG_NAME
);
4795 vb_off_identifier
= get_identifier (SIGTABLE_VB_OFF_NAME
);
4796 vt_off_identifier
= get_identifier (SIGTABLE_VT_OFF_NAME
);
4799 /* Define `int' and `char' first so that dbx will output them first. */
4801 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
4802 record_builtin_type (RID_INT
, NULL_PTR
, integer_type_node
);
4804 /* Define `char', which is like either `signed char' or `unsigned char'
4805 but not the same as either. */
4809 ? make_signed_type (CHAR_TYPE_SIZE
)
4810 : make_unsigned_type (CHAR_TYPE_SIZE
));
4811 record_builtin_type (RID_CHAR
, "char", char_type_node
);
4813 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
4814 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
4816 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
4817 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
4819 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
4820 record_builtin_type (RID_MAX
, "long unsigned int", long_unsigned_type_node
);
4821 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
4823 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
4824 record_builtin_type (RID_MAX
, "long long int", long_long_integer_type_node
);
4826 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
4827 record_builtin_type (RID_MAX
, "long long unsigned int",
4828 long_long_unsigned_type_node
);
4829 record_builtin_type (RID_MAX
, "long long unsigned",
4830 long_long_unsigned_type_node
);
4832 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
4833 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
4834 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
4835 record_builtin_type (RID_MAX
, "short unsigned int", short_unsigned_type_node
);
4836 record_builtin_type (RID_MAX
, "unsigned short", short_unsigned_type_node
);
4838 /* `unsigned long' is the standard type for sizeof.
4839 Note that stddef.h uses `unsigned long',
4840 and this must agree, even of long and int are the same size. */
4842 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE
)));
4845 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE
)));
4847 TREE_TYPE (TYPE_SIZE (integer_type_node
)) = sizetype
;
4848 TREE_TYPE (TYPE_SIZE (char_type_node
)) = sizetype
;
4849 TREE_TYPE (TYPE_SIZE (unsigned_type_node
)) = sizetype
;
4850 TREE_TYPE (TYPE_SIZE (long_unsigned_type_node
)) = sizetype
;
4851 TREE_TYPE (TYPE_SIZE (long_integer_type_node
)) = sizetype
;
4852 TREE_TYPE (TYPE_SIZE (long_long_integer_type_node
)) = sizetype
;
4853 TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node
)) = sizetype
;
4854 TREE_TYPE (TYPE_SIZE (short_integer_type_node
)) = sizetype
;
4855 TREE_TYPE (TYPE_SIZE (short_unsigned_type_node
)) = sizetype
;
4857 /* Define both `signed char' and `unsigned char'. */
4858 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
4859 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
4860 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
4861 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
4863 /* These are types that type_for_size and type_for_mode use. */
4864 intQI_type_node
= make_signed_type (GET_MODE_BITSIZE (QImode
));
4865 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intQI_type_node
));
4866 intHI_type_node
= make_signed_type (GET_MODE_BITSIZE (HImode
));
4867 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intHI_type_node
));
4868 intSI_type_node
= make_signed_type (GET_MODE_BITSIZE (SImode
));
4869 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intSI_type_node
));
4870 intDI_type_node
= make_signed_type (GET_MODE_BITSIZE (DImode
));
4871 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intDI_type_node
));
4872 unsigned_intQI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (QImode
));
4873 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intQI_type_node
));
4874 unsigned_intHI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (HImode
));
4875 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intHI_type_node
));
4876 unsigned_intSI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (SImode
));
4877 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intSI_type_node
));
4878 unsigned_intDI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (DImode
));
4879 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intDI_type_node
));
4881 float_type_node
= make_node (REAL_TYPE
);
4882 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
4883 record_builtin_type (RID_FLOAT
, NULL_PTR
, float_type_node
);
4884 layout_type (float_type_node
);
4886 double_type_node
= make_node (REAL_TYPE
);
4887 if (flag_short_double
)
4888 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
4890 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
4891 record_builtin_type (RID_DOUBLE
, NULL_PTR
, double_type_node
);
4892 layout_type (double_type_node
);
4894 long_double_type_node
= make_node (REAL_TYPE
);
4895 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
4896 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
4897 layout_type (long_double_type_node
);
4899 complex_integer_type_node
= make_node (COMPLEX_TYPE
);
4900 pushdecl (build_decl (TYPE_DECL
, get_identifier ("complex int"),
4901 complex_integer_type_node
));
4902 TREE_TYPE (complex_integer_type_node
) = integer_type_node
;
4903 layout_type (complex_integer_type_node
);
4905 complex_float_type_node
= make_node (COMPLEX_TYPE
);
4906 pushdecl (build_decl (TYPE_DECL
, get_identifier ("complex float"),
4907 complex_float_type_node
));
4908 TREE_TYPE (complex_float_type_node
) = float_type_node
;
4909 layout_type (complex_float_type_node
);
4911 complex_double_type_node
= make_node (COMPLEX_TYPE
);
4912 pushdecl (build_decl (TYPE_DECL
, get_identifier ("complex double"),
4913 complex_double_type_node
));
4914 TREE_TYPE (complex_double_type_node
) = double_type_node
;
4915 layout_type (complex_double_type_node
);
4917 complex_long_double_type_node
= make_node (COMPLEX_TYPE
);
4918 pushdecl (build_decl (TYPE_DECL
, get_identifier ("complex long double"),
4919 complex_long_double_type_node
));
4920 TREE_TYPE (complex_long_double_type_node
) = long_double_type_node
;
4921 layout_type (complex_long_double_type_node
);
4923 integer_zero_node
= build_int_2 (0, 0);
4924 TREE_TYPE (integer_zero_node
) = integer_type_node
;
4925 integer_one_node
= build_int_2 (1, 0);
4926 TREE_TYPE (integer_one_node
) = integer_type_node
;
4927 integer_two_node
= build_int_2 (2, 0);
4928 TREE_TYPE (integer_two_node
) = integer_type_node
;
4929 integer_three_node
= build_int_2 (3, 0);
4930 TREE_TYPE (integer_three_node
) = integer_type_node
;
4932 boolean_type_node
= make_unsigned_type (BOOL_TYPE_SIZE
);
4933 TREE_SET_CODE (boolean_type_node
, BOOLEAN_TYPE
);
4934 record_builtin_type (RID_BOOL
, "bool", boolean_type_node
);
4935 boolean_false_node
= build_int_2 (0, 0);
4936 TREE_TYPE (boolean_false_node
) = boolean_type_node
;
4937 boolean_true_node
= build_int_2 (1, 0);
4938 TREE_TYPE (boolean_true_node
) = boolean_type_node
;
4940 /* These are needed by stor-layout.c. */
4941 size_zero_node
= size_int (0);
4942 size_one_node
= size_int (1);
4944 signed_size_zero_node
= build_int_2 (0, 0);
4945 TREE_TYPE (signed_size_zero_node
) = make_signed_type (TYPE_PRECISION (sizetype
));
4947 void_type_node
= make_node (VOID_TYPE
);
4948 record_builtin_type (RID_VOID
, NULL_PTR
, void_type_node
);
4949 layout_type (void_type_node
); /* Uses integer_zero_node. */
4950 void_list_node
= build_tree_list (NULL_TREE
, void_type_node
);
4951 TREE_PARMLIST (void_list_node
) = 1;
4953 null_pointer_node
= build_int_2 (0, 0);
4954 TREE_TYPE (null_pointer_node
) = build_pointer_type (void_type_node
);
4955 layout_type (TREE_TYPE (null_pointer_node
));
4958 TREE_TYPE (null_node
) = type_for_size (POINTER_SIZE
, 0);
4960 TREE_TYPE (null_node
) = build_pointer_type (void_type_node
);
4962 /* Used for expressions that do nothing, but are not errors. */
4963 void_zero_node
= build_int_2 (0, 0);
4964 TREE_TYPE (void_zero_node
) = void_type_node
;
4966 string_type_node
= build_pointer_type (char_type_node
);
4967 const_string_type_node
4968 = build_pointer_type (build_type_variant (char_type_node
, 1, 0));
4970 record_builtin_type (RID_MAX
, NULL_PTR
, string_type_node
);
4973 /* Make a type to be the domain of a few array types
4974 whose domains don't really matter.
4975 200 is small enough that it always fits in size_t
4976 and large enough that it can hold most function names for the
4977 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4978 array_domain_type
= build_index_type (build_int_2 (200, 0));
4980 /* make a type for arrays of characters.
4981 With luck nothing will ever really depend on the length of this
4983 char_array_type_node
4984 = build_array_type (char_type_node
, array_domain_type
);
4985 /* Likewise for arrays of ints. */
4987 = build_array_type (integer_type_node
, array_domain_type
);
4989 /* This is just some anonymous class type. Nobody should ever
4990 need to look inside this envelope. */
4991 class_star_type_node
= build_pointer_type (make_lang_type (RECORD_TYPE
));
4993 default_function_type
4994 = build_function_type (integer_type_node
, NULL_TREE
);
4996 ptr_type_node
= build_pointer_type (void_type_node
);
4998 = build_pointer_type (build_type_variant (void_type_node
, 1, 0));
5000 record_builtin_type (RID_MAX
, NULL_PTR
, ptr_type_node
);
5002 endlink
= void_list_node
;
5003 int_endlink
= tree_cons (NULL_TREE
, integer_type_node
, endlink
);
5004 double_endlink
= tree_cons (NULL_TREE
, double_type_node
, endlink
);
5005 unsigned_endlink
= tree_cons (NULL_TREE
, unsigned_type_node
, endlink
);
5007 ptr_ftype
= build_function_type (ptr_type_node
, NULL_TREE
);
5008 ptr_ftype_unsigned
= build_function_type (ptr_type_node
, unsigned_endlink
);
5009 sizetype_endlink
= tree_cons (NULL_TREE
, sizetype
, endlink
);
5010 /* We realloc here because sizetype could be int or unsigned. S'ok. */
5011 ptr_ftype_sizetype
= build_function_type (ptr_type_node
, sizetype_endlink
);
5013 void_ftype
= build_function_type (void_type_node
, endlink
);
5014 void_ftype_int
= build_function_type (void_type_node
, int_endlink
);
5016 = build_function_type (void_type_node
,
5017 tree_cons (NULL_TREE
, ptr_type_node
, endlink
));
5019 = build_exception_variant (void_ftype_ptr
,
5020 tree_cons (NULL_TREE
, NULL_TREE
, NULL_TREE
));
5023 = build_function_type (float_type_node
,
5024 tree_cons (NULL_TREE
, float_type_node
, endlink
));
5027 = build_function_type (double_type_node
, double_endlink
);
5029 ldouble_ftype_ldouble
5030 = build_function_type (long_double_type_node
,
5031 tree_cons (NULL_TREE
, long_double_type_node
,
5034 double_ftype_double_double
5035 = build_function_type (double_type_node
,
5036 tree_cons (NULL_TREE
, double_type_node
,
5040 = build_function_type (integer_type_node
, int_endlink
);
5043 = build_function_type (long_integer_type_node
,
5044 tree_cons (NULL_TREE
, long_integer_type_node
,
5047 int_ftype_cptr_cptr_sizet
5048 = build_function_type (integer_type_node
,
5049 tree_cons (NULL_TREE
, const_ptr_type_node
,
5050 tree_cons (NULL_TREE
, const_ptr_type_node
,
5051 tree_cons (NULL_TREE
,
5055 string_ftype_ptr_ptr
/* strcpy prototype */
5056 = build_function_type (string_type_node
,
5057 tree_cons (NULL_TREE
, string_type_node
,
5058 tree_cons (NULL_TREE
,
5059 const_string_type_node
,
5062 int_ftype_string_string
/* strcmp prototype */
5063 = build_function_type (integer_type_node
,
5064 tree_cons (NULL_TREE
, const_string_type_node
,
5065 tree_cons (NULL_TREE
,
5066 const_string_type_node
,
5069 strlen_ftype
/* strlen prototype */
5070 = build_function_type (sizetype
,
5071 tree_cons (NULL_TREE
, const_string_type_node
,
5074 memcpy_ftype
/* memcpy prototype */
5075 = build_function_type (ptr_type_node
,
5076 tree_cons (NULL_TREE
, ptr_type_node
,
5077 tree_cons (NULL_TREE
, const_ptr_type_node
,
5078 sizetype_endlink
)));
5080 if (flag_huge_objects
)
5081 delta_type_node
= long_integer_type_node
;
5083 delta_type_node
= short_integer_type_node
;
5085 builtin_function ("__builtin_constant_p", int_ftype_int
,
5086 BUILT_IN_CONSTANT_P
, NULL_PTR
);
5088 builtin_return_address_fndecl
5089 = builtin_function ("__builtin_return_address", ptr_ftype_unsigned
,
5090 BUILT_IN_RETURN_ADDRESS
, NULL_PTR
);
5092 builtin_function ("__builtin_frame_address", ptr_ftype_unsigned
,
5093 BUILT_IN_FRAME_ADDRESS
, NULL_PTR
);
5095 builtin_function ("__builtin_alloca", ptr_ftype_sizetype
,
5096 BUILT_IN_ALLOCA
, "alloca");
5097 builtin_function ("__builtin_ffs", int_ftype_int
, BUILT_IN_FFS
, NULL_PTR
);
5098 /* Define alloca, ffs as builtins.
5099 Declare _exit just to mark it as volatile. */
5100 if (! flag_no_builtin
&& !flag_no_nonansi_builtin
)
5102 temp
= builtin_function ("alloca", ptr_ftype_sizetype
,
5103 BUILT_IN_ALLOCA
, NULL_PTR
);
5104 /* Suppress error if redefined as a non-function. */
5105 DECL_BUILT_IN_NONANSI (temp
) = 1;
5106 temp
= builtin_function ("ffs", int_ftype_int
, BUILT_IN_FFS
, NULL_PTR
);
5107 /* Suppress error if redefined as a non-function. */
5108 DECL_BUILT_IN_NONANSI (temp
) = 1;
5109 temp
= builtin_function ("_exit", void_ftype_int
,
5110 NOT_BUILT_IN
, NULL_PTR
);
5111 TREE_THIS_VOLATILE (temp
) = 1;
5112 TREE_SIDE_EFFECTS (temp
) = 1;
5113 /* Suppress error if redefined as a non-function. */
5114 DECL_BUILT_IN_NONANSI (temp
) = 1;
5117 builtin_function ("__builtin_abs", int_ftype_int
, BUILT_IN_ABS
, NULL_PTR
);
5118 builtin_function ("__builtin_fabsf", float_ftype_float
, BUILT_IN_FABS
,
5120 builtin_function ("__builtin_fabs", double_ftype_double
, BUILT_IN_FABS
,
5122 builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble
, BUILT_IN_FABS
,
5124 builtin_function ("__builtin_labs", long_ftype_long
,
5125 BUILT_IN_LABS
, NULL_PTR
);
5126 builtin_function ("__builtin_saveregs", ptr_ftype
,
5127 BUILT_IN_SAVEREGS
, NULL_PTR
);
5128 builtin_function ("__builtin_classify_type", default_function_type
,
5129 BUILT_IN_CLASSIFY_TYPE
, NULL_PTR
);
5130 builtin_function ("__builtin_next_arg", ptr_ftype
,
5131 BUILT_IN_NEXT_ARG
, NULL_PTR
);
5132 builtin_function ("__builtin_args_info", int_ftype_int
,
5133 BUILT_IN_ARGS_INFO
, NULL_PTR
);
5134 builtin_function ("__builtin_setjmp",
5135 build_function_type (integer_type_node
,
5136 tree_cons (NULL_TREE
, ptr_type_node
,
5138 BUILT_IN_SETJMP
, NULL_PTR
);
5139 builtin_function ("__builtin_longjmp",
5140 build_function_type (integer_type_node
,
5141 tree_cons (NULL_TREE
, ptr_type_node
,
5142 tree_cons (NULL_TREE
,
5145 BUILT_IN_LONGJMP
, NULL_PTR
);
5147 /* Untyped call and return. */
5148 builtin_function ("__builtin_apply_args", ptr_ftype
,
5149 BUILT_IN_APPLY_ARGS
, NULL_PTR
);
5151 temp
= tree_cons (NULL_TREE
,
5152 build_pointer_type (build_function_type (void_type_node
,
5154 ptr_ftype_sizetype
);
5155 builtin_function ("__builtin_apply",
5156 build_function_type (ptr_type_node
, temp
),
5157 BUILT_IN_APPLY
, NULL_PTR
);
5158 builtin_function ("__builtin_return", void_ftype_ptr
,
5159 BUILT_IN_RETURN
, NULL_PTR
);
5161 /* Currently under experimentation. */
5162 builtin_function ("__builtin_memcpy", memcpy_ftype
,
5163 BUILT_IN_MEMCPY
, "memcpy");
5164 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet
,
5165 BUILT_IN_MEMCMP
, "memcmp");
5166 builtin_function ("__builtin_strcmp", int_ftype_string_string
,
5167 BUILT_IN_STRCMP
, "strcmp");
5168 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr
,
5169 BUILT_IN_STRCPY
, "strcpy");
5170 builtin_function ("__builtin_strlen", strlen_ftype
,
5171 BUILT_IN_STRLEN
, "strlen");
5172 builtin_function ("__builtin_sqrtf", float_ftype_float
,
5173 BUILT_IN_FSQRT
, "sqrtf");
5174 builtin_function ("__builtin_fsqrt", double_ftype_double
,
5175 BUILT_IN_FSQRT
, NULL_PTR
);
5176 builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble
,
5177 BUILT_IN_FSQRT
, "sqrtl");
5178 builtin_function ("__builtin_sinf", float_ftype_float
,
5179 BUILT_IN_SIN
, "sinf");
5180 builtin_function ("__builtin_sin", double_ftype_double
,
5181 BUILT_IN_SIN
, "sin");
5182 builtin_function ("__builtin_sinl", ldouble_ftype_ldouble
,
5183 BUILT_IN_SIN
, "sinl");
5184 builtin_function ("__builtin_cosf", float_ftype_float
,
5185 BUILT_IN_COS
, "cosf");
5186 builtin_function ("__builtin_cos", double_ftype_double
,
5187 BUILT_IN_COS
, "cos");
5188 builtin_function ("__builtin_cosl", ldouble_ftype_ldouble
,
5189 BUILT_IN_COS
, "cosl");
5191 if (!flag_no_builtin
)
5193 #if 0 /* These do not work well with libg++. */
5194 builtin_function ("abs", int_ftype_int
, BUILT_IN_ABS
, NULL_PTR
);
5195 builtin_function ("fabs", double_ftype_double
, BUILT_IN_FABS
, NULL_PTR
);
5196 builtin_function ("labs", long_ftype_long
, BUILT_IN_LABS
, NULL_PTR
);
5198 builtin_function ("fabsf", float_ftype_float
, BUILT_IN_FABS
, NULL_PTR
);
5199 builtin_function ("fabsl", ldouble_ftype_ldouble
, BUILT_IN_FABS
,
5201 builtin_function ("memcpy", memcpy_ftype
, BUILT_IN_MEMCPY
, NULL_PTR
);
5202 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet
, BUILT_IN_MEMCMP
,
5204 builtin_function ("strcmp", int_ftype_string_string
, BUILT_IN_STRCMP
,
5206 builtin_function ("strcpy", string_ftype_ptr_ptr
, BUILT_IN_STRCPY
,
5208 builtin_function ("strlen", strlen_ftype
, BUILT_IN_STRLEN
, NULL_PTR
);
5209 builtin_function ("sqrtf", float_ftype_float
, BUILT_IN_FSQRT
, NULL_PTR
);
5210 builtin_function ("sqrt", double_ftype_double
, BUILT_IN_FSQRT
, NULL_PTR
);
5211 builtin_function ("sqrtl", ldouble_ftype_ldouble
, BUILT_IN_FSQRT
,
5213 builtin_function ("sinf", float_ftype_float
, BUILT_IN_SIN
, NULL_PTR
);
5214 builtin_function ("sin", double_ftype_double
, BUILT_IN_SIN
, NULL_PTR
);
5215 builtin_function ("sinl", ldouble_ftype_ldouble
, BUILT_IN_SIN
, NULL_PTR
);
5216 builtin_function ("cosf", float_ftype_float
, BUILT_IN_COS
, NULL_PTR
);
5217 builtin_function ("cos", double_ftype_double
, BUILT_IN_COS
, NULL_PTR
);
5218 builtin_function ("cosl", ldouble_ftype_ldouble
, BUILT_IN_COS
, NULL_PTR
);
5220 /* Declare these functions volatile
5221 to avoid spurious "control drops through" warnings. */
5222 temp
= builtin_function ("abort", void_ftype
,
5223 NOT_BUILT_IN
, NULL_PTR
);
5224 TREE_THIS_VOLATILE (temp
) = 1;
5225 TREE_SIDE_EFFECTS (temp
) = 1;
5226 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
5228 DECL_BUILT_IN_NONANSI (temp
) = 1;
5229 temp
= builtin_function ("exit", void_ftype_int
,
5230 NOT_BUILT_IN
, NULL_PTR
);
5231 TREE_THIS_VOLATILE (temp
) = 1;
5232 TREE_SIDE_EFFECTS (temp
) = 1;
5233 DECL_BUILT_IN_NONANSI (temp
) = 1;
5237 /* Support for these has not been written in either expand_builtin
5238 or build_function_call. */
5239 builtin_function ("__builtin_div", default_ftype
, BUILT_IN_DIV
, NULL_PTR
);
5240 builtin_function ("__builtin_ldiv", default_ftype
, BUILT_IN_LDIV
, NULL_PTR
);
5241 builtin_function ("__builtin_ffloor", double_ftype_double
, BUILT_IN_FFLOOR
,
5243 builtin_function ("__builtin_fceil", double_ftype_double
, BUILT_IN_FCEIL
,
5245 builtin_function ("__builtin_fmod", double_ftype_double_double
,
5246 BUILT_IN_FMOD
, NULL_PTR
);
5247 builtin_function ("__builtin_frem", double_ftype_double_double
,
5248 BUILT_IN_FREM
, NULL_PTR
);
5249 builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int
,
5250 BUILT_IN_MEMSET
, NULL_PTR
);
5251 builtin_function ("__builtin_getexp", double_ftype_double
, BUILT_IN_GETEXP
,
5253 builtin_function ("__builtin_getman", double_ftype_double
, BUILT_IN_GETMAN
,
5257 /* C++ extensions */
5259 unknown_type_node
= make_node (UNKNOWN_TYPE
);
5260 decl
= pushdecl (build_decl (TYPE_DECL
, get_identifier ("unknown type"),
5261 unknown_type_node
));
5262 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
5263 DECL_IGNORED_P (decl
) = 1;
5264 TYPE_DECL_SUPPRESS_DEBUG (decl
) = 1;
5265 TYPE_SIZE (unknown_type_node
) = TYPE_SIZE (void_type_node
);
5266 TYPE_ALIGN (unknown_type_node
) = 1;
5267 TYPE_MODE (unknown_type_node
) = TYPE_MODE (void_type_node
);
5268 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
5269 TREE_TYPE (unknown_type_node
) = unknown_type_node
;
5270 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
5271 TYPE_POINTER_TO (unknown_type_node
) = unknown_type_node
;
5272 TYPE_REFERENCE_TO (unknown_type_node
) = unknown_type_node
;
5274 /* This is for handling opaque types in signatures. */
5275 opaque_type_node
= copy_node (ptr_type_node
);
5276 TYPE_MAIN_VARIANT (opaque_type_node
) = opaque_type_node
;
5277 record_builtin_type (RID_MAX
, 0, opaque_type_node
);
5279 /* This is special for C++ so functions can be overloaded. */
5281 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE
)));
5282 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
5283 signed_wchar_type_node
= make_signed_type (wchar_type_size
);
5284 unsigned_wchar_type_node
= make_unsigned_type (wchar_type_size
);
5286 = TREE_UNSIGNED (wchar_type_node
)
5287 ? unsigned_wchar_type_node
5288 : signed_wchar_type_node
;
5289 record_builtin_type (RID_WCHAR
, "__wchar_t", wchar_type_node
);
5291 /* Artificial declaration of wchar_t -- can be bashed */
5292 wchar_decl_node
= build_decl (TYPE_DECL
, get_identifier ("wchar_t"),
5294 pushdecl (wchar_decl_node
);
5296 /* This is for wide string constants. */
5297 wchar_array_type_node
5298 = build_array_type (wchar_type_node
, array_domain_type
);
5300 if (flag_vtable_thunks
)
5302 /* Make sure we get a unique function type, so we can give
5303 its pointer type a name. (This wins for gdb.) */
5304 tree vfunc_type
= make_node (FUNCTION_TYPE
);
5305 TREE_TYPE (vfunc_type
) = integer_type_node
;
5306 TYPE_ARG_TYPES (vfunc_type
) = NULL_TREE
;
5307 layout_type (vfunc_type
);
5309 vtable_entry_type
= build_pointer_type (vfunc_type
);
5313 vtable_entry_type
= make_lang_type (RECORD_TYPE
);
5314 fields
[0] = build_lang_field_decl (FIELD_DECL
, delta_identifier
,
5316 fields
[1] = build_lang_field_decl (FIELD_DECL
, index_identifier
,
5318 fields
[2] = build_lang_field_decl (FIELD_DECL
, pfn_identifier
,
5320 finish_builtin_type (vtable_entry_type
, VTBL_PTR_TYPE
, fields
, 2,
5323 /* Make this part of an invisible union. */
5324 fields
[3] = copy_node (fields
[2]);
5325 TREE_TYPE (fields
[3]) = delta_type_node
;
5326 DECL_NAME (fields
[3]) = delta2_identifier
;
5327 DECL_MODE (fields
[3]) = TYPE_MODE (delta_type_node
);
5328 DECL_SIZE (fields
[3]) = TYPE_SIZE (delta_type_node
);
5329 TREE_UNSIGNED (fields
[3]) = 0;
5330 TREE_CHAIN (fields
[2]) = fields
[3];
5331 vtable_entry_type
= build_type_variant (vtable_entry_type
, 1, 0);
5333 record_builtin_type (RID_MAX
, VTBL_PTR_TYPE
, vtable_entry_type
);
5336 = build_array_type (vtable_entry_type
, NULL_TREE
);
5337 layout_type (vtbl_type_node
);
5338 vtbl_type_node
= cp_build_type_variant (vtbl_type_node
, 1, 0);
5339 record_builtin_type (RID_MAX
, NULL_PTR
, vtbl_type_node
);
5341 /* Simplify life by making a "sigtable_entry_type". Give its
5342 fields names so that the debugger can use them. */
5344 if (flag_handle_signatures
)
5346 sigtable_entry_type
= make_lang_type (RECORD_TYPE
);
5347 fields
[0] = build_lang_field_decl (FIELD_DECL
, tag_identifier
,
5349 fields
[1] = build_lang_field_decl (FIELD_DECL
, vb_off_identifier
,
5351 fields
[2] = build_lang_field_decl (FIELD_DECL
, delta_identifier
,
5353 fields
[3] = build_lang_field_decl (FIELD_DECL
, index_identifier
,
5355 fields
[4] = build_lang_field_decl (FIELD_DECL
, pfn_identifier
,
5358 /* Set the alignment to the max of the alignment of ptr_type_node and
5359 delta_type_node. Double alignment wastes a word on the Sparc. */
5360 finish_builtin_type (sigtable_entry_type
, SIGTABLE_PTR_TYPE
, fields
, 4,
5361 (TYPE_ALIGN (ptr_type_node
) > TYPE_ALIGN (delta_type_node
))
5365 /* Make this part of an invisible union. */
5366 fields
[5] = copy_node (fields
[4]);
5367 TREE_TYPE (fields
[5]) = delta_type_node
;
5368 DECL_NAME (fields
[5]) = vt_off_identifier
;
5369 DECL_MODE (fields
[5]) = TYPE_MODE (delta_type_node
);
5370 DECL_SIZE (fields
[5]) = TYPE_SIZE (delta_type_node
);
5371 TREE_UNSIGNED (fields
[5]) = 0;
5372 TREE_CHAIN (fields
[4]) = fields
[5];
5374 sigtable_entry_type
= build_type_variant (sigtable_entry_type
, 1, 0);
5375 record_builtin_type (RID_MAX
, SIGTABLE_PTR_TYPE
, sigtable_entry_type
);
5378 std_node
= build_decl (NAMESPACE_DECL
, get_identifier ("std"),
5380 pushdecl (std_node
);
5385 /* Must build __t_desc type. Currently, type descriptors look like this:
5392 struct __t_desc *points_to;
5393 int ivars_count, meths_count;
5394 struct __i_desc *ivars[];
5395 struct __m_desc *meths[];
5396 struct __t_desc *parents[];
5397 struct __t_desc *vbases[];
5401 ...as per Linton's paper. */
5403 __t_desc_type_node
= make_lang_type (RECORD_TYPE
);
5404 __i_desc_type_node
= make_lang_type (RECORD_TYPE
);
5405 __m_desc_type_node
= make_lang_type (RECORD_TYPE
);
5407 = build_array_type (build_pointer_type (__t_desc_type_node
),
5410 = build_array_type (build_pointer_type (__i_desc_type_node
),
5413 = build_array_type (build_pointer_type (__m_desc_type_node
),
5416 fields
[0] = build_lang_field_decl (FIELD_DECL
, get_identifier ("name"),
5418 fields
[1] = build_lang_field_decl (FIELD_DECL
, get_identifier ("size"),
5419 unsigned_type_node
);
5420 fields
[2] = build_lang_field_decl (FIELD_DECL
, get_identifier ("bits"),
5421 unsigned_type_node
);
5422 fields
[3] = build_lang_field_decl (FIELD_DECL
,
5423 get_identifier ("points_to"),
5424 build_pointer_type (__t_desc_type_node
));
5425 fields
[4] = build_lang_field_decl (FIELD_DECL
,
5426 get_identifier ("ivars_count"),
5428 fields
[5] = build_lang_field_decl (FIELD_DECL
,
5429 get_identifier ("meths_count"),
5431 fields
[6] = build_lang_field_decl (FIELD_DECL
, get_identifier ("ivars"),
5432 build_pointer_type (__i_desc_array_type
));
5433 fields
[7] = build_lang_field_decl (FIELD_DECL
, get_identifier ("meths"),
5434 build_pointer_type (__m_desc_array_type
));
5435 fields
[8] = build_lang_field_decl (FIELD_DECL
, get_identifier ("parents"),
5436 build_pointer_type (__t_desc_array_type
));
5437 fields
[9] = build_lang_field_decl (FIELD_DECL
, get_identifier ("vbases"),
5438 build_pointer_type (__t_desc_array_type
));
5439 fields
[10] = build_lang_field_decl (FIELD_DECL
, get_identifier ("offsets"),
5440 build_pointer_type (integer_type_node
));
5441 finish_builtin_type (__t_desc_type_node
, "__t_desc", fields
, 10, integer_type_node
);
5443 /* ivar descriptors look like this:
5449 struct __t_desc *type;
5453 fields
[0] = build_lang_field_decl (FIELD_DECL
, get_identifier ("name"),
5455 fields
[1] = build_lang_field_decl (FIELD_DECL
, get_identifier ("offset"),
5457 fields
[2] = build_lang_field_decl (FIELD_DECL
, get_identifier ("type"),
5458 build_pointer_type (__t_desc_type_node
));
5459 finish_builtin_type (__i_desc_type_node
, "__i_desc", fields
, 2,
5462 /* method descriptors look like this:
5468 struct __t_desc *vcontext;
5469 struct __t_desc *return_type;
5472 short required_parms;
5473 struct __t_desc *parm_types[];
5477 fields
[0] = build_lang_field_decl (FIELD_DECL
, get_identifier ("name"),
5479 fields
[1] = build_lang_field_decl (FIELD_DECL
, get_identifier ("vindex"),
5481 fields
[2] = build_lang_field_decl (FIELD_DECL
, get_identifier ("vcontext"),
5482 build_pointer_type (__t_desc_type_node
));
5483 fields
[3] = build_lang_field_decl (FIELD_DECL
, get_identifier ("return_type"),
5484 build_pointer_type (__t_desc_type_node
));
5485 fields
[4] = build_lang_field_decl (FIELD_DECL
, get_identifier ("address"),
5486 build_pointer_type (default_function_type
));
5487 fields
[5] = build_lang_field_decl (FIELD_DECL
, get_identifier ("parm_count"),
5488 short_integer_type_node
);
5489 fields
[6] = build_lang_field_decl (FIELD_DECL
, get_identifier ("required_parms"),
5490 short_integer_type_node
);
5491 fields
[7] = build_lang_field_decl (FIELD_DECL
, get_identifier ("parm_types"),
5492 build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node
), NULL_TREE
)));
5493 finish_builtin_type (__m_desc_type_node
, "__m_desc", fields
, 7,
5496 #endif /*flag_rtti*/
5499 current_lang_name
= lang_name_cplusplus
;
5501 auto_function (ansi_opname
[(int) NEW_EXPR
], ptr_ftype_sizetype
,
5503 auto_function (ansi_opname
[(int) VEC_NEW_EXPR
], ptr_ftype_sizetype
,
5505 auto_function (ansi_opname
[(int) DELETE_EXPR
], void_ftype_ptr
,
5507 auto_function (ansi_opname
[(int) VEC_DELETE_EXPR
], void_ftype_ptr
,
5511 = define_function ("__pure_virtual", void_ftype
,
5512 NOT_BUILT_IN
, 0, 0);
5514 /* Perform other language dependent initializations. */
5515 init_class_processing ();
5516 init_init_processing ();
5517 init_search_processing ();
5518 init_rtti_processing ();
5520 if (flag_exceptions
)
5521 init_exception_processing ();
5524 flag_inline_functions
= 0;
5527 if (! supports_one_only ())
5530 /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
5531 declare_function_name ();
5533 /* Prepare to check format strings against argument lists. */
5534 init_function_format_info ();
5537 /* initialize type descriptor type node of various rtti type. */
5544 tdecl
= lookup_name (get_identifier ("type_info"), 0);
5545 if (tdecl
== NULL_TREE
)
5547 __t_desc_type_node
= TREE_TYPE (tdecl
);
5549 __tp_desc_type_node
= build_pointer_type (__t_desc_type_node
);
5553 tdecl
= lookup_name (get_identifier ("__baselist_type_info"), 0);
5554 if (tdecl
== NULL_TREE
)
5556 __baselist_desc_type_node
= TREE_TYPE (tdecl
);
5559 tdecl
= lookup_name (get_identifier ("__builtin_type_info"), 0);
5560 if (tdecl
== NULL_TREE
)
5562 __bltn_desc_type_node
= TREE_TYPE (tdecl
);
5564 tdecl
= lookup_name (get_identifier ("__user_type_info"), 0);
5565 if (tdecl
== NULL_TREE
)
5567 __user_desc_type_node
= TREE_TYPE (tdecl
);
5569 tdecl
= lookup_name (get_identifier ("__class_type_info"), 0);
5570 if (tdecl
== NULL_TREE
)
5572 __class_desc_type_node
= TREE_TYPE (tdecl
);
5574 tdecl
= lookup_field (__class_desc_type_node
,
5575 get_identifier ("access_mode"), 0, 0);
5576 if (tdecl
== NULL_TREE
)
5578 __access_mode_type_node
= TREE_TYPE (tdecl
);
5580 tdecl
= lookup_name (get_identifier ("__attr_type_info"), 0);
5581 if (tdecl
== NULL_TREE
)
5583 __attr_desc_type_node
= TREE_TYPE (tdecl
);
5585 tdecl
= lookup_name (get_identifier ("__pointer_type_info"), 0);
5586 if (tdecl
== NULL_TREE
)
5588 __ptr_desc_type_node
= TREE_TYPE (tdecl
);
5590 tdecl
= lookup_name (get_identifier ("__func_type_info"), 0);
5591 if (tdecl
== NULL_TREE
)
5593 __func_desc_type_node
= TREE_TYPE (tdecl
);
5595 tdecl
= lookup_name (get_identifier ("__ptmf_type_info"), 0);
5596 if (tdecl
== NULL_TREE
)
5598 __ptmf_desc_type_node
= TREE_TYPE (tdecl
);
5600 tdecl
= lookup_name (get_identifier ("__ptmd_type_info"), 0);
5601 if (tdecl
== NULL_TREE
)
5603 __ptmd_desc_type_node
= TREE_TYPE (tdecl
);
5607 /* Make a definition for a builtin function named NAME and whose data type
5608 is TYPE. TYPE should be a function type with argument types.
5609 FUNCTION_CODE tells later passes how to compile calls to this function.
5610 See tree.h for its possible values.
5612 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
5613 the name to be called if we can't opencode the function. */
5616 define_function (name
, type
, function_code
, pfn
, library_name
)
5619 enum built_in_function function_code
;
5620 void (*pfn
) PROTO((tree
));
5623 tree decl
= build_lang_decl (FUNCTION_DECL
, get_identifier (name
), type
);
5624 DECL_EXTERNAL (decl
) = 1;
5625 TREE_PUBLIC (decl
) = 1;
5626 DECL_ARTIFICIAL (decl
) = 1;
5628 /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
5629 we cannot change DECL_ASSEMBLER_NAME until we have installed this
5630 function in the namespace. */
5631 if (pfn
) (*pfn
) (decl
);
5633 DECL_ASSEMBLER_NAME (decl
) = get_identifier (library_name
);
5634 make_function_rtl (decl
);
5635 if (function_code
!= NOT_BUILT_IN
)
5637 DECL_BUILT_IN (decl
) = 1;
5638 DECL_FUNCTION_CODE (decl
) = function_code
;
5643 /* Called when a declaration is seen that contains no names to declare.
5644 If its type is a reference to a structure, union or enum inherited
5645 from a containing scope, shadow that tag name for the current scope
5646 with a forward reference.
5647 If its type defines a new named structure or union
5648 or defines an enum, it is valid but we need not do anything here.
5649 Otherwise, it is an error.
5651 C++: may have to grok the declspecs to learn about static,
5652 complain for anonymous unions. */
5655 shadow_tag (declspecs
)
5659 tree ob_modifier
= NULL_TREE
;
5661 register enum tree_code code
, ok_code
= ERROR_MARK
;
5662 register tree t
= NULL_TREE
;
5664 for (link
= declspecs
; link
; link
= TREE_CHAIN (link
))
5666 register tree value
= TREE_VALUE (link
);
5668 code
= TREE_CODE (value
);
5669 if (IS_AGGR_TYPE_CODE (code
) || code
== ENUMERAL_TYPE
)
5671 my_friendly_assert (TYPE_MAIN_DECL (value
) != NULL_TREE
, 261);
5673 if (IS_AGGR_TYPE (value
) && CLASSTYPE_USE_TEMPLATE (value
))
5675 if (CLASSTYPE_IMPLICIT_INSTANTIATION (value
)
5676 && TYPE_SIZE (value
) == NULL_TREE
)
5678 SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (value
);
5679 if (processing_template_decl
)
5680 push_template_decl (TYPE_MAIN_DECL (value
));
5682 else if (CLASSTYPE_TEMPLATE_INSTANTIATION (value
))
5683 cp_error ("specialization after instantiation of `%T'", value
);
5690 else if (value
== ridpointers
[(int) RID_STATIC
]
5691 || value
== ridpointers
[(int) RID_EXTERN
]
5692 || value
== ridpointers
[(int) RID_AUTO
]
5693 || value
== ridpointers
[(int) RID_REGISTER
]
5694 || value
== ridpointers
[(int) RID_INLINE
]
5695 || value
== ridpointers
[(int) RID_VIRTUAL
]
5696 || value
== ridpointers
[(int) RID_EXPLICIT
])
5697 ob_modifier
= value
;
5700 /* This is where the variables in an anonymous union are
5701 declared. An anonymous union declaration looks like:
5703 because there is no declarator after the union, the parser
5704 sends that declaration here. */
5705 if (ok_code
== UNION_TYPE
5707 && ((TREE_CODE (TYPE_NAME (t
)) == IDENTIFIER_NODE
5708 && ANON_AGGRNAME_P (TYPE_NAME (t
)))
5709 || (TREE_CODE (TYPE_NAME (t
)) == TYPE_DECL
5710 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
)))))
5712 /* See also grok_x_components. */
5715 /* Wipe out memory of synthesized methods */
5716 TYPE_HAS_CONSTRUCTOR (t
) = 0;
5717 TYPE_HAS_DEFAULT_CONSTRUCTOR (t
) = 0;
5718 TYPE_HAS_INIT_REF (t
) = 0;
5719 TYPE_HAS_CONST_INIT_REF (t
) = 0;
5720 TYPE_HAS_ASSIGN_REF (t
) = 0;
5721 TYPE_HAS_ASSIGNMENT (t
) = 0;
5722 TYPE_HAS_CONST_ASSIGN_REF (t
) = 0;
5724 q
= &TYPE_METHODS (t
);
5727 if (DECL_ARTIFICIAL (*q
))
5728 *q
= TREE_CHAIN (*q
);
5730 q
= &TREE_CHAIN (*q
);
5733 /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have
5734 function members. */
5735 if (TYPE_METHODS (t
))
5736 error ("an anonymous union cannot have function members");
5738 if (TYPE_FIELDS (t
))
5740 tree decl
= grokdeclarator (NULL_TREE
, declspecs
, NORMAL
, 0,
5742 finish_anon_union (decl
);
5747 /* Anonymous unions are objects, that's why we only check for
5748 inappropriate specifiers in this branch. */
5752 if (ob_modifier
== ridpointers
[(int) RID_INLINE
]
5753 || ob_modifier
== ridpointers
[(int) RID_VIRTUAL
])
5754 cp_error ("`%D' can only be specified for functions", ob_modifier
);
5755 else if (ob_modifier
== ridpointers
[(int) RID_EXPLICIT
])
5756 cp_error ("`%D' can only be specified for constructors",
5759 cp_error ("`%D' can only be specified for objects and functions",
5764 pedwarn ("abstract declarator used as declaration");
5765 else if (found_tag
> 1)
5766 pedwarn ("multiple types in one declaration");
5770 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
5773 groktypename (typename
)
5776 if (TREE_CODE (typename
) != TREE_LIST
)
5778 return grokdeclarator (TREE_VALUE (typename
),
5779 TREE_PURPOSE (typename
),
5780 TYPENAME
, 0, NULL_TREE
);
5783 /* Decode a declarator in an ordinary declaration or data definition.
5784 This is called as soon as the type information and variable name
5785 have been parsed, before parsing the initializer if any.
5786 Here we create the ..._DECL node, fill in its type,
5787 and put it on the list of decls for the current context.
5788 The ..._DECL node is returned as the value.
5790 Exception: for arrays where the length is not specified,
5791 the type is left null, to be filled in by `cp_finish_decl'.
5793 Function definitions do not come here; they go to start_function
5794 instead. However, external and forward declarations of functions
5795 do go through here. Structure field declarations are done by
5796 grokfield and not through here. */
5798 /* Set this to zero to debug not using the temporary obstack
5799 to parse initializers. */
5800 int debug_temp_inits
= 1;
5803 start_decl (declarator
, declspecs
, initialized
)
5804 tree declarator
, declspecs
;
5808 register tree type
, tem
;
5810 extern int have_extern_spec
;
5811 extern int used_extern_spec
;
5814 /* See code below that used this. */
5815 int init_written
= initialized
;
5818 /* This should only be done once on the top most decl. */
5819 if (have_extern_spec
&& !used_extern_spec
)
5821 declspecs
= decl_tree_cons (NULL_TREE
, get_identifier ("extern"),
5823 used_extern_spec
= 1;
5826 decl
= grokdeclarator (declarator
, declspecs
, NORMAL
, initialized
,
5828 if (decl
== NULL_TREE
|| decl
== void_type_node
)
5831 type
= TREE_TYPE (decl
);
5833 /* Don't lose if destructors must be executed at file-level. */
5834 if (! processing_template_decl
&& TREE_STATIC (decl
)
5835 && TYPE_NEEDS_DESTRUCTOR (complete_type (type
))
5836 && !TREE_PERMANENT (decl
))
5838 push_obstacks (&permanent_obstack
, &permanent_obstack
);
5839 decl
= copy_node (decl
);
5840 if (TREE_CODE (type
) == ARRAY_TYPE
)
5842 tree itype
= TYPE_DOMAIN (type
);
5843 if (itype
&& ! TREE_PERMANENT (itype
))
5845 itype
= build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype
)));
5846 type
= build_cplus_array_type (TREE_TYPE (type
), itype
);
5847 TREE_TYPE (decl
) = type
;
5854 = (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
5855 ? DECL_CLASS_CONTEXT (decl
)
5856 : DECL_CONTEXT (decl
);
5859 /* Is it valid for this decl to have an initializer at all?
5860 If not, set INITIALIZED to zero, which will indirectly
5861 tell `cp_finish_decl' to ignore the initializer once it is parsed. */
5862 switch (TREE_CODE (decl
))
5865 /* typedef foo = bar means give foo the same type as bar.
5866 We haven't parsed bar yet, so `cp_finish_decl' will fix that up.
5867 Any other case of an initialization in a TYPE_DECL is an error. */
5868 if (pedantic
|| list_length (declspecs
) > 1)
5870 cp_error ("typedef `%D' is initialized", decl
);
5876 cp_error ("function `%#D' is initialized like a variable", decl
);
5881 if (! processing_template_decl
)
5883 if (type
!= error_mark_node
)
5885 if (TYPE_SIZE (type
) != NULL_TREE
5886 && ! TREE_CONSTANT (TYPE_SIZE (type
)))
5889 ("variable-sized object `%D' may not be initialized",
5894 if (TREE_CODE (type
) == ARRAY_TYPE
5895 && TYPE_SIZE (complete_type (TREE_TYPE (type
))) == NULL_TREE
)
5898 ("elements of array `%#D' have incomplete type", decl
);
5907 if (! toplevel_bindings_p ()
5908 && DECL_EXTERNAL (decl
))
5909 cp_warning ("declaration of `%#D' has `extern' and is initialized",
5911 DECL_EXTERNAL (decl
) = 0;
5912 if (toplevel_bindings_p ())
5913 TREE_STATIC (decl
) = 1;
5915 /* Tell `pushdecl' this is an initialized decl
5916 even though we don't yet have the initializer expression.
5917 Also tell `cp_finish_decl' it may store the real initializer. */
5918 DECL_INITIAL (decl
) = error_mark_node
;
5921 if (context
&& TYPE_SIZE (complete_type (context
)) != NULL_TREE
)
5923 if (TREE_CODE (decl
) == VAR_DECL
)
5925 tree field
= lookup_field (context
, DECL_NAME (decl
), 0, 0);
5926 if (field
== NULL_TREE
|| TREE_CODE (field
) != VAR_DECL
)
5927 cp_error ("`%#D' is not a static member of `%#T'", decl
, context
);
5930 if (DECL_CONTEXT (field
) != context
)
5931 cp_pedwarn ("ANSI C++ does not permit `%T::%D' to be defined as `%T::%D'", DECL_CONTEXT (field
), DECL_NAME (decl
), context
, DECL_NAME (decl
));
5932 if (duplicate_decls (decl
, field
))
5938 tree field
= check_classfn (context
, decl
);
5939 if (field
&& duplicate_decls (decl
, field
))
5943 /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */
5944 if (DECL_LANG_SPECIFIC (decl
))
5945 DECL_IN_AGGR_P (decl
) = 0;
5946 if (DECL_USE_TEMPLATE (decl
) || CLASSTYPE_USE_TEMPLATE (context
))
5947 SET_DECL_TEMPLATE_SPECIALIZATION (decl
);
5949 /* Stupid stupid stupid stupid (jason 7/21/95) */
5950 if (pedantic
&& DECL_EXTERNAL (decl
)
5951 && ! DECL_TEMPLATE_SPECIALIZATION (decl
))
5952 cp_pedwarn ("declaration of `%#D' outside of class is not definition",
5955 pushclass (context
, 2);
5958 /* Add this decl to the current binding level, but not if it
5959 comes from another scope, e.g. a static member variable.
5960 TEM may equal DECL or it may be a previous decl of the same name. */
5962 if ((TREE_CODE (decl
) != PARM_DECL
&& DECL_CONTEXT (decl
) != NULL_TREE
)
5963 || (TREE_CODE (decl
) == TEMPLATE_DECL
&& !global_bindings_p ())
5964 || TREE_CODE (type
) == LANG_TYPE
)
5967 tem
= pushdecl (decl
);
5969 if (processing_template_decl
)
5971 if (! current_function_decl
)
5972 push_template_decl (tem
);
5973 else if (minimal_parse_mode
)
5975 = build_min_nt (DECL_STMT
, copy_to_permanent (declarator
),
5976 copy_to_permanent (declspecs
),
5981 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
5982 /* Tell the back-end to use or not use .common as appropriate. If we say
5983 -fconserve-space, we want this to save .data space, at the expense of
5984 wrong semantics. If we say -fno-conserve-space, we want this to
5985 produce errors about redefs; to do this we force variables into the
5987 DECL_COMMON (tem
) = flag_conserve_space
|| ! TREE_PUBLIC (tem
);
5990 if (! processing_template_decl
)
5993 /* Corresponding pop_obstacks is done in `cp_finish_decl'. */
5994 push_obstacks_nochange ();
5997 /* We have no way of knowing whether the initializer will need to be
5998 evaluated at run-time or not until we've parsed it, so let's just put
5999 it in the permanent obstack. (jason) */
6001 && ! (TREE_CODE (tem
) == PARM_DECL
6002 || (TREE_READONLY (tem
)
6003 && (TREE_CODE (tem
) == VAR_DECL
6004 || TREE_CODE (tem
) == FIELD_DECL
))))
6006 /* When parsing and digesting the initializer,
6007 use temporary storage. Do this even if we will ignore the value. */
6008 if (toplevel_bindings_p () && debug_temp_inits
)
6010 if (processing_template_decl
6011 || TYPE_NEEDS_CONSTRUCTING (type
)
6012 || TREE_CODE (type
) == REFERENCE_TYPE
)
6013 /* In this case, the initializer must lay down in permanent
6014 storage, since it will be saved until `finish_file' is run. */
6017 temporary_allocation ();
6029 tree type
= TREE_TYPE (decl
);
6030 int initialized
= (DECL_INITIAL (decl
) != NULL_TREE
);
6032 /* If this type of object needs a cleanup, and control may
6033 jump past it, make a new binding level so that it is cleaned
6034 up only when it is initialized first. */
6035 if (TYPE_NEEDS_DESTRUCTOR (type
)
6036 && current_binding_level
->more_cleanups_ok
== 0)
6037 pushlevel_temporary (1);
6040 /* Is it valid for this decl to have an initializer at all?
6041 If not, set INITIALIZED to zero, which will indirectly
6042 tell `cp_finish_decl' to ignore the initializer once it is parsed. */
6044 /* Don't allow initializations for incomplete types except for
6045 arrays which might be completed by the initialization. */
6046 if (type
== error_mark_node
)
6047 ; /* Don't complain again. */
6048 else if (TYPE_SIZE (complete_type (type
)) != NULL_TREE
)
6049 ; /* A complete type is ok. */
6050 else if (TREE_CODE (type
) != ARRAY_TYPE
)
6052 cp_error ("variable `%#D' has initializer but incomplete type",
6056 else if (TYPE_SIZE (complete_type (TREE_TYPE (type
))) == NULL_TREE
)
6058 if (DECL_LANG_SPECIFIC (decl
) && DECL_TEMPLATE_INFO (decl
))
6059 cp_error ("elements of array `%#D' have incomplete type", decl
);
6060 /* else we already gave an error in start_decl. */
6066 && TREE_CODE (decl
) != TYPE_DECL
6067 && TREE_CODE (decl
) != TEMPLATE_DECL
6068 && IS_AGGR_TYPE (type
) && ! DECL_EXTERNAL (decl
))
6070 if ((! processing_template_decl
|| ! uses_template_parms (type
))
6071 && TYPE_SIZE (complete_type (type
)) == NULL_TREE
)
6073 cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
6075 /* Change the type so that assemble_variable will give
6076 DECL an rtl we can live with: (mem (const_int 0)). */
6077 TREE_TYPE (decl
) = error_mark_node
;
6078 type
= error_mark_node
;
6082 /* If any base type in the hierarchy of TYPE needs a constructor,
6083 then we set initialized to 1. This way any nodes which are
6084 created for the purposes of initializing this aggregate
6085 will live as long as it does. This is necessary for global
6086 aggregates which do not have their initializers processed until
6087 the end of the file. */
6088 initialized
= TYPE_NEEDS_CONSTRUCTING (type
);
6093 /* We don't do this yet for GNU C++. */
6094 /* For a local variable, define the RTL now. */
6095 if (! toplevel_bindings_p ()
6096 /* But not if this is a duplicate decl
6097 and we preserved the rtl from the previous one
6098 (which may or may not happen). */
6099 && DECL_RTL (tem
) == NULL_RTX
)
6101 if (TYPE_SIZE (TREE_TYPE (tem
)) != NULL_TREE
)
6103 else if (TREE_CODE (TREE_TYPE (tem
)) == ARRAY_TYPE
6104 && DECL_INITIAL (tem
) != NULL_TREE
)
6110 DECL_INITIAL (decl
) = NULL_TREE
;
6113 /* Handle initialization of references.
6114 These three arguments from from `cp_finish_decl', and have the
6115 same meaning here that they do there.
6117 Quotes on semantics can be found in ARM 8.4.3. */
6120 grok_reference_init (decl
, type
, init
, cleanupp
)
6121 tree decl
, type
, init
;
6126 if (init
== NULL_TREE
)
6128 if ((DECL_LANG_SPECIFIC (decl
) == 0
6129 || DECL_IN_AGGR_P (decl
) == 0)
6130 && ! DECL_THIS_EXTERN (decl
))
6132 cp_error ("`%D' declared as reference but not initialized", decl
);
6133 if (TREE_CODE (decl
) == VAR_DECL
)
6134 SET_DECL_REFERENCE_SLOT (decl
, error_mark_node
);
6139 if (init
== error_mark_node
)
6142 if (TREE_CODE (type
) == REFERENCE_TYPE
6143 && TREE_CODE (init
) == CONSTRUCTOR
)
6145 cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl
);
6149 if (TREE_TYPE (init
) && TREE_CODE (TREE_TYPE (init
)) == UNKNOWN_TYPE
)
6150 /* decay_conversion is probably wrong for references to functions. */
6151 init
= decay_conversion (instantiate_type (TREE_TYPE (type
), init
, 1));
6153 if (TREE_CODE (init
) == TREE_LIST
)
6154 init
= build_compound_expr (init
);
6156 if (TREE_CODE (TREE_TYPE (init
)) == REFERENCE_TYPE
)
6157 init
= convert_from_reference (init
);
6159 if (TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
6160 && TREE_CODE (TREE_TYPE (init
)) == ARRAY_TYPE
)
6162 /* Note: default conversion is only called in very special cases. */
6163 init
= default_conversion (init
);
6166 tmp
= convert_to_reference
6167 (type
, init
, CONV_IMPLICIT
,
6168 LOOKUP_SPECULATIVELY
|LOOKUP_NORMAL
|DIRECT_BIND
, decl
);
6170 if (tmp
== error_mark_node
)
6172 else if (tmp
!= NULL_TREE
)
6175 DECL_INITIAL (decl
) = save_expr (init
);
6179 cp_error ("cannot initialize `%T' from `%T'", type
, TREE_TYPE (init
));
6183 /* ?? Can this be optimized in some cases to
6184 hand back the DECL_INITIAL slot?? */
6185 if (TYPE_SIZE (TREE_TYPE (type
)))
6187 init
= convert_from_reference (decl
);
6188 if (TREE_PERMANENT (decl
))
6189 init
= copy_to_permanent (init
);
6190 SET_DECL_REFERENCE_SLOT (decl
, init
);
6193 if (TREE_STATIC (decl
) && ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6195 expand_static_init (decl
, DECL_INITIAL (decl
));
6196 DECL_INITIAL (decl
) = NULL_TREE
;
6201 if (TREE_CODE (decl
) == VAR_DECL
)
6202 SET_DECL_REFERENCE_SLOT (decl
, error_mark_node
);
6206 /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from
6207 mucking with forces it does not comprehend (i.e. initialization with a
6208 constructor). If we are at global scope and won't go into COMMON, fill
6209 it in with a dummy CONSTRUCTOR to force the variable into .data;
6210 otherwise we can use error_mark_node. */
6213 obscure_complex_init (decl
, init
)
6216 if (! flag_no_inline
&& TREE_STATIC (decl
))
6218 if (extract_init (decl
, init
))
6222 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
6223 if (toplevel_bindings_p () && ! DECL_COMMON (decl
))
6224 DECL_INITIAL (decl
) = build (CONSTRUCTOR
, TREE_TYPE (decl
), NULL_TREE
,
6228 DECL_INITIAL (decl
) = error_mark_node
;
6233 /* Finish processing of a declaration;
6234 install its line number and initial value.
6235 If the length of an array type is not known before,
6236 it must be determined now, from the initial value, or it is an error.
6238 Call `pop_obstacks' iff NEED_POP is nonzero.
6240 For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers
6241 for aggregates that have constructors alive on the permanent obstack,
6242 so that the global initializing functions can be written at the end.
6244 INIT0 holds the value of an initializer that should be allowed to escape
6247 FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0
6248 if the (init) syntax was used.
6250 For functions that take default parameters, DECL points to its
6251 "maximal" instantiation. `cp_finish_decl' must then also declared its
6252 subsequently lower and lower forms of instantiation, checking for
6253 ambiguity as it goes. This can be sped up later. */
6256 cp_finish_decl (decl
, init
, asmspec_tree
, need_pop
, flags
)
6263 tree cleanup
= NULL_TREE
, ttype
;
6265 int temporary
= allocation_temporary_p ();
6266 char *asmspec
= NULL
;
6267 int was_readonly
= 0;
6269 /* If this is 0, then we did not change obstacks. */
6273 error ("assignment (not initialization) in declaration");
6277 /* If a name was specified, get the string. */
6279 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
6281 /* If the type of the thing we are declaring either has
6282 a constructor, or has a virtual function table pointer,
6283 AND its initialization was accepted by `start_decl',
6284 then we stayed on the permanent obstack through the
6285 declaration, otherwise, changed obstacks as GCC would. */
6287 type
= TREE_TYPE (decl
);
6289 if (type
== error_mark_node
)
6291 if (toplevel_bindings_p () && temporary
)
6292 end_temporary_allocation ();
6297 if (processing_template_decl
)
6299 if (init
&& DECL_INITIAL (decl
))
6300 DECL_INITIAL (decl
) = init
;
6301 if (minimal_parse_mode
&& ! DECL_ARTIFICIAL (decl
))
6303 tree stmt
= DECL_VINDEX (decl
);
6304 DECL_VINDEX (decl
) = NULL_TREE
;
6305 TREE_OPERAND (stmt
, 2) = copy_to_permanent (init
);
6311 /* Take care of TYPE_DECLs up front. */
6312 if (TREE_CODE (decl
) == TYPE_DECL
)
6314 if (init
&& DECL_INITIAL (decl
))
6316 /* typedef foo = bar; store the type of bar as the type of foo. */
6317 TREE_TYPE (decl
) = type
= TREE_TYPE (init
);
6318 DECL_INITIAL (decl
) = init
= NULL_TREE
;
6320 if (type
!= error_mark_node
6321 && IS_AGGR_TYPE (type
) && DECL_NAME (decl
))
6323 if (TREE_TYPE (DECL_NAME (decl
)) && TREE_TYPE (decl
) != type
)
6324 cp_warning ("shadowing previous type declaration of `%#D'", decl
);
6325 set_identifier_type_value (DECL_NAME (decl
), type
);
6326 CLASSTYPE_GOT_SEMICOLON (type
) = 1;
6328 GNU_xref_decl (current_function_decl
, decl
);
6330 /* If we have installed this as the canonical typedef for this
6331 type, and that type has not been defined yet, delay emitting
6332 the debug informaion for it, as we will emit it later. */
6333 if (TYPE_MAIN_DECL (TREE_TYPE (decl
)) == decl
6334 && TYPE_SIZE (TREE_TYPE (decl
)) == NULL_TREE
)
6335 TYPE_DECL_SUPPRESS_DEBUG (decl
) = 1;
6337 rest_of_decl_compilation (decl
, NULL_PTR
,
6338 DECL_CONTEXT (decl
) == NULL_TREE
, at_eof
);
6341 if (TREE_CODE (decl
) != FUNCTION_DECL
)
6343 ttype
= target_type (type
);
6346 if (! DECL_EXTERNAL (decl
) && TREE_READONLY (decl
)
6347 && TYPE_NEEDS_CONSTRUCTING (type
))
6350 /* Currently, GNU C++ puts constants in text space, making them
6351 impossible to initialize. In the future, one would hope for
6352 an operating system which understood the difference between
6353 initialization and the running of a program. */
6355 TREE_READONLY (decl
) = 0;
6358 if (TREE_CODE (decl
) == FIELD_DECL
)
6360 if (init
&& init
!= error_mark_node
)
6361 my_friendly_assert (TREE_PERMANENT (init
), 147);
6365 /* This must override the asm specifier which was placed
6366 by grokclassfn. Lay this out fresh. */
6367 DECL_RTL (TREE_TYPE (decl
)) = NULL_RTX
;
6368 DECL_ASSEMBLER_NAME (decl
) = get_identifier (asmspec
);
6369 make_decl_rtl (decl
, asmspec
, 0);
6372 /* If `start_decl' didn't like having an initialization, ignore it now. */
6373 else if (init
!= NULL_TREE
&& DECL_INITIAL (decl
) == NULL_TREE
)
6375 else if (DECL_EXTERNAL (decl
))
6377 else if (TREE_CODE (type
) == REFERENCE_TYPE
6378 || (TYPE_LANG_SPECIFIC (type
) && IS_SIGNATURE_REFERENCE (type
)))
6380 if (TREE_STATIC (decl
))
6381 make_decl_rtl (decl
, NULL_PTR
,
6382 toplevel_bindings_p ()
6383 || pseudo_global_level_p ());
6384 grok_reference_init (decl
, type
, init
, &cleanup
);
6388 GNU_xref_decl (current_function_decl
, decl
);
6390 if (TREE_CODE (decl
) == FIELD_DECL
)
6392 else if (TREE_CODE (decl
) == CONST_DECL
)
6394 my_friendly_assert (TREE_CODE (decl
) != REFERENCE_TYPE
, 148);
6396 DECL_INITIAL (decl
) = init
;
6398 /* This will keep us from needing to worry about our obstacks. */
6399 my_friendly_assert (init
!= NULL_TREE
, 149);
6404 if (TYPE_HAS_CONSTRUCTOR (type
) || TYPE_NEEDS_CONSTRUCTING (type
))
6406 if (TREE_CODE (type
) == ARRAY_TYPE
)
6407 init
= digest_init (type
, init
, (tree
*) 0);
6408 else if (TREE_CODE (init
) == CONSTRUCTOR
)
6410 if (TYPE_NON_AGGREGATE_CLASS (type
))
6412 cp_error ("`%D' must be initialized by constructor, not by `{...}'",
6414 init
= error_mark_node
;
6417 goto dont_use_constructor
;
6422 dont_use_constructor
:
6423 if (TREE_CODE (init
) != TREE_VEC
)
6424 init
= store_init_value (decl
, init
);
6428 /* We must hide the initializer so that expand_decl
6429 won't try to do something it does not understand. */
6430 init
= obscure_complex_init (decl
, init
);
6432 else if (DECL_EXTERNAL (decl
))
6434 else if (TREE_CODE_CLASS (TREE_CODE (type
)) == 't'
6435 && (IS_AGGR_TYPE (type
) || TYPE_NEEDS_CONSTRUCTING (type
)))
6438 while (TREE_CODE (ctype
) == ARRAY_TYPE
)
6439 ctype
= TREE_TYPE (ctype
);
6440 if (! TYPE_NEEDS_CONSTRUCTING (ctype
))
6442 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype
))
6443 cp_error ("structure `%D' with uninitialized const members", decl
);
6444 if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype
))
6445 cp_error ("structure `%D' with uninitialized reference members",
6449 if (TREE_CODE (decl
) == VAR_DECL
6450 && !DECL_INITIAL (decl
)
6451 && !TYPE_NEEDS_CONSTRUCTING (type
)
6452 && (TYPE_READONLY (type
) || TREE_READONLY (decl
)))
6453 cp_error ("uninitialized const `%D'", decl
);
6455 if (TYPE_SIZE (type
) != NULL_TREE
6456 && TYPE_NEEDS_CONSTRUCTING (type
))
6457 init
= obscure_complex_init (decl
, NULL_TREE
);
6459 else if (TREE_CODE (decl
) == VAR_DECL
6460 && TREE_CODE (type
) != REFERENCE_TYPE
6461 && (TYPE_READONLY (type
) || TREE_READONLY (decl
)))
6463 /* ``Unless explicitly declared extern, a const object does not have
6464 external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
6465 However, if it's `const int foo = 1; const int foo;', don't complain
6466 about the second decl, since it does have an initializer before.
6467 We deliberately don't complain about arrays, because they're
6468 supposed to be initialized by a constructor. */
6469 if (! DECL_INITIAL (decl
)
6470 && TREE_CODE (type
) != ARRAY_TYPE
6471 && (!pedantic
|| !current_class_type
))
6472 cp_error ("uninitialized const `%#D'", decl
);
6475 /* For top-level declaration, the initial value was read in
6476 the temporary obstack. MAXINDEX, rtl, etc. to be made below
6477 must go in the permanent obstack; but don't discard the
6478 temporary data yet. */
6480 if (toplevel_bindings_p () && temporary
)
6481 end_temporary_allocation ();
6483 /* Deduce size of array from initialization, if not already known. */
6485 if (TREE_CODE (type
) == ARRAY_TYPE
6486 && TYPE_DOMAIN (type
) == NULL_TREE
6487 && TREE_CODE (decl
) != TYPE_DECL
)
6490 = (TREE_STATIC (decl
)
6491 /* Even if pedantic, an external linkage array
6492 may have incomplete type at first. */
6493 ? pedantic
&& ! DECL_EXTERNAL (decl
)
6494 : !DECL_EXTERNAL (decl
));
6495 tree initializer
= init
? init
: DECL_INITIAL (decl
);
6496 int failure
= complete_array_type (type
, initializer
, do_default
);
6499 cp_error ("initializer fails to determine size of `%D'", decl
);
6504 cp_error ("array size missing in `%D'", decl
);
6505 /* If a `static' var's size isn't known, make it extern as
6506 well as static, so it does not get allocated. If it's not
6507 `static', then don't mark it extern; finish_incomplete_decl
6508 will give it a default size and it will get allocated. */
6509 else if (!pedantic
&& TREE_STATIC (decl
) && !TREE_PUBLIC (decl
))
6510 DECL_EXTERNAL (decl
) = 1;
6513 if (pedantic
&& TYPE_DOMAIN (type
) != NULL_TREE
6514 && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
6516 cp_error ("zero-size array `%D'", decl
);
6518 layout_decl (decl
, 0);
6521 if (TREE_CODE (decl
) == VAR_DECL
)
6523 if (DECL_SIZE (decl
) == NULL_TREE
6524 && TYPE_SIZE (complete_type (TREE_TYPE (decl
))) != NULL_TREE
)
6525 layout_decl (decl
, 0);
6527 if (TREE_STATIC (decl
) && DECL_SIZE (decl
) == NULL_TREE
)
6529 /* A static variable with an incomplete type:
6530 that is an error if it is initialized.
6531 Otherwise, let it through, but if it is not `extern'
6532 then it may cause an error message later. */
6533 if (DECL_INITIAL (decl
) != NULL_TREE
)
6534 cp_error ("storage size of `%D' isn't known", decl
);
6537 else if (!DECL_EXTERNAL (decl
) && DECL_SIZE (decl
) == NULL_TREE
)
6539 /* An automatic variable with an incomplete type: that is an error.
6540 Don't talk about array types here, since we took care of that
6541 message in grokdeclarator. */
6542 cp_error ("storage size of `%D' isn't known", decl
);
6543 TREE_TYPE (decl
) = error_mark_node
;
6545 else if (!DECL_EXTERNAL (decl
) && IS_AGGR_TYPE (ttype
))
6546 /* Let debugger know it should output info for this type. */
6547 note_debug_info_needed (ttype
);
6549 if (TREE_STATIC (decl
) && DECL_CONTEXT (decl
)
6550 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl
))) == 't')
6551 note_debug_info_needed (DECL_CONTEXT (decl
));
6553 if ((DECL_EXTERNAL (decl
) || TREE_STATIC (decl
))
6554 && DECL_SIZE (decl
) != NULL_TREE
6555 && ! TREE_CONSTANT (DECL_SIZE (decl
)))
6557 if (TREE_CODE (DECL_SIZE (decl
)) == INTEGER_CST
)
6558 constant_expression_warning (DECL_SIZE (decl
));
6560 cp_error ("storage size of `%D' isn't constant", decl
);
6563 if (! DECL_EXTERNAL (decl
) && TYPE_NEEDS_DESTRUCTOR (type
)
6564 /* Cleanups for static variables are handled by `finish_file'. */
6565 && ! TREE_STATIC (decl
))
6567 int yes
= suspend_momentary ();
6568 cleanup
= maybe_build_cleanup (decl
);
6569 resume_momentary (yes
);
6572 /* PARM_DECLs get cleanups, too. */
6573 else if (TREE_CODE (decl
) == PARM_DECL
&& TYPE_NEEDS_DESTRUCTOR (type
))
6576 end_temporary_allocation ();
6577 cleanup
= maybe_build_cleanup (decl
);
6579 resume_temporary_allocation ();
6582 /* Output the assembler code and/or RTL code for variables and functions,
6583 unless the type is an undefined structure or union.
6584 If not, it will get done when the type is completed. */
6586 was_incomplete
= (DECL_SIZE (decl
) == NULL_TREE
);
6588 if (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == FUNCTION_DECL
6589 || TREE_CODE (decl
) == RESULT_DECL
)
6591 /* ??? FIXME: What about nested classes? */
6592 int toplev
= toplevel_bindings_p () || pseudo_global_level_p ();
6594 = (TREE_STATIC (decl
) && TYPE_NEEDS_DESTRUCTOR (type
)
6595 && allocation_temporary_p ());
6598 end_temporary_allocation ();
6600 /* Extern inline function static data has external linkage. */
6601 if (TREE_CODE (decl
) == VAR_DECL
6602 && TREE_STATIC (decl
)
6603 && current_function_decl
6604 && DECL_CONTEXT (decl
) == current_function_decl
6605 && DECL_THIS_INLINE (current_function_decl
)
6606 && DECL_PUBLIC (current_function_decl
))
6608 if (DECL_INTERFACE_KNOWN (current_function_decl
))
6610 TREE_PUBLIC (decl
) = 1;
6611 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (current_function_decl
);
6613 /* We can only do this if we can use common or weak, and we
6614 can't if it has been initialized and we don't support weak. */
6615 else if (DECL_INITIAL (decl
) == NULL_TREE
6616 || DECL_INITIAL (decl
) == error_mark_node
)
6618 TREE_PUBLIC (decl
) = 1;
6619 DECL_COMMON (decl
) = 1;
6622 make_decl_one_only (decl
);
6624 if (TREE_PUBLIC (decl
))
6625 DECL_ASSEMBLER_NAME (decl
)
6626 = build_static_name (current_function_decl
, DECL_NAME (decl
));
6627 else if (! DECL_ARTIFICIAL (decl
))
6628 cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl
);
6631 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_VIRTUAL_P (decl
))
6632 make_decl_rtl (decl
, NULL_PTR
, toplev
);
6633 else if (TREE_CODE (decl
) == VAR_DECL
6634 && TREE_READONLY (decl
)
6635 && DECL_INITIAL (decl
) != NULL_TREE
6636 && DECL_INITIAL (decl
) != error_mark_node
6637 && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl
)))
6639 DECL_INITIAL (decl
) = save_expr (DECL_INITIAL (decl
));
6642 DECL_ASSEMBLER_NAME (decl
) = get_identifier (asmspec
);
6645 && TREE_STATIC (decl
)
6646 && ! TREE_SIDE_EFFECTS (decl
)
6647 && ! TREE_PUBLIC (decl
)
6648 && ! DECL_EXTERNAL (decl
)
6649 && ! TYPE_NEEDS_DESTRUCTOR (type
)
6650 && DECL_MODE (decl
) != BLKmode
)
6652 /* If this variable is really a constant, then fill its DECL_RTL
6653 slot with something which won't take up storage.
6654 If something later should take its address, we can always give
6655 it legitimate RTL at that time. */
6656 DECL_RTL (decl
) = gen_reg_rtx (DECL_MODE (decl
));
6657 store_expr (DECL_INITIAL (decl
), DECL_RTL (decl
), 0);
6658 TREE_ASM_WRITTEN (decl
) = 1;
6660 else if (toplev
&& ! TREE_PUBLIC (decl
))
6662 /* If this is a static const, change its apparent linkage
6663 if it belongs to a #pragma interface. */
6664 if (!interface_unknown
)
6666 TREE_PUBLIC (decl
) = 1;
6667 DECL_EXTERNAL (decl
) = interface_only
;
6669 make_decl_rtl (decl
, asmspec
, toplev
);
6672 rest_of_decl_compilation (decl
, asmspec
, toplev
, at_eof
);
6674 else if (TREE_CODE (decl
) == VAR_DECL
6675 && DECL_LANG_SPECIFIC (decl
)
6676 && DECL_IN_AGGR_P (decl
))
6678 if (TREE_STATIC (decl
))
6680 if (init
== NULL_TREE
6681 #ifdef DEFAULT_STATIC_DEFS
6682 /* If this code is dead, then users must
6683 explicitly declare static member variables
6684 outside the class def'n as well. */
6685 && TYPE_NEEDS_CONSTRUCTING (type
)
6689 DECL_EXTERNAL (decl
) = 1;
6690 make_decl_rtl (decl
, asmspec
, 1);
6693 rest_of_decl_compilation (decl
, asmspec
, toplev
, at_eof
);
6696 /* Just a constant field. Should not need any rtl. */
6700 rest_of_decl_compilation (decl
, asmspec
, toplev
, at_eof
);
6703 resume_temporary_allocation ();
6705 if (type
!= error_mark_node
6706 && TYPE_LANG_SPECIFIC (type
)
6707 && CLASSTYPE_ABSTRACT_VIRTUALS (type
))
6708 abstract_virtuals_error (decl
, type
);
6709 else if ((TREE_CODE (type
) == FUNCTION_TYPE
6710 || TREE_CODE (type
) == METHOD_TYPE
)
6711 && TYPE_LANG_SPECIFIC (TREE_TYPE (type
))
6712 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type
)))
6713 abstract_virtuals_error (decl
, TREE_TYPE (type
));
6715 if (TYPE_LANG_SPECIFIC (type
) && IS_SIGNATURE (type
))
6716 signature_error (decl
, type
);
6717 else if ((TREE_CODE (type
) == FUNCTION_TYPE
6718 || TREE_CODE (type
) == METHOD_TYPE
)
6719 && TYPE_LANG_SPECIFIC (TREE_TYPE (type
))
6720 && IS_SIGNATURE (TREE_TYPE (type
)))
6721 signature_error (decl
, TREE_TYPE (type
));
6723 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6725 else if (DECL_EXTERNAL (decl
)
6726 && ! (DECL_LANG_SPECIFIC (decl
)
6727 && DECL_NOT_REALLY_EXTERN (decl
)))
6730 DECL_INITIAL (decl
) = init
;
6732 else if (TREE_STATIC (decl
) && type
!= error_mark_node
)
6734 /* Cleanups for static variables are handled by `finish_file'. */
6735 if (TYPE_NEEDS_CONSTRUCTING (type
) || init
!= NULL_TREE
6736 || TYPE_NEEDS_DESTRUCTOR (type
))
6737 expand_static_init (decl
, init
);
6741 /* This is a declared decl which must live until the
6742 end of the binding contour. It may need a cleanup. */
6744 /* Recompute the RTL of a local array now
6745 if it used to be an incomplete type. */
6746 if (was_incomplete
&& ! TREE_STATIC (decl
))
6748 /* If we used it already as memory, it must stay in memory. */
6749 TREE_ADDRESSABLE (decl
) = TREE_USED (decl
);
6750 /* If it's still incomplete now, no init will save it. */
6751 if (DECL_SIZE (decl
) == NULL_TREE
)
6752 DECL_INITIAL (decl
) = NULL_TREE
;
6755 else if (! TREE_ASM_WRITTEN (decl
)
6756 && (TYPE_SIZE (type
) != NULL_TREE
6757 || TREE_CODE (type
) == ARRAY_TYPE
))
6759 /* Do this here, because we did not expand this decl's
6760 rtl in start_decl. */
6761 if (DECL_RTL (decl
) == NULL_RTX
)
6765 /* XXX: Why don't we use decl here? */
6766 /* Ans: Because it was already expanded? */
6767 if (! expand_decl_cleanup (NULL_TREE
, cleanup
))
6768 cp_error ("parser lost in parsing declaration of `%D'",
6770 /* Cleanup used up here. */
6771 cleanup
= NULL_TREE
;
6775 if (current_binding_level
->is_for_scope
)
6777 struct binding_level
*outer
= current_binding_level
->level_chain
;
6779 /* Check to see if the same name is already bound at
6780 the outer level, either because it was directly declared,
6781 or because a dead for-decl got preserved. In either case,
6782 the code would not have been valid under the ARM
6783 scope rules, so clear is_for_scope for the
6784 current_binding_level.
6786 Otherwise, we need to preserve the temp slot for decl
6787 to last into the outer binding level. */
6789 int handling_dead_for_vars
= 0;
6790 tree link
= outer
->names
;
6791 for (; ; link
= TREE_CHAIN (link
))
6793 if (link
== NULL
&& handling_dead_for_vars
== 0)
6795 link
= outer
->dead_vars_from_for
;
6796 handling_dead_for_vars
= 1;
6800 if (DECL_IN_MEMORY_P (decl
))
6801 preserve_temp_slots (DECL_RTL (decl
));
6804 if (DECL_NAME (link
) == DECL_NAME (decl
))
6806 if (handling_dead_for_vars
)
6809 = purpose_member (DECL_NAME (decl
),
6810 current_binding_level
->shadowed
);
6811 if (shadowing
&& TREE_VALUE (shadowing
) == link
)
6812 TREE_VALUE (shadowing
)
6813 = DECL_SHADOWED_FOR_VAR (link
);
6815 current_binding_level
->is_for_scope
= 0;
6821 expand_start_target_temps ();
6823 if (DECL_SIZE (decl
) && type
!= error_mark_node
)
6825 /* Compute and store the initial value. */
6826 expand_decl_init (decl
);
6828 if (init
|| TYPE_NEEDS_CONSTRUCTING (type
))
6830 emit_line_note (DECL_SOURCE_FILE (decl
),
6831 DECL_SOURCE_LINE (decl
));
6832 expand_aggr_init (decl
, init
, 0, flags
);
6835 /* Set this to 0 so we can tell whether an aggregate which
6836 was initialized was ever used. Don't do this if it has a
6837 destructor, so we don't complain about the 'resource
6838 allocation is initialization' idiom. */
6839 if (TYPE_NEEDS_CONSTRUCTING (type
)
6840 && cleanup
== NULL_TREE
6841 && DECL_NAME (decl
))
6842 TREE_USED (decl
) = 0;
6845 /* Cleanup any temporaries needed for the initial value. */
6846 expand_end_target_temps ();
6848 if (DECL_SIZE (decl
) && type
!= error_mark_node
)
6850 /* Store the cleanup, if there was one. */
6853 if (! expand_decl_cleanup (decl
, cleanup
))
6854 cp_error ("parser lost in parsing declaration of `%D'",
6861 /* Undo call to `pushclass' that was done in `start_decl'
6862 due to initialization of qualified member variable.
6863 I.e., Foo::x = 10; */
6865 tree context
= DECL_REAL_CONTEXT (decl
);
6867 && TREE_CODE_CLASS (TREE_CODE (context
)) == 't'
6868 && (TREE_CODE (decl
) == VAR_DECL
6869 /* We also have a pushclass done that we need to undo here
6870 if we're at top level and declare a method. */
6871 || TREE_CODE (decl
) == FUNCTION_DECL
)
6872 /* If size hasn't been set, we're still defining it,
6873 and therefore inside the class body; don't pop
6874 the binding level.. */
6875 && TYPE_SIZE (context
) != NULL_TREE
6876 && context
== current_class_type
)
6883 /* If requested, warn about definitions of large data objects. */
6885 if (warn_larger_than
6886 && ! processing_template_decl
6887 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
)
6888 && !DECL_EXTERNAL (decl
))
6890 register tree decl_size
= DECL_SIZE (decl
);
6892 if (decl_size
&& TREE_CODE (decl_size
) == INTEGER_CST
)
6894 unsigned units
= TREE_INT_CST_LOW (decl_size
) / BITS_PER_UNIT
;
6896 if (units
> larger_than_size
)
6897 warning_with_decl (decl
, "size of `%s' is %u bytes", units
);
6903 /* Resume permanent allocation, if not within a function. */
6904 /* The corresponding push_obstacks_nochange is in start_decl,
6905 start_method, groktypename, and in grokfield. */
6910 TREE_READONLY (decl
) = 1;
6913 /* This is here for a midend callback from c-common.c */
6916 finish_decl (decl
, init
, asmspec_tree
)
6920 cp_finish_decl (decl
, init
, asmspec_tree
, 1, 0);
6924 expand_static_init (decl
, init
)
6928 tree oldstatic
= value_member (decl
, static_aggregates
);
6932 if (TREE_PURPOSE (oldstatic
) && init
!= NULL_TREE
)
6933 cp_error ("multiple initializations given for `%D'", decl
);
6935 else if (! toplevel_bindings_p () && ! pseudo_global_level_p ())
6937 /* Emit code to perform this initialization but once. */
6940 /* Remember this information until end of file. */
6941 push_obstacks (&permanent_obstack
, &permanent_obstack
);
6943 /* Emit code to perform this initialization but once. */
6944 temp
= get_temp_name (integer_type_node
, 1);
6945 rest_of_decl_compilation (temp
, NULL_PTR
, 0, 0);
6946 expand_start_cond (build_binary_op (EQ_EXPR
, temp
,
6947 integer_zero_node
, 1), 0);
6948 expand_start_target_temps ();
6950 expand_assignment (temp
, integer_one_node
, 0, 0);
6951 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl
))
6952 || (init
&& TREE_CODE (init
) == TREE_LIST
))
6954 expand_aggr_init (decl
, init
, 0, 0);
6955 do_pending_stack_adjust ();
6958 expand_assignment (decl
, init
, 0, 0);
6960 /* Cleanup any temporaries needed for the initial value. */
6961 expand_end_target_temps ();
6963 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl
)))
6965 tree cleanup
, fcall
;
6966 static tree Atexit
= 0;
6969 tree atexit_fndecl
, PFV
, pfvlist
;
6970 /* Remember this information until end of file. */
6971 push_obstacks (&permanent_obstack
, &permanent_obstack
);
6972 PFV
= build_pointer_type (build_function_type
6973 (void_type_node
, void_list_node
));
6975 pfvlist
= tree_cons (NULL_TREE
, PFV
, void_list_node
);
6977 push_lang_context (lang_name_c
);
6979 = builtin_function ("atexit",
6980 build_function_type (void_type_node
,
6982 NOT_BUILT_IN
, NULL_PTR
);
6983 assemble_external (atexit_fndecl
);
6984 Atexit
= default_conversion (atexit_fndecl
);
6985 pop_lang_context ();
6989 cleanup
= start_anon_func ();
6990 expand_expr_stmt (build_cleanup (decl
));
6992 mark_addressable (cleanup
);
6993 cleanup
= build_unary_op (ADDR_EXPR
, cleanup
, 0);
6994 fcall
= build_function_call (Atexit
, tree_cons (NULL_TREE
, cleanup
, NULL_TREE
));
6995 expand_expr_stmt (fcall
);
6999 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl
)))
7001 static_aggregates
= perm_tree_cons (temp
, decl
, static_aggregates
);
7002 TREE_STATIC (static_aggregates
) = 1;
7005 /* Resume old (possibly temporary) allocation. */
7010 /* This code takes into account memory allocation
7011 policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING
7012 does not hold for this object, then we must make permanent
7013 the storage currently in the temporary obstack. */
7014 if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl
)))
7015 preserve_initializer ();
7016 static_aggregates
= perm_tree_cons (init
, decl
, static_aggregates
);
7020 /* Make TYPE a complete type based on INITIAL_VALUE.
7021 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
7022 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
7025 complete_array_type (type
, initial_value
, do_default
)
7026 tree type
, initial_value
;
7029 register tree maxindex
= NULL_TREE
;
7034 /* Note MAXINDEX is really the maximum index,
7035 one less than the size. */
7036 if (TREE_CODE (initial_value
) == STRING_CST
)
7039 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value
)));
7040 maxindex
= build_int_2 ((TREE_STRING_LENGTH (initial_value
)
7043 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
7045 tree elts
= CONSTRUCTOR_ELTS (initial_value
);
7046 maxindex
= size_binop (MINUS_EXPR
, integer_zero_node
, size_one_node
);
7047 for (; elts
; elts
= TREE_CHAIN (elts
))
7049 if (TREE_PURPOSE (elts
))
7050 maxindex
= TREE_PURPOSE (elts
);
7052 maxindex
= size_binop (PLUS_EXPR
, maxindex
, size_one_node
);
7054 maxindex
= copy_node (maxindex
);
7058 /* Make an error message unless that happened already. */
7059 if (initial_value
!= error_mark_node
)
7062 /* Prevent further error messages. */
7063 maxindex
= build_int_2 (0, 0);
7070 maxindex
= build_int_2 (0, 0);
7078 TYPE_DOMAIN (type
) = build_index_type (maxindex
);
7079 if (! TREE_TYPE (maxindex
))
7080 TREE_TYPE (maxindex
) = TYPE_DOMAIN (type
);
7082 itype
= TREE_TYPE (initial_value
);
7085 if (itype
&& !TYPE_DOMAIN (itype
))
7086 TYPE_DOMAIN (itype
) = TYPE_DOMAIN (type
);
7087 /* The type of the main variant should never be used for arrays
7088 of different sizes. It should only ever be completed with the
7089 size of the array. */
7090 if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type
)))
7091 TYPE_DOMAIN (TYPE_MAIN_VARIANT (type
)) = TYPE_DOMAIN (type
);
7094 /* Lay out the type now that we can get the real answer. */
7101 /* Return zero if something is declared to be a member of type
7102 CTYPE when in the context of CUR_TYPE. STRING is the error
7103 message to print in that case. Otherwise, quietly return 1. */
7106 member_function_or_else (ctype
, cur_type
, string
)
7107 tree ctype
, cur_type
;
7110 if (ctype
&& ctype
!= cur_type
)
7112 error (string
, TYPE_NAME_STRING (ctype
));
7118 /* Subroutine of `grokdeclarator'. */
7120 /* Generate errors possibly applicable for a given set of specifiers.
7121 This is for ARM $7.1.2. */
7124 bad_specifiers (object
, type
, virtualp
, quals
, inlinep
, friendp
, raises
)
7127 int virtualp
, quals
, friendp
, raises
, inlinep
;
7130 cp_error ("`%D' declared as a `virtual' %s", object
, type
);
7132 cp_error ("`%D' declared as an `inline' %s", object
, type
);
7134 cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
7137 cp_error_at ("invalid friend declaration", object
);
7139 cp_error_at ("invalid exception specifications", object
);
7142 /* CTYPE is class type, or null if non-class.
7143 TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
7145 DECLARATOR is the function's name.
7146 VIRTUALP is truthvalue of whether the function is virtual or not.
7147 FLAGS are to be passed through to `grokclassfn'.
7148 QUALS are qualifiers indicating whether the function is `const'
7150 RAISES is a list of exceptions that this function can raise.
7151 CHECK is 1 if we must find this method in CTYPE, 0 if we should
7152 not look, and -1 if we should not call `grokclassfn' at all. */
7155 grokfndecl (ctype
, type
, declarator
, virtualp
, flags
, quals
,
7156 raises
, attrlist
, check
, publicp
, inlinep
, funcdef_flag
)
7160 enum overload_flags flags
;
7161 tree quals
, raises
, attrlist
;
7162 int check
, publicp
, inlinep
, funcdef_flag
;
7165 int staticp
= ctype
&& TREE_CODE (type
) == FUNCTION_TYPE
;
7169 cname
= TREE_CODE (TYPE_NAME (ctype
)) == TYPE_DECL
7170 ? TYPE_IDENTIFIER (ctype
) : TYPE_NAME (ctype
);
7176 type
= build_exception_variant (type
, raises
);
7179 decl
= build_lang_decl (FUNCTION_DECL
, declarator
, type
);
7180 /* propagate volatile out from type to decl */
7181 if (TYPE_VOLATILE (type
))
7182 TREE_THIS_VOLATILE (decl
) = 1;
7184 /* Should probably propagate const out from type to decl I bet (mrs). */
7187 DECL_STATIC_FUNCTION_P (decl
) = 1;
7188 DECL_CONTEXT (decl
) = ctype
;
7192 DECL_CLASS_CONTEXT (decl
) = ctype
;
7194 /* All function decls start out public; we'll fix their linkage later (at
7195 definition or EOF) if appropriate. */
7196 TREE_PUBLIC (decl
) = 1;
7198 if (ctype
== NULL_TREE
&& ! strcmp (IDENTIFIER_POINTER (declarator
), "main"))
7201 error ("cannot declare `main' to be inline");
7203 error ("cannot declare `main' to be static");
7209 DECL_C_STATIC (decl
) = 1;
7212 DECL_THIS_INLINE (decl
) = DECL_INLINE (decl
) = 1;
7214 DECL_EXTERNAL (decl
) = 1;
7215 if (quals
!= NULL_TREE
&& TREE_CODE (type
) == FUNCTION_TYPE
)
7217 cp_error ("%smember function `%D' cannot have `%T' method qualifier",
7218 (ctype
? "static " : "non-"), decl
, TREE_VALUE (quals
));
7222 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl
)))
7223 grok_op_properties (decl
, virtualp
, check
< 0);
7225 if (ctype
&& hack_decl_function_context (decl
))
7226 DECL_NO_STATIC_CHAIN (decl
) = 1;
7228 for (t
= TYPE_ARG_TYPES (TREE_TYPE (decl
)); t
; t
= TREE_CHAIN (t
))
7229 if (TREE_PURPOSE (t
)
7230 && TREE_CODE (TREE_PURPOSE (t
)) == DEFAULT_ARG
)
7232 add_defarg_fn (decl
);
7236 /* Caller will do the rest of this. */
7240 if (check
&& funcdef_flag
)
7241 DECL_INITIAL (decl
) = error_mark_node
;
7243 if (flags
== NO_SPECIAL
&& ctype
&& constructor_name (cname
) == declarator
)
7246 /* Just handle constructors here. We could do this
7247 inside the following if stmt, but I think
7248 that the code is more legible by breaking this
7249 case out. See comments below for what each of
7250 the following calls is supposed to do. */
7251 DECL_CONSTRUCTOR_P (decl
) = 1;
7253 grokclassfn (ctype
, declarator
, decl
, flags
, quals
);
7256 tmp
= check_classfn (ctype
, decl
);
7258 if (tmp
&& TREE_CODE (tmp
) == TEMPLATE_DECL
)
7259 tmp
= DECL_TEMPLATE_RESULT(tmp
);
7261 if (tmp
&& DECL_ARTIFICIAL (tmp
))
7262 cp_error ("definition of implicitly-declared `%D'", tmp
);
7263 if (tmp
&& duplicate_decls (decl
, tmp
))
7266 if (! grok_ctor_properties (ctype
, decl
))
7269 if (check
== 0 && ! current_function_decl
)
7271 tmp
= IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl
));
7272 if (tmp
== NULL_TREE
)
7273 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl
)) = decl
;
7274 else if (TREE_CODE (tmp
) != TREE_CODE (decl
))
7275 cp_error ("inconsistent declarations for `%D'", decl
);
7278 duplicate_decls (decl
, tmp
);
7280 /* avoid creating circularities. */
7281 DECL_CHAIN (decl
) = NULL_TREE
;
7283 make_decl_rtl (decl
, NULL_PTR
, 1);
7290 /* Function gets the ugly name, field gets the nice one.
7291 This call may change the type of the function (because
7292 of default parameters)! */
7293 if (ctype
!= NULL_TREE
)
7294 grokclassfn (ctype
, cname
, decl
, flags
, quals
);
7296 if (ctype
!= NULL_TREE
&& check
)
7298 tmp
= check_classfn (ctype
, decl
);
7300 if (tmp
&& TREE_CODE (tmp
) == TEMPLATE_DECL
)
7301 tmp
= DECL_TEMPLATE_RESULT(tmp
);
7303 if (tmp
&& DECL_STATIC_FUNCTION_P (tmp
)
7304 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
)
7306 /* Remove the `this' parm added by grokclassfn.
7307 XXX Isn't this done in start_function, too? */
7308 revert_static_member_fn (&decl
, NULL
, NULL
);
7309 last_function_parms
= TREE_CHAIN (last_function_parms
);
7311 if (tmp
&& DECL_ARTIFICIAL (tmp
))
7312 cp_error ("definition of implicitly-declared `%D'", tmp
);
7315 if (!duplicate_decls (decl
, tmp
))
7316 my_friendly_abort (892);
7321 if (ctype
== NULL_TREE
|| check
)
7324 /* Now install the declaration of this function so that others may
7325 find it (esp. its DECL_FRIENDLIST). Don't do this for local class
7327 if (! current_function_decl
)
7329 /* FIXME: this should only need to look at
7330 IDENTIFIER_GLOBAL_VALUE. */
7331 tmp
= lookup_name (DECL_ASSEMBLER_NAME (decl
), 0);
7332 if (tmp
== NULL_TREE
)
7333 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl
)) = decl
;
7334 else if (TREE_CODE (tmp
) != TREE_CODE (decl
))
7335 cp_error ("inconsistent declarations for `%D'", decl
);
7338 duplicate_decls (decl
, tmp
);
7340 /* avoid creating circularities. */
7341 DECL_CHAIN (decl
) = NULL_TREE
;
7345 cplus_decl_attributes (decl
, TREE_PURPOSE (attrlist
),
7346 TREE_VALUE (attrlist
));
7347 make_decl_rtl (decl
, NULL_PTR
, 1);
7351 DECL_VIRTUAL_P (decl
) = 1;
7352 if (DECL_VINDEX (decl
) == NULL_TREE
)
7353 DECL_VINDEX (decl
) = error_mark_node
;
7354 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl
)) = 1;
7361 grokvardecl (type
, declarator
, specbits_in
, initialized
, constp
)
7364 RID_BIT_TYPE
*specbits_in
;
7369 RID_BIT_TYPE specbits
;
7371 specbits
= *specbits_in
;
7373 if (TREE_CODE (type
) == OFFSET_TYPE
)
7375 /* If you declare a static member so that it
7376 can be initialized, the code will reach here. */
7377 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
7378 type
= TREE_TYPE (type
);
7379 decl
= build_lang_field_decl (VAR_DECL
, declarator
, type
);
7380 DECL_CONTEXT (decl
) = basetype
;
7381 DECL_CLASS_CONTEXT (decl
) = basetype
;
7382 DECL_ASSEMBLER_NAME (decl
) = build_static_name (basetype
, declarator
);
7385 decl
= build_decl (VAR_DECL
, declarator
, complete_type (type
));
7387 DECL_ASSEMBLER_NAME (decl
) = current_namespace_id (DECL_ASSEMBLER_NAME (decl
));
7389 if (RIDBIT_SETP (RID_EXTERN
, specbits
))
7391 DECL_THIS_EXTERN (decl
) = 1;
7392 DECL_EXTERNAL (decl
) = !initialized
;
7395 /* In class context, static means one per class,
7396 public access, and static storage. */
7397 if (DECL_FIELD_CONTEXT (decl
) != NULL_TREE
7398 && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl
)))
7400 TREE_PUBLIC (decl
) = 1;
7401 TREE_STATIC (decl
) = 1;
7402 DECL_EXTERNAL (decl
) = 0;
7404 /* At top level, either `static' or no s.c. makes a definition
7405 (perhaps tentative), and absence of `static' makes it public. */
7406 else if (toplevel_bindings_p ())
7408 TREE_PUBLIC (decl
) = (RIDBIT_NOTSETP (RID_STATIC
, specbits
)
7409 && (DECL_THIS_EXTERN (decl
) || ! constp
));
7410 TREE_STATIC (decl
) = ! DECL_EXTERNAL (decl
);
7412 /* Not at top level, only `static' makes a static definition. */
7415 TREE_STATIC (decl
) = !! RIDBIT_SETP (RID_STATIC
, specbits
);
7416 TREE_PUBLIC (decl
) = DECL_EXTERNAL (decl
);
7421 /* Create a canonical pointer to member function type. */
7424 build_ptrmemfunc_type (type
)
7431 /* If a canonical type already exists for this type, use it. We use
7432 this method instead of type_hash_canon, because it only does a
7433 simple equality check on the list of field members. */
7435 if ((t
= TYPE_GET_PTRMEMFUNC_TYPE (type
)))
7438 push_obstacks (TYPE_OBSTACK (type
), TYPE_OBSTACK (type
));
7440 u
= make_lang_type (UNION_TYPE
);
7441 IS_AGGR_TYPE (u
) = 0;
7442 fields
[0] = build_lang_field_decl (FIELD_DECL
, pfn_identifier
, type
);
7443 fields
[1] = build_lang_field_decl (FIELD_DECL
, delta2_identifier
,
7445 finish_builtin_type (u
, "__ptrmemfunc_type", fields
, 1, ptr_type_node
);
7446 TYPE_NAME (u
) = NULL_TREE
;
7448 t
= make_lang_type (RECORD_TYPE
);
7450 /* Let the front-end know this is a pointer to member function. */
7451 TYPE_PTRMEMFUNC_FLAG (t
) = 1;
7452 /* and not really an aggregate. */
7453 IS_AGGR_TYPE (t
) = 0;
7455 fields
[0] = build_lang_field_decl (FIELD_DECL
, delta_identifier
,
7457 fields
[1] = build_lang_field_decl (FIELD_DECL
, index_identifier
,
7459 fields
[2] = build_lang_field_decl (FIELD_DECL
, pfn_or_delta2_identifier
, u
);
7460 finish_builtin_type (t
, "__ptrmemfunc_type", fields
, 2, ptr_type_node
);
7464 /* Zap out the name so that the back-end will give us the debugging
7465 information for this anonymous RECORD_TYPE. */
7466 TYPE_NAME (t
) = NULL_TREE
;
7468 TYPE_SET_PTRMEMFUNC_TYPE (type
, t
);
7470 /* Seems to be wanted. */
7471 CLASSTYPE_GOT_SEMICOLON (t
) = 1;
7475 /* Given declspecs and a declarator,
7476 determine the name and type of the object declared
7477 and construct a ..._DECL node for it.
7478 (In one case we can return a ..._TYPE node instead.
7479 For invalid input we sometimes return 0.)
7481 DECLSPECS is a chain of tree_list nodes whose value fields
7482 are the storage classes and type specifiers.
7484 DECL_CONTEXT says which syntactic context this declaration is in:
7485 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
7486 FUNCDEF for a function definition. Like NORMAL but a few different
7487 error messages in each case. Return value may be zero meaning
7488 this definition is too screwy to try to parse.
7489 MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
7490 handle member functions (which have FIELD context).
7491 Return value may be zero meaning this definition is too screwy to
7493 PARM for a parameter declaration (either within a function prototype
7494 or before a function body). Make a PARM_DECL, or return void_type_node.
7495 CATCHPARM for a parameter declaration before a catch clause.
7496 TYPENAME if for a typename (in a cast or sizeof).
7497 Don't make a DECL node; just return the ..._TYPE node.
7498 FIELD for a struct or union field; make a FIELD_DECL.
7499 BITFIELD for a field with specified width.
7500 INITIALIZED is 1 if the decl has an initializer.
7502 In the TYPENAME case, DECLARATOR is really an absolute declarator.
7503 It may also be so in the PARM case, for a prototype where the
7504 argument type is specified but not the name.
7506 This function is where the complicated C meanings of `static'
7507 and `extern' are interpreted.
7509 For C++, if there is any monkey business to do, the function which
7510 calls this one must do it, i.e., prepending instance variables,
7511 renaming overloaded function names, etc.
7513 Note that for this C++, it is an error to define a method within a class
7514 which does not belong to that class.
7516 Except in the case where SCOPE_REFs are implicitly known (such as
7517 methods within a class being redundantly qualified),
7518 declarations which involve SCOPE_REFs are returned as SCOPE_REFs
7519 (class_name::decl_name). The caller must also deal with this.
7521 If a constructor or destructor is seen, and the context is FIELD,
7522 then the type gains the attribute TREE_HAS_x. If such a declaration
7523 is erroneous, NULL_TREE is returned.
7525 QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
7526 function, these are the qualifiers to give to the `this' pointer.
7528 May return void_type_node if the declarator turned out to be a friend.
7529 See grokfield for details. */
7531 enum return_types
{ return_normal
, return_ctor
, return_dtor
, return_conversion
};
7534 grokdeclarator (declarator
, declspecs
, decl_context
, initialized
, attrlist
)
7537 enum decl_context decl_context
;
7541 RID_BIT_TYPE specbits
;
7544 tree type
= NULL_TREE
;
7548 int virtualp
, explicitp
, friendp
, inlinep
, staticp
;
7549 int explicit_int
= 0;
7550 int explicit_char
= 0;
7551 int defaulted_int
= 0;
7552 int opaque_typedef
= 0;
7553 tree typedef_decl
= NULL_TREE
;
7555 tree typedef_type
= NULL_TREE
;
7556 int funcdef_flag
= 0;
7557 enum tree_code innermost_code
= ERROR_MARK
;
7560 /* See the code below that used this. */
7561 tree decl_machine_attr
= NULL_TREE
;
7563 /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
7564 All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
7565 tree init
= NULL_TREE
;
7567 /* Keep track of what sort of function is being processed
7568 so that we can warn about default return values, or explicit
7569 return values which do not match prescribed defaults. */
7570 enum return_types return_type
= return_normal
;
7572 tree dname
= NULL_TREE
;
7573 tree ctype
= current_class_type
;
7574 tree ctor_return_type
= NULL_TREE
;
7575 enum overload_flags flags
= NO_SPECIAL
;
7576 tree quals
= NULL_TREE
;
7577 tree raises
= NULL_TREE
;
7579 RIDBIT_RESET_ALL (specbits
);
7580 if (decl_context
== FUNCDEF
)
7581 funcdef_flag
= 1, decl_context
= NORMAL
;
7582 else if (decl_context
== MEMFUNCDEF
)
7583 funcdef_flag
= -1, decl_context
= FIELD
;
7584 else if (decl_context
== BITFIELD
)
7585 bitfield
= 1, decl_context
= FIELD
;
7587 /* Look inside a declarator for the name being declared
7588 and get it as a string, for an error message. */
7590 tree
*next
= &declarator
;
7594 while (next
&& *next
)
7597 switch (TREE_CODE (decl
))
7601 next
= &TREE_OPERAND (decl
, 0);
7604 case BIT_NOT_EXPR
: /* for C++ destructors! */
7606 tree name
= TREE_OPERAND (decl
, 0);
7607 tree rename
= NULL_TREE
;
7609 my_friendly_assert (flags
== NO_SPECIAL
, 152);
7611 return_type
= return_dtor
;
7612 if (TREE_CODE (name
) == TYPE_DECL
)
7613 TREE_OPERAND (decl
, 0) = name
= constructor_name (name
);
7614 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 153);
7615 if (ctype
== NULL_TREE
)
7617 if (current_class_type
== NULL_TREE
)
7619 error ("destructors must be member functions");
7624 tree t
= constructor_name (current_class_name
);
7631 tree t
= constructor_name (ctype
);
7638 cp_error ("destructor `%T' must match class name `%T'",
7640 TREE_OPERAND (decl
, 0) = rename
;
7646 case ADDR_EXPR
: /* C++ reference declaration */
7651 innermost_code
= TREE_CODE (decl
);
7652 next
= &TREE_OPERAND (decl
, 0);
7656 if (parmlist_is_exprlist (TREE_OPERAND (decl
, 1)))
7658 /* This is actually a variable declaration using constructor
7659 syntax. We need to call start_decl and cp_finish_decl so we
7660 can get the variable initialized... */
7662 *next
= TREE_OPERAND (decl
, 0);
7663 init
= TREE_OPERAND (decl
, 1);
7665 decl
= start_decl (declarator
, declspecs
, 1);
7666 finish_decl (decl
, init
, NULL_TREE
);
7669 innermost_code
= TREE_CODE (decl
);
7670 if (decl_context
== FIELD
&& ctype
== NULL_TREE
)
7671 ctype
= current_class_type
;
7673 && TREE_OPERAND (decl
, 0)
7674 && (TREE_CODE (TREE_OPERAND (decl
, 0)) == TYPE_DECL
7675 && ((DECL_NAME (TREE_OPERAND (decl
, 0))
7676 == constructor_name_full (ctype
))
7677 || (DECL_NAME (TREE_OPERAND (decl
, 0))
7678 == constructor_name (ctype
)))))
7679 TREE_OPERAND (decl
, 0) = constructor_name (ctype
);
7680 next
= &TREE_OPERAND (decl
, 0);
7682 if (ctype
!= NULL_TREE
7683 && decl
!= NULL_TREE
&& flags
!= DTOR_FLAG
7684 && decl
== constructor_name (ctype
))
7686 return_type
= return_ctor
;
7687 ctor_return_type
= ctype
;
7692 case IDENTIFIER_NODE
:
7698 cp_error ("declarator-id missing; using reserved word `%D'",
7700 name
= IDENTIFIER_POINTER (dname
);
7702 if (! IDENTIFIER_OPNAME_P (dname
)
7703 /* Linux headers use '__op'. Arrgh. */
7704 || IDENTIFIER_TYPENAME_P (dname
) && ! TREE_TYPE (dname
))
7705 name
= IDENTIFIER_POINTER (dname
);
7708 if (IDENTIFIER_TYPENAME_P (dname
))
7710 my_friendly_assert (flags
== NO_SPECIAL
, 154);
7711 flags
= TYPENAME_FLAG
;
7712 ctor_return_type
= TREE_TYPE (dname
);
7713 return_type
= return_conversion
;
7715 name
= operator_name_string (dname
);
7722 /* Perform error checking, and decide on a ctype. */
7723 tree cname
= TREE_OPERAND (decl
, 0);
7724 if (cname
== NULL_TREE
)
7726 else if (! is_aggr_type (cname
, 1))
7727 TREE_OPERAND (decl
, 0) = NULL_TREE
;
7728 /* Must test TREE_OPERAND (decl, 1), in case user gives
7729 us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */
7730 else if (TREE_OPERAND (decl
, 1)
7731 && TREE_CODE (TREE_OPERAND (decl
, 1)) == INDIRECT_REF
)
7733 else if (TREE_CODE (cname
) == TEMPLATE_TYPE_PARM
)
7735 cp_error ("`%T::%D' is not a valid declarator", cname
,
7736 TREE_OPERAND (decl
, 1));
7737 cp_error (" perhaps you want `typename %T::%D' to make it a type",
7738 cname
, TREE_OPERAND (decl
, 1));
7739 return void_type_node
;
7741 else if (ctype
== NULL_TREE
)
7743 else if (TREE_COMPLEXITY (decl
) == current_class_depth
)
7744 TREE_OPERAND (decl
, 0) = ctype
;
7747 if (! UNIQUELY_DERIVED_FROM_P (cname
, ctype
))
7749 cp_error ("type `%T' is not derived from type `%T'",
7751 TREE_OPERAND (decl
, 0) = NULL_TREE
;
7757 if (ctype
&& TREE_CODE (TREE_OPERAND (decl
, 1)) == TYPE_DECL
7758 && ((DECL_NAME (TREE_OPERAND (decl
, 1))
7759 == constructor_name_full (ctype
))
7760 || (DECL_NAME (TREE_OPERAND (decl
, 1))
7761 == constructor_name (ctype
))))
7762 TREE_OPERAND (decl
, 1) = constructor_name (ctype
);
7763 next
= &TREE_OPERAND (decl
, 1);
7767 if (TREE_CODE (decl
) == IDENTIFIER_NODE
7768 && constructor_name (ctype
) == decl
)
7770 return_type
= return_ctor
;
7771 ctor_return_type
= ctype
;
7773 else if (TREE_CODE (decl
) == BIT_NOT_EXPR
7774 && TREE_CODE (TREE_OPERAND (decl
, 0)) == IDENTIFIER_NODE
7775 && (constructor_name (ctype
) == TREE_OPERAND (decl
, 0)
7776 || constructor_name_full (ctype
) == TREE_OPERAND (decl
, 0)))
7778 return_type
= return_dtor
;
7779 ctor_return_type
= ctype
;
7781 TREE_OPERAND (decl
, 0) = constructor_name (ctype
);
7782 next
= &TREE_OPERAND (decl
, 0);
7793 /* Parse error puts this typespec where
7794 a declarator should go. */
7795 cp_error ("`%T' specified as declarator-id", DECL_NAME (decl
));
7796 if (TREE_TYPE (decl
) == current_class_type
)
7797 cp_error (" perhaps you want `%T' for a constructor",
7798 current_class_name
);
7799 dname
= DECL_NAME (decl
);
7800 name
= IDENTIFIER_POINTER (dname
);
7802 /* Avoid giving two errors for this. */
7803 IDENTIFIER_CLASS_VALUE (dname
) = NULL_TREE
;
7805 declspecs
= temp_tree_cons (NULL_TREE
, integer_type_node
,
7812 cp_compiler_error ("`%D' as declarator", decl
);
7813 return 0; /* We used to do a 155 abort here. */
7820 /* A function definition's declarator must have the form of
7821 a function declarator. */
7823 if (funcdef_flag
&& innermost_code
!= CALL_EXPR
)
7826 if (((dname
&& IDENTIFIER_OPNAME_P (dname
)) || flags
== TYPENAME_FLAG
)
7827 && innermost_code
!= CALL_EXPR
7828 && ! (ctype
&& declspecs
== NULL_TREE
))
7830 cp_error ("declaration of `%D' as non-function", dname
);
7831 return void_type_node
;
7834 /* Anything declared one level down from the top level
7835 must be one of the parameters of a function
7836 (because the body is at least two levels down). */
7838 /* This heuristic cannot be applied to C++ nodes! Fixed, however,
7839 by not allowing C++ class definitions to specify their parameters
7840 with xdecls (must be spec.d in the parmlist).
7842 Since we now wait to push a class scope until we are sure that
7843 we are in a legitimate method context, we must set oldcname
7844 explicitly (since current_class_name is not yet alive).
7846 We also want to avoid calling this a PARM if it is in a namespace. */
7848 if (decl_context
== NORMAL
&& ! namespace_bindings_p ()
7849 && ! pseudo_global_level_p ())
7851 struct binding_level
*b
= current_binding_level
;
7852 current_binding_level
= b
->level_chain
;
7853 if (current_binding_level
!= 0 && toplevel_bindings_p ())
7854 decl_context
= PARM
;
7855 current_binding_level
= b
;
7858 /* Look through the decl specs and record which ones appear.
7859 Some typespecs are defined as built-in typenames.
7860 Others, the ones that are modifiers of other types,
7861 are represented by bits in SPECBITS: set the bits for
7862 the modifiers that appear. Storage class keywords are also in SPECBITS.
7864 If there is a typedef name or a type, store the type in TYPE.
7865 This includes builtin typedefs such as `int'.
7867 Set EXPLICIT_INT if the type is `int' or `char' and did not
7868 come from a user typedef.
7870 Set LONGLONG if `long' is mentioned twice.
7872 For C++, constructors and destructors have their own fast treatment. */
7874 for (spec
= declspecs
; spec
; spec
= TREE_CHAIN (spec
))
7879 /* Certain parse errors slip through. For example,
7880 `int class;' is not caught by the parser. Try
7881 weakly to recover here. */
7882 if (TREE_CODE (spec
) != TREE_LIST
)
7885 id
= TREE_VALUE (spec
);
7887 if (TREE_CODE (id
) == IDENTIFIER_NODE
)
7889 if (id
== ridpointers
[(int) RID_INT
]
7890 || id
== ridpointers
[(int) RID_CHAR
]
7891 || id
== ridpointers
[(int) RID_BOOL
]
7892 || id
== ridpointers
[(int) RID_WCHAR
])
7896 if (id
== ridpointers
[(int) RID_BOOL
])
7897 error ("`bool' is now a keyword");
7899 cp_error ("extraneous `%T' ignored", id
);
7903 if (id
== ridpointers
[(int) RID_INT
])
7905 else if (id
== ridpointers
[(int) RID_CHAR
])
7907 type
= TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id
));
7911 /* C++ aggregate types. */
7912 if (IDENTIFIER_HAS_TYPE_VALUE (id
))
7915 cp_error ("multiple declarations `%T' and `%T'", type
, id
);
7917 type
= IDENTIFIER_TYPE_VALUE (id
);
7921 for (i
= (int) RID_FIRST_MODIFIER
; i
<= (int) RID_LAST_MODIFIER
; i
++)
7923 if (ridpointers
[i
] == id
)
7925 if (i
== (int) RID_LONG
&& RIDBIT_SETP (i
, specbits
))
7927 if (pedantic
&& ! in_system_header
)
7928 pedwarn ("ANSI C++ does not support `long long'");
7930 error ("`long long long' is too long for GCC");
7934 else if (RIDBIT_SETP (i
, specbits
))
7935 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id
));
7936 RIDBIT_SET (i
, specbits
);
7941 /* C++ aggregate types. */
7942 else if (TREE_CODE (id
) == TYPE_DECL
)
7945 cp_error ("multiple declarations `%T' and `%T'", type
,
7949 type
= TREE_TYPE (id
);
7950 TREE_VALUE (spec
) = type
;
7955 error ("two or more data types in declaration of `%s'", name
);
7956 else if (TREE_CODE (id
) == IDENTIFIER_NODE
)
7958 register tree t
= lookup_name (id
, 1);
7959 if (!t
|| TREE_CODE (t
) != TYPE_DECL
)
7960 error ("`%s' fails to be a typedef or built in type",
7961 IDENTIFIER_POINTER (id
));
7964 type
= TREE_TYPE (t
);
7966 /* See the code below that used this. */
7967 decl_machine_attr
= DECL_MACHINE_ATTRIBUTES (id
);
7972 else if (id
!= error_mark_node
)
7973 /* Can't change CLASS nodes into RECORD nodes here! */
7979 typedef_type
= type
;
7981 /* No type at all: default to `int', and set DEFAULTED_INT
7982 because it was not a user-defined typedef.
7983 Except when we have a `typedef' inside a signature, in
7984 which case the type defaults to `unknown type' and is
7985 instantiated when assigning to a signature pointer or ref. */
7987 if (type
== NULL_TREE
7988 && (RIDBIT_SETP (RID_SIGNED
, specbits
)
7989 || RIDBIT_SETP (RID_UNSIGNED
, specbits
)
7990 || RIDBIT_SETP (RID_LONG
, specbits
)
7991 || RIDBIT_SETP (RID_SHORT
, specbits
)))
7993 /* These imply 'int'. */
7994 type
= integer_type_node
;
7998 if (type
== NULL_TREE
)
8001 if (return_type
== return_dtor
)
8002 type
= void_type_node
;
8003 else if (return_type
== return_ctor
)
8004 type
= build_pointer_type (ctor_return_type
);
8005 else if (return_type
== return_conversion
)
8006 type
= ctor_return_type
;
8007 else if (current_class_type
8008 && IS_SIGNATURE (current_class_type
)
8009 && RIDBIT_SETP (RID_TYPEDEF
, specbits
)
8010 && (decl_context
== FIELD
|| decl_context
== NORMAL
))
8014 type
= copy_node (opaque_type_node
);
8020 if (warn_return_type
8021 && return_type
== return_normal
)
8022 /* Save warning until we know what is really going on. */
8023 warn_about_return_type
= 1;
8025 else if (RIDBIT_SETP (RID_TYPEDEF
, specbits
))
8026 pedwarn ("ANSI C++ forbids typedef which does not specify a type");
8027 else if (declspecs
== NULL_TREE
8028 && (innermost_code
!= CALL_EXPR
|| pedantic
))
8029 cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class",
8031 type
= integer_type_node
;
8034 else if (return_type
== return_dtor
)
8036 error ("return type specification for destructor invalid");
8037 type
= void_type_node
;
8039 else if (return_type
== return_ctor
)
8041 error ("return type specification for constructor invalid");
8042 type
= build_pointer_type (ctor_return_type
);
8044 else if (return_type
== return_conversion
)
8046 if (comptypes (type
, ctor_return_type
, 1) == 0)
8047 cp_error ("operator `%T' declared to return `%T'",
8048 ctor_return_type
, type
);
8050 cp_pedwarn ("return type specified for `operator %T'",
8053 type
= ctor_return_type
;
8058 /* Now process the modifiers that were specified
8059 and check for invalid combinations. */
8061 /* Long double is a special combination. */
8063 if (RIDBIT_SETP (RID_LONG
, specbits
)
8064 && TYPE_MAIN_VARIANT (type
) == double_type_node
)
8066 RIDBIT_RESET (RID_LONG
, specbits
);
8067 type
= build_type_variant (long_double_type_node
, TYPE_READONLY (type
),
8068 TYPE_VOLATILE (type
));
8071 /* Check all other uses of type modifiers. */
8073 if (RIDBIT_SETP (RID_UNSIGNED
, specbits
)
8074 || RIDBIT_SETP (RID_SIGNED
, specbits
)
8075 || RIDBIT_SETP (RID_LONG
, specbits
)
8076 || RIDBIT_SETP (RID_SHORT
, specbits
))
8080 if (TREE_CODE (type
) == REAL_TYPE
)
8081 error ("short, signed or unsigned invalid for `%s'", name
);
8082 else if (TREE_CODE (type
) != INTEGER_TYPE
)
8083 error ("long, short, signed or unsigned invalid for `%s'", name
);
8084 else if (RIDBIT_SETP (RID_LONG
, specbits
)
8085 && RIDBIT_SETP (RID_SHORT
, specbits
))
8086 error ("long and short specified together for `%s'", name
);
8087 else if ((RIDBIT_SETP (RID_LONG
, specbits
)
8088 || RIDBIT_SETP (RID_SHORT
, specbits
))
8090 error ("long or short specified with char for `%s'", name
);
8091 else if ((RIDBIT_SETP (RID_LONG
, specbits
)
8092 || RIDBIT_SETP (RID_SHORT
, specbits
))
8093 && TREE_CODE (type
) == REAL_TYPE
)
8094 error ("long or short specified with floating type for `%s'", name
);
8095 else if (RIDBIT_SETP (RID_SIGNED
, specbits
)
8096 && RIDBIT_SETP (RID_UNSIGNED
, specbits
))
8097 error ("signed and unsigned given together for `%s'", name
);
8101 if (!explicit_int
&& !defaulted_int
&& !explicit_char
&& pedantic
)
8103 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
8105 if (flag_pedantic_errors
)
8110 /* Discard the type modifiers if they are invalid. */
8113 RIDBIT_RESET (RID_UNSIGNED
, specbits
);
8114 RIDBIT_RESET (RID_SIGNED
, specbits
);
8115 RIDBIT_RESET (RID_LONG
, specbits
);
8116 RIDBIT_RESET (RID_SHORT
, specbits
);
8121 if (RIDBIT_SETP (RID_COMPLEX
, specbits
)
8122 && TREE_CODE (type
) != INTEGER_TYPE
&& TREE_CODE (type
) != REAL_TYPE
)
8124 error ("complex invalid for `%s'", name
);
8125 RIDBIT_RESET (RID_COMPLEX
, specbits
);
8128 /* Decide whether an integer type is signed or not.
8129 Optionally treat bitfields as signed by default. */
8130 if (RIDBIT_SETP (RID_UNSIGNED
, specbits
)
8131 || (bitfield
&& ! flag_signed_bitfields
8132 && (explicit_int
|| defaulted_int
|| explicit_char
8133 /* A typedef for plain `int' without `signed'
8134 can be controlled just like plain `int'. */
8135 || ! (typedef_decl
!= NULL_TREE
8136 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl
)))
8137 && TREE_CODE (type
) != ENUMERAL_TYPE
8138 && RIDBIT_NOTSETP (RID_SIGNED
, specbits
)))
8141 type
= long_long_unsigned_type_node
;
8142 else if (RIDBIT_SETP (RID_LONG
, specbits
))
8143 type
= long_unsigned_type_node
;
8144 else if (RIDBIT_SETP (RID_SHORT
, specbits
))
8145 type
= short_unsigned_type_node
;
8146 else if (type
== char_type_node
)
8147 type
= unsigned_char_type_node
;
8148 else if (typedef_decl
)
8149 type
= unsigned_type (type
);
8151 type
= unsigned_type_node
;
8153 else if (RIDBIT_SETP (RID_SIGNED
, specbits
)
8154 && type
== char_type_node
)
8155 type
= signed_char_type_node
;
8157 type
= long_long_integer_type_node
;
8158 else if (RIDBIT_SETP (RID_LONG
, specbits
))
8159 type
= long_integer_type_node
;
8160 else if (RIDBIT_SETP (RID_SHORT
, specbits
))
8161 type
= short_integer_type_node
;
8163 if (RIDBIT_SETP (RID_COMPLEX
, specbits
))
8165 /* If we just have "complex", it is equivalent to
8166 "complex double", but if any modifiers at all are specified it is
8167 the complex form of TYPE. E.g, "complex short" is
8168 "complex short int". */
8170 if (defaulted_int
&& ! longlong
8171 && ! (RIDBIT_SETP (RID_LONG
, specbits
)
8172 || RIDBIT_SETP (RID_SHORT
, specbits
)
8173 || RIDBIT_SETP (RID_SIGNED
, specbits
)
8174 || RIDBIT_SETP (RID_UNSIGNED
, specbits
)))
8175 type
= complex_double_type_node
;
8176 else if (type
== integer_type_node
)
8177 type
= complex_integer_type_node
;
8178 else if (type
== float_type_node
)
8179 type
= complex_float_type_node
;
8180 else if (type
== double_type_node
)
8181 type
= complex_double_type_node
;
8182 else if (type
== long_double_type_node
)
8183 type
= complex_long_double_type_node
;
8185 type
= build_complex_type (type
);
8188 /* Set CONSTP if this declaration is `const', whether by
8189 explicit specification or via a typedef.
8190 Likewise for VOLATILEP. */
8192 constp
= !! RIDBIT_SETP (RID_CONST
, specbits
) + TYPE_READONLY (type
);
8193 volatilep
= !! RIDBIT_SETP (RID_VOLATILE
, specbits
) + TYPE_VOLATILE (type
);
8195 inlinep
= !! RIDBIT_SETP (RID_INLINE
, specbits
);
8196 virtualp
= RIDBIT_SETP (RID_VIRTUAL
, specbits
);
8197 RIDBIT_RESET (RID_VIRTUAL
, specbits
);
8198 explicitp
= RIDBIT_SETP (RID_EXPLICIT
, specbits
) != 0;
8199 RIDBIT_RESET (RID_EXPLICIT
, specbits
);
8201 if (RIDBIT_SETP (RID_STATIC
, specbits
))
8202 staticp
= 1 + (decl_context
== FIELD
);
8204 if (virtualp
&& staticp
== 2)
8206 cp_error ("member `%D' cannot be declared both virtual and static",
8210 friendp
= RIDBIT_SETP (RID_FRIEND
, specbits
);
8211 RIDBIT_RESET (RID_FRIEND
, specbits
);
8213 if (RIDBIT_SETP (RID_MUTABLE
, specbits
))
8215 if (decl_context
== PARM
)
8217 error ("non-member `%s' cannot be declared `mutable'", name
);
8218 RIDBIT_RESET (RID_MUTABLE
, specbits
);
8220 else if (friendp
|| decl_context
== TYPENAME
)
8222 error ("non-object member `%s' cannot be declared `mutable'", name
);
8223 RIDBIT_RESET (RID_MUTABLE
, specbits
);
8227 /* Warn if two storage classes are given. Default to `auto'. */
8229 if (RIDBIT_ANY_SET (specbits
))
8231 if (RIDBIT_SETP (RID_STATIC
, specbits
)) nclasses
++;
8232 if (RIDBIT_SETP (RID_EXTERN
, specbits
)) nclasses
++;
8233 if (decl_context
== PARM
&& nclasses
> 0)
8234 error ("storage class specifiers invalid in parameter declarations");
8235 if (RIDBIT_SETP (RID_TYPEDEF
, specbits
))
8237 if (decl_context
== PARM
)
8238 error ("typedef declaration invalid in parameter declaration");
8241 if (RIDBIT_SETP (RID_AUTO
, specbits
)) nclasses
++;
8242 if (RIDBIT_SETP (RID_REGISTER
, specbits
)) nclasses
++;
8245 /* Give error if `virtual' is used outside of class declaration. */
8247 && (current_class_name
== NULL_TREE
|| decl_context
!= FIELD
))
8249 error ("virtual outside class declaration");
8252 if (current_class_name
== NULL_TREE
&& RIDBIT_SETP (RID_MUTABLE
, specbits
))
8254 error ("only members can be declared mutable");
8255 RIDBIT_RESET (RID_MUTABLE
, specbits
);
8258 /* Static anonymous unions are dealt with here. */
8259 if (staticp
&& decl_context
== TYPENAME
8260 && TREE_CODE (declspecs
) == TREE_LIST
8261 && TREE_CODE (TREE_VALUE (declspecs
)) == UNION_TYPE
8262 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs
))))
8263 decl_context
= FIELD
;
8265 /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
8266 is used in a signature member function declaration. */
8267 if (decl_context
== FIELD
8268 && IS_SIGNATURE (current_class_type
)
8269 && RIDBIT_NOTSETP (RID_TYPEDEF
, specbits
))
8273 error ("`const' specified for signature member function `%s'", name
);
8278 error ("`volatile' specified for signature member function `%s'",
8284 error ("`inline' specified for signature member function `%s'", name
);
8285 /* Later, we'll make signature member functions inline. */
8290 error ("`friend' declaration in signature definition");
8295 error ("`virtual' specified for signature member function `%s'",
8297 /* Later, we'll make signature member functions virtual. */
8302 /* Warn about storage classes that are invalid for certain
8303 kinds of declarations (parameters, typenames, etc.). */
8306 error ("multiple storage classes in declaration of `%s'", name
);
8307 else if (decl_context
!= NORMAL
&& nclasses
> 0)
8309 if ((decl_context
== PARM
|| decl_context
== CATCHPARM
)
8310 && (RIDBIT_SETP (RID_REGISTER
, specbits
)
8311 || RIDBIT_SETP (RID_AUTO
, specbits
)))
8313 else if (RIDBIT_SETP (RID_TYPEDEF
, specbits
))
8315 else if (decl_context
== FIELD
8316 && ! IS_SIGNATURE (current_class_type
)
8317 /* C++ allows static class elements */
8318 && RIDBIT_SETP (RID_STATIC
, specbits
))
8319 /* C++ also allows inlines and signed and unsigned elements,
8320 but in those cases we don't come in here. */
8324 if (decl_context
== FIELD
)
8326 tree tmp
= NULL_TREE
;
8327 register int op
= 0;
8331 /* Avoid trying to get an operand off an identifier node. */
8332 if (TREE_CODE (declarator
) == IDENTIFIER_NODE
)
8335 tmp
= TREE_OPERAND (declarator
, 0);
8336 op
= IDENTIFIER_OPNAME_P (tmp
);
8338 error ("storage class specified for %s `%s'",
8339 IS_SIGNATURE (current_class_type
)
8341 ? "signature member operator"
8342 : "signature member function")
8343 : (op
? "member operator" : "field"),
8344 op
? operator_name_string (tmp
) : name
);
8347 error (((decl_context
== PARM
|| decl_context
== CATCHPARM
)
8348 ? "storage class specified for parameter `%s'"
8349 : "storage class specified for typename"), name
);
8350 RIDBIT_RESET (RID_REGISTER
, specbits
);
8351 RIDBIT_RESET (RID_AUTO
, specbits
);
8352 RIDBIT_RESET (RID_EXTERN
, specbits
);
8354 if (decl_context
== FIELD
&& IS_SIGNATURE (current_class_type
))
8356 RIDBIT_RESET (RID_STATIC
, specbits
);
8361 else if (RIDBIT_SETP (RID_EXTERN
, specbits
) && initialized
&& !funcdef_flag
)
8363 if (toplevel_bindings_p ())
8365 /* It's common practice (and completely valid) to have a const
8366 be initialized and declared extern. */
8368 warning ("`%s' initialized and declared `extern'", name
);
8371 error ("`%s' has both `extern' and initializer", name
);
8373 else if (RIDBIT_SETP (RID_EXTERN
, specbits
) && funcdef_flag
8374 && ! toplevel_bindings_p ())
8375 error ("nested function `%s' declared `extern'", name
);
8376 else if (toplevel_bindings_p ())
8378 if (RIDBIT_SETP (RID_AUTO
, specbits
))
8379 error ("top-level declaration of `%s' specifies `auto'", name
);
8382 if (nclasses
> 0 && friendp
)
8383 error ("storage class specifiers invalid in friend function declarations");
8385 /* Now figure out the structure of the declarator proper.
8386 Descend through it, creating more complex types, until we reach
8387 the declared identifier (or NULL_TREE, in an absolute declarator). */
8389 while (declarator
&& TREE_CODE (declarator
) != IDENTIFIER_NODE
)
8391 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
8392 an INDIRECT_REF (for *...),
8393 a CALL_EXPR (for ...(...)),
8394 an identifier (for the name being declared)
8395 or a null pointer (for the place in an absolute declarator
8396 where the name was omitted).
8397 For the last two cases, we have just exited the loop.
8399 For C++ it could also be
8400 a SCOPE_REF (for class :: ...). In this case, we have converted
8401 sensible names to types, and those are the values we use to
8402 qualify the member name.
8403 an ADDR_EXPR (for &...),
8404 a BIT_NOT_EXPR (for destructors)
8406 At this point, TYPE is the type of elements of an array,
8407 or for a function to return, or for a pointer to point to.
8408 After this sequence of ifs, TYPE is the type of the
8409 array or function or pointer, and DECLARATOR has had its
8410 outermost layer removed. */
8412 if (type
== error_mark_node
)
8414 if (TREE_CODE (declarator
) == SCOPE_REF
)
8415 declarator
= TREE_OPERAND (declarator
, 1);
8417 declarator
= TREE_OPERAND (declarator
, 0);
8420 if (quals
!= NULL_TREE
8421 && (declarator
== NULL_TREE
8422 || TREE_CODE (declarator
) != SCOPE_REF
))
8424 if (ctype
== NULL_TREE
&& TREE_CODE (type
) == METHOD_TYPE
)
8425 ctype
= TYPE_METHOD_BASETYPE (type
);
8426 if (ctype
!= NULL_TREE
)
8428 tree dummy
= build_decl (TYPE_DECL
, NULL_TREE
, type
);
8429 ctype
= grok_method_quals (ctype
, dummy
, quals
);
8430 type
= TREE_TYPE (dummy
);
8434 switch (TREE_CODE (declarator
))
8438 register tree itype
= NULL_TREE
;
8439 register tree size
= TREE_OPERAND (declarator
, 1);
8440 /* The index is a signed object `sizetype' bits wide. */
8441 tree index_type
= signed_type (sizetype
);
8443 declarator
= TREE_OPERAND (declarator
, 0);
8445 /* Check for some types that there cannot be arrays of. */
8447 if (TYPE_MAIN_VARIANT (type
) == void_type_node
)
8449 cp_error ("declaration of `%D' as array of voids", dname
);
8450 type
= error_mark_node
;
8453 if (TREE_CODE (type
) == FUNCTION_TYPE
)
8455 cp_error ("declaration of `%D' as array of functions", dname
);
8456 type
= error_mark_node
;
8459 /* ARM $8.4.3: Since you can't have a pointer to a reference,
8460 you can't have arrays of references. If we allowed them,
8461 then we'd be saying x[i] is valid for an array x, but
8462 then you'd have to ask: what does `*(x + i)' mean? */
8463 if (TREE_CODE (type
) == REFERENCE_TYPE
)
8465 if (decl_context
== TYPENAME
)
8466 cp_error ("cannot make arrays of references");
8468 cp_error ("declaration of `%D' as array of references",
8470 type
= error_mark_node
;
8473 if (TREE_CODE (type
) == OFFSET_TYPE
)
8475 cp_error ("declaration of `%D' as array of data members",
8477 type
= error_mark_node
;
8480 if (TREE_CODE (type
) == METHOD_TYPE
)
8482 cp_error ("declaration of `%D' as array of function members",
8484 type
= error_mark_node
;
8487 if (size
== error_mark_node
)
8488 type
= error_mark_node
;
8490 if (type
== error_mark_node
)
8495 /* Must suspend_momentary here because the index
8496 type may need to live until the end of the function.
8497 For example, it is used in the declaration of a
8498 variable which requires destructing at the end of
8499 the function; then build_vec_delete will need this
8501 int yes
= suspend_momentary ();
8502 /* might be a cast */
8503 if (TREE_CODE (size
) == NOP_EXPR
8504 && TREE_TYPE (size
) == TREE_TYPE (TREE_OPERAND (size
, 0)))
8505 size
= TREE_OPERAND (size
, 0);
8507 /* If this involves a template parameter, it'll be
8508 constant, but we don't know what the value is yet. */
8509 if (processing_template_decl
)
8511 itype
= make_node (INTEGER_TYPE
);
8512 TYPE_MIN_VALUE (itype
) = size_zero_node
;
8513 TYPE_MAX_VALUE (itype
) = build_min
8514 (MINUS_EXPR
, sizetype
, size
, integer_one_node
);
8515 goto dont_grok_size
;
8518 if (TREE_CODE (TREE_TYPE (size
)) != INTEGER_TYPE
8519 && TREE_CODE (TREE_TYPE (size
)) != ENUMERAL_TYPE
)
8521 cp_error ("size of array `%D' has non-integer type",
8523 size
= integer_one_node
;
8525 if (TREE_READONLY_DECL_P (size
))
8526 size
= decl_constant_value (size
);
8527 if (pedantic
&& integer_zerop (size
))
8528 cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname
);
8529 if (TREE_CONSTANT (size
))
8531 int old_flag_pedantic_errors
= flag_pedantic_errors
;
8532 int old_pedantic
= pedantic
;
8533 pedantic
= flag_pedantic_errors
= 1;
8534 /* Always give overflow errors on array subscripts. */
8535 constant_expression_warning (size
);
8536 pedantic
= old_pedantic
;
8537 flag_pedantic_errors
= old_flag_pedantic_errors
;
8538 if (INT_CST_LT (size
, integer_zero_node
))
8540 cp_error ("size of array `%D' is negative", dname
);
8541 size
= integer_one_node
;
8549 cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
8552 cp_pedwarn ("ANSI C++ forbids variable-size array");
8557 = fold (build_binary_op (MINUS_EXPR
,
8558 cp_convert (index_type
, size
),
8559 cp_convert (index_type
,
8560 integer_one_node
), 1));
8561 if (! TREE_CONSTANT (itype
))
8562 itype
= variable_size (itype
);
8563 else if (TREE_OVERFLOW (itype
))
8565 error ("overflow in array dimension");
8566 TREE_OVERFLOW (itype
) = 0;
8569 /* If we're a parm, we need to have a permanent type so
8570 mangling checks for re-use will work right. If both the
8571 element and index types are permanent, the array type
8573 if (decl_context
== PARM
8574 && allocation_temporary_p () && TREE_PERMANENT (type
))
8576 push_obstacks (&permanent_obstack
, &permanent_obstack
);
8577 itype
= build_index_type (itype
);
8581 itype
= build_index_type (itype
);
8584 resume_momentary (yes
);
8587 /* Build the array type itself, then merge any constancy or
8588 volatility into the target type. We must do it in this order
8589 to ensure that the TYPE_MAIN_VARIANT field of the array type
8590 is set correctly. */
8592 type
= build_cplus_array_type (type
, itype
);
8593 if (constp
|| volatilep
)
8594 type
= cp_build_type_variant (type
, constp
, volatilep
);
8604 tree inner_parms
= TREE_OPERAND (declarator
, 1);
8605 tree inner_decl
= TREE_OPERAND (declarator
, 0);
8607 /* Declaring a function type.
8608 Make sure we have a valid type for the function to return. */
8610 /* Is this an error? Should they be merged into TYPE here? */
8611 if (pedantic
&& (constp
|| volatilep
))
8612 pedwarn ("function declared to return const or volatile result");
8614 /* Merge any constancy or volatility into the function return
8617 if (constp
|| volatilep
)
8619 type
= cp_build_type_variant (type
, constp
, volatilep
);
8620 if (IS_AGGR_TYPE (type
))
8621 build_pointer_type (type
);
8627 /* Warn about some types functions can't return. */
8629 if (TREE_CODE (type
) == FUNCTION_TYPE
)
8631 error ("`%s' declared as function returning a function", name
);
8632 type
= integer_type_node
;
8634 if (TREE_CODE (type
) == ARRAY_TYPE
)
8636 error ("`%s' declared as function returning an array", name
);
8637 type
= integer_type_node
;
8640 if (inner_decl
&& TREE_CODE (inner_decl
) == SCOPE_REF
)
8641 inner_decl
= TREE_OPERAND (inner_decl
, 1);
8643 /* Pick up type qualifiers which should be applied to `this'. */
8644 quals
= TREE_OPERAND (declarator
, 2);
8646 /* Pick up the exception specifications. */
8647 raises
= TREE_TYPE (declarator
);
8649 /* Say it's a definition only for the CALL_EXPR
8650 closest to the identifier. */
8652 = inner_decl
&& (TREE_CODE (inner_decl
) == IDENTIFIER_NODE
8653 || TREE_CODE (inner_decl
) == BIT_NOT_EXPR
);
8655 if (ctype
== NULL_TREE
8656 && decl_context
== FIELD
8658 && (friendp
== 0 || dname
== current_class_name
))
8659 ctype
= current_class_type
;
8661 if (ctype
&& return_type
== return_conversion
)
8662 TYPE_HAS_CONVERSION (ctype
) = 1;
8663 if (ctype
&& constructor_name (ctype
) == dname
)
8665 /* We are within a class's scope. If our declarator name
8666 is the same as the class name, and we are defining
8667 a function, then it is a constructor/destructor, and
8668 therefore returns a void type. */
8670 if (flags
== DTOR_FLAG
)
8672 /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may
8673 not be declared const or volatile. A destructor
8674 may not be static. */
8676 error ("destructor cannot be static member function");
8679 error ("destructors cannot be declared `const' or `volatile'");
8680 return void_type_node
;
8682 if (decl_context
== FIELD
)
8684 if (! member_function_or_else (ctype
, current_class_type
,
8685 "destructor for alien class `%s' cannot be a member"))
8686 return void_type_node
;
8689 else /* it's a constructor. */
8693 /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may
8694 not be declared const or volatile. A constructor may
8695 not be virtual. A constructor may not be static. */
8697 error ("constructor cannot be static member function");
8700 pedwarn ("constructors cannot be declared virtual");
8705 error ("constructors cannot be declared `const' or `volatile'");
8706 return void_type_node
;
8709 RID_BIT_TYPE tmp_bits
;
8710 bcopy ((void*)&specbits
, (void*)&tmp_bits
, sizeof (RID_BIT_TYPE
));
8711 RIDBIT_RESET (RID_INLINE
, tmp_bits
);
8712 RIDBIT_RESET (RID_STATIC
, tmp_bits
);
8713 if (RIDBIT_ANY_SET (tmp_bits
))
8714 error ("return value type specifier for constructor ignored");
8716 type
= build_pointer_type (ctype
);
8717 if (decl_context
== FIELD
8718 && IS_SIGNATURE (current_class_type
))
8720 error ("constructor not allowed in signature");
8721 return void_type_node
;
8723 else if (decl_context
== FIELD
)
8725 if (! member_function_or_else (ctype
, current_class_type
,
8726 "constructor for alien class `%s' cannot be member"))
8727 return void_type_node
;
8728 TYPE_HAS_CONSTRUCTOR (ctype
) = 1;
8729 if (return_type
!= return_ctor
)
8733 if (decl_context
== FIELD
)
8739 error ("can't initialize friend function `%s'", name
);
8742 /* Cannot be both friend and virtual. */
8743 error ("virtual functions cannot be friends");
8744 RIDBIT_RESET (RID_FRIEND
, specbits
);
8747 if (decl_context
== NORMAL
)
8748 error ("friend declaration not in class definition");
8749 if (current_function_decl
&& funcdef_flag
)
8750 cp_error ("can't define friend function `%s' in a local class definition",
8754 /* Construct the function type and go to the next
8755 inner layer of declarator. */
8757 declarator
= TREE_OPERAND (declarator
, 0);
8759 /* FIXME: This is where default args should be fully
8762 arg_types
= grokparms (inner_parms
, funcdecl_p
? funcdef_flag
: 0);
8766 /* Get past destructors, etc.
8767 We know we have one because FLAGS will be non-zero.
8769 Complain about improper parameter lists here. */
8770 if (TREE_CODE (declarator
) == BIT_NOT_EXPR
)
8772 declarator
= TREE_OPERAND (declarator
, 0);
8774 if (strict_prototype
== 0 && arg_types
== NULL_TREE
)
8775 arg_types
= void_list_node
;
8776 else if (arg_types
== NULL_TREE
8777 || arg_types
!= void_list_node
)
8779 error ("destructors cannot be specified with parameters");
8780 arg_types
= void_list_node
;
8785 /* ANSI says that `const int foo ();'
8786 does not make the function foo const. */
8787 type
= build_function_type (type
, arg_types
);
8791 for (t
= arg_types
; t
; t
= TREE_CHAIN (t
))
8792 if (TREE_PURPOSE (t
)
8793 && TREE_CODE (TREE_PURPOSE (t
)) == DEFAULT_ARG
)
8795 add_defarg_fn (type
);
8804 /* Filter out pointers-to-references and references-to-references.
8805 We can get these if a TYPE_DECL is used. */
8807 if (TREE_CODE (type
) == REFERENCE_TYPE
)
8809 error ("cannot declare %s to references",
8810 TREE_CODE (declarator
) == ADDR_EXPR
8811 ? "references" : "pointers");
8812 declarator
= TREE_OPERAND (declarator
, 0);
8816 if (TREE_CODE (type
) == OFFSET_TYPE
8817 && (TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
8818 || TREE_CODE (TREE_TYPE (type
)) == REFERENCE_TYPE
))
8820 cp_error ("cannot declare pointer to `%#T' member",
8822 type
= TREE_TYPE (type
);
8825 /* Merge any constancy or volatility into the target type
8828 if (constp
|| volatilep
)
8830 /* A const or volatile signature pointer/reference is
8831 pointing to a const or volatile object, i.e., the
8832 `optr' is const or volatile, respectively, not the
8833 signature pointer/reference itself. */
8834 if (! IS_SIGNATURE (type
))
8836 type
= cp_build_type_variant (type
, constp
, volatilep
);
8837 if (IS_AGGR_TYPE (type
))
8838 build_pointer_type (type
);
8844 if (IS_SIGNATURE (type
))
8846 if (TREE_CODE (declarator
) == ADDR_EXPR
)
8848 if (CLASSTYPE_METHOD_VEC (type
) == NULL_TREE
8849 && TYPE_SIZE (type
))
8850 cp_warning ("empty signature `%T' used in signature reference declaration",
8853 type
= build_signature_reference_type (type
,
8856 sorry ("signature reference");
8862 if (CLASSTYPE_METHOD_VEC (type
) == NULL_TREE
8863 && TYPE_SIZE (type
))
8864 cp_warning ("empty signature `%T' used in signature pointer declaration",
8866 type
= build_signature_pointer_type (type
,
8872 else if (TREE_CODE (declarator
) == ADDR_EXPR
)
8874 if (TREE_CODE (type
) == FUNCTION_TYPE
)
8876 error ("cannot declare references to functions; use pointer to function instead");
8877 type
= build_pointer_type (type
);
8881 if (TYPE_MAIN_VARIANT (type
) == void_type_node
)
8882 error ("invalid type: `void &'");
8884 type
= build_reference_type (type
);
8887 else if (TREE_CODE (type
) == METHOD_TYPE
)
8889 type
= build_ptrmemfunc_type (build_pointer_type (type
));
8892 type
= build_pointer_type (type
);
8894 /* Process a list of type modifier keywords (such as
8895 const or volatile) that were given inside the `*' or `&'. */
8897 if (TREE_TYPE (declarator
))
8899 register tree typemodlist
;
8901 for (typemodlist
= TREE_TYPE (declarator
); typemodlist
;
8902 typemodlist
= TREE_CHAIN (typemodlist
))
8904 if (TREE_VALUE (typemodlist
) == ridpointers
[(int) RID_CONST
])
8906 else if (TREE_VALUE (typemodlist
) == ridpointers
[(int) RID_VOLATILE
])
8911 error ("invalid type modifier within %s declarator",
8912 TREE_CODE (declarator
) == ADDR_EXPR
8913 ? "reference" : "pointer");
8917 pedwarn ("duplicate `const'");
8919 pedwarn ("duplicate `volatile'");
8920 if (TREE_CODE (declarator
) == ADDR_EXPR
8921 && (constp
|| volatilep
))
8924 pedwarn ("discarding `const' applied to a reference");
8926 pedwarn ("discarding `volatile' applied to a reference");
8927 constp
= volatilep
= 0;
8930 declarator
= TREE_OPERAND (declarator
, 0);
8936 /* We have converted type names to NULL_TREE if the
8937 name was bogus, or to a _TYPE node, if not.
8939 The variable CTYPE holds the type we will ultimately
8940 resolve to. The code here just needs to build
8941 up appropriate member types. */
8942 tree sname
= TREE_OPERAND (declarator
, 1);
8943 /* Destructors can have their visibilities changed as well. */
8944 if (TREE_CODE (sname
) == BIT_NOT_EXPR
)
8945 sname
= TREE_OPERAND (sname
, 0);
8947 if (TREE_COMPLEXITY (declarator
) == 0)
8948 /* This needs to be here, in case we are called
8949 multiple times. */ ;
8950 else if (friendp
&& (TREE_COMPLEXITY (declarator
) < 2))
8951 /* don't fall out into global scope. Hides real bug? --eichin */ ;
8952 else if (! IS_AGGR_TYPE_CODE
8953 (TREE_CODE (TREE_OPERAND (declarator
, 0))))
8955 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
8957 /* Resolve any TYPENAME_TYPEs from the decl-specifier-seq
8958 that refer to ctype. They couldn't be resolved earlier
8959 because we hadn't pushed into the class yet.
8960 Example: resolve 'B<T>::type' in
8961 'B<typename B<T>::type> B<T>::f () { }'. */
8962 if (current_template_parms
8963 && uses_template_parms (type
)
8964 && uses_template_parms (current_class_type
))
8966 tree args
= current_template_args ();
8967 type
= tsubst (type
, args
,
8968 TREE_VEC_LENGTH (TREE_VEC_ELT
8973 /* This pop_nested_class corresponds to the
8974 push_nested_class used to push into class scope for
8975 parsing the argument list of a function decl, in
8977 pop_nested_class (1);
8978 TREE_COMPLEXITY (declarator
) = current_class_depth
;
8981 my_friendly_abort (16);
8983 if (TREE_OPERAND (declarator
, 0) == NULL_TREE
)
8985 /* We had a reference to a global decl, or
8986 perhaps we were given a non-aggregate typedef,
8987 in which case we cleared this out, and should just
8988 keep going as though it wasn't there. */
8992 ctype
= TREE_OPERAND (declarator
, 0);
8994 if (sname
== NULL_TREE
)
8997 if (TREE_CODE (sname
) == IDENTIFIER_NODE
)
8999 /* This is the `standard' use of the scoping operator:
9000 basetype :: member . */
9002 if (ctype
== current_class_type
)
9008 Is this ill-formed? */
9011 cp_pedwarn ("extra qualification `%T::' on member `%s' ignored",
9014 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
9016 if (current_class_type
== NULL_TREE
9018 type
= build_cplus_method_type (build_type_variant (ctype
, constp
, volatilep
),
9019 TREE_TYPE (type
), TYPE_ARG_TYPES (type
));
9022 cp_error ("cannot declare member function `%T::%s' within `%T'",
9023 ctype
, name
, current_class_type
);
9024 return void_type_node
;
9027 else if (RIDBIT_SETP (RID_TYPEDEF
, specbits
)
9028 || TYPE_SIZE (complete_type (ctype
)) != NULL_TREE
)
9030 /* have to move this code elsewhere in this function.
9031 this code is used for i.e., typedef int A::M; M *pm;
9033 It is? How? jason 10/2/94 */
9035 if (current_class_type
)
9037 cp_error ("cannot declare member `%T::%s' within `%T'",
9038 ctype
, name
, current_class_type
);
9039 return void_type_node
;
9041 type
= build_offset_type (ctype
, type
);
9043 else if (uses_template_parms (ctype
))
9045 if (TREE_CODE (type
) == FUNCTION_TYPE
)
9047 = build_cplus_method_type (build_type_variant (ctype
,
9051 TYPE_ARG_TYPES (type
));
9055 cp_error ("structure `%T' not yet defined", ctype
);
9056 return error_mark_node
;
9061 else if (TREE_CODE (sname
) == SCOPE_REF
)
9062 my_friendly_abort (17);
9066 declarator
= TREE_OPERAND (declarator
, 1);
9067 if (declarator
&& TREE_CODE (declarator
) == CALL_EXPR
)
9068 /* In this case, we will deal with it later. */
9072 if (TREE_CODE (type
) == FUNCTION_TYPE
)
9073 type
= build_cplus_method_type (build_type_variant (ctype
, constp
, volatilep
), TREE_TYPE (type
), TYPE_ARG_TYPES (type
));
9075 type
= build_offset_type (ctype
, type
);
9082 declarator
= TREE_OPERAND (declarator
, 0);
9088 declarator
= NULL_TREE
;
9092 declarator
= NULL_TREE
;
9096 my_friendly_abort (158);
9102 error ("only constructors can be declared `explicit'");
9106 /* Now TYPE has the actual type. */
9108 /* If this is declaring a typedef name, return a TYPE_DECL. */
9110 if (RIDBIT_SETP (RID_MUTABLE
, specbits
))
9114 error ("const `%s' cannot be declared `mutable'", name
);
9115 RIDBIT_RESET (RID_MUTABLE
, specbits
);
9119 error ("static `%s' cannot be declared `mutable'", name
);
9120 RIDBIT_RESET (RID_MUTABLE
, specbits
);
9124 if (RIDBIT_SETP (RID_TYPEDEF
, specbits
) && decl_context
!= TYPENAME
)
9128 /* Note that the grammar rejects storage classes
9129 in typenames, fields or parameters. */
9130 if (constp
|| volatilep
)
9131 type
= cp_build_type_variant (type
, constp
, volatilep
);
9133 if (decl_context
== FIELD
)
9135 if (declarator
== current_class_name
)
9136 cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class",
9138 decl
= build_lang_decl (TYPE_DECL
, declarator
, type
);
9139 if (IS_SIGNATURE (current_class_type
) && opaque_typedef
)
9140 SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type
) = 1;
9143 decl
= build_decl (TYPE_DECL
, declarator
, type
);
9145 /* If the user declares "struct {...} foo" then `foo' will have
9146 an anonymous name. Fill that name in now. Nothing can
9147 refer to it, so nothing needs know about the name change.
9148 The TYPE_NAME field was filled in by build_struct_xref. */
9149 if (type
!= error_mark_node
9151 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9152 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type
)))
9154 /* replace the anonymous name with the real name everywhere. */
9155 lookup_tag_reverse (type
, declarator
);
9156 TYPE_NAME (type
) = decl
;
9158 if (TYPE_LANG_SPECIFIC (type
))
9159 TYPE_WAS_ANONYMOUS (type
) = 1;
9161 DECL_ASSEMBLER_NAME (decl
) = DECL_NAME (decl
);
9162 DECL_ASSEMBLER_NAME (decl
)
9163 = get_identifier (build_overload_name (type
, 1, 1));
9166 if (TREE_CODE (type
) == OFFSET_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
9168 cp_error_at ("typedef name may not be class-qualified", decl
);
9173 if (ctype
== NULL_TREE
)
9175 if (TREE_CODE (type
) != METHOD_TYPE
)
9176 cp_error_at ("invalid type qualifier for non-method type", decl
);
9178 ctype
= TYPE_METHOD_BASETYPE (type
);
9180 if (ctype
!= NULL_TREE
)
9181 grok_method_quals (ctype
, decl
, quals
);
9184 if (RIDBIT_SETP (RID_SIGNED
, specbits
)
9185 || (typedef_decl
&& C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl
)))
9186 C_TYPEDEF_EXPLICITLY_SIGNED (decl
) = 1;
9188 if (RIDBIT_SETP (RID_MUTABLE
, specbits
))
9190 error ("non-object member `%s' cannot be declared mutable", name
);
9193 bad_specifiers (decl
, "type", virtualp
, quals
!= NULL_TREE
,
9194 inlinep
, friendp
, raises
!= NULL_TREE
);
9197 error ("typedef declaration includes an initializer");
9202 /* Detect the case of an array type of unspecified size
9203 which came, as such, direct from a typedef name.
9204 We must copy the type, so that each identifier gets
9205 a distinct type, so that each identifier's size can be
9206 controlled separately by its own initializer. */
9208 if (type
== typedef_type
&& TREE_CODE (type
) == ARRAY_TYPE
9209 && TYPE_DOMAIN (type
) == NULL_TREE
)
9211 type
= build_cplus_array_type (TREE_TYPE (type
), TYPE_DOMAIN (type
));
9214 /* If this is a type name (such as, in a cast or sizeof),
9215 compute the type and return it now. */
9217 if (decl_context
== TYPENAME
)
9219 /* Note that the grammar rejects storage classes
9220 in typenames, fields or parameters. */
9221 if (constp
|| volatilep
)
9222 if (IS_SIGNATURE (type
))
9223 error ("`const' or `volatile' specified with signature type");
9225 type
= cp_build_type_variant (type
, constp
, volatilep
);
9227 /* Special case: "friend class foo" looks like a TYPENAME context. */
9232 cp_error ("`volatile' specified for friend class declaration");
9237 cp_error ("`inline' specified for friend class declaration");
9241 /* Only try to do this stuff if we didn't already give up. */
9242 if (type
!= integer_type_node
)
9244 /* A friendly class? */
9245 if (current_class_type
)
9246 make_friend_class (current_class_type
, TYPE_MAIN_VARIANT (type
));
9248 error ("trying to make class `%s' a friend of global scope",
9249 TYPE_NAME_STRING (type
));
9250 type
= void_type_node
;
9255 tree dummy
= build_decl (TYPE_DECL
, declarator
, type
);
9256 if (ctype
== NULL_TREE
)
9258 my_friendly_assert (TREE_CODE (type
) == METHOD_TYPE
, 159);
9259 ctype
= TYPE_METHOD_BASETYPE (type
);
9261 grok_method_quals (ctype
, dummy
, quals
);
9262 type
= TREE_TYPE (dummy
);
9267 else if (declarator
== NULL_TREE
&& decl_context
!= PARM
9268 && decl_context
!= CATCHPARM
9269 && TREE_CODE (type
) != UNION_TYPE
9272 cp_error ("abstract declarator `%T' used as declaration", type
);
9273 declarator
= make_anon_name ();
9276 /* `void' at top level (not within pointer)
9277 is allowed only in typedefs or type names.
9278 We don't complain about parms either, but that is because
9279 a better error message can be made later. */
9281 if (TYPE_MAIN_VARIANT (type
) == void_type_node
&& decl_context
!= PARM
)
9284 error ("unnamed variable or field declared void");
9285 else if (TREE_CODE (declarator
) == IDENTIFIER_NODE
)
9287 if (IDENTIFIER_OPNAME_P (declarator
))
9288 my_friendly_abort (356);
9290 error ("variable or field `%s' declared void", name
);
9293 error ("variable or field declared void");
9294 type
= integer_type_node
;
9297 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
9298 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
9303 if (decl_context
== PARM
)
9306 error ("cannot use `::' in parameter declaration");
9308 /* A parameter declared as an array of T is really a pointer to T.
9309 One declared as a function is really a pointer to a function.
9310 One declared as a member is really a pointer to member. */
9312 if (TREE_CODE (type
) == ARRAY_TYPE
)
9314 /* Transfer const-ness of array into that of type pointed to. */
9315 type
= build_pointer_type
9316 (cp_build_type_variant (TREE_TYPE (type
), constp
, volatilep
));
9317 volatilep
= constp
= 0;
9319 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
9320 type
= build_pointer_type (type
);
9321 else if (TREE_CODE (type
) == OFFSET_TYPE
)
9322 type
= build_pointer_type (type
);
9323 else if (type
== void_type_node
&& declarator
)
9325 error ("declaration of `%s' as void", name
);
9329 decl
= build_decl (PARM_DECL
, declarator
, complete_type (type
));
9331 bad_specifiers (decl
, "parameter", virtualp
, quals
!= NULL_TREE
,
9332 inlinep
, friendp
, raises
!= NULL_TREE
);
9333 if (current_class_type
9334 && IS_SIGNATURE (current_class_type
))
9337 error ("parameter of signature member function declared `inline'");
9338 if (RIDBIT_SETP (RID_AUTO
, specbits
))
9339 error ("parameter of signature member function declared `auto'");
9340 if (RIDBIT_SETP (RID_REGISTER
, specbits
))
9341 error ("parameter of signature member function declared `register'");
9344 /* Compute the type actually passed in the parmlist,
9345 for the case where there is no prototype.
9346 (For example, shorts and chars are passed as ints.)
9347 When there is a prototype, this is overridden later. */
9349 DECL_ARG_TYPE (decl
) = type_promotes_to (type
);
9351 else if (decl_context
== FIELD
)
9353 if (type
== error_mark_node
)
9355 /* Happens when declaring arrays of sizes which
9356 are error_mark_node, for example. */
9359 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
9363 /* We catch the others as conflicts with the builtin
9365 if (friendp
&& declarator
== ridpointers
[(int) RID_SIGNED
])
9367 cp_error ("function `%D' cannot be declared friend",
9374 if (ctype
== NULL_TREE
)
9375 ctype
= current_class_type
;
9377 if (ctype
== NULL_TREE
)
9379 cp_error ("can't make `%D' into a method -- not in a class",
9381 return void_type_node
;
9384 /* ``A union may [ ... ] not [ have ] virtual functions.''
9386 if (virtualp
&& TREE_CODE (ctype
) == UNION_TYPE
)
9388 cp_error ("function `%D' declared virtual inside a union",
9390 return void_type_node
;
9393 if (declarator
== ansi_opname
[(int) NEW_EXPR
]
9394 || declarator
== ansi_opname
[(int) VEC_NEW_EXPR
]
9395 || declarator
== ansi_opname
[(int) DELETE_EXPR
]
9396 || declarator
== ansi_opname
[(int) VEC_DELETE_EXPR
])
9400 cp_error ("`%D' cannot be declared virtual, since it is always static",
9405 else if (staticp
< 2)
9406 type
= build_cplus_method_type (build_type_variant (ctype
, constp
, volatilep
),
9407 TREE_TYPE (type
), TYPE_ARG_TYPES (type
));
9410 /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
9411 publicp
= (! friendp
|| ! staticp
);
9412 decl
= grokfndecl (ctype
, type
, declarator
,
9413 virtualp
, flags
, quals
, raises
, attrlist
,
9414 friendp
? -1 : 0, publicp
, inlinep
,
9416 if (decl
== NULL_TREE
)
9419 /* This clobbers the attrs stored in `decl' from `attrlist'. */
9420 /* The decl and setting of decl_machine_attr is also turned off. */
9421 decl
= build_decl_attribute_variant (decl
, decl_machine_attr
);
9425 DECL_NONCONVERTING_P (decl
) = 1;
9427 else if (TREE_CODE (type
) == METHOD_TYPE
)
9429 /* We only get here for friend declarations of
9430 members of other classes. */
9431 /* All method decls are public, so tell grokfndecl to set
9432 TREE_PUBLIC, also. */
9433 decl
= grokfndecl (ctype
, type
, declarator
,
9434 virtualp
, flags
, quals
, raises
, attrlist
,
9435 friendp
? -1 : 0, 1, 0, funcdef_flag
);
9436 if (decl
== NULL_TREE
)
9439 else if (!staticp
&& ! processing_template_decl
9440 && TYPE_SIZE (complete_type (type
)) == NULL_TREE
9441 && (TREE_CODE (type
) != ARRAY_TYPE
|| initialized
== 0))
9444 cp_error ("field `%D' has incomplete type", declarator
);
9446 cp_error ("name `%T' has incomplete type", type
);
9448 /* If we're instantiating a template, tell them which
9449 instantiation made the field's type be incomplete. */
9450 if (current_class_type
9451 && TYPE_NAME (current_class_type
)
9452 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type
))
9453 && declspecs
&& TREE_VALUE (declspecs
)
9454 && TREE_TYPE (TREE_VALUE (declspecs
)) == type
)
9455 cp_error (" in instantiation of template `%T'",
9456 current_class_type
);
9458 type
= error_mark_node
;
9465 error ("`%s' is neither function nor method; cannot be declared friend",
9466 IDENTIFIER_POINTER (declarator
));
9474 /* Friends are treated specially. */
9475 if (ctype
== current_class_type
)
9476 warning ("member functions are implicitly friends of their class");
9480 if (decl
&& DECL_NAME (decl
))
9481 t
= do_friend (ctype
, declarator
, decl
,
9482 last_function_parms
, flags
, quals
,
9484 if (t
&& funcdef_flag
)
9487 return void_type_node
;
9491 /* Structure field. It may not be a function, except for C++ */
9493 if (decl
== NULL_TREE
)
9497 /* Motion 10 at San Diego: If a static const integral data
9498 member is initialized with an integral constant
9499 expression, the initializer may appear either in the
9500 declaration (within the class), or in the definition,
9501 but not both. If it appears in the class, the member is
9502 a member constant. The file-scope definition is always
9509 cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
9512 else if (! INTEGRAL_TYPE_P (type
))
9513 cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator
, type
);
9517 /* Note that initialization of const members is prohibited
9518 by the draft ANSI standard, though it appears to be in
9519 common practice. 12.6.2: The argument list is used to
9520 initialize the named nonstatic member.... This (or an
9521 initializer list) is the only way to initialize
9522 nonstatic const and reference members. */
9523 else if (pedantic
|| ! constp
)
9524 cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
9525 constp
? "const member" : "member", declarator
);
9528 if (staticp
|| (constp
&& initialized
))
9530 /* ANSI C++ Apr '95 wp 9.2 */
9531 if (staticp
&& declarator
== current_class_name
)
9532 cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class",
9535 /* C++ allows static class members.
9536 All other work for this is done by grokfield.
9537 This VAR_DECL is built by build_lang_field_decl.
9538 All other VAR_DECLs are built by build_decl. */
9539 decl
= build_lang_field_decl (VAR_DECL
, declarator
, type
);
9540 TREE_STATIC (decl
) = 1;
9541 /* In class context, 'static' means public access. */
9542 TREE_PUBLIC (decl
) = DECL_EXTERNAL (decl
) = !!staticp
;
9546 decl
= build_lang_field_decl (FIELD_DECL
, declarator
, type
);
9547 if (RIDBIT_SETP (RID_MUTABLE
, specbits
))
9549 DECL_MUTABLE_P (decl
) = 1;
9550 RIDBIT_RESET (RID_MUTABLE
, specbits
);
9554 bad_specifiers (decl
, "field", virtualp
, quals
!= NULL_TREE
,
9555 inlinep
, friendp
, raises
!= NULL_TREE
);
9558 else if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
9560 tree original_name
= declarator
;
9566 if (RIDBIT_SETP (RID_AUTO
, specbits
))
9567 error ("storage class `auto' invalid for function `%s'", name
);
9568 else if (RIDBIT_SETP (RID_REGISTER
, specbits
))
9569 error ("storage class `register' invalid for function `%s'", name
);
9571 /* Function declaration not at top level.
9572 Storage classes other than `extern' are not allowed
9573 and `extern' makes no difference. */
9574 if (! toplevel_bindings_p ()
9575 && (RIDBIT_SETP (RID_STATIC
, specbits
)
9576 || RIDBIT_SETP (RID_INLINE
, specbits
))
9579 if (RIDBIT_SETP (RID_STATIC
, specbits
))
9580 pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name
);
9582 pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name
);
9585 if (ctype
== NULL_TREE
)
9589 error ("virtual non-class function `%s'", name
);
9593 if (current_lang_name
== lang_name_cplusplus
9594 && ! processing_template_decl
9595 && ! (IDENTIFIER_LENGTH (original_name
) == 4
9596 && IDENTIFIER_POINTER (original_name
)[0] == 'm'
9597 && strcmp (IDENTIFIER_POINTER (original_name
), "main") == 0)
9598 && ! (IDENTIFIER_LENGTH (original_name
) > 10
9599 && IDENTIFIER_POINTER (original_name
)[0] == '_'
9600 && IDENTIFIER_POINTER (original_name
)[1] == '_'
9601 && strncmp (IDENTIFIER_POINTER (original_name
)+2, "builtin_", 8) == 0))
9602 /* Plain overloading: will not be grok'd by grokclassfn. */
9603 declarator
= build_decl_overload (dname
, TYPE_ARG_TYPES (type
), 0);
9605 else if (TREE_CODE (type
) == FUNCTION_TYPE
&& staticp
< 2)
9606 type
= build_cplus_method_type (build_type_variant (ctype
, constp
, volatilep
),
9607 TREE_TYPE (type
), TYPE_ARG_TYPES (type
));
9609 /* Record presence of `static'. */
9610 publicp
= (ctype
!= NULL_TREE
9611 || RIDBIT_SETP (RID_EXTERN
, specbits
)
9612 || !RIDBIT_SETP (RID_STATIC
, specbits
));
9614 decl
= grokfndecl (ctype
, type
, original_name
,
9615 virtualp
, flags
, quals
, raises
, attrlist
,
9617 publicp
, inlinep
, funcdef_flag
);
9618 if (decl
== NULL_TREE
)
9621 if (ctype
== NULL_TREE
&& DECL_LANGUAGE (decl
) != lang_c
)
9622 DECL_ASSEMBLER_NAME (decl
) = current_namespace_id (declarator
);
9626 int illegal_static
= 0;
9628 /* Don't allow a static member function in a class, and forbid
9629 declaring main to be static. */
9630 if (TREE_CODE (type
) == METHOD_TYPE
)
9632 cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl
);
9635 else if (current_function_decl
)
9637 /* FIXME need arm citation */
9638 error ("cannot declare static function inside another function");
9645 RIDBIT_RESET (RID_STATIC
, specbits
);
9651 /* It's a variable. */
9653 if (decl_context
== CATCHPARM
)
9658 error ("cannot use `::' in parameter declaration");
9661 /* A parameter declared as an array of T is really a pointer to T.
9662 One declared as a function is really a pointer to a function.
9663 One declared as a member is really a pointer to member. */
9665 if (TREE_CODE (type
) == ARRAY_TYPE
)
9667 /* Transfer const-ness of array into that of type
9669 type
= build_pointer_type
9670 (cp_build_type_variant (TREE_TYPE (type
), constp
, volatilep
));
9671 volatilep
= constp
= 0;
9673 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
9674 type
= build_pointer_type (type
);
9675 else if (TREE_CODE (type
) == OFFSET_TYPE
)
9676 type
= build_pointer_type (type
);
9679 /* An uninitialized decl with `extern' is a reference. */
9680 decl
= grokvardecl (type
, declarator
, &specbits
, initialized
, constp
);
9681 bad_specifiers (decl
, "variable", virtualp
, quals
!= NULL_TREE
,
9682 inlinep
, friendp
, raises
!= NULL_TREE
);
9686 DECL_CONTEXT (decl
) = ctype
;
9689 cp_pedwarn ("static member `%D' re-declared as static", decl
);
9691 RIDBIT_RESET (RID_STATIC
, specbits
);
9693 if (RIDBIT_SETP (RID_REGISTER
, specbits
) && TREE_STATIC (decl
))
9695 cp_error ("static member `%D' declared `register'", decl
);
9696 RIDBIT_RESET (RID_REGISTER
, specbits
);
9698 if (RIDBIT_SETP (RID_EXTERN
, specbits
) && pedantic
)
9700 cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage",
9702 RIDBIT_RESET (RID_EXTERN
, specbits
);
9707 if (RIDBIT_SETP (RID_MUTABLE
, specbits
))
9709 error ("`%s' cannot be declared mutable", name
);
9712 /* Record `register' declaration for warnings on &
9713 and in case doing stupid register allocation. */
9715 if (RIDBIT_SETP (RID_REGISTER
, specbits
))
9716 DECL_REGISTER (decl
) = 1;
9718 if (RIDBIT_SETP (RID_EXTERN
, specbits
))
9719 DECL_THIS_EXTERN (decl
) = 1;
9721 if (RIDBIT_SETP (RID_STATIC
, specbits
))
9722 DECL_THIS_STATIC (decl
) = 1;
9724 /* Record constancy and volatility. */
9727 TREE_READONLY (decl
) = TREE_CODE (type
) != REFERENCE_TYPE
;
9730 TREE_SIDE_EFFECTS (decl
) = 1;
9731 TREE_THIS_VOLATILE (decl
) = 1;
9738 /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
9739 An empty exprlist is a parmlist. An exprlist which
9740 contains only identifiers at the global level
9741 is a parmlist. Otherwise, it is an exprlist. */
9744 parmlist_is_exprlist (exprs
)
9747 if (exprs
== NULL_TREE
|| TREE_PARMLIST (exprs
))
9750 if (toplevel_bindings_p ())
9752 /* At the global level, if these are all identifiers,
9753 then it is a parmlist. */
9756 if (TREE_CODE (TREE_VALUE (exprs
)) != IDENTIFIER_NODE
)
9758 exprs
= TREE_CHAIN (exprs
);
9765 /* Subroutine of `grokparms'. In a fcn definition, arg types must
9768 C++: also subroutine of `start_function'. */
9771 require_complete_types_for_parms (parms
)
9774 if (processing_template_decl
)
9779 tree type
= TREE_TYPE (parms
);
9780 if (TYPE_SIZE (complete_type (type
)) == NULL_TREE
)
9782 if (DECL_NAME (parms
))
9783 error ("parameter `%s' has incomplete type",
9784 IDENTIFIER_POINTER (DECL_NAME (parms
)));
9786 error ("parameter has incomplete type");
9787 TREE_TYPE (parms
) = error_mark_node
;
9790 /* If the arg types are incomplete in a declaration,
9791 they must include undefined tags.
9792 These tags can never be defined in the scope of the declaration,
9793 so the types can never be completed,
9794 and no call can be compiled successfully. */
9795 /* This is not the right behavior for C++, but not having
9796 it is also probably wrong. */
9799 /* Now warn if is a pointer to an incomplete type. */
9800 while (TREE_CODE (type
) == POINTER_TYPE
9801 || TREE_CODE (type
) == REFERENCE_TYPE
)
9802 type
= TREE_TYPE (type
);
9803 type
= TYPE_MAIN_VARIANT (type
);
9804 if (TYPE_SIZE (type
) == NULL_TREE
)
9806 if (DECL_NAME (parm
) != NULL_TREE
)
9807 warning ("parameter `%s' points to incomplete type",
9808 IDENTIFIER_POINTER (DECL_NAME (parm
)));
9810 warning ("parameter points to incomplete type");
9814 parms
= TREE_CHAIN (parms
);
9818 /* Decode the list of parameter types for a function type.
9819 Given the list of things declared inside the parens,
9820 return a list of types.
9822 The list we receive can have three kinds of elements:
9823 an IDENTIFIER_NODE for names given without types,
9824 a TREE_LIST node for arguments given as typespecs or names with typespecs,
9825 or void_type_node, to mark the end of an argument list
9826 when additional arguments are not permitted (... was not used).
9828 FUNCDEF_FLAG is nonzero for a function definition, 0 for
9829 a mere declaration. A nonempty identifier-list gets an error message
9830 when FUNCDEF_FLAG is zero.
9831 If FUNCDEF_FLAG is 1, then parameter types must be complete.
9832 If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
9834 If all elements of the input list contain types,
9835 we return a list of the types.
9836 If all elements contain no type (except perhaps a void_type_node
9837 at the end), we return a null list.
9838 If some have types and some do not, it is an error, and we
9841 Also set last_function_parms to either
9842 a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
9843 A list of names is converted to a chain of PARM_DECLs
9844 by store_parm_decls so that ultimately it is always a chain of decls.
9846 Note that in C++, parameters can take default values. These default
9847 values are in the TREE_PURPOSE field of the TREE_LIST. It is
9848 an error to specify default values which are followed by parameters
9849 that have no default values, or an ELLIPSES. For simplicities sake,
9850 only parameters which are specified with their types can take on
9854 grokparms (first_parm
, funcdef_flag
)
9858 tree result
= NULL_TREE
;
9859 tree decls
= NULL_TREE
;
9861 if (first_parm
!= NULL_TREE
9862 && TREE_CODE (TREE_VALUE (first_parm
)) == IDENTIFIER_NODE
)
9865 pedwarn ("parameter names (without types) in function declaration");
9866 last_function_parms
= first_parm
;
9869 else if (first_parm
!= NULL_TREE
9870 && TREE_CODE (TREE_VALUE (first_parm
)) != TREE_LIST
9871 && TREE_VALUE (first_parm
) != void_type_node
)
9872 my_friendly_abort (145);
9875 /* Types were specified. This is a list of declarators
9876 each represented as a TREE_LIST node. */
9877 register tree parm
, chain
;
9878 int any_init
= 0, any_error
= 0;
9880 if (first_parm
!= NULL_TREE
)
9882 tree last_result
= NULL_TREE
;
9883 tree last_decl
= NULL_TREE
;
9885 for (parm
= first_parm
; parm
!= NULL_TREE
; parm
= chain
)
9887 tree type
, list_node
= parm
;
9888 register tree decl
= TREE_VALUE (parm
);
9889 tree init
= TREE_PURPOSE (parm
);
9891 chain
= TREE_CHAIN (parm
);
9892 /* @@ weak defense against parse errors. */
9893 if (decl
!= void_type_node
&& TREE_CODE (decl
) != TREE_LIST
)
9895 /* Give various messages as the need arises. */
9896 if (TREE_CODE (decl
) == STRING_CST
)
9897 cp_error ("invalid string constant `%E'", decl
);
9898 else if (TREE_CODE (decl
) == INTEGER_CST
)
9899 error ("invalid integer constant in parameter list, did you forget to give parameter name?");
9903 if (decl
!= void_type_node
)
9905 decl
= grokdeclarator (TREE_VALUE (decl
),
9906 TREE_PURPOSE (decl
),
9907 PARM
, init
!= NULL_TREE
,
9911 type
= TREE_TYPE (decl
);
9912 if (TYPE_MAIN_VARIANT (type
) == void_type_node
)
9913 decl
= void_type_node
;
9914 else if (TREE_CODE (type
) == METHOD_TYPE
)
9916 if (DECL_NAME (decl
))
9917 /* Cannot use the decl here because
9918 we don't have DECL_CONTEXT set up yet. */
9919 cp_error ("parameter `%D' invalidly declared method type",
9922 error ("parameter invalidly declared method type");
9923 type
= build_pointer_type (type
);
9924 TREE_TYPE (decl
) = type
;
9926 else if (TREE_CODE (type
) == OFFSET_TYPE
)
9928 if (DECL_NAME (decl
))
9929 cp_error ("parameter `%D' invalidly declared offset type",
9932 error ("parameter invalidly declared offset type");
9933 type
= build_pointer_type (type
);
9934 TREE_TYPE (decl
) = type
;
9936 else if (TREE_CODE (type
) == RECORD_TYPE
9937 && TYPE_LANG_SPECIFIC (type
)
9938 && CLASSTYPE_ABSTRACT_VIRTUALS (type
))
9940 abstract_virtuals_error (decl
, type
);
9941 any_error
= 1; /* seems like a good idea */
9943 else if (TREE_CODE (type
) == RECORD_TYPE
9944 && TYPE_LANG_SPECIFIC (type
)
9945 && IS_SIGNATURE (type
))
9947 signature_error (decl
, type
);
9948 any_error
= 1; /* seems like a good idea */
9952 if (decl
== void_type_node
)
9954 if (result
== NULL_TREE
)
9956 result
= void_list_node
;
9957 last_result
= result
;
9961 TREE_CHAIN (last_result
) = void_list_node
;
9962 last_result
= void_list_node
;
9965 && (chain
!= void_list_node
|| TREE_CHAIN (chain
)))
9966 error ("`void' in parameter list must be entire list");
9970 /* Since there is a prototype, args are passed in their own types. */
9971 DECL_ARG_TYPE (decl
) = TREE_TYPE (decl
);
9972 #ifdef PROMOTE_PROTOTYPES
9973 if ((TREE_CODE (type
) == INTEGER_TYPE
9974 || TREE_CODE (type
) == ENUMERAL_TYPE
)
9975 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
9976 DECL_ARG_TYPE (decl
) = integer_type_node
;
9983 if (TREE_CODE (init
) == SAVE_EXPR
)
9984 PARM_DECL_EXPR (init
) = 1;
9985 else if (processing_template_decl
)
9987 /* Unparsed default arg from in-class decl. */
9988 else if (TREE_CODE (init
) == DEFAULT_ARG
)
9990 else if (TREE_CODE (init
) == VAR_DECL
9991 || TREE_CODE (init
) == PARM_DECL
)
9993 if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init
)))
9995 /* ``Local variables may not be used in default
9996 argument expressions.'' dpANSI C++ 8.2.6 */
9997 /* If extern int i; within a function is not
9998 considered a local variable, then this code is
10000 cp_error ("local variable `%D' may not be used as a default argument", init
);
10003 else if (TREE_READONLY_DECL_P (init
))
10004 init
= decl_constant_value (init
);
10007 init
= require_instantiated_type (type
, init
, integer_zero_node
);
10008 if (! processing_template_decl
10009 && TREE_CODE (init
) != DEFAULT_ARG
10010 && ! can_convert_arg (type
, TREE_TYPE (init
), init
))
10011 cp_pedwarn ("invalid type `%T' for default argument to `%#D'",
10012 TREE_TYPE (init
), decl
);
10018 if (decls
== NULL_TREE
)
10025 TREE_CHAIN (last_decl
) = decl
;
10028 if (TREE_PERMANENT (list_node
))
10030 TREE_PURPOSE (list_node
) = init
;
10031 TREE_VALUE (list_node
) = type
;
10032 TREE_CHAIN (list_node
) = NULL_TREE
;
10035 list_node
= saveable_tree_cons (init
, type
, NULL_TREE
);
10036 if (result
== NULL_TREE
)
10038 result
= list_node
;
10039 last_result
= result
;
10043 TREE_CHAIN (last_result
) = list_node
;
10044 last_result
= list_node
;
10048 TREE_CHAIN (last_result
) = NULL_TREE
;
10049 /* If there are no parameters, and the function does not end
10050 with `...', then last_decl will be NULL_TREE. */
10051 if (last_decl
!= NULL_TREE
)
10052 TREE_CHAIN (last_decl
) = NULL_TREE
;
10056 last_function_parms
= decls
;
10058 /* In a fcn definition, arg types must be complete. */
10059 if (funcdef_flag
> 0)
10060 require_complete_types_for_parms (last_function_parms
);
10065 /* Called from the parser to update an element of TYPE_ARG_TYPES for some
10066 FUNCTION_TYPE with the newly parsed version of its default argument, which
10067 was previously digested as text. See snarf_defarg et al in lex.c. */
10070 replace_defarg (arg
, init
)
10073 if (! processing_template_decl
&& ! uses_template_parms (TREE_VALUE (arg
))
10074 && ! can_convert_arg (TREE_VALUE (arg
), TREE_TYPE (init
), init
))
10075 cp_pedwarn ("invalid type `%T' for default argument to `%T'",
10076 TREE_TYPE (init
), TREE_VALUE (arg
));
10077 TREE_PURPOSE (arg
) = init
;
10084 tree t
= FUNCTION_ARG_CHAIN (d
);
10085 if (t
&& TREE_CODE (TREE_VALUE (t
)) == REFERENCE_TYPE
10086 && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (t
)))
10087 == DECL_CLASS_CONTEXT (d
))
10088 && (TREE_CHAIN (t
) == NULL_TREE
10089 || TREE_CHAIN (t
) == void_list_node
10090 || TREE_PURPOSE (TREE_CHAIN (t
))))
10095 /* These memoizing functions keep track of special properties which
10096 a class may have. `grok_ctor_properties' notices whether a class
10097 has a constructor of the form X(X&), and also complains
10098 if the class has a constructor of the form X(X).
10099 `grok_op_properties' takes notice of the various forms of
10100 operator= which are defined, as well as what sorts of type conversion
10101 may apply. Both functions take a FUNCTION_DECL as an argument. */
10104 grok_ctor_properties (ctype
, decl
)
10107 tree parmtypes
= FUNCTION_ARG_CHAIN (decl
);
10108 tree parmtype
= parmtypes
? TREE_VALUE (parmtypes
) : void_type_node
;
10110 /* When a type has virtual baseclasses, a magical first int argument is
10111 added to any ctor so we can tell if the class has been initialized
10112 yet. This could screw things up in this function, so we deliberately
10113 ignore the leading int if we're in that situation. */
10115 && TREE_VALUE (parmtypes
) == integer_type_node
10116 && TYPE_USES_VIRTUAL_BASECLASSES (ctype
))
10118 parmtypes
= TREE_CHAIN (parmtypes
);
10119 parmtype
= TREE_VALUE (parmtypes
);
10122 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
10123 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype
)) == ctype
)
10125 if (TREE_CHAIN (parmtypes
) == NULL_TREE
10126 || TREE_CHAIN (parmtypes
) == void_list_node
10127 || TREE_PURPOSE (TREE_CHAIN (parmtypes
)))
10129 TYPE_HAS_INIT_REF (ctype
) = 1;
10130 if (TYPE_READONLY (TREE_TYPE (parmtype
)))
10131 TYPE_HAS_CONST_INIT_REF (ctype
) = 1;
10134 TYPE_GETS_INIT_AGGR (ctype
) = 1;
10136 else if (TYPE_MAIN_VARIANT (parmtype
) == ctype
)
10138 if (TREE_CHAIN (parmtypes
) != NULL_TREE
10139 && TREE_CHAIN (parmtypes
) == void_list_node
)
10141 cp_error ("invalid constructor; you probably meant `%T (const %T&)'",
10143 SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl
), ctype
);
10148 TYPE_GETS_INIT_AGGR (ctype
) = 1;
10150 else if (TREE_CODE (parmtype
) == VOID_TYPE
10151 || TREE_PURPOSE (parmtypes
) != NULL_TREE
)
10152 TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype
) = 1;
10157 /* An operator with this name can be either unary or binary. */
10163 return (name
== ansi_opname
[(int) INDIRECT_REF
]
10164 || name
== ansi_opname
[(int) ADDR_EXPR
]
10165 || name
== ansi_opname
[(int) NEGATE_EXPR
]
10166 || name
== ansi_opname
[(int) POSTINCREMENT_EXPR
]
10167 || name
== ansi_opname
[(int) POSTDECREMENT_EXPR
]
10168 || name
== ansi_opname
[(int) CONVERT_EXPR
]);
10171 /* An operator with this name can only be unary. */
10177 return (name
== ansi_opname
[(int) TRUTH_NOT_EXPR
]
10178 || name
== ansi_opname
[(int) BIT_NOT_EXPR
]
10179 || name
== ansi_opname
[(int) COMPONENT_REF
]
10180 || OPERATOR_TYPENAME_P (name
));
10183 /* Do a little sanity-checking on how they declared their operator. */
10186 grok_op_properties (decl
, virtualp
, friendp
)
10188 int virtualp
, friendp
;
10190 tree argtypes
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
10191 int methodp
= (TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
);
10192 tree name
= DECL_NAME (decl
);
10194 if (current_class_type
== NULL_TREE
)
10199 if (name
== ansi_opname
[(int) MODIFY_EXPR
])
10200 TYPE_HAS_ASSIGNMENT (current_class_type
) = 1;
10201 else if (name
== ansi_opname
[(int) CALL_EXPR
])
10202 TYPE_OVERLOADS_CALL_EXPR (current_class_type
) = 1;
10203 else if (name
== ansi_opname
[(int) ARRAY_REF
])
10204 TYPE_OVERLOADS_ARRAY_REF (current_class_type
) = 1;
10205 else if (name
== ansi_opname
[(int) COMPONENT_REF
]
10206 || name
== ansi_opname
[(int) MEMBER_REF
])
10207 TYPE_OVERLOADS_ARROW (current_class_type
) = 1;
10208 else if (name
== ansi_opname
[(int) NEW_EXPR
])
10209 TYPE_GETS_NEW (current_class_type
) |= 1;
10210 else if (name
== ansi_opname
[(int) DELETE_EXPR
])
10211 TYPE_GETS_DELETE (current_class_type
) |= 1;
10212 else if (name
== ansi_opname
[(int) VEC_NEW_EXPR
])
10213 TYPE_GETS_NEW (current_class_type
) |= 2;
10214 else if (name
== ansi_opname
[(int) VEC_DELETE_EXPR
])
10215 TYPE_GETS_DELETE (current_class_type
) |= 2;
10218 if (name
== ansi_opname
[(int) NEW_EXPR
]
10219 || name
== ansi_opname
[(int) VEC_NEW_EXPR
])
10221 /* When the compiler encounters the definition of A::operator new, it
10222 doesn't look at the class declaration to find out if it's static. */
10224 revert_static_member_fn (&decl
, NULL
, NULL
);
10226 /* Take care of function decl if we had syntax errors. */
10227 if (argtypes
== NULL_TREE
)
10229 = build_function_type (ptr_type_node
,
10230 hash_tree_chain (integer_type_node
,
10233 TREE_TYPE (decl
) = coerce_new_type (TREE_TYPE (decl
));
10235 else if (name
== ansi_opname
[(int) DELETE_EXPR
]
10236 || name
== ansi_opname
[(int) VEC_DELETE_EXPR
])
10239 revert_static_member_fn (&decl
, NULL
, NULL
);
10241 if (argtypes
== NULL_TREE
)
10243 = build_function_type (void_type_node
,
10244 hash_tree_chain (ptr_type_node
,
10248 TREE_TYPE (decl
) = coerce_delete_type (TREE_TYPE (decl
));
10250 if (! friendp
&& name
== ansi_opname
[(int) VEC_DELETE_EXPR
]
10251 && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
)))
10252 != void_list_node
))
10253 TYPE_VEC_DELETE_TAKES_SIZE (current_class_type
) = 1;
10258 /* An operator function must either be a non-static member function
10259 or have at least one parameter of a class, a reference to a class,
10260 an enumeration, or a reference to an enumeration. 13.4.0.6 */
10261 if (! methodp
|| DECL_STATIC_FUNCTION_P (decl
))
10263 if (OPERATOR_TYPENAME_P (name
)
10264 || name
== ansi_opname
[(int) CALL_EXPR
]
10265 || name
== ansi_opname
[(int) MODIFY_EXPR
]
10266 || name
== ansi_opname
[(int) COMPONENT_REF
]
10267 || name
== ansi_opname
[(int) ARRAY_REF
])
10268 cp_error ("`%D' must be a nonstatic member function", decl
);
10273 if (DECL_STATIC_FUNCTION_P (decl
))
10274 cp_error ("`%D' must be either a non-static member function or a non-member function", decl
);
10277 for (; TREE_VALUE (p
) != void_type_node
; p
= TREE_CHAIN (p
))
10279 tree arg
= TREE_VALUE (p
);
10280 if (TREE_CODE (arg
) == REFERENCE_TYPE
)
10281 arg
= TREE_TYPE (arg
);
10283 /* This lets bad template code slip through. */
10284 if (IS_AGGR_TYPE (arg
)
10285 || TREE_CODE (arg
) == ENUMERAL_TYPE
10286 || TREE_CODE (arg
) == TEMPLATE_TYPE_PARM
)
10290 ("`%D' must have an argument of class or enumerated type",
10297 if (name
== ansi_opname
[(int) CALL_EXPR
]
10298 || name
== ansi_opname
[(int) METHOD_CALL_EXPR
])
10299 return; /* no restrictions on args */
10301 if (IDENTIFIER_TYPENAME_P (name
) && ! DECL_TEMPLATE_INFO (decl
))
10303 tree t
= TREE_TYPE (name
);
10304 if (TREE_CODE (t
) == VOID_TYPE
)
10305 pedwarn ("void is not a valid type conversion operator");
10306 else if (! friendp
)
10308 int ref
= (TREE_CODE (t
) == REFERENCE_TYPE
);
10311 t
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
10313 if (t
== current_class_type
)
10314 what
= "the same type";
10315 /* Don't force t to be complete here. */
10316 else if (IS_AGGR_TYPE (t
)
10318 && DERIVED_FROM_P (t
, current_class_type
))
10319 what
= "a base class";
10322 warning ("conversion to %s%s will never use a type conversion operator",
10323 ref
? "a reference to " : "", what
);
10327 if (name
== ansi_opname
[(int) MODIFY_EXPR
])
10331 if (list_length (argtypes
) != 3 && methodp
)
10333 cp_error ("`%D' must take exactly one argument", decl
);
10336 parmtype
= TREE_VALUE (TREE_CHAIN (argtypes
));
10338 if (copy_assignment_arg_p (parmtype
, virtualp
)
10341 TYPE_HAS_ASSIGN_REF (current_class_type
) = 1;
10342 if (TREE_CODE (parmtype
) != REFERENCE_TYPE
10343 || TYPE_READONLY (TREE_TYPE (parmtype
)))
10344 TYPE_HAS_CONST_ASSIGN_REF (current_class_type
) = 1;
10347 else if (name
== ansi_opname
[(int) COND_EXPR
])
10350 pedwarn ("ANSI C++ prohibits overloading operator ?:");
10351 if (list_length (argtypes
) != 4)
10352 cp_error ("`%D' must take exactly three arguments", decl
);
10354 else if (ambi_op_p (name
))
10356 if (list_length (argtypes
) == 2)
10358 else if (list_length (argtypes
) == 3)
10360 if ((name
== ansi_opname
[(int) POSTINCREMENT_EXPR
]
10361 || name
== ansi_opname
[(int) POSTDECREMENT_EXPR
])
10362 && ! processing_template_decl
10363 && TREE_VALUE (TREE_CHAIN (argtypes
)) != integer_type_node
)
10366 cp_error ("postfix `%D' must take `int' as its argument",
10370 ("postfix `%D' must take `int' as its second argument",
10377 cp_error ("`%D' must take either zero or one argument", decl
);
10379 cp_error ("`%D' must take either one or two arguments", decl
);
10382 /* More Effective C++ rule 6. */
10384 && (name
== ansi_opname
[(int) POSTINCREMENT_EXPR
]
10385 || name
== ansi_opname
[(int) POSTDECREMENT_EXPR
]))
10387 tree arg
= TREE_VALUE (argtypes
);
10388 tree ret
= TREE_TYPE (TREE_TYPE (decl
));
10389 if (methodp
|| TREE_CODE (arg
) == REFERENCE_TYPE
)
10390 arg
= TREE_TYPE (arg
);
10391 arg
= TYPE_MAIN_VARIANT (arg
);
10392 if (list_length (argtypes
) == 2)
10394 if (TREE_CODE (ret
) != REFERENCE_TYPE
10395 || !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ret
)),
10397 cp_warning ("prefix `%D' should return `%T'", decl
,
10398 build_reference_type (arg
));
10402 if (!comptypes (TYPE_MAIN_VARIANT (ret
), arg
, 1))
10403 cp_warning ("postfix `%D' should return `%T'", decl
, arg
);
10407 else if (unary_op_p (name
))
10409 if (list_length (argtypes
) != 2)
10412 cp_error ("`%D' must take `void'", decl
);
10414 cp_error ("`%D' must take exactly one argument", decl
);
10417 else /* if (binary_op_p (name)) */
10419 if (list_length (argtypes
) != 3)
10422 cp_error ("`%D' must take exactly one argument", decl
);
10424 cp_error ("`%D' must take exactly two arguments", decl
);
10427 /* More Effective C++ rule 7. */
10429 && (name
== ansi_opname
[TRUTH_ANDIF_EXPR
]
10430 || name
== ansi_opname
[TRUTH_ORIF_EXPR
]
10431 || name
== ansi_opname
[COMPOUND_EXPR
]))
10432 cp_warning ("user-defined `%D' always evaluates both arguments",
10436 /* Effective C++ rule 23. */
10438 && list_length (argtypes
) == 3
10439 && (name
== ansi_opname
[PLUS_EXPR
]
10440 || name
== ansi_opname
[MINUS_EXPR
]
10441 || name
== ansi_opname
[TRUNC_DIV_EXPR
]
10442 || name
== ansi_opname
[MULT_EXPR
])
10443 && TREE_CODE (TREE_TYPE (TREE_TYPE (decl
))) == REFERENCE_TYPE
)
10444 cp_warning ("`%D' should return by value", decl
);
10448 for (; argtypes
!= void_list_node
; argtypes
= TREE_CHAIN (argtypes
))
10449 if (TREE_PURPOSE (argtypes
))
10451 TREE_PURPOSE (argtypes
) = NULL_TREE
;
10452 if (name
== ansi_opname
[(int) POSTINCREMENT_EXPR
]
10453 || name
== ansi_opname
[(int) POSTDECREMENT_EXPR
])
10456 cp_pedwarn ("`%D' cannot have default arguments", decl
);
10459 cp_error ("`%D' cannot have default arguments", decl
);
10464 /* Get the struct, enum or union (CODE says which) with tag NAME.
10465 Define the tag as a forward-reference if it is not defined.
10467 C++: If a class derivation is given, process it here, and report
10468 an error if multiple derivation declarations are not identical.
10470 If this is a definition, come in through xref_tag and only look in
10471 the current frame for the name (since C++ allows new names in any
10475 xref_tag (code_type_node
, name
, binfo
, globalize
)
10476 tree code_type_node
;
10480 enum tag_types tag_code
;
10481 enum tree_code code
;
10483 register tree ref
, t
;
10484 struct binding_level
*b
= inner_binding_level
;
10487 tag_code
= (enum tag_types
) TREE_INT_CST_LOW (code_type_node
);
10492 case signature_type
:
10493 code
= RECORD_TYPE
;
10499 code
= ENUMERAL_TYPE
;
10502 my_friendly_abort (18);
10505 /* If a cross reference is requested, look up the type
10506 already defined for this tag and return it. */
10507 if (TREE_CODE_CLASS (TREE_CODE (name
)) == 't')
10510 name
= TYPE_IDENTIFIER (t
);
10514 t
= IDENTIFIER_TYPE_VALUE (name
);
10515 if (t
&& TREE_CODE (t
) != code
&& TREE_CODE (t
) != TEMPLATE_TYPE_PARM
)
10520 if (pedantic
&& t
&& TREE_CODE (t
) == TEMPLATE_TYPE_PARM
)
10522 cp_pedwarn ("redeclaration of template type-parameter `%T'", name
);
10523 cp_pedwarn_at (" previously declared here", t
);
10525 if (t
&& TYPE_CONTEXT (t
) && got_type
)
10529 /* If we know we are defining this tag, only look it up in
10530 this scope and don't try to find it as a type. */
10531 ref
= lookup_tag (code
, name
, b
, 1);
10539 ref
= lookup_tag (code
, name
, b
, 0);
10543 /* Try finding it as a type declaration. If that wins, use it. */
10544 ref
= lookup_name (name
, 1);
10545 if (ref
&& TREE_CODE (ref
) == TYPE_DECL
10546 && TREE_CODE (TREE_TYPE (ref
)) == code
)
10547 ref
= TREE_TYPE (ref
);
10553 push_obstacks_nochange ();
10557 /* If no such tag is yet defined, create a forward-reference node
10558 and record it as the "definition".
10559 When a real declaration of this type is found,
10560 the forward-reference will be altered into a real type. */
10562 /* In C++, since these migrate into the global scope, we must
10563 build them on the permanent obstack. */
10565 temp
= allocation_temporary_p ();
10567 end_temporary_allocation ();
10569 if (code
== ENUMERAL_TYPE
)
10571 cp_error ("use of enum `%#D' without previous declaration", name
);
10573 ref
= make_node (ENUMERAL_TYPE
);
10575 /* Give the type a default layout like unsigned int
10576 to avoid crashing if it does not get defined. */
10577 TYPE_MODE (ref
) = TYPE_MODE (unsigned_type_node
);
10578 TYPE_ALIGN (ref
) = TYPE_ALIGN (unsigned_type_node
);
10579 TREE_UNSIGNED (ref
) = 1;
10580 TYPE_PRECISION (ref
) = TYPE_PRECISION (unsigned_type_node
);
10581 TYPE_MIN_VALUE (ref
) = TYPE_MIN_VALUE (unsigned_type_node
);
10582 TYPE_MAX_VALUE (ref
) = TYPE_MAX_VALUE (unsigned_type_node
);
10584 /* Enable us to recognize when a type is created in class context.
10585 To do nested classes correctly, this should probably be cleared
10586 out when we leave this classes scope. Currently this in only
10587 done in `start_enum'. */
10589 pushtag (name
, ref
, globalize
);
10593 struct binding_level
*old_b
= class_binding_level
;
10595 ref
= make_lang_type (code
);
10597 if (tag_code
== signature_type
)
10599 SET_SIGNATURE (ref
);
10600 /* Since a signature type will be turned into the type
10601 of signature tables, it's not only an interface. */
10602 CLASSTYPE_INTERFACE_ONLY (ref
) = 0;
10603 SET_CLASSTYPE_INTERFACE_KNOWN (ref
);
10604 /* A signature doesn't have a vtable. */
10605 CLASSTYPE_VTABLE_NEEDS_WRITING (ref
) = 0;
10608 #ifdef NONNESTED_CLASSES
10609 /* Class types don't nest the way enums do. */
10610 class_binding_level
= (struct binding_level
*)0;
10612 pushtag (name
, ref
, globalize
);
10613 class_binding_level
= old_b
;
10618 /* If it no longer looks like a nested type, make sure it's
10619 in global scope. */
10620 if (b
== global_binding_level
&& !class_binding_level
10621 && IDENTIFIER_GLOBAL_VALUE (name
) == NULL_TREE
)
10622 IDENTIFIER_GLOBAL_VALUE (name
) = TYPE_NAME (ref
);
10626 xref_basetypes (code_type_node
, name
, ref
, binfo
);
10630 /* Until the type is defined, tentatively accept whatever
10631 structure tag the user hands us. */
10632 if (TYPE_SIZE (ref
) == NULL_TREE
10633 && ref
!= current_class_type
10634 /* Have to check this, in case we have contradictory tag info. */
10635 && IS_AGGR_TYPE_CODE (TREE_CODE (ref
)))
10637 if (tag_code
== class_type
)
10638 CLASSTYPE_DECLARED_CLASS (ref
) = 1;
10639 else if (tag_code
== record_type
|| tag_code
== signature_type
)
10640 CLASSTYPE_DECLARED_CLASS (ref
) = 0;
10649 xref_tag_from_type (old
, id
, globalize
)
10653 tree code_type_node
;
10655 if (TREE_CODE (old
) == RECORD_TYPE
)
10656 code_type_node
= (CLASSTYPE_DECLARED_CLASS (old
)
10657 ? class_type_node
: record_type_node
);
10659 code_type_node
= union_type_node
;
10661 if (id
== NULL_TREE
)
10662 id
= TYPE_IDENTIFIER (old
);
10664 return xref_tag (code_type_node
, id
, NULL_TREE
, globalize
);
10668 xref_basetypes (code_type_node
, name
, ref
, binfo
)
10669 tree code_type_node
;
10673 /* In the declaration `A : X, Y, ... Z' we mark all the types
10674 (A, X, Y, ..., Z) so we can check for duplicates. */
10677 enum tag_types tag_code
= (enum tag_types
) TREE_INT_CST_LOW (code_type_node
);
10679 if (tag_code
== union_type
)
10681 cp_error ("derived union `%T' invalid", ref
);
10685 len
= list_length (binfo
);
10686 push_obstacks (TYPE_OBSTACK (ref
), TYPE_OBSTACK (ref
));
10688 SET_CLASSTYPE_MARKED (ref
);
10689 BINFO_BASETYPES (TYPE_BINFO (ref
)) = binfos
= make_tree_vec (len
);
10691 for (i
= 0; binfo
; binfo
= TREE_CHAIN (binfo
))
10693 /* The base of a derived struct is public by default. */
10695 = (TREE_PURPOSE (binfo
) == access_public_node
10696 || TREE_PURPOSE (binfo
) == access_public_virtual_node
10697 || (tag_code
!= class_type
10698 && (TREE_PURPOSE (binfo
) == access_default_node
10699 || TREE_PURPOSE (binfo
) == access_default_virtual_node
)));
10700 int via_protected
= TREE_PURPOSE (binfo
) == access_protected_node
;
10702 = (TREE_PURPOSE (binfo
) == access_private_virtual_node
10703 || TREE_PURPOSE (binfo
) == access_public_virtual_node
10704 || TREE_PURPOSE (binfo
) == access_default_virtual_node
);
10705 tree basetype
= TREE_VALUE (binfo
);
10708 GNU_xref_hier (IDENTIFIER_POINTER (name
),
10709 IDENTIFIER_POINTER (TREE_VALUE (binfo
)),
10710 via_public
, via_virtual
, 0);
10712 if (basetype
&& TREE_CODE (basetype
) == TYPE_DECL
)
10713 basetype
= TREE_TYPE (basetype
);
10715 || (TREE_CODE (basetype
) != RECORD_TYPE
10716 && TREE_CODE (basetype
) != TYPENAME_TYPE
10717 && TREE_CODE (basetype
) != TEMPLATE_TYPE_PARM
))
10719 cp_error ("base type `%T' fails to be a struct or class type",
10720 TREE_VALUE (binfo
));
10724 /* This code replaces similar code in layout_basetypes. */
10725 else if (TYPE_SIZE (complete_type (basetype
)) == NULL_TREE
10726 && ! (current_template_parms
&& uses_template_parms (basetype
)))
10728 cp_error ("base class `%T' has incomplete type", basetype
);
10734 if (CLASSTYPE_MARKED (basetype
))
10736 if (basetype
== ref
)
10737 cp_error ("recursive type `%T' undefined", basetype
);
10739 cp_error ("duplicate base type `%T' invalid", basetype
);
10743 /* Note that the BINFO records which describe individual
10744 inheritances are *not* shared in the lattice! They
10745 cannot be shared because a given baseclass may be
10746 inherited with different `accessibility' by different
10747 derived classes. (Each BINFO record describing an
10748 individual inheritance contains flags which say what
10749 the `accessibility' of that particular inheritance is.) */
10751 base_binfo
= make_binfo (integer_zero_node
, basetype
,
10752 TYPE_BINFO_VTABLE (basetype
),
10753 TYPE_BINFO_VIRTUALS (basetype
), NULL_TREE
);
10755 TREE_VEC_ELT (binfos
, i
) = base_binfo
;
10756 TREE_VIA_PUBLIC (base_binfo
) = via_public
;
10757 TREE_VIA_PROTECTED (base_binfo
) = via_protected
;
10758 TREE_VIA_VIRTUAL (base_binfo
) = via_virtual
;
10759 BINFO_INHERITANCE_CHAIN (base_binfo
) = TYPE_BINFO (ref
);
10761 SET_CLASSTYPE_MARKED (basetype
);
10763 /* We are free to modify these bits because they are meaningless
10764 at top level, and BASETYPE is a top-level type. */
10765 if (via_virtual
|| TYPE_USES_VIRTUAL_BASECLASSES (basetype
))
10767 TYPE_USES_VIRTUAL_BASECLASSES (ref
) = 1;
10768 TYPE_USES_COMPLEX_INHERITANCE (ref
) = 1;
10771 TYPE_OVERLOADS_METHOD_CALL_EXPR (ref
) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype
);
10772 TYPE_GETS_NEW (ref
) |= TYPE_GETS_NEW (basetype
);
10773 TYPE_GETS_DELETE (ref
) |= TYPE_GETS_DELETE (basetype
);
10774 CLASSTYPE_LOCAL_TYPEDECLS (ref
) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype
);
10779 TREE_VEC_LENGTH (binfos
) = i
;
10781 BINFO_BASETYPES (TYPE_BINFO (ref
)) = NULL_TREE
;
10784 TYPE_USES_MULTIPLE_INHERITANCE (ref
) = 1;
10786 TYPE_USES_MULTIPLE_INHERITANCE (ref
)
10787 = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos
, 0)));
10788 if (TYPE_USES_MULTIPLE_INHERITANCE (ref
))
10789 TYPE_USES_COMPLEX_INHERITANCE (ref
) = 1;
10791 /* Unmark all the types. */
10793 CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos
, i
)));
10794 CLEAR_CLASSTYPE_MARKED (ref
);
10800 static tree current_local_enum
= NULL_TREE
;
10802 /* Begin compiling the definition of an enumeration type.
10803 NAME is its name (or null if anonymous).
10804 Returns the type object, as yet incomplete.
10805 Also records info about it so that build_enumerator
10806 may be used to declare the individual values as they are read. */
10812 register tree enumtype
= NULL_TREE
;
10813 struct binding_level
*b
= inner_binding_level
;
10815 if (processing_template_decl
&& current_function_decl
)
10816 end_temporary_allocation ();
10818 /* If this is the real definition for a previous forward reference,
10819 fill in the contents in the same object that used to be the
10820 forward reference. */
10822 if (name
!= NULL_TREE
)
10823 enumtype
= lookup_tag (ENUMERAL_TYPE
, name
, b
, 1);
10825 if (enumtype
!= NULL_TREE
&& TREE_CODE (enumtype
) == ENUMERAL_TYPE
)
10826 cp_error ("multiple definition of `%#T'", enumtype
);
10829 enumtype
= make_node (ENUMERAL_TYPE
);
10830 pushtag (name
, enumtype
, 0);
10833 if (b
->pseudo_global
)
10834 cp_error ("template declaration of `%#T'", enumtype
);
10836 if (current_class_type
)
10837 TREE_ADDRESSABLE (b
->tags
) = 1;
10839 current_local_enum
= NULL_TREE
;
10841 /* We don't copy this value because build_enumerator needs to do it. */
10842 enum_next_value
= integer_zero_node
;
10845 GNU_xref_decl (current_function_decl
, enumtype
);
10849 /* After processing and defining all the values of an enumeration type,
10850 install their decls in the enumeration type and finish it off.
10851 ENUMTYPE is the type object and VALUES a list of name-value pairs.
10852 Returns ENUMTYPE. */
10855 finish_enum (enumtype
, values
)
10856 register tree enumtype
, values
;
10858 register tree minnode
, maxnode
;
10859 /* Calculate the maximum value of any enumerator in this type. */
10863 register tree pair
;
10864 register tree value
= DECL_INITIAL (TREE_VALUE (values
));
10866 if (! processing_template_decl
)
10868 /* Speed up the main loop by performing some precalculations */
10869 TREE_TYPE (TREE_VALUE (values
)) = enumtype
;
10870 TREE_TYPE (value
) = enumtype
;
10871 minnode
= maxnode
= value
;
10873 TREE_VALUE (values
) = value
;
10875 for (pair
= TREE_CHAIN (values
); pair
; pair
= TREE_CHAIN (pair
))
10877 value
= DECL_INITIAL (TREE_VALUE (pair
));
10878 if (! processing_template_decl
)
10880 TREE_TYPE (TREE_VALUE (pair
)) = enumtype
;
10881 TREE_TYPE (value
) = enumtype
;
10882 if (tree_int_cst_lt (maxnode
, value
))
10884 else if (tree_int_cst_lt (value
, minnode
))
10887 TREE_VALUE (pair
) = value
;
10891 maxnode
= minnode
= integer_zero_node
;
10893 TYPE_VALUES (enumtype
) = nreverse (values
);
10895 if (processing_template_decl
)
10897 if (current_function_decl
)
10899 add_tree (build_min (TAG_DEFN
, enumtype
));
10900 resume_temporary_allocation ();
10906 int unsignedp
= tree_int_cst_sgn (minnode
) >= 0;
10907 int lowprec
= min_precision (minnode
, unsignedp
);
10908 int highprec
= min_precision (maxnode
, unsignedp
);
10909 int precision
= MAX (lowprec
, highprec
);
10911 TYPE_SIZE (enumtype
) = NULL_TREE
;
10913 /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */
10915 TYPE_PRECISION (enumtype
) = precision
;
10917 fixup_unsigned_type (enumtype
);
10919 fixup_signed_type (enumtype
);
10921 if (flag_short_enums
|| (precision
> TYPE_PRECISION (integer_type_node
)))
10922 /* Use the width of the narrowest normal C type which is wide enough. */
10923 TYPE_PRECISION (enumtype
) = TYPE_PRECISION (type_for_size
10926 TYPE_PRECISION (enumtype
) = TYPE_PRECISION (integer_type_node
);
10928 TYPE_SIZE (enumtype
) = 0;
10929 layout_type (enumtype
);
10935 /* Fix up all variant types of this enum type. */
10936 for (tem
= TYPE_MAIN_VARIANT (enumtype
); tem
;
10937 tem
= TYPE_NEXT_VARIANT (tem
))
10939 TYPE_VALUES (tem
) = TYPE_VALUES (enumtype
);
10940 TYPE_MIN_VALUE (tem
) = TYPE_MIN_VALUE (enumtype
);
10941 TYPE_MAX_VALUE (tem
) = TYPE_MAX_VALUE (enumtype
);
10942 TYPE_SIZE (tem
) = TYPE_SIZE (enumtype
);
10943 TYPE_MODE (tem
) = TYPE_MODE (enumtype
);
10944 TYPE_PRECISION (tem
) = TYPE_PRECISION (enumtype
);
10945 TYPE_ALIGN (tem
) = TYPE_ALIGN (enumtype
);
10946 TREE_UNSIGNED (tem
) = TREE_UNSIGNED (enumtype
);
10950 /* Finish debugging output for this type. */
10951 rest_of_type_compilation (enumtype
, global_bindings_p ());
10956 /* Build and install a CONST_DECL for one value of the
10957 current enumeration type (one that was begun with start_enum).
10958 Return a tree-list containing the name and its value.
10959 Assignment of sequential values by default is handled here. */
10962 build_enumerator (name
, value
)
10967 /* Remove no-op casts from the value. */
10969 STRIP_TYPE_NOPS (value
);
10971 if (! processing_template_decl
)
10973 /* Validate and default VALUE. */
10974 if (value
!= NULL_TREE
)
10976 if (TREE_READONLY_DECL_P (value
))
10977 value
= decl_constant_value (value
);
10979 if (TREE_CODE (value
) == INTEGER_CST
)
10981 value
= default_conversion (value
);
10982 constant_expression_warning (value
);
10986 cp_error ("enumerator value for `%D' not integer constant", name
);
10991 /* Default based on previous value. */
10992 if (value
== NULL_TREE
&& ! processing_template_decl
)
10994 value
= enum_next_value
;
10996 cp_error ("overflow in enumeration values at `%D'", name
);
10999 /* Remove no-op casts from the value. */
11001 STRIP_TYPE_NOPS (value
);
11003 /* We have to always copy here; not all INTEGER_CSTs are unshared,
11004 and there's no wedding ring. Look at size_int()...*/
11005 value
= copy_node (value
);
11007 /* To fix MAX_VAL enum consts. (bkoz) */
11008 TREE_TYPE (value
) = integer_type_node
;
11012 /* C++ associates enums with global, function, or class declarations. */
11014 decl
= current_scope ();
11015 if (decl
&& decl
== current_class_type
)
11017 /* This enum declaration is local to the class, so we must put
11018 it in that class's list of decls. */
11019 decl
= build_lang_field_decl (CONST_DECL
, name
, integer_type_node
);
11020 DECL_INITIAL (decl
) = value
;
11021 TREE_READONLY (decl
) = 1;
11022 pushdecl_class_level (decl
);
11023 TREE_CHAIN (decl
) = current_local_enum
;
11024 current_local_enum
= decl
;
11028 /* It's a global enum, or it's local to a function. (Note local to
11029 a function could mean local to a class method. */
11030 decl
= build_decl (CONST_DECL
, name
, integer_type_node
);
11031 DECL_INITIAL (decl
) = value
;
11032 TREE_READONLY (decl
) = 1;
11035 GNU_xref_decl (current_function_decl
, decl
);
11038 if (! processing_template_decl
)
11040 /* Set basis for default for next value. */
11041 enum_next_value
= build_binary_op_nodefault (PLUS_EXPR
, value
,
11042 integer_one_node
, PLUS_EXPR
);
11043 enum_overflow
= tree_int_cst_lt (enum_next_value
, value
);
11046 result
= saveable_tree_cons (name
, decl
, NULL_TREE
);
11051 grok_enum_decls (type
, decl
)
11054 tree d
= current_local_enum
;
11056 if (d
== NULL_TREE
)
11061 TREE_TYPE (d
) = type
;
11062 if (TREE_CHAIN (d
) == NULL_TREE
)
11064 TREE_CHAIN (d
) = decl
;
11067 d
= TREE_CHAIN (d
);
11070 decl
= current_local_enum
;
11071 current_local_enum
= NULL_TREE
;
11076 static int function_depth
;
11078 /* Create the FUNCTION_DECL for a function definition.
11079 DECLSPECS and DECLARATOR are the parts of the declaration;
11080 they describe the function's name and the type it returns,
11081 but twisted together in a fashion that parallels the syntax of C.
11083 This function creates a binding context for the function body
11084 as well as setting up the FUNCTION_DECL in current_function_decl.
11086 Returns 1 on success. If the DECLARATOR is not suitable for a function
11087 (it defines a datum instead), we return 0, which tells
11088 yyparse to report a parse error.
11090 For C++, we must first check whether that datum makes any sense.
11091 For example, "class A local_a(1,2);" means that variable local_a
11092 is an aggregate of type A, which should have a constructor
11093 applied to it with the argument list [1, 2].
11095 @@ There is currently no way to retrieve the storage
11096 @@ allocated to FUNCTION (or all of its parms) if we return
11097 @@ something we had previously. */
11100 start_function (declspecs
, declarator
, attrs
, pre_parsed_p
)
11101 tree declspecs
, declarator
, attrs
;
11105 tree ctype
= NULL_TREE
;
11108 extern int have_extern_spec
;
11109 extern int used_extern_spec
;
11110 int doing_friend
= 0;
11112 /* Sanity check. */
11113 my_friendly_assert (TREE_VALUE (void_list_node
) == void_type_node
, 160);
11114 my_friendly_assert (TREE_CHAIN (void_list_node
) == NULL_TREE
, 161);
11116 /* Assume, until we see it does. */
11117 current_function_returns_value
= 0;
11118 current_function_returns_null
= 0;
11119 warn_about_return_type
= 0;
11121 shadowed_labels
= 0;
11122 current_function_assigns_this
= 0;
11123 current_function_just_assigned_this
= 0;
11124 current_function_parms_stored
= 0;
11125 original_result_rtx
= NULL_RTX
;
11126 base_init_expr
= NULL_TREE
;
11127 current_base_init_list
= NULL_TREE
;
11128 current_member_init_list
= NULL_TREE
;
11129 ctor_label
= dtor_label
= NULL_TREE
;
11130 static_labelno
= 0;
11132 clear_temp_name ();
11134 /* This should only be done once on the top most decl. */
11135 if (have_extern_spec
&& !used_extern_spec
)
11137 declspecs
= decl_tree_cons (NULL_TREE
, get_identifier ("extern"), declspecs
);
11138 used_extern_spec
= 1;
11143 decl1
= declarator
;
11145 if (! DECL_ARGUMENTS (decl1
)
11146 && !DECL_STATIC_FUNCTION_P (decl1
)
11147 && DECL_CONTEXT (decl1
)
11148 && TYPE_IDENTIFIER (DECL_CONTEXT (decl1
))
11149 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (DECL_CONTEXT (decl1
))))
11151 cp_error ("redeclaration of `%#D'", decl1
);
11152 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1
)))
11153 cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1
)));
11154 else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1
)))
11155 cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1
)));
11158 fntype
= TREE_TYPE (decl1
);
11159 if (TREE_CODE (fntype
) == METHOD_TYPE
)
11160 ctype
= TYPE_METHOD_BASETYPE (fntype
);
11162 /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a
11163 class is in the (lexical) scope of the class in which it is
11165 if (!ctype
&& DECL_FRIEND_P (decl1
))
11167 ctype
= DECL_CLASS_CONTEXT (decl1
);
11169 /* CTYPE could be null here if we're dealing with a template;
11170 for example, `inline friend float foo()' inside a template
11171 will have no CTYPE set. */
11172 if (ctype
&& TREE_CODE (ctype
) != RECORD_TYPE
)
11178 /* In a fcn definition, arg types must be complete. */
11179 require_complete_types_for_parms (DECL_ARGUMENTS (decl1
));
11181 /* In case some arg types were completed since the declaration was
11182 parsed, fix up the decls. */
11184 tree t
= DECL_ARGUMENTS (decl1
);
11185 for (; t
; t
= TREE_CHAIN (t
))
11186 layout_decl (t
, 0);
11189 last_function_parms
= DECL_ARGUMENTS (decl1
);
11190 last_function_parm_tags
= NULL_TREE
;
11194 decl1
= grokdeclarator (declarator
, declspecs
, FUNCDEF
, 1, NULL_TREE
);
11195 /* If the declarator is not suitable for a function definition,
11196 cause a syntax error. */
11197 if (decl1
== NULL_TREE
|| TREE_CODE (decl1
) != FUNCTION_DECL
) return 0;
11199 fntype
= TREE_TYPE (decl1
);
11201 restype
= TREE_TYPE (fntype
);
11202 if (IS_AGGR_TYPE (restype
) && ! TYPE_PTRMEMFUNC_P (restype
)
11203 && ! CLASSTYPE_GOT_SEMICOLON (restype
))
11205 cp_error ("semicolon missing after declaration of `%#T'", restype
);
11206 shadow_tag (build_tree_list (NULL_TREE
, restype
));
11207 CLASSTYPE_GOT_SEMICOLON (restype
) = 1;
11208 if (TREE_CODE (fntype
) == FUNCTION_TYPE
)
11209 fntype
= build_function_type (integer_type_node
,
11210 TYPE_ARG_TYPES (fntype
));
11212 fntype
= build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype
), TREE_READONLY (decl1
), TREE_SIDE_EFFECTS (decl1
)),
11214 TYPE_ARG_TYPES (fntype
));
11215 TREE_TYPE (decl1
) = fntype
;
11218 if (TREE_CODE (fntype
) == METHOD_TYPE
)
11219 ctype
= TYPE_METHOD_BASETYPE (fntype
);
11220 else if (IDENTIFIER_LENGTH (DECL_NAME (decl1
)) == 4
11221 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1
)), "main")
11222 && DECL_CONTEXT (decl1
) == NULL_TREE
)
11224 /* If this doesn't return integer_type, complain. */
11225 if (TREE_TYPE (TREE_TYPE (decl1
)) != integer_type_node
)
11227 if (pedantic
|| warn_return_type
)
11228 pedwarn ("return type for `main' changed to `int'");
11229 TREE_TYPE (decl1
) = fntype
= default_function_type
;
11231 warn_about_return_type
= 0;
11235 /* Warn if function was previously implicitly declared
11236 (but not if we warned then). */
11237 if (! warn_implicit
11238 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1
)) != NULL_TREE
)
11239 cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1
)));
11241 current_function_decl
= decl1
;
11242 /* Save the parm names or decls from this function's declarator
11243 where store_parm_decls will find them. */
11244 current_function_parms
= last_function_parms
;
11245 current_function_parm_tags
= last_function_parm_tags
;
11247 announce_function (decl1
);
11249 if (! processing_template_decl
)
11251 if (TYPE_SIZE (complete_type (TREE_TYPE (fntype
))) == NULL_TREE
)
11253 cp_error ("return-type `%#T' is an incomplete type",
11254 TREE_TYPE (fntype
));
11256 /* Make it return void instead, but don't change the
11257 type of the DECL_RESULT, in case we have a named return value. */
11260 = build_cplus_method_type (build_type_variant (ctype
,
11261 TREE_READONLY (decl1
),
11262 TREE_SIDE_EFFECTS (decl1
)),
11264 FUNCTION_ARG_CHAIN (decl1
));
11267 = build_function_type (void_type_node
,
11268 TYPE_ARG_TYPES (TREE_TYPE (decl1
)));
11269 DECL_RESULT (decl1
)
11270 = build_decl (RESULT_DECL
, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype
)));
11271 TREE_READONLY (DECL_RESULT (decl1
)) = TYPE_READONLY (TREE_TYPE (fntype
));
11272 TREE_THIS_VOLATILE (DECL_RESULT (decl1
)) = TYPE_VOLATILE (TREE_TYPE (fntype
));
11275 if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype
))
11276 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype
)))
11277 abstract_virtuals_error (decl1
, TREE_TYPE (fntype
));
11280 if (warn_about_return_type
)
11281 warning ("return-type defaults to `int'");
11283 /* Effective C++ rule 15. See also c_expand_return. */
11285 && DECL_NAME (decl1
) == ansi_opname
[(int) MODIFY_EXPR
]
11286 && TREE_TYPE (fntype
) == void_type_node
)
11287 cp_warning ("`operator=' should return a reference to `*this'");
11289 /* Make the init_value nonzero so pushdecl knows this is not tentative.
11290 error_mark_node is replaced below (in poplevel) with the BLOCK. */
11291 DECL_INITIAL (decl1
) = error_mark_node
;
11293 /* This function exists in static storage.
11294 (This does not mean `static' in the C sense!) */
11295 TREE_STATIC (decl1
) = 1;
11297 /* Record the decl so that the function name is defined.
11298 If we already have a decl for this name, and it is a FUNCTION_DECL,
11299 use the old decl. */
11301 if (processing_template_decl
)
11302 push_template_decl (decl1
);
11303 else if (pre_parsed_p
== 0)
11305 decl1
= pushdecl (decl1
);
11306 DECL_MAIN_VARIANT (decl1
) = decl1
;
11307 fntype
= TREE_TYPE (decl1
);
11310 current_function_decl
= decl1
;
11312 if (DECL_INTERFACE_KNOWN (decl1
))
11314 if (DECL_NOT_REALLY_EXTERN (decl1
))
11315 DECL_EXTERNAL (decl1
) = 0;
11317 /* If this function belongs to an interface, it is public.
11318 If it belongs to someone else's interface, it is also external.
11319 It doesn't matter whether it's inline or not. */
11320 else if (interface_unknown
== 0
11321 && (! DECL_TEMPLATE_INSTANTIATION (decl1
)
11322 || flag_alt_external_templates
))
11324 if (DECL_THIS_INLINE (decl1
) || DECL_TEMPLATE_INSTANTIATION (decl1
)
11325 || processing_template_decl
)
11326 DECL_EXTERNAL (decl1
)
11328 || (DECL_THIS_INLINE (decl1
) && ! flag_implement_inlines
));
11331 DECL_EXTERNAL (decl1
) = 0;
11332 if (DECL_C_STATIC (decl1
))
11333 TREE_PUBLIC (decl1
) = 0;
11335 DECL_NOT_REALLY_EXTERN (decl1
) = 0;
11336 DECL_INTERFACE_KNOWN (decl1
) = 1;
11340 /* This is a definition, not a reference.
11341 So clear DECL_EXTERNAL. */
11342 DECL_EXTERNAL (decl1
) = 0;
11344 if ((DECL_THIS_INLINE (decl1
) || DECL_TEMPLATE_INSTANTIATION (decl1
))
11345 && ! DECL_INTERFACE_KNOWN (decl1
)
11346 /* Don't try to defer nested functions for now. */
11347 && ! hack_decl_function_context (decl1
))
11348 DECL_DEFER_OUTPUT (decl1
) = 1;
11351 DECL_INTERFACE_KNOWN (decl1
) = 1;
11352 if (DECL_C_STATIC (decl1
))
11353 TREE_PUBLIC (decl1
) = 0;
11357 if (ctype
!= NULL_TREE
&& DECL_STATIC_FUNCTION_P (decl1
))
11359 if (TREE_CODE (fntype
) == METHOD_TYPE
)
11360 TREE_TYPE (decl1
) = fntype
11361 = build_function_type (TREE_TYPE (fntype
),
11362 TREE_CHAIN (TYPE_ARG_TYPES (fntype
)));
11363 current_function_parms
= TREE_CHAIN (current_function_parms
);
11364 DECL_ARGUMENTS (decl1
) = current_function_parms
;
11367 restype
= TREE_TYPE (fntype
);
11371 push_nested_class (ctype
, 1);
11373 /* If we're compiling a friend function, neither of the variables
11374 current_class_ptr nor current_class_type will have values. */
11375 if (! doing_friend
)
11377 /* We know that this was set up by `grokclassfn'.
11378 We do not wait until `store_parm_decls', since evil
11379 parse errors may never get us to that point. Here
11380 we keep the consistency between `current_class_type'
11381 and `current_class_ptr'. */
11382 tree t
= current_function_parms
;
11384 my_friendly_assert (t
!= NULL_TREE
11385 && TREE_CODE (t
) == PARM_DECL
, 162);
11387 if (TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
11389 int i
= suspend_momentary ();
11391 /* Fool build_indirect_ref. */
11392 current_class_ptr
= NULL_TREE
;
11393 current_class_ref
= build_indirect_ref (t
, NULL_PTR
);
11394 current_class_ptr
= t
;
11395 resume_momentary (i
);
11398 /* We're having a signature pointer here. */
11399 current_class_ref
= current_class_ptr
= t
;
11405 if (DECL_STATIC_FUNCTION_P (decl1
))
11406 push_nested_class (DECL_CONTEXT (decl1
), 2);
11408 push_memoized_context (0, 1);
11409 current_class_ptr
= current_class_ref
= NULL_TREE
;
11413 current_binding_level
->parm_flag
= 1;
11415 GNU_xref_function (decl1
, current_function_parms
);
11418 cplus_decl_attributes (decl1
, NULL_TREE
, attrs
);
11419 make_function_rtl (decl1
);
11421 /* Promote the value to int before returning it. */
11422 if (C_PROMOTING_INTEGER_TYPE_P (restype
))
11423 restype
= type_promotes_to (restype
);
11425 /* If this fcn was already referenced via a block-scope `extern' decl
11426 (or an implicit decl), propagate certain information about the usage. */
11427 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1
)))
11428 TREE_ADDRESSABLE (decl1
) = 1;
11430 if (DECL_RESULT (decl1
) == NULL_TREE
)
11432 DECL_RESULT (decl1
)
11433 = build_decl (RESULT_DECL
, 0, TYPE_MAIN_VARIANT (restype
));
11434 TREE_READONLY (DECL_RESULT (decl1
)) = TYPE_READONLY (restype
);
11435 TREE_THIS_VOLATILE (DECL_RESULT (decl1
)) = TYPE_VOLATILE (restype
);
11438 /* Allocate further tree nodes temporarily during compilation
11439 of this function only. Tiemann moved up here from bottom of fn. */
11440 temporary_allocation ();
11442 if (processing_template_decl
)
11444 extern tree last_tree
;
11445 ++minimal_parse_mode
;
11446 last_tree
= DECL_SAVED_TREE (decl1
)
11447 = build_nt (EXPR_STMT
, void_zero_node
);
11452 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1
))
11453 && DECL_LANGUAGE (decl1
) == lang_cplusplus
)
11455 dtor_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
11456 ctor_label
= NULL_TREE
;
11460 dtor_label
= NULL_TREE
;
11461 if (DECL_CONSTRUCTOR_P (decl1
))
11462 ctor_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
11469 store_after_parms (insns
)
11474 for (x
= get_insns (); x
; x
= next_insn (x
))
11476 if (GET_CODE (x
) == NOTE
&& NOTE_LINE_NUMBER (x
) == NOTE_INSN_FUNCTION_BEG
)
11478 emit_insns_after (insns
, x
);
11483 /* This doesn't work, because the inline output routine doesn't reset
11484 last_parm_insn correctly for get_first_nonparm_insn () to work. */
11486 last_parm_insn
= get_first_nonparm_insn ();
11487 if (last_parm_insn
== NULL_RTX
)
11488 emit_insns (insns
);
11490 emit_insns_before (insns
, last_parm_insn
);
11495 expand_start_early_try_stmts ()
11499 expand_start_try_stmts ();
11500 insns
= get_insns ();
11503 emit_insns_after (insns
, get_insns ());
11505 store_after_parms (insns
);
11509 /* Store the parameter declarations into the current function declaration.
11510 This is called after parsing the parameter declarations, before
11511 digesting the body of the function.
11513 Also install to binding contour return value identifier, if any. */
11516 store_parm_decls ()
11518 register tree fndecl
= current_function_decl
;
11519 register tree parm
;
11520 int parms_have_cleanups
= 0;
11521 tree cleanups
= NULL_TREE
;
11523 /* This is either a chain of PARM_DECLs (when a prototype is used). */
11524 tree specparms
= current_function_parms
;
11526 /* This is a list of types declared among parms in a prototype. */
11527 tree parmtags
= current_function_parm_tags
;
11529 /* This is a chain of any other decls that came in among the parm
11530 declarations. If a parm is declared with enum {foo, bar} x;
11531 then CONST_DECLs for foo and bar are put here. */
11532 tree nonparms
= NULL_TREE
;
11534 if (toplevel_bindings_p ())
11535 fatal ("parse errors have confused me too much");
11537 /* Initialize RTL machinery. */
11538 init_function_start (fndecl
, input_filename
, lineno
);
11540 /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
11541 declare_function_name ();
11543 /* Create a binding level for the parms. */
11544 expand_start_bindings (0);
11546 if (specparms
!= NULL_TREE
)
11548 /* This case is when the function was defined with an ANSI prototype.
11549 The parms already have decls, so we need not do anything here
11550 except record them as in effect
11551 and complain if any redundant old-style parm decls were written. */
11553 register tree next
;
11555 /* Must clear this because it might contain TYPE_DECLs declared
11557 storedecls (NULL_TREE
);
11559 for (parm
= nreverse (specparms
); parm
; parm
= next
)
11561 next
= TREE_CHAIN (parm
);
11562 if (TREE_CODE (parm
) == PARM_DECL
)
11565 if (DECL_NAME (parm
) == NULL_TREE
)
11569 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm
)) == void_type_node
)
11570 cp_error ("parameter `%D' declared void", parm
);
11573 /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
11574 A parameter is assumed not to have any side effects.
11575 If this should change for any reason, then this
11576 will have to wrap the bashed reference type in a save_expr.
11578 Also, if the parameter type is declared to be an X
11579 and there is an X(X&) constructor, we cannot lay it
11580 into the stack (any more), so we make this parameter
11581 look like it is really of reference type. Functions
11582 which pass parameters to this function will know to
11583 create a temporary in their frame, and pass a reference
11586 if (TREE_CODE (TREE_TYPE (parm
)) == REFERENCE_TYPE
11587 && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm
))))
11588 SET_DECL_REFERENCE_SLOT (parm
, convert_from_reference (parm
));
11592 if (! processing_template_decl
11593 && (cleanup
= maybe_build_cleanup (parm
), cleanup
))
11595 expand_decl (parm
);
11596 parms_have_cleanups
= 1;
11598 /* Keep track of the cleanups. */
11599 cleanups
= tree_cons (parm
, cleanup
, cleanups
);
11604 /* If we find an enum constant or a type tag,
11605 put it aside for the moment. */
11606 TREE_CHAIN (parm
) = NULL_TREE
;
11607 nonparms
= chainon (nonparms
, parm
);
11611 /* Get the decls in their original chain order
11612 and record in the function. This is all and only the
11613 PARM_DECLs that were pushed into scope by the loop above. */
11614 DECL_ARGUMENTS (fndecl
) = getdecls ();
11616 storetags (chainon (parmtags
, gettags ()));
11619 DECL_ARGUMENTS (fndecl
) = NULL_TREE
;
11621 /* Now store the final chain of decls for the arguments
11622 as the decl-chain of the current lexical scope.
11623 Put the enumerators in as well, at the front so that
11624 DECL_ARGUMENTS is not modified. */
11626 storedecls (chainon (nonparms
, DECL_ARGUMENTS (fndecl
)));
11628 /* Initialize the RTL code for the function. */
11629 DECL_SAVED_INSNS (fndecl
) = NULL_RTX
;
11630 if (! processing_template_decl
)
11631 expand_function_start (fndecl
, parms_have_cleanups
);
11633 current_function_parms_stored
= 1;
11635 /* If this function is `main', emit a call to `__main'
11636 to run global initializers, etc. */
11637 if (DECL_NAME (fndecl
)
11638 && IDENTIFIER_LENGTH (DECL_NAME (fndecl
)) == 4
11639 && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl
)), "main") == 0
11640 && DECL_CONTEXT (fndecl
) == NULL_TREE
)
11642 expand_main_function ();
11645 /* Now that we have initialized the parms, we can start their
11646 cleanups. We cannot do this before, since expand_decl_cleanup
11647 should not be called before the parm can be used. */
11649 && ! processing_template_decl
)
11651 for (cleanups
= nreverse (cleanups
); cleanups
; cleanups
= TREE_CHAIN (cleanups
))
11653 if (! expand_decl_cleanup (TREE_PURPOSE (cleanups
), TREE_VALUE (cleanups
)))
11654 cp_error ("parser lost in parsing declaration of `%D'",
11655 TREE_PURPOSE (cleanups
));
11659 /* Create a binding contour which can be used to catch
11660 cleanup-generated temporaries. Also, if the return value needs or
11661 has initialization, deal with that now. */
11662 if (parms_have_cleanups
)
11665 expand_start_bindings (0);
11668 last_parm_cleanup_insn
= get_last_insn ();
11670 if (! processing_template_decl
&& flag_exceptions
)
11672 /* Do the starting of the exception specifications, if we have any. */
11673 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl
)))
11674 expand_start_eh_spec ();
11677 last_dtor_insn
= get_last_insn ();
11680 /* Bind a name and initialization to the return value of
11681 the current function. */
11684 store_return_init (return_id
, init
)
11685 tree return_id
, init
;
11687 tree decl
= DECL_RESULT (current_function_decl
);
11690 /* Give this error as many times as there are occurrences,
11691 so that users can use Emacs compilation buffers to find
11692 and fix all such places. */
11693 pedwarn ("ANSI C++ does not permit named return values");
11695 if (return_id
!= NULL_TREE
)
11697 if (DECL_NAME (decl
) == NULL_TREE
)
11699 DECL_NAME (decl
) = return_id
;
11700 DECL_ASSEMBLER_NAME (decl
) = return_id
;
11703 cp_error ("return identifier `%D' already in place", decl
);
11706 /* Can't let this happen for constructors. */
11707 if (DECL_CONSTRUCTOR_P (current_function_decl
))
11709 error ("can't redefine default return value for constructors");
11713 /* If we have a named return value, put that in our scope as well. */
11714 if (DECL_NAME (decl
) != NULL_TREE
)
11716 /* If this named return value comes in a register,
11717 put it in a pseudo-register. */
11718 if (DECL_REGISTER (decl
))
11720 original_result_rtx
= DECL_RTL (decl
);
11721 DECL_RTL (decl
) = gen_reg_rtx (DECL_MODE (decl
));
11724 /* Let `cp_finish_decl' know that this initializer is ok. */
11725 DECL_INITIAL (decl
) = init
;
11728 if (minimal_parse_mode
)
11729 add_tree (build_min_nt (RETURN_INIT
, return_id
,
11730 copy_to_permanent (init
)));
11732 cp_finish_decl (decl
, init
, NULL_TREE
, 0, LOOKUP_ONLYCONVERTING
);
11737 /* Finish up a function declaration and compile that function
11738 all the way to assembler language output. The free the storage
11739 for the function definition.
11741 This is called after parsing the body of the function definition.
11742 LINENO is the current line number.
11744 C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
11745 (and expand_end_bindings) must be made to take care of the binding
11746 contour for the base initializers. This is only relevant for
11749 NESTED is nonzero if we were in the middle of compiling another function
11750 when we started on this one. */
11753 finish_function (lineno
, call_poplevel
, nested
)
11758 register tree fndecl
= current_function_decl
;
11759 tree fntype
, ctype
= NULL_TREE
;
11760 rtx last_parm_insn
, insns
;
11761 /* Label to use if this function is supposed to return a value. */
11762 tree no_return_label
= NULL_TREE
;
11763 tree decls
= NULL_TREE
;
11765 /* When we get some parse errors, we can end up without a
11766 current_function_decl, so cope. */
11767 if (fndecl
== NULL_TREE
)
11770 if (! nested
&& function_depth
> 1)
11773 fntype
= TREE_TYPE (fndecl
);
11775 /* TREE_READONLY (fndecl) = 1;
11776 This caused &foo to be of type ptr-to-const-function
11777 which then got a warning when stored in a ptr-to-function variable. */
11779 /* This happens on strange parse errors. */
11780 if (! current_function_parms_stored
)
11783 store_parm_decls ();
11786 if (processing_template_decl
)
11788 if (DECL_CONSTRUCTOR_P (fndecl
) && call_poplevel
)
11790 decls
= getdecls ();
11791 expand_end_bindings (decls
, decls
!= NULL_TREE
, 0);
11792 poplevel (decls
!= NULL_TREE
, 0, 0);
11797 if (write_symbols
!= NO_DEBUG
/*&& TREE_CODE (fntype) != METHOD_TYPE*/)
11799 tree ttype
= target_type (fntype
);
11802 if (IS_AGGR_TYPE (ttype
))
11803 /* Let debugger know it should output info for this type. */
11804 note_debug_info_needed (ttype
);
11806 for (parmdecl
= DECL_ARGUMENTS (fndecl
); parmdecl
; parmdecl
= TREE_CHAIN (parmdecl
))
11808 ttype
= target_type (TREE_TYPE (parmdecl
));
11809 if (IS_AGGR_TYPE (ttype
))
11810 /* Let debugger know it should output info for this type. */
11811 note_debug_info_needed (ttype
);
11815 /* Clean house because we will need to reorder insns here. */
11816 do_pending_stack_adjust ();
11820 tree binfo
= TYPE_BINFO (current_class_type
);
11821 tree cond
= integer_one_node
;
11823 tree in_charge_node
= lookup_name (in_charge_identifier
, 0);
11825 int ok_to_optimize_dtor
= 0;
11826 int empty_dtor
= get_last_insn () == last_dtor_insn
;
11828 if (current_function_assigns_this
)
11829 cond
= build (NE_EXPR
, boolean_type_node
,
11830 current_class_ptr
, integer_zero_node
);
11833 int n_baseclasses
= CLASSTYPE_N_BASECLASSES (current_class_type
);
11835 /* If this destructor is empty, then we don't need to check
11836 whether `this' is NULL in some cases. */
11837 if ((flag_this_is_variable
& 1) == 0)
11838 ok_to_optimize_dtor
= 1;
11839 else if (empty_dtor
)
11840 ok_to_optimize_dtor
11841 = (n_baseclasses
== 0
11842 || (n_baseclasses
== 1
11843 && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type
, 0))));
11846 /* These initializations might go inline. Protect
11847 the binding level of the parms. */
11849 expand_start_bindings (0);
11851 if (current_function_assigns_this
)
11853 current_function_assigns_this
= 0;
11854 current_function_just_assigned_this
= 0;
11857 /* Generate the code to call destructor on base class.
11858 If this destructor belongs to a class with virtual
11859 functions, then set the virtual function table
11860 pointer to represent the type of our base class. */
11862 /* This side-effect makes call to `build_delete' generate the
11863 code we have to have at the end of this destructor. */
11864 TYPE_HAS_DESTRUCTOR (current_class_type
) = 0;
11866 /* These are two cases where we cannot delegate deletion. */
11867 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
)
11868 || TYPE_GETS_REG_DELETE (current_class_type
))
11869 exprstmt
= build_delete (current_class_type
, current_class_ref
, integer_zero_node
,
11870 LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
|LOOKUP_NORMAL
, 0);
11872 exprstmt
= build_delete (current_class_type
, current_class_ref
, in_charge_node
,
11873 LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
|LOOKUP_NORMAL
, 0);
11875 /* If we did not assign to this, then `this' is non-zero at
11876 the end of a destructor. As a special optimization, don't
11877 emit test if this is an empty destructor. If it does nothing,
11878 it does nothing. If it calls a base destructor, the base
11879 destructor will perform the test. */
11881 if (exprstmt
!= error_mark_node
11882 && (TREE_CODE (exprstmt
) != NOP_EXPR
11883 || TREE_OPERAND (exprstmt
, 0) != integer_zero_node
11884 || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
)))
11886 expand_label (dtor_label
);
11887 if (cond
!= integer_one_node
)
11888 expand_start_cond (cond
, 0);
11889 if (exprstmt
!= void_zero_node
)
11890 /* Don't call `expand_expr_stmt' if we're not going to do
11891 anything, since -Wall will give a diagnostic. */
11892 expand_expr_stmt (exprstmt
);
11894 /* Run destructor on all virtual baseclasses. */
11895 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
11897 tree vbases
= nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type
)));
11898 expand_start_cond (build (BIT_AND_EXPR
, integer_type_node
,
11899 in_charge_node
, integer_two_node
), 0);
11902 if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases
)))
11904 tree vb
= get_vbase
11905 (BINFO_TYPE (vbases
),
11906 TYPE_BINFO (current_class_type
));
11908 (build_scoped_method_call
11909 (current_class_ref
, vb
, dtor_identifier
,
11910 build_tree_list (NULL_TREE
, integer_zero_node
)));
11912 vbases
= TREE_CHAIN (vbases
);
11914 expand_end_cond ();
11917 do_pending_stack_adjust ();
11918 if (cond
!= integer_one_node
)
11919 expand_end_cond ();
11922 TYPE_HAS_DESTRUCTOR (current_class_type
) = 1;
11924 virtual_size
= c_sizeof (current_class_type
);
11926 /* At the end, call delete if that's what's requested. */
11927 if (TYPE_GETS_REG_DELETE (current_class_type
))
11928 /* This NOP_EXPR means we are in a static call context. */
11930 = build_method_call (build_indirect_ref (build1 (NOP_EXPR
,
11931 build_pointer_type (current_class_type
),
11934 ansi_opname
[(int) DELETE_EXPR
],
11935 tree_cons (NULL_TREE
, current_class_ptr
,
11936 build_tree_list (NULL_TREE
, virtual_size
)),
11937 NULL_TREE
, LOOKUP_NORMAL
);
11938 else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
11939 exprstmt
= build_x_delete (ptr_type_node
, current_class_ptr
, 0,
11942 exprstmt
= NULL_TREE
;
11946 cond
= build (BIT_AND_EXPR
, integer_type_node
,
11947 in_charge_node
, integer_one_node
);
11948 expand_start_cond (cond
, 0);
11949 expand_expr_stmt (exprstmt
);
11950 expand_end_cond ();
11953 /* End of destructor. */
11954 expand_end_bindings (NULL_TREE
, getdecls () != NULL_TREE
, 0);
11955 poplevel (2, 0, 0); /* XXX change to 1 */
11957 /* Back to the top of destructor. */
11958 /* Dont execute destructor code if `this' is NULL. */
11962 /* If the dtor is empty, and we know there is not possible way we
11963 could use any vtable entries, before they are possibly set by
11964 a base class dtor, we don't have to setup the vtables, as we
11965 know that any base class dtoring will set up any vtables it
11966 needs. We avoid MI, because one base class dtor can do a
11967 virtual dispatch to an overridden function that would need to
11968 have a non-related vtable set up, we cannot avoid setting up
11969 vtables in that case. We could change this to see if there is
11970 just one vtable. */
11971 if (! empty_dtor
|| TYPE_USES_COMPLEX_INHERITANCE (current_class_type
))
11973 /* Make all virtual function table pointers in non-virtual base
11974 classes point to CURRENT_CLASS_TYPE's virtual function
11976 expand_direct_vtbls_init (binfo
, binfo
, 1, 0, current_class_ptr
);
11978 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
11979 expand_indirect_vtbls_init (binfo
, current_class_ref
, current_class_ptr
);
11982 if (! ok_to_optimize_dtor
)
11984 cond
= build_binary_op (NE_EXPR
,
11985 current_class_ptr
, integer_zero_node
, 1);
11986 expand_start_cond (cond
, 0);
11989 insns
= get_insns ();
11992 last_parm_insn
= get_first_nonparm_insn ();
11993 if (last_parm_insn
== NULL_RTX
)
11994 last_parm_insn
= get_last_insn ();
11996 last_parm_insn
= previous_insn (last_parm_insn
);
11998 emit_insns_after (insns
, last_parm_insn
);
12000 if (! ok_to_optimize_dtor
)
12001 expand_end_cond ();
12003 else if (current_function_assigns_this
)
12005 /* Does not need to call emit_base_init, because
12006 that is done (if needed) just after assignment to this
12009 if (DECL_CONSTRUCTOR_P (current_function_decl
))
12011 end_protect_partials ();
12012 expand_label (ctor_label
);
12013 ctor_label
= NULL_TREE
;
12017 decls
= getdecls ();
12018 expand_end_bindings (decls
, decls
!= NULL_TREE
, 0);
12019 poplevel (decls
!= NULL_TREE
, 0, 0);
12021 c_expand_return (current_class_ptr
);
12023 else if (TYPE_MAIN_VARIANT (TREE_TYPE (
12024 DECL_RESULT (current_function_decl
))) != void_type_node
12025 && return_label
!= NULL_RTX
)
12026 no_return_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
12028 current_function_assigns_this
= 0;
12029 current_function_just_assigned_this
= 0;
12030 base_init_expr
= NULL_TREE
;
12032 else if (DECL_CONSTRUCTOR_P (fndecl
))
12034 tree cond
, thenclause
;
12035 /* Allow constructor for a type to get a new instance of the object
12036 using `build_new'. */
12037 tree abstract_virtuals
= CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type
);
12038 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type
) = NULL_TREE
;
12040 DECL_RETURNS_FIRST_ARG (fndecl
) = 1;
12042 if (flag_this_is_variable
> 0)
12044 cond
= build_binary_op (EQ_EXPR
,
12045 current_class_ptr
, integer_zero_node
, 1);
12046 thenclause
= build_modify_expr (current_class_ptr
, NOP_EXPR
,
12047 build_new (NULL_TREE
, current_class_type
, void_type_node
, 0));
12050 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type
) = abstract_virtuals
;
12054 if (flag_this_is_variable
> 0)
12056 expand_start_cond (cond
, 0);
12057 expand_expr_stmt (thenclause
);
12058 expand_end_cond ();
12061 /* Emit insns from `emit_base_init' which sets up virtual
12062 function table pointer(s). */
12063 if (base_init_expr
)
12065 expand_expr_stmt (base_init_expr
);
12066 base_init_expr
= NULL_TREE
;
12069 insns
= get_insns ();
12072 /* This is where the body of the constructor begins. */
12074 emit_insns_after (insns
, last_parm_cleanup_insn
);
12076 end_protect_partials ();
12078 /* This is where the body of the constructor ends. */
12079 expand_label (ctor_label
);
12080 ctor_label
= NULL_TREE
;
12084 decls
= getdecls ();
12085 expand_end_bindings (decls
, decls
!= NULL_TREE
, 0);
12086 poplevel (decls
!= NULL_TREE
, 1, 0);
12089 c_expand_return (current_class_ptr
);
12091 current_function_assigns_this
= 0;
12092 current_function_just_assigned_this
= 0;
12094 else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl
)) == 4
12095 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl
)), "main")
12096 && DECL_CONTEXT (fndecl
) == NULL_TREE
)
12098 /* Make it so that `main' always returns 0 by default. */
12100 c_expand_return (integer_one_node
);
12102 c_expand_return (integer_zero_node
);
12105 else if (return_label
!= NULL_RTX
12106 && current_function_return_value
== NULL_TREE
12107 && ! DECL_NAME (DECL_RESULT (current_function_decl
)))
12108 no_return_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
12110 if (flag_exceptions
)
12111 expand_exception_blocks ();
12113 /* If this function is supposed to return a value, ensure that
12114 we do not fall into the cleanups by mistake. The end of our
12115 function will look like this:
12117 user code (may have return stmt somewhere)
12118 goto no_return_label
12123 NOTE_INSN_FUNCTION_END
12127 If the user omits a return stmt in the USER CODE section, we
12128 will have a control path which reaches NOTE_INSN_FUNCTION_END.
12129 Otherwise, we won't. */
12130 if (no_return_label
)
12132 DECL_CONTEXT (no_return_label
) = fndecl
;
12133 DECL_INITIAL (no_return_label
) = error_mark_node
;
12134 DECL_SOURCE_FILE (no_return_label
) = input_filename
;
12135 DECL_SOURCE_LINE (no_return_label
) = lineno
;
12136 expand_goto (no_return_label
);
12141 /* remove the binding contour which is used
12142 to catch cleanup-generated temporaries. */
12143 expand_end_bindings (0, 0, 0);
12144 poplevel (0, 0, 0);
12146 /* Emit label at beginning of cleanup code for parameters. */
12147 emit_label (cleanup_label
);
12150 /* Get return value into register if that's where it's supposed to be. */
12151 if (original_result_rtx
)
12152 fixup_result_decl (DECL_RESULT (fndecl
), original_result_rtx
);
12154 /* Finish building code that will trigger warnings if users forget
12155 to make their functions return values. */
12156 if (no_return_label
|| cleanup_label
)
12157 emit_jump (return_label
);
12158 if (no_return_label
)
12160 /* We don't need to call `expand_*_return' here because we
12161 don't need any cleanups here--this path of code is only
12162 for error checking purposes. */
12163 expand_label (no_return_label
);
12166 /* Generate rtl for function exit. */
12167 expand_function_end (input_filename
, lineno
, 1);
12170 /* This must come after expand_function_end because cleanups might
12171 have declarations (from inline functions) that need to go into
12172 this function's blocks. */
12173 if (current_binding_level
->parm_flag
!= 1)
12174 my_friendly_abort (122);
12175 poplevel (1, 0, 1);
12177 /* reset scope for C++: if we were in the scope of a class,
12178 then when we finish this function, we are not longer so.
12179 This cannot be done until we know for sure that no more
12180 class members will ever be referenced in this function
12181 (i.e., calls to destructors). */
12182 if (current_class_name
)
12184 ctype
= current_class_type
;
12185 pop_nested_class (1);
12188 pop_memoized_context (1);
12190 /* Must mark the RESULT_DECL as being in this function. */
12191 DECL_CONTEXT (DECL_RESULT (fndecl
)) = fndecl
;
12193 /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
12194 to the FUNCTION_DECL node itself. */
12195 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
12197 if (! processing_template_decl
)
12199 /* So we can tell if jump_optimize sets it to 1. */
12202 /* Run the optimizers and output the assembler code for this
12205 if (DECL_ARTIFICIAL (fndecl
))
12207 /* Do we really *want* to inline this synthesized method? */
12209 int save_fif
= flag_inline_functions
;
12210 flag_inline_functions
= 1;
12212 /* Turn off DECL_INLINE for the moment so function_cannot_inline_p
12213 will check our size. */
12214 DECL_INLINE (fndecl
) = 0;
12216 rest_of_compilation (fndecl
);
12217 flag_inline_functions
= save_fif
;
12220 rest_of_compilation (fndecl
);
12222 if (DECL_SAVED_INSNS (fndecl
) && ! TREE_ASM_WRITTEN (fndecl
))
12224 /* Set DECL_EXTERNAL so that assemble_external will be called as
12225 necessary. We'll clear it again in finish_file. */
12226 if (! DECL_EXTERNAL (fndecl
))
12227 DECL_NOT_REALLY_EXTERN (fndecl
) = 1;
12228 DECL_EXTERNAL (fndecl
) = 1;
12229 mark_inline_for_output (fndecl
);
12232 if (ctype
&& TREE_ASM_WRITTEN (fndecl
))
12233 note_debug_info_needed (ctype
);
12235 current_function_returns_null
|= can_reach_end
;
12237 /* Since we don't normally go through c_expand_return for constructors,
12238 this normally gets the wrong value.
12239 Also, named return values have their return codes emitted after
12240 NOTE_INSN_FUNCTION_END, confusing jump.c. */
12241 if (DECL_CONSTRUCTOR_P (fndecl
)
12242 || DECL_NAME (DECL_RESULT (fndecl
)) != NULL_TREE
)
12243 current_function_returns_null
= 0;
12245 if (TREE_THIS_VOLATILE (fndecl
) && current_function_returns_null
)
12246 cp_warning ("`noreturn' function `%D' does return", fndecl
);
12247 else if ((warn_return_type
|| pedantic
)
12248 && current_function_returns_null
12249 && TYPE_MAIN_VARIANT (TREE_TYPE (fntype
)) != void_type_node
)
12251 /* If this function returns non-void and control can drop through,
12253 cp_pedwarn ("control reaches end of non-void function `%D'", fndecl
);
12255 /* With just -W, complain only if function returns both with
12256 and without a value. */
12257 else if (extra_warnings
12258 && current_function_returns_value
&& current_function_returns_null
)
12259 warning ("this function may return with or without a value");
12264 /* Free all the tree nodes making up this function. */
12265 /* Switch back to allocating nodes permanently
12266 until we start another function. */
12267 if (processing_template_decl
)
12269 --minimal_parse_mode
;
12270 DECL_SAVED_TREE (fndecl
) = TREE_CHAIN (DECL_SAVED_TREE (fndecl
));
12274 permanent_allocation (1);
12276 if (DECL_SAVED_INSNS (fndecl
) == NULL_RTX
)
12280 /* Stop pointing to the local nodes about to be freed. */
12281 /* But DECL_INITIAL must remain nonzero so we know this
12282 was an actual function definition. */
12283 DECL_INITIAL (fndecl
) = error_mark_node
;
12284 for (t
= DECL_ARGUMENTS (fndecl
); t
; t
= TREE_CHAIN (t
))
12285 DECL_RTL (t
) = DECL_INCOMING_RTL (t
) = NULL_RTX
;
12288 if (DECL_STATIC_CONSTRUCTOR (fndecl
))
12289 static_ctors
= perm_tree_cons (NULL_TREE
, fndecl
, static_ctors
);
12290 if (DECL_STATIC_DESTRUCTOR (fndecl
))
12291 static_dtors
= perm_tree_cons (NULL_TREE
, fndecl
, static_dtors
);
12295 /* Let the error reporting routines know that we're outside a
12296 function. For a nested function, this value is used in
12297 pop_cp_function_context and then reset via pop_function_context. */
12298 current_function_decl
= NULL_TREE
;
12301 named_label_uses
= NULL
;
12302 current_class_ptr
= NULL_TREE
;
12303 current_class_ref
= NULL_TREE
;
12306 /* Create the FUNCTION_DECL for a function definition.
12307 LINE1 is the line number that the definition absolutely begins on.
12308 LINE2 is the line number that the name of the function appears on.
12309 DECLSPECS and DECLARATOR are the parts of the declaration;
12310 they describe the return type and the name of the function,
12311 but twisted together in a fashion that parallels the syntax of C.
12313 This function creates a binding context for the function body
12314 as well as setting up the FUNCTION_DECL in current_function_decl.
12316 Returns a FUNCTION_DECL on success.
12318 If the DECLARATOR is not suitable for a function (it defines a datum
12319 instead), we return 0, which tells yyparse to report a parse error.
12321 May return void_type_node indicating that this method is actually
12322 a friend. See grokfield for more details.
12324 Came here with a `.pushlevel' .
12326 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
12327 CHANGES TO CODE IN `grokfield'. */
12330 start_method (declspecs
, declarator
)
12331 tree declarator
, declspecs
;
12333 tree fndecl
= grokdeclarator (declarator
, declspecs
, MEMFUNCDEF
, 0,
12336 /* Something too ugly to handle. */
12337 if (fndecl
== NULL_TREE
)
12340 /* Pass friends other than inline friend functions back. */
12341 if (TYPE_MAIN_VARIANT (fndecl
) == void_type_node
)
12344 if (TREE_CODE (fndecl
) != FUNCTION_DECL
)
12345 /* Not a function, tell parser to report parse error. */
12348 if (IS_SIGNATURE (current_class_type
))
12349 IS_DEFAULT_IMPLEMENTATION (fndecl
) = 1;
12351 if (DECL_IN_AGGR_P (fndecl
))
12353 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl
)) != current_class_type
)
12355 if (DECL_CONTEXT (fndecl
))
12356 cp_error ("`%D' is already defined in class %s", fndecl
,
12357 TYPE_NAME_STRING (DECL_CONTEXT (fndecl
)));
12359 return void_type_node
;
12362 DECL_THIS_INLINE (fndecl
) = 1;
12364 if (flag_default_inline
)
12365 DECL_INLINE (fndecl
) = 1;
12367 if (processing_template_decl
&& ! current_function_decl
)
12368 push_template_decl (fndecl
);
12370 /* We read in the parameters on the maybepermanent_obstack,
12371 but we won't be getting back to them until after we
12372 may have clobbered them. So the call to preserve_data
12373 will keep them safe. */
12376 if (! DECL_FRIEND_P (fndecl
))
12378 if (DECL_CHAIN (fndecl
) != NULL_TREE
)
12380 /* Need a fresh node here so that we don't get circularity
12381 when we link these together. If FNDECL was a friend, then
12382 `pushdecl' does the right thing, which is nothing wrt its
12383 current value of DECL_CHAIN. */
12384 fndecl
= copy_node (fndecl
);
12386 if (TREE_CHAIN (fndecl
))
12388 fndecl
= copy_node (fndecl
);
12389 TREE_CHAIN (fndecl
) = NULL_TREE
;
12392 if (DECL_CONSTRUCTOR_P (fndecl
))
12394 if (! grok_ctor_properties (current_class_type
, fndecl
))
12395 return void_type_node
;
12397 else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl
)))
12398 grok_op_properties (fndecl
, DECL_VIRTUAL_P (fndecl
), 0);
12401 cp_finish_decl (fndecl
, NULL_TREE
, NULL_TREE
, 0, 0);
12403 /* Make a place for the parms */
12405 current_binding_level
->parm_flag
= 1;
12407 DECL_IN_AGGR_P (fndecl
) = 1;
12411 /* Go through the motions of finishing a function definition.
12412 We don't compile this method until after the whole class has
12415 FINISH_METHOD must return something that looks as though it
12416 came from GROKFIELD (since we are defining a method, after all).
12418 This is called after parsing the body of the function definition.
12419 STMTS is the chain of statements that makes up the function body.
12421 DECL is the ..._DECL that `start_method' provided. */
12424 finish_method (decl
)
12427 register tree fndecl
= decl
;
12430 register tree link
;
12432 if (TYPE_MAIN_VARIANT (decl
) == void_type_node
)
12435 old_initial
= DECL_INITIAL (fndecl
);
12437 /* Undo the level for the parms (from start_method).
12438 This is like poplevel, but it causes nothing to be
12439 saved. Saving information here confuses symbol-table
12440 output routines. Besides, this information will
12441 be correctly output when this method is actually
12444 /* Clear out the meanings of the local variables of this level;
12445 also record in each decl which block it belongs to. */
12447 for (link
= current_binding_level
->names
; link
; link
= TREE_CHAIN (link
))
12449 if (DECL_NAME (link
) != NULL_TREE
)
12450 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link
)) = 0;
12451 my_friendly_assert (TREE_CODE (link
) != FUNCTION_DECL
, 163);
12452 DECL_CONTEXT (link
) = NULL_TREE
;
12455 /* Restore all name-meanings of the outer levels
12456 that were shadowed by this level. */
12458 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
12459 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
12460 for (link
= current_binding_level
->class_shadowed
;
12461 link
; link
= TREE_CHAIN (link
))
12462 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
12463 for (link
= current_binding_level
->type_shadowed
;
12464 link
; link
= TREE_CHAIN (link
))
12465 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
12467 GNU_xref_end_scope ((HOST_WIDE_INT
) current_binding_level
,
12468 (HOST_WIDE_INT
) current_binding_level
->level_chain
,
12469 current_binding_level
->parm_flag
,
12470 current_binding_level
->keep
);
12472 poplevel (0, 0, 0);
12474 DECL_INITIAL (fndecl
) = old_initial
;
12476 /* We used to check if the context of FNDECL was different from
12477 current_class_type as another way to get inside here. This didn't work
12478 for String.cc in libg++. */
12479 if (DECL_FRIEND_P (fndecl
))
12481 CLASSTYPE_INLINE_FRIENDS (current_class_type
)
12482 = tree_cons (NULL_TREE
, fndecl
, CLASSTYPE_INLINE_FRIENDS (current_class_type
));
12483 decl
= void_type_node
;
12489 /* Called when a new struct TYPE is defined.
12490 If this structure or union completes the type of any previous
12491 variable declaration, lay it out and output its rtl. */
12494 hack_incomplete_structures (type
)
12499 if (current_binding_level
->incomplete
== NULL_TREE
)
12502 if (!type
) /* Don't do this for class templates. */
12505 for (list
= ¤t_binding_level
->incomplete
; *list
; )
12507 tree decl
= TREE_VALUE (*list
);
12508 if (decl
&& TREE_TYPE (decl
) == type
12509 || (TREE_TYPE (decl
)
12510 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
12511 && TREE_TYPE (TREE_TYPE (decl
)) == type
))
12513 int toplevel
= toplevel_bindings_p ();
12514 if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
12515 && TREE_TYPE (TREE_TYPE (decl
)) == type
)
12516 layout_type (TREE_TYPE (decl
));
12517 layout_decl (decl
, 0);
12518 rest_of_decl_compilation (decl
, NULL_PTR
, toplevel
, 0);
12522 expand_decl (decl
);
12523 cleanup
= maybe_build_cleanup (decl
);
12524 expand_decl_init (decl
);
12525 if (! expand_decl_cleanup (decl
, cleanup
))
12526 cp_error ("parser lost in parsing declaration of `%D'",
12529 *list
= TREE_CHAIN (*list
);
12532 list
= &TREE_CHAIN (*list
);
12536 /* If DECL is of a type which needs a cleanup, build that cleanup here.
12537 See build_delete for information about AUTO_DELETE.
12539 Don't build these on the momentary obstack; they must live
12540 the life of the binding contour. */
12543 maybe_build_cleanup_1 (decl
, auto_delete
)
12544 tree decl
, auto_delete
;
12546 tree type
= TREE_TYPE (decl
);
12547 if (TYPE_NEEDS_DESTRUCTOR (type
))
12549 int temp
= 0, flags
= LOOKUP_NORMAL
|LOOKUP_DESTRUCTOR
;
12552 if (TREE_CODE (decl
) != PARM_DECL
)
12553 temp
= suspend_momentary ();
12555 if (TREE_CODE (type
) == ARRAY_TYPE
)
12559 mark_addressable (decl
);
12560 rval
= build_unary_op (ADDR_EXPR
, decl
, 0);
12563 /* Optimize for space over speed here. */
12564 if (! TYPE_USES_VIRTUAL_BASECLASSES (type
)
12565 || flag_expensive_optimizations
)
12566 flags
|= LOOKUP_NONVIRTUAL
;
12568 rval
= build_delete (TREE_TYPE (rval
), rval
, auto_delete
, flags
, 0);
12570 if (TYPE_USES_VIRTUAL_BASECLASSES (type
)
12571 && ! TYPE_HAS_DESTRUCTOR (type
))
12572 rval
= build_compound_expr (tree_cons (NULL_TREE
, rval
,
12573 build_tree_list (NULL_TREE
, build_vbase_delete (type
, decl
))));
12575 if (TREE_CODE (decl
) != PARM_DECL
)
12576 resume_momentary (temp
);
12583 /* If DECL is of a type which needs a cleanup, build that cleanup
12584 here. The cleanup does free the storage with a call to delete. */
12587 maybe_build_cleanup_and_delete (decl
)
12590 return maybe_build_cleanup_1 (decl
, integer_three_node
);
12593 /* If DECL is of a type which needs a cleanup, build that cleanup
12594 here. The cleanup does not free the storage with a call a delete. */
12597 maybe_build_cleanup (decl
)
12600 return maybe_build_cleanup_1 (decl
, integer_two_node
);
12603 /* Expand a C++ expression at the statement level.
12604 This is needed to ferret out nodes which have UNKNOWN_TYPE.
12605 The C++ type checker should get all of these out when
12606 expressions are combined with other, type-providing, expressions,
12607 leaving only orphan expressions, such as:
12609 &class::bar; / / takes its address, but does nothing with it. */
12612 cplus_expand_expr_stmt (exp
)
12615 if (processing_template_decl
)
12617 add_tree (build_min_nt (EXPR_STMT
, exp
));
12621 /* Arrange for all temps to disappear. */
12622 expand_start_target_temps ();
12624 if (TREE_TYPE (exp
) == unknown_type_node
)
12626 if (TREE_CODE (exp
) == ADDR_EXPR
|| TREE_CODE (exp
) == TREE_LIST
)
12627 error ("address of overloaded function with no contextual type information");
12628 else if (TREE_CODE (exp
) == COMPONENT_REF
)
12629 warning ("useless reference to a member function name, did you forget the ()?");
12633 if (TREE_CODE (exp
) == FUNCTION_DECL
)
12635 cp_warning ("reference, not call, to function `%D'", exp
);
12636 warning ("at this point in file");
12640 /* We should do this eventually, but right now this causes regex.o from
12641 libg++ to miscompile, and tString to core dump. */
12642 exp
= build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
);
12644 /* If we don't do this, we end up down inside expand_expr
12645 trying to do TYPE_MODE on the ERROR_MARK, and really
12646 go outside the bounds of the type. */
12647 if (exp
!= error_mark_node
)
12648 expand_expr_stmt (break_out_cleanups (exp
));
12651 /* Clean up any pending cleanups. This happens when a function call
12652 returns a cleanup-needing value that nobody uses. */
12653 expand_end_target_temps ();
12656 /* When a stmt has been parsed, this function is called.
12658 Currently, this function only does something within a
12659 constructor's scope: if a stmt has just assigned to this,
12660 and we are in a derived class, we call `emit_base_init'. */
12665 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
12668 if (current_function_assigns_this
12669 || ! current_function_just_assigned_this
)
12671 if (DECL_CONSTRUCTOR_P (current_function_decl
))
12673 /* Constructors must wait until we are out of control
12674 zones before calling base constructors. */
12675 if (cond_stack
|| loop_stack
|| case_stack
)
12677 expand_expr_stmt (base_init_expr
);
12678 check_base_init (current_class_type
);
12680 current_function_assigns_this
= 1;
12683 /* Change a static member function definition into a FUNCTION_TYPE, instead
12684 of the METHOD_TYPE that we create when it's originally parsed.
12686 WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES
12687 (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of
12688 other decls. Either pass the addresses of local variables or NULL. */
12691 revert_static_member_fn (decl
, fn
, argtypes
)
12692 tree
*decl
, *fn
, *argtypes
;
12695 tree function
= fn
? *fn
: TREE_TYPE (*decl
);
12696 tree args
= argtypes
? *argtypes
: TYPE_ARG_TYPES (function
);
12698 if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args
))))
12699 cp_error ("static member function `%#D' declared const", *decl
);
12700 if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args
))))
12701 cp_error ("static member function `%#D' declared volatile", *decl
);
12703 args
= TREE_CHAIN (args
);
12704 tmp
= build_function_type (TREE_TYPE (function
), args
);
12705 tmp
= build_type_variant (tmp
, TYPE_READONLY (function
),
12706 TYPE_VOLATILE (function
));
12707 tmp
= build_exception_variant (tmp
,
12708 TYPE_RAISES_EXCEPTIONS (function
));
12709 TREE_TYPE (*decl
) = tmp
;
12710 if (DECL_ARGUMENTS (*decl
))
12711 DECL_ARGUMENTS (*decl
) = TREE_CHAIN (DECL_ARGUMENTS (*decl
));
12712 DECL_STATIC_FUNCTION_P (*decl
) = 1;
12720 id_in_current_class (id
)
12723 return !!purpose_member (id
, class_binding_level
->class_shadowed
);
12730 int warn_about_return_type
;
12732 int just_assigned_this
;
12734 int temp_name_counter
;
12736 tree shadowed_labels
;
12739 rtx last_dtor_insn
;
12740 rtx last_parm_cleanup_insn
;
12741 tree base_init_list
;
12742 tree member_init_list
;
12743 tree base_init_expr
;
12744 tree current_class_ptr
;
12745 tree current_class_ref
;
12747 struct cp_function
*next
;
12748 struct binding_level
*binding_level
;
12749 int static_labelno
;
12752 static struct cp_function
*cp_function_chain
;
12754 extern int temp_name_counter
;
12756 /* Save and reinitialize the variables
12757 used during compilation of a C++ function. */
12760 push_cp_function_context (context
)
12763 struct cp_function
*p
12764 = (struct cp_function
*) xmalloc (sizeof (struct cp_function
));
12766 push_function_context_to (context
);
12768 p
->next
= cp_function_chain
;
12769 cp_function_chain
= p
;
12771 p
->named_labels
= named_labels
;
12772 p
->shadowed_labels
= shadowed_labels
;
12773 p
->returns_value
= current_function_returns_value
;
12774 p
->returns_null
= current_function_returns_null
;
12775 p
->warn_about_return_type
= warn_about_return_type
;
12776 p
->binding_level
= current_binding_level
;
12777 p
->ctor_label
= ctor_label
;
12778 p
->dtor_label
= dtor_label
;
12779 p
->last_dtor_insn
= last_dtor_insn
;
12780 p
->last_parm_cleanup_insn
= last_parm_cleanup_insn
;
12781 p
->assigns_this
= current_function_assigns_this
;
12782 p
->just_assigned_this
= current_function_just_assigned_this
;
12783 p
->parms_stored
= current_function_parms_stored
;
12784 p
->result_rtx
= original_result_rtx
;
12785 p
->base_init_expr
= base_init_expr
;
12786 p
->temp_name_counter
= temp_name_counter
;
12787 p
->base_init_list
= current_base_init_list
;
12788 p
->member_init_list
= current_member_init_list
;
12789 p
->current_class_ptr
= current_class_ptr
;
12790 p
->current_class_ref
= current_class_ref
;
12791 p
->static_labelno
= static_labelno
;
12794 /* Restore the variables used during compilation of a C++ function. */
12797 pop_cp_function_context (context
)
12800 struct cp_function
*p
= cp_function_chain
;
12803 /* Bring back all the labels that were shadowed. */
12804 for (link
= shadowed_labels
; link
; link
= TREE_CHAIN (link
))
12805 if (DECL_NAME (TREE_VALUE (link
)) != 0)
12806 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link
)),
12807 TREE_VALUE (link
));
12809 pop_function_context_from (context
);
12811 cp_function_chain
= p
->next
;
12813 named_labels
= p
->named_labels
;
12814 shadowed_labels
= p
->shadowed_labels
;
12815 current_function_returns_value
= p
->returns_value
;
12816 current_function_returns_null
= p
->returns_null
;
12817 warn_about_return_type
= p
->warn_about_return_type
;
12818 current_binding_level
= p
->binding_level
;
12819 ctor_label
= p
->ctor_label
;
12820 dtor_label
= p
->dtor_label
;
12821 last_dtor_insn
= p
->last_dtor_insn
;
12822 last_parm_cleanup_insn
= p
->last_parm_cleanup_insn
;
12823 current_function_assigns_this
= p
->assigns_this
;
12824 current_function_just_assigned_this
= p
->just_assigned_this
;
12825 current_function_parms_stored
= p
->parms_stored
;
12826 original_result_rtx
= p
->result_rtx
;
12827 base_init_expr
= p
->base_init_expr
;
12828 temp_name_counter
= p
->temp_name_counter
;
12829 current_base_init_list
= p
->base_init_list
;
12830 current_member_init_list
= p
->member_init_list
;
12831 current_class_ptr
= p
->current_class_ptr
;
12832 current_class_ref
= p
->current_class_ref
;
12833 static_labelno
= p
->static_labelno
;
12841 return function_depth
!= 0;
12844 /* FSF LOCAL dje prefix attributes */
12845 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
12846 This function is used by the parser when a rule will accept attributes
12847 in a particular position, but we don't want to support that just yet.
12849 A warning is issued for every ignored attribute. */
12852 strip_attrs (specs_attrs
)
12857 split_specs_attrs (specs_attrs
, &specs
, &attrs
);
12861 warning ("`%s' attribute ignored",
12862 IDENTIFIER_POINTER (TREE_PURPOSE (attrs
)));
12863 attrs
= TREE_CHAIN (attrs
);
12868 /* END FSF LOCAL */