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 struct obstack permanent_obstack;
46 extern int current_class_depth;
48 /* Stack of places to restore the search obstack back to. */
50 /* Obstack used for remembering local class declarations (like
51 enums and static (const) members. */
53 static struct obstack decl_obstack;
54 static struct stack_level *decl_stack;
56 #ifndef CHAR_TYPE_SIZE
57 #define CHAR_TYPE_SIZE BITS_PER_UNIT
60 #ifndef SHORT_TYPE_SIZE
61 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
65 #define INT_TYPE_SIZE BITS_PER_WORD
68 #ifndef LONG_TYPE_SIZE
69 #define LONG_TYPE_SIZE BITS_PER_WORD
72 #ifndef LONG_LONG_TYPE_SIZE
73 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
76 #ifndef WCHAR_UNSIGNED
77 #define WCHAR_UNSIGNED 0
80 #ifndef FLOAT_TYPE_SIZE
81 #define FLOAT_TYPE_SIZE BITS_PER_WORD
84 #ifndef DOUBLE_TYPE_SIZE
85 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
88 #ifndef LONG_DOUBLE_TYPE_SIZE
89 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
92 /* We let tm.h override the types used here, to handle trivial differences
93 such as the choice of unsigned int or long unsigned int for size_t.
94 When machines start needing nontrivial differences in the size type,
95 it would be best to do something here to figure out automatically
96 from other information what type to use. */
99 #define SIZE_TYPE "long unsigned int"
103 #define PTRDIFF_TYPE "long int"
107 #define WCHAR_TYPE "int"
110 #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
111 define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
112 #define auto_function(NAME, TYPE, CODE) \
114 tree __name = NAME; \
115 tree __type = TYPE; \
116 define_function (IDENTIFIER_POINTER (__name), __type, CODE, \
117 (void (*)())push_overloaded_decl_1, \
118 IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\
121 static tree grokparms PROTO((tree, int));
122 static tree lookup_nested_type PROTO((tree, tree));
123 static char *redeclaration_error_message PROTO((tree, tree));
124 static void grok_op_properties PROTO((tree, int, int));
125 static void deactivate_exception_cleanups PROTO((void));
128 PROTO((char *, tree, enum built_in_function, void (*)(), char *));
130 /* a node which has tree code ERROR_MARK, and whose type is itself.
131 All erroneous expressions are replaced with this node. All functions
132 that accept nodes as arguments should avoid generating error messages
133 if this node is one of the arguments, since it is undesirable to get
134 multiple error messages from one error in the input. */
136 tree error_mark_node;
138 /* Erroneous argument lists can use this *IFF* they do not modify it. */
139 tree error_mark_list;
141 /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
143 tree short_integer_type_node;
144 tree integer_type_node;
145 tree long_integer_type_node;
146 tree long_long_integer_type_node;
148 tree short_unsigned_type_node;
149 tree unsigned_type_node;
150 tree long_unsigned_type_node;
151 tree long_long_unsigned_type_node;
153 tree ptrdiff_type_node;
155 tree unsigned_char_type_node;
156 tree signed_char_type_node;
158 tree wchar_type_node;
159 tree signed_wchar_type_node;
160 tree unsigned_wchar_type_node;
162 tree float_type_node;
163 tree double_type_node;
164 tree long_double_type_node;
166 tree intQI_type_node;
167 tree intHI_type_node;
168 tree intSI_type_node;
169 tree intDI_type_node;
171 tree unsigned_intQI_type_node;
172 tree unsigned_intHI_type_node;
173 tree unsigned_intSI_type_node;
174 tree unsigned_intDI_type_node;
176 /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */
178 tree void_type_node, void_list_node;
181 /* Nodes for types `void *' and `const void *'. */
183 tree ptr_type_node, const_ptr_type_node;
185 /* Nodes for types `char *' and `const char *'. */
187 tree string_type_node, const_string_type_node;
189 /* Type `char[256]' or something like it.
190 Used when an array of char is needed and the size is irrelevant. */
192 tree char_array_type_node;
194 /* Type `int[256]' or something like it.
195 Used when an array of int needed and the size is irrelevant. */
197 tree int_array_type_node;
199 /* Type `wchar_t[256]' or something like it.
200 Used when a wide string literal is created. */
202 tree wchar_array_type_node;
204 /* type `int ()' -- used for implicit declaration of functions. */
206 tree default_function_type;
208 /* function types `double (double)' and `double (double, double)', etc. */
210 tree double_ftype_double, double_ftype_double_double;
211 tree int_ftype_int, long_ftype_long;
213 /* Function type `void (void *, void *, int)' and similar ones. */
215 tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
217 /* Function type `char *(char *, char *)' and similar ones */
218 tree string_ftype_ptr_ptr, int_ftype_string_string;
220 /* Function type `size_t (const char *)' */
221 tree sizet_ftype_string;
223 /* Function type `int (const void *, const void *, size_t)' */
224 tree int_ftype_cptr_cptr_sizet;
227 tree memptr_type, vtable_entry_type;
228 tree delta_type_node;
229 tree __t_desc_type_node, __i_desc_type_node, __m_desc_type_node;
230 tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
231 tree class_star_type_node;
232 tree class_type_node, record_type_node, union_type_node, enum_type_node;
233 tree exception_type_node, unknown_type_node;
234 tree opaque_type_node, signature_type_node;
235 tree sigtable_entry_type;
236 tree maybe_gc_cleanup;
238 /* Used for virtual function tables. */
241 /* Array type `vtable_entry_type[]' */
244 /* Static decls which do not have static initializers have no
245 initializers as far as GNU C is concerned. EMPTY_INIT_NODE
246 is a static initializer which makes varasm code place the decl
247 in data rather than in bss space. Such gymnastics are necessary
248 to avoid the problem that the linker will not include a library
249 file if all the library appears to contribute are bss variables. */
251 tree empty_init_node;
253 /* In a destructor, the point at which all derived class destroying
254 has been done, just before any base class destroying will be done. */
258 /* In a constructor, the point at which we are ready to return
259 the pointer to the initialized object. */
263 /* A FUNCTION_DECL which can call `unhandled_exception'.
264 Not necessarily the one that the user will declare,
265 but sufficient to be called by routines that want to abort the program. */
267 tree unhandled_exception_fndecl;
269 /* A FUNCTION_DECL which can call `abort'. Not necessarily the
270 one that the user will declare, but sufficient to be called
271 by routines that want to abort the program. */
275 extern rtx cleanup_label, return_label;
277 /* If original DECL_RESULT of current function was a register,
278 but due to being an addressable named return value, would up
279 on the stack, this variable holds the named return value's
280 original location. */
281 rtx original_result_rtx;
283 /* Sequence of insns which represents base initialization. */
286 /* C++: Keep these around to reduce calls to `get_identifier'.
287 Identifiers for `this' in member functions and the auto-delete
288 parameter for destructors. */
289 tree this_identifier, in_charge_identifier;
290 /* Used in pointer to member functions, and in vtables. */
291 tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
292 tree pfn_or_delta2_identifier;
294 /* A list (chain of TREE_LIST nodes) of named label uses.
295 The TREE_PURPOSE field is the list of variables defined
296 the the label's scope defined at the point of use.
297 The TREE_VALUE field is the LABEL_DECL used.
298 The TREE_TYPE field holds `current_binding_level' at the
299 point of the label's use.
301 Used only for jumps to as-yet undefined labels, since
302 jumps to defined labels can have their validity checked
305 static tree named_label_uses;
307 /* A list of objects which have constructors or destructors
308 which reside in the global scope. The decl is stored in
309 the TREE_VALUE slot and the initializer is stored
310 in the TREE_PURPOSE slot. */
311 tree static_aggregates;
313 /* A list of overloaded functions which we should forget ever
314 existed, such as functions declared in a function's scope,
315 once we leave that function's scope. */
316 static tree overloads_to_forget;
320 /* Two expressions that are constants with value zero.
321 The first is of type `int', the second of type `void *'. */
323 tree integer_zero_node;
324 tree null_pointer_node;
326 /* A node for the integer constants 1, 2, and 3. */
328 tree integer_one_node, integer_two_node, integer_three_node;
330 /* Nonzero if we have seen an invalid cross reference
331 to a struct, union, or enum, but not yet printed the message. */
333 tree pending_invalid_xref;
334 /* File and line to appear in the eventual error message. */
335 char *pending_invalid_xref_file;
336 int pending_invalid_xref_line;
338 /* While defining an enum type, this is 1 plus the last enumerator
341 static tree enum_next_value;
343 /* Parsing a function declarator leaves a list of parameter names
344 or a chain or parameter decls here. */
346 tree last_function_parms;
348 /* Parsing a function declarator leaves here a chain of structure
349 and enum types declared in the parmlist. */
351 static tree last_function_parm_tags;
353 /* After parsing the declarator that starts a function definition,
354 `start_function' puts here the list of parameter names or chain of decls.
355 `store_parm_decls' finds it here. */
357 static tree current_function_parms;
359 /* Similar, for last_function_parm_tags. */
360 static tree current_function_parm_tags;
362 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
363 that have names. Here so we can clear out their names' definitions
364 at the end of the function. */
366 static tree named_labels;
368 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
370 static tree shadowed_labels;
372 #if 0 /* Not needed by C++ */
373 /* Nonzero when store_parm_decls is called indicates a varargs function.
374 Value not meaningful after store_parm_decls. */
376 static int c_function_varargs;
379 /* The FUNCTION_DECL for the function currently being compiled,
380 or 0 if between functions. */
381 tree current_function_decl;
383 /* Set to 0 at beginning of a function definition, set to 1 if
384 a return statement that specifies a return value is seen. */
386 int current_function_returns_value;
388 /* Set to 0 at beginning of a function definition, set to 1 if
389 a return statement with no argument is seen. */
391 int current_function_returns_null;
393 /* Set to 0 at beginning of a function definition, and whenever
394 a label (case or named) is defined. Set to value of expression
395 returned from function when that value can be transformed into
396 a named return value. */
398 tree current_function_return_value;
400 /* Set to nonzero by `grokdeclarator' for a function
401 whose return type is defaulted, if warnings for this are desired. */
403 static int warn_about_return_type;
405 /* Nonzero when starting a function declared `extern inline'. */
407 static int current_extern_inline;
409 /* Nonzero means give `double' the same size as `float'. */
411 extern int flag_short_double;
413 /* Nonzero means don't recognize any builtin functions. */
415 extern int flag_no_builtin;
417 /* Nonzero means do emit exported implementations of functions even if
418 they can be inlined. */
420 extern int flag_implement_inlines;
422 /* Nonzero means handle things in ANSI, instead of GNU fashion. This
423 flag should be tested for language behavior that's different between
424 ANSI and GNU, but not so horrible as to merit a PEDANTIC label. */
426 extern int flag_ansi;
428 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
430 extern int flag_huge_objects;
432 /* Nonzero if we want to conserve space in the .o files. We do this
433 by putting uninitialized data and runtime initialized data into
434 .common instead of .data at the expense of not flaging multiple
436 extern int flag_conserve_space;
438 /* Pointers to the base and current top of the language name stack. */
440 extern tree *current_lang_base, *current_lang_stack;
442 /* C and C++ flags are in decl2.c. */
444 /* Set to 0 at beginning of a constructor, set to 1
445 if that function does an allocation before referencing its
446 instance variable. */
447 int current_function_assigns_this;
448 int current_function_just_assigned_this;
450 /* Set to 0 at beginning of a function. Set non-zero when
451 store_parm_decls is called. Don't call store_parm_decls
452 if this flag is non-zero! */
453 int current_function_parms_stored;
455 /* Current end of entries in the gc obstack for stack pointer variables. */
457 int current_function_obstack_index;
459 /* Flag saying whether we have used the obstack in this function or not. */
461 int current_function_obstack_usage;
463 /* Flag used when debugging spew.c */
465 extern int spew_debug;
467 /* This is a copy of the class_shadowed list of the previous class binding
468 contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs
469 when entering another class scope (i.e. a cache miss). */
470 extern tree previous_class_values;
473 /* Allocate a level of searching. */
475 push_decl_level (stack, obstack)
476 struct stack_level *stack;
477 struct obstack *obstack;
479 struct stack_level tem;
482 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
485 /* For each binding contour we allocate a binding_level structure
486 * which records the names defined in that contour.
489 * 1) one for each function definition,
490 * where internal declarations of the parameters appear.
491 * 2) one for each compound statement,
492 * to record its declarations.
494 * The current meaning of a name can be found by searching the levels from
495 * the current one out to the global one.
497 * Off to the side, may be the class_binding_level. This exists
498 * only to catch class-local declarations. It is otherwise
501 * Also there may be binding levels that catch cleanups that
502 * must be run when exceptions occur.
505 /* Note that the information in the `names' component of the global contour
506 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
510 /* A chain of _DECL nodes for all variables, constants, functions,
511 * and typedef types. These are in the reverse of the order supplied.
515 /* A list of structure, union and enum definitions,
516 * for looking up tag names.
517 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
518 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
519 * or ENUMERAL_TYPE node.
521 * C++: the TREE_VALUE nodes can be simple types for component_bindings.
526 /* For each level, a list of shadowed outer-level local definitions
527 to be restored when this level is popped.
528 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
529 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
532 /* Same, for IDENTIFIER_CLASS_VALUE. */
535 /* Same, for IDENTIFIER_TYPE_VALUE. */
538 /* For each level (except not the global one),
539 a chain of BLOCK nodes for all the levels
540 that were entered and exited one level down. */
543 /* The BLOCK node for this level, if one has been preallocated.
544 If 0, the BLOCK is allocated (if needed) when the level is popped. */
547 /* The binding level which this one is contained in (inherits from). */
548 struct binding_level *level_chain;
550 /* Number of decls in `names' that have incomplete
551 structure or union types. */
552 unsigned short n_incomplete;
554 /* 1 for the level that holds the parameters of a function.
555 2 for the level that holds a class declaration.
556 3 for levels that hold parameter declarations. */
557 unsigned parm_flag : 4;
559 /* 1 means make a BLOCK for this level regardless of all else.
560 2 for temporary binding contours created by the compiler. */
563 /* Nonzero if this level "doesn't exist" for tags. */
564 unsigned tag_transparent : 1;
566 /* Nonzero if this level can safely have additional
567 cleanup-needing variables added to it. */
568 unsigned more_cleanups_ok : 1;
569 unsigned have_cleanups : 1;
571 /* Nonzero if this level can safely have additional
572 exception-raising statements added to it. */
573 unsigned more_exceptions_ok : 1;
574 unsigned have_exceptions : 1;
576 /* Nonzero if we should accept any name as an identifier in
577 this scope. This happens in some template definitions. */
578 unsigned accept_any : 1;
580 /* Nonzero if this level is for completing a template class definition
581 inside a binding level that temporarily binds the parameters. This
582 means that definitions here should not be popped off when unwinding
583 this binding level. (Not actually implemented this way,
585 unsigned pseudo_global : 1;
587 /* Two bits left for this word. */
589 #if defined(DEBUG_CP_BINDING_LEVELS)
590 /* Binding depth at which this level began. */
591 unsigned binding_depth;
592 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
595 #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
597 /* The (non-class) binding level currently in effect. */
599 static struct binding_level *current_binding_level;
601 /* The binding level of the current class, if any. */
603 static struct binding_level *class_binding_level;
605 /* The current (class or non-class) binding level currently in effect. */
607 #define inner_binding_level \
608 (class_binding_level ? class_binding_level : current_binding_level)
610 /* A chain of binding_level structures awaiting reuse. */
612 static struct binding_level *free_binding_level;
614 /* The outermost binding level, for names of file scope.
615 This is created when the compiler is started and exists
616 through the entire run. */
618 static struct binding_level *global_binding_level;
620 /* Binding level structures are initialized by copying this one. */
622 static struct binding_level clear_binding_level;
624 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
626 static int keep_next_level_flag;
628 #if defined(DEBUG_CP_BINDING_LEVELS)
629 static int binding_depth = 0;
630 static int is_class_level = 0;
637 for (i = 0; i < binding_depth*2; i++)
640 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
642 static tree pushdecl_with_scope PROTO((tree, struct binding_level *));
645 push_binding_level (newlevel, tag_transparent, keep)
646 struct binding_level *newlevel;
647 int tag_transparent, keep;
649 /* Add this level to the front of the chain (stack) of levels that
651 *newlevel = clear_binding_level;
652 if (class_binding_level)
654 newlevel->level_chain = class_binding_level;
655 class_binding_level = (struct binding_level *)0;
659 newlevel->level_chain = current_binding_level;
661 current_binding_level = newlevel;
662 newlevel->tag_transparent = tag_transparent;
663 newlevel->more_cleanups_ok = 1;
664 newlevel->more_exceptions_ok = 1;
665 newlevel->keep = keep;
666 #if defined(DEBUG_CP_BINDING_LEVELS)
667 newlevel->binding_depth = binding_depth;
669 fprintf (stderr, "push %s level 0x%08x line %d\n",
670 (is_class_level) ? "class" : "block", newlevel, lineno);
673 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
679 if (class_binding_level)
680 current_binding_level = class_binding_level;
682 if (global_binding_level)
684 /* cannot pop a level, if there are none left to pop. */
685 if (current_binding_level == global_binding_level)
686 my_friendly_abort (123);
688 /* Pop the current level, and free the structure for reuse. */
689 #if defined(DEBUG_CP_BINDING_LEVELS)
692 fprintf (stderr, "pop %s level 0x%08x line %d\n",
693 (is_class_level) ? "class" : "block",
694 current_binding_level, lineno);
695 if (is_class_level != (current_binding_level == class_binding_level))
696 #if 0 /* XXX Don't abort when we're watching how things are being managed. */
701 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
705 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
707 register struct binding_level *level = current_binding_level;
708 current_binding_level = current_binding_level->level_chain;
709 level->level_chain = free_binding_level;
710 #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
711 if (level->binding_depth != binding_depth)
713 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
714 free_binding_level = level;
716 class_binding_level = current_binding_level;
717 if (class_binding_level->parm_flag != 2)
718 class_binding_level = 0;
719 while (current_binding_level->parm_flag == 2)
720 current_binding_level = current_binding_level->level_chain;
724 /* Nonzero if we are currently in the global binding level. */
729 return current_binding_level == global_binding_level;
735 keep_next_level_flag = 1;
738 /* Nonzero if the current level needs to have a BLOCK made. */
743 return (current_binding_level->blocks != NULL_TREE
744 || current_binding_level->keep
745 || current_binding_level->names != NULL_TREE
746 || (current_binding_level->tags != NULL_TREE
747 && !current_binding_level->tag_transparent));
750 /* Identify this binding level as a level of parameters. */
753 declare_parm_level ()
755 current_binding_level->parm_flag = 1;
758 /* Identify this binding level as a level of a default exception handler. */
761 declare_implicit_exception ()
763 current_binding_level->parm_flag = 3;
766 /* Nonzero if current binding contour contains expressions
767 that might raise exceptions. */
772 return current_binding_level->have_exceptions;
776 declare_uninstantiated_type_level ()
778 current_binding_level->accept_any = 1;
782 uninstantiated_type_level_p ()
784 return current_binding_level->accept_any;
788 declare_pseudo_global_level ()
790 current_binding_level->pseudo_global = 1;
794 pseudo_global_level_p ()
796 return current_binding_level->pseudo_global;
800 set_class_shadows (shadows)
803 class_binding_level->class_shadowed = shadows;
806 /* Enter a new binding level.
807 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
808 not for that of tags. */
811 pushlevel (tag_transparent)
814 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
816 /* If this is the top level of a function,
817 just make sure that NAMED_LABELS is 0.
818 They should have been set to 0 at the end of the previous function. */
820 if (current_binding_level == global_binding_level)
821 my_friendly_assert (named_labels == NULL_TREE, 134);
823 /* Reuse or create a struct for this binding level. */
825 #if defined(DEBUG_CP_BINDING_LEVELS)
827 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
828 if (free_binding_level)
829 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
831 newlevel = free_binding_level;
832 free_binding_level = free_binding_level->level_chain;
836 /* Create a new `struct binding_level'. */
837 newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
839 push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
840 GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
841 keep_next_level_flag = 0;
845 pushlevel_temporary (tag_transparent)
848 pushlevel (tag_transparent);
849 current_binding_level->keep = 2;
852 /* Note we don't call push_momentary() here. Otherwise, it would cause
853 cleanups to be allocated on the momentary obstack, and they will be
854 overwritten by the next statement. */
856 expand_start_bindings (0);
859 /* Exit a binding level.
860 Pop the level off, and restore the state of the identifier-decl mappings
861 that were in effect when this level was entered.
863 If KEEP == 1, this level had explicit declarations, so
864 and create a "block" (a BLOCK node) for the level
865 to record its declarations and subblocks for symbol table output.
867 If KEEP == 2, this level's subblocks go to the front,
868 not the back of the current binding level. This happens,
869 for instance, when code for constructors and destructors
870 need to generate code at the end of a function which must
871 be moved up to the front of the function.
873 If FUNCTIONBODY is nonzero, this level is the body of a function,
874 so create a block as if KEEP were set and also clear out all
877 If REVERSE is nonzero, reverse the order of decls before putting
878 them into the BLOCK. */
881 poplevel (keep, reverse, functionbody)
887 /* The chain of decls was accumulated in reverse order.
888 Put it into forward order, just for cleanliness. */
890 int tmp = functionbody;
891 int implicit_try_block = current_binding_level->parm_flag == 3;
892 int real_functionbody = current_binding_level->keep == 2
893 ? ((functionbody = 0), tmp) : functionbody;
894 tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
895 tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
896 tree block = NULL_TREE;
898 int block_previously_created;
900 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
901 (HOST_WIDE_INT) current_binding_level->level_chain,
902 current_binding_level->parm_flag,
903 current_binding_level->keep,
904 current_binding_level->tag_transparent);
906 if (current_binding_level->keep == 1)
909 /* This warning is turned off because it causes warnings for
910 declarations like `extern struct foo *x'. */
912 /* Warn about incomplete structure types in this level. */
913 for (link = tags; link; link = TREE_CHAIN (link))
914 if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE)
916 tree type = TREE_VALUE (link);
918 switch (TREE_CODE (type))
921 errmsg = "`struct %s' incomplete in scope ending here";
924 errmsg = "`union %s' incomplete in scope ending here";
927 errmsg = "`enum %s' incomplete in scope ending here";
930 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
931 error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
933 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
934 error (errmsg, TYPE_NAME_STRING (type));
938 /* Get the decls in the order they were written.
939 Usually current_binding_level->names is in reverse order.
940 But parameter decls were previously put in forward order. */
943 current_binding_level->names
944 = decls = nreverse (current_binding_level->names);
946 decls = current_binding_level->names;
948 /* Output any nested inline functions within this block
949 if they weren't already output. */
951 for (decl = decls; decl; decl = TREE_CHAIN (decl))
952 if (TREE_CODE (decl) == FUNCTION_DECL
953 && ! TREE_ASM_WRITTEN (decl)
954 && DECL_INITIAL (decl) != NULL_TREE
955 && TREE_ADDRESSABLE (decl))
957 /* If this decl was copied from a file-scope decl
958 on account of a block-scope extern decl,
959 propagate TREE_ADDRESSABLE to the file-scope decl. */
960 if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
961 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
964 push_function_context ();
965 output_inline_function (decl);
966 pop_function_context ();
970 /* If there were any declarations or structure tags in that level,
971 or if this level is a function body,
972 create a BLOCK to record them for the life of this function. */
975 block_previously_created = (current_binding_level->this_block != NULL_TREE);
976 if (block_previously_created)
977 block = current_binding_level->this_block;
978 else if (keep == 1 || functionbody)
979 block = make_node (BLOCK);
980 if (block != NULL_TREE)
982 BLOCK_VARS (block) = decls;
983 BLOCK_TYPE_TAGS (block) = tags;
984 BLOCK_SUBBLOCKS (block) = subblocks;
985 /* If we created the block earlier on, and we are just diddling it now,
986 then it already should have a proper BLOCK_END_NOTE value associated
987 with it, so avoid trashing that. Otherwise, for a new block, install
988 a new BLOCK_END_NOTE value. */
989 if (! block_previously_created)
990 remember_end_note (block);
993 /* In each subblock, record that this is its superior. */
996 for (link = subblocks; link; link = TREE_CHAIN (link))
997 BLOCK_SUPERCONTEXT (link) = block;
999 /* Clear out the meanings of the local variables of this level. */
1001 for (link = decls; link; link = TREE_CHAIN (link))
1003 if (DECL_NAME (link) != NULL_TREE)
1005 /* If the ident. was used or addressed via a local extern decl,
1006 don't forget that fact. */
1007 if (DECL_EXTERNAL (link))
1009 if (TREE_USED (link))
1010 TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
1011 if (TREE_ADDRESSABLE (link))
1012 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1014 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
1018 /* Restore all name-meanings of the outer levels
1019 that were shadowed by this level. */
1021 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1022 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1023 for (link = current_binding_level->class_shadowed;
1024 link; link = TREE_CHAIN (link))
1025 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1026 for (link = current_binding_level->type_shadowed;
1027 link; link = TREE_CHAIN (link))
1028 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1030 /* If the level being exited is the top level of a function,
1031 check over all the labels. */
1035 /* If this is the top level block of a function,
1036 the vars are the function's parameters.
1037 Don't leave them in the BLOCK because they are
1038 found in the FUNCTION_DECL instead. */
1040 BLOCK_VARS (block) = 0;
1042 /* Clear out the definitions of all label names,
1043 since their scopes end here. */
1045 for (link = named_labels; link; link = TREE_CHAIN (link))
1047 register tree label = TREE_VALUE (link);
1049 if (DECL_INITIAL (label) == NULL_TREE)
1051 cp_error_at ("label `%D' used but not defined", label);
1052 /* Avoid crashing later. */
1053 define_label (input_filename, 1, DECL_NAME (label));
1055 else if (warn_unused && !TREE_USED (label))
1056 cp_warning_at ("label `%D' defined but not used", label);
1057 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
1059 /* Put the labels into the "variables" of the
1060 top-level block, so debugger can see them. */
1061 TREE_CHAIN (label) = BLOCK_VARS (block);
1062 BLOCK_VARS (block) = label;
1065 named_labels = NULL_TREE;
1068 /* Any uses of undefined labels now operate under constraints
1069 of next binding contour. */
1071 struct binding_level *level_chain;
1072 level_chain = current_binding_level->level_chain;
1076 for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
1077 if (TREE_TYPE (labels) == (tree)current_binding_level)
1079 TREE_TYPE (labels) = (tree)level_chain;
1080 TREE_PURPOSE (labels) = level_chain->names;
1085 tmp = current_binding_level->keep;
1087 pop_binding_level ();
1089 DECL_INITIAL (current_function_decl) = block;
1092 if (!block_previously_created)
1093 current_binding_level->blocks
1094 = chainon (current_binding_level->blocks, block);
1096 /* If we did not make a block for the level just exited,
1097 any blocks made for inner levels
1098 (since they cannot be recorded as subblocks in that level)
1099 must be carried forward so they will later become subblocks
1100 of something else. */
1104 current_binding_level->blocks
1105 = chainon (subblocks, current_binding_level->blocks);
1107 current_binding_level->blocks
1108 = chainon (current_binding_level->blocks, subblocks);
1111 /* Take care of compiler's internal binding structures. */
1112 if (tmp == 2 && !implicit_try_block)
1115 /* We did not call push_momentary for this
1116 binding contour, so there is nothing to pop. */
1119 expand_end_bindings (getdecls (), keep, 1);
1120 /* Each and every BLOCK node created here in `poplevel' is important
1121 (e.g. for proper debugging information) so if we created one
1122 earlier, mark it as "used". */
1124 TREE_USED (block) = 1;
1125 block = poplevel (keep, reverse, real_functionbody);
1128 /* Each and every BLOCK node created here in `poplevel' is important
1129 (e.g. for proper debugging information) so if we created one
1130 earlier, mark it as "used". */
1132 TREE_USED (block) = 1;
1136 /* Delete the node BLOCK from the current binding level.
1137 This is used for the block inside a stmt expr ({...})
1138 so that the block can be reinserted where appropriate. */
1141 delete_block (block)
1145 if (current_binding_level->blocks == block)
1146 current_binding_level->blocks = TREE_CHAIN (block);
1147 for (t = current_binding_level->blocks; t;)
1149 if (TREE_CHAIN (t) == block)
1150 TREE_CHAIN (t) = TREE_CHAIN (block);
1154 TREE_CHAIN (block) = NULL_TREE;
1155 /* Clear TREE_USED which is always set by poplevel.
1156 The flag is set again if insert_block is called. */
1157 TREE_USED (block) = 0;
1160 /* Insert BLOCK at the end of the list of subblocks of the
1161 current binding level. This is used when a BIND_EXPR is expanded,
1162 to handle the BLOCK node inside the BIND_EXPR. */
1165 insert_block (block)
1168 TREE_USED (block) = 1;
1169 current_binding_level->blocks
1170 = chainon (current_binding_level->blocks, block);
1173 /* Add BLOCK to the current list of blocks for this binding contour. */
1175 add_block_current_level (block)
1178 current_binding_level->blocks
1179 = chainon (current_binding_level->blocks, block);
1182 /* Set the BLOCK node for the innermost scope
1183 (the one we are currently in). */
1187 register tree block;
1189 current_binding_level->this_block = block;
1192 /* Do a pushlevel for class declarations. */
1196 register struct binding_level *newlevel;
1198 /* Reuse or create a struct for this binding level. */
1199 #if defined(DEBUG_CP_BINDING_LEVELS)
1201 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
1202 if (free_binding_level)
1203 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
1205 newlevel = free_binding_level;
1206 free_binding_level = free_binding_level->level_chain;
1210 /* Create a new `struct binding_level'. */
1211 newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
1214 #if defined(DEBUG_CP_BINDING_LEVELS)
1216 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1218 push_binding_level (newlevel, 0, 0);
1220 decl_stack = push_decl_level (decl_stack, &decl_obstack);
1221 class_binding_level = current_binding_level;
1222 class_binding_level->parm_flag = 2;
1223 /* We have just pushed into a new binding level. Now, fake out the rest
1224 of the compiler. Set the `current_binding_level' back to point to
1225 the most closely containing non-class binding level. */
1228 current_binding_level = current_binding_level->level_chain;
1230 while (current_binding_level->parm_flag == 2);
1233 /* ...and a poplevel for class declarations. */
1237 register struct binding_level *level = class_binding_level;
1238 tree block = NULL_TREE;
1241 my_friendly_assert (level != 0, 354);
1243 decl_stack = pop_stack_level (decl_stack);
1244 for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1245 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1246 /* If we're leaving a toplevel class, don't bother to do the setting
1247 of IDENTIFER_CLASS_VALUE to NULL_TREE, since first of all this slot
1248 shouldn't even be used when current_class_type isn't set, and second,
1249 if we don't touch it here, we're able to use the caching effect if the
1250 next time we're entering a class scope, it is the same class. */
1251 if (current_class_depth != 1)
1252 for (shadowed = level->class_shadowed;
1254 shadowed = TREE_CHAIN (shadowed))
1255 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1257 /* Remember to save what IDENTIFIER's were bound in this scope so we
1258 can recover from cache misses. */
1259 previous_class_values = class_binding_level->class_shadowed;
1260 for (shadowed = level->type_shadowed;
1262 shadowed = TREE_CHAIN (shadowed))
1263 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1265 GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
1266 (HOST_WIDE_INT) class_binding_level->level_chain,
1267 class_binding_level->parm_flag,
1268 class_binding_level->keep,
1269 class_binding_level->tag_transparent);
1271 if (class_binding_level->parm_flag != 2)
1272 class_binding_level = (struct binding_level *)0;
1274 /* Now, pop out of the the binding level which we created up in the
1275 `pushlevel_class' routine. */
1276 #if defined(DEBUG_CP_BINDING_LEVELS)
1278 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1280 pop_binding_level ();
1285 /* For debugging. */
1286 int no_print_functions = 0;
1287 int no_print_builtins = 0;
1290 print_binding_level (lvl)
1291 struct binding_level *lvl;
1295 fprintf (stderr, " blocks=");
1296 fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
1297 fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
1298 lvl->n_incomplete, lvl->parm_flag, lvl->keep);
1299 if (lvl->tag_transparent)
1300 fprintf (stderr, " tag-transparent");
1301 if (lvl->more_cleanups_ok)
1302 fprintf (stderr, " more-cleanups-ok");
1303 if (lvl->have_cleanups)
1304 fprintf (stderr, " have-cleanups");
1305 if (lvl->more_exceptions_ok)
1306 fprintf (stderr, " more-exceptions-ok");
1307 if (lvl->have_exceptions)
1308 fprintf (stderr, " have-exceptions");
1309 fprintf (stderr, "\n");
1312 fprintf (stderr, " names:\t");
1313 /* We can probably fit 3 names to a line? */
1314 for (t = lvl->names; t; t = TREE_CHAIN (t))
1316 if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL))
1318 if (no_print_builtins
1319 && (TREE_CODE(t) == TYPE_DECL)
1320 && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
1323 /* Function decls tend to have longer names. */
1324 if (TREE_CODE (t) == FUNCTION_DECL)
1331 fprintf (stderr, "\n\t");
1334 print_node_brief (stderr, "", t, 0);
1335 if (TREE_CODE (t) == ERROR_MARK)
1339 fprintf (stderr, "\n");
1343 fprintf (stderr, " tags:\t");
1345 for (t = lvl->tags; t; t = TREE_CHAIN (t))
1347 if (TREE_PURPOSE (t) == NULL_TREE)
1349 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1356 fprintf (stderr, "\n\t");
1359 if (TREE_PURPOSE (t) == NULL_TREE)
1361 print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
1362 fprintf (stderr, ">");
1364 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1365 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1368 print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
1369 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1370 fprintf (stderr, ">");
1374 fprintf (stderr, "\n");
1378 fprintf (stderr, " shadowed:");
1379 for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
1381 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1383 fprintf (stderr, "\n");
1385 if (lvl->class_shadowed)
1387 fprintf (stderr, " class-shadowed:");
1388 for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
1390 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1392 fprintf (stderr, "\n");
1394 if (lvl->type_shadowed)
1396 fprintf (stderr, " type-shadowed:");
1397 for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
1400 fprintf (stderr, "\n\t");
1401 print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
1403 print_node_brief (stderr, " ", TREE_VALUE (t), 0);
1405 fprintf (stderr, " (none)");
1406 fprintf (stderr, ">");
1408 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1411 fprintf (stderr, "\n");
1416 print_other_binding_stack (stack)
1417 struct binding_level *stack;
1419 struct binding_level *level;
1420 for (level = stack; level != global_binding_level; level = level->level_chain)
1422 fprintf (stderr, "binding level ");
1423 fprintf (stderr, HOST_PTR_PRINTF, level);
1424 fprintf (stderr, "\n");
1425 print_binding_level (level);
1430 print_binding_stack ()
1432 struct binding_level *b;
1433 fprintf (stderr, "current_binding_level=");
1434 fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
1435 fprintf (stderr, "\nclass_binding_level=");
1436 fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
1437 fprintf (stderr, "\nglobal_binding_level=");
1438 fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
1439 fprintf (stderr, "\n");
1440 if (class_binding_level)
1442 for (b = class_binding_level; b; b = b->level_chain)
1443 if (b == current_binding_level)
1446 b = class_binding_level;
1448 b = current_binding_level;
1451 b = current_binding_level;
1452 print_other_binding_stack (b);
1453 fprintf (stderr, "global:\n");
1454 print_binding_level (global_binding_level);
1457 /* Subroutines for reverting temporarily to top-level for instantiation
1458 of templates and such. We actually need to clear out the class- and
1459 local-value slots of all identifiers, so that only the global values
1460 are at all visible. Simply setting current_binding_level to the global
1461 scope isn't enough, because more binding levels may be pushed. */
1462 struct saved_scope {
1463 struct binding_level *old_binding_level;
1465 struct saved_scope *prev;
1466 tree class_name, class_type, class_decl, function_decl;
1467 struct binding_level *class_bindings;
1468 tree previous_class_type;
1469 tree *lang_base, *lang_stack, lang_name;
1473 static struct saved_scope *current_saved_scope;
1474 extern tree prev_class_type;
1477 push_to_top_level ()
1479 extern int current_lang_stacksize;
1480 struct saved_scope *s =
1481 (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
1482 struct binding_level *b = current_binding_level;
1483 tree old_bindings = NULL_TREE;
1485 /* Have to include global_binding_level, because class-level decls
1486 aren't listed anywhere useful. */
1487 for (; b; b = b->level_chain)
1491 if (b == global_binding_level)
1494 for (t = b->names; t; t = TREE_CHAIN (t))
1496 tree binding, t1, t2 = t;
1497 tree id = DECL_ASSEMBLER_NAME (t2);
1500 || (!IDENTIFIER_LOCAL_VALUE (id)
1501 && !IDENTIFIER_CLASS_VALUE (id)))
1504 for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
1505 if (TREE_VEC_ELT (t1, 0) == id)
1508 binding = make_tree_vec (4);
1511 my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
1512 TREE_VEC_ELT (binding, 0) = id;
1513 TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
1514 TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
1515 TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
1516 IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
1517 IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
1519 TREE_CHAIN (binding) = old_bindings;
1520 old_bindings = binding;
1524 /* Unwind type-value slots back to top level. */
1525 for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
1526 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
1528 /* Clear out class-level bindings cache. */
1529 if (current_binding_level == global_binding_level
1530 && previous_class_type != NULL_TREE)
1533 previous_class_type = NULL_TREE;
1536 s->old_binding_level = current_binding_level;
1537 current_binding_level = global_binding_level;
1539 s->class_name = current_class_name;
1540 s->class_type = current_class_type;
1541 s->class_decl = current_class_decl;
1542 s->function_decl = current_function_decl;
1543 s->class_bindings = class_binding_level;
1544 s->previous_class_type = previous_class_type;
1545 s->lang_stack = current_lang_stack;
1546 s->lang_base = current_lang_base;
1547 s->lang_stacksize = current_lang_stacksize;
1548 s->lang_name = current_lang_name;
1549 s->named_labels = named_labels;
1550 current_class_name = current_class_type = current_class_decl = NULL_TREE;
1551 current_function_decl = NULL_TREE;
1552 class_binding_level = (struct binding_level *)0;
1553 previous_class_type = NULL_TREE;
1554 current_lang_stacksize = 10;
1555 current_lang_stack = current_lang_base
1556 = (tree *) xmalloc (current_lang_stacksize * sizeof (tree));
1557 current_lang_name = lang_name_cplusplus;
1558 strict_prototype = strict_prototypes_lang_cplusplus;
1559 named_labels = NULL_TREE;
1561 s->prev = current_saved_scope;
1562 s->old_bindings = old_bindings;
1563 current_saved_scope = s;
1567 pop_from_top_level ()
1569 extern int current_lang_stacksize;
1570 struct saved_scope *s = current_saved_scope;
1573 if (previous_class_type)
1574 previous_class_type = NULL_TREE;
1576 current_binding_level = s->old_binding_level;
1577 current_saved_scope = s->prev;
1578 for (t = s->old_bindings; t; t = TREE_CHAIN (t))
1580 tree id = TREE_VEC_ELT (t, 0);
1583 IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
1584 IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
1585 IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
1588 current_class_name = s->class_name;
1589 current_class_type = s->class_type;
1590 current_class_decl = s->class_decl;
1591 if (current_class_type)
1592 C_C_D = CLASSTYPE_INST_VAR (current_class_type);
1595 current_function_decl = s->function_decl;
1596 class_binding_level = s->class_bindings;
1597 previous_class_type = s->previous_class_type;
1598 free (current_lang_base);
1599 current_lang_base = s->lang_base;
1600 current_lang_stack = s->lang_stack;
1601 current_lang_name = s->lang_name;
1602 current_lang_stacksize = s->lang_stacksize;
1603 if (current_lang_name == lang_name_cplusplus)
1604 strict_prototype = strict_prototypes_lang_cplusplus;
1605 else if (current_lang_name == lang_name_c)
1606 strict_prototype = strict_prototypes_lang_c;
1607 named_labels = s->named_labels;
1612 /* Push a definition of struct, union or enum tag "name".
1613 into binding_level "b". "type" should be the type node,
1614 We assume that the tag "name" is not already defined.
1616 Note that the definition may really be just a forward reference.
1617 In that case, the TYPE_SIZE will be a NULL_TREE.
1619 C++ gratuitously puts all these tags in the name space. */
1621 /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
1622 record the shadowed value for this binding contour. TYPE is
1623 the type that ID maps to. */
1626 set_identifier_type_value_with_scope (id, type, b)
1629 struct binding_level *b;
1631 if (b != global_binding_level)
1633 tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
1635 = tree_cons (id, old_type_value, b->type_shadowed);
1637 SET_IDENTIFIER_TYPE_VALUE (id, type);
1640 /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
1643 set_identifier_type_value (id, type)
1647 set_identifier_type_value_with_scope (id, type, inner_binding_level);
1650 /* Subroutine "set_nested_typename" builds the nested-typename of
1651 the type decl in question. (Argument CLASSNAME can actually be
1652 a function as well, if that's the smallest containing scope.) */
1655 set_nested_typename (decl, classname, name, type)
1656 tree decl, classname, name, type;
1658 my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
1659 if (classname != NULL_TREE)
1662 my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
1663 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
1664 buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
1665 + IDENTIFIER_LENGTH (name));
1666 sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
1667 IDENTIFIER_POINTER (name));
1668 DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
1670 /* This is a special usage of IDENTIFIER_TYPE_VALUE which have no
1671 correspondence in any binding_level. This is ok since the
1672 DECL_NESTED_TYPENAME is just a convenience identifier whose
1673 IDENTIFIER_TYPE_VALUE will remain constant from now on. */
1674 SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type);
1677 DECL_NESTED_TYPENAME (decl) = name;
1680 /* Pop off extraneous binding levels left over due to syntax errors. */
1684 #ifdef DEBUG_CP_BINDING_LEVELS
1685 fprintf (stderr, "XXX entering pop_everything ()\n");
1687 while (current_binding_level != global_binding_level
1688 && ! current_binding_level->pseudo_global)
1690 if (class_binding_level)
1691 pop_nested_class (1);
1695 #ifdef DEBUG_CP_BINDING_LEVELS
1696 fprintf (stderr, "XXX leaving pop_everything ()\n");
1700 #if 0 /* not yet, should get fixed properly later */
1701 /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
1702 Other routines shouldn't use build_decl directly; they'll produce
1703 incorrect results with `-g' unless they duplicate this code.
1705 This is currently needed mainly for dbxout.c, but we can make
1706 use of it in method.c later as well. */
1708 make_type_decl (name, type)
1712 decl = build_decl (TYPE_DECL, name, type);
1713 if (TYPE_NAME (type) == name)
1714 /* Class/union/enum definition, or a redundant typedef for same. */
1716 id = get_identifier (build_overload_name (type, 1, 1));
1717 DECL_ASSEMBLER_NAME (decl) = id;
1719 else if (TYPE_NAME (type) != NULL_TREE)
1720 /* Explicit typedef, or implicit typedef for template expansion. */
1721 DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
1724 /* XXX: Typedef for unnamed struct; some other situations.
1725 TYPE_NAME is null; what's right here? */
1731 /* Push a tag name NAME for struct/class/union/enum type TYPE.
1732 Normally put into into the inner-most non-tag-tranparent scope,
1733 but if GLOBALIZE is true, put it in the inner-most non-class scope.
1734 The latter is needed for implicit declarations. */
1737 pushtag (name, type, globalize)
1741 register struct binding_level *b;
1744 b = inner_binding_level;
1745 while (b->tag_transparent
1746 || (globalize && b->parm_flag == 2))
1749 if (b == global_binding_level)
1750 b->tags = perm_tree_cons (name, type, b->tags);
1752 b->tags = saveable_tree_cons (name, type, b->tags);
1756 t_context = type ? TYPE_CONTEXT(type) : NULL_TREE;
1757 if (!t_context && !globalize)
1758 t_context = current_class_type;
1760 /* Record the identifier as the type's name if it has none. */
1761 if (TYPE_NAME (type) == NULL_TREE)
1762 TYPE_NAME (type) = name;
1764 /* Do C++ gratuitous typedefing. */
1765 if (IDENTIFIER_TYPE_VALUE (name) != type
1766 && (TREE_CODE (type) != RECORD_TYPE
1767 || b->parm_flag != 2
1768 || !CLASSTYPE_DECLARED_EXCEPTION (type)))
1773 if (b->parm_flag != 2
1774 || TYPE_SIZE (current_class_type) != NULL_TREE)
1776 if (current_lang_name == lang_name_cplusplus)
1777 d = lookup_nested_type (type,
1778 t_context ? TYPE_NAME (t_context) : NULL_TREE);
1785 #if 0 /* not yet, should get fixed properly later */
1786 d = make_type_decl (name, type);
1788 d = build_decl (TYPE_DECL, name, type);
1790 #ifdef DWARF_DEBUGGING_INFO
1791 if (write_symbols == DWARF_DEBUG)
1793 /* Mark the TYPE_DECL node we created just above as an
1794 gratuitous one. We need to do this so that dwarfout.c
1795 will understand that it is not supposed to output a
1796 TAG_typedef DIE for it. */
1797 DECL_IGNORED_P (d) = 1;
1799 #endif /* DWARF_DEBUGGING_INFO */
1800 set_identifier_type_value_with_scope (name, type, b);
1805 /* If it is anonymous, then we are called from pushdecl,
1806 and we don't want to infinitely recurse. Also, if the
1807 name is already in scope, we don't want to push it
1808 again--pushdecl is only for pushing new decls. */
1809 if (! ANON_AGGRNAME_P (name)
1811 && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
1812 || lookup_name (name, 1) != TYPE_NAME (type)))
1814 if (b->parm_flag == 2)
1815 d = pushdecl_class_level (d);
1817 d = pushdecl_with_scope (d, b);
1822 /* Make nested declarations go into class-level scope. */
1824 d = build_lang_field_decl (TYPE_DECL, name, type);
1825 #ifdef DWARF_DEBUGGING_INFO
1826 if (write_symbols == DWARF_DEBUG)
1828 /* Mark the TYPE_DECL node we created just above as an
1829 gratuitous one. We need to do this so that dwarfout.c
1830 will understand that it is not supposed to output a
1831 TAG_typedef DIE for it. */
1832 DECL_IGNORED_P (d) = 1;
1834 #endif /* DWARF_DEBUGGING_INFO */
1835 /* Make sure we're in this type's scope when we push the
1836 decl for a template, otherwise class_binding_level will
1837 be NULL and we'll end up dying inside of
1838 push_class_level_binding. */
1839 if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
1840 pushclass (type, 0);
1841 d = pushdecl_class_level (d);
1842 if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
1845 if (write_symbols != DWARF_DEBUG)
1847 if (ANON_AGGRNAME_P (name))
1848 DECL_IGNORED_P (d) = 1;
1850 TYPE_NAME (type) = d;
1852 if ((t_context == NULL_TREE
1853 && current_function_decl == NULL_TREE)
1854 || current_lang_name != lang_name_cplusplus)
1855 /* Non-nested class. */
1856 DECL_NESTED_TYPENAME (d) = name;
1857 else if (current_function_decl != NULL_TREE)
1859 /* Function-nested class. */
1860 set_nested_typename (d,
1861 DECL_ASSEMBLER_NAME (current_function_decl), name, type);
1862 /* This builds the links for classes nested in fn scope. */
1863 DECL_CONTEXT (d) = current_function_decl;
1865 /* else if (TYPE_SIZE (current_class_type) == NULL_TREE)
1867 else if (t_context && TREE_CODE (t_context) == RECORD_TYPE)
1869 /* Class-nested class. */
1870 set_nested_typename (d,
1871 DECL_NESTED_TYPENAME (TYPE_NAME (t_context)), name, type);
1872 /* This builds the links for classes nested in type scope. */
1873 DECL_CONTEXT (d) = t_context;
1874 DECL_CLASS_CONTEXT (d) = t_context;
1876 TYPE_CONTEXT (type) = DECL_CONTEXT (d);
1878 DECL_ASSEMBLER_NAME (d)
1879 = get_identifier (build_overload_name (type, 1, 1));
1881 if (b->parm_flag == 2)
1883 TREE_NONLOCAL_FLAG (type) = 1;
1884 if (TYPE_SIZE (current_class_type) == NULL_TREE)
1885 CLASSTYPE_TAGS (current_class_type) = b->tags;
1889 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1890 /* Use the canonical TYPE_DECL for this node. */
1891 TYPE_STUB_DECL (type) = TYPE_NAME (type);
1894 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
1895 will be the tagged type we just added to the current
1896 binding level. This fake NULL-named TYPE_DECL node helps
1897 dwarfout.c to know when it needs to output a
1898 representation of a tagged type, and it also gives us a
1899 convenient place to record the "scope start" address for
1902 #if 0 /* not yet, should get fixed properly later */
1903 tree d = make_type_decl (NULL_TREE, type);
1905 tree d = build_decl (TYPE_DECL, NULL_TREE, type);
1907 TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
1911 /* Counter used to create anonymous type names. */
1912 static int anon_cnt = 0;
1914 /* Return an IDENTIFIER which can be used as a name for
1915 anonymous structs and unions. */
1921 sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
1922 return get_identifier (buf);
1925 /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
1926 This keeps dbxout from getting confused. */
1930 register struct binding_level *b;
1932 static int last_cnt = 0;
1934 /* Fast out if no new anon names were declared. */
1935 if (last_cnt == anon_cnt)
1938 b = current_binding_level;
1939 while (b->tag_transparent)
1944 /* A NULL purpose means we have already processed all tags
1945 from here to the end of the list. */
1946 if (TREE_PURPOSE (tags) == NULL_TREE)
1948 if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
1949 TREE_PURPOSE (tags) = NULL_TREE;
1950 tags = TREE_CHAIN (tags);
1952 last_cnt = anon_cnt;
1955 /* Subroutine of duplicate_decls: return truthvalue of whether
1956 or not types of these decls match.
1958 For C++, we must compare the parameter list so that `int' can match
1959 `int&' in a parameter position, but `int&' is not confused with
1962 decls_match (newdecl, olddecl)
1963 tree newdecl, olddecl;
1967 if (TREE_CODE (newdecl) == FUNCTION_DECL && TREE_CODE (olddecl) == FUNCTION_DECL)
1969 tree f1 = TREE_TYPE (newdecl);
1970 tree f2 = TREE_TYPE (olddecl);
1971 tree p1 = TYPE_ARG_TYPES (f1);
1972 tree p2 = TYPE_ARG_TYPES (f2);
1974 /* When we parse a static member function definition,
1975 we put together a FUNCTION_DECL which thinks its type
1976 is METHOD_TYPE. Change that to FUNCTION_TYPE, and
1978 if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
1979 revert_static_member_fn (&f1, &newdecl, &p1);
1980 else if (TREE_CODE (f2) == METHOD_TYPE
1981 && DECL_STATIC_FUNCTION_P (newdecl))
1982 revert_static_member_fn (&f2, &olddecl, &p2);
1984 /* Here we must take care of the case where new default
1985 parameters are specified. Also, warn if an old
1986 declaration becomes ambiguous because default
1987 parameters may cause the two to be ambiguous. */
1988 if (TREE_CODE (f1) != TREE_CODE (f2))
1990 if (TREE_CODE (f1) == OFFSET_TYPE)
1991 cp_compiler_error ("`%D' redeclared as member function", newdecl);
1993 cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
1997 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (f1)),
1998 TYPE_MAIN_VARIANT (TREE_TYPE (f2)), 2))
2000 if (DECL_LANGUAGE (olddecl) == lang_c
2001 && ! strict_prototypes_lang_c
2003 types_match = self_promoting_args_p (p1);
2005 types_match = compparms (p1, p2, 1);
2010 else if (TREE_CODE (newdecl) == TEMPLATE_DECL
2011 && TREE_CODE (olddecl) == TEMPLATE_DECL)
2013 tree newargs = DECL_TEMPLATE_PARMS (newdecl);
2014 tree oldargs = DECL_TEMPLATE_PARMS (olddecl);
2015 int i, len = TREE_VEC_LENGTH (newargs);
2017 if (TREE_VEC_LENGTH (oldargs) != len)
2020 for (i = 0; i < len; i++)
2022 tree newarg = TREE_VEC_ELT (newargs, i);
2023 tree oldarg = TREE_VEC_ELT (oldargs, i);
2024 if (TREE_CODE (newarg) != TREE_CODE (oldarg))
2026 else if (TREE_CODE (newarg) == IDENTIFIER_NODE)
2028 else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1))
2032 if (DECL_TEMPLATE_IS_CLASS (newdecl)
2033 != DECL_TEMPLATE_IS_CLASS (olddecl))
2035 else if (DECL_TEMPLATE_IS_CLASS (newdecl))
2038 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
2039 DECL_TEMPLATE_RESULT (newdecl));
2043 if (TREE_TYPE (newdecl) == error_mark_node)
2044 types_match = TREE_TYPE (olddecl) == error_mark_node;
2045 else if (TREE_TYPE (olddecl) == NULL_TREE)
2046 types_match = TREE_TYPE (newdecl) == NULL_TREE;
2048 types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
2054 /* If NEWDECL is `static' and an `extern' was seen previously,
2055 warn about it. (OLDDECL may be NULL_TREE; NAME contains
2056 information about previous usage as an `extern'.)
2058 Note that this does not apply to the C++ case of declaring
2059 a variable `extern const' and then later `const'.
2061 Don't complain if -traditional, since traditional compilers
2064 Don't complain about built-in functions, since they are beyond
2065 the user's control. */
2068 warn_extern_redeclared_static (newdecl, olddecl)
2069 tree newdecl, olddecl;
2073 static char *explicit_extern_static_warning
2074 = "`%D' was declared `extern' and later `static'";
2075 static char *implicit_extern_static_warning
2076 = "`%D' was declared implicitly `extern' and later `static'";
2078 if (flag_traditional
2079 || TREE_CODE (newdecl) == TYPE_DECL
2080 || (! warn_extern_inline
2081 && DECL_INLINE (newdecl)))
2084 name = DECL_ASSEMBLER_NAME (newdecl);
2085 if (TREE_PUBLIC (name) && ! TREE_PUBLIC (newdecl))
2087 /* It's okay to redeclare an ANSI built-in function as static,
2088 or to declare a non-ANSI built-in function as anything. */
2089 if (! (TREE_CODE (newdecl) == FUNCTION_DECL
2090 && olddecl != NULL_TREE
2091 && TREE_CODE (olddecl) == FUNCTION_DECL
2092 && (DECL_BUILT_IN (olddecl)
2093 || DECL_BUILT_IN_NONANSI (olddecl))))
2095 cp_warning (IDENTIFIER_IMPLICIT_DECL (name)
2096 ? implicit_extern_static_warning
2097 : explicit_extern_static_warning, newdecl);
2098 if (olddecl != NULL_TREE)
2099 cp_warning_at ("previous declaration of `%D'", olddecl);
2104 /* Handle when a new declaration NEWDECL has the same name as an old
2105 one OLDDECL in the same binding contour. Prints an error message
2108 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
2109 Otherwise, return 0. */
2112 duplicate_decls (newdecl, olddecl)
2113 register tree newdecl, olddecl;
2115 extern struct obstack permanent_obstack;
2116 unsigned olddecl_uid = DECL_UID (olddecl);
2117 int olddecl_friend = 0, types_match = 0;
2118 int new_defines_function;
2119 tree previous_c_decl = NULL_TREE;
2121 types_match = decls_match (newdecl, olddecl);
2123 if (TREE_CODE (olddecl) != TREE_LIST)
2124 olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
2126 /* If either the type of the new decl or the type of the old decl is an
2127 error_mark_node, then that implies that we have already issued an
2128 error (earlier) for some bogus type specification, and in that case,
2129 it is rather pointless to harass the user with yet more error message
2130 about the same declaration, so well just pretent the types match here. */
2131 if ((TREE_TYPE (newdecl)
2132 && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
2133 || (TREE_TYPE (olddecl)
2134 && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
2137 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2139 if ((TREE_CODE (newdecl) == FUNCTION_DECL
2140 && TREE_CODE (olddecl) == TEMPLATE_DECL
2141 && ! DECL_TEMPLATE_IS_CLASS (olddecl))
2142 || (TREE_CODE (olddecl) == FUNCTION_DECL
2143 && TREE_CODE (newdecl) == TEMPLATE_DECL
2144 && ! DECL_TEMPLATE_IS_CLASS (newdecl)))
2147 cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
2148 if (TREE_CODE (olddecl) == TREE_LIST)
2149 olddecl = TREE_VALUE (olddecl);
2150 cp_error_at ("previous declaration of `%#D'", olddecl);
2152 /* New decl is completely inconsistent with the old one =>
2153 tell caller to replace the old one. */
2158 if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
2159 && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
2160 /* If -traditional, avoid error for redeclaring fcn
2161 after implicit decl. */
2163 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2164 && (DECL_BUILT_IN (olddecl)
2165 || DECL_BUILT_IN_NONANSI (olddecl))
2166 && DECL_ASSEMBLER_NAME (newdecl) == DECL_ASSEMBLER_NAME (olddecl))
2168 /* If you declare a built-in or predefined function name as static,
2169 the old definition is overridden,
2170 but optionally warn this was a bad choice of name. */
2171 if (! TREE_PUBLIC (newdecl))
2174 cp_warning ("shadowing %s function `%#D'",
2175 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
2177 /* Discard the old built-in function. */
2180 /* Likewise, if the built-in is not ansi, then programs can
2181 override it even globally without an error. */
2182 else if (! DECL_BUILT_IN (olddecl))
2183 cp_warning ("library function `%#D' declared as non-function",
2188 cp_warning ("declaration of `%#D'", newdecl);
2189 cp_warning ("conflicts with built-in declaration `%#D'",
2194 else if (!types_match)
2196 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2198 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2200 if (DECL_LANGUAGE (newdecl) == lang_c
2201 && DECL_LANGUAGE (olddecl) == lang_c)
2203 cp_error ("declaration of C function `%#D' conflicts with",
2205 cp_error_at ("previous declaration `%#D' here", olddecl);
2211 /* Already complained about this, so don't do so again. */
2212 if (current_class_type == NULL_TREE
2213 || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
2215 /* Since we're doing this before finish_struct can set the
2216 line number on NEWDECL, we just do a regular error here. */
2217 if (DECL_SOURCE_LINE (newdecl) == 0)
2218 cp_error ("conflicting types for `%#D'", newdecl);
2220 cp_error_at ("conflicting types for `%#D'", newdecl);
2221 cp_error_at ("previous declaration as `%#D'", olddecl);
2226 char *errmsg = redeclaration_error_message (newdecl, olddecl);
2229 cp_error (errmsg, newdecl);
2230 if (DECL_NAME (olddecl) != NULL_TREE)
2231 cp_error_at ((DECL_INITIAL (olddecl)
2232 && current_binding_level == global_binding_level)
2233 ? "`%#D' previously defined here"
2234 : "`%#D' previously declared here", olddecl);
2236 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2237 && DECL_INITIAL (olddecl) != NULL_TREE
2238 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
2239 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
2241 /* Prototype decl follows defn w/o prototype. */
2242 cp_warning_at ("prototype for `%#D'", newdecl);
2243 cp_warning_at ("follows non-prototype definition here", olddecl);
2245 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2246 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2248 /* extern "C" int foo ();
2249 int foo () { bar (); }
2251 if (current_lang_stack == current_lang_base)
2253 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2254 if (TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
2255 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) == void_list_node)
2256 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
2260 cp_error_at ("previous declaration of `%#D' with %L linkage",
2261 olddecl, DECL_LANGUAGE (olddecl));
2262 cp_error ("conflicts with new declaration with %L linkage",
2263 DECL_LANGUAGE (newdecl));
2267 /* These bits are logically part of the type. */
2269 && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
2270 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
2271 cp_error_at ("type qualifiers for `%D' conflict with previous decl", newdecl);
2274 /* If new decl is `static' and an `extern' was seen previously,
2276 warn_extern_redeclared_static (newdecl, olddecl);
2278 /* We have committed to returning 1 at this point. */
2279 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2281 /* Now that functions must hold information normally held
2282 by field decls, there is extra work to do so that
2283 declaration information does not get destroyed during
2285 if (DECL_VINDEX (olddecl))
2286 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2287 if (DECL_CONTEXT (olddecl))
2288 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2289 if (DECL_CLASS_CONTEXT (olddecl))
2290 DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
2291 if (DECL_CHAIN (newdecl) == NULL_TREE)
2292 DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2293 if (DECL_NEXT_METHOD (newdecl) == NULL_TREE)
2294 DECL_NEXT_METHOD (newdecl) = DECL_NEXT_METHOD (olddecl);
2295 if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
2296 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
2299 /* Deal with C++: must preserve virtual function table size. */
2300 if (TREE_CODE (olddecl) == TYPE_DECL)
2302 register tree newtype = TREE_TYPE (newdecl);
2303 register tree oldtype = TREE_TYPE (olddecl);
2305 if (newtype != error_mark_node && oldtype != error_mark_node
2306 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2308 CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
2309 CLASSTYPE_FRIEND_CLASSES (newtype)
2310 = CLASSTYPE_FRIEND_CLASSES (oldtype);
2312 /* why assert here? Just because debugging information is
2314 /* it happens on something like:
2315 typedef struct Thing {
2321 my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl), 139);
2325 /* Special handling ensues if new decl is a function definition. */
2326 new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
2327 && DECL_INITIAL (newdecl) != NULL_TREE);
2329 /* Optionally warn about more than one declaration for the same name,
2330 but don't warn about a function declaration followed by a definition. */
2331 if (warn_redundant_decls
2332 && DECL_SOURCE_LINE (olddecl) != 0
2333 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2334 /* Don't warn about extern decl followed by (tentative) definition. */
2335 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
2337 cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
2338 cp_warning ("previous declaration of `%D'", olddecl);
2341 /* Copy all the DECL_... slots specified in the new decl
2342 except for any that we copy here from the old type. */
2346 /* Automatically handles default parameters. */
2347 tree oldtype = TREE_TYPE (olddecl);
2348 /* Merge the data types specified in the two decls. */
2349 tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2351 if (TREE_CODE (newdecl) == VAR_DECL)
2352 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2353 /* Do this after calling `common_type' so that default
2354 parameters don't confuse us. */
2355 else if (TREE_CODE (newdecl) == FUNCTION_DECL
2356 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
2357 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
2359 tree ctype = NULL_TREE;
2360 ctype = DECL_CLASS_CONTEXT (newdecl);
2361 TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype,
2362 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
2363 TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype,
2364 TYPE_RAISES_EXCEPTIONS (oldtype));
2366 if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE(olddecl), 0))
2368 cp_error ("declaration of `%D' raises different exceptions...", newdecl);
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);
2405 /* Keep the old rtl since we can safely use it, unless it's the
2406 call to abort() used for abstract virtuals. */
2407 if ((DECL_LANG_SPECIFIC (olddecl)
2408 && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
2409 || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
2410 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2412 /* If cannot merge, then use the new type and qualifiers,
2413 and don't preserve the old rtl. */
2416 /* Clean out any memory we had of the old declaration. */
2417 tree oldstatic = value_member (olddecl, static_aggregates);
2419 TREE_VALUE (oldstatic) = error_mark_node;
2421 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2422 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2423 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2424 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2427 /* Merge the storage class information. */
2428 if (DECL_EXTERNAL (newdecl))
2430 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
2431 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
2433 /* For functions, static overrides non-static. */
2434 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2436 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
2437 /* This is since we don't automatically
2438 copy the attributes of NEWDECL into OLDDECL. */
2439 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2440 /* If this clears `static', clear it in the identifier too. */
2441 if (! TREE_PUBLIC (olddecl))
2442 TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl)) = 0;
2445 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2449 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
2450 /* A `const' which was not declared `extern' and is
2451 in static storage is invisible. */
2452 if (TREE_CODE (newdecl) == VAR_DECL
2453 && TREE_READONLY (newdecl) && TREE_STATIC (newdecl)
2454 && ! DECL_THIS_EXTERN (newdecl))
2455 TREE_PUBLIC (newdecl) = 0;
2456 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2459 /* If either decl says `inline', this fn is inline,
2460 unless its definition was passed already. */
2461 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
2462 DECL_INLINE (olddecl) = 1;
2463 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
2465 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2467 if (new_defines_function)
2468 /* If defining a function declared with other language
2469 linkage, use the previously declared language linkage. */
2470 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2473 /* If redeclaring a builtin function, and not a definition,
2474 it stays built in. */
2475 if (DECL_BUILT_IN (olddecl))
2477 DECL_BUILT_IN (newdecl) = 1;
2478 DECL_SET_FUNCTION_CODE (newdecl, DECL_FUNCTION_CODE (olddecl));
2479 /* If we're keeping the built-in definition, keep the rtl,
2480 regardless of declaration matches. */
2481 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2484 DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2486 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2487 if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)))
2488 /* Previously saved insns go together with
2489 the function's previous definition. */
2490 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2491 /* Don't clear out the arguments if we're redefining a function. */
2492 if (DECL_ARGUMENTS (olddecl))
2493 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2497 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2499 if (DECL_TEMPLATE_INFO (olddecl)->length)
2500 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
2501 DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl);
2502 DECL_TEMPLATE_INSTANTIATIONS (newdecl)
2503 = DECL_TEMPLATE_INSTANTIATIONS (olddecl);
2506 /* Now preserve various other info from the definition. */
2507 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2508 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2509 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2511 /* Don't really know how much of the language-specific
2512 values we should copy from old to new. */
2513 if (DECL_LANG_SPECIFIC (olddecl))
2515 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
2516 DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
2519 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2522 struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
2523 struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
2525 function_size = sizeof (struct tree_decl);
2527 bcopy ((char *) newdecl + sizeof (struct tree_common),
2528 (char *) olddecl + sizeof (struct tree_common),
2529 function_size - sizeof (struct tree_common));
2531 /* Can we safely free the storage used by newdecl? */
2533 #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
2534 & ~ obstack_alignment_mask (&permanent_obstack))
2536 if ((char *)newdecl + ROUND (function_size)
2537 + ROUND (sizeof (struct lang_decl))
2538 == obstack_next_free (&permanent_obstack))
2540 DECL_MAIN_VARIANT (newdecl) = olddecl;
2541 DECL_LANG_SPECIFIC (olddecl) = ol;
2542 bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
2544 obstack_free (&permanent_obstack, newdecl);
2546 else if (LANG_DECL_PERMANENT (ol))
2548 if (DECL_MAIN_VARIANT (olddecl) == olddecl)
2550 /* Save these lang_decls that would otherwise be lost. */
2551 extern tree free_lang_decl_chain;
2552 tree free_lang_decl = (tree) ol;
2553 TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
2554 free_lang_decl_chain = free_lang_decl;
2564 bcopy ((char *) newdecl + sizeof (struct tree_common),
2565 (char *) olddecl + sizeof (struct tree_common),
2566 sizeof (struct tree_decl) - sizeof (struct tree_common)
2567 + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
2570 DECL_UID (olddecl) = olddecl_uid;
2572 DECL_FRIEND_P (olddecl) = 1;
2577 /* Record a decl-node X as belonging to the current lexical scope.
2578 Check for errors (such as an incompatible declaration for the same
2579 name already seen in the same scope).
2581 Returns either X or an old decl for the same name.
2582 If an old decl is returned, it may have been smashed
2583 to agree with what X says. */
2590 #if 0 /* not yet, should get fixed properly later */
2593 register tree name = DECL_ASSEMBLER_NAME (x);
2595 register struct binding_level *b = current_binding_level;
2598 static int nglobals; int len;
2600 len = list_length (global_binding_level->names);
2602 my_friendly_abort (8);
2603 else if (len > nglobals)
2607 /* Don't change DECL_CONTEXT of virtual methods. */
2608 if (x != current_function_decl
2609 && (TREE_CODE (x) != FUNCTION_DECL
2610 || !DECL_VIRTUAL_P (x))
2611 && ! DECL_CONTEXT (x))
2612 DECL_CONTEXT (x) = current_function_decl;
2613 /* A local declaration for a function doesn't constitute nesting. */
2614 if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
2615 DECL_CONTEXT (x) = 0;
2617 #if 0 /* not yet, should get fixed properly later */
2618 /* For functions and class static data, we currently look up the encoded
2619 form of the name. For types, we want the real name. The former will
2620 probably be changed soon, according to MDT. */
2621 if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
2622 name = DECL_ASSEMBLER_NAME (x);
2624 name = DECL_NAME (x);
2626 /* Type are looked up using the DECL_NAME, as that is what the rest of the
2627 compiler wants to use. */
2628 if (TREE_CODE (x) == TYPE_DECL)
2629 name = DECL_NAME (x);
2637 t = lookup_name_current_level (name);
2638 if (t == error_mark_node)
2640 /* error_mark_node is 0 for a while during initialization! */
2642 cp_error_at ("`%#D' used prior to declaration", x);
2645 else if (t != NULL_TREE)
2647 if (TREE_CODE (t) == PARM_DECL)
2649 if (DECL_CONTEXT (t) == NULL_TREE)
2650 fatal ("parse errors have confused me too much");
2652 file = DECL_SOURCE_FILE (t);
2653 line = DECL_SOURCE_LINE (t);
2655 if (TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c
2656 && is_overloaded_fn (t))
2657 /* don't do anything just yet */;
2658 else if (TREE_CODE (t) != TREE_CODE (x))
2660 if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (x) == TYPE_DECL)
2662 /* We do nothing special here, because C++ does such nasty
2663 things with TYPE_DECLs. Instead, just let the TYPE_DECL
2664 get shadowed, and know that if we need to find a TYPE_DECL
2665 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
2666 slot of the identifier. */
2669 else if (duplicate_decls (x, t))
2672 else if (duplicate_decls (x, t))
2675 /* This is turned off until I have time to do it right (bpk). */
2677 /* Also warn if they did a prototype with `static' on it, but
2678 then later left the `static' off. */
2679 if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
2681 if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
2686 cp_warning ("`static' missing from declaration of `%D'", t);
2687 warning_with_file_and_line (file, line,
2688 "previous declaration of `%s'",
2689 decl_as_string (t, 0));
2692 /* Now fix things so it'll do what they expect. */
2693 if (current_function_decl)
2694 TREE_PUBLIC (current_function_decl) = 0;
2696 /* Due to interference in memory reclamation (X may be
2697 obstack-deallocated at this point), we must guard against
2698 one really special case. [jason: This should be handled
2699 by start_function] */
2700 if (current_function_decl == x)
2701 current_function_decl = t;
2708 if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x))
2710 t = push_overloaded_decl (x, 1);
2711 if (t != x || DECL_LANGUAGE (x) == lang_c)
2714 else if (TREE_CODE (x) == TEMPLATE_DECL && ! DECL_TEMPLATE_IS_CLASS (x))
2715 return push_overloaded_decl (x, 0);
2717 /* If declaring a type as a typedef, and the type has no known
2718 typedef name, install this TYPE_DECL as its typedef name. */
2719 if (TREE_CODE (x) == TYPE_DECL)
2721 tree type = TREE_TYPE (x);
2722 tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
2724 if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
2726 /* If these are different names, and we're at the global
2727 binding level, make two equivalent definitions. */
2729 if (global_bindings_p ())
2730 TYPE_NAME (type) = x;
2734 tree tname = DECL_NAME (name);
2736 if (global_bindings_p () && ANON_AGGRNAME_P (tname))
2738 /* do gratuitous C++ typedefing, and make sure that
2739 we access this type either through TREE_TYPE field
2740 or via the tags list. */
2741 TYPE_NAME (TREE_TYPE (x)) = x;
2742 pushtag (tname, TREE_TYPE (x), 0);
2745 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
2747 if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name))
2748 set_nested_typename (x, current_class_name,
2749 DECL_NAME (name), type);
2751 if (type != error_mark_node
2753 && TYPE_IDENTIFIER (type))
2754 set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
2757 /* Multiple external decls of the same identifier ought to match.
2759 We get warnings about inline functions where they are defined.
2760 Avoid duplicate warnings where they are used. */
2761 if (TREE_PUBLIC (x) && !DECL_INLINE (x))
2765 if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
2766 && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
2767 || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
2768 decl = IDENTIFIER_GLOBAL_VALUE (name);
2772 if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1)
2773 /* If different sort of thing, we already gave an error. */
2774 && TREE_CODE (decl) == TREE_CODE (x)
2775 /* If old decl is built-in, we already warned if we should. */
2776 && !DECL_BUILT_IN (decl))
2778 cp_pedwarn ("type mismatch with previous external decl", x);
2779 cp_pedwarn_at ("previous external decl of `%#D'", decl);
2783 /* In PCC-compatibility mode, extern decls of vars with no current decl
2784 take effect at top level no matter where they are. */
2785 if (flag_traditional && DECL_EXTERNAL (x)
2786 && lookup_name (name, 0) == NULL_TREE)
2787 b = global_binding_level;
2789 /* This name is new in its binding level.
2790 Install the new declaration and return it. */
2791 if (b == global_binding_level)
2793 /* Install a global value. */
2795 /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
2796 A `const' which was not declared `extern' is invisible. */
2797 if (TREE_CODE (x) == VAR_DECL
2798 && TREE_READONLY (x) && ! DECL_THIS_EXTERN (x))
2799 TREE_PUBLIC (x) = 0;
2801 /* If the first global decl has external linkage,
2802 warn if we later see static one. */
2803 if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x))
2804 TREE_PUBLIC (name) = 1;
2806 /* Don't install a TYPE_DECL if we already have another
2807 sort of _DECL with that name. */
2808 if (TREE_CODE (x) != TYPE_DECL
2810 || TREE_CODE (t) == TYPE_DECL)
2811 IDENTIFIER_GLOBAL_VALUE (name) = x;
2813 /* Don't forget if the function was used via an implicit decl. */
2814 if (IDENTIFIER_IMPLICIT_DECL (name)
2815 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
2818 /* Don't forget if its address was taken in that way. */
2819 if (IDENTIFIER_IMPLICIT_DECL (name)
2820 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
2821 TREE_ADDRESSABLE (x) = 1;
2823 /* Warn about mismatches against previous implicit decl. */
2824 if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
2825 /* If this real decl matches the implicit, don't complain. */
2826 && ! (TREE_CODE (x) == FUNCTION_DECL
2827 && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
2829 ("`%D' was previously implicitly declared to return `int'", x);
2831 /* If new decl is `static' and an `extern' was seen previously,
2833 warn_extern_redeclared_static (x, t);
2837 /* Here to install a non-global value. */
2838 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
2839 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
2841 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2842 IDENTIFIER_LOCAL_VALUE (name) = x;
2844 /* If this is a TYPE_DECL, push it into the type value slot. */
2845 if (TREE_CODE (x) == TYPE_DECL)
2846 set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
2848 /* If this is an extern function declaration, see if we
2849 have a global definition or declaration for the function. */
2850 if (oldlocal == NULL_TREE
2851 && DECL_EXTERNAL (x) && !DECL_INLINE (x)
2852 && oldglobal != NULL_TREE
2853 && TREE_CODE (x) == FUNCTION_DECL
2854 && TREE_CODE (oldglobal) == FUNCTION_DECL)
2856 /* We have one. Their types must agree. */
2857 if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1))
2859 cp_warning ("extern declaration of `%#D' doesn't match", x);
2860 cp_warning_at ("global declaration `%#D'", oldglobal);
2864 /* Inner extern decl is inline if global one is.
2865 Copy enough to really inline it. */
2866 if (DECL_INLINE (oldglobal))
2868 DECL_INLINE (x) = DECL_INLINE (oldglobal);
2869 DECL_INITIAL (x) = (current_function_decl == oldglobal
2870 ? NULL_TREE : DECL_INITIAL (oldglobal));
2871 DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
2872 DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal);
2873 DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
2874 DECL_RESULT (x) = DECL_RESULT (oldglobal);
2875 TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
2876 DECL_ABSTRACT_ORIGIN (x) = oldglobal;
2878 /* Inner extern decl is built-in if global one is. */
2879 if (DECL_BUILT_IN (oldglobal))
2881 DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal);
2882 DECL_SET_FUNCTION_CODE (x, DECL_FUNCTION_CODE (oldglobal));
2884 /* Keep the arg types from a file-scope fcn defn. */
2885 if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != NULL_TREE
2886 && DECL_INITIAL (oldglobal)
2887 && TYPE_ARG_TYPES (TREE_TYPE (x)) == NULL_TREE)
2888 TREE_TYPE (x) = TREE_TYPE (oldglobal);
2891 /* If we have a local external declaration,
2892 and no file-scope declaration has yet been seen,
2893 then if we later have a file-scope decl it must not be static. */
2894 if (oldlocal == NULL_TREE
2895 && oldglobal == NULL_TREE
2896 && DECL_EXTERNAL (x)
2899 TREE_PUBLIC (name) = 1;
2902 if (DECL_FROM_INLINE (x))
2903 /* Inline decls shadow nothing. */;
2905 /* Warn if shadowing an argument at the top level of the body. */
2906 else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
2907 && TREE_CODE (oldlocal) == PARM_DECL
2908 && TREE_CODE (x) != PARM_DECL)
2910 /* Go to where the parms should be and see if we
2912 struct binding_level *b = current_binding_level->level_chain;
2918 if (b->parm_flag == 1)
2919 cp_error ("declaration of `%#D' shadows a parameter", name);
2921 /* Maybe warn if shadowing something else. */
2922 else if (warn_shadow && !DECL_EXTERNAL (x)
2923 /* No shadow warnings for internally generated vars. */
2924 && DECL_SOURCE_LINE (x) != 0
2925 /* No shadow warnings for vars made for inlining. */
2926 && ! DECL_FROM_INLINE (x))
2928 char *warnstring = NULL;
2930 if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
2931 warnstring = "declaration of `%s' shadows a parameter";
2932 else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
2933 && !TREE_STATIC (name))
2934 warnstring = "declaration of `%s' shadows a member of `this'";
2935 else if (oldlocal != NULL_TREE)
2936 warnstring = "declaration of `%s' shadows previous local";
2937 else if (oldglobal != NULL_TREE)
2938 warnstring = "declaration of `%s' shadows global declaration";
2941 warning (warnstring, IDENTIFIER_POINTER (name));
2944 /* If storing a local value, there may already be one (inherited).
2945 If so, record it for restoration when this binding level ends. */
2946 if (oldlocal != NULL_TREE)
2947 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2950 /* Keep count of variables in this level with incomplete type. */
2951 if (TREE_CODE (x) != TEMPLATE_DECL
2952 && TREE_CODE (x) != CPLUS_CATCH_DECL
2953 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
2954 && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
2956 if (++b->n_incomplete == 0)
2957 error ("too many incomplete variables at this point");
2961 if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE)
2963 if (current_class_name)
2965 if (!DECL_NESTED_TYPENAME (x))
2966 set_nested_typename (x, current_class_name, DECL_NAME (x),
2971 /* Put decls on list in reverse order.
2972 We will reverse them later if necessary. */
2973 TREE_CHAIN (x) = b->names;
2975 if (! (b != global_binding_level || TREE_PERMANENT (x)))
2976 my_friendly_abort (124);
2981 /* Same as pushdecl, but define X in binding-level LEVEL. */
2984 pushdecl_with_scope (x, level)
2986 struct binding_level *level;
2988 register struct binding_level *b = current_binding_level;
2990 current_binding_level = level;
2992 current_binding_level = b;
2996 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
2999 pushdecl_top_level (x)
3002 register struct binding_level *b = inner_binding_level;
3003 register tree t = pushdecl_with_scope (x, global_binding_level);
3005 /* Now, the type_shadowed stack may screw us. Munge it so it does
3007 if (TREE_CODE (x) == TYPE_DECL)
3009 tree name = DECL_NAME (x);
3011 tree *ptr = (tree *)0;
3012 for (; b != global_binding_level; b = b->level_chain)
3014 tree shadowed = b->type_shadowed;
3015 for (; shadowed; shadowed = TREE_CHAIN (shadowed))
3016 if (TREE_PURPOSE (shadowed) == name)
3018 ptr = &TREE_VALUE (shadowed);
3019 /* Can't break out of the loop here because sometimes
3020 a binding level will have duplicate bindings for
3021 PT names. It's gross, but I haven't time to fix it. */
3024 newval = TREE_TYPE (x);
3025 if (ptr == (tree *)0)
3027 /* @@ This shouldn't be needed. My test case "zstring.cc" trips
3028 up here if this is changed to an assertion. --KR */
3029 SET_IDENTIFIER_TYPE_VALUE (name, newval);
3034 /* Disabled this 11/10/92, since there are many cases which
3035 behave just fine when *ptr doesn't satisfy either of these.
3036 For example, nested classes declared as friends of their enclosing
3037 class will not meet this criteria. (bpk) */
3038 my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141);
3046 /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
3049 push_overloaded_decl_top_level (x, forget)
3053 struct binding_level *b = current_binding_level;
3055 current_binding_level = global_binding_level;
3056 push_overloaded_decl (x, forget);
3057 current_binding_level = b;
3060 /* Make the declaration of X appear in CLASS scope. */
3062 pushdecl_class_level (x)
3065 /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class
3066 scope looks for the pre-mangled name. */
3067 register tree name = DECL_NAME (x);
3071 push_class_level_binding (name, x);
3072 if (TREE_CODE (x) == TYPE_DECL)
3074 set_identifier_type_value (name, TREE_TYPE (x));
3075 if (!DECL_NESTED_TYPENAME (x))
3076 set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
3082 /* Make the declaration(s) of X appear in CLASS scope
3083 under the name NAME. */
3085 push_class_level_binding (name, x)
3089 maybe_push_cache_obstack ();
3090 class_binding_level->class_shadowed
3091 = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
3092 class_binding_level->class_shadowed);
3094 IDENTIFIER_CLASS_VALUE (name) = x;
3095 obstack_ptr_grow (&decl_obstack, x);
3098 /* Tell caller how to interpret a TREE_LIST which contains
3099 chains of FUNCTION_DECLS. */
3101 overloaded_globals_p (list)
3104 my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
3106 /* Don't commit caller to seeing them as globals. */
3107 if (TREE_NONLOCAL_FLAG (list))
3109 /* Do commit caller to seeing them as globals. */
3110 if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
3112 /* Do commit caller to not seeing them as globals. */
3116 /* DECL is a FUNCTION_DECL which may have other definitions already in place.
3117 We get around this by making IDENTIFIER_GLOBAL_VALUE (DECL_NAME (DECL))
3118 point to a list of all the things that want to be referenced by that name.
3119 It is then up to the users of that name to decide what to do with that
3122 DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
3123 slot. It is dealt with the same way.
3125 The value returned may be a previous declaration if we guessed wrong
3126 about what language DECL should belong to (C or C++). Otherwise,
3127 it's always DECL (and never something that's not a _DECL). */
3129 push_overloaded_decl (decl, forgettable)
3133 tree orig_name = DECL_NAME (decl);
3134 tree glob = IDENTIFIER_GLOBAL_VALUE (orig_name);
3137 && ! flag_traditional
3138 && (glob == NULL_TREE || TREE_PERMANENT (glob) == 1)
3139 && !global_bindings_p ()
3140 && !pseudo_global_level_p ())
3141 overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
3145 /* We cache the value of builtin functions as ADDR_EXPRs
3146 in the name space. Convert it to some kind of _DECL after
3147 remembering what to forget. */
3148 if (TREE_CODE (glob) == ADDR_EXPR)
3149 glob = TREE_OPERAND (glob, 0);
3151 else if (TREE_CODE (decl) == TEMPLATE_DECL)
3155 for (tmp = get_first_fn (glob); tmp; tmp = DECL_CHAIN (tmp))
3156 if (decl == tmp || duplicate_decls (decl, tmp))
3159 else if (TREE_CODE (glob) == VAR_DECL)
3161 cp_error_at ("previous non-function declaration `%#D'", glob);
3162 cp_error ("conflicts with function declaration `%#D'", decl);
3163 return error_mark_node;
3165 else if (TREE_CODE (glob) == TYPE_DECL)
3167 tree t = TREE_TYPE (glob);
3168 if (IS_AGGR_TYPE (t) && warn_shadow)
3169 cp_warning ("`%#D' hides constructor for `%#T'", decl, t);
3171 else if (is_overloaded_fn (glob))
3175 for (tmp = get_first_fn (glob); tmp; tmp = DECL_CHAIN (tmp))
3177 if (decl == tmp || duplicate_decls (decl, tmp))
3179 if (compparms (TYPE_ARG_TYPES (TREE_TYPE (decl)),
3180 TYPE_ARG_TYPES (TREE_TYPE (tmp)), 2))
3182 cp_error ("new declaration `%#D'", decl);
3183 cp_error_at ("ambiguates old declaration `%#D'", tmp);
3188 if (glob || TREE_CODE (decl) == TEMPLATE_DECL)
3190 if (glob && is_overloaded_fn (glob))
3191 DECL_CHAIN (decl) = get_first_fn (glob);
3193 DECL_CHAIN (decl) = NULL_TREE;
3194 glob = tree_cons (orig_name, decl, NULL_TREE);
3195 TREE_TYPE (glob) = unknown_type_node;
3198 /* orig_name is not ambiguous. */
3201 IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
3205 /* Generate an implicit declaration for identifier FUNCTIONID
3206 as a function of type int (). Print a warning if appropriate. */
3209 implicitly_declare (functionid)
3213 int temp = allocation_temporary_p ();
3215 push_obstacks_nochange ();
3217 /* Save the decl permanently so we can warn if definition follows.
3218 In ANSI C, warn_implicit is usually false, so the saves little space.
3219 But in C++, it's usually true, hence the extra code. */
3220 if (temp && (flag_traditional || !warn_implicit
3221 || current_binding_level == global_binding_level))
3222 end_temporary_allocation ();
3224 /* We used to reuse an old implicit decl here,
3225 but this loses with inline functions because it can clobber
3226 the saved decl chains. */
3227 decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
3229 DECL_EXTERNAL (decl) = 1;
3230 TREE_PUBLIC (decl) = 1;
3232 /* ANSI standard says implicit declarations are in the innermost block.
3233 So we record the decl in the standard fashion.
3234 If flag_traditional is set, pushdecl does it top-level. */
3236 rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
3239 /* Only one warning per identifier. */
3240 && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
3242 cp_pedwarn ("implicit declaration of function `%#D'", decl);
3245 SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
3252 /* Return zero if the declaration NEWDECL is valid
3253 when the declaration OLDDECL (assumed to be for the same name)
3254 has already been seen.
3255 Otherwise return an error message format string with a %s
3256 where the identifier should go. */
3259 redeclaration_error_message (newdecl, olddecl)
3260 tree newdecl, olddecl;
3262 if (TREE_CODE (newdecl) == TYPE_DECL)
3264 /* Because C++ can put things into name space for free,
3265 constructs like "typedef struct foo { ... } foo"
3266 would look like an erroneous redeclaration. */
3267 if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
3270 return "redefinition of `%#D'";
3272 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3274 /* If this is a pure function, its olddecl will actually be
3275 the original initialization to `0' (which we force to call
3276 abort()). Don't complain about redefinition in this case. */
3277 if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
3280 /* Declarations of functions can insist on internal linkage
3281 but they can't be inconsistent with internal linkage,
3282 so there can be no error on that account.
3283 However defining the same name twice is no good. */
3284 if (DECL_INITIAL (olddecl) != NULL_TREE
3285 && DECL_INITIAL (newdecl) != NULL_TREE
3286 /* However, defining once as extern inline and a second
3287 time in another way is ok. */
3288 && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
3289 && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
3291 if (DECL_NAME (olddecl) == NULL_TREE)
3292 return "`%#D' not declared in class";
3294 return "redefinition of `%#D'";
3298 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
3300 if (DECL_INITIAL (olddecl) && DECL_INITIAL (newdecl))
3301 return "redefinition of `%#D'";
3304 else if (current_binding_level == global_binding_level)
3306 /* Objects declared at top level: */
3307 /* If at least one is a reference, it's ok. */
3308 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3310 /* Now we have two tentative defs, or one tentative and one real def. */
3311 /* Insist that the linkage match. */
3312 if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
3313 return "conflicting declarations of `%#D'";
3314 /* Reject two definitions. */
3315 return "redefinition of `%#D'";
3319 /* Objects declared with block scope: */
3320 /* Reject two definitions, and reject a definition
3321 together with an external reference. */
3322 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3323 return "redeclaration of `%#D'";
3328 /* Get the LABEL_DECL corresponding to identifier ID as a label.
3329 Create one if none exists so far for the current function.
3330 This function is called for both label definitions and label references. */
3336 register tree decl = IDENTIFIER_LABEL_VALUE (id);
3338 if (current_function_decl == NULL_TREE)
3340 error ("label `%s' referenced outside of any function",
3341 IDENTIFIER_POINTER (id));
3345 if ((decl == NULL_TREE
3346 || DECL_SOURCE_LINE (decl) == 0)
3347 && (named_label_uses == NULL_TREE
3348 || TREE_PURPOSE (named_label_uses) != current_binding_level->names
3349 || TREE_VALUE (named_label_uses) != decl))
3352 = tree_cons (current_binding_level->names, decl, named_label_uses);
3353 TREE_TYPE (named_label_uses) = (tree)current_binding_level;
3356 /* Use a label already defined or ref'd with this name. */
3357 if (decl != NULL_TREE)
3359 /* But not if it is inherited and wasn't declared to be inheritable. */
3360 if (DECL_CONTEXT (decl) != current_function_decl
3361 && ! C_DECLARED_LABEL_FLAG (decl))
3362 return shadow_label (id);
3366 decl = build_decl (LABEL_DECL, id, void_type_node);
3368 /* A label not explicitly declared must be local to where it's ref'd. */
3369 DECL_CONTEXT (decl) = current_function_decl;
3371 DECL_MODE (decl) = VOIDmode;
3373 /* Say where one reference is to the label,
3374 for the sake of the error if it is not defined. */
3375 DECL_SOURCE_LINE (decl) = lineno;
3376 DECL_SOURCE_FILE (decl) = input_filename;
3378 SET_IDENTIFIER_LABEL_VALUE (id, decl);
3380 named_labels = tree_cons (NULL_TREE, decl, named_labels);
3381 TREE_VALUE (named_label_uses) = decl;
3386 /* Make a label named NAME in the current function,
3387 shadowing silently any that may be inherited from containing functions
3388 or containing scopes.
3390 Note that valid use, if the label being shadowed
3391 comes from another scope in the same function,
3392 requires calling declare_nonlocal_label right away. */
3398 register tree decl = IDENTIFIER_LABEL_VALUE (name);
3400 if (decl != NULL_TREE)
3402 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3403 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3404 SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
3407 return lookup_label (name);
3410 /* Define a label, specifying the location in the source file.
3411 Return the LABEL_DECL node for the label, if the definition is valid.
3412 Otherwise return 0. */
3415 define_label (filename, line, name)
3420 tree decl = lookup_label (name);
3422 /* After labels, make any new cleanups go into their
3423 own new (temporary) binding contour. */
3424 current_binding_level->more_cleanups_ok = 0;
3426 /* If label with this name is known from an outer context, shadow it. */
3427 if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
3429 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3430 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3431 decl = lookup_label (name);
3434 if (DECL_INITIAL (decl) != NULL_TREE)
3436 cp_error ("duplicate label `%D'", decl);
3443 /* Mark label as having been defined. */
3444 DECL_INITIAL (decl) = error_mark_node;
3445 /* Say where in the source. */
3446 DECL_SOURCE_FILE (decl) = filename;
3447 DECL_SOURCE_LINE (decl) = line;
3449 for (prev = NULL_TREE, uses = named_label_uses;
3451 prev = uses, uses = TREE_CHAIN (uses))
3452 if (TREE_VALUE (uses) == decl)
3454 struct binding_level *b = current_binding_level;
3457 tree new_decls = b->names;
3458 tree old_decls = ((tree)b == TREE_TYPE (uses)
3459 ? TREE_PURPOSE (uses) : NULL_TREE);
3460 while (new_decls != old_decls)
3462 if (TREE_CODE (new_decls) == VAR_DECL
3463 /* Don't complain about crossing initialization
3464 of internal entities. They can't be accessed,
3465 and they should be cleaned up
3466 by the time we get to the label. */
3467 && DECL_SOURCE_LINE (new_decls) != 0
3468 && ((DECL_INITIAL (new_decls) != NULL_TREE
3469 && DECL_INITIAL (new_decls) != error_mark_node)
3470 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
3472 if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE)
3473 cp_error ("invalid jump to label `%D'", decl);
3474 SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl);
3475 cp_error ("crosses initialization of `%D'", new_decls);
3477 new_decls = TREE_CHAIN (new_decls);
3479 if ((tree)b == TREE_TYPE (uses))
3485 TREE_CHAIN (prev) = TREE_CHAIN (uses);
3487 named_label_uses = TREE_CHAIN (uses);
3489 current_function_return_value = NULL_TREE;
3494 /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */
3495 /* XXX Note decl is never actually used. (bpk) */
3497 define_case_label (decl)
3500 tree cleanup = last_cleanup_this_contour ();
3503 static int explained = 0;
3504 cp_error_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
3505 error ("where case label appears here");
3508 error ("(enclose actions of previous case statements requiring");
3509 error ("destructors in their own binding contours.)");
3514 /* After labels, make any new cleanups go into their
3515 own new (temporary) binding contour. */
3517 current_binding_level->more_cleanups_ok = 0;
3518 current_function_return_value = NULL_TREE;
3521 /* Return the list of declarations of the current level.
3522 Note that this list is in reverse order unless/until
3523 you nreverse it; and when you do nreverse it, you must
3524 store the result back using `storedecls' or you will lose. */
3529 return current_binding_level->names;
3532 /* Return the list of type-tags (for structs, etc) of the current level. */
3537 return current_binding_level->tags;
3540 /* Store the list of declarations of the current level.
3541 This is done for the parameter declarations of a function being defined,
3542 after they are modified in the light of any missing parameters. */
3548 current_binding_level->names = decls;
3551 /* Similarly, store the list of tags of the current level. */
3557 current_binding_level->tags = tags;
3560 /* Given NAME, an IDENTIFIER_NODE,
3561 return the structure (or union or enum) definition for that name.
3562 Searches binding levels from BINDING_LEVEL up to the global level.
3563 If THISLEVEL_ONLY is nonzero, searches only the specified context
3564 (but skips any tag-transparent contexts to find one that is
3565 meaningful for tags).
3566 FORM says which kind of type the caller wants;
3567 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
3568 If the wrong kind of type is found, and it's not a template, an error is
3572 lookup_tag (form, name, binding_level, thislevel_only)
3573 enum tree_code form;
3574 struct binding_level *binding_level;
3578 register struct binding_level *level;
3580 for (level = binding_level; level; level = level->level_chain)
3583 if (ANON_AGGRNAME_P (name))
3584 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3586 /* There's no need for error checking here, because
3587 anon names are unique throughout the compilation. */
3588 if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
3589 return TREE_VALUE (tail);
3592 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3594 if (TREE_PURPOSE (tail) == name)
3596 enum tree_code code = TREE_CODE (TREE_VALUE (tail));
3597 /* Should tighten this up; it'll probably permit
3598 UNION_TYPE and a struct template, for example. */
3600 && !(form != ENUMERAL_TYPE
3601 && (code == TEMPLATE_DECL
3602 || code == UNINSTANTIATED_P_TYPE)))
3605 /* Definition isn't the kind we were looking for. */
3606 cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
3609 return TREE_VALUE (tail);
3612 if (thislevel_only && ! level->tag_transparent)
3614 if (current_class_type && level->level_chain == global_binding_level)
3616 /* Try looking in this class's tags before heading into
3617 global binding level. */
3618 tree context = current_class_type;
3621 switch (TREE_CODE_CLASS (TREE_CODE (context)))
3625 these_tags = CLASSTYPE_TAGS (context);
3626 if (ANON_AGGRNAME_P (name))
3629 if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
3631 return TREE_VALUE (tail);
3632 these_tags = TREE_CHAIN (these_tags);
3637 if (TREE_PURPOSE (these_tags) == name)
3639 if (TREE_CODE (TREE_VALUE (these_tags)) != form)
3641 cp_error ("`%#D' redeclared as %C in class scope",
3642 TREE_VALUE (tail), form);
3644 return TREE_VALUE (tail);
3646 these_tags = TREE_CHAIN (these_tags);
3648 /* If this type is not yet complete, then don't
3649 look at its context. */
3650 if (TYPE_SIZE (context) == NULL_TREE)
3652 /* Go to next enclosing type, if any. */
3653 context = DECL_CONTEXT (TYPE_NAME (context));
3656 context = DECL_CONTEXT (context);
3659 my_friendly_abort (10);
3671 set_current_level_tags_transparency (tags_transparent)
3672 int tags_transparent;
3674 current_binding_level->tag_transparent = tags_transparent;
3677 /* Given a type, find the tag that was defined for it and return the tag name.
3678 Otherwise return 0. However, the value can never be 0
3679 in the cases in which this is used.
3681 C++: If NAME is non-zero, this is the new name to install. This is
3682 done when replacing anonymous tags with real tag names. */
3685 lookup_tag_reverse (type, name)
3689 register struct binding_level *level;
3691 for (level = current_binding_level; level; level = level->level_chain)
3694 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3696 if (TREE_VALUE (tail) == type)
3699 TREE_PURPOSE (tail) = name;
3700 return TREE_PURPOSE (tail);
3707 /* Given type TYPE which was not declared in C++ language context,
3708 attempt to find a name by which it is referred. */
3710 typedecl_for_tag (tag)
3713 struct binding_level *b = current_binding_level;
3715 if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
3716 return TYPE_NAME (tag);
3720 tree decls = b->names;
3723 if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
3725 decls = TREE_CHAIN (decls);
3734 /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
3735 Return the type value, or NULL_TREE if not found. */
3737 lookup_nested_type (type, context)
3741 if (context == NULL_TREE)
3745 switch (TREE_CODE (context))
3749 tree ctype = TREE_TYPE (context);
3750 tree match = value_member (type, CLASSTYPE_TAGS (ctype));
3752 return TREE_VALUE (match);
3753 context = DECL_CONTEXT (context);
3755 /* When we have a nested class whose member functions have
3756 local types (e.g., a set of enums), we'll arrive here
3757 with the DECL_CONTEXT as the actual RECORD_TYPE node for
3758 the enclosing class. Instead, we want to make sure we
3759 come back in here with the TYPE_DECL, not the RECORD_TYPE. */
3760 if (context && TREE_CODE (context) == RECORD_TYPE)
3761 context = TREE_CHAIN (context);
3765 return TYPE_IDENTIFIER (type) ? lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE;
3768 my_friendly_abort (12);
3774 /* Look up NAME in the current binding level and its superiors in the
3775 namespace of variables, functions and typedefs. Return a ..._DECL
3776 node of some kind representing its definition if there is only one
3777 such declaration, or return a TREE_LIST with all the overloaded
3778 definitions if there are many, or return 0 if it is undefined.
3780 If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
3781 Otherwise we prefer non-TYPE_DECLs. */
3784 lookup_name (name, prefer_type)
3790 if (current_binding_level != global_binding_level
3791 && IDENTIFIER_LOCAL_VALUE (name))
3792 val = IDENTIFIER_LOCAL_VALUE (name);
3793 /* In C++ class fields are between local and global scope,
3794 just before the global scope. */
3795 else if (current_class_type)
3797 val = IDENTIFIER_CLASS_VALUE (name);
3798 if (val == NULL_TREE
3799 && TYPE_SIZE (current_class_type) == NULL_TREE
3800 && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
3802 /* Try to find values from base classes
3803 if we are presently defining a type.
3804 We are presently only interested in TYPE_DECLs. */
3805 val = lookup_field (current_class_type, name, 0, prefer_type < 0);
3806 if (val == error_mark_node)
3808 if (val && TREE_CODE (val) != TYPE_DECL)
3812 /* yylex() calls this with -2, since we should never start digging for
3813 the nested name at the point where we haven't even, for example,
3814 created the COMPONENT_REF or anything like that. */
3815 if (val == NULL_TREE)
3816 val = lookup_nested_field (name, prefer_type != -2);
3818 if (val == NULL_TREE)
3819 val = IDENTIFIER_GLOBAL_VALUE (name);
3822 val = IDENTIFIER_GLOBAL_VALUE (name);
3826 extern int looking_for_typename;
3828 /* Arbitrate between finding a TYPE_DECL and finding
3829 other kinds of _DECLs. */
3830 if (TREE_CODE (val) == TYPE_DECL || looking_for_typename < 0)
3833 if (IDENTIFIER_HAS_TYPE_VALUE (name))
3835 register tree val_as_type = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
3837 if (val == val_as_type || prefer_type > 0
3838 || looking_for_typename > 0)
3843 if (TREE_TYPE (val) == error_mark_node)
3844 return error_mark_node;
3850 /* Similar to `lookup_name' but look only at current binding level. */
3853 lookup_name_current_level (name)
3856 register tree t = NULL_TREE;
3858 if (current_binding_level == global_binding_level)
3860 t = IDENTIFIER_GLOBAL_VALUE (name);
3862 /* extern "C" function() */
3863 if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
3866 else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
3868 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
3869 if (DECL_NAME (t) == name)
3876 /* Arrange for the user to get a source line number, even when the
3877 compiler is going down in flames, so that she at least has a
3878 chance of working around problems in the compiler. We used to
3879 call error(), but that let the segmentation fault continue
3880 through; now, it's much more passive by asking them to send the
3881 maintainers mail about the problem. */
3887 signal (SIGSEGV, SIG_DFL);
3889 signal (SIGIOT, SIG_DFL);
3892 signal (SIGILL, SIG_DFL);
3895 signal (SIGABRT, SIG_DFL);
3898 signal (SIGBUS, SIG_DFL);
3900 my_friendly_abort (0);
3903 /* Array for holding types considered "built-in". These types
3904 are output in the module in which `main' is defined. */
3905 static tree *builtin_type_tdescs_arr;
3906 static int builtin_type_tdescs_len, builtin_type_tdescs_max;
3908 /* Push the declarations of builtin types into the namespace.
3909 RID_INDEX, if < RID_MAX is the index of the builtin type
3910 in the array RID_POINTERS. NAME is the name used when looking
3911 up the builtin type. TYPE is the _TYPE node for the builtin type. */
3914 record_builtin_type (rid_index, name, type)
3919 tree rname = NULL_TREE, tname = NULL_TREE;
3922 if ((int) rid_index < (int) RID_MAX)
3923 rname = ridpointers[(int) rid_index];
3925 tname = get_identifier (name);
3927 TYPE_BUILT_IN (type) = 1;
3931 #if 0 /* not yet, should get fixed properly later */
3932 tdecl = pushdecl (make_type_decl (tname, type));
3934 tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
3936 set_identifier_type_value (tname, NULL_TREE);
3937 if ((int) rid_index < (int) RID_MAX)
3938 IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
3940 if (rname != NULL_TREE)
3942 if (tname != NULL_TREE)
3944 set_identifier_type_value (rname, NULL_TREE);
3945 IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
3949 #if 0 /* not yet, should get fixed properly later */
3950 tdecl = pushdecl (make_type_decl (rname, type));
3952 tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
3954 set_identifier_type_value (rname, NULL_TREE);
3960 if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
3962 builtin_type_tdescs_max *= 2;
3963 builtin_type_tdescs_arr
3964 = (tree *)xrealloc (builtin_type_tdescs_arr,
3965 builtin_type_tdescs_max * sizeof (tree));
3967 builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
3968 if (TREE_CODE (type) != POINTER_TYPE)
3970 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3971 = build_pointer_type (type);
3972 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3973 = build_type_variant (TYPE_POINTER_TO (type), 1, 0);
3975 if (TREE_CODE (type) != VOID_TYPE)
3977 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3978 = build_reference_type (type);
3979 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3980 = build_type_variant (TYPE_REFERENCE_TO (type), 1, 0);
3986 output_builtin_tdesc_entries ()
3988 extern struct obstack permanent_obstack;
3990 /* If there's more than one main in this file, don't crash. */
3991 if (builtin_type_tdescs_arr == 0)
3994 push_obstacks (&permanent_obstack, &permanent_obstack);
3995 while (builtin_type_tdescs_len > 0)
3997 tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
3998 tree tdesc = build_t_desc (type, 0);
3999 TREE_ASM_WRITTEN (tdesc) = 0;
4000 build_t_desc (type, 2);
4002 free (builtin_type_tdescs_arr);
4003 builtin_type_tdescs_arr = 0;
4007 /* Push overloaded decl, in global scope, with one argument so it
4008 can be used as a callback from define_function. */
4010 push_overloaded_decl_1 (x)
4013 push_overloaded_decl (x, 0);
4016 /* Create the predefined scalar types of C,
4017 and some nodes representing standard constants (0, 1, (void *)0).
4018 Initialize the global binding level.
4019 Make definitions for built-in primitive functions. */
4022 init_decl_processing ()
4025 register tree endlink, int_endlink, double_endlink, ptr_endlink;
4027 /* Either char* or void*. */
4028 tree traditional_ptr_type_node;
4029 /* Data type of memcpy. */
4031 #if 0 /* Not yet. */
4032 /* Data type of strncpy. */
4035 int wchar_type_size;
4037 tree array_domain_type;
4039 /* Have to make these distinct before we try using them. */
4040 lang_name_cplusplus = get_identifier ("C++");
4041 lang_name_c = get_identifier ("C");
4043 if (flag_ansi || pedantic)
4044 strict_prototypes_lang_c = strict_prototypes_lang_cplusplus;
4047 current_lang_name = lang_name_c;
4049 current_function_decl = NULL_TREE;
4050 named_labels = NULL_TREE;
4051 named_label_uses = NULL_TREE;
4052 current_binding_level = NULL_BINDING_LEVEL;
4053 free_binding_level = NULL_BINDING_LEVEL;
4055 /* Because most segmentation signals can be traced back into user
4056 code, catch them and at least give the user a chance of working
4057 around compiler bugs. */
4058 signal (SIGSEGV, signal_catch);
4060 /* We will also catch aborts in the back-end through signal_catch and
4061 give the user a chance to see where the error might be, and to defeat
4062 aborts in the back-end when there have been errors previously in their
4065 signal (SIGIOT, signal_catch);
4068 signal (SIGILL, signal_catch);
4071 signal (SIGABRT, signal_catch);
4074 signal (SIGBUS, signal_catch);
4077 gcc_obstack_init (&decl_obstack);
4080 builtin_type_tdescs_max = 100;
4081 builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
4084 /* Must lay these out before anything else gets laid out. */
4085 error_mark_node = make_node (ERROR_MARK);
4086 TREE_PERMANENT (error_mark_node) = 1;
4087 TREE_TYPE (error_mark_node) = error_mark_node;
4088 error_mark_list = build_tree_list (error_mark_node, error_mark_node);
4089 TREE_TYPE (error_mark_list) = error_mark_node;
4091 pushlevel (0); /* make the binding_level structure for global names. */
4092 global_binding_level = current_binding_level;
4094 this_identifier = get_identifier (THIS_NAME);
4095 in_charge_identifier = get_identifier (IN_CHARGE_NAME);
4096 pfn_identifier = get_identifier (VTABLE_PFN_NAME);
4097 index_identifier = get_identifier (VTABLE_INDEX_NAME);
4098 delta_identifier = get_identifier (VTABLE_DELTA_NAME);
4099 delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
4100 pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
4102 /* Define `int' and `char' first so that dbx will output them first. */
4104 integer_type_node = make_signed_type (INT_TYPE_SIZE);
4105 record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
4107 /* Define `char', which is like either `signed char' or `unsigned char'
4108 but not the same as either. */
4112 ? make_signed_type (CHAR_TYPE_SIZE)
4113 : make_unsigned_type (CHAR_TYPE_SIZE));
4114 record_builtin_type (RID_CHAR, "char", char_type_node);
4116 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4117 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
4119 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4120 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
4122 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4123 record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
4124 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
4126 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4127 record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
4129 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4130 record_builtin_type (RID_MAX, "long long unsigned int",
4131 long_long_unsigned_type_node);
4132 record_builtin_type (RID_MAX, "long long unsigned",
4133 long_long_unsigned_type_node);
4135 /* `unsigned long' is the standard type for sizeof.
4136 Traditionally, use a signed type.
4137 Note that stddef.h uses `unsigned long',
4138 and this must agree, even of long and int are the same size. */
4140 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
4141 if (flag_traditional && TREE_UNSIGNED (sizetype))
4142 sizetype = signed_type (sizetype);
4145 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
4147 TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
4148 TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
4149 TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
4150 TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
4151 TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
4152 TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
4153 TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
4155 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4156 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
4157 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4158 record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
4159 record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
4161 /* Define both `signed char' and `unsigned char'. */
4162 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4163 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
4164 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4165 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
4167 /* These are types that type_for_size and type_for_mode use. */
4168 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4169 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
4170 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4171 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
4172 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4173 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
4174 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4175 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
4176 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4177 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
4178 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4179 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
4180 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4181 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
4182 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4183 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
4185 float_type_node = make_node (REAL_TYPE);
4186 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4187 record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
4188 layout_type (float_type_node);
4190 double_type_node = make_node (REAL_TYPE);
4191 if (flag_short_double)
4192 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4194 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4195 record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
4196 layout_type (double_type_node);
4198 long_double_type_node = make_node (REAL_TYPE);
4199 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4200 record_builtin_type (RID_MAX, "long double", long_double_type_node);
4201 layout_type (long_double_type_node);
4203 integer_zero_node = build_int_2 (0, 0);
4204 TREE_TYPE (integer_zero_node) = integer_type_node;
4205 integer_one_node = build_int_2 (1, 0);
4206 TREE_TYPE (integer_one_node) = integer_type_node;
4207 integer_two_node = build_int_2 (2, 0);
4208 TREE_TYPE (integer_two_node) = integer_type_node;
4209 integer_three_node = build_int_2 (3, 0);
4210 TREE_TYPE (integer_three_node) = integer_type_node;
4211 empty_init_node = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
4213 /* These are needed by stor-layout.c. */
4214 size_zero_node = size_int (0);
4215 size_one_node = size_int (1);
4217 void_type_node = make_node (VOID_TYPE);
4218 record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
4219 layout_type (void_type_node); /* Uses integer_zero_node. */
4220 void_list_node = build_tree_list (NULL_TREE, void_type_node);
4221 TREE_PARMLIST (void_list_node) = 1;
4223 null_pointer_node = build_int_2 (0, 0);
4224 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4225 layout_type (TREE_TYPE (null_pointer_node));
4227 /* Used for expressions that do nothing, but are not errors. */
4228 void_zero_node = build_int_2 (0, 0);
4229 TREE_TYPE (void_zero_node) = void_type_node;
4231 string_type_node = build_pointer_type (char_type_node);
4232 const_string_type_node = build_pointer_type (build_type_variant (char_type_node, 1, 0));
4233 record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
4235 /* Make a type to be the domain of a few array types
4236 whose domains don't really matter.
4237 200 is small enough that it always fits in size_t
4238 and large enough that it can hold most function names for the
4239 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4240 array_domain_type = build_index_type (build_int_2 (200, 0));
4242 /* make a type for arrays of characters.
4243 With luck nothing will ever really depend on the length of this
4245 char_array_type_node
4246 = build_array_type (char_type_node, array_domain_type);
4247 /* Likewise for arrays of ints. */
4249 = build_array_type (integer_type_node, array_domain_type);
4251 /* This is just some anonymous class type. Nobody should ever
4252 need to look inside this envelope. */
4253 class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
4255 default_function_type
4256 = build_function_type (integer_type_node, NULL_TREE);
4257 build_pointer_type (default_function_type);
4259 ptr_type_node = build_pointer_type (void_type_node);
4260 const_ptr_type_node = build_pointer_type (build_type_variant (void_type_node, 1, 0));
4261 record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
4262 endlink = void_list_node;
4263 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
4264 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
4265 ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
4268 = build_function_type (double_type_node, double_endlink);
4270 double_ftype_double_double
4271 = build_function_type (double_type_node,
4272 tree_cons (NULL_TREE, double_type_node, double_endlink));
4275 = build_function_type (integer_type_node, int_endlink);
4278 = build_function_type (long_integer_type_node,
4279 tree_cons (NULL_TREE, long_integer_type_node, endlink));
4281 void_ftype_ptr_ptr_int
4282 = build_function_type (void_type_node,
4283 tree_cons (NULL_TREE, ptr_type_node,
4284 tree_cons (NULL_TREE, ptr_type_node,
4287 int_ftype_cptr_cptr_sizet
4288 = build_function_type (integer_type_node,
4289 tree_cons (NULL_TREE, const_ptr_type_node,
4290 tree_cons (NULL_TREE, const_ptr_type_node,
4291 tree_cons (NULL_TREE,
4295 void_ftype_ptr_int_int
4296 = build_function_type (void_type_node,
4297 tree_cons (NULL_TREE, ptr_type_node,
4298 tree_cons (NULL_TREE, integer_type_node,
4301 string_ftype_ptr_ptr /* strcpy prototype */
4302 = build_function_type (string_type_node,
4303 tree_cons (NULL_TREE, string_type_node,
4304 tree_cons (NULL_TREE,
4305 const_string_type_node,
4310 strncpy_ftype /* strncpy prototype */
4311 = build_function_type (string_type_node,
4312 tree_cons (NULL_TREE, string_type_node,
4313 tree_cons (NULL_TREE, const_string_type_node,
4314 tree_cons (NULL_TREE,
4319 int_ftype_string_string /* strcmp prototype */
4320 = build_function_type (integer_type_node,
4321 tree_cons (NULL_TREE, const_string_type_node,
4322 tree_cons (NULL_TREE,
4323 const_string_type_node,
4326 sizet_ftype_string /* strlen prototype */
4327 = build_function_type (sizetype,
4328 tree_cons (NULL_TREE, const_string_type_node,
4331 traditional_ptr_type_node
4332 = (flag_traditional ? string_type_node : ptr_type_node);
4334 memcpy_ftype /* memcpy prototype */
4335 = build_function_type (traditional_ptr_type_node,
4336 tree_cons (NULL_TREE, ptr_type_node,
4337 tree_cons (NULL_TREE, const_ptr_type_node,
4338 tree_cons (NULL_TREE,
4342 if (flag_huge_objects)
4343 delta_type_node = long_integer_type_node;
4345 delta_type_node = short_integer_type_node;
4347 builtin_function ("__builtin_constant_p", int_ftype_int,
4348 BUILT_IN_CONSTANT_P, NULL_PTR);
4350 builtin_function ("__builtin_return_address",
4351 build_function_type (ptr_type_node,
4352 tree_cons (NULL_TREE,
4355 BUILT_IN_RETURN_ADDRESS, NULL_PTR);
4357 builtin_function ("__builtin_frame_address",
4358 build_function_type (ptr_type_node,
4359 tree_cons (NULL_TREE,
4362 BUILT_IN_FRAME_ADDRESS, NULL_PTR);
4365 builtin_function ("__builtin_alloca",
4366 build_function_type (ptr_type_node,
4367 tree_cons (NULL_TREE,
4370 BUILT_IN_ALLOCA, "alloca");
4372 builtin_function ("alloca",
4373 build_function_type (ptr_type_node,
4374 tree_cons (NULL_TREE,
4377 BUILT_IN_ALLOCA, NULL_PTR);
4380 builtin_function ("__builtin_abs", int_ftype_int,
4381 BUILT_IN_ABS, NULL_PTR);
4382 builtin_function ("__builtin_fabs", double_ftype_double,
4383 BUILT_IN_FABS, NULL_PTR);
4384 builtin_function ("__builtin_labs", long_ftype_long,
4385 BUILT_IN_LABS, NULL_PTR);
4386 builtin_function ("__builtin_ffs", int_ftype_int,
4387 BUILT_IN_FFS, NULL_PTR);
4388 builtin_function ("__builtin_fsqrt", double_ftype_double,
4389 BUILT_IN_FSQRT, NULL_PTR);
4390 builtin_function ("__builtin_sin", double_ftype_double,
4391 BUILT_IN_SIN, "sin");
4392 builtin_function ("__builtin_cos", double_ftype_double,
4393 BUILT_IN_COS, "cos");
4394 builtin_function ("__builtin_saveregs",
4395 build_function_type (ptr_type_node, NULL_TREE),
4396 BUILT_IN_SAVEREGS, NULL_PTR);
4397 /* EXPAND_BUILTIN_VARARGS is obsolete. */
4399 builtin_function ("__builtin_varargs",
4400 build_function_type (ptr_type_node,
4401 tree_cons (NULL_TREE,
4404 BUILT_IN_VARARGS, NULL_PTR);
4406 builtin_function ("__builtin_classify_type", default_function_type,
4407 BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
4408 builtin_function ("__builtin_next_arg",
4409 build_function_type (ptr_type_node, NULL_TREE),
4410 BUILT_IN_NEXT_ARG, NULL_PTR);
4411 builtin_function ("__builtin_args_info",
4412 build_function_type (integer_type_node,
4413 tree_cons (NULL_TREE,
4416 BUILT_IN_ARGS_INFO, NULL_PTR);
4418 /* Untyped call and return. */
4419 builtin_function ("__builtin_apply_args",
4420 build_function_type (ptr_type_node, NULL_TREE),
4421 BUILT_IN_APPLY_ARGS, NULL_PTR);
4423 temp = tree_cons (NULL_TREE,
4424 build_pointer_type (build_function_type (void_type_node,
4426 tree_cons (NULL_TREE,
4428 tree_cons (NULL_TREE,
4431 builtin_function ("__builtin_apply",
4432 build_function_type (ptr_type_node, temp),
4433 BUILT_IN_APPLY, NULL_PTR);
4434 builtin_function ("__builtin_return",
4435 build_function_type (void_type_node,
4436 tree_cons (NULL_TREE,
4439 BUILT_IN_RETURN, NULL_PTR);
4441 /* Currently under experimentation. */
4442 builtin_function ("__builtin_memcpy", memcpy_ftype,
4443 BUILT_IN_MEMCPY, "memcpy");
4444 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
4445 BUILT_IN_MEMCMP, "memcmp");
4446 builtin_function ("__builtin_strcmp", int_ftype_string_string,
4447 BUILT_IN_STRCMP, "strcmp");
4448 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
4449 BUILT_IN_STRCPY, "strcpy");
4452 builtin_function ("__builtin_strncpy", strncpy_ftype,
4453 BUILT_IN_STRNCPY, "strncpy");
4455 builtin_function ("__builtin_strlen", sizet_ftype_string,
4456 BUILT_IN_STRLEN, "strlen");
4458 if (!flag_no_builtin)
4460 #if 0 /* These do not work well with libg++. */
4461 builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
4462 builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
4463 builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
4465 builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
4466 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
4468 builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR);
4469 builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, NULL_PTR);
4472 builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR);
4474 builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR);
4475 builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
4476 builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
4480 /* Support for these has not been written in either expand_builtin
4481 or build_function_call. */
4482 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
4483 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
4484 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, 0);
4485 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
4486 builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD, 0);
4487 builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM, 0);
4488 builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, 0);
4489 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, 0);
4490 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, 0);
4493 /* C++ extensions */
4495 unknown_type_node = make_node (UNKNOWN_TYPE);
4496 #if 0 /* not yet, should get fixed properly later */
4497 pushdecl (make_type_decl (get_identifier ("unknown type"),
4498 unknown_type_node));
4500 decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
4501 unknown_type_node));
4502 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
4503 DECL_IGNORED_P (decl) = 1;
4505 TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
4506 TYPE_ALIGN (unknown_type_node) = 1;
4507 TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
4508 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
4509 TREE_TYPE (unknown_type_node) = unknown_type_node;
4510 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
4511 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
4512 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
4514 /* This is for handling opaque types in signatures. */
4515 opaque_type_node = copy_node (ptr_type_node);
4516 TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
4517 record_builtin_type (RID_MAX, 0, opaque_type_node);
4519 /* This is special for C++ so functions can be overloaded. */
4521 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
4522 wchar_type_size = TYPE_PRECISION (wchar_type_node);
4523 signed_wchar_type_node = make_signed_type (wchar_type_size);
4524 unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
4526 = TREE_UNSIGNED (wchar_type_node)
4527 ? unsigned_wchar_type_node
4528 : signed_wchar_type_node;
4529 record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
4531 /* This is for wide string constants. */
4532 wchar_array_type_node
4533 = build_array_type (wchar_type_node, array_domain_type);
4535 /* This is a hack that should go away when we deliver the
4539 builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
4540 pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
4543 /* Simplify life by making a "memptr_type". Give its
4544 fields names so that the debugger can use them. */
4546 memptr_type = make_lang_type (RECORD_TYPE);
4547 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, delta_type_node);
4548 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, delta_type_node);
4549 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, ptr_type_node);
4550 finish_builtin_type (memptr_type, VTBL_PTR_TYPE, fields, 2,
4553 /* Make this part of an invisible union. */
4554 fields[3] = copy_node (fields[2]);
4555 TREE_TYPE (fields[3]) = delta_type_node;
4556 DECL_NAME (fields[3]) = delta2_identifier;
4557 DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
4558 DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
4559 TREE_UNSIGNED (fields[3]) = 0;
4560 TREE_CHAIN (fields[2]) = fields[3];
4561 memptr_type = build_type_variant (memptr_type, 1, 0);
4562 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, memptr_type);
4564 if (flag_vtable_thunks)
4565 vtable_entry_type = ptr_type_node;
4567 vtable_entry_type = memptr_type;
4569 #ifdef VTABLE_USES_MASK
4570 /* This is primarily for virtual function definition. We
4571 declare an array of `void *', which can later be
4572 converted to the appropriate function pointer type.
4573 To do pointers to members, we need a mask which can
4574 distinguish an index value into a virtual function table
4576 vtbl_mask = build_int_2 (~((HOST_WIDE_INT) VINDEX_MAX - 1), -1);
4580 = build_array_type (vtable_entry_type, NULL_TREE);
4581 layout_type (vtbl_type_node);
4582 vtbl_type_node = build_type_variant (vtbl_type_node, 1, 0);
4583 record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
4585 /* Simplify life by making a "sigtable_entry_type". Give its
4586 fields names so that the debugger can use them. */
4588 if (flag_handle_signatures)
4590 sigtable_entry_type = make_lang_type (RECORD_TYPE);
4591 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_CODE_NAME), short_integer_type_node);
4592 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_OFFSET_NAME), short_integer_type_node);
4593 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_PFN_NAME), ptr_type_node);
4594 finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 2,
4596 sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
4597 record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
4602 /* Must build __t_desc type. Currently, type descriptors look like this:
4609 struct __t_desc *points_to;
4610 int ivars_count, meths_count;
4611 struct __i_desc *ivars[];
4612 struct __m_desc *meths[];
4613 struct __t_desc *parents[];
4614 struct __t_desc *vbases[];
4618 ...as per Linton's paper. */
4620 __t_desc_type_node = make_lang_type (RECORD_TYPE);
4621 __i_desc_type_node = make_lang_type (RECORD_TYPE);
4622 __m_desc_type_node = make_lang_type (RECORD_TYPE);
4623 __t_desc_array_type = build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE);
4624 __i_desc_array_type = build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE);
4625 __m_desc_array_type = build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE);
4627 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4629 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
4630 unsigned_type_node);
4631 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
4632 unsigned_type_node);
4633 fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("points_to"),
4634 TYPE_POINTER_TO (__t_desc_type_node));
4635 fields[4] = build_lang_field_decl (FIELD_DECL,
4636 get_identifier ("ivars_count"),
4638 fields[5] = build_lang_field_decl (FIELD_DECL,
4639 get_identifier ("meths_count"),
4641 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
4642 build_pointer_type (__i_desc_array_type));
4643 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
4644 build_pointer_type (__m_desc_array_type));
4645 fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
4646 build_pointer_type (__t_desc_array_type));
4647 fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
4648 build_pointer_type (__t_desc_array_type));
4649 fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
4650 build_pointer_type (integer_type_node));
4651 finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
4653 /* ivar descriptors look like this:
4659 struct __t_desc *type;
4663 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4665 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
4667 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
4668 TYPE_POINTER_TO (__t_desc_type_node));
4669 finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, integer_type_node);
4671 /* method descriptors look like this:
4677 struct __t_desc *vcontext;
4678 struct __t_desc *return_type;
4681 short required_parms;
4682 struct __t_desc *parm_types[];
4686 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4688 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
4690 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
4691 TYPE_POINTER_TO (__t_desc_type_node));
4692 fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
4693 TYPE_POINTER_TO (__t_desc_type_node));
4694 fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
4695 build_pointer_type (default_function_type));
4696 fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
4697 short_integer_type_node);
4698 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
4699 short_integer_type_node);
4700 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
4701 build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE)));
4702 finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, integer_type_node);
4706 current_lang_name = lang_name_cplusplus;
4709 int i = builtin_type_tdescs_len;
4712 tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
4713 TREE_ASM_WRITTEN (tdesc) = 1;
4714 TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
4718 auto_function (ansi_opname[(int) NEW_EXPR],
4719 build_function_type (ptr_type_node,
4720 tree_cons (NULL_TREE, sizetype,
4723 auto_function (ansi_opname[(int) DELETE_EXPR],
4724 build_function_type (void_type_node,
4725 tree_cons (NULL_TREE, ptr_type_node,
4730 = define_function ("abort",
4731 build_function_type (void_type_node, void_list_node),
4732 NOT_BUILT_IN, 0, 0);
4734 unhandled_exception_fndecl
4735 = define_function ("__unhandled_exception",
4736 build_function_type (void_type_node, NULL_TREE),
4737 NOT_BUILT_IN, 0, 0);
4739 /* Perform other language dependent initializations. */
4740 init_class_processing ();
4741 init_init_processing ();
4742 init_search_processing ();
4744 if (flag_handle_exceptions)
4746 if (flag_handle_exceptions == 2)
4747 /* Too much trouble to inline all the trys needed for this. */
4748 flag_this_is_variable = 2;
4749 init_exception_processing ();
4752 init_gc_processing ();
4755 flag_inline_functions = 0;
4757 /* This causes uneccessary emission of inline functions. */
4758 flag_default_inline = 0;
4764 /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
4765 declare_function_name ();
4767 /* Prepare to check format strings against argument lists. */
4768 init_function_format_info ();
4771 /* Make a definition for a builtin function named NAME and whose data type
4772 is TYPE. TYPE should be a function type with argument types.
4773 FUNCTION_CODE tells later passes how to compile calls to this function.
4774 See tree.h for its possible values.
4776 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
4777 the name to be called if we can't opencode the function. */
4780 define_function (name, type, function_code, pfn, library_name)
4783 enum built_in_function function_code;
4787 tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
4788 DECL_EXTERNAL (decl) = 1;
4789 TREE_PUBLIC (decl) = 1;
4791 /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
4792 we cannot change DECL_ASSEMBLER_NAME until we have installed this
4793 function in the namespace. */
4794 if (pfn) (*pfn) (decl);
4796 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
4797 make_function_rtl (decl);
4798 if (function_code != NOT_BUILT_IN)
4800 DECL_BUILT_IN (decl) = 1;
4801 DECL_SET_FUNCTION_CODE (decl, function_code);
4806 /* Called when a declaration is seen that contains no names to declare.
4807 If its type is a reference to a structure, union or enum inherited
4808 from a containing scope, shadow that tag name for the current scope
4809 with a forward reference.
4810 If its type defines a new named structure or union
4811 or defines an enum, it is valid but we need not do anything here.
4812 Otherwise, it is an error.
4814 C++: may have to grok the declspecs to learn about static,
4815 complain for anonymous unions. */
4818 shadow_tag (declspecs)
4823 int static_or_extern = 0;
4825 register enum tree_code code, ok_code = ERROR_MARK;
4826 register tree t = NULL_TREE;
4828 for (link = declspecs; link; link = TREE_CHAIN (link))
4830 register tree value = TREE_VALUE (link);
4832 code = TREE_CODE (value);
4833 if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
4834 /* Used to test also that TYPE_SIZE (value) != 0.
4835 That caused warning for `struct foo;' at top level in the file. */
4837 register tree name = TYPE_NAME (value);
4839 if (name == NULL_TREE)
4840 name = lookup_tag_reverse (value, NULL_TREE);
4842 if (name && TREE_CODE (name) == TYPE_DECL)
4843 name = DECL_NAME (name);
4845 t = lookup_tag (code, name, inner_binding_level, 1);
4849 push_obstacks (&permanent_obstack, &permanent_obstack);
4850 if (IS_AGGR_TYPE_CODE (code))
4851 t = make_lang_type (code);
4853 t = make_node (code);
4854 pushtag (name, t, 0);
4859 else if (name != NULL_TREE || code == ENUMERAL_TYPE)
4862 if (ok_code != ERROR_MARK)
4867 pedwarn ("useless keyword or type name in declaration");
4871 else if (value == ridpointers[(int) RID_STATIC]
4872 || value == ridpointers[(int) RID_EXTERN])
4873 static_or_extern = 1;
4876 /* This is where the variables in an anonymous union are
4877 declared. An anonymous union declaration looks like:
4879 because there is no declarator after the union, the parser
4880 sends that declaration here. */
4881 if (ok_code == UNION_TYPE
4883 && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
4884 && ANON_AGGRNAME_P (TYPE_NAME (t)))
4885 || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
4886 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
4888 /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have
4889 function members. */
4890 if (TYPE_FIELDS (t))
4892 tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, NULL_TREE);
4893 finish_anon_union (decl);
4896 error ("anonymous union cannot have a function member");
4900 /* Anonymous unions are objects, that's why we only check for
4901 static/extern specifiers in this branch. */
4902 if (static_or_extern)
4903 error ("static/extern can only be specified for objects and functions");
4905 if (ok_code == RECORD_TYPE
4907 && TYPE_LANG_SPECIFIC (t)
4908 && CLASSTYPE_DECLARED_EXCEPTION (t))
4911 cp_error ("redeclaration of exception `%T'", t);
4916 push_obstacks (&permanent_obstack, &permanent_obstack);
4919 finish_exception (t, NULL_TREE);
4921 ename = TYPE_NAME (t);
4922 if (TREE_CODE (ename) == TYPE_DECL)
4923 ename = DECL_NAME (ename);
4924 decl = build_lang_field_decl (VAR_DECL, ename, t);
4925 finish_exception_decl (current_class_name, decl);
4926 end_exception_decls ();
4931 else if (!warned && found_tag > 1)
4932 warning ("multiple types in one declaration");
4936 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
4939 groktypename (typename)
4942 if (TREE_CODE (typename) != TREE_LIST)
4944 return grokdeclarator (TREE_VALUE (typename),
4945 TREE_PURPOSE (typename),
4946 TYPENAME, 0, NULL_TREE);
4949 /* Decode a declarator in an ordinary declaration or data definition.
4950 This is called as soon as the type information and variable name
4951 have been parsed, before parsing the initializer if any.
4952 Here we create the ..._DECL node, fill in its type,
4953 and put it on the list of decls for the current context.
4954 The ..._DECL node is returned as the value.
4956 Exception: for arrays where the length is not specified,
4957 the type is left null, to be filled in by `finish_decl'.
4959 Function definitions do not come here; they go to start_function
4960 instead. However, external and forward declarations of functions
4961 do go through here. Structure field declarations are done by
4962 grokfield and not through here. */
4964 /* Set this to zero to debug not using the temporary obstack
4965 to parse initializers. */
4966 int debug_temp_inits = 1;
4969 start_decl (declarator, declspecs, initialized, raises)
4970 tree declarator, declspecs;
4975 register tree type, tem;
4977 extern int have_extern_spec;
4978 extern int used_extern_spec;
4980 int init_written = initialized;
4982 /* This should only be done once on the top most decl. */
4983 if (have_extern_spec && !used_extern_spec)
4985 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
4986 used_extern_spec = 1;
4989 decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises);
4990 if (decl == NULL_TREE || decl == void_type_node)
4993 type = TREE_TYPE (decl);
4995 /* Don't lose if destructors must be executed at file-level. */
4996 if (TREE_STATIC (decl)
4997 && TYPE_NEEDS_DESTRUCTOR (type)
4998 && !TREE_PERMANENT (decl))
5000 push_obstacks (&permanent_obstack, &permanent_obstack);
5001 decl = copy_node (decl);
5002 if (TREE_CODE (type) == ARRAY_TYPE)
5004 tree itype = TYPE_DOMAIN (type);
5005 if (itype && ! TREE_PERMANENT (itype))
5007 itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
5008 type = build_cplus_array_type (TREE_TYPE (type), itype);
5009 TREE_TYPE (decl) = type;
5015 /* Interesting work for this is done in `finish_exception_decl'. */
5016 if (TREE_CODE (type) == RECORD_TYPE
5017 && CLASSTYPE_DECLARED_EXCEPTION (type))
5020 /* Corresponding pop_obstacks is done in `finish_decl'. */
5021 push_obstacks_nochange ();
5024 = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
5025 ? DECL_CLASS_CONTEXT (decl)
5026 : DECL_CONTEXT (decl);
5028 if (processing_template_decl)
5031 if (TREE_CODE (decl) == FUNCTION_DECL)
5033 /* Declarator is a call_expr; extract arguments from it, since
5034 grokdeclarator didn't do it. */
5036 args = copy_to_permanent (last_function_parms);
5037 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
5039 tree t = TREE_TYPE (decl);
5041 t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
5042 if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE)
5044 t = build_pointer_type (t); /* base type of `this' */
5046 /* I suspect this is wrong. */
5047 t = build_type_variant (t, flag_this_is_variable <= 0,
5048 0); /* type of `this' */
5050 t = build_type_variant (t, 0, 0); /* type of `this' */
5052 t = build (PARM_DECL, t, this_identifier);
5053 TREE_CHAIN (t) = args;
5057 DECL_ARGUMENTS (decl) = args;
5059 d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
5060 if (interface_unknown && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
5061 warn_if_unknown_interface ();
5062 TREE_PUBLIC (d) = TREE_PUBLIC (decl) = flag_external_templates && !interface_unknown;
5063 TREE_STATIC (d) = TREE_STATIC (decl);
5064 DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl)
5065 && !(context && !DECL_THIS_EXTERN (decl)));
5066 DECL_TEMPLATE_RESULT (d) = decl;
5070 if (context && TYPE_SIZE (context) != NULL_TREE)
5072 /* If it was not explicitly declared `extern',
5073 revoke any previous claims of DECL_EXTERNAL. */
5074 if (DECL_THIS_EXTERN (decl) == 0)
5075 DECL_EXTERNAL (decl) = 0;
5076 if (DECL_LANG_SPECIFIC (decl))
5077 DECL_IN_AGGR_P (decl) = 0;
5078 pushclass (context, 2);
5081 /* If this type of object needs a cleanup, and control may
5082 jump past it, make a new binding level so that it is cleaned
5083 up only when it is initialized first. */
5084 if (TYPE_NEEDS_DESTRUCTOR (type)
5085 && current_binding_level->more_cleanups_ok == 0)
5086 pushlevel_temporary (1);
5089 /* Is it valid for this decl to have an initializer at all?
5090 If not, set INITIALIZED to zero, which will indirectly
5091 tell `finish_decl' to ignore the initializer once it is parsed. */
5092 switch (TREE_CODE (decl))
5095 /* typedef foo = bar means give foo the same type as bar.
5096 We haven't parsed bar yet, so `finish_decl' will fix that up.
5097 Any other case of an initialization in a TYPE_DECL is an error. */
5098 if (pedantic || list_length (declspecs) > 1)
5100 cp_error ("typedef `%D' is initialized", decl);
5106 cp_error ("function `%#D' is initialized like a variable", decl);
5111 /* Don't allow initializations for incomplete types except for
5112 arrays which might be completed by the initialization. */
5113 if (TYPE_SIZE (type) != NULL_TREE)
5114 ; /* A complete type is ok. */
5115 else if (TREE_CODE (type) != ARRAY_TYPE)
5117 cp_error ("variable `%#D' has initializer but incomplete type",
5121 else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE)
5123 cp_error ("elements of array `%#D' have incomplete type", decl);
5129 && TREE_CODE (decl) != TYPE_DECL
5130 && TREE_CODE (decl) != TEMPLATE_DECL
5131 && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
5133 if (TYPE_SIZE (type) == NULL_TREE)
5135 cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
5137 /* Change the type so that assemble_variable will give
5138 DECL an rtl we can live with: (mem (const_int 0)). */
5139 TREE_TYPE (decl) = error_mark_node;
5140 type = error_mark_node;
5144 /* If any base type in the hierarchy of TYPE needs a constructor,
5145 then we set initialized to 1. This way any nodes which are
5146 created for the purposes of initializing this aggregate
5147 will live as long as it does. This is necessary for global
5148 aggregates which do not have their initializers processed until
5149 the end of the file. */
5150 initialized = TYPE_NEEDS_CONSTRUCTING (type);
5156 if (current_binding_level != global_binding_level
5157 && DECL_EXTERNAL (decl))
5158 cp_warning ("declaration of `%#D' has `extern' and is initialized",
5160 DECL_EXTERNAL (decl) = 0;
5161 if (current_binding_level == global_binding_level)
5162 TREE_STATIC (decl) = 1;
5164 /* Tell `pushdecl' this is an initialized decl
5165 even though we don't yet have the initializer expression.
5166 Also tell `finish_decl' it may store the real initializer. */
5167 DECL_INITIAL (decl) = error_mark_node;
5170 /* Add this decl to the current binding level, but not if it
5171 comes from another scope, e.g. a static member variable.
5172 TEM may equal DECL or it may be a previous decl of the same name. */
5173 if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
5174 || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
5175 || TREE_CODE (type) == LANG_TYPE)
5178 tem = pushdecl (decl);
5180 /* Tell the back-end to use or not use .common as appropriate. */
5181 DECL_COMMON (tem) = flag_conserve_space;
5184 /* We don't do this yet for GNU C++. */
5185 /* For a local variable, define the RTL now. */
5186 if (current_binding_level != global_binding_level
5187 /* But not if this is a duplicate decl
5188 and we preserved the rtl from the previous one
5189 (which may or may not happen). */
5190 && DECL_RTL (tem) == NULL_RTX)
5192 if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
5194 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
5195 && DECL_INITIAL (tem) != NULL_TREE)
5200 if (TREE_CODE (decl) == TEMPLATE_DECL)
5202 tree result = DECL_TEMPLATE_RESULT (decl);
5203 if (DECL_CONTEXT (result) != NULL_TREE)
5206 type = DECL_CONTEXT (result);
5208 if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE)
5210 cp_error ("declaration of `%D' in non-template type `%T'",
5215 if (/* TREE_CODE (result) == VAR_DECL */ 1)
5218 tree tmpl = UPT_TEMPLATE (type);
5220 fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
5221 print_node_brief (stderr, "", DECL_NAME (tem), 0);
5222 fprintf (stderr, " to class %s\n",
5223 IDENTIFIER_POINTER (DECL_NAME (tmpl)));
5224 DECL_TEMPLATE_MEMBERS (tmpl)
5225 = perm_tree_cons (DECL_NAME (tem), tem,
5226 DECL_TEMPLATE_MEMBERS (tmpl));
5230 my_friendly_abort (13);
5232 else if (TREE_CODE (result) == FUNCTION_DECL)
5233 /*tem = push_overloaded_decl (tem, 0)*/;
5234 else if (TREE_CODE (result) == VAR_DECL
5235 || TREE_CODE (result) == TYPE_DECL)
5237 cp_error ("invalid template `%#D'", result);
5241 my_friendly_abort (14);
5245 && ! (TREE_CODE (tem) == PARM_DECL
5246 || (TREE_READONLY (tem)
5247 && (TREE_CODE (tem) == VAR_DECL
5248 || TREE_CODE (tem) == FIELD_DECL))))
5250 /* When parsing and digesting the initializer,
5251 use temporary storage. Do this even if we will ignore the value. */
5252 if (current_binding_level == global_binding_level && debug_temp_inits)
5254 if (TYPE_NEEDS_CONSTRUCTING (type) || TREE_CODE (type) == REFERENCE_TYPE)
5255 /* In this case, the initializer must lay down in permanent
5256 storage, since it will be saved until `finish_file' is run. */
5259 temporary_allocation ();
5264 cadillac_start_decl (tem);
5271 make_temporary_for_reference (decl, ctor_call, init, cleanupp)
5272 tree decl, ctor_call, init;
5275 tree type = TREE_TYPE (decl);
5276 tree target_type = TREE_TYPE (type);
5281 tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
5282 if (TREE_CODE (tmp_addr) == NOP_EXPR)
5283 tmp_addr = TREE_OPERAND (tmp_addr, 0);
5284 my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146);
5285 tmp = TREE_OPERAND (tmp_addr, 0);
5289 tmp = get_temp_name (target_type,
5290 current_binding_level == global_binding_level);
5291 tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
5294 TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
5295 DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr);
5296 TREE_TYPE (DECL_INITIAL (decl)) = type;
5297 if (TYPE_NEEDS_CONSTRUCTING (target_type))
5299 if (current_binding_level == global_binding_level)
5301 /* lay this variable out now. Otherwise `output_addressed_constants'
5302 gets confused by its initializer. */
5303 make_decl_rtl (tmp, NULL_PTR, 1);
5304 static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
5308 if (ctor_call != NULL_TREE)
5311 init = build_method_call (tmp, constructor_name_full (target_type),
5312 build_tree_list (NULL_TREE, init),
5313 NULL_TREE, LOOKUP_NORMAL);
5314 DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
5315 DECL_INITIAL (decl));
5316 *cleanupp = maybe_build_cleanup (tmp);
5321 DECL_INITIAL (tmp) = init;
5322 TREE_STATIC (tmp) = current_binding_level == global_binding_level;
5323 finish_decl (tmp, init, 0, 0);
5325 if (TREE_STATIC (tmp))
5326 preserve_initializer ();
5330 /* Handle initialization of references.
5331 These three arguments from from `finish_decl', and have the
5332 same meaning here that they do there. */
5333 /* quotes on semantics can be found in ARM 8.4.3. */
5335 grok_reference_init (decl, type, init, cleanupp)
5336 tree decl, type, init;
5339 char *errstr = NULL;
5342 tree this_ptr_type, actual_init = NULL_TREE;
5344 if (init == NULL_TREE)
5346 if (DECL_LANG_SPECIFIC (decl) == 0
5347 || DECL_IN_AGGR_P (decl) == 0)
5349 cp_error ("`%D' declared as reference but not initialized", decl);
5350 if (TREE_CODE (decl) == VAR_DECL)
5351 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
5356 if (init == error_mark_node)
5359 if (TREE_CODE (type) == REFERENCE_TYPE
5360 && TREE_CODE (init) == CONSTRUCTOR)
5362 cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
5366 if (TREE_CODE (init) == TREE_LIST)
5367 init = build_compound_expr (init);
5368 is_reference = TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE;
5369 tmp = is_reference ? convert_from_reference (init) : init;
5371 if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
5372 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
5374 /* Note: default conversion is only called in very
5376 init = default_conversion (init);
5379 /* Can we just enreference this lvalue? */
5380 if ((is_reference || lvalue_p (init)
5381 || (actual_init = unary_complex_lvalue (ADDR_EXPR, init)))
5382 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
5383 TYPE_MAIN_VARIANT (TREE_TYPE (tmp)), 0))
5385 /* This section implements ANSI C++ June 5 1992 WP 8.4.3.5. */
5387 /* A reference to a volatile T cannot be initialized with
5388 a const T, and vice-versa. */
5389 if (TYPE_VOLATILE (TREE_TYPE (type)) && TREE_READONLY (init))
5390 errstr = "cannot initialize a reference to a volatile `%T' with a const `%T'";
5391 else if (TYPE_READONLY (TREE_TYPE (type)) && TREE_THIS_VOLATILE (init))
5392 errstr = "cannot initialize a reference to a const `%T' with a volatile `%T'";
5393 /* A reference to a plain T can be initialized only with a plain T. */
5394 else if (!TYPE_VOLATILE (TREE_TYPE (type))
5395 && !TYPE_READONLY (TREE_TYPE (type)))
5397 if (TREE_READONLY (init))
5398 errstr = "cannot initialize a reference to `%T' with a const `%T'";
5399 else if (TREE_THIS_VOLATILE (init))
5400 errstr = "cannot initialize a reference to `%T' with a volatile `%T'";
5404 cp_error (errstr, TREE_TYPE (type), TREE_TYPE (tmp));
5408 /* OK, can we generate a reference then? */
5409 else if ((actual_init = convert_to_reference
5410 (decl, type, init, 0, 0, "initialization", 0,
5411 LOOKUP_SPECULATIVELY|LOOKUP_NORMAL)))
5413 if (actual_init == error_mark_node)
5419 /* OK, try going through a temporary. */
5420 else if ((actual_init = convert_to_reference
5421 (error_mark_node, type, init, 0, 0, "initialization",
5424 if (actual_init == error_mark_node)
5430 if (TREE_CODE (init) == WITH_CLEANUP_EXPR)
5432 /* Associate the cleanup with the reference so that we
5433 don't get burned by "aggressive" cleanup policy. */
5434 *cleanupp = TREE_OPERAND (init, 2);
5435 TREE_OPERAND (init, 2) = error_mark_node;
5440 cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
5444 /* In the case of initialization, it is permissible
5445 to assign one reference to another. */
5446 this_ptr_type = build_pointer_type (TREE_TYPE (type));
5450 if (TREE_SIDE_EFFECTS (init))
5451 DECL_INITIAL (decl) = save_expr (init);
5453 DECL_INITIAL (decl) = init;
5455 else if (lvalue_p (init))
5457 tmp = build_unary_op (ADDR_EXPR, init, 0);
5458 if (TREE_CODE (tmp) == ADDR_EXPR
5459 && TREE_CODE (TREE_OPERAND (tmp, 0)) == WITH_CLEANUP_EXPR)
5461 if (*cleanupp) my_friendly_abort (1);
5462 *cleanupp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 2);
5463 TREE_OPERAND (TREE_OPERAND (tmp, 0), 2) = error_mark_node;
5465 if (IS_AGGR_TYPE (TREE_TYPE (this_ptr_type)))
5466 DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), tmp);
5468 DECL_INITIAL (decl) = convert (this_ptr_type, tmp);
5470 DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
5471 if (DECL_INITIAL (decl) == current_class_decl)
5472 DECL_INITIAL (decl) = copy_node (current_class_decl);
5473 TREE_TYPE (DECL_INITIAL (decl)) = type;
5475 /* If actual_init is set here, it is set from the first check above. */
5476 else if (actual_init)
5478 /* The initializer for this decl goes into its
5479 DECL_REFERENCE_SLOT. Make sure that we can handle
5480 multiple evaluations without ill effect. */
5481 if (TREE_CODE (actual_init) == ADDR_EXPR
5482 && TREE_CODE (TREE_OPERAND (actual_init, 0)) == TARGET_EXPR)
5483 actual_init = save_expr (actual_init);
5484 DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), actual_init);
5485 DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
5486 TREE_TYPE (DECL_INITIAL (decl)) = type;
5489 my_friendly_abort (1);
5491 /* ?? Can this be optimized in some cases to
5492 hand back the DECL_INITIAL slot?? */
5493 if (TYPE_SIZE (TREE_TYPE (type)))
5495 init = convert_from_reference (decl);
5496 if (TREE_PERMANENT (decl))
5497 init = copy_to_permanent (init);
5498 SET_DECL_REFERENCE_SLOT (decl, init);
5501 if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
5503 expand_static_init (decl, DECL_INITIAL (decl));
5504 DECL_INITIAL (decl) = NULL_TREE;
5509 if (TREE_CODE (decl) == VAR_DECL)
5510 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
5514 /* Finish processing of a declaration;
5515 install its line number and initial value.
5516 If the length of an array type is not known before,
5517 it must be determined now, from the initial value, or it is an error.
5519 Call `pop_obstacks' iff NEED_POP is nonzero.
5521 For C++, `finish_decl' must be fairly evasive: it must keep initializers
5522 for aggregates that have constructors alive on the permanent obstack,
5523 so that the global initializing functions can be written at the end.
5525 INIT0 holds the value of an initializer that should be allowed to escape
5528 For functions that take default parameters, DECL points to its
5529 "maximal" instantiation. `finish_decl' must then also declared its
5530 subsequently lower and lower forms of instantiation, checking for
5531 ambiguity as it goes. This can be sped up later. */
5534 finish_decl (decl, init, asmspec_tree, need_pop)
5540 tree cleanup = NULL_TREE, ttype;
5542 int temporary = allocation_temporary_p ();
5543 char *asmspec = NULL;
5544 int was_readonly = 0;
5546 /* If this is 0, then we did not change obstacks. */
5550 error ("assignment (not initialization) in declaration");
5556 asmspec = TREE_STRING_POINTER (asmspec_tree);
5557 /* Zero out old RTL, since we will rewrite it. */
5558 DECL_RTL (decl) = NULL_RTX;
5561 /* If the type of the thing we are declaring either has
5562 a constructor, or has a virtual function table pointer,
5563 AND its initialization was accepted by `start_decl',
5564 then we stayed on the permanent obstack through the
5565 declaration, otherwise, changed obstacks as GCC would. */
5567 type = TREE_TYPE (decl);
5569 was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
5571 /* Take care of TYPE_DECLs up front. */
5572 if (TREE_CODE (decl) == TYPE_DECL)
5574 if (init && DECL_INITIAL (decl))
5576 /* typedef foo = bar; store the type of bar as the type of foo. */
5577 TREE_TYPE (decl) = type = TREE_TYPE (init);
5578 DECL_INITIAL (decl) = init = NULL_TREE;
5580 if (IS_AGGR_TYPE (type) && DECL_NAME (decl))
5582 if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
5583 cp_warning ("shadowing previous type declaration of `%#D'", decl);
5584 set_identifier_type_value (DECL_NAME (decl), type);
5585 CLASSTYPE_GOT_SEMICOLON (type) = 1;
5587 GNU_xref_decl (current_function_decl, decl);
5588 rest_of_decl_compilation (decl, NULL_PTR,
5589 DECL_CONTEXT (decl) == NULL_TREE, 0);
5592 if (type != error_mark_node && IS_AGGR_TYPE (type)
5593 && CLASSTYPE_DECLARED_EXCEPTION (type))
5595 finish_exception_decl (NULL_TREE, decl);
5596 CLASSTYPE_GOT_SEMICOLON (type) = 1;
5599 if (TREE_CODE (decl) != FUNCTION_DECL)
5601 ttype = target_type (type);
5603 Leave this out until we can figure out why it was
5604 needed/desirable in the first place. Then put a comment
5605 here explaining why. Or just delete the code if no ill
5607 if (TYPE_NAME (ttype)
5608 && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
5609 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
5611 tree old_id = TYPE_IDENTIFIER (ttype);
5612 char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
5613 /* Need to preserve template data for UPT nodes. */
5614 tree old_template = IDENTIFIER_TEMPLATE (old_id);
5616 bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
5617 IDENTIFIER_LENGTH (old_id) + 1);
5618 old_id = get_identifier (newname);
5619 lookup_tag_reverse (ttype, old_id);
5620 TYPE_IDENTIFIER (ttype) = old_id;
5621 IDENTIFIER_TEMPLATE (old_id) = old_template;
5626 if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
5627 && TYPE_NEEDS_CONSTRUCTING (type))
5630 /* Currently, GNU C++ puts constants in text space, making them
5631 impossible to initialize. In the future, one would hope for
5632 an operating system which understood the difference between
5633 initialization and the running of a program. */
5635 TREE_READONLY (decl) = 0;
5638 if (TREE_CODE (decl) == FIELD_DECL)
5640 if (init && init != error_mark_node)
5641 my_friendly_assert (TREE_PERMANENT (init), 147);
5645 /* This must override the asm specifier which was placed
5646 by grokclassfn. Lay this out fresh.
5648 @@ Should emit an error if this redefines an asm-specified
5649 @@ name, or if we have already used the function's name. */
5650 DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
5651 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
5652 make_decl_rtl (decl, asmspec, 0);
5655 /* If `start_decl' didn't like having an initialization, ignore it now. */
5656 else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
5658 else if (DECL_EXTERNAL (decl))
5660 else if (TREE_CODE (type) == REFERENCE_TYPE
5661 || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
5663 grok_reference_init (decl, type, init, &cleanup);
5667 GNU_xref_decl (current_function_decl, decl);
5669 if (TREE_CODE (decl) == FIELD_DECL || DECL_EXTERNAL (decl))
5671 else if (TREE_CODE (decl) == CONST_DECL)
5673 my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
5675 DECL_INITIAL (decl) = init;
5677 /* This will keep us from needing to worry about our obstacks. */
5678 my_friendly_assert (init != NULL_TREE, 149);
5683 if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
5685 if (TREE_CODE (type) == ARRAY_TYPE)
5686 init = digest_init (type, init, (tree *) 0);
5687 else if (TREE_CODE (init) == CONSTRUCTOR
5688 && CONSTRUCTOR_ELTS (init) != NULL_TREE)
5690 if (TYPE_NEEDS_CONSTRUCTING (type))
5692 cp_error ("`%D' must be initialized by constructor, not by `{...}'", decl);
5693 init = error_mark_node;
5696 goto dont_use_constructor;
5699 /* fix this in `build_functional_cast' instead.
5700 Here's the trigger code:
5705 ostream (int, char *);
5712 int buf_size = 1024;
5713 static char buf[buf_size];
5714 const char *debug(int i) {
5716 ostream o = ostream(buf_size, b);
5722 else if (TREE_CODE (init) == TARGET_EXPR
5723 && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR))
5725 /* User wrote something like `foo x = foo (args)' */
5726 my_friendly_assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL, 150);
5727 my_friendly_assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE, 151);
5729 /* User wrote exactly `foo x = foo (args)' */
5730 if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init))
5732 init = build (CALL_EXPR, TREE_TYPE (init),
5733 TREE_OPERAND (TREE_OPERAND (init, 1), 0),
5734 TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0);
5735 TREE_SIDE_EFFECTS (init) = 1;
5740 /* We must hide the initializer so that expand_decl
5741 won't try to do something it does not understand. */
5742 if (current_binding_level == global_binding_level)
5745 if (flag_conserve_space)
5746 /* If we say -fconserve-space, we want this to save
5747 space, at the expense of wrong semantics. */
5748 /* Should this be a NULL_TREE? */
5749 value = error_mark_node;
5751 /* If we say -fno-conserve-space, we want this to
5752 produce errors about redefs, to do this we make it
5753 go in the data space */
5754 value = digest_init (type, empty_init_node, (tree *) 0);
5755 DECL_INITIAL (decl) = value;
5758 DECL_INITIAL (decl) = error_mark_node;
5762 dont_use_constructor:
5763 if (TREE_CODE (init) != TREE_VEC)
5764 init = store_init_value (decl, init);
5767 /* Don't let anyone try to initialize this variable
5768 until we are ready to do so. */
5769 DECL_INITIAL (decl) = error_mark_node;
5772 else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
5773 && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
5776 while (TREE_CODE (ctype) == ARRAY_TYPE)
5777 ctype = TREE_TYPE (ctype);
5778 if (! TYPE_NEEDS_CONSTRUCTING (ctype))
5780 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
5781 cp_error ("structure `%D' with uninitialized const members", decl);
5782 if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
5783 cp_error ("structure `%D' with uninitialized reference members", decl);
5786 if (TREE_CODE (decl) == VAR_DECL
5787 && !DECL_INITIAL (decl)
5788 && !TYPE_NEEDS_CONSTRUCTING (type)
5789 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
5790 cp_error ("uninitialized const `%D'", decl);
5792 /* Initialize variables in need of static initialization
5793 with `empty_init_node' to keep assemble_variable from putting them
5794 in the wrong program space. (Common storage is okay for non-public
5795 uninitialized data; the linker can't match it with storage from other
5796 files, and we may save some disk space.) */
5798 && TREE_STATIC (decl)
5799 && TREE_PUBLIC (decl)
5800 && ! DECL_EXTERNAL (decl)
5801 && TREE_CODE (decl) == VAR_DECL
5802 && TYPE_NEEDS_CONSTRUCTING (type)
5803 && (DECL_INITIAL (decl) == NULL_TREE
5804 || DECL_INITIAL (decl) == error_mark_node)
5805 /* If we say -fconserve-space, we want this to save space,
5806 at the expense of wrong semantics. */
5807 && ! flag_conserve_space)
5809 tree value = digest_init (type, empty_init_node, (tree *) 0);
5810 DECL_INITIAL (decl) = value;
5813 else if (TREE_CODE (decl) == VAR_DECL
5814 && TREE_CODE (type) != REFERENCE_TYPE
5815 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
5817 /* ``Unless explicitly declared extern, a const object does not have
5818 external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
5819 However, if it's `const int foo = 1; const int foo;', don't complain
5820 about the second decl, since it does have an initializer before.
5821 We deliberately don't complain about arrays, because they're
5822 supposed to be initialized by a constructor. */
5823 if (! DECL_INITIAL (decl)
5824 && TREE_CODE (type) != ARRAY_TYPE
5825 && (!pedantic || !current_class_type))
5826 cp_error ("uninitialized const `%#D'", decl);
5829 /* For top-level declaration, the initial value was read in
5830 the temporary obstack. MAXINDEX, rtl, etc. to be made below
5831 must go in the permanent obstack; but don't discard the
5832 temporary data yet. */
5834 if (current_binding_level == global_binding_level && temporary)
5835 end_temporary_allocation ();
5837 /* Deduce size of array from initialization, if not already known. */
5839 if (TREE_CODE (type) == ARRAY_TYPE
5840 && TYPE_DOMAIN (type) == NULL_TREE
5841 && TREE_CODE (decl) != TYPE_DECL)
5844 = (TREE_STATIC (decl)
5845 /* Even if pedantic, an external linkage array
5846 may have incomplete type at first. */
5847 ? pedantic && ! DECL_EXTERNAL (decl)
5848 : !DECL_EXTERNAL (decl));
5849 tree initializer = init ? init : DECL_INITIAL (decl);
5850 int failure = complete_array_type (type, initializer, do_default);
5853 cp_error ("initializer fails to determine size of `%D'", decl);
5858 cp_error ("array size missing in `%D'", decl);
5859 /* If a `static' var's size isn't known, make it extern as
5860 well as static, so it does not get allocated. If it's not
5861 `static', then don't mark it extern; finish_incomplete_decl
5862 will give it a default size and it will get allocated. */
5863 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
5864 DECL_EXTERNAL (decl) = 1;
5867 if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
5868 && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
5870 cp_error ("zero-size array `%D'", decl);
5872 layout_decl (decl, 0);
5875 if (TREE_CODE (decl) == VAR_DECL)
5877 if (DECL_SIZE (decl) == NULL_TREE
5878 && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
5879 layout_decl (decl, 0);
5881 if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
5883 /* A static variable with an incomplete type:
5884 that is an error if it is initialized.
5885 Otherwise, let it through, but if it is not `extern'
5886 then it may cause an error message later. */
5887 if (DECL_INITIAL (decl) != NULL_TREE)
5888 cp_error ("storage size of `%D' isn't known", decl);
5891 else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
5893 /* An automatic variable with an incomplete type: that is an error.
5894 Don't talk about array types here, since we took care of that
5895 message in grokdeclarator. */
5896 cp_error ("storage size of `%D' isn't known", decl);
5897 TREE_TYPE (decl) = error_mark_node;
5899 else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
5900 /* Let debugger know it should output info for this type. */
5901 note_debug_info_needed (ttype);
5903 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
5904 && DECL_SIZE (decl) != NULL_TREE
5905 && ! TREE_CONSTANT (DECL_SIZE (decl)))
5907 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
5908 constant_expression_warning (DECL_SIZE (decl));
5910 cp_error ("storage size of `%D' isn't constant", decl);
5913 if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
5915 int yes = suspend_momentary ();
5917 /* If INIT comes from a functional cast, use the cleanup
5918 we built for that. Otherwise, make our own cleanup. */
5919 if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
5920 && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
5922 cleanup = TREE_OPERAND (init, 2);
5923 init = TREE_OPERAND (init, 0);
5924 current_binding_level->have_cleanups = 1;
5925 current_binding_level->more_exceptions_ok = 0;
5928 cleanup = maybe_build_cleanup (decl);
5929 resume_momentary (yes);
5932 /* PARM_DECLs get cleanups, too. */
5933 else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
5936 end_temporary_allocation ();
5937 cleanup = maybe_build_cleanup (decl);
5939 resume_temporary_allocation ();
5942 /* Output the assembler code and/or RTL code for variables and functions,
5943 unless the type is an undefined structure or union.
5944 If not, it will get done when the type is completed. */
5946 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
5947 || TREE_CODE (decl) == RESULT_DECL)
5949 /* ??? FIXME: What about nested classes? */
5950 int toplev = (current_binding_level == global_binding_level
5951 || pseudo_global_level_p ());
5953 = ((flag_traditional
5954 || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
5955 && allocation_temporary_p ());
5958 end_temporary_allocation ();
5960 /* If we are in need of a cleanup, get out of any implicit
5961 handlers that have been established so far. */
5962 if (cleanup && current_binding_level->parm_flag == 3)
5964 pop_implicit_try_blocks (decl);
5965 current_binding_level->more_exceptions_ok = 0;
5968 if (TREE_CODE (decl) == VAR_DECL
5969 && current_binding_level != global_binding_level
5970 && ! TREE_STATIC (decl)
5971 && type_needs_gc_entry (type))
5972 DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
5974 if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
5975 make_decl_rtl (decl, NULL_PTR, toplev);
5976 else if (TREE_CODE (decl) == VAR_DECL
5977 && TREE_READONLY (decl)
5978 && DECL_INITIAL (decl) != NULL_TREE
5979 && DECL_INITIAL (decl) != error_mark_node
5980 && DECL_INITIAL (decl) != empty_init_node)
5982 DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
5985 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
5988 && TREE_STATIC (decl)
5989 && ! TREE_SIDE_EFFECTS (decl)
5990 && ! TREE_PUBLIC (decl)
5991 && ! DECL_EXTERNAL (decl)
5992 && ! TYPE_NEEDS_DESTRUCTOR (type)
5993 && DECL_MODE (decl) != BLKmode)
5995 /* If this variable is really a constant, then fill its DECL_RTL
5996 slot with something which won't take up storage.
5997 If something later should take its address, we can always give
5998 it legitimate RTL at that time. */
5999 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
6000 store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
6001 TREE_ASM_WRITTEN (decl) = 1;
6005 /* Keep GCC from complaining that this variable
6006 is defined but never used. */
6007 TREE_USED (decl) = 1;
6008 /* If this is a static const, change its apparent linkage
6009 if it belongs to a #pragma interface. */
6010 if (TREE_STATIC (decl) && !interface_unknown)
6012 TREE_PUBLIC (decl) = 1;
6013 DECL_EXTERNAL (decl) = interface_only;
6015 make_decl_rtl (decl, asmspec, toplev);
6018 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6020 else if (TREE_CODE (decl) == VAR_DECL
6021 && DECL_LANG_SPECIFIC (decl)
6022 && DECL_IN_AGGR_P (decl))
6024 if (TREE_STATIC (decl))
6026 if (init == NULL_TREE
6027 #ifdef DEFAULT_STATIC_DEFS
6028 /* If this code is dead, then users must
6029 explicitly declare static member variables
6030 outside the class def'n as well. */
6031 && TYPE_NEEDS_CONSTRUCTING (type)
6035 DECL_EXTERNAL (decl) = 1;
6036 make_decl_rtl (decl, asmspec, 1);
6039 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6042 /* Just a constant field. Should not need any rtl. */
6046 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6049 resume_temporary_allocation ();
6051 if (type != error_mark_node
6052 && TYPE_LANG_SPECIFIC (type)
6053 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
6054 abstract_virtuals_error (decl, type);
6055 else if ((TREE_CODE (type) == FUNCTION_TYPE
6056 || TREE_CODE (type) == METHOD_TYPE)
6057 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6058 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
6059 abstract_virtuals_error (decl, TREE_TYPE (type));
6061 if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
6062 signature_error (decl, type);
6063 else if ((TREE_CODE (type) == FUNCTION_TYPE
6064 || TREE_CODE (type) == METHOD_TYPE)
6065 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6066 && IS_SIGNATURE (TREE_TYPE (type)))
6067 signature_error (decl, TREE_TYPE (type));
6069 if (TREE_CODE (decl) == FUNCTION_DECL)
6072 /* C++: Handle overloaded functions with default parameters. */
6073 if (DECL_OVERLOADED (decl))
6075 tree parmtypes = TYPE_ARG_TYPES (type);
6076 tree prev = NULL_TREE;
6077 tree original_name = DECL_NAME (decl);
6078 struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl);
6079 /* All variants will share an uncollectible lang_decl. */
6080 copy_decl_lang_specific (decl);
6082 while (parmtypes && parmtypes != void_list_node)
6084 /* The default value for the parameter in parmtypes is
6085 stored in the TREE_PURPOSE of the TREE_LIST. */
6086 if (TREE_PURPOSE (parmtypes))
6088 tree fnname, fndecl;
6091 argp = prev ? & TREE_CHAIN (prev)
6092 : & TYPE_ARG_TYPES (type);
6095 fnname = build_decl_overload (original_name, TYPE_ARG_TYPES (type), 0);
6097 fndecl = build_decl (FUNCTION_DECL, fnname, type);
6098 DECL_EXTERNAL (fndecl) = DECL_EXTERNAL (decl);
6099 TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl);
6100 DECL_INLINE (fndecl) = DECL_INLINE (decl);
6101 /* Keep G++ from thinking this function is unused.
6102 It is only used to speed up search in name space. */
6103 TREE_USED (fndecl) = 1;
6104 TREE_ASM_WRITTEN (fndecl) = 1;
6105 DECL_INITIAL (fndecl) = NULL_TREE;
6106 DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl);
6107 fndecl = pushdecl (fndecl);
6108 DECL_INITIAL (fndecl) = error_mark_node;
6109 DECL_RTL (fndecl) = DECL_RTL (decl);
6112 parmtypes = TREE_CHAIN (parmtypes);
6114 DECL_LANG_SPECIFIC (decl) = tmp_lang_decl;
6118 else if (DECL_EXTERNAL (decl))
6120 else if (TREE_STATIC (decl) && type != error_mark_node)
6122 /* Cleanups for static variables are handled by `finish_file'. */
6123 if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE)
6124 expand_static_init (decl, init);
6125 else if (TYPE_NEEDS_DESTRUCTOR (type))
6126 static_aggregates = perm_tree_cons (NULL_TREE, decl,
6129 /* Make entry in appropriate vector. */
6130 if (flag_gc && type_needs_gc_entry (type))
6131 build_static_gc_entry (decl, type);
6135 /* This is a declared decl which must live until the
6136 end of the binding contour. It may need a cleanup. */
6138 /* Recompute the RTL of a local array now
6139 if it used to be an incomplete type. */
6140 if (was_incomplete && ! TREE_STATIC (decl))
6142 /* If we used it already as memory, it must stay in memory. */
6143 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
6144 /* If it's still incomplete now, no init will save it. */
6145 if (DECL_SIZE (decl) == NULL_TREE)
6146 DECL_INITIAL (decl) = NULL_TREE;
6149 else if (! TREE_ASM_WRITTEN (decl)
6150 && (TYPE_SIZE (type) != NULL_TREE
6151 || TREE_CODE (type) == ARRAY_TYPE))
6153 /* Do this here, because we did not expand this decl's
6154 rtl in start_decl. */
6155 if (DECL_RTL (decl) == NULL_RTX)
6159 expand_decl_cleanup (NULL_TREE, cleanup);
6160 /* Cleanup used up here. */
6161 cleanup = NULL_TREE;
6165 if (DECL_SIZE (decl) && type != error_mark_node)
6167 /* Compute and store the initial value. */
6168 expand_decl_init (decl);
6170 if (init || TYPE_NEEDS_CONSTRUCTING (type))
6172 emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
6173 expand_aggr_init (decl, init, 0);
6176 /* Set this to 0 so we can tell whether an aggregate
6177 which was initialized was ever used. */
6178 if (TYPE_NEEDS_CONSTRUCTING (type))
6179 TREE_USED (decl) = 0;
6181 /* Store the cleanup, if there was one. */
6184 if (! expand_decl_cleanup (decl, cleanup))
6185 cp_error ("parser lost in parsing declaration of `%D'", decl);
6191 /* Undo call to `pushclass' that was done in `start_decl'
6192 due to initialization of qualified member variable.
6193 I.e., Foo::x = 10; */
6195 tree context = DECL_CONTEXT (decl);
6197 && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
6198 && (TREE_CODE (decl) == VAR_DECL
6199 /* We also have a pushclass done that we need to undo here
6200 if we're at top level and declare a method. */
6201 || (TREE_CODE (decl) == FUNCTION_DECL
6202 /* If size hasn't been set, we're still defining it,
6203 and therefore inside the class body; don't pop
6204 the binding level.. */
6205 && TYPE_SIZE (context) != NULL_TREE
6206 /* The binding level gets popped elsewhere for a
6207 friend declaration inside another class. */
6209 && TYPE_IDENTIFIER (context) == current_class_name
6211 && context == current_class_type
6221 /* Resume permanent allocation, if not within a function. */
6222 /* The corresponding push_obstacks_nochange is in start_decl,
6223 start_method, groktypename, and in grokfield. */
6228 TREE_READONLY (decl) = 1;
6231 cadillac_finish_decl (decl);
6235 expand_static_init (decl, init)
6239 tree oldstatic = value_member (decl, static_aggregates);
6242 if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
6243 cp_error ("multiple initializations given for `%D'", decl);
6245 else if (current_binding_level != global_binding_level)
6247 /* Emit code to perform this initialization but once. */
6250 /* Remember this information until end of file. */
6251 push_obstacks (&permanent_obstack, &permanent_obstack);
6253 /* Emit code to perform this initialization but once. */
6254 temp = get_temp_name (integer_type_node, 1);
6255 rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
6256 expand_start_cond (build_binary_op (EQ_EXPR, temp,
6257 integer_zero_node, 1), 0);
6258 expand_assignment (temp, integer_one_node, 0, 0);
6259 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6261 expand_aggr_init (decl, init, 0);
6262 do_pending_stack_adjust ();
6265 expand_assignment (decl, init, 0, 0);
6267 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
6269 static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
6270 TREE_STATIC (static_aggregates) = 1;
6273 /* Resume old (possibly temporary) allocation. */
6278 /* This code takes into account memory allocation
6279 policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING
6280 does not hold for this object, then we must make permanent
6281 the storage currently in the temporary obstack. */
6282 if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6283 preserve_initializer ();
6284 static_aggregates = perm_tree_cons (init, decl, static_aggregates);
6288 /* Make TYPE a complete type based on INITIAL_VALUE.
6289 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
6290 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
6293 complete_array_type (type, initial_value, do_default)
6294 tree type, initial_value;
6297 register tree maxindex = NULL_TREE;
6302 /* Note MAXINDEX is really the maximum index,
6303 one less than the size. */
6304 if (TREE_CODE (initial_value) == STRING_CST)
6305 maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
6306 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
6309 = list_length (CONSTRUCTOR_ELTS (initial_value));
6310 maxindex = build_int_2 (nelts - 1, - (nelts == 0));
6314 /* Make an error message unless that happened already. */
6315 if (initial_value != error_mark_node)
6318 /* Prevent further error messages. */
6319 maxindex = build_int_2 (0, 0);
6326 maxindex = build_int_2 (0, 0);
6334 TYPE_DOMAIN (type) = build_index_type (maxindex);
6335 if (!TREE_TYPE (maxindex))
6336 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
6338 itype = TREE_TYPE (initial_value);
6341 if (itype && !TYPE_DOMAIN (itype))
6342 TYPE_DOMAIN (itype) = TYPE_DOMAIN (type);
6345 /* Lay out the type now that we can get the real answer. */
6352 /* Return zero if something is declared to be a member of type
6353 CTYPE when in the context of CUR_TYPE. STRING is the error
6354 message to print in that case. Otherwise, quietly return 1. */
6356 member_function_or_else (ctype, cur_type, string)
6357 tree ctype, cur_type;
6360 if (ctype && ctype != cur_type)
6362 error (string, TYPE_NAME_STRING (ctype));
6368 /* Subroutine of `grokdeclarator'. */
6370 /* Generate errors possibly applicable for a given set of specifiers.
6371 This is for ARM $7.1.2. */
6373 bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
6376 int virtualp, quals, friendp, raises, inlinep;
6379 cp_error ("`%D' declared as a `virtual' %s", object, type);
6381 cp_error ("`%D' declared as an `inline' %s", object, type);
6383 cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", object, type);
6385 cp_error_at ("invalid friend declaration", object);
6387 cp_error_at ("invalid raises declaration", object);
6390 /* CTYPE is class type, or null if non-class.
6391 TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
6393 DECLARATOR is the function's name.
6394 VIRTUALP is truthvalue of whether the function is virtual or not.
6395 FLAGS are to be passed through to `grokclassfn'.
6396 QUALS are qualifiers indicating whether the function is `const'
6398 RAISES is a list of exceptions that this function can raise.
6399 CHECK is 1 if we must find this method in CTYPE, 0 if we should
6400 not look, and -1 if we should not call `grokclassfn' at all. */
6402 grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, check, publicp)
6406 enum overload_flags flags;
6411 int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
6414 cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
6415 ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
6421 type = build_exception_variant (ctype, type, raises);
6422 raises = TYPE_RAISES_EXCEPTIONS (type);
6424 decl = build_lang_decl (FUNCTION_DECL, declarator, type);
6425 /* propagate volatile out from type to decl */
6426 if (TYPE_VOLATILE (type))
6427 TREE_THIS_VOLATILE (decl) = 1;
6429 /* Should probably propagate const out from type to decl I bet (mrs). */
6432 DECL_STATIC_FUNCTION_P (decl) = 1;
6433 DECL_CONTEXT (decl) = ctype;
6434 DECL_CLASS_CONTEXT (decl) = ctype;
6438 TREE_PUBLIC (decl) = 1;
6440 DECL_EXTERNAL (decl) = 1;
6441 if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
6443 cp_error ("%smember function `%D' cannot have `%T' method qualifier",
6444 (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
6448 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
6449 grok_op_properties (decl, virtualp, check < 0);
6451 /* Caller will do the rest of this. */
6455 if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
6458 /* Just handle constructors here. We could do this
6459 inside the following if stmt, but I think
6460 that the code is more legible by breaking this
6461 case out. See comments below for what each of
6462 the following calls is supposed to do. */
6463 DECL_CONSTRUCTOR_P (decl) = 1;
6465 grokclassfn (ctype, declarator, decl, flags, quals);
6467 check_classfn (ctype, declarator, decl);
6468 grok_ctor_properties (ctype, decl);
6471 /* FIXME: this should only need to look at IDENTIFIER_GLOBAL_VALUE. */
6472 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
6473 if (tmp == NULL_TREE)
6474 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
6475 else if (TREE_CODE (tmp) != TREE_CODE (decl))
6476 cp_error ("inconsistent declarations for `%D'", decl);
6479 duplicate_decls (decl, tmp);
6481 /* avoid creating circularities. */
6482 DECL_CHAIN (decl) = NULL_TREE;
6484 make_decl_rtl (decl, NULL_PTR, 1);
6491 /* Function gets the ugly name, field gets the nice one.
6492 This call may change the type of the function (because
6493 of default parameters)! */
6494 if (ctype != NULL_TREE)
6495 grokclassfn (ctype, cname, decl, flags, quals);
6497 if (ctype != NULL_TREE && check)
6498 check_classfn (ctype, cname, decl);
6500 if (ctype == NULL_TREE || check)
6503 /* Now install the declaration of this function so that
6504 others may find it (esp. its DECL_FRIENDLIST).
6505 Pretend we are at top level, we will get true
6506 reference later, perhaps.
6508 FIXME: This should only need to look at IDENTIFIER_GLOBAL_VALUE. */
6509 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
6510 if (tmp == NULL_TREE)
6511 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
6512 else if (TREE_CODE (tmp) != TREE_CODE (decl))
6513 cp_error ("inconsistent declarations for `%D'", decl);
6516 duplicate_decls (decl, tmp);
6518 /* avoid creating circularities. */
6519 DECL_CHAIN (decl) = NULL_TREE;
6521 make_decl_rtl (decl, NULL_PTR, 1);
6523 /* If this declaration supersedes the declaration of
6524 a method declared virtual in the base class, then
6525 mark this field as being virtual as well. */
6527 tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
6528 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
6530 for (i = 0; i < n_baselinks; i++)
6532 tree base_binfo = TREE_VEC_ELT (binfos, i);
6533 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)) || flag_all_virtual == 1)
6535 tmp = get_first_matching_virtual (base_binfo, decl,
6536 flags == DTOR_FLAG);
6539 /* If this function overrides some virtual in some base
6540 class, then the function itself is also necessarily
6541 virtual, even if the user didn't explicitly say so. */
6542 DECL_VIRTUAL_P (decl) = 1;
6544 /* The TMP we really want is the one from the deepest
6545 baseclass on this path, taking care not to
6546 duplicate if we have already found it (via another
6547 path to its virtual baseclass. */
6550 cp_error ("method `%D' may not be declared static", decl);
6551 cp_error_at ("(since `%D' declared virtual in base class.)", tmp);
6557 /* Disable this as we want the most recent fndecl, not the most
6559 if ((TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (base_binfo))
6560 || TYPE_USES_MULTIPLE_INHERITANCE (ctype))
6561 && BINFO_TYPE (base_binfo) != DECL_CONTEXT (tmp))
6562 tmp = get_first_matching_virtual (TYPE_BINFO (DECL_CONTEXT (tmp)),
6563 decl, flags == DTOR_FLAG);
6565 if (value_member (tmp, DECL_VINDEX (decl)) == NULL_TREE)
6567 /* The argument types may have changed... */
6568 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
6569 tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
6571 argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
6572 TREE_CHAIN (argtypes));
6573 /* But the return type has not. */
6574 type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
6577 type = build_exception_variant (ctype, type, raises);
6578 raises = TYPE_RAISES_EXCEPTIONS (type);
6580 TREE_TYPE (decl) = type;
6582 = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
6590 if (DECL_VINDEX (decl) == NULL_TREE)
6591 DECL_VINDEX (decl) = error_mark_node;
6592 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
6593 if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
6594 /* If this function is derived from a template, don't
6595 make it public. This shouldn't be here, but there's
6596 no good way to override the interface pragmas for one
6597 function or class only. Bletch. */
6598 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE
6599 && (write_virtuals == 2
6600 || (write_virtuals == 3
6601 && CLASSTYPE_INTERFACE_KNOWN (ctype))))
6602 TREE_PUBLIC (decl) = 1;
6609 grokvardecl (type, declarator, specbits, initialized)
6612 RID_BIT_TYPE specbits;
6617 if (TREE_CODE (type) == OFFSET_TYPE)
6619 /* If you declare a static member so that it
6620 can be initialized, the code will reach here. */
6621 tree field = lookup_field (TYPE_OFFSET_BASETYPE (type),
6623 if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
6625 tree basetype = TYPE_OFFSET_BASETYPE (type);
6626 error ("`%s' is not a static member of class `%s'",
6627 IDENTIFIER_POINTER (declarator),
6628 TYPE_NAME_STRING (basetype));
6629 type = TREE_TYPE (type);
6630 decl = build_lang_field_decl (VAR_DECL, declarator, type);
6631 DECL_CONTEXT (decl) = basetype;
6632 DECL_CLASS_CONTEXT (decl) = basetype;
6636 tree f_type = TREE_TYPE (field);
6637 tree o_type = TREE_TYPE (type);
6639 if (TYPE_SIZE (f_type) == NULL_TREE)
6641 if (TREE_CODE (f_type) != TREE_CODE (o_type)
6642 || (TREE_CODE (f_type) == ARRAY_TYPE
6643 && TREE_TYPE (f_type) != TREE_TYPE (o_type)))
6644 error ("redeclaration of type for `%s'",
6645 IDENTIFIER_POINTER (declarator));
6646 else if (TYPE_SIZE (o_type) != NULL_TREE)
6647 TREE_TYPE (field) = type;
6649 else if (f_type != o_type)
6650 error ("redeclaration of type for `%s'",
6651 IDENTIFIER_POINTER (declarator));
6653 if (initialized && DECL_INITIAL (decl)
6654 /* Complain about multiply-initialized
6655 member variables, but don't be faked
6656 out if initializer is faked up from `empty_init_node'. */
6657 && (TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
6658 || CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) != NULL_TREE))
6659 error_with_aggr_type (DECL_CONTEXT (decl),
6660 "multiple initializations of static member `%s::%s'",
6661 IDENTIFIER_POINTER (DECL_NAME (decl)));
6665 decl = build_decl (VAR_DECL, declarator, type);
6667 if (RIDBIT_SETP (RID_EXTERN, specbits))
6669 DECL_THIS_EXTERN (decl) = 1;
6670 DECL_EXTERNAL (decl) = !initialized;
6673 /* In class context, static means one per class,
6674 public access, and static storage. */
6675 if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
6676 && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
6678 TREE_PUBLIC (decl) = 1;
6679 TREE_STATIC (decl) = 1;
6680 DECL_EXTERNAL (decl) = !initialized;
6682 /* At top level, either `static' or no s.c. makes a definition
6683 (perhaps tentative), and absence of `static' makes it public. */
6684 else if (current_binding_level == global_binding_level)
6686 TREE_PUBLIC (decl) = RIDBIT_NOTSETP (RID_STATIC, specbits);
6687 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
6689 /* Not at top level, only `static' makes a static definition. */
6692 TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
6693 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
6698 /* Create a canonical pointer to member function type. */
6701 build_ptrmemfunc_type (type)
6708 /* If a canonical type already exists for this type, use it. We use
6709 this method instead of type_hash_canon, because it only does a
6710 simple equality check on the list of field members. */
6712 if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
6715 push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
6717 u = make_lang_type (UNION_TYPE);
6718 fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
6719 fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, delta_type_node);
6720 finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
6721 TYPE_NAME (u) = NULL_TREE;
6723 t = make_lang_type (RECORD_TYPE);
6725 /* Let the front-end know this is a pointer to member function. */
6726 TYPE_PTRMEMFUNC_FLAG(t) = 1;
6728 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, delta_type_node);
6729 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, delta_type_node);
6730 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
6731 finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
6735 /* Zap out the name so that the back-end will give us the debugging
6736 information for this anonymous RECORD_TYPE. */
6737 TYPE_NAME (t) = NULL_TREE;
6739 TYPE_SET_PTRMEMFUNC_TYPE (type, t);
6741 /* Seems to be wanted. */
6742 CLASSTYPE_GOT_SEMICOLON (t) = 1;
6746 /* Given declspecs and a declarator,
6747 determine the name and type of the object declared
6748 and construct a ..._DECL node for it.
6749 (In one case we can return a ..._TYPE node instead.
6750 For invalid input we sometimes return 0.)
6752 DECLSPECS is a chain of tree_list nodes whose value fields
6753 are the storage classes and type specifiers.
6755 DECL_CONTEXT says which syntactic context this declaration is in:
6756 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
6757 FUNCDEF for a function definition. Like NORMAL but a few different
6758 error messages in each case. Return value may be zero meaning
6759 this definition is too screwy to try to parse.
6760 MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
6761 handle member functions (which have FIELD context).
6762 Return value may be zero meaning this definition is too screwy to
6764 PARM for a parameter declaration (either within a function prototype
6765 or before a function body). Make a PARM_DECL, or return void_type_node.
6766 TYPENAME if for a typename (in a cast or sizeof).
6767 Don't make a DECL node; just return the ..._TYPE node.
6768 FIELD for a struct or union field; make a FIELD_DECL.
6769 BITFIELD for a field with specified width.
6770 INITIALIZED is 1 if the decl has an initializer.
6772 In the TYPENAME case, DECLARATOR is really an absolute declarator.
6773 It may also be so in the PARM case, for a prototype where the
6774 argument type is specified but not the name.
6776 This function is where the complicated C meanings of `static'
6777 and `extern' are interpreted.
6779 For C++, if there is any monkey business to do, the function which
6780 calls this one must do it, i.e., prepending instance variables,
6781 renaming overloaded function names, etc.
6783 Note that for this C++, it is an error to define a method within a class
6784 which does not belong to that class.
6786 Except in the case where SCOPE_REFs are implicitly known (such as
6787 methods within a class being redundantly qualified),
6788 declarations which involve SCOPE_REFs are returned as SCOPE_REFs
6789 (class_name::decl_name). The caller must also deal with this.
6791 If a constructor or destructor is seen, and the context is FIELD,
6792 then the type gains the attribute TREE_HAS_x. If such a declaration
6793 is erroneous, NULL_TREE is returned.
6795 QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
6796 function, these are the qualifiers to give to the `this' pointer.
6798 May return void_type_node if the declarator turned out to be a friend.
6799 See grokfield for details. */
6801 enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
6804 grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
6807 enum decl_context decl_context;
6811 RID_BIT_TYPE specbits;
6814 tree type = NULL_TREE;
6818 int virtualp, friendp, inlinep, staticp;
6819 int explicit_int = 0;
6820 int explicit_char = 0;
6821 int opaque_typedef = 0;
6822 tree typedef_decl = NULL_TREE;
6824 tree typedef_type = NULL_TREE;
6825 int funcdef_flag = 0;
6826 enum tree_code innermost_code = ERROR_MARK;
6828 int size_varies = 0;
6829 /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
6830 All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
6831 tree init = NULL_TREE;
6833 /* Keep track of what sort of function is being processed
6834 so that we can warn about default return values, or explicit
6835 return values which do not match prescribed defaults. */
6836 enum return_types return_type = return_normal;
6838 tree dname = NULL_TREE;
6839 tree ctype = current_class_type;
6840 tree ctor_return_type = NULL_TREE;
6841 enum overload_flags flags = NO_SPECIAL;
6842 int seen_scope_ref = 0;
6843 tree quals = NULL_TREE;
6845 RIDBIT_RESET_ALL (specbits);
6846 if (decl_context == FUNCDEF)
6847 funcdef_flag = 1, decl_context = NORMAL;
6848 else if (decl_context == MEMFUNCDEF)
6849 funcdef_flag = -1, decl_context = FIELD;
6850 else if (decl_context == BITFIELD)
6851 bitfield = 1, decl_context = FIELD;
6853 if (flag_traditional && allocation_temporary_p ())
6854 end_temporary_allocation ();
6856 /* Look inside a declarator for the name being declared
6857 and get it as a string, for an error message. */
6859 tree last = NULL_TREE;
6860 register tree decl = declarator;
6864 switch (TREE_CODE (decl))
6868 decl = TREE_OPERAND (decl, 0);
6871 case BIT_NOT_EXPR: /* for C++ destructors! */
6873 tree name = TREE_OPERAND (decl, 0);
6874 tree rename = NULL_TREE;
6876 my_friendly_assert (flags == NO_SPECIAL, 152);
6878 return_type = return_dtor;
6879 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
6880 if (ctype == NULL_TREE)
6882 if (current_class_type == NULL_TREE)
6884 error ("destructors must be member functions");
6889 tree t = constructor_name (current_class_name);
6896 tree t = constructor_name (ctype);
6903 error ("destructor `%s' must match class name `%s'",
6904 IDENTIFIER_POINTER (name),
6905 IDENTIFIER_POINTER (rename));
6906 TREE_OPERAND (decl, 0) = rename;
6912 case ADDR_EXPR: /* C++ reference declaration */
6917 innermost_code = TREE_CODE (decl);
6919 decl = TREE_OPERAND (decl, 0);
6923 if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
6925 /* This is actually a variable declaration using constructor
6926 syntax. We need to call start_decl and finish_decl so we
6927 can get the variable initialized... */
6930 /* We need to insinuate ourselves into the declarator in place
6931 of the CALL_EXPR. */
6932 TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
6934 declarator = TREE_OPERAND (decl, 0);
6936 init = TREE_OPERAND (decl, 1);
6938 decl = start_decl (declarator, declspecs, 1, NULL_TREE);
6939 finish_decl (decl, init, NULL_TREE, 1);
6942 innermost_code = TREE_CODE (decl);
6943 decl = TREE_OPERAND (decl, 0);
6944 if (decl_context == FIELD && ctype == NULL_TREE)
6945 ctype = current_class_type;
6946 if (ctype != NULL_TREE
6947 && decl != NULL_TREE && flags != DTOR_FLAG
6948 && decl == constructor_name (ctype))
6950 return_type = return_ctor;
6951 ctor_return_type = ctype;
6956 case IDENTIFIER_NODE:
6960 if (IDENTIFIER_TYPENAME_P (dname))
6962 my_friendly_assert (flags == NO_SPECIAL, 154);
6963 flags = TYPENAME_FLAG;
6964 ctor_return_type = TREE_TYPE (dname);
6965 return_type = return_conversion;
6968 if (IDENTIFIER_OPNAME_P (dname))
6969 name = operator_name_string (dname);
6971 name = IDENTIFIER_POINTER (dname);
6977 /* Parse error puts this typespec where
6978 a declarator should go. */
6979 error ("declarator name missing");
6980 dname = TYPE_NAME (decl);
6981 if (dname && TREE_CODE (dname) == TYPE_DECL)
6982 dname = DECL_NAME (dname);
6983 name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
6984 declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
6991 if (seen_scope_ref == 1)
6992 error ("multiple `::' terms in declarator invalid");
6994 seen_scope_ref += 1;
6996 /* Perform error checking, and convert class names to types.
6997 We may call grokdeclarator multiple times for the same
6998 tree structure, so only do the conversion once. In this
6999 case, we have exactly what we want for `ctype'. */
7000 tree cname = TREE_OPERAND (decl, 0);
7001 if (cname == NULL_TREE)
7003 /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */
7004 else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname))
7005 || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE)
7007 else if (! is_aggr_typedef (cname, 1))
7009 TREE_OPERAND (decl, 0) = NULL_TREE;
7011 /* Must test TREE_OPERAND (decl, 1), in case user gives
7012 us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */
7013 else if (TREE_OPERAND (decl, 1)
7014 && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
7016 TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
7018 else if (ctype == NULL_TREE)
7020 ctype = IDENTIFIER_TYPE_VALUE (cname);
7021 TREE_OPERAND (decl, 0) = ctype;
7023 else if (TREE_COMPLEXITY (decl) == current_class_depth)
7024 TREE_OPERAND (decl, 0) = ctype;
7027 if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname),
7030 cp_error ("type `%T' is not derived from type `%T'",
7031 IDENTIFIER_TYPE_VALUE (cname), ctype);
7032 TREE_OPERAND (decl, 0) = NULL_TREE;
7036 ctype = IDENTIFIER_TYPE_VALUE (cname);
7037 TREE_OPERAND (decl, 0) = ctype;
7041 decl = TREE_OPERAND (decl, 1);
7044 if (TREE_CODE (decl) == IDENTIFIER_NODE
7045 && constructor_name (ctype) == decl)
7047 return_type = return_ctor;
7048 ctor_return_type = ctype;
7050 else if (TREE_CODE (decl) == BIT_NOT_EXPR
7051 && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
7052 && constructor_name (ctype) == TREE_OPERAND (decl, 0))
7054 return_type = return_dtor;
7055 ctor_return_type = ctype;
7057 decl = TREE_OPERAND (decl, 0);
7068 return 0; /* We used to do a 155 abort here. */
7074 /* A function definition's declarator must have the form of
7075 a function declarator. */
7077 if (funcdef_flag && innermost_code != CALL_EXPR)
7080 /* Anything declared one level down from the top level
7081 must be one of the parameters of a function
7082 (because the body is at least two levels down). */
7084 /* This heuristic cannot be applied to C++ nodes! Fixed, however,
7085 by not allowing C++ class definitions to specify their parameters
7086 with xdecls (must be spec.d in the parmlist).
7088 Since we now wait to push a class scope until we are sure that
7089 we are in a legitimate method context, we must set oldcname
7090 explicitly (since current_class_name is not yet alive). */
7092 if (decl_context == NORMAL
7093 && current_binding_level->level_chain == global_binding_level)
7094 decl_context = PARM;
7096 /* Look through the decl specs and record which ones appear.
7097 Some typespecs are defined as built-in typenames.
7098 Others, the ones that are modifiers of other types,
7099 are represented by bits in SPECBITS: set the bits for
7100 the modifiers that appear. Storage class keywords are also in SPECBITS.
7102 If there is a typedef name or a type, store the type in TYPE.
7103 This includes builtin typedefs such as `int'.
7105 Set EXPLICIT_INT if the type is `int' or `char' and did not
7106 come from a user typedef.
7108 Set LONGLONG if `long' is mentioned twice.
7110 For C++, constructors and destructors have their own fast treatment. */
7112 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
7117 /* Certain parse errors slip through. For example,
7118 `int class;' is not caught by the parser. Try
7119 weakly to recover here. */
7120 if (TREE_CODE (spec) != TREE_LIST)
7123 id = TREE_VALUE (spec);
7125 if (TREE_CODE (id) == IDENTIFIER_NODE)
7127 if (id == ridpointers[(int) RID_INT])
7130 error ("extraneous `int' ignored");
7134 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7138 if (id == ridpointers[(int) RID_CHAR])
7141 error ("extraneous `char' ignored");
7145 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7149 if (id == ridpointers[(int) RID_WCHAR])
7152 error ("extraneous `__wchar_t' ignored");
7155 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7159 /* C++ aggregate types. */
7160 if (IDENTIFIER_HAS_TYPE_VALUE (id))
7163 cp_error ("multiple declarations `%T' and `%T'", type, id);
7165 type = IDENTIFIER_TYPE_VALUE (id);
7169 for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
7171 if (ridpointers[i] == id)
7173 if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
7177 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
7181 error ("`long long long' is too long for GCC");
7185 else if (RIDBIT_SETP (i, specbits))
7186 warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
7187 RIDBIT_SET (i, specbits);
7193 error ("two or more data types in declaration of `%s'", name);
7194 else if (TREE_CODE (id) == IDENTIFIER_NODE)
7196 register tree t = lookup_name (id, 1);
7197 if (!t || TREE_CODE (t) != TYPE_DECL)
7198 error ("`%s' fails to be a typedef or built in type",
7199 IDENTIFIER_POINTER (id));
7202 type = TREE_TYPE (t);
7206 else if (TREE_CODE (id) != ERROR_MARK)
7207 /* Can't change CLASS nodes into RECORD nodes here! */
7213 typedef_type = type;
7215 /* No type at all: default to `int', and set EXPLICIT_INT
7216 because it was not a user-defined typedef.
7217 Except when we have a `typedef' inside a signature, in
7218 which case the type defaults to `unknown type' and is
7219 instantiated when assigning to a signature pointer or ref. */
7221 if (type == NULL_TREE)
7224 if (return_type == return_dtor)
7225 type = void_type_node;
7226 else if (return_type == return_ctor)
7227 type = TYPE_POINTER_TO (ctor_return_type);
7228 else if (return_type == return_conversion)
7229 type = ctor_return_type;
7230 else if (current_class_type
7231 && IS_SIGNATURE (current_class_type)
7232 && (RIDBIT_SETP (RID_TYPEDEF, specbits)
7233 || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7234 && (decl_context == FIELD || decl_context == NORMAL))
7238 type = copy_node (opaque_type_node);
7242 if (funcdef_flag && warn_return_type
7243 && return_type == return_normal
7244 && ! (RIDBIT_SETP (RID_SIGNED, specbits)
7245 || RIDBIT_SETP (RID_UNSIGNED, specbits)
7246 || RIDBIT_SETP (RID_LONG, specbits)
7247 || RIDBIT_SETP (RID_SHORT, specbits)))
7248 warn_about_return_type = 1;
7249 /* Save warning until we know what is really going on. */
7250 type = integer_type_node;
7253 else if (return_type == return_dtor)
7255 error ("return type specification for destructor invalid");
7256 type = void_type_node;
7258 else if (return_type == return_ctor)
7260 error ("return type specification for constructor invalid");
7261 type = TYPE_POINTER_TO (ctor_return_type);
7263 else if (return_type == return_conversion)
7265 if (comp_target_types (type, ctor_return_type, 1) == 0)
7266 cp_error ("operator `%T' declared to return `%T'",
7267 ctor_return_type, type);
7269 cp_pedwarn ("return type specified for `operator %T'",
7272 type = ctor_return_type;
7277 /* Now process the modifiers that were specified
7278 and check for invalid combinations. */
7280 /* Long double is a special combination. */
7282 if (RIDBIT_SETP (RID_LONG, specbits)
7283 && TYPE_MAIN_VARIANT (type) == double_type_node)
7285 RIDBIT_RESET (RID_LONG, specbits);
7286 type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
7287 TYPE_VOLATILE (type));
7290 /* Check all other uses of type modifiers. */
7292 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7293 || RIDBIT_SETP (RID_SIGNED, specbits)
7294 || RIDBIT_SETP (RID_LONG, specbits)
7295 || RIDBIT_SETP (RID_SHORT, specbits))
7299 if (TREE_CODE (type) == REAL_TYPE)
7300 error ("short, signed or unsigned invalid for `%s'", name);
7301 else if (TREE_CODE (type) != INTEGER_TYPE || type == wchar_type_node)
7302 error ("long, short, signed or unsigned invalid for `%s'", name);
7303 else if (RIDBIT_SETP (RID_LONG, specbits)
7304 && RIDBIT_SETP (RID_SHORT, specbits))
7305 error ("long and short specified together for `%s'", name);
7306 else if ((RIDBIT_SETP (RID_LONG, specbits)
7307 || RIDBIT_SETP (RID_SHORT, specbits))
7309 error ("long or short specified with char for `%s'", name);
7310 else if ((RIDBIT_SETP (RID_LONG, specbits)
7311 || RIDBIT_SETP (RID_SHORT, specbits))
7312 && TREE_CODE (type) == REAL_TYPE)
7313 error ("long or short specified with floating type for `%s'", name);
7314 else if (RIDBIT_SETP (RID_SIGNED, specbits)
7315 && RIDBIT_SETP (RID_UNSIGNED, specbits))
7316 error ("signed and unsigned given together for `%s'", name);
7320 if (!explicit_int && !explicit_char && pedantic)
7322 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
7324 if (flag_pedantic_errors)
7329 /* Discard the type modifiers if they are invalid. */
7332 RIDBIT_RESET (RID_UNSIGNED, specbits);
7333 RIDBIT_RESET (RID_SIGNED, specbits);
7334 RIDBIT_RESET (RID_LONG, specbits);
7335 RIDBIT_RESET (RID_SHORT, specbits);
7340 /* Decide whether an integer type is signed or not.
7341 Optionally treat bitfields as signed by default. */
7342 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7343 /* Traditionally, all bitfields are unsigned. */
7344 || (bitfield && flag_traditional)
7345 || (bitfield && ! flag_signed_bitfields
7346 && (explicit_int || explicit_char
7347 /* A typedef for plain `int' without `signed'
7348 can be controlled just like plain `int'. */
7349 || ! (typedef_decl != NULL_TREE
7350 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
7351 && TREE_CODE (type) != ENUMERAL_TYPE
7352 && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
7355 type = long_long_unsigned_type_node;
7356 else if (RIDBIT_SETP (RID_LONG, specbits))
7357 type = long_unsigned_type_node;
7358 else if (RIDBIT_SETP (RID_SHORT, specbits))
7359 type = short_unsigned_type_node;
7360 else if (type == char_type_node)
7361 type = unsigned_char_type_node;
7362 else if (typedef_decl)
7363 type = unsigned_type (type);
7365 type = unsigned_type_node;
7367 else if (RIDBIT_SETP (RID_SIGNED, specbits)
7368 && type == char_type_node)
7369 type = signed_char_type_node;
7371 type = long_long_integer_type_node;
7372 else if (RIDBIT_SETP (RID_LONG, specbits))
7373 type = long_integer_type_node;
7374 else if (RIDBIT_SETP (RID_SHORT, specbits))
7375 type = short_integer_type_node;
7377 /* Set CONSTP if this declaration is `const', whether by
7378 explicit specification or via a typedef.
7379 Likewise for VOLATILEP. */
7381 constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
7382 volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
7384 inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
7386 warning ("duplicate `const'");
7388 warning ("duplicate `volatile'");
7389 virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
7391 /* operators new and delete are implicitly static. */
7392 if (RIDBIT_SETP (RID_STATIC, specbits))
7393 staticp = 1 + (decl_context == FIELD);
7395 if (virtualp && staticp == 2)
7397 cp_error ("member `%D' cannot be declared both virtual and static",
7401 friendp = RIDBIT_SETP (RID_FRIEND, specbits);
7402 RIDBIT_RESET (RID_VIRTUAL, specbits);
7403 RIDBIT_RESET (RID_FRIEND, specbits);
7405 if (RIDBIT_SETP (RID_MUTABLE, specbits))
7407 if (decl_context == PARM)
7409 error ("non-member `%s' cannot be declared mutable", name);
7410 RIDBIT_RESET (RID_MUTABLE, specbits);
7412 else if (friendp || decl_context == TYPENAME)
7414 error ("non-object member `%s' cannot be declared mutable", name);
7415 RIDBIT_RESET (RID_MUTABLE, specbits);
7419 error ("static `%s' cannot be declared mutable", name);
7420 RIDBIT_RESET (RID_MUTABLE, specbits);
7423 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7425 error ("non-object member `%s' cannot be declared mutable", name);
7426 RIDBIT_RESET (RID_MUTABLE, specbits);
7428 /* Because local typedefs are parsed twice, we don't want this
7430 else if (decl_context != FIELD)
7432 error ("non-member `%s' cannot be declared mutable", name);
7433 RIDBIT_RESET (RID_MUTABLE, specbits);
7438 /* Warn if two storage classes are given. Default to `auto'. */
7440 if (RIDBIT_ANY_SET (specbits))
7442 if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
7443 if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
7444 if (decl_context == PARM && nclasses > 0)
7445 error ("storage class specifiers invalid in parameter declarations");
7446 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7448 if (decl_context == PARM)
7449 error ("typedef declaration invalid in parameter declaration");
7452 if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
7453 if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
7456 /* Give error if `virtual' is used outside of class declaration. */
7457 if (virtualp && current_class_name == NULL_TREE)
7459 error ("virtual outside class declaration");
7462 if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
7464 error ("only members can be declared mutable");
7465 RIDBIT_RESET (RID_MUTABLE, specbits);
7468 /* Static anonymous unions are dealt with here. */
7469 if (staticp && decl_context == TYPENAME
7470 && TREE_CODE (declspecs) == TREE_LIST
7471 && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
7472 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
7473 decl_context = FIELD;
7475 /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
7476 is used in a signature member function declaration. */
7477 if (decl_context == FIELD
7478 && IS_SIGNATURE (current_class_type)
7479 && RIDBIT_NOTSETP(RID_TYPEDEF, specbits)
7480 && !SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7484 error ("`const' specified for signature member function `%s'", name);
7489 error ("`volatile' specified for signature member function `%s'", name);
7494 error ("`inline' specified for signature member function `%s'", name);
7495 /* Later, we'll make signature member functions inline. */
7500 error ("`friend' declaration in signature definition");
7505 error ("`virtual' specified for signature member function `%s'", name);
7506 /* Later, we'll make signature member functions virtual. */
7511 /* Warn about storage classes that are invalid for certain
7512 kinds of declarations (parameters, typenames, etc.). */
7515 error ("multiple storage classes in declaration of `%s'", name);
7516 else if (decl_context != NORMAL && nclasses > 0)
7518 if (decl_context == PARM
7519 && (RIDBIT_SETP (RID_REGISTER, specbits)
7520 || RIDBIT_SETP (RID_AUTO, specbits)))
7522 else if (decl_context == FIELD
7523 && RIDBIT_SETP (RID_TYPEDEF, specbits))
7525 /* Processing a typedef declaration nested within a class type
7527 register tree scanner;
7528 register tree previous_declspec;
7532 error ("typedef declaration includes an initializer");
7534 /* To process a class-local typedef declaration, we descend down
7535 the chain of declspecs looking for the `typedef' spec. When
7536 we find it, we replace it with `static', and then recursively
7537 call `grokdeclarator' with the original declarator and with
7538 the newly adjusted declspecs. This call should return a
7539 FIELD_DECL node with the TREE_TYPE (and other parts) set
7540 appropriately. We can then just change the TREE_CODE on that
7541 from FIELD_DECL to TYPE_DECL and we're done. */
7543 for (previous_declspec = NULL_TREE, scanner = declspecs;
7545 previous_declspec = scanner, scanner = TREE_CHAIN (scanner))
7547 if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF])
7551 if (scanner == IDENTIFIER_AS_LIST (ridpointers [(int) RID_TYPEDEF]))
7553 if (previous_declspec)
7554 TREE_CHAIN (previous_declspec)
7555 = IDENTIFIER_AS_LIST (ridpointers [(int) RID_STATIC]);
7558 = IDENTIFIER_AS_LIST (ridpointers [(int) RID_STATIC]);
7561 TREE_VALUE (scanner) = ridpointers[(int) RID_STATIC];
7563 /* In the recursive call to grokdeclarator we need to know
7564 whether we are working on a signature-local typedef. */
7565 if (IS_SIGNATURE (current_class_type))
7566 SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1;
7569 grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE);
7571 if (loc_typedecl != error_mark_node)
7573 register int i = sizeof (struct lang_decl_flags) / sizeof (int);
7576 TREE_SET_CODE (loc_typedecl, TYPE_DECL);
7578 pi = (int *) permalloc (sizeof (struct lang_decl_flags));
7581 DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
7584 if (IS_SIGNATURE (current_class_type))
7586 SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0;
7587 if (loc_typedecl != error_mark_node && opaque_typedef)
7588 SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
7591 return loc_typedecl;
7593 else if (decl_context == FIELD
7594 && (! IS_SIGNATURE (current_class_type))
7595 /* C++ allows static class elements */
7596 && RIDBIT_SETP (RID_STATIC, specbits))
7597 /* C++ also allows inlines and signed and unsigned elements,
7598 but in those cases we don't come in here. */
7602 if (decl_context == FIELD)
7604 tree tmp = TREE_OPERAND (declarator, 0);
7605 register int op = IDENTIFIER_OPNAME_P (tmp);
7606 error ("storage class specified for %s `%s'",
7607 IS_SIGNATURE (current_class_type)
7609 ? "signature member operator"
7610 : "signature member function")
7611 : (op ? "member operator" : "structure field"),
7612 op ? operator_name_string (tmp) : name);
7615 error ((decl_context == PARM
7616 ? "storage class specified for parameter `%s'"
7617 : "storage class specified for typename"), name);
7618 RIDBIT_RESET (RID_REGISTER, specbits);
7619 RIDBIT_RESET (RID_AUTO, specbits);
7620 RIDBIT_RESET (RID_EXTERN, specbits);
7622 if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
7624 RIDBIT_RESET (RID_STATIC, specbits);
7629 else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
7631 if (current_binding_level == global_binding_level)
7633 /* It's common practice (and completely legal) to have a const
7634 be initialized and declared extern. */
7636 warning ("`%s' initialized and declared `extern'", name);
7639 error ("`%s' has both `extern' and initializer", name);
7641 else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
7642 && current_binding_level != global_binding_level)
7643 error ("nested function `%s' declared `extern'", name);
7644 else if (current_binding_level == global_binding_level)
7646 if (RIDBIT_SETP (RID_AUTO, specbits))
7647 error ("top-level declaration of `%s' specifies `auto'", name);
7649 if (RIDBIT_SETP (RID_REGISTER, specbits))
7650 error ("top-level declaration of `%s' specifies `register'", name);
7653 /* I'm not sure under what circumstances we should turn
7654 on the extern bit, and under what circumstances we should
7655 warn if other bits are turned on. */
7656 if (decl_context == NORMAL
7657 && RIDBIT_NOSETP (RID_EXTERN, specbits)
7658 && ! root_lang_context_p ())
7660 RIDBIT_SET (RID_EXTERN, specbits);
7665 /* Now figure out the structure of the declarator proper.
7666 Descend through it, creating more complex types, until we reach
7667 the declared identifier (or NULL_TREE, in an absolute declarator). */
7669 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
7671 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
7672 an INDIRECT_REF (for *...),
7673 a CALL_EXPR (for ...(...)),
7674 an identifier (for the name being declared)
7675 or a null pointer (for the place in an absolute declarator
7676 where the name was omitted).
7677 For the last two cases, we have just exited the loop.
7679 For C++ it could also be
7680 a SCOPE_REF (for class :: ...). In this case, we have converted
7681 sensible names to types, and those are the values we use to
7682 qualify the member name.
7683 an ADDR_EXPR (for &...),
7684 a BIT_NOT_EXPR (for destructors)
7686 At this point, TYPE is the type of elements of an array,
7687 or for a function to return, or for a pointer to point to.
7688 After this sequence of ifs, TYPE is the type of the
7689 array or function or pointer, and DECLARATOR has had its
7690 outermost layer removed. */
7692 if (TREE_CODE (type) == ERROR_MARK)
7694 if (TREE_CODE (declarator) == SCOPE_REF)
7695 declarator = TREE_OPERAND (declarator, 1);
7697 declarator = TREE_OPERAND (declarator, 0);
7700 if (quals != NULL_TREE
7701 && (declarator == NULL_TREE
7702 || TREE_CODE (declarator) != SCOPE_REF))
7704 if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
7705 ctype = TYPE_METHOD_BASETYPE (type);
7706 if (ctype != NULL_TREE)
7708 #if 0 /* not yet, should get fixed properly later */
7709 tree dummy = make_type_decl (NULL_TREE, type);
7711 tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
7713 ctype = grok_method_quals (ctype, dummy, quals);
7714 type = TREE_TYPE (dummy);
7718 switch (TREE_CODE (declarator))
7722 register tree itype = NULL_TREE;
7723 register tree size = TREE_OPERAND (declarator, 1);
7725 declarator = TREE_OPERAND (declarator, 0);
7727 /* Check for some types that there cannot be arrays of. */
7729 if (TYPE_MAIN_VARIANT (type) == void_type_node)
7731 cp_error ("declaration of `%D' as array of voids", dname);
7732 type = error_mark_node;
7735 if (TREE_CODE (type) == FUNCTION_TYPE)
7737 cp_error ("declaration of `%D' as array of functions", dname);
7738 type = error_mark_node;
7741 /* ARM $8.4.3: Since you can't have a pointer to a reference,
7742 you can't have arrays of references. If we allowed them,
7743 then we'd be saying x[i] is legal for an array x, but
7744 then you'd have to ask: what does `*(x + i)' mean? */
7745 if (TREE_CODE (type) == REFERENCE_TYPE)
7747 if (decl_context == TYPENAME)
7748 cp_error ("cannot make arrays of references");
7750 cp_error ("declaration of `%D' as array of references",
7752 type = error_mark_node;
7755 if (TREE_CODE (type) == OFFSET_TYPE)
7757 cp_error ("declaration of `%D' as array of data members",
7759 type = error_mark_node;
7762 if (TREE_CODE (type) == METHOD_TYPE)
7764 cp_error ("declaration of `%D' as array of function members",
7766 type = error_mark_node;
7769 if (size == error_mark_node)
7770 type = error_mark_node;
7772 if (type == error_mark_node)
7777 /* Must suspend_momentary here because the index
7778 type may need to live until the end of the function.
7779 For example, it is used in the declaration of a
7780 variable which requires destructing at the end of
7781 the function; then build_vec_delete will need this
7783 int yes = suspend_momentary ();
7784 /* might be a cast */
7785 if (TREE_CODE (size) == NOP_EXPR
7786 && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
7787 size = TREE_OPERAND (size, 0);
7789 /* If this is a template parameter, it'll be constant, but
7790 we don't know what the value is yet. */
7791 if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
7792 goto dont_grok_size;
7794 if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
7795 && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
7797 cp_error ("size of array `%D' has non-integer type",
7799 size = integer_one_node;
7801 if (TREE_READONLY_DECL_P (size))
7802 size = decl_constant_value (size);
7803 if (pedantic && integer_zerop (size))
7804 cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
7805 if (TREE_CONSTANT (size))
7807 constant_expression_warning (size);
7808 if (INT_CST_LT (size, integer_zero_node))
7810 cp_error ("size of array `%D' is negative", dname);
7811 size = integer_one_node;
7813 itype = build_index_type (size_binop (MINUS_EXPR, size,
7819 cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", dname);
7822 build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
7823 /* Make sure the array size remains visibly nonconstant
7824 even if it is (eg) a const variable with known value. */
7826 itype = variable_size (itype);
7827 itype = build_index_type (itype);
7829 resume_momentary (yes);
7832 /* Build the array type itself, then merge any constancy or
7833 volatility into the target type. We must do it in this order
7834 to ensure that the TYPE_MAIN_VARIANT field of the array type
7835 is set correctly. */
7837 type = build_cplus_array_type (type, itype);
7838 if (constp || volatilep)
7839 /* Should this be c_build_type_variant? -jason */
7840 type = build_type_variant (type, constp, volatilep);
7850 /* Declaring a function type.
7851 Make sure we have a valid type for the function to return. */
7853 /* Is this an error? Should they be merged into TYPE here? */
7854 if (pedantic && (constp || volatilep))
7855 pedwarn ("function declared to return const or volatile result");
7857 /* Merge any constancy or volatility into the target type
7860 if (constp || volatilep)
7862 type = build_type_variant (type, constp, volatilep);
7863 if (IS_AGGR_TYPE (type))
7864 build_pointer_type (type);
7870 /* Warn about some types functions can't return. */
7872 if (TREE_CODE (type) == FUNCTION_TYPE)
7874 error ("`%s' declared as function returning a function", name);
7875 type = integer_type_node;
7877 if (TREE_CODE (type) == ARRAY_TYPE)
7879 error ("`%s' declared as function returning an array", name);
7880 type = integer_type_node;
7883 if (ctype == NULL_TREE
7884 && decl_context == FIELD
7885 && (friendp == 0 || dname == current_class_name))
7886 ctype = current_class_type;
7888 if (ctype && return_type == return_conversion)
7889 TYPE_HAS_CONVERSION (ctype) = 1;
7890 if (ctype && constructor_name (ctype) == dname)
7892 /* We are within a class's scope. If our declarator name
7893 is the same as the class name, and we are defining
7894 a function, then it is a constructor/destructor, and
7895 therefore returns a void type. */
7897 if (flags == DTOR_FLAG)
7899 /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may
7900 not be declared const or volatile. A destructor
7901 may not be static. */
7903 error ("destructor cannot be static member function");
7904 if (TYPE_READONLY (type))
7906 error ("destructors cannot be declared `const'");
7907 return void_type_node;
7909 if (TYPE_VOLATILE (type))
7911 error ("destructors cannot be declared `volatile'");
7912 return void_type_node;
7914 if (decl_context == FIELD)
7916 if (! member_function_or_else (ctype, current_class_type,
7917 "destructor for alien class `%s' cannot be a member"))
7918 return void_type_node;
7921 else /* it's a constructor. */
7923 /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may
7924 not be declared const or volatile. A constructor may
7925 not be virtual. A constructor may not be static. */
7927 error ("constructor cannot be static member function");
7930 pedwarn ("constructors cannot be declared virtual");
7933 if (TYPE_READONLY (type))
7935 error ("constructors cannot be declared `const'");
7936 return void_type_node;
7938 if (TYPE_VOLATILE (type))
7940 error ("constructors cannot be declared `volatile'");
7941 return void_type_node;
7944 RID_BIT_TYPE tmp_bits;
7945 bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE));
7946 RIDBIT_RESET (RID_INLINE, tmp_bits);
7947 RIDBIT_RESET (RID_STATIC, tmp_bits);
7948 if (RIDBIT_ANY_SET (tmp_bits))
7949 error ("return value type specifier for constructor ignored");
7951 type = TYPE_POINTER_TO (ctype);
7952 if (decl_context == FIELD &&
7953 IS_SIGNATURE (current_class_type))
7955 error ("constructor not allowed in signature");
7956 return void_type_node;
7958 else if (decl_context == FIELD)
7960 if (! member_function_or_else (ctype, current_class_type,
7961 "constructor for alien class `%s' cannot be member"))
7962 return void_type_node;
7963 TYPE_HAS_CONSTRUCTOR (ctype) = 1;
7964 if (return_type != return_ctor)
7968 if (decl_context == FIELD)
7971 else if (friendp && virtualp)
7973 /* Cannot be both friend and virtual. */
7974 error ("virtual functions cannot be friends");
7975 RIDBIT_RESET (RID_FRIEND, specbits);
7979 if (decl_context == NORMAL && friendp)
7980 error ("friend declaration not in class definition");
7982 /* Pick up type qualifiers which should be applied to `this'. */
7983 quals = TREE_OPERAND (declarator, 2);
7985 /* Traditionally, declaring return type float means double. */
7987 if (flag_traditional
7988 && TYPE_MAIN_VARIANT (type) == float_type_node)
7990 type = build_type_variant (double_type_node,
7991 TYPE_READONLY (type),
7992 TYPE_VOLATILE (type));
7995 /* Construct the function type and go to the next
7996 inner layer of declarator. */
8000 tree inner_parms = TREE_OPERAND (declarator, 1);
8001 tree inner_decl = TREE_OPERAND (declarator, 0);
8003 declarator = TREE_OPERAND (declarator, 0);
8005 if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
8006 inner_decl = TREE_OPERAND (inner_decl, 1);
8008 /* Say it's a definition only for the CALL_EXPR
8009 closest to the identifier. */
8011 (inner_decl && TREE_CODE (inner_decl) == IDENTIFIER_NODE)
8014 /* FIXME: This is where default args should be fully
8017 arg_types = grokparms (inner_parms, funcdef_p);
8022 /* Get past destructors, etc.
8023 We know we have one because FLAGS will be non-zero.
8025 Complain about improper parameter lists here. */
8026 if (TREE_CODE (declarator) == BIT_NOT_EXPR)
8028 declarator = TREE_OPERAND (declarator, 0);
8030 if (strict_prototype == 0 && arg_types == NULL_TREE)
8031 arg_types = void_list_node;
8032 else if (arg_types == NULL_TREE
8033 || arg_types != void_list_node)
8035 error ("destructors cannot be specified with parameters");
8036 arg_types = void_list_node;
8041 /* ANSI seems to say that `const int foo ();'
8042 does not make the function foo const. */
8043 type = build_function_type (type,
8044 flag_traditional ? 0 : arg_types);
8050 /* Filter out pointers-to-references and references-to-references.
8051 We can get these if a TYPE_DECL is used. */
8053 if (TREE_CODE (type) == REFERENCE_TYPE)
8055 error ("cannot declare %s to references",
8056 TREE_CODE (declarator) == ADDR_EXPR
8057 ? "references" : "pointers");
8058 declarator = TREE_OPERAND (declarator, 0);
8062 /* Merge any constancy or volatility into the target type
8065 if (constp || volatilep)
8067 /* A const or volatile signature pointer/reference is
8068 pointing to a const or volatile object, i.e., the
8069 `optr' is const or volatile, respectively, not the
8070 signature pointer/reference itself. */
8071 if (! IS_SIGNATURE (type))
8073 type = build_type_variant (type, constp, volatilep);
8074 if (IS_AGGR_TYPE (type))
8075 build_pointer_type (type);
8081 if (IS_SIGNATURE (type))
8083 if (TREE_CODE (declarator) == ADDR_EXPR)
8085 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE)
8086 warning ("empty signature `%s' used in signature reference declaration",
8087 TYPE_NAME_STRING(type));
8089 type = build_signature_reference_type (type,
8092 sorry ("signature reference");
8098 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE)
8099 warning ("empty signature `%s' used in signature pointer declaration",
8100 TYPE_NAME_STRING(type));
8101 type = build_signature_pointer_type (type,
8107 else if (TREE_CODE (declarator) == ADDR_EXPR)
8109 if (TREE_CODE (type) == FUNCTION_TYPE)
8111 error ("cannot declare references to functions; use pointer to function instead");
8112 type = build_pointer_type (type);
8116 if (TYPE_MAIN_VARIANT (type) == void_type_node)
8117 error ("invalid type: `void &'");
8119 type = build_reference_type (type);
8122 else if (TREE_CODE (type) == METHOD_TYPE)
8124 type = build_ptrmemfunc_type (build_pointer_type (type));
8127 type = build_pointer_type (type);
8129 /* Process a list of type modifier keywords (such as
8130 const or volatile) that were given inside the `*' or `&'. */
8132 if (TREE_TYPE (declarator))
8134 register tree typemodlist;
8136 for (typemodlist = TREE_TYPE (declarator); typemodlist;
8137 typemodlist = TREE_CHAIN (typemodlist))
8139 if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
8141 else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
8146 error ("invalid type modifier within %s declarator",
8147 TREE_CODE (declarator) == ADDR_EXPR
8148 ? "reference" : "pointer");
8152 warning ("duplicate `const'");
8154 warning ("duplicate `volatile'");
8156 declarator = TREE_OPERAND (declarator, 0);
8162 /* We have converted type names to NULL_TREE if the
8163 name was bogus, or to a _TYPE node, if not.
8165 The variable CTYPE holds the type we will ultimately
8166 resolve to. The code here just needs to build
8167 up appropriate member types. */
8168 tree sname = TREE_OPERAND (declarator, 1);
8169 /* Destructors can have their visibilities changed as well. */
8170 if (TREE_CODE (sname) == BIT_NOT_EXPR)
8171 sname = TREE_OPERAND (sname, 0);
8173 if (TREE_COMPLEXITY (declarator) == 0)
8174 /* This needs to be here, in case we are called
8175 multiple times. */ ;
8176 else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
8177 /* don't fall out into global scope. Hides real bug? --eichin */ ;
8178 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
8180 /* I'm not really sure what pushclass calls this popclass
8181 corresponds to. One is in build_push_scope and that has
8182 been changed to a push_nested_class call, that's why I
8183 try to use pop_nested_class here instead.
8185 pop_nested_class (1);
8186 TREE_COMPLEXITY (declarator) = current_class_depth;
8189 my_friendly_abort (16);
8191 if (TREE_OPERAND (declarator, 0) == NULL_TREE)
8193 /* We had a reference to a global decl, or
8194 perhaps we were given a non-aggregate typedef,
8195 in which case we cleared this out, and should just
8196 keep going as though it wasn't there. */
8200 ctype = TREE_OPERAND (declarator, 0);
8202 if (sname == NULL_TREE)
8205 if (TREE_CODE (sname) == IDENTIFIER_NODE)
8207 /* This is the `standard' use of the scoping operator:
8208 basetype :: member . */
8210 if (TREE_CODE (type) == FUNCTION_TYPE)
8212 if (current_class_type == NULL_TREE
8213 || TYPE_MAIN_VARIANT (ctype) == current_class_type
8215 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8216 TREE_TYPE (type), TYPE_ARG_TYPES (type));
8219 error ("cannot declare member function `%s::%s' within this class",
8220 TYPE_NAME_STRING (ctype), name);
8221 return void_type_node;
8224 else if (TYPE_MAIN_VARIANT (ctype) == current_class_type)
8227 warning ("extra qualification `%s' on member `%s' ignored",
8228 TYPE_NAME_STRING (ctype), name);
8229 type = build_offset_type (ctype, type);
8231 else if (TYPE_SIZE (ctype) != NULL_TREE
8232 || (RIDBIT_SETP (RID_TYPEDEF, specbits)))
8235 /* have to move this code elsewhere in this function.
8236 this code is used for i.e., typedef int A::M; M *pm; */
8238 if (explicit_int == -1 && decl_context == FIELD
8239 && funcdef_flag == 0)
8241 /* The code in here should only be used to build
8242 stuff that will be grokked as access decls. */
8243 t = lookup_field (ctype, sname, 0, 0);
8246 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
8247 DECL_INITIAL (t) = init;
8250 /* No such field, try member functions. */
8251 t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
8254 if (flags == DTOR_FLAG)
8256 else if (CLASSTYPE_METHOD_VEC (ctype)
8257 && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
8259 /* Don't include destructor with constructors. */
8260 t = DECL_CHAIN (TREE_VALUE (t));
8262 error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname));
8263 t = build_tree_list (NULL_TREE, t);
8265 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
8266 DECL_INITIAL (t) = init;
8271 ("field `%D' is not a member of structure `%T'",
8275 if (current_class_type)
8277 if (TYPE_MAIN_VARIANT (ctype) != current_class_type)
8279 cp_error ("cannot declare member `%T::%s' within `%T'",
8280 ctype, name, current_class_type);
8281 return void_type_node;
8283 else if (extra_warnings)
8284 cp_warning ("extra qualification `%T' on member `%s' ignored",
8287 type = build_offset_type (ctype, type);
8289 else if (uses_template_parms (ctype))
8292 if (TREE_CODE (type) == FUNCTION_TYPE)
8294 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8296 TYPE_ARG_TYPES (type));
8302 cp_error ("structure `%T' not yet defined", ctype);
8303 return error_mark_node;
8308 else if (TREE_CODE (sname) == SCOPE_REF)
8309 my_friendly_abort (17);
8313 declarator = TREE_OPERAND (declarator, 1);
8314 if (declarator && TREE_CODE (declarator) == CALL_EXPR)
8315 /* In this case, we will deal with it later. */
8319 if (TREE_CODE (type) == FUNCTION_TYPE)
8320 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
8322 type = build_offset_type (ctype, type);
8329 declarator = TREE_OPERAND (declarator, 0);
8335 declarator = NULL_TREE;
8339 declarator = NULL_TREE;
8343 my_friendly_abort (158);
8347 /* Now TYPE has the actual type. */
8349 /* If this is declaring a typedef name, return a TYPE_DECL. */
8351 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8355 /* Note that the grammar rejects storage classes
8356 in typenames, fields or parameters. */
8357 if (constp || volatilep)
8358 type = build_type_variant (type, constp, volatilep);
8360 /* If the user declares "struct {...} foo" then `foo' will have
8361 an anonymous name. Fill that name in now. Nothing can
8362 refer to it, so nothing needs know about the name change.
8363 The TYPE_NAME field was filled in by build_struct_xref. */
8364 if (type != error_mark_node
8366 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8367 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
8369 /* replace the anonymous name with the real name everywhere. */
8370 lookup_tag_reverse (type, declarator);
8371 TYPE_IDENTIFIER (type) = declarator;
8373 if (TYPE_LANG_SPECIFIC (type))
8374 TYPE_WAS_ANONYMOUS (type) = 1;
8377 tree d = TYPE_NAME (type), c = DECL_CONTEXT (d);
8380 set_nested_typename (d, 0, declarator, type);
8381 else if (TREE_CODE (c) == FUNCTION_DECL)
8382 set_nested_typename (d, DECL_ASSEMBLER_NAME (c),
8385 set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type);
8389 #if 0 /* not yet, should get fixed properly later */
8390 decl = make_type_decl (declarator, type);
8392 decl = build_decl (TYPE_DECL, declarator, type);
8394 if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
8396 cp_error_at ("typedef name may not be class-qualified", decl);
8397 TREE_TYPE (decl) = error_mark_node;
8401 if (ctype == NULL_TREE)
8403 if (TREE_CODE (type) != METHOD_TYPE)
8404 cp_error_at ("invalid type qualifier for non-method type", decl);
8406 ctype = TYPE_METHOD_BASETYPE (type);
8408 if (ctype != NULL_TREE)
8409 grok_method_quals (ctype, decl, quals);
8412 if (RIDBIT_SETP (RID_SIGNED, specbits)
8413 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
8414 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
8416 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8418 error ("non-object member `%s' cannot be declared mutable", name);
8424 /* Detect the case of an array type of unspecified size
8425 which came, as such, direct from a typedef name.
8426 We must copy the type, so that each identifier gets
8427 a distinct type, so that each identifier's size can be
8428 controlled separately by its own initializer. */
8430 if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
8431 && TYPE_DOMAIN (type) == NULL_TREE)
8433 type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
8436 /* If this is a type name (such as, in a cast or sizeof),
8437 compute the type and return it now. */
8439 if (decl_context == TYPENAME)
8441 /* Note that the grammar rejects storage classes
8442 in typenames, fields or parameters. */
8443 if (constp || volatilep)
8444 if (IS_SIGNATURE (type))
8445 error ("`const' or `volatile' specified with signature type");
8447 type = build_type_variant (type, constp, volatilep);
8449 /* Special case: "friend class foo" looks like a TYPENAME context. */
8452 /* A friendly class? */
8453 if (current_class_type)
8454 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
8456 error("trying to make class `%s' a friend of global scope",
8457 TYPE_NAME_STRING (type));
8458 type = void_type_node;
8462 #if 0 /* not yet, should get fixed properly later */
8463 tree dummy = make_type_decl (declarator, type);
8465 tree dummy = build_decl (TYPE_DECL, declarator, type);
8467 if (ctype == NULL_TREE)
8469 my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
8470 ctype = TYPE_METHOD_BASETYPE (type);
8472 grok_method_quals (ctype, dummy, quals);
8473 type = TREE_TYPE (dummy);
8478 else if (declarator == NULL_TREE && decl_context != PARM
8479 && TREE_CODE (type) != UNION_TYPE
8482 cp_error ("abstract declarator `%T' used as declaration", type);
8483 declarator = make_anon_name ();
8486 /* `void' at top level (not within pointer)
8487 is allowed only in typedefs or type names.
8488 We don't complain about parms either, but that is because
8489 a better error message can be made later. */
8491 if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
8493 if (TREE_CODE (declarator) == IDENTIFIER_NODE)
8495 if (IDENTIFIER_OPNAME_P (declarator))
8496 #if 0 /* How could this happen? */
8497 error ("operator `%s' declared void",
8498 operator_name_string (declarator));
8500 my_friendly_abort (356);
8503 error ("variable or field `%s' declared void", name);
8506 error ("variable or field declared void");
8507 type = integer_type_node;
8510 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
8511 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
8516 if (decl_context == PARM)
8518 tree parmtype = type;
8521 error ("cannot use `::' in parameter declaration");
8523 /* A parameter declared as an array of T is really a pointer to T.
8524 One declared as a function is really a pointer to a function.
8525 One declared as a member is really a pointer to member.
8527 Don't be misled by references. */
8529 if (TREE_CODE (type) == REFERENCE_TYPE)
8530 type = TREE_TYPE (type);
8532 if (TREE_CODE (type) == ARRAY_TYPE)
8534 if (parmtype == type)
8536 /* Transfer const-ness of array into that of type
8538 type = build_pointer_type
8539 (build_type_variant (TREE_TYPE (type), constp, volatilep));
8540 volatilep = constp = 0;
8543 type = build_pointer_type (TREE_TYPE (type));
8545 else if (TREE_CODE (type) == FUNCTION_TYPE)
8546 type = build_pointer_type (type);
8547 else if (TREE_CODE (type) == OFFSET_TYPE)
8548 type = build_pointer_type (type);
8550 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
8552 /* Transfer const-ness of reference into that of type pointed to. */
8553 type = build_type_variant (build_reference_type (type), constp, volatilep);
8554 constp = volatilep = 0;
8557 decl = build_decl (PARM_DECL, declarator, type);
8559 bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
8560 inlinep, friendp, raises != NULL_TREE);
8561 if (current_class_type
8562 && IS_SIGNATURE (current_class_type))
8565 error ("parameter of signature member function declared `inline'");
8566 if (RIDBIT_SETP (RID_AUTO, specbits))
8567 error ("parameter of signature member function declared `auto'");
8568 if (RIDBIT_SETP (RID_REGISTER, specbits))
8569 error ("parameter of signature member function declared `register'");
8572 /* Compute the type actually passed in the parmlist,
8573 for the case where there is no prototype.
8574 (For example, shorts and chars are passed as ints.)
8575 When there is a prototype, this is overridden later. */
8577 DECL_ARG_TYPE (decl) = type;
8578 if (TYPE_MAIN_VARIANT (type) == float_type_node)
8579 DECL_ARG_TYPE (decl) = build_type_variant (double_type_node,
8580 TYPE_READONLY (type),
8581 TYPE_VOLATILE (type));
8582 else if (C_PROMOTING_INTEGER_TYPE_P (type))
8586 /* Retain unsignedness if traditional or if not really
8588 if (TREE_UNSIGNED (type)
8589 && (flag_traditional
8590 || TYPE_PRECISION (type)
8591 == TYPE_PRECISION (integer_type_node)))
8592 argtype = unsigned_type_node;
8594 argtype = integer_type_node;
8595 DECL_ARG_TYPE (decl) = build_type_variant (argtype,
8596 TYPE_READONLY (type),
8597 TYPE_VOLATILE (type));
8600 else if (decl_context == FIELD)
8602 if (type == error_mark_node)
8604 /* Happens when declaring arrays of sizes which
8605 are error_mark_node, for example. */
8608 else if (TREE_CODE (type) == FUNCTION_TYPE)
8614 if (ctype == NULL_TREE)
8615 ctype = current_class_type;
8617 if (ctype == NULL_TREE)
8619 cp_error ("can't make `%D' into a method -- not in a class",
8621 return void_type_node;
8624 /* ``A union may [ ... ] not [ have ] virtual functions.''
8626 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
8628 cp_error ("function `%D' declared virtual inside a union",
8630 return void_type_node;
8633 if (declarator == ansi_opname[(int) NEW_EXPR]
8634 || declarator == ansi_opname[(int) DELETE_EXPR])
8638 cp_error ("`%D' cannot be declared virtual, since it is always static",
8643 else if (staticp < 2)
8644 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8645 TREE_TYPE (type), TYPE_ARG_TYPES (type));
8648 /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
8649 publicp = (RIDBIT_SETP (RID_EXTERN, specbits)
8650 || (ctype != NULL_TREE && funcdef_flag >= 0)
8653 && RIDBIT_NOTSETP (RID_STATIC, specbits)
8654 && RIDBIT_NOTSETP (RID_INLINE, specbits)));
8655 decl = grokfndecl (ctype, type, declarator,
8656 virtualp, flags, quals,
8657 raises, friendp ? -1 : 0, publicp);
8658 DECL_INLINE (decl) = inlinep;
8660 else if (TREE_CODE (type) == METHOD_TYPE)
8662 /* All method decls are public, so tell grokfndecl to set
8663 TREE_PUBLIC, also. */
8664 decl = grokfndecl (ctype, type, declarator,
8665 virtualp, flags, quals,
8666 raises, friendp ? -1 : 0, 1);
8667 DECL_INLINE (decl) = inlinep;
8669 else if (TREE_CODE (type) == RECORD_TYPE
8670 && CLASSTYPE_DECLARED_EXCEPTION (type))
8672 /* Handle a class-local exception declaration. */
8673 decl = build_lang_field_decl (VAR_DECL, declarator, type);
8674 if (ctype == NULL_TREE)
8675 ctype = current_class_type;
8676 finish_exception_decl (TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
8677 ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype), decl);
8678 return void_type_node;
8680 else if (TYPE_SIZE (type) == NULL_TREE && !staticp
8681 && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
8683 error ("field `%s' has incomplete type",
8684 IDENTIFIER_POINTER (declarator));
8686 /* If we're instantiating a template, tell them which
8687 instantiation made the field's type be incomplete. */
8688 if (current_class_type
8689 && TYPE_NAME (current_class_type)
8690 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type)))
8691 && declspecs && TREE_VALUE (declspecs)
8692 && TREE_TYPE (TREE_VALUE (declspecs)) == type)
8693 error (" in instantiation of template `%s'",
8694 TYPE_NAME_STRING (current_class_type));
8696 type = error_mark_node;
8703 error ("`%s' is neither function nor method; cannot be declared friend",
8704 IDENTIFIER_POINTER (declarator));
8712 /* Friends are treated specially. */
8713 if (ctype == current_class_type)
8714 warning ("member functions are implicitly friends of their class");
8718 if (decl && DECL_NAME (decl))
8719 t = do_friend (ctype, declarator, decl,
8720 last_function_parms, flags, quals);
8721 if (t && funcdef_flag)
8724 return void_type_node;
8728 /* Structure field. It may not be a function, except for C++ */
8730 if (decl == NULL_TREE)
8732 /* ANSI C++ June 5 1992 WP 9.2.2 and 9.4.2. A member-declarator
8733 cannot have an initializer, and a static member declaration must
8734 be defined elsewhere. */
8738 error ("static member `%s' must be defined separately from its declaration",
8739 IDENTIFIER_POINTER (declarator));
8740 /* Note that initialization of const members is prohibited
8741 by the draft ANSI standard, though it appears to be in
8742 common practice. 12.6.2: The argument list is used to
8743 initialize the named nonstatic member.... This (or an
8744 aggregate) is the only way to initialize nonstatic const
8745 and reference members. */
8747 pedwarn ("ANSI C++ forbids initialization of %s `%s'",
8748 constp ? "const member" : "member",
8749 IDENTIFIER_POINTER (declarator));
8752 if (staticp || (constp && initialized))
8754 /* C++ allows static class members.
8755 All other work for this is done by grokfield.
8756 This VAR_DECL is built by build_lang_field_decl.
8757 All other VAR_DECLs are built by build_decl. */
8758 decl = build_lang_field_decl (VAR_DECL, declarator, type);
8759 if (staticp || TREE_CODE (type) == ARRAY_TYPE)
8760 TREE_STATIC (decl) = 1;
8761 /* In class context, static means public access. */
8762 TREE_PUBLIC (decl) = 1;
8763 DECL_EXTERNAL (decl) = !initialized;
8767 decl = build_lang_field_decl (FIELD_DECL, declarator, type);
8768 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8770 DECL_MUTABLE_P (decl) = 1;
8771 RIDBIT_RESET (RID_MUTABLE, specbits);
8775 bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
8776 inlinep, friendp, raises != NULL_TREE);
8779 else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
8781 tree original_name = declarator;
8787 if (RIDBIT_SETP (RID_AUTO, specbits))
8788 error ("storage class `auto' invalid for function `%s'", name);
8789 else if (RIDBIT_SETP (RID_REGISTER, specbits))
8790 error ("storage class `register' invalid for function `%s'", name);
8792 /* Function declaration not at top level.
8793 Storage classes other than `extern' are not allowed
8794 and `extern' makes no difference. */
8795 if (current_binding_level != global_binding_level
8796 && ! processing_template_decl
8797 && (RIDBIT_SETP (RID_STATIC, specbits)
8798 || RIDBIT_SETP (RID_INLINE, specbits))
8801 if (RIDBIT_SETP (RID_STATIC, specbits))
8802 pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name);
8804 pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name);
8807 if (ctype == NULL_TREE)
8811 error ("virtual non-class function `%s'", name);
8815 if (current_lang_name == lang_name_cplusplus
8816 && ! (IDENTIFIER_LENGTH (original_name) == 4
8817 && IDENTIFIER_POINTER (original_name)[0] == 'm'
8818 && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
8819 && ! (IDENTIFIER_LENGTH (original_name) > 10
8820 && IDENTIFIER_POINTER (original_name)[0] == '_'
8821 && IDENTIFIER_POINTER (original_name)[1] == '_'
8822 && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
8823 /* Plain overloading: will not be grok'd by grokclassfn. */
8824 declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
8826 else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
8827 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8828 TREE_TYPE (type), TYPE_ARG_TYPES (type));
8830 /* Record presence of `static'. In C++, `inline' is like `static'.
8831 Methods of classes should be public, unless we're dropping them
8832 into some other file, so we don't clear TREE_PUBLIC for them. */
8835 && CLASSTYPE_INTERFACE_KNOWN (ctype))
8836 || !(RIDBIT_SETP (RID_STATIC, specbits)
8837 || RIDBIT_SETP (RID_INLINE, specbits)));
8839 decl = grokfndecl (ctype, type, original_name,
8840 virtualp, flags, quals,
8842 processing_template_decl ? 0 : friendp ? 2 : 1,
8845 if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
8846 DECL_ASSEMBLER_NAME (decl) = declarator;
8850 int illegal_static = 0;
8852 /* Don't allow a static member function in a class, and forbid
8853 declaring main to be static. */
8854 if (TREE_CODE (type) == METHOD_TYPE)
8856 cp_error_at ("cannot declare member function `%D' to have static linkage", decl);
8860 && IDENTIFIER_LENGTH (original_name) == 4
8861 && IDENTIFIER_POINTER (original_name)[0] == 'm'
8862 && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
8864 error ("cannot declare function `main' to have static linkage");
8867 else if (current_function_decl)
8869 /* FIXME need arm citation */
8870 error ("cannot declare static function inside another function");
8877 RIDBIT_RESET (RID_STATIC, specbits);
8881 /* Record presence of `inline', if it is reasonable. */
8884 tree last = tree_last (TYPE_ARG_TYPES (type));
8887 && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
8888 error ("cannot inline function `main'");
8889 else if (last && last != void_list_node)
8890 cp_warning ("cannot inline function `%D' which takes `...'", original_name);
8892 /* Assume that otherwise the function can be inlined. */
8893 DECL_INLINE (decl) = 1;
8895 if (RIDBIT_SETP (RID_EXTERN, specbits))
8897 current_extern_inline = 1;
8898 if (flag_ansi || pedantic || flag_pedantic_errors)
8899 pedwarn ("ANSI C++ does not permit `extern inline'");
8905 /* It's a variable. */
8907 /* An uninitialized decl with `extern' is a reference. */
8908 decl = grokvardecl (type, declarator, specbits, initialized);
8909 bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
8910 inlinep, friendp, raises != NULL_TREE);
8916 cp_error ("static member `%D' re-declared as static",
8919 RIDBIT_RESET (RID_STATIC, specbits);
8921 if (RIDBIT_SETP (RID_EXTERN, specbits))
8923 cp_error ("cannot explicitly declare member `%#D' to have extern linkage",
8925 RIDBIT_RESET (RID_EXTERN, specbits);
8930 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8932 error ("`%s' cannot be declared mutable", name);
8935 /* Record `register' declaration for warnings on &
8936 and in case doing stupid register allocation. */
8938 if (RIDBIT_SETP (RID_REGISTER, specbits))
8939 DECL_REGISTER (decl) = 1;
8941 if (RIDBIT_SETP (RID_EXTERN, specbits))
8942 DECL_THIS_EXTERN (decl) = 1;
8944 /* Record constancy and volatility. */
8947 TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
8950 TREE_SIDE_EFFECTS (decl) = 1;
8951 TREE_THIS_VOLATILE (decl) = 1;
8958 /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
8959 An empty exprlist is a parmlist. An exprlist which
8960 contains only identifiers at the global level
8961 is a parmlist. Otherwise, it is an exprlist. */
8963 parmlist_is_exprlist (exprs)
8966 if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
8969 if (current_binding_level == global_binding_level)
8971 /* At the global level, if these are all identifiers,
8972 then it is a parmlist. */
8975 if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
8977 exprs = TREE_CHAIN (exprs);
8984 /* Subroutine of `grokparms'. In a fcn definition, arg types must
8987 C++: also subroutine of `start_function'. */
8989 require_complete_types_for_parms (parms)
8994 tree type = TREE_TYPE (parms);
8995 if (TYPE_SIZE (type) == NULL_TREE)
8997 if (DECL_NAME (parms))
8998 error ("parameter `%s' has incomplete type",
8999 IDENTIFIER_POINTER (DECL_NAME (parms)));
9001 error ("parameter has incomplete type");
9002 TREE_TYPE (parms) = error_mark_node;
9005 /* If the arg types are incomplete in a declaration,
9006 they must include undefined tags.
9007 These tags can never be defined in the scope of the declaration,
9008 so the types can never be completed,
9009 and no call can be compiled successfully. */
9010 /* This is not the right behavior for C++, but not having
9011 it is also probably wrong. */
9014 /* Now warn if is a pointer to an incomplete type. */
9015 while (TREE_CODE (type) == POINTER_TYPE
9016 || TREE_CODE (type) == REFERENCE_TYPE)
9017 type = TREE_TYPE (type);
9018 type = TYPE_MAIN_VARIANT (type);
9019 if (TYPE_SIZE (type) == NULL_TREE)
9021 if (DECL_NAME (parm) != NULL_TREE)
9022 warning ("parameter `%s' points to incomplete type",
9023 IDENTIFIER_POINTER (DECL_NAME (parm)));
9025 warning ("parameter points to incomplete type");
9029 parms = TREE_CHAIN (parms);
9033 /* Decode the list of parameter types for a function type.
9034 Given the list of things declared inside the parens,
9035 return a list of types.
9037 The list we receive can have three kinds of elements:
9038 an IDENTIFIER_NODE for names given without types,
9039 a TREE_LIST node for arguments given as typespecs or names with typespecs,
9040 or void_type_node, to mark the end of an argument list
9041 when additional arguments are not permitted (... was not used).
9043 FUNCDEF_FLAG is nonzero for a function definition, 0 for
9044 a mere declaration. A nonempty identifier-list gets an error message
9045 when FUNCDEF_FLAG is zero.
9046 If FUNCDEF_FLAG is 1, then parameter types must be complete.
9047 If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
9049 If all elements of the input list contain types,
9050 we return a list of the types.
9051 If all elements contain no type (except perhaps a void_type_node
9052 at the end), we return a null list.
9053 If some have types and some do not, it is an error, and we
9056 Also set last_function_parms to either
9057 a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
9058 A list of names is converted to a chain of PARM_DECLs
9059 by store_parm_decls so that ultimately it is always a chain of decls.
9061 Note that in C++, parameters can take default values. These default
9062 values are in the TREE_PURPOSE field of the TREE_LIST. It is
9063 an error to specify default values which are followed by parameters
9064 that have no default values, or an ELLIPSES. For simplicities sake,
9065 only parameters which are specified with their types can take on
9069 grokparms (first_parm, funcdef_flag)
9073 tree result = NULL_TREE;
9074 tree decls = NULL_TREE;
9076 if (first_parm != NULL_TREE
9077 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
9080 pedwarn ("parameter names (without types) in function declaration");
9081 last_function_parms = first_parm;
9084 else if (first_parm != NULL_TREE
9085 && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
9086 && TREE_VALUE (first_parm) != void_type_node)
9087 my_friendly_abort (145);
9090 /* Types were specified. This is a list of declarators
9091 each represented as a TREE_LIST node. */
9092 register tree parm, chain;
9093 int any_init = 0, any_error = 0, saw_void = 0;
9095 if (first_parm != NULL_TREE)
9097 tree last_result = NULL_TREE;
9098 tree last_decl = NULL_TREE;
9100 for (parm = first_parm; parm != NULL_TREE; parm = chain)
9102 tree type, list_node = parm;
9103 register tree decl = TREE_VALUE (parm);
9104 tree init = TREE_PURPOSE (parm);
9106 chain = TREE_CHAIN (parm);
9107 /* @@ weak defense against parse errors. */
9108 if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
9110 /* Give various messages as the need arises. */
9111 if (TREE_CODE (decl) == STRING_CST)
9112 error ("invalid string constant `%s'",
9113 TREE_STRING_POINTER (decl));
9114 else if (TREE_CODE (decl) == INTEGER_CST)
9115 error ("invalid integer constant in parameter list, did you forget to give parameter name?");
9119 if (decl != void_type_node)
9121 /* @@ May need to fetch out a `raises' here. */
9122 decl = grokdeclarator (TREE_VALUE (decl),
9123 TREE_PURPOSE (decl),
9124 PARM, init != NULL_TREE, NULL_TREE);
9127 type = TREE_TYPE (decl);
9128 if (TYPE_MAIN_VARIANT (type) == void_type_node)
9129 decl = void_type_node;
9130 else if (TREE_CODE (type) == METHOD_TYPE)
9132 if (DECL_NAME (decl))
9133 /* Cannot use `error_with_decl' here because
9134 we don't have DECL_CONTEXT set up yet. */
9135 error ("parameter `%s' invalidly declared method type",
9136 IDENTIFIER_POINTER (DECL_NAME (decl)));
9138 error ("parameter invalidly declared method type");
9139 type = build_pointer_type (type);
9140 TREE_TYPE (decl) = type;
9142 else if (TREE_CODE (type) == OFFSET_TYPE)
9144 if (DECL_NAME (decl))
9145 error ("parameter `%s' invalidly declared offset type",
9146 IDENTIFIER_POINTER (DECL_NAME (decl)));
9148 error ("parameter invalidly declared offset type");
9149 type = build_pointer_type (type);
9150 TREE_TYPE (decl) = type;
9152 else if (TREE_CODE (type) == RECORD_TYPE
9153 && TYPE_LANG_SPECIFIC (type)
9154 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
9156 abstract_virtuals_error (decl, type);
9157 any_error = 1; /* seems like a good idea */
9159 else if (TREE_CODE (type) == RECORD_TYPE
9160 && TYPE_LANG_SPECIFIC (type)
9161 && IS_SIGNATURE (type))
9163 signature_error (decl, type);
9164 any_error = 1; /* seems like a good idea */
9168 if (decl == void_type_node)
9170 if (result == NULL_TREE)
9172 result = void_list_node;
9173 last_result = result;
9177 TREE_CHAIN (last_result) = void_list_node;
9178 last_result = void_list_node;
9182 && (chain != void_list_node || TREE_CHAIN (chain)))
9183 error ("`void' in parameter list must be entire list");
9187 /* Since there is a prototype, args are passed in their own types. */
9188 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
9189 #ifdef PROMOTE_PROTOTYPES
9190 if ((TREE_CODE (type) == INTEGER_TYPE
9191 || TREE_CODE (type) == ENUMERAL_TYPE)
9192 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
9193 DECL_ARG_TYPE (decl) = integer_type_node;
9200 if (TREE_CODE (init) == SAVE_EXPR)
9201 PARM_DECL_EXPR (init) = 1;
9202 else if (TREE_CODE (init) == VAR_DECL)
9204 if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
9206 /* ``Local variables may not be used in default
9207 argument expressions.'' dpANSI C++ 8.2.6 */
9208 /* If extern int i; within a function is not
9209 considered a local variable, then this code is
9211 cp_error ("local variable `%D' may not be used as a default argument", init);
9214 else if (TREE_READONLY_DECL_P (init))
9215 init = decl_constant_value (init);
9218 init = require_instantiated_type (type, init, integer_zero_node);
9222 error ("all trailing parameters must have default arguments");
9229 if (decls == NULL_TREE)
9236 TREE_CHAIN (last_decl) = decl;
9239 if (TREE_PERMANENT (list_node))
9241 TREE_PURPOSE (list_node) = init;
9242 TREE_VALUE (list_node) = type;
9243 TREE_CHAIN (list_node) = NULL_TREE;
9246 list_node = saveable_tree_cons (init, type, NULL_TREE);
9247 if (result == NULL_TREE)
9250 last_result = result;
9254 TREE_CHAIN (last_result) = list_node;
9255 last_result = list_node;
9259 TREE_CHAIN (last_result) = NULL_TREE;
9260 /* If there are no parameters, and the function does not end
9261 with `...', then last_decl will be NULL_TREE. */
9262 if (last_decl != NULL_TREE)
9263 TREE_CHAIN (last_decl) = NULL_TREE;
9267 last_function_parms = decls;
9269 /* In a fcn definition, arg types must be complete. */
9270 if (funcdef_flag > 0)
9271 require_complete_types_for_parms (last_function_parms);
9276 /* These memoizing functions keep track of special properties which
9277 a class may have. `grok_ctor_properties' notices whether a class
9278 has a constructor of the form X(X&), and also complains
9279 if the class has a constructor of the form X(X).
9280 `grok_op_properties' takes notice of the various forms of
9281 operator= which are defined, as well as what sorts of type conversion
9282 may apply. Both functions take a FUNCTION_DECL as an argument. */
9284 grok_ctor_properties (ctype, decl)
9287 tree parmtypes = FUNCTION_ARG_CHAIN (decl);
9288 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
9290 /* When a type has virtual baseclasses, a magical first int argument is
9291 added to any ctor so we can tell if the class has been initialized
9292 yet. This could screw things up in this function, so we deliberately
9293 ignore the leading int if we're in that situation. */
9295 && TREE_VALUE (parmtypes) == integer_type_node
9296 && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
9298 parmtypes = TREE_CHAIN (parmtypes);
9299 parmtype = TREE_VALUE (parmtypes);
9302 if (TREE_CODE (parmtype) == REFERENCE_TYPE
9303 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
9305 if (TREE_CHAIN (parmtypes) == NULL_TREE
9306 || TREE_CHAIN (parmtypes) == void_list_node
9307 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
9309 TYPE_HAS_INIT_REF (ctype) = 1;
9310 if (TYPE_READONLY (TREE_TYPE (parmtype)))
9311 TYPE_HAS_CONST_INIT_REF (ctype) = 1;
9314 TYPE_GETS_INIT_AGGR (ctype) = 1;
9316 else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
9318 if (TREE_CHAIN (parmtypes) != NULL_TREE
9319 && TREE_CHAIN (parmtypes) == void_list_node)
9320 cp_error ("invalid constructor; you probably meant `%T (%T&)'",
9322 SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
9323 TYPE_GETS_INIT_AGGR (ctype) = 1;
9325 else if (TREE_CODE (parmtype) == VOID_TYPE
9326 || TREE_PURPOSE (parmtypes) != NULL_TREE)
9327 TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
9330 /* An operator with this name can be either unary or binary. */
9331 int ambi_op_p (name)
9334 return (name == ansi_opname [(int) INDIRECT_REF]
9335 || name == ansi_opname [(int) ADDR_EXPR]
9336 || name == ansi_opname [(int) NEGATE_EXPR]
9337 || name == ansi_opname[(int) POSTINCREMENT_EXPR]
9338 || name == ansi_opname[(int) POSTDECREMENT_EXPR]
9339 || name == ansi_opname [(int) CONVERT_EXPR]);
9342 /* An operator with this name can only be unary. */
9343 int unary_op_p (name)
9346 return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
9347 || name == ansi_opname [(int) BIT_NOT_EXPR]
9348 || name == ansi_opname [(int) COMPONENT_REF]
9349 || OPERATOR_TYPENAME_P (name));
9352 /* Do a little sanity-checking on how they declared their operator. */
9354 grok_op_properties (decl, virtualp, friendp)
9356 int virtualp, friendp;
9358 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
9359 int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
9360 tree name = DECL_NAME (decl);
9364 for (t = current_class_type; t; t = TYPE_NEXT_VARIANT (t))
9366 if (name == ansi_opname[(int) MODIFY_EXPR])
9367 TYPE_HAS_ASSIGNMENT (t) = 1;
9368 else if (name == ansi_opname[(int) CALL_EXPR])
9369 TYPE_OVERLOADS_CALL_EXPR (t) = 1;
9370 else if (name == ansi_opname[(int) ARRAY_REF])
9371 TYPE_OVERLOADS_ARRAY_REF (t) = 1;
9372 else if (name == ansi_opname[(int) COMPONENT_REF]
9373 || name == ansi_opname[(int) MEMBER_REF])
9374 TYPE_OVERLOADS_ARROW (t) = 1;
9375 else if (name == ansi_opname[(int) NEW_EXPR])
9377 if (TREE_CHAIN (argtypes) == void_list_node)
9378 TREE_GETS_NEW (t) = 1;
9380 TREE_GETS_PLACED_NEW (t) = 1;
9382 else if (name == ansi_opname[(int) DELETE_EXPR])
9383 TREE_GETS_DELETE (t) = 1;
9385 else if (name == ansi_opname[(int) VEC_NEW_EXPR])
9386 TREE_GETS_NEW (t) = 1;
9387 else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
9388 TREE_GETS_DELETE (t) = 1;
9392 if (name == ansi_opname[(int) NEW_EXPR])
9395 /* When the compiler encounters the definition of A::operator new, it
9396 doesn't look at the class declaration to find out if it's static. */
9397 my_friendly_assert (!methodp, 355);
9400 /* Take care of function decl if we had syntax errors. */
9401 if (argtypes == NULL_TREE)
9403 build_function_type (ptr_type_node,
9404 hash_tree_chain (integer_type_node,
9407 decl = coerce_new_type (TREE_TYPE (decl));
9410 else if (name == ansi_opname[(int) VEC_NEW_EXPR])
9414 else if (name == ansi_opname[(int) DELETE_EXPR])
9417 my_friendly_assert (!methodp, 355);
9420 if (argtypes == NULL_TREE)
9422 build_function_type (void_type_node,
9423 hash_tree_chain (ptr_type_node,
9426 decl = coerce_delete_type (TREE_TYPE (decl));
9429 else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
9435 /* An operator function must either be a non-static member function
9436 or have at least one parameter of a class, a reference to a class,
9437 an enumeration, or a reference to an enumeration. 13.4.0.6 */
9440 if (OPERATOR_TYPENAME_P (name)
9441 || name == ansi_opname[(int) CALL_EXPR]
9442 || name == ansi_opname[(int) MODIFY_EXPR]
9443 || name == ansi_opname[(int) COMPONENT_REF]
9444 || name == ansi_opname[(int) ARRAY_REF])
9445 cp_error ("`%D' must be a nonstatic member function", decl);
9451 for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
9453 tree arg = TREE_VALUE (p);
9454 if (TREE_CODE (arg) == REFERENCE_TYPE)
9455 arg = TREE_TYPE (arg);
9457 /* This lets bad template code slip through. */
9458 if (IS_AGGR_TYPE (arg)
9459 || TREE_CODE (arg) == ENUMERAL_TYPE
9460 || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
9464 ("`%D' must have an argument of class or enumerated type",
9471 if (name == ansi_opname[(int) CALL_EXPR]
9472 || name == ansi_opname[(int) METHOD_CALL_EXPR])
9473 return; /* no restrictions on args */
9475 if (name == ansi_opname[(int) MODIFY_EXPR])
9479 if (list_length (argtypes) != 3 && methodp)
9481 cp_error ("`%D' must take exactly one argument", decl);
9484 parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
9486 if (TREE_CODE (parmtype) == REFERENCE_TYPE
9487 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype))
9488 == current_class_type)
9490 TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
9491 if (TYPE_READONLY (TREE_TYPE (parmtype)))
9492 TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
9495 else if (name == ansi_opname[(int) COND_EXPR])
9498 pedwarn ("ANSI C++ prohibits overloading operator ?:");
9499 if (list_length (argtypes) != 4)
9500 cp_error ("`%D' must take exactly three arguments", decl);
9502 else if (ambi_op_p (name))
9504 if (list_length (argtypes) == 2)
9506 else if (list_length (argtypes) == 3)
9508 if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
9509 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
9510 && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
9513 cp_error ("postfix `%D' must take `int' as its argument",
9517 ("postfix `%D' must take `int' as its second argument",
9524 cp_error ("`%D' must take either zero or one argument", decl);
9526 cp_error ("`%D' must take either one or two arguments", decl);
9529 else if (unary_op_p (name))
9531 if (list_length (argtypes) != 2)
9534 cp_error ("`%D' must take `void'", decl);
9536 cp_error ("`%D' must take exactly one argument", decl);
9539 else /* if (binary_op_p (name)) */
9541 if (list_length (argtypes) != 3)
9544 cp_error ("`%D' must take exactly one argument", decl);
9546 cp_error ("`%D' must take exactly two arguments", decl);
9552 for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
9553 if (TREE_PURPOSE (argtypes))
9555 TREE_PURPOSE (argtypes) = NULL_TREE;
9556 if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
9557 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
9560 cp_pedwarn ("`%D' cannot have default arguments", decl);
9563 cp_error ("`%D' cannot have default arguments", decl);
9568 /* Get the struct, enum or union (CODE says which) with tag NAME.
9569 Define the tag as a forward-reference if it is not defined.
9571 C++: If a class derivation is given, process it here, and report
9572 an error if multiple derivation declarations are not identical.
9574 If this is a definition, come in through xref_tag and only look in
9575 the current frame for the name (since C++ allows new names in any
9578 /* avoid rewriting all callers of xref_tag */
9579 static int xref_next_defn = 0;
9582 xref_defn_tag (code_type_node, name, binfo)
9583 tree code_type_node;
9589 if (class_binding_level)
9593 /* we need to build a new IDENTIFIER_NODE for name which nukes
9596 n1 = IDENTIFIER_LOCAL_VALUE (current_class_name);
9598 n1 = DECL_NAME (n1);
9600 n1 = current_class_name;
9602 n1 = TYPE_NAME(current_class_type);
9604 n1 = DECL_NESTED_TYPENAME(n1);
9606 n1 = current_class_name;
9608 buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1)
9609 + IDENTIFIER_LENGTH (name));
9611 sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1),
9612 IDENTIFIER_POINTER (name));
9613 ncp = get_identifier (buf);
9616 printf("*** %s ***\n", IDENTIFIER_POINTER (ncp));
9619 IDENTIFIER_LOCAL_VALUE (name) =
9620 build_lang_decl (TYPE_DECL, ncp, NULL_TREE);
9622 rv = xref_tag (code_type_node, name, binfo, 0);
9623 if (! ANON_AGGRNAME_P (name))
9625 register tree type_decl = build_lang_decl (TYPE_DECL, ncp, rv);
9626 #ifdef DWARF_DEBUGGING_INFO
9627 /* Mark the TYPE_DECL node created just above as a gratuitous one
9628 so that dwarfout.c will know not to generate a TAG_typedef DIE
9630 if (write_symbols == DWARF_DEBUG)
9631 DECL_IGNORED_P (type_decl) = 1;
9632 #endif /* DWARF_DEBUGGING_INFO */
9633 pushdecl_top_level (type_decl);
9638 rv = xref_tag (code_type_node, name, binfo, 0);
9645 xref_tag (code_type_node, name, binfo, globalize)
9646 tree code_type_node;
9650 enum tag_types tag_code;
9651 enum tree_code code;
9654 register tree ref, t;
9655 struct binding_level *b = inner_binding_level;
9657 tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
9662 case exception_type:
9663 case signature_type:
9665 len = list_length (binfo);
9671 cp_error ("derived union `%T' invalid", name);
9677 code = ENUMERAL_TYPE;
9680 my_friendly_abort (18);
9683 /* If a cross reference is requested, look up the type
9684 already defined for this tag and return it. */
9685 if ((t = IDENTIFIER_TYPE_VALUE(name)))
9687 if (TREE_CODE(t) != code) t = NULL_TREE;
9691 /* If we know we are defining this tag, only look it up in this scope
9692 * and don't try to find it as a type. */
9694 if (t && TYPE_CONTEXT(t) && strstr(IDENTIFIER_POINTER(name), "::"))
9697 ref = lookup_tag (code, name, b, 1);
9704 ref = lookup_tag (code, name, b, 0);
9708 /* Try finding it as a type declaration. If that wins, use it. */
9709 ref = lookup_name (name, 1);
9710 if (ref && TREE_CODE (ref) == TYPE_DECL
9711 && TREE_CODE (TREE_TYPE (ref)) == code)
9712 ref = TREE_TYPE (ref);
9718 push_obstacks_nochange ();
9722 /* If no such tag is yet defined, create a forward-reference node
9723 and record it as the "definition".
9724 When a real declaration of this type is found,
9725 the forward-reference will be altered into a real type. */
9727 /* In C++, since these migrate into the global scope, we must
9728 build them on the permanent obstack. */
9730 temp = allocation_temporary_p ();
9732 end_temporary_allocation ();
9734 if (code == ENUMERAL_TYPE)
9736 ref = make_node (ENUMERAL_TYPE);
9738 /* Give the type a default layout like unsigned int
9739 to avoid crashing if it does not get defined. */
9740 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
9741 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
9742 TREE_UNSIGNED (ref) = 1;
9743 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
9744 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
9745 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
9747 /* Enable us to recognize when a type is created in class context.
9748 To do nested classes correctly, this should probably be cleared
9749 out when we leave this classes scope. Currently this in only
9750 done in `start_enum'. */
9752 pushtag (name, ref, globalize);
9754 cadillac_start_enum (ref);
9756 else if (tag_code == exception_type)
9758 ref = make_lang_type (code);
9759 /* Enable us to recognize when an exception type is created in
9760 class context. To do nested classes correctly, this should
9761 probably be cleared out when we leave this class's scope. */
9762 CLASSTYPE_DECLARED_EXCEPTION (ref) = 1;
9763 pushtag (name, ref, globalize);
9765 cadillac_start_struct (ref);
9769 extern tree pending_vtables;
9770 struct binding_level *old_b = class_binding_level;
9773 ref = make_lang_type (code);
9775 /* A signature type will contain the fields of the signature
9776 table. Therefore, it's not only an interface. */
9777 if (tag_code == signature_type)
9779 SET_SIGNATURE (ref);
9780 CLASSTYPE_INTERFACE_ONLY (ref) = 0;
9781 CLASSTYPE_INTERFACE_UNKNOWN (ref) = 0;
9784 /* Record how to set the access of this class's
9785 virtual functions. If write_virtuals == 2 or 3, then
9786 inline virtuals are ``extern inline''. */
9787 switch (write_virtuals)
9794 needs_writing = !! value_member (name, pending_vtables);
9797 needs_writing = ! CLASSTYPE_INTERFACE_ONLY (ref)
9798 && CLASSTYPE_INTERFACE_KNOWN (ref);
9804 /* Signatures don't have a vtable. As long as we don't have default
9805 implementations, they behave as if `write_virtuals' were 3. */
9806 if (tag_code == signature_type)
9807 CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
9809 CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing;
9811 #ifdef NONNESTED_CLASSES
9812 /* Class types don't nest the way enums do. */
9813 class_binding_level = (struct binding_level *)0;
9815 pushtag (name, ref, globalize);
9816 class_binding_level = old_b;
9819 cadillac_start_struct (ref);
9824 if (IS_AGGR_TYPE_CODE (code))
9826 if (IS_AGGR_TYPE (ref)
9827 && ((tag_code == exception_type)
9828 != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1)))
9830 cp_error ("type `%T' is both exception and aggregate type", ref);
9831 CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type);
9835 /* If it no longer looks like a nested type, make sure it's
9837 if (b == global_binding_level && !class_binding_level
9838 && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
9839 IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
9844 tree tt2 = TYPE_BINFO_BASETYPES (ref);
9846 if (TYPE_BINFO_BASETYPES (ref))
9847 for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
9848 if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
9850 cp_error ("redeclaration of derivation chain of type `%#T'",
9855 if (tt1 == NULL_TREE)
9856 /* The user told us something we already knew. */
9859 /* In C++, since these migrate into the global scope, we must
9860 build them on the permanent obstack. */
9861 end_temporary_allocation ();
9867 /* In the declaration `A : X, Y, ... Z' we mark all the types
9868 (A, X, Y, ..., Z) so we can check for duplicates. */
9871 SET_CLASSTYPE_MARKED (ref);
9872 BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
9874 for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
9876 /* The base of a derived struct is public by default. */
9878 = (TREE_PURPOSE (binfo) == (tree)access_public
9879 || TREE_PURPOSE (binfo) == (tree)access_public_virtual
9880 || (tag_code != class_type
9881 && (TREE_PURPOSE (binfo) == (tree)access_default
9882 || TREE_PURPOSE (binfo) == (tree)access_default_virtual)));
9883 int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected;
9885 = (TREE_PURPOSE (binfo) == (tree)access_private_virtual
9886 || TREE_PURPOSE (binfo) == (tree)access_public_virtual
9887 || TREE_PURPOSE (binfo) == (tree)access_default_virtual);
9888 tree basetype = TREE_TYPE (TREE_VALUE (binfo));
9891 GNU_xref_hier (IDENTIFIER_POINTER (name),
9892 IDENTIFIER_POINTER (TREE_VALUE (binfo)),
9893 via_public, via_virtual, 0);
9895 if (basetype && TREE_CODE (basetype) == TYPE_DECL)
9896 basetype = TREE_TYPE (basetype);
9897 if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
9899 error ("base type `%s' fails to be a struct or class type",
9900 IDENTIFIER_POINTER (TREE_VALUE (binfo)));
9904 /* This code replaces similar code in layout_basetypes. */
9905 else if (TYPE_SIZE (basetype) == NULL_TREE)
9907 cp_error ("base class `%T' has incomplete type", basetype);
9913 if (CLASSTYPE_MARKED (basetype))
9915 if (basetype == ref)
9916 cp_error ("recursive type `%T' undefined", basetype);
9918 cp_error ("duplicate base type `%T' invalid", basetype);
9922 /* Note that the BINFO records which describe individual
9923 inheritances are *not* shared in the lattice! They
9924 cannot be shared because a given baseclass may be
9925 inherited with different `accessibility' by different
9926 derived classes. (Each BINFO record describing an
9927 individual inheritance contains flags which say what
9928 the `accessibility' of that particular inheritance is.) */
9930 base_binfo = make_binfo (integer_zero_node, basetype,
9931 TYPE_BINFO_VTABLE (basetype),
9932 TYPE_BINFO_VIRTUALS (basetype), NULL_TREE);
9934 TREE_VEC_ELT (binfos, i) = base_binfo;
9935 TREE_VIA_PUBLIC (base_binfo) = via_public;
9936 TREE_VIA_PROTECTED (base_binfo) = via_protected;
9937 TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
9939 SET_CLASSTYPE_MARKED (basetype);
9941 /* XYZZY TEST VIRTUAL BASECLASSES */
9942 if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE
9943 && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
9944 && via_virtual == 0)
9946 warning ("making type `%s' a virtual baseclass",
9947 TYPE_NAME_STRING (basetype));
9951 /* We are free to modify these bits because they are meaningless
9952 at top level, and BASETYPE is a top-level type. */
9953 if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
9955 TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
9956 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
9959 TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
9960 TREE_GETS_NEW (ref) |= TREE_GETS_NEW (basetype);
9961 TREE_GETS_PLACED_NEW (ref) |= TREE_GETS_PLACED_NEW (basetype);
9962 TREE_GETS_DELETE (ref) |= TREE_GETS_DELETE (basetype);
9963 CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
9968 TREE_VEC_LENGTH (binfos) = i;
9970 BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
9973 TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
9975 TYPE_USES_MULTIPLE_INHERITANCE (ref)
9976 = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
9977 if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
9978 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
9980 /* Unmark all the types. */
9982 CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
9983 CLEAR_CLASSTYPE_MARKED (ref);
9988 /* Until the type is defined, tentatively accept whatever
9989 structure tag the user hands us. */
9990 if (TYPE_SIZE (ref) == NULL_TREE
9991 && ref != current_class_type
9992 /* Have to check this, in case we have contradictory tag info. */
9993 && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
9995 if (tag_code == class_type)
9996 CLASSTYPE_DECLARED_CLASS (ref) = 1;
9997 else if (tag_code == record_type || tag_code == signature_type)
9998 CLASSTYPE_DECLARED_CLASS (ref) = 0;
10006 static tree current_local_enum = NULL_TREE;
10008 /* Begin compiling the definition of an enumeration type.
10009 NAME is its name (or null if anonymous).
10010 Returns the type object, as yet incomplete.
10011 Also records info about it so that build_enumerator
10012 may be used to declare the individual values as they are read. */
10018 register tree enumtype = NULL_TREE;
10019 struct binding_level *b = inner_binding_level;
10021 /* If this is the real definition for a previous forward reference,
10022 fill in the contents in the same object that used to be the
10023 forward reference. */
10025 if (name != NULL_TREE)
10026 enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
10028 if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
10029 cp_error ("multiple definition of enum `%T'", enumtype);
10032 enumtype = make_node (ENUMERAL_TYPE);
10033 pushtag (name, enumtype, 0);
10036 if (current_class_type)
10037 TREE_ADDRESSABLE (b->tags) = 1;
10038 current_local_enum = NULL_TREE;
10040 if (TYPE_VALUES (enumtype) != NULL_TREE)
10041 /* Completely replace its old definition.
10042 The old enumerators remain defined, however. */
10043 TYPE_VALUES (enumtype) = NULL_TREE;
10045 /* Initially, set up this enum as like `int'
10046 so that we can create the enumerators' declarations and values.
10047 Later on, the precision of the type may be changed and
10048 it may be laid out again. */
10050 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
10051 TYPE_SIZE (enumtype) = NULL_TREE;
10052 fixup_unsigned_type (enumtype);
10054 /* We copy this value because enumerated type constants
10055 are really of the type of the enumerator, not integer_type_node. */
10056 enum_next_value = copy_node (integer_zero_node);
10058 GNU_xref_decl (current_function_decl, enumtype);
10062 /* After processing and defining all the values of an enumeration type,
10063 install their decls in the enumeration type and finish it off.
10064 ENUMTYPE is the type object and VALUES a list of name-value pairs.
10065 Returns ENUMTYPE. */
10068 finish_enum (enumtype, values)
10069 register tree enumtype, values;
10071 register tree pair, tem;
10072 register HOST_WIDE_INT maxvalue = 0;
10073 register HOST_WIDE_INT minvalue = 0;
10074 register HOST_WIDE_INT i;
10076 TYPE_VALUES (enumtype) = values;
10078 /* Calculate the maximum value of any enumerator in this type. */
10082 /* Speed up the main loop by performing some precalculations */
10084 HOST_WIDE_INT value = TREE_INT_CST_LOW (TREE_VALUE (values));
10085 TREE_TYPE (TREE_VALUE (values)) = enumtype;
10086 minvalue = maxvalue = value;
10088 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
10090 value = TREE_INT_CST_LOW (TREE_VALUE (pair));
10091 if (value > maxvalue)
10093 else if (value < minvalue)
10095 TREE_TYPE (TREE_VALUE (pair)) = enumtype;
10099 if (flag_short_enums)
10101 /* Determine the precision this type needs, lay it out, and define it. */
10103 for (i = maxvalue; i; i >>= 1)
10104 TYPE_PRECISION (enumtype)++;
10106 if (!TYPE_PRECISION (enumtype))
10107 TYPE_PRECISION (enumtype) = 1;
10109 /* Cancel the laying out previously done for the enum type,
10110 so that fixup_unsigned_type will do it over. */
10111 TYPE_SIZE (enumtype) = NULL_TREE;
10113 fixup_unsigned_type (enumtype);
10116 TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue;
10118 /* An enum can have some negative values; then it is signed. */
10121 TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue;
10122 TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1;
10123 TREE_UNSIGNED (enumtype) = 0;
10126 cadillac_finish_enum (enumtype);
10128 /* Fix up all variant types of this enum type. */
10129 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
10131 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
10132 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
10133 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
10134 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
10135 TYPE_MODE (tem) = TYPE_MODE (enumtype);
10136 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
10137 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
10138 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
10141 /* Finish debugging output for this type. */
10143 /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
10144 information should *not* be generated? I think not. */
10145 if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
10147 rest_of_type_compilation (enumtype, global_bindings_p ());
10152 /* Build and install a CONST_DECL for one value of the
10153 current enumeration type (one that was begun with start_enum).
10154 Return a tree-list containing the name and its value.
10155 Assignment of sequential values by default is handled here. */
10158 build_enumerator (name, value)
10162 /* Change this to zero if we find VALUE is not shareable. */
10165 /* Remove no-op casts from the value. */
10167 STRIP_TYPE_NOPS (value);
10169 /* Validate and default VALUE. */
10170 if (value != NULL_TREE)
10172 if (TREE_READONLY_DECL_P (value))
10174 value = decl_constant_value (value);
10178 if (TREE_CODE (value) == INTEGER_CST)
10180 value = default_conversion (value);
10181 constant_expression_warning (value);
10185 error ("enumerator value for `%s' not integer constant",
10186 IDENTIFIER_POINTER (name));
10191 /* The order of things is reversed here so that we
10192 can check for possible sharing of enum values,
10193 to keep that from happening. */
10194 /* Default based on previous value. */
10195 if (value == NULL_TREE)
10196 value = enum_next_value;
10198 /* Remove no-op casts from the value. */
10200 STRIP_TYPE_NOPS (value);
10202 /* Make up for hacks in lex.c. */
10203 if (value == integer_zero_node)
10204 value = build_int_2 (0, 0);
10205 else if (value == integer_one_node)
10206 value = build_int_2 (1, 0);
10207 else if (TREE_CODE (value) == INTEGER_CST
10209 || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
10211 value = copy_node (value);
10212 TREE_TYPE (value) = integer_type_node;
10215 result = saveable_tree_cons (name, value, NULL_TREE);
10217 /* C++ associates enums with global, function, or class declarations. */
10219 /* There are a number of cases we need to be aware of here:
10220 current_class_type current_function_decl
10221 * global enums NULL NULL
10222 * fn-local enum NULL SET
10223 * class-local enum SET NULL
10224 * class->fn->enum SET SET
10225 * fn->class->enum SET SET
10227 Those last two make life interesting. If it's a fn-local enum which is
10228 itself inside a class, we need the enum to go into the fn's decls (our
10229 second case below). But if it's a class-local enum and the class itself
10230 is inside a function, we need that enum to go into the decls for the
10231 class. To achieve this last goal, we must see if, when both
10232 current_class_decl and current_function_decl are set, the class was
10233 declared inside that function. If so, we know to put the enum into
10234 the class's scope. */
10236 if ((current_class_type && ! current_function_decl)
10237 || (current_class_type && current_function_decl
10238 && TYPE_CONTEXT (current_class_type) == current_function_decl))
10240 /* This enum declaration is local to the class, so we must put
10241 it in that class's list of decls. */
10242 decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
10243 DECL_INITIAL (decl) = value;
10244 TREE_READONLY (decl) = 1;
10245 pushdecl_class_level (decl);
10246 TREE_CHAIN (decl) = current_local_enum;
10247 current_local_enum = decl;
10251 /* It's a global enum, or it's local to a function. (Note local to
10252 a function could mean local to a class method. */
10253 decl = build_decl (CONST_DECL, name, integer_type_node);
10254 DECL_INITIAL (decl) = value;
10257 GNU_xref_decl (current_function_decl, decl);
10260 /* Set basis for default for next value. */
10261 enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
10262 integer_one_node, PLUS_EXPR);
10263 if (enum_next_value == integer_one_node)
10264 enum_next_value = copy_node (enum_next_value);
10270 grok_enum_decls (type, decl)
10273 tree d = current_local_enum;
10275 if (d == NULL_TREE)
10280 TREE_TYPE (d) = type;
10281 if (TREE_CHAIN (d) == NULL_TREE)
10283 TREE_CHAIN (d) = decl;
10286 d = TREE_CHAIN (d);
10289 decl = current_local_enum;
10290 current_local_enum = NULL_TREE;
10295 /* Create the FUNCTION_DECL for a function definition.
10296 DECLSPECS and DECLARATOR are the parts of the declaration;
10297 they describe the function's name and the type it returns,
10298 but twisted together in a fashion that parallels the syntax of C.
10300 This function creates a binding context for the function body
10301 as well as setting up the FUNCTION_DECL in current_function_decl.
10303 Returns 1 on success. If the DECLARATOR is not suitable for a function
10304 (it defines a datum instead), we return 0, which tells
10305 yyparse to report a parse error.
10307 For C++, we must first check whether that datum makes any sense.
10308 For example, "class A local_a(1,2);" means that variable local_a
10309 is an aggregate of type A, which should have a constructor
10310 applied to it with the argument list [1, 2].
10312 @@ There is currently no way to retrieve the storage
10313 @@ allocated to FUNCTION (or all of its parms) if we return
10314 @@ something we had previously. */
10317 start_function (declspecs, declarator, raises, pre_parsed_p)
10318 tree declarator, declspecs, raises;
10321 extern tree EHS_decl;
10322 tree decl1, olddecl;
10323 tree ctype = NULL_TREE;
10326 extern int have_extern_spec;
10327 extern int used_extern_spec;
10328 int doing_friend = 0;
10330 if (flag_handle_exceptions && EHS_decl == NULL_TREE)
10331 init_exception_processing_1 ();
10333 /* Sanity check. */
10334 my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
10335 my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
10337 /* Assume, until we see it does. */
10338 current_function_returns_value = 0;
10339 current_function_returns_null = 0;
10340 warn_about_return_type = 0;
10341 current_extern_inline = 0;
10342 current_function_assigns_this = 0;
10343 current_function_just_assigned_this = 0;
10344 current_function_parms_stored = 0;
10345 original_result_rtx = NULL_RTX;
10346 current_function_obstack_index = 0;
10347 current_function_obstack_usage = 0;
10349 clear_temp_name ();
10351 /* This should only be done once on the top most decl. */
10352 if (have_extern_spec && !used_extern_spec)
10354 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
10355 used_extern_spec = 1;
10360 decl1 = declarator;
10362 if (! DECL_ARGUMENTS (decl1)
10363 && !DECL_STATIC_FUNCTION_P (decl1)
10364 && DECL_CONTEXT (decl1)
10365 && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))
10366 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))))
10368 cp_error ("redeclaration of `%#D'", decl1);
10369 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
10370 cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
10371 else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
10372 cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
10375 last_function_parms = DECL_ARGUMENTS (decl1);
10376 last_function_parm_tags = NULL_TREE;
10377 fntype = TREE_TYPE (decl1);
10378 if (TREE_CODE (fntype) == METHOD_TYPE)
10379 ctype = TYPE_METHOD_BASETYPE (fntype);
10381 /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a
10382 class is in the (lexical) scope of the class in which it is
10384 if (!ctype && DECL_FRIEND_P (decl1))
10386 ctype = DECL_CLASS_CONTEXT (decl1);
10388 /* CTYPE could be null here if we're dealing with a template;
10389 for example, `inline friend float foo()' inside a template
10390 will have no CTYPE set. */
10391 if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
10397 if ( !(DECL_VINDEX (decl1)
10398 && write_virtuals >= 2
10399 && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)))
10400 current_extern_inline = DECL_THIS_EXTERN (decl1) && DECL_INLINE (decl1);
10402 raises = TYPE_RAISES_EXCEPTIONS (fntype);
10404 /* In a fcn definition, arg types must be complete. */
10405 require_complete_types_for_parms (last_function_parms);
10409 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises);
10410 /* If the declarator is not suitable for a function definition,
10411 cause a syntax error. */
10412 if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
10414 fntype = TREE_TYPE (decl1);
10416 restype = TREE_TYPE (fntype);
10417 if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
10418 && ! CLASSTYPE_GOT_SEMICOLON (restype))
10420 cp_error ("semicolon missing after declaration of `%#T'", restype);
10421 shadow_tag (build_tree_list (NULL_TREE, restype));
10422 CLASSTYPE_GOT_SEMICOLON (restype) = 1;
10423 if (TREE_CODE (fntype) == FUNCTION_TYPE)
10424 fntype = build_function_type (integer_type_node,
10425 TYPE_ARG_TYPES (fntype));
10427 fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
10429 TYPE_ARG_TYPES (fntype));
10430 TREE_TYPE (decl1) = fntype;
10433 if (TREE_CODE (fntype) == METHOD_TYPE)
10434 ctype = TYPE_METHOD_BASETYPE (fntype);
10435 else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
10436 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
10437 && DECL_CONTEXT (decl1) == NULL_TREE)
10439 /* If this doesn't return integer_type, complain. */
10440 if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
10442 warning ("return type for `main' changed to integer type");
10443 TREE_TYPE (decl1) = fntype = default_function_type;
10445 warn_about_return_type = 0;
10449 /* Warn if function was previously implicitly declared
10450 (but not if we warned then). */
10451 if (! warn_implicit
10452 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
10453 cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
10455 current_function_decl = decl1;
10458 cadillac_start_function (decl1);
10460 announce_function (decl1);
10462 if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE)
10464 if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
10465 error_with_aggr_type (TREE_TYPE (fntype),
10466 "return-type `%s' is an incomplete type");
10468 error ("return-type is an incomplete type");
10470 /* Make it return void instead, but don't change the
10471 type of the DECL_RESULT, in case we have a named return value. */
10474 = build_cplus_method_type (build_type_variant (ctype,
10475 TREE_READONLY (decl1),
10476 TREE_SIDE_EFFECTS (decl1)),
10478 FUNCTION_ARG_CHAIN (decl1));
10481 = build_function_type (void_type_node,
10482 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
10483 DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TREE_TYPE (fntype));
10486 if (warn_about_return_type)
10487 warning ("return-type defaults to `int'");
10489 /* Make the init_value nonzero so pushdecl knows this is not tentative.
10490 error_mark_node is replaced below (in poplevel) with the BLOCK. */
10491 DECL_INITIAL (decl1) = error_mark_node;
10493 /* Didn't get anything from C. */
10494 olddecl = NULL_TREE;
10496 /* This function exists in static storage.
10497 (This does not mean `static' in the C sense!) */
10498 TREE_STATIC (decl1) = 1;
10500 /* If this function belongs to an interface, it is public.
10501 If it belongs to someone else's interface, it is also external.
10502 It doesn't matter whether it's inline or not. */
10503 if (interface_unknown == 0)
10505 TREE_PUBLIC (decl1) = 1;
10506 DECL_EXTERNAL (decl1) = (interface_only
10507 || (DECL_INLINE (decl1)
10508 && ! flag_implement_inlines));
10511 /* This is a definition, not a reference.
10512 So normally clear DECL_EXTERNAL.
10513 However, `extern inline' acts like a declaration except for
10514 defining how to inline. So set DECL_EXTERNAL in that case. */
10515 DECL_EXTERNAL (decl1) = current_extern_inline;
10517 /* Record the decl so that the function name is defined.
10518 If we already have a decl for this name, and it is a FUNCTION_DECL,
10519 use the old decl. */
10521 if (pre_parsed_p == 0)
10523 current_function_decl = decl1 = pushdecl (decl1);
10524 DECL_MAIN_VARIANT (decl1) = decl1;
10525 fntype = TREE_TYPE (decl1);
10528 current_function_decl = decl1;
10530 if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
10532 if (TREE_CODE (fntype) == METHOD_TYPE)
10533 TREE_TYPE (decl1) = fntype
10534 = build_function_type (TREE_TYPE (fntype),
10535 TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
10536 last_function_parms = TREE_CHAIN (last_function_parms);
10537 DECL_ARGUMENTS (decl1) = last_function_parms;
10540 restype = TREE_TYPE (fntype);
10543 current_binding_level->parm_flag = 1;
10545 /* Save the parm names or decls from this function's declarator
10546 where store_parm_decls will find them. */
10547 current_function_parms = last_function_parms;
10548 current_function_parm_tags = last_function_parm_tags;
10550 GNU_xref_function (decl1, current_function_parms);
10552 make_function_rtl (decl1);
10556 push_nested_class (ctype, 1);
10558 /* If we're compiling a friend function, neither of the variables
10559 current_class_decl nor current_class_type will have values. */
10560 if (! doing_friend)
10562 /* We know that this was set up by `grokclassfn'.
10563 We do not wait until `store_parm_decls', since evil
10564 parse errors may never get us to that point. Here
10565 we keep the consistency between `current_class_type'
10566 and `current_class_decl'. */
10567 current_class_decl = last_function_parms;
10568 my_friendly_assert (current_class_decl != NULL_TREE
10569 && TREE_CODE (current_class_decl) == PARM_DECL, 162);
10570 if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
10572 tree variant = TREE_TYPE (TREE_TYPE (current_class_decl));
10573 if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE)
10575 /* Can't call build_indirect_ref here, because it has special
10576 logic to return C_C_D given this argument. */
10577 C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
10578 CLASSTYPE_INST_VAR (ctype) = C_C_D;
10582 C_C_D = CLASSTYPE_INST_VAR (ctype);
10583 /* `current_class_decl' is different for every
10584 function we compile. */
10585 TREE_OPERAND (C_C_D, 0) = current_class_decl;
10587 TREE_READONLY (C_C_D) = TYPE_READONLY (variant);
10588 TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant);
10589 TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant);
10592 C_C_D = current_class_decl;
10597 if (DECL_STATIC_FUNCTION_P (decl1))
10598 push_nested_class (DECL_CONTEXT (decl1), 2);
10600 push_memoized_context (0, 1);
10603 /* Allocate further tree nodes temporarily during compilation
10604 of this function only. Tiemann moved up here from bottom of fn. */
10605 temporary_allocation ();
10607 /* Promote the value to int before returning it. */
10608 if (C_PROMOTING_INTEGER_TYPE_P (restype))
10610 /* It retains unsignedness if traditional or if it isn't
10611 really getting wider. */
10612 if (TREE_UNSIGNED (restype)
10613 && (flag_traditional
10614 || TYPE_PRECISION (restype)
10615 == TYPE_PRECISION (integer_type_node)))
10616 restype = unsigned_type_node;
10618 restype = integer_type_node;
10620 if (DECL_RESULT (decl1) == NULL_TREE)
10621 DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, restype);
10623 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)))
10625 dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10626 ctor_label = NULL_TREE;
10630 dtor_label = NULL_TREE;
10631 if (DECL_CONSTRUCTOR_P (decl1))
10632 ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10635 /* If this fcn was already referenced via a block-scope `extern' decl
10636 (or an implicit decl), propagate certain information about the usage. */
10637 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
10638 TREE_ADDRESSABLE (decl1) = 1;
10643 /* Store the parameter declarations into the current function declaration.
10644 This is called after parsing the parameter declarations, before
10645 digesting the body of the function.
10647 Also install to binding contour return value identifier, if any. */
10650 store_parm_decls ()
10652 register tree fndecl = current_function_decl;
10653 register tree parm;
10654 int parms_have_cleanups = 0;
10657 /* This is either a chain of PARM_DECLs (when a prototype is used). */
10658 tree specparms = current_function_parms;
10660 /* This is a list of types declared among parms in a prototype. */
10661 tree parmtags = current_function_parm_tags;
10663 /* This is a chain of any other decls that came in among the parm
10664 declarations. If a parm is declared with enum {foo, bar} x;
10665 then CONST_DECLs for foo and bar are put here. */
10666 tree nonparms = NULL_TREE;
10668 if (current_binding_level == global_binding_level)
10669 fatal ("parse errors have confused me too much");
10671 /* Initialize RTL machinery. */
10672 init_function_start (fndecl, input_filename, lineno);
10674 /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
10675 declare_function_name ();
10677 /* Create a binding level for the parms. */
10678 expand_start_bindings (0);
10680 /* Prepare to catch raises, if appropriate. */
10681 if (flag_handle_exceptions)
10683 /* Get this cleanup to be run last, since it
10684 is a call to `longjmp'. */
10685 setup_exception_throw_decl ();
10686 eh_decl = current_binding_level->names;
10687 current_binding_level->names = TREE_CHAIN (current_binding_level->names);
10689 if (flag_handle_exceptions)
10690 expand_start_try (integer_one_node, 0, 1);
10692 if (specparms != NULL_TREE)
10694 /* This case is when the function was defined with an ANSI prototype.
10695 The parms already have decls, so we need not do anything here
10696 except record them as in effect
10697 and complain if any redundant old-style parm decls were written. */
10699 register tree next;
10701 /* Must clear this because it might contain TYPE_DECLs declared
10703 storedecls (NULL_TREE);
10704 for (parm = nreverse (specparms); parm; parm = next)
10706 next = TREE_CHAIN (parm);
10707 if (TREE_CODE (parm) == PARM_DECL)
10709 tree cleanup = maybe_build_cleanup (parm);
10710 if (DECL_NAME (parm) == NULL_TREE)
10713 cp_error_at ("parameter name omitted", parm);
10715 /* for C++, this is not an error. */
10719 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
10720 cp_error ("parameter `%D' declared void", parm);
10723 /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
10724 A parameter is assumed not to have any side effects.
10725 If this should change for any reason, then this
10726 will have to wrap the bashed reference type in a save_expr.
10728 Also, if the parameter type is declared to be an X
10729 and there is an X(X&) constructor, we cannot lay it
10730 into the stack (any more), so we make this parameter
10731 look like it is really of reference type. Functions
10732 which pass parameters to this function will know to
10733 create a temporary in their frame, and pass a reference
10736 if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
10737 && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
10738 SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
10744 expand_decl (parm);
10745 expand_decl_cleanup (parm, cleanup);
10746 parms_have_cleanups = 1;
10751 /* If we find an enum constant or a type tag,
10752 put it aside for the moment. */
10753 TREE_CHAIN (parm) = NULL_TREE;
10754 nonparms = chainon (nonparms, parm);
10758 /* Get the decls in their original chain order
10759 and record in the function. This is all and only the
10760 PARM_DECLs that were pushed into scope by the loop above. */
10761 DECL_ARGUMENTS (fndecl) = getdecls ();
10763 storetags (chainon (parmtags, gettags ()));
10766 DECL_ARGUMENTS (fndecl) = NULL_TREE;
10768 /* Now store the final chain of decls for the arguments
10769 as the decl-chain of the current lexical scope.
10770 Put the enumerators in as well, at the front so that
10771 DECL_ARGUMENTS is not modified. */
10773 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
10775 /* Initialize the RTL code for the function. */
10776 DECL_SAVED_INSNS (fndecl) = NULL_RTX;
10777 expand_function_start (fndecl, parms_have_cleanups);
10779 if (flag_handle_exceptions)
10781 /* Make the throw decl visible at this level, just
10782 not in the way of the parameters. */
10783 pushdecl (eh_decl);
10784 expand_decl_init (eh_decl);
10787 /* Create a binding contour which can be used to catch
10788 cleanup-generated temporaries. Also, if the return value needs or
10789 has initialization, deal with that now. */
10790 if (parms_have_cleanups)
10793 expand_start_bindings (0);
10796 current_function_parms_stored = 1;
10800 maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
10801 expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup);
10804 /* If this function is `main', emit a call to `__main'
10805 to run global initializers, etc. */
10806 if (DECL_NAME (fndecl)
10807 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
10808 && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
10809 && DECL_CONTEXT (fndecl) == NULL_TREE)
10811 expand_main_function ();
10814 expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
10818 output_builtin_tdesc_entries ();
10822 /* Bind a name and initialization to the return value of
10823 the current function. */
10825 store_return_init (return_id, init)
10826 tree return_id, init;
10828 tree decl = DECL_RESULT (current_function_decl);
10831 /* Give this error as many times as there are occurrences,
10832 so that users can use Emacs compilation buffers to find
10833 and fix all such places. */
10834 pedwarn ("ANSI C++ does not permit named return values");
10836 if (return_id != NULL_TREE)
10838 if (DECL_NAME (decl) == NULL_TREE)
10840 DECL_NAME (decl) = return_id;
10841 DECL_ASSEMBLER_NAME (decl) = return_id;
10844 error ("return identifier `%s' already in place",
10845 IDENTIFIER_POINTER (DECL_NAME (decl)));
10848 /* Can't let this happen for constructors. */
10849 if (DECL_CONSTRUCTOR_P (current_function_decl))
10851 error ("can't redefine default return value for constructors");
10855 /* If we have a named return value, put that in our scope as well. */
10856 if (DECL_NAME (decl) != NULL_TREE)
10858 /* If this named return value comes in a register,
10859 put it in a pseudo-register. */
10860 if (DECL_REGISTER (decl))
10862 original_result_rtx = DECL_RTL (decl);
10863 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
10866 /* Let `finish_decl' know that this initializer is ok. */
10867 DECL_INITIAL (decl) = init;
10869 finish_decl (decl, init, 0, 0);
10874 /* Generate code for default X() constructor. */
10876 build_default_constructor (fndecl)
10879 int i = CLASSTYPE_N_BASECLASSES (current_class_type);
10880 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
10881 tree fields = TYPE_FIELDS (current_class_type);
10882 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
10884 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
10885 parm = TREE_CHAIN (parm);
10886 parm = DECL_REFERENCE_SLOT (parm);
10890 tree basetype = TREE_VEC_ELT (binfos, i);
10891 if (TYPE_HAS_INIT_REF (basetype))
10893 tree name = TYPE_NAME (basetype);
10894 if (TREE_CODE (name) == TYPE_DECL)
10895 name = DECL_NAME (name);
10896 current_base_init_list = tree_cons (name, parm, current_base_init_list);
10899 for (; fields; fields = TREE_CHAIN (fields))
10902 if (TREE_STATIC (fields))
10904 if (TREE_CODE (fields) != FIELD_DECL)
10906 if (DECL_NAME (fields))
10908 if (VFIELD_NAME_P (DECL_NAME (fields)))
10910 if (VBASE_NAME_P (DECL_NAME (fields)))
10913 /* True for duplicate members. */
10914 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields)
10918 init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields);
10919 init = build_tree_list (NULL_TREE, init);
10921 current_member_init_list
10922 = tree_cons (DECL_NAME (fields), init, current_member_init_list);
10927 /* Finish up a function declaration and compile that function
10928 all the way to assembler language output. The free the storage
10929 for the function definition.
10931 This is called after parsing the body of the function definition.
10932 LINENO is the current line number.
10934 C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
10935 (and expand_end_bindings) must be made to take care of the binding
10936 contour for the base initializers. This is only relevant for
10940 finish_function (lineno, call_poplevel)
10944 register tree fndecl = current_function_decl;
10945 tree fntype, ctype = NULL_TREE;
10946 rtx head, last_parm_insn, mark;
10947 extern int sets_exception_throw_decl;
10948 /* Label to use if this function is supposed to return a value. */
10949 tree no_return_label = NULL_TREE;
10950 tree decls = NULL_TREE;
10952 /* When we get some parse errors, we can end up without a
10953 current_function_decl, so cope. */
10954 if (fndecl == NULL_TREE)
10957 fntype = TREE_TYPE (fndecl);
10959 /* TREE_READONLY (fndecl) = 1;
10960 This caused &foo to be of type ptr-to-const-function
10961 which then got a warning when stored in a ptr-to-function variable. */
10963 /* This happens on strange parse errors. */
10964 if (! current_function_parms_stored)
10967 store_parm_decls ();
10970 if (write_symbols != NO_DEBUG && TREE_CODE (fntype) != METHOD_TYPE)
10972 tree ttype = target_type (fntype);
10975 if (IS_AGGR_TYPE (ttype))
10976 /* Let debugger know it should output info for this type. */
10977 note_debug_info_needed (ttype);
10979 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
10981 ttype = target_type (TREE_TYPE (parmdecl));
10982 if (IS_AGGR_TYPE (ttype))
10983 /* Let debugger know it should output info for this type. */
10984 note_debug_info_needed (ttype);
10988 /* Clean house because we will need to reorder insns here. */
10989 do_pending_stack_adjust ();
10993 tree binfo = TYPE_BINFO (current_class_type);
10994 tree cond = integer_one_node;
10995 tree exprstmt, vfields;
10996 tree in_charge_node = lookup_name (in_charge_identifier, 0);
10998 int ok_to_optimize_dtor = 0;
11000 if (current_function_assigns_this)
11001 cond = build (NE_EXPR, integer_type_node,
11002 current_class_decl, integer_zero_node);
11005 int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
11007 /* If this destructor is empty, then we don't need to check
11008 whether `this' is NULL in some cases. */
11009 mark = get_last_insn ();
11010 last_parm_insn = get_first_nonparm_insn ();
11012 if ((flag_this_is_variable & 1) == 0)
11013 ok_to_optimize_dtor = 1;
11014 else if (mark == last_parm_insn)
11015 ok_to_optimize_dtor
11016 = (n_baseclasses == 0
11017 || (n_baseclasses == 1
11018 && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
11021 /* These initializations might go inline. Protect
11022 the binding level of the parms. */
11024 expand_start_bindings (0);
11026 if (current_function_assigns_this)
11028 current_function_assigns_this = 0;
11029 current_function_just_assigned_this = 0;
11032 /* Generate the code to call destructor on base class.
11033 If this destructor belongs to a class with virtual
11034 functions, then set the virtual function table
11035 pointer to represent the type of our base class. */
11037 /* This side-effect makes call to `build_delete' generate the
11038 code we have to have at the end of this destructor. */
11039 TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
11041 /* These are two cases where we cannot delegate deletion. */
11042 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
11043 || TREE_GETS_DELETE (current_class_type))
11044 exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
11045 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11047 exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
11048 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11050 /* If we did not assign to this, then `this' is non-zero at
11051 the end of a destructor. As a special optimization, don't
11052 emit test if this is an empty destructor. If it does nothing,
11053 it does nothing. If it calls a base destructor, the base
11054 destructor will perform the test. */
11056 if (exprstmt != error_mark_node
11057 && (TREE_CODE (exprstmt) != NOP_EXPR
11058 || TREE_OPERAND (exprstmt, 0) != integer_zero_node
11059 || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
11061 expand_label (dtor_label);
11062 if (cond != integer_one_node)
11063 expand_start_cond (cond, 0);
11064 if (exprstmt != void_zero_node)
11065 /* Don't call `expand_expr_stmt' if we're not going to do
11066 anything, since -Wall will give a diagnostic. */
11067 expand_expr_stmt (exprstmt);
11069 /* Run destructor on all virtual baseclasses. */
11070 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11072 tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
11073 expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
11074 in_charge_node, integer_two_node), 0);
11077 if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
11079 tree ptr = convert_pointer_to_vbase (vbases, current_class_decl);
11080 expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases)),
11081 ptr, integer_zero_node,
11082 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
11084 vbases = TREE_CHAIN (vbases);
11086 expand_end_cond ();
11089 do_pending_stack_adjust ();
11090 if (cond != integer_one_node)
11091 expand_end_cond ();
11094 TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
11096 virtual_size = c_sizeof (current_class_type);
11098 /* At the end, call delete if that's what's requested. */
11099 if (TREE_GETS_DELETE (current_class_type))
11100 /* This NOP_EXPR means we are in a static call context. */
11103 (build_indirect_ref
11104 (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type),
11107 ansi_opname[(int) DELETE_EXPR],
11108 tree_cons (NULL_TREE, current_class_decl,
11109 build_tree_list (NULL_TREE, virtual_size)),
11110 NULL_TREE, LOOKUP_NORMAL);
11111 else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11112 exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
11115 exprstmt = NULL_TREE;
11119 cond = build (BIT_AND_EXPR, integer_type_node,
11120 in_charge_node, integer_one_node);
11121 expand_start_cond (cond, 0);
11122 expand_expr_stmt (exprstmt);
11123 expand_end_cond ();
11126 /* End of destructor. */
11127 expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0);
11128 poplevel (2, 0, 0); /* XXX change to 1 */
11130 /* Back to the top of destructor. */
11131 /* Dont execute destructor code if `this' is NULL. */
11132 mark = get_last_insn ();
11133 last_parm_insn = get_first_nonparm_insn ();
11134 if (last_parm_insn == NULL_RTX)
11135 last_parm_insn = mark;
11137 last_parm_insn = previous_insn (last_parm_insn);
11139 /* Make all virtual function table pointers in non-virtual base
11140 classes point to CURRENT_CLASS_TYPE's virtual function
11142 init_vtbl_ptrs (binfo, 1, 0);
11143 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11144 expand_vbase_vtables_init (binfo, binfo, C_C_D, current_class_decl, 0);
11145 if (! ok_to_optimize_dtor)
11147 cond = build_binary_op (NE_EXPR,
11148 current_class_decl, integer_zero_node, 1);
11149 expand_start_cond (cond, 0);
11151 if (mark != get_last_insn ())
11152 reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
11153 if (! ok_to_optimize_dtor)
11154 expand_end_cond ();
11156 else if (current_function_assigns_this)
11158 /* Does not need to call emit_base_init, because
11159 that is done (if needed) just after assignment to this
11162 if (DECL_CONSTRUCTOR_P (current_function_decl))
11164 expand_label (ctor_label);
11165 ctor_label = NULL_TREE;
11169 decls = getdecls ();
11170 if (flag_handle_exceptions == 2)
11171 deactivate_exception_cleanups ();
11172 expand_end_bindings (decls, decls != NULL_TREE, 0);
11173 poplevel (decls != NULL_TREE, 0, 0);
11175 c_expand_return (current_class_decl);
11177 else if (TYPE_MAIN_VARIANT (TREE_TYPE (
11178 DECL_RESULT (current_function_decl))) != void_type_node
11179 && return_label != NULL_RTX)
11180 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11182 current_function_assigns_this = 0;
11183 current_function_just_assigned_this = 0;
11184 base_init_insns = NULL_RTX;
11186 else if (DECL_CONSTRUCTOR_P (fndecl))
11188 tree allocated_this;
11189 tree cond, thenclause;
11190 /* Allow constructor for a type to get a new instance of the object
11191 using `build_new'. */
11192 tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
11193 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
11195 DECL_RETURNS_FIRST_ARG (fndecl) = 1;
11197 if (flag_this_is_variable > 0)
11199 cond = build_binary_op (EQ_EXPR,
11200 current_class_decl, integer_zero_node, 1);
11201 thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
11202 build_new (NULL_TREE, current_class_type, void_type_node, 0));
11203 if (flag_handle_exceptions == 2)
11205 tree cleanup, cleanup_deallocate;
11208 /* This is the size of the virtual object pointed to by
11209 allocated_this. In this case, it is simple. */
11210 virtual_size = c_sizeof (current_class_type);
11212 allocated_this = build_decl (VAR_DECL, NULL_TREE, ptr_type_node);
11213 DECL_REGISTER (allocated_this) = 1;
11214 DECL_INITIAL (allocated_this) = error_mark_node;
11215 expand_decl (allocated_this);
11216 expand_decl_init (allocated_this);
11217 /* How we cleanup `this' if an exception was raised before
11218 we are ready to bail out. */
11219 cleanup = TREE_GETS_DELETE (current_class_type)
11220 ? build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, allocated_this, virtual_size, NULL_TREE)
11221 /* The size of allocated_this is wrong, and hence the
11222 second argument to operator delete will be wrong. */
11223 : build_delete (TREE_TYPE (allocated_this), allocated_this,
11224 integer_three_node,
11225 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 1);
11227 = build_modify_expr (current_class_decl, NOP_EXPR, integer_zero_node);
11228 cleanup = tree_cons (NULL_TREE, cleanup,
11229 build_tree_list (NULL_TREE, cleanup_deallocate));
11231 expand_decl_cleanup (allocated_this,
11232 build (COND_EXPR, integer_type_node,
11233 build (NE_EXPR, integer_type_node,
11234 allocated_this, integer_zero_node),
11235 build_compound_expr (cleanup),
11236 integer_zero_node));
11240 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
11242 /* must keep the first insn safe. */
11243 head = get_insns ();
11245 /* this note will come up to the top with us. */
11246 mark = get_last_insn ();
11248 if (flag_this_is_variable > 0)
11250 expand_start_cond (cond, 0);
11251 expand_expr_stmt (thenclause);
11252 if (flag_handle_exceptions == 2)
11253 expand_assignment (allocated_this, current_class_decl, 0, 0);
11254 expand_end_cond ();
11258 if (DECL_NAME (fndecl) == NULL_TREE
11259 && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
11260 build_default_constructor (fndecl);
11263 /* Emit insns from `emit_base_init' which sets up virtual
11264 function table pointer(s). */
11265 emit_insns (base_init_insns);
11266 base_init_insns = NULL_RTX;
11268 /* This is where the body of the constructor begins.
11269 If there were no insns in this function body, then the
11270 last_parm_insn is also the last insn.
11272 If optimization is enabled, last_parm_insn may move, so
11273 we don't hold on to it (across emit_base_init). */
11274 last_parm_insn = get_first_nonparm_insn ();
11275 if (last_parm_insn == NULL_RTX)
11276 last_parm_insn = mark;
11278 last_parm_insn = previous_insn (last_parm_insn);
11280 if (mark != get_last_insn ())
11281 reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
11283 /* This is where the body of the constructor ends. */
11284 expand_label (ctor_label);
11285 ctor_label = NULL_TREE;
11286 if (flag_handle_exceptions == 2)
11288 expand_assignment (allocated_this, integer_zero_node, 0, 0);
11290 deactivate_exception_cleanups ();
11293 pop_implicit_try_blocks (NULL_TREE);
11297 expand_end_bindings (decls = getdecls (), decls != NULL_TREE, 0);
11298 poplevel (decls != NULL_TREE, 1, 0);
11301 c_expand_return (current_class_decl);
11303 current_function_assigns_this = 0;
11304 current_function_just_assigned_this = 0;
11306 else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
11307 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
11308 && DECL_CONTEXT (fndecl) == NULL_TREE)
11310 /* Make it so that `main' always returns 0 by default. */
11312 c_expand_return (integer_one_node);
11314 c_expand_return (integer_zero_node);
11317 else if (return_label != NULL_RTX
11318 && current_function_return_value == NULL_TREE
11319 && ! DECL_NAME (DECL_RESULT (current_function_decl)))
11320 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11323 expand_gc_prologue_and_epilogue ();
11325 /* That's the end of the vtable decl's life. Need to mark it such
11326 if doing stupid register allocation.
11328 Note that current_vtable_decl is really an INDIRECT_REF
11329 on top of a VAR_DECL here. */
11330 if (obey_regdecls && current_vtable_decl)
11331 use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0)));
11333 /* If this function is supposed to return a value, ensure that
11334 we do not fall into the cleanups by mistake. The end of our
11335 function will look like this:
11337 user code (may have return stmt somewhere)
11338 goto no_return_label
11343 NOTE_INSN_FUNCTION_END
11347 If the user omits a return stmt in the USER CODE section, we
11348 will have a control path which reaches NOTE_INSN_FUNCTION_END.
11349 Otherwise, we won't. */
11350 if (no_return_label)
11352 DECL_CONTEXT (no_return_label) = fndecl;
11353 DECL_INITIAL (no_return_label) = error_mark_node;
11354 DECL_SOURCE_FILE (no_return_label) = input_filename;
11355 DECL_SOURCE_LINE (no_return_label) = lineno;
11356 expand_goto (no_return_label);
11361 /* remove the binding contour which is used
11362 to catch cleanup-generated temporaries. */
11363 expand_end_bindings (0, 0, 0);
11364 poplevel (0, 0, 0);
11368 /* Emit label at beginning of cleanup code for parameters. */
11369 emit_label (cleanup_label);
11372 /* Cheap hack to get better code from GNU C++. Remove when cse is fixed. */
11373 if (exception_throw_decl && sets_exception_throw_decl == 0)
11374 expand_assignment (exception_throw_decl, integer_zero_node, 0, 0);
11377 if (flag_handle_exceptions)
11380 expand_start_except (0, 0);
11381 expand_end_except ();
11384 /* Get return value into register if that's where it's supposed to be. */
11385 if (original_result_rtx)
11386 fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
11388 /* Finish building code that will trigger warnings if users forget
11389 to make their functions return values. */
11390 if (no_return_label || cleanup_label)
11391 emit_jump (return_label);
11392 if (no_return_label)
11394 /* We don't need to call `expand_*_return' here because we
11395 don't need any cleanups here--this path of code is only
11396 for error checking purposes. */
11397 expand_label (no_return_label);
11400 /* reset scope for C++: if we were in the scope of a class,
11401 then when we finish this function, we are not longer so.
11402 This cannot be done until we know for sure that no more
11403 class members will ever be referenced in this function
11404 (i.e., calls to destructors). */
11405 if (current_class_name)
11407 ctype = current_class_type;
11408 pop_nested_class (1);
11411 pop_memoized_context (1);
11413 /* Forget about all overloaded functions defined in
11414 this scope which go away. */
11415 while (overloads_to_forget)
11417 IDENTIFIER_GLOBAL_VALUE (TREE_PURPOSE (overloads_to_forget))
11418 = TREE_VALUE (overloads_to_forget);
11419 overloads_to_forget = TREE_CHAIN (overloads_to_forget);
11422 /* Generate rtl for function exit. */
11423 expand_function_end (input_filename, lineno, 1);
11425 /* This must come after expand_function_end because cleanups might
11426 have declarations (from inline functions) that need to go into
11427 this function's blocks. */
11428 if (current_binding_level->parm_flag != 1)
11429 my_friendly_abort (122);
11430 poplevel (1, 0, 1);
11432 /* Must mark the RESULT_DECL as being in this function. */
11433 DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
11435 /* Obey `register' declarations if `setjmp' is called in this fn. */
11436 if (flag_traditional && current_function_calls_setjmp)
11437 setjmp_protect (DECL_INITIAL (fndecl));
11439 /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
11440 to the FUNCTION_DECL node itself. */
11441 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
11443 /* So we can tell if jump_optimize sets it to 1. */
11446 /* ??? Compensate for Sun brain damage in dealing with data segments
11449 && (DECL_CONSTRUCTOR_P (fndecl)
11450 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
11451 && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype)))
11452 DECL_INLINE (fndecl) = 0;
11454 if (DECL_EXTERNAL (fndecl)
11455 /* This function is just along for the ride. If we can make
11456 it inline, that's great. Otherwise, just punt it. */
11457 && (DECL_INLINE (fndecl) == 0
11459 || function_cannot_inline_p (fndecl)))
11461 extern int rtl_dump_and_exit;
11462 int old_rtl_dump_and_exit = rtl_dump_and_exit;
11463 int inline_spec = DECL_INLINE (fndecl);
11465 /* This throws away the code for FNDECL. */
11466 rtl_dump_and_exit = 1;
11467 /* This throws away the memory of the code for FNDECL. */
11468 if (flag_no_inline)
11469 DECL_INLINE (fndecl) = 0;
11470 rest_of_compilation (fndecl);
11471 rtl_dump_and_exit = old_rtl_dump_and_exit;
11472 DECL_INLINE (fndecl) = inline_spec;
11476 /* Run the optimizers and output the assembler code for this
11478 rest_of_compilation (fndecl);
11481 if (DECL_INLINE (fndecl)
11482 && !TREE_ASM_WRITTEN (fndecl) && DECL_FUNCTION_MEMBER_P (fndecl))
11484 mark_inline_for_output (fndecl);
11487 if (ctype && TREE_ASM_WRITTEN (fndecl))
11488 note_debug_info_needed (ctype);
11490 current_function_returns_null |= can_reach_end;
11492 /* Since we don't normally go through c_expand_return for constructors,
11493 this normally gets the wrong value.
11494 Also, named return values have their return codes emitted after
11495 NOTE_INSN_FUNCTION_END, confusing jump.c. */
11496 if (DECL_CONSTRUCTOR_P (fndecl)
11497 || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
11498 current_function_returns_null = 0;
11500 if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
11501 cp_warning ("`noreturn' function `%D' does return", fndecl);
11502 else if ((warn_return_type || pedantic)
11503 && current_function_returns_null
11504 && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
11506 /* If this function returns non-void and control can drop through,
11508 cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
11510 /* With just -W, complain only if function returns both with
11511 and without a value. */
11512 else if (extra_warnings
11513 && current_function_returns_value && current_function_returns_null)
11514 warning ("this function may return with or without a value");
11516 /* Free all the tree nodes making up this function. */
11517 /* Switch back to allocating nodes permanently
11518 until we start another function. */
11519 permanent_allocation (1);
11522 cadillac_finish_function (fndecl);
11524 if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
11526 /* Stop pointing to the local nodes about to be freed. */
11527 /* But DECL_INITIAL must remain nonzero so we know this
11528 was an actual function definition. */
11529 DECL_INITIAL (fndecl) = error_mark_node;
11530 if (! DECL_CONSTRUCTOR_P (fndecl)
11531 || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
11532 DECL_ARGUMENTS (fndecl) = NULL_TREE;
11535 /* Let the error reporting routines know that we're outside a function. */
11536 current_function_decl = NULL_TREE;
11537 named_label_uses = NULL_TREE;
11540 /* Create the FUNCTION_DECL for a function definition.
11541 LINE1 is the line number that the definition absolutely begins on.
11542 LINE2 is the line number that the name of the function appears on.
11543 DECLSPECS and DECLARATOR are the parts of the declaration;
11544 they describe the return type and the name of the function,
11545 but twisted together in a fashion that parallels the syntax of C.
11547 This function creates a binding context for the function body
11548 as well as setting up the FUNCTION_DECL in current_function_decl.
11550 Returns a FUNCTION_DECL on success.
11552 If the DECLARATOR is not suitable for a function (it defines a datum
11553 instead), we return 0, which tells yyparse to report a parse error.
11555 May return void_type_node indicating that this method is actually
11556 a friend. See grokfield for more details.
11558 Came here with a `.pushlevel' .
11560 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
11561 CHANGES TO CODE IN `grokfield'. */
11563 start_method (declspecs, declarator, raises)
11564 tree declarator, declspecs, raises;
11566 tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises);
11568 /* Something too ugly to handle. */
11569 if (fndecl == NULL_TREE)
11572 /* Pass friends other than inline friend functions back. */
11573 if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
11576 if (TREE_CODE (fndecl) != FUNCTION_DECL)
11577 /* Not a function, tell parser to report parse error. */
11580 if (IS_SIGNATURE (current_class_type))
11582 IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
11583 /* In case we need this info later. */
11584 HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1;
11587 if (DECL_IN_AGGR_P (fndecl))
11589 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
11591 if (DECL_CONTEXT (fndecl))
11592 cp_error ("`%D' is already defined in class %s", fndecl,
11593 TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
11595 return void_type_node;
11598 if (flag_default_inline)
11599 DECL_INLINE (fndecl) = 1;
11601 /* We read in the parameters on the maybepermanent_obstack,
11602 but we won't be getting back to them until after we
11603 may have clobbered them. So the call to preserve_data
11604 will keep them safe. */
11607 if (! DECL_FRIEND_P (fndecl))
11609 if (DECL_CHAIN (fndecl) != NULL_TREE)
11611 /* Need a fresh node here so that we don't get circularity
11612 when we link these together. If FNDECL was a friend, then
11613 `pushdecl' does the right thing, which is nothing wrt its
11614 current value of DECL_CHAIN. */
11615 fndecl = copy_node (fndecl);
11617 if (TREE_CHAIN (fndecl))
11619 fndecl = copy_node (fndecl);
11620 TREE_CHAIN (fndecl) = NULL_TREE;
11623 if (DECL_CONSTRUCTOR_P (fndecl))
11624 grok_ctor_properties (current_class_type, fndecl);
11625 else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
11626 grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
11629 finish_decl (fndecl, NULL_TREE, NULL_TREE, 0);
11631 /* Make a place for the parms */
11633 current_binding_level->parm_flag = 1;
11635 DECL_IN_AGGR_P (fndecl) = 1;
11639 /* Go through the motions of finishing a function definition.
11640 We don't compile this method until after the whole class has
11643 FINISH_METHOD must return something that looks as though it
11644 came from GROKFIELD (since we are defining a method, after all).
11646 This is called after parsing the body of the function definition.
11647 STMTS is the chain of statements that makes up the function body.
11649 DECL is the ..._DECL that `start_method' provided. */
11652 finish_method (decl)
11655 register tree fndecl = decl;
11658 register tree link;
11660 if (TYPE_MAIN_VARIANT (decl) == void_type_node)
11663 old_initial = DECL_INITIAL (fndecl);
11665 /* Undo the level for the parms (from start_method).
11666 This is like poplevel, but it causes nothing to be
11667 saved. Saving information here confuses symbol-table
11668 output routines. Besides, this information will
11669 be correctly output when this method is actually
11672 /* Clear out the meanings of the local variables of this level;
11673 also record in each decl which block it belongs to. */
11675 for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
11677 if (DECL_NAME (link) != NULL_TREE)
11678 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
11679 my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
11680 DECL_CONTEXT (link) = NULL_TREE;
11683 /* Restore all name-meanings of the outer levels
11684 that were shadowed by this level. */
11686 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
11687 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11688 for (link = current_binding_level->class_shadowed;
11689 link; link = TREE_CHAIN (link))
11690 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11691 for (link = current_binding_level->type_shadowed;
11692 link; link = TREE_CHAIN (link))
11693 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11695 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
11696 (HOST_WIDE_INT) current_binding_level->level_chain,
11697 current_binding_level->parm_flag,
11698 current_binding_level->keep,
11699 current_binding_level->tag_transparent);
11701 poplevel (0, 0, 0);
11703 DECL_INITIAL (fndecl) = old_initial;
11705 /* We used to check if the context of FNDECL was different from
11706 current_class_type as another way to get inside here. This didn't work
11707 for String.cc in libg++. */
11708 if (DECL_FRIEND_P (fndecl))
11710 CLASSTYPE_INLINE_FRIENDS (current_class_type)
11711 = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
11712 decl = void_type_node;
11718 /* Called when a new struct TYPE is defined.
11719 If this structure or union completes the type of any previous
11720 variable declaration, lay it out and output its rtl. */
11723 hack_incomplete_structures (type)
11728 if (current_binding_level->n_incomplete == 0)
11731 if (!type) /* Don't do this for class templates. */
11734 for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
11735 if (TREE_TYPE (decl) == type
11736 || (TREE_TYPE (decl)
11737 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
11738 && TREE_TYPE (TREE_TYPE (decl)) == type))
11740 if (TREE_CODE (decl) == TYPE_DECL)
11741 layout_type (TREE_TYPE (decl));
11744 int toplevel = global_binding_level == current_binding_level;
11745 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
11746 && TREE_TYPE (TREE_TYPE (decl)) == type)
11747 layout_type (TREE_TYPE (decl));
11748 layout_decl (decl, 0);
11749 rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
11752 expand_decl (decl);
11753 expand_decl_cleanup (decl, maybe_build_cleanup (decl));
11754 expand_decl_init (decl);
11757 my_friendly_assert (current_binding_level->n_incomplete > 0, 164);
11758 --current_binding_level->n_incomplete;
11762 /* Nonzero if presently building a cleanup. Needed because
11763 SAVE_EXPRs are not the right things to use inside of cleanups.
11764 They are only ever evaluated once, where the cleanup
11765 might be evaluated several times. In this case, a later evaluation
11766 of the cleanup might fill in the SAVE_EXPR_RTL, and it will
11767 not be valid for an earlier cleanup. */
11769 int building_cleanup;
11771 /* If DECL is of a type which needs a cleanup, build that cleanup here.
11772 We don't build cleanups if just going for syntax checking, since
11773 fixup_cleanups does not know how to not handle them.
11775 Don't build these on the momentary obstack; they must live
11776 the life of the binding contour. */
11778 maybe_build_cleanup (decl)
11781 tree type = TREE_TYPE (decl);
11782 if (TYPE_NEEDS_DESTRUCTOR (type))
11784 int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
11786 int old_building_cleanup = building_cleanup;
11787 building_cleanup = 1;
11789 if (TREE_CODE (decl) != PARM_DECL)
11790 temp = suspend_momentary ();
11792 if (TREE_CODE (type) == ARRAY_TYPE)
11796 mark_addressable (decl);
11797 rval = build_unary_op (ADDR_EXPR, decl, 0);
11800 /* Optimize for space over speed here. */
11801 if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
11802 || flag_expensive_optimizations)
11803 flags |= LOOKUP_NONVIRTUAL;
11805 /* Use TYPE_MAIN_VARIANT so we don't get a warning about
11806 calling delete on a `const' variable. */
11807 if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval))))
11808 rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval);
11810 rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0);
11812 if (TYPE_USES_VIRTUAL_BASECLASSES (type)
11813 && ! TYPE_HAS_DESTRUCTOR (type))
11814 rval = build_compound_expr (tree_cons (NULL_TREE, rval,
11815 build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
11817 current_binding_level->have_cleanups = 1;
11818 current_binding_level->more_exceptions_ok = 0;
11820 if (TREE_CODE (decl) != PARM_DECL)
11821 resume_momentary (temp);
11823 building_cleanup = old_building_cleanup;
11830 /* Expand a C++ expression at the statement level.
11831 This is needed to ferret out nodes which have UNKNOWN_TYPE.
11832 The C++ type checker should get all of these out when
11833 expressions are combined with other, type-providing, expressions,
11834 leaving only orphan expressions, such as:
11836 &class::bar; / / takes its address, but does nothing with it.
11840 cplus_expand_expr_stmt (exp)
11843 if (TREE_TYPE (exp) == unknown_type_node)
11845 if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
11846 error ("address of overloaded function with no contextual type information");
11847 else if (TREE_CODE (exp) == COMPONENT_REF)
11848 warning ("useless reference to a member function name, did you forget the ()?");
11852 int remove_implicit_immediately = 0;
11854 if (TREE_CODE (exp) == FUNCTION_DECL)
11856 cp_warning ("reference, not call, to function `%D'", exp);
11857 warning ("at this point in file");
11859 if (TREE_RAISES (exp))
11861 my_friendly_assert (flag_handle_exceptions, 165);
11862 if (flag_handle_exceptions == 2)
11864 if (! current_binding_level->more_exceptions_ok)
11866 extern struct nesting *nesting_stack, *block_stack;
11868 remove_implicit_immediately
11869 = (nesting_stack != block_stack);
11870 cplus_expand_start_try (1);
11872 current_binding_level->have_exceptions = 1;
11876 expand_expr_stmt (break_out_cleanups (exp));
11878 if (remove_implicit_immediately)
11879 pop_implicit_try_blocks (NULL_TREE);
11882 /* Clean up any pending cleanups. This happens when a function call
11883 returns a cleanup-needing value that nobody uses. */
11884 expand_cleanups_to (NULL_TREE);
11887 /* When a stmt has been parsed, this function is called.
11889 Currently, this function only does something within a
11890 constructor's scope: if a stmt has just assigned to this,
11891 and we are in a derived class, we call `emit_base_init'. */
11896 extern struct nesting *cond_stack, *loop_stack, *case_stack;
11899 if (current_function_assigns_this
11900 || ! current_function_just_assigned_this)
11902 if (DECL_CONSTRUCTOR_P (current_function_decl))
11904 /* Constructors must wait until we are out of control
11905 zones before calling base constructors. */
11906 if (cond_stack || loop_stack || case_stack)
11908 emit_insns (base_init_insns);
11909 check_base_init (current_class_type);
11911 current_function_assigns_this = 1;
11914 cadillac_finish_stmt ();
11918 pop_implicit_try_blocks (decl)
11923 my_friendly_assert (current_binding_level->parm_flag == 3, 166);
11924 current_binding_level->names = TREE_CHAIN (decl);
11927 while (current_binding_level->parm_flag == 3)
11929 tree name = get_identifier ("(compiler error)");
11930 tree orig_ex_type = current_exception_type;
11931 tree orig_ex_decl = current_exception_decl;
11932 tree orig_ex_obj = current_exception_object;
11933 tree decl = cplus_expand_end_try (2);
11935 /* @@ It would be nice to make all these point
11936 to exactly the same handler. */
11937 /* Start hidden EXCEPT. */
11938 cplus_expand_start_except (name, decl);
11940 cplus_expand_reraise (NULL_TREE);
11941 current_exception_type = orig_ex_type;
11942 current_exception_decl = orig_ex_decl;
11943 current_exception_object = orig_ex_obj;
11944 /* This will reraise for us. */
11945 cplus_expand_end_except (error_mark_node);
11950 TREE_CHAIN (decl) = current_binding_level->names;
11951 current_binding_level->names = decl;
11955 /* Push a cleanup onto the current binding contour that will cause
11956 ADDR to be cleaned up, in the case that an exception propagates
11957 through its binding contour. */
11960 push_exception_cleanup (addr)
11963 tree decl = build_decl (VAR_DECL, get_identifier (EXCEPTION_CLEANUP_NAME), ptr_type_node);
11966 decl = pushdecl (decl);
11967 DECL_REGISTER (decl) = 1;
11968 store_init_value (decl, addr);
11969 expand_decl (decl);
11970 expand_decl_init (decl);
11972 cleanup = build (COND_EXPR, integer_type_node,
11973 build (NE_EXPR, integer_type_node,
11974 decl, integer_zero_node),
11975 build_delete (TREE_TYPE (addr), decl,
11976 lookup_name (in_charge_identifier, 0),
11977 LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0),
11978 integer_zero_node);
11979 expand_decl_cleanup (decl, cleanup);
11982 /* For each binding contour, emit code that deactivates the
11983 exception cleanups. All other cleanups are left as they were. */
11986 deactivate_exception_cleanups ()
11988 struct binding_level *b = current_binding_level;
11989 tree xyzzy = get_identifier (EXCEPTION_CLEANUP_NAME);
11990 while (b != class_binding_level)
11992 if (b->parm_flag == 3)
11994 tree decls = b->names;
11997 if (DECL_NAME (decls) == xyzzy)
11998 expand_assignment (decls, integer_zero_node, 0, 0);
11999 decls = TREE_CHAIN (decls);
12002 b = b->level_chain;
12006 /* Change a static member function definition into a FUNCTION_TYPE, instead
12007 of the METHOD_TYPE that we create when it's originally parsed. */
12009 revert_static_member_fn (fn, decl, argtypes)
12010 tree *fn, *decl, *argtypes;
12012 tree tmp, function = *fn;
12014 *argtypes = TREE_CHAIN (*argtypes);
12015 tmp = build_function_type (TREE_TYPE (function), *argtypes);
12016 tmp = build_type_variant (tmp, TYPE_READONLY (function),
12017 TYPE_VOLATILE (function));
12018 tmp = build_exception_variant (TYPE_METHOD_BASETYPE (function), tmp,
12019 TYPE_RAISES_EXCEPTIONS (function));
12020 TREE_TYPE (*decl) = tmp;
12022 DECL_STATIC_FUNCTION_P (*decl) = 1;