1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
37 #include <sys/types.h>
41 #define obstack_chunk_alloc xmalloc
42 #define obstack_chunk_free free
44 extern tree builtin_return_address_fndecl
;
46 extern struct obstack permanent_obstack
;
48 extern int current_class_depth
;
50 extern tree cleanups_this_call
;
52 /* Stack of places to restore the search obstack back to. */
54 /* Obstack used for remembering local class declarations (like
55 enums and static (const) members. */
57 static struct obstack decl_obstack
;
58 static struct stack_level
*decl_stack
;
60 #ifndef CHAR_TYPE_SIZE
61 #define CHAR_TYPE_SIZE BITS_PER_UNIT
64 #ifndef SHORT_TYPE_SIZE
65 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
69 #define INT_TYPE_SIZE BITS_PER_WORD
72 #ifndef LONG_TYPE_SIZE
73 #define LONG_TYPE_SIZE BITS_PER_WORD
76 #ifndef LONG_LONG_TYPE_SIZE
77 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
80 #ifndef WCHAR_UNSIGNED
81 #define WCHAR_UNSIGNED 0
84 #ifndef FLOAT_TYPE_SIZE
85 #define FLOAT_TYPE_SIZE BITS_PER_WORD
88 #ifndef DOUBLE_TYPE_SIZE
89 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
92 #ifndef LONG_DOUBLE_TYPE_SIZE
93 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
96 /* We let tm.h override the types used here, to handle trivial differences
97 such as the choice of unsigned int or long unsigned int for size_t.
98 When machines start needing nontrivial differences in the size type,
99 it would be best to do something here to figure out automatically
100 from other information what type to use. */
103 #define SIZE_TYPE "long unsigned int"
107 #define PTRDIFF_TYPE "long int"
111 #define WCHAR_TYPE "int"
114 #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
115 define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
116 #define auto_function(NAME, TYPE, CODE) \
118 tree __name = NAME; \
119 tree __type = TYPE; \
120 define_function (IDENTIFIER_POINTER (__name), __type, CODE, \
121 (void (*)())push_overloaded_decl_1, \
122 IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\
125 static tree grokparms
PROTO((tree
, int));
126 static tree lookup_nested_type
PROTO((tree
, tree
));
127 static char *redeclaration_error_message
PROTO((tree
, tree
));
128 static void grok_op_properties
PROTO((tree
, int, int));
131 PROTO((char *, tree
, enum built_in_function
, void (*)(), char *));
133 /* a node which has tree code ERROR_MARK, and whose type is itself.
134 All erroneous expressions are replaced with this node. All functions
135 that accept nodes as arguments should avoid generating error messages
136 if this node is one of the arguments, since it is undesirable to get
137 multiple error messages from one error in the input. */
139 tree error_mark_node
;
141 /* Erroneous argument lists can use this *IFF* they do not modify it. */
142 tree error_mark_list
;
144 /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
146 tree short_integer_type_node
;
147 tree integer_type_node
;
148 tree long_integer_type_node
;
149 tree long_long_integer_type_node
;
151 tree short_unsigned_type_node
;
152 tree unsigned_type_node
;
153 tree long_unsigned_type_node
;
154 tree long_long_unsigned_type_node
;
156 tree ptrdiff_type_node
;
158 tree unsigned_char_type_node
;
159 tree signed_char_type_node
;
161 tree wchar_type_node
;
162 tree signed_wchar_type_node
;
163 tree unsigned_wchar_type_node
;
165 tree float_type_node
;
166 tree double_type_node
;
167 tree long_double_type_node
;
169 tree intQI_type_node
;
170 tree intHI_type_node
;
171 tree intSI_type_node
;
172 tree intDI_type_node
;
174 tree unsigned_intQI_type_node
;
175 tree unsigned_intHI_type_node
;
176 tree unsigned_intSI_type_node
;
177 tree unsigned_intDI_type_node
;
179 /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */
181 tree void_type_node
, void_list_node
;
184 /* Nodes for types `void *' and `const void *'. */
186 tree ptr_type_node
, const_ptr_type_node
;
188 /* Nodes for types `char *' and `const char *'. */
190 tree string_type_node
, const_string_type_node
;
192 /* Type `char[256]' or something like it.
193 Used when an array of char is needed and the size is irrelevant. */
195 tree char_array_type_node
;
197 /* Type `int[256]' or something like it.
198 Used when an array of int needed and the size is irrelevant. */
200 tree int_array_type_node
;
202 /* Type `wchar_t[256]' or something like it.
203 Used when a wide string literal is created. */
205 tree wchar_array_type_node
;
207 /* The bool data type, and constants */
208 tree bool_type_node
, true_node
, false_node
;
210 /* type `int ()' -- used for implicit declaration of functions. */
212 tree default_function_type
;
214 /* function types `double (double)' and `double (double, double)', etc. */
216 tree double_ftype_double
, double_ftype_double_double
;
217 tree int_ftype_int
, long_ftype_long
;
219 /* Function type `void (void *, void *, int)' and similar ones. */
221 tree void_ftype_ptr_ptr_int
, int_ftype_ptr_ptr_int
, void_ftype_ptr_int_int
;
223 /* Function type `char *(char *, char *)' and similar ones */
224 tree string_ftype_ptr_ptr
, int_ftype_string_string
;
226 /* Function type `size_t (const char *)' */
227 tree sizet_ftype_string
;
229 /* Function type `int (const void *, const void *, size_t)' */
230 tree int_ftype_cptr_cptr_sizet
;
233 tree vtable_entry_type
;
234 tree delta_type_node
;
235 tree __t_desc_type_node
, __i_desc_type_node
, __m_desc_type_node
;
236 tree __t_desc_array_type
, __i_desc_array_type
, __m_desc_array_type
;
237 tree class_star_type_node
;
238 tree class_type_node
, record_type_node
, union_type_node
, enum_type_node
;
239 tree exception_type_node
, unknown_type_node
;
240 tree opaque_type_node
, signature_type_node
;
241 tree sigtable_entry_type
;
242 tree maybe_gc_cleanup
;
244 /* Array type `vtable_entry_type[]' */
247 /* In a destructor, the point at which all derived class destroying
248 has been done, just before any base class destroying will be done. */
252 /* In a constructor, the point at which we are ready to return
253 the pointer to the initialized object. */
257 /* A FUNCTION_DECL which can call `abort'. Not necessarily the
258 one that the user will declare, but sufficient to be called
259 by routines that want to abort the program. */
263 extern rtx cleanup_label
, return_label
;
265 /* If original DECL_RESULT of current function was a register,
266 but due to being an addressable named return value, would up
267 on the stack, this variable holds the named return value's
268 original location. */
269 rtx original_result_rtx
;
271 /* Sequence of insns which represents base initialization. */
274 /* C++: Keep these around to reduce calls to `get_identifier'.
275 Identifiers for `this' in member functions and the auto-delete
276 parameter for destructors. */
277 tree this_identifier
, in_charge_identifier
;
278 /* Used in pointer to member functions, and in vtables. */
279 tree pfn_identifier
, index_identifier
, delta_identifier
, delta2_identifier
;
280 tree pfn_or_delta2_identifier
;
282 /* A list (chain of TREE_LIST nodes) of named label uses.
283 The TREE_PURPOSE field is the list of variables defined
284 the the label's scope defined at the point of use.
285 The TREE_VALUE field is the LABEL_DECL used.
286 The TREE_TYPE field holds `current_binding_level' at the
287 point of the label's use.
289 Used only for jumps to as-yet undefined labels, since
290 jumps to defined labels can have their validity checked
293 static tree named_label_uses
;
295 /* A list of objects which have constructors or destructors
296 which reside in the global scope. The decl is stored in
297 the TREE_VALUE slot and the initializer is stored
298 in the TREE_PURPOSE slot. */
299 tree static_aggregates
;
303 /* Two expressions that are constants with value zero.
304 The first is of type `int', the second of type `void *'. */
306 tree integer_zero_node
;
307 tree null_pointer_node
;
309 /* A node for the integer constants 1, 2, and 3. */
311 tree integer_one_node
, integer_two_node
, integer_three_node
;
313 /* Nonzero if we have seen an invalid cross reference
314 to a struct, union, or enum, but not yet printed the message. */
316 tree pending_invalid_xref
;
317 /* File and line to appear in the eventual error message. */
318 char *pending_invalid_xref_file
;
319 int pending_invalid_xref_line
;
321 /* While defining an enum type, this is 1 plus the last enumerator
324 static tree enum_next_value
;
326 /* Nonzero means that there was overflow computing enum_next_value. */
328 static int enum_overflow
;
330 /* Parsing a function declarator leaves a list of parameter names
331 or a chain or parameter decls here. */
333 tree last_function_parms
;
335 /* Parsing a function declarator leaves here a chain of structure
336 and enum types declared in the parmlist. */
338 static tree last_function_parm_tags
;
340 /* After parsing the declarator that starts a function definition,
341 `start_function' puts here the list of parameter names or chain of decls.
342 `store_parm_decls' finds it here. */
344 static tree current_function_parms
;
346 /* Similar, for last_function_parm_tags. */
347 static tree current_function_parm_tags
;
349 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
350 that have names. Here so we can clear out their names' definitions
351 at the end of the function. */
353 static tree named_labels
;
355 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
357 static tree shadowed_labels
;
359 #if 0 /* Not needed by C++ */
360 /* Nonzero when store_parm_decls is called indicates a varargs function.
361 Value not meaningful after store_parm_decls. */
363 static int c_function_varargs
;
366 /* The FUNCTION_DECL for the function currently being compiled,
367 or 0 if between functions. */
368 tree current_function_decl
;
370 /* Set to 0 at beginning of a function definition, set to 1 if
371 a return statement that specifies a return value is seen. */
373 int current_function_returns_value
;
375 /* Set to 0 at beginning of a function definition, set to 1 if
376 a return statement with no argument is seen. */
378 int current_function_returns_null
;
380 /* Set to 0 at beginning of a function definition, and whenever
381 a label (case or named) is defined. Set to value of expression
382 returned from function when that value can be transformed into
383 a named return value. */
385 tree current_function_return_value
;
387 /* Set to nonzero by `grokdeclarator' for a function
388 whose return type is defaulted, if warnings for this are desired. */
390 static int warn_about_return_type
;
392 /* Nonzero when starting a function declared `extern inline'. */
394 static int current_extern_inline
;
396 /* Nonzero means give `double' the same size as `float'. */
398 extern int flag_short_double
;
400 /* Nonzero means don't recognize any builtin functions. */
402 extern int flag_no_builtin
;
404 /* Nonzero means disable GNU extensions. */
406 extern int flag_ansi
;
408 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
410 extern int flag_huge_objects
;
412 /* Nonzero if we want to conserve space in the .o files. We do this
413 by putting uninitialized data and runtime initialized data into
414 .common instead of .data at the expense of not flaging multiple
416 extern int flag_conserve_space
;
418 /* Pointers to the base and current top of the language name stack. */
420 extern tree
*current_lang_base
, *current_lang_stack
;
422 /* C and C++ flags are in decl2.c. */
424 /* Set to 0 at beginning of a constructor, set to 1
425 if that function does an allocation before referencing its
426 instance variable. */
427 int current_function_assigns_this
;
428 int current_function_just_assigned_this
;
430 /* Set to 0 at beginning of a function. Set non-zero when
431 store_parm_decls is called. Don't call store_parm_decls
432 if this flag is non-zero! */
433 int current_function_parms_stored
;
435 /* Current end of entries in the gc obstack for stack pointer variables. */
437 int current_function_obstack_index
;
439 /* Flag saying whether we have used the obstack in this function or not. */
441 int current_function_obstack_usage
;
443 /* Flag used when debugging spew.c */
445 extern int spew_debug
;
447 /* This is a copy of the class_shadowed list of the previous class binding
448 contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs
449 when entering another class scope (i.e. a cache miss). */
450 extern tree previous_class_values
;
453 /* Allocate a level of searching. */
455 push_decl_level (stack
, obstack
)
456 struct stack_level
*stack
;
457 struct obstack
*obstack
;
459 struct stack_level tem
;
462 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
465 /* For each binding contour we allocate a binding_level structure
466 * which records the names defined in that contour.
469 * 1) one for each function definition,
470 * where internal declarations of the parameters appear.
471 * 2) one for each compound statement,
472 * to record its declarations.
474 * The current meaning of a name can be found by searching the levels from
475 * the current one out to the global one.
477 * Off to the side, may be the class_binding_level. This exists
478 * only to catch class-local declarations. It is otherwise
481 * Also there may be binding levels that catch cleanups that
482 * must be run when exceptions occur.
485 /* Note that the information in the `names' component of the global contour
486 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
490 /* A chain of _DECL nodes for all variables, constants, functions,
491 * and typedef types. These are in the reverse of the order supplied.
495 /* A list of structure, union and enum definitions,
496 * for looking up tag names.
497 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
498 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
499 * or ENUMERAL_TYPE node.
501 * C++: the TREE_VALUE nodes can be simple types for component_bindings.
506 /* For each level, a list of shadowed outer-level local definitions
507 to be restored when this level is popped.
508 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
509 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
512 /* Same, for IDENTIFIER_CLASS_VALUE. */
515 /* Same, for IDENTIFIER_TYPE_VALUE. */
518 /* For each level (except not the global one),
519 a chain of BLOCK nodes for all the levels
520 that were entered and exited one level down. */
523 /* The BLOCK node for this level, if one has been preallocated.
524 If 0, the BLOCK is allocated (if needed) when the level is popped. */
527 /* The binding level which this one is contained in (inherits from). */
528 struct binding_level
*level_chain
;
530 /* Number of decls in `names' that have incomplete
531 structure or union types. */
532 unsigned short n_incomplete
;
534 /* 1 for the level that holds the parameters of a function.
535 2 for the level that holds a class declaration.
536 3 for levels that hold parameter declarations. */
537 unsigned parm_flag
: 4;
539 /* 1 means make a BLOCK for this level regardless of all else.
540 2 for temporary binding contours created by the compiler. */
543 /* Nonzero if this level "doesn't exist" for tags. */
544 unsigned tag_transparent
: 1;
546 /* Nonzero if this level can safely have additional
547 cleanup-needing variables added to it. */
548 unsigned more_cleanups_ok
: 1;
549 unsigned have_cleanups
: 1;
551 /* Nonzero if we should accept any name as an identifier in
552 this scope. This happens in some template definitions. */
553 unsigned accept_any
: 1;
555 /* Nonzero if this level is for completing a template class definition
556 inside a binding level that temporarily binds the parameters. This
557 means that definitions here should not be popped off when unwinding
558 this binding level. (Not actually implemented this way,
560 unsigned pseudo_global
: 1;
562 /* Two bits left for this word. */
564 #if defined(DEBUG_CP_BINDING_LEVELS)
565 /* Binding depth at which this level began. */
566 unsigned binding_depth
;
567 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
570 #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
572 /* The (non-class) binding level currently in effect. */
574 static struct binding_level
*current_binding_level
;
576 /* The binding level of the current class, if any. */
578 static struct binding_level
*class_binding_level
;
580 /* The current (class or non-class) binding level currently in effect. */
582 #define inner_binding_level \
583 (class_binding_level ? class_binding_level : current_binding_level)
585 /* A chain of binding_level structures awaiting reuse. */
587 static struct binding_level
*free_binding_level
;
589 /* The outermost binding level, for names of file scope.
590 This is created when the compiler is started and exists
591 through the entire run. */
593 static struct binding_level
*global_binding_level
;
595 /* Binding level structures are initialized by copying this one. */
597 static struct binding_level clear_binding_level
;
599 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
601 static int keep_next_level_flag
;
603 #if defined(DEBUG_CP_BINDING_LEVELS)
604 static int binding_depth
= 0;
605 static int is_class_level
= 0;
612 for (i
= 0; i
< binding_depth
*2; i
++)
615 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
617 static tree pushdecl_with_scope
PROTO((tree
, struct binding_level
*));
620 push_binding_level (newlevel
, tag_transparent
, keep
)
621 struct binding_level
*newlevel
;
622 int tag_transparent
, keep
;
624 /* Add this level to the front of the chain (stack) of levels that
626 *newlevel
= clear_binding_level
;
627 if (class_binding_level
)
629 newlevel
->level_chain
= class_binding_level
;
630 class_binding_level
= (struct binding_level
*)0;
634 newlevel
->level_chain
= current_binding_level
;
636 current_binding_level
= newlevel
;
637 newlevel
->tag_transparent
= tag_transparent
;
638 newlevel
->more_cleanups_ok
= 1;
639 newlevel
->keep
= keep
;
640 #if defined(DEBUG_CP_BINDING_LEVELS)
641 newlevel
->binding_depth
= binding_depth
;
643 fprintf (stderr
, "push %s level 0x%08x line %d\n",
644 (is_class_level
) ? "class" : "block", newlevel
, lineno
);
647 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
653 if (class_binding_level
)
654 current_binding_level
= class_binding_level
;
656 if (global_binding_level
)
658 /* cannot pop a level, if there are none left to pop. */
659 if (current_binding_level
== global_binding_level
)
660 my_friendly_abort (123);
662 /* Pop the current level, and free the structure for reuse. */
663 #if defined(DEBUG_CP_BINDING_LEVELS)
666 fprintf (stderr
, "pop %s level 0x%08x line %d\n",
667 (is_class_level
) ? "class" : "block",
668 current_binding_level
, lineno
);
669 if (is_class_level
!= (current_binding_level
== class_binding_level
))
670 #if 0 /* XXX Don't abort when we're watching how things are being managed. */
675 fprintf (stderr
, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
679 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
681 register struct binding_level
*level
= current_binding_level
;
682 current_binding_level
= current_binding_level
->level_chain
;
683 level
->level_chain
= free_binding_level
;
684 #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
685 if (level
->binding_depth
!= binding_depth
)
687 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
688 free_binding_level
= level
;
690 class_binding_level
= current_binding_level
;
691 if (class_binding_level
->parm_flag
!= 2)
692 class_binding_level
= 0;
693 while (current_binding_level
->parm_flag
== 2)
694 current_binding_level
= current_binding_level
->level_chain
;
698 /* Nonzero if we are currently in the global binding level. */
703 return current_binding_level
== global_binding_level
;
709 keep_next_level_flag
= 1;
712 /* Nonzero if the current level needs to have a BLOCK made. */
717 return (current_binding_level
->blocks
!= NULL_TREE
718 || current_binding_level
->keep
719 || current_binding_level
->names
!= NULL_TREE
720 || (current_binding_level
->tags
!= NULL_TREE
721 && !current_binding_level
->tag_transparent
));
724 /* Identify this binding level as a level of parameters. */
727 declare_parm_level ()
729 current_binding_level
->parm_flag
= 1;
733 declare_uninstantiated_type_level ()
735 current_binding_level
->accept_any
= 1;
739 uninstantiated_type_level_p ()
741 return current_binding_level
->accept_any
;
745 declare_pseudo_global_level ()
747 current_binding_level
->pseudo_global
= 1;
751 pseudo_global_level_p ()
753 return current_binding_level
->pseudo_global
;
757 set_class_shadows (shadows
)
760 class_binding_level
->class_shadowed
= shadows
;
763 /* Enter a new binding level.
764 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
765 not for that of tags. */
768 pushlevel (tag_transparent
)
771 register struct binding_level
*newlevel
= NULL_BINDING_LEVEL
;
773 /* If this is the top level of a function,
774 just make sure that NAMED_LABELS is 0.
775 They should have been set to 0 at the end of the previous function. */
777 if (current_binding_level
== global_binding_level
)
778 my_friendly_assert (named_labels
== NULL_TREE
, 134);
780 /* Reuse or create a struct for this binding level. */
782 #if defined(DEBUG_CP_BINDING_LEVELS)
784 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
785 if (free_binding_level
)
786 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
788 newlevel
= free_binding_level
;
789 free_binding_level
= free_binding_level
->level_chain
;
793 /* Create a new `struct binding_level'. */
794 newlevel
= (struct binding_level
*) xmalloc (sizeof (struct binding_level
));
796 push_binding_level (newlevel
, tag_transparent
, keep_next_level_flag
);
797 GNU_xref_start_scope ((HOST_WIDE_INT
) newlevel
);
798 keep_next_level_flag
= 0;
802 pushlevel_temporary (tag_transparent
)
805 pushlevel (tag_transparent
);
806 current_binding_level
->keep
= 2;
809 /* Note we don't call push_momentary() here. Otherwise, it would cause
810 cleanups to be allocated on the momentary obstack, and they will be
811 overwritten by the next statement. */
813 expand_start_bindings (0);
816 /* Exit a binding level.
817 Pop the level off, and restore the state of the identifier-decl mappings
818 that were in effect when this level was entered.
820 If KEEP == 1, this level had explicit declarations, so
821 and create a "block" (a BLOCK node) for the level
822 to record its declarations and subblocks for symbol table output.
824 If KEEP == 2, this level's subblocks go to the front,
825 not the back of the current binding level. This happens,
826 for instance, when code for constructors and destructors
827 need to generate code at the end of a function which must
828 be moved up to the front of the function.
830 If FUNCTIONBODY is nonzero, this level is the body of a function,
831 so create a block as if KEEP were set and also clear out all
834 If REVERSE is nonzero, reverse the order of decls before putting
835 them into the BLOCK. */
838 poplevel (keep
, reverse
, functionbody
)
844 /* The chain of decls was accumulated in reverse order.
845 Put it into forward order, just for cleanliness. */
847 int tmp
= functionbody
;
848 int implicit_try_block
= current_binding_level
->parm_flag
== 3;
849 int real_functionbody
= current_binding_level
->keep
== 2
850 ? ((functionbody
= 0), tmp
) : functionbody
;
851 tree tags
= functionbody
>= 0 ? current_binding_level
->tags
: 0;
852 tree subblocks
= functionbody
>= 0 ? current_binding_level
->blocks
: 0;
853 tree block
= NULL_TREE
;
855 int block_previously_created
;
857 GNU_xref_end_scope ((HOST_WIDE_INT
) current_binding_level
,
858 (HOST_WIDE_INT
) current_binding_level
->level_chain
,
859 current_binding_level
->parm_flag
,
860 current_binding_level
->keep
,
861 current_binding_level
->tag_transparent
);
863 if (current_binding_level
->keep
== 1)
866 /* This warning is turned off because it causes warnings for
867 declarations like `extern struct foo *x'. */
869 /* Warn about incomplete structure types in this level. */
870 for (link
= tags
; link
; link
= TREE_CHAIN (link
))
871 if (TYPE_SIZE (TREE_VALUE (link
)) == NULL_TREE
)
873 tree type
= TREE_VALUE (link
);
875 switch (TREE_CODE (type
))
878 errmsg
= "`struct %s' incomplete in scope ending here";
881 errmsg
= "`union %s' incomplete in scope ending here";
884 errmsg
= "`enum %s' incomplete in scope ending here";
887 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
888 error (errmsg
, IDENTIFIER_POINTER (TYPE_NAME (type
)));
890 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
891 error (errmsg
, TYPE_NAME_STRING (type
));
895 /* Get the decls in the order they were written.
896 Usually current_binding_level->names is in reverse order.
897 But parameter decls were previously put in forward order. */
900 current_binding_level
->names
901 = decls
= nreverse (current_binding_level
->names
);
903 decls
= current_binding_level
->names
;
905 /* Output any nested inline functions within this block
906 if they weren't already output. */
908 for (decl
= decls
; decl
; decl
= TREE_CHAIN (decl
))
909 if (TREE_CODE (decl
) == FUNCTION_DECL
910 && ! TREE_ASM_WRITTEN (decl
)
911 && DECL_INITIAL (decl
) != NULL_TREE
912 && TREE_ADDRESSABLE (decl
))
914 /* If this decl was copied from a file-scope decl
915 on account of a block-scope extern decl,
916 propagate TREE_ADDRESSABLE to the file-scope decl. */
917 if (DECL_ABSTRACT_ORIGIN (decl
) != NULL_TREE
)
918 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl
)) = 1;
921 push_function_context ();
922 output_inline_function (decl
);
923 pop_function_context ();
927 /* If there were any declarations or structure tags in that level,
928 or if this level is a function body,
929 create a BLOCK to record them for the life of this function. */
932 block_previously_created
= (current_binding_level
->this_block
!= NULL_TREE
);
933 if (block_previously_created
)
934 block
= current_binding_level
->this_block
;
935 else if (keep
== 1 || functionbody
)
936 block
= make_node (BLOCK
);
937 if (block
!= NULL_TREE
)
939 BLOCK_VARS (block
) = decls
;
940 BLOCK_TYPE_TAGS (block
) = tags
;
941 BLOCK_SUBBLOCKS (block
) = subblocks
;
942 /* If we created the block earlier on, and we are just diddling it now,
943 then it already should have a proper BLOCK_END_NOTE value associated
944 with it, so avoid trashing that. Otherwise, for a new block, install
945 a new BLOCK_END_NOTE value. */
946 if (! block_previously_created
)
947 remember_end_note (block
);
950 /* In each subblock, record that this is its superior. */
953 for (link
= subblocks
; link
; link
= TREE_CHAIN (link
))
954 BLOCK_SUPERCONTEXT (link
) = block
;
956 /* Clear out the meanings of the local variables of this level. */
958 for (link
= decls
; link
; link
= TREE_CHAIN (link
))
960 if (DECL_NAME (link
) != NULL_TREE
)
962 /* If the ident. was used or addressed via a local extern decl,
963 don't forget that fact. */
964 if (DECL_EXTERNAL (link
))
966 if (TREE_USED (link
))
967 TREE_USED (DECL_ASSEMBLER_NAME (link
)) = 1;
968 if (TREE_ADDRESSABLE (link
))
969 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link
)) = 1;
971 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link
)) = NULL_TREE
;
975 /* Restore all name-meanings of the outer levels
976 that were shadowed by this level. */
978 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
979 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
980 for (link
= current_binding_level
->class_shadowed
;
981 link
; link
= TREE_CHAIN (link
))
982 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
983 for (link
= current_binding_level
->type_shadowed
;
984 link
; link
= TREE_CHAIN (link
))
985 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
987 /* If the level being exited is the top level of a function,
988 check over all the labels. */
992 /* If this is the top level block of a function,
993 the vars are the function's parameters.
994 Don't leave them in the BLOCK because they are
995 found in the FUNCTION_DECL instead. */
997 BLOCK_VARS (block
) = 0;
999 /* Clear out the definitions of all label names,
1000 since their scopes end here. */
1002 for (link
= named_labels
; link
; link
= TREE_CHAIN (link
))
1004 register tree label
= TREE_VALUE (link
);
1006 if (DECL_INITIAL (label
) == NULL_TREE
)
1008 cp_error_at ("label `%D' used but not defined", label
);
1009 /* Avoid crashing later. */
1010 define_label (input_filename
, 1, DECL_NAME (label
));
1012 else if (warn_unused
&& !TREE_USED (label
))
1013 cp_warning_at ("label `%D' defined but not used", label
);
1014 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label
), NULL_TREE
);
1016 /* Put the labels into the "variables" of the
1017 top-level block, so debugger can see them. */
1018 TREE_CHAIN (label
) = BLOCK_VARS (block
);
1019 BLOCK_VARS (block
) = label
;
1022 named_labels
= NULL_TREE
;
1025 /* Any uses of undefined labels now operate under constraints
1026 of next binding contour. */
1028 struct binding_level
*level_chain
;
1029 level_chain
= current_binding_level
->level_chain
;
1033 for (labels
= named_label_uses
; labels
; labels
= TREE_CHAIN (labels
))
1034 if (TREE_TYPE (labels
) == (tree
)current_binding_level
)
1036 TREE_TYPE (labels
) = (tree
)level_chain
;
1037 TREE_PURPOSE (labels
) = level_chain
->names
;
1042 tmp
= current_binding_level
->keep
;
1044 pop_binding_level ();
1046 DECL_INITIAL (current_function_decl
) = block
;
1049 if (!block_previously_created
)
1050 current_binding_level
->blocks
1051 = chainon (current_binding_level
->blocks
, block
);
1053 /* If we did not make a block for the level just exited,
1054 any blocks made for inner levels
1055 (since they cannot be recorded as subblocks in that level)
1056 must be carried forward so they will later become subblocks
1057 of something else. */
1061 current_binding_level
->blocks
1062 = chainon (subblocks
, current_binding_level
->blocks
);
1064 current_binding_level
->blocks
1065 = chainon (current_binding_level
->blocks
, subblocks
);
1068 /* Take care of compiler's internal binding structures. */
1072 /* We did not call push_momentary for this
1073 binding contour, so there is nothing to pop. */
1076 expand_end_bindings (getdecls (), keep
, 1);
1077 /* Each and every BLOCK node created here in `poplevel' is important
1078 (e.g. for proper debugging information) so if we created one
1079 earlier, mark it as "used". */
1081 TREE_USED (block
) = 1;
1082 block
= poplevel (keep
, reverse
, real_functionbody
);
1085 /* Each and every BLOCK node created here in `poplevel' is important
1086 (e.g. for proper debugging information) so if we created one
1087 earlier, mark it as "used". */
1089 TREE_USED (block
) = 1;
1093 /* Delete the node BLOCK from the current binding level.
1094 This is used for the block inside a stmt expr ({...})
1095 so that the block can be reinserted where appropriate. */
1098 delete_block (block
)
1102 if (current_binding_level
->blocks
== block
)
1103 current_binding_level
->blocks
= TREE_CHAIN (block
);
1104 for (t
= current_binding_level
->blocks
; t
;)
1106 if (TREE_CHAIN (t
) == block
)
1107 TREE_CHAIN (t
) = TREE_CHAIN (block
);
1111 TREE_CHAIN (block
) = NULL_TREE
;
1112 /* Clear TREE_USED which is always set by poplevel.
1113 The flag is set again if insert_block is called. */
1114 TREE_USED (block
) = 0;
1117 /* Insert BLOCK at the end of the list of subblocks of the
1118 current binding level. This is used when a BIND_EXPR is expanded,
1119 to handle the BLOCK node inside the BIND_EXPR. */
1122 insert_block (block
)
1125 TREE_USED (block
) = 1;
1126 current_binding_level
->blocks
1127 = chainon (current_binding_level
->blocks
, block
);
1130 /* Add BLOCK to the current list of blocks for this binding contour. */
1132 add_block_current_level (block
)
1135 current_binding_level
->blocks
1136 = chainon (current_binding_level
->blocks
, block
);
1139 /* Set the BLOCK node for the innermost scope
1140 (the one we are currently in). */
1144 register tree block
;
1146 current_binding_level
->this_block
= block
;
1149 /* Do a pushlevel for class declarations. */
1153 register struct binding_level
*newlevel
;
1155 /* Reuse or create a struct for this binding level. */
1156 #if defined(DEBUG_CP_BINDING_LEVELS)
1158 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
1159 if (free_binding_level
)
1160 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
1162 newlevel
= free_binding_level
;
1163 free_binding_level
= free_binding_level
->level_chain
;
1167 /* Create a new `struct binding_level'. */
1168 newlevel
= (struct binding_level
*) xmalloc (sizeof (struct binding_level
));
1171 #if defined(DEBUG_CP_BINDING_LEVELS)
1173 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1175 push_binding_level (newlevel
, 0, 0);
1177 decl_stack
= push_decl_level (decl_stack
, &decl_obstack
);
1178 class_binding_level
= current_binding_level
;
1179 class_binding_level
->parm_flag
= 2;
1180 /* We have just pushed into a new binding level. Now, fake out the rest
1181 of the compiler. Set the `current_binding_level' back to point to
1182 the most closely containing non-class binding level. */
1185 current_binding_level
= current_binding_level
->level_chain
;
1187 while (current_binding_level
->parm_flag
== 2);
1190 /* ...and a poplevel for class declarations. FORCE is used to force
1191 clearing out of CLASS_VALUEs after a class definition. */
1193 poplevel_class (force
)
1196 register struct binding_level
*level
= class_binding_level
;
1197 tree block
= NULL_TREE
;
1200 my_friendly_assert (level
!= 0, 354);
1202 decl_stack
= pop_stack_level (decl_stack
);
1203 for (shadowed
= level
->shadowed
; shadowed
; shadowed
= TREE_CHAIN (shadowed
))
1204 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed
)) = TREE_VALUE (shadowed
);
1205 /* If we're leaving a toplevel class, don't bother to do the setting
1206 of IDENTIFER_CLASS_VALUE to NULL_TREE, since first of all this slot
1207 shouldn't even be used when current_class_type isn't set, and second,
1208 if we don't touch it here, we're able to use the caching effect if the
1209 next time we're entering a class scope, it is the same class. */
1210 if (current_class_depth
!= 1 || force
)
1211 for (shadowed
= level
->class_shadowed
;
1213 shadowed
= TREE_CHAIN (shadowed
))
1214 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed
)) = TREE_VALUE (shadowed
);
1216 /* Remember to save what IDENTIFIER's were bound in this scope so we
1217 can recover from cache misses. */
1218 previous_class_values
= class_binding_level
->class_shadowed
;
1219 for (shadowed
= level
->type_shadowed
;
1221 shadowed
= TREE_CHAIN (shadowed
))
1222 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed
)) = TREE_VALUE (shadowed
);
1224 GNU_xref_end_scope ((HOST_WIDE_INT
) class_binding_level
,
1225 (HOST_WIDE_INT
) class_binding_level
->level_chain
,
1226 class_binding_level
->parm_flag
,
1227 class_binding_level
->keep
,
1228 class_binding_level
->tag_transparent
);
1230 if (class_binding_level
->parm_flag
!= 2)
1231 class_binding_level
= (struct binding_level
*)0;
1233 /* Now, pop out of the the binding level which we created up in the
1234 `pushlevel_class' routine. */
1235 #if defined(DEBUG_CP_BINDING_LEVELS)
1237 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1239 pop_binding_level ();
1244 /* For debugging. */
1245 int no_print_functions
= 0;
1246 int no_print_builtins
= 0;
1249 print_binding_level (lvl
)
1250 struct binding_level
*lvl
;
1254 fprintf (stderr
, " blocks=");
1255 fprintf (stderr
, HOST_PTR_PRINTF
, lvl
->blocks
);
1256 fprintf (stderr
, " n_incomplete=%d parm_flag=%d keep=%d",
1257 lvl
->n_incomplete
, lvl
->parm_flag
, lvl
->keep
);
1258 if (lvl
->tag_transparent
)
1259 fprintf (stderr
, " tag-transparent");
1260 if (lvl
->more_cleanups_ok
)
1261 fprintf (stderr
, " more-cleanups-ok");
1262 if (lvl
->have_cleanups
)
1263 fprintf (stderr
, " have-cleanups");
1264 fprintf (stderr
, "\n");
1267 fprintf (stderr
, " names:\t");
1268 /* We can probably fit 3 names to a line? */
1269 for (t
= lvl
->names
; t
; t
= TREE_CHAIN (t
))
1271 if (no_print_functions
&& (TREE_CODE(t
) == FUNCTION_DECL
))
1273 if (no_print_builtins
1274 && (TREE_CODE(t
) == TYPE_DECL
)
1275 && (!strcmp(DECL_SOURCE_FILE(t
),"<built-in>")))
1278 /* Function decls tend to have longer names. */
1279 if (TREE_CODE (t
) == FUNCTION_DECL
)
1286 fprintf (stderr
, "\n\t");
1289 print_node_brief (stderr
, "", t
, 0);
1290 if (TREE_CODE (t
) == ERROR_MARK
)
1294 fprintf (stderr
, "\n");
1298 fprintf (stderr
, " tags:\t");
1300 for (t
= lvl
->tags
; t
; t
= TREE_CHAIN (t
))
1302 if (TREE_PURPOSE (t
) == NULL_TREE
)
1304 else if (TREE_PURPOSE (t
) == TYPE_IDENTIFIER (TREE_VALUE (t
)))
1311 fprintf (stderr
, "\n\t");
1314 if (TREE_PURPOSE (t
) == NULL_TREE
)
1316 print_node_brief (stderr
, "<unnamed-typedef", TREE_VALUE (t
), 0);
1317 fprintf (stderr
, ">");
1319 else if (TREE_PURPOSE (t
) == TYPE_IDENTIFIER (TREE_VALUE (t
)))
1320 print_node_brief (stderr
, "", TREE_VALUE (t
), 0);
1323 print_node_brief (stderr
, "<typedef", TREE_PURPOSE (t
), 0);
1324 print_node_brief (stderr
, "", TREE_VALUE (t
), 0);
1325 fprintf (stderr
, ">");
1329 fprintf (stderr
, "\n");
1333 fprintf (stderr
, " shadowed:");
1334 for (t
= lvl
->shadowed
; t
; t
= TREE_CHAIN (t
))
1336 fprintf (stderr
, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
1338 fprintf (stderr
, "\n");
1340 if (lvl
->class_shadowed
)
1342 fprintf (stderr
, " class-shadowed:");
1343 for (t
= lvl
->class_shadowed
; t
; t
= TREE_CHAIN (t
))
1345 fprintf (stderr
, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
1347 fprintf (stderr
, "\n");
1349 if (lvl
->type_shadowed
)
1351 fprintf (stderr
, " type-shadowed:");
1352 for (t
= lvl
->type_shadowed
; t
; t
= TREE_CHAIN (t
))
1355 fprintf (stderr
, "\n\t");
1356 print_node_brief (stderr
, "<", TREE_PURPOSE (t
), 0);
1358 print_node_brief (stderr
, " ", TREE_VALUE (t
), 0);
1360 fprintf (stderr
, " (none)");
1361 fprintf (stderr
, ">");
1363 fprintf (stderr
, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t
)));
1366 fprintf (stderr
, "\n");
1371 print_other_binding_stack (stack
)
1372 struct binding_level
*stack
;
1374 struct binding_level
*level
;
1375 for (level
= stack
; level
!= global_binding_level
; level
= level
->level_chain
)
1377 fprintf (stderr
, "binding level ");
1378 fprintf (stderr
, HOST_PTR_PRINTF
, level
);
1379 fprintf (stderr
, "\n");
1380 print_binding_level (level
);
1385 print_binding_stack ()
1387 struct binding_level
*b
;
1388 fprintf (stderr
, "current_binding_level=");
1389 fprintf (stderr
, HOST_PTR_PRINTF
, current_binding_level
);
1390 fprintf (stderr
, "\nclass_binding_level=");
1391 fprintf (stderr
, HOST_PTR_PRINTF
, class_binding_level
);
1392 fprintf (stderr
, "\nglobal_binding_level=");
1393 fprintf (stderr
, HOST_PTR_PRINTF
, global_binding_level
);
1394 fprintf (stderr
, "\n");
1395 if (class_binding_level
)
1397 for (b
= class_binding_level
; b
; b
= b
->level_chain
)
1398 if (b
== current_binding_level
)
1401 b
= class_binding_level
;
1403 b
= current_binding_level
;
1406 b
= current_binding_level
;
1407 print_other_binding_stack (b
);
1408 fprintf (stderr
, "global:\n");
1409 print_binding_level (global_binding_level
);
1412 /* Subroutines for reverting temporarily to top-level for instantiation
1413 of templates and such. We actually need to clear out the class- and
1414 local-value slots of all identifiers, so that only the global values
1415 are at all visible. Simply setting current_binding_level to the global
1416 scope isn't enough, because more binding levels may be pushed. */
1417 struct saved_scope
{
1418 struct binding_level
*old_binding_level
;
1420 struct saved_scope
*prev
;
1421 tree class_name
, class_type
, class_decl
, function_decl
;
1422 struct binding_level
*class_bindings
;
1423 tree previous_class_type
;
1424 tree
*lang_base
, *lang_stack
, lang_name
;
1428 static struct saved_scope
*current_saved_scope
;
1429 extern tree prev_class_type
;
1432 push_to_top_level ()
1434 extern int current_lang_stacksize
;
1435 struct saved_scope
*s
=
1436 (struct saved_scope
*) xmalloc (sizeof (struct saved_scope
));
1437 struct binding_level
*b
= current_binding_level
;
1438 tree old_bindings
= NULL_TREE
;
1440 /* Have to include global_binding_level, because class-level decls
1441 aren't listed anywhere useful. */
1442 for (; b
; b
= b
->level_chain
)
1446 if (b
== global_binding_level
)
1449 for (t
= b
->names
; t
; t
= TREE_CHAIN (t
))
1451 tree binding
, t1
, t2
= t
;
1452 tree id
= DECL_ASSEMBLER_NAME (t2
);
1455 || (!IDENTIFIER_LOCAL_VALUE (id
)
1456 && !IDENTIFIER_CLASS_VALUE (id
)))
1459 for (t1
= old_bindings
; t1
; t1
= TREE_CHAIN (t1
))
1460 if (TREE_VEC_ELT (t1
, 0) == id
)
1463 binding
= make_tree_vec (4);
1466 my_friendly_assert (TREE_CODE (id
) == IDENTIFIER_NODE
, 135);
1467 TREE_VEC_ELT (binding
, 0) = id
;
1468 TREE_VEC_ELT (binding
, 1) = IDENTIFIER_TYPE_VALUE (id
);
1469 TREE_VEC_ELT (binding
, 2) = IDENTIFIER_LOCAL_VALUE (id
);
1470 TREE_VEC_ELT (binding
, 3) = IDENTIFIER_CLASS_VALUE (id
);
1471 IDENTIFIER_LOCAL_VALUE (id
) = NULL_TREE
;
1472 IDENTIFIER_CLASS_VALUE (id
) = NULL_TREE
;
1474 TREE_CHAIN (binding
) = old_bindings
;
1475 old_bindings
= binding
;
1479 /* Unwind type-value slots back to top level. */
1480 for (t
= b
->type_shadowed
; t
; t
= TREE_CHAIN (t
))
1481 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t
), TREE_VALUE (t
));
1483 /* Clear out class-level bindings cache. */
1484 if (current_binding_level
== global_binding_level
1485 && previous_class_type
!= NULL_TREE
)
1488 previous_class_type
= NULL_TREE
;
1491 s
->old_binding_level
= current_binding_level
;
1492 current_binding_level
= global_binding_level
;
1494 s
->class_name
= current_class_name
;
1495 s
->class_type
= current_class_type
;
1496 s
->class_decl
= current_class_decl
;
1497 s
->function_decl
= current_function_decl
;
1498 s
->class_bindings
= class_binding_level
;
1499 s
->previous_class_type
= previous_class_type
;
1500 s
->lang_stack
= current_lang_stack
;
1501 s
->lang_base
= current_lang_base
;
1502 s
->lang_stacksize
= current_lang_stacksize
;
1503 s
->lang_name
= current_lang_name
;
1504 s
->named_labels
= named_labels
;
1505 current_class_name
= current_class_type
= current_class_decl
= NULL_TREE
;
1506 current_function_decl
= NULL_TREE
;
1507 class_binding_level
= (struct binding_level
*)0;
1508 previous_class_type
= NULL_TREE
;
1509 current_lang_stacksize
= 10;
1510 current_lang_stack
= current_lang_base
1511 = (tree
*) xmalloc (current_lang_stacksize
* sizeof (tree
));
1512 current_lang_name
= lang_name_cplusplus
;
1513 strict_prototype
= strict_prototypes_lang_cplusplus
;
1514 named_labels
= NULL_TREE
;
1516 s
->prev
= current_saved_scope
;
1517 s
->old_bindings
= old_bindings
;
1518 current_saved_scope
= s
;
1522 pop_from_top_level ()
1524 extern int current_lang_stacksize
;
1525 struct saved_scope
*s
= current_saved_scope
;
1528 if (previous_class_type
)
1529 previous_class_type
= NULL_TREE
;
1531 current_binding_level
= s
->old_binding_level
;
1532 current_saved_scope
= s
->prev
;
1533 for (t
= s
->old_bindings
; t
; t
= TREE_CHAIN (t
))
1535 tree id
= TREE_VEC_ELT (t
, 0);
1538 IDENTIFIER_TYPE_VALUE (id
) = TREE_VEC_ELT (t
, 1);
1539 IDENTIFIER_LOCAL_VALUE (id
) = TREE_VEC_ELT (t
, 2);
1540 IDENTIFIER_CLASS_VALUE (id
) = TREE_VEC_ELT (t
, 3);
1543 current_class_name
= s
->class_name
;
1544 current_class_type
= s
->class_type
;
1545 current_class_decl
= s
->class_decl
;
1546 if (current_class_type
)
1547 C_C_D
= CLASSTYPE_INST_VAR (current_class_type
);
1550 current_function_decl
= s
->function_decl
;
1551 class_binding_level
= s
->class_bindings
;
1552 previous_class_type
= s
->previous_class_type
;
1553 free (current_lang_base
);
1554 current_lang_base
= s
->lang_base
;
1555 current_lang_stack
= s
->lang_stack
;
1556 current_lang_name
= s
->lang_name
;
1557 current_lang_stacksize
= s
->lang_stacksize
;
1558 if (current_lang_name
== lang_name_cplusplus
)
1559 strict_prototype
= strict_prototypes_lang_cplusplus
;
1560 else if (current_lang_name
== lang_name_c
)
1561 strict_prototype
= strict_prototypes_lang_c
;
1562 named_labels
= s
->named_labels
;
1567 /* Push a definition of struct, union or enum tag "name".
1568 into binding_level "b". "type" should be the type node,
1569 We assume that the tag "name" is not already defined.
1571 Note that the definition may really be just a forward reference.
1572 In that case, the TYPE_SIZE will be a NULL_TREE.
1574 C++ gratuitously puts all these tags in the name space. */
1576 /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
1577 record the shadowed value for this binding contour. TYPE is
1578 the type that ID maps to. */
1581 set_identifier_type_value_with_scope (id
, type
, b
)
1584 struct binding_level
*b
;
1586 if (b
!= global_binding_level
)
1588 tree old_type_value
= IDENTIFIER_TYPE_VALUE (id
);
1590 = tree_cons (id
, old_type_value
, b
->type_shadowed
);
1592 SET_IDENTIFIER_TYPE_VALUE (id
, type
);
1595 /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
1598 set_identifier_type_value (id
, type
)
1602 set_identifier_type_value_with_scope (id
, type
, inner_binding_level
);
1605 /* Subroutine "set_nested_typename" builds the nested-typename of
1606 the type decl in question. (Argument CLASSNAME can actually be
1607 a function as well, if that's the smallest containing scope.) */
1610 set_nested_typename (decl
, classname
, name
, type
)
1611 tree decl
, classname
, name
, type
;
1613 my_friendly_assert (TREE_CODE (decl
) == TYPE_DECL
, 136);
1614 if (classname
!= NULL_TREE
)
1617 my_friendly_assert (TREE_CODE (classname
) == IDENTIFIER_NODE
, 137);
1618 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 138);
1619 buf
= (char *) alloca (4 + IDENTIFIER_LENGTH (classname
)
1620 + IDENTIFIER_LENGTH (name
));
1621 sprintf (buf
, "%s::%s", IDENTIFIER_POINTER (classname
),
1622 IDENTIFIER_POINTER (name
));
1623 DECL_NESTED_TYPENAME (decl
) = get_identifier (buf
);
1624 TREE_MANGLED (DECL_NESTED_TYPENAME (decl
)) = 1;
1626 /* This is a special usage of IDENTIFIER_TYPE_VALUE which have no
1627 correspondence in any binding_level. This is ok since the
1628 DECL_NESTED_TYPENAME is just a convenience identifier whose
1629 IDENTIFIER_TYPE_VALUE will remain constant from now on. */
1630 SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl
), type
);
1633 DECL_NESTED_TYPENAME (decl
) = name
;
1636 /* Pop off extraneous binding levels left over due to syntax errors. */
1640 #ifdef DEBUG_CP_BINDING_LEVELS
1641 fprintf (stderr
, "XXX entering pop_everything ()\n");
1643 while (current_binding_level
!= global_binding_level
1644 && ! current_binding_level
->pseudo_global
)
1646 if (class_binding_level
)
1647 pop_nested_class (1);
1651 #ifdef DEBUG_CP_BINDING_LEVELS
1652 fprintf (stderr
, "XXX leaving pop_everything ()\n");
1656 #if 0 /* not yet, should get fixed properly later */
1657 /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
1658 Other routines shouldn't use build_decl directly; they'll produce
1659 incorrect results with `-g' unless they duplicate this code.
1661 This is currently needed mainly for dbxout.c, but we can make
1662 use of it in method.c later as well. */
1664 make_type_decl (name
, type
)
1668 decl
= build_decl (TYPE_DECL
, name
, type
);
1669 if (TYPE_NAME (type
) == name
)
1670 /* Class/union/enum definition, or a redundant typedef for same. */
1672 id
= get_identifier (build_overload_name (type
, 1, 1));
1673 DECL_ASSEMBLER_NAME (decl
) = id
;
1675 else if (TYPE_NAME (type
) != NULL_TREE
)
1676 /* Explicit typedef, or implicit typedef for template expansion. */
1677 DECL_ASSEMBLER_NAME (decl
) = DECL_ASSEMBLER_NAME (TYPE_NAME (type
));
1680 /* XXX: Typedef for unnamed struct; some other situations.
1681 TYPE_NAME is null; what's right here? */
1687 /* Push a tag name NAME for struct/class/union/enum type TYPE.
1688 Normally put into into the inner-most non-tag-tranparent scope,
1689 but if GLOBALIZE is true, put it in the inner-most non-class scope.
1690 The latter is needed for implicit declarations. */
1693 pushtag (name
, type
, globalize
)
1697 register struct binding_level
*b
;
1701 b
= inner_binding_level
;
1702 while (b
->tag_transparent
1703 || (globalize
&& b
->parm_flag
== 2))
1706 if (b
== global_binding_level
)
1707 b
->tags
= perm_tree_cons (name
, type
, b
->tags
);
1709 b
->tags
= saveable_tree_cons (name
, type
, b
->tags
);
1713 context
= type
? TYPE_CONTEXT (type
) : NULL_TREE
;
1714 if (! context
&& ! globalize
)
1715 context
= current_scope ();
1717 c_decl
= TREE_CODE (context
) == FUNCTION_DECL
1718 ? context
: TYPE_NAME (context
);
1720 /* Record the identifier as the type's name if it has none. */
1721 if (TYPE_NAME (type
) == NULL_TREE
)
1722 TYPE_NAME (type
) = name
;
1724 /* Do C++ gratuitous typedefing. */
1725 if (IDENTIFIER_TYPE_VALUE (name
) != type
1726 && (TREE_CODE (type
) != RECORD_TYPE
1727 || b
->parm_flag
!= 2
1728 || !CLASSTYPE_DECLARED_EXCEPTION (type
)))
1733 if (b
->parm_flag
!= 2
1734 || TYPE_SIZE (current_class_type
) != NULL_TREE
)
1736 d
= lookup_nested_type (type
, c_decl
);
1741 #if 0 /* not yet, should get fixed properly later */
1742 d
= make_type_decl (name
, type
);
1744 d
= build_decl (TYPE_DECL
, name
, type
);
1746 #ifdef DWARF_DEBUGGING_INFO
1747 if (write_symbols
== DWARF_DEBUG
)
1749 /* Mark the TYPE_DECL node we created just above as an
1750 gratuitous one. We need to do this so that dwarfout.c
1751 will understand that it is not supposed to output a
1752 TAG_typedef DIE for it. */
1753 DECL_IGNORED_P (d
) = 1;
1755 #endif /* DWARF_DEBUGGING_INFO */
1756 set_identifier_type_value_with_scope (name
, type
, b
);
1761 /* If it is anonymous, then we are called from pushdecl,
1762 and we don't want to infinitely recurse. Also, if the
1763 name is already in scope, we don't want to push it
1764 again--pushdecl is only for pushing new decls. */
1765 if (! ANON_AGGRNAME_P (name
)
1767 && (TREE_CODE (TYPE_NAME (type
)) != TYPE_DECL
1768 || lookup_name (name
, 1) != TYPE_NAME (type
)))
1770 if (b
->parm_flag
== 2)
1771 d
= pushdecl_class_level (d
);
1773 d
= pushdecl_with_scope (d
, b
);
1778 /* Make nested declarations go into class-level scope. */
1780 d
= build_decl (TYPE_DECL
, name
, type
);
1781 #ifdef DWARF_DEBUGGING_INFO
1782 if (write_symbols
== DWARF_DEBUG
)
1784 /* Mark the TYPE_DECL node we created just above as an
1785 gratuitous one. We need to do this so that dwarfout.c
1786 will understand that it is not supposed to output a
1787 TAG_typedef DIE for it. */
1788 DECL_IGNORED_P (d
) = 1;
1790 #endif /* DWARF_DEBUGGING_INFO */
1791 /* Make sure we're in this type's scope when we push the
1792 decl for a template, otherwise class_binding_level will
1793 be NULL and we'll end up dying inside of
1794 push_class_level_binding. */
1795 if (TREE_CODE (type
) == UNINSTANTIATED_P_TYPE
)
1796 pushclass (type
, 0);
1797 d
= pushdecl_class_level (d
);
1798 if (TREE_CODE (type
) == UNINSTANTIATED_P_TYPE
)
1801 if (write_symbols
!= DWARF_DEBUG
)
1803 if (ANON_AGGRNAME_P (name
))
1804 DECL_IGNORED_P (d
) = 1;
1806 TYPE_NAME (type
) = d
;
1808 if (context
== NULL_TREE
)
1809 /* Non-nested class. */
1810 DECL_NESTED_TYPENAME (d
) = name
;
1811 else if (context
&& TREE_CODE (context
) == FUNCTION_DECL
)
1813 /* Function-nested class. */
1814 set_nested_typename (d
, DECL_ASSEMBLER_NAME (c_decl
),
1816 /* This builds the links for classes nested in fn scope. */
1817 DECL_CONTEXT (d
) = context
;
1819 /* else if (TYPE_SIZE (current_class_type) == NULL_TREE)
1821 else if (context
&& IS_AGGR_TYPE (context
))
1823 /* Class-nested class. */
1824 set_nested_typename (d
, DECL_NESTED_TYPENAME (c_decl
),
1826 /* This builds the links for classes nested in type scope. */
1827 DECL_CONTEXT (d
) = context
;
1829 TYPE_CONTEXT (type
) = DECL_CONTEXT (d
);
1831 DECL_ASSEMBLER_NAME (d
)
1832 = get_identifier (build_overload_name (type
, 1, 1));
1834 if (b
->parm_flag
== 2)
1836 TREE_NONLOCAL_FLAG (type
) = 1;
1837 if (TYPE_SIZE (current_class_type
) == NULL_TREE
)
1838 CLASSTYPE_TAGS (current_class_type
) = b
->tags
;
1842 if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
)
1843 /* Use the canonical TYPE_DECL for this node. */
1844 TYPE_STUB_DECL (type
) = TYPE_NAME (type
);
1847 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
1848 will be the tagged type we just added to the current
1849 binding level. This fake NULL-named TYPE_DECL node helps
1850 dwarfout.c to know when it needs to output a
1851 representation of a tagged type, and it also gives us a
1852 convenient place to record the "scope start" address for
1855 #if 0 /* not yet, should get fixed properly later */
1856 tree d
= make_type_decl (NULL_TREE
, type
);
1858 tree d
= build_decl (TYPE_DECL
, NULL_TREE
, type
);
1860 TYPE_STUB_DECL (type
) = pushdecl_with_scope (d
, b
);
1864 /* Counter used to create anonymous type names. */
1865 static int anon_cnt
= 0;
1867 /* Return an IDENTIFIER which can be used as a name for
1868 anonymous structs and unions. */
1874 sprintf (buf
, ANON_AGGRNAME_FORMAT
, anon_cnt
++);
1875 return get_identifier (buf
);
1878 /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
1879 This keeps dbxout from getting confused. */
1883 register struct binding_level
*b
;
1885 static int last_cnt
= 0;
1887 /* Fast out if no new anon names were declared. */
1888 if (last_cnt
== anon_cnt
)
1891 b
= current_binding_level
;
1892 while (b
->tag_transparent
)
1897 /* A NULL purpose means we have already processed all tags
1898 from here to the end of the list. */
1899 if (TREE_PURPOSE (tags
) == NULL_TREE
)
1901 if (ANON_AGGRNAME_P (TREE_PURPOSE (tags
)))
1902 TREE_PURPOSE (tags
) = NULL_TREE
;
1903 tags
= TREE_CHAIN (tags
);
1905 last_cnt
= anon_cnt
;
1908 /* Subroutine of duplicate_decls: return truthvalue of whether
1909 or not types of these decls match.
1911 For C++, we must compare the parameter list so that `int' can match
1912 `int&' in a parameter position, but `int&' is not confused with
1915 decls_match (newdecl
, olddecl
)
1916 tree newdecl
, olddecl
;
1920 if (TREE_CODE (newdecl
) == FUNCTION_DECL
1921 && TREE_CODE (olddecl
) == FUNCTION_DECL
)
1923 tree f1
= TREE_TYPE (newdecl
);
1924 tree f2
= TREE_TYPE (olddecl
);
1925 tree p1
= TYPE_ARG_TYPES (f1
);
1926 tree p2
= TYPE_ARG_TYPES (f2
);
1928 /* When we parse a static member function definition,
1929 we put together a FUNCTION_DECL which thinks its type
1930 is METHOD_TYPE. Change that to FUNCTION_TYPE, and
1932 if (TREE_CODE (f1
) == METHOD_TYPE
&& DECL_STATIC_FUNCTION_P (olddecl
))
1933 revert_static_member_fn (&newdecl
, &f1
, &p1
);
1934 else if (TREE_CODE (f2
) == METHOD_TYPE
1935 && DECL_STATIC_FUNCTION_P (newdecl
))
1936 revert_static_member_fn (&olddecl
, &f2
, &p2
);
1938 /* Here we must take care of the case where new default
1939 parameters are specified. Also, warn if an old
1940 declaration becomes ambiguous because default
1941 parameters may cause the two to be ambiguous. */
1942 if (TREE_CODE (f1
) != TREE_CODE (f2
))
1944 if (TREE_CODE (f1
) == OFFSET_TYPE
)
1945 cp_compiler_error ("`%D' redeclared as member function", newdecl
);
1947 cp_compiler_error ("`%D' redeclared as non-member function", newdecl
);
1951 if (comptypes (TREE_TYPE (f1
), TREE_TYPE (f2
), 1))
1953 if (! strict_prototypes_lang_c
&& DECL_LANGUAGE (olddecl
) == lang_c
1956 types_match
= self_promoting_args_p (p1
);
1957 if (p1
== void_list_node
)
1958 TREE_TYPE (newdecl
) = TREE_TYPE (olddecl
);
1960 else if (!strict_prototypes_lang_c
&& DECL_LANGUAGE (olddecl
)==lang_c
1961 && DECL_LANGUAGE (newdecl
) == lang_c
&& p1
== NULL_TREE
)
1963 types_match
= self_promoting_args_p (p2
);
1964 TREE_TYPE (newdecl
) = TREE_TYPE (olddecl
);
1967 types_match
= compparms (p1
, p2
, 3);
1972 else if (TREE_CODE (newdecl
) == TEMPLATE_DECL
1973 && TREE_CODE (olddecl
) == TEMPLATE_DECL
)
1975 tree newargs
= DECL_TEMPLATE_PARMS (newdecl
);
1976 tree oldargs
= DECL_TEMPLATE_PARMS (olddecl
);
1977 int i
, len
= TREE_VEC_LENGTH (newargs
);
1979 if (TREE_VEC_LENGTH (oldargs
) != len
)
1982 for (i
= 0; i
< len
; i
++)
1984 tree newarg
= TREE_VEC_ELT (newargs
, i
);
1985 tree oldarg
= TREE_VEC_ELT (oldargs
, i
);
1986 if (TREE_CODE (newarg
) != TREE_CODE (oldarg
))
1988 else if (TREE_CODE (newarg
) == IDENTIFIER_NODE
)
1990 else if (! comptypes (TREE_TYPE (newarg
), TREE_TYPE (oldarg
), 1))
1994 if (DECL_TEMPLATE_IS_CLASS (newdecl
)
1995 != DECL_TEMPLATE_IS_CLASS (olddecl
))
1997 else if (DECL_TEMPLATE_IS_CLASS (newdecl
))
2000 types_match
= decls_match (DECL_TEMPLATE_RESULT (olddecl
),
2001 DECL_TEMPLATE_RESULT (newdecl
));
2005 if (TREE_TYPE (newdecl
) == error_mark_node
)
2006 types_match
= TREE_TYPE (olddecl
) == error_mark_node
;
2007 else if (TREE_TYPE (olddecl
) == NULL_TREE
)
2008 types_match
= TREE_TYPE (newdecl
) == NULL_TREE
;
2009 else if (TREE_TYPE (newdecl
) == NULL_TREE
)
2012 types_match
= comptypes (TREE_TYPE (newdecl
), TREE_TYPE (olddecl
), 1);
2018 /* If NEWDECL is `static' and an `extern' was seen previously,
2019 warn about it. (OLDDECL may be NULL_TREE; NAME contains
2020 information about previous usage as an `extern'.)
2022 Note that this does not apply to the C++ case of declaring
2023 a variable `extern const' and then later `const'.
2025 Don't complain if -traditional, since traditional compilers
2028 Don't complain about built-in functions, since they are beyond
2029 the user's control. */
2032 warn_extern_redeclared_static (newdecl
, olddecl
)
2033 tree newdecl
, olddecl
;
2037 static char *explicit_extern_static_warning
2038 = "`%D' was declared `extern' and later `static'";
2039 static char *implicit_extern_static_warning
2040 = "`%D' was declared implicitly `extern' and later `static'";
2042 if (flag_traditional
2043 || TREE_CODE (newdecl
) == TYPE_DECL
2044 || (! warn_extern_inline
2045 && DECL_INLINE (newdecl
)))
2048 name
= DECL_ASSEMBLER_NAME (newdecl
);
2049 if (TREE_PUBLIC (name
) && ! TREE_PUBLIC (newdecl
))
2051 /* It's okay to redeclare an ANSI built-in function as static,
2052 or to declare a non-ANSI built-in function as anything. */
2053 if (! (TREE_CODE (newdecl
) == FUNCTION_DECL
2054 && olddecl
!= NULL_TREE
2055 && TREE_CODE (olddecl
) == FUNCTION_DECL
2056 && (DECL_BUILT_IN (olddecl
)
2057 || DECL_BUILT_IN_NONANSI (olddecl
))))
2059 cp_warning (IDENTIFIER_IMPLICIT_DECL (name
)
2060 ? implicit_extern_static_warning
2061 : explicit_extern_static_warning
, newdecl
);
2062 if (olddecl
!= NULL_TREE
)
2063 cp_warning_at ("previous declaration of `%D'", olddecl
);
2068 /* Handle when a new declaration NEWDECL has the same name as an old
2069 one OLDDECL in the same binding contour. Prints an error message
2072 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
2073 Otherwise, return 0. */
2076 duplicate_decls (newdecl
, olddecl
)
2077 register tree newdecl
, olddecl
;
2079 extern struct obstack permanent_obstack
;
2080 unsigned olddecl_uid
= DECL_UID (olddecl
);
2081 int olddecl_friend
= 0, types_match
= 0;
2082 int new_defines_function
;
2083 tree previous_c_decl
= NULL_TREE
;
2085 types_match
= decls_match (newdecl
, olddecl
);
2087 if (TREE_CODE (olddecl
) != TREE_LIST
)
2088 olddecl_friend
= DECL_LANG_SPECIFIC (olddecl
) && DECL_FRIEND_P (olddecl
);
2090 /* If either the type of the new decl or the type of the old decl is an
2091 error_mark_node, then that implies that we have already issued an
2092 error (earlier) for some bogus type specification, and in that case,
2093 it is rather pointless to harass the user with yet more error message
2094 about the same declaration, so well just pretent the types match here. */
2095 if ((TREE_TYPE (newdecl
)
2096 && TREE_CODE (TREE_TYPE (newdecl
)) == ERROR_MARK
)
2097 || (TREE_TYPE (olddecl
)
2098 && TREE_CODE (TREE_TYPE (olddecl
)) == ERROR_MARK
))
2101 if (flag_traditional
&& TREE_CODE (newdecl
) == FUNCTION_DECL
2102 && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl
)) == olddecl
)
2103 /* If -traditional, avoid error for redeclaring fcn
2104 after implicit decl. */
2106 else if (TREE_CODE (olddecl
) == FUNCTION_DECL
2107 && (DECL_BUILT_IN (olddecl
) || DECL_BUILT_IN_NONANSI (olddecl
)))
2109 /* If you declare a built-in or predefined function name as static,
2110 the old definition is overridden, but optionally warn this was a
2111 bad choice of name. Ditto for overloads. */
2112 if (! TREE_PUBLIC (newdecl
)
2113 || (TREE_CODE (newdecl
) == FUNCTION_DECL
2114 && DECL_LANGUAGE (newdecl
) != DECL_LANGUAGE (olddecl
)))
2117 cp_warning ("shadowing %s function `%#D'",
2118 DECL_BUILT_IN (olddecl
) ? "built-in" : "library",
2120 /* Discard the old built-in function. */
2123 else if (! types_match
)
2125 if (TREE_CODE (newdecl
) != FUNCTION_DECL
)
2127 /* If the built-in is not ansi, then programs can override
2128 it even globally without an error. */
2129 if (! DECL_BUILT_IN (olddecl
))
2130 cp_warning ("library function `%#D' redeclared as non-function `%#D'",
2134 cp_error ("declaration of `%#D'", newdecl
);
2135 cp_error ("conflicts with built-in declaration `%#D'",
2141 cp_warning ("declaration of `%#D'", newdecl
);
2142 cp_warning ("conflicts with built-in declaration `%#D'",
2146 else if (TREE_CODE (olddecl
) != TREE_CODE (newdecl
))
2148 if ((TREE_CODE (newdecl
) == FUNCTION_DECL
2149 && TREE_CODE (olddecl
) == TEMPLATE_DECL
2150 && ! DECL_TEMPLATE_IS_CLASS (olddecl
))
2151 || (TREE_CODE (olddecl
) == FUNCTION_DECL
2152 && TREE_CODE (newdecl
) == TEMPLATE_DECL
2153 && ! DECL_TEMPLATE_IS_CLASS (newdecl
)))
2156 cp_error ("`%#D' redeclared as different kind of symbol", newdecl
);
2157 if (TREE_CODE (olddecl
) == TREE_LIST
)
2158 olddecl
= TREE_VALUE (olddecl
);
2159 cp_error_at ("previous declaration of `%#D'", olddecl
);
2161 /* New decl is completely inconsistent with the old one =>
2162 tell caller to replace the old one. */
2166 else if (!types_match
)
2168 if (TREE_CODE (newdecl
) == TEMPLATE_DECL
)
2170 /* The name of a class template may not be declared to refer to
2171 any other template, class, function, object, namespace, value,
2172 or type in the same scope. */
2173 if (DECL_TEMPLATE_IS_CLASS (olddecl
)
2174 || DECL_TEMPLATE_IS_CLASS (newdecl
))
2176 cp_error ("declaration of template `%#D'", newdecl
);
2177 cp_error_at ("conflicts with previous declaration `%#D'",
2182 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
2184 if (DECL_LANGUAGE (newdecl
) == lang_c
2185 && DECL_LANGUAGE (olddecl
) == lang_c
)
2187 cp_error ("declaration of C function `%#D' conflicts with",
2189 cp_error_at ("previous declaration `%#D' here", olddecl
);
2192 if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl
)),
2193 TYPE_ARG_TYPES (TREE_TYPE (olddecl
)), 2))
2195 cp_error ("new declaration `%#D'", newdecl
);
2196 cp_error_at ("ambiguates old declaration `%#D'", olddecl
);
2202 /* Already complained about this, so don't do so again. */
2203 else if (current_class_type
== NULL_TREE
2204 || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl
)) != current_class_type
)
2206 /* Since we're doing this before finish_struct can set the
2207 line number on NEWDECL, we just do a regular error here. */
2208 if (DECL_SOURCE_LINE (newdecl
) == 0)
2209 cp_error ("conflicting types for `%#D'", newdecl
);
2211 cp_error_at ("conflicting types for `%#D'", newdecl
);
2212 cp_error_at ("previous declaration as `%#D'", olddecl
);
2217 char *errmsg
= redeclaration_error_message (newdecl
, olddecl
);
2220 cp_error (errmsg
, newdecl
);
2221 if (DECL_NAME (olddecl
) != NULL_TREE
)
2222 cp_error_at ((DECL_INITIAL (olddecl
)
2223 && current_binding_level
== global_binding_level
)
2224 ? "`%#D' previously defined here"
2225 : "`%#D' previously declared here", olddecl
);
2227 else if (TREE_CODE (olddecl
) == FUNCTION_DECL
2228 && DECL_INITIAL (olddecl
) != NULL_TREE
2229 && TYPE_ARG_TYPES (TREE_TYPE (olddecl
)) == NULL_TREE
2230 && TYPE_ARG_TYPES (TREE_TYPE (newdecl
)) != NULL_TREE
)
2232 /* Prototype decl follows defn w/o prototype. */
2233 cp_warning_at ("prototype for `%#D'", newdecl
);
2234 cp_warning_at ("follows non-prototype definition here", olddecl
);
2236 else if (TREE_CODE (olddecl
) == FUNCTION_DECL
2237 && DECL_LANGUAGE (newdecl
) != DECL_LANGUAGE (olddecl
))
2239 /* extern "C" int foo ();
2240 int foo () { bar (); }
2242 if (current_lang_stack
== current_lang_base
)
2243 DECL_LANGUAGE (newdecl
) = DECL_LANGUAGE (olddecl
);
2246 cp_error_at ("previous declaration of `%#D' with %L linkage",
2247 olddecl
, DECL_LANGUAGE (olddecl
));
2248 cp_error ("conflicts with new declaration with %L linkage",
2249 DECL_LANGUAGE (newdecl
));
2253 /* These bits are logically part of the type. */
2255 && (TREE_READONLY (newdecl
) != TREE_READONLY (olddecl
)
2256 || TREE_THIS_VOLATILE (newdecl
) != TREE_THIS_VOLATILE (olddecl
)))
2257 cp_error_at ("type qualifiers for `%D' conflict with previous decl",
2261 /* If new decl is `static' and an `extern' was seen previously,
2263 warn_extern_redeclared_static (newdecl
, olddecl
);
2265 /* We have committed to returning 1 at this point. */
2266 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
2268 /* Now that functions must hold information normally held
2269 by field decls, there is extra work to do so that
2270 declaration information does not get destroyed during
2272 if (DECL_VINDEX (olddecl
))
2273 DECL_VINDEX (newdecl
) = DECL_VINDEX (olddecl
);
2274 if (DECL_CONTEXT (olddecl
))
2275 DECL_CONTEXT (newdecl
) = DECL_CONTEXT (olddecl
);
2276 if (DECL_CLASS_CONTEXT (olddecl
))
2277 DECL_CLASS_CONTEXT (newdecl
) = DECL_CLASS_CONTEXT (olddecl
);
2278 if (DECL_CHAIN (newdecl
) == NULL_TREE
)
2279 DECL_CHAIN (newdecl
) = DECL_CHAIN (olddecl
);
2280 if (DECL_NEXT_METHOD (newdecl
) == NULL_TREE
)
2281 DECL_NEXT_METHOD (newdecl
) = DECL_NEXT_METHOD (olddecl
);
2282 if (DECL_PENDING_INLINE_INFO (newdecl
) == (struct pending_inline
*)0)
2283 DECL_PENDING_INLINE_INFO (newdecl
) = DECL_PENDING_INLINE_INFO (olddecl
);
2286 /* Deal with C++: must preserve virtual function table size. */
2287 if (TREE_CODE (olddecl
) == TYPE_DECL
)
2289 register tree newtype
= TREE_TYPE (newdecl
);
2290 register tree oldtype
= TREE_TYPE (olddecl
);
2292 if (newtype
!= error_mark_node
&& oldtype
!= error_mark_node
2293 && TYPE_LANG_SPECIFIC (newtype
) && TYPE_LANG_SPECIFIC (oldtype
))
2295 CLASSTYPE_VSIZE (newtype
) = CLASSTYPE_VSIZE (oldtype
);
2296 CLASSTYPE_FRIEND_CLASSES (newtype
)
2297 = CLASSTYPE_FRIEND_CLASSES (oldtype
);
2300 /* why assert here? Just because debugging information is
2302 /* it happens on something like:
2303 typedef struct Thing {
2308 my_friendly_assert (DECL_IGNORED_P (olddecl
) == DECL_IGNORED_P (newdecl
),
2313 /* Special handling ensues if new decl is a function definition. */
2314 new_defines_function
= (TREE_CODE (newdecl
) == FUNCTION_DECL
2315 && DECL_INITIAL (newdecl
) != NULL_TREE
);
2317 /* Optionally warn about more than one declaration for the same name,
2318 but don't warn about a function declaration followed by a definition. */
2319 if (warn_redundant_decls
2320 && ! DECL_ARTIFICIAL (olddecl
)
2321 && !(new_defines_function
&& DECL_INITIAL (olddecl
) == NULL_TREE
)
2322 /* Don't warn about extern decl followed by (tentative) definition. */
2323 && !(DECL_EXTERNAL (olddecl
) && ! DECL_EXTERNAL (newdecl
)))
2325 cp_warning ("redundant redeclaration of `%D' in same scope", newdecl
);
2326 cp_warning ("previous declaration of `%D'", olddecl
);
2329 /* Copy all the DECL_... slots specified in the new decl
2330 except for any that we copy here from the old type. */
2334 /* Automatically handles default parameters. */
2335 tree oldtype
= TREE_TYPE (olddecl
);
2336 /* Merge the data types specified in the two decls. */
2337 tree newtype
= common_type (TREE_TYPE (newdecl
), TREE_TYPE (olddecl
));
2339 /* Make sure we put the new type in the same obstack as the old ones.
2340 If the old types are not both in the same obstack, use the permanent
2342 if (oldtype
&& TYPE_OBSTACK (oldtype
) == TYPE_OBSTACK (newtype
))
2343 push_obstacks (TYPE_OBSTACK (oldtype
), TYPE_OBSTACK (oldtype
));
2346 push_obstacks_nochange ();
2347 end_temporary_allocation ();
2350 if (TREE_CODE (newdecl
) == VAR_DECL
)
2351 DECL_THIS_EXTERN (newdecl
) |= DECL_THIS_EXTERN (olddecl
);
2352 /* Do this after calling `common_type' so that default
2353 parameters don't confuse us. */
2354 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
2355 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl
))
2356 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl
))))
2358 tree ctype
= NULL_TREE
;
2359 ctype
= DECL_CLASS_CONTEXT (newdecl
);
2360 TREE_TYPE (newdecl
) = build_exception_variant (ctype
, newtype
,
2361 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl
)));
2362 TREE_TYPE (olddecl
) = build_exception_variant (ctype
, newtype
,
2363 TYPE_RAISES_EXCEPTIONS (oldtype
));
2365 if (! compexcepttypes (TREE_TYPE (newdecl
), TREE_TYPE (olddecl
), 0))
2367 cp_error ("declaration of `%D' raises different exceptions...",
2369 cp_error_at ("...from previous declaration here", olddecl
);
2372 TREE_TYPE (newdecl
) = TREE_TYPE (olddecl
) = newtype
;
2374 /* Lay the type out, unless already done. */
2375 if (oldtype
!= TREE_TYPE (newdecl
))
2377 if (TREE_TYPE (newdecl
) != error_mark_node
)
2378 layout_type (TREE_TYPE (newdecl
));
2379 if (TREE_CODE (newdecl
) != FUNCTION_DECL
2380 && TREE_CODE (newdecl
) != TYPE_DECL
2381 && TREE_CODE (newdecl
) != CONST_DECL
2382 && TREE_CODE (newdecl
) != TEMPLATE_DECL
)
2383 layout_decl (newdecl
, 0);
2387 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
2388 DECL_SIZE (newdecl
) = DECL_SIZE (olddecl
);
2391 /* Merge the type qualifiers. */
2392 if (TREE_READONLY (newdecl
))
2393 TREE_READONLY (olddecl
) = 1;
2394 if (TREE_THIS_VOLATILE (newdecl
))
2395 TREE_THIS_VOLATILE (olddecl
) = 1;
2397 /* Merge the initialization information. */
2398 if (DECL_INITIAL (newdecl
) == NULL_TREE
2399 && DECL_INITIAL (olddecl
) != NULL_TREE
)
2401 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
2402 DECL_SOURCE_FILE (newdecl
) = DECL_SOURCE_FILE (olddecl
);
2403 DECL_SOURCE_LINE (newdecl
) = DECL_SOURCE_LINE (olddecl
);
2406 /* Merge the section attribute.
2407 We want to issue an error if the sections conflict but that must be
2408 done later in decl_attributes since we are called before attributes
2410 if (DECL_SECTION_NAME (newdecl
) == NULL_TREE
)
2411 DECL_SECTION_NAME (newdecl
) = DECL_SECTION_NAME (olddecl
);
2413 /* Keep the old rtl since we can safely use it, unless it's the
2414 call to abort() used for abstract virtuals. */
2415 if ((DECL_LANG_SPECIFIC (olddecl
)
2416 && !DECL_ABSTRACT_VIRTUAL_P (olddecl
))
2417 || DECL_RTL (olddecl
) != DECL_RTL (abort_fndecl
))
2418 DECL_RTL (newdecl
) = DECL_RTL (olddecl
);
2422 /* If cannot merge, then use the new type and qualifiers,
2423 and don't preserve the old rtl. */
2426 /* Clean out any memory we had of the old declaration. */
2427 tree oldstatic
= value_member (olddecl
, static_aggregates
);
2429 TREE_VALUE (oldstatic
) = error_mark_node
;
2431 TREE_TYPE (olddecl
) = TREE_TYPE (newdecl
);
2432 TREE_READONLY (olddecl
) = TREE_READONLY (newdecl
);
2433 TREE_THIS_VOLATILE (olddecl
) = TREE_THIS_VOLATILE (newdecl
);
2434 TREE_SIDE_EFFECTS (olddecl
) = TREE_SIDE_EFFECTS (newdecl
);
2437 /* Merge the storage class information. */
2438 if (DECL_EXTERNAL (newdecl
))
2440 TREE_STATIC (newdecl
) = TREE_STATIC (olddecl
);
2441 DECL_EXTERNAL (newdecl
) = DECL_EXTERNAL (olddecl
);
2443 if (TREE_CODE (newdecl
) != FUNCTION_DECL
)
2444 TREE_PUBLIC (newdecl
) = TREE_PUBLIC (olddecl
);
2448 TREE_STATIC (olddecl
) = TREE_STATIC (newdecl
);
2449 /* A `const' which was not declared `extern' and is
2450 in static storage is invisible. */
2451 if (TREE_CODE (newdecl
) == VAR_DECL
2452 && TREE_READONLY (newdecl
) && TREE_STATIC (newdecl
)
2453 && ! DECL_THIS_EXTERN (newdecl
))
2454 TREE_PUBLIC (newdecl
) = 0;
2455 else if (TREE_CODE (newdecl
) != FUNCTION_DECL
)
2456 TREE_PUBLIC (olddecl
) = TREE_PUBLIC (newdecl
);
2459 /* For functions, static overrides non-static. */
2460 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
2462 TREE_PUBLIC (newdecl
) &= TREE_PUBLIC (olddecl
);
2463 /* This is since we don't automatically
2464 copy the attributes of NEWDECL into OLDDECL. */
2465 TREE_PUBLIC (olddecl
) = TREE_PUBLIC (newdecl
);
2466 /* If this clears `static', clear it in the identifier too. */
2467 if (! TREE_PUBLIC (olddecl
))
2468 TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl
)) = 0;
2471 /* If either decl says `inline', this fn is inline,
2472 unless its definition was passed already. */
2473 if (DECL_INLINE (newdecl
) && DECL_INITIAL (olddecl
) == NULL_TREE
)
2474 DECL_INLINE (olddecl
) = 1;
2475 DECL_INLINE (newdecl
) = DECL_INLINE (olddecl
);
2477 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
2481 DECL_LANGUAGE (olddecl
) = DECL_LANGUAGE (newdecl
);
2482 DECL_ASSEMBLER_NAME (olddecl
) = DECL_ASSEMBLER_NAME (newdecl
);
2483 DECL_ARGUMENTS (olddecl
) = DECL_ARGUMENTS (newdecl
);
2484 DECL_RESULT (olddecl
) = DECL_RESULT (newdecl
);
2485 DECL_RTL (olddecl
) = DECL_RTL (newdecl
);
2487 if (new_defines_function
)
2488 /* If defining a function declared with other language
2489 linkage, use the previously declared language linkage. */
2490 DECL_LANGUAGE (newdecl
) = DECL_LANGUAGE (olddecl
);
2493 /* If redeclaring a builtin function, and not a definition,
2494 it stays built in. */
2495 if (DECL_BUILT_IN (olddecl
))
2497 DECL_BUILT_IN (newdecl
) = 1;
2498 DECL_FUNCTION_CODE (newdecl
) = DECL_FUNCTION_CODE (olddecl
);
2499 /* If we're keeping the built-in definition, keep the rtl,
2500 regardless of declaration matches. */
2501 DECL_RTL (newdecl
) = DECL_RTL (olddecl
);
2504 DECL_FRAME_SIZE (newdecl
) = DECL_FRAME_SIZE (olddecl
);
2506 DECL_RESULT (newdecl
) = DECL_RESULT (olddecl
);
2507 if ((DECL_SAVED_INSNS (newdecl
) = DECL_SAVED_INSNS (olddecl
)))
2508 /* Previously saved insns go together with
2509 the function's previous definition. */
2510 DECL_INITIAL (newdecl
) = DECL_INITIAL (olddecl
);
2511 /* Don't clear out the arguments if we're redefining a function. */
2512 if (DECL_ARGUMENTS (olddecl
))
2513 DECL_ARGUMENTS (newdecl
) = DECL_ARGUMENTS (olddecl
);
2517 if (TREE_CODE (newdecl
) == TEMPLATE_DECL
)
2519 if (DECL_TEMPLATE_INFO (olddecl
)->length
)
2520 DECL_TEMPLATE_INFO (newdecl
) = DECL_TEMPLATE_INFO (olddecl
);
2521 DECL_TEMPLATE_MEMBERS (newdecl
) = DECL_TEMPLATE_MEMBERS (olddecl
);
2522 DECL_TEMPLATE_INSTANTIATIONS (newdecl
)
2523 = DECL_TEMPLATE_INSTANTIATIONS (olddecl
);
2526 /* Now preserve various other info from the definition. */
2527 TREE_ADDRESSABLE (newdecl
) = TREE_ADDRESSABLE (olddecl
);
2528 TREE_ASM_WRITTEN (newdecl
) = TREE_ASM_WRITTEN (olddecl
);
2529 DECL_COMMON (newdecl
) = DECL_COMMON (olddecl
);
2531 /* Don't really know how much of the language-specific
2532 values we should copy from old to new. */
2533 if (DECL_LANG_SPECIFIC (olddecl
))
2535 DECL_IN_AGGR_P (newdecl
) = DECL_IN_AGGR_P (olddecl
);
2536 DECL_ACCESS (newdecl
) = DECL_ACCESS (olddecl
);
2539 if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
2542 struct lang_decl
*ol
= DECL_LANG_SPECIFIC (olddecl
);
2543 struct lang_decl
*nl
= DECL_LANG_SPECIFIC (newdecl
);
2545 function_size
= sizeof (struct tree_decl
);
2547 bcopy ((char *) newdecl
+ sizeof (struct tree_common
),
2548 (char *) olddecl
+ sizeof (struct tree_common
),
2549 function_size
- sizeof (struct tree_common
));
2551 /* Can we safely free the storage used by newdecl? */
2553 #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
2554 & ~ obstack_alignment_mask (&permanent_obstack))
2556 if ((char *)newdecl
+ ROUND (function_size
)
2557 + ROUND (sizeof (struct lang_decl
))
2558 == obstack_next_free (&permanent_obstack
))
2560 DECL_MAIN_VARIANT (newdecl
) = olddecl
;
2561 DECL_LANG_SPECIFIC (olddecl
) = ol
;
2562 bcopy ((char *)nl
, (char *)ol
, sizeof (struct lang_decl
));
2564 obstack_free (&permanent_obstack
, newdecl
);
2566 else if (LANG_DECL_PERMANENT (ol
))
2568 if (DECL_MAIN_VARIANT (olddecl
) == olddecl
)
2570 /* Save these lang_decls that would otherwise be lost. */
2571 extern tree free_lang_decl_chain
;
2572 tree free_lang_decl
= (tree
) ol
;
2573 TREE_CHAIN (free_lang_decl
) = free_lang_decl_chain
;
2574 free_lang_decl_chain
= free_lang_decl
;
2584 bcopy ((char *) newdecl
+ sizeof (struct tree_common
),
2585 (char *) olddecl
+ sizeof (struct tree_common
),
2586 sizeof (struct tree_decl
) - sizeof (struct tree_common
)
2587 + tree_code_length
[(int)TREE_CODE (newdecl
)] * sizeof (char *));
2590 DECL_UID (olddecl
) = olddecl_uid
;
2592 DECL_FRIEND_P (olddecl
) = 1;
2597 /* Record a decl-node X as belonging to the current lexical scope.
2598 Check for errors (such as an incompatible declaration for the same
2599 name already seen in the same scope).
2601 Returns either X or an old decl for the same name.
2602 If an old decl is returned, it may have been smashed
2603 to agree with what X says. */
2610 #if 0 /* not yet, should get fixed properly later */
2613 register tree name
= DECL_ASSEMBLER_NAME (x
);
2615 register struct binding_level
*b
= current_binding_level
;
2618 static int nglobals
; int len
;
2620 len
= list_length (global_binding_level
->names
);
2622 my_friendly_abort (8);
2623 else if (len
> nglobals
)
2627 if (x
!= current_function_decl
2628 /* Don't change DECL_CONTEXT of virtual methods. */
2629 && (TREE_CODE (x
) != FUNCTION_DECL
|| !DECL_VIRTUAL_P (x
))
2630 && ! DECL_CONTEXT (x
))
2631 DECL_CONTEXT (x
) = current_function_decl
;
2632 /* A local declaration for a function doesn't constitute nesting. */
2633 if (TREE_CODE (x
) == FUNCTION_DECL
&& DECL_INITIAL (x
) == 0)
2634 DECL_CONTEXT (x
) = 0;
2636 #if 0 /* not yet, should get fixed properly later */
2637 /* For functions and class static data, we currently look up the encoded
2638 form of the name. For types, we want the real name. The former will
2639 probably be changed soon, according to MDT. */
2640 if (TREE_CODE (x
) == FUNCTION_DECL
|| TREE_CODE (x
) == VAR_DECL
)
2641 name
= DECL_ASSEMBLER_NAME (x
);
2643 name
= DECL_NAME (x
);
2645 /* Type are looked up using the DECL_NAME, as that is what the rest of the
2646 compiler wants to use. */
2647 if (TREE_CODE (x
) == TYPE_DECL
)
2648 name
= DECL_NAME (x
);
2656 t
= lookup_name_current_level (name
);
2657 if (t
== error_mark_node
)
2659 /* error_mark_node is 0 for a while during initialization! */
2661 cp_error_at ("`%#D' used prior to declaration", x
);
2664 else if (t
!= NULL_TREE
)
2666 if (TREE_CODE (t
) == PARM_DECL
)
2668 if (DECL_CONTEXT (t
) == NULL_TREE
)
2669 fatal ("parse errors have confused me too much");
2671 file
= DECL_SOURCE_FILE (t
);
2672 line
= DECL_SOURCE_LINE (t
);
2674 if (((TREE_CODE (x
) == FUNCTION_DECL
&& DECL_LANGUAGE (x
) == lang_c
)
2675 || (TREE_CODE (x
) == TEMPLATE_DECL
2676 && ! DECL_TEMPLATE_IS_CLASS (x
)))
2677 && is_overloaded_fn (t
))
2678 /* don't do anything just yet */;
2679 else if (TREE_CODE (t
) != TREE_CODE (x
))
2681 if (TREE_CODE (t
) == TYPE_DECL
|| TREE_CODE (x
) == TYPE_DECL
)
2683 /* We do nothing special here, because C++ does such nasty
2684 things with TYPE_DECLs. Instead, just let the TYPE_DECL
2685 get shadowed, and know that if we need to find a TYPE_DECL
2686 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
2687 slot of the identifier. */
2690 else if (duplicate_decls (x
, t
))
2693 else if (duplicate_decls (x
, t
))
2696 /* This is turned off until I have time to do it right (bpk). */
2698 /* Also warn if they did a prototype with `static' on it, but
2699 then later left the `static' off. */
2700 if (! TREE_PUBLIC (name
) && TREE_PUBLIC (x
))
2702 if (DECL_LANG_SPECIFIC (t
) && DECL_FRIEND_P (t
))
2707 cp_warning ("`static' missing from declaration of `%D'",
2709 warning_with_file_and_line (file
, line
,
2710 "previous declaration of `%s'",
2711 decl_as_string (t
, 0));
2714 /* Now fix things so it'll do what they expect. */
2715 if (current_function_decl
)
2716 TREE_PUBLIC (current_function_decl
) = 0;
2718 /* Due to interference in memory reclamation (X may be
2719 obstack-deallocated at this point), we must guard against
2720 one really special case. [jason: This should be handled
2721 by start_function] */
2722 if (current_function_decl
== x
)
2723 current_function_decl
= t
;
2725 if (TREE_CODE (t
) == TYPE_DECL
)
2726 SET_IDENTIFIER_TYPE_VALUE (name
, TREE_TYPE (t
));
2732 if (TREE_CODE (x
) == FUNCTION_DECL
&& ! DECL_FUNCTION_MEMBER_P (x
))
2734 t
= push_overloaded_decl (x
, 1);
2735 if (t
!= x
|| DECL_LANGUAGE (x
) == lang_c
)
2738 else if (TREE_CODE (x
) == TEMPLATE_DECL
&& ! DECL_TEMPLATE_IS_CLASS (x
))
2739 return push_overloaded_decl (x
, 0);
2741 /* If declaring a type as a typedef, and the type has no known
2742 typedef name, install this TYPE_DECL as its typedef name. */
2743 if (TREE_CODE (x
) == TYPE_DECL
)
2745 tree type
= TREE_TYPE (x
);
2746 tree name
= (type
!= error_mark_node
) ? TYPE_NAME (type
) : x
;
2748 if (name
== NULL_TREE
|| TREE_CODE (name
) != TYPE_DECL
)
2750 /* If these are different names, and we're at the global
2751 binding level, make two equivalent definitions. */
2753 if (global_bindings_p ())
2754 TYPE_NAME (type
) = x
;
2758 tree tname
= DECL_NAME (name
);
2760 if (global_bindings_p () && ANON_AGGRNAME_P (tname
))
2762 /* do gratuitous C++ typedefing, and make sure that
2763 we access this type either through TREE_TYPE field
2764 or via the tags list. */
2765 TYPE_NAME (TREE_TYPE (x
)) = x
;
2766 pushtag (tname
, TREE_TYPE (x
), 0);
2769 my_friendly_assert (TREE_CODE (name
) == TYPE_DECL
, 140);
2771 if (DECL_NAME (name
) && !DECL_NESTED_TYPENAME (name
))
2772 set_nested_typename (x
, current_class_name
,
2773 DECL_NAME (name
), type
);
2775 if (type
!= error_mark_node
2777 && TYPE_IDENTIFIER (type
))
2778 set_identifier_type_value_with_scope (DECL_NAME (x
), type
, b
);
2781 /* Multiple external decls of the same identifier ought to match.
2783 We get warnings about inline functions where they are defined.
2784 We get warnings about other functions from push_overloaded_decl.
2786 Avoid duplicate warnings where they are used. */
2787 if (TREE_PUBLIC (x
) && TREE_CODE (x
) != FUNCTION_DECL
)
2791 if (IDENTIFIER_GLOBAL_VALUE (name
) != NULL_TREE
2792 && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name
))
2793 || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name
))))
2794 decl
= IDENTIFIER_GLOBAL_VALUE (name
);
2799 /* If different sort of thing, we already gave an error. */
2800 && TREE_CODE (decl
) == TREE_CODE (x
)
2801 && ! comptypes (TREE_TYPE (x
), TREE_TYPE (decl
), 1))
2803 cp_pedwarn ("type mismatch with previous external decl", x
);
2804 cp_pedwarn_at ("previous external decl of `%#D'", decl
);
2808 /* In PCC-compatibility mode, extern decls of vars with no current decl
2809 take effect at top level no matter where they are. */
2810 if (flag_traditional
&& DECL_EXTERNAL (x
)
2811 && lookup_name (name
, 0) == NULL_TREE
)
2812 b
= global_binding_level
;
2814 /* This name is new in its binding level.
2815 Install the new declaration and return it. */
2816 if (b
== global_binding_level
)
2818 /* Install a global value. */
2820 /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
2821 A `const' which was not declared `extern' is invisible. */
2822 if (TREE_CODE (x
) == VAR_DECL
2823 && TREE_READONLY (x
) && ! DECL_THIS_EXTERN (x
))
2824 TREE_PUBLIC (x
) = 0;
2826 /* If the first global decl has external linkage,
2827 warn if we later see static one. */
2828 if (IDENTIFIER_GLOBAL_VALUE (name
) == NULL_TREE
&& TREE_PUBLIC (x
))
2829 TREE_PUBLIC (name
) = 1;
2831 /* Don't install a TYPE_DECL if we already have another
2832 sort of _DECL with that name. */
2833 if (TREE_CODE (x
) != TYPE_DECL
2835 || TREE_CODE (t
) == TYPE_DECL
)
2836 IDENTIFIER_GLOBAL_VALUE (name
) = x
;
2838 /* Don't forget if the function was used via an implicit decl. */
2839 if (IDENTIFIER_IMPLICIT_DECL (name
)
2840 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name
)))
2843 /* Don't forget if its address was taken in that way. */
2844 if (IDENTIFIER_IMPLICIT_DECL (name
)
2845 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name
)))
2846 TREE_ADDRESSABLE (x
) = 1;
2848 /* Warn about mismatches against previous implicit decl. */
2849 if (IDENTIFIER_IMPLICIT_DECL (name
) != NULL_TREE
2850 /* If this real decl matches the implicit, don't complain. */
2851 && ! (TREE_CODE (x
) == FUNCTION_DECL
2852 && TREE_TYPE (TREE_TYPE (x
)) == integer_type_node
))
2854 ("`%D' was previously implicitly declared to return `int'", x
);
2856 /* If new decl is `static' and an `extern' was seen previously,
2858 if (x
!= NULL_TREE
&& t
!= NULL_TREE
&& decls_match (x
, t
))
2859 warn_extern_redeclared_static (x
, t
);
2863 /* Here to install a non-global value. */
2864 tree oldlocal
= IDENTIFIER_LOCAL_VALUE (name
);
2865 tree oldglobal
= IDENTIFIER_GLOBAL_VALUE (name
);
2867 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
2868 IDENTIFIER_LOCAL_VALUE (name
) = x
;
2870 /* If this is a TYPE_DECL, push it into the type value slot. */
2871 if (TREE_CODE (x
) == TYPE_DECL
)
2872 set_identifier_type_value_with_scope (name
, TREE_TYPE (x
), b
);
2874 /* If this is an extern function declaration, see if we
2875 have a global definition or declaration for the function. */
2876 if (oldlocal
== NULL_TREE
2877 && DECL_EXTERNAL (x
) && !DECL_INLINE (x
)
2878 && oldglobal
!= NULL_TREE
2879 && TREE_CODE (x
) == FUNCTION_DECL
2880 && TREE_CODE (oldglobal
) == FUNCTION_DECL
)
2882 /* We have one. Their types must agree. */
2883 if (! comptypes (TREE_TYPE (x
), TREE_TYPE (oldglobal
), 1))
2885 cp_warning ("extern declaration of `%#D' doesn't match", x
);
2886 cp_warning_at ("global declaration `%#D'", oldglobal
);
2890 /* Inner extern decl is inline if global one is.
2891 Copy enough to really inline it. */
2892 if (DECL_INLINE (oldglobal
))
2894 DECL_INLINE (x
) = DECL_INLINE (oldglobal
);
2895 DECL_INITIAL (x
) = (current_function_decl
== oldglobal
2896 ? NULL_TREE
: DECL_INITIAL (oldglobal
));
2897 DECL_SAVED_INSNS (x
) = DECL_SAVED_INSNS (oldglobal
);
2898 DECL_FRAME_SIZE (x
) = DECL_FRAME_SIZE (oldglobal
);
2899 DECL_ARGUMENTS (x
) = DECL_ARGUMENTS (oldglobal
);
2900 DECL_RESULT (x
) = DECL_RESULT (oldglobal
);
2901 TREE_ASM_WRITTEN (x
) = TREE_ASM_WRITTEN (oldglobal
);
2902 DECL_ABSTRACT_ORIGIN (x
) = oldglobal
;
2904 /* Inner extern decl is built-in if global one is. */
2905 if (DECL_BUILT_IN (oldglobal
))
2907 DECL_BUILT_IN (x
) = DECL_BUILT_IN (oldglobal
);
2908 DECL_FUNCTION_CODE (x
) = DECL_FUNCTION_CODE (oldglobal
);
2910 /* Keep the arg types from a file-scope fcn defn. */
2911 if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal
)) != NULL_TREE
2912 && DECL_INITIAL (oldglobal
)
2913 && TYPE_ARG_TYPES (TREE_TYPE (x
)) == NULL_TREE
)
2914 TREE_TYPE (x
) = TREE_TYPE (oldglobal
);
2917 /* If we have a local external declaration,
2918 and no file-scope declaration has yet been seen,
2919 then if we later have a file-scope decl it must not be static. */
2920 if (oldlocal
== NULL_TREE
2921 && oldglobal
== NULL_TREE
2922 && DECL_EXTERNAL (x
)
2925 TREE_PUBLIC (name
) = 1;
2928 if (DECL_FROM_INLINE (x
))
2929 /* Inline decls shadow nothing. */;
2931 /* Warn if shadowing an argument at the top level of the body. */
2932 else if (oldlocal
!= NULL_TREE
&& !DECL_EXTERNAL (x
)
2933 && TREE_CODE (oldlocal
) == PARM_DECL
2934 && TREE_CODE (x
) != PARM_DECL
)
2936 /* Go to where the parms should be and see if we
2938 struct binding_level
*b
= current_binding_level
->level_chain
;
2944 if (b
->parm_flag
== 1)
2945 cp_error ("declaration of `%#D' shadows a parameter", name
);
2947 /* Maybe warn if shadowing something else. */
2948 else if (warn_shadow
&& !DECL_EXTERNAL (x
)
2949 /* No shadow warnings for internally generated vars. */
2950 && ! DECL_ARTIFICIAL (x
)
2951 /* No shadow warnings for vars made for inlining. */
2952 && ! DECL_FROM_INLINE (x
))
2954 char *warnstring
= NULL
;
2956 if (oldlocal
!= NULL_TREE
&& TREE_CODE (oldlocal
) == PARM_DECL
)
2957 warnstring
= "declaration of `%s' shadows a parameter";
2958 else if (IDENTIFIER_CLASS_VALUE (name
) != NULL_TREE
2959 && !TREE_STATIC (name
))
2960 warnstring
= "declaration of `%s' shadows a member of `this'";
2961 else if (oldlocal
!= NULL_TREE
)
2962 warnstring
= "declaration of `%s' shadows previous local";
2963 else if (oldglobal
!= NULL_TREE
)
2964 warnstring
= "declaration of `%s' shadows global declaration";
2967 warning (warnstring
, IDENTIFIER_POINTER (name
));
2970 /* If storing a local value, there may already be one (inherited).
2971 If so, record it for restoration when this binding level ends. */
2972 if (oldlocal
!= NULL_TREE
)
2973 b
->shadowed
= tree_cons (name
, oldlocal
, b
->shadowed
);
2976 /* Keep count of variables in this level with incomplete type. */
2977 if (TREE_CODE (x
) != TEMPLATE_DECL
2978 && TYPE_SIZE (TREE_TYPE (x
)) == NULL_TREE
2979 && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x
), ARRAY_TYPE
))
2981 if (++b
->n_incomplete
== 0)
2982 error ("too many incomplete variables at this point");
2986 if (TREE_CODE (x
) == TYPE_DECL
&& name
!= NULL_TREE
)
2988 if (current_class_name
)
2990 if (! TREE_MANGLED (name
))
2991 set_nested_typename (x
, current_class_name
, DECL_NAME (x
),
2996 /* Put decls on list in reverse order.
2997 We will reverse them later if necessary. */
2998 TREE_CHAIN (x
) = b
->names
;
3000 if (! (b
!= global_binding_level
|| TREE_PERMANENT (x
)))
3001 my_friendly_abort (124);
3006 /* Same as pushdecl, but define X in binding-level LEVEL. */
3009 pushdecl_with_scope (x
, level
)
3011 struct binding_level
*level
;
3013 register struct binding_level
*b
= current_binding_level
;
3015 current_binding_level
= level
;
3017 current_binding_level
= b
;
3021 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
3024 pushdecl_top_level (x
)
3027 register struct binding_level
*b
= inner_binding_level
;
3028 register tree t
= pushdecl_with_scope (x
, global_binding_level
);
3030 /* Now, the type_shadowed stack may screw us. Munge it so it does
3032 if (TREE_CODE (x
) == TYPE_DECL
)
3034 tree name
= DECL_NAME (x
);
3036 tree
*ptr
= (tree
*)0;
3037 for (; b
!= global_binding_level
; b
= b
->level_chain
)
3039 tree shadowed
= b
->type_shadowed
;
3040 for (; shadowed
; shadowed
= TREE_CHAIN (shadowed
))
3041 if (TREE_PURPOSE (shadowed
) == name
)
3043 ptr
= &TREE_VALUE (shadowed
);
3044 /* Can't break out of the loop here because sometimes
3045 a binding level will have duplicate bindings for
3046 PT names. It's gross, but I haven't time to fix it. */
3049 newval
= TREE_TYPE (x
);
3050 if (ptr
== (tree
*)0)
3052 /* @@ This shouldn't be needed. My test case "zstring.cc" trips
3053 up here if this is changed to an assertion. --KR */
3054 SET_IDENTIFIER_TYPE_VALUE (name
, newval
);
3059 /* Disabled this 11/10/92, since there are many cases which
3060 behave just fine when *ptr doesn't satisfy either of these.
3061 For example, nested classes declared as friends of their enclosing
3062 class will not meet this criteria. (bpk) */
3063 my_friendly_assert (*ptr
== NULL_TREE
|| *ptr
== newval
, 141);
3071 /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
3074 push_overloaded_decl_top_level (x
, forget
)
3078 struct binding_level
*b
= current_binding_level
;
3080 current_binding_level
= global_binding_level
;
3081 push_overloaded_decl (x
, forget
);
3082 current_binding_level
= b
;
3085 /* Make the declaration of X appear in CLASS scope. */
3087 pushdecl_class_level (x
)
3090 /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class
3091 scope looks for the pre-mangled name. */
3092 register tree name
= DECL_NAME (x
);
3096 if (TYPE_BEING_DEFINED (current_class_type
))
3098 /* Check for inconsistent use of this name in the class body.
3099 Types, enums, and static vars are checked here; other
3100 members are checked in finish_struct. */
3101 tree icv
= IDENTIFIER_CLASS_VALUE (name
);
3104 /* Don't complain about inherited names. */
3105 && id_in_current_class (name
)
3106 /* Or shadowed tags. */
3107 && !(TREE_CODE (icv
) == TYPE_DECL
3108 && DECL_CONTEXT (icv
) == current_class_type
))
3110 cp_error ("declaration of identifier `%D' as `%#D'", name
, x
);
3111 cp_error_at ("conflicts with previous use in class as `%#D'",
3116 push_class_level_binding (name
, x
);
3117 if (TREE_CODE (x
) == TYPE_DECL
)
3119 set_identifier_type_value (name
, TREE_TYPE (x
));
3120 if (!DECL_NESTED_TYPENAME (x
))
3121 set_nested_typename (x
, current_class_name
, name
, TREE_TYPE (x
));
3127 /* This function is used to push the mangled decls for nested types into
3128 the appropriate scope. Previously pushdecl_top_level was used, but that
3129 is incorrect for members of local classes. */
3131 pushdecl_nonclass_level (x
)
3134 struct binding_level
*b
= current_binding_level
;
3137 /* Get out of class scope -- this isn't necessary, because class scope
3138 doesn't make it into current_binding_level. */
3139 while (b
->parm_flag
== 2)
3142 my_friendly_assert (b
->parm_flag
!= 2, 180);
3145 /* Get out of template binding levels */
3146 while (b
->pseudo_global
)
3149 pushdecl_with_scope (x
, b
);
3152 /* Make the declaration(s) of X appear in CLASS scope
3153 under the name NAME. */
3155 push_class_level_binding (name
, x
)
3159 maybe_push_cache_obstack ();
3160 class_binding_level
->class_shadowed
3161 = tree_cons (name
, IDENTIFIER_CLASS_VALUE (name
),
3162 class_binding_level
->class_shadowed
);
3164 IDENTIFIER_CLASS_VALUE (name
) = x
;
3165 obstack_ptr_grow (&decl_obstack
, x
);
3168 /* Tell caller how to interpret a TREE_LIST which contains
3169 chains of FUNCTION_DECLS. */
3171 overloaded_globals_p (list
)
3174 my_friendly_assert (TREE_CODE (list
) == TREE_LIST
, 142);
3176 /* Don't commit caller to seeing them as globals. */
3177 if (TREE_NONLOCAL_FLAG (list
))
3179 /* Do commit caller to seeing them as globals. */
3180 if (TREE_CODE (TREE_PURPOSE (list
)) == IDENTIFIER_NODE
)
3182 /* Do commit caller to not seeing them as globals. */
3186 /* DECL is a FUNCTION_DECL which may have other definitions already in
3187 place. We get around this by making the value of the identifier point
3188 to a list of all the things that want to be referenced by that name. It
3189 is then up to the users of that name to decide what to do with that
3192 DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
3193 slot. It is dealt with the same way.
3195 The value returned may be a previous declaration if we guessed wrong
3196 about what language DECL should belong to (C or C++). Otherwise,
3197 it's always DECL (and never something that's not a _DECL). */
3199 push_overloaded_decl (decl
, forgettable
)
3203 tree orig_name
= DECL_NAME (decl
);
3205 int doing_global
= (global_bindings_p () || ! forgettable
3206 || flag_traditional
|| pseudo_global_level_p ());
3210 old
= IDENTIFIER_GLOBAL_VALUE (orig_name
);
3211 if (old
&& TREE_CODE (old
) == FUNCTION_DECL
3212 && DECL_ARTIFICIAL (old
)
3213 && (DECL_BUILT_IN (old
) || DECL_BUILT_IN_NONANSI (old
)))
3215 if (duplicate_decls (decl
, old
))
3222 old
= IDENTIFIER_LOCAL_VALUE (orig_name
);
3224 if (! purpose_member (orig_name
, current_binding_level
->shadowed
))
3226 current_binding_level
->shadowed
3227 = tree_cons (orig_name
, old
, current_binding_level
->shadowed
);
3235 /* We cache the value of builtin functions as ADDR_EXPRs
3236 in the name space. Convert it to some kind of _DECL after
3237 remembering what to forget. */
3238 if (TREE_CODE (old
) == ADDR_EXPR
)
3239 old
= TREE_OPERAND (old
, 0);
3242 if (TREE_CODE (old
) == VAR_DECL
)
3244 cp_error_at ("previous non-function declaration `%#D'", old
);
3245 cp_error ("conflicts with function declaration `%#D'", decl
);
3246 return error_mark_node
;
3248 else if (TREE_CODE (old
) == TYPE_DECL
)
3250 tree t
= TREE_TYPE (old
);
3251 if (IS_AGGR_TYPE (t
) && warn_shadow
)
3252 cp_warning ("`%#D' hides constructor for `%#T'", decl
, t
);
3255 else if (is_overloaded_fn (old
))
3259 for (tmp
= get_first_fn (old
); tmp
; tmp
= DECL_CHAIN (tmp
))
3260 if (decl
== tmp
|| duplicate_decls (decl
, tmp
))
3265 if (old
|| TREE_CODE (decl
) == TEMPLATE_DECL
)
3267 if (old
&& is_overloaded_fn (old
))
3268 DECL_CHAIN (decl
) = get_first_fn (old
);
3270 DECL_CHAIN (decl
) = NULL_TREE
;
3271 old
= tree_cons (orig_name
, decl
, NULL_TREE
);
3272 TREE_TYPE (old
) = unknown_type_node
;
3275 /* orig_name is not ambiguous. */
3279 IDENTIFIER_GLOBAL_VALUE (orig_name
) = old
;
3281 IDENTIFIER_LOCAL_VALUE (orig_name
) = old
;
3286 /* Generate an implicit declaration for identifier FUNCTIONID
3287 as a function of type int (). Print a warning if appropriate. */
3290 implicitly_declare (functionid
)
3294 int temp
= allocation_temporary_p ();
3296 push_obstacks_nochange ();
3298 /* Save the decl permanently so we can warn if definition follows.
3299 In ANSI C, warn_implicit is usually false, so the saves little space.
3300 But in C++, it's usually true, hence the extra code. */
3301 if (temp
&& (flag_traditional
|| !warn_implicit
3302 || current_binding_level
== global_binding_level
))
3303 end_temporary_allocation ();
3305 /* We used to reuse an old implicit decl here,
3306 but this loses with inline functions because it can clobber
3307 the saved decl chains. */
3308 decl
= build_lang_decl (FUNCTION_DECL
, functionid
, default_function_type
);
3310 DECL_EXTERNAL (decl
) = 1;
3311 TREE_PUBLIC (decl
) = 1;
3313 /* ANSI standard says implicit declarations are in the innermost block.
3314 So we record the decl in the standard fashion.
3315 If flag_traditional is set, pushdecl does it top-level. */
3317 rest_of_decl_compilation (decl
, NULL_PTR
, 0, 0);
3320 /* Only one warning per identifier. */
3321 && IDENTIFIER_IMPLICIT_DECL (functionid
) == NULL_TREE
)
3323 cp_pedwarn ("implicit declaration of function `%#D'", decl
);
3326 SET_IDENTIFIER_IMPLICIT_DECL (functionid
, decl
);
3333 /* Return zero if the declaration NEWDECL is valid
3334 when the declaration OLDDECL (assumed to be for the same name)
3335 has already been seen.
3336 Otherwise return an error message format string with a %s
3337 where the identifier should go. */
3340 redeclaration_error_message (newdecl
, olddecl
)
3341 tree newdecl
, olddecl
;
3343 if (TREE_CODE (newdecl
) == TYPE_DECL
)
3345 /* Because C++ can put things into name space for free,
3346 constructs like "typedef struct foo { ... } foo"
3347 would look like an erroneous redeclaration. */
3348 if (comptypes (TREE_TYPE (newdecl
), TREE_TYPE (olddecl
), 0))
3351 return "redefinition of `%#D'";
3353 else if (TREE_CODE (newdecl
) == FUNCTION_DECL
)
3355 /* If this is a pure function, its olddecl will actually be
3356 the original initialization to `0' (which we force to call
3357 abort()). Don't complain about redefinition in this case. */
3358 if (DECL_LANG_SPECIFIC (olddecl
) && DECL_ABSTRACT_VIRTUAL_P (olddecl
))
3361 /* Declarations of functions can insist on internal linkage
3362 but they can't be inconsistent with internal linkage,
3363 so there can be no error on that account.
3364 However defining the same name twice is no good. */
3365 if (DECL_INITIAL (olddecl
) != NULL_TREE
3366 && DECL_INITIAL (newdecl
) != NULL_TREE
3367 /* However, defining once as extern inline and a second
3368 time in another way is ok. */
3369 && !(DECL_INLINE (olddecl
) && DECL_EXTERNAL (olddecl
)
3370 && !(DECL_INLINE (newdecl
) && DECL_EXTERNAL (newdecl
))))
3372 if (DECL_NAME (olddecl
) == NULL_TREE
)
3373 return "`%#D' not declared in class";
3375 return "redefinition of `%#D'";
3379 tree t1
= TYPE_ARG_TYPES (TREE_TYPE (olddecl
));
3380 tree t2
= TYPE_ARG_TYPES (TREE_TYPE (newdecl
));
3382 if (TREE_CODE (TREE_TYPE (newdecl
)) == METHOD_TYPE
)
3383 t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
);
3385 for (; t1
; t1
= TREE_CHAIN (t1
), t2
= TREE_CHAIN (t2
))
3386 if (TREE_PURPOSE (t1
) && TREE_PURPOSE (t2
))
3387 return "duplicate default arguments given for `%#D'";
3391 else if (TREE_CODE (newdecl
) == TEMPLATE_DECL
)
3393 if (DECL_INITIAL (olddecl
) && DECL_INITIAL (newdecl
))
3394 return "redefinition of `%#D'";
3397 else if (current_binding_level
== global_binding_level
)
3399 /* Objects declared at top level: */
3400 /* If at least one is a reference, it's ok. */
3401 if (DECL_EXTERNAL (newdecl
) || DECL_EXTERNAL (olddecl
))
3403 /* Now we have two tentative defs, or one tentative and one real def. */
3404 /* Insist that the linkage match. */
3405 if (TREE_PUBLIC (olddecl
) != TREE_PUBLIC (newdecl
))
3406 return "conflicting declarations of `%#D'";
3407 /* Reject two definitions. */
3408 return "redefinition of `%#D'";
3412 /* Objects declared with block scope: */
3413 /* Reject two definitions, and reject a definition
3414 together with an external reference. */
3415 if (!(DECL_EXTERNAL (newdecl
) && DECL_EXTERNAL (olddecl
)))
3416 return "redeclaration of `%#D'";
3421 /* Get the LABEL_DECL corresponding to identifier ID as a label.
3422 Create one if none exists so far for the current function.
3423 This function is called for both label definitions and label references. */
3429 register tree decl
= IDENTIFIER_LABEL_VALUE (id
);
3431 if (current_function_decl
== NULL_TREE
)
3433 error ("label `%s' referenced outside of any function",
3434 IDENTIFIER_POINTER (id
));
3438 if ((decl
== NULL_TREE
3439 || DECL_SOURCE_LINE (decl
) == 0)
3440 && (named_label_uses
== NULL_TREE
3441 || TREE_PURPOSE (named_label_uses
) != current_binding_level
->names
3442 || TREE_VALUE (named_label_uses
) != decl
))
3445 = tree_cons (current_binding_level
->names
, decl
, named_label_uses
);
3446 TREE_TYPE (named_label_uses
) = (tree
)current_binding_level
;
3449 /* Use a label already defined or ref'd with this name. */
3450 if (decl
!= NULL_TREE
)
3452 /* But not if it is inherited and wasn't declared to be inheritable. */
3453 if (DECL_CONTEXT (decl
) != current_function_decl
3454 && ! C_DECLARED_LABEL_FLAG (decl
))
3455 return shadow_label (id
);
3459 decl
= build_decl (LABEL_DECL
, id
, void_type_node
);
3461 /* A label not explicitly declared must be local to where it's ref'd. */
3462 DECL_CONTEXT (decl
) = current_function_decl
;
3464 DECL_MODE (decl
) = VOIDmode
;
3466 /* Say where one reference is to the label,
3467 for the sake of the error if it is not defined. */
3468 DECL_SOURCE_LINE (decl
) = lineno
;
3469 DECL_SOURCE_FILE (decl
) = input_filename
;
3471 SET_IDENTIFIER_LABEL_VALUE (id
, decl
);
3473 named_labels
= tree_cons (NULL_TREE
, decl
, named_labels
);
3474 TREE_VALUE (named_label_uses
) = decl
;
3479 /* Make a label named NAME in the current function,
3480 shadowing silently any that may be inherited from containing functions
3481 or containing scopes.
3483 Note that valid use, if the label being shadowed
3484 comes from another scope in the same function,
3485 requires calling declare_nonlocal_label right away. */
3491 register tree decl
= IDENTIFIER_LABEL_VALUE (name
);
3493 if (decl
!= NULL_TREE
)
3495 shadowed_labels
= tree_cons (NULL_TREE
, decl
, shadowed_labels
);
3496 SET_IDENTIFIER_LABEL_VALUE (name
, NULL_TREE
);
3497 SET_IDENTIFIER_LABEL_VALUE (decl
, NULL_TREE
);
3500 return lookup_label (name
);
3503 /* Define a label, specifying the location in the source file.
3504 Return the LABEL_DECL node for the label, if the definition is valid.
3505 Otherwise return 0. */
3508 define_label (filename
, line
, name
)
3513 tree decl
= lookup_label (name
);
3515 /* After labels, make any new cleanups go into their
3516 own new (temporary) binding contour. */
3517 current_binding_level
->more_cleanups_ok
= 0;
3519 /* If label with this name is known from an outer context, shadow it. */
3520 if (decl
!= NULL_TREE
&& DECL_CONTEXT (decl
) != current_function_decl
)
3522 shadowed_labels
= tree_cons (NULL_TREE
, decl
, shadowed_labels
);
3523 SET_IDENTIFIER_LABEL_VALUE (name
, NULL_TREE
);
3524 decl
= lookup_label (name
);
3527 if (DECL_INITIAL (decl
) != NULL_TREE
)
3529 cp_error ("duplicate label `%D'", decl
);
3536 /* Mark label as having been defined. */
3537 DECL_INITIAL (decl
) = error_mark_node
;
3538 /* Say where in the source. */
3539 DECL_SOURCE_FILE (decl
) = filename
;
3540 DECL_SOURCE_LINE (decl
) = line
;
3542 for (prev
= NULL_TREE
, uses
= named_label_uses
;
3544 prev
= uses
, uses
= TREE_CHAIN (uses
))
3545 if (TREE_VALUE (uses
) == decl
)
3547 struct binding_level
*b
= current_binding_level
;
3550 tree new_decls
= b
->names
;
3551 tree old_decls
= ((tree
)b
== TREE_TYPE (uses
)
3552 ? TREE_PURPOSE (uses
) : NULL_TREE
);
3553 while (new_decls
!= old_decls
)
3555 if (TREE_CODE (new_decls
) == VAR_DECL
3556 /* Don't complain about crossing initialization
3557 of internal entities. They can't be accessed,
3558 and they should be cleaned up
3559 by the time we get to the label. */
3560 && ! DECL_ARTIFICIAL (new_decls
)
3561 && ((DECL_INITIAL (new_decls
) != NULL_TREE
3562 && DECL_INITIAL (new_decls
) != error_mark_node
)
3563 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls
))))
3565 if (IDENTIFIER_ERROR_LOCUS (decl
) == NULL_TREE
)
3566 cp_error ("invalid jump to label `%D'", decl
);
3567 SET_IDENTIFIER_ERROR_LOCUS (decl
, current_function_decl
);
3568 cp_error ("crosses initialization of `%D'", new_decls
);
3570 new_decls
= TREE_CHAIN (new_decls
);
3572 if ((tree
)b
== TREE_TYPE (uses
))
3578 TREE_CHAIN (prev
) = TREE_CHAIN (uses
);
3580 named_label_uses
= TREE_CHAIN (uses
);
3582 current_function_return_value
= NULL_TREE
;
3587 /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */
3588 /* XXX Note decl is never actually used. (bpk) */
3590 define_case_label (decl
)
3593 tree cleanup
= last_cleanup_this_contour ();
3596 static int explained
= 0;
3597 cp_error_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup
));
3598 error ("where case label appears here");
3601 error ("(enclose actions of previous case statements requiring");
3602 error ("destructors in their own binding contours.)");
3607 /* After labels, make any new cleanups go into their
3608 own new (temporary) binding contour. */
3610 current_binding_level
->more_cleanups_ok
= 0;
3611 current_function_return_value
= NULL_TREE
;
3614 /* Return the list of declarations of the current level.
3615 Note that this list is in reverse order unless/until
3616 you nreverse it; and when you do nreverse it, you must
3617 store the result back using `storedecls' or you will lose. */
3622 return current_binding_level
->names
;
3625 /* Return the list of type-tags (for structs, etc) of the current level. */
3630 return current_binding_level
->tags
;
3633 /* Store the list of declarations of the current level.
3634 This is done for the parameter declarations of a function being defined,
3635 after they are modified in the light of any missing parameters. */
3641 current_binding_level
->names
= decls
;
3644 /* Similarly, store the list of tags of the current level. */
3650 current_binding_level
->tags
= tags
;
3653 /* Given NAME, an IDENTIFIER_NODE,
3654 return the structure (or union or enum) definition for that name.
3655 Searches binding levels from BINDING_LEVEL up to the global level.
3656 If THISLEVEL_ONLY is nonzero, searches only the specified context
3657 (but skips any tag-transparent contexts to find one that is
3658 meaningful for tags).
3659 FORM says which kind of type the caller wants;
3660 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
3661 If the wrong kind of type is found, and it's not a template, an error is
3665 lookup_tag (form
, name
, binding_level
, thislevel_only
)
3666 enum tree_code form
;
3667 struct binding_level
*binding_level
;
3671 register struct binding_level
*level
;
3673 for (level
= binding_level
; level
; level
= level
->level_chain
)
3676 if (ANON_AGGRNAME_P (name
))
3677 for (tail
= level
->tags
; tail
; tail
= TREE_CHAIN (tail
))
3679 /* There's no need for error checking here, because
3680 anon names are unique throughout the compilation. */
3681 if (TYPE_IDENTIFIER (TREE_VALUE (tail
)) == name
)
3682 return TREE_VALUE (tail
);
3685 for (tail
= level
->tags
; tail
; tail
= TREE_CHAIN (tail
))
3687 if (TREE_PURPOSE (tail
) == name
)
3689 enum tree_code code
= TREE_CODE (TREE_VALUE (tail
));
3690 /* Should tighten this up; it'll probably permit
3691 UNION_TYPE and a struct template, for example. */
3693 && !(form
!= ENUMERAL_TYPE
3694 && (code
== TEMPLATE_DECL
3695 || code
== UNINSTANTIATED_P_TYPE
)))
3698 /* Definition isn't the kind we were looking for. */
3699 cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail
),
3702 return TREE_VALUE (tail
);
3705 if (thislevel_only
&& ! level
->tag_transparent
)
3707 if (current_class_type
&& level
->level_chain
== global_binding_level
)
3709 /* Try looking in this class's tags before heading into
3710 global binding level. */
3711 tree context
= current_class_type
;
3714 switch (TREE_CODE_CLASS (TREE_CODE (context
)))
3718 these_tags
= CLASSTYPE_TAGS (context
);
3719 if (ANON_AGGRNAME_P (name
))
3722 if (TYPE_IDENTIFIER (TREE_VALUE (these_tags
))
3724 return TREE_VALUE (tail
);
3725 these_tags
= TREE_CHAIN (these_tags
);
3730 if (TREE_PURPOSE (these_tags
) == name
)
3732 if (TREE_CODE (TREE_VALUE (these_tags
)) != form
)
3734 cp_error ("`%#D' redeclared as %C in class scope",
3735 TREE_VALUE (tail
), form
);
3737 return TREE_VALUE (tail
);
3739 these_tags
= TREE_CHAIN (these_tags
);
3741 /* If this type is not yet complete, then don't
3742 look at its context. */
3743 if (TYPE_SIZE (context
) == NULL_TREE
)
3745 /* Go to next enclosing type, if any. */
3746 context
= DECL_CONTEXT (TYPE_NAME (context
));
3749 context
= DECL_CONTEXT (context
);
3752 my_friendly_abort (10);
3764 set_current_level_tags_transparency (tags_transparent
)
3765 int tags_transparent
;
3767 current_binding_level
->tag_transparent
= tags_transparent
;
3770 /* Given a type, find the tag that was defined for it and return the tag name.
3771 Otherwise return 0. However, the value can never be 0
3772 in the cases in which this is used.
3774 C++: If NAME is non-zero, this is the new name to install. This is
3775 done when replacing anonymous tags with real tag names. */
3778 lookup_tag_reverse (type
, name
)
3782 register struct binding_level
*level
;
3784 for (level
= current_binding_level
; level
; level
= level
->level_chain
)
3787 for (tail
= level
->tags
; tail
; tail
= TREE_CHAIN (tail
))
3789 if (TREE_VALUE (tail
) == type
)
3792 TREE_PURPOSE (tail
) = name
;
3793 return TREE_PURPOSE (tail
);
3800 /* Given type TYPE which was not declared in C++ language context,
3801 attempt to find a name by which it is referred. */
3803 typedecl_for_tag (tag
)
3806 struct binding_level
*b
= current_binding_level
;
3808 if (TREE_CODE (TYPE_NAME (tag
)) == TYPE_DECL
)
3809 return TYPE_NAME (tag
);
3813 tree decls
= b
->names
;
3816 if (TREE_CODE (decls
) == TYPE_DECL
&& TREE_TYPE (decls
) == tag
)
3818 decls
= TREE_CHAIN (decls
);
3827 /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
3828 Return the type value, or NULL_TREE if not found. */
3830 lookup_nested_type (type
, context
)
3834 if (context
== NULL_TREE
)
3838 switch (TREE_CODE (context
))
3842 tree ctype
= TREE_TYPE (context
);
3843 tree match
= value_member (type
, CLASSTYPE_TAGS (ctype
));
3845 return TREE_VALUE (match
);
3846 context
= DECL_CONTEXT (context
);
3848 /* When we have a nested class whose member functions have
3849 local types (e.g., a set of enums), we'll arrive here
3850 with the DECL_CONTEXT as the actual RECORD_TYPE node for
3851 the enclosing class. Instead, we want to make sure we
3852 come back in here with the TYPE_DECL, not the RECORD_TYPE. */
3853 if (context
&& TREE_CODE (context
) == RECORD_TYPE
)
3854 context
= TREE_CHAIN (context
);
3858 return TYPE_IDENTIFIER (type
) ?
3859 lookup_name (TYPE_IDENTIFIER (type
), 1) : NULL_TREE
;
3862 my_friendly_abort (12);
3868 /* Look up NAME in the current binding level and its superiors in the
3869 namespace of variables, functions and typedefs. Return a ..._DECL
3870 node of some kind representing its definition if there is only one
3871 such declaration, or return a TREE_LIST with all the overloaded
3872 definitions if there are many, or return 0 if it is undefined.
3874 If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
3875 If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
3876 Otherwise we prefer non-TYPE_DECLs. */
3879 lookup_name_real (name
, prefer_type
, nonclass
)
3881 int prefer_type
, nonclass
;
3886 if (prefer_type
== -2)
3888 extern int looking_for_typename
;
3891 prefer_type
= looking_for_typename
;
3893 if (got_scope
!= NULL_TREE
)
3895 if (got_scope
== void_type_node
)
3896 val
= IDENTIFIER_GLOBAL_VALUE (name
);
3897 else if (TREE_CODE (got_scope
) == TEMPLATE_TYPE_PARM
3898 /* TFIXME -- don't do this for UPTs in new model. */
3899 || TREE_CODE (got_scope
) == UNINSTANTIATED_P_TYPE
)
3901 if (prefer_type
> 0)
3902 val
= create_nested_upt (got_scope
, name
);
3906 else if (! IS_AGGR_TYPE (got_scope
))
3907 /* Someone else will give an error about this if needed. */
3909 else if (TYPE_BEING_DEFINED (got_scope
))
3911 val
= IDENTIFIER_CLASS_VALUE (name
);
3912 if (val
&& DECL_CONTEXT (val
) != got_scope
)
3914 struct binding_level
*b
= class_binding_level
;
3915 for (val
= NULL_TREE
; b
; b
= b
->level_chain
)
3917 tree t
= purpose_member (name
, b
->class_shadowed
);
3918 if (t
&& TREE_VALUE (t
)
3919 && DECL_CONTEXT (TREE_VALUE (t
)) == got_scope
)
3921 val
= TREE_VALUE (t
);
3926 if (val
== NULL_TREE
3927 && CLASSTYPE_LOCAL_TYPEDECLS (got_scope
))
3928 val
= lookup_field (got_scope
, name
, 0, 1);
3930 else if (got_scope
== current_class_type
)
3931 val
= IDENTIFIER_CLASS_VALUE (name
);
3933 val
= lookup_field (got_scope
, name
, 0, 0);
3939 if (current_binding_level
!= global_binding_level
3940 && IDENTIFIER_LOCAL_VALUE (name
))
3941 val
= IDENTIFIER_LOCAL_VALUE (name
);
3942 /* In C++ class fields are between local and global scope,
3943 just before the global scope. */
3944 else if (current_class_type
&& ! nonclass
)
3946 val
= IDENTIFIER_CLASS_VALUE (name
);
3947 if (val
== NULL_TREE
3948 && TYPE_BEING_DEFINED (current_class_type
)
3949 && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type
))
3950 /* Try to find values from base classes if we are presently
3951 defining a type. We are presently only interested in
3953 val
= lookup_field (current_class_type
, name
, 0, 1);
3955 /* yylex() calls this with -2, since we should never start digging for
3956 the nested name at the point where we haven't even, for example,
3957 created the COMPONENT_REF or anything like that. */
3958 if (val
== NULL_TREE
)
3959 val
= lookup_nested_field (name
, ! yylex
);
3961 if (val
== NULL_TREE
)
3962 val
= IDENTIFIER_GLOBAL_VALUE (name
);
3965 val
= IDENTIFIER_GLOBAL_VALUE (name
);
3970 if ((TREE_CODE (val
) == TEMPLATE_DECL
&& looking_for_template
)
3971 || TREE_CODE (val
) == TYPE_DECL
|| prefer_type
<= 0)
3974 if (IDENTIFIER_HAS_TYPE_VALUE (name
))
3975 return TYPE_NAME (IDENTIFIER_TYPE_VALUE (name
));
3977 if (TREE_TYPE (val
) == error_mark_node
)
3978 return error_mark_node
;
3985 lookup_name_nonclass (name
)
3988 return lookup_name_real (name
, 0, 1);
3992 lookup_name (name
, prefer_type
)
3996 return lookup_name_real (name
, prefer_type
, 0);
3999 /* Similar to `lookup_name' but look only at current binding level. */
4002 lookup_name_current_level (name
)
4005 register tree t
= NULL_TREE
;
4007 if (current_binding_level
== global_binding_level
)
4009 t
= IDENTIFIER_GLOBAL_VALUE (name
);
4011 /* extern "C" function() */
4012 if (t
!= NULL_TREE
&& TREE_CODE (t
) == TREE_LIST
)
4015 else if (IDENTIFIER_LOCAL_VALUE (name
) != NULL_TREE
)
4017 struct binding_level
*b
= current_binding_level
;
4020 for (t
= b
->names
; t
; t
= TREE_CHAIN (t
))
4021 if (DECL_NAME (t
) == name
)
4035 /* Arrange for the user to get a source line number, even when the
4036 compiler is going down in flames, so that she at least has a
4037 chance of working around problems in the compiler. We used to
4038 call error(), but that let the segmentation fault continue
4039 through; now, it's much more passive by asking them to send the
4040 maintainers mail about the problem. */
4046 signal (SIGSEGV
, SIG_DFL
);
4048 signal (SIGIOT
, SIG_DFL
);
4051 signal (SIGILL
, SIG_DFL
);
4054 signal (SIGABRT
, SIG_DFL
);
4057 signal (SIGBUS
, SIG_DFL
);
4059 my_friendly_abort (0);
4062 /* Array for holding types considered "built-in". These types
4063 are output in the module in which `main' is defined. */
4064 static tree
*builtin_type_tdescs_arr
;
4065 static int builtin_type_tdescs_len
, builtin_type_tdescs_max
;
4067 /* Push the declarations of builtin types into the namespace.
4068 RID_INDEX, if < RID_MAX is the index of the builtin type
4069 in the array RID_POINTERS. NAME is the name used when looking
4070 up the builtin type. TYPE is the _TYPE node for the builtin type. */
4073 record_builtin_type (rid_index
, name
, type
)
4078 tree rname
= NULL_TREE
, tname
= NULL_TREE
;
4081 if ((int) rid_index
< (int) RID_MAX
)
4082 rname
= ridpointers
[(int) rid_index
];
4084 tname
= get_identifier (name
);
4086 TYPE_BUILT_IN (type
) = 1;
4090 #if 0 /* not yet, should get fixed properly later */
4091 tdecl
= pushdecl (make_type_decl (tname
, type
));
4093 tdecl
= pushdecl (build_decl (TYPE_DECL
, tname
, type
));
4095 set_identifier_type_value (tname
, NULL_TREE
);
4096 if ((int) rid_index
< (int) RID_MAX
)
4097 IDENTIFIER_GLOBAL_VALUE (tname
) = tdecl
;
4099 if (rname
!= NULL_TREE
)
4101 if (tname
!= NULL_TREE
)
4103 set_identifier_type_value (rname
, NULL_TREE
);
4104 IDENTIFIER_GLOBAL_VALUE (rname
) = tdecl
;
4108 #if 0 /* not yet, should get fixed properly later */
4109 tdecl
= pushdecl (make_type_decl (rname
, type
));
4111 tdecl
= pushdecl (build_decl (TYPE_DECL
, rname
, type
));
4113 set_identifier_type_value (rname
, NULL_TREE
);
4119 if (builtin_type_tdescs_len
+5 >= builtin_type_tdescs_max
)
4121 builtin_type_tdescs_max
*= 2;
4122 builtin_type_tdescs_arr
4123 = (tree
*)xrealloc (builtin_type_tdescs_arr
,
4124 builtin_type_tdescs_max
* sizeof (tree
));
4126 builtin_type_tdescs_arr
[builtin_type_tdescs_len
++] = type
;
4127 if (TREE_CODE (type
) != POINTER_TYPE
)
4129 builtin_type_tdescs_arr
[builtin_type_tdescs_len
++]
4130 = build_pointer_type (type
);
4131 builtin_type_tdescs_arr
[builtin_type_tdescs_len
++]
4132 = build_pointer_type (build_type_variant (type
, 1, 0));
4134 if (TREE_CODE (type
) != VOID_TYPE
)
4136 builtin_type_tdescs_arr
[builtin_type_tdescs_len
++]
4137 = build_reference_type (type
);
4138 builtin_type_tdescs_arr
[builtin_type_tdescs_len
++]
4139 = build_reference_type (build_type_variant (type
, 1, 0));
4145 output_builtin_tdesc_entries ()
4147 extern struct obstack permanent_obstack
;
4149 /* If there's more than one main in this file, don't crash. */
4150 if (builtin_type_tdescs_arr
== 0)
4153 push_obstacks (&permanent_obstack
, &permanent_obstack
);
4154 while (builtin_type_tdescs_len
> 0)
4156 tree type
= builtin_type_tdescs_arr
[--builtin_type_tdescs_len
];
4157 tree tdesc
= build_t_desc (type
, 0);
4158 TREE_ASM_WRITTEN (tdesc
) = 0;
4159 build_t_desc (type
, 2);
4161 free (builtin_type_tdescs_arr
);
4162 builtin_type_tdescs_arr
= 0;
4166 /* Push overloaded decl, in global scope, with one argument so it
4167 can be used as a callback from define_function. */
4169 push_overloaded_decl_1 (x
)
4172 push_overloaded_decl (x
, 0);
4175 /* Create the predefined scalar types of C,
4176 and some nodes representing standard constants (0, 1, (void *)0).
4177 Initialize the global binding level.
4178 Make definitions for built-in primitive functions. */
4181 init_decl_processing ()
4184 register tree endlink
, int_endlink
, double_endlink
, ptr_endlink
;
4186 /* Either char* or void*. */
4187 tree traditional_ptr_type_node
;
4188 /* Data type of memcpy. */
4190 #if 0 /* Not yet. */
4191 /* Data type of strncpy. */
4194 int wchar_type_size
;
4196 tree array_domain_type
;
4198 /* Have to make these distinct before we try using them. */
4199 lang_name_cplusplus
= get_identifier ("C++");
4200 lang_name_c
= get_identifier ("C");
4202 if (flag_ansi
|| pedantic
)
4203 strict_prototypes_lang_c
= strict_prototypes_lang_cplusplus
;
4206 current_lang_name
= lang_name_c
;
4208 current_function_decl
= NULL_TREE
;
4209 named_labels
= NULL_TREE
;
4210 named_label_uses
= NULL_TREE
;
4211 current_binding_level
= NULL_BINDING_LEVEL
;
4212 free_binding_level
= NULL_BINDING_LEVEL
;
4214 /* Because most segmentation signals can be traced back into user
4215 code, catch them and at least give the user a chance of working
4216 around compiler bugs. */
4217 signal (SIGSEGV
, signal_catch
);
4219 /* We will also catch aborts in the back-end through signal_catch and
4220 give the user a chance to see where the error might be, and to defeat
4221 aborts in the back-end when there have been errors previously in their
4224 signal (SIGIOT
, signal_catch
);
4227 signal (SIGILL
, signal_catch
);
4230 signal (SIGABRT
, signal_catch
);
4233 signal (SIGBUS
, signal_catch
);
4236 gcc_obstack_init (&decl_obstack
);
4239 builtin_type_tdescs_max
= 100;
4240 builtin_type_tdescs_arr
= (tree
*)xmalloc (100 * sizeof (tree
));
4243 /* Must lay these out before anything else gets laid out. */
4244 error_mark_node
= make_node (ERROR_MARK
);
4245 TREE_PERMANENT (error_mark_node
) = 1;
4246 TREE_TYPE (error_mark_node
) = error_mark_node
;
4247 error_mark_list
= build_tree_list (error_mark_node
, error_mark_node
);
4248 TREE_TYPE (error_mark_list
) = error_mark_node
;
4250 /* Make the binding_level structure for global names. */
4252 global_binding_level
= current_binding_level
;
4254 this_identifier
= get_identifier (THIS_NAME
);
4255 in_charge_identifier
= get_identifier (IN_CHARGE_NAME
);
4256 pfn_identifier
= get_identifier (VTABLE_PFN_NAME
);
4257 index_identifier
= get_identifier (VTABLE_INDEX_NAME
);
4258 delta_identifier
= get_identifier (VTABLE_DELTA_NAME
);
4259 delta2_identifier
= get_identifier (VTABLE_DELTA2_NAME
);
4260 pfn_or_delta2_identifier
= get_identifier ("__pfn_or_delta2");
4262 /* Define `int' and `char' first so that dbx will output them first. */
4264 integer_type_node
= make_signed_type (INT_TYPE_SIZE
);
4265 record_builtin_type (RID_INT
, NULL_PTR
, integer_type_node
);
4267 /* Define `char', which is like either `signed char' or `unsigned char'
4268 but not the same as either. */
4272 ? make_signed_type (CHAR_TYPE_SIZE
)
4273 : make_unsigned_type (CHAR_TYPE_SIZE
));
4274 record_builtin_type (RID_CHAR
, "char", char_type_node
);
4276 long_integer_type_node
= make_signed_type (LONG_TYPE_SIZE
);
4277 record_builtin_type (RID_LONG
, "long int", long_integer_type_node
);
4279 unsigned_type_node
= make_unsigned_type (INT_TYPE_SIZE
);
4280 record_builtin_type (RID_UNSIGNED
, "unsigned int", unsigned_type_node
);
4282 long_unsigned_type_node
= make_unsigned_type (LONG_TYPE_SIZE
);
4283 record_builtin_type (RID_MAX
, "long unsigned int", long_unsigned_type_node
);
4284 record_builtin_type (RID_MAX
, "unsigned long", long_unsigned_type_node
);
4286 long_long_integer_type_node
= make_signed_type (LONG_LONG_TYPE_SIZE
);
4287 record_builtin_type (RID_MAX
, "long long int", long_long_integer_type_node
);
4289 long_long_unsigned_type_node
= make_unsigned_type (LONG_LONG_TYPE_SIZE
);
4290 record_builtin_type (RID_MAX
, "long long unsigned int",
4291 long_long_unsigned_type_node
);
4292 record_builtin_type (RID_MAX
, "long long unsigned",
4293 long_long_unsigned_type_node
);
4295 /* `unsigned long' is the standard type for sizeof.
4296 Traditionally, use a signed type.
4297 Note that stddef.h uses `unsigned long',
4298 and this must agree, even of long and int are the same size. */
4300 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE
)));
4301 if (flag_traditional
&& TREE_UNSIGNED (sizetype
))
4302 sizetype
= signed_type (sizetype
);
4305 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE
)));
4307 TREE_TYPE (TYPE_SIZE (integer_type_node
)) = sizetype
;
4308 TREE_TYPE (TYPE_SIZE (char_type_node
)) = sizetype
;
4309 TREE_TYPE (TYPE_SIZE (unsigned_type_node
)) = sizetype
;
4310 TREE_TYPE (TYPE_SIZE (long_unsigned_type_node
)) = sizetype
;
4311 TREE_TYPE (TYPE_SIZE (long_integer_type_node
)) = sizetype
;
4312 TREE_TYPE (TYPE_SIZE (long_long_integer_type_node
)) = sizetype
;
4313 TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node
)) = sizetype
;
4315 short_integer_type_node
= make_signed_type (SHORT_TYPE_SIZE
);
4316 record_builtin_type (RID_SHORT
, "short int", short_integer_type_node
);
4317 short_unsigned_type_node
= make_unsigned_type (SHORT_TYPE_SIZE
);
4318 record_builtin_type (RID_MAX
, "short unsigned int", short_unsigned_type_node
);
4319 record_builtin_type (RID_MAX
, "unsigned short", short_unsigned_type_node
);
4321 /* Define both `signed char' and `unsigned char'. */
4322 signed_char_type_node
= make_signed_type (CHAR_TYPE_SIZE
);
4323 record_builtin_type (RID_MAX
, "signed char", signed_char_type_node
);
4324 unsigned_char_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
4325 record_builtin_type (RID_MAX
, "unsigned char", unsigned_char_type_node
);
4327 /* These are types that type_for_size and type_for_mode use. */
4328 intQI_type_node
= make_signed_type (GET_MODE_BITSIZE (QImode
));
4329 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intQI_type_node
));
4330 intHI_type_node
= make_signed_type (GET_MODE_BITSIZE (HImode
));
4331 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intHI_type_node
));
4332 intSI_type_node
= make_signed_type (GET_MODE_BITSIZE (SImode
));
4333 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intSI_type_node
));
4334 intDI_type_node
= make_signed_type (GET_MODE_BITSIZE (DImode
));
4335 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, intDI_type_node
));
4336 unsigned_intQI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (QImode
));
4337 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intQI_type_node
));
4338 unsigned_intHI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (HImode
));
4339 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intHI_type_node
));
4340 unsigned_intSI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (SImode
));
4341 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intSI_type_node
));
4342 unsigned_intDI_type_node
= make_unsigned_type (GET_MODE_BITSIZE (DImode
));
4343 pushdecl (build_decl (TYPE_DECL
, NULL_TREE
, unsigned_intDI_type_node
));
4345 float_type_node
= make_node (REAL_TYPE
);
4346 TYPE_PRECISION (float_type_node
) = FLOAT_TYPE_SIZE
;
4347 record_builtin_type (RID_FLOAT
, NULL_PTR
, float_type_node
);
4348 layout_type (float_type_node
);
4350 double_type_node
= make_node (REAL_TYPE
);
4351 if (flag_short_double
)
4352 TYPE_PRECISION (double_type_node
) = FLOAT_TYPE_SIZE
;
4354 TYPE_PRECISION (double_type_node
) = DOUBLE_TYPE_SIZE
;
4355 record_builtin_type (RID_DOUBLE
, NULL_PTR
, double_type_node
);
4356 layout_type (double_type_node
);
4358 long_double_type_node
= make_node (REAL_TYPE
);
4359 TYPE_PRECISION (long_double_type_node
) = LONG_DOUBLE_TYPE_SIZE
;
4360 record_builtin_type (RID_MAX
, "long double", long_double_type_node
);
4361 layout_type (long_double_type_node
);
4363 integer_zero_node
= build_int_2 (0, 0);
4364 TREE_TYPE (integer_zero_node
) = integer_type_node
;
4365 integer_one_node
= build_int_2 (1, 0);
4366 TREE_TYPE (integer_one_node
) = integer_type_node
;
4367 integer_two_node
= build_int_2 (2, 0);
4368 TREE_TYPE (integer_two_node
) = integer_type_node
;
4369 integer_three_node
= build_int_2 (3, 0);
4370 TREE_TYPE (integer_three_node
) = integer_type_node
;
4372 bool_type_node
= make_unsigned_type (CHAR_TYPE_SIZE
);
4373 TREE_SET_CODE (bool_type_node
, BOOLEAN_TYPE
);
4374 record_builtin_type (RID_BOOL
, "bool", bool_type_node
);
4375 false_node
= build_int_2 (0, 0);
4376 TREE_TYPE (false_node
) = bool_type_node
;
4377 true_node
= build_int_2 (1, 0);
4378 TREE_TYPE (true_node
) = bool_type_node
;
4380 /* These are needed by stor-layout.c. */
4381 size_zero_node
= size_int (0);
4382 size_one_node
= size_int (1);
4384 void_type_node
= make_node (VOID_TYPE
);
4385 record_builtin_type (RID_VOID
, NULL_PTR
, void_type_node
);
4386 layout_type (void_type_node
); /* Uses integer_zero_node. */
4387 void_list_node
= build_tree_list (NULL_TREE
, void_type_node
);
4388 TREE_PARMLIST (void_list_node
) = 1;
4390 null_pointer_node
= build_int_2 (0, 0);
4391 TREE_TYPE (null_pointer_node
) = build_pointer_type (void_type_node
);
4392 layout_type (TREE_TYPE (null_pointer_node
));
4394 /* Used for expressions that do nothing, but are not errors. */
4395 void_zero_node
= build_int_2 (0, 0);
4396 TREE_TYPE (void_zero_node
) = void_type_node
;
4398 string_type_node
= build_pointer_type (char_type_node
);
4399 const_string_type_node
=
4400 build_pointer_type (build_type_variant (char_type_node
, 1, 0));
4401 record_builtin_type (RID_MAX
, NULL_PTR
, string_type_node
);
4403 /* Make a type to be the domain of a few array types
4404 whose domains don't really matter.
4405 200 is small enough that it always fits in size_t
4406 and large enough that it can hold most function names for the
4407 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4408 array_domain_type
= build_index_type (build_int_2 (200, 0));
4410 /* make a type for arrays of characters.
4411 With luck nothing will ever really depend on the length of this
4413 char_array_type_node
4414 = build_array_type (char_type_node
, array_domain_type
);
4415 /* Likewise for arrays of ints. */
4417 = build_array_type (integer_type_node
, array_domain_type
);
4419 /* This is just some anonymous class type. Nobody should ever
4420 need to look inside this envelope. */
4421 class_star_type_node
= build_pointer_type (make_lang_type (RECORD_TYPE
));
4423 default_function_type
4424 = build_function_type (integer_type_node
, NULL_TREE
);
4425 build_pointer_type (default_function_type
);
4427 ptr_type_node
= build_pointer_type (void_type_node
);
4428 const_ptr_type_node
=
4429 build_pointer_type (build_type_variant (void_type_node
, 1, 0));
4430 record_builtin_type (RID_MAX
, NULL_PTR
, ptr_type_node
);
4431 endlink
= void_list_node
;
4432 int_endlink
= tree_cons (NULL_TREE
, integer_type_node
, endlink
);
4433 double_endlink
= tree_cons (NULL_TREE
, double_type_node
, endlink
);
4434 ptr_endlink
= tree_cons (NULL_TREE
, ptr_type_node
, endlink
);
4437 = build_function_type (double_type_node
, double_endlink
);
4439 double_ftype_double_double
4440 = build_function_type (double_type_node
,
4441 tree_cons (NULL_TREE
, double_type_node
,
4445 = build_function_type (integer_type_node
, int_endlink
);
4448 = build_function_type (long_integer_type_node
,
4449 tree_cons (NULL_TREE
, long_integer_type_node
,
4452 void_ftype_ptr_ptr_int
4453 = build_function_type (void_type_node
,
4454 tree_cons (NULL_TREE
, ptr_type_node
,
4455 tree_cons (NULL_TREE
, ptr_type_node
,
4458 int_ftype_cptr_cptr_sizet
4459 = build_function_type (integer_type_node
,
4460 tree_cons (NULL_TREE
, const_ptr_type_node
,
4461 tree_cons (NULL_TREE
, const_ptr_type_node
,
4462 tree_cons (NULL_TREE
,
4466 void_ftype_ptr_int_int
4467 = build_function_type (void_type_node
,
4468 tree_cons (NULL_TREE
, ptr_type_node
,
4469 tree_cons (NULL_TREE
, integer_type_node
,
4472 string_ftype_ptr_ptr
/* strcpy prototype */
4473 = build_function_type (string_type_node
,
4474 tree_cons (NULL_TREE
, string_type_node
,
4475 tree_cons (NULL_TREE
,
4476 const_string_type_node
,
4481 strncpy_ftype
/* strncpy prototype */
4482 = build_function_type (string_type_node
,
4483 tree_cons (NULL_TREE
, string_type_node
,
4484 tree_cons (NULL_TREE
, const_string_type_node
,
4485 tree_cons (NULL_TREE
,
4490 int_ftype_string_string
/* strcmp prototype */
4491 = build_function_type (integer_type_node
,
4492 tree_cons (NULL_TREE
, const_string_type_node
,
4493 tree_cons (NULL_TREE
,
4494 const_string_type_node
,
4497 sizet_ftype_string
/* strlen prototype */
4498 = build_function_type (sizetype
,
4499 tree_cons (NULL_TREE
, const_string_type_node
,
4502 traditional_ptr_type_node
4503 = (flag_traditional
? string_type_node
: ptr_type_node
);
4505 memcpy_ftype
/* memcpy prototype */
4506 = build_function_type (traditional_ptr_type_node
,
4507 tree_cons (NULL_TREE
, ptr_type_node
,
4508 tree_cons (NULL_TREE
, const_ptr_type_node
,
4509 tree_cons (NULL_TREE
,
4513 if (flag_huge_objects
)
4514 delta_type_node
= long_integer_type_node
;
4516 delta_type_node
= short_integer_type_node
;
4518 builtin_function ("__builtin_constant_p", int_ftype_int
,
4519 BUILT_IN_CONSTANT_P
, NULL_PTR
);
4521 builtin_return_address_fndecl
=
4522 builtin_function ("__builtin_return_address",
4523 build_function_type (ptr_type_node
,
4524 tree_cons (NULL_TREE
,
4527 BUILT_IN_RETURN_ADDRESS
, NULL_PTR
);
4529 builtin_function ("__builtin_frame_address",
4530 build_function_type (ptr_type_node
,
4531 tree_cons (NULL_TREE
,
4534 BUILT_IN_FRAME_ADDRESS
, NULL_PTR
);
4537 builtin_function ("__builtin_alloca",
4538 build_function_type (ptr_type_node
,
4539 tree_cons (NULL_TREE
,
4542 BUILT_IN_ALLOCA
, "alloca");
4544 builtin_function ("alloca",
4545 build_function_type (ptr_type_node
,
4546 tree_cons (NULL_TREE
,
4549 BUILT_IN_ALLOCA
, NULL_PTR
);
4552 builtin_function ("__builtin_abs", int_ftype_int
,
4553 BUILT_IN_ABS
, NULL_PTR
);
4554 builtin_function ("__builtin_fabs", double_ftype_double
,
4555 BUILT_IN_FABS
, NULL_PTR
);
4556 builtin_function ("__builtin_labs", long_ftype_long
,
4557 BUILT_IN_LABS
, NULL_PTR
);
4558 builtin_function ("__builtin_ffs", int_ftype_int
,
4559 BUILT_IN_FFS
, NULL_PTR
);
4560 builtin_function ("__builtin_fsqrt", double_ftype_double
,
4561 BUILT_IN_FSQRT
, NULL_PTR
);
4562 builtin_function ("__builtin_sin", double_ftype_double
,
4563 BUILT_IN_SIN
, "sin");
4564 builtin_function ("__builtin_cos", double_ftype_double
,
4565 BUILT_IN_COS
, "cos");
4566 builtin_function ("__builtin_saveregs",
4567 build_function_type (ptr_type_node
, NULL_TREE
),
4568 BUILT_IN_SAVEREGS
, NULL_PTR
);
4569 /* EXPAND_BUILTIN_VARARGS is obsolete. */
4571 builtin_function ("__builtin_varargs",
4572 build_function_type (ptr_type_node
,
4573 tree_cons (NULL_TREE
,
4576 BUILT_IN_VARARGS
, NULL_PTR
);
4578 builtin_function ("__builtin_classify_type", default_function_type
,
4579 BUILT_IN_CLASSIFY_TYPE
, NULL_PTR
);
4580 builtin_function ("__builtin_next_arg",
4581 build_function_type (ptr_type_node
, NULL_TREE
),
4582 BUILT_IN_NEXT_ARG
, NULL_PTR
);
4583 builtin_function ("__builtin_args_info",
4584 build_function_type (integer_type_node
,
4585 tree_cons (NULL_TREE
,
4588 BUILT_IN_ARGS_INFO
, NULL_PTR
);
4590 /* Untyped call and return. */
4591 builtin_function ("__builtin_apply_args",
4592 build_function_type (ptr_type_node
, NULL_TREE
),
4593 BUILT_IN_APPLY_ARGS
, NULL_PTR
);
4595 temp
= tree_cons (NULL_TREE
,
4596 build_pointer_type (build_function_type (void_type_node
,
4598 tree_cons (NULL_TREE
,
4600 tree_cons (NULL_TREE
,
4603 builtin_function ("__builtin_apply",
4604 build_function_type (ptr_type_node
, temp
),
4605 BUILT_IN_APPLY
, NULL_PTR
);
4606 builtin_function ("__builtin_return",
4607 build_function_type (void_type_node
,
4608 tree_cons (NULL_TREE
,
4611 BUILT_IN_RETURN
, NULL_PTR
);
4613 /* Currently under experimentation. */
4614 builtin_function ("__builtin_memcpy", memcpy_ftype
,
4615 BUILT_IN_MEMCPY
, "memcpy");
4616 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet
,
4617 BUILT_IN_MEMCMP
, "memcmp");
4618 builtin_function ("__builtin_strcmp", int_ftype_string_string
,
4619 BUILT_IN_STRCMP
, "strcmp");
4620 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr
,
4621 BUILT_IN_STRCPY
, "strcpy");
4624 builtin_function ("__builtin_strncpy", strncpy_ftype
,
4625 BUILT_IN_STRNCPY
, "strncpy");
4627 builtin_function ("__builtin_strlen", sizet_ftype_string
,
4628 BUILT_IN_STRLEN
, "strlen");
4630 if (!flag_no_builtin
)
4632 #if 0 /* These do not work well with libg++. */
4633 builtin_function ("abs", int_ftype_int
, BUILT_IN_ABS
, NULL_PTR
);
4634 builtin_function ("fabs", double_ftype_double
, BUILT_IN_FABS
, NULL_PTR
);
4635 builtin_function ("labs", long_ftype_long
, BUILT_IN_LABS
, NULL_PTR
);
4637 builtin_function ("memcpy", memcpy_ftype
, BUILT_IN_MEMCPY
, NULL_PTR
);
4638 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet
, BUILT_IN_MEMCMP
,
4640 builtin_function ("strcmp", int_ftype_string_string
, BUILT_IN_STRCMP
, NULL_PTR
);
4641 builtin_function ("strcpy", string_ftype_ptr_ptr
, BUILT_IN_STRCPY
,
4645 builtin_function ("strncpy", strncpy_ftype
, BUILT_IN_STRNCPY
, NULL_PTR
);
4647 builtin_function ("strlen", sizet_ftype_string
, BUILT_IN_STRLEN
, NULL_PTR
);
4648 builtin_function ("sin", double_ftype_double
, BUILT_IN_SIN
, NULL_PTR
);
4649 builtin_function ("cos", double_ftype_double
, BUILT_IN_COS
, NULL_PTR
);
4653 /* Support for these has not been written in either expand_builtin
4654 or build_function_call. */
4655 builtin_function ("__builtin_div", default_ftype
, BUILT_IN_DIV
, 0);
4656 builtin_function ("__builtin_ldiv", default_ftype
, BUILT_IN_LDIV
, 0);
4657 builtin_function ("__builtin_ffloor", double_ftype_double
, BUILT_IN_FFLOOR
,
4659 builtin_function ("__builtin_fceil", double_ftype_double
, BUILT_IN_FCEIL
, 0);
4660 builtin_function ("__builtin_fmod", double_ftype_double_double
,
4662 builtin_function ("__builtin_frem", double_ftype_double_double
,
4664 builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int
, BUILT_IN_MEMSET
,
4666 builtin_function ("__builtin_getexp", double_ftype_double
, BUILT_IN_GETEXP
,
4668 builtin_function ("__builtin_getman", double_ftype_double
, BUILT_IN_GETMAN
,
4672 /* C++ extensions */
4674 unknown_type_node
= make_node (UNKNOWN_TYPE
);
4675 #if 0 /* not yet, should get fixed properly later */
4676 pushdecl (make_type_decl (get_identifier ("unknown type"),
4677 unknown_type_node
));
4679 decl
= pushdecl (build_decl (TYPE_DECL
, get_identifier ("unknown type"),
4680 unknown_type_node
));
4681 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
4682 DECL_IGNORED_P (decl
) = 1;
4683 TYPE_DECL_SUPPRESS_DEBUG (decl
) = 1;
4685 TYPE_SIZE (unknown_type_node
) = TYPE_SIZE (void_type_node
);
4686 TYPE_ALIGN (unknown_type_node
) = 1;
4687 TYPE_MODE (unknown_type_node
) = TYPE_MODE (void_type_node
);
4688 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
4689 TREE_TYPE (unknown_type_node
) = unknown_type_node
;
4690 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
4691 TYPE_POINTER_TO (unknown_type_node
) = unknown_type_node
;
4692 TYPE_REFERENCE_TO (unknown_type_node
) = unknown_type_node
;
4694 /* This is for handling opaque types in signatures. */
4695 opaque_type_node
= copy_node (ptr_type_node
);
4696 TYPE_MAIN_VARIANT (opaque_type_node
) = opaque_type_node
;
4697 record_builtin_type (RID_MAX
, 0, opaque_type_node
);
4699 /* This is special for C++ so functions can be overloaded. */
4701 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE
)));
4702 wchar_type_size
= TYPE_PRECISION (wchar_type_node
);
4703 signed_wchar_type_node
= make_signed_type (wchar_type_size
);
4704 unsigned_wchar_type_node
= make_unsigned_type (wchar_type_size
);
4706 = TREE_UNSIGNED (wchar_type_node
)
4707 ? unsigned_wchar_type_node
4708 : signed_wchar_type_node
;
4709 record_builtin_type (RID_WCHAR
, "__wchar_t", wchar_type_node
);
4711 /* This is for wide string constants. */
4712 wchar_array_type_node
4713 = build_array_type (wchar_type_node
, array_domain_type
);
4715 /* This is a hack that should go away when we deliver the
4719 builtin_function ("__gc_main", default_function_type
, NOT_BUILT_IN
, 0);
4720 pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
4723 if (flag_vtable_thunks
)
4725 /* Make sure we get a unique function type, so we can give
4726 its pointer type a name. (This wins for gdb.) */
4727 tree vfunc_type
= make_node (FUNCTION_TYPE
);
4728 TREE_TYPE (vfunc_type
) = integer_type_node
;
4729 TYPE_ARG_TYPES (vfunc_type
) = NULL_TREE
;
4730 layout_type (vfunc_type
);
4732 vtable_entry_type
= build_pointer_type (vfunc_type
);
4736 vtable_entry_type
= make_lang_type (RECORD_TYPE
);
4737 fields
[0] = build_lang_field_decl (FIELD_DECL
, delta_identifier
,
4739 fields
[1] = build_lang_field_decl (FIELD_DECL
, index_identifier
,
4741 fields
[2] = build_lang_field_decl (FIELD_DECL
, pfn_identifier
,
4743 finish_builtin_type (vtable_entry_type
, VTBL_PTR_TYPE
, fields
, 2,
4746 /* Make this part of an invisible union. */
4747 fields
[3] = copy_node (fields
[2]);
4748 TREE_TYPE (fields
[3]) = delta_type_node
;
4749 DECL_NAME (fields
[3]) = delta2_identifier
;
4750 DECL_MODE (fields
[3]) = TYPE_MODE (delta_type_node
);
4751 DECL_SIZE (fields
[3]) = TYPE_SIZE (delta_type_node
);
4752 TREE_UNSIGNED (fields
[3]) = 0;
4753 TREE_CHAIN (fields
[2]) = fields
[3];
4754 vtable_entry_type
= build_type_variant (vtable_entry_type
, 1, 0);
4756 record_builtin_type (RID_MAX
, VTBL_PTR_TYPE
, vtable_entry_type
);
4759 = build_array_type (vtable_entry_type
, NULL_TREE
);
4760 layout_type (vtbl_type_node
);
4761 vtbl_type_node
= c_build_type_variant (vtbl_type_node
, 1, 0);
4762 record_builtin_type (RID_MAX
, NULL_PTR
, vtbl_type_node
);
4764 /* Simplify life by making a "sigtable_entry_type". Give its
4765 fields names so that the debugger can use them. */
4767 if (flag_handle_signatures
)
4769 sigtable_entry_type
= make_lang_type (RECORD_TYPE
);
4770 fields
[0] = build_lang_field_decl (FIELD_DECL
,
4771 get_identifier (SIGTABLE_CODE_NAME
),
4772 short_integer_type_node
);
4773 fields
[1] = build_lang_field_decl (FIELD_DECL
,
4774 get_identifier (SIGTABLE_OFFSET_NAME
),
4775 short_integer_type_node
);
4776 fields
[2] = build_lang_field_decl (FIELD_DECL
,
4777 get_identifier (SIGTABLE_PFN_NAME
),
4779 finish_builtin_type (sigtable_entry_type
, SIGTABLE_PTR_TYPE
, fields
, 2,
4781 sigtable_entry_type
= build_type_variant (sigtable_entry_type
, 1, 0);
4782 record_builtin_type (RID_MAX
, SIGTABLE_PTR_TYPE
, sigtable_entry_type
);
4787 /* Must build __t_desc type. Currently, type descriptors look like this:
4794 struct __t_desc *points_to;
4795 int ivars_count, meths_count;
4796 struct __i_desc *ivars[];
4797 struct __m_desc *meths[];
4798 struct __t_desc *parents[];
4799 struct __t_desc *vbases[];
4803 ...as per Linton's paper. */
4805 __t_desc_type_node
= make_lang_type (RECORD_TYPE
);
4806 __i_desc_type_node
= make_lang_type (RECORD_TYPE
);
4807 __m_desc_type_node
= make_lang_type (RECORD_TYPE
);
4808 __t_desc_array_type
=
4809 build_array_type (TYPE_POINTER_TO (__t_desc_type_node
), NULL_TREE
);
4810 __i_desc_array_type
=
4811 build_array_type (TYPE_POINTER_TO (__i_desc_type_node
), NULL_TREE
);
4812 __m_desc_array_type
=
4813 build_array_type (TYPE_POINTER_TO (__m_desc_type_node
), NULL_TREE
);
4815 fields
[0] = build_lang_field_decl (FIELD_DECL
, get_identifier ("name"),
4817 fields
[1] = build_lang_field_decl (FIELD_DECL
, get_identifier ("size"),
4818 unsigned_type_node
);
4819 fields
[2] = build_lang_field_decl (FIELD_DECL
, get_identifier ("bits"),
4820 unsigned_type_node
);
4821 fields
[3] = build_lang_field_decl (FIELD_DECL
,
4822 get_identifier ("points_to"),
4823 TYPE_POINTER_TO (__t_desc_type_node
));
4824 fields
[4] = build_lang_field_decl (FIELD_DECL
,
4825 get_identifier ("ivars_count"),
4827 fields
[5] = build_lang_field_decl (FIELD_DECL
,
4828 get_identifier ("meths_count"),
4830 fields
[6] = build_lang_field_decl (FIELD_DECL
, get_identifier ("ivars"),
4831 build_pointer_type (__i_desc_array_type
));
4832 fields
[7] = build_lang_field_decl (FIELD_DECL
, get_identifier ("meths"),
4833 build_pointer_type (__m_desc_array_type
));
4834 fields
[8] = build_lang_field_decl (FIELD_DECL
, get_identifier ("parents"),
4835 build_pointer_type (__t_desc_array_type
));
4836 fields
[9] = build_lang_field_decl (FIELD_DECL
, get_identifier ("vbases"),
4837 build_pointer_type (__t_desc_array_type
));
4838 fields
[10] = build_lang_field_decl (FIELD_DECL
, get_identifier ("offsets"),
4839 build_pointer_type (integer_type_node
));
4840 finish_builtin_type (__t_desc_type_node
, "__t_desc", fields
, 10, integer_type_node
);
4842 /* ivar descriptors look like this:
4848 struct __t_desc *type;
4852 fields
[0] = build_lang_field_decl (FIELD_DECL
, get_identifier ("name"),
4854 fields
[1] = build_lang_field_decl (FIELD_DECL
, get_identifier ("offset"),
4856 fields
[2] = build_lang_field_decl (FIELD_DECL
, get_identifier ("type"),
4857 TYPE_POINTER_TO (__t_desc_type_node
));
4858 finish_builtin_type (__i_desc_type_node
, "__i_desc", fields
, 2,
4861 /* method descriptors look like this:
4867 struct __t_desc *vcontext;
4868 struct __t_desc *return_type;
4871 short required_parms;
4872 struct __t_desc *parm_types[];
4876 fields
[0] = build_lang_field_decl (FIELD_DECL
, get_identifier ("name"),
4878 fields
[1] = build_lang_field_decl (FIELD_DECL
, get_identifier ("vindex"),
4880 fields
[2] = build_lang_field_decl (FIELD_DECL
, get_identifier ("vcontext"),
4881 TYPE_POINTER_TO (__t_desc_type_node
));
4882 fields
[3] = build_lang_field_decl (FIELD_DECL
, get_identifier ("return_type"),
4883 TYPE_POINTER_TO (__t_desc_type_node
));
4884 fields
[4] = build_lang_field_decl (FIELD_DECL
, get_identifier ("address"),
4885 build_pointer_type (default_function_type
));
4886 fields
[5] = build_lang_field_decl (FIELD_DECL
, get_identifier ("parm_count"),
4887 short_integer_type_node
);
4888 fields
[6] = build_lang_field_decl (FIELD_DECL
, get_identifier ("required_parms"),
4889 short_integer_type_node
);
4890 fields
[7] = build_lang_field_decl (FIELD_DECL
, get_identifier ("parm_types"),
4891 build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node
), NULL_TREE
)));
4892 finish_builtin_type (__m_desc_type_node
, "__m_desc", fields
, 7,
4897 current_lang_name
= lang_name_cplusplus
;
4900 int i
= builtin_type_tdescs_len
;
4903 tree tdesc
= build_t_desc (builtin_type_tdescs_arr
[--i
], 0);
4904 TREE_ASM_WRITTEN (tdesc
) = 1;
4905 TREE_PUBLIC (TREE_OPERAND (tdesc
, 0)) = 1;
4909 auto_function (ansi_opname
[(int) NEW_EXPR
],
4910 build_function_type (ptr_type_node
,
4911 tree_cons (NULL_TREE
, sizetype
,
4914 auto_function (ansi_opname
[(int) VEC_NEW_EXPR
],
4915 build_function_type (ptr_type_node
,
4916 tree_cons (NULL_TREE
, sizetype
,
4919 auto_function (ansi_opname
[(int) DELETE_EXPR
],
4920 build_function_type (void_type_node
,
4921 tree_cons (NULL_TREE
, ptr_type_node
,
4924 auto_function (ansi_opname
[(int) VEC_DELETE_EXPR
],
4925 build_function_type (void_type_node
,
4926 tree_cons (NULL_TREE
, ptr_type_node
,
4931 = define_function ("abort",
4932 build_function_type (void_type_node
, void_list_node
),
4933 NOT_BUILT_IN
, 0, 0);
4935 /* Perform other language dependent initializations. */
4936 init_class_processing ();
4937 init_init_processing ();
4938 init_search_processing ();
4940 if (flag_handle_exceptions
)
4941 init_exception_processing ();
4943 init_gc_processing ();
4946 flag_inline_functions
= 0;
4948 /* This causes uneccessary emission of inline functions. */
4949 flag_default_inline
= 0;
4955 /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
4956 declare_function_name ();
4958 /* Prepare to check format strings against argument lists. */
4959 init_function_format_info ();
4962 /* Make a definition for a builtin function named NAME and whose data type
4963 is TYPE. TYPE should be a function type with argument types.
4964 FUNCTION_CODE tells later passes how to compile calls to this function.
4965 See tree.h for its possible values.
4967 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
4968 the name to be called if we can't opencode the function. */
4971 define_function (name
, type
, function_code
, pfn
, library_name
)
4974 enum built_in_function function_code
;
4978 tree decl
= build_lang_decl (FUNCTION_DECL
, get_identifier (name
), type
);
4979 DECL_EXTERNAL (decl
) = 1;
4980 TREE_PUBLIC (decl
) = 1;
4982 /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
4983 we cannot change DECL_ASSEMBLER_NAME until we have installed this
4984 function in the namespace. */
4985 if (pfn
) (*pfn
) (decl
);
4987 DECL_ASSEMBLER_NAME (decl
) = get_identifier (library_name
);
4988 make_function_rtl (decl
);
4989 if (function_code
!= NOT_BUILT_IN
)
4991 DECL_BUILT_IN (decl
) = 1;
4992 DECL_FUNCTION_CODE (decl
) = function_code
;
4997 /* Called when a declaration is seen that contains no names to declare.
4998 If its type is a reference to a structure, union or enum inherited
4999 from a containing scope, shadow that tag name for the current scope
5000 with a forward reference.
5001 If its type defines a new named structure or union
5002 or defines an enum, it is valid but we need not do anything here.
5003 Otherwise, it is an error.
5005 C++: may have to grok the declspecs to learn about static,
5006 complain for anonymous unions. */
5009 shadow_tag (declspecs
)
5014 tree ob_modifier
= NULL_TREE
;
5016 register enum tree_code code
, ok_code
= ERROR_MARK
;
5017 register tree t
= NULL_TREE
;
5019 for (link
= declspecs
; link
; link
= TREE_CHAIN (link
))
5021 register tree value
= TREE_VALUE (link
);
5023 code
= TREE_CODE (value
);
5024 if (IS_AGGR_TYPE_CODE (code
) || code
== ENUMERAL_TYPE
)
5026 register tree name
= TYPE_NAME (value
);
5028 if (code
== ENUMERAL_TYPE
&& TYPE_SIZE (value
) == 0)
5029 cp_error ("forward declaration of `%#T'", value
);
5031 if (name
== NULL_TREE
)
5032 name
= lookup_tag_reverse (value
, NULL_TREE
);
5034 if (name
&& TREE_CODE (name
) == TYPE_DECL
)
5035 name
= DECL_NAME (name
);
5037 t
= lookup_tag (code
, name
, inner_binding_level
, 1);
5041 push_obstacks (&permanent_obstack
, &permanent_obstack
);
5042 if (IS_AGGR_TYPE_CODE (code
))
5043 t
= make_lang_type (code
);
5045 t
= make_node (code
);
5046 pushtag (name
, t
, 0);
5050 else if (name
!= NULL_TREE
|| code
== ENUMERAL_TYPE
)
5053 if (ok_code
!= ERROR_MARK
)
5058 pedwarn ("useless keyword or type name in declaration");
5062 else if (value
== ridpointers
[(int) RID_STATIC
]
5063 || value
== ridpointers
[(int) RID_EXTERN
]
5064 || value
== ridpointers
[(int) RID_AUTO
]
5065 || value
== ridpointers
[(int) RID_REGISTER
])
5066 ob_modifier
= value
;
5069 /* This is where the variables in an anonymous union are
5070 declared. An anonymous union declaration looks like:
5072 because there is no declarator after the union, the parser
5073 sends that declaration here. */
5074 if (ok_code
== UNION_TYPE
5076 && ((TREE_CODE (TYPE_NAME (t
)) == IDENTIFIER_NODE
5077 && ANON_AGGRNAME_P (TYPE_NAME (t
)))
5078 || (TREE_CODE (TYPE_NAME (t
)) == TYPE_DECL
5079 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
)))))
5081 /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have
5082 function members. */
5083 if (TYPE_FIELDS (t
))
5085 tree decl
= grokdeclarator (NULL_TREE
, declspecs
, NORMAL
, 0,
5087 finish_anon_union (decl
);
5090 error ("anonymous union cannot have a function member");
5094 /* Anonymous unions are objects, that's why we only check for
5095 inappropriate specifiers in this branch. */
5097 cp_error ("`%D' can only be specified for objects and functions",
5100 if (ok_code
== RECORD_TYPE
5102 && TYPE_LANG_SPECIFIC (t
)
5103 && CLASSTYPE_DECLARED_EXCEPTION (t
))
5106 cp_error ("redeclaration of exception `%T'", t
);
5111 push_obstacks (&permanent_obstack
, &permanent_obstack
);
5115 ename
= TYPE_NAME (t
);
5116 if (TREE_CODE (ename
) == TYPE_DECL
)
5117 ename
= DECL_NAME (ename
);
5118 decl
= build_lang_field_decl (VAR_DECL
, ename
, t
);
5123 else if (found_tag
== 0)
5124 pedwarn ("abstract declarator used as declaration");
5125 else if (!warned
&& found_tag
> 1)
5126 pedwarn ("multiple types in one declaration");
5130 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
5133 groktypename (typename
)
5136 if (TREE_CODE (typename
) != TREE_LIST
)
5138 return grokdeclarator (TREE_VALUE (typename
),
5139 TREE_PURPOSE (typename
),
5140 TYPENAME
, 0, NULL_TREE
);
5143 /* Decode a declarator in an ordinary declaration or data definition.
5144 This is called as soon as the type information and variable name
5145 have been parsed, before parsing the initializer if any.
5146 Here we create the ..._DECL node, fill in its type,
5147 and put it on the list of decls for the current context.
5148 The ..._DECL node is returned as the value.
5150 Exception: for arrays where the length is not specified,
5151 the type is left null, to be filled in by `finish_decl'.
5153 Function definitions do not come here; they go to start_function
5154 instead. However, external and forward declarations of functions
5155 do go through here. Structure field declarations are done by
5156 grokfield and not through here. */
5158 /* Set this to zero to debug not using the temporary obstack
5159 to parse initializers. */
5160 int debug_temp_inits
= 1;
5163 start_decl (declarator
, declspecs
, initialized
, raises
)
5164 tree declarator
, declspecs
;
5169 register tree type
, tem
;
5171 extern int have_extern_spec
;
5172 extern int used_extern_spec
;
5174 int init_written
= initialized
;
5176 /* This should only be done once on the top most decl. */
5177 if (have_extern_spec
&& !used_extern_spec
)
5179 declspecs
= decl_tree_cons (NULL_TREE
, get_identifier ("extern"),
5181 used_extern_spec
= 1;
5184 decl
= grokdeclarator (declarator
, declspecs
, NORMAL
, initialized
, raises
);
5185 if (decl
== NULL_TREE
|| decl
== void_type_node
)
5188 type
= TREE_TYPE (decl
);
5190 /* Don't lose if destructors must be executed at file-level. */
5191 if (TREE_STATIC (decl
)
5192 && TYPE_NEEDS_DESTRUCTOR (type
)
5193 && !TREE_PERMANENT (decl
))
5195 push_obstacks (&permanent_obstack
, &permanent_obstack
);
5196 decl
= copy_node (decl
);
5197 if (TREE_CODE (type
) == ARRAY_TYPE
)
5199 tree itype
= TYPE_DOMAIN (type
);
5200 if (itype
&& ! TREE_PERMANENT (itype
))
5202 itype
= build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype
)));
5203 type
= build_cplus_array_type (TREE_TYPE (type
), itype
);
5204 TREE_TYPE (decl
) = type
;
5210 /* Interesting work for this is done in `finish_exception_decl'. */
5211 if (TREE_CODE (type
) == RECORD_TYPE
5212 && CLASSTYPE_DECLARED_EXCEPTION (type
))
5215 /* Corresponding pop_obstacks is done in `finish_decl'. */
5216 push_obstacks_nochange ();
5219 = (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_VIRTUAL_P (decl
))
5220 ? DECL_CLASS_CONTEXT (decl
)
5221 : DECL_CONTEXT (decl
);
5223 if (processing_template_decl
)
5226 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5228 /* Declarator is a call_expr; extract arguments from it, since
5229 grokdeclarator didn't do it. */
5231 args
= copy_to_permanent (last_function_parms
);
5232 if (TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
)
5234 tree t
= TREE_TYPE (decl
);
5236 t
= TYPE_METHOD_BASETYPE (t
); /* type method belongs to */
5237 if (TREE_CODE (t
) != UNINSTANTIATED_P_TYPE
)
5239 t
= build_pointer_type (t
); /* base type of `this' */
5241 /* I suspect this is wrong. */
5242 t
= build_type_variant (t
, flag_this_is_variable
<= 0,
5243 0); /* type of `this' */
5245 t
= build_type_variant (t
, 0, 0); /* type of `this' */
5247 t
= build (PARM_DECL
, t
, this_identifier
);
5248 TREE_CHAIN (t
) = args
;
5252 DECL_ARGUMENTS (decl
) = args
;
5254 d
= build_lang_decl (TEMPLATE_DECL
, DECL_NAME (decl
), TREE_TYPE (decl
));
5255 if (interface_unknown
&& flag_external_templates
5256 && ! DECL_IN_SYSTEM_HEADER (decl
))
5257 warn_if_unknown_interface ();
5258 TREE_PUBLIC (d
) = TREE_PUBLIC (decl
) =
5259 flag_external_templates
&& !interface_unknown
;
5260 TREE_STATIC (d
) = TREE_STATIC (decl
);
5261 DECL_EXTERNAL (d
) = (DECL_EXTERNAL (decl
)
5262 && !(context
&& !DECL_THIS_EXTERN (decl
)));
5263 DECL_TEMPLATE_RESULT (d
) = decl
;
5267 /* If this type of object needs a cleanup, and control may
5268 jump past it, make a new binding level so that it is cleaned
5269 up only when it is initialized first. */
5270 if (TYPE_NEEDS_DESTRUCTOR (type
)
5271 && current_binding_level
->more_cleanups_ok
== 0)
5272 pushlevel_temporary (1);
5275 /* Is it valid for this decl to have an initializer at all?
5276 If not, set INITIALIZED to zero, which will indirectly
5277 tell `finish_decl' to ignore the initializer once it is parsed. */
5278 switch (TREE_CODE (decl
))
5281 /* typedef foo = bar means give foo the same type as bar.
5282 We haven't parsed bar yet, so `finish_decl' will fix that up.
5283 Any other case of an initialization in a TYPE_DECL is an error. */
5284 if (pedantic
|| list_length (declspecs
) > 1)
5286 cp_error ("typedef `%D' is initialized", decl
);
5292 cp_error ("function `%#D' is initialized like a variable", decl
);
5297 /* Don't allow initializations for incomplete types except for
5298 arrays which might be completed by the initialization. */
5299 if (type
== error_mark_node
)
5300 ; /* Don't complain again. */
5301 else if (TYPE_SIZE (type
) != NULL_TREE
)
5302 ; /* A complete type is ok. */
5303 else if (TREE_CODE (type
) != ARRAY_TYPE
)
5305 cp_error ("variable `%#D' has initializer but incomplete type",
5309 else if (TYPE_SIZE (TREE_TYPE (type
)) == NULL_TREE
)
5311 cp_error ("elements of array `%#D' have incomplete type", decl
);
5317 && TREE_CODE (decl
) != TYPE_DECL
5318 && TREE_CODE (decl
) != TEMPLATE_DECL
5319 && IS_AGGR_TYPE (type
) && ! DECL_EXTERNAL (decl
))
5321 if (TYPE_SIZE (type
) == NULL_TREE
)
5323 cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
5325 /* Change the type so that assemble_variable will give
5326 DECL an rtl we can live with: (mem (const_int 0)). */
5327 TREE_TYPE (decl
) = error_mark_node
;
5328 type
= error_mark_node
;
5332 /* If any base type in the hierarchy of TYPE needs a constructor,
5333 then we set initialized to 1. This way any nodes which are
5334 created for the purposes of initializing this aggregate
5335 will live as long as it does. This is necessary for global
5336 aggregates which do not have their initializers processed until
5337 the end of the file. */
5338 initialized
= TYPE_NEEDS_CONSTRUCTING (type
);
5344 if (current_binding_level
!= global_binding_level
5345 && DECL_EXTERNAL (decl
))
5346 cp_warning ("declaration of `%#D' has `extern' and is initialized",
5348 DECL_EXTERNAL (decl
) = 0;
5349 if (current_binding_level
== global_binding_level
)
5350 TREE_STATIC (decl
) = 1;
5352 /* Tell `pushdecl' this is an initialized decl
5353 even though we don't yet have the initializer expression.
5354 Also tell `finish_decl' it may store the real initializer. */
5355 DECL_INITIAL (decl
) = error_mark_node
;
5358 if (context
&& TYPE_SIZE (context
) != NULL_TREE
)
5360 if (TREE_CODE (decl
) == VAR_DECL
)
5362 tree field
= lookup_field (context
, DECL_NAME (decl
), 0, 0);
5363 if (field
== NULL_TREE
|| TREE_CODE (field
) != VAR_DECL
)
5364 cp_error ("`%#D' is not a static member of `%#T'", decl
, context
);
5365 else if (duplicate_decls (decl
, field
))
5369 /* If it was not explicitly declared `extern',
5370 revoke any previous claims of DECL_EXTERNAL. */
5371 if (DECL_THIS_EXTERN (decl
) == 0)
5372 DECL_EXTERNAL (decl
) = 0;
5373 if (DECL_LANG_SPECIFIC (decl
))
5374 DECL_IN_AGGR_P (decl
) = 0;
5375 pushclass (context
, 2);
5378 /* Add this decl to the current binding level, but not if it
5379 comes from another scope, e.g. a static member variable.
5380 TEM may equal DECL or it may be a previous decl of the same name. */
5382 if ((TREE_CODE (decl
) != PARM_DECL
&& DECL_CONTEXT (decl
) != NULL_TREE
)
5383 || (TREE_CODE (decl
) == TEMPLATE_DECL
&& !global_bindings_p ())
5384 || TREE_CODE (type
) == LANG_TYPE
)
5387 tem
= pushdecl (decl
);
5389 /* Tell the back-end to use or not use .common as appropriate. If we say
5390 -fconserve-space, we want this to save space, at the expense of wrong
5391 semantics. If we say -fno-conserve-space, we want this to produce
5392 errors about redefs; to do this we force variables into the data
5393 segment. Common storage is okay for non-public uninitialized data;
5394 the linker can't match it with storage from other files, and we may
5395 save some disk space. */
5396 DECL_COMMON (tem
) = flag_conserve_space
|| ! TREE_PUBLIC (tem
);
5399 /* We don't do this yet for GNU C++. */
5400 /* For a local variable, define the RTL now. */
5401 if (current_binding_level
!= global_binding_level
5402 /* But not if this is a duplicate decl
5403 and we preserved the rtl from the previous one
5404 (which may or may not happen). */
5405 && DECL_RTL (tem
) == NULL_RTX
)
5407 if (TYPE_SIZE (TREE_TYPE (tem
)) != NULL_TREE
)
5409 else if (TREE_CODE (TREE_TYPE (tem
)) == ARRAY_TYPE
5410 && DECL_INITIAL (tem
) != NULL_TREE
)
5415 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
5417 tree result
= DECL_TEMPLATE_RESULT (decl
);
5418 if (DECL_CONTEXT (result
) != NULL_TREE
)
5421 type
= DECL_CONTEXT (result
);
5423 if (TREE_CODE (type
) != UNINSTANTIATED_P_TYPE
)
5425 cp_error ("declaration of `%D' in non-template type `%T'",
5430 if (TREE_CODE (result
) == FUNCTION_DECL
)
5432 else if (TREE_CODE (result
) == VAR_DECL
)
5435 tree tmpl
= UPT_TEMPLATE (type
);
5437 fprintf (stderr
, "%s:%d: adding ", __FILE__
, __LINE__
);
5438 print_node_brief (stderr
, "", DECL_NAME (tem
), 0);
5439 fprintf (stderr
, " to class %s\n",
5440 IDENTIFIER_POINTER (DECL_NAME (tmpl
)));
5441 DECL_TEMPLATE_MEMBERS (tmpl
)
5442 = perm_tree_cons (DECL_NAME (tem
), tem
,
5443 DECL_TEMPLATE_MEMBERS (tmpl
));
5446 sorry ("static data member templates");
5451 my_friendly_abort (13);
5453 else if (TREE_CODE (result
) == FUNCTION_DECL
)
5454 /*tem = push_overloaded_decl (tem, 0)*/;
5455 else if (TREE_CODE (result
) == VAR_DECL
)
5457 cp_error ("data template `%#D' must be member of a class template",
5461 else if (TREE_CODE (result
) == TYPE_DECL
)
5463 cp_error ("invalid template `%#D'", result
);
5467 my_friendly_abort (14);
5471 && ! (TREE_CODE (tem
) == PARM_DECL
5472 || (TREE_READONLY (tem
)
5473 && (TREE_CODE (tem
) == VAR_DECL
5474 || TREE_CODE (tem
) == FIELD_DECL
))))
5476 /* When parsing and digesting the initializer,
5477 use temporary storage. Do this even if we will ignore the value. */
5478 if (current_binding_level
== global_binding_level
&& debug_temp_inits
)
5480 if (TYPE_NEEDS_CONSTRUCTING (type
)
5481 || TREE_CODE (type
) == REFERENCE_TYPE
)
5482 /* In this case, the initializer must lay down in permanent
5483 storage, since it will be saved until `finish_file' is run. */
5486 temporary_allocation ();
5491 cadillac_start_decl (tem
);
5498 make_temporary_for_reference (decl
, ctor_call
, init
, cleanupp
)
5499 tree decl
, ctor_call
, init
;
5502 tree type
= TREE_TYPE (decl
);
5503 tree target_type
= TREE_TYPE (type
);
5508 tmp_addr
= TREE_VALUE (TREE_OPERAND (ctor_call
, 1));
5509 if (TREE_CODE (tmp_addr
) == NOP_EXPR
)
5510 tmp_addr
= TREE_OPERAND (tmp_addr
, 0);
5511 my_friendly_assert (TREE_CODE (tmp_addr
) == ADDR_EXPR
, 146);
5512 tmp
= TREE_OPERAND (tmp_addr
, 0);
5516 tmp
= get_temp_name (target_type
,
5517 current_binding_level
== global_binding_level
);
5518 tmp_addr
= build_unary_op (ADDR_EXPR
, tmp
, 0);
5521 TREE_TYPE (tmp_addr
) = build_pointer_type (target_type
);
5522 DECL_INITIAL (decl
) = convert (TYPE_POINTER_TO (target_type
), tmp_addr
);
5523 TREE_TYPE (DECL_INITIAL (decl
)) = type
;
5524 if (TYPE_NEEDS_CONSTRUCTING (target_type
))
5526 if (current_binding_level
== global_binding_level
)
5528 /* lay this variable out now. Otherwise `output_addressed_constants'
5529 gets confused by its initializer. */
5530 make_decl_rtl (tmp
, NULL_PTR
, 1);
5531 static_aggregates
= perm_tree_cons (init
, tmp
, static_aggregates
);
5535 if (ctor_call
!= NULL_TREE
)
5538 init
= build_method_call (tmp
, constructor_name_full (target_type
),
5539 build_tree_list (NULL_TREE
, init
),
5540 NULL_TREE
, LOOKUP_NORMAL
);
5541 DECL_INITIAL (decl
) = build (COMPOUND_EXPR
, type
, init
,
5542 DECL_INITIAL (decl
));
5543 *cleanupp
= maybe_build_cleanup (tmp
);
5548 DECL_INITIAL (tmp
) = init
;
5549 TREE_STATIC (tmp
) = current_binding_level
== global_binding_level
;
5550 finish_decl (tmp
, init
, 0, 0);
5552 if (TREE_STATIC (tmp
))
5553 preserve_initializer ();
5557 /* Handle initialization of references.
5558 These three arguments from from `finish_decl', and have the
5559 same meaning here that they do there. */
5560 /* quotes on semantics can be found in ARM 8.4.3. */
5562 grok_reference_init (decl
, type
, init
, cleanupp
)
5563 tree decl
, type
, init
;
5568 if (init
== NULL_TREE
)
5570 if (DECL_LANG_SPECIFIC (decl
) == 0
5571 || DECL_IN_AGGR_P (decl
) == 0)
5573 cp_error ("`%D' declared as reference but not initialized", decl
);
5574 if (TREE_CODE (decl
) == VAR_DECL
)
5575 SET_DECL_REFERENCE_SLOT (decl
, error_mark_node
);
5580 if (init
== error_mark_node
)
5583 if (TREE_CODE (type
) == REFERENCE_TYPE
5584 && TREE_CODE (init
) == CONSTRUCTOR
)
5586 cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl
);
5590 if (TREE_CODE (init
) == TREE_LIST
)
5591 init
= build_compound_expr (init
);
5593 if (TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
5594 && TREE_CODE (TREE_TYPE (init
)) == ARRAY_TYPE
)
5596 /* Note: default conversion is only called in very special cases. */
5597 init
= default_conversion (init
);
5600 tmp
= convert_to_reference
5601 (type
, init
, CONV_IMPLICIT
, LOOKUP_SPECULATIVELY
|LOOKUP_NORMAL
, decl
);
5603 if (tmp
== error_mark_node
)
5605 else if (tmp
!= NULL_TREE
)
5607 tree subtype
= TREE_TYPE (type
);
5610 /* Associate the cleanup with the reference so that we
5611 don't get burned by "aggressive" cleanup policy. */
5612 if (TYPE_NEEDS_DESTRUCTOR (subtype
))
5614 if (TREE_CODE (init
) == WITH_CLEANUP_EXPR
)
5616 *cleanupp
= TREE_OPERAND (init
, 2);
5617 TREE_OPERAND (init
, 2) = error_mark_node
;
5621 if (TREE_CODE (tmp
) == ADDR_EXPR
)
5622 tmp
= TREE_OPERAND (tmp
, 0);
5623 if (TREE_CODE (tmp
) == TARGET_EXPR
)
5625 *cleanupp
= build_delete
5626 (TYPE_POINTER_TO (subtype
),
5627 build_unary_op (ADDR_EXPR
, TREE_OPERAND (tmp
, 0), 0),
5628 integer_two_node
, LOOKUP_NORMAL
|LOOKUP_DESTRUCTOR
, 0);
5629 TREE_OPERAND (tmp
, 2) = error_mark_node
;
5634 if (TREE_SIDE_EFFECTS (init
))
5635 DECL_INITIAL (decl
) = save_expr (init
);
5637 DECL_INITIAL (decl
) = init
;
5641 cp_error ("cannot initialize `%T' from `%T'", type
, TREE_TYPE (init
));
5645 /* ?? Can this be optimized in some cases to
5646 hand back the DECL_INITIAL slot?? */
5647 if (TYPE_SIZE (TREE_TYPE (type
)))
5649 init
= convert_from_reference (decl
);
5650 if (TREE_PERMANENT (decl
))
5651 init
= copy_to_permanent (init
);
5652 SET_DECL_REFERENCE_SLOT (decl
, init
);
5655 if (TREE_STATIC (decl
) && ! TREE_CONSTANT (DECL_INITIAL (decl
)))
5657 expand_static_init (decl
, DECL_INITIAL (decl
));
5658 DECL_INITIAL (decl
) = NULL_TREE
;
5663 if (TREE_CODE (decl
) == VAR_DECL
)
5664 SET_DECL_REFERENCE_SLOT (decl
, error_mark_node
);
5668 /* Finish processing of a declaration;
5669 install its line number and initial value.
5670 If the length of an array type is not known before,
5671 it must be determined now, from the initial value, or it is an error.
5673 Call `pop_obstacks' iff NEED_POP is nonzero.
5675 For C++, `finish_decl' must be fairly evasive: it must keep initializers
5676 for aggregates that have constructors alive on the permanent obstack,
5677 so that the global initializing functions can be written at the end.
5679 INIT0 holds the value of an initializer that should be allowed to escape
5682 For functions that take default parameters, DECL points to its
5683 "maximal" instantiation. `finish_decl' must then also declared its
5684 subsequently lower and lower forms of instantiation, checking for
5685 ambiguity as it goes. This can be sped up later. */
5688 finish_decl (decl
, init
, asmspec_tree
, need_pop
)
5694 tree cleanup
= NULL_TREE
, ttype
;
5696 int temporary
= allocation_temporary_p ();
5697 char *asmspec
= NULL
;
5698 int was_readonly
= 0;
5700 /* If this is 0, then we did not change obstacks. */
5704 error ("assignment (not initialization) in declaration");
5708 /* If a name was specified, get the string. */
5710 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
5712 /* If the type of the thing we are declaring either has
5713 a constructor, or has a virtual function table pointer,
5714 AND its initialization was accepted by `start_decl',
5715 then we stayed on the permanent obstack through the
5716 declaration, otherwise, changed obstacks as GCC would. */
5718 type
= TREE_TYPE (decl
);
5720 was_incomplete
= (DECL_SIZE (decl
) == NULL_TREE
);
5722 /* Take care of TYPE_DECLs up front. */
5723 if (TREE_CODE (decl
) == TYPE_DECL
)
5725 if (init
&& DECL_INITIAL (decl
))
5727 /* typedef foo = bar; store the type of bar as the type of foo. */
5728 TREE_TYPE (decl
) = type
= TREE_TYPE (init
);
5729 DECL_INITIAL (decl
) = init
= NULL_TREE
;
5731 if (type
!= error_mark_node
5732 && IS_AGGR_TYPE (type
) && DECL_NAME (decl
))
5734 if (TREE_TYPE (DECL_NAME (decl
)) && TREE_TYPE (decl
) != type
)
5735 cp_warning ("shadowing previous type declaration of `%#D'", decl
);
5736 set_identifier_type_value (DECL_NAME (decl
), type
);
5737 CLASSTYPE_GOT_SEMICOLON (type
) = 1;
5739 GNU_xref_decl (current_function_decl
, decl
);
5740 rest_of_decl_compilation (decl
, NULL_PTR
,
5741 DECL_CONTEXT (decl
) == NULL_TREE
, 0);
5744 if (type
!= error_mark_node
&& IS_AGGR_TYPE (type
)
5745 && CLASSTYPE_DECLARED_EXCEPTION (type
))
5747 CLASSTYPE_GOT_SEMICOLON (type
) = 1;
5750 if (TREE_CODE (decl
) != FUNCTION_DECL
)
5752 ttype
= target_type (type
);
5754 Leave this out until we can figure out why it was
5755 needed/desirable in the first place. Then put a comment
5756 here explaining why. Or just delete the code if no ill
5758 if (TYPE_NAME (ttype
)
5759 && TREE_CODE (TYPE_NAME (ttype
)) == TYPE_DECL
5760 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype
)))
5762 tree old_id
= TYPE_IDENTIFIER (ttype
);
5763 char *newname
= (char *)alloca (IDENTIFIER_LENGTH (old_id
) + 2);
5764 /* Need to preserve template data for UPT nodes. */
5765 tree old_template
= IDENTIFIER_TEMPLATE (old_id
);
5767 bcopy (IDENTIFIER_POINTER (old_id
), newname
+ 1,
5768 IDENTIFIER_LENGTH (old_id
) + 1);
5769 old_id
= get_identifier (newname
);
5770 lookup_tag_reverse (ttype
, old_id
);
5771 TYPE_IDENTIFIER (ttype
) = old_id
;
5772 IDENTIFIER_TEMPLATE (old_id
) = old_template
;
5777 if (! DECL_EXTERNAL (decl
) && TREE_READONLY (decl
)
5778 && TYPE_NEEDS_CONSTRUCTING (type
))
5781 /* Currently, GNU C++ puts constants in text space, making them
5782 impossible to initialize. In the future, one would hope for
5783 an operating system which understood the difference between
5784 initialization and the running of a program. */
5786 TREE_READONLY (decl
) = 0;
5789 if (TREE_CODE (decl
) == FIELD_DECL
)
5791 if (init
&& init
!= error_mark_node
)
5792 my_friendly_assert (TREE_PERMANENT (init
), 147);
5796 /* This must override the asm specifier which was placed
5797 by grokclassfn. Lay this out fresh.
5799 @@ Should emit an error if this redefines an asm-specified
5800 @@ name, or if we have already used the function's name. */
5801 DECL_RTL (TREE_TYPE (decl
)) = NULL_RTX
;
5802 DECL_ASSEMBLER_NAME (decl
) = get_identifier (asmspec
);
5803 make_decl_rtl (decl
, asmspec
, 0);
5806 /* If `start_decl' didn't like having an initialization, ignore it now. */
5807 else if (init
!= NULL_TREE
&& DECL_INITIAL (decl
) == NULL_TREE
)
5809 else if (DECL_EXTERNAL (decl
))
5811 else if (TREE_CODE (type
) == REFERENCE_TYPE
5812 || (TYPE_LANG_SPECIFIC (type
) && IS_SIGNATURE_REFERENCE (type
)))
5814 grok_reference_init (decl
, type
, init
, &cleanup
);
5818 GNU_xref_decl (current_function_decl
, decl
);
5820 if (TREE_CODE (decl
) == FIELD_DECL
)
5822 else if (TREE_CODE (decl
) == CONST_DECL
)
5824 my_friendly_assert (TREE_CODE (decl
) != REFERENCE_TYPE
, 148);
5826 DECL_INITIAL (decl
) = init
;
5828 /* This will keep us from needing to worry about our obstacks. */
5829 my_friendly_assert (init
!= NULL_TREE
, 149);
5834 if (TYPE_HAS_CONSTRUCTOR (type
) || TYPE_NEEDS_CONSTRUCTING (type
))
5836 if (TREE_CODE (type
) == ARRAY_TYPE
)
5837 init
= digest_init (type
, init
, (tree
*) 0);
5838 else if (TREE_CODE (init
) == CONSTRUCTOR
)
5840 if (TYPE_NEEDS_CONSTRUCTING (type
))
5842 cp_error ("`%D' must be initialized by constructor, not by `{...}'",
5844 init
= error_mark_node
;
5847 goto dont_use_constructor
;
5850 /* fix this in `build_functional_cast' instead.
5851 Here's the trigger code:
5856 ostream (int, char *);
5863 int buf_size = 1024;
5864 static char buf[buf_size];
5865 const char *debug(int i) {
5867 ostream o = ostream(buf_size, b);
5873 else if (TREE_CODE (init
) == TARGET_EXPR
5874 && TREE_CODE (TREE_OPERAND (init
, 1) == NEW_EXPR
))
5876 /* User wrote something like `foo x = foo (args)' */
5877 my_friendly_assert (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
, 150);
5878 my_friendly_assert (DECL_NAME (TREE_OPERAND (init
, 0)) == NULL_TREE
, 151);
5880 /* User wrote exactly `foo x = foo (args)' */
5881 if (TYPE_MAIN_VARIANT (type
) == TREE_TYPE (init
))
5883 init
= build (CALL_EXPR
, TREE_TYPE (init
),
5884 TREE_OPERAND (TREE_OPERAND (init
, 1), 0),
5885 TREE_OPERAND (TREE_OPERAND (init
, 1), 1), 0);
5886 TREE_SIDE_EFFECTS (init
) = 1;
5891 /* We must hide the initializer so that expand_decl
5892 won't try to do something it does not understand. */
5893 if (current_binding_level
== global_binding_level
)
5896 if (DECL_COMMON (decl
))
5897 /* Should this be a NULL_TREE? */
5898 value
= error_mark_node
;
5900 value
= build (CONSTRUCTOR
, type
, NULL_TREE
, NULL_TREE
);
5901 DECL_INITIAL (decl
) = value
;
5904 DECL_INITIAL (decl
) = error_mark_node
;
5908 dont_use_constructor
:
5909 if (TREE_CODE (init
) != TREE_VEC
)
5910 init
= store_init_value (decl
, init
);
5912 /* Don't let anyone try to initialize this variable
5913 until we are ready to do so. */
5917 if (DECL_COMMON (decl
))
5918 value
= error_mark_node
;
5920 value
= build (CONSTRUCTOR
, type
, NULL_TREE
, NULL_TREE
);
5921 DECL_INITIAL (decl
) = value
;
5925 else if (DECL_EXTERNAL (decl
))
5927 else if (TREE_CODE_CLASS (TREE_CODE (type
)) == 't'
5928 && (IS_AGGR_TYPE (type
) || TYPE_NEEDS_CONSTRUCTING (type
)))
5931 while (TREE_CODE (ctype
) == ARRAY_TYPE
)
5932 ctype
= TREE_TYPE (ctype
);
5933 if (! TYPE_NEEDS_CONSTRUCTING (ctype
))
5935 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype
))
5936 cp_error ("structure `%D' with uninitialized const members", decl
);
5937 if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype
))
5938 cp_error ("structure `%D' with uninitialized reference members",
5942 if (TREE_CODE (decl
) == VAR_DECL
5943 && !DECL_INITIAL (decl
)
5944 && !TYPE_NEEDS_CONSTRUCTING (type
)
5945 && (TYPE_READONLY (type
) || TREE_READONLY (decl
)))
5946 cp_error ("uninitialized const `%D'", decl
);
5948 /* Initialize variables in need of static initialization with
5949 an empty CONSTRUCTOR to keep assemble_variable from putting them in
5950 the wrong program space. */
5952 && TREE_STATIC (decl
)
5953 && TREE_PUBLIC (decl
)
5954 && ! DECL_EXTERNAL (decl
)
5955 && TREE_CODE (decl
) == VAR_DECL
5956 && TYPE_NEEDS_CONSTRUCTING (type
)
5957 && (DECL_INITIAL (decl
) == NULL_TREE
5958 || DECL_INITIAL (decl
) == error_mark_node
)
5959 && ! DECL_COMMON (decl
))
5960 DECL_INITIAL (decl
) = build (CONSTRUCTOR
, type
, NULL_TREE
,
5963 else if (TREE_CODE (decl
) == VAR_DECL
5964 && TREE_CODE (type
) != REFERENCE_TYPE
5965 && (TYPE_READONLY (type
) || TREE_READONLY (decl
)))
5967 /* ``Unless explicitly declared extern, a const object does not have
5968 external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
5969 However, if it's `const int foo = 1; const int foo;', don't complain
5970 about the second decl, since it does have an initializer before.
5971 We deliberately don't complain about arrays, because they're
5972 supposed to be initialized by a constructor. */
5973 if (! DECL_INITIAL (decl
)
5974 && TREE_CODE (type
) != ARRAY_TYPE
5975 && (!pedantic
|| !current_class_type
))
5976 cp_error ("uninitialized const `%#D'", decl
);
5979 /* For top-level declaration, the initial value was read in
5980 the temporary obstack. MAXINDEX, rtl, etc. to be made below
5981 must go in the permanent obstack; but don't discard the
5982 temporary data yet. */
5984 if (current_binding_level
== global_binding_level
&& temporary
)
5985 end_temporary_allocation ();
5987 /* Deduce size of array from initialization, if not already known. */
5989 if (TREE_CODE (type
) == ARRAY_TYPE
5990 && TYPE_DOMAIN (type
) == NULL_TREE
5991 && TREE_CODE (decl
) != TYPE_DECL
)
5994 = (TREE_STATIC (decl
)
5995 /* Even if pedantic, an external linkage array
5996 may have incomplete type at first. */
5997 ? pedantic
&& ! DECL_EXTERNAL (decl
)
5998 : !DECL_EXTERNAL (decl
));
5999 tree initializer
= init
? init
: DECL_INITIAL (decl
);
6000 int failure
= complete_array_type (type
, initializer
, do_default
);
6003 cp_error ("initializer fails to determine size of `%D'", decl
);
6008 cp_error ("array size missing in `%D'", decl
);
6009 /* If a `static' var's size isn't known, make it extern as
6010 well as static, so it does not get allocated. If it's not
6011 `static', then don't mark it extern; finish_incomplete_decl
6012 will give it a default size and it will get allocated. */
6013 else if (!pedantic
&& TREE_STATIC (decl
) && !TREE_PUBLIC (decl
))
6014 DECL_EXTERNAL (decl
) = 1;
6017 if (pedantic
&& TYPE_DOMAIN (type
) != NULL_TREE
6018 && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
6020 cp_error ("zero-size array `%D'", decl
);
6022 layout_decl (decl
, 0);
6025 if (TREE_CODE (decl
) == VAR_DECL
)
6027 if (DECL_SIZE (decl
) == NULL_TREE
6028 && TYPE_SIZE (TREE_TYPE (decl
)) != NULL_TREE
)
6029 layout_decl (decl
, 0);
6031 if (TREE_STATIC (decl
) && DECL_SIZE (decl
) == NULL_TREE
)
6033 /* A static variable with an incomplete type:
6034 that is an error if it is initialized.
6035 Otherwise, let it through, but if it is not `extern'
6036 then it may cause an error message later. */
6037 if (DECL_INITIAL (decl
) != NULL_TREE
)
6038 cp_error ("storage size of `%D' isn't known", decl
);
6041 else if (!DECL_EXTERNAL (decl
) && DECL_SIZE (decl
) == NULL_TREE
)
6043 /* An automatic variable with an incomplete type: that is an error.
6044 Don't talk about array types here, since we took care of that
6045 message in grokdeclarator. */
6046 cp_error ("storage size of `%D' isn't known", decl
);
6047 TREE_TYPE (decl
) = error_mark_node
;
6049 else if (!DECL_EXTERNAL (decl
) && IS_AGGR_TYPE (ttype
))
6050 /* Let debugger know it should output info for this type. */
6051 note_debug_info_needed (ttype
);
6053 if ((DECL_EXTERNAL (decl
) || TREE_STATIC (decl
))
6054 && DECL_SIZE (decl
) != NULL_TREE
6055 && ! TREE_CONSTANT (DECL_SIZE (decl
)))
6057 if (TREE_CODE (DECL_SIZE (decl
)) == INTEGER_CST
)
6058 constant_expression_warning (DECL_SIZE (decl
));
6060 cp_error ("storage size of `%D' isn't constant", decl
);
6063 if (!DECL_EXTERNAL (decl
) && TYPE_NEEDS_DESTRUCTOR (type
))
6065 int yes
= suspend_momentary ();
6067 /* If INIT comes from a functional cast, use the cleanup
6068 we built for that. Otherwise, make our own cleanup. */
6069 if (init
&& TREE_CODE (init
) == WITH_CLEANUP_EXPR
6070 && comptypes (TREE_TYPE (decl
), TREE_TYPE (init
), 1))
6072 cleanup
= TREE_OPERAND (init
, 2);
6073 init
= TREE_OPERAND (init
, 0);
6074 current_binding_level
->have_cleanups
= 1;
6077 cleanup
= maybe_build_cleanup (decl
);
6078 resume_momentary (yes
);
6081 /* PARM_DECLs get cleanups, too. */
6082 else if (TREE_CODE (decl
) == PARM_DECL
&& TYPE_NEEDS_DESTRUCTOR (type
))
6085 end_temporary_allocation ();
6086 cleanup
= maybe_build_cleanup (decl
);
6088 resume_temporary_allocation ();
6091 /* Output the assembler code and/or RTL code for variables and functions,
6092 unless the type is an undefined structure or union.
6093 If not, it will get done when the type is completed. */
6095 if (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == FUNCTION_DECL
6096 || TREE_CODE (decl
) == RESULT_DECL
)
6098 /* ??? FIXME: What about nested classes? */
6099 int toplev
= (current_binding_level
== global_binding_level
6100 || pseudo_global_level_p ());
6102 = ((flag_traditional
6103 || (TREE_STATIC (decl
) && TYPE_NEEDS_DESTRUCTOR (type
)))
6104 && allocation_temporary_p ());
6107 end_temporary_allocation ();
6109 if (TREE_CODE (decl
) == VAR_DECL
6110 && current_binding_level
!= global_binding_level
6111 && ! TREE_STATIC (decl
)
6112 && type_needs_gc_entry (type
))
6113 DECL_GC_OFFSET (decl
) = size_int (++current_function_obstack_index
);
6115 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_VIRTUAL_P (decl
))
6116 make_decl_rtl (decl
, NULL_PTR
, toplev
);
6117 else if (TREE_CODE (decl
) == VAR_DECL
6118 && TREE_READONLY (decl
)
6119 && DECL_INITIAL (decl
) != NULL_TREE
6120 && DECL_INITIAL (decl
) != error_mark_node
6121 && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl
)))
6123 DECL_INITIAL (decl
) = save_expr (DECL_INITIAL (decl
));
6126 DECL_ASSEMBLER_NAME (decl
) = get_identifier (asmspec
);
6129 && TREE_STATIC (decl
)
6130 && ! TREE_SIDE_EFFECTS (decl
)
6131 && ! TREE_PUBLIC (decl
)
6132 && ! DECL_EXTERNAL (decl
)
6133 && ! TYPE_NEEDS_DESTRUCTOR (type
)
6134 && DECL_MODE (decl
) != BLKmode
)
6136 /* If this variable is really a constant, then fill its DECL_RTL
6137 slot with something which won't take up storage.
6138 If something later should take its address, we can always give
6139 it legitimate RTL at that time. */
6140 DECL_RTL (decl
) = gen_reg_rtx (DECL_MODE (decl
));
6141 store_expr (DECL_INITIAL (decl
), DECL_RTL (decl
), 0);
6142 TREE_ASM_WRITTEN (decl
) = 1;
6144 else if (toplev
&& ! TREE_PUBLIC (decl
))
6146 /* If this is a static const, change its apparent linkage
6147 if it belongs to a #pragma interface. */
6148 if (!interface_unknown
)
6150 TREE_PUBLIC (decl
) = 1;
6151 DECL_EXTERNAL (decl
) = interface_only
;
6153 make_decl_rtl (decl
, asmspec
, toplev
);
6156 rest_of_decl_compilation (decl
, asmspec
, toplev
, 0);
6158 else if (TREE_CODE (decl
) == VAR_DECL
6159 && DECL_LANG_SPECIFIC (decl
)
6160 && DECL_IN_AGGR_P (decl
))
6162 if (TREE_STATIC (decl
))
6164 if (init
== NULL_TREE
6165 #ifdef DEFAULT_STATIC_DEFS
6166 /* If this code is dead, then users must
6167 explicitly declare static member variables
6168 outside the class def'n as well. */
6169 && TYPE_NEEDS_CONSTRUCTING (type
)
6173 DECL_EXTERNAL (decl
) = 1;
6174 make_decl_rtl (decl
, asmspec
, 1);
6177 rest_of_decl_compilation (decl
, asmspec
, toplev
, 0);
6180 /* Just a constant field. Should not need any rtl. */
6184 rest_of_decl_compilation (decl
, asmspec
, toplev
, 0);
6187 resume_temporary_allocation ();
6189 if (type
!= error_mark_node
6190 && TYPE_LANG_SPECIFIC (type
)
6191 && CLASSTYPE_ABSTRACT_VIRTUALS (type
))
6192 abstract_virtuals_error (decl
, type
);
6193 else if ((TREE_CODE (type
) == FUNCTION_TYPE
6194 || TREE_CODE (type
) == METHOD_TYPE
)
6195 && TYPE_LANG_SPECIFIC (TREE_TYPE (type
))
6196 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type
)))
6197 abstract_virtuals_error (decl
, TREE_TYPE (type
));
6199 if (TYPE_LANG_SPECIFIC (type
) && IS_SIGNATURE (type
))
6200 signature_error (decl
, type
);
6201 else if ((TREE_CODE (type
) == FUNCTION_TYPE
6202 || TREE_CODE (type
) == METHOD_TYPE
)
6203 && TYPE_LANG_SPECIFIC (TREE_TYPE (type
))
6204 && IS_SIGNATURE (TREE_TYPE (type
)))
6205 signature_error (decl
, TREE_TYPE (type
));
6207 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6210 /* C++: Handle overloaded functions with default parameters. */
6211 if (DECL_OVERLOADED (decl
))
6213 tree parmtypes
= TYPE_ARG_TYPES (type
);
6214 tree prev
= NULL_TREE
;
6215 tree original_name
= DECL_NAME (decl
);
6216 struct lang_decl
*tmp_lang_decl
= DECL_LANG_SPECIFIC (decl
);
6217 /* All variants will share an uncollectible lang_decl. */
6218 copy_decl_lang_specific (decl
);
6220 while (parmtypes
&& parmtypes
!= void_list_node
)
6222 /* The default value for the parameter in parmtypes is
6223 stored in the TREE_PURPOSE of the TREE_LIST. */
6224 if (TREE_PURPOSE (parmtypes
))
6226 tree fnname
, fndecl
;
6229 argp
= prev
? & TREE_CHAIN (prev
)
6230 : & TYPE_ARG_TYPES (type
);
6233 fnname
= build_decl_overload (original_name
,
6234 TYPE_ARG_TYPES (type
), 0);
6236 fndecl
= build_decl (FUNCTION_DECL
, fnname
, type
);
6237 DECL_EXTERNAL (fndecl
) = DECL_EXTERNAL (decl
);
6238 TREE_PUBLIC (fndecl
) = TREE_PUBLIC (decl
);
6239 DECL_INLINE (fndecl
) = DECL_INLINE (decl
);
6240 /* Keep G++ from thinking this function is unused.
6241 It is only used to speed up search in name space. */
6242 TREE_USED (fndecl
) = 1;
6243 TREE_ASM_WRITTEN (fndecl
) = 1;
6244 DECL_INITIAL (fndecl
) = NULL_TREE
;
6245 DECL_LANG_SPECIFIC (fndecl
) = DECL_LANG_SPECIFIC (decl
);
6246 fndecl
= pushdecl (fndecl
);
6247 DECL_INITIAL (fndecl
) = error_mark_node
;
6248 DECL_RTL (fndecl
) = DECL_RTL (decl
);
6251 parmtypes
= TREE_CHAIN (parmtypes
);
6253 DECL_LANG_SPECIFIC (decl
) = tmp_lang_decl
;
6257 else if (DECL_EXTERNAL (decl
))
6259 else if (TREE_STATIC (decl
) && type
!= error_mark_node
)
6261 /* Cleanups for static variables are handled by `finish_file'. */
6262 if (TYPE_NEEDS_CONSTRUCTING (type
) || init
!= NULL_TREE
)
6263 expand_static_init (decl
, init
);
6264 else if (TYPE_NEEDS_DESTRUCTOR (type
))
6265 static_aggregates
= perm_tree_cons (NULL_TREE
, decl
,
6268 /* Make entry in appropriate vector. */
6269 if (flag_gc
&& type_needs_gc_entry (type
))
6270 build_static_gc_entry (decl
, type
);
6274 tree old_cleanups
= cleanups_this_call
;
6275 /* This is a declared decl which must live until the
6276 end of the binding contour. It may need a cleanup. */
6278 /* Recompute the RTL of a local array now
6279 if it used to be an incomplete type. */
6280 if (was_incomplete
&& ! TREE_STATIC (decl
))
6282 /* If we used it already as memory, it must stay in memory. */
6283 TREE_ADDRESSABLE (decl
) = TREE_USED (decl
);
6284 /* If it's still incomplete now, no init will save it. */
6285 if (DECL_SIZE (decl
) == NULL_TREE
)
6286 DECL_INITIAL (decl
) = NULL_TREE
;
6289 else if (! TREE_ASM_WRITTEN (decl
)
6290 && (TYPE_SIZE (type
) != NULL_TREE
6291 || TREE_CODE (type
) == ARRAY_TYPE
))
6293 /* Do this here, because we did not expand this decl's
6294 rtl in start_decl. */
6295 if (DECL_RTL (decl
) == NULL_RTX
)
6299 /* XXX: Why don't we use decl here? */
6300 /* Ans: Because it was already expanded? */
6301 if (! expand_decl_cleanup (NULL_TREE
, cleanup
))
6302 cp_error ("parser lost in parsing declaration of `%D'",
6304 /* Cleanup used up here. */
6305 cleanup
= NULL_TREE
;
6309 if (DECL_SIZE (decl
) && type
!= error_mark_node
)
6311 /* Compute and store the initial value. */
6312 expand_decl_init (decl
);
6314 if (init
|| TYPE_NEEDS_CONSTRUCTING (type
))
6316 emit_line_note (DECL_SOURCE_FILE (decl
),
6317 DECL_SOURCE_LINE (decl
));
6318 expand_aggr_init (decl
, init
, 0);
6321 /* Set this to 0 so we can tell whether an aggregate
6322 which was initialized was ever used. */
6323 if (TYPE_NEEDS_CONSTRUCTING (type
))
6324 TREE_USED (decl
) = 0;
6326 /* Store the cleanup, if there was one. */
6329 if (! expand_decl_cleanup (decl
, cleanup
))
6330 cp_error ("parser lost in parsing declaration of `%D'",
6334 /* Cleanup any temporaries needed for the initial value. */
6335 expand_cleanups_to (old_cleanups
);
6339 /* Undo call to `pushclass' that was done in `start_decl'
6340 due to initialization of qualified member variable.
6341 I.e., Foo::x = 10; */
6343 tree context
= DECL_CONTEXT (decl
);
6345 && TREE_CODE_CLASS (TREE_CODE (context
)) == 't'
6346 && (TREE_CODE (decl
) == VAR_DECL
6347 /* We also have a pushclass done that we need to undo here
6348 if we're at top level and declare a method. */
6349 || (TREE_CODE (decl
) == FUNCTION_DECL
6350 /* If size hasn't been set, we're still defining it,
6351 and therefore inside the class body; don't pop
6352 the binding level.. */
6353 && TYPE_SIZE (context
) != NULL_TREE
6354 /* The binding level gets popped elsewhere for a
6355 friend declaration inside another class. */
6357 && TYPE_IDENTIFIER (context) == current_class_name
6359 && context
== current_class_type
6367 /* If requested, warn about definitions of large data objects. */
6369 if (warn_larger_than
6370 && (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
)
6371 && !DECL_EXTERNAL (decl
))
6373 register tree decl_size
= DECL_SIZE (decl
);
6375 if (decl_size
&& TREE_CODE (decl_size
) == INTEGER_CST
)
6377 unsigned units
= TREE_INT_CST_LOW (decl_size
) / BITS_PER_UNIT
;
6379 if (units
> larger_than_size
)
6380 warning_with_decl (decl
, "size of `%s' is %u bytes", units
);
6386 /* Resume permanent allocation, if not within a function. */
6387 /* The corresponding push_obstacks_nochange is in start_decl,
6388 start_method, groktypename, and in grokfield. */
6393 TREE_READONLY (decl
) = 1;
6396 cadillac_finish_decl (decl
);
6400 expand_static_init (decl
, init
)
6404 tree oldstatic
= value_member (decl
, static_aggregates
);
6409 if (TREE_PURPOSE (oldstatic
) && init
!= NULL_TREE
)
6410 cp_error ("multiple initializations given for `%D'", decl
);
6412 else if (current_binding_level
!= global_binding_level
6413 && current_binding_level
->pseudo_global
== 0)
6415 /* Emit code to perform this initialization but once. */
6418 /* Remember this information until end of file. */
6419 push_obstacks (&permanent_obstack
, &permanent_obstack
);
6421 /* Emit code to perform this initialization but once. */
6422 temp
= get_temp_name (integer_type_node
, 1);
6423 rest_of_decl_compilation (temp
, NULL_PTR
, 0, 0);
6424 expand_start_cond (build_binary_op (EQ_EXPR
, temp
,
6425 integer_zero_node
, 1), 0);
6426 old_cleanups
= cleanups_this_call
;
6427 expand_assignment (temp
, integer_one_node
, 0, 0);
6428 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl
)))
6430 expand_aggr_init (decl
, init
, 0);
6431 do_pending_stack_adjust ();
6434 expand_assignment (decl
, init
, 0, 0);
6435 /* Cleanup any temporaries needed for the initial value. */
6436 expand_cleanups_to (old_cleanups
);
6438 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl
)))
6440 static_aggregates
= perm_tree_cons (temp
, decl
, static_aggregates
);
6441 TREE_STATIC (static_aggregates
) = 1;
6444 /* Resume old (possibly temporary) allocation. */
6449 /* This code takes into account memory allocation
6450 policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING
6451 does not hold for this object, then we must make permanent
6452 the storage currently in the temporary obstack. */
6453 if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl
)))
6454 preserve_initializer ();
6455 static_aggregates
= perm_tree_cons (init
, decl
, static_aggregates
);
6459 /* Make TYPE a complete type based on INITIAL_VALUE.
6460 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
6461 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
6464 complete_array_type (type
, initial_value
, do_default
)
6465 tree type
, initial_value
;
6468 register tree maxindex
= NULL_TREE
;
6473 /* Note MAXINDEX is really the maximum index,
6474 one less than the size. */
6475 if (TREE_CODE (initial_value
) == STRING_CST
)
6476 maxindex
= build_int_2 (TREE_STRING_LENGTH (initial_value
) - 1, 0);
6477 else if (TREE_CODE (initial_value
) == CONSTRUCTOR
)
6480 = list_length (CONSTRUCTOR_ELTS (initial_value
));
6481 maxindex
= build_int_2 (nelts
- 1, - (nelts
== 0));
6485 /* Make an error message unless that happened already. */
6486 if (initial_value
!= error_mark_node
)
6489 /* Prevent further error messages. */
6490 maxindex
= build_int_2 (0, 0);
6497 maxindex
= build_int_2 (0, 0);
6505 TYPE_DOMAIN (type
) = build_index_type (maxindex
);
6506 if (!TREE_TYPE (maxindex
))
6507 TREE_TYPE (maxindex
) = TYPE_DOMAIN (type
);
6509 itype
= TREE_TYPE (initial_value
);
6512 if (itype
&& !TYPE_DOMAIN (itype
))
6513 TYPE_DOMAIN (itype
) = TYPE_DOMAIN (type
);
6516 /* Lay out the type now that we can get the real answer. */
6523 /* Return zero if something is declared to be a member of type
6524 CTYPE when in the context of CUR_TYPE. STRING is the error
6525 message to print in that case. Otherwise, quietly return 1. */
6527 member_function_or_else (ctype
, cur_type
, string
)
6528 tree ctype
, cur_type
;
6531 if (ctype
&& ctype
!= cur_type
)
6533 error (string
, TYPE_NAME_STRING (ctype
));
6539 /* Subroutine of `grokdeclarator'. */
6541 /* Generate errors possibly applicable for a given set of specifiers.
6542 This is for ARM $7.1.2. */
6544 bad_specifiers (object
, type
, virtualp
, quals
, inlinep
, friendp
, raises
)
6547 int virtualp
, quals
, friendp
, raises
, inlinep
;
6550 cp_error ("`%D' declared as a `virtual' %s", object
, type
);
6552 cp_error ("`%D' declared as an `inline' %s", object
, type
);
6554 cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
6557 cp_error_at ("invalid friend declaration", object
);
6559 cp_error_at ("invalid raises declaration", object
);
6562 /* CTYPE is class type, or null if non-class.
6563 TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
6565 DECLARATOR is the function's name.
6566 VIRTUALP is truthvalue of whether the function is virtual or not.
6567 FLAGS are to be passed through to `grokclassfn'.
6568 QUALS are qualifiers indicating whether the function is `const'
6570 RAISES is a list of exceptions that this function can raise.
6571 CHECK is 1 if we must find this method in CTYPE, 0 if we should
6572 not look, and -1 if we should not call `grokclassfn' at all. */
6574 grokfndecl (ctype
, type
, declarator
, virtualp
, flags
, quals
,
6575 raises
, check
, publicp
)
6579 enum overload_flags flags
;
6584 int staticp
= ctype
&& TREE_CODE (type
) == FUNCTION_TYPE
;
6587 cname
= TREE_CODE (TYPE_NAME (ctype
)) == TYPE_DECL
6588 ? TYPE_IDENTIFIER (ctype
) : TYPE_NAME (ctype
);
6594 type
= build_exception_variant (ctype
, type
, raises
);
6595 raises
= TYPE_RAISES_EXCEPTIONS (type
);
6597 decl
= build_lang_decl (FUNCTION_DECL
, declarator
, type
);
6598 /* propagate volatile out from type to decl */
6599 if (TYPE_VOLATILE (type
))
6600 TREE_THIS_VOLATILE (decl
) = 1;
6602 /* Should probably propagate const out from type to decl I bet (mrs). */
6605 DECL_STATIC_FUNCTION_P (decl
) = 1;
6606 DECL_CONTEXT (decl
) = ctype
;
6607 DECL_CLASS_CONTEXT (decl
) = ctype
;
6611 TREE_PUBLIC (decl
) = 1;
6613 DECL_EXTERNAL (decl
) = 1;
6614 if (quals
!= NULL_TREE
&& TREE_CODE (type
) == FUNCTION_TYPE
)
6616 cp_error ("%smember function `%D' cannot have `%T' method qualifier",
6617 (ctype
? "static " : "non-"), decl
, TREE_VALUE (quals
));
6621 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl
)))
6622 grok_op_properties (decl
, virtualp
, check
< 0);
6624 /* Caller will do the rest of this. */
6628 if (flags
== NO_SPECIAL
&& ctype
&& constructor_name (cname
) == declarator
)
6631 /* Just handle constructors here. We could do this
6632 inside the following if stmt, but I think
6633 that the code is more legible by breaking this
6634 case out. See comments below for what each of
6635 the following calls is supposed to do. */
6636 DECL_CONSTRUCTOR_P (decl
) = 1;
6638 grokclassfn (ctype
, declarator
, decl
, flags
, quals
);
6640 check_classfn (ctype
, declarator
, decl
);
6641 if (! grok_ctor_properties (ctype
, decl
))
6644 if (check
== 0 && ! current_function_decl
)
6646 /* FIXME: this should only need to look at
6647 IDENTIFIER_GLOBAL_VALUE. */
6648 tmp
= lookup_name (DECL_ASSEMBLER_NAME (decl
), 0);
6649 if (tmp
== NULL_TREE
)
6650 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl
)) = decl
;
6651 else if (TREE_CODE (tmp
) != TREE_CODE (decl
))
6652 cp_error ("inconsistent declarations for `%D'", decl
);
6655 duplicate_decls (decl
, tmp
);
6657 /* avoid creating circularities. */
6658 DECL_CHAIN (decl
) = NULL_TREE
;
6660 make_decl_rtl (decl
, NULL_PTR
, 1);
6667 /* Function gets the ugly name, field gets the nice one.
6668 This call may change the type of the function (because
6669 of default parameters)! */
6670 if (ctype
!= NULL_TREE
)
6671 grokclassfn (ctype
, cname
, decl
, flags
, quals
);
6673 if (ctype
!= NULL_TREE
&& check
)
6674 check_classfn (ctype
, cname
, decl
);
6676 if (ctype
== NULL_TREE
|| check
)
6679 /* Now install the declaration of this function so that others may
6680 find it (esp. its DECL_FRIENDLIST). Don't do this for local class
6682 if (! current_function_decl
)
6684 /* FIXME: this should only need to look at
6685 IDENTIFIER_GLOBAL_VALUE. */
6686 tmp
= lookup_name (DECL_ASSEMBLER_NAME (decl
), 0);
6687 if (tmp
== NULL_TREE
)
6688 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl
)) = decl
;
6689 else if (TREE_CODE (tmp
) != TREE_CODE (decl
))
6690 cp_error ("inconsistent declarations for `%D'", decl
);
6693 duplicate_decls (decl
, tmp
);
6695 /* avoid creating circularities. */
6696 DECL_CHAIN (decl
) = NULL_TREE
;
6698 make_decl_rtl (decl
, NULL_PTR
, 1);
6701 /* If this declaration supersedes the declaration of
6702 a method declared virtual in the base class, then
6703 mark this field as being virtual as well. */
6705 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (ctype
));
6706 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
6708 for (i
= 0; i
< n_baselinks
; i
++)
6710 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
6711 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo
))
6712 || flag_all_virtual
== 1)
6714 tmp
= get_matching_virtual (base_binfo
, decl
,
6715 flags
== DTOR_FLAG
);
6718 /* If this function overrides some virtual in some base
6719 class, then the function itself is also necessarily
6720 virtual, even if the user didn't explicitly say so. */
6721 DECL_VIRTUAL_P (decl
) = 1;
6723 /* The TMP we really want is the one from the deepest
6724 baseclass on this path, taking care not to
6725 duplicate if we have already found it (via another
6726 path to its virtual baseclass. */
6729 cp_error ("method `%D' may not be declared static",
6731 cp_error_at ("(since `%D' declared virtual in base class.)",
6738 /* The argument types may have changed... */
6739 tree argtypes
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
6740 tree base_variant
= TREE_TYPE (TREE_VALUE (argtypes
));
6742 argtypes
= commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp
))),
6743 TREE_CHAIN (argtypes
));
6744 /* But the return type has not. */
6745 type
= build_cplus_method_type (base_variant
, TREE_TYPE (type
), argtypes
);
6748 type
= build_exception_variant (ctype
, type
, raises
);
6749 raises
= TYPE_RAISES_EXCEPTIONS (type
);
6751 TREE_TYPE (decl
) = type
;
6753 = tree_cons (NULL_TREE
, tmp
, DECL_VINDEX (decl
));
6762 if (DECL_VINDEX (decl
) == NULL_TREE
)
6763 DECL_VINDEX (decl
) = error_mark_node
;
6764 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl
)) = 1;
6765 if (ctype
&& CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
)
6766 /* If this function is derived from a template, don't
6767 make it public. This shouldn't be here, but there's
6768 no good way to override the interface pragmas for one
6769 function or class only. Bletch. */
6770 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype
)) == NULL_TREE
6771 && (write_virtuals
== 2
6772 || (write_virtuals
== 3
6773 && CLASSTYPE_INTERFACE_KNOWN (ctype
))))
6774 TREE_PUBLIC (decl
) = 1;
6781 grokvardecl (type
, declarator
, specbits
, initialized
)
6784 RID_BIT_TYPE specbits
;
6789 if (TREE_CODE (type
) == OFFSET_TYPE
)
6791 /* If you declare a static member so that it
6792 can be initialized, the code will reach here. */
6793 tree basetype
= TYPE_OFFSET_BASETYPE (type
);
6794 type
= TREE_TYPE (type
);
6795 decl
= build_lang_field_decl (VAR_DECL
, declarator
, type
);
6796 DECL_CONTEXT (decl
) = basetype
;
6797 DECL_CLASS_CONTEXT (decl
) = basetype
;
6800 decl
= build_decl (VAR_DECL
, declarator
, type
);
6802 if (RIDBIT_SETP (RID_EXTERN
, specbits
))
6804 DECL_THIS_EXTERN (decl
) = 1;
6805 DECL_EXTERNAL (decl
) = !initialized
;
6808 /* In class context, static means one per class,
6809 public access, and static storage. */
6810 if (DECL_FIELD_CONTEXT (decl
) != NULL_TREE
6811 && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl
)))
6813 TREE_PUBLIC (decl
) = 1;
6814 TREE_STATIC (decl
) = 1;
6815 DECL_EXTERNAL (decl
) = 0;
6817 /* At top level, either `static' or no s.c. makes a definition
6818 (perhaps tentative), and absence of `static' makes it public. */
6819 else if (current_binding_level
== global_binding_level
)
6821 TREE_PUBLIC (decl
) = RIDBIT_NOTSETP (RID_STATIC
, specbits
);
6822 TREE_STATIC (decl
) = ! DECL_EXTERNAL (decl
);
6824 /* Not at top level, only `static' makes a static definition. */
6827 TREE_STATIC (decl
) = !! RIDBIT_SETP (RID_STATIC
, specbits
);
6828 TREE_PUBLIC (decl
) = DECL_EXTERNAL (decl
);
6833 /* Create a canonical pointer to member function type. */
6836 build_ptrmemfunc_type (type
)
6843 /* If a canonical type already exists for this type, use it. We use
6844 this method instead of type_hash_canon, because it only does a
6845 simple equality check on the list of field members. */
6847 if ((t
= TYPE_GET_PTRMEMFUNC_TYPE (type
)))
6850 push_obstacks (TYPE_OBSTACK (type
), TYPE_OBSTACK (type
));
6852 u
= make_lang_type (UNION_TYPE
);
6853 fields
[0] = build_lang_field_decl (FIELD_DECL
, pfn_identifier
, type
);
6854 fields
[1] = build_lang_field_decl (FIELD_DECL
, delta2_identifier
,
6856 finish_builtin_type (u
, "__ptrmemfunc_type", fields
, 1, ptr_type_node
);
6857 TYPE_NAME (u
) = NULL_TREE
;
6859 t
= make_lang_type (RECORD_TYPE
);
6861 /* Let the front-end know this is a pointer to member function. */
6862 TYPE_PTRMEMFUNC_FLAG(t
) = 1;
6864 fields
[0] = build_lang_field_decl (FIELD_DECL
, delta_identifier
,
6866 fields
[1] = build_lang_field_decl (FIELD_DECL
, index_identifier
,
6868 fields
[2] = build_lang_field_decl (FIELD_DECL
, pfn_or_delta2_identifier
, u
);
6869 finish_builtin_type (t
, "__ptrmemfunc_type", fields
, 2, ptr_type_node
);
6873 /* Zap out the name so that the back-end will give us the debugging
6874 information for this anonymous RECORD_TYPE. */
6875 TYPE_NAME (t
) = NULL_TREE
;
6877 TYPE_SET_PTRMEMFUNC_TYPE (type
, t
);
6879 /* Seems to be wanted. */
6880 CLASSTYPE_GOT_SEMICOLON (t
) = 1;
6884 /* Given declspecs and a declarator,
6885 determine the name and type of the object declared
6886 and construct a ..._DECL node for it.
6887 (In one case we can return a ..._TYPE node instead.
6888 For invalid input we sometimes return 0.)
6890 DECLSPECS is a chain of tree_list nodes whose value fields
6891 are the storage classes and type specifiers.
6893 DECL_CONTEXT says which syntactic context this declaration is in:
6894 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
6895 FUNCDEF for a function definition. Like NORMAL but a few different
6896 error messages in each case. Return value may be zero meaning
6897 this definition is too screwy to try to parse.
6898 MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
6899 handle member functions (which have FIELD context).
6900 Return value may be zero meaning this definition is too screwy to
6902 PARM for a parameter declaration (either within a function prototype
6903 or before a function body). Make a PARM_DECL, or return void_type_node.
6904 TYPENAME if for a typename (in a cast or sizeof).
6905 Don't make a DECL node; just return the ..._TYPE node.
6906 FIELD for a struct or union field; make a FIELD_DECL.
6907 BITFIELD for a field with specified width.
6908 INITIALIZED is 1 if the decl has an initializer.
6910 In the TYPENAME case, DECLARATOR is really an absolute declarator.
6911 It may also be so in the PARM case, for a prototype where the
6912 argument type is specified but not the name.
6914 This function is where the complicated C meanings of `static'
6915 and `extern' are interpreted.
6917 For C++, if there is any monkey business to do, the function which
6918 calls this one must do it, i.e., prepending instance variables,
6919 renaming overloaded function names, etc.
6921 Note that for this C++, it is an error to define a method within a class
6922 which does not belong to that class.
6924 Except in the case where SCOPE_REFs are implicitly known (such as
6925 methods within a class being redundantly qualified),
6926 declarations which involve SCOPE_REFs are returned as SCOPE_REFs
6927 (class_name::decl_name). The caller must also deal with this.
6929 If a constructor or destructor is seen, and the context is FIELD,
6930 then the type gains the attribute TREE_HAS_x. If such a declaration
6931 is erroneous, NULL_TREE is returned.
6933 QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
6934 function, these are the qualifiers to give to the `this' pointer.
6936 May return void_type_node if the declarator turned out to be a friend.
6937 See grokfield for details. */
6939 enum return_types
{ return_normal
, return_ctor
, return_dtor
, return_conversion
};
6942 grokdeclarator (declarator
, declspecs
, decl_context
, initialized
, raises
)
6945 enum decl_context decl_context
;
6949 RID_BIT_TYPE specbits
;
6952 tree type
= NULL_TREE
;
6956 int virtualp
, friendp
, inlinep
, staticp
;
6957 int explicit_int
= 0;
6958 int explicit_char
= 0;
6959 int opaque_typedef
= 0;
6960 tree typedef_decl
= NULL_TREE
;
6962 tree typedef_type
= NULL_TREE
;
6963 int funcdef_flag
= 0;
6964 enum tree_code innermost_code
= ERROR_MARK
;
6966 int size_varies
= 0;
6967 /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
6968 All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
6969 tree init
= NULL_TREE
;
6971 /* Keep track of what sort of function is being processed
6972 so that we can warn about default return values, or explicit
6973 return values which do not match prescribed defaults. */
6974 enum return_types return_type
= return_normal
;
6976 tree dname
= NULL_TREE
;
6977 tree ctype
= current_class_type
;
6978 tree ctor_return_type
= NULL_TREE
;
6979 enum overload_flags flags
= NO_SPECIAL
;
6980 tree quals
= NULL_TREE
;
6982 RIDBIT_RESET_ALL (specbits
);
6983 if (decl_context
== FUNCDEF
)
6984 funcdef_flag
= 1, decl_context
= NORMAL
;
6985 else if (decl_context
== MEMFUNCDEF
)
6986 funcdef_flag
= -1, decl_context
= FIELD
;
6987 else if (decl_context
== BITFIELD
)
6988 bitfield
= 1, decl_context
= FIELD
;
6990 if (flag_traditional
&& allocation_temporary_p ())
6991 end_temporary_allocation ();
6993 /* Look inside a declarator for the name being declared
6994 and get it as a string, for an error message. */
6996 tree last
= NULL_TREE
;
6997 register tree decl
= declarator
;
7001 switch (TREE_CODE (decl
))
7005 decl
= TREE_OPERAND (decl
, 0);
7008 case BIT_NOT_EXPR
: /* for C++ destructors! */
7010 tree name
= TREE_OPERAND (decl
, 0);
7011 tree rename
= NULL_TREE
;
7013 my_friendly_assert (flags
== NO_SPECIAL
, 152);
7015 return_type
= return_dtor
;
7016 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 153);
7017 if (ctype
== NULL_TREE
)
7019 if (current_class_type
== NULL_TREE
)
7021 error ("destructors must be member functions");
7026 tree t
= constructor_name (current_class_name
);
7033 tree t
= constructor_name (ctype
);
7040 error ("destructor `%s' must match class name `%s'",
7041 IDENTIFIER_POINTER (name
),
7042 IDENTIFIER_POINTER (rename
));
7043 TREE_OPERAND (decl
, 0) = rename
;
7049 case ADDR_EXPR
: /* C++ reference declaration */
7054 innermost_code
= TREE_CODE (decl
);
7056 decl
= TREE_OPERAND (decl
, 0);
7060 if (parmlist_is_exprlist (TREE_OPERAND (decl
, 1)))
7062 /* This is actually a variable declaration using constructor
7063 syntax. We need to call start_decl and finish_decl so we
7064 can get the variable initialized... */
7067 /* We need to insinuate ourselves into the declarator in place
7068 of the CALL_EXPR. */
7069 TREE_OPERAND (last
, 0) = TREE_OPERAND (decl
, 0);
7071 declarator
= TREE_OPERAND (decl
, 0);
7073 init
= TREE_OPERAND (decl
, 1);
7075 decl
= start_decl (declarator
, declspecs
, 1, NULL_TREE
);
7076 finish_decl (decl
, init
, NULL_TREE
, 1);
7079 innermost_code
= TREE_CODE (decl
);
7080 decl
= TREE_OPERAND (decl
, 0);
7081 if (decl_context
== FIELD
&& ctype
== NULL_TREE
)
7082 ctype
= current_class_type
;
7083 if (ctype
!= NULL_TREE
7084 && decl
!= NULL_TREE
&& flags
!= DTOR_FLAG
7085 && decl
== constructor_name (ctype
))
7087 return_type
= return_ctor
;
7088 ctor_return_type
= ctype
;
7093 case IDENTIFIER_NODE
:
7097 if (IDENTIFIER_OPNAME_P (dname
))
7099 if (IDENTIFIER_TYPENAME_P (dname
))
7101 my_friendly_assert (flags
== NO_SPECIAL
, 154);
7102 flags
= TYPENAME_FLAG
;
7103 ctor_return_type
= TREE_TYPE (dname
);
7104 return_type
= return_conversion
;
7106 name
= operator_name_string (dname
);
7109 name
= IDENTIFIER_POINTER (dname
);
7115 /* Parse error puts this typespec where
7116 a declarator should go. */
7117 error ("declarator name missing");
7118 dname
= TYPE_NAME (decl
);
7119 if (dname
&& TREE_CODE (dname
) == TYPE_DECL
)
7120 dname
= DECL_NAME (dname
);
7121 name
= dname
? IDENTIFIER_POINTER (dname
) : "<nameless>";
7122 declspecs
= temp_tree_cons (NULL_TREE
, decl
, declspecs
);
7129 /* Perform error checking, and convert class names to types.
7130 We may call grokdeclarator multiple times for the same
7131 tree structure, so only do the conversion once. In this
7132 case, we have exactly what we want for `ctype'. */
7133 tree cname
= TREE_OPERAND (decl
, 0);
7134 if (cname
== NULL_TREE
)
7136 /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */
7137 else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname
))
7138 || TREE_CODE (cname
) == UNINSTANTIATED_P_TYPE
)
7140 else if (! is_aggr_typedef (cname
, 1))
7142 TREE_OPERAND (decl
, 0) = NULL_TREE
;
7144 /* Must test TREE_OPERAND (decl, 1), in case user gives
7145 us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */
7146 else if (TREE_OPERAND (decl
, 1)
7147 && TREE_CODE (TREE_OPERAND (decl
, 1)) == INDIRECT_REF
)
7149 TREE_OPERAND (decl
, 0) = IDENTIFIER_TYPE_VALUE (cname
);
7151 else if (ctype
== NULL_TREE
)
7153 ctype
= IDENTIFIER_TYPE_VALUE (cname
);
7154 TREE_OPERAND (decl
, 0) = ctype
;
7156 else if (TREE_COMPLEXITY (decl
) == current_class_depth
)
7157 TREE_OPERAND (decl
, 0) = ctype
;
7160 if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname
),
7163 cp_error ("type `%T' is not derived from type `%T'",
7164 IDENTIFIER_TYPE_VALUE (cname
), ctype
);
7165 TREE_OPERAND (decl
, 0) = NULL_TREE
;
7169 ctype
= IDENTIFIER_TYPE_VALUE (cname
);
7170 TREE_OPERAND (decl
, 0) = ctype
;
7174 decl
= TREE_OPERAND (decl
, 1);
7177 if (TREE_CODE (decl
) == IDENTIFIER_NODE
7178 && constructor_name (ctype
) == decl
)
7180 return_type
= return_ctor
;
7181 ctor_return_type
= ctype
;
7183 else if (TREE_CODE (decl
) == BIT_NOT_EXPR
7184 && TREE_CODE (TREE_OPERAND (decl
, 0)) == IDENTIFIER_NODE
7185 && constructor_name (ctype
) == TREE_OPERAND (decl
, 0))
7187 return_type
= return_dtor
;
7188 ctor_return_type
= ctype
;
7190 decl
= TREE_OPERAND (decl
, 0);
7201 return 0; /* We used to do a 155 abort here. */
7207 /* A function definition's declarator must have the form of
7208 a function declarator. */
7210 if (funcdef_flag
&& innermost_code
!= CALL_EXPR
)
7213 /* Anything declared one level down from the top level
7214 must be one of the parameters of a function
7215 (because the body is at least two levels down). */
7217 /* This heuristic cannot be applied to C++ nodes! Fixed, however,
7218 by not allowing C++ class definitions to specify their parameters
7219 with xdecls (must be spec.d in the parmlist).
7221 Since we now wait to push a class scope until we are sure that
7222 we are in a legitimate method context, we must set oldcname
7223 explicitly (since current_class_name is not yet alive). */
7225 if (decl_context
== NORMAL
7226 && current_binding_level
->level_chain
== global_binding_level
)
7227 decl_context
= PARM
;
7229 /* Look through the decl specs and record which ones appear.
7230 Some typespecs are defined as built-in typenames.
7231 Others, the ones that are modifiers of other types,
7232 are represented by bits in SPECBITS: set the bits for
7233 the modifiers that appear. Storage class keywords are also in SPECBITS.
7235 If there is a typedef name or a type, store the type in TYPE.
7236 This includes builtin typedefs such as `int'.
7238 Set EXPLICIT_INT if the type is `int' or `char' and did not
7239 come from a user typedef.
7241 Set LONGLONG if `long' is mentioned twice.
7243 For C++, constructors and destructors have their own fast treatment. */
7245 for (spec
= declspecs
; spec
; spec
= TREE_CHAIN (spec
))
7250 /* Certain parse errors slip through. For example,
7251 `int class;' is not caught by the parser. Try
7252 weakly to recover here. */
7253 if (TREE_CODE (spec
) != TREE_LIST
)
7256 id
= TREE_VALUE (spec
);
7258 if (TREE_CODE (id
) == IDENTIFIER_NODE
)
7260 if (id
== ridpointers
[(int) RID_INT
]
7261 || id
== ridpointers
[(int) RID_CHAR
]
7262 || id
== ridpointers
[(int) RID_BOOL
]
7263 || id
== ridpointers
[(int) RID_WCHAR
])
7266 error ("extraneous `%T' ignored", id
);
7269 if (id
== ridpointers
[(int) RID_INT
])
7271 else if (id
== ridpointers
[(int) RID_CHAR
])
7273 type
= TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id
));
7277 /* C++ aggregate types. */
7278 if (IDENTIFIER_HAS_TYPE_VALUE (id
))
7281 cp_error ("multiple declarations `%T' and `%T'", type
, id
);
7283 type
= IDENTIFIER_TYPE_VALUE (id
);
7287 for (i
= (int) RID_FIRST_MODIFIER
; i
< (int) RID_MAX
; i
++)
7289 if (ridpointers
[i
] == id
)
7291 if (i
== (int) RID_LONG
&& RIDBIT_SETP (i
, specbits
))
7293 if (pedantic
&& flag_ansi
)
7294 pedwarn ("duplicate `long'");
7296 error ("`long long long' is too long for GCC");
7300 else if (RIDBIT_SETP (i
, specbits
))
7301 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id
));
7302 RIDBIT_SET (i
, specbits
);
7308 error ("two or more data types in declaration of `%s'", name
);
7309 else if (TREE_CODE (id
) == IDENTIFIER_NODE
)
7311 register tree t
= lookup_name (id
, 1);
7312 if (!t
|| TREE_CODE (t
) != TYPE_DECL
)
7313 error ("`%s' fails to be a typedef or built in type",
7314 IDENTIFIER_POINTER (id
));
7317 type
= TREE_TYPE (t
);
7321 else if (TREE_CODE (id
) != ERROR_MARK
)
7322 /* Can't change CLASS nodes into RECORD nodes here! */
7328 typedef_type
= type
;
7330 /* No type at all: default to `int', and set EXPLICIT_INT
7331 because it was not a user-defined typedef.
7332 Except when we have a `typedef' inside a signature, in
7333 which case the type defaults to `unknown type' and is
7334 instantiated when assigning to a signature pointer or ref. */
7336 if (type
== NULL_TREE
7337 && (RIDBIT_SETP (RID_SIGNED
, specbits
)
7338 || RIDBIT_SETP (RID_UNSIGNED
, specbits
)
7339 || RIDBIT_SETP (RID_LONG
, specbits
)
7340 || RIDBIT_SETP (RID_SHORT
, specbits
)))
7342 /* These imply 'int'. */
7343 type
= integer_type_node
;
7347 if (type
== NULL_TREE
)
7350 if (return_type
== return_dtor
)
7351 type
= void_type_node
;
7352 else if (return_type
== return_ctor
)
7353 type
= TYPE_POINTER_TO (ctor_return_type
);
7354 else if (return_type
== return_conversion
)
7355 type
= ctor_return_type
;
7356 else if (current_class_type
7357 && IS_SIGNATURE (current_class_type
)
7358 && (RIDBIT_SETP (RID_TYPEDEF
, specbits
)
7359 || SIGNATURE_GROKKING_TYPEDEF (current_class_type
))
7360 && (decl_context
== FIELD
|| decl_context
== NORMAL
))
7364 type
= copy_node (opaque_type_node
);
7366 /* access declaration */
7367 else if (decl_context
== FIELD
&& declarator
7368 && TREE_CODE (declarator
) == SCOPE_REF
)
7369 type
= void_type_node
;
7374 if (warn_return_type
7375 && return_type
== return_normal
)
7376 /* Save warning until we know what is really going on. */
7377 warn_about_return_type
= 1;
7379 else if (RIDBIT_SETP (RID_TYPEDEF
, specbits
))
7380 pedwarn ("ANSI C++ forbids typedef which does not specify a type");
7381 else if (declspecs
== NULL_TREE
&&
7382 (innermost_code
!= CALL_EXPR
|| pedantic
))
7383 cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class",
7385 type
= integer_type_node
;
7388 else if (return_type
== return_dtor
)
7390 error ("return type specification for destructor invalid");
7391 type
= void_type_node
;
7393 else if (return_type
== return_ctor
)
7395 error ("return type specification for constructor invalid");
7396 type
= TYPE_POINTER_TO (ctor_return_type
);
7398 else if (return_type
== return_conversion
)
7400 if (comp_target_types (type
, ctor_return_type
, 1) == 0)
7401 cp_error ("operator `%T' declared to return `%T'",
7402 ctor_return_type
, type
);
7404 cp_pedwarn ("return type specified for `operator %T'",
7407 type
= ctor_return_type
;
7409 /* Catch typedefs that only specify a type, like 'typedef int;'. */
7410 else if (RIDBIT_SETP (RID_TYPEDEF
, specbits
) && declarator
== NULL_TREE
)
7412 /* Template "this is a type" syntax; just ignore for now. */
7413 if (processing_template_defn
)
7414 return void_type_node
;
7419 /* Now process the modifiers that were specified
7420 and check for invalid combinations. */
7422 /* Long double is a special combination. */
7424 if (RIDBIT_SETP (RID_LONG
, specbits
)
7425 && TYPE_MAIN_VARIANT (type
) == double_type_node
)
7427 RIDBIT_RESET (RID_LONG
, specbits
);
7428 type
= build_type_variant (long_double_type_node
, TYPE_READONLY (type
),
7429 TYPE_VOLATILE (type
));
7432 /* Check all other uses of type modifiers. */
7434 if (RIDBIT_SETP (RID_UNSIGNED
, specbits
)
7435 || RIDBIT_SETP (RID_SIGNED
, specbits
)
7436 || RIDBIT_SETP (RID_LONG
, specbits
)
7437 || RIDBIT_SETP (RID_SHORT
, specbits
))
7441 if (TREE_CODE (type
) == REAL_TYPE
)
7442 error ("short, signed or unsigned invalid for `%s'", name
);
7443 else if (TREE_CODE (type
) != INTEGER_TYPE
|| type
== wchar_type_node
)
7444 error ("long, short, signed or unsigned invalid for `%s'", name
);
7445 else if (RIDBIT_SETP (RID_LONG
, specbits
)
7446 && RIDBIT_SETP (RID_SHORT
, specbits
))
7447 error ("long and short specified together for `%s'", name
);
7448 else if ((RIDBIT_SETP (RID_LONG
, specbits
)
7449 || RIDBIT_SETP (RID_SHORT
, specbits
))
7451 error ("long or short specified with char for `%s'", name
);
7452 else if ((RIDBIT_SETP (RID_LONG
, specbits
)
7453 || RIDBIT_SETP (RID_SHORT
, specbits
))
7454 && TREE_CODE (type
) == REAL_TYPE
)
7455 error ("long or short specified with floating type for `%s'", name
);
7456 else if (RIDBIT_SETP (RID_SIGNED
, specbits
)
7457 && RIDBIT_SETP (RID_UNSIGNED
, specbits
))
7458 error ("signed and unsigned given together for `%s'", name
);
7462 if (!explicit_int
&& !explicit_char
&& pedantic
)
7464 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
7466 if (flag_pedantic_errors
)
7471 /* Discard the type modifiers if they are invalid. */
7474 RIDBIT_RESET (RID_UNSIGNED
, specbits
);
7475 RIDBIT_RESET (RID_SIGNED
, specbits
);
7476 RIDBIT_RESET (RID_LONG
, specbits
);
7477 RIDBIT_RESET (RID_SHORT
, specbits
);
7482 /* Decide whether an integer type is signed or not.
7483 Optionally treat bitfields as signed by default. */
7484 if (RIDBIT_SETP (RID_UNSIGNED
, specbits
)
7485 /* Traditionally, all bitfields are unsigned. */
7486 || (bitfield
&& flag_traditional
)
7487 || (bitfield
&& ! flag_signed_bitfields
7488 && (explicit_int
|| explicit_char
7489 /* A typedef for plain `int' without `signed'
7490 can be controlled just like plain `int'. */
7491 || ! (typedef_decl
!= NULL_TREE
7492 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl
)))
7493 && TREE_CODE (type
) != ENUMERAL_TYPE
7494 && RIDBIT_NOTSETP (RID_SIGNED
, specbits
)))
7497 type
= long_long_unsigned_type_node
;
7498 else if (RIDBIT_SETP (RID_LONG
, specbits
))
7499 type
= long_unsigned_type_node
;
7500 else if (RIDBIT_SETP (RID_SHORT
, specbits
))
7501 type
= short_unsigned_type_node
;
7502 else if (type
== char_type_node
)
7503 type
= unsigned_char_type_node
;
7504 else if (typedef_decl
)
7505 type
= unsigned_type (type
);
7507 type
= unsigned_type_node
;
7509 else if (RIDBIT_SETP (RID_SIGNED
, specbits
)
7510 && type
== char_type_node
)
7511 type
= signed_char_type_node
;
7513 type
= long_long_integer_type_node
;
7514 else if (RIDBIT_SETP (RID_LONG
, specbits
))
7515 type
= long_integer_type_node
;
7516 else if (RIDBIT_SETP (RID_SHORT
, specbits
))
7517 type
= short_integer_type_node
;
7519 /* Set CONSTP if this declaration is `const', whether by
7520 explicit specification or via a typedef.
7521 Likewise for VOLATILEP. */
7523 constp
= !! RIDBIT_SETP (RID_CONST
, specbits
) + TYPE_READONLY (type
);
7524 volatilep
= !! RIDBIT_SETP (RID_VOLATILE
, specbits
) + TYPE_VOLATILE (type
);
7526 inlinep
= !! RIDBIT_SETP (RID_INLINE
, specbits
);
7528 warning ("duplicate `const'");
7530 warning ("duplicate `volatile'");
7531 virtualp
= RIDBIT_SETP (RID_VIRTUAL
, specbits
);
7533 if (RIDBIT_SETP (RID_STATIC
, specbits
))
7534 staticp
= 1 + (decl_context
== FIELD
);
7536 if (virtualp
&& staticp
== 2)
7538 cp_error ("member `%D' cannot be declared both virtual and static",
7542 friendp
= RIDBIT_SETP (RID_FRIEND
, specbits
);
7543 RIDBIT_RESET (RID_VIRTUAL
, specbits
);
7544 RIDBIT_RESET (RID_FRIEND
, specbits
);
7546 if (RIDBIT_SETP (RID_MUTABLE
, specbits
))
7548 if (decl_context
== PARM
)
7550 error ("non-member `%s' cannot be declared mutable", name
);
7551 RIDBIT_RESET (RID_MUTABLE
, specbits
);
7553 else if (friendp
|| decl_context
== TYPENAME
)
7555 error ("non-object member `%s' cannot be declared mutable", name
);
7556 RIDBIT_RESET (RID_MUTABLE
, specbits
);
7560 error ("static `%s' cannot be declared mutable", name
);
7561 RIDBIT_RESET (RID_MUTABLE
, specbits
);
7564 if (RIDBIT_SETP (RID_TYPEDEF
, specbits
))
7566 error ("non-object member `%s' cannot be declared mutable", name
);
7567 RIDBIT_RESET (RID_MUTABLE
, specbits
);
7569 /* Because local typedefs are parsed twice, we don't want this
7571 else if (decl_context
!= FIELD
)
7573 error ("non-member `%s' cannot be declared mutable", name
);
7574 RIDBIT_RESET (RID_MUTABLE
, specbits
);
7579 /* Warn if two storage classes are given. Default to `auto'. */
7581 if (RIDBIT_ANY_SET (specbits
))
7583 if (RIDBIT_SETP (RID_STATIC
, specbits
)) nclasses
++;
7584 if (RIDBIT_SETP (RID_EXTERN
, specbits
)) nclasses
++;
7585 if (decl_context
== PARM
&& nclasses
> 0)
7586 error ("storage class specifiers invalid in parameter declarations");
7587 if (RIDBIT_SETP (RID_TYPEDEF
, specbits
))
7589 if (decl_context
== PARM
)
7590 error ("typedef declaration invalid in parameter declaration");
7593 if (RIDBIT_SETP (RID_AUTO
, specbits
)) nclasses
++;
7594 if (RIDBIT_SETP (RID_REGISTER
, specbits
)) nclasses
++;
7597 /* Give error if `virtual' is used outside of class declaration. */
7598 if (virtualp
&& current_class_name
== NULL_TREE
)
7600 error ("virtual outside class declaration");
7603 if (current_class_name
== NULL_TREE
&& RIDBIT_SETP (RID_MUTABLE
, specbits
))
7605 error ("only members can be declared mutable");
7606 RIDBIT_RESET (RID_MUTABLE
, specbits
);
7609 /* Static anonymous unions are dealt with here. */
7610 if (staticp
&& decl_context
== TYPENAME
7611 && TREE_CODE (declspecs
) == TREE_LIST
7612 && TREE_CODE (TREE_VALUE (declspecs
)) == UNION_TYPE
7613 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs
))))
7614 decl_context
= FIELD
;
7616 /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
7617 is used in a signature member function declaration. */
7618 if (decl_context
== FIELD
7619 && IS_SIGNATURE (current_class_type
)
7620 && RIDBIT_NOTSETP(RID_TYPEDEF
, specbits
)
7621 && !SIGNATURE_GROKKING_TYPEDEF (current_class_type
))
7625 error ("`const' specified for signature member function `%s'", name
);
7630 error ("`volatile' specified for signature member function `%s'",
7636 error ("`inline' specified for signature member function `%s'", name
);
7637 /* Later, we'll make signature member functions inline. */
7642 error ("`friend' declaration in signature definition");
7647 error ("`virtual' specified for signature member function `%s'",
7649 /* Later, we'll make signature member functions virtual. */
7654 /* Warn about storage classes that are invalid for certain
7655 kinds of declarations (parameters, typenames, etc.). */
7658 error ("multiple storage classes in declaration of `%s'", name
);
7659 else if (decl_context
!= NORMAL
&& nclasses
> 0)
7661 if (decl_context
== PARM
7662 && (RIDBIT_SETP (RID_REGISTER
, specbits
)
7663 || RIDBIT_SETP (RID_AUTO
, specbits
)))
7665 else if (decl_context
== FIELD
7666 && RIDBIT_SETP (RID_TYPEDEF
, specbits
))
7668 /* Processing a typedef declaration nested within a class type
7670 register tree scanner
;
7671 register tree previous_declspec
;
7675 error ("typedef declaration includes an initializer");
7677 /* To process a class-local typedef declaration, we descend down
7678 the chain of declspecs looking for the `typedef' spec. When
7679 we find it, we replace it with `static', and then recursively
7680 call `grokdeclarator' with the original declarator and with
7681 the newly adjusted declspecs. This call should return a
7682 FIELD_DECL node with the TREE_TYPE (and other parts) set
7683 appropriately. We can then just change the TREE_CODE on that
7684 from FIELD_DECL to TYPE_DECL and we're done. */
7686 for (previous_declspec
= NULL_TREE
, scanner
= declspecs
;
7688 previous_declspec
= scanner
, scanner
= TREE_CHAIN (scanner
))
7690 if (TREE_VALUE (scanner
) == ridpointers
[(int) RID_TYPEDEF
])
7694 if (scanner
== IDENTIFIER_AS_LIST (ridpointers
[(int) RID_TYPEDEF
]))
7696 if (previous_declspec
)
7697 TREE_CHAIN (previous_declspec
)
7698 = IDENTIFIER_AS_LIST (ridpointers
[(int) RID_STATIC
]);
7701 = IDENTIFIER_AS_LIST (ridpointers
[(int) RID_STATIC
]);
7704 TREE_VALUE (scanner
) = ridpointers
[(int) RID_STATIC
];
7706 /* In the recursive call to grokdeclarator we need to know
7707 whether we are working on a signature-local typedef. */
7708 if (IS_SIGNATURE (current_class_type
))
7709 SIGNATURE_GROKKING_TYPEDEF (current_class_type
) = 1;
7712 grokdeclarator (declarator
, declspecs
, FIELD
, 0, NULL_TREE
);
7714 if (loc_typedecl
!= error_mark_node
)
7716 register int i
= sizeof (struct lang_decl_flags
) / sizeof (int);
7719 TREE_SET_CODE (loc_typedecl
, TYPE_DECL
);
7721 pi
= (int *) permalloc (sizeof (struct lang_decl_flags
));
7724 DECL_LANG_SPECIFIC (loc_typedecl
) = (struct lang_decl
*) pi
;
7727 if (IS_SIGNATURE (current_class_type
))
7729 SIGNATURE_GROKKING_TYPEDEF (current_class_type
) = 0;
7730 if (loc_typedecl
!= error_mark_node
&& opaque_typedef
)
7731 SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type
) = 1;
7734 return loc_typedecl
;
7736 else if (decl_context
== FIELD
7737 && (! IS_SIGNATURE (current_class_type
)
7738 || SIGNATURE_GROKKING_TYPEDEF (current_class_type
))
7739 /* C++ allows static class elements */
7740 && RIDBIT_SETP (RID_STATIC
, specbits
))
7741 /* C++ also allows inlines and signed and unsigned elements,
7742 but in those cases we don't come in here. */
7746 if (decl_context
== FIELD
)
7748 tree tmp
= TREE_OPERAND (declarator
, 0);
7749 register int op
= IDENTIFIER_OPNAME_P (tmp
);
7750 error ("storage class specified for %s `%s'",
7751 IS_SIGNATURE (current_class_type
)
7753 ? "signature member operator"
7754 : "signature member function")
7755 : (op
? "member operator" : "structure field"),
7756 op
? operator_name_string (tmp
) : name
);
7759 error ((decl_context
== PARM
7760 ? "storage class specified for parameter `%s'"
7761 : "storage class specified for typename"), name
);
7762 RIDBIT_RESET (RID_REGISTER
, specbits
);
7763 RIDBIT_RESET (RID_AUTO
, specbits
);
7764 RIDBIT_RESET (RID_EXTERN
, specbits
);
7766 if (decl_context
== FIELD
&& IS_SIGNATURE (current_class_type
))
7768 RIDBIT_RESET (RID_STATIC
, specbits
);
7773 else if (RIDBIT_SETP (RID_EXTERN
, specbits
) && initialized
&& !funcdef_flag
)
7775 if (current_binding_level
== global_binding_level
)
7777 /* It's common practice (and completely legal) to have a const
7778 be initialized and declared extern. */
7780 warning ("`%s' initialized and declared `extern'", name
);
7783 error ("`%s' has both `extern' and initializer", name
);
7785 else if (RIDBIT_SETP (RID_EXTERN
, specbits
) && funcdef_flag
7786 && current_binding_level
!= global_binding_level
)
7787 error ("nested function `%s' declared `extern'", name
);
7788 else if (current_binding_level
== global_binding_level
)
7790 if (RIDBIT_SETP (RID_AUTO
, specbits
))
7791 error ("top-level declaration of `%s' specifies `auto'", name
);
7793 if (RIDBIT_SETP (RID_REGISTER
, specbits
))
7794 error ("top-level declaration of `%s' specifies `register'", name
);
7797 /* I'm not sure under what circumstances we should turn
7798 on the extern bit, and under what circumstances we should
7799 warn if other bits are turned on. */
7800 if (decl_context
== NORMAL
7801 && RIDBIT_NOSETP (RID_EXTERN
, specbits
)
7802 && ! root_lang_context_p ())
7804 RIDBIT_SET (RID_EXTERN
, specbits
);
7809 /* Now figure out the structure of the declarator proper.
7810 Descend through it, creating more complex types, until we reach
7811 the declared identifier (or NULL_TREE, in an absolute declarator). */
7813 while (declarator
&& TREE_CODE (declarator
) != IDENTIFIER_NODE
)
7815 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
7816 an INDIRECT_REF (for *...),
7817 a CALL_EXPR (for ...(...)),
7818 an identifier (for the name being declared)
7819 or a null pointer (for the place in an absolute declarator
7820 where the name was omitted).
7821 For the last two cases, we have just exited the loop.
7823 For C++ it could also be
7824 a SCOPE_REF (for class :: ...). In this case, we have converted
7825 sensible names to types, and those are the values we use to
7826 qualify the member name.
7827 an ADDR_EXPR (for &...),
7828 a BIT_NOT_EXPR (for destructors)
7830 At this point, TYPE is the type of elements of an array,
7831 or for a function to return, or for a pointer to point to.
7832 After this sequence of ifs, TYPE is the type of the
7833 array or function or pointer, and DECLARATOR has had its
7834 outermost layer removed. */
7836 if (TREE_CODE (type
) == ERROR_MARK
)
7838 if (TREE_CODE (declarator
) == SCOPE_REF
)
7839 declarator
= TREE_OPERAND (declarator
, 1);
7841 declarator
= TREE_OPERAND (declarator
, 0);
7844 if (quals
!= NULL_TREE
7845 && (declarator
== NULL_TREE
7846 || TREE_CODE (declarator
) != SCOPE_REF
))
7848 if (ctype
== NULL_TREE
&& TREE_CODE (type
) == METHOD_TYPE
)
7849 ctype
= TYPE_METHOD_BASETYPE (type
);
7850 if (ctype
!= NULL_TREE
)
7852 #if 0 /* not yet, should get fixed properly later */
7853 tree dummy
= make_type_decl (NULL_TREE
, type
);
7855 tree dummy
= build_decl (TYPE_DECL
, NULL_TREE
, type
);
7857 ctype
= grok_method_quals (ctype
, dummy
, quals
);
7858 type
= TREE_TYPE (dummy
);
7862 switch (TREE_CODE (declarator
))
7866 register tree itype
= NULL_TREE
;
7867 register tree size
= TREE_OPERAND (declarator
, 1);
7869 declarator
= TREE_OPERAND (declarator
, 0);
7871 /* Check for some types that there cannot be arrays of. */
7873 if (TYPE_MAIN_VARIANT (type
) == void_type_node
)
7875 cp_error ("declaration of `%D' as array of voids", dname
);
7876 type
= error_mark_node
;
7879 if (TREE_CODE (type
) == FUNCTION_TYPE
)
7881 cp_error ("declaration of `%D' as array of functions", dname
);
7882 type
= error_mark_node
;
7885 /* ARM $8.4.3: Since you can't have a pointer to a reference,
7886 you can't have arrays of references. If we allowed them,
7887 then we'd be saying x[i] is legal for an array x, but
7888 then you'd have to ask: what does `*(x + i)' mean? */
7889 if (TREE_CODE (type
) == REFERENCE_TYPE
)
7891 if (decl_context
== TYPENAME
)
7892 cp_error ("cannot make arrays of references");
7894 cp_error ("declaration of `%D' as array of references",
7896 type
= error_mark_node
;
7899 if (TREE_CODE (type
) == OFFSET_TYPE
)
7901 cp_error ("declaration of `%D' as array of data members",
7903 type
= error_mark_node
;
7906 if (TREE_CODE (type
) == METHOD_TYPE
)
7908 cp_error ("declaration of `%D' as array of function members",
7910 type
= error_mark_node
;
7913 if (size
== error_mark_node
)
7914 type
= error_mark_node
;
7916 if (type
== error_mark_node
)
7921 /* Must suspend_momentary here because the index
7922 type may need to live until the end of the function.
7923 For example, it is used in the declaration of a
7924 variable which requires destructing at the end of
7925 the function; then build_vec_delete will need this
7927 int yes
= suspend_momentary ();
7928 /* might be a cast */
7929 if (TREE_CODE (size
) == NOP_EXPR
7930 && TREE_TYPE (size
) == TREE_TYPE (TREE_OPERAND (size
, 0)))
7931 size
= TREE_OPERAND (size
, 0);
7933 /* If this is a template parameter, it'll be constant, but
7934 we don't know what the value is yet. */
7935 if (TREE_CODE (size
) == TEMPLATE_CONST_PARM
)
7936 goto dont_grok_size
;
7938 if (TREE_CODE (TREE_TYPE (size
)) != INTEGER_TYPE
7939 && TREE_CODE (TREE_TYPE (size
)) != ENUMERAL_TYPE
)
7941 cp_error ("size of array `%D' has non-integer type",
7943 size
= integer_one_node
;
7945 if (TREE_READONLY_DECL_P (size
))
7946 size
= decl_constant_value (size
);
7947 if (flag_ansi
&& integer_zerop (size
))
7948 cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname
);
7949 if (TREE_CONSTANT (size
))
7951 constant_expression_warning (size
);
7952 if (INT_CST_LT (size
, integer_zero_node
))
7954 cp_error ("size of array `%D' is negative", dname
);
7955 size
= integer_one_node
;
7957 itype
= build_index_type (size_binop (MINUS_EXPR
, size
,
7965 cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
7968 cp_pedwarn ("ANSI C++ forbids variable-size array");
7972 build_binary_op (MINUS_EXPR
, size
, integer_one_node
, 1);
7973 /* Make sure the array size remains visibly nonconstant
7974 even if it is (eg) a const variable with known value. */
7976 itype
= variable_size (itype
);
7977 itype
= build_index_type (itype
);
7979 resume_momentary (yes
);
7982 /* Build the array type itself, then merge any constancy or
7983 volatility into the target type. We must do it in this order
7984 to ensure that the TYPE_MAIN_VARIANT field of the array type
7985 is set correctly. */
7987 type
= build_cplus_array_type (type
, itype
);
7988 if (constp
|| volatilep
)
7989 type
= c_build_type_variant (type
, constp
, volatilep
);
7999 /* Declaring a function type.
8000 Make sure we have a valid type for the function to return. */
8002 /* Is this an error? Should they be merged into TYPE here? */
8003 if (pedantic
&& (constp
|| volatilep
))
8004 pedwarn ("function declared to return const or volatile result");
8006 /* Merge any constancy or volatility into the function return
8009 if (constp
|| volatilep
)
8011 type
= c_build_type_variant (type
, constp
, volatilep
);
8012 if (IS_AGGR_TYPE (type
))
8013 build_pointer_type (type
);
8019 /* Warn about some types functions can't return. */
8021 if (TREE_CODE (type
) == FUNCTION_TYPE
)
8023 error ("`%s' declared as function returning a function", name
);
8024 type
= integer_type_node
;
8026 if (TREE_CODE (type
) == ARRAY_TYPE
)
8028 error ("`%s' declared as function returning an array", name
);
8029 type
= integer_type_node
;
8032 if (ctype
== NULL_TREE
8033 && decl_context
== FIELD
8034 && (friendp
== 0 || dname
== current_class_name
))
8035 ctype
= current_class_type
;
8037 if (ctype
&& return_type
== return_conversion
)
8038 TYPE_HAS_CONVERSION (ctype
) = 1;
8039 if (ctype
&& constructor_name (ctype
) == dname
)
8041 /* We are within a class's scope. If our declarator name
8042 is the same as the class name, and we are defining
8043 a function, then it is a constructor/destructor, and
8044 therefore returns a void type. */
8046 if (flags
== DTOR_FLAG
)
8048 /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may
8049 not be declared const or volatile. A destructor
8050 may not be static. */
8052 error ("destructor cannot be static member function");
8053 if (TYPE_READONLY (type
))
8055 error ("destructors cannot be declared `const'");
8056 return void_type_node
;
8058 if (TYPE_VOLATILE (type
))
8060 error ("destructors cannot be declared `volatile'");
8061 return void_type_node
;
8063 if (decl_context
== FIELD
)
8065 if (! member_function_or_else (ctype
, current_class_type
,
8066 "destructor for alien class `%s' cannot be a member"))
8067 return void_type_node
;
8070 else /* it's a constructor. */
8072 /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may
8073 not be declared const or volatile. A constructor may
8074 not be virtual. A constructor may not be static. */
8076 error ("constructor cannot be static member function");
8079 pedwarn ("constructors cannot be declared virtual");
8082 if (TYPE_READONLY (type
))
8084 error ("constructors cannot be declared `const'");
8085 return void_type_node
;
8087 if (TYPE_VOLATILE (type
))
8089 error ("constructors cannot be declared `volatile'");
8090 return void_type_node
;
8093 RID_BIT_TYPE tmp_bits
;
8094 bcopy ((void*)&specbits
, (void*)&tmp_bits
, sizeof(RID_BIT_TYPE
));
8095 RIDBIT_RESET (RID_INLINE
, tmp_bits
);
8096 RIDBIT_RESET (RID_STATIC
, tmp_bits
);
8097 if (RIDBIT_ANY_SET (tmp_bits
))
8098 error ("return value type specifier for constructor ignored");
8100 type
= TYPE_POINTER_TO (ctype
);
8101 if (decl_context
== FIELD
&&
8102 IS_SIGNATURE (current_class_type
))
8104 error ("constructor not allowed in signature");
8105 return void_type_node
;
8107 else if (decl_context
== FIELD
)
8109 if (! member_function_or_else (ctype
, current_class_type
,
8110 "constructor for alien class `%s' cannot be member"))
8111 return void_type_node
;
8112 TYPE_HAS_CONSTRUCTOR (ctype
) = 1;
8113 if (return_type
!= return_ctor
)
8117 if (decl_context
== FIELD
)
8120 else if (friendp
&& virtualp
)
8122 /* Cannot be both friend and virtual. */
8123 error ("virtual functions cannot be friends");
8124 RIDBIT_RESET (RID_FRIEND
, specbits
);
8128 if (decl_context
== NORMAL
&& friendp
)
8129 error ("friend declaration not in class definition");
8131 /* Pick up type qualifiers which should be applied to `this'. */
8132 quals
= TREE_OPERAND (declarator
, 2);
8134 /* Traditionally, declaring return type float means double. */
8136 if (flag_traditional
8137 && TYPE_MAIN_VARIANT (type
) == float_type_node
)
8139 type
= build_type_variant (double_type_node
,
8140 TYPE_READONLY (type
),
8141 TYPE_VOLATILE (type
));
8144 /* Construct the function type and go to the next
8145 inner layer of declarator. */
8149 tree inner_parms
= TREE_OPERAND (declarator
, 1);
8150 tree inner_decl
= TREE_OPERAND (declarator
, 0);
8152 declarator
= TREE_OPERAND (declarator
, 0);
8154 if (inner_decl
&& TREE_CODE (inner_decl
) == SCOPE_REF
)
8155 inner_decl
= TREE_OPERAND (inner_decl
, 1);
8157 /* Say it's a definition only for the CALL_EXPR
8158 closest to the identifier. */
8160 (inner_decl
&& TREE_CODE (inner_decl
) == IDENTIFIER_NODE
)
8163 /* FIXME: This is where default args should be fully
8166 arg_types
= grokparms (inner_parms
, funcdef_p
);
8171 /* Get past destructors, etc.
8172 We know we have one because FLAGS will be non-zero.
8174 Complain about improper parameter lists here. */
8175 if (TREE_CODE (declarator
) == BIT_NOT_EXPR
)
8177 declarator
= TREE_OPERAND (declarator
, 0);
8179 if (strict_prototype
== 0 && arg_types
== NULL_TREE
)
8180 arg_types
= void_list_node
;
8181 else if (arg_types
== NULL_TREE
8182 || arg_types
!= void_list_node
)
8184 error ("destructors cannot be specified with parameters");
8185 arg_types
= void_list_node
;
8190 /* ANSI seems to say that `const int foo ();'
8191 does not make the function foo const. */
8192 type
= build_function_type (type
,
8193 flag_traditional
? 0 : arg_types
);
8199 /* Filter out pointers-to-references and references-to-references.
8200 We can get these if a TYPE_DECL is used. */
8202 if (TREE_CODE (type
) == REFERENCE_TYPE
)
8204 error ("cannot declare %s to references",
8205 TREE_CODE (declarator
) == ADDR_EXPR
8206 ? "references" : "pointers");
8207 declarator
= TREE_OPERAND (declarator
, 0);
8211 /* Merge any constancy or volatility into the target type
8214 if (constp
|| volatilep
)
8216 /* A const or volatile signature pointer/reference is
8217 pointing to a const or volatile object, i.e., the
8218 `optr' is const or volatile, respectively, not the
8219 signature pointer/reference itself. */
8220 if (! IS_SIGNATURE (type
))
8222 type
= c_build_type_variant (type
, constp
, volatilep
);
8223 if (IS_AGGR_TYPE (type
))
8224 build_pointer_type (type
);
8230 if (IS_SIGNATURE (type
))
8232 if (TREE_CODE (declarator
) == ADDR_EXPR
)
8234 if (CLASSTYPE_METHOD_VEC (type
) == NULL_TREE
8235 && TYPE_SIZE (type
))
8236 cp_warning ("empty signature `%T' used in signature reference declaration",
8239 type
= build_signature_reference_type (type
,
8242 sorry ("signature reference");
8248 if (CLASSTYPE_METHOD_VEC (type
) == NULL_TREE
8249 && TYPE_SIZE (type
))
8250 cp_warning ("empty signature `%T' used in signature pointer declaration",
8252 type
= build_signature_pointer_type (type
,
8258 else if (TREE_CODE (declarator
) == ADDR_EXPR
)
8260 if (TREE_CODE (type
) == FUNCTION_TYPE
)
8262 error ("cannot declare references to functions; use pointer to function instead");
8263 type
= build_pointer_type (type
);
8267 if (TYPE_MAIN_VARIANT (type
) == void_type_node
)
8268 error ("invalid type: `void &'");
8270 type
= build_reference_type (type
);
8273 else if (TREE_CODE (type
) == METHOD_TYPE
)
8275 type
= build_ptrmemfunc_type (build_pointer_type (type
));
8278 type
= build_pointer_type (type
);
8280 /* Process a list of type modifier keywords (such as
8281 const or volatile) that were given inside the `*' or `&'. */
8283 if (TREE_TYPE (declarator
))
8285 register tree typemodlist
;
8287 for (typemodlist
= TREE_TYPE (declarator
); typemodlist
;
8288 typemodlist
= TREE_CHAIN (typemodlist
))
8290 if (TREE_VALUE (typemodlist
) == ridpointers
[(int) RID_CONST
])
8292 else if (TREE_VALUE (typemodlist
) == ridpointers
[(int) RID_VOLATILE
])
8297 error ("invalid type modifier within %s declarator",
8298 TREE_CODE (declarator
) == ADDR_EXPR
8299 ? "reference" : "pointer");
8303 pedwarn ("duplicate `const'");
8305 pedwarn ("duplicate `volatile'");
8306 if (TREE_CODE (declarator
) == ADDR_EXPR
8307 && (constp
|| volatilep
))
8310 warning ("discarding `const' applied to a reference");
8312 warning ("discarding `volatile' applied to a reference");
8313 constp
= volatilep
= 0;
8316 declarator
= TREE_OPERAND (declarator
, 0);
8322 /* We have converted type names to NULL_TREE if the
8323 name was bogus, or to a _TYPE node, if not.
8325 The variable CTYPE holds the type we will ultimately
8326 resolve to. The code here just needs to build
8327 up appropriate member types. */
8328 tree sname
= TREE_OPERAND (declarator
, 1);
8329 /* Destructors can have their visibilities changed as well. */
8330 if (TREE_CODE (sname
) == BIT_NOT_EXPR
)
8331 sname
= TREE_OPERAND (sname
, 0);
8333 if (TREE_COMPLEXITY (declarator
) == 0)
8334 /* This needs to be here, in case we are called
8335 multiple times. */ ;
8336 else if (friendp
&& (TREE_COMPLEXITY (declarator
) < 2))
8337 /* don't fall out into global scope. Hides real bug? --eichin */ ;
8338 else if (TREE_COMPLEXITY (declarator
) == current_class_depth
)
8340 /* This pop_nested_class corresponds to the
8341 push_nested_class used to push into class scope for
8342 parsing the argument list of a function decl, in
8344 pop_nested_class (1);
8345 TREE_COMPLEXITY (declarator
) = current_class_depth
;
8348 my_friendly_abort (16);
8350 if (TREE_OPERAND (declarator
, 0) == NULL_TREE
)
8352 /* We had a reference to a global decl, or
8353 perhaps we were given a non-aggregate typedef,
8354 in which case we cleared this out, and should just
8355 keep going as though it wasn't there. */
8359 ctype
= TREE_OPERAND (declarator
, 0);
8361 if (sname
== NULL_TREE
)
8364 if (TREE_CODE (sname
) == IDENTIFIER_NODE
)
8366 /* This is the `standard' use of the scoping operator:
8367 basetype :: member . */
8369 if (TREE_CODE (type
) == FUNCTION_TYPE
)
8371 if (current_class_type
== NULL_TREE
8372 || TYPE_MAIN_VARIANT (ctype
) == current_class_type
8374 type
= build_cplus_method_type (build_type_variant (ctype
, constp
, volatilep
),
8375 TREE_TYPE (type
), TYPE_ARG_TYPES (type
));
8378 cp_error ("cannot declare member function `%T::%s' within `%T'",
8379 ctype
, name
, current_class_type
);
8380 return void_type_node
;
8383 else if (TYPE_MAIN_VARIANT (ctype
) == current_class_type
)
8386 cp_warning ("redundant qualification `%T' on member `%s' ignored",
8388 type
= build_offset_type (ctype
, type
);
8390 else if (TYPE_SIZE (ctype
) != NULL_TREE
8391 || (RIDBIT_SETP (RID_TYPEDEF
, specbits
)))
8394 /* have to move this code elsewhere in this function.
8395 this code is used for i.e., typedef int A::M; M *pm; */
8397 if (explicit_int
== -1 && decl_context
== FIELD
8398 && funcdef_flag
== 0)
8400 /* The code in here should only be used to build
8401 stuff that will be grokked as access decls. */
8402 t
= lookup_field (ctype
, sname
, 0, 0);
8405 t
= build_lang_field_decl (FIELD_DECL
, build_nt (SCOPE_REF
, ctype
, t
), type
);
8406 DECL_INITIAL (t
) = init
;
8409 /* No such field, try member functions. */
8410 t
= lookup_fnfields (TYPE_BINFO (ctype
), sname
, 0);
8413 if (flags
== DTOR_FLAG
)
8415 else if (CLASSTYPE_METHOD_VEC (ctype
)
8416 && TREE_VALUE (t
) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype
), 0))
8418 /* Don't include destructor with constructors. */
8419 t
= DECL_CHAIN (TREE_VALUE (t
));
8421 error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname
));
8422 t
= build_tree_list (NULL_TREE
, t
);
8424 t
= build_lang_field_decl (FIELD_DECL
, build_nt (SCOPE_REF
, ctype
, t
), type
);
8425 DECL_INITIAL (t
) = init
;
8430 ("field `%D' is not a member of structure `%T'",
8434 if (current_class_type
)
8436 if (TYPE_MAIN_VARIANT (ctype
) != current_class_type
)
8438 cp_error ("cannot declare member `%T::%s' within `%T'",
8439 ctype
, name
, current_class_type
);
8440 return void_type_node
;
8442 else if (extra_warnings
)
8443 cp_warning ("extra qualification `%T' on member `%s' ignored",
8446 type
= build_offset_type (ctype
, type
);
8448 else if (uses_template_parms (ctype
))
8451 if (TREE_CODE (type
) == FUNCTION_TYPE
)
8453 type
= build_cplus_method_type (build_type_variant (ctype
, constp
, volatilep
),
8455 TYPE_ARG_TYPES (type
));
8461 cp_error ("structure `%T' not yet defined", ctype
);
8462 return error_mark_node
;
8467 else if (TREE_CODE (sname
) == SCOPE_REF
)
8468 my_friendly_abort (17);
8472 declarator
= TREE_OPERAND (declarator
, 1);
8473 if (declarator
&& TREE_CODE (declarator
) == CALL_EXPR
)
8474 /* In this case, we will deal with it later. */
8478 if (TREE_CODE (type
) == FUNCTION_TYPE
)
8479 type
= build_cplus_method_type (build_type_variant (ctype
, constp
, volatilep
), TREE_TYPE (type
), TYPE_ARG_TYPES (type
));
8481 type
= build_offset_type (ctype
, type
);
8488 declarator
= TREE_OPERAND (declarator
, 0);
8494 declarator
= NULL_TREE
;
8498 declarator
= NULL_TREE
;
8502 my_friendly_abort (158);
8506 /* Now TYPE has the actual type. */
8508 /* If this is declaring a typedef name, return a TYPE_DECL. */
8510 if (RIDBIT_SETP (RID_TYPEDEF
, specbits
))
8514 /* Note that the grammar rejects storage classes
8515 in typenames, fields or parameters. */
8516 if (constp
|| volatilep
)
8517 type
= c_build_type_variant (type
, constp
, volatilep
);
8519 /* If the user declares "struct {...} foo" then `foo' will have
8520 an anonymous name. Fill that name in now. Nothing can
8521 refer to it, so nothing needs know about the name change.
8522 The TYPE_NAME field was filled in by build_struct_xref. */
8523 if (type
!= error_mark_node
8525 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
8526 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type
)))
8528 /* replace the anonymous name with the real name everywhere. */
8529 lookup_tag_reverse (type
, declarator
);
8530 TYPE_IDENTIFIER (type
) = declarator
;
8532 if (TYPE_LANG_SPECIFIC (type
))
8533 TYPE_WAS_ANONYMOUS (type
) = 1;
8536 tree d
= TYPE_NAME (type
), c
= DECL_CONTEXT (d
);
8539 set_nested_typename (d
, 0, declarator
, type
);
8540 else if (TREE_CODE (c
) == FUNCTION_DECL
)
8541 set_nested_typename (d
, DECL_ASSEMBLER_NAME (c
),
8544 set_nested_typename (d
, TYPE_NESTED_NAME (c
), declarator
, type
);
8548 #if 0 /* not yet, should get fixed properly later */
8549 decl
= make_type_decl (declarator
, type
);
8551 decl
= build_decl (TYPE_DECL
, declarator
, type
);
8553 if (TREE_CODE (type
) == OFFSET_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
8555 cp_error_at ("typedef name may not be class-qualified", decl
);
8560 if (ctype
== NULL_TREE
)
8562 if (TREE_CODE (type
) != METHOD_TYPE
)
8563 cp_error_at ("invalid type qualifier for non-method type", decl
);
8565 ctype
= TYPE_METHOD_BASETYPE (type
);
8567 if (ctype
!= NULL_TREE
)
8568 grok_method_quals (ctype
, decl
, quals
);
8571 if (RIDBIT_SETP (RID_SIGNED
, specbits
)
8572 || (typedef_decl
&& C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl
)))
8573 C_TYPEDEF_EXPLICITLY_SIGNED (decl
) = 1;
8575 if (RIDBIT_SETP (RID_MUTABLE
, specbits
))
8577 error ("non-object member `%s' cannot be declared mutable", name
);
8583 /* Detect the case of an array type of unspecified size
8584 which came, as such, direct from a typedef name.
8585 We must copy the type, so that each identifier gets
8586 a distinct type, so that each identifier's size can be
8587 controlled separately by its own initializer. */
8589 if (type
== typedef_type
&& TREE_CODE (type
) == ARRAY_TYPE
8590 && TYPE_DOMAIN (type
) == NULL_TREE
)
8592 type
= build_cplus_array_type (TREE_TYPE (type
), TYPE_DOMAIN (type
));
8595 /* If this is a type name (such as, in a cast or sizeof),
8596 compute the type and return it now. */
8598 if (decl_context
== TYPENAME
)
8600 /* Note that the grammar rejects storage classes
8601 in typenames, fields or parameters. */
8602 if (constp
|| volatilep
)
8603 if (IS_SIGNATURE (type
))
8604 error ("`const' or `volatile' specified with signature type");
8606 type
= c_build_type_variant (type
, constp
, volatilep
);
8608 /* Special case: "friend class foo" looks like a TYPENAME context. */
8611 /* A friendly class? */
8612 if (current_class_type
)
8613 make_friend_class (current_class_type
, TYPE_MAIN_VARIANT (type
));
8615 error("trying to make class `%s' a friend of global scope",
8616 TYPE_NAME_STRING (type
));
8617 type
= void_type_node
;
8621 #if 0 /* not yet, should get fixed properly later */
8622 tree dummy
= make_type_decl (declarator
, type
);
8624 tree dummy
= build_decl (TYPE_DECL
, declarator
, type
);
8626 if (ctype
== NULL_TREE
)
8628 my_friendly_assert (TREE_CODE (type
) == METHOD_TYPE
, 159);
8629 ctype
= TYPE_METHOD_BASETYPE (type
);
8631 grok_method_quals (ctype
, dummy
, quals
);
8632 type
= TREE_TYPE (dummy
);
8637 else if (declarator
== NULL_TREE
&& decl_context
!= PARM
8638 && TREE_CODE (type
) != UNION_TYPE
8641 cp_error ("abstract declarator `%T' used as declaration", type
);
8642 declarator
= make_anon_name ();
8645 /* `void' at top level (not within pointer)
8646 is allowed only in typedefs or type names.
8647 We don't complain about parms either, but that is because
8648 a better error message can be made later. */
8650 if (TYPE_MAIN_VARIANT (type
) == void_type_node
&& decl_context
!= PARM
)
8652 if (TREE_CODE (declarator
) == IDENTIFIER_NODE
)
8654 if (IDENTIFIER_OPNAME_P (declarator
))
8655 #if 0 /* How could this happen? */
8656 error ("operator `%s' declared void",
8657 operator_name_string (declarator
));
8659 my_friendly_abort (356);
8662 error ("variable or field `%s' declared void", name
);
8665 error ("variable or field declared void");
8666 type
= integer_type_node
;
8669 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
8670 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
8675 if (decl_context
== PARM
)
8678 error ("cannot use `::' in parameter declaration");
8680 /* A parameter declared as an array of T is really a pointer to T.
8681 One declared as a function is really a pointer to a function.
8682 One declared as a member is really a pointer to member. */
8684 if (TREE_CODE (type
) == ARRAY_TYPE
)
8686 /* Transfer const-ness of array into that of type pointed to. */
8687 type
= build_pointer_type
8688 (c_build_type_variant (TREE_TYPE (type
), constp
, volatilep
));
8689 volatilep
= constp
= 0;
8691 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
8692 type
= build_pointer_type (type
);
8693 else if (TREE_CODE (type
) == OFFSET_TYPE
)
8694 type
= build_pointer_type (type
);
8696 decl
= build_decl (PARM_DECL
, declarator
, type
);
8698 bad_specifiers (decl
, "parameter", virtualp
, quals
!= NULL_TREE
,
8699 inlinep
, friendp
, raises
!= NULL_TREE
);
8700 if (current_class_type
8701 && IS_SIGNATURE (current_class_type
))
8704 error ("parameter of signature member function declared `inline'");
8705 if (RIDBIT_SETP (RID_AUTO
, specbits
))
8706 error ("parameter of signature member function declared `auto'");
8707 if (RIDBIT_SETP (RID_REGISTER
, specbits
))
8708 error ("parameter of signature member function declared `register'");
8711 /* Compute the type actually passed in the parmlist,
8712 for the case where there is no prototype.
8713 (For example, shorts and chars are passed as ints.)
8714 When there is a prototype, this is overridden later. */
8716 DECL_ARG_TYPE (decl
) = type_promotes_to (type
);
8718 else if (decl_context
== FIELD
)
8720 if (type
== error_mark_node
)
8722 /* Happens when declaring arrays of sizes which
8723 are error_mark_node, for example. */
8726 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
8732 if (ctype
== NULL_TREE
)
8733 ctype
= current_class_type
;
8735 if (ctype
== NULL_TREE
)
8737 cp_error ("can't make `%D' into a method -- not in a class",
8739 return void_type_node
;
8742 /* ``A union may [ ... ] not [ have ] virtual functions.''
8744 if (virtualp
&& TREE_CODE (ctype
) == UNION_TYPE
)
8746 cp_error ("function `%D' declared virtual inside a union",
8748 return void_type_node
;
8751 if (declarator
== ansi_opname
[(int) NEW_EXPR
]
8752 || declarator
== ansi_opname
[(int) VEC_NEW_EXPR
]
8753 || declarator
== ansi_opname
[(int) DELETE_EXPR
]
8754 || declarator
== ansi_opname
[(int) VEC_DELETE_EXPR
])
8758 cp_error ("`%D' cannot be declared virtual, since it is always static",
8763 else if (staticp
< 2)
8764 type
= build_cplus_method_type (build_type_variant (ctype
, constp
, volatilep
),
8765 TREE_TYPE (type
), TYPE_ARG_TYPES (type
));
8768 /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
8769 publicp
= (RIDBIT_SETP (RID_EXTERN
, specbits
)
8770 || (ctype
!= NULL_TREE
8771 && funcdef_flag
>= 0
8772 && RIDBIT_NOTSETP (RID_INLINE
, specbits
))
8775 && RIDBIT_NOTSETP (RID_STATIC
, specbits
)
8776 && RIDBIT_NOTSETP (RID_INLINE
, specbits
)));
8777 decl
= grokfndecl (ctype
, type
, declarator
,
8778 virtualp
, flags
, quals
,
8779 raises
, friendp
? -1 : 0, publicp
);
8780 if (decl
== NULL_TREE
)
8783 DECL_INLINE (decl
) = inlinep
;
8785 else if (TREE_CODE (type
) == METHOD_TYPE
)
8787 /* All method decls are public, so tell grokfndecl to set
8788 TREE_PUBLIC, also. */
8789 decl
= grokfndecl (ctype
, type
, declarator
,
8790 virtualp
, flags
, quals
,
8791 raises
, friendp
? -1 : 0, 1);
8792 if (decl
== NULL_TREE
)
8795 DECL_INLINE (decl
) = inlinep
;
8797 else if (TREE_CODE (type
) == RECORD_TYPE
8798 && CLASSTYPE_DECLARED_EXCEPTION (type
))
8800 /* Handle a class-local exception declaration. */
8801 decl
= build_lang_field_decl (VAR_DECL
, declarator
, type
);
8802 if (ctype
== NULL_TREE
)
8803 ctype
= current_class_type
;
8804 return void_type_node
;
8806 else if (TYPE_SIZE (type
) == NULL_TREE
&& !staticp
8807 && (TREE_CODE (type
) != ARRAY_TYPE
|| initialized
== 0))
8809 error ("field `%s' has incomplete type",
8810 IDENTIFIER_POINTER (declarator
));
8812 /* If we're instantiating a template, tell them which
8813 instantiation made the field's type be incomplete. */
8814 if (current_class_type
8815 && TYPE_NAME (current_class_type
)
8816 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type
)))
8817 && declspecs
&& TREE_VALUE (declspecs
)
8818 && TREE_TYPE (TREE_VALUE (declspecs
)) == type
)
8819 error (" in instantiation of template `%s'",
8820 TYPE_NAME_STRING (current_class_type
));
8822 type
= error_mark_node
;
8829 error ("`%s' is neither function nor method; cannot be declared friend",
8830 IDENTIFIER_POINTER (declarator
));
8838 /* Friends are treated specially. */
8839 if (ctype
== current_class_type
)
8840 warning ("member functions are implicitly friends of their class");
8844 if (decl
&& DECL_NAME (decl
))
8845 t
= do_friend (ctype
, declarator
, decl
,
8846 last_function_parms
, flags
, quals
);
8847 if (t
&& funcdef_flag
)
8850 return void_type_node
;
8854 /* Structure field. It may not be a function, except for C++ */
8856 if (decl
== NULL_TREE
)
8860 /* Motion 10 at San Diego: If a static const integral data
8861 member is initialized with an integral constant
8862 expression, the initializer may appear either in the
8863 declaration (within the class), or in the definition,
8864 but not both. If it appears in the class, the member is
8865 a member constant. The file-scope definition is always
8872 cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
8875 else if (! INTEGRAL_TYPE_P (type
))
8876 cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator
, type
);
8880 /* Note that initialization of const members is prohibited
8881 by the draft ANSI standard, though it appears to be in
8882 common practice. 12.6.2: The argument list is used to
8883 initialize the named nonstatic member.... This (or an
8884 initializer list) is the only way to initialize
8885 nonstatic const and reference members. */
8886 else if (flag_ansi
|| ! constp
)
8887 cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
8888 constp
? "const member" : "member", declarator
);
8891 if (staticp
|| (constp
&& initialized
))
8893 /* C++ allows static class members.
8894 All other work for this is done by grokfield.
8895 This VAR_DECL is built by build_lang_field_decl.
8896 All other VAR_DECLs are built by build_decl. */
8897 decl
= build_lang_field_decl (VAR_DECL
, declarator
, type
);
8898 TREE_STATIC (decl
) = 1;
8899 /* In class context, 'static' means public access. */
8900 TREE_PUBLIC (decl
) = DECL_EXTERNAL (decl
) = !!staticp
;
8904 decl
= build_lang_field_decl (FIELD_DECL
, declarator
, type
);
8905 if (RIDBIT_SETP (RID_MUTABLE
, specbits
))
8907 DECL_MUTABLE_P (decl
) = 1;
8908 RIDBIT_RESET (RID_MUTABLE
, specbits
);
8912 bad_specifiers (decl
, "field", virtualp
, quals
!= NULL_TREE
,
8913 inlinep
, friendp
, raises
!= NULL_TREE
);
8916 else if (TREE_CODE (type
) == FUNCTION_TYPE
|| TREE_CODE (type
) == METHOD_TYPE
)
8918 tree original_name
= declarator
;
8924 if (RIDBIT_SETP (RID_AUTO
, specbits
))
8925 error ("storage class `auto' invalid for function `%s'", name
);
8926 else if (RIDBIT_SETP (RID_REGISTER
, specbits
))
8927 error ("storage class `register' invalid for function `%s'", name
);
8929 /* Function declaration not at top level.
8930 Storage classes other than `extern' are not allowed
8931 and `extern' makes no difference. */
8932 if (current_binding_level
!= global_binding_level
8933 && ! processing_template_decl
8934 && (RIDBIT_SETP (RID_STATIC
, specbits
)
8935 || RIDBIT_SETP (RID_INLINE
, specbits
))
8938 if (RIDBIT_SETP (RID_STATIC
, specbits
))
8939 pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name
);
8941 pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name
);
8944 if (ctype
== NULL_TREE
)
8948 error ("virtual non-class function `%s'", name
);
8952 if (current_lang_name
== lang_name_cplusplus
8953 && ! (IDENTIFIER_LENGTH (original_name
) == 4
8954 && IDENTIFIER_POINTER (original_name
)[0] == 'm'
8955 && strcmp (IDENTIFIER_POINTER (original_name
), "main") == 0)
8956 && ! (IDENTIFIER_LENGTH (original_name
) > 10
8957 && IDENTIFIER_POINTER (original_name
)[0] == '_'
8958 && IDENTIFIER_POINTER (original_name
)[1] == '_'
8959 && strncmp (IDENTIFIER_POINTER (original_name
)+2, "builtin_", 8) == 0))
8960 /* Plain overloading: will not be grok'd by grokclassfn. */
8961 declarator
= build_decl_overload (dname
, TYPE_ARG_TYPES (type
), 0);
8963 else if (TREE_CODE (type
) == FUNCTION_TYPE
&& staticp
< 2)
8964 type
= build_cplus_method_type (build_type_variant (ctype
, constp
, volatilep
),
8965 TREE_TYPE (type
), TYPE_ARG_TYPES (type
));
8967 /* Record presence of `static'. In C++, `inline' is like `static'.
8968 Methods of classes should be public, unless we're dropping them
8969 into some other file, so we don't clear TREE_PUBLIC for them. */
8972 && CLASSTYPE_INTERFACE_KNOWN (ctype
))
8973 || !(RIDBIT_SETP (RID_STATIC
, specbits
)
8974 || RIDBIT_SETP (RID_INLINE
, specbits
)));
8976 decl
= grokfndecl (ctype
, type
, original_name
,
8977 virtualp
, flags
, quals
,
8979 processing_template_decl
? 0 : friendp
? 2 : 1,
8981 if (decl
== NULL_TREE
)
8984 if (ctype
== NULL_TREE
&& DECL_LANGUAGE (decl
) != lang_c
)
8985 DECL_ASSEMBLER_NAME (decl
) = declarator
;
8989 int illegal_static
= 0;
8991 /* Don't allow a static member function in a class, and forbid
8992 declaring main to be static. */
8993 if (TREE_CODE (type
) == METHOD_TYPE
)
8995 cp_error_at ("cannot declare member function `%D' to have static linkage", decl
);
8999 && IDENTIFIER_LENGTH (original_name
) == 4
9000 && IDENTIFIER_POINTER (original_name
)[0] == 'm'
9001 && ! strcmp (IDENTIFIER_POINTER (original_name
), "main"))
9003 error ("cannot declare function `main' to have static linkage");
9006 else if (current_function_decl
)
9008 /* FIXME need arm citation */
9009 error ("cannot declare static function inside another function");
9016 RIDBIT_RESET (RID_STATIC
, specbits
);
9020 /* Record presence of `inline', if it is reasonable. */
9023 tree last
= tree_last (TYPE_ARG_TYPES (type
));
9026 && ! strcmp (IDENTIFIER_POINTER (original_name
), "main"))
9027 error ("cannot inline function `main'");
9028 else if (last
&& last
!= void_list_node
)
9029 cp_warning ("cannot inline function `%D' which takes `...'", original_name
);
9031 /* Assume that otherwise the function can be inlined. */
9032 DECL_INLINE (decl
) = 1;
9034 if (RIDBIT_SETP (RID_EXTERN
, specbits
))
9036 current_extern_inline
= 1;
9038 pedwarn ("ANSI C++ does not permit `extern inline'");
9044 /* It's a variable. */
9046 /* An uninitialized decl with `extern' is a reference. */
9047 decl
= grokvardecl (type
, declarator
, specbits
, initialized
);
9048 bad_specifiers (decl
, "variable", virtualp
, quals
!= NULL_TREE
,
9049 inlinep
, friendp
, raises
!= NULL_TREE
);
9053 DECL_CONTEXT (decl
) = ctype
;
9056 cp_error ("static member `%D' re-declared as static",
9059 RIDBIT_RESET (RID_STATIC
, specbits
);
9061 if (RIDBIT_SETP (RID_EXTERN
, specbits
))
9063 cp_error ("cannot explicitly declare member `%#D' to have extern linkage",
9065 RIDBIT_RESET (RID_EXTERN
, specbits
);
9070 if (RIDBIT_SETP (RID_MUTABLE
, specbits
))
9072 error ("`%s' cannot be declared mutable", name
);
9075 /* Record `register' declaration for warnings on &
9076 and in case doing stupid register allocation. */
9078 if (RIDBIT_SETP (RID_REGISTER
, specbits
))
9079 DECL_REGISTER (decl
) = 1;
9081 if (RIDBIT_SETP (RID_EXTERN
, specbits
))
9082 DECL_THIS_EXTERN (decl
) = 1;
9084 /* Record constancy and volatility. */
9087 TREE_READONLY (decl
) = TREE_CODE (type
) != REFERENCE_TYPE
;
9090 TREE_SIDE_EFFECTS (decl
) = 1;
9091 TREE_THIS_VOLATILE (decl
) = 1;
9098 /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
9099 An empty exprlist is a parmlist. An exprlist which
9100 contains only identifiers at the global level
9101 is a parmlist. Otherwise, it is an exprlist. */
9103 parmlist_is_exprlist (exprs
)
9106 if (exprs
== NULL_TREE
|| TREE_PARMLIST (exprs
))
9109 if (current_binding_level
== global_binding_level
)
9111 /* At the global level, if these are all identifiers,
9112 then it is a parmlist. */
9115 if (TREE_CODE (TREE_VALUE (exprs
)) != IDENTIFIER_NODE
)
9117 exprs
= TREE_CHAIN (exprs
);
9124 /* Subroutine of `grokparms'. In a fcn definition, arg types must
9127 C++: also subroutine of `start_function'. */
9129 require_complete_types_for_parms (parms
)
9134 tree type
= TREE_TYPE (parms
);
9135 if (TYPE_SIZE (type
) == NULL_TREE
)
9137 if (DECL_NAME (parms
))
9138 error ("parameter `%s' has incomplete type",
9139 IDENTIFIER_POINTER (DECL_NAME (parms
)));
9141 error ("parameter has incomplete type");
9142 TREE_TYPE (parms
) = error_mark_node
;
9145 /* If the arg types are incomplete in a declaration,
9146 they must include undefined tags.
9147 These tags can never be defined in the scope of the declaration,
9148 so the types can never be completed,
9149 and no call can be compiled successfully. */
9150 /* This is not the right behavior for C++, but not having
9151 it is also probably wrong. */
9154 /* Now warn if is a pointer to an incomplete type. */
9155 while (TREE_CODE (type
) == POINTER_TYPE
9156 || TREE_CODE (type
) == REFERENCE_TYPE
)
9157 type
= TREE_TYPE (type
);
9158 type
= TYPE_MAIN_VARIANT (type
);
9159 if (TYPE_SIZE (type
) == NULL_TREE
)
9161 if (DECL_NAME (parm
) != NULL_TREE
)
9162 warning ("parameter `%s' points to incomplete type",
9163 IDENTIFIER_POINTER (DECL_NAME (parm
)));
9165 warning ("parameter points to incomplete type");
9169 parms
= TREE_CHAIN (parms
);
9173 /* Decode the list of parameter types for a function type.
9174 Given the list of things declared inside the parens,
9175 return a list of types.
9177 The list we receive can have three kinds of elements:
9178 an IDENTIFIER_NODE for names given without types,
9179 a TREE_LIST node for arguments given as typespecs or names with typespecs,
9180 or void_type_node, to mark the end of an argument list
9181 when additional arguments are not permitted (... was not used).
9183 FUNCDEF_FLAG is nonzero for a function definition, 0 for
9184 a mere declaration. A nonempty identifier-list gets an error message
9185 when FUNCDEF_FLAG is zero.
9186 If FUNCDEF_FLAG is 1, then parameter types must be complete.
9187 If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
9189 If all elements of the input list contain types,
9190 we return a list of the types.
9191 If all elements contain no type (except perhaps a void_type_node
9192 at the end), we return a null list.
9193 If some have types and some do not, it is an error, and we
9196 Also set last_function_parms to either
9197 a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
9198 A list of names is converted to a chain of PARM_DECLs
9199 by store_parm_decls so that ultimately it is always a chain of decls.
9201 Note that in C++, parameters can take default values. These default
9202 values are in the TREE_PURPOSE field of the TREE_LIST. It is
9203 an error to specify default values which are followed by parameters
9204 that have no default values, or an ELLIPSES. For simplicities sake,
9205 only parameters which are specified with their types can take on
9209 grokparms (first_parm
, funcdef_flag
)
9213 tree result
= NULL_TREE
;
9214 tree decls
= NULL_TREE
;
9216 if (first_parm
!= NULL_TREE
9217 && TREE_CODE (TREE_VALUE (first_parm
)) == IDENTIFIER_NODE
)
9220 pedwarn ("parameter names (without types) in function declaration");
9221 last_function_parms
= first_parm
;
9224 else if (first_parm
!= NULL_TREE
9225 && TREE_CODE (TREE_VALUE (first_parm
)) != TREE_LIST
9226 && TREE_VALUE (first_parm
) != void_type_node
)
9227 my_friendly_abort (145);
9230 /* Types were specified. This is a list of declarators
9231 each represented as a TREE_LIST node. */
9232 register tree parm
, chain
;
9233 int any_init
= 0, any_error
= 0, saw_void
= 0;
9235 if (first_parm
!= NULL_TREE
)
9237 tree last_result
= NULL_TREE
;
9238 tree last_decl
= NULL_TREE
;
9240 for (parm
= first_parm
; parm
!= NULL_TREE
; parm
= chain
)
9242 tree type
, list_node
= parm
;
9243 register tree decl
= TREE_VALUE (parm
);
9244 tree init
= TREE_PURPOSE (parm
);
9246 chain
= TREE_CHAIN (parm
);
9247 /* @@ weak defense against parse errors. */
9248 if (decl
!= void_type_node
&& TREE_CODE (decl
) != TREE_LIST
)
9250 /* Give various messages as the need arises. */
9251 if (TREE_CODE (decl
) == STRING_CST
)
9252 error ("invalid string constant `%s'",
9253 TREE_STRING_POINTER (decl
));
9254 else if (TREE_CODE (decl
) == INTEGER_CST
)
9255 error ("invalid integer constant in parameter list, did you forget to give parameter name?");
9259 if (decl
!= void_type_node
)
9261 /* @@ May need to fetch out a `raises' here. */
9262 decl
= grokdeclarator (TREE_VALUE (decl
),
9263 TREE_PURPOSE (decl
),
9264 PARM
, init
!= NULL_TREE
, NULL_TREE
);
9267 type
= TREE_TYPE (decl
);
9268 if (TYPE_MAIN_VARIANT (type
) == void_type_node
)
9269 decl
= void_type_node
;
9270 else if (TREE_CODE (type
) == METHOD_TYPE
)
9272 if (DECL_NAME (decl
))
9273 /* Cannot use `error_with_decl' here because
9274 we don't have DECL_CONTEXT set up yet. */
9275 error ("parameter `%s' invalidly declared method type",
9276 IDENTIFIER_POINTER (DECL_NAME (decl
)));
9278 error ("parameter invalidly declared method type");
9279 type
= build_pointer_type (type
);
9280 TREE_TYPE (decl
) = type
;
9282 else if (TREE_CODE (type
) == OFFSET_TYPE
)
9284 if (DECL_NAME (decl
))
9285 error ("parameter `%s' invalidly declared offset type",
9286 IDENTIFIER_POINTER (DECL_NAME (decl
)));
9288 error ("parameter invalidly declared offset type");
9289 type
= build_pointer_type (type
);
9290 TREE_TYPE (decl
) = type
;
9292 else if (TREE_CODE (type
) == RECORD_TYPE
9293 && TYPE_LANG_SPECIFIC (type
)
9294 && CLASSTYPE_ABSTRACT_VIRTUALS (type
))
9296 abstract_virtuals_error (decl
, type
);
9297 any_error
= 1; /* seems like a good idea */
9299 else if (TREE_CODE (type
) == RECORD_TYPE
9300 && TYPE_LANG_SPECIFIC (type
)
9301 && IS_SIGNATURE (type
))
9303 signature_error (decl
, type
);
9304 any_error
= 1; /* seems like a good idea */
9308 if (decl
== void_type_node
)
9310 if (result
== NULL_TREE
)
9312 result
= void_list_node
;
9313 last_result
= result
;
9317 TREE_CHAIN (last_result
) = void_list_node
;
9318 last_result
= void_list_node
;
9322 && (chain
!= void_list_node
|| TREE_CHAIN (chain
)))
9323 error ("`void' in parameter list must be entire list");
9327 /* Since there is a prototype, args are passed in their own types. */
9328 DECL_ARG_TYPE (decl
) = TREE_TYPE (decl
);
9329 #ifdef PROMOTE_PROTOTYPES
9330 if ((TREE_CODE (type
) == INTEGER_TYPE
9331 || TREE_CODE (type
) == ENUMERAL_TYPE
)
9332 && TYPE_PRECISION (type
) < TYPE_PRECISION (integer_type_node
))
9333 DECL_ARG_TYPE (decl
) = integer_type_node
;
9340 if (TREE_CODE (init
) == SAVE_EXPR
)
9341 PARM_DECL_EXPR (init
) = 1;
9342 else if (TREE_CODE (init
) == VAR_DECL
)
9344 if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init
)))
9346 /* ``Local variables may not be used in default
9347 argument expressions.'' dpANSI C++ 8.2.6 */
9348 /* If extern int i; within a function is not
9349 considered a local variable, then this code is
9351 cp_error ("local variable `%D' may not be used as a default argument", init
);
9354 else if (TREE_READONLY_DECL_P (init
))
9355 init
= decl_constant_value (init
);
9358 init
= require_instantiated_type (type
, init
, integer_zero_node
);
9362 error ("all trailing parameters must have default arguments");
9369 if (decls
== NULL_TREE
)
9376 TREE_CHAIN (last_decl
) = decl
;
9379 if (TREE_PERMANENT (list_node
))
9381 TREE_PURPOSE (list_node
) = init
;
9382 TREE_VALUE (list_node
) = type
;
9383 TREE_CHAIN (list_node
) = NULL_TREE
;
9386 list_node
= saveable_tree_cons (init
, type
, NULL_TREE
);
9387 if (result
== NULL_TREE
)
9390 last_result
= result
;
9394 TREE_CHAIN (last_result
) = list_node
;
9395 last_result
= list_node
;
9399 TREE_CHAIN (last_result
) = NULL_TREE
;
9400 /* If there are no parameters, and the function does not end
9401 with `...', then last_decl will be NULL_TREE. */
9402 if (last_decl
!= NULL_TREE
)
9403 TREE_CHAIN (last_decl
) = NULL_TREE
;
9407 last_function_parms
= decls
;
9409 /* In a fcn definition, arg types must be complete. */
9410 if (funcdef_flag
> 0)
9411 require_complete_types_for_parms (last_function_parms
);
9416 /* These memoizing functions keep track of special properties which
9417 a class may have. `grok_ctor_properties' notices whether a class
9418 has a constructor of the form X(X&), and also complains
9419 if the class has a constructor of the form X(X).
9420 `grok_op_properties' takes notice of the various forms of
9421 operator= which are defined, as well as what sorts of type conversion
9422 may apply. Both functions take a FUNCTION_DECL as an argument. */
9424 grok_ctor_properties (ctype
, decl
)
9427 tree parmtypes
= FUNCTION_ARG_CHAIN (decl
);
9428 tree parmtype
= parmtypes
? TREE_VALUE (parmtypes
) : void_type_node
;
9430 /* When a type has virtual baseclasses, a magical first int argument is
9431 added to any ctor so we can tell if the class has been initialized
9432 yet. This could screw things up in this function, so we deliberately
9433 ignore the leading int if we're in that situation. */
9435 && TREE_VALUE (parmtypes
) == integer_type_node
9436 && TYPE_USES_VIRTUAL_BASECLASSES (ctype
))
9438 parmtypes
= TREE_CHAIN (parmtypes
);
9439 parmtype
= TREE_VALUE (parmtypes
);
9442 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
9443 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype
)) == ctype
)
9445 if (TREE_CHAIN (parmtypes
) == NULL_TREE
9446 || TREE_CHAIN (parmtypes
) == void_list_node
9447 || TREE_PURPOSE (TREE_CHAIN (parmtypes
)))
9449 TYPE_HAS_INIT_REF (ctype
) = 1;
9450 if (TYPE_READONLY (TREE_TYPE (parmtype
)))
9451 TYPE_HAS_CONST_INIT_REF (ctype
) = 1;
9454 TYPE_GETS_INIT_AGGR (ctype
) = 1;
9456 else if (TYPE_MAIN_VARIANT (parmtype
) == ctype
)
9458 if (TREE_CHAIN (parmtypes
) != NULL_TREE
9459 && TREE_CHAIN (parmtypes
) == void_list_node
)
9461 cp_error ("invalid constructor; you probably meant `%T (%T&)'",
9463 SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl
), ctype
);
9468 TYPE_GETS_INIT_AGGR (ctype
) = 1;
9470 else if (TREE_CODE (parmtype
) == VOID_TYPE
9471 || TREE_PURPOSE (parmtypes
) != NULL_TREE
)
9472 TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype
) = 1;
9477 /* An operator with this name can be either unary or binary. */
9482 return (name
== ansi_opname
[(int) INDIRECT_REF
]
9483 || name
== ansi_opname
[(int) ADDR_EXPR
]
9484 || name
== ansi_opname
[(int) NEGATE_EXPR
]
9485 || name
== ansi_opname
[(int) POSTINCREMENT_EXPR
]
9486 || name
== ansi_opname
[(int) POSTDECREMENT_EXPR
]
9487 || name
== ansi_opname
[(int) CONVERT_EXPR
]);
9490 /* An operator with this name can only be unary. */
9495 return (name
== ansi_opname
[(int) TRUTH_NOT_EXPR
]
9496 || name
== ansi_opname
[(int) BIT_NOT_EXPR
]
9497 || name
== ansi_opname
[(int) COMPONENT_REF
]
9498 || OPERATOR_TYPENAME_P (name
));
9501 /* Do a little sanity-checking on how they declared their operator. */
9503 grok_op_properties (decl
, virtualp
, friendp
)
9505 int virtualp
, friendp
;
9507 tree argtypes
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
9508 int methodp
= (TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
);
9509 tree name
= DECL_NAME (decl
);
9511 if (current_class_type
== NULL_TREE
)
9516 if (name
== ansi_opname
[(int) MODIFY_EXPR
])
9517 TYPE_HAS_ASSIGNMENT (current_class_type
) = 1;
9518 else if (name
== ansi_opname
[(int) CALL_EXPR
])
9519 TYPE_OVERLOADS_CALL_EXPR (current_class_type
) = 1;
9520 else if (name
== ansi_opname
[(int) ARRAY_REF
])
9521 TYPE_OVERLOADS_ARRAY_REF (current_class_type
) = 1;
9522 else if (name
== ansi_opname
[(int) COMPONENT_REF
]
9523 || name
== ansi_opname
[(int) MEMBER_REF
])
9524 TYPE_OVERLOADS_ARROW (current_class_type
) = 1;
9525 else if (name
== ansi_opname
[(int) NEW_EXPR
])
9526 TYPE_GETS_NEW (current_class_type
) |= 1;
9527 else if (name
== ansi_opname
[(int) DELETE_EXPR
])
9528 TYPE_GETS_DELETE (current_class_type
) |= 1;
9529 else if (name
== ansi_opname
[(int) VEC_NEW_EXPR
])
9530 TYPE_GETS_NEW (current_class_type
) |= 2;
9531 else if (name
== ansi_opname
[(int) VEC_DELETE_EXPR
])
9532 TYPE_GETS_DELETE (current_class_type
) |= 2;
9535 if (name
== ansi_opname
[(int) NEW_EXPR
]
9536 || name
== ansi_opname
[(int) VEC_NEW_EXPR
])
9538 /* When the compiler encounters the definition of A::operator new, it
9539 doesn't look at the class declaration to find out if it's static. */
9541 revert_static_member_fn (&decl
, NULL
, NULL
);
9543 /* Take care of function decl if we had syntax errors. */
9544 if (argtypes
== NULL_TREE
)
9546 build_function_type (ptr_type_node
,
9547 hash_tree_chain (integer_type_node
,
9550 TREE_TYPE (decl
) = coerce_new_type (TREE_TYPE (decl
));
9552 else if (name
== ansi_opname
[(int) DELETE_EXPR
]
9553 || name
== ansi_opname
[(int) VEC_DELETE_EXPR
])
9556 revert_static_member_fn (&decl
, NULL
, NULL
);
9558 if (argtypes
== NULL_TREE
)
9560 build_function_type (void_type_node
,
9561 hash_tree_chain (ptr_type_node
,
9565 TREE_TYPE (decl
) = coerce_delete_type (TREE_TYPE (decl
));
9567 if (! friendp
&& name
== ansi_opname
[(int) VEC_DELETE_EXPR
]
9568 && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
)))
9570 TYPE_VEC_DELETE_TAKES_SIZE (current_class_type
) = 1;
9575 /* An operator function must either be a non-static member function
9576 or have at least one parameter of a class, a reference to a class,
9577 an enumeration, or a reference to an enumeration. 13.4.0.6 */
9578 if (! methodp
|| DECL_STATIC_FUNCTION_P (decl
))
9580 if (OPERATOR_TYPENAME_P (name
)
9581 || name
== ansi_opname
[(int) CALL_EXPR
]
9582 || name
== ansi_opname
[(int) MODIFY_EXPR
]
9583 || name
== ansi_opname
[(int) COMPONENT_REF
]
9584 || name
== ansi_opname
[(int) ARRAY_REF
])
9585 cp_error ("`%D' must be a nonstatic member function", decl
);
9590 if (DECL_STATIC_FUNCTION_P (decl
))
9591 cp_error ("`%D' must be either a non-static member function or a non-member function", decl
);
9594 for (; TREE_VALUE (p
) != void_type_node
; p
= TREE_CHAIN (p
))
9596 tree arg
= TREE_VALUE (p
);
9597 if (TREE_CODE (arg
) == REFERENCE_TYPE
)
9598 arg
= TREE_TYPE (arg
);
9600 /* This lets bad template code slip through. */
9601 if (IS_AGGR_TYPE (arg
)
9602 || TREE_CODE (arg
) == ENUMERAL_TYPE
9603 || TREE_CODE (arg
) == TEMPLATE_TYPE_PARM
)
9607 ("`%D' must have an argument of class or enumerated type",
9614 if (name
== ansi_opname
[(int) CALL_EXPR
]
9615 || name
== ansi_opname
[(int) METHOD_CALL_EXPR
])
9616 return; /* no restrictions on args */
9618 if (IDENTIFIER_TYPENAME_P (name
))
9620 tree t
= TREE_TYPE (name
);
9621 if (TREE_CODE (t
) == VOID_TYPE
)
9622 pedwarn ("void is not a valid type conversion operator");
9625 int ref
= (TREE_CODE (t
) == REFERENCE_TYPE
);
9628 t
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
9630 if (t
== current_class_type
)
9631 what
= "the same type";
9632 else if (IS_AGGR_TYPE (t
)
9633 && DERIVED_FROM_P (t
, current_class_type
))
9634 what
= "a base class";
9637 warning ("conversion to %s%s will never use a type conversion operator",
9638 ref
? "a reference to " : "", what
);
9642 if (name
== ansi_opname
[(int) MODIFY_EXPR
])
9646 if (list_length (argtypes
) != 3 && methodp
)
9648 cp_error ("`%D' must take exactly one argument", decl
);
9651 parmtype
= TREE_VALUE (TREE_CHAIN (argtypes
));
9653 if (copy_assignment_arg_p (parmtype
, virtualp
)
9656 TYPE_HAS_ASSIGN_REF (current_class_type
) = 1;
9657 if (TREE_CODE (parmtype
) != REFERENCE_TYPE
9658 || TYPE_READONLY (TREE_TYPE (parmtype
)))
9659 TYPE_HAS_CONST_ASSIGN_REF (current_class_type
) = 1;
9660 #if 0 /* Too soon; done in grok_function_init */
9661 if (DECL_ABSTRACT_VIRTUAL_P (decl
))
9662 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type
) = 1;
9666 else if (name
== ansi_opname
[(int) COND_EXPR
])
9669 pedwarn ("ANSI C++ prohibits overloading operator ?:");
9670 if (list_length (argtypes
) != 4)
9671 cp_error ("`%D' must take exactly three arguments", decl
);
9673 else if (ambi_op_p (name
))
9675 if (list_length (argtypes
) == 2)
9677 else if (list_length (argtypes
) == 3)
9679 if ((name
== ansi_opname
[(int) POSTINCREMENT_EXPR
]
9680 || name
== ansi_opname
[(int) POSTDECREMENT_EXPR
])
9681 && TREE_VALUE (TREE_CHAIN (argtypes
)) != integer_type_node
)
9684 cp_error ("postfix `%D' must take `int' as its argument",
9688 ("postfix `%D' must take `int' as its second argument",
9695 cp_error ("`%D' must take either zero or one argument", decl
);
9697 cp_error ("`%D' must take either one or two arguments", decl
);
9700 else if (unary_op_p (name
))
9702 if (list_length (argtypes
) != 2)
9705 cp_error ("`%D' must take `void'", decl
);
9707 cp_error ("`%D' must take exactly one argument", decl
);
9710 else /* if (binary_op_p (name)) */
9712 if (list_length (argtypes
) != 3)
9715 cp_error ("`%D' must take exactly one argument", decl
);
9717 cp_error ("`%D' must take exactly two arguments", decl
);
9723 for (; argtypes
!= void_list_node
; argtypes
= TREE_CHAIN (argtypes
))
9724 if (TREE_PURPOSE (argtypes
))
9726 TREE_PURPOSE (argtypes
) = NULL_TREE
;
9727 if (name
== ansi_opname
[(int) POSTINCREMENT_EXPR
]
9728 || name
== ansi_opname
[(int) POSTDECREMENT_EXPR
])
9731 cp_pedwarn ("`%D' cannot have default arguments", decl
);
9734 cp_error ("`%D' cannot have default arguments", decl
);
9739 /* Get the struct, enum or union (CODE says which) with tag NAME.
9740 Define the tag as a forward-reference if it is not defined.
9742 C++: If a class derivation is given, process it here, and report
9743 an error if multiple derivation declarations are not identical.
9745 If this is a definition, come in through xref_tag and only look in
9746 the current frame for the name (since C++ allows new names in any
9749 /* avoid rewriting all callers of xref_tag */
9750 static int xref_next_defn
= 0;
9753 xref_defn_tag (code_type_node
, name
, binfo
)
9754 tree code_type_node
;
9760 if (class_binding_level
)
9764 /* we need to build a new IDENTIFIER_NODE for name which nukes
9767 n1 = IDENTIFIER_LOCAL_VALUE (current_class_name);
9769 n1 = DECL_NAME (n1);
9771 n1 = current_class_name;
9773 n1
= TYPE_NAME (current_class_type
);
9775 n1
= DECL_NESTED_TYPENAME(n1
);
9777 n1
= current_class_name
;
9779 buf
= (char *) alloca (4 + IDENTIFIER_LENGTH (n1
)
9780 + IDENTIFIER_LENGTH (name
));
9782 sprintf (buf
, "%s::%s", IDENTIFIER_POINTER (n1
),
9783 IDENTIFIER_POINTER (name
));
9784 ncp
= get_identifier (buf
);
9787 printf("*** %s ***\n", IDENTIFIER_POINTER (ncp
));
9790 IDENTIFIER_LOCAL_VALUE (name
) =
9791 build_decl (TYPE_DECL
, ncp
, NULL_TREE
);
9793 rv
= xref_tag (code_type_node
, name
, binfo
, 0);
9794 if (! ANON_AGGRNAME_P (name
))
9796 register tree type_decl
= build_decl (TYPE_DECL
, ncp
, rv
);
9797 #ifdef DWARF_DEBUGGING_INFO
9798 /* Mark the TYPE_DECL node created just above as a gratuitous one
9799 so that dwarfout.c will know not to generate a TAG_typedef DIE
9801 if (write_symbols
== DWARF_DEBUG
)
9802 DECL_IGNORED_P (type_decl
) = 1;
9803 #endif /* DWARF_DEBUGGING_INFO */
9804 pushdecl_nonclass_level (type_decl
);
9809 rv
= xref_tag (code_type_node
, name
, binfo
, 0);
9816 xref_tag (code_type_node
, name
, binfo
, globalize
)
9817 tree code_type_node
;
9821 enum tag_types tag_code
;
9822 enum tree_code code
;
9825 register tree ref
, t
;
9826 struct binding_level
*b
= inner_binding_level
;
9828 tag_code
= (enum tag_types
) TREE_INT_CST_LOW (code_type_node
);
9833 case exception_type
:
9834 case signature_type
:
9836 len
= list_length (binfo
);
9842 cp_error ("derived union `%T' invalid", name
);
9848 code
= ENUMERAL_TYPE
;
9851 my_friendly_abort (18);
9854 /* If a cross reference is requested, look up the type
9855 already defined for this tag and return it. */
9856 t
= IDENTIFIER_TYPE_VALUE (name
);
9857 if (t
&& TREE_CODE (t
) != code
)
9862 /* If we know we are defining this tag, only look it up in this scope
9863 * and don't try to find it as a type. */
9865 if (t
&& TYPE_CONTEXT(t
))
9867 if (TREE_MANGLED (name
))
9870 ref
= lookup_tag (code
, name
, b
, 1);
9873 ref
= lookup_tag (code
, name
, b
, 1);
9880 ref
= lookup_tag (code
, name
, b
, 0);
9884 /* Try finding it as a type declaration. If that wins, use it. */
9885 ref
= lookup_name (name
, 1);
9886 if (ref
&& TREE_CODE (ref
) == TYPE_DECL
9887 && TREE_CODE (TREE_TYPE (ref
)) == code
)
9888 ref
= TREE_TYPE (ref
);
9894 push_obstacks_nochange ();
9898 /* If no such tag is yet defined, create a forward-reference node
9899 and record it as the "definition".
9900 When a real declaration of this type is found,
9901 the forward-reference will be altered into a real type. */
9903 /* In C++, since these migrate into the global scope, we must
9904 build them on the permanent obstack. */
9906 temp
= allocation_temporary_p ();
9908 end_temporary_allocation ();
9910 if (code
== ENUMERAL_TYPE
)
9912 ref
= make_node (ENUMERAL_TYPE
);
9914 /* Give the type a default layout like unsigned int
9915 to avoid crashing if it does not get defined. */
9916 TYPE_MODE (ref
) = TYPE_MODE (unsigned_type_node
);
9917 TYPE_ALIGN (ref
) = TYPE_ALIGN (unsigned_type_node
);
9918 TREE_UNSIGNED (ref
) = 1;
9919 TYPE_PRECISION (ref
) = TYPE_PRECISION (unsigned_type_node
);
9920 TYPE_MIN_VALUE (ref
) = TYPE_MIN_VALUE (unsigned_type_node
);
9921 TYPE_MAX_VALUE (ref
) = TYPE_MAX_VALUE (unsigned_type_node
);
9923 /* Enable us to recognize when a type is created in class context.
9924 To do nested classes correctly, this should probably be cleared
9925 out when we leave this classes scope. Currently this in only
9926 done in `start_enum'. */
9928 pushtag (name
, ref
, globalize
);
9930 cadillac_start_enum (ref
);
9932 else if (tag_code
== exception_type
)
9934 ref
= make_lang_type (code
);
9935 /* Enable us to recognize when an exception type is created in
9936 class context. To do nested classes correctly, this should
9937 probably be cleared out when we leave this class's scope. */
9938 CLASSTYPE_DECLARED_EXCEPTION (ref
) = 1;
9939 pushtag (name
, ref
, globalize
);
9941 cadillac_start_struct (ref
);
9945 extern tree pending_vtables
;
9946 struct binding_level
*old_b
= class_binding_level
;
9949 ref
= make_lang_type (code
);
9951 /* A signature type will contain the fields of the signature
9952 table. Therefore, it's not only an interface. */
9953 if (tag_code
== signature_type
)
9955 SET_SIGNATURE (ref
);
9956 CLASSTYPE_INTERFACE_ONLY (ref
) = 0;
9957 CLASSTYPE_INTERFACE_UNKNOWN (ref
) = 0;
9960 /* Record how to set the access of this class's
9961 virtual functions. If write_virtuals == 2 or 3, then
9962 inline virtuals are ``extern inline''. */
9963 switch (write_virtuals
)
9970 needs_writing
= !! value_member (name
, pending_vtables
);
9973 needs_writing
= ! CLASSTYPE_INTERFACE_ONLY (ref
)
9974 && CLASSTYPE_INTERFACE_KNOWN (ref
);
9980 /* Signatures don't have a vtable. As long as we don't have default
9981 implementations, they behave as if `write_virtuals' were 3. */
9982 if (tag_code
== signature_type
)
9983 CLASSTYPE_VTABLE_NEEDS_WRITING (ref
) = 0;
9985 CLASSTYPE_VTABLE_NEEDS_WRITING (ref
) = needs_writing
;
9987 #ifdef NONNESTED_CLASSES
9988 /* Class types don't nest the way enums do. */
9989 class_binding_level
= (struct binding_level
*)0;
9991 pushtag (name
, ref
, globalize
);
9992 class_binding_level
= old_b
;
9995 cadillac_start_struct (ref
);
10000 if (IS_AGGR_TYPE_CODE (code
))
10002 if (IS_AGGR_TYPE (ref
)
10003 && ((tag_code
== exception_type
)
10004 != (CLASSTYPE_DECLARED_EXCEPTION (ref
) == 1)))
10006 cp_error ("type `%T' is both exception and aggregate type", ref
);
10007 CLASSTYPE_DECLARED_EXCEPTION (ref
) = (tag_code
== exception_type
);
10011 /* If it no longer looks like a nested type, make sure it's
10012 in global scope. */
10013 if (b
== global_binding_level
&& !class_binding_level
10014 && IDENTIFIER_GLOBAL_VALUE (name
) == NULL_TREE
)
10015 IDENTIFIER_GLOBAL_VALUE (name
) = TYPE_NAME (ref
);
10020 tree tt2
= TYPE_BINFO_BASETYPES (ref
);
10022 if (TYPE_BINFO_BASETYPES (ref
))
10023 for (i
= 0; tt1
; i
++, tt1
= TREE_CHAIN (tt1
))
10024 if (TREE_VALUE (tt1
) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2
, i
))))
10026 cp_error ("redeclaration of derivation chain of type `%#T'",
10031 if (tt1
== NULL_TREE
)
10032 /* The user told us something we already knew. */
10035 /* In C++, since these migrate into the global scope, we must
10036 build them on the permanent obstack. */
10037 end_temporary_allocation ();
10043 /* In the declaration `A : X, Y, ... Z' we mark all the types
10044 (A, X, Y, ..., Z) so we can check for duplicates. */
10047 SET_CLASSTYPE_MARKED (ref
);
10048 BINFO_BASETYPES (TYPE_BINFO (ref
)) = binfos
= make_tree_vec (len
);
10050 for (i
= 0; binfo
; binfo
= TREE_CHAIN (binfo
))
10052 /* The base of a derived struct is public by default. */
10054 = (TREE_PURPOSE (binfo
) == (tree
)access_public
10055 || TREE_PURPOSE (binfo
) == (tree
)access_public_virtual
10056 || (tag_code
!= class_type
10057 && (TREE_PURPOSE (binfo
) == (tree
)access_default
10058 || TREE_PURPOSE (binfo
) == (tree
)access_default_virtual
)));
10059 int via_protected
= TREE_PURPOSE (binfo
) == (tree
)access_protected
;
10061 = (TREE_PURPOSE (binfo
) == (tree
)access_private_virtual
10062 || TREE_PURPOSE (binfo
) == (tree
)access_public_virtual
10063 || TREE_PURPOSE (binfo
) == (tree
)access_default_virtual
);
10064 tree basetype
= TREE_TYPE (TREE_VALUE (binfo
));
10067 GNU_xref_hier (IDENTIFIER_POINTER (name
),
10068 IDENTIFIER_POINTER (TREE_VALUE (binfo
)),
10069 via_public
, via_virtual
, 0);
10071 if (basetype
&& TREE_CODE (basetype
) == TYPE_DECL
)
10072 basetype
= TREE_TYPE (basetype
);
10073 if (!basetype
|| TREE_CODE (basetype
) != RECORD_TYPE
)
10075 error ("base type `%s' fails to be a struct or class type",
10076 IDENTIFIER_POINTER (TREE_VALUE (binfo
)));
10080 /* This code replaces similar code in layout_basetypes. */
10081 else if (TYPE_SIZE (basetype
) == NULL_TREE
)
10083 cp_error ("base class `%T' has incomplete type", basetype
);
10089 if (CLASSTYPE_MARKED (basetype
))
10091 if (basetype
== ref
)
10092 cp_error ("recursive type `%T' undefined", basetype
);
10094 cp_error ("duplicate base type `%T' invalid", basetype
);
10098 /* Note that the BINFO records which describe individual
10099 inheritances are *not* shared in the lattice! They
10100 cannot be shared because a given baseclass may be
10101 inherited with different `accessibility' by different
10102 derived classes. (Each BINFO record describing an
10103 individual inheritance contains flags which say what
10104 the `accessibility' of that particular inheritance is.) */
10106 base_binfo
= make_binfo (integer_zero_node
, basetype
,
10107 TYPE_BINFO_VTABLE (basetype
),
10108 TYPE_BINFO_VIRTUALS (basetype
), NULL_TREE
);
10110 TREE_VEC_ELT (binfos
, i
) = base_binfo
;
10111 TREE_VIA_PUBLIC (base_binfo
) = via_public
;
10112 TREE_VIA_PROTECTED (base_binfo
) = via_protected
;
10113 TREE_VIA_VIRTUAL (base_binfo
) = via_virtual
;
10115 SET_CLASSTYPE_MARKED (basetype
);
10117 /* XYZZY TEST VIRTUAL BASECLASSES */
10118 if (CLASSTYPE_N_BASECLASSES (basetype
) == NULL_TREE
10119 && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype
)
10120 && via_virtual
== 0)
10122 warning ("making type `%s' a virtual baseclass",
10123 TYPE_NAME_STRING (basetype
));
10127 /* We are free to modify these bits because they are meaningless
10128 at top level, and BASETYPE is a top-level type. */
10129 if (via_virtual
|| TYPE_USES_VIRTUAL_BASECLASSES (basetype
))
10131 TYPE_USES_VIRTUAL_BASECLASSES (ref
) = 1;
10132 TYPE_USES_COMPLEX_INHERITANCE (ref
) = 1;
10135 TYPE_OVERLOADS_METHOD_CALL_EXPR (ref
) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype
);
10136 TYPE_GETS_NEW (ref
) |= TYPE_GETS_NEW (basetype
);
10137 TYPE_GETS_DELETE (ref
) |= TYPE_GETS_DELETE (basetype
);
10138 CLASSTYPE_LOCAL_TYPEDECLS (ref
) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype
);
10143 TREE_VEC_LENGTH (binfos
) = i
;
10145 BINFO_BASETYPES (TYPE_BINFO (ref
)) = NULL_TREE
;
10148 TYPE_USES_MULTIPLE_INHERITANCE (ref
) = 1;
10150 TYPE_USES_MULTIPLE_INHERITANCE (ref
)
10151 = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos
, 0)));
10152 if (TYPE_USES_MULTIPLE_INHERITANCE (ref
))
10153 TYPE_USES_COMPLEX_INHERITANCE (ref
) = 1;
10155 /* Unmark all the types. */
10157 CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos
, i
)));
10158 CLEAR_CLASSTYPE_MARKED (ref
);
10163 /* Until the type is defined, tentatively accept whatever
10164 structure tag the user hands us. */
10165 if (TYPE_SIZE (ref
) == NULL_TREE
10166 && ref
!= current_class_type
10167 /* Have to check this, in case we have contradictory tag info. */
10168 && IS_AGGR_TYPE_CODE (TREE_CODE (ref
)))
10170 if (tag_code
== class_type
)
10171 CLASSTYPE_DECLARED_CLASS (ref
) = 1;
10172 else if (tag_code
== record_type
|| tag_code
== signature_type
)
10173 CLASSTYPE_DECLARED_CLASS (ref
) = 0;
10181 static tree current_local_enum
= NULL_TREE
;
10183 /* Begin compiling the definition of an enumeration type.
10184 NAME is its name (or null if anonymous).
10185 Returns the type object, as yet incomplete.
10186 Also records info about it so that build_enumerator
10187 may be used to declare the individual values as they are read. */
10193 register tree enumtype
= NULL_TREE
;
10194 struct binding_level
*b
= inner_binding_level
;
10196 /* If this is the real definition for a previous forward reference,
10197 fill in the contents in the same object that used to be the
10198 forward reference. */
10200 if (name
!= NULL_TREE
)
10201 enumtype
= lookup_tag (ENUMERAL_TYPE
, name
, b
, 1);
10203 if (enumtype
!= NULL_TREE
&& TREE_CODE (enumtype
) == ENUMERAL_TYPE
)
10204 cp_error ("multiple definition of enum `%T'", enumtype
);
10207 enumtype
= make_node (ENUMERAL_TYPE
);
10208 pushtag (name
, enumtype
, 0);
10211 if (current_class_type
)
10212 TREE_ADDRESSABLE (b
->tags
) = 1;
10213 current_local_enum
= NULL_TREE
;
10215 if (TYPE_VALUES (enumtype
) != NULL_TREE
)
10216 /* Completely replace its old definition.
10217 The old enumerators remain defined, however. */
10218 TYPE_VALUES (enumtype
) = NULL_TREE
;
10220 /* Initially, set up this enum as like `int'
10221 so that we can create the enumerators' declarations and values.
10222 Later on, the precision of the type may be changed and
10223 it may be laid out again. */
10225 TYPE_PRECISION (enumtype
) = TYPE_PRECISION (integer_type_node
);
10226 TYPE_SIZE (enumtype
) = NULL_TREE
;
10227 fixup_unsigned_type (enumtype
);
10229 /* We copy this value because enumerated type constants
10230 are really of the type of the enumerator, not integer_type_node. */
10231 enum_next_value
= copy_node (integer_zero_node
);
10234 GNU_xref_decl (current_function_decl
, enumtype
);
10238 /* After processing and defining all the values of an enumeration type,
10239 install their decls in the enumeration type and finish it off.
10240 ENUMTYPE is the type object and VALUES a list of name-value pairs.
10241 Returns ENUMTYPE. */
10244 finish_enum (enumtype
, values
)
10245 register tree enumtype
, values
;
10247 register tree pair
, tem
;
10248 register HOST_WIDE_INT maxvalue
= 0;
10249 register HOST_WIDE_INT minvalue
= 0;
10250 register HOST_WIDE_INT i
;
10252 /* Calculate the maximum value of any enumerator in this type. */
10256 /* Speed up the main loop by performing some precalculations */
10258 HOST_WIDE_INT value
;
10259 TREE_TYPE (TREE_VALUE (values
)) = enumtype
;
10260 TREE_TYPE (DECL_INITIAL (TREE_VALUE (values
))) = enumtype
;
10261 TREE_VALUE (values
) = DECL_INITIAL (TREE_VALUE (values
));
10262 value
= TREE_INT_CST_LOW (TREE_VALUE (values
));
10263 minvalue
= maxvalue
= value
;
10265 for (pair
= TREE_CHAIN (values
); pair
; pair
= TREE_CHAIN (pair
))
10267 TREE_TYPE (TREE_VALUE (pair
)) = enumtype
;
10268 TREE_TYPE (DECL_INITIAL (TREE_VALUE (pair
))) = enumtype
;
10269 TREE_VALUE (pair
) = DECL_INITIAL (TREE_VALUE (pair
));
10270 value
= TREE_INT_CST_LOW (TREE_VALUE (pair
));
10271 if (value
> maxvalue
)
10273 else if (value
< minvalue
)
10278 TYPE_VALUES (enumtype
) = values
;
10280 if (flag_short_enums
)
10282 /* Determine the precision this type needs, lay it out, and define
10285 /* First reset precision */
10286 TYPE_PRECISION (enumtype
) = 0;
10288 for (i
= maxvalue
; i
; i
>>= 1)
10289 TYPE_PRECISION (enumtype
)++;
10291 if (!TYPE_PRECISION (enumtype
))
10292 TYPE_PRECISION (enumtype
) = 1;
10294 /* Cancel the laying out previously done for the enum type,
10295 so that fixup_unsigned_type will do it over. */
10296 TYPE_SIZE (enumtype
) = NULL_TREE
;
10298 fixup_unsigned_type (enumtype
);
10301 TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype
)) = maxvalue
;
10303 /* An enum can have some negative values; then it is signed. */
10306 TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype
)) = minvalue
;
10307 TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype
)) = -1;
10308 TREE_UNSIGNED (enumtype
) = 0;
10311 cadillac_finish_enum (enumtype
);
10313 /* Fix up all variant types of this enum type. */
10314 for (tem
= TYPE_MAIN_VARIANT (enumtype
); tem
; tem
= TYPE_NEXT_VARIANT (tem
))
10316 TYPE_VALUES (tem
) = TYPE_VALUES (enumtype
);
10317 TYPE_MIN_VALUE (tem
) = TYPE_MIN_VALUE (enumtype
);
10318 TYPE_MAX_VALUE (tem
) = TYPE_MAX_VALUE (enumtype
);
10319 TYPE_SIZE (tem
) = TYPE_SIZE (enumtype
);
10320 TYPE_MODE (tem
) = TYPE_MODE (enumtype
);
10321 TYPE_PRECISION (tem
) = TYPE_PRECISION (enumtype
);
10322 TYPE_ALIGN (tem
) = TYPE_ALIGN (enumtype
);
10323 TREE_UNSIGNED (tem
) = TREE_UNSIGNED (enumtype
);
10326 /* Finish debugging output for this type. */
10328 /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
10329 information should *not* be generated? I think not. */
10330 if (! DECL_IGNORED_P (TYPE_NAME (enumtype
)))
10332 rest_of_type_compilation (enumtype
, global_bindings_p ());
10337 /* Build and install a CONST_DECL for one value of the
10338 current enumeration type (one that was begun with start_enum).
10339 Return a tree-list containing the name and its value.
10340 Assignment of sequential values by default is handled here. */
10343 build_enumerator (name
, value
)
10347 /* Change this to zero if we find VALUE is not shareable. */
10350 /* Remove no-op casts from the value. */
10352 STRIP_TYPE_NOPS (value
);
10354 /* Validate and default VALUE. */
10355 if (value
!= NULL_TREE
)
10357 if (TREE_READONLY_DECL_P (value
))
10359 value
= decl_constant_value (value
);
10363 if (TREE_CODE (value
) == INTEGER_CST
)
10365 value
= default_conversion (value
);
10366 constant_expression_warning (value
);
10370 cp_error ("enumerator value for `%D' not integer constant", name
);
10375 /* The order of things is reversed here so that we
10376 can check for possible sharing of enum values,
10377 to keep that from happening. */
10378 /* Default based on previous value. */
10379 if (value
== NULL_TREE
)
10381 value
= enum_next_value
;
10383 cp_error ("overflow in enumeration values at `%D'", name
);
10386 /* Remove no-op casts from the value. */
10388 STRIP_TYPE_NOPS (value
);
10390 /* Make up for hacks in lex.c. */
10391 if (value
== integer_zero_node
)
10392 value
= build_int_2 (0, 0);
10393 else if (value
== integer_one_node
)
10394 value
= build_int_2 (1, 0);
10395 else if (TREE_CODE (value
) == INTEGER_CST
10397 || TREE_CODE (TREE_TYPE (value
)) == ENUMERAL_TYPE
))
10399 value
= copy_node (value
);
10400 TREE_TYPE (value
) = integer_type_node
;
10403 /* C++ associates enums with global, function, or class declarations. */
10405 decl
= current_scope ();
10406 if (decl
&& decl
== current_class_type
)
10408 /* This enum declaration is local to the class, so we must put
10409 it in that class's list of decls. */
10410 decl
= build_lang_field_decl (CONST_DECL
, name
, integer_type_node
);
10411 DECL_INITIAL (decl
) = value
;
10412 TREE_READONLY (decl
) = 1;
10413 pushdecl_class_level (decl
);
10414 TREE_CHAIN (decl
) = current_local_enum
;
10415 current_local_enum
= decl
;
10419 /* It's a global enum, or it's local to a function. (Note local to
10420 a function could mean local to a class method. */
10421 decl
= build_decl (CONST_DECL
, name
, integer_type_node
);
10422 DECL_INITIAL (decl
) = value
;
10425 GNU_xref_decl (current_function_decl
, decl
);
10428 /* Set basis for default for next value. */
10429 enum_next_value
= build_binary_op_nodefault (PLUS_EXPR
, value
,
10430 integer_one_node
, PLUS_EXPR
);
10431 enum_overflow
= tree_int_cst_lt (enum_next_value
, value
);
10433 if (enum_next_value
== integer_one_node
)
10434 enum_next_value
= copy_node (enum_next_value
);
10436 result
= saveable_tree_cons (name
, decl
, NULL_TREE
);
10441 grok_enum_decls (type
, decl
)
10444 tree d
= current_local_enum
;
10446 if (d
== NULL_TREE
)
10451 TREE_TYPE (d
) = type
;
10452 if (TREE_CHAIN (d
) == NULL_TREE
)
10454 TREE_CHAIN (d
) = decl
;
10457 d
= TREE_CHAIN (d
);
10460 decl
= current_local_enum
;
10461 current_local_enum
= NULL_TREE
;
10466 /* Create the FUNCTION_DECL for a function definition.
10467 DECLSPECS and DECLARATOR are the parts of the declaration;
10468 they describe the function's name and the type it returns,
10469 but twisted together in a fashion that parallels the syntax of C.
10471 This function creates a binding context for the function body
10472 as well as setting up the FUNCTION_DECL in current_function_decl.
10474 Returns 1 on success. If the DECLARATOR is not suitable for a function
10475 (it defines a datum instead), we return 0, which tells
10476 yyparse to report a parse error.
10478 For C++, we must first check whether that datum makes any sense.
10479 For example, "class A local_a(1,2);" means that variable local_a
10480 is an aggregate of type A, which should have a constructor
10481 applied to it with the argument list [1, 2].
10483 @@ There is currently no way to retrieve the storage
10484 @@ allocated to FUNCTION (or all of its parms) if we return
10485 @@ something we had previously. */
10488 start_function (declspecs
, declarator
, raises
, pre_parsed_p
)
10489 tree declarator
, declspecs
, raises
;
10492 tree decl1
, olddecl
;
10493 tree ctype
= NULL_TREE
;
10496 extern int have_extern_spec
;
10497 extern int used_extern_spec
;
10498 int doing_friend
= 0;
10500 /* Sanity check. */
10501 my_friendly_assert (TREE_VALUE (void_list_node
) == void_type_node
, 160);
10502 my_friendly_assert (TREE_CHAIN (void_list_node
) == NULL_TREE
, 161);
10504 /* Assume, until we see it does. */
10505 current_function_returns_value
= 0;
10506 current_function_returns_null
= 0;
10507 warn_about_return_type
= 0;
10508 current_extern_inline
= 0;
10509 current_function_assigns_this
= 0;
10510 current_function_just_assigned_this
= 0;
10511 current_function_parms_stored
= 0;
10512 original_result_rtx
= NULL_RTX
;
10513 current_function_obstack_index
= 0;
10514 current_function_obstack_usage
= 0;
10516 clear_temp_name ();
10518 /* This should only be done once on the top most decl. */
10519 if (have_extern_spec
&& !used_extern_spec
)
10521 declspecs
= decl_tree_cons (NULL_TREE
, get_identifier ("extern"), declspecs
);
10522 used_extern_spec
= 1;
10527 decl1
= declarator
;
10529 if (! DECL_ARGUMENTS (decl1
)
10530 && !DECL_STATIC_FUNCTION_P (decl1
)
10531 && DECL_CONTEXT (decl1
)
10532 && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1
)))
10533 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1
)))))
10535 cp_error ("redeclaration of `%#D'", decl1
);
10536 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1
)))
10537 cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1
)));
10538 else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1
)))
10539 cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1
)));
10542 last_function_parms
= DECL_ARGUMENTS (decl1
);
10543 last_function_parm_tags
= NULL_TREE
;
10544 fntype
= TREE_TYPE (decl1
);
10545 if (TREE_CODE (fntype
) == METHOD_TYPE
)
10546 ctype
= TYPE_METHOD_BASETYPE (fntype
);
10548 /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a
10549 class is in the (lexical) scope of the class in which it is
10551 if (!ctype
&& DECL_FRIEND_P (decl1
))
10553 ctype
= DECL_CLASS_CONTEXT (decl1
);
10555 /* CTYPE could be null here if we're dealing with a template;
10556 for example, `inline friend float foo()' inside a template
10557 will have no CTYPE set. */
10558 if (ctype
&& TREE_CODE (ctype
) != RECORD_TYPE
)
10564 if ( !(DECL_VINDEX (decl1
)
10565 && write_virtuals
>= 2
10566 && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype
)))
10567 current_extern_inline
= DECL_THIS_EXTERN (decl1
) && DECL_INLINE (decl1
);
10569 raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
10571 /* In a fcn definition, arg types must be complete. */
10572 require_complete_types_for_parms (last_function_parms
);
10576 decl1
= grokdeclarator (declarator
, declspecs
, FUNCDEF
, 1, raises
);
10577 /* If the declarator is not suitable for a function definition,
10578 cause a syntax error. */
10579 if (decl1
== NULL_TREE
|| TREE_CODE (decl1
) != FUNCTION_DECL
) return 0;
10581 fntype
= TREE_TYPE (decl1
);
10583 restype
= TREE_TYPE (fntype
);
10584 if (IS_AGGR_TYPE (restype
) && ! TYPE_PTRMEMFUNC_P (restype
)
10585 && ! CLASSTYPE_GOT_SEMICOLON (restype
))
10587 cp_error ("semicolon missing after declaration of `%#T'", restype
);
10588 shadow_tag (build_tree_list (NULL_TREE
, restype
));
10589 CLASSTYPE_GOT_SEMICOLON (restype
) = 1;
10590 if (TREE_CODE (fntype
) == FUNCTION_TYPE
)
10591 fntype
= build_function_type (integer_type_node
,
10592 TYPE_ARG_TYPES (fntype
));
10594 fntype
= build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype
), TREE_READONLY (decl1
), TREE_SIDE_EFFECTS (decl1
)),
10596 TYPE_ARG_TYPES (fntype
));
10597 TREE_TYPE (decl1
) = fntype
;
10600 if (TREE_CODE (fntype
) == METHOD_TYPE
)
10601 ctype
= TYPE_METHOD_BASETYPE (fntype
);
10602 else if (IDENTIFIER_LENGTH (DECL_NAME (decl1
)) == 4
10603 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1
)), "main")
10604 && DECL_CONTEXT (decl1
) == NULL_TREE
)
10606 /* If this doesn't return integer_type, complain. */
10607 if (TREE_TYPE (TREE_TYPE (decl1
)) != integer_type_node
)
10609 if (pedantic
|| warn_return_type
)
10610 warning ("return type for `main' changed to integer type");
10611 TREE_TYPE (decl1
) = fntype
= default_function_type
;
10613 warn_about_return_type
= 0;
10617 /* Warn if function was previously implicitly declared
10618 (but not if we warned then). */
10619 if (! warn_implicit
10620 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1
)) != NULL_TREE
)
10621 cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1
)));
10623 current_function_decl
= decl1
;
10626 cadillac_start_function (decl1
);
10628 announce_function (decl1
);
10630 if (TYPE_SIZE (TREE_TYPE (fntype
)) == NULL_TREE
)
10632 if (IS_AGGR_TYPE (TREE_TYPE (fntype
)))
10633 error_with_aggr_type (TREE_TYPE (fntype
),
10634 "return-type `%s' is an incomplete type");
10636 error ("return-type is an incomplete type");
10638 /* Make it return void instead, but don't change the
10639 type of the DECL_RESULT, in case we have a named return value. */
10642 = build_cplus_method_type (build_type_variant (ctype
,
10643 TREE_READONLY (decl1
),
10644 TREE_SIDE_EFFECTS (decl1
)),
10646 FUNCTION_ARG_CHAIN (decl1
));
10649 = build_function_type (void_type_node
,
10650 TYPE_ARG_TYPES (TREE_TYPE (decl1
)));
10651 DECL_RESULT (decl1
) = build_decl (RESULT_DECL
, 0, TREE_TYPE (fntype
));
10654 if (warn_about_return_type
)
10655 warning ("return-type defaults to `int'");
10657 /* Make the init_value nonzero so pushdecl knows this is not tentative.
10658 error_mark_node is replaced below (in poplevel) with the BLOCK. */
10659 DECL_INITIAL (decl1
) = error_mark_node
;
10661 /* Didn't get anything from C. */
10662 olddecl
= NULL_TREE
;
10664 /* This function exists in static storage.
10665 (This does not mean `static' in the C sense!) */
10666 TREE_STATIC (decl1
) = 1;
10668 /* Record the decl so that the function name is defined.
10669 If we already have a decl for this name, and it is a FUNCTION_DECL,
10670 use the old decl. */
10672 if (pre_parsed_p
== 0)
10674 current_function_decl
= decl1
= pushdecl (decl1
);
10675 DECL_MAIN_VARIANT (decl1
) = decl1
;
10676 fntype
= TREE_TYPE (decl1
);
10679 current_function_decl
= decl1
;
10681 /* If this function belongs to an interface, it is public.
10682 If it belongs to someone else's interface, it is also external.
10683 It doesn't matter whether it's inline or not. */
10684 if (interface_unknown
== 0)
10686 TREE_PUBLIC (decl1
) = 1;
10687 DECL_EXTERNAL (decl1
)
10689 || (DECL_INLINE (decl1
) && ! flag_implement_inlines
));
10691 else if (DECL_EXPLICIT_INSTANTIATION (decl1
))
10692 /* PUBLIC and EXTERNAL set by do_*_instantiation */;
10695 /* This is a definition, not a reference.
10696 So normally clear DECL_EXTERNAL.
10697 However, `extern inline' acts like a declaration except for
10698 defining how to inline. So set DECL_EXTERNAL in that case. */
10699 DECL_EXTERNAL (decl1
) = current_extern_inline
;
10701 DECL_DEFER_OUTPUT (decl1
) = DECL_INLINE (decl1
);
10704 if (ctype
!= NULL_TREE
&& DECL_STATIC_FUNCTION_P (decl1
))
10706 if (TREE_CODE (fntype
) == METHOD_TYPE
)
10707 TREE_TYPE (decl1
) = fntype
10708 = build_function_type (TREE_TYPE (fntype
),
10709 TREE_CHAIN (TYPE_ARG_TYPES (fntype
)));
10710 last_function_parms
= TREE_CHAIN (last_function_parms
);
10711 DECL_ARGUMENTS (decl1
) = last_function_parms
;
10714 restype
= TREE_TYPE (fntype
);
10717 current_binding_level
->parm_flag
= 1;
10719 /* Save the parm names or decls from this function's declarator
10720 where store_parm_decls will find them. */
10721 current_function_parms
= last_function_parms
;
10722 current_function_parm_tags
= last_function_parm_tags
;
10724 GNU_xref_function (decl1
, current_function_parms
);
10726 make_function_rtl (decl1
);
10730 push_nested_class (ctype
, 1);
10732 /* If we're compiling a friend function, neither of the variables
10733 current_class_decl nor current_class_type will have values. */
10734 if (! doing_friend
)
10736 /* We know that this was set up by `grokclassfn'.
10737 We do not wait until `store_parm_decls', since evil
10738 parse errors may never get us to that point. Here
10739 we keep the consistency between `current_class_type'
10740 and `current_class_decl'. */
10741 current_class_decl
= last_function_parms
;
10742 my_friendly_assert (current_class_decl
!= NULL_TREE
10743 && TREE_CODE (current_class_decl
) == PARM_DECL
, 162);
10744 if (TREE_CODE (TREE_TYPE (current_class_decl
)) == POINTER_TYPE
)
10746 tree variant
= TREE_TYPE (TREE_TYPE (current_class_decl
));
10747 if (CLASSTYPE_INST_VAR (ctype
) == NULL_TREE
)
10749 /* Can't call build_indirect_ref here, because it has special
10750 logic to return C_C_D given this argument. */
10751 C_C_D
= build1 (INDIRECT_REF
, current_class_type
, current_class_decl
);
10752 CLASSTYPE_INST_VAR (ctype
) = C_C_D
;
10756 C_C_D
= CLASSTYPE_INST_VAR (ctype
);
10757 /* `current_class_decl' is different for every
10758 function we compile. */
10759 TREE_OPERAND (C_C_D
, 0) = current_class_decl
;
10761 TREE_READONLY (C_C_D
) = TYPE_READONLY (variant
);
10762 TREE_SIDE_EFFECTS (C_C_D
) = TYPE_VOLATILE (variant
);
10763 TREE_THIS_VOLATILE (C_C_D
) = TYPE_VOLATILE (variant
);
10766 C_C_D
= current_class_decl
;
10771 if (DECL_STATIC_FUNCTION_P (decl1
))
10772 push_nested_class (DECL_CONTEXT (decl1
), 2);
10774 push_memoized_context (0, 1);
10777 /* Allocate further tree nodes temporarily during compilation
10778 of this function only. Tiemann moved up here from bottom of fn. */
10779 temporary_allocation ();
10781 /* Promote the value to int before returning it. */
10782 if (C_PROMOTING_INTEGER_TYPE_P (restype
))
10784 /* It retains unsignedness if traditional or if it isn't
10785 really getting wider. */
10786 if (TREE_UNSIGNED (restype
)
10787 && (flag_traditional
10788 || TYPE_PRECISION (restype
)
10789 == TYPE_PRECISION (integer_type_node
)))
10790 restype
= unsigned_type_node
;
10792 restype
= integer_type_node
;
10794 if (DECL_RESULT (decl1
) == NULL_TREE
)
10795 DECL_RESULT (decl1
) = build_decl (RESULT_DECL
, 0, restype
);
10797 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1
)))
10799 dtor_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
10800 ctor_label
= NULL_TREE
;
10804 dtor_label
= NULL_TREE
;
10805 if (DECL_CONSTRUCTOR_P (decl1
))
10806 ctor_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
10809 /* If this fcn was already referenced via a block-scope `extern' decl
10810 (or an implicit decl), propagate certain information about the usage. */
10811 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1
)))
10812 TREE_ADDRESSABLE (decl1
) = 1;
10817 /* Store the parameter declarations into the current function declaration.
10818 This is called after parsing the parameter declarations, before
10819 digesting the body of the function.
10821 Also install to binding contour return value identifier, if any. */
10824 store_parm_decls ()
10826 register tree fndecl
= current_function_decl
;
10827 register tree parm
;
10828 int parms_have_cleanups
= 0;
10830 /* This is either a chain of PARM_DECLs (when a prototype is used). */
10831 tree specparms
= current_function_parms
;
10833 /* This is a list of types declared among parms in a prototype. */
10834 tree parmtags
= current_function_parm_tags
;
10836 /* This is a chain of any other decls that came in among the parm
10837 declarations. If a parm is declared with enum {foo, bar} x;
10838 then CONST_DECLs for foo and bar are put here. */
10839 tree nonparms
= NULL_TREE
;
10841 if (current_binding_level
== global_binding_level
)
10842 fatal ("parse errors have confused me too much");
10844 /* Initialize RTL machinery. */
10845 init_function_start (fndecl
, input_filename
, lineno
);
10847 /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
10848 declare_function_name ();
10850 /* Create a binding level for the parms. */
10851 expand_start_bindings (0);
10853 if (specparms
!= NULL_TREE
)
10855 /* This case is when the function was defined with an ANSI prototype.
10856 The parms already have decls, so we need not do anything here
10857 except record them as in effect
10858 and complain if any redundant old-style parm decls were written. */
10860 register tree next
;
10862 /* Must clear this because it might contain TYPE_DECLs declared
10864 storedecls (NULL_TREE
);
10865 for (parm
= nreverse (specparms
); parm
; parm
= next
)
10867 next
= TREE_CHAIN (parm
);
10868 if (TREE_CODE (parm
) == PARM_DECL
)
10870 tree cleanup
= maybe_build_cleanup (parm
);
10871 if (DECL_NAME (parm
) == NULL_TREE
)
10874 cp_error_at ("parameter name omitted", parm
);
10876 /* for C++, this is not an error. */
10880 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm
)) == void_type_node
)
10881 cp_error ("parameter `%D' declared void", parm
);
10884 /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
10885 A parameter is assumed not to have any side effects.
10886 If this should change for any reason, then this
10887 will have to wrap the bashed reference type in a save_expr.
10889 Also, if the parameter type is declared to be an X
10890 and there is an X(X&) constructor, we cannot lay it
10891 into the stack (any more), so we make this parameter
10892 look like it is really of reference type. Functions
10893 which pass parameters to this function will know to
10894 create a temporary in their frame, and pass a reference
10897 if (TREE_CODE (TREE_TYPE (parm
)) == REFERENCE_TYPE
10898 && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm
))))
10899 SET_DECL_REFERENCE_SLOT (parm
, convert_from_reference (parm
));
10905 expand_decl (parm
);
10906 if (! expand_decl_cleanup (parm
, cleanup
))
10907 cp_error ("parser lost in parsing declaration of `%D'",
10909 parms_have_cleanups
= 1;
10914 /* If we find an enum constant or a type tag,
10915 put it aside for the moment. */
10916 TREE_CHAIN (parm
) = NULL_TREE
;
10917 nonparms
= chainon (nonparms
, parm
);
10921 /* Get the decls in their original chain order
10922 and record in the function. This is all and only the
10923 PARM_DECLs that were pushed into scope by the loop above. */
10924 DECL_ARGUMENTS (fndecl
) = getdecls ();
10926 storetags (chainon (parmtags
, gettags ()));
10929 DECL_ARGUMENTS (fndecl
) = NULL_TREE
;
10931 /* Now store the final chain of decls for the arguments
10932 as the decl-chain of the current lexical scope.
10933 Put the enumerators in as well, at the front so that
10934 DECL_ARGUMENTS is not modified. */
10936 storedecls (chainon (nonparms
, DECL_ARGUMENTS (fndecl
)));
10938 /* Initialize the RTL code for the function. */
10939 DECL_SAVED_INSNS (fndecl
) = NULL_RTX
;
10940 expand_function_start (fndecl
, parms_have_cleanups
);
10942 /* Create a binding contour which can be used to catch
10943 cleanup-generated temporaries. Also, if the return value needs or
10944 has initialization, deal with that now. */
10945 if (parms_have_cleanups
)
10948 expand_start_bindings (0);
10951 current_function_parms_stored
= 1;
10955 maybe_gc_cleanup
= build_tree_list (NULL_TREE
, error_mark_node
);
10956 if (! expand_decl_cleanup (NULL_TREE
, maybe_gc_cleanup
))
10957 cp_error ("parser lost in parsing declaration of `%D'", fndecl
);
10960 /* If this function is `main', emit a call to `__main'
10961 to run global initializers, etc. */
10962 if (DECL_NAME (fndecl
)
10963 && IDENTIFIER_LENGTH (DECL_NAME (fndecl
)) == 4
10964 && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl
)), "main") == 0
10965 && DECL_CONTEXT (fndecl
) == NULL_TREE
)
10967 expand_main_function ();
10970 expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE
),
10974 output_builtin_tdesc_entries ();
10978 /* Bind a name and initialization to the return value of
10979 the current function. */
10981 store_return_init (return_id
, init
)
10982 tree return_id
, init
;
10984 tree decl
= DECL_RESULT (current_function_decl
);
10987 /* Give this error as many times as there are occurrences,
10988 so that users can use Emacs compilation buffers to find
10989 and fix all such places. */
10990 pedwarn ("ANSI C++ does not permit named return values");
10992 if (return_id
!= NULL_TREE
)
10994 if (DECL_NAME (decl
) == NULL_TREE
)
10996 DECL_NAME (decl
) = return_id
;
10997 DECL_ASSEMBLER_NAME (decl
) = return_id
;
11000 error ("return identifier `%s' already in place",
11001 IDENTIFIER_POINTER (DECL_NAME (decl
)));
11004 /* Can't let this happen for constructors. */
11005 if (DECL_CONSTRUCTOR_P (current_function_decl
))
11007 error ("can't redefine default return value for constructors");
11011 /* If we have a named return value, put that in our scope as well. */
11012 if (DECL_NAME (decl
) != NULL_TREE
)
11014 /* If this named return value comes in a register,
11015 put it in a pseudo-register. */
11016 if (DECL_REGISTER (decl
))
11018 original_result_rtx
= DECL_RTL (decl
);
11019 DECL_RTL (decl
) = gen_reg_rtx (DECL_MODE (decl
));
11022 /* Let `finish_decl' know that this initializer is ok. */
11023 DECL_INITIAL (decl
) = init
;
11025 finish_decl (decl
, init
, 0, 0);
11030 /* Generate code for default X() constructor. */
11032 build_default_constructor (fndecl
)
11035 int i
= CLASSTYPE_N_BASECLASSES (current_class_type
);
11036 tree parm
= TREE_CHAIN (DECL_ARGUMENTS (fndecl
));
11037 tree fields
= TYPE_FIELDS (current_class_type
);
11038 tree binfos
= TYPE_BINFO_BASETYPES (current_class_type
);
11040 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
11041 parm
= TREE_CHAIN (parm
);
11042 parm
= DECL_REFERENCE_SLOT (parm
);
11046 tree basetype
= TREE_VEC_ELT (binfos
, i
);
11047 if (TYPE_HAS_INIT_REF (basetype
))
11049 tree name
= TYPE_NAME (basetype
);
11050 if (TREE_CODE (name
) == TYPE_DECL
)
11051 name
= DECL_NAME (name
);
11052 current_base_init_list
= tree_cons (name
, parm
, current_base_init_list
);
11055 for (; fields
; fields
= TREE_CHAIN (fields
))
11058 if (TREE_STATIC (fields
))
11060 if (TREE_CODE (fields
) != FIELD_DECL
)
11062 if (DECL_NAME (fields
))
11064 if (VFIELD_NAME_P (DECL_NAME (fields
)))
11066 if (VBASE_NAME_P (DECL_NAME (fields
)))
11069 /* True for duplicate members. */
11070 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields
)) != fields
)
11074 init
= build (COMPONENT_REF
, TREE_TYPE (fields
), parm
, fields
);
11075 init
= build_tree_list (NULL_TREE
, init
);
11077 current_member_init_list
11078 = tree_cons (DECL_NAME (fields
), init
, current_member_init_list
);
11083 /* Finish up a function declaration and compile that function
11084 all the way to assembler language output. The free the storage
11085 for the function definition.
11087 This is called after parsing the body of the function definition.
11088 LINENO is the current line number.
11090 C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
11091 (and expand_end_bindings) must be made to take care of the binding
11092 contour for the base initializers. This is only relevant for
11096 finish_function (lineno
, call_poplevel
)
11100 register tree fndecl
= current_function_decl
;
11101 tree fntype
, ctype
= NULL_TREE
;
11102 rtx head
, last_parm_insn
, mark
;
11103 /* Label to use if this function is supposed to return a value. */
11104 tree no_return_label
= NULL_TREE
;
11105 tree decls
= NULL_TREE
;
11107 /* When we get some parse errors, we can end up without a
11108 current_function_decl, so cope. */
11109 if (fndecl
== NULL_TREE
)
11112 fntype
= TREE_TYPE (fndecl
);
11114 /* TREE_READONLY (fndecl) = 1;
11115 This caused &foo to be of type ptr-to-const-function
11116 which then got a warning when stored in a ptr-to-function variable. */
11118 /* This happens on strange parse errors. */
11119 if (! current_function_parms_stored
)
11122 store_parm_decls ();
11125 if (write_symbols
!= NO_DEBUG
&& TREE_CODE (fntype
) != METHOD_TYPE
)
11127 tree ttype
= target_type (fntype
);
11130 if (IS_AGGR_TYPE (ttype
))
11131 /* Let debugger know it should output info for this type. */
11132 note_debug_info_needed (ttype
);
11134 for (parmdecl
= DECL_ARGUMENTS (fndecl
); parmdecl
; parmdecl
= TREE_CHAIN (parmdecl
))
11136 ttype
= target_type (TREE_TYPE (parmdecl
));
11137 if (IS_AGGR_TYPE (ttype
))
11138 /* Let debugger know it should output info for this type. */
11139 note_debug_info_needed (ttype
);
11143 /* Clean house because we will need to reorder insns here. */
11144 do_pending_stack_adjust ();
11148 tree binfo
= TYPE_BINFO (current_class_type
);
11149 tree cond
= integer_one_node
;
11150 tree exprstmt
, vfields
;
11151 tree in_charge_node
= lookup_name (in_charge_identifier
, 0);
11153 int ok_to_optimize_dtor
= 0;
11155 if (current_function_assigns_this
)
11156 cond
= build (NE_EXPR
, integer_type_node
,
11157 current_class_decl
, integer_zero_node
);
11160 int n_baseclasses
= CLASSTYPE_N_BASECLASSES (current_class_type
);
11162 /* If this destructor is empty, then we don't need to check
11163 whether `this' is NULL in some cases. */
11164 mark
= get_last_insn ();
11165 last_parm_insn
= get_first_nonparm_insn ();
11167 if ((flag_this_is_variable
& 1) == 0)
11168 ok_to_optimize_dtor
= 1;
11169 else if (mark
== last_parm_insn
)
11170 ok_to_optimize_dtor
11171 = (n_baseclasses
== 0
11172 || (n_baseclasses
== 1
11173 && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type
, 0))));
11176 /* These initializations might go inline. Protect
11177 the binding level of the parms. */
11179 expand_start_bindings (0);
11181 if (current_function_assigns_this
)
11183 current_function_assigns_this
= 0;
11184 current_function_just_assigned_this
= 0;
11187 /* Generate the code to call destructor on base class.
11188 If this destructor belongs to a class with virtual
11189 functions, then set the virtual function table
11190 pointer to represent the type of our base class. */
11192 /* This side-effect makes call to `build_delete' generate the
11193 code we have to have at the end of this destructor. */
11194 TYPE_HAS_DESTRUCTOR (current_class_type
) = 0;
11196 /* These are two cases where we cannot delegate deletion. */
11197 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
)
11198 || TYPE_GETS_REG_DELETE (current_class_type
))
11199 exprstmt
= build_delete (current_class_type
, C_C_D
, integer_zero_node
,
11200 LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
11202 exprstmt
= build_delete (current_class_type
, C_C_D
, in_charge_node
,
11203 LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
, 0);
11205 /* If we did not assign to this, then `this' is non-zero at
11206 the end of a destructor. As a special optimization, don't
11207 emit test if this is an empty destructor. If it does nothing,
11208 it does nothing. If it calls a base destructor, the base
11209 destructor will perform the test. */
11211 if (exprstmt
!= error_mark_node
11212 && (TREE_CODE (exprstmt
) != NOP_EXPR
11213 || TREE_OPERAND (exprstmt
, 0) != integer_zero_node
11214 || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
)))
11216 expand_label (dtor_label
);
11217 if (cond
!= integer_one_node
)
11218 expand_start_cond (cond
, 0);
11219 if (exprstmt
!= void_zero_node
)
11220 /* Don't call `expand_expr_stmt' if we're not going to do
11221 anything, since -Wall will give a diagnostic. */
11222 expand_expr_stmt (exprstmt
);
11224 /* Run destructor on all virtual baseclasses. */
11225 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
11227 tree vbases
= nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type
)));
11228 expand_start_cond (build (BIT_AND_EXPR
, integer_type_node
,
11229 in_charge_node
, integer_two_node
), 0);
11232 if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases
)))
11234 tree ptr
= convert_pointer_to_vbase (vbases
, current_class_decl
);
11235 expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases
)),
11236 ptr
, integer_zero_node
,
11237 LOOKUP_NONVIRTUAL
|LOOKUP_DESTRUCTOR
|LOOKUP_HAS_IN_CHARGE
, 0));
11239 vbases
= TREE_CHAIN (vbases
);
11241 expand_end_cond ();
11244 do_pending_stack_adjust ();
11245 if (cond
!= integer_one_node
)
11246 expand_end_cond ();
11249 TYPE_HAS_DESTRUCTOR (current_class_type
) = 1;
11251 virtual_size
= c_sizeof (current_class_type
);
11253 /* At the end, call delete if that's what's requested. */
11254 if (TYPE_GETS_REG_DELETE (current_class_type
))
11255 /* This NOP_EXPR means we are in a static call context. */
11258 (build_indirect_ref
11259 (build1 (NOP_EXPR
, TYPE_POINTER_TO (current_class_type
),
11262 ansi_opname
[(int) DELETE_EXPR
],
11263 tree_cons (NULL_TREE
, current_class_decl
,
11264 build_tree_list (NULL_TREE
, virtual_size
)),
11265 NULL_TREE
, LOOKUP_NORMAL
);
11266 else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
11267 exprstmt
= build_x_delete (ptr_type_node
, current_class_decl
, 0,
11270 exprstmt
= NULL_TREE
;
11274 cond
= build (BIT_AND_EXPR
, integer_type_node
,
11275 in_charge_node
, integer_one_node
);
11276 expand_start_cond (cond
, 0);
11277 expand_expr_stmt (exprstmt
);
11278 expand_end_cond ();
11281 /* End of destructor. */
11282 expand_end_bindings (NULL_TREE
, getdecls() != NULL_TREE
, 0);
11283 poplevel (2, 0, 0); /* XXX change to 1 */
11285 /* Back to the top of destructor. */
11286 /* Dont execute destructor code if `this' is NULL. */
11287 mark
= get_last_insn ();
11288 last_parm_insn
= get_first_nonparm_insn ();
11289 if (last_parm_insn
== NULL_RTX
)
11290 last_parm_insn
= mark
;
11292 last_parm_insn
= previous_insn (last_parm_insn
);
11294 /* Make all virtual function table pointers in non-virtual base
11295 classes point to CURRENT_CLASS_TYPE's virtual function
11297 expand_direct_vtbls_init (binfo
, binfo
, 1, 0, current_class_decl
);
11298 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
11299 expand_indirect_vtbls_init (binfo
, C_C_D
, current_class_decl
, 0);
11300 if (! ok_to_optimize_dtor
)
11302 cond
= build_binary_op (NE_EXPR
,
11303 current_class_decl
, integer_zero_node
, 1);
11304 expand_start_cond (cond
, 0);
11306 if (mark
!= get_last_insn ())
11307 reorder_insns (next_insn (mark
), get_last_insn (), last_parm_insn
);
11308 if (! ok_to_optimize_dtor
)
11309 expand_end_cond ();
11311 else if (current_function_assigns_this
)
11313 /* Does not need to call emit_base_init, because
11314 that is done (if needed) just after assignment to this
11317 if (DECL_CONSTRUCTOR_P (current_function_decl
))
11319 expand_label (ctor_label
);
11320 ctor_label
= NULL_TREE
;
11324 decls
= getdecls ();
11325 expand_end_bindings (decls
, decls
!= NULL_TREE
, 0);
11326 poplevel (decls
!= NULL_TREE
, 0, 0);
11328 c_expand_return (current_class_decl
);
11330 else if (TYPE_MAIN_VARIANT (TREE_TYPE (
11331 DECL_RESULT (current_function_decl
))) != void_type_node
11332 && return_label
!= NULL_RTX
)
11333 no_return_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
11335 current_function_assigns_this
= 0;
11336 current_function_just_assigned_this
= 0;
11337 base_init_insns
= NULL_RTX
;
11339 else if (DECL_CONSTRUCTOR_P (fndecl
))
11341 tree allocated_this
;
11342 tree cond
, thenclause
;
11343 /* Allow constructor for a type to get a new instance of the object
11344 using `build_new'. */
11345 tree abstract_virtuals
= CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type
);
11346 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type
) = NULL_TREE
;
11348 DECL_RETURNS_FIRST_ARG (fndecl
) = 1;
11350 if (flag_this_is_variable
> 0)
11352 cond
= build_binary_op (EQ_EXPR
,
11353 current_class_decl
, integer_zero_node
, 1);
11354 thenclause
= build_modify_expr (current_class_decl
, NOP_EXPR
,
11355 build_new (NULL_TREE
, current_class_type
, void_type_node
, 0));
11358 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type
) = abstract_virtuals
;
11360 /* must keep the first insn safe. */
11361 head
= get_insns ();
11363 /* this note will come up to the top with us. */
11364 mark
= get_last_insn ();
11366 if (flag_this_is_variable
> 0)
11368 expand_start_cond (cond
, 0);
11369 expand_expr_stmt (thenclause
);
11370 expand_end_cond ();
11374 if (DECL_NAME (fndecl
) == NULL_TREE
11375 && TREE_CHAIN (DECL_ARGUMENTS (fndecl
)) != NULL_TREE
)
11376 build_default_constructor (fndecl
);
11379 /* Emit insns from `emit_base_init' which sets up virtual
11380 function table pointer(s). */
11381 emit_insns (base_init_insns
);
11382 base_init_insns
= NULL_RTX
;
11384 /* This is where the body of the constructor begins.
11385 If there were no insns in this function body, then the
11386 last_parm_insn is also the last insn.
11388 If optimization is enabled, last_parm_insn may move, so
11389 we don't hold on to it (across emit_base_init). */
11390 last_parm_insn
= get_first_nonparm_insn ();
11391 if (last_parm_insn
== NULL_RTX
)
11392 last_parm_insn
= mark
;
11394 last_parm_insn
= previous_insn (last_parm_insn
);
11396 if (mark
!= get_last_insn ())
11397 reorder_insns (next_insn (mark
), get_last_insn (), last_parm_insn
);
11399 /* This is where the body of the constructor ends. */
11400 expand_label (ctor_label
);
11401 ctor_label
= NULL_TREE
;
11405 expand_end_bindings (decls
= getdecls (), decls
!= NULL_TREE
, 0);
11406 poplevel (decls
!= NULL_TREE
, 1, 0);
11409 c_expand_return (current_class_decl
);
11411 current_function_assigns_this
= 0;
11412 current_function_just_assigned_this
= 0;
11414 else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl
)) == 4
11415 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl
)), "main")
11416 && DECL_CONTEXT (fndecl
) == NULL_TREE
)
11418 /* Make it so that `main' always returns 0 by default. */
11420 c_expand_return (integer_one_node
);
11422 c_expand_return (integer_zero_node
);
11425 else if (return_label
!= NULL_RTX
11426 && current_function_return_value
== NULL_TREE
11427 && ! DECL_NAME (DECL_RESULT (current_function_decl
)))
11428 no_return_label
= build_decl (LABEL_DECL
, NULL_TREE
, NULL_TREE
);
11431 expand_gc_prologue_and_epilogue ();
11433 /* That's the end of the vtable decl's life. Need to mark it such
11434 if doing stupid register allocation.
11436 Note that current_vtable_decl is really an INDIRECT_REF
11437 on top of a VAR_DECL here. */
11438 if (obey_regdecls
&& current_vtable_decl
)
11439 use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl
, 0)));
11441 /* If this function is supposed to return a value, ensure that
11442 we do not fall into the cleanups by mistake. The end of our
11443 function will look like this:
11445 user code (may have return stmt somewhere)
11446 goto no_return_label
11451 NOTE_INSN_FUNCTION_END
11455 If the user omits a return stmt in the USER CODE section, we
11456 will have a control path which reaches NOTE_INSN_FUNCTION_END.
11457 Otherwise, we won't. */
11458 if (no_return_label
)
11460 DECL_CONTEXT (no_return_label
) = fndecl
;
11461 DECL_INITIAL (no_return_label
) = error_mark_node
;
11462 DECL_SOURCE_FILE (no_return_label
) = input_filename
;
11463 DECL_SOURCE_LINE (no_return_label
) = lineno
;
11464 expand_goto (no_return_label
);
11469 /* remove the binding contour which is used
11470 to catch cleanup-generated temporaries. */
11471 expand_end_bindings (0, 0, 0);
11472 poplevel (0, 0, 0);
11476 /* Emit label at beginning of cleanup code for parameters. */
11477 emit_label (cleanup_label
);
11479 /* Get return value into register if that's where it's supposed to be. */
11480 if (original_result_rtx
)
11481 fixup_result_decl (DECL_RESULT (fndecl
), original_result_rtx
);
11483 /* Finish building code that will trigger warnings if users forget
11484 to make their functions return values. */
11485 if (no_return_label
|| cleanup_label
)
11486 emit_jump (return_label
);
11487 if (no_return_label
)
11489 /* We don't need to call `expand_*_return' here because we
11490 don't need any cleanups here--this path of code is only
11491 for error checking purposes. */
11492 expand_label (no_return_label
);
11495 /* reset scope for C++: if we were in the scope of a class,
11496 then when we finish this function, we are not longer so.
11497 This cannot be done until we know for sure that no more
11498 class members will ever be referenced in this function
11499 (i.e., calls to destructors). */
11500 if (current_class_name
)
11502 ctype
= current_class_type
;
11503 pop_nested_class (1);
11506 pop_memoized_context (1);
11508 /* Generate rtl for function exit. */
11509 expand_function_end (input_filename
, lineno
, 1);
11511 if (flag_handle_exceptions
)
11512 expand_exception_blocks();
11514 /* This must come after expand_function_end because cleanups might
11515 have declarations (from inline functions) that need to go into
11516 this function's blocks. */
11517 if (current_binding_level
->parm_flag
!= 1)
11518 my_friendly_abort (122);
11519 poplevel (1, 0, 1);
11521 /* Must mark the RESULT_DECL as being in this function. */
11522 DECL_CONTEXT (DECL_RESULT (fndecl
)) = DECL_INITIAL (fndecl
);
11524 /* Obey `register' declarations if `setjmp' is called in this fn. */
11525 if (flag_traditional
&& current_function_calls_setjmp
)
11526 setjmp_protect (DECL_INITIAL (fndecl
));
11528 /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
11529 to the FUNCTION_DECL node itself. */
11530 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl
)) = fndecl
;
11532 /* So we can tell if jump_optimize sets it to 1. */
11535 /* ??? Compensate for Sun brain damage in dealing with data segments
11538 && (DECL_CONSTRUCTOR_P (fndecl
)
11539 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
11540 && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype
)))
11541 DECL_INLINE (fndecl
) = 0;
11543 if (DECL_EXTERNAL (fndecl
)
11544 /* This function is just along for the ride. If we can make
11545 it inline, that's great. Otherwise, just punt it. */
11546 && (DECL_INLINE (fndecl
) == 0
11548 || function_cannot_inline_p (fndecl
)))
11550 extern int rtl_dump_and_exit
;
11551 int old_rtl_dump_and_exit
= rtl_dump_and_exit
;
11552 int inline_spec
= DECL_INLINE (fndecl
);
11554 /* This throws away the code for FNDECL. */
11555 rtl_dump_and_exit
= 1;
11556 /* This throws away the memory of the code for FNDECL. */
11557 if (flag_no_inline
)
11558 DECL_INLINE (fndecl
) = 0;
11559 rest_of_compilation (fndecl
);
11560 rtl_dump_and_exit
= old_rtl_dump_and_exit
;
11561 DECL_INLINE (fndecl
) = inline_spec
;
11565 /* Run the optimizers and output the assembler code for this
11567 rest_of_compilation (fndecl
);
11570 if (DECL_INLINE (fndecl
)
11571 && !TREE_ASM_WRITTEN (fndecl
) && DECL_FUNCTION_MEMBER_P (fndecl
))
11573 mark_inline_for_output (fndecl
);
11576 if (ctype
&& TREE_ASM_WRITTEN (fndecl
))
11577 note_debug_info_needed (ctype
);
11579 current_function_returns_null
|= can_reach_end
;
11581 /* Since we don't normally go through c_expand_return for constructors,
11582 this normally gets the wrong value.
11583 Also, named return values have their return codes emitted after
11584 NOTE_INSN_FUNCTION_END, confusing jump.c. */
11585 if (DECL_CONSTRUCTOR_P (fndecl
)
11586 || DECL_NAME (DECL_RESULT (fndecl
)) != NULL_TREE
)
11587 current_function_returns_null
= 0;
11589 if (TREE_THIS_VOLATILE (fndecl
) && current_function_returns_null
)
11590 cp_warning ("`noreturn' function `%D' does return", fndecl
);
11591 else if ((warn_return_type
|| pedantic
)
11592 && current_function_returns_null
11593 && TYPE_MAIN_VARIANT (TREE_TYPE (fntype
)) != void_type_node
)
11595 /* If this function returns non-void and control can drop through,
11597 cp_pedwarn ("control reaches end of non-void function `%D'", fndecl
);
11599 /* With just -W, complain only if function returns both with
11600 and without a value. */
11601 else if (extra_warnings
11602 && current_function_returns_value
&& current_function_returns_null
)
11603 warning ("this function may return with or without a value");
11605 /* Free all the tree nodes making up this function. */
11606 /* Switch back to allocating nodes permanently
11607 until we start another function. */
11608 permanent_allocation (1);
11611 cadillac_finish_function (fndecl
);
11613 if (DECL_SAVED_INSNS (fndecl
) == NULL_RTX
)
11615 /* Stop pointing to the local nodes about to be freed. */
11616 /* But DECL_INITIAL must remain nonzero so we know this
11617 was an actual function definition. */
11618 DECL_INITIAL (fndecl
) = error_mark_node
;
11619 if (! DECL_CONSTRUCTOR_P (fndecl
)
11620 || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype
)))
11621 DECL_ARGUMENTS (fndecl
) = NULL_TREE
;
11624 /* Let the error reporting routines know that we're outside a function. */
11625 current_function_decl
= NULL_TREE
;
11626 named_label_uses
= NULL_TREE
;
11629 /* Create the FUNCTION_DECL for a function definition.
11630 LINE1 is the line number that the definition absolutely begins on.
11631 LINE2 is the line number that the name of the function appears on.
11632 DECLSPECS and DECLARATOR are the parts of the declaration;
11633 they describe the return type and the name of the function,
11634 but twisted together in a fashion that parallels the syntax of C.
11636 This function creates a binding context for the function body
11637 as well as setting up the FUNCTION_DECL in current_function_decl.
11639 Returns a FUNCTION_DECL on success.
11641 If the DECLARATOR is not suitable for a function (it defines a datum
11642 instead), we return 0, which tells yyparse to report a parse error.
11644 May return void_type_node indicating that this method is actually
11645 a friend. See grokfield for more details.
11647 Came here with a `.pushlevel' .
11649 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
11650 CHANGES TO CODE IN `grokfield'. */
11652 start_method (declspecs
, declarator
, raises
)
11653 tree declarator
, declspecs
, raises
;
11655 tree fndecl
= grokdeclarator (declarator
, declspecs
, MEMFUNCDEF
, 0, raises
);
11657 /* Something too ugly to handle. */
11658 if (fndecl
== NULL_TREE
)
11661 /* Pass friends other than inline friend functions back. */
11662 if (TYPE_MAIN_VARIANT (fndecl
) == void_type_node
)
11665 if (TREE_CODE (fndecl
) != FUNCTION_DECL
)
11666 /* Not a function, tell parser to report parse error. */
11669 if (IS_SIGNATURE (current_class_type
))
11671 IS_DEFAULT_IMPLEMENTATION (fndecl
) = 1;
11672 /* In case we need this info later. */
11673 HAS_DEFAULT_IMPLEMENTATION (current_class_type
) = 1;
11676 if (DECL_IN_AGGR_P (fndecl
))
11678 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl
)) != current_class_type
)
11680 if (DECL_CONTEXT (fndecl
))
11681 cp_error ("`%D' is already defined in class %s", fndecl
,
11682 TYPE_NAME_STRING (DECL_CONTEXT (fndecl
)));
11684 return void_type_node
;
11687 if (flag_default_inline
)
11688 DECL_INLINE (fndecl
) = 1;
11690 if (processing_template_defn
)
11691 SET_DECL_IMPLICIT_INSTANTIATION (fndecl
);
11693 /* We read in the parameters on the maybepermanent_obstack,
11694 but we won't be getting back to them until after we
11695 may have clobbered them. So the call to preserve_data
11696 will keep them safe. */
11699 if (! DECL_FRIEND_P (fndecl
))
11701 if (DECL_CHAIN (fndecl
) != NULL_TREE
)
11703 /* Need a fresh node here so that we don't get circularity
11704 when we link these together. If FNDECL was a friend, then
11705 `pushdecl' does the right thing, which is nothing wrt its
11706 current value of DECL_CHAIN. */
11707 fndecl
= copy_node (fndecl
);
11709 if (TREE_CHAIN (fndecl
))
11711 fndecl
= copy_node (fndecl
);
11712 TREE_CHAIN (fndecl
) = NULL_TREE
;
11715 if (DECL_CONSTRUCTOR_P (fndecl
))
11717 if (! grok_ctor_properties (current_class_type
, fndecl
))
11718 return void_type_node
;
11720 else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl
)))
11721 grok_op_properties (fndecl
, DECL_VIRTUAL_P (fndecl
), 0);
11724 finish_decl (fndecl
, NULL_TREE
, NULL_TREE
, 0);
11726 /* Make a place for the parms */
11728 current_binding_level
->parm_flag
= 1;
11730 DECL_IN_AGGR_P (fndecl
) = 1;
11734 /* Go through the motions of finishing a function definition.
11735 We don't compile this method until after the whole class has
11738 FINISH_METHOD must return something that looks as though it
11739 came from GROKFIELD (since we are defining a method, after all).
11741 This is called after parsing the body of the function definition.
11742 STMTS is the chain of statements that makes up the function body.
11744 DECL is the ..._DECL that `start_method' provided. */
11747 finish_method (decl
)
11750 register tree fndecl
= decl
;
11753 register tree link
;
11755 if (TYPE_MAIN_VARIANT (decl
) == void_type_node
)
11758 old_initial
= DECL_INITIAL (fndecl
);
11760 /* Undo the level for the parms (from start_method).
11761 This is like poplevel, but it causes nothing to be
11762 saved. Saving information here confuses symbol-table
11763 output routines. Besides, this information will
11764 be correctly output when this method is actually
11767 /* Clear out the meanings of the local variables of this level;
11768 also record in each decl which block it belongs to. */
11770 for (link
= current_binding_level
->names
; link
; link
= TREE_CHAIN (link
))
11772 if (DECL_NAME (link
) != NULL_TREE
)
11773 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link
)) = 0;
11774 my_friendly_assert (TREE_CODE (link
) != FUNCTION_DECL
, 163);
11775 DECL_CONTEXT (link
) = NULL_TREE
;
11778 /* Restore all name-meanings of the outer levels
11779 that were shadowed by this level. */
11781 for (link
= current_binding_level
->shadowed
; link
; link
= TREE_CHAIN (link
))
11782 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
11783 for (link
= current_binding_level
->class_shadowed
;
11784 link
; link
= TREE_CHAIN (link
))
11785 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
11786 for (link
= current_binding_level
->type_shadowed
;
11787 link
; link
= TREE_CHAIN (link
))
11788 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link
)) = TREE_VALUE (link
);
11790 GNU_xref_end_scope ((HOST_WIDE_INT
) current_binding_level
,
11791 (HOST_WIDE_INT
) current_binding_level
->level_chain
,
11792 current_binding_level
->parm_flag
,
11793 current_binding_level
->keep
,
11794 current_binding_level
->tag_transparent
);
11796 poplevel (0, 0, 0);
11798 DECL_INITIAL (fndecl
) = old_initial
;
11800 /* We used to check if the context of FNDECL was different from
11801 current_class_type as another way to get inside here. This didn't work
11802 for String.cc in libg++. */
11803 if (DECL_FRIEND_P (fndecl
))
11805 CLASSTYPE_INLINE_FRIENDS (current_class_type
)
11806 = tree_cons (NULL_TREE
, fndecl
, CLASSTYPE_INLINE_FRIENDS (current_class_type
));
11807 decl
= void_type_node
;
11813 /* Called when a new struct TYPE is defined.
11814 If this structure or union completes the type of any previous
11815 variable declaration, lay it out and output its rtl. */
11818 hack_incomplete_structures (type
)
11823 if (current_binding_level
->n_incomplete
== 0)
11826 if (!type
) /* Don't do this for class templates. */
11829 for (decl
= current_binding_level
->names
; decl
; decl
= TREE_CHAIN (decl
))
11830 if (TREE_TYPE (decl
) == type
11831 || (TREE_TYPE (decl
)
11832 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
11833 && TREE_TYPE (TREE_TYPE (decl
)) == type
))
11835 if (TREE_CODE (decl
) == TYPE_DECL
)
11836 layout_type (TREE_TYPE (decl
));
11839 int toplevel
= global_binding_level
== current_binding_level
;
11840 if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
11841 && TREE_TYPE (TREE_TYPE (decl
)) == type
)
11842 layout_type (TREE_TYPE (decl
));
11843 layout_decl (decl
, 0);
11844 rest_of_decl_compilation (decl
, NULL_PTR
, toplevel
, 0);
11848 expand_decl (decl
);
11849 cleanup
= maybe_build_cleanup (decl
);
11850 expand_decl_init (decl
);
11851 if (! expand_decl_cleanup (decl
, cleanup
))
11852 cp_error ("parser lost in parsing declaration of `%D'",
11856 my_friendly_assert (current_binding_level
->n_incomplete
> 0, 164);
11857 --current_binding_level
->n_incomplete
;
11861 /* Nonzero if presently building a cleanup. Needed because
11862 SAVE_EXPRs are not the right things to use inside of cleanups.
11863 They are only ever evaluated once, where the cleanup
11864 might be evaluated several times. In this case, a later evaluation
11865 of the cleanup might fill in the SAVE_EXPR_RTL, and it will
11866 not be valid for an earlier cleanup. */
11868 int building_cleanup
;
11870 /* If DECL is of a type which needs a cleanup, build that cleanup here.
11871 We don't build cleanups if just going for syntax checking, since
11872 fixup_cleanups does not know how to not handle them.
11874 Don't build these on the momentary obstack; they must live
11875 the life of the binding contour. */
11877 maybe_build_cleanup (decl
)
11880 tree type
= TREE_TYPE (decl
);
11881 if (TYPE_NEEDS_DESTRUCTOR (type
))
11883 int temp
= 0, flags
= LOOKUP_NORMAL
|LOOKUP_DESTRUCTOR
;
11885 int old_building_cleanup
= building_cleanup
;
11886 building_cleanup
= 1;
11888 if (TREE_CODE (decl
) != PARM_DECL
)
11889 temp
= suspend_momentary ();
11891 if (TREE_CODE (type
) == ARRAY_TYPE
)
11895 mark_addressable (decl
);
11896 rval
= build_unary_op (ADDR_EXPR
, decl
, 0);
11899 /* Optimize for space over speed here. */
11900 if (! TYPE_USES_VIRTUAL_BASECLASSES (type
)
11901 || flag_expensive_optimizations
)
11902 flags
|= LOOKUP_NONVIRTUAL
;
11904 /* Use TYPE_MAIN_VARIANT so we don't get a warning about
11905 calling delete on a `const' variable. */
11906 if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval
))))
11907 rval
= build1 (NOP_EXPR
, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval
)))), rval
);
11909 rval
= build_delete (TREE_TYPE (rval
), rval
, integer_two_node
, flags
, 0);
11911 if (TYPE_USES_VIRTUAL_BASECLASSES (type
)
11912 && ! TYPE_HAS_DESTRUCTOR (type
))
11913 rval
= build_compound_expr (tree_cons (NULL_TREE
, rval
,
11914 build_tree_list (NULL_TREE
, build_vbase_delete (type
, decl
))));
11916 if (TREE_CODE (decl
) != PARM_DECL
)
11917 resume_momentary (temp
);
11919 building_cleanup
= old_building_cleanup
;
11926 /* Expand a C++ expression at the statement level.
11927 This is needed to ferret out nodes which have UNKNOWN_TYPE.
11928 The C++ type checker should get all of these out when
11929 expressions are combined with other, type-providing, expressions,
11930 leaving only orphan expressions, such as:
11932 &class::bar; / / takes its address, but does nothing with it.
11936 cplus_expand_expr_stmt (exp
)
11939 if (TREE_TYPE (exp
) == unknown_type_node
)
11941 if (TREE_CODE (exp
) == ADDR_EXPR
|| TREE_CODE (exp
) == TREE_LIST
)
11942 error ("address of overloaded function with no contextual type information");
11943 else if (TREE_CODE (exp
) == COMPONENT_REF
)
11944 warning ("useless reference to a member function name, did you forget the ()?");
11948 int remove_implicit_immediately
= 0;
11950 if (TREE_CODE (exp
) == FUNCTION_DECL
)
11952 cp_warning ("reference, not call, to function `%D'", exp
);
11953 warning ("at this point in file");
11956 exp
= build1 (CLEANUP_POINT_EXPR
, TREE_TYPE (exp
), exp
);
11957 expand_expr_stmt (break_out_cleanups (exp
));
11960 /* Clean up any pending cleanups. This happens when a function call
11961 returns a cleanup-needing value that nobody uses. */
11962 expand_cleanups_to (NULL_TREE
);
11965 /* When a stmt has been parsed, this function is called.
11967 Currently, this function only does something within a
11968 constructor's scope: if a stmt has just assigned to this,
11969 and we are in a derived class, we call `emit_base_init'. */
11974 extern struct nesting
*cond_stack
, *loop_stack
, *case_stack
;
11977 if (current_function_assigns_this
11978 || ! current_function_just_assigned_this
)
11980 if (DECL_CONSTRUCTOR_P (current_function_decl
))
11982 /* Constructors must wait until we are out of control
11983 zones before calling base constructors. */
11984 if (cond_stack
|| loop_stack
|| case_stack
)
11986 emit_insns (base_init_insns
);
11987 check_base_init (current_class_type
);
11989 current_function_assigns_this
= 1;
11992 cadillac_finish_stmt ();
11995 /* Change a static member function definition into a FUNCTION_TYPE, instead
11996 of the METHOD_TYPE that we create when it's originally parsed.
11998 WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES
11999 (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of
12000 other decls. Either pass the addresses of local variables or NULL. */
12003 revert_static_member_fn (decl
, fn
, argtypes
)
12004 tree
*decl
, *fn
, *argtypes
;
12007 tree function
= fn
? *fn
: TREE_TYPE (*decl
);
12008 tree args
= argtypes
? *argtypes
: TYPE_ARG_TYPES (function
);
12010 args
= TREE_CHAIN (args
);
12011 tmp
= build_function_type (TREE_TYPE (function
), args
);
12012 tmp
= build_type_variant (tmp
, TYPE_READONLY (function
),
12013 TYPE_VOLATILE (function
));
12014 tmp
= build_exception_variant (TYPE_METHOD_BASETYPE (function
), tmp
,
12015 TYPE_RAISES_EXCEPTIONS (function
));
12016 TREE_TYPE (*decl
) = tmp
;
12017 DECL_STATIC_FUNCTION_P (*decl
) = 1;
12025 id_in_current_class (id
)
12028 return !!purpose_member (id
, class_binding_level
->class_shadowed
);