1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
37 #include <sys/types.h>
41 #define obstack_chunk_alloc xmalloc
42 #define obstack_chunk_free free
44 extern tree builtin_return_address_fndecl;
46 extern struct obstack permanent_obstack;
48 extern int current_class_depth;
50 extern tree cleanups_this_call;
52 /* Stack of places to restore the search obstack back to. */
54 /* Obstack used for remembering local class declarations (like
55 enums and static (const) members. */
57 static struct obstack decl_obstack;
58 static struct stack_level *decl_stack;
60 #ifndef CHAR_TYPE_SIZE
61 #define CHAR_TYPE_SIZE BITS_PER_UNIT
64 #ifndef SHORT_TYPE_SIZE
65 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
69 #define INT_TYPE_SIZE BITS_PER_WORD
72 #ifndef LONG_TYPE_SIZE
73 #define LONG_TYPE_SIZE BITS_PER_WORD
76 #ifndef LONG_LONG_TYPE_SIZE
77 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
80 #ifndef WCHAR_UNSIGNED
81 #define WCHAR_UNSIGNED 0
84 #ifndef FLOAT_TYPE_SIZE
85 #define FLOAT_TYPE_SIZE BITS_PER_WORD
88 #ifndef DOUBLE_TYPE_SIZE
89 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
92 #ifndef LONG_DOUBLE_TYPE_SIZE
93 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
96 /* We let tm.h override the types used here, to handle trivial differences
97 such as the choice of unsigned int or long unsigned int for size_t.
98 When machines start needing nontrivial differences in the size type,
99 it would be best to do something here to figure out automatically
100 from other information what type to use. */
103 #define SIZE_TYPE "long unsigned int"
107 #define PTRDIFF_TYPE "long int"
111 #define WCHAR_TYPE "int"
114 #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
115 define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
116 #define auto_function(NAME, TYPE, CODE) \
118 tree __name = NAME; \
119 tree __type = TYPE; \
120 define_function (IDENTIFIER_POINTER (__name), __type, CODE, \
121 (void (*)())push_overloaded_decl_1, \
122 IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\
125 static tree grokparms PROTO((tree, int));
126 static tree lookup_nested_type PROTO((tree, tree));
127 static char *redeclaration_error_message PROTO((tree, tree));
128 static void grok_op_properties PROTO((tree, int, int));
131 PROTO((char *, tree, enum built_in_function, void (*)(), char *));
133 /* a node which has tree code ERROR_MARK, and whose type is itself.
134 All erroneous expressions are replaced with this node. All functions
135 that accept nodes as arguments should avoid generating error messages
136 if this node is one of the arguments, since it is undesirable to get
137 multiple error messages from one error in the input. */
139 tree error_mark_node;
141 /* Erroneous argument lists can use this *IFF* they do not modify it. */
142 tree error_mark_list;
144 /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
146 tree short_integer_type_node;
147 tree integer_type_node;
148 tree long_integer_type_node;
149 tree long_long_integer_type_node;
151 tree short_unsigned_type_node;
152 tree unsigned_type_node;
153 tree long_unsigned_type_node;
154 tree long_long_unsigned_type_node;
156 tree ptrdiff_type_node;
158 tree unsigned_char_type_node;
159 tree signed_char_type_node;
161 tree wchar_type_node;
162 tree signed_wchar_type_node;
163 tree unsigned_wchar_type_node;
165 tree wchar_decl_node;
167 tree float_type_node;
168 tree double_type_node;
169 tree long_double_type_node;
171 tree intQI_type_node;
172 tree intHI_type_node;
173 tree intSI_type_node;
174 tree intDI_type_node;
176 tree unsigned_intQI_type_node;
177 tree unsigned_intHI_type_node;
178 tree unsigned_intSI_type_node;
179 tree unsigned_intDI_type_node;
181 /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */
183 tree void_type_node, void_list_node;
186 /* Nodes for types `void *' and `const void *'. */
188 tree ptr_type_node, const_ptr_type_node;
190 /* Nodes for types `char *' and `const char *'. */
192 tree string_type_node, const_string_type_node;
194 /* Type `char[256]' or something like it.
195 Used when an array of char is needed and the size is irrelevant. */
197 tree char_array_type_node;
199 /* Type `int[256]' or something like it.
200 Used when an array of int needed and the size is irrelevant. */
202 tree int_array_type_node;
204 /* Type `wchar_t[256]' or something like it.
205 Used when a wide string literal is created. */
207 tree wchar_array_type_node;
209 /* The bool data type, and constants */
210 tree bool_type_node, true_node, false_node;
212 /* type `int ()' -- used for implicit declaration of functions. */
214 tree default_function_type;
216 /* function types `double (double)' and `double (double, double)', etc. */
218 tree double_ftype_double, double_ftype_double_double;
219 tree int_ftype_int, long_ftype_long;
221 /* Function type `void (void *, void *, int)' and similar ones. */
223 tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
225 /* Function type `char *(char *, char *)' and similar ones */
226 tree string_ftype_ptr_ptr, int_ftype_string_string;
228 /* Function type `size_t (const char *)' */
229 tree sizet_ftype_string;
231 /* Function type `int (const void *, const void *, size_t)' */
232 tree int_ftype_cptr_cptr_sizet;
235 tree vtable_entry_type;
236 tree delta_type_node;
238 /* Old rtti stuff. */
239 tree __baselist_desc_type_node;
240 tree __i_desc_type_node, __m_desc_type_node;
241 tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
243 tree __t_desc_type_node, __tp_desc_type_node;
244 tree __access_mode_type_node;
245 tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node;
246 tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node;
247 tree __ptmf_desc_type_node, __ptmd_desc_type_node;
249 /* Not needed yet? May be needed one day? */
250 tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type;
251 tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type;
252 tree __ptmf_desc_array_type, __ptmd_desc_array_type;
255 tree class_star_type_node;
256 tree class_type_node, record_type_node, union_type_node, enum_type_node;
257 tree unknown_type_node;
258 tree opaque_type_node, signature_type_node;
259 tree sigtable_entry_type;
260 tree maybe_gc_cleanup;
262 /* Array type `vtable_entry_type[]' */
265 /* In a destructor, the point at which all derived class destroying
266 has been done, just before any base class destroying will be done. */
270 /* In a constructor, the point at which we are ready to return
271 the pointer to the initialized object. */
275 /* A FUNCTION_DECL which can call `abort'. Not necessarily the
276 one that the user will declare, but sufficient to be called
277 by routines that want to abort the program. */
281 extern rtx cleanup_label, return_label;
283 /* If original DECL_RESULT of current function was a register,
284 but due to being an addressable named return value, would up
285 on the stack, this variable holds the named return value's
286 original location. */
287 rtx original_result_rtx;
289 /* Sequence of insns which represents base initialization. */
292 /* C++: Keep these around to reduce calls to `get_identifier'.
293 Identifiers for `this' in member functions and the auto-delete
294 parameter for destructors. */
295 tree this_identifier, in_charge_identifier;
296 /* Used in pointer to member functions, and in vtables. */
297 tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
298 tree pfn_or_delta2_identifier;
300 /* A list (chain of TREE_LIST nodes) of named label uses.
301 The TREE_PURPOSE field is the list of variables defined
302 the the label's scope defined at the point of use.
303 The TREE_VALUE field is the LABEL_DECL used.
304 The TREE_TYPE field holds `current_binding_level' at the
305 point of the label's use.
307 Used only for jumps to as-yet undefined labels, since
308 jumps to defined labels can have their validity checked
311 static tree named_label_uses;
313 /* A list of objects which have constructors or destructors
314 which reside in the global scope. The decl is stored in
315 the TREE_VALUE slot and the initializer is stored
316 in the TREE_PURPOSE slot. */
317 tree static_aggregates;
321 /* Two expressions that are constants with value zero.
322 The first is of type `int', the second of type `void *'. */
324 tree integer_zero_node;
325 tree null_pointer_node;
327 /* A node for the integer constants 1, 2, and 3. */
329 tree integer_one_node, integer_two_node, integer_three_node;
331 /* Nonzero if we have seen an invalid cross reference
332 to a struct, union, or enum, but not yet printed the message. */
334 tree pending_invalid_xref;
335 /* File and line to appear in the eventual error message. */
336 char *pending_invalid_xref_file;
337 int pending_invalid_xref_line;
339 /* While defining an enum type, this is 1 plus the last enumerator
342 static tree enum_next_value;
344 /* Nonzero means that there was overflow computing enum_next_value. */
346 static int enum_overflow;
348 /* Parsing a function declarator leaves a list of parameter names
349 or a chain or parameter decls here. */
351 tree last_function_parms;
353 /* Parsing a function declarator leaves here a chain of structure
354 and enum types declared in the parmlist. */
356 static tree last_function_parm_tags;
358 /* After parsing the declarator that starts a function definition,
359 `start_function' puts here the list of parameter names or chain of decls.
360 `store_parm_decls' finds it here. */
362 static tree current_function_parms;
364 /* Similar, for last_function_parm_tags. */
365 static tree current_function_parm_tags;
367 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
368 that have names. Here so we can clear out their names' definitions
369 at the end of the function. */
371 static tree named_labels;
373 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
375 static tree shadowed_labels;
377 #if 0 /* Not needed by C++ */
378 /* Nonzero when store_parm_decls is called indicates a varargs function.
379 Value not meaningful after store_parm_decls. */
381 static int c_function_varargs;
384 /* The FUNCTION_DECL for the function currently being compiled,
385 or 0 if between functions. */
386 tree current_function_decl;
388 /* Set to 0 at beginning of a function definition, set to 1 if
389 a return statement that specifies a return value is seen. */
391 int current_function_returns_value;
393 /* Set to 0 at beginning of a function definition, set to 1 if
394 a return statement with no argument is seen. */
396 int current_function_returns_null;
398 /* Set to 0 at beginning of a function definition, and whenever
399 a label (case or named) is defined. Set to value of expression
400 returned from function when that value can be transformed into
401 a named return value. */
403 tree current_function_return_value;
405 /* Set to nonzero by `grokdeclarator' for a function
406 whose return type is defaulted, if warnings for this are desired. */
408 static int warn_about_return_type;
410 /* Nonzero when starting a function declared `extern inline'. */
412 static int current_extern_inline;
414 /* Nonzero means give `double' the same size as `float'. */
416 extern int flag_short_double;
418 /* Nonzero means don't recognize any builtin functions. */
420 extern int flag_no_builtin;
422 /* Nonzero means don't recognize the non-ANSI builtin functions.
425 extern int flag_no_nonansi_builtin;
427 /* Nonzero means disable GNU extensions. */
429 extern int flag_ansi;
431 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
433 extern int flag_huge_objects;
435 /* Nonzero if we want to conserve space in the .o files. We do this
436 by putting uninitialized data and runtime initialized data into
437 .common instead of .data at the expense of not flaging multiple
439 extern int flag_conserve_space;
441 /* Pointers to the base and current top of the language name stack. */
443 extern tree *current_lang_base, *current_lang_stack;
445 /* C and C++ flags are in decl2.c. */
447 /* Set to 0 at beginning of a constructor, set to 1
448 if that function does an allocation before referencing its
449 instance variable. */
450 int current_function_assigns_this;
451 int current_function_just_assigned_this;
453 /* Set to 0 at beginning of a function. Set non-zero when
454 store_parm_decls is called. Don't call store_parm_decls
455 if this flag is non-zero! */
456 int current_function_parms_stored;
458 /* Current end of entries in the gc obstack for stack pointer variables. */
460 int current_function_obstack_index;
462 /* Flag saying whether we have used the obstack in this function or not. */
464 int current_function_obstack_usage;
466 /* Flag used when debugging spew.c */
468 extern int spew_debug;
470 /* This is a copy of the class_shadowed list of the previous class binding
471 contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs
472 when entering another class scope (i.e. a cache miss). */
473 extern tree previous_class_values;
476 /* Allocate a level of searching. */
478 push_decl_level (stack, obstack)
479 struct stack_level *stack;
480 struct obstack *obstack;
482 struct stack_level tem;
485 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
488 /* For each binding contour we allocate a binding_level structure
489 * which records the names defined in that contour.
492 * 1) one for each function definition,
493 * where internal declarations of the parameters appear.
494 * 2) one for each compound statement,
495 * to record its declarations.
497 * The current meaning of a name can be found by searching the levels from
498 * the current one out to the global one.
500 * Off to the side, may be the class_binding_level. This exists
501 * only to catch class-local declarations. It is otherwise
504 * Also there may be binding levels that catch cleanups that
505 * must be run when exceptions occur.
508 /* Note that the information in the `names' component of the global contour
509 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
513 /* A chain of _DECL nodes for all variables, constants, functions,
514 * and typedef types. These are in the reverse of the order supplied.
518 /* A list of structure, union and enum definitions,
519 * for looking up tag names.
520 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
521 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
522 * or ENUMERAL_TYPE node.
524 * C++: the TREE_VALUE nodes can be simple types for component_bindings.
529 /* For each level, a list of shadowed outer-level local definitions
530 to be restored when this level is popped.
531 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
532 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
535 /* Same, for IDENTIFIER_CLASS_VALUE. */
538 /* Same, for IDENTIFIER_TYPE_VALUE. */
541 /* For each level (except not the global one),
542 a chain of BLOCK nodes for all the levels
543 that were entered and exited one level down. */
546 /* The BLOCK node for this level, if one has been preallocated.
547 If 0, the BLOCK is allocated (if needed) when the level is popped. */
550 /* The binding level which this one is contained in (inherits from). */
551 struct binding_level *level_chain;
553 /* Number of decls in `names' that have incomplete
554 structure or union types. */
555 unsigned int n_incomplete;
557 /* 1 for the level that holds the parameters of a function.
558 2 for the level that holds a class declaration.
559 3 for levels that hold parameter declarations. */
560 unsigned parm_flag : 4;
562 /* 1 means make a BLOCK for this level regardless of all else.
563 2 for temporary binding contours created by the compiler. */
566 /* Nonzero if this level "doesn't exist" for tags. */
567 unsigned tag_transparent : 1;
569 /* Nonzero if this level can safely have additional
570 cleanup-needing variables added to it. */
571 unsigned more_cleanups_ok : 1;
572 unsigned have_cleanups : 1;
574 /* Nonzero if we should accept any name as an identifier in
575 this scope. This happens in some template definitions. */
576 unsigned accept_any : 1;
578 /* Nonzero if this level is for completing a template class definition
579 inside a binding level that temporarily binds the parameters. This
580 means that definitions here should not be popped off when unwinding
581 this binding level. (Not actually implemented this way,
583 unsigned pseudo_global : 1;
585 /* Two bits left for this word. */
587 #if defined(DEBUG_CP_BINDING_LEVELS)
588 /* Binding depth at which this level began. */
589 unsigned binding_depth;
590 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
593 #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
595 /* The (non-class) binding level currently in effect. */
597 static struct binding_level *current_binding_level;
599 /* The binding level of the current class, if any. */
601 static struct binding_level *class_binding_level;
603 /* The current (class or non-class) binding level currently in effect. */
605 #define inner_binding_level \
606 (class_binding_level ? class_binding_level : current_binding_level)
608 /* A chain of binding_level structures awaiting reuse. */
610 static struct binding_level *free_binding_level;
612 /* The outermost binding level, for names of file scope.
613 This is created when the compiler is started and exists
614 through the entire run. */
616 static struct binding_level *global_binding_level;
618 /* Binding level structures are initialized by copying this one. */
620 static struct binding_level clear_binding_level;
622 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
624 static int keep_next_level_flag;
626 #if defined(DEBUG_CP_BINDING_LEVELS)
627 static int binding_depth = 0;
628 static int is_class_level = 0;
635 for (i = 0; i < binding_depth*2; i++)
638 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
640 static tree pushdecl_with_scope PROTO((tree, struct binding_level *));
643 push_binding_level (newlevel, tag_transparent, keep)
644 struct binding_level *newlevel;
645 int tag_transparent, keep;
647 /* Add this level to the front of the chain (stack) of levels that
649 *newlevel = clear_binding_level;
650 if (class_binding_level)
652 newlevel->level_chain = class_binding_level;
653 class_binding_level = (struct binding_level *)0;
657 newlevel->level_chain = current_binding_level;
659 current_binding_level = newlevel;
660 newlevel->tag_transparent = tag_transparent;
661 newlevel->more_cleanups_ok = 1;
662 newlevel->keep = keep;
663 #if defined(DEBUG_CP_BINDING_LEVELS)
664 newlevel->binding_depth = binding_depth;
666 fprintf (stderr, "push %s level 0x%08x line %d\n",
667 (is_class_level) ? "class" : "block", newlevel, lineno);
670 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
676 if (class_binding_level)
677 current_binding_level = class_binding_level;
679 if (global_binding_level)
681 /* cannot pop a level, if there are none left to pop. */
682 if (current_binding_level == global_binding_level)
683 my_friendly_abort (123);
685 /* Pop the current level, and free the structure for reuse. */
686 #if defined(DEBUG_CP_BINDING_LEVELS)
689 fprintf (stderr, "pop %s level 0x%08x line %d\n",
690 (is_class_level) ? "class" : "block",
691 current_binding_level, lineno);
692 if (is_class_level != (current_binding_level == class_binding_level))
693 #if 0 /* XXX Don't abort when we're watching how things are being managed. */
698 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
702 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
704 register struct binding_level *level = current_binding_level;
705 current_binding_level = current_binding_level->level_chain;
706 level->level_chain = free_binding_level;
707 #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
708 if (level->binding_depth != binding_depth)
710 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
711 free_binding_level = level;
713 class_binding_level = current_binding_level;
714 if (class_binding_level->parm_flag != 2)
715 class_binding_level = 0;
716 while (current_binding_level->parm_flag == 2)
717 current_binding_level = current_binding_level->level_chain;
721 /* Nonzero if we are currently in the global binding level. */
726 return current_binding_level == global_binding_level;
732 keep_next_level_flag = 1;
735 /* Nonzero if the current level needs to have a BLOCK made. */
740 return (current_binding_level->blocks != NULL_TREE
741 || current_binding_level->keep
742 || current_binding_level->names != NULL_TREE
743 || (current_binding_level->tags != NULL_TREE
744 && !current_binding_level->tag_transparent));
747 /* Identify this binding level as a level of parameters. */
750 declare_parm_level ()
752 current_binding_level->parm_flag = 1;
756 declare_uninstantiated_type_level ()
758 current_binding_level->accept_any = 1;
762 uninstantiated_type_level_p ()
764 return current_binding_level->accept_any;
768 declare_pseudo_global_level ()
770 current_binding_level->pseudo_global = 1;
774 pseudo_global_level_p ()
776 return current_binding_level->pseudo_global;
780 set_class_shadows (shadows)
783 class_binding_level->class_shadowed = shadows;
786 /* Enter a new binding level.
787 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
788 not for that of tags. */
791 pushlevel (tag_transparent)
794 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
796 /* If this is the top level of a function,
797 just make sure that NAMED_LABELS is 0.
798 They should have been set to 0 at the end of the previous function. */
800 if (current_binding_level == global_binding_level)
801 my_friendly_assert (named_labels == NULL_TREE, 134);
803 /* Reuse or create a struct for this binding level. */
805 #if defined(DEBUG_CP_BINDING_LEVELS)
807 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
808 if (free_binding_level)
809 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
811 newlevel = free_binding_level;
812 free_binding_level = free_binding_level->level_chain;
816 /* Create a new `struct binding_level'. */
817 newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
819 push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
820 GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
821 keep_next_level_flag = 0;
825 pushlevel_temporary (tag_transparent)
828 pushlevel (tag_transparent);
829 current_binding_level->keep = 2;
832 /* Note we don't call push_momentary() here. Otherwise, it would cause
833 cleanups to be allocated on the momentary obstack, and they will be
834 overwritten by the next statement. */
836 expand_start_bindings (0);
839 /* Exit a binding level.
840 Pop the level off, and restore the state of the identifier-decl mappings
841 that were in effect when this level was entered.
843 If KEEP == 1, this level had explicit declarations, so
844 and create a "block" (a BLOCK node) for the level
845 to record its declarations and subblocks for symbol table output.
847 If KEEP == 2, this level's subblocks go to the front,
848 not the back of the current binding level. This happens,
849 for instance, when code for constructors and destructors
850 need to generate code at the end of a function which must
851 be moved up to the front of the function.
853 If FUNCTIONBODY is nonzero, this level is the body of a function,
854 so create a block as if KEEP were set and also clear out all
857 If REVERSE is nonzero, reverse the order of decls before putting
858 them into the BLOCK. */
861 poplevel (keep, reverse, functionbody)
867 /* The chain of decls was accumulated in reverse order.
868 Put it into forward order, just for cleanliness. */
870 int tmp = functionbody;
871 int implicit_try_block = current_binding_level->parm_flag == 3;
872 int real_functionbody = current_binding_level->keep == 2
873 ? ((functionbody = 0), tmp) : functionbody;
874 tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
875 tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
876 tree block = NULL_TREE;
878 int block_previously_created;
880 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
881 (HOST_WIDE_INT) current_binding_level->level_chain,
882 current_binding_level->parm_flag,
883 current_binding_level->keep,
884 current_binding_level->tag_transparent);
886 if (current_binding_level->keep == 1)
889 /* This warning is turned off because it causes warnings for
890 declarations like `extern struct foo *x'. */
892 /* Warn about incomplete structure types in this level. */
893 for (link = tags; link; link = TREE_CHAIN (link))
894 if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE)
896 tree type = TREE_VALUE (link);
898 switch (TREE_CODE (type))
901 errmsg = "`struct %s' incomplete in scope ending here";
904 errmsg = "`union %s' incomplete in scope ending here";
907 errmsg = "`enum %s' incomplete in scope ending here";
910 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
911 error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
913 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
914 error (errmsg, TYPE_NAME_STRING (type));
918 /* Get the decls in the order they were written.
919 Usually current_binding_level->names is in reverse order.
920 But parameter decls were previously put in forward order. */
923 current_binding_level->names
924 = decls = nreverse (current_binding_level->names);
926 decls = current_binding_level->names;
928 /* Output any nested inline functions within this block
929 if they weren't already output. */
931 for (decl = decls; decl; decl = TREE_CHAIN (decl))
932 if (TREE_CODE (decl) == FUNCTION_DECL
933 && ! TREE_ASM_WRITTEN (decl)
934 && DECL_INITIAL (decl) != NULL_TREE
935 && TREE_ADDRESSABLE (decl)
936 && decl_function_context (decl) == current_function_decl)
938 /* If this decl was copied from a file-scope decl
939 on account of a block-scope extern decl,
940 propagate TREE_ADDRESSABLE to the file-scope decl. */
941 if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
942 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
945 push_function_context ();
946 output_inline_function (decl);
947 pop_function_context ();
951 /* If there were any declarations or structure tags in that level,
952 or if this level is a function body,
953 create a BLOCK to record them for the life of this function. */
956 block_previously_created = (current_binding_level->this_block != NULL_TREE);
957 if (block_previously_created)
958 block = current_binding_level->this_block;
959 else if (keep == 1 || functionbody)
960 block = make_node (BLOCK);
961 if (block != NULL_TREE)
963 BLOCK_VARS (block) = decls;
964 BLOCK_TYPE_TAGS (block) = tags;
965 BLOCK_SUBBLOCKS (block) = subblocks;
966 /* If we created the block earlier on, and we are just diddling it now,
967 then it already should have a proper BLOCK_END_NOTE value associated
968 with it, so avoid trashing that. Otherwise, for a new block, install
969 a new BLOCK_END_NOTE value. */
970 if (! block_previously_created)
971 remember_end_note (block);
974 /* In each subblock, record that this is its superior. */
977 for (link = subblocks; link; link = TREE_CHAIN (link))
978 BLOCK_SUPERCONTEXT (link) = block;
980 /* Clear out the meanings of the local variables of this level. */
982 for (link = decls; link; link = TREE_CHAIN (link))
984 if (DECL_NAME (link) != NULL_TREE)
986 /* If the ident. was used or addressed via a local extern decl,
987 don't forget that fact. */
988 if (DECL_EXTERNAL (link))
990 if (TREE_USED (link))
991 TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
992 if (TREE_ADDRESSABLE (link))
993 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
995 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
999 /* Restore all name-meanings of the outer levels
1000 that were shadowed by this level. */
1002 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1003 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1004 for (link = current_binding_level->class_shadowed;
1005 link; link = TREE_CHAIN (link))
1006 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1007 for (link = current_binding_level->type_shadowed;
1008 link; link = TREE_CHAIN (link))
1009 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1011 /* If the level being exited is the top level of a function,
1012 check over all the labels. */
1016 /* If this is the top level block of a function,
1017 the vars are the function's parameters.
1018 Don't leave them in the BLOCK because they are
1019 found in the FUNCTION_DECL instead. */
1021 BLOCK_VARS (block) = 0;
1023 /* Clear out the definitions of all label names,
1024 since their scopes end here. */
1026 for (link = named_labels; link; link = TREE_CHAIN (link))
1028 register tree label = TREE_VALUE (link);
1030 if (DECL_INITIAL (label) == NULL_TREE)
1032 cp_error_at ("label `%D' used but not defined", label);
1033 /* Avoid crashing later. */
1034 define_label (input_filename, 1, DECL_NAME (label));
1036 else if (warn_unused && !TREE_USED (label))
1037 cp_warning_at ("label `%D' defined but not used", label);
1038 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
1040 /* Put the labels into the "variables" of the
1041 top-level block, so debugger can see them. */
1042 TREE_CHAIN (label) = BLOCK_VARS (block);
1043 BLOCK_VARS (block) = label;
1046 named_labels = NULL_TREE;
1049 /* Any uses of undefined labels now operate under constraints
1050 of next binding contour. */
1052 struct binding_level *level_chain;
1053 level_chain = current_binding_level->level_chain;
1057 for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
1058 if (TREE_TYPE (labels) == (tree)current_binding_level)
1060 TREE_TYPE (labels) = (tree)level_chain;
1061 TREE_PURPOSE (labels) = level_chain->names;
1066 tmp = current_binding_level->keep;
1068 pop_binding_level ();
1070 DECL_INITIAL (current_function_decl) = block;
1073 if (!block_previously_created)
1074 current_binding_level->blocks
1075 = chainon (current_binding_level->blocks, block);
1077 /* If we did not make a block for the level just exited,
1078 any blocks made for inner levels
1079 (since they cannot be recorded as subblocks in that level)
1080 must be carried forward so they will later become subblocks
1081 of something else. */
1085 current_binding_level->blocks
1086 = chainon (subblocks, current_binding_level->blocks);
1088 current_binding_level->blocks
1089 = chainon (current_binding_level->blocks, subblocks);
1092 /* Take care of compiler's internal binding structures. */
1096 /* We did not call push_momentary for this
1097 binding contour, so there is nothing to pop. */
1100 expand_end_bindings (getdecls (), keep, 1);
1101 /* Each and every BLOCK node created here in `poplevel' is important
1102 (e.g. for proper debugging information) so if we created one
1103 earlier, mark it as "used". */
1105 TREE_USED (block) = 1;
1106 block = poplevel (keep, reverse, real_functionbody);
1109 /* Each and every BLOCK node created here in `poplevel' is important
1110 (e.g. for proper debugging information) so if we created one
1111 earlier, mark it as "used". */
1113 TREE_USED (block) = 1;
1117 /* Delete the node BLOCK from the current binding level.
1118 This is used for the block inside a stmt expr ({...})
1119 so that the block can be reinserted where appropriate. */
1122 delete_block (block)
1126 if (current_binding_level->blocks == block)
1127 current_binding_level->blocks = TREE_CHAIN (block);
1128 for (t = current_binding_level->blocks; t;)
1130 if (TREE_CHAIN (t) == block)
1131 TREE_CHAIN (t) = TREE_CHAIN (block);
1135 TREE_CHAIN (block) = NULL_TREE;
1136 /* Clear TREE_USED which is always set by poplevel.
1137 The flag is set again if insert_block is called. */
1138 TREE_USED (block) = 0;
1141 /* Insert BLOCK at the end of the list of subblocks of the
1142 current binding level. This is used when a BIND_EXPR is expanded,
1143 to handle the BLOCK node inside the BIND_EXPR. */
1146 insert_block (block)
1149 TREE_USED (block) = 1;
1150 current_binding_level->blocks
1151 = chainon (current_binding_level->blocks, block);
1154 /* Add BLOCK to the current list of blocks for this binding contour. */
1156 add_block_current_level (block)
1159 current_binding_level->blocks
1160 = chainon (current_binding_level->blocks, block);
1163 /* Set the BLOCK node for the innermost scope
1164 (the one we are currently in). */
1168 register tree block;
1170 current_binding_level->this_block = block;
1173 /* Do a pushlevel for class declarations. */
1177 register struct binding_level *newlevel;
1179 /* Reuse or create a struct for this binding level. */
1180 #if defined(DEBUG_CP_BINDING_LEVELS)
1182 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
1183 if (free_binding_level)
1184 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
1186 newlevel = free_binding_level;
1187 free_binding_level = free_binding_level->level_chain;
1191 /* Create a new `struct binding_level'. */
1192 newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
1195 #if defined(DEBUG_CP_BINDING_LEVELS)
1197 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1199 push_binding_level (newlevel, 0, 0);
1201 decl_stack = push_decl_level (decl_stack, &decl_obstack);
1202 class_binding_level = current_binding_level;
1203 class_binding_level->parm_flag = 2;
1204 /* We have just pushed into a new binding level. Now, fake out the rest
1205 of the compiler. Set the `current_binding_level' back to point to
1206 the most closely containing non-class binding level. */
1209 current_binding_level = current_binding_level->level_chain;
1211 while (current_binding_level->parm_flag == 2);
1214 /* ...and a poplevel for class declarations. FORCE is used to force
1215 clearing out of CLASS_VALUEs after a class definition. */
1217 poplevel_class (force)
1220 register struct binding_level *level = class_binding_level;
1221 tree block = NULL_TREE;
1224 my_friendly_assert (level != 0, 354);
1226 decl_stack = pop_stack_level (decl_stack);
1227 for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1228 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1229 /* If we're leaving a toplevel class, don't bother to do the setting
1230 of IDENTIFER_CLASS_VALUE to NULL_TREE, since first of all this slot
1231 shouldn't even be used when current_class_type isn't set, and second,
1232 if we don't touch it here, we're able to use the caching effect if the
1233 next time we're entering a class scope, it is the same class. */
1234 if (current_class_depth != 1 || force)
1235 for (shadowed = level->class_shadowed;
1237 shadowed = TREE_CHAIN (shadowed))
1238 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1240 /* Remember to save what IDENTIFIER's were bound in this scope so we
1241 can recover from cache misses. */
1242 previous_class_values = class_binding_level->class_shadowed;
1243 for (shadowed = level->type_shadowed;
1245 shadowed = TREE_CHAIN (shadowed))
1246 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1248 GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
1249 (HOST_WIDE_INT) class_binding_level->level_chain,
1250 class_binding_level->parm_flag,
1251 class_binding_level->keep,
1252 class_binding_level->tag_transparent);
1254 if (class_binding_level->parm_flag != 2)
1255 class_binding_level = (struct binding_level *)0;
1257 /* Now, pop out of the the binding level which we created up in the
1258 `pushlevel_class' routine. */
1259 #if defined(DEBUG_CP_BINDING_LEVELS)
1261 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1263 pop_binding_level ();
1268 /* For debugging. */
1269 int no_print_functions = 0;
1270 int no_print_builtins = 0;
1273 print_binding_level (lvl)
1274 struct binding_level *lvl;
1278 fprintf (stderr, " blocks=");
1279 fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
1280 fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
1281 lvl->n_incomplete, lvl->parm_flag, lvl->keep);
1282 if (lvl->tag_transparent)
1283 fprintf (stderr, " tag-transparent");
1284 if (lvl->more_cleanups_ok)
1285 fprintf (stderr, " more-cleanups-ok");
1286 if (lvl->have_cleanups)
1287 fprintf (stderr, " have-cleanups");
1288 fprintf (stderr, "\n");
1291 fprintf (stderr, " names:\t");
1292 /* We can probably fit 3 names to a line? */
1293 for (t = lvl->names; t; t = TREE_CHAIN (t))
1295 if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL))
1297 if (no_print_builtins
1298 && (TREE_CODE(t) == TYPE_DECL)
1299 && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
1302 /* Function decls tend to have longer names. */
1303 if (TREE_CODE (t) == FUNCTION_DECL)
1310 fprintf (stderr, "\n\t");
1313 print_node_brief (stderr, "", t, 0);
1314 if (TREE_CODE (t) == ERROR_MARK)
1318 fprintf (stderr, "\n");
1322 fprintf (stderr, " tags:\t");
1324 for (t = lvl->tags; t; t = TREE_CHAIN (t))
1326 if (TREE_PURPOSE (t) == NULL_TREE)
1328 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1335 fprintf (stderr, "\n\t");
1338 if (TREE_PURPOSE (t) == NULL_TREE)
1340 print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
1341 fprintf (stderr, ">");
1343 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1344 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1347 print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
1348 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1349 fprintf (stderr, ">");
1353 fprintf (stderr, "\n");
1357 fprintf (stderr, " shadowed:");
1358 for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
1360 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1362 fprintf (stderr, "\n");
1364 if (lvl->class_shadowed)
1366 fprintf (stderr, " class-shadowed:");
1367 for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
1369 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1371 fprintf (stderr, "\n");
1373 if (lvl->type_shadowed)
1375 fprintf (stderr, " type-shadowed:");
1376 for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
1379 fprintf (stderr, "\n\t");
1380 print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
1382 print_node_brief (stderr, " ", TREE_VALUE (t), 0);
1384 fprintf (stderr, " (none)");
1385 fprintf (stderr, ">");
1387 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1390 fprintf (stderr, "\n");
1395 print_other_binding_stack (stack)
1396 struct binding_level *stack;
1398 struct binding_level *level;
1399 for (level = stack; level != global_binding_level; level = level->level_chain)
1401 fprintf (stderr, "binding level ");
1402 fprintf (stderr, HOST_PTR_PRINTF, level);
1403 fprintf (stderr, "\n");
1404 print_binding_level (level);
1409 print_binding_stack ()
1411 struct binding_level *b;
1412 fprintf (stderr, "current_binding_level=");
1413 fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
1414 fprintf (stderr, "\nclass_binding_level=");
1415 fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
1416 fprintf (stderr, "\nglobal_binding_level=");
1417 fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
1418 fprintf (stderr, "\n");
1419 if (class_binding_level)
1421 for (b = class_binding_level; b; b = b->level_chain)
1422 if (b == current_binding_level)
1425 b = class_binding_level;
1427 b = current_binding_level;
1430 b = current_binding_level;
1431 print_other_binding_stack (b);
1432 fprintf (stderr, "global:\n");
1433 print_binding_level (global_binding_level);
1436 /* Subroutines for reverting temporarily to top-level for instantiation
1437 of templates and such. We actually need to clear out the class- and
1438 local-value slots of all identifiers, so that only the global values
1439 are at all visible. Simply setting current_binding_level to the global
1440 scope isn't enough, because more binding levels may be pushed. */
1441 struct saved_scope {
1442 struct binding_level *old_binding_level;
1444 struct saved_scope *prev;
1445 tree class_name, class_type, class_decl, function_decl;
1446 struct binding_level *class_bindings;
1447 tree previous_class_type;
1448 tree *lang_base, *lang_stack, lang_name;
1452 static struct saved_scope *current_saved_scope;
1453 extern tree prev_class_type;
1456 push_to_top_level ()
1458 extern int current_lang_stacksize;
1459 struct saved_scope *s =
1460 (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
1461 struct binding_level *b = current_binding_level;
1462 tree old_bindings = NULL_TREE;
1464 /* Have to include global_binding_level, because class-level decls
1465 aren't listed anywhere useful. */
1466 for (; b; b = b->level_chain)
1470 if (b == global_binding_level)
1473 for (t = b->names; t; t = TREE_CHAIN (t))
1475 tree binding, t1, t2 = t;
1476 tree id = DECL_ASSEMBLER_NAME (t2);
1479 || (!IDENTIFIER_LOCAL_VALUE (id)
1480 && !IDENTIFIER_CLASS_VALUE (id)))
1483 for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
1484 if (TREE_VEC_ELT (t1, 0) == id)
1487 binding = make_tree_vec (4);
1490 my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
1491 TREE_VEC_ELT (binding, 0) = id;
1492 TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
1493 TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
1494 TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
1495 IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
1496 IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
1498 TREE_CHAIN (binding) = old_bindings;
1499 old_bindings = binding;
1503 /* Unwind type-value slots back to top level. */
1504 for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
1505 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
1507 /* Clear out class-level bindings cache. */
1508 if (current_binding_level == global_binding_level
1509 && previous_class_type != NULL_TREE)
1512 previous_class_type = NULL_TREE;
1515 s->old_binding_level = current_binding_level;
1516 current_binding_level = global_binding_level;
1518 s->class_name = current_class_name;
1519 s->class_type = current_class_type;
1520 s->class_decl = current_class_decl;
1521 s->function_decl = current_function_decl;
1522 s->class_bindings = class_binding_level;
1523 s->previous_class_type = previous_class_type;
1524 s->lang_stack = current_lang_stack;
1525 s->lang_base = current_lang_base;
1526 s->lang_stacksize = current_lang_stacksize;
1527 s->lang_name = current_lang_name;
1528 s->named_labels = named_labels;
1529 current_class_name = current_class_type = current_class_decl = NULL_TREE;
1530 current_function_decl = NULL_TREE;
1531 class_binding_level = (struct binding_level *)0;
1532 previous_class_type = NULL_TREE;
1533 current_lang_stacksize = 10;
1534 current_lang_stack = current_lang_base
1535 = (tree *) xmalloc (current_lang_stacksize * sizeof (tree));
1536 current_lang_name = lang_name_cplusplus;
1537 strict_prototype = strict_prototypes_lang_cplusplus;
1538 named_labels = NULL_TREE;
1540 s->prev = current_saved_scope;
1541 s->old_bindings = old_bindings;
1542 current_saved_scope = s;
1546 pop_from_top_level ()
1548 extern int current_lang_stacksize;
1549 struct saved_scope *s = current_saved_scope;
1552 if (previous_class_type)
1553 previous_class_type = NULL_TREE;
1555 current_binding_level = s->old_binding_level;
1556 current_saved_scope = s->prev;
1557 for (t = s->old_bindings; t; t = TREE_CHAIN (t))
1559 tree id = TREE_VEC_ELT (t, 0);
1562 IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
1563 IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
1564 IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
1567 current_class_name = s->class_name;
1568 current_class_type = s->class_type;
1569 current_class_decl = s->class_decl;
1570 if (current_class_type)
1571 C_C_D = CLASSTYPE_INST_VAR (current_class_type);
1574 current_function_decl = s->function_decl;
1575 class_binding_level = s->class_bindings;
1576 previous_class_type = s->previous_class_type;
1577 free (current_lang_base);
1578 current_lang_base = s->lang_base;
1579 current_lang_stack = s->lang_stack;
1580 current_lang_name = s->lang_name;
1581 current_lang_stacksize = s->lang_stacksize;
1582 if (current_lang_name == lang_name_cplusplus)
1583 strict_prototype = strict_prototypes_lang_cplusplus;
1584 else if (current_lang_name == lang_name_c)
1585 strict_prototype = strict_prototypes_lang_c;
1586 named_labels = s->named_labels;
1591 /* Push a definition of struct, union or enum tag "name".
1592 into binding_level "b". "type" should be the type node,
1593 We assume that the tag "name" is not already defined.
1595 Note that the definition may really be just a forward reference.
1596 In that case, the TYPE_SIZE will be a NULL_TREE.
1598 C++ gratuitously puts all these tags in the name space. */
1600 /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
1601 record the shadowed value for this binding contour. TYPE is
1602 the type that ID maps to. */
1605 set_identifier_type_value_with_scope (id, type, b)
1608 struct binding_level *b;
1610 if (b != global_binding_level)
1612 tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
1614 = tree_cons (id, old_type_value, b->type_shadowed);
1616 SET_IDENTIFIER_TYPE_VALUE (id, type);
1619 /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
1622 set_identifier_type_value (id, type)
1626 set_identifier_type_value_with_scope (id, type, inner_binding_level);
1629 /* Subroutine "set_nested_typename" builds the nested-typename of
1630 the type decl in question. (Argument CLASSNAME can actually be
1631 a function as well, if that's the smallest containing scope.) */
1634 set_nested_typename (decl, classname, name, type)
1635 tree decl, classname, name, type;
1637 my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
1638 if (classname != NULL_TREE)
1641 my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
1642 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
1643 buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
1644 + IDENTIFIER_LENGTH (name));
1645 sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
1646 IDENTIFIER_POINTER (name));
1647 DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
1648 TREE_MANGLED (DECL_NESTED_TYPENAME (decl)) = 1;
1650 /* This is a special usage of IDENTIFIER_TYPE_VALUE which have no
1651 correspondence in any binding_level. This is ok since the
1652 DECL_NESTED_TYPENAME is just a convenience identifier whose
1653 IDENTIFIER_TYPE_VALUE will remain constant from now on. */
1654 SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type);
1657 DECL_NESTED_TYPENAME (decl) = name;
1660 /* Pop off extraneous binding levels left over due to syntax errors. */
1664 #ifdef DEBUG_CP_BINDING_LEVELS
1665 fprintf (stderr, "XXX entering pop_everything ()\n");
1667 while (current_binding_level != global_binding_level
1668 && ! current_binding_level->pseudo_global)
1670 if (class_binding_level)
1671 pop_nested_class (1);
1675 #ifdef DEBUG_CP_BINDING_LEVELS
1676 fprintf (stderr, "XXX leaving pop_everything ()\n");
1680 #if 0 /* not yet, should get fixed properly later */
1681 /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
1682 Other routines shouldn't use build_decl directly; they'll produce
1683 incorrect results with `-g' unless they duplicate this code.
1685 This is currently needed mainly for dbxout.c, but we can make
1686 use of it in method.c later as well. */
1688 make_type_decl (name, type)
1692 decl = build_decl (TYPE_DECL, name, type);
1693 if (TYPE_NAME (type) == name)
1694 /* Class/union/enum definition, or a redundant typedef for same. */
1696 id = get_identifier (build_overload_name (type, 1, 1));
1697 DECL_ASSEMBLER_NAME (decl) = id;
1699 else if (TYPE_NAME (type) != NULL_TREE)
1700 /* Explicit typedef, or implicit typedef for template expansion. */
1701 DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
1704 /* XXX: Typedef for unnamed struct; some other situations.
1705 TYPE_NAME is null; what's right here? */
1711 /* Push a tag name NAME for struct/class/union/enum type TYPE.
1712 Normally put into into the inner-most non-tag-tranparent scope,
1713 but if GLOBALIZE is true, put it in the inner-most non-class scope.
1714 The latter is needed for implicit declarations. */
1717 pushtag (name, type, globalize)
1721 register struct binding_level *b;
1725 b = inner_binding_level;
1726 while (b->tag_transparent
1727 || (globalize && b->parm_flag == 2))
1730 if (b == global_binding_level)
1731 b->tags = perm_tree_cons (name, type, b->tags);
1733 b->tags = saveable_tree_cons (name, type, b->tags);
1737 context = type ? TYPE_CONTEXT (type) : NULL_TREE;
1738 if (! context && ! globalize)
1739 context = current_scope ();
1741 c_decl = TREE_CODE (context) == FUNCTION_DECL
1742 ? context : TYPE_NAME (context);
1744 /* Record the identifier as the type's name if it has none. */
1745 if (TYPE_NAME (type) == NULL_TREE)
1746 TYPE_NAME (type) = name;
1748 /* Do C++ gratuitous typedefing. */
1749 if (IDENTIFIER_TYPE_VALUE (name) != type)
1754 if (b->parm_flag != 2
1755 || TYPE_SIZE (current_class_type) != NULL_TREE)
1757 d = lookup_nested_type (type, c_decl);
1762 #if 0 /* not yet, should get fixed properly later */
1763 d = make_type_decl (name, type);
1765 d = build_decl (TYPE_DECL, name, type);
1767 SET_DECL_ARTIFICIAL (d);
1768 #ifdef DWARF_DEBUGGING_INFO
1769 if (write_symbols == DWARF_DEBUG)
1771 /* Mark the TYPE_DECL node we created just above as an
1772 gratuitous one. We need to do this so that dwarfout.c
1773 will understand that it is not supposed to output a
1774 TAG_typedef DIE for it. */
1775 DECL_IGNORED_P (d) = 1;
1777 #endif /* DWARF_DEBUGGING_INFO */
1778 set_identifier_type_value_with_scope (name, type, b);
1783 /* If it is anonymous, then we are called from pushdecl,
1784 and we don't want to infinitely recurse. Also, if the
1785 name is already in scope, we don't want to push it
1786 again--pushdecl is only for pushing new decls. */
1787 if (! ANON_AGGRNAME_P (name)
1789 && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
1790 || lookup_name (name, 1) != TYPE_NAME (type)))
1792 if (b->parm_flag == 2)
1793 d = pushdecl_class_level (d);
1795 d = pushdecl_with_scope (d, b);
1800 /* Make nested declarations go into class-level scope. */
1802 d = build_decl (TYPE_DECL, name, type);
1803 SET_DECL_ARTIFICIAL (d);
1804 #ifdef DWARF_DEBUGGING_INFO
1805 if (write_symbols == DWARF_DEBUG)
1807 /* Mark the TYPE_DECL node we created just above as an
1808 gratuitous one. We need to do this so that dwarfout.c
1809 will understand that it is not supposed to output a
1810 TAG_typedef DIE for it. */
1811 DECL_IGNORED_P (d) = 1;
1813 #endif /* DWARF_DEBUGGING_INFO */
1814 /* Make sure we're in this type's scope when we push the
1815 decl for a template, otherwise class_binding_level will
1816 be NULL and we'll end up dying inside of
1817 push_class_level_binding. */
1818 if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
1819 pushclass (type, 0);
1820 d = pushdecl_class_level (d);
1821 if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
1824 if (write_symbols != DWARF_DEBUG)
1826 if (ANON_AGGRNAME_P (name))
1827 DECL_IGNORED_P (d) = 1;
1829 TYPE_NAME (type) = d;
1831 if (context == NULL_TREE)
1832 /* Non-nested class. */
1833 DECL_NESTED_TYPENAME (d) = name;
1834 else if (context && TREE_CODE (context) == FUNCTION_DECL)
1836 /* Function-nested class. */
1837 set_nested_typename (d, DECL_ASSEMBLER_NAME (c_decl),
1839 /* This builds the links for classes nested in fn scope. */
1840 DECL_CONTEXT (d) = context;
1842 /* else if (TYPE_SIZE (current_class_type) == NULL_TREE)
1844 else if (context && IS_AGGR_TYPE (context))
1846 /* Class-nested class. */
1847 set_nested_typename (d, DECL_NESTED_TYPENAME (c_decl),
1849 /* This builds the links for classes nested in type scope. */
1850 DECL_CONTEXT (d) = context;
1852 TYPE_CONTEXT (type) = DECL_CONTEXT (d);
1854 DECL_ASSEMBLER_NAME (d)
1855 = get_identifier (build_overload_name (type, 1, 1));
1857 if (b->parm_flag == 2)
1859 TREE_NONLOCAL_FLAG (type) = 1;
1860 if (TYPE_SIZE (current_class_type) == NULL_TREE)
1861 CLASSTYPE_TAGS (current_class_type) = b->tags;
1865 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1866 /* Use the canonical TYPE_DECL for this node. */
1867 TYPE_STUB_DECL (type) = TYPE_NAME (type);
1870 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
1871 will be the tagged type we just added to the current
1872 binding level. This fake NULL-named TYPE_DECL node helps
1873 dwarfout.c to know when it needs to output a
1874 representation of a tagged type, and it also gives us a
1875 convenient place to record the "scope start" address for
1878 #if 0 /* not yet, should get fixed properly later */
1879 tree d = make_type_decl (NULL_TREE, type);
1881 tree d = build_decl (TYPE_DECL, NULL_TREE, type);
1883 TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
1887 /* Counter used to create anonymous type names. */
1888 static int anon_cnt = 0;
1890 /* Return an IDENTIFIER which can be used as a name for
1891 anonymous structs and unions. */
1897 sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
1898 return get_identifier (buf);
1901 /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
1902 This keeps dbxout from getting confused. */
1906 register struct binding_level *b;
1908 static int last_cnt = 0;
1910 /* Fast out if no new anon names were declared. */
1911 if (last_cnt == anon_cnt)
1914 b = current_binding_level;
1915 while (b->tag_transparent)
1920 /* A NULL purpose means we have already processed all tags
1921 from here to the end of the list. */
1922 if (TREE_PURPOSE (tags) == NULL_TREE)
1924 if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
1925 TREE_PURPOSE (tags) = NULL_TREE;
1926 tags = TREE_CHAIN (tags);
1928 last_cnt = anon_cnt;
1931 /* Subroutine of duplicate_decls: return truthvalue of whether
1932 or not types of these decls match.
1934 For C++, we must compare the parameter list so that `int' can match
1935 `int&' in a parameter position, but `int&' is not confused with
1938 decls_match (newdecl, olddecl)
1939 tree newdecl, olddecl;
1943 if (TREE_CODE (newdecl) == FUNCTION_DECL
1944 && TREE_CODE (olddecl) == FUNCTION_DECL)
1946 tree f1 = TREE_TYPE (newdecl);
1947 tree f2 = TREE_TYPE (olddecl);
1948 tree p1 = TYPE_ARG_TYPES (f1);
1949 tree p2 = TYPE_ARG_TYPES (f2);
1951 /* When we parse a static member function definition,
1952 we put together a FUNCTION_DECL which thinks its type
1953 is METHOD_TYPE. Change that to FUNCTION_TYPE, and
1955 if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
1956 revert_static_member_fn (&newdecl, &f1, &p1);
1957 else if (TREE_CODE (f2) == METHOD_TYPE
1958 && DECL_STATIC_FUNCTION_P (newdecl))
1959 revert_static_member_fn (&olddecl, &f2, &p2);
1961 /* Here we must take care of the case where new default
1962 parameters are specified. Also, warn if an old
1963 declaration becomes ambiguous because default
1964 parameters may cause the two to be ambiguous. */
1965 if (TREE_CODE (f1) != TREE_CODE (f2))
1967 if (TREE_CODE (f1) == OFFSET_TYPE)
1968 cp_compiler_error ("`%D' redeclared as member function", newdecl);
1970 cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
1974 if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1))
1976 if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c
1979 types_match = self_promoting_args_p (p1);
1980 if (p1 == void_list_node)
1981 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
1983 else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c
1984 && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE)
1986 types_match = self_promoting_args_p (p2);
1987 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
1990 types_match = compparms (p1, p2, 3);
1995 else if (TREE_CODE (newdecl) == TEMPLATE_DECL
1996 && TREE_CODE (olddecl) == TEMPLATE_DECL)
1998 tree newargs = DECL_TEMPLATE_PARMS (newdecl);
1999 tree oldargs = DECL_TEMPLATE_PARMS (olddecl);
2000 int i, len = TREE_VEC_LENGTH (newargs);
2002 if (TREE_VEC_LENGTH (oldargs) != len)
2005 for (i = 0; i < len; i++)
2007 tree newarg = TREE_VALUE (TREE_VEC_ELT (newargs, i));
2008 tree oldarg = TREE_VALUE (TREE_VEC_ELT (oldargs, i));
2009 if (TREE_CODE (newarg) != TREE_CODE (oldarg))
2011 else if (TREE_CODE (newarg) == TYPE_DECL)
2013 else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1))
2017 if (DECL_TEMPLATE_IS_CLASS (newdecl)
2018 != DECL_TEMPLATE_IS_CLASS (olddecl))
2020 else if (DECL_TEMPLATE_IS_CLASS (newdecl))
2023 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
2024 DECL_TEMPLATE_RESULT (newdecl));
2028 if (TREE_TYPE (newdecl) == error_mark_node)
2029 types_match = TREE_TYPE (olddecl) == error_mark_node;
2030 else if (TREE_TYPE (olddecl) == NULL_TREE)
2031 types_match = TREE_TYPE (newdecl) == NULL_TREE;
2032 else if (TREE_TYPE (newdecl) == NULL_TREE)
2035 types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
2041 /* If NEWDECL is `static' and an `extern' was seen previously,
2042 warn about it. (OLDDECL may be NULL_TREE; NAME contains
2043 information about previous usage as an `extern'.)
2045 Note that this does not apply to the C++ case of declaring
2046 a variable `extern const' and then later `const'.
2048 Don't complain if -traditional, since traditional compilers
2051 Don't complain about built-in functions, since they are beyond
2052 the user's control. */
2055 warn_extern_redeclared_static (newdecl, olddecl)
2056 tree newdecl, olddecl;
2060 static char *explicit_extern_static_warning
2061 = "`%D' was declared `extern' and later `static'";
2062 static char *implicit_extern_static_warning
2063 = "`%D' was declared implicitly `extern' and later `static'";
2065 if (flag_traditional
2066 || TREE_CODE (newdecl) == TYPE_DECL
2067 || (! warn_extern_inline
2068 && DECL_INLINE (newdecl)))
2071 name = DECL_ASSEMBLER_NAME (newdecl);
2072 if (TREE_PUBLIC (name) && ! DECL_PUBLIC (newdecl))
2074 /* It's okay to redeclare an ANSI built-in function as static,
2075 or to declare a non-ANSI built-in function as anything. */
2076 if (! (TREE_CODE (newdecl) == FUNCTION_DECL
2077 && olddecl != NULL_TREE
2078 && TREE_CODE (olddecl) == FUNCTION_DECL
2079 && (DECL_BUILT_IN (olddecl)
2080 || DECL_BUILT_IN_NONANSI (olddecl))))
2082 cp_warning (IDENTIFIER_IMPLICIT_DECL (name)
2083 ? implicit_extern_static_warning
2084 : explicit_extern_static_warning, newdecl);
2085 if (olddecl != NULL_TREE)
2086 cp_warning_at ("previous declaration of `%D'", olddecl);
2091 /* Handle when a new declaration NEWDECL has the same name as an old
2092 one OLDDECL in the same binding contour. Prints an error message
2095 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
2096 Otherwise, return 0. */
2099 duplicate_decls (newdecl, olddecl)
2100 register tree newdecl, olddecl;
2102 extern struct obstack permanent_obstack;
2103 unsigned olddecl_uid = DECL_UID (olddecl);
2104 int olddecl_friend = 0, types_match = 0;
2105 int new_defines_function;
2106 tree previous_c_decl = NULL_TREE;
2108 types_match = decls_match (newdecl, olddecl);
2110 if (TREE_CODE (olddecl) != TREE_LIST)
2111 olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
2113 /* If either the type of the new decl or the type of the old decl is an
2114 error_mark_node, then that implies that we have already issued an
2115 error (earlier) for some bogus type specification, and in that case,
2116 it is rather pointless to harass the user with yet more error message
2117 about the same declaration, so well just pretent the types match here. */
2118 if ((TREE_TYPE (newdecl)
2119 && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
2120 || (TREE_TYPE (olddecl)
2121 && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
2124 if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
2125 && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
2126 /* If -traditional, avoid error for redeclaring fcn
2127 after implicit decl. */
2129 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2130 && DECL_ARTIFICIAL (olddecl)
2131 && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))
2133 /* If you declare a built-in or predefined function name as static,
2134 the old definition is overridden, but optionally warn this was a
2135 bad choice of name. Ditto for overloads. */
2136 if (! DECL_PUBLIC (newdecl)
2137 || (TREE_CODE (newdecl) == FUNCTION_DECL
2138 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)))
2141 cp_warning ("shadowing %s function `%#D'",
2142 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
2144 /* Discard the old built-in function. */
2147 else if (! types_match)
2149 if (TREE_CODE (newdecl) != FUNCTION_DECL)
2151 /* If the built-in is not ansi, then programs can override
2152 it even globally without an error. */
2153 if (! DECL_BUILT_IN (olddecl))
2154 cp_warning ("library function `%#D' redeclared as non-function `%#D'",
2158 cp_error ("declaration of `%#D'", newdecl);
2159 cp_error ("conflicts with built-in declaration `%#D'",
2165 cp_warning ("declaration of `%#D'", newdecl);
2166 cp_warning ("conflicts with built-in declaration `%#D'",
2170 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2172 if ((TREE_CODE (newdecl) == FUNCTION_DECL
2173 && TREE_CODE (olddecl) == TEMPLATE_DECL
2174 && ! DECL_TEMPLATE_IS_CLASS (olddecl))
2175 || (TREE_CODE (olddecl) == FUNCTION_DECL
2176 && TREE_CODE (newdecl) == TEMPLATE_DECL
2177 && ! DECL_TEMPLATE_IS_CLASS (newdecl)))
2180 cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
2181 if (TREE_CODE (olddecl) == TREE_LIST)
2182 olddecl = TREE_VALUE (olddecl);
2183 cp_error_at ("previous declaration of `%#D'", olddecl);
2185 /* New decl is completely inconsistent with the old one =>
2186 tell caller to replace the old one. */
2190 else if (!types_match)
2192 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2194 /* The name of a class template may not be declared to refer to
2195 any other template, class, function, object, namespace, value,
2196 or type in the same scope. */
2197 if (DECL_TEMPLATE_IS_CLASS (olddecl)
2198 || DECL_TEMPLATE_IS_CLASS (newdecl))
2200 cp_error ("declaration of template `%#D'", newdecl);
2201 cp_error_at ("conflicts with previous declaration `%#D'",
2206 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2208 if (DECL_LANGUAGE (newdecl) == lang_c
2209 && DECL_LANGUAGE (olddecl) == lang_c)
2211 cp_error ("declaration of C function `%#D' conflicts with",
2213 cp_error_at ("previous declaration `%#D' here", olddecl);
2215 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2216 TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 2))
2218 cp_error ("new declaration `%#D'", newdecl);
2219 cp_error_at ("ambiguates old declaration `%#D'", olddecl);
2225 if (olddecl == wchar_decl_node)
2227 if (pedantic && ! DECL_IN_SYSTEM_HEADER (newdecl))
2228 cp_pedwarn ("redeclaration of wchar_t as `%T'",
2229 TREE_TYPE (newdecl));
2231 /* Throw away the redeclaration. */
2235 /* Already complained about this, so don't do so again. */
2236 else if (current_class_type == NULL_TREE
2237 || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
2239 cp_error ("conflicting types for `%#D'", newdecl);
2240 cp_error_at ("previous declaration as `%#D'", olddecl);
2245 char *errmsg = redeclaration_error_message (newdecl, olddecl);
2248 cp_error (errmsg, newdecl);
2249 if (DECL_NAME (olddecl) != NULL_TREE)
2250 cp_error_at ((DECL_INITIAL (olddecl)
2251 && current_binding_level == global_binding_level)
2252 ? "`%#D' previously defined here"
2253 : "`%#D' previously declared here", olddecl);
2255 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2256 && DECL_INITIAL (olddecl) != NULL_TREE
2257 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
2258 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
2260 /* Prototype decl follows defn w/o prototype. */
2261 cp_warning_at ("prototype for `%#D'", newdecl);
2262 cp_warning_at ("follows non-prototype definition here", olddecl);
2264 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2265 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2267 /* extern "C" int foo ();
2268 int foo () { bar (); }
2270 if (current_lang_stack == current_lang_base)
2271 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2274 cp_error_at ("previous declaration of `%#D' with %L linkage",
2275 olddecl, DECL_LANGUAGE (olddecl));
2276 cp_error ("conflicts with new declaration with %L linkage",
2277 DECL_LANGUAGE (newdecl));
2282 /* If new decl is `static' and an `extern' was seen previously,
2284 warn_extern_redeclared_static (newdecl, olddecl);
2286 /* We have committed to returning 1 at this point. */
2287 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2289 /* Now that functions must hold information normally held
2290 by field decls, there is extra work to do so that
2291 declaration information does not get destroyed during
2293 if (DECL_VINDEX (olddecl))
2294 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2295 if (DECL_CONTEXT (olddecl))
2296 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2297 if (DECL_CLASS_CONTEXT (olddecl))
2298 DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
2299 if (DECL_CHAIN (newdecl) == NULL_TREE)
2300 DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2301 if (DECL_NEXT_METHOD (newdecl) == NULL_TREE)
2302 DECL_NEXT_METHOD (newdecl) = DECL_NEXT_METHOD (olddecl);
2303 if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
2304 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
2307 /* Deal with C++: must preserve virtual function table size. */
2308 if (TREE_CODE (olddecl) == TYPE_DECL)
2310 register tree newtype = TREE_TYPE (newdecl);
2311 register tree oldtype = TREE_TYPE (olddecl);
2313 if (newtype != error_mark_node && oldtype != error_mark_node
2314 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2316 CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
2317 CLASSTYPE_FRIEND_CLASSES (newtype)
2318 = CLASSTYPE_FRIEND_CLASSES (oldtype);
2321 /* why assert here? Just because debugging information is
2323 /* it happens on something like:
2324 typedef struct Thing {
2329 my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl),
2334 /* Special handling ensues if new decl is a function definition. */
2335 new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
2336 && DECL_INITIAL (newdecl) != NULL_TREE);
2338 /* Optionally warn about more than one declaration for the same name,
2339 but don't warn about a function declaration followed by a definition. */
2340 if (warn_redundant_decls
2341 && ! DECL_ARTIFICIAL (olddecl)
2342 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2343 /* Don't warn about extern decl followed by (tentative) definition. */
2344 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
2346 cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
2347 cp_warning ("previous declaration of `%D'", olddecl);
2350 /* Copy all the DECL_... slots specified in the new decl
2351 except for any that we copy here from the old type. */
2355 /* Automatically handles default parameters. */
2356 tree oldtype = TREE_TYPE (olddecl);
2357 /* Merge the data types specified in the two decls. */
2358 tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2360 /* Make sure we put the new type in the same obstack as the old ones.
2361 If the old types are not both in the same obstack, use the permanent
2363 if (oldtype && TYPE_OBSTACK (oldtype) == TYPE_OBSTACK (newtype))
2364 push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
2367 push_obstacks_nochange ();
2368 end_temporary_allocation ();
2371 if (TREE_CODE (newdecl) == VAR_DECL)
2372 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2373 /* Do this after calling `common_type' so that default
2374 parameters don't confuse us. */
2375 else if (TREE_CODE (newdecl) == FUNCTION_DECL
2376 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
2377 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
2379 tree ctype = NULL_TREE;
2380 ctype = DECL_CLASS_CONTEXT (newdecl);
2381 TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype,
2382 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
2383 TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype,
2384 TYPE_RAISES_EXCEPTIONS (oldtype));
2386 if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
2388 cp_error ("declaration of `%D' throws different exceptions...",
2390 cp_error_at ("...from previous declaration here", olddecl);
2393 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2395 /* Lay the type out, unless already done. */
2396 if (oldtype != TREE_TYPE (newdecl))
2398 if (TREE_TYPE (newdecl) != error_mark_node)
2399 layout_type (TREE_TYPE (newdecl));
2400 if (TREE_CODE (newdecl) != FUNCTION_DECL
2401 && TREE_CODE (newdecl) != TYPE_DECL
2402 && TREE_CODE (newdecl) != CONST_DECL
2403 && TREE_CODE (newdecl) != TEMPLATE_DECL)
2404 layout_decl (newdecl, 0);
2408 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
2409 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
2412 /* Merge the type qualifiers. */
2413 if (TREE_READONLY (newdecl))
2414 TREE_READONLY (olddecl) = 1;
2415 if (TREE_THIS_VOLATILE (newdecl))
2416 TREE_THIS_VOLATILE (olddecl) = 1;
2418 /* Merge the initialization information. */
2419 if (DECL_INITIAL (newdecl) == NULL_TREE
2420 && DECL_INITIAL (olddecl) != NULL_TREE)
2422 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2423 DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
2424 DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
2427 /* Merge the section attribute.
2428 We want to issue an error if the sections conflict but that must be
2429 done later in decl_attributes since we are called before attributes
2431 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
2432 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
2434 /* Keep the old rtl since we can safely use it, unless it's the
2435 call to abort() used for abstract virtuals. */
2436 if ((DECL_LANG_SPECIFIC (olddecl)
2437 && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
2438 || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
2439 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2443 /* If cannot merge, then use the new type and qualifiers,
2444 and don't preserve the old rtl. */
2447 /* Clean out any memory we had of the old declaration. */
2448 tree oldstatic = value_member (olddecl, static_aggregates);
2450 TREE_VALUE (oldstatic) = error_mark_node;
2452 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2453 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2454 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2455 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2458 /* Merge the storage class information. */
2459 if (DECL_EXTERNAL (newdecl))
2461 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
2462 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
2463 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2465 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2467 DECL_DECLARED_STATIC (newdecl) = DECL_DECLARED_STATIC (olddecl);
2468 DECL_INTERFACE_KNOWN (newdecl) = DECL_INTERFACE_KNOWN (olddecl);
2473 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
2474 /* A `const' which was not declared `extern' gets internal linkage. */
2475 if (TREE_CODE (newdecl) == VAR_DECL
2476 && TREE_READONLY (newdecl) && ! DECL_THIS_EXTERN (newdecl))
2477 TREE_PUBLIC (newdecl) = 0;
2480 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2482 /* If this clears PUBLIC, clear it in the identifier too. */
2483 if (TREE_CODE (newdecl) == FUNCTION_DECL && ! TREE_PUBLIC (olddecl))
2484 TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl)) = 0;
2488 /* If either decl says `inline', this fn is inline,
2489 unless its definition was passed already. */
2490 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
2491 DECL_INLINE (olddecl) = 1;
2492 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
2494 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2498 DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl);
2499 DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl);
2500 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
2501 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
2502 DECL_RTL (olddecl) = DECL_RTL (newdecl);
2504 if (new_defines_function)
2505 /* If defining a function declared with other language
2506 linkage, use the previously declared language linkage. */
2507 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2510 /* If redeclaring a builtin function, and not a definition,
2511 it stays built in. */
2512 if (DECL_BUILT_IN (olddecl))
2514 DECL_BUILT_IN (newdecl) = 1;
2515 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2516 /* If we're keeping the built-in definition, keep the rtl,
2517 regardless of declaration matches. */
2518 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2521 DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2523 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2524 if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)))
2525 /* Previously saved insns go together with
2526 the function's previous definition. */
2527 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2528 /* Don't clear out the arguments if we're redefining a function. */
2529 if (DECL_ARGUMENTS (olddecl))
2530 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2532 if (DECL_LANG_SPECIFIC (olddecl))
2533 DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl);
2536 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2538 if (DECL_TEMPLATE_INFO (olddecl)->length)
2539 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
2540 DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl);
2541 DECL_TEMPLATE_INSTANTIATIONS (newdecl)
2542 = DECL_TEMPLATE_INSTANTIATIONS (olddecl);
2543 if (DECL_CHAIN (newdecl) == NULL_TREE)
2544 DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2547 /* Now preserve various other info from the definition. */
2548 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2549 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2550 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2551 DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl);
2553 /* Don't really know how much of the language-specific
2554 values we should copy from old to new. */
2555 if (DECL_LANG_SPECIFIC (olddecl))
2557 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
2558 DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
2559 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
2562 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2565 struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
2566 struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
2568 function_size = sizeof (struct tree_decl);
2570 bcopy ((char *) newdecl + sizeof (struct tree_common),
2571 (char *) olddecl + sizeof (struct tree_common),
2572 function_size - sizeof (struct tree_common));
2574 /* Can we safely free the storage used by newdecl? */
2576 #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
2577 & ~ obstack_alignment_mask (&permanent_obstack))
2579 if ((char *)newdecl + ROUND (function_size)
2580 + ROUND (sizeof (struct lang_decl))
2581 == obstack_next_free (&permanent_obstack))
2583 DECL_MAIN_VARIANT (newdecl) = olddecl;
2584 DECL_LANG_SPECIFIC (olddecl) = ol;
2585 bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
2587 obstack_free (&permanent_obstack, newdecl);
2589 else if (LANG_DECL_PERMANENT (ol))
2591 if (DECL_MAIN_VARIANT (olddecl) == olddecl)
2593 /* Save these lang_decls that would otherwise be lost. */
2594 extern tree free_lang_decl_chain;
2595 tree free_lang_decl = (tree) ol;
2596 TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
2597 free_lang_decl_chain = free_lang_decl;
2607 bcopy ((char *) newdecl + sizeof (struct tree_common),
2608 (char *) olddecl + sizeof (struct tree_common),
2609 sizeof (struct tree_decl) - sizeof (struct tree_common)
2610 + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
2613 DECL_UID (olddecl) = olddecl_uid;
2615 DECL_FRIEND_P (olddecl) = 1;
2620 /* Record a decl-node X as belonging to the current lexical scope.
2621 Check for errors (such as an incompatible declaration for the same
2622 name already seen in the same scope).
2624 Returns either X or an old decl for the same name.
2625 If an old decl is returned, it may have been smashed
2626 to agree with what X says. */
2633 #if 0 /* not yet, should get fixed properly later */
2636 register tree name = DECL_ASSEMBLER_NAME (x);
2638 register struct binding_level *b = current_binding_level;
2641 static int nglobals; int len;
2643 len = list_length (global_binding_level->names);
2645 my_friendly_abort (8);
2646 else if (len > nglobals)
2650 if (x != current_function_decl
2651 /* Don't change DECL_CONTEXT of virtual methods. */
2652 && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x))
2653 && ! DECL_CONTEXT (x))
2654 DECL_CONTEXT (x) = current_function_decl;
2655 /* A local declaration for a function doesn't constitute nesting. */
2656 if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
2657 DECL_CONTEXT (x) = 0;
2659 #if 0 /* not yet, should get fixed properly later */
2660 /* For functions and class static data, we currently look up the encoded
2661 form of the name. For types, we want the real name. The former will
2662 probably be changed soon, according to MDT. */
2663 if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
2664 name = DECL_ASSEMBLER_NAME (x);
2666 name = DECL_NAME (x);
2668 /* Type are looked up using the DECL_NAME, as that is what the rest of the
2669 compiler wants to use. */
2670 if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL)
2671 name = DECL_NAME (x);
2679 t = lookup_name_current_level (name);
2680 if (t == error_mark_node)
2682 /* error_mark_node is 0 for a while during initialization! */
2684 cp_error_at ("`%#D' used prior to declaration", x);
2687 else if (t != NULL_TREE)
2689 if (TREE_CODE (t) == PARM_DECL)
2691 if (DECL_CONTEXT (t) == NULL_TREE)
2692 fatal ("parse errors have confused me too much");
2694 file = DECL_SOURCE_FILE (t);
2695 line = DECL_SOURCE_LINE (t);
2697 if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c)
2698 || (TREE_CODE (x) == TEMPLATE_DECL
2699 && ! DECL_TEMPLATE_IS_CLASS (x)))
2700 && is_overloaded_fn (t))
2701 /* don't do anything just yet */;
2702 else if (TREE_CODE (t) != TREE_CODE (x))
2704 if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
2705 || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)))
2707 /* We do nothing special here, because C++ does such nasty
2708 things with TYPE_DECLs. Instead, just let the TYPE_DECL
2709 get shadowed, and know that if we need to find a TYPE_DECL
2710 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
2711 slot of the identifier. */
2714 else if (duplicate_decls (x, t))
2717 else if (duplicate_decls (x, t))
2720 /* This is turned off until I have time to do it right (bpk). */
2722 /* Also warn if they did a prototype with `static' on it, but
2723 then later left the `static' off. */
2724 if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
2726 if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
2731 cp_warning ("`static' missing from declaration of `%D'",
2733 warning_with_file_and_line (file, line,
2734 "previous declaration of `%s'",
2735 decl_as_string (t, 0));
2738 /* Now fix things so it'll do what they expect. */
2739 if (current_function_decl)
2740 TREE_PUBLIC (current_function_decl) = 0;
2742 /* Due to interference in memory reclamation (X may be
2743 obstack-deallocated at this point), we must guard against
2744 one really special case. [jason: This should be handled
2745 by start_function] */
2746 if (current_function_decl == x)
2747 current_function_decl = t;
2749 if (TREE_CODE (t) == TYPE_DECL)
2750 SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t));
2756 if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x))
2758 t = push_overloaded_decl (x, 1);
2759 if (t != x || DECL_LANGUAGE (x) == lang_c)
2762 else if (TREE_CODE (x) == TEMPLATE_DECL && ! DECL_TEMPLATE_IS_CLASS (x))
2763 return push_overloaded_decl (x, 0);
2765 /* If declaring a type as a typedef, and the type has no known
2766 typedef name, install this TYPE_DECL as its typedef name. */
2767 if (TREE_CODE (x) == TYPE_DECL)
2769 tree type = TREE_TYPE (x);
2770 tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
2772 if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
2774 /* If these are different names, and we're at the global
2775 binding level, make two equivalent definitions. */
2777 if (global_bindings_p ())
2778 TYPE_NAME (type) = x;
2782 tree tname = DECL_NAME (name);
2784 if (global_bindings_p () && ANON_AGGRNAME_P (tname))
2786 /* do gratuitous C++ typedefing, and make sure that
2787 we access this type either through TREE_TYPE field
2788 or via the tags list. */
2789 TYPE_NAME (TREE_TYPE (x)) = x;
2790 pushtag (tname, TREE_TYPE (x), 0);
2793 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
2795 if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name))
2796 set_nested_typename (x, current_class_name,
2797 DECL_NAME (name), type);
2799 if (type != error_mark_node
2801 && TYPE_IDENTIFIER (type))
2802 set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
2805 /* Multiple external decls of the same identifier ought to match.
2807 We get warnings about inline functions where they are defined.
2808 We get warnings about other functions from push_overloaded_decl.
2810 Avoid duplicate warnings where they are used. */
2811 if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
2815 if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
2816 && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
2817 || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
2818 decl = IDENTIFIER_GLOBAL_VALUE (name);
2823 /* If different sort of thing, we already gave an error. */
2824 && TREE_CODE (decl) == TREE_CODE (x)
2825 && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1))
2827 cp_pedwarn ("type mismatch with previous external decl", x);
2828 cp_pedwarn_at ("previous external decl of `%#D'", decl);
2832 /* In PCC-compatibility mode, extern decls of vars with no current decl
2833 take effect at top level no matter where they are. */
2834 if (flag_traditional && DECL_EXTERNAL (x)
2835 && lookup_name (name, 0) == NULL_TREE)
2836 b = global_binding_level;
2838 /* This name is new in its binding level.
2839 Install the new declaration and return it. */
2840 if (b == global_binding_level)
2842 /* Install a global value. */
2844 /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
2845 A `const' which was not declared `extern' is invisible. */
2846 if (TREE_CODE (x) == VAR_DECL
2847 && TREE_READONLY (x) && ! DECL_THIS_EXTERN (x))
2848 TREE_PUBLIC (x) = 0;
2850 /* If the first global decl has external linkage,
2851 warn if we later see static one. */
2852 if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && DECL_PUBLIC (x))
2853 TREE_PUBLIC (name) = 1;
2855 /* Don't install a TYPE_DECL if we already have another
2856 sort of _DECL with that name. */
2857 if (TREE_CODE (x) != TYPE_DECL
2859 || TREE_CODE (t) == TYPE_DECL)
2860 IDENTIFIER_GLOBAL_VALUE (name) = x;
2862 /* Don't forget if the function was used via an implicit decl. */
2863 if (IDENTIFIER_IMPLICIT_DECL (name)
2864 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
2867 /* Don't forget if its address was taken in that way. */
2868 if (IDENTIFIER_IMPLICIT_DECL (name)
2869 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
2870 TREE_ADDRESSABLE (x) = 1;
2872 /* Warn about mismatches against previous implicit decl. */
2873 if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
2874 /* If this real decl matches the implicit, don't complain. */
2875 && ! (TREE_CODE (x) == FUNCTION_DECL
2876 && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
2878 ("`%D' was previously implicitly declared to return `int'", x);
2880 /* If new decl is `static' and an `extern' was seen previously,
2882 if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
2883 warn_extern_redeclared_static (x, t);
2887 /* Here to install a non-global value. */
2888 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
2889 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
2891 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2892 IDENTIFIER_LOCAL_VALUE (name) = x;
2894 /* If this is a TYPE_DECL, push it into the type value slot. */
2895 if (TREE_CODE (x) == TYPE_DECL)
2896 set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
2898 /* If this is an extern function declaration, see if we
2899 have a global definition or declaration for the function. */
2900 if (oldlocal == NULL_TREE
2901 && DECL_EXTERNAL (x) && !DECL_INLINE (x)
2902 && oldglobal != NULL_TREE
2903 && TREE_CODE (x) == FUNCTION_DECL
2904 && TREE_CODE (oldglobal) == FUNCTION_DECL)
2906 /* We have one. Their types must agree. */
2907 if (duplicate_decls (x, oldglobal))
2911 cp_warning ("extern declaration of `%#D' doesn't match", x);
2912 cp_warning_at ("global declaration `%#D'", oldglobal);
2915 /* If we have a local external declaration,
2916 and no file-scope declaration has yet been seen,
2917 then if we later have a file-scope decl it must not be static. */
2918 if (oldlocal == NULL_TREE
2919 && oldglobal == NULL_TREE
2920 && DECL_EXTERNAL (x)
2923 TREE_PUBLIC (name) = 1;
2926 if (DECL_FROM_INLINE (x))
2927 /* Inline decls shadow nothing. */;
2929 /* Warn if shadowing an argument at the top level of the body. */
2930 else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
2931 && TREE_CODE (oldlocal) == PARM_DECL
2932 && TREE_CODE (x) != PARM_DECL)
2934 /* Go to where the parms should be and see if we
2936 struct binding_level *b = current_binding_level->level_chain;
2942 if (b->parm_flag == 1)
2943 cp_error ("declaration of `%#D' shadows a parameter", name);
2945 /* Maybe warn if shadowing something else. */
2946 else if (warn_shadow && !DECL_EXTERNAL (x)
2947 /* No shadow warnings for internally generated vars. */
2948 && ! DECL_ARTIFICIAL (x)
2949 /* No shadow warnings for vars made for inlining. */
2950 && ! DECL_FROM_INLINE (x))
2952 char *warnstring = NULL;
2954 if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
2955 warnstring = "declaration of `%s' shadows a parameter";
2956 else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
2957 && !TREE_STATIC (name))
2958 warnstring = "declaration of `%s' shadows a member of `this'";
2959 else if (oldlocal != NULL_TREE)
2960 warnstring = "declaration of `%s' shadows previous local";
2961 else if (oldglobal != NULL_TREE)
2962 warnstring = "declaration of `%s' shadows global declaration";
2965 warning (warnstring, IDENTIFIER_POINTER (name));
2968 /* If storing a local value, there may already be one (inherited).
2969 If so, record it for restoration when this binding level ends. */
2970 if (oldlocal != NULL_TREE)
2971 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2974 /* Keep count of variables in this level with incomplete type. */
2975 if (TREE_CODE (x) != TEMPLATE_DECL
2976 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
2977 && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
2979 if (++b->n_incomplete == 0)
2980 error ("too many incomplete variables at this point");
2983 /* Keep count of variables in this level with incomplete type. */
2984 /* RTTI TD entries are created while defining the type_info. */
2985 if (TREE_CODE (x) == VAR_DECL
2986 && TYPE_LANG_SPECIFIC (TREE_TYPE (x))
2987 && TYPE_BEING_DEFINED (TREE_TYPE (x)))
2989 if (++b->n_incomplete == 0)
2990 error ("too many incomplete variables at this point");
2994 if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE)
2996 if (current_class_name)
2998 if (! TREE_MANGLED (name))
2999 set_nested_typename (x, current_class_name, DECL_NAME (x),
3004 /* Put decls on list in reverse order.
3005 We will reverse them later if necessary. */
3006 TREE_CHAIN (x) = b->names;
3008 if (! (b != global_binding_level || TREE_PERMANENT (x)))
3009 my_friendly_abort (124);
3014 /* Same as pushdecl, but define X in binding-level LEVEL. */
3017 pushdecl_with_scope (x, level)
3019 struct binding_level *level;
3021 register struct binding_level *b = current_binding_level;
3023 current_binding_level = level;
3025 current_binding_level = b;
3029 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
3032 pushdecl_top_level (x)
3035 register struct binding_level *b = inner_binding_level;
3036 register tree t = pushdecl_with_scope (x, global_binding_level);
3038 /* Now, the type_shadowed stack may screw us. Munge it so it does
3040 if (TREE_CODE (x) == TYPE_DECL)
3042 tree name = DECL_NAME (x);
3044 tree *ptr = (tree *)0;
3045 for (; b != global_binding_level; b = b->level_chain)
3047 tree shadowed = b->type_shadowed;
3048 for (; shadowed; shadowed = TREE_CHAIN (shadowed))
3049 if (TREE_PURPOSE (shadowed) == name)
3051 ptr = &TREE_VALUE (shadowed);
3052 /* Can't break out of the loop here because sometimes
3053 a binding level will have duplicate bindings for
3054 PT names. It's gross, but I haven't time to fix it. */
3057 newval = TREE_TYPE (x);
3058 if (ptr == (tree *)0)
3060 /* @@ This shouldn't be needed. My test case "zstring.cc" trips
3061 up here if this is changed to an assertion. --KR */
3062 SET_IDENTIFIER_TYPE_VALUE (name, newval);
3067 /* Disabled this 11/10/92, since there are many cases which
3068 behave just fine when *ptr doesn't satisfy either of these.
3069 For example, nested classes declared as friends of their enclosing
3070 class will not meet this criteria. (bpk) */
3071 my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141);
3079 /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
3082 push_overloaded_decl_top_level (x, forget)
3086 struct binding_level *b = current_binding_level;
3088 current_binding_level = global_binding_level;
3089 push_overloaded_decl (x, forget);
3090 current_binding_level = b;
3093 /* Make the declaration of X appear in CLASS scope. */
3095 pushdecl_class_level (x)
3098 /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class
3099 scope looks for the pre-mangled name. */
3100 register tree name = DECL_NAME (x);
3104 if (TYPE_BEING_DEFINED (current_class_type))
3106 /* Check for inconsistent use of this name in the class body.
3107 Types, enums, and static vars are checked here; other
3108 members are checked in finish_struct. */
3109 tree icv = IDENTIFIER_CLASS_VALUE (name);
3112 /* Don't complain about inherited names. */
3113 && id_in_current_class (name)
3114 /* Or shadowed tags. */
3115 && !(TREE_CODE (icv) == TYPE_DECL
3116 && DECL_CONTEXT (icv) == current_class_type))
3118 cp_error ("declaration of identifier `%D' as `%#D'", name, x);
3119 cp_error_at ("conflicts with previous use in class as `%#D'",
3124 push_class_level_binding (name, x);
3125 if (TREE_CODE (x) == TYPE_DECL)
3127 set_identifier_type_value (name, TREE_TYPE (x));
3128 if (!DECL_NESTED_TYPENAME (x))
3129 set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
3135 /* This function is used to push the mangled decls for nested types into
3136 the appropriate scope. Previously pushdecl_top_level was used, but that
3137 is incorrect for members of local classes. */
3139 pushdecl_nonclass_level (x)
3142 struct binding_level *b = current_binding_level;
3145 /* Get out of class scope -- this isn't necessary, because class scope
3146 doesn't make it into current_binding_level. */
3147 while (b->parm_flag == 2)
3150 my_friendly_assert (b->parm_flag != 2, 180);
3153 /* Get out of template binding levels */
3154 while (b->pseudo_global)
3157 pushdecl_with_scope (x, b);
3160 /* Make the declaration(s) of X appear in CLASS scope
3161 under the name NAME. */
3163 push_class_level_binding (name, x)
3167 maybe_push_cache_obstack ();
3168 class_binding_level->class_shadowed
3169 = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
3170 class_binding_level->class_shadowed);
3172 IDENTIFIER_CLASS_VALUE (name) = x;
3173 obstack_ptr_grow (&decl_obstack, x);
3176 /* Tell caller how to interpret a TREE_LIST which contains
3177 chains of FUNCTION_DECLS. */
3179 overloaded_globals_p (list)
3182 my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
3184 /* Don't commit caller to seeing them as globals. */
3185 if (TREE_NONLOCAL_FLAG (list))
3187 /* Do commit caller to seeing them as globals. */
3188 if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
3190 /* Do commit caller to not seeing them as globals. */
3194 /* DECL is a FUNCTION_DECL which may have other definitions already in
3195 place. We get around this by making the value of the identifier point
3196 to a list of all the things that want to be referenced by that name. It
3197 is then up to the users of that name to decide what to do with that
3200 DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
3201 slot. It is dealt with the same way.
3203 The value returned may be a previous declaration if we guessed wrong
3204 about what language DECL should belong to (C or C++). Otherwise,
3205 it's always DECL (and never something that's not a _DECL). */
3207 push_overloaded_decl (decl, forgettable)
3211 tree orig_name = DECL_NAME (decl);
3213 int doing_global = (global_bindings_p () || ! forgettable
3214 || flag_traditional || pseudo_global_level_p ());
3218 old = IDENTIFIER_GLOBAL_VALUE (orig_name);
3219 if (old && TREE_CODE (old) == FUNCTION_DECL
3220 && DECL_ARTIFICIAL (old)
3221 && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old)))
3223 if (duplicate_decls (decl, old))
3230 old = IDENTIFIER_LOCAL_VALUE (orig_name);
3232 if (! purpose_member (orig_name, current_binding_level->shadowed))
3234 current_binding_level->shadowed
3235 = tree_cons (orig_name, old, current_binding_level->shadowed);
3243 /* We cache the value of builtin functions as ADDR_EXPRs
3244 in the name space. Convert it to some kind of _DECL after
3245 remembering what to forget. */
3246 if (TREE_CODE (old) == ADDR_EXPR)
3247 old = TREE_OPERAND (old, 0);
3250 if (TREE_CODE (old) == VAR_DECL)
3252 cp_error_at ("previous non-function declaration `%#D'", old);
3253 cp_error ("conflicts with function declaration `%#D'", decl);
3254 return error_mark_node;
3256 else if (TREE_CODE (old) == TYPE_DECL)
3258 tree t = TREE_TYPE (old);
3259 if (IS_AGGR_TYPE (t) && warn_shadow)
3260 cp_warning ("`%#D' hides constructor for `%#T'", decl, t);
3263 else if (is_overloaded_fn (old))
3267 for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp))
3268 if (decl == tmp || duplicate_decls (decl, tmp))
3273 if (old || TREE_CODE (decl) == TEMPLATE_DECL)
3275 if (old && is_overloaded_fn (old))
3276 DECL_CHAIN (decl) = get_first_fn (old);
3278 DECL_CHAIN (decl) = NULL_TREE;
3279 old = tree_cons (orig_name, decl, NULL_TREE);
3280 TREE_TYPE (old) = unknown_type_node;
3283 /* orig_name is not ambiguous. */
3287 IDENTIFIER_GLOBAL_VALUE (orig_name) = old;
3289 IDENTIFIER_LOCAL_VALUE (orig_name) = old;
3294 /* Generate an implicit declaration for identifier FUNCTIONID
3295 as a function of type int (). Print a warning if appropriate. */
3298 implicitly_declare (functionid)
3302 int temp = allocation_temporary_p ();
3304 push_obstacks_nochange ();
3306 /* Save the decl permanently so we can warn if definition follows.
3307 In ANSI C, warn_implicit is usually false, so the saves little space.
3308 But in C++, it's usually true, hence the extra code. */
3309 if (temp && (flag_traditional || !warn_implicit
3310 || current_binding_level == global_binding_level))
3311 end_temporary_allocation ();
3313 /* We used to reuse an old implicit decl here,
3314 but this loses with inline functions because it can clobber
3315 the saved decl chains. */
3316 decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
3318 DECL_EXTERNAL (decl) = 1;
3319 TREE_PUBLIC (decl) = 1;
3321 /* ANSI standard says implicit declarations are in the innermost block.
3322 So we record the decl in the standard fashion.
3323 If flag_traditional is set, pushdecl does it top-level. */
3325 rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
3328 /* Only one warning per identifier. */
3329 && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
3331 cp_pedwarn ("implicit declaration of function `%#D'", decl);
3334 SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
3341 /* Return zero if the declaration NEWDECL is valid
3342 when the declaration OLDDECL (assumed to be for the same name)
3343 has already been seen.
3344 Otherwise return an error message format string with a %s
3345 where the identifier should go. */
3348 redeclaration_error_message (newdecl, olddecl)
3349 tree newdecl, olddecl;
3351 if (TREE_CODE (newdecl) == TYPE_DECL)
3353 /* Because C++ can put things into name space for free,
3354 constructs like "typedef struct foo { ... } foo"
3355 would look like an erroneous redeclaration. */
3356 if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
3359 return "redefinition of `%#D'";
3361 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3363 /* If this is a pure function, its olddecl will actually be
3364 the original initialization to `0' (which we force to call
3365 abort()). Don't complain about redefinition in this case. */
3366 if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
3369 /* We'll complain about linkage mismatches in
3370 warn_extern_redeclared_static. */
3372 /* defining the same name twice is no good. */
3373 if (DECL_INITIAL (olddecl) != NULL_TREE
3374 && DECL_INITIAL (newdecl) != NULL_TREE
3375 /* However, defining once as extern inline and a second
3376 time in another way is ok. */
3377 && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
3378 && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
3380 if (DECL_NAME (olddecl) == NULL_TREE)
3381 return "`%#D' not declared in class";
3383 return "redefinition of `%#D'";
3387 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
3388 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
3390 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
3391 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
3393 for (; t1; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
3394 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
3395 return "duplicate default arguments given for `%#D'";
3399 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
3401 if (DECL_INITIAL (olddecl) && DECL_INITIAL (newdecl))
3402 return "redefinition of `%#D'";
3405 else if (current_binding_level == global_binding_level)
3407 /* Objects declared at top level: */
3408 /* Insist that the linkage match. */
3409 if (! TREE_PUBLIC (newdecl) && TREE_PUBLIC (olddecl))
3410 return "conflicting declarations of `%#D'";
3411 /* If at least one is a reference, it's ok. */
3412 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3414 /* Reject two definitions. */
3415 return "redefinition of `%#D'";
3419 /* Objects declared with block scope: */
3420 /* Reject two definitions, and reject a definition
3421 together with an external reference. */
3422 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3423 return "redeclaration of `%#D'";
3428 /* Get the LABEL_DECL corresponding to identifier ID as a label.
3429 Create one if none exists so far for the current function.
3430 This function is called for both label definitions and label references. */
3436 register tree decl = IDENTIFIER_LABEL_VALUE (id);
3438 if (current_function_decl == NULL_TREE)
3440 error ("label `%s' referenced outside of any function",
3441 IDENTIFIER_POINTER (id));
3445 if ((decl == NULL_TREE
3446 || DECL_SOURCE_LINE (decl) == 0)
3447 && (named_label_uses == NULL_TREE
3448 || TREE_PURPOSE (named_label_uses) != current_binding_level->names
3449 || TREE_VALUE (named_label_uses) != decl))
3452 = tree_cons (current_binding_level->names, decl, named_label_uses);
3453 TREE_TYPE (named_label_uses) = (tree)current_binding_level;
3456 /* Use a label already defined or ref'd with this name. */
3457 if (decl != NULL_TREE)
3459 /* But not if it is inherited and wasn't declared to be inheritable. */
3460 if (DECL_CONTEXT (decl) != current_function_decl
3461 && ! C_DECLARED_LABEL_FLAG (decl))
3462 return shadow_label (id);
3466 decl = build_decl (LABEL_DECL, id, void_type_node);
3468 /* A label not explicitly declared must be local to where it's ref'd. */
3469 DECL_CONTEXT (decl) = current_function_decl;
3471 DECL_MODE (decl) = VOIDmode;
3473 /* Say where one reference is to the label,
3474 for the sake of the error if it is not defined. */
3475 DECL_SOURCE_LINE (decl) = lineno;
3476 DECL_SOURCE_FILE (decl) = input_filename;
3478 SET_IDENTIFIER_LABEL_VALUE (id, decl);
3480 named_labels = tree_cons (NULL_TREE, decl, named_labels);
3481 TREE_VALUE (named_label_uses) = decl;
3486 /* Make a label named NAME in the current function,
3487 shadowing silently any that may be inherited from containing functions
3488 or containing scopes.
3490 Note that valid use, if the label being shadowed
3491 comes from another scope in the same function,
3492 requires calling declare_nonlocal_label right away. */
3498 register tree decl = IDENTIFIER_LABEL_VALUE (name);
3500 if (decl != NULL_TREE)
3502 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3503 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3504 SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
3507 return lookup_label (name);
3510 /* Define a label, specifying the location in the source file.
3511 Return the LABEL_DECL node for the label, if the definition is valid.
3512 Otherwise return 0. */
3515 define_label (filename, line, name)
3520 tree decl = lookup_label (name);
3522 /* After labels, make any new cleanups go into their
3523 own new (temporary) binding contour. */
3524 current_binding_level->more_cleanups_ok = 0;
3526 /* If label with this name is known from an outer context, shadow it. */
3527 if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
3529 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3530 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3531 decl = lookup_label (name);
3534 if (DECL_INITIAL (decl) != NULL_TREE)
3536 cp_error ("duplicate label `%D'", decl);
3543 /* Mark label as having been defined. */
3544 DECL_INITIAL (decl) = error_mark_node;
3545 /* Say where in the source. */
3546 DECL_SOURCE_FILE (decl) = filename;
3547 DECL_SOURCE_LINE (decl) = line;
3549 for (prev = NULL_TREE, uses = named_label_uses;
3551 prev = uses, uses = TREE_CHAIN (uses))
3552 if (TREE_VALUE (uses) == decl)
3554 struct binding_level *b = current_binding_level;
3557 tree new_decls = b->names;
3558 tree old_decls = ((tree)b == TREE_TYPE (uses)
3559 ? TREE_PURPOSE (uses) : NULL_TREE);
3560 while (new_decls != old_decls)
3562 if (TREE_CODE (new_decls) == VAR_DECL
3563 /* Don't complain about crossing initialization
3564 of internal entities. They can't be accessed,
3565 and they should be cleaned up
3566 by the time we get to the label. */
3567 && ! DECL_ARTIFICIAL (new_decls)
3568 && ((DECL_INITIAL (new_decls) != NULL_TREE
3569 && DECL_INITIAL (new_decls) != error_mark_node)
3570 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
3572 if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE)
3573 cp_error ("invalid jump to label `%D'", decl);
3574 SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl);
3575 cp_error ("crosses initialization of `%D'", new_decls);
3577 new_decls = TREE_CHAIN (new_decls);
3579 if ((tree)b == TREE_TYPE (uses))
3585 TREE_CHAIN (prev) = TREE_CHAIN (uses);
3587 named_label_uses = TREE_CHAIN (uses);
3589 current_function_return_value = NULL_TREE;
3594 /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */
3595 /* XXX Note decl is never actually used. (bpk) */
3597 define_case_label (decl)
3600 tree cleanup = last_cleanup_this_contour ();
3603 static int explained = 0;
3604 cp_error_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
3605 error ("where case label appears here");
3608 error ("(enclose actions of previous case statements requiring");
3609 error ("destructors in their own binding contours.)");
3614 /* After labels, make any new cleanups go into their
3615 own new (temporary) binding contour. */
3617 current_binding_level->more_cleanups_ok = 0;
3618 current_function_return_value = NULL_TREE;
3621 /* Return the list of declarations of the current level.
3622 Note that this list is in reverse order unless/until
3623 you nreverse it; and when you do nreverse it, you must
3624 store the result back using `storedecls' or you will lose. */
3629 return current_binding_level->names;
3632 /* Return the list of type-tags (for structs, etc) of the current level. */
3637 return current_binding_level->tags;
3640 /* Store the list of declarations of the current level.
3641 This is done for the parameter declarations of a function being defined,
3642 after they are modified in the light of any missing parameters. */
3648 current_binding_level->names = decls;
3651 /* Similarly, store the list of tags of the current level. */
3657 current_binding_level->tags = tags;
3660 /* Given NAME, an IDENTIFIER_NODE,
3661 return the structure (or union or enum) definition for that name.
3662 Searches binding levels from BINDING_LEVEL up to the global level.
3663 If THISLEVEL_ONLY is nonzero, searches only the specified context
3664 (but skips any tag-transparent contexts to find one that is
3665 meaningful for tags).
3666 FORM says which kind of type the caller wants;
3667 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
3668 If the wrong kind of type is found, and it's not a template, an error is
3672 lookup_tag (form, name, binding_level, thislevel_only)
3673 enum tree_code form;
3674 struct binding_level *binding_level;
3678 register struct binding_level *level;
3680 for (level = binding_level; level; level = level->level_chain)
3683 if (ANON_AGGRNAME_P (name))
3684 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3686 /* There's no need for error checking here, because
3687 anon names are unique throughout the compilation. */
3688 if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
3689 return TREE_VALUE (tail);
3692 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3694 if (TREE_PURPOSE (tail) == name)
3696 enum tree_code code = TREE_CODE (TREE_VALUE (tail));
3697 /* Should tighten this up; it'll probably permit
3698 UNION_TYPE and a struct template, for example. */
3700 && !(form != ENUMERAL_TYPE
3701 && (code == TEMPLATE_DECL
3702 || code == UNINSTANTIATED_P_TYPE)))
3705 /* Definition isn't the kind we were looking for. */
3706 cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
3709 return TREE_VALUE (tail);
3712 if (thislevel_only && ! level->tag_transparent)
3714 if (current_class_type && level->level_chain == global_binding_level)
3716 /* Try looking in this class's tags before heading into
3717 global binding level. */
3718 tree context = current_class_type;
3721 switch (TREE_CODE_CLASS (TREE_CODE (context)))
3725 these_tags = CLASSTYPE_TAGS (context);
3726 if (ANON_AGGRNAME_P (name))
3729 if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
3731 return TREE_VALUE (tail);
3732 these_tags = TREE_CHAIN (these_tags);
3737 if (TREE_PURPOSE (these_tags) == name)
3739 if (TREE_CODE (TREE_VALUE (these_tags)) != form)
3741 cp_error ("`%#D' redeclared as %C in class scope",
3742 TREE_VALUE (tail), form);
3744 return TREE_VALUE (tail);
3746 these_tags = TREE_CHAIN (these_tags);
3748 /* If this type is not yet complete, then don't
3749 look at its context. */
3750 if (TYPE_SIZE (context) == NULL_TREE)
3752 /* Go to next enclosing type, if any. */
3753 context = DECL_CONTEXT (TYPE_NAME (context));
3756 context = DECL_CONTEXT (context);
3759 my_friendly_abort (10);
3771 set_current_level_tags_transparency (tags_transparent)
3772 int tags_transparent;
3774 current_binding_level->tag_transparent = tags_transparent;
3777 /* Given a type, find the tag that was defined for it and return the tag name.
3778 Otherwise return 0. However, the value can never be 0
3779 in the cases in which this is used.
3781 C++: If NAME is non-zero, this is the new name to install. This is
3782 done when replacing anonymous tags with real tag names. */
3785 lookup_tag_reverse (type, name)
3789 register struct binding_level *level;
3791 for (level = current_binding_level; level; level = level->level_chain)
3794 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3796 if (TREE_VALUE (tail) == type)
3799 TREE_PURPOSE (tail) = name;
3800 return TREE_PURPOSE (tail);
3807 /* Given type TYPE which was not declared in C++ language context,
3808 attempt to find a name by which it is referred. */
3810 typedecl_for_tag (tag)
3813 struct binding_level *b = current_binding_level;
3815 if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
3816 return TYPE_NAME (tag);
3820 tree decls = b->names;
3823 if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
3825 decls = TREE_CHAIN (decls);
3834 /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
3835 Return the type value, or NULL_TREE if not found. */
3837 lookup_nested_type (type, context)
3841 if (context == NULL_TREE)
3845 switch (TREE_CODE (context))
3849 tree ctype = TREE_TYPE (context);
3850 tree match = value_member (type, CLASSTYPE_TAGS (ctype));
3852 return TREE_VALUE (match);
3853 context = DECL_CONTEXT (context);
3855 /* When we have a nested class whose member functions have
3856 local types (e.g., a set of enums), we'll arrive here
3857 with the DECL_CONTEXT as the actual RECORD_TYPE node for
3858 the enclosing class. Instead, we want to make sure we
3859 come back in here with the TYPE_DECL, not the RECORD_TYPE. */
3860 if (context && TREE_CODE (context) == RECORD_TYPE)
3861 context = TREE_CHAIN (context);
3865 return TYPE_IDENTIFIER (type) ?
3866 lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE;
3869 my_friendly_abort (12);
3875 /* Look up NAME in the current binding level and its superiors in the
3876 namespace of variables, functions and typedefs. Return a ..._DECL
3877 node of some kind representing its definition if there is only one
3878 such declaration, or return a TREE_LIST with all the overloaded
3879 definitions if there are many, or return 0 if it is undefined.
3881 If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
3882 If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
3883 Otherwise we prefer non-TYPE_DECLs. */
3886 lookup_name_real (name, prefer_type, nonclass)
3888 int prefer_type, nonclass;
3893 if (prefer_type == -2)
3895 extern int looking_for_typename;
3898 prefer_type = looking_for_typename;
3900 if (got_scope != NULL_TREE)
3902 if (got_scope == error_mark_node)
3903 return error_mark_node;
3904 else if (got_scope == void_type_node)
3905 val = IDENTIFIER_GLOBAL_VALUE (name);
3906 else if (TREE_CODE (got_scope) == TEMPLATE_TYPE_PARM
3907 /* TFIXME -- don't do this for UPTs in new model. */
3908 || TREE_CODE (got_scope) == UNINSTANTIATED_P_TYPE)
3910 if (prefer_type > 0)
3911 val = create_nested_upt (got_scope, name);
3915 else if (! IS_AGGR_TYPE (got_scope))
3916 /* Someone else will give an error about this if needed. */
3918 else if (TYPE_BEING_DEFINED (got_scope))
3920 val = IDENTIFIER_CLASS_VALUE (name);
3921 if (val && DECL_CONTEXT (val) != got_scope)
3923 struct binding_level *b = class_binding_level;
3924 for (val = NULL_TREE; b; b = b->level_chain)
3926 tree t = purpose_member (name, b->class_shadowed);
3927 if (t && TREE_VALUE (t)
3928 && DECL_CONTEXT (TREE_VALUE (t)) == got_scope)
3930 val = TREE_VALUE (t);
3935 if (val == NULL_TREE
3936 && CLASSTYPE_LOCAL_TYPEDECLS (got_scope))
3937 val = lookup_field (got_scope, name, 0, 1);
3939 else if (got_scope == current_class_type)
3940 val = IDENTIFIER_CLASS_VALUE (name);
3942 val = lookup_field (got_scope, name, 0, 0);
3948 if (current_binding_level != global_binding_level
3949 && IDENTIFIER_LOCAL_VALUE (name))
3950 val = IDENTIFIER_LOCAL_VALUE (name);
3951 /* In C++ class fields are between local and global scope,
3952 just before the global scope. */
3953 else if (current_class_type && ! nonclass)
3955 val = IDENTIFIER_CLASS_VALUE (name);
3956 if (val == NULL_TREE
3957 && TYPE_BEING_DEFINED (current_class_type)
3958 && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
3959 /* Try to find values from base classes if we are presently
3960 defining a type. We are presently only interested in
3962 val = lookup_field (current_class_type, name, 0, 1);
3964 /* yylex() calls this with -2, since we should never start digging for
3965 the nested name at the point where we haven't even, for example,
3966 created the COMPONENT_REF or anything like that. */
3967 if (val == NULL_TREE)
3968 val = lookup_nested_field (name, ! yylex);
3970 if (val == NULL_TREE)
3971 val = IDENTIFIER_GLOBAL_VALUE (name);
3974 val = IDENTIFIER_GLOBAL_VALUE (name);
3979 if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template)
3980 || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0)
3983 if (IDENTIFIER_HAS_TYPE_VALUE (name))
3984 return TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
3986 if (TREE_TYPE (val) == error_mark_node)
3987 return error_mark_node;
3994 lookup_name_nonclass (name)
3997 return lookup_name_real (name, 0, 1);
4001 lookup_name (name, prefer_type)
4005 return lookup_name_real (name, prefer_type, 0);
4008 /* Similar to `lookup_name' but look only at current binding level. */
4011 lookup_name_current_level (name)
4014 register tree t = NULL_TREE;
4016 if (current_binding_level == global_binding_level)
4018 t = IDENTIFIER_GLOBAL_VALUE (name);
4020 /* extern "C" function() */
4021 if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
4024 else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
4026 struct binding_level *b = current_binding_level;
4029 for (t = b->names; t; t = TREE_CHAIN (t))
4030 if (DECL_NAME (t) == name)
4044 /* Arrange for the user to get a source line number, even when the
4045 compiler is going down in flames, so that she at least has a
4046 chance of working around problems in the compiler. We used to
4047 call error(), but that let the segmentation fault continue
4048 through; now, it's much more passive by asking them to send the
4049 maintainers mail about the problem. */
4055 signal (SIGSEGV, SIG_DFL);
4057 signal (SIGIOT, SIG_DFL);
4060 signal (SIGILL, SIG_DFL);
4063 signal (SIGABRT, SIG_DFL);
4066 signal (SIGBUS, SIG_DFL);
4068 my_friendly_abort (0);
4071 /* Array for holding types considered "built-in". These types
4072 are output in the module in which `main' is defined. */
4073 static tree *builtin_type_tdescs_arr;
4074 static int builtin_type_tdescs_len, builtin_type_tdescs_max;
4076 /* Push the declarations of builtin types into the namespace.
4077 RID_INDEX, if < RID_MAX is the index of the builtin type
4078 in the array RID_POINTERS. NAME is the name used when looking
4079 up the builtin type. TYPE is the _TYPE node for the builtin type. */
4082 record_builtin_type (rid_index, name, type)
4087 tree rname = NULL_TREE, tname = NULL_TREE;
4090 if ((int) rid_index < (int) RID_MAX)
4091 rname = ridpointers[(int) rid_index];
4093 tname = get_identifier (name);
4095 TYPE_BUILT_IN (type) = 1;
4099 #if 0 /* not yet, should get fixed properly later */
4100 tdecl = pushdecl (make_type_decl (tname, type));
4102 tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
4104 set_identifier_type_value (tname, NULL_TREE);
4105 if ((int) rid_index < (int) RID_MAX)
4106 IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
4108 if (rname != NULL_TREE)
4110 if (tname != NULL_TREE)
4112 set_identifier_type_value (rname, NULL_TREE);
4113 IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
4117 #if 0 /* not yet, should get fixed properly later */
4118 tdecl = pushdecl (make_type_decl (rname, type));
4120 tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
4122 set_identifier_type_value (rname, NULL_TREE);
4128 if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
4130 builtin_type_tdescs_max *= 2;
4131 builtin_type_tdescs_arr
4132 = (tree *)xrealloc (builtin_type_tdescs_arr,
4133 builtin_type_tdescs_max * sizeof (tree));
4135 builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
4136 if (TREE_CODE (type) != POINTER_TYPE)
4138 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4139 = build_pointer_type (type);
4140 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4141 = build_pointer_type (build_type_variant (type, 1, 0));
4143 if (TREE_CODE (type) != VOID_TYPE)
4145 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4146 = build_reference_type (type);
4147 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4148 = build_reference_type (build_type_variant (type, 1, 0));
4154 output_builtin_tdesc_entries ()
4156 extern struct obstack permanent_obstack;
4158 /* If there's more than one main in this file, don't crash. */
4159 if (builtin_type_tdescs_arr == 0)
4162 push_obstacks (&permanent_obstack, &permanent_obstack);
4163 while (builtin_type_tdescs_len > 0)
4165 tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
4166 tree tdesc = build_t_desc (type, 0);
4167 TREE_ASM_WRITTEN (tdesc) = 0;
4168 build_t_desc (type, 2);
4170 free (builtin_type_tdescs_arr);
4171 builtin_type_tdescs_arr = 0;
4175 /* Push overloaded decl, in global scope, with one argument so it
4176 can be used as a callback from define_function. */
4178 push_overloaded_decl_1 (x)
4181 push_overloaded_decl (x, 0);
4184 /* Create the predefined scalar types of C,
4185 and some nodes representing standard constants (0, 1, (void *)0).
4186 Initialize the global binding level.
4187 Make definitions for built-in primitive functions. */
4190 init_decl_processing ()
4193 register tree endlink, int_endlink, double_endlink, ptr_endlink;
4195 /* Either char* or void*. */
4196 tree traditional_ptr_type_node;
4197 /* Data type of memcpy. */
4199 #if 0 /* Not yet. */
4200 /* Data type of strncpy. */
4203 int wchar_type_size;
4205 tree array_domain_type;
4207 /* Have to make these distinct before we try using them. */
4208 lang_name_cplusplus = get_identifier ("C++");
4209 lang_name_c = get_identifier ("C");
4211 if (flag_ansi || pedantic)
4212 strict_prototypes_lang_c = strict_prototypes_lang_cplusplus;
4215 current_lang_name = lang_name_c;
4217 current_function_decl = NULL_TREE;
4218 named_labels = NULL_TREE;
4219 named_label_uses = NULL_TREE;
4220 current_binding_level = NULL_BINDING_LEVEL;
4221 free_binding_level = NULL_BINDING_LEVEL;
4223 /* Because most segmentation signals can be traced back into user
4224 code, catch them and at least give the user a chance of working
4225 around compiler bugs. */
4226 signal (SIGSEGV, signal_catch);
4228 /* We will also catch aborts in the back-end through signal_catch and
4229 give the user a chance to see where the error might be, and to defeat
4230 aborts in the back-end when there have been errors previously in their
4233 signal (SIGIOT, signal_catch);
4236 signal (SIGILL, signal_catch);
4239 signal (SIGABRT, signal_catch);
4242 signal (SIGBUS, signal_catch);
4245 gcc_obstack_init (&decl_obstack);
4248 builtin_type_tdescs_max = 100;
4249 builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
4252 /* Must lay these out before anything else gets laid out. */
4253 error_mark_node = make_node (ERROR_MARK);
4254 TREE_PERMANENT (error_mark_node) = 1;
4255 TREE_TYPE (error_mark_node) = error_mark_node;
4256 error_mark_list = build_tree_list (error_mark_node, error_mark_node);
4257 TREE_TYPE (error_mark_list) = error_mark_node;
4259 /* Make the binding_level structure for global names. */
4261 global_binding_level = current_binding_level;
4263 this_identifier = get_identifier (THIS_NAME);
4264 in_charge_identifier = get_identifier (IN_CHARGE_NAME);
4265 pfn_identifier = get_identifier (VTABLE_PFN_NAME);
4266 index_identifier = get_identifier (VTABLE_INDEX_NAME);
4267 delta_identifier = get_identifier (VTABLE_DELTA_NAME);
4268 delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
4269 pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
4271 /* Define `int' and `char' first so that dbx will output them first. */
4273 integer_type_node = make_signed_type (INT_TYPE_SIZE);
4274 record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
4276 /* Define `char', which is like either `signed char' or `unsigned char'
4277 but not the same as either. */
4281 ? make_signed_type (CHAR_TYPE_SIZE)
4282 : make_unsigned_type (CHAR_TYPE_SIZE));
4283 record_builtin_type (RID_CHAR, "char", char_type_node);
4285 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4286 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
4288 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4289 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
4291 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4292 record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
4293 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
4295 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4296 record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
4298 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4299 record_builtin_type (RID_MAX, "long long unsigned int",
4300 long_long_unsigned_type_node);
4301 record_builtin_type (RID_MAX, "long long unsigned",
4302 long_long_unsigned_type_node);
4304 /* `unsigned long' is the standard type for sizeof.
4305 Traditionally, use a signed type.
4306 Note that stddef.h uses `unsigned long',
4307 and this must agree, even of long and int are the same size. */
4309 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
4310 if (flag_traditional && TREE_UNSIGNED (sizetype))
4311 sizetype = signed_type (sizetype);
4314 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
4316 TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
4317 TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
4318 TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
4319 TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
4320 TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
4321 TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
4322 TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
4324 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4325 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
4326 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4327 record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
4328 record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
4330 /* Define both `signed char' and `unsigned char'. */
4331 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4332 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
4333 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4334 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
4336 /* These are types that type_for_size and type_for_mode use. */
4337 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4338 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
4339 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4340 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
4341 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4342 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
4343 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4344 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
4345 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4346 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
4347 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4348 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
4349 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4350 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
4351 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4352 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
4354 float_type_node = make_node (REAL_TYPE);
4355 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4356 record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
4357 layout_type (float_type_node);
4359 double_type_node = make_node (REAL_TYPE);
4360 if (flag_short_double)
4361 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4363 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4364 record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
4365 layout_type (double_type_node);
4367 long_double_type_node = make_node (REAL_TYPE);
4368 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4369 record_builtin_type (RID_MAX, "long double", long_double_type_node);
4370 layout_type (long_double_type_node);
4372 integer_zero_node = build_int_2 (0, 0);
4373 TREE_TYPE (integer_zero_node) = integer_type_node;
4374 integer_one_node = build_int_2 (1, 0);
4375 TREE_TYPE (integer_one_node) = integer_type_node;
4376 integer_two_node = build_int_2 (2, 0);
4377 TREE_TYPE (integer_two_node) = integer_type_node;
4378 integer_three_node = build_int_2 (3, 0);
4379 TREE_TYPE (integer_three_node) = integer_type_node;
4381 bool_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4382 TREE_SET_CODE (bool_type_node, BOOLEAN_TYPE);
4383 record_builtin_type (RID_BOOL, "bool", bool_type_node);
4384 false_node = build_int_2 (0, 0);
4385 TREE_TYPE (false_node) = bool_type_node;
4386 true_node = build_int_2 (1, 0);
4387 TREE_TYPE (true_node) = bool_type_node;
4389 /* These are needed by stor-layout.c. */
4390 size_zero_node = size_int (0);
4391 size_one_node = size_int (1);
4393 void_type_node = make_node (VOID_TYPE);
4394 record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
4395 layout_type (void_type_node); /* Uses integer_zero_node. */
4396 void_list_node = build_tree_list (NULL_TREE, void_type_node);
4397 TREE_PARMLIST (void_list_node) = 1;
4399 null_pointer_node = build_int_2 (0, 0);
4400 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4401 layout_type (TREE_TYPE (null_pointer_node));
4403 /* Used for expressions that do nothing, but are not errors. */
4404 void_zero_node = build_int_2 (0, 0);
4405 TREE_TYPE (void_zero_node) = void_type_node;
4407 string_type_node = build_pointer_type (char_type_node);
4408 const_string_type_node =
4409 build_pointer_type (build_type_variant (char_type_node, 1, 0));
4410 record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
4412 /* Make a type to be the domain of a few array types
4413 whose domains don't really matter.
4414 200 is small enough that it always fits in size_t
4415 and large enough that it can hold most function names for the
4416 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4417 array_domain_type = build_index_type (build_int_2 (200, 0));
4419 /* make a type for arrays of characters.
4420 With luck nothing will ever really depend on the length of this
4422 char_array_type_node
4423 = build_array_type (char_type_node, array_domain_type);
4424 /* Likewise for arrays of ints. */
4426 = build_array_type (integer_type_node, array_domain_type);
4428 /* This is just some anonymous class type. Nobody should ever
4429 need to look inside this envelope. */
4430 class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
4432 default_function_type
4433 = build_function_type (integer_type_node, NULL_TREE);
4434 build_pointer_type (default_function_type);
4436 ptr_type_node = build_pointer_type (void_type_node);
4437 const_ptr_type_node =
4438 build_pointer_type (build_type_variant (void_type_node, 1, 0));
4439 record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
4440 endlink = void_list_node;
4441 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
4442 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
4443 ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
4446 = build_function_type (double_type_node, double_endlink);
4448 double_ftype_double_double
4449 = build_function_type (double_type_node,
4450 tree_cons (NULL_TREE, double_type_node,
4454 = build_function_type (integer_type_node, int_endlink);
4457 = build_function_type (long_integer_type_node,
4458 tree_cons (NULL_TREE, long_integer_type_node,
4461 void_ftype_ptr_ptr_int
4462 = build_function_type (void_type_node,
4463 tree_cons (NULL_TREE, ptr_type_node,
4464 tree_cons (NULL_TREE, ptr_type_node,
4467 int_ftype_cptr_cptr_sizet
4468 = build_function_type (integer_type_node,
4469 tree_cons (NULL_TREE, const_ptr_type_node,
4470 tree_cons (NULL_TREE, const_ptr_type_node,
4471 tree_cons (NULL_TREE,
4475 void_ftype_ptr_int_int
4476 = build_function_type (void_type_node,
4477 tree_cons (NULL_TREE, ptr_type_node,
4478 tree_cons (NULL_TREE, integer_type_node,
4481 string_ftype_ptr_ptr /* strcpy prototype */
4482 = build_function_type (string_type_node,
4483 tree_cons (NULL_TREE, string_type_node,
4484 tree_cons (NULL_TREE,
4485 const_string_type_node,
4490 strncpy_ftype /* strncpy prototype */
4491 = build_function_type (string_type_node,
4492 tree_cons (NULL_TREE, string_type_node,
4493 tree_cons (NULL_TREE, const_string_type_node,
4494 tree_cons (NULL_TREE,
4499 int_ftype_string_string /* strcmp prototype */
4500 = build_function_type (integer_type_node,
4501 tree_cons (NULL_TREE, const_string_type_node,
4502 tree_cons (NULL_TREE,
4503 const_string_type_node,
4506 sizet_ftype_string /* strlen prototype */
4507 = build_function_type (sizetype,
4508 tree_cons (NULL_TREE, const_string_type_node,
4511 traditional_ptr_type_node
4512 = (flag_traditional ? string_type_node : ptr_type_node);
4514 memcpy_ftype /* memcpy prototype */
4515 = build_function_type (traditional_ptr_type_node,
4516 tree_cons (NULL_TREE, ptr_type_node,
4517 tree_cons (NULL_TREE, const_ptr_type_node,
4518 tree_cons (NULL_TREE,
4522 if (flag_huge_objects)
4523 delta_type_node = long_integer_type_node;
4525 delta_type_node = short_integer_type_node;
4527 builtin_function ("__builtin_constant_p", int_ftype_int,
4528 BUILT_IN_CONSTANT_P, NULL_PTR);
4530 builtin_return_address_fndecl =
4531 builtin_function ("__builtin_return_address",
4532 build_function_type (ptr_type_node,
4533 tree_cons (NULL_TREE,
4536 BUILT_IN_RETURN_ADDRESS, NULL_PTR);
4538 builtin_function ("__builtin_frame_address",
4539 build_function_type (ptr_type_node,
4540 tree_cons (NULL_TREE,
4543 BUILT_IN_FRAME_ADDRESS, NULL_PTR);
4546 builtin_function ("__builtin_alloca",
4547 build_function_type (ptr_type_node,
4548 tree_cons (NULL_TREE,
4551 BUILT_IN_ALLOCA, "alloca");
4552 /* Define alloca, ffs as builtins.
4553 Declare _exit just to mark it as volatile. */
4554 if (! flag_no_builtin && !flag_no_nonansi_builtin)
4556 temp = builtin_function ("alloca",
4557 build_function_type (ptr_type_node,
4558 tree_cons (NULL_TREE,
4561 BUILT_IN_ALLOCA, NULL_PTR);
4562 /* Suppress error if redefined as a non-function. */
4563 DECL_BUILT_IN_NONANSI (temp) = 1;
4564 temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
4565 /* Suppress error if redefined as a non-function. */
4566 DECL_BUILT_IN_NONANSI (temp) = 1;
4567 temp = builtin_function ("_exit", build_function_type (void_type_node,
4569 NOT_BUILT_IN, NULL_PTR);
4570 TREE_THIS_VOLATILE (temp) = 1;
4571 TREE_SIDE_EFFECTS (temp) = 1;
4572 /* Suppress error if redefined as a non-function. */
4573 DECL_BUILT_IN_NONANSI (temp) = 1;
4576 builtin_function ("__builtin_abs", int_ftype_int,
4577 BUILT_IN_ABS, NULL_PTR);
4578 builtin_function ("__builtin_fabs", double_ftype_double,
4579 BUILT_IN_FABS, NULL_PTR);
4580 builtin_function ("__builtin_labs", long_ftype_long,
4581 BUILT_IN_LABS, NULL_PTR);
4582 builtin_function ("__builtin_ffs", int_ftype_int,
4583 BUILT_IN_FFS, NULL_PTR);
4584 builtin_function ("__builtin_fsqrt", double_ftype_double,
4585 BUILT_IN_FSQRT, NULL_PTR);
4586 builtin_function ("__builtin_sin", double_ftype_double,
4587 BUILT_IN_SIN, "sin");
4588 builtin_function ("__builtin_cos", double_ftype_double,
4589 BUILT_IN_COS, "cos");
4590 builtin_function ("__builtin_saveregs",
4591 build_function_type (ptr_type_node, NULL_TREE),
4592 BUILT_IN_SAVEREGS, NULL_PTR);
4593 /* EXPAND_BUILTIN_VARARGS is obsolete. */
4595 builtin_function ("__builtin_varargs",
4596 build_function_type (ptr_type_node,
4597 tree_cons (NULL_TREE,
4600 BUILT_IN_VARARGS, NULL_PTR);
4602 builtin_function ("__builtin_classify_type", default_function_type,
4603 BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
4604 builtin_function ("__builtin_next_arg",
4605 build_function_type (ptr_type_node, NULL_TREE),
4606 BUILT_IN_NEXT_ARG, NULL_PTR);
4607 builtin_function ("__builtin_args_info",
4608 build_function_type (integer_type_node,
4609 tree_cons (NULL_TREE,
4612 BUILT_IN_ARGS_INFO, NULL_PTR);
4614 /* Untyped call and return. */
4615 builtin_function ("__builtin_apply_args",
4616 build_function_type (ptr_type_node, NULL_TREE),
4617 BUILT_IN_APPLY_ARGS, NULL_PTR);
4619 temp = tree_cons (NULL_TREE,
4620 build_pointer_type (build_function_type (void_type_node,
4622 tree_cons (NULL_TREE,
4624 tree_cons (NULL_TREE,
4627 builtin_function ("__builtin_apply",
4628 build_function_type (ptr_type_node, temp),
4629 BUILT_IN_APPLY, NULL_PTR);
4630 builtin_function ("__builtin_return",
4631 build_function_type (void_type_node,
4632 tree_cons (NULL_TREE,
4635 BUILT_IN_RETURN, NULL_PTR);
4637 /* Currently under experimentation. */
4638 builtin_function ("__builtin_memcpy", memcpy_ftype,
4639 BUILT_IN_MEMCPY, "memcpy");
4640 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
4641 BUILT_IN_MEMCMP, "memcmp");
4642 builtin_function ("__builtin_strcmp", int_ftype_string_string,
4643 BUILT_IN_STRCMP, "strcmp");
4644 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
4645 BUILT_IN_STRCPY, "strcpy");
4648 builtin_function ("__builtin_strncpy", strncpy_ftype,
4649 BUILT_IN_STRNCPY, "strncpy");
4651 builtin_function ("__builtin_strlen", sizet_ftype_string,
4652 BUILT_IN_STRLEN, "strlen");
4654 if (!flag_no_builtin)
4656 #if 0 /* These do not work well with libg++. */
4657 builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
4658 builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
4659 builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
4661 builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
4662 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
4664 builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR);
4665 builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
4669 builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR);
4671 builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR);
4672 builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
4673 builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
4675 /* Declare these functions volatile
4676 to avoid spurious "control drops through" warnings. */
4677 temp = builtin_function ("abort",
4678 build_function_type (void_type_node, endlink),
4679 NOT_BUILT_IN, NULL_PTR);
4680 TREE_THIS_VOLATILE (temp) = 1;
4681 TREE_SIDE_EFFECTS (temp) = 1;
4682 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
4684 DECL_BUILT_IN_NONANSI (temp) = 1;
4685 temp = builtin_function ("exit", build_function_type (void_type_node,
4687 NOT_BUILT_IN, NULL_PTR);
4688 TREE_THIS_VOLATILE (temp) = 1;
4689 TREE_SIDE_EFFECTS (temp) = 1;
4690 DECL_BUILT_IN_NONANSI (temp) = 1;
4694 /* Support for these has not been written in either expand_builtin
4695 or build_function_call. */
4696 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
4697 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
4698 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
4700 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
4701 builtin_function ("__builtin_fmod", double_ftype_double_double,
4703 builtin_function ("__builtin_frem", double_ftype_double_double,
4705 builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET,
4707 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
4709 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
4713 /* C++ extensions */
4715 unknown_type_node = make_node (UNKNOWN_TYPE);
4716 #if 0 /* not yet, should get fixed properly later */
4717 pushdecl (make_type_decl (get_identifier ("unknown type"),
4718 unknown_type_node));
4720 decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
4721 unknown_type_node));
4722 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
4723 DECL_IGNORED_P (decl) = 1;
4724 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
4726 TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
4727 TYPE_ALIGN (unknown_type_node) = 1;
4728 TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
4729 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
4730 TREE_TYPE (unknown_type_node) = unknown_type_node;
4731 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
4732 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
4733 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
4735 /* This is for handling opaque types in signatures. */
4736 opaque_type_node = copy_node (ptr_type_node);
4737 TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
4738 record_builtin_type (RID_MAX, 0, opaque_type_node);
4740 /* This is special for C++ so functions can be overloaded. */
4742 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
4743 wchar_type_size = TYPE_PRECISION (wchar_type_node);
4744 signed_wchar_type_node = make_signed_type (wchar_type_size);
4745 unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
4747 = TREE_UNSIGNED (wchar_type_node)
4748 ? unsigned_wchar_type_node
4749 : signed_wchar_type_node;
4750 record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
4752 /* Artificial declaration of wchar_t -- can be bashed */
4753 wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"),
4755 pushdecl (wchar_decl_node);
4757 /* This is for wide string constants. */
4758 wchar_array_type_node
4759 = build_array_type (wchar_type_node, array_domain_type);
4761 /* This is a hack that should go away when we deliver the
4765 builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
4766 pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
4769 if (flag_vtable_thunks)
4771 /* Make sure we get a unique function type, so we can give
4772 its pointer type a name. (This wins for gdb.) */
4773 tree vfunc_type = make_node (FUNCTION_TYPE);
4774 TREE_TYPE (vfunc_type) = integer_type_node;
4775 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
4776 layout_type (vfunc_type);
4778 vtable_entry_type = build_pointer_type (vfunc_type);
4782 vtable_entry_type = make_lang_type (RECORD_TYPE);
4783 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
4785 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
4787 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
4789 finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
4792 /* Make this part of an invisible union. */
4793 fields[3] = copy_node (fields[2]);
4794 TREE_TYPE (fields[3]) = delta_type_node;
4795 DECL_NAME (fields[3]) = delta2_identifier;
4796 DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
4797 DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
4798 TREE_UNSIGNED (fields[3]) = 0;
4799 TREE_CHAIN (fields[2]) = fields[3];
4800 vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
4802 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
4805 = build_array_type (vtable_entry_type, NULL_TREE);
4806 layout_type (vtbl_type_node);
4807 vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0);
4808 record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
4810 /* Simplify life by making a "sigtable_entry_type". Give its
4811 fields names so that the debugger can use them. */
4813 if (flag_handle_signatures)
4815 sigtable_entry_type = make_lang_type (RECORD_TYPE);
4816 fields[0] = build_lang_field_decl (FIELD_DECL,
4817 get_identifier (SIGTABLE_CODE_NAME),
4818 short_integer_type_node);
4819 fields[1] = build_lang_field_decl (FIELD_DECL,
4820 get_identifier (SIGTABLE_OFFSET_NAME),
4821 short_integer_type_node);
4822 fields[2] = build_lang_field_decl (FIELD_DECL,
4823 get_identifier (SIGTABLE_PFN_NAME),
4825 finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 2,
4827 sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
4828 record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
4834 /* Must build __t_desc type. Currently, type descriptors look like this:
4841 struct __t_desc *points_to;
4842 int ivars_count, meths_count;
4843 struct __i_desc *ivars[];
4844 struct __m_desc *meths[];
4845 struct __t_desc *parents[];
4846 struct __t_desc *vbases[];
4850 ...as per Linton's paper. */
4852 __t_desc_type_node = make_lang_type (RECORD_TYPE);
4853 __i_desc_type_node = make_lang_type (RECORD_TYPE);
4854 __m_desc_type_node = make_lang_type (RECORD_TYPE);
4855 __t_desc_array_type =
4856 build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE);
4857 __i_desc_array_type =
4858 build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE);
4859 __m_desc_array_type =
4860 build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE);
4862 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4864 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
4865 unsigned_type_node);
4866 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
4867 unsigned_type_node);
4868 fields[3] = build_lang_field_decl (FIELD_DECL,
4869 get_identifier ("points_to"),
4870 TYPE_POINTER_TO (__t_desc_type_node));
4871 fields[4] = build_lang_field_decl (FIELD_DECL,
4872 get_identifier ("ivars_count"),
4874 fields[5] = build_lang_field_decl (FIELD_DECL,
4875 get_identifier ("meths_count"),
4877 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
4878 build_pointer_type (__i_desc_array_type));
4879 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
4880 build_pointer_type (__m_desc_array_type));
4881 fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
4882 build_pointer_type (__t_desc_array_type));
4883 fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
4884 build_pointer_type (__t_desc_array_type));
4885 fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
4886 build_pointer_type (integer_type_node));
4887 finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
4889 /* ivar descriptors look like this:
4895 struct __t_desc *type;
4899 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4901 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
4903 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
4904 TYPE_POINTER_TO (__t_desc_type_node));
4905 finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2,
4908 /* method descriptors look like this:
4914 struct __t_desc *vcontext;
4915 struct __t_desc *return_type;
4918 short required_parms;
4919 struct __t_desc *parm_types[];
4923 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4925 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
4927 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
4928 TYPE_POINTER_TO (__t_desc_type_node));
4929 fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
4930 TYPE_POINTER_TO (__t_desc_type_node));
4931 fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
4932 build_pointer_type (default_function_type));
4933 fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
4934 short_integer_type_node);
4935 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
4936 short_integer_type_node);
4937 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
4938 build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE)));
4939 finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7,
4945 int i = builtin_type_tdescs_len;
4948 tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
4949 TREE_ASM_WRITTEN (tdesc) = 1;
4950 TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
4953 #endif /*flag_rtti*/
4956 current_lang_name = lang_name_cplusplus;
4958 auto_function (ansi_opname[(int) NEW_EXPR],
4959 build_function_type (ptr_type_node,
4960 tree_cons (NULL_TREE, sizetype,
4963 auto_function (ansi_opname[(int) VEC_NEW_EXPR],
4964 build_function_type (ptr_type_node,
4965 tree_cons (NULL_TREE, sizetype,
4968 auto_function (ansi_opname[(int) DELETE_EXPR],
4969 build_function_type (void_type_node,
4970 tree_cons (NULL_TREE, ptr_type_node,
4973 auto_function (ansi_opname[(int) VEC_DELETE_EXPR],
4974 build_function_type (void_type_node,
4975 tree_cons (NULL_TREE, ptr_type_node,
4980 = define_function ("__pure_virtual",
4981 build_function_type (void_type_node, void_list_node),
4982 NOT_BUILT_IN, 0, 0);
4984 /* Perform other language dependent initializations. */
4985 init_class_processing ();
4986 init_init_processing ();
4987 init_search_processing ();
4989 if (flag_handle_exceptions)
4990 init_exception_processing ();
4992 init_gc_processing ();
4995 flag_inline_functions = 0;
4997 /* This causes uneccessary emission of inline functions. */
4998 flag_default_inline = 0;
5004 /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
5005 declare_function_name ();
5007 /* Prepare to check format strings against argument lists. */
5008 init_function_format_info ();
5011 /* initialize type descriptor type node of various rtti type. */
5018 tdecl = lookup_name (get_identifier ("type_info"), 0);
5019 if (tdecl == NULL_TREE)
5021 __t_desc_type_node = TREE_TYPE(tdecl);
5022 __tp_desc_type_node = build_pointer_type (__t_desc_type_node);
5025 tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0);
5026 if (tdecl == NULL_TREE)
5028 __baselist_desc_type_node = TREE_TYPE (tdecl);
5031 tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0);
5032 if (tdecl == NULL_TREE)
5034 __bltn_desc_type_node = TREE_TYPE (tdecl);
5036 tdecl = lookup_name (get_identifier ("__user_type_info"), 0);
5037 if (tdecl == NULL_TREE)
5039 __user_desc_type_node = TREE_TYPE (tdecl);
5041 tdecl = lookup_name (get_identifier ("__class_type_info"), 0);
5042 if (tdecl == NULL_TREE)
5044 __class_desc_type_node = TREE_TYPE (tdecl);
5046 tdecl = lookup_field (__class_desc_type_node,
5047 get_identifier ("access_mode"), 0, 0);
5048 if (tdecl == NULL_TREE)
5050 __access_mode_type_node = TREE_TYPE (tdecl);
5052 tdecl = lookup_name (get_identifier ("__attr_type_info"), 0);
5053 if (tdecl == NULL_TREE)
5055 __attr_desc_type_node = TREE_TYPE (tdecl);
5057 tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0);
5058 if (tdecl == NULL_TREE)
5060 __ptr_desc_type_node = TREE_TYPE (tdecl);
5062 tdecl = lookup_name (get_identifier ("__func_type_info"), 0);
5063 if (tdecl == NULL_TREE)
5065 __func_desc_type_node = TREE_TYPE (tdecl);
5067 tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0);
5068 if (tdecl == NULL_TREE)
5070 __ptmf_desc_type_node = TREE_TYPE (tdecl);
5072 tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0);
5073 if (tdecl == NULL_TREE)
5075 __ptmd_desc_type_node = TREE_TYPE (tdecl);
5079 /* Make a definition for a builtin function named NAME and whose data type
5080 is TYPE. TYPE should be a function type with argument types.
5081 FUNCTION_CODE tells later passes how to compile calls to this function.
5082 See tree.h for its possible values.
5084 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
5085 the name to be called if we can't opencode the function. */
5088 define_function (name, type, function_code, pfn, library_name)
5091 enum built_in_function function_code;
5095 tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
5096 DECL_EXTERNAL (decl) = 1;
5097 TREE_PUBLIC (decl) = 1;
5098 DECL_INTERFACE_KNOWN (decl) = 1;
5100 /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
5101 we cannot change DECL_ASSEMBLER_NAME until we have installed this
5102 function in the namespace. */
5103 if (pfn) (*pfn) (decl);
5105 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
5106 make_function_rtl (decl);
5107 if (function_code != NOT_BUILT_IN)
5109 DECL_BUILT_IN (decl) = 1;
5110 DECL_FUNCTION_CODE (decl) = function_code;
5115 /* Called when a declaration is seen that contains no names to declare.
5116 If its type is a reference to a structure, union or enum inherited
5117 from a containing scope, shadow that tag name for the current scope
5118 with a forward reference.
5119 If its type defines a new named structure or union
5120 or defines an enum, it is valid but we need not do anything here.
5121 Otherwise, it is an error.
5123 C++: may have to grok the declspecs to learn about static,
5124 complain for anonymous unions. */
5127 shadow_tag (declspecs)
5131 tree ob_modifier = NULL_TREE;
5133 register enum tree_code code, ok_code = ERROR_MARK;
5134 register tree t = NULL_TREE;
5136 for (link = declspecs; link; link = TREE_CHAIN (link))
5138 register tree value = TREE_VALUE (link);
5140 code = TREE_CODE (value);
5141 if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
5143 my_friendly_assert (TYPE_NAME (value) != NULL_TREE, 261);
5145 if (code == ENUMERAL_TYPE && TYPE_SIZE (value) == 0)
5146 cp_error ("forward declaration of `%#T'", value);
5152 else if (value == ridpointers[(int) RID_STATIC]
5153 || value == ridpointers[(int) RID_EXTERN]
5154 || value == ridpointers[(int) RID_AUTO]
5155 || value == ridpointers[(int) RID_REGISTER])
5156 ob_modifier = value;
5159 /* This is where the variables in an anonymous union are
5160 declared. An anonymous union declaration looks like:
5162 because there is no declarator after the union, the parser
5163 sends that declaration here. */
5164 if (ok_code == UNION_TYPE
5166 && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
5167 && ANON_AGGRNAME_P (TYPE_NAME (t)))
5168 || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
5169 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
5171 /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have
5172 function members. */
5173 if (TYPE_FIELDS (t))
5175 tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0,
5177 finish_anon_union (decl);
5180 error ("anonymous union cannot have a function member");
5184 /* Anonymous unions are objects, that's why we only check for
5185 inappropriate specifiers in this branch. */
5187 cp_error ("`%D' can only be specified for objects and functions",
5191 pedwarn ("abstract declarator used as declaration");
5192 else if (found_tag > 1)
5193 pedwarn ("multiple types in one declaration");
5197 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
5200 groktypename (typename)
5203 if (TREE_CODE (typename) != TREE_LIST)
5205 return grokdeclarator (TREE_VALUE (typename),
5206 TREE_PURPOSE (typename),
5207 TYPENAME, 0, NULL_TREE);
5210 /* Decode a declarator in an ordinary declaration or data definition.
5211 This is called as soon as the type information and variable name
5212 have been parsed, before parsing the initializer if any.
5213 Here we create the ..._DECL node, fill in its type,
5214 and put it on the list of decls for the current context.
5215 The ..._DECL node is returned as the value.
5217 Exception: for arrays where the length is not specified,
5218 the type is left null, to be filled in by `finish_decl'.
5220 Function definitions do not come here; they go to start_function
5221 instead. However, external and forward declarations of functions
5222 do go through here. Structure field declarations are done by
5223 grokfield and not through here. */
5225 /* Set this to zero to debug not using the temporary obstack
5226 to parse initializers. */
5227 int debug_temp_inits = 1;
5230 start_decl (declarator, declspecs, initialized, raises)
5231 tree declarator, declspecs;
5236 register tree type, tem;
5238 extern int have_extern_spec;
5239 extern int used_extern_spec;
5241 int init_written = initialized;
5243 /* This should only be done once on the top most decl. */
5244 if (have_extern_spec && !used_extern_spec)
5246 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"),
5248 used_extern_spec = 1;
5251 decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises);
5252 if (decl == NULL_TREE || decl == void_type_node)
5255 type = TREE_TYPE (decl);
5257 /* Don't lose if destructors must be executed at file-level. */
5258 if (TREE_STATIC (decl)
5259 && TYPE_NEEDS_DESTRUCTOR (type)
5260 && !TREE_PERMANENT (decl))
5262 push_obstacks (&permanent_obstack, &permanent_obstack);
5263 decl = copy_node (decl);
5264 if (TREE_CODE (type) == ARRAY_TYPE)
5266 tree itype = TYPE_DOMAIN (type);
5267 if (itype && ! TREE_PERMANENT (itype))
5269 itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
5270 type = build_cplus_array_type (TREE_TYPE (type), itype);
5271 TREE_TYPE (decl) = type;
5277 /* Corresponding pop_obstacks is done in `finish_decl'. */
5278 push_obstacks_nochange ();
5281 = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
5282 ? DECL_CLASS_CONTEXT (decl)
5283 : DECL_CONTEXT (decl);
5285 if (processing_template_decl)
5288 if (TREE_CODE (decl) == FUNCTION_DECL)
5290 /* Declarator is a call_expr; extract arguments from it, since
5291 grokdeclarator didn't do it. */
5293 args = copy_to_permanent (last_function_parms);
5294 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
5296 tree t = TREE_TYPE (decl);
5298 t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
5299 if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE)
5301 t = build_pointer_type (t); /* base type of `this' */
5303 /* I suspect this is wrong. */
5304 t = build_type_variant (t, flag_this_is_variable <= 0,
5305 0); /* type of `this' */
5307 t = build_type_variant (t, 0, 0); /* type of `this' */
5309 t = build (PARM_DECL, t, this_identifier);
5310 TREE_CHAIN (t) = args;
5314 DECL_ARGUMENTS (decl) = args;
5316 d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
5317 TREE_PUBLIC (d) = TREE_PUBLIC (decl);
5318 TREE_STATIC (d) = TREE_STATIC (decl);
5319 DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl)
5320 && !(context && !DECL_THIS_EXTERN (decl)));
5321 DECL_TEMPLATE_RESULT (d) = decl;
5325 /* If this type of object needs a cleanup, and control may
5326 jump past it, make a new binding level so that it is cleaned
5327 up only when it is initialized first. */
5328 if (TYPE_NEEDS_DESTRUCTOR (type)
5329 && current_binding_level->more_cleanups_ok == 0)
5330 pushlevel_temporary (1);
5333 /* Is it valid for this decl to have an initializer at all?
5334 If not, set INITIALIZED to zero, which will indirectly
5335 tell `finish_decl' to ignore the initializer once it is parsed. */
5336 switch (TREE_CODE (decl))
5339 /* typedef foo = bar means give foo the same type as bar.
5340 We haven't parsed bar yet, so `finish_decl' will fix that up.
5341 Any other case of an initialization in a TYPE_DECL is an error. */
5342 if (pedantic || list_length (declspecs) > 1)
5344 cp_error ("typedef `%D' is initialized", decl);
5350 cp_error ("function `%#D' is initialized like a variable", decl);
5355 /* Don't allow initializations for incomplete types except for
5356 arrays which might be completed by the initialization. */
5357 if (type == error_mark_node)
5358 ; /* Don't complain again. */
5359 else if (TYPE_SIZE (type) != NULL_TREE)
5360 ; /* A complete type is ok. */
5361 else if (TREE_CODE (type) != ARRAY_TYPE)
5363 cp_error ("variable `%#D' has initializer but incomplete type",
5367 else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE)
5369 cp_error ("elements of array `%#D' have incomplete type", decl);
5375 && TREE_CODE (decl) != TYPE_DECL
5376 && TREE_CODE (decl) != TEMPLATE_DECL
5377 && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
5379 if (TYPE_SIZE (type) == NULL_TREE)
5381 cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
5383 /* Change the type so that assemble_variable will give
5384 DECL an rtl we can live with: (mem (const_int 0)). */
5385 TREE_TYPE (decl) = error_mark_node;
5386 type = error_mark_node;
5390 /* If any base type in the hierarchy of TYPE needs a constructor,
5391 then we set initialized to 1. This way any nodes which are
5392 created for the purposes of initializing this aggregate
5393 will live as long as it does. This is necessary for global
5394 aggregates which do not have their initializers processed until
5395 the end of the file. */
5396 initialized = TYPE_NEEDS_CONSTRUCTING (type);
5402 if (current_binding_level != global_binding_level
5403 && DECL_EXTERNAL (decl))
5404 cp_warning ("declaration of `%#D' has `extern' and is initialized",
5406 DECL_EXTERNAL (decl) = 0;
5407 if (current_binding_level == global_binding_level)
5408 TREE_STATIC (decl) = 1;
5410 /* Tell `pushdecl' this is an initialized decl
5411 even though we don't yet have the initializer expression.
5412 Also tell `finish_decl' it may store the real initializer. */
5413 DECL_INITIAL (decl) = error_mark_node;
5416 if (context && TYPE_SIZE (context) != NULL_TREE)
5418 if (TREE_CODE (decl) == VAR_DECL)
5420 tree field = lookup_field (context, DECL_NAME (decl), 0, 0);
5421 if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
5422 cp_error ("`%#D' is not a static member of `%#T'", decl, context);
5423 else if (duplicate_decls (decl, field))
5427 /* If it was not explicitly declared `extern',
5428 revoke any previous claims of DECL_EXTERNAL. */
5429 if (DECL_THIS_EXTERN (decl) == 0)
5430 DECL_EXTERNAL (decl) = 0;
5431 if (DECL_LANG_SPECIFIC (decl))
5432 DECL_IN_AGGR_P (decl) = 0;
5433 pushclass (context, 2);
5436 /* Add this decl to the current binding level, but not if it
5437 comes from another scope, e.g. a static member variable.
5438 TEM may equal DECL or it may be a previous decl of the same name. */
5440 if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
5441 || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
5442 || TREE_CODE (type) == LANG_TYPE)
5445 tem = pushdecl (decl);
5447 /* Tell the back-end to use or not use .common as appropriate. If we say
5448 -fconserve-space, we want this to save space, at the expense of wrong
5449 semantics. If we say -fno-conserve-space, we want this to produce
5450 errors about redefs; to do this we force variables into the data
5451 segment. Common storage is okay for non-public uninitialized data;
5452 the linker can't match it with storage from other files, and we may
5453 save some disk space. */
5454 DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem);
5457 /* We don't do this yet for GNU C++. */
5458 /* For a local variable, define the RTL now. */
5459 if (current_binding_level != global_binding_level
5460 /* But not if this is a duplicate decl
5461 and we preserved the rtl from the previous one
5462 (which may or may not happen). */
5463 && DECL_RTL (tem) == NULL_RTX)
5465 if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
5467 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
5468 && DECL_INITIAL (tem) != NULL_TREE)
5473 if (TREE_CODE (decl) == TEMPLATE_DECL)
5475 tree result = DECL_TEMPLATE_RESULT (decl);
5476 if (DECL_CONTEXT (result) != NULL_TREE)
5479 type = DECL_CONTEXT (result);
5481 if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE)
5483 cp_error ("declaration of `%D' in non-template type `%T'",
5488 if (TREE_CODE (result) == FUNCTION_DECL)
5490 else if (TREE_CODE (result) == VAR_DECL)
5493 tree tmpl = UPT_TEMPLATE (type);
5495 fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
5496 print_node_brief (stderr, "", DECL_NAME (tem), 0);
5497 fprintf (stderr, " to class %s\n",
5498 IDENTIFIER_POINTER (DECL_NAME (tmpl)));
5499 DECL_TEMPLATE_MEMBERS (tmpl)
5500 = perm_tree_cons (DECL_NAME (tem), tem,
5501 DECL_TEMPLATE_MEMBERS (tmpl));
5504 sorry ("static data member templates");
5509 my_friendly_abort (13);
5511 else if (TREE_CODE (result) == FUNCTION_DECL)
5512 /*tem = push_overloaded_decl (tem, 0)*/;
5513 else if (TREE_CODE (result) == VAR_DECL)
5515 cp_error ("data template `%#D' must be member of a class template",
5519 else if (TREE_CODE (result) == TYPE_DECL)
5521 cp_error ("invalid template `%#D'", result);
5525 my_friendly_abort (14);
5529 && ! (TREE_CODE (tem) == PARM_DECL
5530 || (TREE_READONLY (tem)
5531 && (TREE_CODE (tem) == VAR_DECL
5532 || TREE_CODE (tem) == FIELD_DECL))))
5534 /* When parsing and digesting the initializer,
5535 use temporary storage. Do this even if we will ignore the value. */
5536 if (current_binding_level == global_binding_level && debug_temp_inits)
5538 if (TYPE_NEEDS_CONSTRUCTING (type)
5539 || TREE_CODE (type) == REFERENCE_TYPE)
5540 /* In this case, the initializer must lay down in permanent
5541 storage, since it will be saved until `finish_file' is run. */
5544 temporary_allocation ();
5549 cadillac_start_decl (tem);
5556 make_temporary_for_reference (decl, ctor_call, init, cleanupp)
5557 tree decl, ctor_call, init;
5560 tree type = TREE_TYPE (decl);
5561 tree target_type = TREE_TYPE (type);
5566 tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
5567 if (TREE_CODE (tmp_addr) == NOP_EXPR)
5568 tmp_addr = TREE_OPERAND (tmp_addr, 0);
5569 my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146);
5570 tmp = TREE_OPERAND (tmp_addr, 0);
5574 tmp = get_temp_name (target_type,
5575 current_binding_level == global_binding_level);
5576 tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
5579 TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
5580 DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr);
5581 TREE_TYPE (DECL_INITIAL (decl)) = type;
5582 if (TYPE_NEEDS_CONSTRUCTING (target_type))
5584 if (current_binding_level == global_binding_level)
5586 /* lay this variable out now. Otherwise `output_addressed_constants'
5587 gets confused by its initializer. */
5588 make_decl_rtl (tmp, NULL_PTR, 1);
5589 static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
5593 if (ctor_call != NULL_TREE)
5596 init = build_method_call (tmp, constructor_name_full (target_type),
5597 build_tree_list (NULL_TREE, init),
5598 NULL_TREE, LOOKUP_NORMAL);
5599 DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
5600 DECL_INITIAL (decl));
5601 *cleanupp = maybe_build_cleanup (tmp);
5606 DECL_INITIAL (tmp) = init;
5607 TREE_STATIC (tmp) = current_binding_level == global_binding_level;
5608 finish_decl (tmp, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
5610 if (TREE_STATIC (tmp))
5611 preserve_initializer ();
5615 /* Handle initialization of references.
5616 These three arguments from from `finish_decl', and have the
5617 same meaning here that they do there. */
5618 /* quotes on semantics can be found in ARM 8.4.3. */
5620 grok_reference_init (decl, type, init, cleanupp)
5621 tree decl, type, init;
5626 if (init == NULL_TREE)
5628 if (DECL_LANG_SPECIFIC (decl) == 0
5629 || DECL_IN_AGGR_P (decl) == 0)
5631 cp_error ("`%D' declared as reference but not initialized", decl);
5632 if (TREE_CODE (decl) == VAR_DECL)
5633 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
5638 if (init == error_mark_node)
5641 if (TREE_CODE (type) == REFERENCE_TYPE
5642 && TREE_CODE (init) == CONSTRUCTOR)
5644 cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
5648 if (TREE_CODE (init) == TREE_LIST)
5649 init = build_compound_expr (init);
5651 if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
5652 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
5654 /* Note: default conversion is only called in very special cases. */
5655 init = default_conversion (init);
5658 tmp = convert_to_reference
5659 (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL, decl);
5661 if (tmp == error_mark_node)
5663 else if (tmp != NULL_TREE)
5665 tree subtype = TREE_TYPE (type);
5668 /* Associate the cleanup with the reference so that we
5669 don't get burned by "aggressive" cleanup policy. */
5670 if (TYPE_NEEDS_DESTRUCTOR (subtype))
5672 if (TREE_CODE (init) == WITH_CLEANUP_EXPR)
5674 *cleanupp = TREE_OPERAND (init, 2);
5675 TREE_OPERAND (init, 2) = error_mark_node;
5679 if (TREE_CODE (tmp) == ADDR_EXPR)
5680 tmp = TREE_OPERAND (tmp, 0);
5681 if (TREE_CODE (tmp) == TARGET_EXPR)
5683 *cleanupp = build_delete
5684 (TYPE_POINTER_TO (subtype),
5685 build_unary_op (ADDR_EXPR, TREE_OPERAND (tmp, 0), 0),
5686 integer_two_node, LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0);
5687 TREE_OPERAND (tmp, 2) = error_mark_node;
5692 DECL_INITIAL (decl) = save_expr (init);
5696 cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
5700 /* ?? Can this be optimized in some cases to
5701 hand back the DECL_INITIAL slot?? */
5702 if (TYPE_SIZE (TREE_TYPE (type)))
5704 init = convert_from_reference (decl);
5705 if (TREE_PERMANENT (decl))
5706 init = copy_to_permanent (init);
5707 SET_DECL_REFERENCE_SLOT (decl, init);
5710 if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
5712 expand_static_init (decl, DECL_INITIAL (decl));
5713 DECL_INITIAL (decl) = NULL_TREE;
5718 if (TREE_CODE (decl) == VAR_DECL)
5719 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
5723 /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from
5724 mucking with forces it does not comprehend (i.e. initialization with a
5725 constructor). If we are at global scope and won't go into COMMON, fill
5726 it in with a dummy CONSTRUCTOR to force the variable into .data;
5727 otherwise we can use error_mark_node. */
5730 obscure_complex_init (decl)
5733 if (current_binding_level == global_binding_level
5734 && ! DECL_COMMON (decl))
5735 DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE,
5738 DECL_INITIAL (decl) = error_mark_node;
5741 /* Finish processing of a declaration;
5742 install its line number and initial value.
5743 If the length of an array type is not known before,
5744 it must be determined now, from the initial value, or it is an error.
5746 Call `pop_obstacks' iff NEED_POP is nonzero.
5748 For C++, `finish_decl' must be fairly evasive: it must keep initializers
5749 for aggregates that have constructors alive on the permanent obstack,
5750 so that the global initializing functions can be written at the end.
5752 INIT0 holds the value of an initializer that should be allowed to escape
5755 FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0
5756 if the (init) syntax was used.
5758 For functions that take default parameters, DECL points to its
5759 "maximal" instantiation. `finish_decl' must then also declared its
5760 subsequently lower and lower forms of instantiation, checking for
5761 ambiguity as it goes. This can be sped up later. */
5764 finish_decl (decl, init, asmspec_tree, need_pop, flags)
5771 tree cleanup = NULL_TREE, ttype;
5773 int temporary = allocation_temporary_p ();
5774 char *asmspec = NULL;
5775 int was_readonly = 0;
5777 /* If this is 0, then we did not change obstacks. */
5781 error ("assignment (not initialization) in declaration");
5785 /* If a name was specified, get the string. */
5787 asmspec = TREE_STRING_POINTER (asmspec_tree);
5789 /* If the type of the thing we are declaring either has
5790 a constructor, or has a virtual function table pointer,
5791 AND its initialization was accepted by `start_decl',
5792 then we stayed on the permanent obstack through the
5793 declaration, otherwise, changed obstacks as GCC would. */
5795 type = TREE_TYPE (decl);
5797 if (type == error_mark_node)
5799 if (current_binding_level == global_binding_level && temporary)
5800 end_temporary_allocation ();
5805 was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
5807 /* Take care of TYPE_DECLs up front. */
5808 if (TREE_CODE (decl) == TYPE_DECL)
5810 if (init && DECL_INITIAL (decl))
5812 /* typedef foo = bar; store the type of bar as the type of foo. */
5813 TREE_TYPE (decl) = type = TREE_TYPE (init);
5814 DECL_INITIAL (decl) = init = NULL_TREE;
5816 if (type != error_mark_node
5817 && IS_AGGR_TYPE (type) && DECL_NAME (decl))
5819 if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
5820 cp_warning ("shadowing previous type declaration of `%#D'", decl);
5821 set_identifier_type_value (DECL_NAME (decl), type);
5822 CLASSTYPE_GOT_SEMICOLON (type) = 1;
5824 GNU_xref_decl (current_function_decl, decl);
5825 rest_of_decl_compilation (decl, NULL_PTR,
5826 DECL_CONTEXT (decl) == NULL_TREE, 0);
5829 if (TREE_CODE (decl) != FUNCTION_DECL)
5831 ttype = target_type (type);
5833 Leave this out until we can figure out why it was
5834 needed/desirable in the first place. Then put a comment
5835 here explaining why. Or just delete the code if no ill
5837 if (TYPE_NAME (ttype)
5838 && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
5839 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
5841 tree old_id = TYPE_IDENTIFIER (ttype);
5842 char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
5843 /* Need to preserve template data for UPT nodes. */
5844 tree old_template = IDENTIFIER_TEMPLATE (old_id);
5846 bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
5847 IDENTIFIER_LENGTH (old_id) + 1);
5848 old_id = get_identifier (newname);
5849 lookup_tag_reverse (ttype, old_id);
5850 TYPE_IDENTIFIER (ttype) = old_id;
5851 IDENTIFIER_TEMPLATE (old_id) = old_template;
5856 if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
5857 && TYPE_NEEDS_CONSTRUCTING (type))
5860 /* Currently, GNU C++ puts constants in text space, making them
5861 impossible to initialize. In the future, one would hope for
5862 an operating system which understood the difference between
5863 initialization and the running of a program. */
5865 TREE_READONLY (decl) = 0;
5868 if (TREE_CODE (decl) == FIELD_DECL)
5870 if (init && init != error_mark_node)
5871 my_friendly_assert (TREE_PERMANENT (init), 147);
5875 /* This must override the asm specifier which was placed
5876 by grokclassfn. Lay this out fresh. */
5877 DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
5878 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
5879 make_decl_rtl (decl, asmspec, 0);
5882 /* If `start_decl' didn't like having an initialization, ignore it now. */
5883 else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
5885 else if (DECL_EXTERNAL (decl))
5887 else if (TREE_CODE (type) == REFERENCE_TYPE
5888 || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
5890 if (TREE_STATIC (decl))
5891 make_decl_rtl (decl, NULL_PTR,
5892 current_binding_level == global_binding_level
5893 || pseudo_global_level_p ());
5894 grok_reference_init (decl, type, init, &cleanup);
5898 GNU_xref_decl (current_function_decl, decl);
5900 if (TREE_CODE (decl) == FIELD_DECL)
5902 else if (TREE_CODE (decl) == CONST_DECL)
5904 my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
5906 DECL_INITIAL (decl) = init;
5908 /* This will keep us from needing to worry about our obstacks. */
5909 my_friendly_assert (init != NULL_TREE, 149);
5914 if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
5916 if (TREE_CODE (type) == ARRAY_TYPE)
5917 init = digest_init (type, init, (tree *) 0);
5918 else if (TREE_CODE (init) == CONSTRUCTOR)
5920 if (TYPE_NEEDS_CONSTRUCTING (type))
5922 cp_error ("`%D' must be initialized by constructor, not by `{...}'",
5924 init = error_mark_node;
5927 goto dont_use_constructor;
5930 /* fix this in `build_functional_cast' instead.
5931 Here's the trigger code:
5936 ostream (int, char *);
5943 int buf_size = 1024;
5944 static char buf[buf_size];
5945 const char *debug(int i) {
5947 ostream o = ostream(buf_size, b);
5953 else if (TREE_CODE (init) == TARGET_EXPR
5954 && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR))
5956 /* User wrote something like `foo x = foo (args)' */
5957 my_friendly_assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL, 150);
5958 my_friendly_assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE, 151);
5960 /* User wrote exactly `foo x = foo (args)' */
5961 if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init))
5963 init = build (CALL_EXPR, TREE_TYPE (init),
5964 TREE_OPERAND (TREE_OPERAND (init, 1), 0),
5965 TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0);
5966 TREE_SIDE_EFFECTS (init) = 1;
5971 /* We must hide the initializer so that expand_decl
5972 won't try to do something it does not understand. */
5973 obscure_complex_init (decl);
5977 dont_use_constructor:
5978 if (TREE_CODE (init) != TREE_VEC)
5979 init = store_init_value (decl, init);
5981 /* Don't let anyone try to initialize this variable
5982 until we are ready to do so. */
5984 obscure_complex_init (decl);
5987 else if (DECL_EXTERNAL (decl))
5989 else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
5990 && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
5993 while (TREE_CODE (ctype) == ARRAY_TYPE)
5994 ctype = TREE_TYPE (ctype);
5995 if (! TYPE_NEEDS_CONSTRUCTING (ctype))
5997 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
5998 cp_error ("structure `%D' with uninitialized const members", decl);
5999 if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
6000 cp_error ("structure `%D' with uninitialized reference members",
6004 if (TREE_CODE (decl) == VAR_DECL
6005 && !DECL_INITIAL (decl)
6006 && !TYPE_NEEDS_CONSTRUCTING (type)
6007 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
6008 cp_error ("uninitialized const `%D'", decl);
6010 if (TYPE_SIZE (type) != NULL_TREE
6011 && TYPE_NEEDS_CONSTRUCTING (type))
6012 obscure_complex_init (decl);
6014 else if (TREE_CODE (decl) == VAR_DECL
6015 && TREE_CODE (type) != REFERENCE_TYPE
6016 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
6018 /* ``Unless explicitly declared extern, a const object does not have
6019 external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
6020 However, if it's `const int foo = 1; const int foo;', don't complain
6021 about the second decl, since it does have an initializer before.
6022 We deliberately don't complain about arrays, because they're
6023 supposed to be initialized by a constructor. */
6024 if (! DECL_INITIAL (decl)
6025 && TREE_CODE (type) != ARRAY_TYPE
6026 && (!pedantic || !current_class_type))
6027 cp_error ("uninitialized const `%#D'", decl);
6030 /* For top-level declaration, the initial value was read in
6031 the temporary obstack. MAXINDEX, rtl, etc. to be made below
6032 must go in the permanent obstack; but don't discard the
6033 temporary data yet. */
6035 if (current_binding_level == global_binding_level && temporary)
6036 end_temporary_allocation ();
6038 /* Deduce size of array from initialization, if not already known. */
6040 if (TREE_CODE (type) == ARRAY_TYPE
6041 && TYPE_DOMAIN (type) == NULL_TREE
6042 && TREE_CODE (decl) != TYPE_DECL)
6045 = (TREE_STATIC (decl)
6046 /* Even if pedantic, an external linkage array
6047 may have incomplete type at first. */
6048 ? pedantic && ! DECL_EXTERNAL (decl)
6049 : !DECL_EXTERNAL (decl));
6050 tree initializer = init ? init : DECL_INITIAL (decl);
6051 int failure = complete_array_type (type, initializer, do_default);
6054 cp_error ("initializer fails to determine size of `%D'", decl);
6059 cp_error ("array size missing in `%D'", decl);
6060 /* If a `static' var's size isn't known, make it extern as
6061 well as static, so it does not get allocated. If it's not
6062 `static', then don't mark it extern; finish_incomplete_decl
6063 will give it a default size and it will get allocated. */
6064 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
6065 DECL_EXTERNAL (decl) = 1;
6068 if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
6069 && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6071 cp_error ("zero-size array `%D'", decl);
6073 layout_decl (decl, 0);
6076 if (TREE_CODE (decl) == VAR_DECL)
6078 if (DECL_SIZE (decl) == NULL_TREE
6079 && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
6080 layout_decl (decl, 0);
6082 if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
6084 /* A static variable with an incomplete type:
6085 that is an error if it is initialized.
6086 Otherwise, let it through, but if it is not `extern'
6087 then it may cause an error message later. */
6088 if (DECL_INITIAL (decl) != NULL_TREE)
6089 cp_error ("storage size of `%D' isn't known", decl);
6092 else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
6094 /* An automatic variable with an incomplete type: that is an error.
6095 Don't talk about array types here, since we took care of that
6096 message in grokdeclarator. */
6097 cp_error ("storage size of `%D' isn't known", decl);
6098 TREE_TYPE (decl) = error_mark_node;
6100 else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
6101 /* Let debugger know it should output info for this type. */
6102 note_debug_info_needed (ttype);
6104 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
6105 && DECL_SIZE (decl) != NULL_TREE
6106 && ! TREE_CONSTANT (DECL_SIZE (decl)))
6108 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
6109 constant_expression_warning (DECL_SIZE (decl));
6111 cp_error ("storage size of `%D' isn't constant", decl);
6114 if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
6116 int yes = suspend_momentary ();
6118 /* If INIT comes from a functional cast, use the cleanup
6119 we built for that. Otherwise, make our own cleanup. */
6120 if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
6121 && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
6123 cleanup = TREE_OPERAND (init, 2);
6124 init = TREE_OPERAND (init, 0);
6125 current_binding_level->have_cleanups = 1;
6128 cleanup = maybe_build_cleanup (decl);
6129 resume_momentary (yes);
6132 /* PARM_DECLs get cleanups, too. */
6133 else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
6136 end_temporary_allocation ();
6137 cleanup = maybe_build_cleanup (decl);
6139 resume_temporary_allocation ();
6142 /* Output the assembler code and/or RTL code for variables and functions,
6143 unless the type is an undefined structure or union.
6144 If not, it will get done when the type is completed. */
6146 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
6147 || TREE_CODE (decl) == RESULT_DECL)
6149 /* ??? FIXME: What about nested classes? */
6150 int toplev = (current_binding_level == global_binding_level
6151 || pseudo_global_level_p ());
6153 = ((flag_traditional
6154 || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
6155 && allocation_temporary_p ());
6158 end_temporary_allocation ();
6160 if (TREE_CODE (decl) == VAR_DECL
6161 && current_binding_level != global_binding_level
6162 && ! TREE_STATIC (decl)
6163 && type_needs_gc_entry (type))
6164 DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
6166 if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
6167 make_decl_rtl (decl, NULL_PTR, toplev);
6168 else if (TREE_CODE (decl) == VAR_DECL
6169 && TREE_READONLY (decl)
6170 && DECL_INITIAL (decl) != NULL_TREE
6171 && DECL_INITIAL (decl) != error_mark_node
6172 && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
6174 DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
6177 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
6180 && TREE_STATIC (decl)
6181 && ! TREE_SIDE_EFFECTS (decl)
6182 && ! TREE_PUBLIC (decl)
6183 && ! DECL_EXTERNAL (decl)
6184 && ! TYPE_NEEDS_DESTRUCTOR (type)
6185 && DECL_MODE (decl) != BLKmode)
6187 /* If this variable is really a constant, then fill its DECL_RTL
6188 slot with something which won't take up storage.
6189 If something later should take its address, we can always give
6190 it legitimate RTL at that time. */
6191 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
6192 store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
6193 TREE_ASM_WRITTEN (decl) = 1;
6195 else if (toplev && ! TREE_PUBLIC (decl))
6197 /* If this is a static const, change its apparent linkage
6198 if it belongs to a #pragma interface. */
6199 if (!interface_unknown)
6201 TREE_PUBLIC (decl) = 1;
6202 DECL_EXTERNAL (decl) = interface_only;
6204 make_decl_rtl (decl, asmspec, toplev);
6207 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6209 else if (TREE_CODE (decl) == VAR_DECL
6210 && DECL_LANG_SPECIFIC (decl)
6211 && DECL_IN_AGGR_P (decl))
6213 if (TREE_STATIC (decl))
6215 if (init == NULL_TREE
6216 #ifdef DEFAULT_STATIC_DEFS
6217 /* If this code is dead, then users must
6218 explicitly declare static member variables
6219 outside the class def'n as well. */
6220 && TYPE_NEEDS_CONSTRUCTING (type)
6224 DECL_EXTERNAL (decl) = 1;
6225 make_decl_rtl (decl, asmspec, 1);
6228 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6231 /* Just a constant field. Should not need any rtl. */
6235 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6238 resume_temporary_allocation ();
6240 if (type != error_mark_node
6241 && TYPE_LANG_SPECIFIC (type)
6242 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
6243 abstract_virtuals_error (decl, type);
6244 else if ((TREE_CODE (type) == FUNCTION_TYPE
6245 || TREE_CODE (type) == METHOD_TYPE)
6246 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6247 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
6248 abstract_virtuals_error (decl, TREE_TYPE (type));
6250 if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
6251 signature_error (decl, type);
6252 else if ((TREE_CODE (type) == FUNCTION_TYPE
6253 || TREE_CODE (type) == METHOD_TYPE)
6254 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6255 && IS_SIGNATURE (TREE_TYPE (type)))
6256 signature_error (decl, TREE_TYPE (type));
6258 if (TREE_CODE (decl) == FUNCTION_DECL)
6261 /* C++: Handle overloaded functions with default parameters. */
6262 if (DECL_OVERLOADED (decl))
6264 tree parmtypes = TYPE_ARG_TYPES (type);
6265 tree prev = NULL_TREE;
6266 tree original_name = DECL_NAME (decl);
6267 struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl);
6268 /* All variants will share an uncollectible lang_decl. */
6269 copy_decl_lang_specific (decl);
6271 while (parmtypes && parmtypes != void_list_node)
6273 /* The default value for the parameter in parmtypes is
6274 stored in the TREE_PURPOSE of the TREE_LIST. */
6275 if (TREE_PURPOSE (parmtypes))
6277 tree fnname, fndecl;
6280 argp = prev ? & TREE_CHAIN (prev)
6281 : & TYPE_ARG_TYPES (type);
6284 fnname = build_decl_overload (original_name,
6285 TYPE_ARG_TYPES (type), 0);
6287 fndecl = build_decl (FUNCTION_DECL, fnname, type);
6288 DECL_EXTERNAL (fndecl) = DECL_EXTERNAL (decl);
6289 TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl);
6290 DECL_INLINE (fndecl) = DECL_INLINE (decl);
6291 /* Keep G++ from thinking this function is unused.
6292 It is only used to speed up search in name space. */
6293 TREE_USED (fndecl) = 1;
6294 TREE_ASM_WRITTEN (fndecl) = 1;
6295 DECL_INITIAL (fndecl) = NULL_TREE;
6296 DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl);
6297 fndecl = pushdecl (fndecl);
6298 DECL_INITIAL (fndecl) = error_mark_node;
6299 DECL_RTL (fndecl) = DECL_RTL (decl);
6302 parmtypes = TREE_CHAIN (parmtypes);
6304 DECL_LANG_SPECIFIC (decl) = tmp_lang_decl;
6308 else if (DECL_EXTERNAL (decl))
6310 else if (TREE_STATIC (decl) && type != error_mark_node)
6312 /* Cleanups for static variables are handled by `finish_file'. */
6313 if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE)
6314 expand_static_init (decl, init);
6315 else if (TYPE_NEEDS_DESTRUCTOR (type))
6316 static_aggregates = perm_tree_cons (NULL_TREE, decl,
6319 /* Make entry in appropriate vector. */
6320 if (flag_gc && type_needs_gc_entry (type))
6321 build_static_gc_entry (decl, type);
6325 tree old_cleanups = cleanups_this_call;
6326 /* This is a declared decl which must live until the
6327 end of the binding contour. It may need a cleanup. */
6329 /* Recompute the RTL of a local array now
6330 if it used to be an incomplete type. */
6331 if (was_incomplete && ! TREE_STATIC (decl))
6333 /* If we used it already as memory, it must stay in memory. */
6334 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
6335 /* If it's still incomplete now, no init will save it. */
6336 if (DECL_SIZE (decl) == NULL_TREE)
6337 DECL_INITIAL (decl) = NULL_TREE;
6340 else if (! TREE_ASM_WRITTEN (decl)
6341 && (TYPE_SIZE (type) != NULL_TREE
6342 || TREE_CODE (type) == ARRAY_TYPE))
6344 /* Do this here, because we did not expand this decl's
6345 rtl in start_decl. */
6346 if (DECL_RTL (decl) == NULL_RTX)
6350 /* XXX: Why don't we use decl here? */
6351 /* Ans: Because it was already expanded? */
6352 if (! expand_decl_cleanup (NULL_TREE, cleanup))
6353 cp_error ("parser lost in parsing declaration of `%D'",
6355 /* Cleanup used up here. */
6356 cleanup = NULL_TREE;
6360 if (DECL_SIZE (decl) && type != error_mark_node)
6362 /* Compute and store the initial value. */
6363 expand_decl_init (decl);
6365 if (init || TYPE_NEEDS_CONSTRUCTING (type))
6367 emit_line_note (DECL_SOURCE_FILE (decl),
6368 DECL_SOURCE_LINE (decl));
6369 expand_aggr_init (decl, init, 0, flags);
6372 /* Set this to 0 so we can tell whether an aggregate which
6373 was initialized was ever used. Don't do this if it has a
6374 destructor, so we don't complain about the 'resource
6375 allocation is initialization' idiom. */
6376 if (TYPE_NEEDS_CONSTRUCTING (type) && cleanup == NULL_TREE)
6377 TREE_USED (decl) = 0;
6379 /* Store the cleanup, if there was one. */
6382 if (! expand_decl_cleanup (decl, cleanup))
6383 cp_error ("parser lost in parsing declaration of `%D'",
6387 /* Cleanup any temporaries needed for the initial value. */
6388 expand_cleanups_to (old_cleanups);
6392 /* Undo call to `pushclass' that was done in `start_decl'
6393 due to initialization of qualified member variable.
6394 I.e., Foo::x = 10; */
6396 tree context = DECL_CONTEXT (decl);
6398 && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
6399 && (TREE_CODE (decl) == VAR_DECL
6400 /* We also have a pushclass done that we need to undo here
6401 if we're at top level and declare a method. */
6402 || (TREE_CODE (decl) == FUNCTION_DECL
6403 /* If size hasn't been set, we're still defining it,
6404 and therefore inside the class body; don't pop
6405 the binding level.. */
6406 && TYPE_SIZE (context) != NULL_TREE
6407 /* The binding level gets popped elsewhere for a
6408 friend declaration inside another class. */
6410 && TYPE_IDENTIFIER (context) == current_class_name
6412 && context == current_class_type
6420 /* If requested, warn about definitions of large data objects. */
6422 if (warn_larger_than
6423 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
6424 && !DECL_EXTERNAL (decl))
6426 register tree decl_size = DECL_SIZE (decl);
6428 if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
6430 unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT;
6432 if (units > larger_than_size)
6433 warning_with_decl (decl, "size of `%s' is %u bytes", units);
6439 /* Resume permanent allocation, if not within a function. */
6440 /* The corresponding push_obstacks_nochange is in start_decl,
6441 start_method, groktypename, and in grokfield. */
6446 TREE_READONLY (decl) = 1;
6449 cadillac_finish_decl (decl);
6453 expand_static_init (decl, init)
6457 tree oldstatic = value_member (decl, static_aggregates);
6462 if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
6463 cp_error ("multiple initializations given for `%D'", decl);
6465 else if (current_binding_level != global_binding_level
6466 && current_binding_level->pseudo_global == 0)
6468 /* Emit code to perform this initialization but once. */
6471 /* Remember this information until end of file. */
6472 push_obstacks (&permanent_obstack, &permanent_obstack);
6474 /* Emit code to perform this initialization but once. */
6475 temp = get_temp_name (integer_type_node, 1);
6476 rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
6477 expand_start_cond (build_binary_op (EQ_EXPR, temp,
6478 integer_zero_node, 1), 0);
6479 old_cleanups = cleanups_this_call;
6480 expand_assignment (temp, integer_one_node, 0, 0);
6481 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6483 expand_aggr_init (decl, init, 0, 0);
6484 do_pending_stack_adjust ();
6487 expand_assignment (decl, init, 0, 0);
6488 /* Cleanup any temporaries needed for the initial value. */
6489 expand_cleanups_to (old_cleanups);
6491 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
6493 static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
6494 TREE_STATIC (static_aggregates) = 1;
6497 /* Resume old (possibly temporary) allocation. */
6502 /* This code takes into account memory allocation
6503 policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING
6504 does not hold for this object, then we must make permanent
6505 the storage currently in the temporary obstack. */
6506 if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6507 preserve_initializer ();
6508 static_aggregates = perm_tree_cons (init, decl, static_aggregates);
6512 /* Make TYPE a complete type based on INITIAL_VALUE.
6513 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
6514 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
6517 complete_array_type (type, initial_value, do_default)
6518 tree type, initial_value;
6521 register tree maxindex = NULL_TREE;
6526 /* Note MAXINDEX is really the maximum index,
6527 one less than the size. */
6528 if (TREE_CODE (initial_value) == STRING_CST)
6529 maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
6530 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
6533 = list_length (CONSTRUCTOR_ELTS (initial_value));
6534 maxindex = build_int_2 (nelts - 1, - (nelts == 0));
6538 /* Make an error message unless that happened already. */
6539 if (initial_value != error_mark_node)
6542 /* Prevent further error messages. */
6543 maxindex = build_int_2 (0, 0);
6550 maxindex = build_int_2 (0, 0);
6558 TYPE_DOMAIN (type) = build_index_type (maxindex);
6559 if (!TREE_TYPE (maxindex))
6560 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
6562 itype = TREE_TYPE (initial_value);
6565 if (itype && !TYPE_DOMAIN (itype))
6566 TYPE_DOMAIN (itype) = TYPE_DOMAIN (type);
6569 /* Lay out the type now that we can get the real answer. */
6576 /* Return zero if something is declared to be a member of type
6577 CTYPE when in the context of CUR_TYPE. STRING is the error
6578 message to print in that case. Otherwise, quietly return 1. */
6580 member_function_or_else (ctype, cur_type, string)
6581 tree ctype, cur_type;
6584 if (ctype && ctype != cur_type)
6586 error (string, TYPE_NAME_STRING (ctype));
6592 /* Subroutine of `grokdeclarator'. */
6594 /* Generate errors possibly applicable for a given set of specifiers.
6595 This is for ARM $7.1.2. */
6597 bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
6600 int virtualp, quals, friendp, raises, inlinep;
6603 cp_error ("`%D' declared as a `virtual' %s", object, type);
6605 cp_error ("`%D' declared as an `inline' %s", object, type);
6607 cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
6610 cp_error_at ("invalid friend declaration", object);
6612 cp_error_at ("invalid exception specifications", object);
6615 /* CTYPE is class type, or null if non-class.
6616 TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
6618 DECLARATOR is the function's name.
6619 VIRTUALP is truthvalue of whether the function is virtual or not.
6620 FLAGS are to be passed through to `grokclassfn'.
6621 QUALS are qualifiers indicating whether the function is `const'
6623 RAISES is a list of exceptions that this function can raise.
6624 CHECK is 1 if we must find this method in CTYPE, 0 if we should
6625 not look, and -1 if we should not call `grokclassfn' at all. */
6627 grokfndecl (ctype, type, declarator, virtualp, flags, quals,
6628 raises, check, publicp)
6632 enum overload_flags flags;
6637 int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
6640 cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
6641 ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
6647 type = build_exception_variant (ctype, type, raises);
6648 raises = TYPE_RAISES_EXCEPTIONS (type);
6650 decl = build_lang_decl (FUNCTION_DECL, declarator, type);
6651 /* propagate volatile out from type to decl */
6652 if (TYPE_VOLATILE (type))
6653 TREE_THIS_VOLATILE (decl) = 1;
6655 /* Should probably propagate const out from type to decl I bet (mrs). */
6658 DECL_STATIC_FUNCTION_P (decl) = 1;
6659 DECL_CONTEXT (decl) = ctype;
6660 DECL_CLASS_CONTEXT (decl) = ctype;
6663 /* All function decls start out public; we'll fix their linkage later (at
6664 definition or EOF) if appropriate. */
6665 TREE_PUBLIC (decl) = 1;
6670 DECL_DECLARED_STATIC (decl) = 1;
6672 DECL_EXTERNAL (decl) = 1;
6673 if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
6675 cp_error ("%smember function `%D' cannot have `%T' method qualifier",
6676 (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
6680 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
6681 grok_op_properties (decl, virtualp, check < 0);
6683 /* Caller will do the rest of this. */
6687 if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
6690 /* Just handle constructors here. We could do this
6691 inside the following if stmt, but I think
6692 that the code is more legible by breaking this
6693 case out. See comments below for what each of
6694 the following calls is supposed to do. */
6695 DECL_CONSTRUCTOR_P (decl) = 1;
6697 grokclassfn (ctype, declarator, decl, flags, quals);
6699 check_classfn (ctype, declarator, decl);
6700 if (! grok_ctor_properties (ctype, decl))
6703 if (check == 0 && ! current_function_decl)
6705 /* FIXME: this should only need to look at
6706 IDENTIFIER_GLOBAL_VALUE. */
6707 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
6708 if (tmp == NULL_TREE)
6709 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
6710 else if (TREE_CODE (tmp) != TREE_CODE (decl))
6711 cp_error ("inconsistent declarations for `%D'", decl);
6714 duplicate_decls (decl, tmp);
6716 /* avoid creating circularities. */
6717 DECL_CHAIN (decl) = NULL_TREE;
6719 make_decl_rtl (decl, NULL_PTR, 1);
6726 /* Function gets the ugly name, field gets the nice one.
6727 This call may change the type of the function (because
6728 of default parameters)! */
6729 if (ctype != NULL_TREE)
6730 grokclassfn (ctype, cname, decl, flags, quals);
6732 if (ctype != NULL_TREE && check)
6733 check_classfn (ctype, cname, decl);
6735 if (ctype == NULL_TREE || check)
6738 /* Now install the declaration of this function so that others may
6739 find it (esp. its DECL_FRIENDLIST). Don't do this for local class
6741 if (! current_function_decl)
6743 /* FIXME: this should only need to look at
6744 IDENTIFIER_GLOBAL_VALUE. */
6745 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
6746 if (tmp == NULL_TREE)
6747 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
6748 else if (TREE_CODE (tmp) != TREE_CODE (decl))
6749 cp_error ("inconsistent declarations for `%D'", decl);
6752 duplicate_decls (decl, tmp);
6754 /* avoid creating circularities. */
6755 DECL_CHAIN (decl) = NULL_TREE;
6757 make_decl_rtl (decl, NULL_PTR, 1);
6760 /* If this declaration supersedes the declaration of
6761 a method declared virtual in the base class, then
6762 mark this field as being virtual as well. */
6764 tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
6765 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
6767 for (i = 0; i < n_baselinks; i++)
6769 tree base_binfo = TREE_VEC_ELT (binfos, i);
6770 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo))
6771 || flag_all_virtual == 1)
6773 tmp = get_matching_virtual (base_binfo, decl,
6774 flags == DTOR_FLAG);
6777 /* If this function overrides some virtual in some base
6778 class, then the function itself is also necessarily
6779 virtual, even if the user didn't explicitly say so. */
6780 DECL_VIRTUAL_P (decl) = 1;
6782 /* The TMP we really want is the one from the deepest
6783 baseclass on this path, taking care not to
6784 duplicate if we have already found it (via another
6785 path to its virtual baseclass. */
6788 cp_error ("method `%D' may not be declared static",
6790 cp_error_at ("(since `%D' declared virtual in base class.)",
6797 /* The argument types may have changed... */
6798 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
6799 tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
6801 argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
6802 TREE_CHAIN (argtypes));
6803 /* But the return type has not. */
6804 type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
6807 type = build_exception_variant (ctype, type, raises);
6808 raises = TYPE_RAISES_EXCEPTIONS (type);
6810 TREE_TYPE (decl) = type;
6812 = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
6821 if (DECL_VINDEX (decl) == NULL_TREE)
6822 DECL_VINDEX (decl) = error_mark_node;
6823 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
6824 if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
6825 /* If this function is derived from a template, don't
6826 make it public. This shouldn't be here, but there's
6827 no good way to override the interface pragmas for one
6828 function or class only. Bletch. */
6829 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE
6830 && (write_virtuals == 2
6831 || (write_virtuals == 3
6832 && CLASSTYPE_INTERFACE_KNOWN (ctype))))
6833 TREE_PUBLIC (decl) = 1;
6840 grokvardecl (type, declarator, specbits, initialized)
6843 RID_BIT_TYPE specbits;
6848 if (TREE_CODE (type) == OFFSET_TYPE)
6850 /* If you declare a static member so that it
6851 can be initialized, the code will reach here. */
6852 tree basetype = TYPE_OFFSET_BASETYPE (type);
6853 type = TREE_TYPE (type);
6854 decl = build_lang_field_decl (VAR_DECL, declarator, type);
6855 DECL_CONTEXT (decl) = basetype;
6856 DECL_CLASS_CONTEXT (decl) = basetype;
6857 DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator);
6860 decl = build_decl (VAR_DECL, declarator, type);
6862 DECL_ASSEMBLER_NAME (decl) = current_namespace_id (DECL_ASSEMBLER_NAME (decl));
6864 if (RIDBIT_SETP (RID_EXTERN, specbits))
6866 DECL_THIS_EXTERN (decl) = 1;
6867 DECL_EXTERNAL (decl) = !initialized;
6870 /* In class context, static means one per class,
6871 public access, and static storage. */
6872 if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
6873 && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
6875 TREE_PUBLIC (decl) = 1;
6876 TREE_STATIC (decl) = 1;
6877 DECL_EXTERNAL (decl) = 0;
6879 /* At top level, either `static' or no s.c. makes a definition
6880 (perhaps tentative), and absence of `static' makes it public. */
6881 else if (current_binding_level == global_binding_level)
6883 TREE_PUBLIC (decl) = RIDBIT_NOTSETP (RID_STATIC, specbits);
6884 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
6886 /* Not at top level, only `static' makes a static definition. */
6889 TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
6890 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
6895 /* Create a canonical pointer to member function type. */
6898 build_ptrmemfunc_type (type)
6905 /* If a canonical type already exists for this type, use it. We use
6906 this method instead of type_hash_canon, because it only does a
6907 simple equality check on the list of field members. */
6909 if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
6912 push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
6914 u = make_lang_type (UNION_TYPE);
6915 fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
6916 fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier,
6918 finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
6919 TYPE_NAME (u) = NULL_TREE;
6921 t = make_lang_type (RECORD_TYPE);
6923 /* Let the front-end know this is a pointer to member function. */
6924 TYPE_PTRMEMFUNC_FLAG (t) = 1;
6925 /* and not really an aggregate. */
6926 IS_AGGR_TYPE (t) = 0;
6928 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
6930 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
6932 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
6933 finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
6937 /* Zap out the name so that the back-end will give us the debugging
6938 information for this anonymous RECORD_TYPE. */
6939 TYPE_NAME (t) = NULL_TREE;
6941 TYPE_SET_PTRMEMFUNC_TYPE (type, t);
6943 /* Seems to be wanted. */
6944 CLASSTYPE_GOT_SEMICOLON (t) = 1;
6948 /* Given declspecs and a declarator,
6949 determine the name and type of the object declared
6950 and construct a ..._DECL node for it.
6951 (In one case we can return a ..._TYPE node instead.
6952 For invalid input we sometimes return 0.)
6954 DECLSPECS is a chain of tree_list nodes whose value fields
6955 are the storage classes and type specifiers.
6957 DECL_CONTEXT says which syntactic context this declaration is in:
6958 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
6959 FUNCDEF for a function definition. Like NORMAL but a few different
6960 error messages in each case. Return value may be zero meaning
6961 this definition is too screwy to try to parse.
6962 MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
6963 handle member functions (which have FIELD context).
6964 Return value may be zero meaning this definition is too screwy to
6966 PARM for a parameter declaration (either within a function prototype
6967 or before a function body). Make a PARM_DECL, or return void_type_node.
6968 CATCHPARM for a parameter declaration before a catch clause.
6969 TYPENAME if for a typename (in a cast or sizeof).
6970 Don't make a DECL node; just return the ..._TYPE node.
6971 FIELD for a struct or union field; make a FIELD_DECL.
6972 BITFIELD for a field with specified width.
6973 INITIALIZED is 1 if the decl has an initializer.
6975 In the TYPENAME case, DECLARATOR is really an absolute declarator.
6976 It may also be so in the PARM case, for a prototype where the
6977 argument type is specified but not the name.
6979 This function is where the complicated C meanings of `static'
6980 and `extern' are interpreted.
6982 For C++, if there is any monkey business to do, the function which
6983 calls this one must do it, i.e., prepending instance variables,
6984 renaming overloaded function names, etc.
6986 Note that for this C++, it is an error to define a method within a class
6987 which does not belong to that class.
6989 Except in the case where SCOPE_REFs are implicitly known (such as
6990 methods within a class being redundantly qualified),
6991 declarations which involve SCOPE_REFs are returned as SCOPE_REFs
6992 (class_name::decl_name). The caller must also deal with this.
6994 If a constructor or destructor is seen, and the context is FIELD,
6995 then the type gains the attribute TREE_HAS_x. If such a declaration
6996 is erroneous, NULL_TREE is returned.
6998 QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
6999 function, these are the qualifiers to give to the `this' pointer.
7001 May return void_type_node if the declarator turned out to be a friend.
7002 See grokfield for details. */
7004 enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
7007 grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
7010 enum decl_context decl_context;
7014 RID_BIT_TYPE specbits;
7017 tree type = NULL_TREE;
7021 int virtualp, explicitp, friendp, inlinep, staticp;
7022 int explicit_int = 0;
7023 int explicit_char = 0;
7024 int opaque_typedef = 0;
7025 tree typedef_decl = NULL_TREE;
7027 tree typedef_type = NULL_TREE;
7028 int funcdef_flag = 0;
7029 enum tree_code innermost_code = ERROR_MARK;
7031 int size_varies = 0;
7032 /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
7033 All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
7034 tree init = NULL_TREE;
7036 /* Keep track of what sort of function is being processed
7037 so that we can warn about default return values, or explicit
7038 return values which do not match prescribed defaults. */
7039 enum return_types return_type = return_normal;
7041 tree dname = NULL_TREE;
7042 tree ctype = current_class_type;
7043 tree ctor_return_type = NULL_TREE;
7044 enum overload_flags flags = NO_SPECIAL;
7045 tree quals = NULL_TREE;
7047 RIDBIT_RESET_ALL (specbits);
7048 if (decl_context == FUNCDEF)
7049 funcdef_flag = 1, decl_context = NORMAL;
7050 else if (decl_context == MEMFUNCDEF)
7051 funcdef_flag = -1, decl_context = FIELD;
7052 else if (decl_context == BITFIELD)
7053 bitfield = 1, decl_context = FIELD;
7055 if (flag_traditional && allocation_temporary_p ())
7056 end_temporary_allocation ();
7058 /* Look inside a declarator for the name being declared
7059 and get it as a string, for an error message. */
7061 tree last = NULL_TREE;
7062 register tree decl = declarator;
7066 switch (TREE_CODE (decl))
7070 decl = TREE_OPERAND (decl, 0);
7073 case BIT_NOT_EXPR: /* for C++ destructors! */
7075 tree name = TREE_OPERAND (decl, 0);
7076 tree rename = NULL_TREE;
7078 my_friendly_assert (flags == NO_SPECIAL, 152);
7080 return_type = return_dtor;
7081 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
7082 if (ctype == NULL_TREE)
7084 if (current_class_type == NULL_TREE)
7086 error ("destructors must be member functions");
7091 tree t = constructor_name (current_class_name);
7098 tree t = constructor_name (ctype);
7105 error ("destructor `%s' must match class name `%s'",
7106 IDENTIFIER_POINTER (name),
7107 IDENTIFIER_POINTER (rename));
7108 TREE_OPERAND (decl, 0) = rename;
7114 case ADDR_EXPR: /* C++ reference declaration */
7119 innermost_code = TREE_CODE (decl);
7121 decl = TREE_OPERAND (decl, 0);
7125 if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
7127 /* This is actually a variable declaration using constructor
7128 syntax. We need to call start_decl and finish_decl so we
7129 can get the variable initialized... */
7132 /* We need to insinuate ourselves into the declarator in place
7133 of the CALL_EXPR. */
7134 TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
7136 declarator = TREE_OPERAND (decl, 0);
7138 init = TREE_OPERAND (decl, 1);
7140 decl = start_decl (declarator, declspecs, 1, NULL_TREE);
7141 finish_decl (decl, init, NULL_TREE, 1, 0);
7144 innermost_code = TREE_CODE (decl);
7145 decl = TREE_OPERAND (decl, 0);
7146 if (decl_context == FIELD && ctype == NULL_TREE)
7147 ctype = current_class_type;
7148 if (ctype != NULL_TREE
7149 && decl != NULL_TREE && flags != DTOR_FLAG
7150 && decl == constructor_name (ctype))
7152 return_type = return_ctor;
7153 ctor_return_type = ctype;
7158 case IDENTIFIER_NODE:
7162 if (! IDENTIFIER_OPNAME_P (dname)
7163 /* Linux headers use '__op'. Arrgh. */
7164 || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))
7165 name = IDENTIFIER_POINTER (dname);
7168 if (IDENTIFIER_TYPENAME_P (dname))
7170 my_friendly_assert (flags == NO_SPECIAL, 154);
7171 flags = TYPENAME_FLAG;
7172 ctor_return_type = TREE_TYPE (dname);
7173 return_type = return_conversion;
7175 name = operator_name_string (dname);
7182 /* Parse error puts this typespec where
7183 a declarator should go. */
7184 error ("declarator name missing");
7185 dname = TYPE_NAME (decl);
7186 if (dname && TREE_CODE (dname) == TYPE_DECL)
7187 dname = DECL_NAME (dname);
7188 name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
7189 declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
7196 /* Perform error checking, and convert class names to types.
7197 We may call grokdeclarator multiple times for the same
7198 tree structure, so only do the conversion once. In this
7199 case, we have exactly what we want for `ctype'. */
7200 tree cname = TREE_OPERAND (decl, 0);
7201 if (cname == NULL_TREE)
7203 /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */
7204 else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname))
7205 || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE)
7207 else if (! is_aggr_typedef (cname, 1))
7209 TREE_OPERAND (decl, 0) = NULL_TREE;
7211 /* Must test TREE_OPERAND (decl, 1), in case user gives
7212 us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */
7213 else if (TREE_OPERAND (decl, 1)
7214 && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
7216 TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
7218 else if (ctype == NULL_TREE)
7220 ctype = IDENTIFIER_TYPE_VALUE (cname);
7221 TREE_OPERAND (decl, 0) = ctype;
7223 else if (TREE_COMPLEXITY (decl) == current_class_depth)
7224 TREE_OPERAND (decl, 0) = ctype;
7227 if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname),
7230 cp_error ("type `%T' is not derived from type `%T'",
7231 IDENTIFIER_TYPE_VALUE (cname), ctype);
7232 TREE_OPERAND (decl, 0) = NULL_TREE;
7236 ctype = IDENTIFIER_TYPE_VALUE (cname);
7237 TREE_OPERAND (decl, 0) = ctype;
7241 decl = TREE_OPERAND (decl, 1);
7244 if (TREE_CODE (decl) == IDENTIFIER_NODE
7245 && constructor_name (ctype) == decl)
7247 return_type = return_ctor;
7248 ctor_return_type = ctype;
7250 else if (TREE_CODE (decl) == BIT_NOT_EXPR
7251 && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
7252 && constructor_name (ctype) == TREE_OPERAND (decl, 0))
7254 return_type = return_dtor;
7255 ctor_return_type = ctype;
7257 decl = TREE_OPERAND (decl, 0);
7268 return 0; /* We used to do a 155 abort here. */
7274 /* A function definition's declarator must have the form of
7275 a function declarator. */
7277 if (funcdef_flag && innermost_code != CALL_EXPR)
7280 /* Anything declared one level down from the top level
7281 must be one of the parameters of a function
7282 (because the body is at least two levels down). */
7284 /* This heuristic cannot be applied to C++ nodes! Fixed, however,
7285 by not allowing C++ class definitions to specify their parameters
7286 with xdecls (must be spec.d in the parmlist).
7288 Since we now wait to push a class scope until we are sure that
7289 we are in a legitimate method context, we must set oldcname
7290 explicitly (since current_class_name is not yet alive). */
7292 if (decl_context == NORMAL
7293 && current_binding_level->level_chain == global_binding_level)
7294 decl_context = PARM;
7296 /* Look through the decl specs and record which ones appear.
7297 Some typespecs are defined as built-in typenames.
7298 Others, the ones that are modifiers of other types,
7299 are represented by bits in SPECBITS: set the bits for
7300 the modifiers that appear. Storage class keywords are also in SPECBITS.
7302 If there is a typedef name or a type, store the type in TYPE.
7303 This includes builtin typedefs such as `int'.
7305 Set EXPLICIT_INT if the type is `int' or `char' and did not
7306 come from a user typedef.
7308 Set LONGLONG if `long' is mentioned twice.
7310 For C++, constructors and destructors have their own fast treatment. */
7312 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
7317 /* Certain parse errors slip through. For example,
7318 `int class;' is not caught by the parser. Try
7319 weakly to recover here. */
7320 if (TREE_CODE (spec) != TREE_LIST)
7323 id = TREE_VALUE (spec);
7325 if (TREE_CODE (id) == IDENTIFIER_NODE)
7327 if (id == ridpointers[(int) RID_INT]
7328 || id == ridpointers[(int) RID_CHAR]
7329 || id == ridpointers[(int) RID_BOOL]
7330 || id == ridpointers[(int) RID_WCHAR])
7333 error ("extraneous `%T' ignored", id);
7336 if (id == ridpointers[(int) RID_INT])
7338 else if (id == ridpointers[(int) RID_CHAR])
7340 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7344 /* C++ aggregate types. */
7345 if (IDENTIFIER_HAS_TYPE_VALUE (id))
7348 cp_error ("multiple declarations `%T' and `%T'", type, id);
7350 type = IDENTIFIER_TYPE_VALUE (id);
7354 for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++)
7356 if (ridpointers[i] == id)
7358 if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
7360 if (pedantic && flag_ansi)
7361 pedwarn ("duplicate `long'");
7363 error ("`long long long' is too long for GCC");
7367 else if (RIDBIT_SETP (i, specbits))
7368 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
7369 RIDBIT_SET (i, specbits);
7375 error ("two or more data types in declaration of `%s'", name);
7376 else if (TREE_CODE (id) == IDENTIFIER_NODE)
7378 register tree t = lookup_name (id, 1);
7379 if (!t || TREE_CODE (t) != TYPE_DECL)
7380 error ("`%s' fails to be a typedef or built in type",
7381 IDENTIFIER_POINTER (id));
7384 type = TREE_TYPE (t);
7388 else if (TREE_CODE (id) != ERROR_MARK)
7389 /* Can't change CLASS nodes into RECORD nodes here! */
7395 typedef_type = type;
7397 /* No type at all: default to `int', and set EXPLICIT_INT
7398 because it was not a user-defined typedef.
7399 Except when we have a `typedef' inside a signature, in
7400 which case the type defaults to `unknown type' and is
7401 instantiated when assigning to a signature pointer or ref. */
7403 if (type == NULL_TREE
7404 && (RIDBIT_SETP (RID_SIGNED, specbits)
7405 || RIDBIT_SETP (RID_UNSIGNED, specbits)
7406 || RIDBIT_SETP (RID_LONG, specbits)
7407 || RIDBIT_SETP (RID_SHORT, specbits)))
7409 /* These imply 'int'. */
7410 type = integer_type_node;
7414 if (type == NULL_TREE)
7417 if (return_type == return_dtor)
7418 type = void_type_node;
7419 else if (return_type == return_ctor)
7420 type = TYPE_POINTER_TO (ctor_return_type);
7421 else if (return_type == return_conversion)
7422 type = ctor_return_type;
7423 else if (current_class_type
7424 && IS_SIGNATURE (current_class_type)
7425 && (RIDBIT_SETP (RID_TYPEDEF, specbits)
7426 || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7427 && (decl_context == FIELD || decl_context == NORMAL))
7431 type = copy_node (opaque_type_node);
7433 /* access declaration */
7434 else if (decl_context == FIELD && declarator
7435 && TREE_CODE (declarator) == SCOPE_REF)
7436 type = void_type_node;
7441 if (warn_return_type
7442 && return_type == return_normal)
7443 /* Save warning until we know what is really going on. */
7444 warn_about_return_type = 1;
7446 else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7447 pedwarn ("ANSI C++ forbids typedef which does not specify a type");
7448 else if (declspecs == NULL_TREE &&
7449 (innermost_code != CALL_EXPR || pedantic))
7450 cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class",
7452 type = integer_type_node;
7455 else if (return_type == return_dtor)
7457 error ("return type specification for destructor invalid");
7458 type = void_type_node;
7460 else if (return_type == return_ctor)
7462 error ("return type specification for constructor invalid");
7463 type = TYPE_POINTER_TO (ctor_return_type);
7465 else if (return_type == return_conversion)
7467 if (comp_target_types (type, ctor_return_type, 1) == 0)
7468 cp_error ("operator `%T' declared to return `%T'",
7469 ctor_return_type, type);
7471 cp_pedwarn ("return type specified for `operator %T'",
7474 type = ctor_return_type;
7476 /* Catch typedefs that only specify a type, like 'typedef int;'. */
7477 else if (RIDBIT_SETP (RID_TYPEDEF, specbits) && declarator == NULL_TREE)
7479 /* Template "this is a type" syntax; just ignore for now. */
7480 if (processing_template_defn)
7481 return void_type_node;
7486 /* Now process the modifiers that were specified
7487 and check for invalid combinations. */
7489 /* Long double is a special combination. */
7491 if (RIDBIT_SETP (RID_LONG, specbits)
7492 && TYPE_MAIN_VARIANT (type) == double_type_node)
7494 RIDBIT_RESET (RID_LONG, specbits);
7495 type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
7496 TYPE_VOLATILE (type));
7499 /* Check all other uses of type modifiers. */
7501 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7502 || RIDBIT_SETP (RID_SIGNED, specbits)
7503 || RIDBIT_SETP (RID_LONG, specbits)
7504 || RIDBIT_SETP (RID_SHORT, specbits))
7508 if (TREE_CODE (type) == REAL_TYPE)
7509 error ("short, signed or unsigned invalid for `%s'", name);
7510 else if (TREE_CODE (type) != INTEGER_TYPE || type == wchar_type_node)
7511 error ("long, short, signed or unsigned invalid for `%s'", name);
7512 else if (RIDBIT_SETP (RID_LONG, specbits)
7513 && RIDBIT_SETP (RID_SHORT, specbits))
7514 error ("long and short specified together for `%s'", name);
7515 else if ((RIDBIT_SETP (RID_LONG, specbits)
7516 || RIDBIT_SETP (RID_SHORT, specbits))
7518 error ("long or short specified with char for `%s'", name);
7519 else if ((RIDBIT_SETP (RID_LONG, specbits)
7520 || RIDBIT_SETP (RID_SHORT, specbits))
7521 && TREE_CODE (type) == REAL_TYPE)
7522 error ("long or short specified with floating type for `%s'", name);
7523 else if (RIDBIT_SETP (RID_SIGNED, specbits)
7524 && RIDBIT_SETP (RID_UNSIGNED, specbits))
7525 error ("signed and unsigned given together for `%s'", name);
7529 if (!explicit_int && !explicit_char && pedantic)
7531 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
7533 if (flag_pedantic_errors)
7538 /* Discard the type modifiers if they are invalid. */
7541 RIDBIT_RESET (RID_UNSIGNED, specbits);
7542 RIDBIT_RESET (RID_SIGNED, specbits);
7543 RIDBIT_RESET (RID_LONG, specbits);
7544 RIDBIT_RESET (RID_SHORT, specbits);
7549 /* Decide whether an integer type is signed or not.
7550 Optionally treat bitfields as signed by default. */
7551 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7552 /* Traditionally, all bitfields are unsigned. */
7553 || (bitfield && flag_traditional)
7554 || (bitfield && ! flag_signed_bitfields
7555 && (explicit_int || explicit_char
7556 /* A typedef for plain `int' without `signed'
7557 can be controlled just like plain `int'. */
7558 || ! (typedef_decl != NULL_TREE
7559 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
7560 && TREE_CODE (type) != ENUMERAL_TYPE
7561 && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
7564 type = long_long_unsigned_type_node;
7565 else if (RIDBIT_SETP (RID_LONG, specbits))
7566 type = long_unsigned_type_node;
7567 else if (RIDBIT_SETP (RID_SHORT, specbits))
7568 type = short_unsigned_type_node;
7569 else if (type == char_type_node)
7570 type = unsigned_char_type_node;
7571 else if (typedef_decl)
7572 type = unsigned_type (type);
7574 type = unsigned_type_node;
7576 else if (RIDBIT_SETP (RID_SIGNED, specbits)
7577 && type == char_type_node)
7578 type = signed_char_type_node;
7580 type = long_long_integer_type_node;
7581 else if (RIDBIT_SETP (RID_LONG, specbits))
7582 type = long_integer_type_node;
7583 else if (RIDBIT_SETP (RID_SHORT, specbits))
7584 type = short_integer_type_node;
7586 /* Set CONSTP if this declaration is `const', whether by
7587 explicit specification or via a typedef.
7588 Likewise for VOLATILEP. */
7590 constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
7591 volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
7593 inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
7595 /* This sort of redundancy is blessed in a footnote to the Sep 94 WP. */
7597 warning ("duplicate `const'");
7599 warning ("duplicate `volatile'");
7601 virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
7602 RIDBIT_RESET (RID_VIRTUAL, specbits);
7603 explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0;
7604 RIDBIT_RESET (RID_EXPLICIT, specbits);
7606 if (RIDBIT_SETP (RID_STATIC, specbits))
7607 staticp = 1 + (decl_context == FIELD);
7609 if (virtualp && staticp == 2)
7611 cp_error ("member `%D' cannot be declared both virtual and static",
7615 friendp = RIDBIT_SETP (RID_FRIEND, specbits);
7616 RIDBIT_RESET (RID_FRIEND, specbits);
7618 if (RIDBIT_SETP (RID_MUTABLE, specbits))
7620 if (decl_context == PARM)
7622 error ("non-member `%s' cannot be declared `mutable'", name);
7623 RIDBIT_RESET (RID_MUTABLE, specbits);
7625 else if (friendp || decl_context == TYPENAME)
7627 error ("non-object member `%s' cannot be declared `mutable'", name);
7628 RIDBIT_RESET (RID_MUTABLE, specbits);
7632 error ("static `%s' cannot be declared `mutable'", name);
7633 RIDBIT_RESET (RID_MUTABLE, specbits);
7636 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7638 error ("non-object member `%s' cannot be declared `mutable'", name);
7639 RIDBIT_RESET (RID_MUTABLE, specbits);
7641 /* Because local typedefs are parsed twice, we don't want this
7643 else if (decl_context != FIELD)
7645 error ("non-member `%s' cannot be declared `mutable'", name);
7646 RIDBIT_RESET (RID_MUTABLE, specbits);
7651 /* Warn if two storage classes are given. Default to `auto'. */
7653 if (RIDBIT_ANY_SET (specbits))
7655 if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
7656 if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
7657 if (decl_context == PARM && nclasses > 0)
7658 error ("storage class specifiers invalid in parameter declarations");
7659 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7661 if (decl_context == PARM)
7662 error ("typedef declaration invalid in parameter declaration");
7665 if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
7666 if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
7669 /* Give error if `virtual' is used outside of class declaration. */
7670 if (virtualp && current_class_name == NULL_TREE)
7672 error ("virtual outside class declaration");
7675 if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
7677 error ("only members can be declared mutable");
7678 RIDBIT_RESET (RID_MUTABLE, specbits);
7681 /* Static anonymous unions are dealt with here. */
7682 if (staticp && decl_context == TYPENAME
7683 && TREE_CODE (declspecs) == TREE_LIST
7684 && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
7685 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
7686 decl_context = FIELD;
7688 /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
7689 is used in a signature member function declaration. */
7690 if (decl_context == FIELD
7691 && IS_SIGNATURE (current_class_type)
7692 && RIDBIT_NOTSETP(RID_TYPEDEF, specbits)
7693 && !SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7697 error ("`const' specified for signature member function `%s'", name);
7702 error ("`volatile' specified for signature member function `%s'",
7708 error ("`inline' specified for signature member function `%s'", name);
7709 /* Later, we'll make signature member functions inline. */
7714 error ("`friend' declaration in signature definition");
7719 error ("`virtual' specified for signature member function `%s'",
7721 /* Later, we'll make signature member functions virtual. */
7726 /* Warn about storage classes that are invalid for certain
7727 kinds of declarations (parameters, typenames, etc.). */
7730 error ("multiple storage classes in declaration of `%s'", name);
7731 else if (decl_context != NORMAL && nclasses > 0)
7733 if ((decl_context == PARM || decl_context == CATCHPARM)
7734 && (RIDBIT_SETP (RID_REGISTER, specbits)
7735 || RIDBIT_SETP (RID_AUTO, specbits)))
7737 else if (decl_context == FIELD
7738 && RIDBIT_SETP (RID_TYPEDEF, specbits))
7740 /* Processing a typedef declaration nested within a class type
7742 register tree scanner;
7743 register tree previous_declspec;
7747 error ("typedef declaration includes an initializer");
7749 /* To process a class-local typedef declaration, we descend down
7750 the chain of declspecs looking for the `typedef' spec. When
7751 we find it, we replace it with `static', and then recursively
7752 call `grokdeclarator' with the original declarator and with
7753 the newly adjusted declspecs. This call should return a
7754 FIELD_DECL node with the TREE_TYPE (and other parts) set
7755 appropriately. We can then just change the TREE_CODE on that
7756 from FIELD_DECL to TYPE_DECL and we're done. */
7758 for (previous_declspec = NULL_TREE, scanner = declspecs;
7760 previous_declspec = scanner, scanner = TREE_CHAIN (scanner))
7762 if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF])
7766 if (previous_declspec)
7767 TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner);
7769 declspecs = TREE_CHAIN (scanner);
7771 declspecs = tree_cons (NULL_TREE, ridpointers[(int) RID_STATIC],
7774 /* In the recursive call to grokdeclarator we need to know
7775 whether we are working on a signature-local typedef. */
7776 if (IS_SIGNATURE (current_class_type))
7777 SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1;
7780 grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE);
7782 if (previous_declspec)
7783 TREE_CHAIN (previous_declspec) = scanner;
7785 if (loc_typedecl != error_mark_node)
7787 register int i = sizeof (struct lang_decl_flags) / sizeof (int);
7790 TREE_SET_CODE (loc_typedecl, TYPE_DECL);
7791 /* This is the same field as DECL_ARGUMENTS, which is set for
7792 function typedefs by the above grokdeclarator. */
7793 DECL_NESTED_TYPENAME (loc_typedecl) = 0;
7795 pi = (int *) permalloc (sizeof (struct lang_decl_flags));
7798 DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
7801 if (IS_SIGNATURE (current_class_type))
7803 SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0;
7804 if (loc_typedecl != error_mark_node && opaque_typedef)
7805 SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
7808 return loc_typedecl;
7810 else if (decl_context == FIELD
7811 && (! IS_SIGNATURE (current_class_type)
7812 || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7813 /* C++ allows static class elements */
7814 && RIDBIT_SETP (RID_STATIC, specbits))
7815 /* C++ also allows inlines and signed and unsigned elements,
7816 but in those cases we don't come in here. */
7820 if (decl_context == FIELD)
7822 tree tmp = TREE_OPERAND (declarator, 0);
7823 register int op = IDENTIFIER_OPNAME_P (tmp);
7824 error ("storage class specified for %s `%s'",
7825 IS_SIGNATURE (current_class_type)
7827 ? "signature member operator"
7828 : "signature member function")
7829 : (op ? "member operator" : "structure field"),
7830 op ? operator_name_string (tmp) : name);
7833 error (((decl_context == PARM || decl_context == CATCHPARM)
7834 ? "storage class specified for parameter `%s'"
7835 : "storage class specified for typename"), name);
7836 RIDBIT_RESET (RID_REGISTER, specbits);
7837 RIDBIT_RESET (RID_AUTO, specbits);
7838 RIDBIT_RESET (RID_EXTERN, specbits);
7840 if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
7842 RIDBIT_RESET (RID_STATIC, specbits);
7847 else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
7849 if (current_binding_level == global_binding_level)
7851 /* It's common practice (and completely legal) to have a const
7852 be initialized and declared extern. */
7854 warning ("`%s' initialized and declared `extern'", name);
7857 error ("`%s' has both `extern' and initializer", name);
7859 else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
7860 && current_binding_level != global_binding_level)
7861 error ("nested function `%s' declared `extern'", name);
7862 else if (current_binding_level == global_binding_level)
7864 if (RIDBIT_SETP (RID_AUTO, specbits))
7865 error ("top-level declaration of `%s' specifies `auto'", name);
7867 if (RIDBIT_SETP (RID_REGISTER, specbits))
7868 error ("top-level declaration of `%s' specifies `register'", name);
7871 /* I'm not sure under what circumstances we should turn
7872 on the extern bit, and under what circumstances we should
7873 warn if other bits are turned on. */
7874 if (decl_context == NORMAL
7875 && RIDBIT_NOSETP (RID_EXTERN, specbits)
7876 && ! root_lang_context_p ())
7878 RIDBIT_SET (RID_EXTERN, specbits);
7883 /* Now figure out the structure of the declarator proper.
7884 Descend through it, creating more complex types, until we reach
7885 the declared identifier (or NULL_TREE, in an absolute declarator). */
7887 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
7889 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
7890 an INDIRECT_REF (for *...),
7891 a CALL_EXPR (for ...(...)),
7892 an identifier (for the name being declared)
7893 or a null pointer (for the place in an absolute declarator
7894 where the name was omitted).
7895 For the last two cases, we have just exited the loop.
7897 For C++ it could also be
7898 a SCOPE_REF (for class :: ...). In this case, we have converted
7899 sensible names to types, and those are the values we use to
7900 qualify the member name.
7901 an ADDR_EXPR (for &...),
7902 a BIT_NOT_EXPR (for destructors)
7904 At this point, TYPE is the type of elements of an array,
7905 or for a function to return, or for a pointer to point to.
7906 After this sequence of ifs, TYPE is the type of the
7907 array or function or pointer, and DECLARATOR has had its
7908 outermost layer removed. */
7910 if (TREE_CODE (type) == ERROR_MARK)
7912 if (TREE_CODE (declarator) == SCOPE_REF)
7913 declarator = TREE_OPERAND (declarator, 1);
7915 declarator = TREE_OPERAND (declarator, 0);
7918 if (quals != NULL_TREE
7919 && (declarator == NULL_TREE
7920 || TREE_CODE (declarator) != SCOPE_REF))
7922 if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
7923 ctype = TYPE_METHOD_BASETYPE (type);
7924 if (ctype != NULL_TREE)
7926 #if 0 /* not yet, should get fixed properly later */
7927 tree dummy = make_type_decl (NULL_TREE, type);
7929 tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
7931 ctype = grok_method_quals (ctype, dummy, quals);
7932 type = TREE_TYPE (dummy);
7936 switch (TREE_CODE (declarator))
7940 register tree itype = NULL_TREE;
7941 register tree size = TREE_OPERAND (declarator, 1);
7943 declarator = TREE_OPERAND (declarator, 0);
7945 /* Check for some types that there cannot be arrays of. */
7947 if (TYPE_MAIN_VARIANT (type) == void_type_node)
7949 cp_error ("declaration of `%D' as array of voids", dname);
7950 type = error_mark_node;
7953 if (TREE_CODE (type) == FUNCTION_TYPE)
7955 cp_error ("declaration of `%D' as array of functions", dname);
7956 type = error_mark_node;
7959 /* ARM $8.4.3: Since you can't have a pointer to a reference,
7960 you can't have arrays of references. If we allowed them,
7961 then we'd be saying x[i] is legal for an array x, but
7962 then you'd have to ask: what does `*(x + i)' mean? */
7963 if (TREE_CODE (type) == REFERENCE_TYPE)
7965 if (decl_context == TYPENAME)
7966 cp_error ("cannot make arrays of references");
7968 cp_error ("declaration of `%D' as array of references",
7970 type = error_mark_node;
7973 if (TREE_CODE (type) == OFFSET_TYPE)
7975 cp_error ("declaration of `%D' as array of data members",
7977 type = error_mark_node;
7980 if (TREE_CODE (type) == METHOD_TYPE)
7982 cp_error ("declaration of `%D' as array of function members",
7984 type = error_mark_node;
7987 if (size == error_mark_node)
7988 type = error_mark_node;
7990 if (type == error_mark_node)
7995 /* Must suspend_momentary here because the index
7996 type may need to live until the end of the function.
7997 For example, it is used in the declaration of a
7998 variable which requires destructing at the end of
7999 the function; then build_vec_delete will need this
8001 int yes = suspend_momentary ();
8002 /* might be a cast */
8003 if (TREE_CODE (size) == NOP_EXPR
8004 && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
8005 size = TREE_OPERAND (size, 0);
8007 /* If this is a template parameter, it'll be constant, but
8008 we don't know what the value is yet. */
8009 if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
8010 goto dont_grok_size;
8012 if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
8013 && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
8015 cp_error ("size of array `%D' has non-integer type",
8017 size = integer_one_node;
8019 if (TREE_READONLY_DECL_P (size))
8020 size = decl_constant_value (size);
8021 if (flag_ansi && integer_zerop (size))
8022 cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
8023 if (TREE_CONSTANT (size))
8025 constant_expression_warning (size);
8026 if (INT_CST_LT (size, integer_zero_node))
8028 cp_error ("size of array `%D' is negative", dname);
8029 size = integer_one_node;
8031 itype = build_index_type (size_binop (MINUS_EXPR, size,
8039 cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
8042 cp_pedwarn ("ANSI C++ forbids variable-size array");
8046 build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
8047 /* Make sure the array size remains visibly nonconstant
8048 even if it is (eg) a const variable with known value. */
8050 itype = variable_size (itype);
8051 itype = build_index_type (itype);
8053 resume_momentary (yes);
8056 /* Build the array type itself, then merge any constancy or
8057 volatility into the target type. We must do it in this order
8058 to ensure that the TYPE_MAIN_VARIANT field of the array type
8059 is set correctly. */
8061 type = build_cplus_array_type (type, itype);
8062 if (constp || volatilep)
8063 type = cp_build_type_variant (type, constp, volatilep);
8073 tree inner_parms = TREE_OPERAND (declarator, 1);
8074 tree inner_decl = TREE_OPERAND (declarator, 0);
8076 /* Declaring a function type.
8077 Make sure we have a valid type for the function to return. */
8079 /* Is this an error? Should they be merged into TYPE here? */
8080 if (pedantic && (constp || volatilep))
8081 pedwarn ("function declared to return const or volatile result");
8083 /* Merge any constancy or volatility into the function return
8086 if (constp || volatilep)
8088 type = cp_build_type_variant (type, constp, volatilep);
8089 if (IS_AGGR_TYPE (type))
8090 build_pointer_type (type);
8096 /* Warn about some types functions can't return. */
8098 if (TREE_CODE (type) == FUNCTION_TYPE)
8100 error ("`%s' declared as function returning a function", name);
8101 type = integer_type_node;
8103 if (TREE_CODE (type) == ARRAY_TYPE)
8105 error ("`%s' declared as function returning an array", name);
8106 type = integer_type_node;
8109 if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
8110 inner_decl = TREE_OPERAND (inner_decl, 1);
8112 /* Say it's a definition only for the CALL_EXPR
8113 closest to the identifier. */
8115 inner_decl && TREE_CODE (inner_decl) == IDENTIFIER_NODE;
8117 if (ctype == NULL_TREE
8118 && decl_context == FIELD
8120 && (friendp == 0 || dname == current_class_name))
8121 ctype = current_class_type;
8123 if (ctype && return_type == return_conversion)
8124 TYPE_HAS_CONVERSION (ctype) = 1;
8125 if (ctype && constructor_name (ctype) == dname)
8127 /* We are within a class's scope. If our declarator name
8128 is the same as the class name, and we are defining
8129 a function, then it is a constructor/destructor, and
8130 therefore returns a void type. */
8132 if (flags == DTOR_FLAG)
8134 /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may
8135 not be declared const or volatile. A destructor
8136 may not be static. */
8138 error ("destructor cannot be static member function");
8139 if (TYPE_READONLY (type))
8141 error ("destructors cannot be declared `const'");
8142 return void_type_node;
8144 if (TYPE_VOLATILE (type))
8146 error ("destructors cannot be declared `volatile'");
8147 return void_type_node;
8149 if (decl_context == FIELD)
8151 if (! member_function_or_else (ctype, current_class_type,
8152 "destructor for alien class `%s' cannot be a member"))
8153 return void_type_node;
8156 else /* it's a constructor. */
8160 /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may
8161 not be declared const or volatile. A constructor may
8162 not be virtual. A constructor may not be static. */
8164 error ("constructor cannot be static member function");
8167 pedwarn ("constructors cannot be declared virtual");
8170 if (TYPE_READONLY (type))
8172 error ("constructors cannot be declared `const'");
8173 return void_type_node;
8175 if (TYPE_VOLATILE (type))
8177 error ("constructors cannot be declared `volatile'");
8178 return void_type_node;
8181 RID_BIT_TYPE tmp_bits;
8182 bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE));
8183 RIDBIT_RESET (RID_INLINE, tmp_bits);
8184 RIDBIT_RESET (RID_STATIC, tmp_bits);
8185 if (RIDBIT_ANY_SET (tmp_bits))
8186 error ("return value type specifier for constructor ignored");
8188 type = TYPE_POINTER_TO (ctype);
8189 if (decl_context == FIELD &&
8190 IS_SIGNATURE (current_class_type))
8192 error ("constructor not allowed in signature");
8193 return void_type_node;
8195 else if (decl_context == FIELD)
8197 if (! member_function_or_else (ctype, current_class_type,
8198 "constructor for alien class `%s' cannot be member"))
8199 return void_type_node;
8200 TYPE_HAS_CONSTRUCTOR (ctype) = 1;
8201 if (return_type != return_ctor)
8205 if (decl_context == FIELD)
8208 else if (friendp && virtualp)
8210 /* Cannot be both friend and virtual. */
8211 error ("virtual functions cannot be friends");
8212 RIDBIT_RESET (RID_FRIEND, specbits);
8216 if (decl_context == NORMAL && friendp)
8217 error ("friend declaration not in class definition");
8219 /* Pick up type qualifiers which should be applied to `this'. */
8220 quals = TREE_OPERAND (declarator, 2);
8222 /* Traditionally, declaring return type float means double. */
8224 if (flag_traditional
8225 && TYPE_MAIN_VARIANT (type) == float_type_node)
8227 type = build_type_variant (double_type_node,
8228 TYPE_READONLY (type),
8229 TYPE_VOLATILE (type));
8232 /* Construct the function type and go to the next
8233 inner layer of declarator. */
8235 declarator = TREE_OPERAND (declarator, 0);
8237 /* FIXME: This is where default args should be fully
8240 arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0);
8244 /* Get past destructors, etc.
8245 We know we have one because FLAGS will be non-zero.
8247 Complain about improper parameter lists here. */
8248 if (TREE_CODE (declarator) == BIT_NOT_EXPR)
8250 declarator = TREE_OPERAND (declarator, 0);
8252 if (strict_prototype == 0 && arg_types == NULL_TREE)
8253 arg_types = void_list_node;
8254 else if (arg_types == NULL_TREE
8255 || arg_types != void_list_node)
8257 error ("destructors cannot be specified with parameters");
8258 arg_types = void_list_node;
8263 /* ANSI seems to say that `const int foo ();'
8264 does not make the function foo const. */
8265 type = build_function_type (type,
8266 flag_traditional ? 0 : arg_types);
8272 /* Filter out pointers-to-references and references-to-references.
8273 We can get these if a TYPE_DECL is used. */
8275 if (TREE_CODE (type) == REFERENCE_TYPE)
8277 error ("cannot declare %s to references",
8278 TREE_CODE (declarator) == ADDR_EXPR
8279 ? "references" : "pointers");
8280 declarator = TREE_OPERAND (declarator, 0);
8284 /* Merge any constancy or volatility into the target type
8287 if (constp || volatilep)
8289 /* A const or volatile signature pointer/reference is
8290 pointing to a const or volatile object, i.e., the
8291 `optr' is const or volatile, respectively, not the
8292 signature pointer/reference itself. */
8293 if (! IS_SIGNATURE (type))
8295 type = cp_build_type_variant (type, constp, volatilep);
8296 if (IS_AGGR_TYPE (type))
8297 build_pointer_type (type);
8303 if (IS_SIGNATURE (type))
8305 if (TREE_CODE (declarator) == ADDR_EXPR)
8307 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
8308 && TYPE_SIZE (type))
8309 cp_warning ("empty signature `%T' used in signature reference declaration",
8312 type = build_signature_reference_type (type,
8315 sorry ("signature reference");
8321 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
8322 && TYPE_SIZE (type))
8323 cp_warning ("empty signature `%T' used in signature pointer declaration",
8325 type = build_signature_pointer_type (type,
8331 else if (TREE_CODE (declarator) == ADDR_EXPR)
8333 if (TREE_CODE (type) == FUNCTION_TYPE)
8335 error ("cannot declare references to functions; use pointer to function instead");
8336 type = build_pointer_type (type);
8340 if (TYPE_MAIN_VARIANT (type) == void_type_node)
8341 error ("invalid type: `void &'");
8343 type = build_reference_type (type);
8346 else if (TREE_CODE (type) == METHOD_TYPE)
8348 type = build_ptrmemfunc_type (build_pointer_type (type));
8351 type = build_pointer_type (type);
8353 /* Process a list of type modifier keywords (such as
8354 const or volatile) that were given inside the `*' or `&'. */
8356 if (TREE_TYPE (declarator))
8358 register tree typemodlist;
8360 for (typemodlist = TREE_TYPE (declarator); typemodlist;
8361 typemodlist = TREE_CHAIN (typemodlist))
8363 if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
8365 else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
8370 error ("invalid type modifier within %s declarator",
8371 TREE_CODE (declarator) == ADDR_EXPR
8372 ? "reference" : "pointer");
8376 pedwarn ("duplicate `const'");
8378 pedwarn ("duplicate `volatile'");
8379 if (TREE_CODE (declarator) == ADDR_EXPR
8380 && (constp || volatilep))
8383 warning ("discarding `const' applied to a reference");
8385 warning ("discarding `volatile' applied to a reference");
8386 constp = volatilep = 0;
8389 declarator = TREE_OPERAND (declarator, 0);
8395 /* We have converted type names to NULL_TREE if the
8396 name was bogus, or to a _TYPE node, if not.
8398 The variable CTYPE holds the type we will ultimately
8399 resolve to. The code here just needs to build
8400 up appropriate member types. */
8401 tree sname = TREE_OPERAND (declarator, 1);
8402 /* Destructors can have their visibilities changed as well. */
8403 if (TREE_CODE (sname) == BIT_NOT_EXPR)
8404 sname = TREE_OPERAND (sname, 0);
8406 if (TREE_COMPLEXITY (declarator) == 0)
8407 /* This needs to be here, in case we are called
8408 multiple times. */ ;
8409 else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
8410 /* don't fall out into global scope. Hides real bug? --eichin */ ;
8411 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
8413 /* This pop_nested_class corresponds to the
8414 push_nested_class used to push into class scope for
8415 parsing the argument list of a function decl, in
8417 pop_nested_class (1);
8418 TREE_COMPLEXITY (declarator) = current_class_depth;
8421 my_friendly_abort (16);
8423 if (TREE_OPERAND (declarator, 0) == NULL_TREE)
8425 /* We had a reference to a global decl, or
8426 perhaps we were given a non-aggregate typedef,
8427 in which case we cleared this out, and should just
8428 keep going as though it wasn't there. */
8432 ctype = TREE_OPERAND (declarator, 0);
8434 if (sname == NULL_TREE)
8437 if (TREE_CODE (sname) == IDENTIFIER_NODE)
8439 /* This is the `standard' use of the scoping operator:
8440 basetype :: member . */
8442 if (ctype == current_class_type)
8443 cp_pedwarn ("extra qualification `%T::' on member `%s' ignored",
8445 else if (TREE_CODE (type) == FUNCTION_TYPE)
8447 if (current_class_type == NULL_TREE
8449 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8450 TREE_TYPE (type), TYPE_ARG_TYPES (type));
8453 cp_error ("cannot declare member function `%T::%s' within `%T'",
8454 ctype, name, current_class_type);
8455 return void_type_node;
8458 else if (TYPE_SIZE (ctype) != NULL_TREE
8459 || (RIDBIT_SETP (RID_TYPEDEF, specbits)))
8462 /* have to move this code elsewhere in this function.
8463 this code is used for i.e., typedef int A::M; M *pm;
8465 It is? How? jason 10/2/94 */
8467 if (explicit_int == -1 && decl_context == FIELD
8468 && funcdef_flag == 0)
8470 /* The code in here should only be used to build
8471 stuff that will be grokked as access decls. */
8472 t = lookup_field (ctype, sname, 0, 0);
8475 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
8476 DECL_INITIAL (t) = init;
8479 /* No such field, try member functions. */
8480 t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
8483 if (flags == DTOR_FLAG)
8485 else if (CLASSTYPE_METHOD_VEC (ctype)
8486 && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
8488 /* Don't include destructor with constructors. */
8489 t = DECL_CHAIN (TREE_VALUE (t));
8491 cp_error ("`%T' does not have any constructors",
8493 t = build_tree_list (NULL_TREE, t);
8495 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
8496 DECL_INITIAL (t) = init;
8501 ("field `%D' is not a member of structure `%T'",
8505 if (current_class_type)
8507 cp_error ("cannot declare member `%T::%s' within `%T'",
8508 ctype, name, current_class_type);
8509 return void_type_node;
8511 type = build_offset_type (ctype, type);
8513 else if (uses_template_parms (ctype))
8516 if (TREE_CODE (type) == FUNCTION_TYPE)
8518 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8520 TYPE_ARG_TYPES (type));
8526 cp_error ("structure `%T' not yet defined", ctype);
8527 return error_mark_node;
8532 else if (TREE_CODE (sname) == SCOPE_REF)
8533 my_friendly_abort (17);
8537 declarator = TREE_OPERAND (declarator, 1);
8538 if (declarator && TREE_CODE (declarator) == CALL_EXPR)
8539 /* In this case, we will deal with it later. */
8543 if (TREE_CODE (type) == FUNCTION_TYPE)
8544 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
8546 type = build_offset_type (ctype, type);
8553 declarator = TREE_OPERAND (declarator, 0);
8559 declarator = NULL_TREE;
8563 declarator = NULL_TREE;
8567 my_friendly_abort (158);
8573 error ("only constructors can be declared `explicit'");
8577 /* Now TYPE has the actual type. */
8579 /* If this is declaring a typedef name, return a TYPE_DECL. */
8581 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8585 /* Note that the grammar rejects storage classes
8586 in typenames, fields or parameters. */
8587 if (constp || volatilep)
8588 type = cp_build_type_variant (type, constp, volatilep);
8590 /* If the user declares "struct {...} foo" then `foo' will have
8591 an anonymous name. Fill that name in now. Nothing can
8592 refer to it, so nothing needs know about the name change.
8593 The TYPE_NAME field was filled in by build_struct_xref. */
8594 if (type != error_mark_node
8596 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8597 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
8599 /* replace the anonymous name with the real name everywhere. */
8600 lookup_tag_reverse (type, declarator);
8601 TYPE_IDENTIFIER (type) = declarator;
8603 if (TYPE_LANG_SPECIFIC (type))
8604 TYPE_WAS_ANONYMOUS (type) = 1;
8607 tree d = TYPE_NAME (type), c = DECL_CONTEXT (d);
8610 set_nested_typename (d, 0, declarator, type);
8611 else if (TREE_CODE (c) == FUNCTION_DECL)
8612 set_nested_typename (d, DECL_ASSEMBLER_NAME (c),
8615 set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type);
8617 DECL_ASSEMBLER_NAME (d) = DECL_NAME (d);
8618 DECL_ASSEMBLER_NAME (d)
8619 = get_identifier (build_overload_name (type, 1, 1));
8623 #if 0 /* not yet, should get fixed properly later */
8624 decl = make_type_decl (declarator, type);
8626 decl = build_decl (TYPE_DECL, declarator, type);
8628 if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
8630 cp_error_at ("typedef name may not be class-qualified", decl);
8635 if (ctype == NULL_TREE)
8637 if (TREE_CODE (type) != METHOD_TYPE)
8638 cp_error_at ("invalid type qualifier for non-method type", decl);
8640 ctype = TYPE_METHOD_BASETYPE (type);
8642 if (ctype != NULL_TREE)
8643 grok_method_quals (ctype, decl, quals);
8646 if (RIDBIT_SETP (RID_SIGNED, specbits)
8647 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
8648 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
8650 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8652 error ("non-object member `%s' cannot be declared mutable", name);
8658 /* Detect the case of an array type of unspecified size
8659 which came, as such, direct from a typedef name.
8660 We must copy the type, so that each identifier gets
8661 a distinct type, so that each identifier's size can be
8662 controlled separately by its own initializer. */
8664 if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
8665 && TYPE_DOMAIN (type) == NULL_TREE)
8667 type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
8670 /* If this is a type name (such as, in a cast or sizeof),
8671 compute the type and return it now. */
8673 if (decl_context == TYPENAME)
8675 /* Note that the grammar rejects storage classes
8676 in typenames, fields or parameters. */
8677 if (constp || volatilep)
8678 if (IS_SIGNATURE (type))
8679 error ("`const' or `volatile' specified with signature type");
8681 type = cp_build_type_variant (type, constp, volatilep);
8683 /* Special case: "friend class foo" looks like a TYPENAME context. */
8686 /* A friendly class? */
8687 if (current_class_type)
8688 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
8690 error("trying to make class `%s' a friend of global scope",
8691 TYPE_NAME_STRING (type));
8692 type = void_type_node;
8696 #if 0 /* not yet, should get fixed properly later */
8697 tree dummy = make_type_decl (declarator, type);
8699 tree dummy = build_decl (TYPE_DECL, declarator, type);
8701 if (ctype == NULL_TREE)
8703 my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
8704 ctype = TYPE_METHOD_BASETYPE (type);
8706 grok_method_quals (ctype, dummy, quals);
8707 type = TREE_TYPE (dummy);
8712 else if (declarator == NULL_TREE && decl_context != PARM
8713 && decl_context != CATCHPARM
8714 && TREE_CODE (type) != UNION_TYPE
8717 cp_error ("abstract declarator `%T' used as declaration", type);
8718 declarator = make_anon_name ();
8721 /* `void' at top level (not within pointer)
8722 is allowed only in typedefs or type names.
8723 We don't complain about parms either, but that is because
8724 a better error message can be made later. */
8726 if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
8728 if (TREE_CODE (declarator) == IDENTIFIER_NODE)
8730 if (IDENTIFIER_OPNAME_P (declarator))
8731 #if 0 /* How could this happen? */
8732 error ("operator `%s' declared void",
8733 operator_name_string (declarator));
8735 my_friendly_abort (356);
8738 error ("variable or field `%s' declared void", name);
8741 error ("variable or field declared void");
8742 type = integer_type_node;
8745 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
8746 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
8751 if (decl_context == PARM)
8754 error ("cannot use `::' in parameter declaration");
8756 /* A parameter declared as an array of T is really a pointer to T.
8757 One declared as a function is really a pointer to a function.
8758 One declared as a member is really a pointer to member. */
8760 if (TREE_CODE (type) == ARRAY_TYPE)
8762 /* Transfer const-ness of array into that of type pointed to. */
8763 type = build_pointer_type
8764 (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
8765 volatilep = constp = 0;
8767 else if (TREE_CODE (type) == FUNCTION_TYPE)
8768 type = build_pointer_type (type);
8769 else if (TREE_CODE (type) == OFFSET_TYPE)
8770 type = build_pointer_type (type);
8772 decl = build_decl (PARM_DECL, declarator, type);
8774 bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
8775 inlinep, friendp, raises != NULL_TREE);
8776 if (current_class_type
8777 && IS_SIGNATURE (current_class_type))
8780 error ("parameter of signature member function declared `inline'");
8781 if (RIDBIT_SETP (RID_AUTO, specbits))
8782 error ("parameter of signature member function declared `auto'");
8783 if (RIDBIT_SETP (RID_REGISTER, specbits))
8784 error ("parameter of signature member function declared `register'");
8787 /* Compute the type actually passed in the parmlist,
8788 for the case where there is no prototype.
8789 (For example, shorts and chars are passed as ints.)
8790 When there is a prototype, this is overridden later. */
8792 DECL_ARG_TYPE (decl) = type_promotes_to (type);
8794 else if (decl_context == FIELD)
8796 if (type == error_mark_node)
8798 /* Happens when declaring arrays of sizes which
8799 are error_mark_node, for example. */
8802 else if (TREE_CODE (type) == FUNCTION_TYPE)
8808 if (ctype == NULL_TREE)
8809 ctype = current_class_type;
8811 if (ctype == NULL_TREE)
8813 cp_error ("can't make `%D' into a method -- not in a class",
8815 return void_type_node;
8818 /* ``A union may [ ... ] not [ have ] virtual functions.''
8820 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
8822 cp_error ("function `%D' declared virtual inside a union",
8824 return void_type_node;
8827 if (declarator == ansi_opname[(int) NEW_EXPR]
8828 || declarator == ansi_opname[(int) VEC_NEW_EXPR]
8829 || declarator == ansi_opname[(int) DELETE_EXPR]
8830 || declarator == ansi_opname[(int) VEC_DELETE_EXPR])
8834 cp_error ("`%D' cannot be declared virtual, since it is always static",
8839 else if (staticp < 2)
8840 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8841 TREE_TYPE (type), TYPE_ARG_TYPES (type));
8844 /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
8845 publicp = (RIDBIT_SETP (RID_EXTERN, specbits)
8846 || (ctype != NULL_TREE
8847 && funcdef_flag >= 0
8848 && RIDBIT_NOTSETP (RID_INLINE, specbits))
8851 && RIDBIT_NOTSETP (RID_STATIC, specbits)
8852 && RIDBIT_NOTSETP (RID_INLINE, specbits)));
8853 decl = grokfndecl (ctype, type, declarator,
8854 virtualp, flags, quals,
8855 raises, friendp ? -1 : 0, publicp);
8856 if (decl == NULL_TREE)
8860 DECL_NONCONVERTING_P (decl) = 1;
8862 DECL_INLINE (decl) = inlinep;
8864 else if (TREE_CODE (type) == METHOD_TYPE)
8866 /* All method decls are public, so tell grokfndecl to set
8867 TREE_PUBLIC, also. */
8868 decl = grokfndecl (ctype, type, declarator,
8869 virtualp, flags, quals,
8870 raises, friendp ? -1 : 0, 1);
8871 if (decl == NULL_TREE)
8874 DECL_INLINE (decl) = inlinep;
8876 else if (TYPE_SIZE (type) == NULL_TREE && !staticp
8877 && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
8879 cp_error ("field `%D' has incomplete type", declarator);
8881 /* If we're instantiating a template, tell them which
8882 instantiation made the field's type be incomplete. */
8883 if (current_class_type
8884 && TYPE_NAME (current_class_type)
8885 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type)))
8886 && declspecs && TREE_VALUE (declspecs)
8887 && TREE_TYPE (TREE_VALUE (declspecs)) == type)
8888 cp_error (" in instantiation of template `%T'",
8889 current_class_type);
8891 type = error_mark_node;
8898 error ("`%s' is neither function nor method; cannot be declared friend",
8899 IDENTIFIER_POINTER (declarator));
8907 /* Friends are treated specially. */
8908 if (ctype == current_class_type)
8909 warning ("member functions are implicitly friends of their class");
8913 if (decl && DECL_NAME (decl))
8914 t = do_friend (ctype, declarator, decl,
8915 last_function_parms, flags, quals);
8916 if (t && funcdef_flag)
8919 return void_type_node;
8923 /* Structure field. It may not be a function, except for C++ */
8925 if (decl == NULL_TREE)
8929 /* Motion 10 at San Diego: If a static const integral data
8930 member is initialized with an integral constant
8931 expression, the initializer may appear either in the
8932 declaration (within the class), or in the definition,
8933 but not both. If it appears in the class, the member is
8934 a member constant. The file-scope definition is always
8941 cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
8944 else if (! INTEGRAL_TYPE_P (type))
8945 cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type);
8949 /* Note that initialization of const members is prohibited
8950 by the draft ANSI standard, though it appears to be in
8951 common practice. 12.6.2: The argument list is used to
8952 initialize the named nonstatic member.... This (or an
8953 initializer list) is the only way to initialize
8954 nonstatic const and reference members. */
8955 else if (flag_ansi || ! constp)
8956 cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
8957 constp ? "const member" : "member", declarator);
8960 if (staticp || (constp && initialized))
8962 /* C++ allows static class members.
8963 All other work for this is done by grokfield.
8964 This VAR_DECL is built by build_lang_field_decl.
8965 All other VAR_DECLs are built by build_decl. */
8966 decl = build_lang_field_decl (VAR_DECL, declarator, type);
8967 TREE_STATIC (decl) = 1;
8968 /* In class context, 'static' means public access. */
8969 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp;
8973 decl = build_lang_field_decl (FIELD_DECL, declarator, type);
8974 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8976 DECL_MUTABLE_P (decl) = 1;
8977 RIDBIT_RESET (RID_MUTABLE, specbits);
8981 bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
8982 inlinep, friendp, raises != NULL_TREE);
8985 else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
8987 tree original_name = declarator;
8993 if (RIDBIT_SETP (RID_AUTO, specbits))
8994 error ("storage class `auto' invalid for function `%s'", name);
8995 else if (RIDBIT_SETP (RID_REGISTER, specbits))
8996 error ("storage class `register' invalid for function `%s'", name);
8998 /* Function declaration not at top level.
8999 Storage classes other than `extern' are not allowed
9000 and `extern' makes no difference. */
9001 if (current_binding_level != global_binding_level
9002 && ! processing_template_decl
9003 && (RIDBIT_SETP (RID_STATIC, specbits)
9004 || RIDBIT_SETP (RID_INLINE, specbits))
9007 if (RIDBIT_SETP (RID_STATIC, specbits))
9008 pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name);
9010 pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name);
9013 if (ctype == NULL_TREE)
9017 error ("virtual non-class function `%s'", name);
9021 if (current_lang_name == lang_name_cplusplus
9022 && ! (IDENTIFIER_LENGTH (original_name) == 4
9023 && IDENTIFIER_POINTER (original_name)[0] == 'm'
9024 && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
9025 && ! (IDENTIFIER_LENGTH (original_name) > 10
9026 && IDENTIFIER_POINTER (original_name)[0] == '_'
9027 && IDENTIFIER_POINTER (original_name)[1] == '_'
9028 && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
9029 /* Plain overloading: will not be grok'd by grokclassfn. */
9030 declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
9032 else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
9033 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
9034 TREE_TYPE (type), TYPE_ARG_TYPES (type));
9036 /* Record presence of `static'. In C++, `inline' is like `static'. */
9038 = !(RIDBIT_SETP (RID_STATIC, specbits)
9039 || RIDBIT_SETP (RID_INLINE, specbits));
9041 decl = grokfndecl (ctype, type, original_name,
9042 virtualp, flags, quals,
9044 processing_template_decl ? 0 : friendp ? 2 : 1,
9046 if (decl == NULL_TREE)
9049 if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
9050 DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator);
9054 int illegal_static = 0;
9056 /* Don't allow a static member function in a class, and forbid
9057 declaring main to be static. */
9058 if (TREE_CODE (type) == METHOD_TYPE)
9060 cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl);
9064 && IDENTIFIER_LENGTH (original_name) == 4
9065 && IDENTIFIER_POINTER (original_name)[0] == 'm'
9066 && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
9068 error ("cannot declare function `main' to have static linkage");
9071 else if (current_function_decl)
9073 /* FIXME need arm citation */
9074 error ("cannot declare static function inside another function");
9081 RIDBIT_RESET (RID_STATIC, specbits);
9085 /* Record presence of `inline', if it is reasonable. */
9088 tree last = tree_last (TYPE_ARG_TYPES (type));
9091 && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
9092 error ("cannot inline function `main'");
9093 else if (last && last != void_list_node)
9094 cp_warning ("cannot inline function `%D' which takes `...'", original_name);
9096 /* Assume that otherwise the function can be inlined. */
9097 DECL_INLINE (decl) = 1;
9099 if (RIDBIT_SETP (RID_EXTERN, specbits))
9101 current_extern_inline = 1;
9103 pedwarn ("ANSI C++ does not permit `extern inline'");
9109 /* It's a variable. */
9111 if (decl_context == CATCHPARM)
9116 error ("cannot use `::' in parameter declaration");
9119 /* A parameter declared as an array of T is really a pointer to T.
9120 One declared as a function is really a pointer to a function.
9121 One declared as a member is really a pointer to member. */
9123 if (TREE_CODE (type) == ARRAY_TYPE)
9125 /* Transfer const-ness of array into that of type pointed to. */
9126 type = build_pointer_type
9127 (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
9128 volatilep = constp = 0;
9130 else if (TREE_CODE (type) == FUNCTION_TYPE)
9131 type = build_pointer_type (type);
9132 else if (TREE_CODE (type) == OFFSET_TYPE)
9133 type = build_pointer_type (type);
9136 /* An uninitialized decl with `extern' is a reference. */
9137 decl = grokvardecl (type, declarator, specbits, initialized);
9138 bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
9139 inlinep, friendp, raises != NULL_TREE);
9143 DECL_CONTEXT (decl) = ctype;
9146 cp_error ("static member `%D' re-declared as static",
9149 RIDBIT_RESET (RID_STATIC, specbits);
9151 if (RIDBIT_SETP (RID_EXTERN, specbits))
9153 cp_error ("cannot explicitly declare member `%#D' to have extern linkage",
9155 RIDBIT_RESET (RID_EXTERN, specbits);
9160 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9162 error ("`%s' cannot be declared mutable", name);
9165 /* Record `register' declaration for warnings on &
9166 and in case doing stupid register allocation. */
9168 if (RIDBIT_SETP (RID_REGISTER, specbits))
9169 DECL_REGISTER (decl) = 1;
9171 if (RIDBIT_SETP (RID_EXTERN, specbits))
9172 DECL_THIS_EXTERN (decl) = 1;
9174 /* Record constancy and volatility. */
9177 TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
9180 TREE_SIDE_EFFECTS (decl) = 1;
9181 TREE_THIS_VOLATILE (decl) = 1;
9188 /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
9189 An empty exprlist is a parmlist. An exprlist which
9190 contains only identifiers at the global level
9191 is a parmlist. Otherwise, it is an exprlist. */
9193 parmlist_is_exprlist (exprs)
9196 if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
9199 if (current_binding_level == global_binding_level)
9201 /* At the global level, if these are all identifiers,
9202 then it is a parmlist. */
9205 if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
9207 exprs = TREE_CHAIN (exprs);
9214 /* Subroutine of `grokparms'. In a fcn definition, arg types must
9217 C++: also subroutine of `start_function'. */
9219 require_complete_types_for_parms (parms)
9224 tree type = TREE_TYPE (parms);
9225 if (TYPE_SIZE (type) == NULL_TREE)
9227 if (DECL_NAME (parms))
9228 error ("parameter `%s' has incomplete type",
9229 IDENTIFIER_POINTER (DECL_NAME (parms)));
9231 error ("parameter has incomplete type");
9232 TREE_TYPE (parms) = error_mark_node;
9235 /* If the arg types are incomplete in a declaration,
9236 they must include undefined tags.
9237 These tags can never be defined in the scope of the declaration,
9238 so the types can never be completed,
9239 and no call can be compiled successfully. */
9240 /* This is not the right behavior for C++, but not having
9241 it is also probably wrong. */
9244 /* Now warn if is a pointer to an incomplete type. */
9245 while (TREE_CODE (type) == POINTER_TYPE
9246 || TREE_CODE (type) == REFERENCE_TYPE)
9247 type = TREE_TYPE (type);
9248 type = TYPE_MAIN_VARIANT (type);
9249 if (TYPE_SIZE (type) == NULL_TREE)
9251 if (DECL_NAME (parm) != NULL_TREE)
9252 warning ("parameter `%s' points to incomplete type",
9253 IDENTIFIER_POINTER (DECL_NAME (parm)));
9255 warning ("parameter points to incomplete type");
9259 parms = TREE_CHAIN (parms);
9263 /* Decode the list of parameter types for a function type.
9264 Given the list of things declared inside the parens,
9265 return a list of types.
9267 The list we receive can have three kinds of elements:
9268 an IDENTIFIER_NODE for names given without types,
9269 a TREE_LIST node for arguments given as typespecs or names with typespecs,
9270 or void_type_node, to mark the end of an argument list
9271 when additional arguments are not permitted (... was not used).
9273 FUNCDEF_FLAG is nonzero for a function definition, 0 for
9274 a mere declaration. A nonempty identifier-list gets an error message
9275 when FUNCDEF_FLAG is zero.
9276 If FUNCDEF_FLAG is 1, then parameter types must be complete.
9277 If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
9279 If all elements of the input list contain types,
9280 we return a list of the types.
9281 If all elements contain no type (except perhaps a void_type_node
9282 at the end), we return a null list.
9283 If some have types and some do not, it is an error, and we
9286 Also set last_function_parms to either
9287 a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
9288 A list of names is converted to a chain of PARM_DECLs
9289 by store_parm_decls so that ultimately it is always a chain of decls.
9291 Note that in C++, parameters can take default values. These default
9292 values are in the TREE_PURPOSE field of the TREE_LIST. It is
9293 an error to specify default values which are followed by parameters
9294 that have no default values, or an ELLIPSES. For simplicities sake,
9295 only parameters which are specified with their types can take on
9299 grokparms (first_parm, funcdef_flag)
9303 tree result = NULL_TREE;
9304 tree decls = NULL_TREE;
9306 if (first_parm != NULL_TREE
9307 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
9310 pedwarn ("parameter names (without types) in function declaration");
9311 last_function_parms = first_parm;
9314 else if (first_parm != NULL_TREE
9315 && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
9316 && TREE_VALUE (first_parm) != void_type_node)
9317 my_friendly_abort (145);
9320 /* Types were specified. This is a list of declarators
9321 each represented as a TREE_LIST node. */
9322 register tree parm, chain;
9323 int any_init = 0, any_error = 0, saw_void = 0;
9325 if (first_parm != NULL_TREE)
9327 tree last_result = NULL_TREE;
9328 tree last_decl = NULL_TREE;
9330 for (parm = first_parm; parm != NULL_TREE; parm = chain)
9332 tree type, list_node = parm;
9333 register tree decl = TREE_VALUE (parm);
9334 tree init = TREE_PURPOSE (parm);
9336 chain = TREE_CHAIN (parm);
9337 /* @@ weak defense against parse errors. */
9338 if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
9340 /* Give various messages as the need arises. */
9341 if (TREE_CODE (decl) == STRING_CST)
9342 error ("invalid string constant `%s'",
9343 TREE_STRING_POINTER (decl));
9344 else if (TREE_CODE (decl) == INTEGER_CST)
9345 error ("invalid integer constant in parameter list, did you forget to give parameter name?");
9349 if (decl != void_type_node)
9351 /* @@ May need to fetch out a `raises' here. */
9352 decl = grokdeclarator (TREE_VALUE (decl),
9353 TREE_PURPOSE (decl),
9354 PARM, init != NULL_TREE, NULL_TREE);
9357 type = TREE_TYPE (decl);
9358 if (TYPE_MAIN_VARIANT (type) == void_type_node)
9359 decl = void_type_node;
9360 else if (TREE_CODE (type) == METHOD_TYPE)
9362 if (DECL_NAME (decl))
9363 /* Cannot use `error_with_decl' here because
9364 we don't have DECL_CONTEXT set up yet. */
9365 error ("parameter `%s' invalidly declared method type",
9366 IDENTIFIER_POINTER (DECL_NAME (decl)));
9368 error ("parameter invalidly declared method type");
9369 type = build_pointer_type (type);
9370 TREE_TYPE (decl) = type;
9372 else if (TREE_CODE (type) == OFFSET_TYPE)
9374 if (DECL_NAME (decl))
9375 error ("parameter `%s' invalidly declared offset type",
9376 IDENTIFIER_POINTER (DECL_NAME (decl)));
9378 error ("parameter invalidly declared offset type");
9379 type = build_pointer_type (type);
9380 TREE_TYPE (decl) = type;
9382 else if (TREE_CODE (type) == RECORD_TYPE
9383 && TYPE_LANG_SPECIFIC (type)
9384 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
9386 abstract_virtuals_error (decl, type);
9387 any_error = 1; /* seems like a good idea */
9389 else if (TREE_CODE (type) == RECORD_TYPE
9390 && TYPE_LANG_SPECIFIC (type)
9391 && IS_SIGNATURE (type))
9393 signature_error (decl, type);
9394 any_error = 1; /* seems like a good idea */
9398 if (decl == void_type_node)
9400 if (result == NULL_TREE)
9402 result = void_list_node;
9403 last_result = result;
9407 TREE_CHAIN (last_result) = void_list_node;
9408 last_result = void_list_node;
9412 && (chain != void_list_node || TREE_CHAIN (chain)))
9413 error ("`void' in parameter list must be entire list");
9417 /* Since there is a prototype, args are passed in their own types. */
9418 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
9419 #ifdef PROMOTE_PROTOTYPES
9420 if ((TREE_CODE (type) == INTEGER_TYPE
9421 || TREE_CODE (type) == ENUMERAL_TYPE)
9422 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
9423 DECL_ARG_TYPE (decl) = integer_type_node;
9430 if (TREE_CODE (init) == SAVE_EXPR)
9431 PARM_DECL_EXPR (init) = 1;
9432 else if (TREE_CODE (init) == VAR_DECL)
9434 if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
9436 /* ``Local variables may not be used in default
9437 argument expressions.'' dpANSI C++ 8.2.6 */
9438 /* If extern int i; within a function is not
9439 considered a local variable, then this code is
9441 cp_error ("local variable `%D' may not be used as a default argument", init);
9444 else if (TREE_READONLY_DECL_P (init))
9445 init = decl_constant_value (init);
9448 init = require_instantiated_type (type, init, integer_zero_node);
9452 error ("all trailing parameters must have default arguments");
9459 if (decls == NULL_TREE)
9466 TREE_CHAIN (last_decl) = decl;
9469 if (TREE_PERMANENT (list_node))
9471 TREE_PURPOSE (list_node) = init;
9472 TREE_VALUE (list_node) = type;
9473 TREE_CHAIN (list_node) = NULL_TREE;
9476 list_node = saveable_tree_cons (init, type, NULL_TREE);
9477 if (result == NULL_TREE)
9480 last_result = result;
9484 TREE_CHAIN (last_result) = list_node;
9485 last_result = list_node;
9489 TREE_CHAIN (last_result) = NULL_TREE;
9490 /* If there are no parameters, and the function does not end
9491 with `...', then last_decl will be NULL_TREE. */
9492 if (last_decl != NULL_TREE)
9493 TREE_CHAIN (last_decl) = NULL_TREE;
9497 last_function_parms = decls;
9499 /* In a fcn definition, arg types must be complete. */
9500 if (funcdef_flag > 0)
9501 require_complete_types_for_parms (last_function_parms);
9506 /* These memoizing functions keep track of special properties which
9507 a class may have. `grok_ctor_properties' notices whether a class
9508 has a constructor of the form X(X&), and also complains
9509 if the class has a constructor of the form X(X).
9510 `grok_op_properties' takes notice of the various forms of
9511 operator= which are defined, as well as what sorts of type conversion
9512 may apply. Both functions take a FUNCTION_DECL as an argument. */
9514 grok_ctor_properties (ctype, decl)
9517 tree parmtypes = FUNCTION_ARG_CHAIN (decl);
9518 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
9520 /* When a type has virtual baseclasses, a magical first int argument is
9521 added to any ctor so we can tell if the class has been initialized
9522 yet. This could screw things up in this function, so we deliberately
9523 ignore the leading int if we're in that situation. */
9525 && TREE_VALUE (parmtypes) == integer_type_node
9526 && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
9528 parmtypes = TREE_CHAIN (parmtypes);
9529 parmtype = TREE_VALUE (parmtypes);
9532 if (TREE_CODE (parmtype) == REFERENCE_TYPE
9533 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
9535 if (TREE_CHAIN (parmtypes) == NULL_TREE
9536 || TREE_CHAIN (parmtypes) == void_list_node
9537 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
9539 TYPE_HAS_INIT_REF (ctype) = 1;
9540 if (TYPE_READONLY (TREE_TYPE (parmtype)))
9541 TYPE_HAS_CONST_INIT_REF (ctype) = 1;
9544 TYPE_GETS_INIT_AGGR (ctype) = 1;
9546 else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
9548 if (TREE_CHAIN (parmtypes) != NULL_TREE
9549 && TREE_CHAIN (parmtypes) == void_list_node)
9551 cp_error ("invalid constructor; you probably meant `%T (%T&)'",
9553 SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
9558 TYPE_GETS_INIT_AGGR (ctype) = 1;
9560 else if (TREE_CODE (parmtype) == VOID_TYPE
9561 || TREE_PURPOSE (parmtypes) != NULL_TREE)
9562 TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
9567 /* An operator with this name can be either unary or binary. */
9572 return (name == ansi_opname [(int) INDIRECT_REF]
9573 || name == ansi_opname [(int) ADDR_EXPR]
9574 || name == ansi_opname [(int) NEGATE_EXPR]
9575 || name == ansi_opname[(int) POSTINCREMENT_EXPR]
9576 || name == ansi_opname[(int) POSTDECREMENT_EXPR]
9577 || name == ansi_opname [(int) CONVERT_EXPR]);
9580 /* An operator with this name can only be unary. */
9585 return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
9586 || name == ansi_opname [(int) BIT_NOT_EXPR]
9587 || name == ansi_opname [(int) COMPONENT_REF]
9588 || OPERATOR_TYPENAME_P (name));
9591 /* Do a little sanity-checking on how they declared their operator. */
9593 grok_op_properties (decl, virtualp, friendp)
9595 int virtualp, friendp;
9597 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
9598 int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
9599 tree name = DECL_NAME (decl);
9601 if (current_class_type == NULL_TREE)
9606 if (name == ansi_opname[(int) MODIFY_EXPR])
9607 TYPE_HAS_ASSIGNMENT (current_class_type) = 1;
9608 else if (name == ansi_opname[(int) CALL_EXPR])
9609 TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1;
9610 else if (name == ansi_opname[(int) ARRAY_REF])
9611 TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1;
9612 else if (name == ansi_opname[(int) COMPONENT_REF]
9613 || name == ansi_opname[(int) MEMBER_REF])
9614 TYPE_OVERLOADS_ARROW (current_class_type) = 1;
9615 else if (name == ansi_opname[(int) NEW_EXPR])
9616 TYPE_GETS_NEW (current_class_type) |= 1;
9617 else if (name == ansi_opname[(int) DELETE_EXPR])
9618 TYPE_GETS_DELETE (current_class_type) |= 1;
9619 else if (name == ansi_opname[(int) VEC_NEW_EXPR])
9620 TYPE_GETS_NEW (current_class_type) |= 2;
9621 else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
9622 TYPE_GETS_DELETE (current_class_type) |= 2;
9625 if (name == ansi_opname[(int) NEW_EXPR]
9626 || name == ansi_opname[(int) VEC_NEW_EXPR])
9628 /* When the compiler encounters the definition of A::operator new, it
9629 doesn't look at the class declaration to find out if it's static. */
9631 revert_static_member_fn (&decl, NULL, NULL);
9633 /* Take care of function decl if we had syntax errors. */
9634 if (argtypes == NULL_TREE)
9636 build_function_type (ptr_type_node,
9637 hash_tree_chain (integer_type_node,
9640 TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
9642 else if (name == ansi_opname[(int) DELETE_EXPR]
9643 || name == ansi_opname[(int) VEC_DELETE_EXPR])
9646 revert_static_member_fn (&decl, NULL, NULL);
9648 if (argtypes == NULL_TREE)
9650 build_function_type (void_type_node,
9651 hash_tree_chain (ptr_type_node,
9655 TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
9657 if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR]
9658 && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))
9660 TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1;
9665 /* An operator function must either be a non-static member function
9666 or have at least one parameter of a class, a reference to a class,
9667 an enumeration, or a reference to an enumeration. 13.4.0.6 */
9668 if (! methodp || DECL_STATIC_FUNCTION_P (decl))
9670 if (OPERATOR_TYPENAME_P (name)
9671 || name == ansi_opname[(int) CALL_EXPR]
9672 || name == ansi_opname[(int) MODIFY_EXPR]
9673 || name == ansi_opname[(int) COMPONENT_REF]
9674 || name == ansi_opname[(int) ARRAY_REF])
9675 cp_error ("`%D' must be a nonstatic member function", decl);
9680 if (DECL_STATIC_FUNCTION_P (decl))
9681 cp_error ("`%D' must be either a non-static member function or a non-member function", decl);
9684 for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
9686 tree arg = TREE_VALUE (p);
9687 if (TREE_CODE (arg) == REFERENCE_TYPE)
9688 arg = TREE_TYPE (arg);
9690 /* This lets bad template code slip through. */
9691 if (IS_AGGR_TYPE (arg)
9692 || TREE_CODE (arg) == ENUMERAL_TYPE
9693 || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
9697 ("`%D' must have an argument of class or enumerated type",
9704 if (name == ansi_opname[(int) CALL_EXPR]
9705 || name == ansi_opname[(int) METHOD_CALL_EXPR])
9706 return; /* no restrictions on args */
9708 if (IDENTIFIER_TYPENAME_P (name))
9710 tree t = TREE_TYPE (name);
9711 if (TREE_CODE (t) == VOID_TYPE)
9712 pedwarn ("void is not a valid type conversion operator");
9715 int ref = (TREE_CODE (t) == REFERENCE_TYPE);
9718 t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
9720 if (t == current_class_type)
9721 what = "the same type";
9722 else if (IS_AGGR_TYPE (t)
9723 && DERIVED_FROM_P (t, current_class_type))
9724 what = "a base class";
9727 warning ("conversion to %s%s will never use a type conversion operator",
9728 ref ? "a reference to " : "", what);
9732 if (name == ansi_opname[(int) MODIFY_EXPR])
9736 if (list_length (argtypes) != 3 && methodp)
9738 cp_error ("`%D' must take exactly one argument", decl);
9741 parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
9743 if (copy_assignment_arg_p (parmtype, virtualp)
9746 TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
9747 if (TREE_CODE (parmtype) != REFERENCE_TYPE
9748 || TYPE_READONLY (TREE_TYPE (parmtype)))
9749 TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
9750 #if 0 /* Too soon; done in grok_function_init */
9751 if (DECL_ABSTRACT_VIRTUAL_P (decl))
9752 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
9756 else if (name == ansi_opname[(int) COND_EXPR])
9759 pedwarn ("ANSI C++ prohibits overloading operator ?:");
9760 if (list_length (argtypes) != 4)
9761 cp_error ("`%D' must take exactly three arguments", decl);
9763 else if (ambi_op_p (name))
9765 if (list_length (argtypes) == 2)
9767 else if (list_length (argtypes) == 3)
9769 if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
9770 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
9771 && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
9774 cp_error ("postfix `%D' must take `int' as its argument",
9778 ("postfix `%D' must take `int' as its second argument",
9785 cp_error ("`%D' must take either zero or one argument", decl);
9787 cp_error ("`%D' must take either one or two arguments", decl);
9790 else if (unary_op_p (name))
9792 if (list_length (argtypes) != 2)
9795 cp_error ("`%D' must take `void'", decl);
9797 cp_error ("`%D' must take exactly one argument", decl);
9800 else /* if (binary_op_p (name)) */
9802 if (list_length (argtypes) != 3)
9805 cp_error ("`%D' must take exactly one argument", decl);
9807 cp_error ("`%D' must take exactly two arguments", decl);
9813 for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
9814 if (TREE_PURPOSE (argtypes))
9816 TREE_PURPOSE (argtypes) = NULL_TREE;
9817 if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
9818 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
9821 cp_pedwarn ("`%D' cannot have default arguments", decl);
9824 cp_error ("`%D' cannot have default arguments", decl);
9829 /* Get the struct, enum or union (CODE says which) with tag NAME.
9830 Define the tag as a forward-reference if it is not defined.
9832 C++: If a class derivation is given, process it here, and report
9833 an error if multiple derivation declarations are not identical.
9835 If this is a definition, come in through xref_tag and only look in
9836 the current frame for the name (since C++ allows new names in any
9839 /* avoid rewriting all callers of xref_tag */
9840 static int xref_next_defn = 0;
9843 xref_defn_tag (code_type_node, name, binfo)
9844 tree code_type_node;
9850 if (class_binding_level)
9854 /* we need to build a new IDENTIFIER_NODE for name which nukes
9857 n1 = IDENTIFIER_LOCAL_VALUE (current_class_name);
9859 n1 = DECL_NAME (n1);
9861 n1 = current_class_name;
9863 n1 = TYPE_NAME (current_class_type);
9865 n1 = DECL_NESTED_TYPENAME(n1);
9867 n1 = current_class_name;
9869 buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1)
9870 + IDENTIFIER_LENGTH (name));
9872 sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1),
9873 IDENTIFIER_POINTER (name));
9874 ncp = get_identifier (buf);
9877 printf("*** %s ***\n", IDENTIFIER_POINTER (ncp));
9880 IDENTIFIER_LOCAL_VALUE (name) =
9881 build_decl (TYPE_DECL, ncp, NULL_TREE);
9883 rv = xref_tag (code_type_node, name, binfo, 0);
9884 if (! ANON_AGGRNAME_P (name))
9886 register tree type_decl = build_decl (TYPE_DECL, ncp, rv);
9887 SET_DECL_ARTIFICIAL (type_decl);
9888 #ifdef DWARF_DEBUGGING_INFO
9889 /* Mark the TYPE_DECL node created just above as a gratuitous one
9890 so that dwarfout.c will know not to generate a TAG_typedef DIE
9892 if (write_symbols == DWARF_DEBUG)
9893 DECL_IGNORED_P (type_decl) = 1;
9894 #endif /* DWARF_DEBUGGING_INFO */
9895 pushdecl_nonclass_level (type_decl);
9900 rv = xref_tag (code_type_node, name, binfo, 0);
9907 xref_tag (code_type_node, name, binfo, globalize)
9908 tree code_type_node;
9912 enum tag_types tag_code;
9913 enum tree_code code;
9916 register tree ref, t;
9917 struct binding_level *b = inner_binding_level;
9919 tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
9924 case signature_type:
9926 len = list_length (binfo);
9932 cp_error ("derived union `%T' invalid", name);
9938 code = ENUMERAL_TYPE;
9941 my_friendly_abort (18);
9944 /* If a cross reference is requested, look up the type
9945 already defined for this tag and return it. */
9946 t = IDENTIFIER_TYPE_VALUE (name);
9947 if (t && TREE_CODE (t) != code)
9952 /* If we know we are defining this tag, only look it up in this scope
9953 * and don't try to find it as a type. */
9955 if (t && TYPE_CONTEXT(t))
9957 if (TREE_MANGLED (name))
9960 ref = lookup_tag (code, name, b, 1);
9963 ref = lookup_tag (code, name, b, 1);
9970 ref = lookup_tag (code, name, b, 0);
9974 /* Try finding it as a type declaration. If that wins, use it. */
9975 ref = lookup_name (name, 1);
9976 if (ref && TREE_CODE (ref) == TYPE_DECL
9977 && TREE_CODE (TREE_TYPE (ref)) == code)
9978 ref = TREE_TYPE (ref);
9984 push_obstacks_nochange ();
9988 /* If no such tag is yet defined, create a forward-reference node
9989 and record it as the "definition".
9990 When a real declaration of this type is found,
9991 the forward-reference will be altered into a real type. */
9993 /* In C++, since these migrate into the global scope, we must
9994 build them on the permanent obstack. */
9996 temp = allocation_temporary_p ();
9998 end_temporary_allocation ();
10000 if (code == ENUMERAL_TYPE)
10002 ref = make_node (ENUMERAL_TYPE);
10004 /* Give the type a default layout like unsigned int
10005 to avoid crashing if it does not get defined. */
10006 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
10007 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
10008 TREE_UNSIGNED (ref) = 1;
10009 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
10010 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
10011 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
10013 /* Enable us to recognize when a type is created in class context.
10014 To do nested classes correctly, this should probably be cleared
10015 out when we leave this classes scope. Currently this in only
10016 done in `start_enum'. */
10018 pushtag (name, ref, globalize);
10020 cadillac_start_enum (ref);
10024 struct binding_level *old_b = class_binding_level;
10026 ref = make_lang_type (code);
10028 if (tag_code == signature_type)
10030 SET_SIGNATURE (ref);
10031 /* Since a signature type will be turned into the type
10032 of signature tables, it's not only an interface. */
10033 CLASSTYPE_INTERFACE_ONLY (ref) = 0;
10034 SET_CLASSTYPE_INTERFACE_KNOWN (ref);
10035 /* A signature doesn't have a vtable. */
10036 CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
10039 #ifdef NONNESTED_CLASSES
10040 /* Class types don't nest the way enums do. */
10041 class_binding_level = (struct binding_level *)0;
10043 pushtag (name, ref, globalize);
10044 class_binding_level = old_b;
10047 cadillac_start_struct (ref);
10052 /* If it no longer looks like a nested type, make sure it's
10053 in global scope. */
10054 if (b == global_binding_level && !class_binding_level
10055 && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
10056 IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
10061 tree tt2 = TYPE_BINFO_BASETYPES (ref);
10063 if (TYPE_BINFO_BASETYPES (ref))
10064 for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
10065 if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
10067 cp_error ("redeclaration of derivation chain of type `%#T'",
10072 if (tt1 == NULL_TREE)
10073 /* The user told us something we already knew. */
10076 /* In C++, since these migrate into the global scope, we must
10077 build them on the permanent obstack. */
10078 end_temporary_allocation ();
10084 /* In the declaration `A : X, Y, ... Z' we mark all the types
10085 (A, X, Y, ..., Z) so we can check for duplicates. */
10088 SET_CLASSTYPE_MARKED (ref);
10089 BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
10091 for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
10093 /* The base of a derived struct is public by default. */
10095 = (TREE_PURPOSE (binfo) == (tree)access_public
10096 || TREE_PURPOSE (binfo) == (tree)access_public_virtual
10097 || (tag_code != class_type
10098 && (TREE_PURPOSE (binfo) == (tree)access_default
10099 || TREE_PURPOSE (binfo) == (tree)access_default_virtual)));
10100 int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected;
10102 = (TREE_PURPOSE (binfo) == (tree)access_private_virtual
10103 || TREE_PURPOSE (binfo) == (tree)access_public_virtual
10104 || TREE_PURPOSE (binfo) == (tree)access_default_virtual);
10105 tree basetype = TREE_TYPE (TREE_VALUE (binfo));
10108 GNU_xref_hier (IDENTIFIER_POINTER (name),
10109 IDENTIFIER_POINTER (TREE_VALUE (binfo)),
10110 via_public, via_virtual, 0);
10112 if (basetype && TREE_CODE (basetype) == TYPE_DECL)
10113 basetype = TREE_TYPE (basetype);
10114 if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
10116 error ("base type `%s' fails to be a struct or class type",
10117 IDENTIFIER_POINTER (TREE_VALUE (binfo)));
10121 /* This code replaces similar code in layout_basetypes. */
10122 else if (TYPE_SIZE (basetype) == NULL_TREE)
10124 cp_error ("base class `%T' has incomplete type", basetype);
10130 if (CLASSTYPE_MARKED (basetype))
10132 if (basetype == ref)
10133 cp_error ("recursive type `%T' undefined", basetype);
10135 cp_error ("duplicate base type `%T' invalid", basetype);
10139 /* Note that the BINFO records which describe individual
10140 inheritances are *not* shared in the lattice! They
10141 cannot be shared because a given baseclass may be
10142 inherited with different `accessibility' by different
10143 derived classes. (Each BINFO record describing an
10144 individual inheritance contains flags which say what
10145 the `accessibility' of that particular inheritance is.) */
10147 base_binfo = make_binfo (integer_zero_node, basetype,
10148 TYPE_BINFO_VTABLE (basetype),
10149 TYPE_BINFO_VIRTUALS (basetype), NULL_TREE);
10151 TREE_VEC_ELT (binfos, i) = base_binfo;
10152 TREE_VIA_PUBLIC (base_binfo) = via_public;
10153 TREE_VIA_PROTECTED (base_binfo) = via_protected;
10154 TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
10155 BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref);
10157 SET_CLASSTYPE_MARKED (basetype);
10159 /* XYZZY TEST VIRTUAL BASECLASSES */
10160 if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE
10161 && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
10162 && via_virtual == 0)
10164 warning ("making type `%s' a virtual baseclass",
10165 TYPE_NAME_STRING (basetype));
10169 /* We are free to modify these bits because they are meaningless
10170 at top level, and BASETYPE is a top-level type. */
10171 if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
10173 TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
10174 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
10177 TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
10178 TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype);
10179 TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
10180 CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
10185 TREE_VEC_LENGTH (binfos) = i;
10187 BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
10190 TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
10192 TYPE_USES_MULTIPLE_INHERITANCE (ref)
10193 = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
10194 if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
10195 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
10197 /* Unmark all the types. */
10199 CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
10200 CLEAR_CLASSTYPE_MARKED (ref);
10205 /* Until the type is defined, tentatively accept whatever
10206 structure tag the user hands us. */
10207 if (TYPE_SIZE (ref) == NULL_TREE
10208 && ref != current_class_type
10209 /* Have to check this, in case we have contradictory tag info. */
10210 && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
10212 if (tag_code == class_type)
10213 CLASSTYPE_DECLARED_CLASS (ref) = 1;
10214 else if (tag_code == record_type || tag_code == signature_type)
10215 CLASSTYPE_DECLARED_CLASS (ref) = 0;
10223 static tree current_local_enum = NULL_TREE;
10225 /* Begin compiling the definition of an enumeration type.
10226 NAME is its name (or null if anonymous).
10227 Returns the type object, as yet incomplete.
10228 Also records info about it so that build_enumerator
10229 may be used to declare the individual values as they are read. */
10235 register tree enumtype = NULL_TREE;
10236 struct binding_level *b = inner_binding_level;
10238 /* If this is the real definition for a previous forward reference,
10239 fill in the contents in the same object that used to be the
10240 forward reference. */
10242 if (name != NULL_TREE)
10243 enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
10245 if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
10246 cp_error ("multiple definition of enum `%T'", enumtype);
10249 enumtype = make_node (ENUMERAL_TYPE);
10250 pushtag (name, enumtype, 0);
10253 if (current_class_type)
10254 TREE_ADDRESSABLE (b->tags) = 1;
10255 current_local_enum = NULL_TREE;
10257 #if 0 /* This stuff gets cleared in finish_enum anyway. */
10258 if (TYPE_VALUES (enumtype) != NULL_TREE)
10259 /* Completely replace its old definition.
10260 The old enumerators remain defined, however. */
10261 TYPE_VALUES (enumtype) = NULL_TREE;
10263 /* Initially, set up this enum as like `int'
10264 so that we can create the enumerators' declarations and values.
10265 Later on, the precision of the type may be changed and
10266 it may be laid out again. */
10268 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
10269 TYPE_SIZE (enumtype) = NULL_TREE;
10270 fixup_signed_type (enumtype);
10273 /* We copy this value because enumerated type constants
10274 are really of the type of the enumerator, not integer_type_node. */
10275 enum_next_value = copy_node (integer_zero_node);
10278 GNU_xref_decl (current_function_decl, enumtype);
10282 /* After processing and defining all the values of an enumeration type,
10283 install their decls in the enumeration type and finish it off.
10284 ENUMTYPE is the type object and VALUES a list of name-value pairs.
10285 Returns ENUMTYPE. */
10288 finish_enum (enumtype, values)
10289 register tree enumtype, values;
10291 register tree minnode, maxnode;
10292 /* Calculate the maximum value of any enumerator in this type. */
10296 register tree pair;
10297 register tree value = DECL_INITIAL (TREE_VALUE (values));
10299 /* Speed up the main loop by performing some precalculations */
10300 TREE_TYPE (TREE_VALUE (values)) = enumtype;
10301 TREE_TYPE (value) = enumtype;
10302 TREE_VALUE (values) = value;
10303 minnode = maxnode = value;
10305 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
10307 value = DECL_INITIAL (TREE_VALUE (pair));
10308 TREE_TYPE (TREE_VALUE (pair)) = enumtype;
10309 TREE_TYPE (value) = enumtype;
10310 TREE_VALUE (pair) = value;
10311 if (tree_int_cst_lt (maxnode, value))
10313 else if (tree_int_cst_lt (value, minnode))
10318 maxnode = minnode = integer_zero_node;
10320 TYPE_VALUES (enumtype) = values;
10323 int unsignedp = tree_int_cst_sgn (minnode) >= 0;
10324 int lowprec = min_precision (minnode, unsignedp);
10325 int highprec = min_precision (maxnode, unsignedp);
10326 int precision = MAX (lowprec, highprec);
10328 TYPE_SIZE (enumtype) = NULL_TREE;
10330 /* Lay out the type as though it were an integer. */
10331 if (! flag_short_enums && precision < TYPE_PRECISION (integer_type_node))
10333 TYPE_MIN_VALUE (enumtype) = minnode;
10334 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
10335 layout_type (enumtype);
10338 TYPE_PRECISION (enumtype) = precision;
10340 fixup_unsigned_type (enumtype);
10342 fixup_signed_type (enumtype);
10346 cadillac_finish_enum (enumtype);
10351 /* Fix up all variant types of this enum type. */
10352 for (tem = TYPE_MAIN_VARIANT (enumtype); tem;
10353 tem = TYPE_NEXT_VARIANT (tem))
10355 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
10356 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
10357 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
10358 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
10359 TYPE_MODE (tem) = TYPE_MODE (enumtype);
10360 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
10361 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
10362 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
10366 /* Finish debugging output for this type. */
10368 /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
10369 information should *not* be generated? I think not. */
10370 if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
10372 rest_of_type_compilation (enumtype, global_bindings_p ());
10377 /* Build and install a CONST_DECL for one value of the
10378 current enumeration type (one that was begun with start_enum).
10379 Return a tree-list containing the name and its value.
10380 Assignment of sequential values by default is handled here. */
10383 build_enumerator (name, value)
10387 /* Change this to zero if we find VALUE is not shareable. */
10390 /* Remove no-op casts from the value. */
10392 STRIP_TYPE_NOPS (value);
10394 /* Validate and default VALUE. */
10395 if (value != NULL_TREE)
10397 if (TREE_READONLY_DECL_P (value))
10399 value = decl_constant_value (value);
10403 if (TREE_CODE (value) == INTEGER_CST)
10405 value = default_conversion (value);
10406 constant_expression_warning (value);
10410 cp_error ("enumerator value for `%D' not integer constant", name);
10415 /* The order of things is reversed here so that we
10416 can check for possible sharing of enum values,
10417 to keep that from happening. */
10418 /* Default based on previous value. */
10419 if (value == NULL_TREE)
10421 value = enum_next_value;
10423 cp_error ("overflow in enumeration values at `%D'", name);
10426 /* Remove no-op casts from the value. */
10428 STRIP_TYPE_NOPS (value);
10430 /* Make up for hacks in lex.c. */
10431 if (value == integer_zero_node)
10432 value = build_int_2 (0, 0);
10433 else if (value == integer_one_node)
10434 value = build_int_2 (1, 0);
10435 else if (TREE_CODE (value) == INTEGER_CST
10437 || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
10439 value = copy_node (value);
10440 TREE_TYPE (value) = integer_type_node;
10443 /* C++ associates enums with global, function, or class declarations. */
10445 decl = current_scope ();
10446 if (decl && decl == current_class_type)
10448 /* This enum declaration is local to the class, so we must put
10449 it in that class's list of decls. */
10450 decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
10451 DECL_INITIAL (decl) = value;
10452 TREE_READONLY (decl) = 1;
10453 pushdecl_class_level (decl);
10454 TREE_CHAIN (decl) = current_local_enum;
10455 current_local_enum = decl;
10459 /* It's a global enum, or it's local to a function. (Note local to
10460 a function could mean local to a class method. */
10461 decl = build_decl (CONST_DECL, name, integer_type_node);
10462 DECL_INITIAL (decl) = value;
10465 GNU_xref_decl (current_function_decl, decl);
10468 /* Set basis for default for next value. */
10469 enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
10470 integer_one_node, PLUS_EXPR);
10471 enum_overflow = tree_int_cst_lt (enum_next_value, value);
10473 if (enum_next_value == integer_one_node)
10474 enum_next_value = copy_node (enum_next_value);
10476 result = saveable_tree_cons (name, decl, NULL_TREE);
10481 grok_enum_decls (type, decl)
10484 tree d = current_local_enum;
10486 if (d == NULL_TREE)
10491 TREE_TYPE (d) = type;
10492 if (TREE_CHAIN (d) == NULL_TREE)
10494 TREE_CHAIN (d) = decl;
10497 d = TREE_CHAIN (d);
10500 decl = current_local_enum;
10501 current_local_enum = NULL_TREE;
10506 /* Create the FUNCTION_DECL for a function definition.
10507 DECLSPECS and DECLARATOR are the parts of the declaration;
10508 they describe the function's name and the type it returns,
10509 but twisted together in a fashion that parallels the syntax of C.
10511 This function creates a binding context for the function body
10512 as well as setting up the FUNCTION_DECL in current_function_decl.
10514 Returns 1 on success. If the DECLARATOR is not suitable for a function
10515 (it defines a datum instead), we return 0, which tells
10516 yyparse to report a parse error.
10518 For C++, we must first check whether that datum makes any sense.
10519 For example, "class A local_a(1,2);" means that variable local_a
10520 is an aggregate of type A, which should have a constructor
10521 applied to it with the argument list [1, 2].
10523 @@ There is currently no way to retrieve the storage
10524 @@ allocated to FUNCTION (or all of its parms) if we return
10525 @@ something we had previously. */
10528 start_function (declspecs, declarator, raises, pre_parsed_p)
10529 tree declarator, declspecs, raises;
10532 tree decl1, olddecl;
10533 tree ctype = NULL_TREE;
10536 extern int have_extern_spec;
10537 extern int used_extern_spec;
10538 int doing_friend = 0;
10540 /* Sanity check. */
10541 my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
10542 my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
10544 /* Assume, until we see it does. */
10545 current_function_returns_value = 0;
10546 current_function_returns_null = 0;
10547 warn_about_return_type = 0;
10548 current_extern_inline = 0;
10549 current_function_assigns_this = 0;
10550 current_function_just_assigned_this = 0;
10551 current_function_parms_stored = 0;
10552 original_result_rtx = NULL_RTX;
10553 current_function_obstack_index = 0;
10554 current_function_obstack_usage = 0;
10556 clear_temp_name ();
10558 /* This should only be done once on the top most decl. */
10559 if (have_extern_spec && !used_extern_spec)
10561 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
10562 used_extern_spec = 1;
10567 decl1 = declarator;
10569 if (! DECL_ARGUMENTS (decl1)
10570 && !DECL_STATIC_FUNCTION_P (decl1)
10571 && DECL_CONTEXT (decl1)
10572 && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))
10573 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))))
10575 cp_error ("redeclaration of `%#D'", decl1);
10576 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
10577 cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
10578 else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
10579 cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
10582 last_function_parms = DECL_ARGUMENTS (decl1);
10583 last_function_parm_tags = NULL_TREE;
10584 fntype = TREE_TYPE (decl1);
10585 if (TREE_CODE (fntype) == METHOD_TYPE)
10586 ctype = TYPE_METHOD_BASETYPE (fntype);
10588 /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a
10589 class is in the (lexical) scope of the class in which it is
10591 if (!ctype && DECL_FRIEND_P (decl1))
10593 ctype = DECL_CLASS_CONTEXT (decl1);
10595 /* CTYPE could be null here if we're dealing with a template;
10596 for example, `inline friend float foo()' inside a template
10597 will have no CTYPE set. */
10598 if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
10604 if ( !(DECL_VINDEX (decl1)
10605 && write_virtuals >= 2
10606 && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)))
10607 current_extern_inline = DECL_THIS_EXTERN (decl1) && DECL_INLINE (decl1);
10609 raises = TYPE_RAISES_EXCEPTIONS (fntype);
10611 /* In a fcn definition, arg types must be complete. */
10612 require_complete_types_for_parms (last_function_parms);
10616 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises);
10617 /* If the declarator is not suitable for a function definition,
10618 cause a syntax error. */
10619 if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
10621 fntype = TREE_TYPE (decl1);
10623 restype = TREE_TYPE (fntype);
10624 if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
10625 && ! CLASSTYPE_GOT_SEMICOLON (restype))
10627 cp_error ("semicolon missing after declaration of `%#T'", restype);
10628 shadow_tag (build_tree_list (NULL_TREE, restype));
10629 CLASSTYPE_GOT_SEMICOLON (restype) = 1;
10630 if (TREE_CODE (fntype) == FUNCTION_TYPE)
10631 fntype = build_function_type (integer_type_node,
10632 TYPE_ARG_TYPES (fntype));
10634 fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
10636 TYPE_ARG_TYPES (fntype));
10637 TREE_TYPE (decl1) = fntype;
10640 if (TREE_CODE (fntype) == METHOD_TYPE)
10641 ctype = TYPE_METHOD_BASETYPE (fntype);
10642 else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
10643 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
10644 && DECL_CONTEXT (decl1) == NULL_TREE)
10646 /* If this doesn't return integer_type, complain. */
10647 if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
10649 if (pedantic || warn_return_type)
10650 warning ("return type for `main' changed to integer type");
10651 TREE_TYPE (decl1) = fntype = default_function_type;
10653 warn_about_return_type = 0;
10657 /* Warn if function was previously implicitly declared
10658 (but not if we warned then). */
10659 if (! warn_implicit
10660 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
10661 cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
10663 current_function_decl = decl1;
10666 cadillac_start_function (decl1);
10668 announce_function (decl1);
10670 if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE)
10672 if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
10673 error_with_aggr_type (TREE_TYPE (fntype),
10674 "return-type `%s' is an incomplete type");
10676 error ("return-type is an incomplete type");
10678 /* Make it return void instead, but don't change the
10679 type of the DECL_RESULT, in case we have a named return value. */
10682 = build_cplus_method_type (build_type_variant (ctype,
10683 TREE_READONLY (decl1),
10684 TREE_SIDE_EFFECTS (decl1)),
10686 FUNCTION_ARG_CHAIN (decl1));
10689 = build_function_type (void_type_node,
10690 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
10691 DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TREE_TYPE (fntype));
10694 if (warn_about_return_type)
10695 warning ("return-type defaults to `int'");
10697 /* Make the init_value nonzero so pushdecl knows this is not tentative.
10698 error_mark_node is replaced below (in poplevel) with the BLOCK. */
10699 DECL_INITIAL (decl1) = error_mark_node;
10701 /* Didn't get anything from C. */
10702 olddecl = NULL_TREE;
10704 /* This function exists in static storage.
10705 (This does not mean `static' in the C sense!) */
10706 TREE_STATIC (decl1) = 1;
10708 if (DECL_INTERFACE_KNOWN (decl1))
10710 /* If this function belongs to an interface, it is public.
10711 If it belongs to someone else's interface, it is also external.
10712 It doesn't matter whether it's inline or not. */
10713 else if (interface_unknown == 0)
10715 if (DECL_DECLARED_STATIC (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1))
10716 DECL_EXTERNAL (decl1)
10718 || (DECL_INLINE (decl1) && ! flag_implement_inlines));
10720 DECL_EXTERNAL (decl1) = current_extern_inline;
10721 DECL_INTERFACE_KNOWN (decl1) = 1;
10725 /* This is a definition, not a reference.
10726 So normally clear DECL_EXTERNAL.
10727 However, `extern inline' acts like a declaration except for
10728 defining how to inline. So set DECL_EXTERNAL in that case. */
10729 DECL_EXTERNAL (decl1) = current_extern_inline;
10731 if (DECL_INLINE (decl1) && (DECL_FUNCTION_MEMBER_P (decl1)
10732 || DECL_TEMPLATE_INSTANTIATION (decl1)))
10733 /* We know nothing yet */;
10736 DECL_INTERFACE_KNOWN (decl1) = 1;
10737 if (DECL_DECLARED_STATIC (decl1))
10738 TREE_PUBLIC (decl1) = 0;
10741 DECL_DEFER_OUTPUT (decl1) = ! DECL_INTERFACE_KNOWN (decl1);
10744 /* Record the decl so that the function name is defined.
10745 If we already have a decl for this name, and it is a FUNCTION_DECL,
10746 use the old decl. */
10748 if (pre_parsed_p == 0)
10750 current_function_decl = decl1 = pushdecl (decl1);
10751 DECL_MAIN_VARIANT (decl1) = decl1;
10752 fntype = TREE_TYPE (decl1);
10755 current_function_decl = decl1;
10757 if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
10759 if (TREE_CODE (fntype) == METHOD_TYPE)
10760 TREE_TYPE (decl1) = fntype
10761 = build_function_type (TREE_TYPE (fntype),
10762 TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
10763 last_function_parms = TREE_CHAIN (last_function_parms);
10764 DECL_ARGUMENTS (decl1) = last_function_parms;
10767 restype = TREE_TYPE (fntype);
10771 push_nested_class (ctype, 1);
10773 /* If we're compiling a friend function, neither of the variables
10774 current_class_decl nor current_class_type will have values. */
10775 if (! doing_friend)
10777 /* We know that this was set up by `grokclassfn'.
10778 We do not wait until `store_parm_decls', since evil
10779 parse errors may never get us to that point. Here
10780 we keep the consistency between `current_class_type'
10781 and `current_class_decl'. */
10782 current_class_decl = last_function_parms;
10783 my_friendly_assert (current_class_decl != NULL_TREE
10784 && TREE_CODE (current_class_decl) == PARM_DECL, 162);
10785 if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
10787 tree variant = TREE_TYPE (TREE_TYPE (current_class_decl));
10788 if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE)
10790 /* Can't call build_indirect_ref here, because it has special
10791 logic to return C_C_D given this argument. */
10792 C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
10793 CLASSTYPE_INST_VAR (ctype) = C_C_D;
10797 C_C_D = CLASSTYPE_INST_VAR (ctype);
10798 /* `current_class_decl' is different for every
10799 function we compile. */
10800 TREE_OPERAND (C_C_D, 0) = current_class_decl;
10802 TREE_READONLY (C_C_D) = TYPE_READONLY (variant);
10803 TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant);
10804 TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant);
10807 C_C_D = current_class_decl;
10812 if (DECL_STATIC_FUNCTION_P (decl1))
10813 push_nested_class (DECL_CONTEXT (decl1), 2);
10815 push_memoized_context (0, 1);
10819 current_binding_level->parm_flag = 1;
10821 /* Save the parm names or decls from this function's declarator
10822 where store_parm_decls will find them. */
10823 current_function_parms = last_function_parms;
10824 current_function_parm_tags = last_function_parm_tags;
10826 GNU_xref_function (decl1, current_function_parms);
10828 make_function_rtl (decl1);
10830 /* Allocate further tree nodes temporarily during compilation
10831 of this function only. Tiemann moved up here from bottom of fn. */
10832 temporary_allocation ();
10834 /* Promote the value to int before returning it. */
10835 if (C_PROMOTING_INTEGER_TYPE_P (restype))
10837 /* It retains unsignedness if traditional or if it isn't
10838 really getting wider. */
10839 if (TREE_UNSIGNED (restype)
10840 && (flag_traditional
10841 || TYPE_PRECISION (restype)
10842 == TYPE_PRECISION (integer_type_node)))
10843 restype = unsigned_type_node;
10845 restype = integer_type_node;
10847 if (DECL_RESULT (decl1) == NULL_TREE)
10848 DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, restype);
10850 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)))
10852 dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10853 ctor_label = NULL_TREE;
10857 dtor_label = NULL_TREE;
10858 if (DECL_CONSTRUCTOR_P (decl1))
10859 ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10862 /* If this fcn was already referenced via a block-scope `extern' decl
10863 (or an implicit decl), propagate certain information about the usage. */
10864 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
10865 TREE_ADDRESSABLE (decl1) = 1;
10870 /* Store the parameter declarations into the current function declaration.
10871 This is called after parsing the parameter declarations, before
10872 digesting the body of the function.
10874 Also install to binding contour return value identifier, if any. */
10877 store_parm_decls ()
10879 register tree fndecl = current_function_decl;
10880 register tree parm;
10881 int parms_have_cleanups = 0;
10883 /* This is either a chain of PARM_DECLs (when a prototype is used). */
10884 tree specparms = current_function_parms;
10886 /* This is a list of types declared among parms in a prototype. */
10887 tree parmtags = current_function_parm_tags;
10889 /* This is a chain of any other decls that came in among the parm
10890 declarations. If a parm is declared with enum {foo, bar} x;
10891 then CONST_DECLs for foo and bar are put here. */
10892 tree nonparms = NULL_TREE;
10894 if (current_binding_level == global_binding_level)
10895 fatal ("parse errors have confused me too much");
10897 /* Initialize RTL machinery. */
10898 init_function_start (fndecl, input_filename, lineno);
10900 /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
10901 declare_function_name ();
10903 /* Create a binding level for the parms. */
10904 expand_start_bindings (0);
10906 if (specparms != NULL_TREE)
10908 /* This case is when the function was defined with an ANSI prototype.
10909 The parms already have decls, so we need not do anything here
10910 except record them as in effect
10911 and complain if any redundant old-style parm decls were written. */
10913 register tree next;
10915 /* Must clear this because it might contain TYPE_DECLs declared
10917 storedecls (NULL_TREE);
10918 for (parm = nreverse (specparms); parm; parm = next)
10920 next = TREE_CHAIN (parm);
10921 if (TREE_CODE (parm) == PARM_DECL)
10923 tree cleanup = maybe_build_cleanup (parm);
10924 if (DECL_NAME (parm) == NULL_TREE)
10927 cp_error_at ("parameter name omitted", parm);
10929 /* for C++, this is not an error. */
10933 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
10934 cp_error ("parameter `%D' declared void", parm);
10937 /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
10938 A parameter is assumed not to have any side effects.
10939 If this should change for any reason, then this
10940 will have to wrap the bashed reference type in a save_expr.
10942 Also, if the parameter type is declared to be an X
10943 and there is an X(X&) constructor, we cannot lay it
10944 into the stack (any more), so we make this parameter
10945 look like it is really of reference type. Functions
10946 which pass parameters to this function will know to
10947 create a temporary in their frame, and pass a reference
10950 if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
10951 && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
10952 SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
10958 expand_decl (parm);
10959 if (! expand_decl_cleanup (parm, cleanup))
10960 cp_error ("parser lost in parsing declaration of `%D'",
10962 parms_have_cleanups = 1;
10967 /* If we find an enum constant or a type tag,
10968 put it aside for the moment. */
10969 TREE_CHAIN (parm) = NULL_TREE;
10970 nonparms = chainon (nonparms, parm);
10974 /* Get the decls in their original chain order
10975 and record in the function. This is all and only the
10976 PARM_DECLs that were pushed into scope by the loop above. */
10977 DECL_ARGUMENTS (fndecl) = getdecls ();
10979 storetags (chainon (parmtags, gettags ()));
10982 DECL_ARGUMENTS (fndecl) = NULL_TREE;
10984 /* Now store the final chain of decls for the arguments
10985 as the decl-chain of the current lexical scope.
10986 Put the enumerators in as well, at the front so that
10987 DECL_ARGUMENTS is not modified. */
10989 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
10991 /* Initialize the RTL code for the function. */
10992 DECL_SAVED_INSNS (fndecl) = NULL_RTX;
10993 expand_function_start (fndecl, parms_have_cleanups);
10995 /* Create a binding contour which can be used to catch
10996 cleanup-generated temporaries. Also, if the return value needs or
10997 has initialization, deal with that now. */
10998 if (parms_have_cleanups)
11001 expand_start_bindings (0);
11004 current_function_parms_stored = 1;
11008 maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
11009 if (! expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup))
11010 cp_error ("parser lost in parsing declaration of `%D'", fndecl);
11013 /* If this function is `main', emit a call to `__main'
11014 to run global initializers, etc. */
11015 if (DECL_NAME (fndecl)
11016 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
11017 && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
11018 && DECL_CONTEXT (fndecl) == NULL_TREE)
11020 expand_main_function ();
11023 expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
11026 /* done at a differnet time */
11028 output_builtin_tdesc_entries ();
11033 /* Bind a name and initialization to the return value of
11034 the current function. */
11036 store_return_init (return_id, init)
11037 tree return_id, init;
11039 tree decl = DECL_RESULT (current_function_decl);
11042 /* Give this error as many times as there are occurrences,
11043 so that users can use Emacs compilation buffers to find
11044 and fix all such places. */
11045 pedwarn ("ANSI C++ does not permit named return values");
11047 if (return_id != NULL_TREE)
11049 if (DECL_NAME (decl) == NULL_TREE)
11051 DECL_NAME (decl) = return_id;
11052 DECL_ASSEMBLER_NAME (decl) = return_id;
11055 error ("return identifier `%s' already in place",
11056 IDENTIFIER_POINTER (DECL_NAME (decl)));
11059 /* Can't let this happen for constructors. */
11060 if (DECL_CONSTRUCTOR_P (current_function_decl))
11062 error ("can't redefine default return value for constructors");
11066 /* If we have a named return value, put that in our scope as well. */
11067 if (DECL_NAME (decl) != NULL_TREE)
11069 /* If this named return value comes in a register,
11070 put it in a pseudo-register. */
11071 if (DECL_REGISTER (decl))
11073 original_result_rtx = DECL_RTL (decl);
11074 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
11077 /* Let `finish_decl' know that this initializer is ok. */
11078 DECL_INITIAL (decl) = init;
11080 finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
11085 /* Finish up a function declaration and compile that function
11086 all the way to assembler language output. The free the storage
11087 for the function definition.
11089 This is called after parsing the body of the function definition.
11090 LINENO is the current line number.
11092 C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
11093 (and expand_end_bindings) must be made to take care of the binding
11094 contour for the base initializers. This is only relevant for
11098 finish_function (lineno, call_poplevel, nested)
11103 register tree fndecl = current_function_decl;
11104 tree fntype, ctype = NULL_TREE;
11105 rtx head, last_parm_insn, mark;
11106 /* Label to use if this function is supposed to return a value. */
11107 tree no_return_label = NULL_TREE;
11108 tree decls = NULL_TREE;
11110 /* When we get some parse errors, we can end up without a
11111 current_function_decl, so cope. */
11112 if (fndecl == NULL_TREE)
11115 fntype = TREE_TYPE (fndecl);
11117 /* TREE_READONLY (fndecl) = 1;
11118 This caused &foo to be of type ptr-to-const-function
11119 which then got a warning when stored in a ptr-to-function variable. */
11121 /* This happens on strange parse errors. */
11122 if (! current_function_parms_stored)
11125 store_parm_decls ();
11128 if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/)
11130 tree ttype = target_type (fntype);
11133 if (IS_AGGR_TYPE (ttype))
11134 /* Let debugger know it should output info for this type. */
11135 note_debug_info_needed (ttype);
11137 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
11139 ttype = target_type (TREE_TYPE (parmdecl));
11140 if (IS_AGGR_TYPE (ttype))
11141 /* Let debugger know it should output info for this type. */
11142 note_debug_info_needed (ttype);
11146 /* Clean house because we will need to reorder insns here. */
11147 do_pending_stack_adjust ();
11151 tree binfo = TYPE_BINFO (current_class_type);
11152 tree cond = integer_one_node;
11153 tree exprstmt, vfields;
11154 tree in_charge_node = lookup_name (in_charge_identifier, 0);
11156 int ok_to_optimize_dtor = 0;
11158 if (current_function_assigns_this)
11159 cond = build (NE_EXPR, integer_type_node,
11160 current_class_decl, integer_zero_node);
11163 int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
11165 /* If this destructor is empty, then we don't need to check
11166 whether `this' is NULL in some cases. */
11167 mark = get_last_insn ();
11168 last_parm_insn = get_first_nonparm_insn ();
11170 if ((flag_this_is_variable & 1) == 0)
11171 ok_to_optimize_dtor = 1;
11172 else if (mark == last_parm_insn)
11173 ok_to_optimize_dtor
11174 = (n_baseclasses == 0
11175 || (n_baseclasses == 1
11176 && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
11179 /* These initializations might go inline. Protect
11180 the binding level of the parms. */
11182 expand_start_bindings (0);
11184 if (current_function_assigns_this)
11186 current_function_assigns_this = 0;
11187 current_function_just_assigned_this = 0;
11190 /* Generate the code to call destructor on base class.
11191 If this destructor belongs to a class with virtual
11192 functions, then set the virtual function table
11193 pointer to represent the type of our base class. */
11195 /* This side-effect makes call to `build_delete' generate the
11196 code we have to have at the end of this destructor. */
11197 TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
11199 /* These are two cases where we cannot delegate deletion. */
11200 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
11201 || TYPE_GETS_REG_DELETE (current_class_type))
11202 exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
11203 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11205 exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
11206 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11208 /* If we did not assign to this, then `this' is non-zero at
11209 the end of a destructor. As a special optimization, don't
11210 emit test if this is an empty destructor. If it does nothing,
11211 it does nothing. If it calls a base destructor, the base
11212 destructor will perform the test. */
11214 if (exprstmt != error_mark_node
11215 && (TREE_CODE (exprstmt) != NOP_EXPR
11216 || TREE_OPERAND (exprstmt, 0) != integer_zero_node
11217 || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
11219 expand_label (dtor_label);
11220 if (cond != integer_one_node)
11221 expand_start_cond (cond, 0);
11222 if (exprstmt != void_zero_node)
11223 /* Don't call `expand_expr_stmt' if we're not going to do
11224 anything, since -Wall will give a diagnostic. */
11225 expand_expr_stmt (exprstmt);
11227 /* Run destructor on all virtual baseclasses. */
11228 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11230 tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
11231 expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
11232 in_charge_node, integer_two_node), 0);
11235 if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
11237 tree ptr = convert_pointer_to_vbase (vbases, current_class_decl);
11238 expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases)),
11239 ptr, integer_zero_node,
11240 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
11242 vbases = TREE_CHAIN (vbases);
11244 expand_end_cond ();
11247 do_pending_stack_adjust ();
11248 if (cond != integer_one_node)
11249 expand_end_cond ();
11252 TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
11254 virtual_size = c_sizeof (current_class_type);
11256 /* At the end, call delete if that's what's requested. */
11257 if (TYPE_GETS_REG_DELETE (current_class_type))
11258 /* This NOP_EXPR means we are in a static call context. */
11261 (build_indirect_ref
11262 (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type),
11265 ansi_opname[(int) DELETE_EXPR],
11266 tree_cons (NULL_TREE, current_class_decl,
11267 build_tree_list (NULL_TREE, virtual_size)),
11268 NULL_TREE, LOOKUP_NORMAL);
11269 else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11270 exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
11273 exprstmt = NULL_TREE;
11277 cond = build (BIT_AND_EXPR, integer_type_node,
11278 in_charge_node, integer_one_node);
11279 expand_start_cond (cond, 0);
11280 expand_expr_stmt (exprstmt);
11281 expand_end_cond ();
11284 /* End of destructor. */
11285 expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0);
11286 poplevel (2, 0, 0); /* XXX change to 1 */
11288 /* Back to the top of destructor. */
11289 /* Dont execute destructor code if `this' is NULL. */
11290 mark = get_last_insn ();
11291 last_parm_insn = get_first_nonparm_insn ();
11292 if (last_parm_insn == NULL_RTX)
11293 last_parm_insn = mark;
11295 last_parm_insn = previous_insn (last_parm_insn);
11297 /* Make all virtual function table pointers in non-virtual base
11298 classes point to CURRENT_CLASS_TYPE's virtual function
11300 expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_decl);
11301 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11302 expand_indirect_vtbls_init (binfo, C_C_D, current_class_decl, 0);
11303 if (! ok_to_optimize_dtor)
11305 cond = build_binary_op (NE_EXPR,
11306 current_class_decl, integer_zero_node, 1);
11307 expand_start_cond (cond, 0);
11309 if (mark != get_last_insn ())
11310 reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
11311 if (! ok_to_optimize_dtor)
11312 expand_end_cond ();
11314 else if (current_function_assigns_this)
11316 /* Does not need to call emit_base_init, because
11317 that is done (if needed) just after assignment to this
11320 if (DECL_CONSTRUCTOR_P (current_function_decl))
11322 expand_label (ctor_label);
11323 ctor_label = NULL_TREE;
11327 decls = getdecls ();
11328 expand_end_bindings (decls, decls != NULL_TREE, 0);
11329 poplevel (decls != NULL_TREE, 0, 0);
11331 c_expand_return (current_class_decl);
11333 else if (TYPE_MAIN_VARIANT (TREE_TYPE (
11334 DECL_RESULT (current_function_decl))) != void_type_node
11335 && return_label != NULL_RTX)
11336 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11338 current_function_assigns_this = 0;
11339 current_function_just_assigned_this = 0;
11340 base_init_insns = NULL_RTX;
11342 else if (DECL_CONSTRUCTOR_P (fndecl))
11344 tree allocated_this;
11345 tree cond, thenclause;
11346 /* Allow constructor for a type to get a new instance of the object
11347 using `build_new'. */
11348 tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
11349 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
11351 DECL_RETURNS_FIRST_ARG (fndecl) = 1;
11353 if (flag_this_is_variable > 0)
11355 cond = build_binary_op (EQ_EXPR,
11356 current_class_decl, integer_zero_node, 1);
11357 thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
11358 build_new (NULL_TREE, current_class_type, void_type_node, 0));
11361 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
11363 /* must keep the first insn safe. */
11364 head = get_insns ();
11366 /* this note will come up to the top with us. */
11367 mark = get_last_insn ();
11369 if (flag_this_is_variable > 0)
11371 expand_start_cond (cond, 0);
11372 expand_expr_stmt (thenclause);
11373 expand_end_cond ();
11377 if (DECL_NAME (fndecl) == NULL_TREE
11378 && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
11379 build_default_constructor (fndecl);
11382 /* Emit insns from `emit_base_init' which sets up virtual
11383 function table pointer(s). */
11384 emit_insns (base_init_insns);
11385 base_init_insns = NULL_RTX;
11387 /* This is where the body of the constructor begins.
11388 If there were no insns in this function body, then the
11389 last_parm_insn is also the last insn.
11391 If optimization is enabled, last_parm_insn may move, so
11392 we don't hold on to it (across emit_base_init). */
11393 last_parm_insn = get_first_nonparm_insn ();
11394 if (last_parm_insn == NULL_RTX)
11395 last_parm_insn = mark;
11397 last_parm_insn = previous_insn (last_parm_insn);
11399 if (mark != get_last_insn ())
11400 reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
11402 /* This is where the body of the constructor ends. */
11403 expand_label (ctor_label);
11404 ctor_label = NULL_TREE;
11408 expand_end_bindings (decls = getdecls (), decls != NULL_TREE, 0);
11409 poplevel (decls != NULL_TREE, 1, 0);
11412 c_expand_return (current_class_decl);
11414 current_function_assigns_this = 0;
11415 current_function_just_assigned_this = 0;
11417 else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
11418 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
11419 && DECL_CONTEXT (fndecl) == NULL_TREE)
11421 /* Make it so that `main' always returns 0 by default. */
11423 c_expand_return (integer_one_node);
11425 c_expand_return (integer_zero_node);
11428 else if (return_label != NULL_RTX
11429 && current_function_return_value == NULL_TREE
11430 && ! DECL_NAME (DECL_RESULT (current_function_decl)))
11431 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11434 expand_gc_prologue_and_epilogue ();
11436 /* That's the end of the vtable decl's life. Need to mark it such
11437 if doing stupid register allocation.
11439 Note that current_vtable_decl is really an INDIRECT_REF
11440 on top of a VAR_DECL here. */
11441 if (obey_regdecls && current_vtable_decl)
11442 use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0)));
11444 /* If this function is supposed to return a value, ensure that
11445 we do not fall into the cleanups by mistake. The end of our
11446 function will look like this:
11448 user code (may have return stmt somewhere)
11449 goto no_return_label
11454 NOTE_INSN_FUNCTION_END
11458 If the user omits a return stmt in the USER CODE section, we
11459 will have a control path which reaches NOTE_INSN_FUNCTION_END.
11460 Otherwise, we won't. */
11461 if (no_return_label)
11463 DECL_CONTEXT (no_return_label) = fndecl;
11464 DECL_INITIAL (no_return_label) = error_mark_node;
11465 DECL_SOURCE_FILE (no_return_label) = input_filename;
11466 DECL_SOURCE_LINE (no_return_label) = lineno;
11467 expand_goto (no_return_label);
11472 /* remove the binding contour which is used
11473 to catch cleanup-generated temporaries. */
11474 expand_end_bindings (0, 0, 0);
11475 poplevel (0, 0, 0);
11479 /* Emit label at beginning of cleanup code for parameters. */
11480 emit_label (cleanup_label);
11482 /* Get return value into register if that's where it's supposed to be. */
11483 if (original_result_rtx)
11484 fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
11486 /* Finish building code that will trigger warnings if users forget
11487 to make their functions return values. */
11488 if (no_return_label || cleanup_label)
11489 emit_jump (return_label);
11490 if (no_return_label)
11492 /* We don't need to call `expand_*_return' here because we
11493 don't need any cleanups here--this path of code is only
11494 for error checking purposes. */
11495 expand_label (no_return_label);
11498 /* Generate rtl for function exit. */
11499 expand_function_end (input_filename, lineno, 1);
11501 if (flag_handle_exceptions)
11502 expand_exception_blocks();
11504 /* This must come after expand_function_end because cleanups might
11505 have declarations (from inline functions) that need to go into
11506 this function's blocks. */
11507 if (current_binding_level->parm_flag != 1)
11508 my_friendly_abort (122);
11509 poplevel (1, 0, 1);
11511 /* reset scope for C++: if we were in the scope of a class,
11512 then when we finish this function, we are not longer so.
11513 This cannot be done until we know for sure that no more
11514 class members will ever be referenced in this function
11515 (i.e., calls to destructors). */
11516 if (current_class_name)
11518 ctype = current_class_type;
11519 pop_nested_class (1);
11522 pop_memoized_context (1);
11524 /* Must mark the RESULT_DECL as being in this function. */
11525 DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
11527 /* Obey `register' declarations if `setjmp' is called in this fn. */
11528 if (flag_traditional && current_function_calls_setjmp)
11529 setjmp_protect (DECL_INITIAL (fndecl));
11531 /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
11532 to the FUNCTION_DECL node itself. */
11533 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
11535 /* So we can tell if jump_optimize sets it to 1. */
11538 if (DECL_EXTERNAL (fndecl)
11539 /* This function is just along for the ride. If we can make
11540 it inline, that's great. Otherwise, just punt it. */
11541 && (DECL_INLINE (fndecl) == 0
11543 || function_cannot_inline_p (fndecl)
11544 /* ??? Compensate for Sun brain damage in dealing with
11545 data segments of PIC code. */
11547 && (DECL_CONSTRUCTOR_P (fndecl)
11548 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
11549 && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype)))))
11552 extern int rtl_dump_and_exit;
11553 int old_rtl_dump_and_exit = rtl_dump_and_exit;
11554 int inline_spec = DECL_INLINE (fndecl);
11556 /* This throws away the code for FNDECL. */
11557 rtl_dump_and_exit = 1;
11558 /* This throws away the memory of the code for FNDECL. */
11559 if (flag_no_inline)
11560 DECL_INLINE (fndecl) = 0;
11561 rest_of_compilation (fndecl);
11562 rtl_dump_and_exit = old_rtl_dump_and_exit;
11563 DECL_INLINE (fndecl) = inline_spec;
11567 /* Run the optimizers and output the assembler code for this
11569 rest_of_compilation (fndecl);
11572 if (DECL_INLINE (fndecl) && !TREE_ASM_WRITTEN (fndecl)
11573 && DECL_DEFER_OUTPUT (fndecl))
11575 mark_inline_for_output (fndecl);
11578 if (ctype && TREE_ASM_WRITTEN (fndecl))
11579 note_debug_info_needed (ctype);
11581 current_function_returns_null |= can_reach_end;
11583 /* Since we don't normally go through c_expand_return for constructors,
11584 this normally gets the wrong value.
11585 Also, named return values have their return codes emitted after
11586 NOTE_INSN_FUNCTION_END, confusing jump.c. */
11587 if (DECL_CONSTRUCTOR_P (fndecl)
11588 || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
11589 current_function_returns_null = 0;
11591 if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
11592 cp_warning ("`noreturn' function `%D' does return", fndecl);
11593 else if ((warn_return_type || pedantic)
11594 && current_function_returns_null
11595 && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
11597 /* If this function returns non-void and control can drop through,
11599 cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
11601 /* With just -W, complain only if function returns both with
11602 and without a value. */
11603 else if (extra_warnings
11604 && current_function_returns_value && current_function_returns_null)
11605 warning ("this function may return with or without a value");
11607 /* Free all the tree nodes making up this function. */
11608 /* Switch back to allocating nodes permanently
11609 until we start another function. */
11611 permanent_allocation (1);
11614 cadillac_finish_function (fndecl);
11616 if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
11618 /* Stop pointing to the local nodes about to be freed. */
11619 /* But DECL_INITIAL must remain nonzero so we know this
11620 was an actual function definition. */
11621 DECL_INITIAL (fndecl) = error_mark_node;
11622 if (! DECL_CONSTRUCTOR_P (fndecl)
11623 || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
11624 DECL_ARGUMENTS (fndecl) = NULL_TREE;
11627 /* Let the error reporting routines know that we're outside a function. */
11628 current_function_decl = NULL_TREE;
11629 named_label_uses = NULL_TREE;
11632 /* Create the FUNCTION_DECL for a function definition.
11633 LINE1 is the line number that the definition absolutely begins on.
11634 LINE2 is the line number that the name of the function appears on.
11635 DECLSPECS and DECLARATOR are the parts of the declaration;
11636 they describe the return type and the name of the function,
11637 but twisted together in a fashion that parallels the syntax of C.
11639 This function creates a binding context for the function body
11640 as well as setting up the FUNCTION_DECL in current_function_decl.
11642 Returns a FUNCTION_DECL on success.
11644 If the DECLARATOR is not suitable for a function (it defines a datum
11645 instead), we return 0, which tells yyparse to report a parse error.
11647 May return void_type_node indicating that this method is actually
11648 a friend. See grokfield for more details.
11650 Came here with a `.pushlevel' .
11652 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
11653 CHANGES TO CODE IN `grokfield'. */
11655 start_method (declspecs, declarator, raises)
11656 tree declarator, declspecs, raises;
11658 tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises);
11660 /* Something too ugly to handle. */
11661 if (fndecl == NULL_TREE)
11664 /* Pass friends other than inline friend functions back. */
11665 if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
11668 if (TREE_CODE (fndecl) != FUNCTION_DECL)
11669 /* Not a function, tell parser to report parse error. */
11672 if (IS_SIGNATURE (current_class_type))
11674 IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
11675 /* In case we need this info later. */
11676 HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1;
11679 if (DECL_IN_AGGR_P (fndecl))
11681 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
11683 if (DECL_CONTEXT (fndecl))
11684 cp_error ("`%D' is already defined in class %s", fndecl,
11685 TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
11687 return void_type_node;
11690 if (flag_default_inline)
11691 DECL_INLINE (fndecl) = 1;
11693 if (processing_template_defn)
11694 SET_DECL_IMPLICIT_INSTANTIATION (fndecl);
11696 /* We read in the parameters on the maybepermanent_obstack,
11697 but we won't be getting back to them until after we
11698 may have clobbered them. So the call to preserve_data
11699 will keep them safe. */
11702 if (! DECL_FRIEND_P (fndecl))
11704 if (DECL_CHAIN (fndecl) != NULL_TREE)
11706 /* Need a fresh node here so that we don't get circularity
11707 when we link these together. If FNDECL was a friend, then
11708 `pushdecl' does the right thing, which is nothing wrt its
11709 current value of DECL_CHAIN. */
11710 fndecl = copy_node (fndecl);
11712 if (TREE_CHAIN (fndecl))
11714 fndecl = copy_node (fndecl);
11715 TREE_CHAIN (fndecl) = NULL_TREE;
11718 if (DECL_CONSTRUCTOR_P (fndecl))
11720 if (! grok_ctor_properties (current_class_type, fndecl))
11721 return void_type_node;
11723 else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
11724 grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
11727 finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0);
11729 /* Make a place for the parms */
11731 current_binding_level->parm_flag = 1;
11733 DECL_IN_AGGR_P (fndecl) = 1;
11737 /* Go through the motions of finishing a function definition.
11738 We don't compile this method until after the whole class has
11741 FINISH_METHOD must return something that looks as though it
11742 came from GROKFIELD (since we are defining a method, after all).
11744 This is called after parsing the body of the function definition.
11745 STMTS is the chain of statements that makes up the function body.
11747 DECL is the ..._DECL that `start_method' provided. */
11750 finish_method (decl)
11753 register tree fndecl = decl;
11756 register tree link;
11758 if (TYPE_MAIN_VARIANT (decl) == void_type_node)
11761 old_initial = DECL_INITIAL (fndecl);
11763 /* Undo the level for the parms (from start_method).
11764 This is like poplevel, but it causes nothing to be
11765 saved. Saving information here confuses symbol-table
11766 output routines. Besides, this information will
11767 be correctly output when this method is actually
11770 /* Clear out the meanings of the local variables of this level;
11771 also record in each decl which block it belongs to. */
11773 for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
11775 if (DECL_NAME (link) != NULL_TREE)
11776 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
11777 my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
11778 DECL_CONTEXT (link) = NULL_TREE;
11781 /* Restore all name-meanings of the outer levels
11782 that were shadowed by this level. */
11784 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
11785 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11786 for (link = current_binding_level->class_shadowed;
11787 link; link = TREE_CHAIN (link))
11788 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11789 for (link = current_binding_level->type_shadowed;
11790 link; link = TREE_CHAIN (link))
11791 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11793 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
11794 (HOST_WIDE_INT) current_binding_level->level_chain,
11795 current_binding_level->parm_flag,
11796 current_binding_level->keep,
11797 current_binding_level->tag_transparent);
11799 poplevel (0, 0, 0);
11801 DECL_INITIAL (fndecl) = old_initial;
11803 /* We used to check if the context of FNDECL was different from
11804 current_class_type as another way to get inside here. This didn't work
11805 for String.cc in libg++. */
11806 if (DECL_FRIEND_P (fndecl))
11808 CLASSTYPE_INLINE_FRIENDS (current_class_type)
11809 = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
11810 decl = void_type_node;
11816 /* Called when a new struct TYPE is defined.
11817 If this structure or union completes the type of any previous
11818 variable declaration, lay it out and output its rtl. */
11821 hack_incomplete_structures (type)
11826 if (current_binding_level->n_incomplete == 0)
11829 if (!type) /* Don't do this for class templates. */
11832 for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
11833 if (TREE_TYPE (decl) == type
11834 || (TREE_TYPE (decl)
11835 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
11836 && TREE_TYPE (TREE_TYPE (decl)) == type))
11838 if (TREE_CODE (decl) == TYPE_DECL)
11839 layout_type (TREE_TYPE (decl));
11842 int toplevel = global_binding_level == current_binding_level;
11843 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
11844 && TREE_TYPE (TREE_TYPE (decl)) == type)
11845 layout_type (TREE_TYPE (decl));
11846 layout_decl (decl, 0);
11847 rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
11851 expand_decl (decl);
11852 cleanup = maybe_build_cleanup (decl);
11853 expand_decl_init (decl);
11854 if (! expand_decl_cleanup (decl, cleanup))
11855 cp_error ("parser lost in parsing declaration of `%D'",
11860 my_friendly_assert (current_binding_level->n_incomplete > 0, 164);
11862 --current_binding_level->n_incomplete;
11866 /* Nonzero if presently building a cleanup. Needed because
11867 SAVE_EXPRs are not the right things to use inside of cleanups.
11868 They are only ever evaluated once, where the cleanup
11869 might be evaluated several times. In this case, a later evaluation
11870 of the cleanup might fill in the SAVE_EXPR_RTL, and it will
11871 not be valid for an earlier cleanup. */
11873 int building_cleanup;
11875 /* If DECL is of a type which needs a cleanup, build that cleanup here.
11876 We don't build cleanups if just going for syntax checking, since
11877 fixup_cleanups does not know how to not handle them.
11879 Don't build these on the momentary obstack; they must live
11880 the life of the binding contour. */
11882 maybe_build_cleanup (decl)
11885 tree type = TREE_TYPE (decl);
11886 if (TYPE_NEEDS_DESTRUCTOR (type))
11888 int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
11890 int old_building_cleanup = building_cleanup;
11891 building_cleanup = 1;
11893 if (TREE_CODE (decl) != PARM_DECL)
11894 temp = suspend_momentary ();
11896 if (TREE_CODE (type) == ARRAY_TYPE)
11900 mark_addressable (decl);
11901 rval = build_unary_op (ADDR_EXPR, decl, 0);
11904 /* Optimize for space over speed here. */
11905 if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
11906 || flag_expensive_optimizations)
11907 flags |= LOOKUP_NONVIRTUAL;
11909 /* Use TYPE_MAIN_VARIANT so we don't get a warning about
11910 calling delete on a `const' variable. */
11911 if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval))))
11912 rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval);
11914 rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0);
11916 if (TYPE_USES_VIRTUAL_BASECLASSES (type)
11917 && ! TYPE_HAS_DESTRUCTOR (type))
11918 rval = build_compound_expr (tree_cons (NULL_TREE, rval,
11919 build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
11921 if (TREE_CODE (decl) != PARM_DECL)
11922 resume_momentary (temp);
11924 building_cleanup = old_building_cleanup;
11931 /* Expand a C++ expression at the statement level.
11932 This is needed to ferret out nodes which have UNKNOWN_TYPE.
11933 The C++ type checker should get all of these out when
11934 expressions are combined with other, type-providing, expressions,
11935 leaving only orphan expressions, such as:
11937 &class::bar; / / takes its address, but does nothing with it.
11941 cplus_expand_expr_stmt (exp)
11944 if (TREE_TYPE (exp) == unknown_type_node)
11946 if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
11947 error ("address of overloaded function with no contextual type information");
11948 else if (TREE_CODE (exp) == COMPONENT_REF)
11949 warning ("useless reference to a member function name, did you forget the ()?");
11953 int remove_implicit_immediately = 0;
11955 if (TREE_CODE (exp) == FUNCTION_DECL)
11957 cp_warning ("reference, not call, to function `%D'", exp);
11958 warning ("at this point in file");
11962 /* We should do this eventually, but right now this causes regex.o from
11963 libg++ to miscompile, and tString to core dump. */
11964 exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp);
11966 expand_expr_stmt (break_out_cleanups (exp));
11969 /* Clean up any pending cleanups. This happens when a function call
11970 returns a cleanup-needing value that nobody uses. */
11971 expand_cleanups_to (NULL_TREE);
11974 /* When a stmt has been parsed, this function is called.
11976 Currently, this function only does something within a
11977 constructor's scope: if a stmt has just assigned to this,
11978 and we are in a derived class, we call `emit_base_init'. */
11983 extern struct nesting *cond_stack, *loop_stack, *case_stack;
11986 if (current_function_assigns_this
11987 || ! current_function_just_assigned_this)
11989 if (DECL_CONSTRUCTOR_P (current_function_decl))
11991 /* Constructors must wait until we are out of control
11992 zones before calling base constructors. */
11993 if (cond_stack || loop_stack || case_stack)
11995 emit_insns (base_init_insns);
11996 check_base_init (current_class_type);
11998 current_function_assigns_this = 1;
12001 cadillac_finish_stmt ();
12004 /* Change a static member function definition into a FUNCTION_TYPE, instead
12005 of the METHOD_TYPE that we create when it's originally parsed.
12007 WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES
12008 (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of
12009 other decls. Either pass the addresses of local variables or NULL. */
12012 revert_static_member_fn (decl, fn, argtypes)
12013 tree *decl, *fn, *argtypes;
12016 tree function = fn ? *fn : TREE_TYPE (*decl);
12017 tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function);
12019 args = TREE_CHAIN (args);
12020 tmp = build_function_type (TREE_TYPE (function), args);
12021 tmp = build_type_variant (tmp, TYPE_READONLY (function),
12022 TYPE_VOLATILE (function));
12023 tmp = build_exception_variant (TYPE_METHOD_BASETYPE (function), tmp,
12024 TYPE_RAISES_EXCEPTIONS (function));
12025 TREE_TYPE (*decl) = tmp;
12026 DECL_STATIC_FUNCTION_P (*decl) = 1;
12034 id_in_current_class (id)
12037 return !!purpose_member (id, class_binding_level->class_shadowed);
12044 int warn_about_return_type;
12047 int just_assigned_this;
12050 tree shadowed_labels;
12054 struct cp_function *next;
12055 struct binding_level *binding_level;
12058 struct cp_function *cp_function_chain;
12060 /* Save and reinitialize the variables
12061 used during compilation of a C++ function. */
12064 push_cp_function_context (toplev)
12067 struct cp_function *p
12068 = (struct cp_function *) xmalloc (sizeof (struct cp_function));
12070 push_function_context_to (toplev);
12072 p->next = cp_function_chain;
12073 cp_function_chain = p;
12075 p->named_labels = named_labels;
12076 p->shadowed_labels = shadowed_labels;
12077 p->returns_value = current_function_returns_value;
12078 p->returns_null = current_function_returns_null;
12079 p->warn_about_return_type = warn_about_return_type;
12080 p->extern_inline = current_extern_inline;
12081 p->binding_level = current_binding_level;
12082 p->ctor_label = ctor_label;
12083 p->dtor_label = dtor_label;
12084 p->assigns_this = current_function_assigns_this;
12085 p->just_assigned_this = current_function_just_assigned_this;
12086 p->parms_stored = current_function_parms_stored;
12087 p->result_rtx = original_result_rtx;
12090 /* Restore the variables used during compilation of a C++ function. */
12093 pop_cp_function_context (toplev)
12096 struct cp_function *p = cp_function_chain;
12099 /* Bring back all the labels that were shadowed. */
12100 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
12101 if (DECL_NAME (TREE_VALUE (link)) != 0)
12102 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)),
12103 TREE_VALUE (link));
12106 if (DECL_SAVED_INSNS (current_function_decl) == 0)
12108 /* Stop pointing to the local nodes about to be freed. */
12109 /* But DECL_INITIAL must remain nonzero so we know this
12110 was an actual function definition. */
12111 DECL_INITIAL (current_function_decl) = error_mark_node;
12112 DECL_ARGUMENTS (current_function_decl) = 0;
12116 pop_function_context_from (toplev);
12118 cp_function_chain = p->next;
12120 named_labels = p->named_labels;
12121 shadowed_labels = p->shadowed_labels;
12122 current_function_returns_value = p->returns_value;
12123 current_function_returns_null = p->returns_null;
12124 warn_about_return_type = p->warn_about_return_type;
12125 current_extern_inline = p->extern_inline;
12126 current_binding_level = p->binding_level;
12127 ctor_label = p->ctor_label;
12128 dtor_label = p->dtor_label;
12129 current_function_assigns_this = p->assigns_this;
12130 current_function_just_assigned_this = p->just_assigned_this;
12131 current_function_parms_stored = p->parms_stored;
12132 original_result_rtx = p->result_rtx;