1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* Process declarations and symbol lookup for C front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
37 #include <sys/types.h>
41 #define obstack_chunk_alloc xmalloc
42 #define obstack_chunk_free free
44 extern struct obstack permanent_obstack;
46 extern int current_class_depth;
48 /* Stack of places to restore the search obstack back to. */
50 /* Obstack used for remembering local class declarations (like
51 enums and static (const) members. */
53 static struct obstack decl_obstack;
54 static struct stack_level *decl_stack;
56 #ifndef CHAR_TYPE_SIZE
57 #define CHAR_TYPE_SIZE BITS_PER_UNIT
60 #ifndef SHORT_TYPE_SIZE
61 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
65 #define INT_TYPE_SIZE BITS_PER_WORD
68 #ifndef LONG_TYPE_SIZE
69 #define LONG_TYPE_SIZE BITS_PER_WORD
72 #ifndef LONG_LONG_TYPE_SIZE
73 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
76 #ifndef WCHAR_UNSIGNED
77 #define WCHAR_UNSIGNED 0
80 #ifndef FLOAT_TYPE_SIZE
81 #define FLOAT_TYPE_SIZE BITS_PER_WORD
84 #ifndef DOUBLE_TYPE_SIZE
85 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
88 #ifndef LONG_DOUBLE_TYPE_SIZE
89 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
92 /* We let tm.h override the types used here, to handle trivial differences
93 such as the choice of unsigned int or long unsigned int for size_t.
94 When machines start needing nontrivial differences in the size type,
95 it would be best to do something here to figure out automatically
96 from other information what type to use. */
99 #define SIZE_TYPE "long unsigned int"
103 #define PTRDIFF_TYPE "long int"
107 #define WCHAR_TYPE "int"
110 #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
111 define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
112 #define auto_function(NAME, TYPE, CODE) \
114 tree __name = NAME; \
115 tree __type = TYPE; \
116 define_function (IDENTIFIER_POINTER (__name), __type, CODE, \
117 (void (*)())push_overloaded_decl_1, \
118 IDENTIFIER_POINTER (build_decl_overload (__name, TYPE_ARG_TYPES (__type), 0)));\
121 static tree grokparms PROTO((tree, int));
122 static tree lookup_nested_type PROTO((tree, tree));
123 static char *redeclaration_error_message PROTO((tree, tree));
124 static void grok_op_properties PROTO((tree, int, int));
125 static void deactivate_exception_cleanups PROTO((void));
128 PROTO((char *, tree, enum built_in_function, void (*)(), char *));
130 /* a node which has tree code ERROR_MARK, and whose type is itself.
131 All erroneous expressions are replaced with this node. All functions
132 that accept nodes as arguments should avoid generating error messages
133 if this node is one of the arguments, since it is undesirable to get
134 multiple error messages from one error in the input. */
136 tree error_mark_node;
138 /* Erroneous argument lists can use this *IFF* they do not modify it. */
139 tree error_mark_list;
141 /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
143 tree short_integer_type_node;
144 tree integer_type_node;
145 tree long_integer_type_node;
146 tree long_long_integer_type_node;
148 tree short_unsigned_type_node;
149 tree unsigned_type_node;
150 tree long_unsigned_type_node;
151 tree long_long_unsigned_type_node;
153 tree ptrdiff_type_node;
155 tree unsigned_char_type_node;
156 tree signed_char_type_node;
158 tree wchar_type_node;
159 tree signed_wchar_type_node;
160 tree unsigned_wchar_type_node;
162 tree float_type_node;
163 tree double_type_node;
164 tree long_double_type_node;
166 tree intQI_type_node;
167 tree intHI_type_node;
168 tree intSI_type_node;
169 tree intDI_type_node;
171 tree unsigned_intQI_type_node;
172 tree unsigned_intHI_type_node;
173 tree unsigned_intSI_type_node;
174 tree unsigned_intDI_type_node;
176 /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */
178 tree void_type_node, void_list_node;
181 /* Nodes for types `void *' and `const void *'. */
183 tree ptr_type_node, const_ptr_type_node;
185 /* Nodes for types `char *' and `const char *'. */
187 tree string_type_node, const_string_type_node;
189 /* Type `char[256]' or something like it.
190 Used when an array of char is needed and the size is irrelevant. */
192 tree char_array_type_node;
194 /* Type `int[256]' or something like it.
195 Used when an array of int needed and the size is irrelevant. */
197 tree int_array_type_node;
199 /* Type `wchar_t[256]' or something like it.
200 Used when a wide string literal is created. */
202 tree wchar_array_type_node;
204 /* type `int ()' -- used for implicit declaration of functions. */
206 tree default_function_type;
208 /* function types `double (double)' and `double (double, double)', etc. */
210 tree double_ftype_double, double_ftype_double_double;
211 tree int_ftype_int, long_ftype_long;
213 /* Function type `void (void *, void *, int)' and similar ones. */
215 tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
217 /* Function type `char *(char *, char *)' and similar ones */
218 tree string_ftype_ptr_ptr, int_ftype_string_string;
220 /* Function type `size_t (const char *)' */
221 tree sizet_ftype_string;
223 /* Function type `int (const void *, const void *, size_t)' */
224 tree int_ftype_cptr_cptr_sizet;
227 tree vtable_entry_type;
228 tree delta_type_node;
229 tree __t_desc_type_node, __i_desc_type_node, __m_desc_type_node;
230 tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
231 tree class_star_type_node;
232 tree class_type_node, record_type_node, union_type_node, enum_type_node;
233 tree exception_type_node, unknown_type_node;
234 tree opaque_type_node, signature_type_node;
235 tree sigtable_entry_type;
236 tree maybe_gc_cleanup;
238 /* Used for virtual function tables. */
241 /* Array type `vtable_entry_type[]' */
244 /* Static decls which do not have static initializers have no
245 initializers as far as GNU C is concerned. EMPTY_INIT_NODE
246 is a static initializer which makes varasm code place the decl
247 in data rather than in bss space. Such gymnastics are necessary
248 to avoid the problem that the linker will not include a library
249 file if all the library appears to contribute are bss variables. */
251 tree empty_init_node;
253 /* In a destructor, the point at which all derived class destroying
254 has been done, just before any base class destroying will be done. */
258 /* In a constructor, the point at which we are ready to return
259 the pointer to the initialized object. */
263 /* A FUNCTION_DECL which can call `unhandled_exception'.
264 Not necessarily the one that the user will declare,
265 but sufficient to be called by routines that want to abort the program. */
267 tree unhandled_exception_fndecl;
269 /* A FUNCTION_DECL which can call `abort'. Not necessarily the
270 one that the user will declare, but sufficient to be called
271 by routines that want to abort the program. */
275 extern rtx cleanup_label, return_label;
277 /* If original DECL_RESULT of current function was a register,
278 but due to being an addressable named return value, would up
279 on the stack, this variable holds the named return value's
280 original location. */
281 rtx original_result_rtx;
283 /* Sequence of insns which represents base initialization. */
286 /* C++: Keep these around to reduce calls to `get_identifier'.
287 Identifiers for `this' in member functions and the auto-delete
288 parameter for destructors. */
289 tree this_identifier, in_charge_identifier;
290 /* Used in pointer to member functions, and in vtables. */
291 tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
292 tree pfn_or_delta2_identifier;
294 /* A list (chain of TREE_LIST nodes) of named label uses.
295 The TREE_PURPOSE field is the list of variables defined
296 the the label's scope defined at the point of use.
297 The TREE_VALUE field is the LABEL_DECL used.
298 The TREE_TYPE field holds `current_binding_level' at the
299 point of the label's use.
301 Used only for jumps to as-yet undefined labels, since
302 jumps to defined labels can have their validity checked
305 static tree named_label_uses;
307 /* A list of objects which have constructors or destructors
308 which reside in the global scope. The decl is stored in
309 the TREE_VALUE slot and the initializer is stored
310 in the TREE_PURPOSE slot. */
311 tree static_aggregates;
313 /* A list of functions which were declared inline, but later had their
314 address taken. Used only for non-virtual member functions, since we can
315 find other functions easily enough. */
316 tree pending_addressable_inlines;
318 /* A list of overloaded functions which we should forget ever
319 existed, such as functions declared in a function's scope,
320 once we leave that function's scope. */
321 static tree overloads_to_forget;
325 /* Two expressions that are constants with value zero.
326 The first is of type `int', the second of type `void *'. */
328 tree integer_zero_node;
329 tree null_pointer_node;
331 /* A node for the integer constants 1, 2, and 3. */
333 tree integer_one_node, integer_two_node, integer_three_node;
335 /* Nonzero if we have seen an invalid cross reference
336 to a struct, union, or enum, but not yet printed the message. */
338 tree pending_invalid_xref;
339 /* File and line to appear in the eventual error message. */
340 char *pending_invalid_xref_file;
341 int pending_invalid_xref_line;
343 /* While defining an enum type, this is 1 plus the last enumerator
346 static tree enum_next_value;
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 do emit exported implementations of functions even if
423 they can be inlined. */
425 extern int flag_implement_inlines;
427 /* Nonzero means handle things in ANSI, instead of GNU fashion. This
428 flag should be tested for language behavior that's different between
429 ANSI and GNU, but not so horrible as to merit a PEDANTIC label. */
431 extern int flag_ansi;
433 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
435 extern int flag_huge_objects;
437 /* Nonzero if we want to conserve space in the .o files. We do this
438 by putting uninitialized data and runtime initialized data into
439 .common instead of .data at the expense of not flaging multiple
441 extern int flag_conserve_space;
443 /* Pointers to the base and current top of the language name stack. */
445 extern tree *current_lang_base, *current_lang_stack;
447 /* C and C++ flags are in cp-decl2.c. */
449 /* Set to 0 at beginning of a constructor, set to 1
450 if that function does an allocation before referencing its
451 instance variable. */
452 int current_function_assigns_this;
453 int current_function_just_assigned_this;
455 /* Set to 0 at beginning of a function. Set non-zero when
456 store_parm_decls is called. Don't call store_parm_decls
457 if this flag is non-zero! */
458 int current_function_parms_stored;
460 /* Current end of entries in the gc obstack for stack pointer variables. */
462 int current_function_obstack_index;
464 /* Flag saying whether we have used the obstack in this function or not. */
466 int current_function_obstack_usage;
468 /* Flag used when debugging cp-spew.c */
470 extern int spew_debug;
472 /* This is a copy of the class_shadowed list of the previous class binding
473 contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs
474 when entering another class scope (i.e. a cache miss). */
475 extern tree previous_class_values;
478 /* Allocate a level of searching. */
480 push_decl_level (stack, obstack)
481 struct stack_level *stack;
482 struct obstack *obstack;
484 struct stack_level tem;
487 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
490 /* For each binding contour we allocate a binding_level structure
491 * which records the names defined in that contour.
494 * 1) one for each function definition,
495 * where internal declarations of the parameters appear.
496 * 2) one for each compound statement,
497 * to record its declarations.
499 * The current meaning of a name can be found by searching the levels from
500 * the current one out to the global one.
502 * Off to the side, may be the class_binding_level. This exists
503 * only to catch class-local declarations. It is otherwise
506 * Also there may be binding levels that catch cleanups that
507 * must be run when exceptions occur.
510 /* Note that the information in the `names' component of the global contour
511 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
515 /* A chain of _DECL nodes for all variables, constants, functions,
516 * and typedef types. These are in the reverse of the order supplied.
520 /* A list of structure, union and enum definitions,
521 * for looking up tag names.
522 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
523 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
524 * or ENUMERAL_TYPE node.
526 * C++: the TREE_VALUE nodes can be simple types for component_bindings.
531 /* For each level, a list of shadowed outer-level local definitions
532 to be restored when this level is popped.
533 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
534 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
537 /* Same, for IDENTIFIER_CLASS_VALUE. */
540 /* Same, for IDENTIFIER_TYPE_VALUE. */
543 /* For each level (except not the global one),
544 a chain of BLOCK nodes for all the levels
545 that were entered and exited one level down. */
548 /* The BLOCK node for this level, if one has been preallocated.
549 If 0, the BLOCK is allocated (if needed) when the level is popped. */
552 /* The binding level which this one is contained in (inherits from). */
553 struct binding_level *level_chain;
555 /* Number of decls in `names' that have incomplete
556 structure or union types. */
557 unsigned short n_incomplete;
559 /* 1 for the level that holds the parameters of a function.
560 2 for the level that holds a class declaration.
561 3 for levels that hold parameter declarations. */
562 unsigned parm_flag : 4;
564 /* 1 means make a BLOCK for this level regardless of all else.
565 2 for temporary binding contours created by the compiler. */
568 /* Nonzero if this level "doesn't exist" for tags. */
569 unsigned tag_transparent : 1;
571 /* Nonzero if this level can safely have additional
572 cleanup-needing variables added to it. */
573 unsigned more_cleanups_ok : 1;
574 unsigned have_cleanups : 1;
576 /* Nonzero if this level can safely have additional
577 exception-raising statements added to it. */
578 unsigned more_exceptions_ok : 1;
579 unsigned have_exceptions : 1;
581 /* Nonzero if we should accept any name as an identifier in
582 this scope. This happens in some template definitions. */
583 unsigned accept_any : 1;
585 /* Nonzero if this level is for completing a template class definition
586 inside a binding level that temporarily binds the parameters. This
587 means that definitions here should not be popped off when unwinding
588 this binding level. (Not actually implemented this way,
590 unsigned pseudo_global : 1;
592 /* Two bits left for this word. */
594 #if defined(DEBUG_CP_BINDING_LEVELS)
595 /* Binding depth at which this level began. */
596 unsigned binding_depth;
597 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
600 #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
602 /* The (non-class) binding level currently in effect. */
604 static struct binding_level *current_binding_level;
606 /* The binding level of the current class, if any. */
608 static struct binding_level *class_binding_level;
610 /* The current (class or non-class) binding level currently in effect. */
612 #define inner_binding_level \
613 (class_binding_level ? class_binding_level : current_binding_level)
615 /* A chain of binding_level structures awaiting reuse. */
617 static struct binding_level *free_binding_level;
619 /* The outermost binding level, for names of file scope.
620 This is created when the compiler is started and exists
621 through the entire run. */
623 static struct binding_level *global_binding_level;
625 /* Binding level structures are initialized by copying this one. */
627 static struct binding_level clear_binding_level;
629 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
631 static int keep_next_level_flag;
633 #if defined(DEBUG_CP_BINDING_LEVELS)
634 static int binding_depth = 0;
635 static int is_class_level = 0;
642 for (i = 0; i < binding_depth*2; i++)
645 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
647 static tree pushdecl_with_scope PROTO((tree, struct binding_level *));
650 push_binding_level (newlevel, tag_transparent, keep)
651 struct binding_level *newlevel;
652 int tag_transparent, keep;
654 /* Add this level to the front of the chain (stack) of levels that
656 *newlevel = clear_binding_level;
657 if (class_binding_level)
659 newlevel->level_chain = class_binding_level;
660 class_binding_level = (struct binding_level *)0;
664 newlevel->level_chain = current_binding_level;
666 current_binding_level = newlevel;
667 newlevel->tag_transparent = tag_transparent;
668 newlevel->more_cleanups_ok = 1;
669 newlevel->more_exceptions_ok = 1;
670 newlevel->keep = keep;
671 #if defined(DEBUG_CP_BINDING_LEVELS)
672 newlevel->binding_depth = binding_depth;
674 fprintf (stderr, "push %s level 0x%08x line %d\n",
675 (is_class_level) ? "class" : "block", newlevel, lineno);
678 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
684 if (class_binding_level)
685 current_binding_level = class_binding_level;
687 if (global_binding_level)
689 /* cannot pop a level, if there are none left to pop. */
690 if (current_binding_level == global_binding_level)
691 my_friendly_abort (123);
693 /* Pop the current level, and free the structure for reuse. */
694 #if defined(DEBUG_CP_BINDING_LEVELS)
697 fprintf (stderr, "pop %s level 0x%08x line %d\n",
698 (is_class_level) ? "class" : "block",
699 current_binding_level, lineno);
700 if (is_class_level != (current_binding_level == class_binding_level))
701 #if 0 /* XXX Don't abort when we're watching how things are being managed. */
706 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
710 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
712 register struct binding_level *level = current_binding_level;
713 current_binding_level = current_binding_level->level_chain;
714 level->level_chain = free_binding_level;
715 #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
716 if (level->binding_depth != binding_depth)
718 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
719 free_binding_level = level;
721 class_binding_level = current_binding_level;
722 if (class_binding_level->parm_flag != 2)
723 class_binding_level = 0;
724 while (current_binding_level->parm_flag == 2)
725 current_binding_level = current_binding_level->level_chain;
729 /* Nonzero if we are currently in the global binding level. */
734 return current_binding_level == global_binding_level;
740 keep_next_level_flag = 1;
743 /* Nonzero if the current level needs to have a BLOCK made. */
748 return (current_binding_level->blocks != NULL_TREE
749 || current_binding_level->keep
750 || current_binding_level->names != NULL_TREE
751 || (current_binding_level->tags != NULL_TREE
752 && !current_binding_level->tag_transparent));
755 /* Identify this binding level as a level of parameters. */
758 declare_parm_level ()
760 current_binding_level->parm_flag = 1;
763 /* Identify this binding level as a level of a default exception handler. */
766 declare_implicit_exception ()
768 current_binding_level->parm_flag = 3;
771 /* Nonzero if current binding contour contains expressions
772 that might raise exceptions. */
777 return current_binding_level->have_exceptions;
781 declare_uninstantiated_type_level ()
783 current_binding_level->accept_any = 1;
787 uninstantiated_type_level_p ()
789 return current_binding_level->accept_any;
793 declare_pseudo_global_level ()
795 current_binding_level->pseudo_global = 1;
799 pseudo_global_level_p ()
801 return current_binding_level->pseudo_global;
805 set_class_shadows (shadows)
808 class_binding_level->class_shadowed = shadows;
811 /* Enter a new binding level.
812 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
813 not for that of tags. */
816 pushlevel (tag_transparent)
819 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
821 /* If this is the top level of a function,
822 just make sure that NAMED_LABELS is 0.
823 They should have been set to 0 at the end of the previous function. */
825 if (current_binding_level == global_binding_level)
826 my_friendly_assert (named_labels == NULL_TREE, 134);
828 /* Reuse or create a struct for this binding level. */
830 #if defined(DEBUG_CP_BINDING_LEVELS)
832 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
833 if (free_binding_level)
834 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
836 newlevel = free_binding_level;
837 free_binding_level = free_binding_level->level_chain;
841 /* Create a new `struct binding_level'. */
842 newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
844 push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
845 GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
846 keep_next_level_flag = 0;
850 pushlevel_temporary (tag_transparent)
853 pushlevel (tag_transparent);
854 current_binding_level->keep = 2;
857 /* Note we don't call push_momentary() here. Otherwise, it would cause
858 cleanups to be allocated on the momentary obstack, and they will be
859 overwritten by the next statement. */
861 expand_start_bindings (0);
864 /* Exit a binding level.
865 Pop the level off, and restore the state of the identifier-decl mappings
866 that were in effect when this level was entered.
868 If KEEP == 1, this level had explicit declarations, so
869 and create a "block" (a BLOCK node) for the level
870 to record its declarations and subblocks for symbol table output.
872 If KEEP == 2, this level's subblocks go to the front,
873 not the back of the current binding level. This happens,
874 for instance, when code for constructors and destructors
875 need to generate code at the end of a function which must
876 be moved up to the front of the function.
878 If FUNCTIONBODY is nonzero, this level is the body of a function,
879 so create a block as if KEEP were set and also clear out all
882 If REVERSE is nonzero, reverse the order of decls before putting
883 them into the BLOCK. */
886 poplevel (keep, reverse, functionbody)
892 /* The chain of decls was accumulated in reverse order.
893 Put it into forward order, just for cleanliness. */
895 int tmp = functionbody;
896 int implicit_try_block = current_binding_level->parm_flag == 3;
897 int real_functionbody = current_binding_level->keep == 2
898 ? ((functionbody = 0), tmp) : functionbody;
899 tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
900 tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
901 tree block = NULL_TREE;
903 int block_previously_created;
905 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
906 (HOST_WIDE_INT) current_binding_level->level_chain,
907 current_binding_level->parm_flag,
908 current_binding_level->keep,
909 current_binding_level->tag_transparent);
911 if (current_binding_level->keep == 1)
914 /* This warning is turned off because it causes warnings for
915 declarations like `extern struct foo *x'. */
917 /* Warn about incomplete structure types in this level. */
918 for (link = tags; link; link = TREE_CHAIN (link))
919 if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE)
921 tree type = TREE_VALUE (link);
923 switch (TREE_CODE (type))
926 errmsg = "`struct %s' incomplete in scope ending here";
929 errmsg = "`union %s' incomplete in scope ending here";
932 errmsg = "`enum %s' incomplete in scope ending here";
935 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
936 error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
938 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
939 error (errmsg, TYPE_NAME_STRING (type));
943 /* Get the decls in the order they were written.
944 Usually current_binding_level->names is in reverse order.
945 But parameter decls were previously put in forward order. */
948 current_binding_level->names
949 = decls = nreverse (current_binding_level->names);
951 decls = current_binding_level->names;
953 /* Output any nested inline functions within this block
954 if they weren't already output. */
956 for (decl = decls; decl; decl = TREE_CHAIN (decl))
957 if (TREE_CODE (decl) == FUNCTION_DECL
958 && ! TREE_ASM_WRITTEN (decl)
959 && DECL_INITIAL (decl) != NULL_TREE
960 && TREE_ADDRESSABLE (decl))
962 /* If this decl was copied from a file-scope decl
963 on account of a block-scope extern decl,
964 propagate TREE_ADDRESSABLE to the file-scope decl. */
965 if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
966 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
969 push_function_context ();
970 output_inline_function (decl);
971 pop_function_context ();
975 /* If there were any declarations or structure tags in that level,
976 or if this level is a function body,
977 create a BLOCK to record them for the life of this function. */
980 block_previously_created = (current_binding_level->this_block != NULL_TREE);
981 if (block_previously_created)
982 block = current_binding_level->this_block;
983 else if (keep == 1 || functionbody)
984 block = make_node (BLOCK);
985 if (block != NULL_TREE)
987 BLOCK_VARS (block) = decls;
988 BLOCK_TYPE_TAGS (block) = tags;
989 BLOCK_SUBBLOCKS (block) = subblocks;
990 /* If we created the block earlier on, and we are just diddling it now,
991 then it already should have a proper BLOCK_END_NOTE value associated
992 with it, so avoid trashing that. Otherwise, for a new block, install
993 a new BLOCK_END_NOTE value. */
994 if (! block_previously_created)
995 remember_end_note (block);
998 /* In each subblock, record that this is its superior. */
1001 for (link = subblocks; link; link = TREE_CHAIN (link))
1002 BLOCK_SUPERCONTEXT (link) = block;
1004 /* Clear out the meanings of the local variables of this level. */
1006 for (link = decls; link; link = TREE_CHAIN (link))
1008 if (DECL_NAME (link) != NULL_TREE)
1010 /* If the ident. was used or addressed via a local extern decl,
1011 don't forget that fact. */
1012 if (DECL_EXTERNAL (link))
1014 if (TREE_USED (link))
1015 TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
1016 if (TREE_ADDRESSABLE (link))
1017 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1019 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
1023 /* Restore all name-meanings of the outer levels
1024 that were shadowed by this level. */
1026 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1027 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1028 for (link = current_binding_level->class_shadowed;
1029 link; link = TREE_CHAIN (link))
1030 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1031 for (link = current_binding_level->type_shadowed;
1032 link; link = TREE_CHAIN (link))
1033 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1035 /* If the level being exited is the top level of a function,
1036 check over all the labels. */
1040 /* If this is the top level block of a function,
1041 the vars are the function's parameters.
1042 Don't leave them in the BLOCK because they are
1043 found in the FUNCTION_DECL instead. */
1045 BLOCK_VARS (block) = 0;
1047 /* Clear out the definitions of all label names,
1048 since their scopes end here. */
1050 for (link = named_labels; link; link = TREE_CHAIN (link))
1052 register tree label = TREE_VALUE (link);
1054 if (DECL_INITIAL (label) == NULL_TREE)
1056 cp_error_at ("label `%D' used but not defined", label);
1057 /* Avoid crashing later. */
1058 define_label (input_filename, 1, DECL_NAME (label));
1060 else if (warn_unused && !TREE_USED (label))
1061 cp_warning_at ("label `%D' defined but not used", label);
1062 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
1064 /* Put the labels into the "variables" of the
1065 top-level block, so debugger can see them. */
1066 TREE_CHAIN (label) = BLOCK_VARS (block);
1067 BLOCK_VARS (block) = label;
1070 named_labels = NULL_TREE;
1073 /* Any uses of undefined labels now operate under constraints
1074 of next binding contour. */
1076 struct binding_level *level_chain;
1077 level_chain = current_binding_level->level_chain;
1081 for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
1082 if (TREE_TYPE (labels) == (tree)current_binding_level)
1084 TREE_TYPE (labels) = (tree)level_chain;
1085 TREE_PURPOSE (labels) = level_chain->names;
1090 tmp = current_binding_level->keep;
1092 pop_binding_level ();
1094 DECL_INITIAL (current_function_decl) = block;
1097 if (!block_previously_created)
1098 current_binding_level->blocks
1099 = chainon (current_binding_level->blocks, block);
1101 /* If we did not make a block for the level just exited,
1102 any blocks made for inner levels
1103 (since they cannot be recorded as subblocks in that level)
1104 must be carried forward so they will later become subblocks
1105 of something else. */
1109 current_binding_level->blocks
1110 = chainon (subblocks, current_binding_level->blocks);
1112 current_binding_level->blocks
1113 = chainon (current_binding_level->blocks, subblocks);
1116 /* Take care of compiler's internal binding structures. */
1117 if (tmp == 2 && !implicit_try_block)
1120 /* We did not call push_momentary for this
1121 binding contour, so there is nothing to pop. */
1124 expand_end_bindings (getdecls (), keep, 1);
1125 /* Each and every BLOCK node created here in `poplevel' is important
1126 (e.g. for proper debugging information) so if we created one
1127 earlier, mark it as "used". */
1129 TREE_USED (block) = 1;
1130 block = poplevel (keep, reverse, real_functionbody);
1133 /* Each and every BLOCK node created here in `poplevel' is important
1134 (e.g. for proper debugging information) so if we created one
1135 earlier, mark it as "used". */
1137 TREE_USED (block) = 1;
1141 /* Delete the node BLOCK from the current binding level.
1142 This is used for the block inside a stmt expr ({...})
1143 so that the block can be reinserted where appropriate. */
1146 delete_block (block)
1150 if (current_binding_level->blocks == block)
1151 current_binding_level->blocks = TREE_CHAIN (block);
1152 for (t = current_binding_level->blocks; t;)
1154 if (TREE_CHAIN (t) == block)
1155 TREE_CHAIN (t) = TREE_CHAIN (block);
1159 TREE_CHAIN (block) = NULL_TREE;
1160 /* Clear TREE_USED which is always set by poplevel.
1161 The flag is set again if insert_block is called. */
1162 TREE_USED (block) = 0;
1165 /* Insert BLOCK at the end of the list of subblocks of the
1166 current binding level. This is used when a BIND_EXPR is expanded,
1167 to handle the BLOCK node inside the BIND_EXPR. */
1170 insert_block (block)
1173 TREE_USED (block) = 1;
1174 current_binding_level->blocks
1175 = chainon (current_binding_level->blocks, block);
1178 /* Add BLOCK to the current list of blocks for this binding contour. */
1180 add_block_current_level (block)
1183 current_binding_level->blocks
1184 = chainon (current_binding_level->blocks, block);
1187 /* Set the BLOCK node for the innermost scope
1188 (the one we are currently in). */
1192 register tree block;
1194 current_binding_level->this_block = block;
1197 /* Do a pushlevel for class declarations. */
1201 register struct binding_level *newlevel;
1203 /* Reuse or create a struct for this binding level. */
1204 #if defined(DEBUG_CP_BINDING_LEVELS)
1206 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
1207 if (free_binding_level)
1208 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
1210 newlevel = free_binding_level;
1211 free_binding_level = free_binding_level->level_chain;
1215 /* Create a new `struct binding_level'. */
1216 newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
1219 #if defined(DEBUG_CP_BINDING_LEVELS)
1221 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1223 push_binding_level (newlevel, 0, 0);
1225 decl_stack = push_decl_level (decl_stack, &decl_obstack);
1226 class_binding_level = current_binding_level;
1227 class_binding_level->parm_flag = 2;
1228 /* We have just pushed into a new binding level. Now, fake out the rest
1229 of the compiler. Set the `current_binding_level' back to point to
1230 the most closely containing non-class binding level. */
1233 current_binding_level = current_binding_level->level_chain;
1235 while (current_binding_level->parm_flag == 2);
1238 /* ...and a poplevel for class declarations. */
1242 register struct binding_level *level = class_binding_level;
1243 tree block = NULL_TREE;
1246 my_friendly_assert (level != 0, 354);
1248 decl_stack = pop_stack_level (decl_stack);
1249 for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1250 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1251 /* If we're leaving a toplevel class, don't bother to do the setting
1252 of IDENTIFER_CLASS_VALUE to NULL_TREE, since first of all this slot
1253 shouldn't even be used when current_class_type isn't set, and second,
1254 if we don't touch it here, we're able to use the caching effect if the
1255 next time we're entering a class scope, it is the same class. */
1256 if (current_class_depth != 1)
1257 for (shadowed = level->class_shadowed;
1259 shadowed = TREE_CHAIN (shadowed))
1260 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1262 /* Remember to save what IDENTIFIER's were bound in this scope so we
1263 can recover from cache misses. */
1264 previous_class_values = class_binding_level->class_shadowed;
1265 for (shadowed = level->type_shadowed;
1267 shadowed = TREE_CHAIN (shadowed))
1268 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1270 GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
1271 (HOST_WIDE_INT) class_binding_level->level_chain,
1272 class_binding_level->parm_flag,
1273 class_binding_level->keep,
1274 class_binding_level->tag_transparent);
1276 if (class_binding_level->parm_flag != 2)
1277 class_binding_level = (struct binding_level *)0;
1279 /* Now, pop out of the the binding level which we created up in the
1280 `pushlevel_class' routine. */
1281 #if defined(DEBUG_CP_BINDING_LEVELS)
1283 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1285 pop_binding_level ();
1290 /* For debugging. */
1291 int no_print_functions = 0;
1292 int no_print_builtins = 0;
1295 print_binding_level (lvl)
1296 struct binding_level *lvl;
1300 fprintf (stderr, " blocks=");
1301 fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
1302 fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
1303 lvl->n_incomplete, lvl->parm_flag, lvl->keep);
1304 if (lvl->tag_transparent)
1305 fprintf (stderr, " tag-transparent");
1306 if (lvl->more_cleanups_ok)
1307 fprintf (stderr, " more-cleanups-ok");
1308 if (lvl->have_cleanups)
1309 fprintf (stderr, " have-cleanups");
1310 if (lvl->more_exceptions_ok)
1311 fprintf (stderr, " more-exceptions-ok");
1312 if (lvl->have_exceptions)
1313 fprintf (stderr, " have-exceptions");
1314 fprintf (stderr, "\n");
1317 fprintf (stderr, " names:\t");
1318 /* We can probably fit 3 names to a line? */
1319 for (t = lvl->names; t; t = TREE_CHAIN (t))
1321 if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL))
1323 if (no_print_builtins
1324 && (TREE_CODE(t) == TYPE_DECL)
1325 && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
1328 /* Function decls tend to have longer names. */
1329 if (TREE_CODE (t) == FUNCTION_DECL)
1336 fprintf (stderr, "\n\t");
1339 print_node_brief (stderr, "", t, 0);
1340 if (TREE_CODE (t) == ERROR_MARK)
1344 fprintf (stderr, "\n");
1348 fprintf (stderr, " tags:\t");
1350 for (t = lvl->tags; t; t = TREE_CHAIN (t))
1352 if (TREE_PURPOSE (t) == NULL_TREE)
1354 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1361 fprintf (stderr, "\n\t");
1364 if (TREE_PURPOSE (t) == NULL_TREE)
1366 print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
1367 fprintf (stderr, ">");
1369 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1370 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1373 print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
1374 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1375 fprintf (stderr, ">");
1379 fprintf (stderr, "\n");
1383 fprintf (stderr, " shadowed:");
1384 for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
1386 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1388 fprintf (stderr, "\n");
1390 if (lvl->class_shadowed)
1392 fprintf (stderr, " class-shadowed:");
1393 for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
1395 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1397 fprintf (stderr, "\n");
1399 if (lvl->type_shadowed)
1401 fprintf (stderr, " type-shadowed:");
1402 for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
1405 fprintf (stderr, "\n\t");
1406 print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
1408 print_node_brief (stderr, " ", TREE_VALUE (t), 0);
1410 fprintf (stderr, " (none)");
1411 fprintf (stderr, ">");
1413 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1416 fprintf (stderr, "\n");
1421 print_other_binding_stack (stack)
1422 struct binding_level *stack;
1424 struct binding_level *level;
1425 for (level = stack; level != global_binding_level; level = level->level_chain)
1427 fprintf (stderr, "binding level ");
1428 fprintf (stderr, HOST_PTR_PRINTF, level);
1429 fprintf (stderr, "\n");
1430 print_binding_level (level);
1435 print_binding_stack ()
1437 struct binding_level *b;
1438 fprintf (stderr, "current_binding_level=");
1439 fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
1440 fprintf (stderr, "\nclass_binding_level=");
1441 fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
1442 fprintf (stderr, "\nglobal_binding_level=");
1443 fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
1444 fprintf (stderr, "\n");
1445 if (class_binding_level)
1447 for (b = class_binding_level; b; b = b->level_chain)
1448 if (b == current_binding_level)
1451 b = class_binding_level;
1453 b = current_binding_level;
1456 b = current_binding_level;
1457 print_other_binding_stack (b);
1458 fprintf (stderr, "global:\n");
1459 print_binding_level (global_binding_level);
1462 /* Subroutines for reverting temporarily to top-level for instantiation
1463 of templates and such. We actually need to clear out the class- and
1464 local-value slots of all identifiers, so that only the global values
1465 are at all visible. Simply setting current_binding_level to the global
1466 scope isn't enough, because more binding levels may be pushed. */
1467 struct saved_scope {
1468 struct binding_level *old_binding_level;
1470 struct saved_scope *prev;
1471 tree class_name, class_type, class_decl, function_decl;
1472 struct binding_level *class_bindings;
1473 tree previous_class_type;
1475 static struct saved_scope *current_saved_scope;
1476 extern tree prev_class_type;
1479 push_to_top_level ()
1481 struct saved_scope *s =
1482 (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
1483 struct binding_level *b = current_binding_level;
1484 tree old_bindings = NULL_TREE;
1486 /* Have to include global_binding_level, because class-level decls
1487 aren't listed anywhere useful. */
1488 for (; b; b = b->level_chain)
1492 if (b == global_binding_level)
1495 for (t = b->names; t; t = TREE_CHAIN (t))
1497 tree binding, t1, t2 = t;
1498 tree id = DECL_ASSEMBLER_NAME (t2);
1501 || (!IDENTIFIER_LOCAL_VALUE (id)
1502 && !IDENTIFIER_CLASS_VALUE (id)))
1505 for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
1506 if (TREE_VEC_ELT (t1, 0) == id)
1509 binding = make_tree_vec (4);
1512 my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
1513 TREE_VEC_ELT (binding, 0) = id;
1514 TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
1515 TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
1516 TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
1517 IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
1518 IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
1520 TREE_CHAIN (binding) = old_bindings;
1521 old_bindings = binding;
1525 /* Unwind type-value slots back to top level. */
1526 for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
1527 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
1529 /* Clear out class-level bindings cache. */
1530 if (current_binding_level == global_binding_level
1531 && previous_class_type != NULL_TREE)
1534 previous_class_type = NULL_TREE;
1537 s->old_binding_level = current_binding_level;
1538 current_binding_level = global_binding_level;
1540 s->class_name = current_class_name;
1541 s->class_type = current_class_type;
1542 s->class_decl = current_class_decl;
1543 s->function_decl = current_function_decl;
1544 s->class_bindings = class_binding_level;
1545 s->previous_class_type = previous_class_type;
1546 current_class_name = current_class_type = current_class_decl = NULL_TREE;
1547 current_function_decl = NULL_TREE;
1548 class_binding_level = (struct binding_level *)0;
1549 previous_class_type = NULL_TREE;
1551 s->prev = current_saved_scope;
1552 s->old_bindings = old_bindings;
1553 current_saved_scope = s;
1557 pop_from_top_level ()
1559 struct saved_scope *s = current_saved_scope;
1562 if (previous_class_type)
1563 previous_class_type = NULL_TREE;
1565 current_binding_level = s->old_binding_level;
1566 current_saved_scope = s->prev;
1567 for (t = s->old_bindings; t; t = TREE_CHAIN (t))
1569 tree id = TREE_VEC_ELT (t, 0);
1572 IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
1573 IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
1574 IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
1577 current_class_name = s->class_name;
1578 current_class_type = s->class_type;
1579 current_class_decl = s->class_decl;
1580 if (current_class_type)
1581 C_C_D = CLASSTYPE_INST_VAR (current_class_type);
1584 current_function_decl = s->function_decl;
1585 class_binding_level = s->class_bindings;
1586 previous_class_type = s->previous_class_type;
1590 /* Push a definition of struct, union or enum tag "name".
1591 into binding_level "b". "type" should be the type node,
1592 We assume that the tag "name" is not already defined.
1594 Note that the definition may really be just a forward reference.
1595 In that case, the TYPE_SIZE will be a NULL_TREE.
1597 C++ gratuitously puts all these tags in the name space. */
1599 /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
1600 record the shadowed value for this binding contour. TYPE is
1601 the type that ID maps to. */
1604 set_identifier_type_value_with_scope (id, type, b)
1607 struct binding_level *b;
1609 if (b != global_binding_level)
1611 tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
1613 = tree_cons (id, old_type_value, b->type_shadowed);
1615 SET_IDENTIFIER_TYPE_VALUE (id, type);
1618 /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
1621 set_identifier_type_value (id, type)
1625 set_identifier_type_value_with_scope (id, type, inner_binding_level);
1628 /* Subroutine "set_nested_typename" builds the nested-typename of
1629 the type decl in question. (Argument CLASSNAME can actually be
1630 a function as well, if that's the smallest containing scope.) */
1633 set_nested_typename (decl, classname, name, type)
1634 tree decl, classname, name, type;
1636 my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
1637 if (classname != NULL_TREE)
1640 my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
1641 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
1642 buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
1643 + IDENTIFIER_LENGTH (name));
1644 sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
1645 IDENTIFIER_POINTER (name));
1646 DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
1648 /* This is a special usage of IDENTIFIER_TYPE_VALUE which have no
1649 correspondence in any binding_level. This is ok since the
1650 DECL_NESTED_TYPENAME is just a convenience identifier whose
1651 IDENTIFIER_TYPE_VALUE will remain constant from now on. */
1652 SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type);
1655 DECL_NESTED_TYPENAME (decl) = name;
1658 #if 0 /* not yet, should get fixed properly later */
1659 /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
1660 Other routines shouldn't use build_decl directly; they'll produce
1661 incorrect results with `-g' unless they duplicate this code.
1663 This is currently needed mainly for dbxout.c, but we can make
1664 use of it in cp-method.c later as well. */
1666 make_type_decl (name, type)
1670 decl = build_decl (TYPE_DECL, name, type);
1671 if (TYPE_NAME (type) == name)
1672 /* Class/union/enum definition, or a redundant typedef for same. */
1674 id = get_identifier (build_overload_name (type, 1, 1));
1675 DECL_ASSEMBLER_NAME (decl) = id;
1677 else if (TYPE_NAME (type) != NULL_TREE)
1678 /* Explicit typedef, or implicit typedef for template expansion. */
1679 DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
1682 /* XXX: Typedef for unnamed struct; some other situations.
1683 TYPE_NAME is null; what's right here? */
1689 /* Push a tag name NAME for struct/class/union/enum type TYPE.
1690 Normally put into into the inner-most non-tag-tranparent scope,
1691 but if GLOBALIZE is true, put it in the inner-most non-class scope.
1692 The latter is needed for implicit declarations. */
1695 pushtag (name, type, globalize)
1699 register struct binding_level *b;
1702 b = inner_binding_level;
1703 while (b->tag_transparent
1704 || (globalize && b->parm_flag == 2))
1707 if (b == global_binding_level)
1708 b->tags = perm_tree_cons (name, type, b->tags);
1710 b->tags = saveable_tree_cons (name, type, b->tags);
1714 t_context = type ? TYPE_CONTEXT(type) : NULL_TREE;
1715 if (!t_context && !globalize)
1716 t_context = current_class_type;
1718 /* Record the identifier as the type's name if it has none. */
1719 if (TYPE_NAME (type) == NULL_TREE)
1720 TYPE_NAME (type) = name;
1722 /* Do C++ gratuitous typedefing. */
1723 if (IDENTIFIER_TYPE_VALUE (name) != type
1724 && (TREE_CODE (type) != RECORD_TYPE
1725 || b->parm_flag != 2
1726 || !CLASSTYPE_DECLARED_EXCEPTION (type)))
1731 if (b->parm_flag != 2
1732 || TYPE_SIZE (current_class_type) != NULL_TREE)
1734 if (current_lang_name == lang_name_cplusplus)
1735 d = lookup_nested_type (type,
1736 t_context ? TYPE_NAME (t_context) : NULL_TREE);
1743 #if 0 /* not yet, should get fixed properly later */
1744 d = make_type_decl (name, type);
1746 d = build_decl (TYPE_DECL, name, type);
1748 #ifdef DWARF_DEBUGGING_INFO
1749 if (write_symbols == DWARF_DEBUG)
1751 /* Mark the TYPE_DECL node we created just above as an
1752 gratuitous one. We need to do this so that dwarfout.c
1753 will understand that it is not supposed to output a
1754 TAG_typedef DIE for it. */
1755 DECL_IGNORED_P (d) = 1;
1757 #endif /* DWARF_DEBUGGING_INFO */
1758 set_identifier_type_value_with_scope (name, type, b);
1763 /* If it is anonymous, then we are called from pushdecl,
1764 and we don't want to infinitely recurse. Also, if the
1765 name is already in scope, we don't want to push it
1766 again--pushdecl is only for pushing new decls. */
1767 if (! ANON_AGGRNAME_P (name)
1769 && (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
1770 || lookup_name (name, 1) != TYPE_NAME (type)))
1772 if (b->parm_flag == 2)
1773 d = pushdecl_class_level (d);
1775 d = pushdecl_with_scope (d, b);
1780 /* Make nested declarations go into class-level scope. */
1782 d = build_lang_field_decl (TYPE_DECL, name, type);
1783 #ifdef DWARF_DEBUGGING_INFO
1784 if (write_symbols == DWARF_DEBUG)
1786 /* Mark the TYPE_DECL node we created just above as an
1787 gratuitous one. We need to do this so that dwarfout.c
1788 will understand that it is not supposed to output a
1789 TAG_typedef DIE for it. */
1790 DECL_IGNORED_P (d) = 1;
1792 #endif /* DWARF_DEBUGGING_INFO */
1793 /* Make sure we're in this type's scope when we push the
1794 decl for a template, otherwise class_binding_level will
1795 be NULL and we'll end up dying inside of
1796 push_class_level_binding. */
1797 if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
1798 pushclass (type, 0);
1799 d = pushdecl_class_level (d);
1800 if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
1803 if (write_symbols != DWARF_DEBUG)
1805 if (ANON_AGGRNAME_P (name))
1806 DECL_IGNORED_P (d) = 1;
1808 TYPE_NAME (type) = d;
1810 if ((t_context == NULL_TREE
1811 && current_function_decl == NULL_TREE)
1812 || current_lang_name != lang_name_cplusplus)
1813 /* Non-nested class. */
1814 DECL_NESTED_TYPENAME (d) = name;
1815 else if (current_function_decl != NULL_TREE)
1817 /* Function-nested class. */
1818 set_nested_typename (d,
1819 DECL_ASSEMBLER_NAME (current_function_decl), name, type);
1820 /* This builds the links for classes nested in fn scope. */
1821 DECL_CONTEXT (d) = current_function_decl;
1823 /* else if (TYPE_SIZE (current_class_type) == NULL_TREE)
1825 else if (t_context && TREE_CODE (t_context) == RECORD_TYPE)
1827 /* Class-nested class. */
1828 set_nested_typename (d,
1829 DECL_NESTED_TYPENAME (TYPE_NAME (t_context)), name, type);
1830 /* This builds the links for classes nested in type scope. */
1831 DECL_CONTEXT (d) = t_context;
1832 DECL_CLASS_CONTEXT (d) = t_context;
1834 TYPE_CONTEXT (type) = DECL_CONTEXT (d);
1836 DECL_ASSEMBLER_NAME (d)
1837 = get_identifier (build_overload_name (type, 1, 1));
1839 if (b->parm_flag == 2)
1841 TREE_NONLOCAL_FLAG (type) = 1;
1842 if (TYPE_SIZE (current_class_type) == NULL_TREE)
1843 CLASSTYPE_TAGS (current_class_type) = b->tags;
1847 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1848 /* Use the canonical TYPE_DECL for this node. */
1849 TYPE_STUB_DECL (type) = TYPE_NAME (type);
1852 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
1853 will be the tagged type we just added to the current
1854 binding level. This fake NULL-named TYPE_DECL node helps
1855 dwarfout.c to know when it needs to output a
1856 representation of a tagged type, and it also gives us a
1857 convenient place to record the "scope start" address for
1860 #if 0 /* not yet, should get fixed properly later */
1861 tree d = make_type_decl (NULL_TREE, type);
1863 tree d = build_decl (TYPE_DECL, NULL_TREE, type);
1865 TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
1869 /* Counter used to create anonymous type names. */
1870 static int anon_cnt = 0;
1872 /* Return an IDENTIFIER which can be used as a name for
1873 anonymous structs and unions. */
1879 sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
1880 return get_identifier (buf);
1883 /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
1884 This keeps dbxout from getting confused. */
1888 register struct binding_level *b;
1890 static int last_cnt = 0;
1892 /* Fast out if no new anon names were declared. */
1893 if (last_cnt == anon_cnt)
1896 b = current_binding_level;
1897 while (b->tag_transparent)
1902 /* A NULL purpose means we have already processed all tags
1903 from here to the end of the list. */
1904 if (TREE_PURPOSE (tags) == NULL_TREE)
1906 if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
1907 TREE_PURPOSE (tags) = NULL_TREE;
1908 tags = TREE_CHAIN (tags);
1910 last_cnt = anon_cnt;
1913 /* Subroutine of duplicate_decls: return truthvalue of whether
1914 or not types of these decls match.
1916 For C++, we must compare the parameter list so that `int' can match
1917 `int&' in a parameter position, but `int&' is not confused with
1920 decls_match (newdecl, olddecl)
1921 tree newdecl, olddecl;
1925 if (TREE_CODE (newdecl) == FUNCTION_DECL && TREE_CODE (olddecl) == FUNCTION_DECL)
1927 tree f1 = TREE_TYPE (newdecl);
1928 tree f2 = TREE_TYPE (olddecl);
1929 tree p1 = TYPE_ARG_TYPES (f1);
1930 tree p2 = TYPE_ARG_TYPES (f2);
1932 /* When we parse a static member function definition,
1933 we put together a FUNCTION_DECL which thinks its type
1934 is METHOD_TYPE. Change that to FUNCTION_TYPE, and
1936 if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
1937 revert_static_member_fn (&f1, &newdecl, &p1);
1938 else if (TREE_CODE (f2) == METHOD_TYPE
1939 && DECL_STATIC_FUNCTION_P (newdecl))
1940 revert_static_member_fn (&f2, &olddecl, &p2);
1942 /* Here we must take care of the case where new default
1943 parameters are specified. Also, warn if an old
1944 declaration becomes ambiguous because default
1945 parameters may cause the two to be ambiguous. */
1946 if (TREE_CODE (f1) != TREE_CODE (f2))
1948 if (TREE_CODE (f1) == OFFSET_TYPE)
1949 cp_compiler_error ("`%D' redeclared as member function", newdecl);
1951 cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
1955 if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (f1)),
1956 TYPE_MAIN_VARIANT (TREE_TYPE (f2)), 2))
1957 types_match = compparms (p1, p2, 2);
1963 if (TREE_TYPE (newdecl) == error_mark_node)
1964 types_match = TREE_TYPE (olddecl) == error_mark_node;
1965 else if (TREE_TYPE (olddecl) == NULL_TREE)
1966 types_match = TREE_TYPE (newdecl) == NULL_TREE;
1968 types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
1974 /* If NEWDECL is `static' and an `extern' was seen previously,
1975 warn about it. (OLDDECL may be NULL_TREE; NAME contains
1976 information about previous usage as an `extern'.)
1978 Note that this does not apply to the C++ case of declaring
1979 a variable `extern const' and then later `const'.
1981 Don't complain if -traditional, since traditional compilers
1984 Don't complain about built-in functions, since they are beyond
1985 the user's control. */
1988 warn_extern_redeclared_static (newdecl, olddecl)
1989 tree newdecl, olddecl;
1993 static char *explicit_extern_static_warning
1994 = "`%D' was declared `extern' and later `static'";
1995 static char *implicit_extern_static_warning
1996 = "`%D' was declared implicitly `extern' and later `static'";
1998 if (flag_traditional
1999 || TREE_CODE (newdecl) == TYPE_DECL
2000 || (! warn_extern_inline
2001 && DECL_INLINE (newdecl)))
2004 name = DECL_ASSEMBLER_NAME (newdecl);
2005 if (TREE_PUBLIC (name) && ! TREE_PUBLIC (newdecl))
2007 /* It's okay to redeclare an ANSI built-in function as static,
2008 or to declare a non-ANSI built-in function as anything. */
2009 if (! (TREE_CODE (newdecl) == FUNCTION_DECL
2010 && olddecl != NULL_TREE
2011 && TREE_CODE (olddecl) == FUNCTION_DECL
2012 && (DECL_BUILT_IN (olddecl)
2013 || DECL_BUILT_IN_NONANSI (olddecl))))
2015 cp_warning (IDENTIFIER_IMPLICIT_DECL (name)
2016 ? implicit_extern_static_warning
2017 : explicit_extern_static_warning, newdecl);
2018 if (olddecl != NULL_TREE)
2019 cp_warning_at ("previous declaration of `%D'", olddecl);
2024 /* Handle when a new declaration NEWDECL has the same name as an old
2025 one OLDDECL in the same binding contour. Prints an error message
2028 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
2029 Otherwise, return 0. */
2032 duplicate_decls (newdecl, olddecl)
2033 register tree newdecl, olddecl;
2035 extern struct obstack permanent_obstack;
2036 unsigned olddecl_uid = DECL_UID (olddecl);
2037 int olddecl_friend = 0, types_match = 0;
2038 int new_defines_function;
2039 tree previous_c_decl = NULL_TREE;
2041 if (TREE_CODE (newdecl) == FUNCTION_DECL
2042 && is_overloaded_fn (olddecl))
2044 olddecl = get_first_fn (olddecl);
2048 if (DECL_LANGUAGE (olddecl) == lang_c)
2049 previous_c_decl = olddecl;
2051 /* Redeclaration. */
2052 if (decls_match (newdecl, olddecl))
2057 /* Ambiguous overload. */
2058 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2059 TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 2))
2062 /* Attempt to define multiple C-binding fns. */
2063 if (previous_c_decl)
2066 olddecl = DECL_CHAIN (olddecl);
2070 /* If we found no match, make this join the other
2071 overloaded decls. */
2072 DECL_OVERLOADED (newdecl) = 1;
2077 types_match = decls_match (newdecl, olddecl);
2079 if (TREE_CODE (olddecl) != TREE_LIST)
2080 olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
2082 /* If either the type of the new decl or the type of the old decl is an
2083 error_mark_node, then that implies that we have already issued an
2084 error (earlier) for some bogus type specification, and in that case,
2085 it is rather pointless to harass the user with yet more error message
2086 about the same declaration, so well just pretent the types match here. */
2087 if ((TREE_TYPE (newdecl)
2088 && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
2089 || (TREE_TYPE (olddecl)
2090 && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
2093 if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2095 cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
2096 if (TREE_CODE (olddecl) == TREE_LIST)
2097 olddecl = TREE_VALUE (olddecl);
2098 cp_error_at ("previous declaration of `%#D'", olddecl);
2100 /* New decl is completely inconsistent with the old one =>
2101 tell caller to replace the old one. */
2106 if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
2107 && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
2108 /* If -traditional, avoid error for redeclaring fcn
2109 after implicit decl. */
2111 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2112 && (DECL_BUILT_IN (olddecl)
2113 || DECL_BUILT_IN_NONANSI (olddecl)))
2115 /* If you declare a built-in or predefined function name as static,
2116 the old definition is overridden,
2117 but optionally warn this was a bad choice of name. */
2118 if (! TREE_PUBLIC (newdecl))
2121 cp_warning ("shadowing %s function `%#D'",
2122 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
2124 /* Discard the old built-in function. */
2127 /* Likewise, if the built-in is not ansi, then programs can
2128 override it even globally without an error. */
2129 else if (! DECL_BUILT_IN (olddecl))
2130 cp_warning ("library function `%#D' declared as non-function",
2135 cp_warning ("declaration of `%#D'", newdecl);
2136 cp_warning ("conflicts with built-in declaration `%#D'",
2141 else if (!types_match && previous_c_decl
2142 && DECL_LANGUAGE (newdecl) == lang_c)
2144 cp_error ("declaration of C function `%#D' conflicts with", newdecl);
2145 cp_error_at ("previous declaration `%#D' here", previous_c_decl);
2147 else if (!types_match)
2149 tree oldtype = TREE_TYPE (olddecl);
2150 tree newtype = TREE_TYPE (newdecl);
2153 /* Already complained about this, so don't do so again. */
2154 if (current_class_type == NULL_TREE
2155 || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
2159 /* Since we're doing this before finish_struct can set the
2160 line number on NEWDECL, we just do a regular error here. */
2161 if (DECL_SOURCE_LINE (newdecl) == 0)
2162 cp_error ("conflicting types for `%#D'", newdecl);
2164 cp_error_at ("conflicting types for `%#D'", newdecl);
2167 /* Check for function type mismatch
2168 involving an empty arglist vs a nonempty one. */
2169 if (TREE_CODE (olddecl) == FUNCTION_DECL
2170 && comptypes (TREE_TYPE (oldtype),
2171 TREE_TYPE (newtype), 1)
2172 && ((TYPE_ARG_TYPES (oldtype) == NULL_TREE
2173 && DECL_INITIAL (olddecl) == NULL_TREE)
2174 || (TYPE_ARG_TYPES (newtype) == NULL_TREE
2175 && DECL_INITIAL (newdecl) == NULL_TREE)))
2177 /* Classify the problem further. */
2178 register tree t = TYPE_ARG_TYPES (oldtype);
2181 t = TYPE_ARG_TYPES (newtype);
2182 for (; t; t = TREE_CHAIN (t))
2184 register tree type = TREE_VALUE (t);
2186 if (TREE_CHAIN (t) == NULL_TREE && type != void_type_node)
2189 error ("A parameter list with an ellipsis can't match");
2190 error ("an empty parameter name list declaration.");
2194 if (TYPE_MAIN_VARIANT (type) == float_type_node
2195 || C_PROMOTING_INTEGER_TYPE_P (type))
2198 error ("An argument type that has a default promotion");
2199 error ("can't match an empty parameter name list declaration.");
2205 cp_error_at ("previous declaration as `%#D'", olddecl);
2207 /* There is one thing GNU C++ cannot tolerate: a constructor
2208 which takes the type of object being constructed.
2209 Farm that case out here. */
2210 if (TREE_CODE (newdecl) == FUNCTION_DECL
2211 && DECL_CONSTRUCTOR_P (newdecl))
2213 tree tmp = TREE_CHAIN (TYPE_ARG_TYPES (newtype));
2215 if (tmp != NULL_TREE
2216 && (TYPE_MAIN_VARIANT (TREE_VALUE (tmp))
2217 == TYPE_METHOD_BASETYPE (newtype)))
2219 tree parm = TREE_CHAIN (DECL_ARGUMENTS (newdecl));
2221 = hash_tree_chain (build_reference_type (TREE_VALUE (tmp)),
2224 DECL_ARG_TYPE (parm)
2226 = TYPE_REFERENCE_TO (TREE_VALUE (tmp));
2228 TREE_TYPE (newdecl) = newtype
2229 = build_cplus_method_type (TYPE_METHOD_BASETYPE (newtype),
2230 TREE_TYPE (newtype), argtypes);
2231 error ("constructor cannot take as argument the type being constructed");
2232 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl), current_class_type);
2238 char *errmsg = redeclaration_error_message (newdecl, olddecl);
2241 error_with_decl (newdecl, errmsg);
2242 if (DECL_NAME (olddecl) != NULL_TREE)
2243 cp_error_at ((DECL_INITIAL (olddecl)
2244 && current_binding_level == global_binding_level)
2245 ? "`%#D' previously defined here"
2246 : "`%#D' previously declared here", olddecl);
2248 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2249 && DECL_INITIAL (olddecl) != NULL_TREE
2250 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
2251 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
2253 /* Prototype decl follows defn w/o prototype. */
2254 cp_warning_at ("prototype for `%#D'", newdecl);
2255 cp_warning_at ("follows non-prototype definition here", olddecl);
2257 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2258 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2259 /* extern "C" int foo ();
2260 int foo () { bar (); }
2262 if (current_lang_stack == current_lang_base)
2263 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2266 cp_error_at ("previous declaration of `%#D' with %L linkage",
2267 olddecl, DECL_LANGUAGE (olddecl));
2268 cp_error ("conflicts with new declaration with %L linkage",
2269 DECL_LANGUAGE (newdecl));
2272 /* These bits are logically part of the type. */
2274 && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
2275 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
2276 cp_error_at ("type qualifiers for `%D' conflict with previous decl", newdecl);
2279 /* If new decl is `static' and an `extern' was seen previously,
2281 warn_extern_redeclared_static (newdecl, olddecl);
2283 /* We have committed to returning 1 at this point. */
2284 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2286 /* Now that functions must hold information normally held
2287 by field decls, there is extra work to do so that
2288 declaration information does not get destroyed during
2290 if (DECL_VINDEX (olddecl))
2291 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2292 if (DECL_CONTEXT (olddecl))
2293 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2294 if (DECL_CLASS_CONTEXT (olddecl))
2295 DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
2296 if (DECL_CHAIN (newdecl) == NULL_TREE)
2297 DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2298 if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
2299 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
2302 /* Deal with C++: must preserve virtual function table size. */
2303 if (TREE_CODE (olddecl) == TYPE_DECL)
2305 register tree newtype = TREE_TYPE (newdecl);
2306 register tree oldtype = TREE_TYPE (olddecl);
2308 if (newtype != error_mark_node && oldtype != error_mark_node
2309 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2311 CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
2312 CLASSTYPE_FRIEND_CLASSES (newtype)
2313 = CLASSTYPE_FRIEND_CLASSES (oldtype);
2315 /* why assert here? Just because debugging information is
2317 /* it happens on something like:
2318 typedef struct Thing {
2324 my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl), 139);
2328 /* Special handling ensues if new decl is a function definition. */
2329 new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
2330 && DECL_INITIAL (newdecl) != NULL_TREE);
2332 /* Optionally warn about more than one declaration for the same name,
2333 but don't warn about a function declaration followed by a definition. */
2334 if (warn_redundant_decls
2335 && DECL_SOURCE_LINE (olddecl) != 0
2336 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2337 /* Don't warn about extern decl followed by (tentative) definition. */
2338 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
2340 cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
2341 cp_warning ("previous declaration of `%D'", olddecl);
2344 /* Copy all the DECL_... slots specified in the new decl
2345 except for any that we copy here from the old type. */
2349 /* Automatically handles default parameters. */
2350 tree oldtype = TREE_TYPE (olddecl);
2351 /* Merge the data types specified in the two decls. */
2352 tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2354 if (TREE_CODE (newdecl) == VAR_DECL)
2355 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2356 /* Do this after calling `common_type' so that default
2357 parameters don't confuse us. */
2358 else if (TREE_CODE (newdecl) == FUNCTION_DECL
2359 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
2360 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
2362 tree ctype = NULL_TREE;
2363 ctype = DECL_CLASS_CONTEXT (newdecl);
2364 TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype,
2365 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
2366 TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype,
2367 TYPE_RAISES_EXCEPTIONS (oldtype));
2369 if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE(olddecl), 0))
2371 cp_error ("declaration of `%D' raises different exceptions...", newdecl);
2372 cp_error_at ("...from previous declaration here", olddecl);
2375 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2377 /* Lay the type out, unless already done. */
2378 if (oldtype != TREE_TYPE (newdecl))
2380 if (TREE_TYPE (newdecl) != error_mark_node)
2381 layout_type (TREE_TYPE (newdecl));
2382 if (TREE_CODE (newdecl) != FUNCTION_DECL
2383 && TREE_CODE (newdecl) != TYPE_DECL
2384 && TREE_CODE (newdecl) != CONST_DECL)
2385 layout_decl (newdecl, 0);
2389 /* Since the type is OLDDECL's, make OLDDECL's size go with. */
2390 DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
2393 /* Merge the type qualifiers. */
2394 if (TREE_READONLY (newdecl))
2395 TREE_READONLY (olddecl) = 1;
2396 if (TREE_THIS_VOLATILE (newdecl))
2397 TREE_THIS_VOLATILE (olddecl) = 1;
2399 /* Merge the initialization information. */
2400 if (DECL_INITIAL (newdecl) == NULL_TREE)
2401 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2402 /* Keep the old rtl since we can safely use it, unless it's the
2403 call to abort() used for abstract virtuals. */
2404 if ((DECL_LANG_SPECIFIC (olddecl)
2405 && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
2406 || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
2407 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2409 /* If cannot merge, then use the new type and qualifiers,
2410 and don't preserve the old rtl. */
2413 /* Clean out any memory we had of the old declaration. */
2414 tree oldstatic = value_member (olddecl, static_aggregates);
2416 TREE_VALUE (oldstatic) = error_mark_node;
2418 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2419 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2420 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2421 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2424 /* Merge the storage class information. */
2425 if (DECL_EXTERNAL (newdecl))
2427 TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
2428 DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
2430 /* For functions, static overrides non-static. */
2431 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2433 TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
2434 /* This is since we don't automatically
2435 copy the attributes of NEWDECL into OLDDECL. */
2436 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2437 /* If this clears `static', clear it in the identifier too. */
2438 if (! TREE_PUBLIC (olddecl))
2439 TREE_PUBLIC (DECL_ASSEMBLER_NAME (olddecl)) = 0;
2442 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2446 TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
2447 /* A `const' which was not declared `extern' and is
2448 in static storage is invisible. */
2449 if (TREE_CODE (newdecl) == VAR_DECL
2450 && TREE_READONLY (newdecl) && TREE_STATIC (newdecl)
2451 && ! DECL_THIS_EXTERN (newdecl))
2452 TREE_PUBLIC (newdecl) = 0;
2453 TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
2456 /* If either decl says `inline', this fn is inline,
2457 unless its definition was passed already. */
2458 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
2459 DECL_INLINE (olddecl) = 1;
2460 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
2462 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2464 if (new_defines_function)
2465 /* If defining a function declared with other language
2466 linkage, use the previously declared language linkage. */
2467 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2470 /* If redeclaring a builtin function, and not a definition,
2471 it stays built in. */
2472 if (DECL_BUILT_IN (olddecl))
2474 DECL_BUILT_IN (newdecl) = 1;
2475 DECL_SET_FUNCTION_CODE (newdecl, DECL_FUNCTION_CODE (olddecl));
2476 /* If we're keeping the built-in definition, keep the rtl,
2477 regardless of declaration matches. */
2478 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2481 DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2483 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2484 if (DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))
2485 /* Previously saved insns go together with
2486 the function's previous definition. */
2487 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2488 /* Don't clear out the arguments if we're redefining a function. */
2489 if (DECL_ARGUMENTS (olddecl))
2490 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2494 /* Now preserve various other info from the definition. */
2495 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2496 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
2497 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
2499 /* Don't really know how much of the language-specific
2500 values we should copy from old to new. */
2501 if (DECL_LANG_SPECIFIC (olddecl))
2503 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
2504 DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
2507 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2510 struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
2511 struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
2513 function_size = sizeof (struct tree_decl);
2515 bcopy ((char *) newdecl + sizeof (struct tree_common),
2516 (char *) olddecl + sizeof (struct tree_common),
2517 function_size - sizeof (struct tree_common));
2519 /* Can we safely free the storage used by newdecl? */
2521 #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
2522 & ~ obstack_alignment_mask (&permanent_obstack))
2524 if ((char *)newdecl + ROUND (function_size)
2525 + ROUND (sizeof (struct lang_decl))
2526 == obstack_next_free (&permanent_obstack))
2528 DECL_MAIN_VARIANT (newdecl) = olddecl;
2529 DECL_LANG_SPECIFIC (olddecl) = ol;
2530 bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
2532 obstack_free (&permanent_obstack, newdecl);
2534 else if (LANG_DECL_PERMANENT (ol))
2536 if (DECL_MAIN_VARIANT (olddecl) == olddecl)
2538 /* Save these lang_decls that would otherwise be lost. */
2539 extern tree free_lang_decl_chain;
2540 tree free_lang_decl = (tree) ol;
2541 TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
2542 free_lang_decl_chain = free_lang_decl;
2552 bcopy ((char *) newdecl + sizeof (struct tree_common),
2553 (char *) olddecl + sizeof (struct tree_common),
2554 sizeof (struct tree_decl) - sizeof (struct tree_common)
2555 + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
2558 DECL_UID (olddecl) = olddecl_uid;
2560 DECL_FRIEND_P (olddecl) = 1;
2565 /* Record a decl-node X as belonging to the current lexical scope.
2566 Check for errors (such as an incompatible declaration for the same
2567 name already seen in the same scope).
2569 Returns either X or an old decl for the same name.
2570 If an old decl is returned, it may have been smashed
2571 to agree with what X says. */
2578 #if 0 /* not yet, should get fixed properly later */
2581 register tree name = DECL_ASSEMBLER_NAME (x);
2583 register struct binding_level *b = current_binding_level;
2586 static int nglobals; int len;
2588 len = list_length (global_binding_level->names);
2590 my_friendly_abort (8);
2591 else if (len > nglobals)
2595 /* Don't change DECL_CONTEXT of virtual methods. */
2596 if (x != current_function_decl
2597 && (TREE_CODE (x) != FUNCTION_DECL
2598 || !DECL_VIRTUAL_P (x))
2599 && ! DECL_CONTEXT (x))
2600 DECL_CONTEXT (x) = current_function_decl;
2601 /* A local declaration for a function doesn't constitute nesting. */
2602 if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
2603 DECL_CONTEXT (x) = 0;
2605 #if 0 /* not yet, should get fixed properly later */
2606 /* For functions and class static data, we currently look up the encoded
2607 form of the name. For types, we want the real name. The former will
2608 probably be changed soon, according to MDT. */
2609 if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
2610 name = DECL_ASSEMBLER_NAME (x);
2612 name = DECL_NAME (x);
2614 /* Type are looked up using the DECL_NAME, as that is what the rest of the
2615 compiler wants to use. */
2616 if (TREE_CODE (x) == TYPE_DECL)
2617 name = DECL_NAME (x);
2625 t = lookup_name_current_level (name);
2626 if (t == error_mark_node)
2628 /* error_mark_node is 0 for a while during initialization! */
2630 cp_error_at ("`%#D' used prior to declaration", x);
2635 if (TREE_CODE (t) == PARM_DECL)
2637 if (DECL_CONTEXT (t) == NULL_TREE)
2638 fatal ("parse errors have confused me too much");
2640 file = DECL_SOURCE_FILE (t);
2641 line = DECL_SOURCE_LINE (t);
2645 && (TREE_CODE (t) != TREE_CODE (x) || is_overloaded_fn (t)))
2647 if (TREE_CODE (t) == TYPE_DECL || TREE_CODE (x) == TYPE_DECL)
2649 /* We do nothing special here, because C++ does such nasty
2650 things with TYPE_DECLs. Instead, just let the TYPE_DECL
2651 get shadowed, and know that if we need to find a TYPE_DECL
2652 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
2653 slot of the identifier. */
2656 else if (duplicate_decls (x, t))
2659 else if (t != NULL_TREE && duplicate_decls (x, t))
2662 /* This is turned off until I have time to do it right (bpk). */
2664 /* Also warn if they did a prototype with `static' on it, but
2665 then later left the `static' off. */
2666 else if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
2668 if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
2673 cp_warning ("`static' missing from declaration of `%D'", t);
2674 warning_with_file_and_line (file, line,
2675 "previous declaration of `%s'",
2676 decl_as_string (t, 0));
2679 /* Now fix things so it'll do what they expect. */
2680 if (current_function_decl)
2681 TREE_PUBLIC (current_function_decl) = 0;
2685 /* Due to interference in memory reclamation (X may be
2686 obstack-deallocated at this point), we must guard against
2687 one really special case. */
2688 if (current_function_decl == x)
2689 current_function_decl = t;
2694 /* If declaring a type as a typedef, and the type has no known
2695 typedef name, install this TYPE_DECL as its typedef name. */
2696 if (TREE_CODE (x) == TYPE_DECL)
2698 tree type = TREE_TYPE (x);
2699 tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
2701 if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
2703 /* If these are different names, and we're at the global
2704 binding level, make two equivalent definitions. */
2706 if (global_bindings_p ())
2707 TYPE_NAME (type) = x;
2711 tree tname = DECL_NAME (name);
2713 if (global_bindings_p () && ANON_AGGRNAME_P (tname))
2715 /* do gratuitous C++ typedefing, and make sure that
2716 we access this type either through TREE_TYPE field
2717 or via the tags list. */
2718 TYPE_NAME (TREE_TYPE (x)) = x;
2719 pushtag (tname, TREE_TYPE (x), 0);
2722 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
2724 if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name))
2725 set_nested_typename (x, current_class_name,
2726 DECL_NAME (name), type);
2728 if (type != error_mark_node
2730 && TYPE_IDENTIFIER (type))
2731 set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
2734 /* Multiple external decls of the same identifier ought to match.
2736 We get warnings about inline functions where they are defined.
2737 Avoid duplicate warnings where they are used. */
2738 if (TREE_PUBLIC (x) && !DECL_INLINE (x))
2742 if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
2743 && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
2744 || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
2745 decl = IDENTIFIER_GLOBAL_VALUE (name);
2749 if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1)
2750 /* If different sort of thing, we already gave an error. */
2751 && TREE_CODE (decl) == TREE_CODE (x)
2752 /* If old decl is built-in, we already warned if we should. */
2753 && !DECL_BUILT_IN (decl))
2755 cp_pedwarn ("type mismatch with previous external decl", x);
2756 cp_pedwarn_at ("previous external decl of `%D'", decl);
2760 /* In PCC-compatibility mode, extern decls of vars with no current decl
2761 take effect at top level no matter where they are. */
2762 if (flag_traditional && DECL_EXTERNAL (x)
2763 && lookup_name (name, 0) == NULL_TREE)
2764 b = global_binding_level;
2766 /* This name is new in its binding level.
2767 Install the new declaration and return it. */
2768 if (b == global_binding_level)
2770 /* Install a global value. */
2772 /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
2773 A `const' which was not declared `extern' is invisible. */
2774 if (TREE_CODE (x) == VAR_DECL
2775 && TREE_READONLY (x) && ! DECL_THIS_EXTERN (x))
2776 TREE_PUBLIC (x) = 0;
2778 /* If the first global decl has external linkage,
2779 warn if we later see static one. */
2780 if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x))
2781 TREE_PUBLIC (name) = 1;
2783 /* Don't install a TYPE_DECL if we already have another
2784 sort of _DECL with that name. */
2785 if (TREE_CODE (x) != TYPE_DECL
2787 || TREE_CODE (t) == TYPE_DECL)
2788 IDENTIFIER_GLOBAL_VALUE (name) = x;
2790 /* Don't forget if the function was used via an implicit decl. */
2791 if (IDENTIFIER_IMPLICIT_DECL (name)
2792 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
2795 /* Don't forget if its address was taken in that way. */
2796 if (IDENTIFIER_IMPLICIT_DECL (name)
2797 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
2798 TREE_ADDRESSABLE (x) = 1;
2800 /* Warn about mismatches against previous implicit decl. */
2801 if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
2802 /* If this real decl matches the implicit, don't complain. */
2803 && ! (TREE_CODE (x) == FUNCTION_DECL
2804 && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
2806 ("`%D' was previously implicitly declared to return `int'", x);
2808 /* If new decl is `static' and an `extern' was seen previously,
2810 warn_extern_redeclared_static (x, t);
2814 /* Here to install a non-global value. */
2815 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
2816 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
2818 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2819 IDENTIFIER_LOCAL_VALUE (name) = x;
2821 /* If this is a TYPE_DECL, push it into the type value slot. */
2822 if (TREE_CODE (x) == TYPE_DECL)
2823 set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
2825 /* If this is an extern function declaration, see if we
2826 have a global definition or declaration for the function. */
2827 if (oldlocal == NULL_TREE
2828 && DECL_EXTERNAL (x) && !DECL_INLINE (x)
2829 && oldglobal != NULL_TREE
2830 && TREE_CODE (x) == FUNCTION_DECL
2831 && TREE_CODE (oldglobal) == FUNCTION_DECL)
2833 /* We have one. Their types must agree. */
2834 if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1))
2836 cp_warning ("extern declaration of `%#D' doesn't match", x);
2837 cp_warning_at ("global declaration `%#D'", oldglobal);
2841 /* Inner extern decl is inline if global one is.
2842 Copy enough to really inline it. */
2843 if (DECL_INLINE (oldglobal))
2845 DECL_INLINE (x) = DECL_INLINE (oldglobal);
2846 DECL_INITIAL (x) = (current_function_decl == oldglobal
2847 ? NULL_TREE : DECL_INITIAL (oldglobal));
2848 DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
2849 DECL_FRAME_SIZE (x) = DECL_FRAME_SIZE (oldglobal);
2850 DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
2851 DECL_RESULT (x) = DECL_RESULT (oldglobal);
2852 TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
2853 DECL_ABSTRACT_ORIGIN (x) = oldglobal;
2855 /* Inner extern decl is built-in if global one is. */
2856 if (DECL_BUILT_IN (oldglobal))
2858 DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal);
2859 DECL_SET_FUNCTION_CODE (x, DECL_FUNCTION_CODE (oldglobal));
2861 /* Keep the arg types from a file-scope fcn defn. */
2862 if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != NULL_TREE
2863 && DECL_INITIAL (oldglobal)
2864 && TYPE_ARG_TYPES (TREE_TYPE (x)) == NULL_TREE)
2865 TREE_TYPE (x) = TREE_TYPE (oldglobal);
2868 /* If we have a local external declaration,
2869 and no file-scope declaration has yet been seen,
2870 then if we later have a file-scope decl it must not be static. */
2871 if (oldlocal == NULL_TREE
2872 && oldglobal == NULL_TREE
2873 && DECL_EXTERNAL (x)
2876 TREE_PUBLIC (name) = 1;
2879 if (DECL_FROM_INLINE (x))
2880 /* Inline decls shadow nothing. */;
2882 /* Warn if shadowing an argument at the top level of the body. */
2883 else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
2884 && TREE_CODE (oldlocal) == PARM_DECL
2885 && TREE_CODE (x) != PARM_DECL)
2887 /* Go to where the parms should be and see if we
2889 struct binding_level *b = current_binding_level->level_chain;
2895 if (b->parm_flag == 1)
2896 cp_error ("declaration of `%#D' shadows a parameter", name);
2898 /* Maybe warn if shadowing something else. */
2899 else if (warn_shadow && !DECL_EXTERNAL (x)
2900 /* No shadow warnings for internally generated vars. */
2901 && DECL_SOURCE_LINE (x) != 0
2902 /* No shadow warnings for vars made for inlining. */
2903 && ! DECL_FROM_INLINE (x))
2905 char *warnstring = NULL;
2907 if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
2908 warnstring = "declaration of `%s' shadows a parameter";
2909 else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
2910 && !TREE_STATIC (name))
2911 warnstring = "declaration of `%s' shadows a member of `this'";
2912 else if (oldlocal != NULL_TREE)
2913 warnstring = "declaration of `%s' shadows previous local";
2914 else if (oldglobal != NULL_TREE)
2915 warnstring = "declaration of `%s' shadows global declaration";
2918 warning (warnstring, IDENTIFIER_POINTER (name));
2921 /* If storing a local value, there may already be one (inherited).
2922 If so, record it for restoration when this binding level ends. */
2923 if (oldlocal != NULL_TREE)
2924 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
2927 /* Keep count of variables in this level with incomplete type. */
2928 if (TREE_CODE (x) != TEMPLATE_DECL
2929 && TREE_CODE (x) != CPLUS_CATCH_DECL
2930 && TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
2931 && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
2933 if (++b->n_incomplete == 0)
2934 error ("too many incomplete variables at this point");
2938 if (TREE_CODE (x) == TYPE_DECL && name != NULL_TREE)
2940 if (current_class_name)
2942 if (!DECL_NESTED_TYPENAME (x))
2943 set_nested_typename (x, current_class_name, DECL_NAME (x),
2948 /* Put decls on list in reverse order.
2949 We will reverse them later if necessary. */
2950 TREE_CHAIN (x) = b->names;
2952 if (! (b != global_binding_level || TREE_PERMANENT (x)))
2953 my_friendly_abort (124);
2958 /* Same as pushdecl, but define X in binding-level LEVEL. */
2961 pushdecl_with_scope (x, level)
2963 struct binding_level *level;
2965 register struct binding_level *b = current_binding_level;
2967 current_binding_level = level;
2969 current_binding_level = b;
2973 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
2976 pushdecl_top_level (x)
2979 register struct binding_level *b = inner_binding_level;
2980 register tree t = pushdecl_with_scope (x, global_binding_level);
2982 /* Now, the type_shadowed stack may screw us. Munge it so it does
2984 if (TREE_CODE (x) == TYPE_DECL)
2986 tree name = DECL_NAME (x);
2988 tree *ptr = (tree *)0;
2989 for (; b != global_binding_level; b = b->level_chain)
2991 tree shadowed = b->type_shadowed;
2992 for (; shadowed; shadowed = TREE_CHAIN (shadowed))
2993 if (TREE_PURPOSE (shadowed) == name)
2995 ptr = &TREE_VALUE (shadowed);
2996 /* Can't break out of the loop here because sometimes
2997 a binding level will have duplicate bindings for
2998 PT names. It's gross, but I haven't time to fix it. */
3001 newval = TREE_TYPE (x);
3002 if (ptr == (tree *)0)
3004 /* @@ This shouldn't be needed. My test case "zstring.cc" trips
3005 up here if this is changed to an assertion. --KR */
3006 SET_IDENTIFIER_TYPE_VALUE (name, newval);
3011 /* Disabled this 11/10/92, since there are many cases which
3012 behave just fine when *ptr doesn't satisfy either of these.
3013 For example, nested classes declared as friends of their enclosing
3014 class will not meet this criteria. (bpk) */
3015 my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141);
3023 /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
3026 push_overloaded_decl_top_level (x, forget)
3030 struct binding_level *b = current_binding_level;
3032 current_binding_level = global_binding_level;
3033 push_overloaded_decl (x, forget);
3034 current_binding_level = b;
3037 /* Make the declaration of X appear in CLASS scope. */
3039 pushdecl_class_level (x)
3042 /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class
3043 scope looks for the pre-mangled name. */
3044 register tree name = DECL_NAME (x);
3048 push_class_level_binding (name, x);
3049 if (TREE_CODE (x) == TYPE_DECL)
3051 set_identifier_type_value (name, TREE_TYPE (x));
3052 if (!DECL_NESTED_TYPENAME (x))
3053 set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
3059 /* Make the declaration(s) of X appear in CLASS scope
3060 under the name NAME. */
3062 push_class_level_binding (name, x)
3066 maybe_push_cache_obstack ();
3067 class_binding_level->class_shadowed
3068 = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
3069 class_binding_level->class_shadowed);
3071 IDENTIFIER_CLASS_VALUE (name) = x;
3072 obstack_ptr_grow (&decl_obstack, x);
3075 /* Tell caller how to interpret a TREE_LIST which contains
3076 chains of FUNCTION_DECLS. */
3078 overloaded_globals_p (list)
3081 my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
3083 /* Don't commit caller to seeing them as globals. */
3084 if (TREE_NONLOCAL_FLAG (list))
3086 /* Do commit caller to seeing them as globals. */
3087 if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
3089 /* Do commit caller to not seeing them as globals. */
3093 /* DECL is a FUNCTION_DECL which may have other definitions already in place.
3094 We get around this by making IDENTIFIER_GLOBAL_VALUE (DECL_NAME (DECL))
3095 point to a list of all the things that want to be referenced by that name.
3096 It is then up to the users of that name to decide what to do with that
3099 DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
3100 slot. It is dealt with the same way.
3102 The value returned may be a previous declaration if we guessed wrong
3103 about what language DECL should belong to (C or C++). Otherwise,
3104 it's always DECL (and never something that's not a _DECL). */
3106 push_overloaded_decl (decl, forgettable)
3110 tree orig_name = DECL_NAME (decl);
3111 tree glob = IDENTIFIER_GLOBAL_VALUE (orig_name);
3113 DECL_OVERLOADED (decl) = 1;
3116 && ! flag_traditional
3117 && (glob == NULL_TREE || TREE_PERMANENT (glob) == 1)
3118 && !global_bindings_p ()
3119 && !pseudo_global_level_p ())
3120 overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
3124 if (DECL_LANGUAGE (decl) == lang_c)
3126 tree decls = get_first_fn (glob);
3127 while (decls && DECL_LANGUAGE (decls) == lang_cplusplus)
3128 decls = DECL_CHAIN (decls);
3131 cp_error_at ("C-language function `%#D'", decls);
3132 cp_error ("overloaded as `%#D'", decl);
3136 /* We cache the value of builtin functions as ADDR_EXPRs
3137 in the name space. Convert it to some kind of _DECL after
3138 remembering what to forget. */
3139 if (TREE_CODE (glob) == ADDR_EXPR)
3140 glob = TREE_OPERAND (glob, 0);
3142 else if (TREE_CODE (decl) == TEMPLATE_DECL)
3146 for (tmp = get_first_fn (glob); tmp; tmp = DECL_CHAIN (tmp))
3150 else if (TREE_CODE (glob) == VAR_DECL)
3152 cp_error_at ("previous non-function declaration `%#D'", glob);
3153 cp_error ("conflicts with function declaration `%#D'", decl);
3154 return error_mark_node;
3156 else if (is_overloaded_fn (glob))
3158 tree name = DECL_ASSEMBLER_NAME (decl);
3161 for (tmp = get_first_fn (glob); tmp; tmp = DECL_CHAIN (tmp))
3163 if (TREE_CODE (tmp) == FUNCTION_DECL
3164 && comptypes (TREE_TYPE (tmp), TREE_TYPE (decl), 2))
3166 if (DECL_LANGUAGE (tmp) != DECL_LANGUAGE (decl))
3168 if (current_lang_stack == current_lang_base)
3170 DECL_LANGUAGE (decl) = DECL_LANGUAGE (tmp);
3173 cp_error_at ("previous declaration of `%#D' with %L linkage",
3174 tmp, DECL_LANGUAGE (tmp));
3175 cp_error ("conflicts with new %L-language declaration",
3176 DECL_LANGUAGE (decl));
3178 else if (TREE_CODE (tmp) != TEMPLATE_DECL
3179 && DECL_ASSEMBLER_NAME (tmp) != name)
3181 cp_error ("new declaration `%#D'", decl);
3182 cp_error_at ("ambiguates old declaration `%#D'", tmp);
3185 /* If we really have seen this before, then if it ambiguates
3186 something, we've already given an error before. */
3187 if (TREE_CODE (tmp) != TEMPLATE_DECL
3188 && DECL_ASSEMBLER_NAME (tmp) == name)
3193 if (glob || TREE_CODE (decl) == TEMPLATE_DECL)
3195 if (glob && is_overloaded_fn (glob))
3196 DECL_CHAIN (decl) = get_first_fn (glob);
3198 DECL_CHAIN (decl) = NULL_TREE;
3199 glob = tree_cons (orig_name, decl, NULL_TREE);
3200 TREE_TYPE (glob) = unknown_type_node;
3203 /* orig_name is not ambiguous. */
3206 IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
3210 /* Generate an implicit declaration for identifier FUNCTIONID
3211 as a function of type int (). Print a warning if appropriate. */
3214 implicitly_declare (functionid)
3218 int temp = allocation_temporary_p ();
3220 push_obstacks_nochange ();
3222 /* Save the decl permanently so we can warn if definition follows.
3223 In ANSI C, warn_implicit is usually false, so the saves little space.
3224 But in C++, it's usually true, hence the extra code. */
3225 if (temp && (flag_traditional || !warn_implicit
3226 || current_binding_level == global_binding_level))
3227 end_temporary_allocation ();
3229 /* We used to reuse an old implicit decl here,
3230 but this loses with inline functions because it can clobber
3231 the saved decl chains. */
3232 decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
3234 DECL_EXTERNAL (decl) = 1;
3235 TREE_PUBLIC (decl) = 1;
3237 /* ANSI standard says implicit declarations are in the innermost block.
3238 So we record the decl in the standard fashion.
3239 If flag_traditional is set, pushdecl does it top-level. */
3241 rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
3244 /* Only one warning per identifier. */
3245 && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
3247 cp_pedwarn ("implicit declaration of function `%#D'", decl);
3250 SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
3257 /* Return zero if the declaration NEWDECL is valid
3258 when the declaration OLDDECL (assumed to be for the same name)
3259 has already been seen.
3260 Otherwise return an error message format string with a %s
3261 where the identifier should go. */
3264 redeclaration_error_message (newdecl, olddecl)
3265 tree newdecl, olddecl;
3267 if (TREE_CODE (newdecl) == TYPE_DECL)
3269 /* Because C++ can put things into name space for free,
3270 constructs like "typedef struct foo { ... } foo"
3271 would look like an erroneous redeclaration. */
3272 if (comptypes (newdecl, olddecl, 0))
3275 return "redefinition of `%s'";
3277 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3279 /* If this is a pure function, its olddecl will actually be
3280 the original initialization to `0' (which we force to call
3281 abort()). Don't complain about redefinition in this case. */
3282 if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
3285 /* Declarations of functions can insist on internal linkage
3286 but they can't be inconsistent with internal linkage,
3287 so there can be no error on that account.
3288 However defining the same name twice is no good. */
3289 if (DECL_INITIAL (olddecl) != NULL_TREE
3290 && DECL_INITIAL (newdecl) != NULL_TREE
3291 /* However, defining once as extern inline and a second
3292 time in another way is ok. */
3293 && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
3294 && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
3296 if (DECL_NAME (olddecl) == NULL_TREE)
3297 return "`%s' not declared in class";
3299 return "redefinition of `%s'";
3303 else if (current_binding_level == global_binding_level)
3305 /* Objects declared at top level: */
3306 /* If at least one is a reference, it's ok. */
3307 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3309 /* Reject two definitions. */
3310 if (DECL_INITIAL (olddecl) != NULL_TREE
3311 && DECL_INITIAL (newdecl) != NULL_TREE)
3312 return "redefinition of `%s'";
3313 /* Now we have two tentative defs, or one tentative and one real def. */
3314 /* Insist that the linkage match. */
3315 if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
3316 return "conflicting declarations of `%s'";
3321 /* Objects declared with block scope: */
3322 /* Reject two definitions, and reject a definition
3323 together with an external reference. */
3324 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3325 return "redeclaration of `%s'";
3330 /* Get the LABEL_DECL corresponding to identifier ID as a label.
3331 Create one if none exists so far for the current function.
3332 This function is called for both label definitions and label references. */
3338 register tree decl = IDENTIFIER_LABEL_VALUE (id);
3340 if (current_function_decl == NULL_TREE)
3342 error ("label `%s' referenced outside of any function",
3343 IDENTIFIER_POINTER (id));
3347 if ((decl == NULL_TREE
3348 || DECL_SOURCE_LINE (decl) == 0)
3349 && (named_label_uses == NULL_TREE
3350 || TREE_PURPOSE (named_label_uses) != current_binding_level->names
3351 || TREE_VALUE (named_label_uses) != decl))
3354 = tree_cons (current_binding_level->names, decl, named_label_uses);
3355 TREE_TYPE (named_label_uses) = (tree)current_binding_level;
3358 /* Use a label already defined or ref'd with this name. */
3359 if (decl != NULL_TREE)
3361 /* But not if it is inherited and wasn't declared to be inheritable. */
3362 if (DECL_CONTEXT (decl) != current_function_decl
3363 && ! C_DECLARED_LABEL_FLAG (decl))
3364 return shadow_label (id);
3368 decl = build_decl (LABEL_DECL, id, void_type_node);
3370 /* A label not explicitly declared must be local to where it's ref'd. */
3371 DECL_CONTEXT (decl) = current_function_decl;
3373 DECL_MODE (decl) = VOIDmode;
3375 /* Say where one reference is to the label,
3376 for the sake of the error if it is not defined. */
3377 DECL_SOURCE_LINE (decl) = lineno;
3378 DECL_SOURCE_FILE (decl) = input_filename;
3380 SET_IDENTIFIER_LABEL_VALUE (id, decl);
3382 named_labels = tree_cons (NULL_TREE, decl, named_labels);
3383 TREE_VALUE (named_label_uses) = decl;
3388 /* Make a label named NAME in the current function,
3389 shadowing silently any that may be inherited from containing functions
3390 or containing scopes.
3392 Note that valid use, if the label being shadowed
3393 comes from another scope in the same function,
3394 requires calling declare_nonlocal_label right away. */
3400 register tree decl = IDENTIFIER_LABEL_VALUE (name);
3402 if (decl != NULL_TREE)
3404 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3405 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3406 SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
3409 return lookup_label (name);
3412 /* Define a label, specifying the location in the source file.
3413 Return the LABEL_DECL node for the label, if the definition is valid.
3414 Otherwise return 0. */
3417 define_label (filename, line, name)
3422 tree decl = lookup_label (name);
3424 /* After labels, make any new cleanups go into their
3425 own new (temporary) binding contour. */
3426 current_binding_level->more_cleanups_ok = 0;
3428 /* If label with this name is known from an outer context, shadow it. */
3429 if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
3431 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3432 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3433 decl = lookup_label (name);
3436 if (DECL_INITIAL (decl) != NULL_TREE)
3438 cp_error ("duplicate label `%D'", decl);
3445 /* Mark label as having been defined. */
3446 DECL_INITIAL (decl) = error_mark_node;
3447 /* Say where in the source. */
3448 DECL_SOURCE_FILE (decl) = filename;
3449 DECL_SOURCE_LINE (decl) = line;
3451 for (prev = NULL_TREE, uses = named_label_uses;
3453 prev = uses, uses = TREE_CHAIN (uses))
3454 if (TREE_VALUE (uses) == decl)
3456 struct binding_level *b = current_binding_level;
3459 tree new_decls = b->names;
3460 tree old_decls = ((tree)b == TREE_TYPE (uses)
3461 ? TREE_PURPOSE (uses) : NULL_TREE);
3462 while (new_decls != old_decls)
3464 if (TREE_CODE (new_decls) == VAR_DECL
3465 /* Don't complain about crossing initialization
3466 of internal entities. They can't be accessed,
3467 and they should be cleaned up
3468 by the time we get to the label. */
3469 && DECL_SOURCE_LINE (new_decls) != 0
3470 && ((DECL_INITIAL (new_decls) != NULL_TREE
3471 && DECL_INITIAL (new_decls) != error_mark_node)
3472 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
3474 if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE)
3475 cp_error ("invalid jump to label `%D'", decl);
3476 SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl);
3477 cp_error ("crosses initialization of `%D'", new_decls);
3479 new_decls = TREE_CHAIN (new_decls);
3481 if ((tree)b == TREE_TYPE (uses))
3487 TREE_CHAIN (prev) = TREE_CHAIN (uses);
3489 named_label_uses = TREE_CHAIN (uses);
3491 current_function_return_value = NULL_TREE;
3496 /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */
3497 /* XXX Note decl is never actually used. (bpk) */
3499 define_case_label (decl)
3502 tree cleanup = last_cleanup_this_contour ();
3505 static int explained = 0;
3506 cp_error_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
3507 error ("where case label appears here");
3510 error ("(enclose actions of previous case statements requiring");
3511 error ("destructors in their own binding contours.)");
3516 /* After labels, make any new cleanups go into their
3517 own new (temporary) binding contour. */
3519 current_binding_level->more_cleanups_ok = 0;
3520 current_function_return_value = NULL_TREE;
3523 /* Return the list of declarations of the current level.
3524 Note that this list is in reverse order unless/until
3525 you nreverse it; and when you do nreverse it, you must
3526 store the result back using `storedecls' or you will lose. */
3531 return current_binding_level->names;
3534 /* Return the list of type-tags (for structs, etc) of the current level. */
3539 return current_binding_level->tags;
3542 /* Store the list of declarations of the current level.
3543 This is done for the parameter declarations of a function being defined,
3544 after they are modified in the light of any missing parameters. */
3550 current_binding_level->names = decls;
3553 /* Similarly, store the list of tags of the current level. */
3559 current_binding_level->tags = tags;
3562 /* Given NAME, an IDENTIFIER_NODE,
3563 return the structure (or union or enum) definition for that name.
3564 Searches binding levels from BINDING_LEVEL up to the global level.
3565 If THISLEVEL_ONLY is nonzero, searches only the specified context
3566 (but skips any tag-transparent contexts to find one that is
3567 meaningful for tags).
3568 FORM says which kind of type the caller wants;
3569 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
3570 If the wrong kind of type is found, and it's not a template, an error is
3574 lookup_tag (form, name, binding_level, thislevel_only)
3575 enum tree_code form;
3576 struct binding_level *binding_level;
3580 register struct binding_level *level;
3582 for (level = binding_level; level; level = level->level_chain)
3585 if (ANON_AGGRNAME_P (name))
3586 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3588 /* There's no need for error checking here, because
3589 anon names are unique throughout the compilation. */
3590 if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
3591 return TREE_VALUE (tail);
3594 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3596 if (TREE_PURPOSE (tail) == name)
3598 enum tree_code code = TREE_CODE (TREE_VALUE (tail));
3599 /* Should tighten this up; it'll probably permit
3600 UNION_TYPE and a struct template, for example. */
3602 && !(form != ENUMERAL_TYPE
3603 && (code == TEMPLATE_DECL
3604 || code == UNINSTANTIATED_P_TYPE)))
3607 /* Definition isn't the kind we were looking for. */
3608 cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
3611 return TREE_VALUE (tail);
3614 if (thislevel_only && ! level->tag_transparent)
3616 if (current_class_type && level->level_chain == global_binding_level)
3618 /* Try looking in this class's tags before heading into
3619 global binding level. */
3620 tree context = current_class_type;
3623 switch (TREE_CODE_CLASS (TREE_CODE (context)))
3627 these_tags = CLASSTYPE_TAGS (context);
3628 if (ANON_AGGRNAME_P (name))
3631 if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
3633 return TREE_VALUE (tail);
3634 these_tags = TREE_CHAIN (these_tags);
3639 if (TREE_PURPOSE (these_tags) == name)
3641 if (TREE_CODE (TREE_VALUE (these_tags)) != form)
3643 cp_error ("`%#D' redeclared as %C in class scope",
3644 TREE_VALUE (tail), form);
3646 return TREE_VALUE (tail);
3648 these_tags = TREE_CHAIN (these_tags);
3650 /* If this type is not yet complete, then don't
3651 look at its context. */
3652 if (TYPE_SIZE (context) == NULL_TREE)
3654 /* Go to next enclosing type, if any. */
3655 context = DECL_CONTEXT (TYPE_NAME (context));
3658 context = DECL_CONTEXT (context);
3661 my_friendly_abort (10);
3673 set_current_level_tags_transparency (tags_transparent)
3674 int tags_transparent;
3676 current_binding_level->tag_transparent = tags_transparent;
3679 /* Given a type, find the tag that was defined for it and return the tag name.
3680 Otherwise return 0. However, the value can never be 0
3681 in the cases in which this is used.
3683 C++: If NAME is non-zero, this is the new name to install. This is
3684 done when replacing anonymous tags with real tag names. */
3687 lookup_tag_reverse (type, name)
3691 register struct binding_level *level;
3693 for (level = current_binding_level; level; level = level->level_chain)
3696 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
3698 if (TREE_VALUE (tail) == type)
3701 TREE_PURPOSE (tail) = name;
3702 return TREE_PURPOSE (tail);
3709 /* Given type TYPE which was not declared in C++ language context,
3710 attempt to find a name by which it is referred. */
3712 typedecl_for_tag (tag)
3715 struct binding_level *b = current_binding_level;
3717 if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
3718 return TYPE_NAME (tag);
3722 tree decls = b->names;
3725 if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
3727 decls = TREE_CHAIN (decls);
3736 /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
3737 Return the type value, or NULL_TREE if not found. */
3739 lookup_nested_type (type, context)
3743 if (context == NULL_TREE)
3747 switch (TREE_CODE (context))
3751 tree ctype = TREE_TYPE (context);
3752 tree match = value_member (type, CLASSTYPE_TAGS (ctype));
3754 return TREE_VALUE (match);
3755 context = DECL_CONTEXT (context);
3757 /* When we have a nested class whose member functions have
3758 local types (e.g., a set of enums), we'll arrive here
3759 with the DECL_CONTEXT as the actual RECORD_TYPE node for
3760 the enclosing class. Instead, we want to make sure we
3761 come back in here with the TYPE_DECL, not the RECORD_TYPE. */
3762 if (context && TREE_CODE (context) == RECORD_TYPE)
3763 context = TREE_CHAIN (context);
3767 return TYPE_IDENTIFIER (type) ? lookup_name (TYPE_IDENTIFIER (type), 1) : NULL_TREE;
3770 my_friendly_abort (12);
3776 /* Look up NAME in the current binding level and its superiors in the
3777 namespace of variables, functions and typedefs. Return a ..._DECL
3778 node of some kind representing its definition if there is only one
3779 such declaration, or return a TREE_LIST with all the overloaded
3780 definitions if there are many, or return 0 if it is undefined.
3782 If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
3783 If PREFER_TYPE is = 0, we prefer non-TYPE_DECLs.
3784 If PREFER_TYPE is < 0, we arbitrate according to lexical context. */
3787 lookup_name (name, prefer_type)
3793 if (current_binding_level != global_binding_level
3794 && IDENTIFIER_LOCAL_VALUE (name))
3795 val = IDENTIFIER_LOCAL_VALUE (name);
3796 /* In C++ class fields are between local and global scope,
3797 just before the global scope. */
3798 else if (current_class_type)
3800 val = IDENTIFIER_CLASS_VALUE (name);
3801 if (val == NULL_TREE
3802 && TYPE_SIZE (current_class_type) == NULL_TREE
3803 && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
3805 /* Try to find values from base classes
3806 if we are presently defining a type.
3807 We are presently only interested in TYPE_DECLs. */
3808 val = lookup_field (current_class_type, name, 0, prefer_type < 0);
3809 if (val == error_mark_node)
3811 if (val && TREE_CODE (val) != TYPE_DECL)
3815 /* yylex() calls this with -2, since we should never start digging for
3816 the nested name at the point where we haven't even, for example,
3817 created the COMPONENT_REF or anything like that. */
3818 if (val == NULL_TREE)
3819 val = lookup_nested_field (name, prefer_type != -2);
3821 if (val == NULL_TREE)
3822 val = IDENTIFIER_GLOBAL_VALUE (name);
3825 val = IDENTIFIER_GLOBAL_VALUE (name);
3829 extern int looking_for_typename;
3831 /* Arbitrate between finding a TYPE_DECL and finding
3832 other kinds of _DECLs. */
3833 if (TREE_CODE (val) == TYPE_DECL || looking_for_typename < 0)
3836 if (IDENTIFIER_HAS_TYPE_VALUE (name))
3838 register tree val_as_type = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
3840 if (val == val_as_type || prefer_type > 0
3841 || looking_for_typename > 0)
3843 if (prefer_type == 0)
3845 return arbitrate_lookup (name, val, val_as_type);
3847 if (TREE_TYPE (val) == error_mark_node)
3848 return error_mark_node;
3854 /* Similar to `lookup_name' but look only at current binding level. */
3857 lookup_name_current_level (name)
3860 register tree t = NULL_TREE;
3862 if (current_binding_level == global_binding_level)
3864 t = IDENTIFIER_GLOBAL_VALUE (name);
3866 /* extern "C" function() */
3867 if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
3870 else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
3872 for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
3873 if (DECL_NAME (t) == name)
3880 /* Arrange for the user to get a source line number, even when the
3881 compiler is going down in flames, so that she at least has a
3882 chance of working around problems in the compiler. We used to
3883 call error(), but that let the segmentation fault continue
3884 through; now, it's much more passive by asking them to send the
3885 maintainers mail about the problem. */
3891 signal (SIGSEGV, SIG_DFL);
3893 signal (SIGIOT, SIG_DFL);
3896 signal (SIGILL, SIG_DFL);
3899 signal (SIGABRT, SIG_DFL);
3902 signal (SIGBUS, SIG_DFL);
3904 my_friendly_abort (0);
3907 /* Array for holding types considered "built-in". These types
3908 are output in the module in which `main' is defined. */
3909 static tree *builtin_type_tdescs_arr;
3910 static int builtin_type_tdescs_len, builtin_type_tdescs_max;
3912 /* Push the declarations of builtin types into the namespace.
3913 RID_INDEX, if < RID_MAX is the index of the builtin type
3914 in the array RID_POINTERS. NAME is the name used when looking
3915 up the builtin type. TYPE is the _TYPE node for the builtin type. */
3918 record_builtin_type (rid_index, name, type)
3923 tree rname = NULL_TREE, tname = NULL_TREE;
3926 if ((int) rid_index < (int) RID_MAX)
3927 rname = ridpointers[(int) rid_index];
3929 tname = get_identifier (name);
3931 TYPE_BUILT_IN (type) = 1;
3935 #if 0 /* not yet, should get fixed properly later */
3936 tdecl = pushdecl (make_type_decl (tname, type));
3938 tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
3940 set_identifier_type_value (tname, NULL_TREE);
3941 if ((int) rid_index < (int) RID_MAX)
3942 IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
3944 if (rname != NULL_TREE)
3946 if (tname != NULL_TREE)
3948 set_identifier_type_value (rname, NULL_TREE);
3949 IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
3953 #if 0 /* not yet, should get fixed properly later */
3954 tdecl = pushdecl (make_type_decl (rname, type));
3956 tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
3958 set_identifier_type_value (rname, NULL_TREE);
3964 if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
3966 builtin_type_tdescs_max *= 2;
3967 builtin_type_tdescs_arr
3968 = (tree *)xrealloc (builtin_type_tdescs_arr,
3969 builtin_type_tdescs_max * sizeof (tree));
3971 builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
3972 if (TREE_CODE (type) != POINTER_TYPE)
3974 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3975 = build_pointer_type (type);
3976 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3977 = build_type_variant (TYPE_POINTER_TO (type), 1, 0);
3979 if (TREE_CODE (type) != VOID_TYPE)
3981 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3982 = build_reference_type (type);
3983 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
3984 = build_type_variant (TYPE_REFERENCE_TO (type), 1, 0);
3990 output_builtin_tdesc_entries ()
3992 extern struct obstack permanent_obstack;
3994 /* If there's more than one main in this file, don't crash. */
3995 if (builtin_type_tdescs_arr == 0)
3998 push_obstacks (&permanent_obstack, &permanent_obstack);
3999 while (builtin_type_tdescs_len > 0)
4001 tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
4002 tree tdesc = build_t_desc (type, 0);
4003 TREE_ASM_WRITTEN (tdesc) = 0;
4004 build_t_desc (type, 2);
4006 free (builtin_type_tdescs_arr);
4007 builtin_type_tdescs_arr = 0;
4011 /* Push overloaded decl, in global scope, with one argument so it
4012 can be used as a callback from define_function. */
4014 push_overloaded_decl_1 (x)
4017 push_overloaded_decl (x, 0);
4020 /* Create the predefined scalar types of C,
4021 and some nodes representing standard constants (0, 1, (void *)0).
4022 Initialize the global binding level.
4023 Make definitions for built-in primitive functions. */
4026 init_decl_processing ()
4029 register tree endlink, int_endlink, double_endlink, ptr_endlink;
4031 /* Either char* or void*. */
4032 tree traditional_ptr_type_node;
4033 /* Data type of memcpy. */
4035 #if 0 /* Not yet. */
4036 /* Data type of strncpy. */
4039 int wchar_type_size;
4041 tree array_domain_type;
4043 /* Have to make these distinct before we try using them. */
4044 lang_name_cplusplus = get_identifier ("C++");
4045 lang_name_c = get_identifier ("C");
4048 current_lang_name = lang_name_c;
4050 current_function_decl = NULL_TREE;
4051 named_labels = NULL_TREE;
4052 named_label_uses = NULL_TREE;
4053 current_binding_level = NULL_BINDING_LEVEL;
4054 free_binding_level = NULL_BINDING_LEVEL;
4056 /* Because most segmentation signals can be traced back into user
4057 code, catch them and at least give the user a chance of working
4058 around compiler bugs. */
4059 signal (SIGSEGV, signal_catch);
4061 /* We will also catch aborts in the back-end through signal_catch and
4062 give the user a chance to see where the error might be, and to defeat
4063 aborts in the back-end when there have been errors previously in their
4066 signal (SIGIOT, signal_catch);
4069 signal (SIGILL, signal_catch);
4072 signal (SIGABRT, signal_catch);
4075 signal (SIGBUS, signal_catch);
4078 gcc_obstack_init (&decl_obstack);
4081 builtin_type_tdescs_max = 100;
4082 builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
4085 /* Must lay these out before anything else gets laid out. */
4086 error_mark_node = make_node (ERROR_MARK);
4087 TREE_PERMANENT (error_mark_node) = 1;
4088 TREE_TYPE (error_mark_node) = error_mark_node;
4089 error_mark_list = build_tree_list (error_mark_node, error_mark_node);
4090 TREE_TYPE (error_mark_list) = error_mark_node;
4092 pushlevel (0); /* make the binding_level structure for global names. */
4093 global_binding_level = current_binding_level;
4095 this_identifier = get_identifier (THIS_NAME);
4096 in_charge_identifier = get_identifier (IN_CHARGE_NAME);
4097 pfn_identifier = get_identifier (VTABLE_PFN_NAME);
4098 index_identifier = get_identifier (VTABLE_INDEX_NAME);
4099 delta_identifier = get_identifier (VTABLE_DELTA_NAME);
4100 delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
4101 pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
4103 /* Define `int' and `char' first so that dbx will output them first. */
4105 integer_type_node = make_signed_type (INT_TYPE_SIZE);
4106 record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
4108 /* Define `char', which is like either `signed char' or `unsigned char'
4109 but not the same as either. */
4113 ? make_signed_type (CHAR_TYPE_SIZE)
4114 : make_unsigned_type (CHAR_TYPE_SIZE));
4115 record_builtin_type (RID_CHAR, "char", char_type_node);
4117 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4118 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
4120 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4121 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
4123 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4124 record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
4125 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
4127 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4128 record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
4130 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4131 record_builtin_type (RID_MAX, "long long unsigned int",
4132 long_long_unsigned_type_node);
4133 record_builtin_type (RID_MAX, "long long unsigned",
4134 long_long_unsigned_type_node);
4136 /* `unsigned long' is the standard type for sizeof.
4137 Traditionally, use a signed type.
4138 Note that stddef.h uses `unsigned long',
4139 and this must agree, even of long and int are the same size. */
4141 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
4142 if (flag_traditional && TREE_UNSIGNED (sizetype))
4143 sizetype = signed_type (sizetype);
4146 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
4148 TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
4149 TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
4150 TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
4151 TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
4152 TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
4153 TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
4154 TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
4156 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4157 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
4158 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4159 record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
4160 record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
4162 /* Define both `signed char' and `unsigned char'. */
4163 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4164 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
4165 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4166 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
4168 /* These are types that type_for_size and type_for_mode use. */
4169 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4170 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
4171 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4172 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
4173 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4174 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
4175 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4176 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
4177 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4178 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
4179 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4180 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
4181 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4182 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
4183 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4184 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
4186 float_type_node = make_node (REAL_TYPE);
4187 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4188 record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
4189 layout_type (float_type_node);
4191 double_type_node = make_node (REAL_TYPE);
4192 if (flag_short_double)
4193 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4195 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4196 record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
4197 layout_type (double_type_node);
4199 long_double_type_node = make_node (REAL_TYPE);
4200 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4201 record_builtin_type (RID_MAX, "long double", long_double_type_node);
4202 layout_type (long_double_type_node);
4204 integer_zero_node = build_int_2 (0, 0);
4205 TREE_TYPE (integer_zero_node) = integer_type_node;
4206 integer_one_node = build_int_2 (1, 0);
4207 TREE_TYPE (integer_one_node) = integer_type_node;
4208 integer_two_node = build_int_2 (2, 0);
4209 TREE_TYPE (integer_two_node) = integer_type_node;
4210 integer_three_node = build_int_2 (3, 0);
4211 TREE_TYPE (integer_three_node) = integer_type_node;
4212 empty_init_node = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
4214 /* These are needed by stor-layout.c. */
4215 size_zero_node = size_int (0);
4216 size_one_node = size_int (1);
4218 void_type_node = make_node (VOID_TYPE);
4219 record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
4220 layout_type (void_type_node); /* Uses integer_zero_node. */
4221 void_list_node = build_tree_list (NULL_TREE, void_type_node);
4222 TREE_PARMLIST (void_list_node) = 1;
4224 null_pointer_node = build_int_2 (0, 0);
4225 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4226 layout_type (TREE_TYPE (null_pointer_node));
4228 /* Used for expressions that do nothing, but are not errors. */
4229 void_zero_node = build_int_2 (0, 0);
4230 TREE_TYPE (void_zero_node) = void_type_node;
4232 string_type_node = build_pointer_type (char_type_node);
4233 const_string_type_node = build_pointer_type (build_type_variant (char_type_node, 1, 0));
4234 record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
4236 /* Make a type to be the domain of a few array types
4237 whose domains don't really matter.
4238 200 is small enough that it always fits in size_t
4239 and large enough that it can hold most function names for the
4240 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4241 array_domain_type = build_index_type (build_int_2 (200, 0));
4243 /* make a type for arrays of characters.
4244 With luck nothing will ever really depend on the length of this
4246 char_array_type_node
4247 = build_array_type (char_type_node, array_domain_type);
4248 /* Likewise for arrays of ints. */
4250 = build_array_type (integer_type_node, array_domain_type);
4252 /* This is just some anonymous class type. Nobody should ever
4253 need to look inside this envelope. */
4254 class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
4256 default_function_type
4257 = build_function_type (integer_type_node, NULL_TREE);
4258 build_pointer_type (default_function_type);
4260 ptr_type_node = build_pointer_type (void_type_node);
4261 const_ptr_type_node = build_pointer_type (build_type_variant (void_type_node, 1, 0));
4262 record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
4263 endlink = void_list_node;
4264 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
4265 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
4266 ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
4269 = build_function_type (double_type_node, double_endlink);
4271 double_ftype_double_double
4272 = build_function_type (double_type_node,
4273 tree_cons (NULL_TREE, double_type_node, double_endlink));
4276 = build_function_type (integer_type_node, int_endlink);
4279 = build_function_type (long_integer_type_node,
4280 tree_cons (NULL_TREE, long_integer_type_node, endlink));
4282 void_ftype_ptr_ptr_int
4283 = build_function_type (void_type_node,
4284 tree_cons (NULL_TREE, ptr_type_node,
4285 tree_cons (NULL_TREE, ptr_type_node,
4288 int_ftype_cptr_cptr_sizet
4289 = build_function_type (integer_type_node,
4290 tree_cons (NULL_TREE, const_ptr_type_node,
4291 tree_cons (NULL_TREE, const_ptr_type_node,
4292 tree_cons (NULL_TREE,
4296 void_ftype_ptr_int_int
4297 = build_function_type (void_type_node,
4298 tree_cons (NULL_TREE, ptr_type_node,
4299 tree_cons (NULL_TREE, integer_type_node,
4302 string_ftype_ptr_ptr /* strcpy prototype */
4303 = build_function_type (string_type_node,
4304 tree_cons (NULL_TREE, string_type_node,
4305 tree_cons (NULL_TREE,
4306 const_string_type_node,
4311 strncpy_ftype /* strncpy prototype */
4312 = build_function_type (string_type_node,
4313 tree_cons (NULL_TREE, string_type_node,
4314 tree_cons (NULL_TREE, const_string_type_node,
4315 tree_cons (NULL_TREE,
4320 int_ftype_string_string /* strcmp prototype */
4321 = build_function_type (integer_type_node,
4322 tree_cons (NULL_TREE, const_string_type_node,
4323 tree_cons (NULL_TREE,
4324 const_string_type_node,
4327 sizet_ftype_string /* strlen prototype */
4328 = build_function_type (sizetype,
4329 tree_cons (NULL_TREE, const_string_type_node,
4332 traditional_ptr_type_node
4333 = (flag_traditional ? string_type_node : ptr_type_node);
4335 memcpy_ftype /* memcpy prototype */
4336 = build_function_type (traditional_ptr_type_node,
4337 tree_cons (NULL_TREE, ptr_type_node,
4338 tree_cons (NULL_TREE, const_ptr_type_node,
4339 tree_cons (NULL_TREE,
4343 if (flag_huge_objects)
4344 delta_type_node = long_integer_type_node;
4346 delta_type_node = short_integer_type_node;
4348 builtin_function ("__builtin_constant_p", int_ftype_int,
4349 BUILT_IN_CONSTANT_P, NULL_PTR);
4351 builtin_function ("__builtin_alloca",
4352 build_function_type (ptr_type_node,
4353 tree_cons (NULL_TREE,
4356 BUILT_IN_ALLOCA, "alloca");
4358 builtin_function ("alloca",
4359 build_function_type (ptr_type_node,
4360 tree_cons (NULL_TREE,
4363 BUILT_IN_ALLOCA, NULL_PTR);
4366 builtin_function ("__builtin_abs", int_ftype_int,
4367 BUILT_IN_ABS, NULL_PTR);
4368 builtin_function ("__builtin_fabs", double_ftype_double,
4369 BUILT_IN_FABS, NULL_PTR);
4370 builtin_function ("__builtin_labs", long_ftype_long,
4371 BUILT_IN_LABS, NULL_PTR);
4372 builtin_function ("__builtin_ffs", int_ftype_int,
4373 BUILT_IN_FFS, NULL_PTR);
4374 builtin_function ("__builtin_fsqrt", double_ftype_double,
4375 BUILT_IN_FSQRT, NULL_PTR);
4376 builtin_function ("__builtin_sin", double_ftype_double,
4377 BUILT_IN_SIN, "sin");
4378 builtin_function ("__builtin_cos", double_ftype_double,
4379 BUILT_IN_COS, "cos");
4380 builtin_function ("__builtin_saveregs",
4381 build_function_type (ptr_type_node, NULL_TREE),
4382 BUILT_IN_SAVEREGS, NULL_PTR);
4383 /* EXPAND_BUILTIN_VARARGS is obsolete. */
4385 builtin_function ("__builtin_varargs",
4386 build_function_type (ptr_type_node,
4387 tree_cons (NULL_TREE,
4390 BUILT_IN_VARARGS, NULL_PTR);
4392 builtin_function ("__builtin_classify_type", default_function_type,
4393 BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
4394 builtin_function ("__builtin_next_arg",
4395 build_function_type (ptr_type_node, NULL_TREE),
4396 BUILT_IN_NEXT_ARG, NULL_PTR);
4397 builtin_function ("__builtin_args_info",
4398 build_function_type (integer_type_node,
4399 tree_cons (NULL_TREE,
4402 BUILT_IN_ARGS_INFO, NULL_PTR);
4404 /* Untyped call and return. */
4405 builtin_function ("__builtin_apply_args",
4406 build_function_type (ptr_type_node, NULL_TREE),
4407 BUILT_IN_APPLY_ARGS, NULL_PTR);
4409 temp = tree_cons (NULL_TREE,
4410 build_pointer_type (build_function_type (void_type_node,
4412 tree_cons (NULL_TREE,
4414 tree_cons (NULL_TREE,
4417 builtin_function ("__builtin_apply",
4418 build_function_type (ptr_type_node, temp),
4419 BUILT_IN_APPLY, NULL_PTR);
4420 builtin_function ("__builtin_return",
4421 build_function_type (void_type_node,
4422 tree_cons (NULL_TREE,
4425 BUILT_IN_RETURN, NULL_PTR);
4427 /* Currently under experimentation. */
4428 builtin_function ("__builtin_memcpy", memcpy_ftype,
4429 BUILT_IN_MEMCPY, "memcpy");
4430 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
4431 BUILT_IN_MEMCMP, "memcmp");
4432 builtin_function ("__builtin_strcmp", int_ftype_string_string,
4433 BUILT_IN_STRCMP, "strcmp");
4434 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
4435 BUILT_IN_STRCPY, "strcpy");
4438 builtin_function ("__builtin_strncpy", strncpy_ftype,
4439 BUILT_IN_STRNCPY, "strncpy");
4441 builtin_function ("__builtin_strlen", sizet_ftype_string,
4442 BUILT_IN_STRLEN, "strlen");
4444 if (!flag_no_builtin)
4446 #if 0 /* These do not work well with libg++. */
4447 builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
4448 builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
4449 builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
4451 builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
4452 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
4454 builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR);
4455 builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, NULL_PTR);
4458 builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR);
4460 builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR);
4461 builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
4462 builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
4466 /* Support for these has not been written in either expand_builtin
4467 or build_function_call. */
4468 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
4469 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
4470 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, 0);
4471 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
4472 builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD, 0);
4473 builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM, 0);
4474 builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, 0);
4475 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, 0);
4476 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, 0);
4479 /* C++ extensions */
4481 unknown_type_node = make_node (UNKNOWN_TYPE);
4482 #if 0 /* not yet, should get fixed properly later */
4483 pushdecl (make_type_decl (get_identifier ("unknown type"),
4484 unknown_type_node));
4486 decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
4487 unknown_type_node));
4488 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
4489 DECL_IGNORED_P (decl) = 1;
4491 TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
4492 TYPE_ALIGN (unknown_type_node) = 1;
4493 TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
4494 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
4495 TREE_TYPE (unknown_type_node) = unknown_type_node;
4496 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
4497 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
4498 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
4500 /* This is for handling opaque types in signatures. */
4501 opaque_type_node = copy_node (ptr_type_node);
4502 TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
4503 record_builtin_type (RID_MAX, 0, opaque_type_node);
4505 /* This is special for C++ so functions can be overloaded. */
4507 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
4508 wchar_type_size = TYPE_PRECISION (wchar_type_node);
4509 signed_wchar_type_node = make_signed_type (wchar_type_size);
4510 unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
4512 = TREE_UNSIGNED (wchar_type_node)
4513 ? unsigned_wchar_type_node
4514 : signed_wchar_type_node;
4515 record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
4517 /* This is for wide string constants. */
4518 wchar_array_type_node
4519 = build_array_type (wchar_type_node, array_domain_type);
4521 /* This is a hack that should go away when we deliver the
4525 builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
4526 pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
4529 /* Simplify life by making a "vtable_entry_type". Give its
4530 fields names so that the debugger can use them. */
4532 vtable_entry_type = make_lang_type (RECORD_TYPE);
4533 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, delta_type_node);
4534 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, delta_type_node);
4535 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, ptr_type_node);
4536 finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
4539 /* Make this part of an invisible union. */
4540 fields[3] = copy_node (fields[2]);
4541 TREE_TYPE (fields[3]) = delta_type_node;
4542 DECL_NAME (fields[3]) = delta2_identifier;
4543 DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
4544 DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
4545 TREE_UNSIGNED (fields[3]) = 0;
4546 TREE_CHAIN (fields[2]) = fields[3];
4547 vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
4548 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
4550 #ifdef VTABLE_USES_MASK
4551 /* This is primarily for virtual function definition. We
4552 declare an array of `void *', which can later be
4553 converted to the appropriate function pointer type.
4554 To do pointers to members, we need a mask which can
4555 distinguish an index value into a virtual function table
4557 vtbl_mask = build_int_2 (~((HOST_WIDE_INT) VINDEX_MAX - 1), -1);
4561 = build_array_type (vtable_entry_type, NULL_TREE);
4562 layout_type (vtbl_type_node);
4563 vtbl_type_node = build_type_variant (vtbl_type_node, 1, 0);
4564 record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
4566 /* Simplify life by making a "sigtable_entry_type". Give its
4567 fields names so that the debugger can use them. */
4569 if (flag_handle_signatures)
4571 sigtable_entry_type = make_lang_type (RECORD_TYPE);
4572 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_CODE_NAME), short_integer_type_node);
4573 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_OFFSET_NAME), short_integer_type_node);
4574 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier (SIGTABLE_PFN_NAME), ptr_type_node);
4575 finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 2,
4577 sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
4578 record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
4583 /* Must build __t_desc type. Currently, type descriptors look like this:
4590 struct __t_desc *points_to;
4591 int ivars_count, meths_count;
4592 struct __i_desc *ivars[];
4593 struct __m_desc *meths[];
4594 struct __t_desc *parents[];
4595 struct __t_desc *vbases[];
4599 ...as per Linton's paper. */
4601 __t_desc_type_node = make_lang_type (RECORD_TYPE);
4602 __i_desc_type_node = make_lang_type (RECORD_TYPE);
4603 __m_desc_type_node = make_lang_type (RECORD_TYPE);
4604 __t_desc_array_type = build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE);
4605 __i_desc_array_type = build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE);
4606 __m_desc_array_type = build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE);
4608 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4610 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
4611 unsigned_type_node);
4612 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
4613 unsigned_type_node);
4614 fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("points_to"),
4615 TYPE_POINTER_TO (__t_desc_type_node));
4616 fields[4] = build_lang_field_decl (FIELD_DECL,
4617 get_identifier ("ivars_count"),
4619 fields[5] = build_lang_field_decl (FIELD_DECL,
4620 get_identifier ("meths_count"),
4622 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
4623 build_pointer_type (__i_desc_array_type));
4624 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
4625 build_pointer_type (__m_desc_array_type));
4626 fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
4627 build_pointer_type (__t_desc_array_type));
4628 fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
4629 build_pointer_type (__t_desc_array_type));
4630 fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
4631 build_pointer_type (integer_type_node));
4632 finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
4634 /* ivar descriptors look like this:
4640 struct __t_desc *type;
4644 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4646 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
4648 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
4649 TYPE_POINTER_TO (__t_desc_type_node));
4650 finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, integer_type_node);
4652 /* method descriptors look like this:
4658 struct __t_desc *vcontext;
4659 struct __t_desc *return_type;
4662 short required_parms;
4663 struct __t_desc *parm_types[];
4667 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
4669 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
4671 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
4672 TYPE_POINTER_TO (__t_desc_type_node));
4673 fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
4674 TYPE_POINTER_TO (__t_desc_type_node));
4675 fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
4676 build_pointer_type (default_function_type));
4677 fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
4678 short_integer_type_node);
4679 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
4680 short_integer_type_node);
4681 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
4682 build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE)));
4683 finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, integer_type_node);
4687 current_lang_name = lang_name_cplusplus;
4690 int i = builtin_type_tdescs_len;
4693 tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
4694 TREE_ASM_WRITTEN (tdesc) = 1;
4695 TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
4699 auto_function (ansi_opname[(int) NEW_EXPR],
4700 build_function_type (ptr_type_node,
4701 tree_cons (NULL_TREE, sizetype,
4704 auto_function (ansi_opname[(int) DELETE_EXPR],
4705 build_function_type (void_type_node,
4706 tree_cons (NULL_TREE, ptr_type_node,
4711 = define_function ("abort",
4712 build_function_type (void_type_node, void_list_node),
4713 NOT_BUILT_IN, 0, 0);
4715 unhandled_exception_fndecl
4716 = define_function ("__unhandled_exception",
4717 build_function_type (void_type_node, NULL_TREE),
4718 NOT_BUILT_IN, 0, 0);
4720 /* Perform other language dependent initializations. */
4721 init_class_processing ();
4722 init_init_processing ();
4723 init_search_processing ();
4725 if (flag_handle_exceptions)
4727 if (flag_handle_exceptions == 2)
4728 /* Too much trouble to inline all the trys needed for this. */
4729 flag_this_is_variable = 2;
4730 init_exception_processing ();
4733 init_gc_processing ();
4736 flag_inline_functions = 0;
4738 /* This causes uneccessary emission of inline functions. */
4739 flag_default_inline = 0;
4745 /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
4746 declare_function_name ();
4748 /* Prepare to check format strings against argument lists. */
4749 init_function_format_info ();
4752 /* Make a definition for a builtin function named NAME and whose data type
4753 is TYPE. TYPE should be a function type with argument types.
4754 FUNCTION_CODE tells later passes how to compile calls to this function.
4755 See tree.h for its possible values.
4757 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
4758 the name to be called if we can't opencode the function. */
4761 define_function (name, type, function_code, pfn, library_name)
4764 enum built_in_function function_code;
4768 tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
4769 DECL_EXTERNAL (decl) = 1;
4770 TREE_PUBLIC (decl) = 1;
4772 /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
4773 we cannot change DECL_ASSEMBLER_NAME until we have installed this
4774 function in the namespace. */
4775 if (pfn) (*pfn) (decl);
4777 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
4778 make_function_rtl (decl);
4779 if (function_code != NOT_BUILT_IN)
4781 DECL_BUILT_IN (decl) = 1;
4782 DECL_SET_FUNCTION_CODE (decl, function_code);
4787 /* Called when a declaration is seen that contains no names to declare.
4788 If its type is a reference to a structure, union or enum inherited
4789 from a containing scope, shadow that tag name for the current scope
4790 with a forward reference.
4791 If its type defines a new named structure or union
4792 or defines an enum, it is valid but we need not do anything here.
4793 Otherwise, it is an error.
4795 C++: may have to grok the declspecs to learn about static,
4796 complain for anonymous unions. */
4799 shadow_tag (declspecs)
4804 int static_or_extern = 0;
4806 register enum tree_code code, ok_code = ERROR_MARK;
4807 register tree t = NULL_TREE;
4809 for (link = declspecs; link; link = TREE_CHAIN (link))
4811 register tree value = TREE_VALUE (link);
4813 code = TREE_CODE (value);
4814 if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
4815 /* Used to test also that TYPE_SIZE (value) != 0.
4816 That caused warning for `struct foo;' at top level in the file. */
4818 register tree name = TYPE_NAME (value);
4820 if (name == NULL_TREE)
4821 name = lookup_tag_reverse (value, NULL_TREE);
4823 if (name && TREE_CODE (name) == TYPE_DECL)
4824 name = DECL_NAME (name);
4826 t = lookup_tag (code, name, inner_binding_level, 1);
4830 push_obstacks (&permanent_obstack, &permanent_obstack);
4831 if (IS_AGGR_TYPE_CODE (code))
4832 t = make_lang_type (code);
4834 t = make_node (code);
4835 pushtag (name, t, 0);
4840 else if (name != NULL_TREE || code == ENUMERAL_TYPE)
4843 if (ok_code != ERROR_MARK)
4848 pedwarn ("useless keyword or type name in declaration");
4852 else if (value == ridpointers[(int) RID_STATIC]
4853 || value == ridpointers[(int) RID_EXTERN])
4854 static_or_extern = 1;
4857 /* This is where the variables in an anonymous union are
4858 declared. An anonymous union declaration looks like:
4860 because there is no declarator after the union, the parser
4861 sends that declaration here. */
4862 if (ok_code == UNION_TYPE
4864 && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
4865 && ANON_AGGRNAME_P (TYPE_NAME (t)))
4866 || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
4867 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
4869 /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have
4870 function members. */
4871 if (TYPE_FIELDS (t))
4873 tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, NULL_TREE);
4874 finish_anon_union (decl);
4877 error ("anonymous union cannot have a function member");
4881 /* Anonymous unions are objects, that's why we only check for
4882 static/extern specifiers in this branch. */
4883 if (static_or_extern)
4884 error ("static/extern can only be specified for objects and functions");
4886 if (ok_code == RECORD_TYPE
4888 && TYPE_LANG_SPECIFIC (t)
4889 && CLASSTYPE_DECLARED_EXCEPTION (t))
4892 cp_error ("redeclaration of exception `%T'", t);
4897 push_obstacks (&permanent_obstack, &permanent_obstack);
4900 finish_exception (t, NULL_TREE);
4902 ename = TYPE_NAME (t);
4903 if (TREE_CODE (ename) == TYPE_DECL)
4904 ename = DECL_NAME (ename);
4905 decl = build_lang_field_decl (VAR_DECL, ename, t);
4906 finish_exception_decl (current_class_name, decl);
4907 end_exception_decls ();
4912 else if (!warned && found_tag > 1)
4913 warning ("multiple types in one declaration");
4917 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
4920 groktypename (typename)
4923 if (TREE_CODE (typename) != TREE_LIST)
4925 return grokdeclarator (TREE_VALUE (typename),
4926 TREE_PURPOSE (typename),
4927 TYPENAME, 0, NULL_TREE);
4930 /* Decode a declarator in an ordinary declaration or data definition.
4931 This is called as soon as the type information and variable name
4932 have been parsed, before parsing the initializer if any.
4933 Here we create the ..._DECL node, fill in its type,
4934 and put it on the list of decls for the current context.
4935 The ..._DECL node is returned as the value.
4937 Exception: for arrays where the length is not specified,
4938 the type is left null, to be filled in by `finish_decl'.
4940 Function definitions do not come here; they go to start_function
4941 instead. However, external and forward declarations of functions
4942 do go through here. Structure field declarations are done by
4943 grokfield and not through here. */
4945 /* Set this to zero to debug not using the temporary obstack
4946 to parse initializers. */
4947 int debug_temp_inits = 1;
4950 start_decl (declarator, declspecs, initialized, raises)
4951 tree declarator, declspecs;
4956 register tree type, tem;
4958 extern int have_extern_spec;
4959 extern int used_extern_spec;
4961 int init_written = initialized;
4963 /* This should only be done once on the top most decl. */
4964 if (have_extern_spec && !used_extern_spec)
4966 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
4967 used_extern_spec = 1;
4970 decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises);
4971 if (decl == NULL_TREE || decl == void_type_node)
4974 type = TREE_TYPE (decl);
4976 /* Don't lose if destructors must be executed at file-level. */
4977 if (TREE_STATIC (decl)
4978 && TYPE_NEEDS_DESTRUCTOR (type)
4979 && !TREE_PERMANENT (decl))
4981 push_obstacks (&permanent_obstack, &permanent_obstack);
4982 decl = copy_node (decl);
4983 if (TREE_CODE (type) == ARRAY_TYPE)
4985 tree itype = TYPE_DOMAIN (type);
4986 if (itype && ! TREE_PERMANENT (itype))
4988 itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
4989 type = build_cplus_array_type (TREE_TYPE (type), itype);
4990 TREE_TYPE (decl) = type;
4996 /* Interesting work for this is done in `finish_exception_decl'. */
4997 if (TREE_CODE (type) == RECORD_TYPE
4998 && CLASSTYPE_DECLARED_EXCEPTION (type))
5001 /* Corresponding pop_obstacks is done in `finish_decl'. */
5002 push_obstacks_nochange ();
5005 = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
5006 ? DECL_CLASS_CONTEXT (decl)
5007 : DECL_CONTEXT (decl);
5009 if (processing_template_decl)
5012 if (TREE_CODE (decl) == FUNCTION_DECL)
5014 /* Declarator is a call_expr; extract arguments from it, since
5015 grokdeclarator didn't do it. */
5017 args = copy_to_permanent (last_function_parms);
5018 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
5020 tree t = TREE_TYPE (decl);
5022 t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
5023 if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE)
5025 t = build_pointer_type (t); /* base type of `this' */
5027 /* I suspect this is wrong. */
5028 t = build_type_variant (t, flag_this_is_variable <= 0,
5029 0); /* type of `this' */
5031 t = build_type_variant (t, 0, 0); /* type of `this' */
5033 t = build (PARM_DECL, t, this_identifier);
5034 TREE_CHAIN (t) = args;
5038 DECL_ARGUMENTS (decl) = args;
5040 d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
5041 if (interface_unknown && flag_external_templates && ! DECL_IN_SYSTEM_HEADER (decl))
5042 warn_if_unknown_interface ();
5043 TREE_PUBLIC (d) = TREE_PUBLIC (decl) = flag_external_templates && !interface_unknown;
5044 TREE_STATIC (d) = TREE_STATIC (decl);
5045 DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl)
5046 && !(context && !DECL_THIS_EXTERN (decl)));
5047 DECL_TEMPLATE_RESULT (d) = decl;
5048 DECL_OVERLOADED (d) = 1;
5052 if (context && TYPE_SIZE (context) != NULL_TREE)
5054 /* If it was not explicitly declared `extern',
5055 revoke any previous claims of DECL_EXTERNAL. */
5056 if (DECL_THIS_EXTERN (decl) == 0)
5057 DECL_EXTERNAL (decl) = 0;
5058 if (DECL_LANG_SPECIFIC (decl))
5059 DECL_IN_AGGR_P (decl) = 0;
5060 pushclass (context, 2);
5063 /* If this type of object needs a cleanup, and control may
5064 jump past it, make a new binding level so that it is cleaned
5065 up only when it is initialized first. */
5066 if (TYPE_NEEDS_DESTRUCTOR (type)
5067 && current_binding_level->more_cleanups_ok == 0)
5068 pushlevel_temporary (1);
5071 /* Is it valid for this decl to have an initializer at all?
5072 If not, set INITIALIZED to zero, which will indirectly
5073 tell `finish_decl' to ignore the initializer once it is parsed. */
5074 switch (TREE_CODE (decl))
5077 /* typedef foo = bar means give foo the same type as bar.
5078 We haven't parsed bar yet, so `finish_decl' will fix that up.
5079 Any other case of an initialization in a TYPE_DECL is an error. */
5080 if (pedantic || list_length (declspecs) > 1)
5082 cp_error ("typedef `%D' is initialized", decl);
5088 cp_error ("function `%#D' is initialized like a variable", decl);
5093 /* Don't allow initializations for incomplete types except for
5094 arrays which might be completed by the initialization. */
5095 if (TYPE_SIZE (type) != NULL_TREE)
5096 ; /* A complete type is ok. */
5097 else if (TREE_CODE (type) != ARRAY_TYPE)
5099 cp_error ("variable `%#D' has initializer but incomplete type",
5103 else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE)
5105 cp_error ("elements of array `%#D' have incomplete type", decl);
5111 && TREE_CODE (decl) != TYPE_DECL
5112 && TREE_CODE (decl) != TEMPLATE_DECL
5113 && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
5115 if (TYPE_SIZE (type) == NULL_TREE)
5117 cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
5119 /* Change the type so that assemble_variable will give
5120 DECL an rtl we can live with: (mem (const_int 0)). */
5121 TREE_TYPE (decl) = error_mark_node;
5122 type = error_mark_node;
5126 /* If any base type in the hierarchy of TYPE needs a constructor,
5127 then we set initialized to 1. This way any nodes which are
5128 created for the purposes of initializing this aggregate
5129 will live as long as it does. This is necessary for global
5130 aggregates which do not have their initializers processed until
5131 the end of the file. */
5132 initialized = TYPE_NEEDS_CONSTRUCTING (type);
5138 if (current_binding_level != global_binding_level
5139 && DECL_EXTERNAL (decl))
5140 cp_warning ("declaration of `%#D' has `extern' and is initialized",
5142 DECL_EXTERNAL (decl) = 0;
5143 if (current_binding_level == global_binding_level)
5144 TREE_STATIC (decl) = 1;
5146 /* Tell `pushdecl' this is an initialized decl
5147 even though we don't yet have the initializer expression.
5148 Also tell `finish_decl' it may store the real initializer. */
5149 DECL_INITIAL (decl) = error_mark_node;
5152 /* Add this decl to the current binding level, but not if it
5153 comes from another scope, e.g. a static member variable.
5154 TEM may equal DECL or it may be a previous decl of the same name. */
5155 if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
5156 || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
5157 || TREE_CODE (type) == LANG_TYPE)
5161 tem = pushdecl (decl);
5162 if (is_overloaded_fn (tem))
5165 tem = get_first_fn (tem);
5166 tem2 = decl_value_member (decl, tem);
5168 if (tem2 != NULL_TREE)
5172 while (tem && ! decls_match (decl, tem))
5173 tem = DECL_CHAIN (tem);
5174 if (tem == NULL_TREE)
5180 /* Tell the back-end to use or not use .common as appropriate. */
5181 DECL_COMMON (tem) = flag_conserve_space;
5184 /* We don't do this yet for GNU C++. */
5185 /* For a local variable, define the RTL now. */
5186 if (current_binding_level != global_binding_level
5187 /* But not if this is a duplicate decl
5188 and we preserved the rtl from the previous one
5189 (which may or may not happen). */
5190 && DECL_RTL (tem) == NULL_RTX)
5192 if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
5194 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
5195 && DECL_INITIAL (tem) != NULL_TREE)
5200 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_OVERLOADED (decl))
5201 /* @@ Also done in start_function. */
5202 tem = push_overloaded_decl (tem, 1);
5203 else if (TREE_CODE (decl) == TEMPLATE_DECL)
5205 tree result = DECL_TEMPLATE_RESULT (decl);
5206 if (DECL_CONTEXT (result) != NULL_TREE)
5209 type = DECL_CONTEXT (result);
5211 if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE)
5213 cp_error ("declaration of `%D' in non-template type `%T'",
5218 if (/* TREE_CODE (result) == VAR_DECL */ 1)
5221 tree tmpl = UPT_TEMPLATE (type);
5223 fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
5224 print_node_brief (stderr, "", DECL_NAME (tem), 0);
5225 fprintf (stderr, " to class %s\n",
5226 IDENTIFIER_POINTER (DECL_NAME (tmpl)));
5227 DECL_TEMPLATE_MEMBERS (tmpl)
5228 = perm_tree_cons (DECL_NAME (tem), tem,
5229 DECL_TEMPLATE_MEMBERS (tmpl));
5233 my_friendly_abort (13);
5235 else if (TREE_CODE (result) == FUNCTION_DECL)
5236 tem = push_overloaded_decl (tem, 0);
5237 else if (TREE_CODE (result) == VAR_DECL
5238 || TREE_CODE (result) == TYPE_DECL)
5240 cp_error ("invalid template `%#D'", result);
5244 my_friendly_abort (14);
5248 && ! (TREE_CODE (tem) == PARM_DECL
5249 || (TREE_READONLY (tem)
5250 && (TREE_CODE (tem) == VAR_DECL
5251 || TREE_CODE (tem) == FIELD_DECL))))
5253 /* When parsing and digesting the initializer,
5254 use temporary storage. Do this even if we will ignore the value. */
5255 if (current_binding_level == global_binding_level && debug_temp_inits)
5257 if (TYPE_NEEDS_CONSTRUCTING (type) || TREE_CODE (type) == REFERENCE_TYPE)
5258 /* In this case, the initializer must lay down in permanent
5259 storage, since it will be saved until `finish_file' is run. */
5262 temporary_allocation ();
5267 cadillac_start_decl (tem);
5273 make_temporary_for_reference (decl, ctor_call, init, cleanupp)
5274 tree decl, ctor_call, init;
5277 tree type = TREE_TYPE (decl);
5278 tree target_type = TREE_TYPE (type);
5283 tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
5284 if (TREE_CODE (tmp_addr) == NOP_EXPR)
5285 tmp_addr = TREE_OPERAND (tmp_addr, 0);
5286 my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146);
5287 tmp = TREE_OPERAND (tmp_addr, 0);
5291 tmp = get_temp_name (target_type,
5292 current_binding_level == global_binding_level);
5293 tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
5296 TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
5297 DECL_INITIAL (decl) = convert (TYPE_POINTER_TO (target_type), tmp_addr);
5298 TREE_TYPE (DECL_INITIAL (decl)) = type;
5299 if (TYPE_NEEDS_CONSTRUCTING (target_type))
5301 if (current_binding_level == global_binding_level)
5303 /* lay this variable out now. Otherwise `output_addressed_constants'
5304 gets confused by its initializer. */
5305 make_decl_rtl (tmp, NULL_PTR, 1);
5306 static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
5310 if (ctor_call != NULL_TREE)
5313 init = build_method_call (tmp, constructor_name_full (target_type),
5314 build_tree_list (NULL_TREE, init),
5315 NULL_TREE, LOOKUP_NORMAL);
5316 DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
5317 DECL_INITIAL (decl));
5318 *cleanupp = maybe_build_cleanup (tmp);
5323 DECL_INITIAL (tmp) = init;
5324 TREE_STATIC (tmp) = current_binding_level == global_binding_level;
5325 finish_decl (tmp, init, 0, 0);
5327 if (TREE_STATIC (tmp))
5328 preserve_initializer ();
5331 /* Handle initialization of references.
5332 These three arguments from from `finish_decl', and have the
5333 same meaning here that they do there. */
5334 /* quotes on semantics can be found in ARM 8.4.3. */
5336 grok_reference_init (decl, type, init, cleanupp)
5337 tree decl, type, init;
5340 char *errstr = NULL;
5343 tree this_ptr_type, actual_init = NULL_TREE;
5345 if (init == NULL_TREE)
5347 if (DECL_LANG_SPECIFIC (decl) == 0
5348 || DECL_IN_AGGR_P (decl) == 0)
5350 cp_error ("`%D' declared as reference but not initialized", decl);
5351 if (TREE_CODE (decl) == VAR_DECL)
5352 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
5357 if (init == error_mark_node)
5360 if (TREE_CODE (type) == REFERENCE_TYPE
5361 && TREE_CODE (init) == CONSTRUCTOR)
5363 cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
5367 if (TREE_CODE (init) == TREE_LIST)
5368 init = build_compound_expr (init);
5369 is_reference = TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE;
5370 tmp = is_reference ? convert_from_reference (init) : init;
5372 if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
5373 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
5375 /* Note: default conversion is only called in very
5377 init = default_conversion (init);
5380 /* Can we just enreference this lvalue? */
5381 if ((is_reference || lvalue_p (init)
5382 || (actual_init = unary_complex_lvalue (ADDR_EXPR, init)))
5383 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
5384 TYPE_MAIN_VARIANT (TREE_TYPE (tmp)), 0))
5386 /* This section implements ANSI C++ June 5 1992 WP 8.4.3.5. */
5388 /* A reference to a volatile T cannot be initialized with
5389 a const T, and vice-versa. */
5390 if (TYPE_VOLATILE (TREE_TYPE (type)) && TREE_READONLY (init))
5391 errstr = "cannot initialize a reference to a volatile `%T' with a const `%T'";
5392 else if (TYPE_READONLY (TREE_TYPE (type)) && TREE_THIS_VOLATILE (init))
5393 errstr = "cannot initialize a reference to a const `%T' with a volatile `%T'";
5394 /* A reference to a plain T can be initialized only with a plain T. */
5395 else if (!TYPE_VOLATILE (TREE_TYPE (type))
5396 && !TYPE_READONLY (TREE_TYPE (type)))
5398 if (TREE_READONLY (init))
5399 errstr = "cannot initialize a reference to `%T' with a const `%T'";
5400 else if (TREE_THIS_VOLATILE (init))
5401 errstr = "cannot initialize a reference to `%T' with a volatile `%T'";
5405 cp_error (errstr, TREE_TYPE (type), TREE_TYPE (tmp));
5409 /* OK, can we generate a reference then? */
5410 else if ((actual_init = convert_to_reference
5411 (decl, type, init, 0, 0, "initialization", 0,
5412 LOOKUP_SPECULATIVELY|LOOKUP_NORMAL)))
5414 if (actual_init == error_mark_node)
5420 /* OK, try going through a temporary. */
5421 else if ((actual_init = convert_to_reference
5422 (error_mark_node, type, init, 0, 0, "initialization",
5425 if (actual_init == error_mark_node)
5431 if (TREE_CODE (init) == WITH_CLEANUP_EXPR)
5433 /* Associate the cleanup with the reference so that we
5434 don't get burned by "aggressive" cleanup policy. */
5435 *cleanupp = TREE_OPERAND (init, 2);
5436 TREE_OPERAND (init, 2) = error_mark_node;
5441 cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
5445 /* In the case of initialization, it is permissible
5446 to assign one reference to another. */
5447 this_ptr_type = build_pointer_type (TREE_TYPE (type));
5451 if (TREE_SIDE_EFFECTS (init))
5452 DECL_INITIAL (decl) = save_expr (init);
5454 DECL_INITIAL (decl) = init;
5456 else if (lvalue_p (init))
5458 tmp = build_unary_op (ADDR_EXPR, init, 0);
5459 if (TREE_CODE (tmp) == ADDR_EXPR
5460 && TREE_CODE (TREE_OPERAND (tmp, 0)) == WITH_CLEANUP_EXPR)
5462 if (*cleanupp) my_friendly_abort (1);
5463 *cleanupp = TREE_OPERAND (TREE_OPERAND (tmp, 0), 2);
5464 TREE_OPERAND (TREE_OPERAND (tmp, 0), 2) = error_mark_node;
5466 if (IS_AGGR_TYPE (TREE_TYPE (this_ptr_type)))
5467 DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), tmp);
5469 DECL_INITIAL (decl) = convert (this_ptr_type, tmp);
5471 DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
5472 if (DECL_INITIAL (decl) == current_class_decl)
5473 DECL_INITIAL (decl) = copy_node (current_class_decl);
5474 TREE_TYPE (DECL_INITIAL (decl)) = type;
5476 /* If actual_init is set here, it is set from the first check above. */
5477 else if (actual_init)
5479 /* The initializer for this decl goes into its
5480 DECL_REFERENCE_SLOT. Make sure that we can handle
5481 multiple evaluations without ill effect. */
5482 if (TREE_CODE (actual_init) == ADDR_EXPR
5483 && TREE_CODE (TREE_OPERAND (actual_init, 0)) == TARGET_EXPR)
5484 actual_init = save_expr (actual_init);
5485 DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), actual_init);
5486 DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
5487 TREE_TYPE (DECL_INITIAL (decl)) = type;
5490 my_friendly_abort (1);
5493 /* ?? Can this be optimized in some cases to
5494 hand back the DECL_INITIAL slot?? */
5495 if (TYPE_SIZE (TREE_TYPE (type)))
5497 init = convert_from_reference (decl);
5498 if (TREE_PERMANENT (decl))
5499 init = copy_to_permanent (init);
5500 SET_DECL_REFERENCE_SLOT (decl, init);
5503 if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
5505 expand_static_init (decl, DECL_INITIAL (decl));
5506 DECL_INITIAL (decl) = NULL_TREE;
5511 if (TREE_CODE (decl) == VAR_DECL)
5512 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
5516 /* Finish processing of a declaration;
5517 install its line number and initial value.
5518 If the length of an array type is not known before,
5519 it must be determined now, from the initial value, or it is an error.
5521 Call `pop_obstacks' iff NEED_POP is nonzero.
5523 For C++, `finish_decl' must be fairly evasive: it must keep initializers
5524 for aggregates that have constructors alive on the permanent obstack,
5525 so that the global initializing functions can be written at the end.
5527 INIT0 holds the value of an initializer that should be allowed to escape
5530 For functions that take default parameters, DECL points to its
5531 "maximal" instantiation. `finish_decl' must then also declared its
5532 subsequently lower and lower forms of instantiation, checking for
5533 ambiguity as it goes. This can be sped up later. */
5536 finish_decl (decl, init, asmspec_tree, need_pop)
5542 tree cleanup = NULL_TREE, ttype;
5544 int temporary = allocation_temporary_p ();
5545 char *asmspec = NULL;
5546 int was_readonly = 0;
5548 /* If this is 0, then we did not change obstacks. */
5552 error ("assignment (not initialization) in declaration");
5558 asmspec = TREE_STRING_POINTER (asmspec_tree);
5559 /* Zero out old RTL, since we will rewrite it. */
5560 DECL_RTL (decl) = NULL_RTX;
5563 /* If the type of the thing we are declaring either has
5564 a constructor, or has a virtual function table pointer,
5565 AND its initialization was accepted by `start_decl',
5566 then we stayed on the permanent obstack through the
5567 declaration, otherwise, changed obstacks as GCC would. */
5569 type = TREE_TYPE (decl);
5571 was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
5573 /* Take care of TYPE_DECLs up front. */
5574 if (TREE_CODE (decl) == TYPE_DECL)
5576 if (init && DECL_INITIAL (decl))
5578 /* typedef foo = bar; store the type of bar as the type of foo. */
5579 TREE_TYPE (decl) = type = TREE_TYPE (init);
5580 DECL_INITIAL (decl) = init = NULL_TREE;
5582 if (IS_AGGR_TYPE (type) && DECL_NAME (decl))
5584 if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
5585 cp_warning ("shadowing previous type declaration of `%#D'", decl);
5586 set_identifier_type_value (DECL_NAME (decl), type);
5587 CLASSTYPE_GOT_SEMICOLON (type) = 1;
5589 GNU_xref_decl (current_function_decl, decl);
5590 rest_of_decl_compilation (decl, NULL_PTR,
5591 DECL_CONTEXT (decl) == NULL_TREE, 0);
5594 if (type != error_mark_node && IS_AGGR_TYPE (type)
5595 && CLASSTYPE_DECLARED_EXCEPTION (type))
5597 finish_exception_decl (NULL_TREE, decl);
5598 CLASSTYPE_GOT_SEMICOLON (type) = 1;
5601 if (TREE_CODE (decl) != FUNCTION_DECL)
5603 ttype = target_type (type);
5605 Leave this out until we can figure out why it was
5606 needed/desirable in the first place. Then put a comment
5607 here explaining why. Or just delete the code if no ill
5609 if (TYPE_NAME (ttype)
5610 && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
5611 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
5613 tree old_id = TYPE_IDENTIFIER (ttype);
5614 char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
5615 /* Need to preserve template data for UPT nodes. */
5616 tree old_template = IDENTIFIER_TEMPLATE (old_id);
5618 bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
5619 IDENTIFIER_LENGTH (old_id) + 1);
5620 old_id = get_identifier (newname);
5621 lookup_tag_reverse (ttype, old_id);
5622 TYPE_IDENTIFIER (ttype) = old_id;
5623 IDENTIFIER_TEMPLATE (old_id) = old_template;
5628 if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
5629 && TYPE_NEEDS_CONSTRUCTING (type))
5632 /* Currently, GNU C++ puts constants in text space, making them
5633 impossible to initialize. In the future, one would hope for
5634 an operating system which understood the difference between
5635 initialization and the running of a program. */
5637 TREE_READONLY (decl) = 0;
5640 if (TREE_CODE (decl) == FIELD_DECL)
5642 if (init && init != error_mark_node)
5643 my_friendly_assert (TREE_PERMANENT (init), 147);
5647 /* This must override the asm specifier which was placed
5648 by grokclassfn. Lay this out fresh.
5650 @@ Should emit an error if this redefines an asm-specified
5651 @@ name, or if we have already used the function's name. */
5652 DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
5653 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
5654 make_decl_rtl (decl, asmspec, 0);
5657 /* If `start_decl' didn't like having an initialization, ignore it now. */
5658 else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
5660 else if (DECL_EXTERNAL (decl))
5662 else if (TREE_CODE (type) == REFERENCE_TYPE
5663 || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
5665 grok_reference_init (decl, type, init, &cleanup);
5669 GNU_xref_decl (current_function_decl, decl);
5671 if (TREE_CODE (decl) == FIELD_DECL || DECL_EXTERNAL (decl))
5673 else if (TREE_CODE (decl) == CONST_DECL)
5675 my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
5677 DECL_INITIAL (decl) = init;
5679 /* This will keep us from needing to worry about our obstacks. */
5680 my_friendly_assert (init != NULL_TREE, 149);
5685 if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
5687 if (TREE_CODE (type) == ARRAY_TYPE)
5688 init = digest_init (type, init, (tree *) 0);
5689 else if (TREE_CODE (init) == CONSTRUCTOR
5690 && CONSTRUCTOR_ELTS (init) != NULL_TREE)
5692 if (TYPE_NEEDS_CONSTRUCTING (type))
5694 cp_error ("`%D' must be initialized by constructor, not by `{...}'", decl);
5695 init = error_mark_node;
5698 goto dont_use_constructor;
5701 /* fix this in `build_functional_cast' instead.
5702 Here's the trigger code:
5707 ostream (int, char *);
5714 int buf_size = 1024;
5715 static char buf[buf_size];
5716 const char *debug(int i) {
5718 ostream o = ostream(buf_size, b);
5724 else if (TREE_CODE (init) == TARGET_EXPR
5725 && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR))
5727 /* User wrote something like `foo x = foo (args)' */
5728 my_friendly_assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL, 150);
5729 my_friendly_assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE, 151);
5731 /* User wrote exactly `foo x = foo (args)' */
5732 if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init))
5734 init = build (CALL_EXPR, TREE_TYPE (init),
5735 TREE_OPERAND (TREE_OPERAND (init, 1), 0),
5736 TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0);
5737 TREE_SIDE_EFFECTS (init) = 1;
5742 /* We must hide the initializer so that expand_decl
5743 won't try to do something it does not understand. */
5744 if (current_binding_level == global_binding_level)
5747 if (flag_conserve_space)
5748 /* If we say -fconserve-space, we want this to save
5749 space, at the expense of wrong semantics. */
5750 /* Should this be a NULL_TREE? */
5751 value = error_mark_node;
5753 /* If we say -fno-conserve-space, we want this to
5754 produce errors about redefs, to do this we make it
5755 go in the data space */
5756 value = digest_init (type, empty_init_node, (tree *) 0);
5757 DECL_INITIAL (decl) = value;
5760 DECL_INITIAL (decl) = error_mark_node;
5764 dont_use_constructor:
5765 if (TREE_CODE (init) != TREE_VEC)
5766 init = store_init_value (decl, init);
5769 /* Don't let anyone try to initialize this variable
5770 until we are ready to do so. */
5771 DECL_INITIAL (decl) = error_mark_node;
5774 else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
5775 && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
5778 while (TREE_CODE (ctype) == ARRAY_TYPE)
5779 ctype = TREE_TYPE (ctype);
5780 if (! TYPE_NEEDS_CONSTRUCTING (ctype))
5782 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
5783 cp_error ("structure `%D' with uninitialized const members", decl);
5784 if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
5785 cp_error ("structure `%D' with uninitialized reference members", decl);
5788 if (TREE_CODE (decl) == VAR_DECL
5789 && !DECL_INITIAL (decl)
5790 && !TYPE_NEEDS_CONSTRUCTING (type)
5791 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
5792 cp_error ("uninitialized const `%D'", decl);
5794 /* Initialize variables in need of static initialization
5795 with `empty_init_node' to keep assemble_variable from putting them
5796 in the wrong program space. (Common storage is okay for non-public
5797 uninitialized data; the linker can't match it with storage from other
5798 files, and we may save some disk space.) */
5800 && TREE_STATIC (decl)
5801 && TREE_PUBLIC (decl)
5802 && ! DECL_EXTERNAL (decl)
5803 && TREE_CODE (decl) == VAR_DECL
5804 && TYPE_NEEDS_CONSTRUCTING (type)
5805 && (DECL_INITIAL (decl) == NULL_TREE
5806 || DECL_INITIAL (decl) == error_mark_node)
5807 /* If we say -fconserve-space, we want this to save space,
5808 at the expense of wrong semantics. */
5809 && ! flag_conserve_space)
5811 tree value = digest_init (type, empty_init_node, (tree *) 0);
5812 DECL_INITIAL (decl) = value;
5815 else if (TREE_CODE (decl) == VAR_DECL
5816 && TREE_CODE (type) != REFERENCE_TYPE
5817 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
5819 /* ``Unless explicitly declared extern, a const object does not have
5820 external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
5821 However, if it's `const int foo = 1; const int foo;', don't complain
5822 about the second decl, since it does have an initializer before.
5823 We deliberately don't complain about arrays, because they're
5824 supposed to be initialized by a constructor. */
5825 if (! DECL_INITIAL (decl)
5826 && TREE_CODE (type) != ARRAY_TYPE
5827 && (!pedantic || !current_class_type))
5828 cp_error ("uninitialized const `%#D'", decl);
5831 /* For top-level declaration, the initial value was read in
5832 the temporary obstack. MAXINDEX, rtl, etc. to be made below
5833 must go in the permanent obstack; but don't discard the
5834 temporary data yet. */
5836 if (current_binding_level == global_binding_level && temporary)
5837 end_temporary_allocation ();
5839 /* Deduce size of array from initialization, if not already known. */
5841 if (TREE_CODE (type) == ARRAY_TYPE
5842 && TYPE_DOMAIN (type) == NULL_TREE
5843 && TREE_CODE (decl) != TYPE_DECL)
5846 = (TREE_STATIC (decl)
5847 /* Even if pedantic, an external linkage array
5848 may have incomplete type at first. */
5849 ? pedantic && ! DECL_EXTERNAL (decl)
5850 : !DECL_EXTERNAL (decl));
5851 tree initializer = init ? init : DECL_INITIAL (decl);
5852 int failure = complete_array_type (type, initializer, do_default);
5855 cp_error ("initializer fails to determine size of `%D'", decl);
5860 cp_error ("array size missing in `%D'", decl);
5861 /* If a `static' var's size isn't known, make it extern as
5862 well as static, so it does not get allocated. If it's not
5863 `static', then don't mark it extern; finish_incomplete_decl
5864 will give it a default size and it will get allocated. */
5865 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
5866 DECL_EXTERNAL (decl) = 1;
5869 if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
5870 && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
5872 cp_error ("zero-size array `%D'", decl);
5874 layout_decl (decl, 0);
5877 if (TREE_CODE (decl) == VAR_DECL)
5879 if (DECL_SIZE (decl) == NULL_TREE
5880 && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
5881 layout_decl (decl, 0);
5883 if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
5885 /* A static variable with an incomplete type:
5886 that is an error if it is initialized.
5887 Otherwise, let it through, but if it is not `extern'
5888 then it may cause an error message later. */
5889 if (DECL_INITIAL (decl) != NULL_TREE)
5890 cp_error ("storage size of `%D' isn't known", decl);
5893 else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
5895 /* An automatic variable with an incomplete type: that is an error.
5896 Don't talk about array types here, since we took care of that
5897 message in grokdeclarator. */
5898 cp_error ("storage size of `%D' isn't known", decl);
5899 TREE_TYPE (decl) = error_mark_node;
5901 else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
5902 /* Let debugger know it should output info for this type. */
5903 note_debug_info_needed (ttype);
5905 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
5906 && DECL_SIZE (decl) != NULL_TREE
5907 && ! TREE_CONSTANT (DECL_SIZE (decl)))
5909 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
5910 constant_expression_warning (DECL_SIZE (decl));
5912 cp_error ("storage size of `%D' isn't constant", decl);
5915 if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
5917 int yes = suspend_momentary ();
5919 /* If INIT comes from a functional cast, use the cleanup
5920 we built for that. Otherwise, make our own cleanup. */
5921 if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
5922 && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
5924 cleanup = TREE_OPERAND (init, 2);
5925 init = TREE_OPERAND (init, 0);
5926 current_binding_level->have_cleanups = 1;
5927 current_binding_level->more_exceptions_ok = 0;
5930 cleanup = maybe_build_cleanup (decl);
5931 resume_momentary (yes);
5934 /* PARM_DECLs get cleanups, too. */
5935 else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
5938 end_temporary_allocation ();
5939 cleanup = maybe_build_cleanup (decl);
5941 resume_temporary_allocation ();
5944 /* Output the assembler code and/or RTL code for variables and functions,
5945 unless the type is an undefined structure or union.
5946 If not, it will get done when the type is completed. */
5948 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
5949 || TREE_CODE (decl) == RESULT_DECL)
5951 /* ??? FIXME: What about nested classes? */
5952 int toplev = (current_binding_level == global_binding_level
5953 || pseudo_global_level_p ());
5955 = ((flag_traditional
5956 || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
5957 && allocation_temporary_p ());
5960 end_temporary_allocation ();
5962 /* If we are in need of a cleanup, get out of any implicit
5963 handlers that have been established so far. */
5964 if (cleanup && current_binding_level->parm_flag == 3)
5966 pop_implicit_try_blocks (decl);
5967 current_binding_level->more_exceptions_ok = 0;
5970 if (TREE_CODE (decl) == VAR_DECL
5971 && current_binding_level != global_binding_level
5972 && ! TREE_STATIC (decl)
5973 && type_needs_gc_entry (type))
5974 DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
5976 if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
5977 make_decl_rtl (decl, NULL_PTR, toplev);
5978 else if (TREE_CODE (decl) == VAR_DECL
5979 && TREE_READONLY (decl)
5980 && DECL_INITIAL (decl) != NULL_TREE
5981 && DECL_INITIAL (decl) != error_mark_node
5982 && DECL_INITIAL (decl) != empty_init_node)
5984 DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
5987 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
5990 && TREE_STATIC (decl)
5991 && ! TREE_SIDE_EFFECTS (decl)
5992 && ! TREE_PUBLIC (decl)
5993 && ! DECL_EXTERNAL (decl)
5994 && ! TYPE_NEEDS_DESTRUCTOR (type)
5995 && DECL_MODE (decl) != BLKmode)
5997 /* If this variable is really a constant, then fill its DECL_RTL
5998 slot with something which won't take up storage.
5999 If something later should take its address, we can always give
6000 it legitimate RTL at that time. */
6001 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
6002 store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
6003 TREE_ASM_WRITTEN (decl) = 1;
6007 /* Keep GCC from complaining that this variable
6008 is defined but never used. */
6009 TREE_USED (decl) = 1;
6010 /* If this is a static const, change its apparent linkage
6011 if it belongs to a #pragma interface. */
6012 if (TREE_STATIC (decl) && !interface_unknown)
6014 TREE_PUBLIC (decl) = 1;
6015 DECL_EXTERNAL (decl) = interface_only;
6017 make_decl_rtl (decl, asmspec, toplev);
6020 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6022 else if (TREE_CODE (decl) == VAR_DECL
6023 && DECL_LANG_SPECIFIC (decl)
6024 && DECL_IN_AGGR_P (decl))
6026 if (TREE_STATIC (decl))
6028 if (init == NULL_TREE
6029 #ifdef DEFAULT_STATIC_DEFS
6030 /* If this code is dead, then users must
6031 explicitly declare static member variables
6032 outside the class def'n as well. */
6033 && TYPE_NEEDS_CONSTRUCTING (type)
6037 DECL_EXTERNAL (decl) = 1;
6038 make_decl_rtl (decl, asmspec, 1);
6041 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6044 /* Just a constant field. Should not need any rtl. */
6048 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6051 resume_temporary_allocation ();
6053 if (type != error_mark_node
6054 && TYPE_LANG_SPECIFIC (type)
6055 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
6056 abstract_virtuals_error (decl, type);
6057 else if ((TREE_CODE (type) == FUNCTION_TYPE
6058 || TREE_CODE (type) == METHOD_TYPE)
6059 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6060 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
6061 abstract_virtuals_error (decl, TREE_TYPE (type));
6063 if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
6064 signature_error (decl, type);
6065 else if ((TREE_CODE (type) == FUNCTION_TYPE
6066 || TREE_CODE (type) == METHOD_TYPE)
6067 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6068 && IS_SIGNATURE (TREE_TYPE (type)))
6069 signature_error (decl, TREE_TYPE (type));
6071 if (TREE_CODE (decl) == FUNCTION_DECL)
6073 /* C++: Handle overloaded functions with default parameters. */
6074 if (DECL_OVERLOADED (decl))
6076 tree parmtypes = TYPE_ARG_TYPES (type);
6077 tree prev = NULL_TREE;
6078 tree original_name = DECL_NAME (decl);
6079 struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl);
6080 /* All variants will share an uncollectible lang_decl. */
6081 copy_decl_lang_specific (decl);
6083 while (parmtypes && parmtypes != void_list_node)
6085 /* The default value for the parameter in parmtypes is
6086 stored in the TREE_PURPOSE of the TREE_LIST. */
6087 if (TREE_PURPOSE (parmtypes))
6089 tree fnname, fndecl;
6092 argp = prev ? & TREE_CHAIN (prev)
6093 : & TYPE_ARG_TYPES (type);
6096 fnname = build_decl_overload (original_name, TYPE_ARG_TYPES (type), 0);
6098 fndecl = build_decl (FUNCTION_DECL, fnname, type);
6099 DECL_EXTERNAL (fndecl) = DECL_EXTERNAL (decl);
6100 TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl);
6101 DECL_INLINE (fndecl) = DECL_INLINE (decl);
6102 /* Keep G++ from thinking this function is unused.
6103 It is only used to speed up search in name space. */
6104 TREE_USED (fndecl) = 1;
6105 TREE_ASM_WRITTEN (fndecl) = 1;
6106 DECL_INITIAL (fndecl) = NULL_TREE;
6107 DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl);
6108 fndecl = pushdecl (fndecl);
6109 DECL_INITIAL (fndecl) = error_mark_node;
6110 DECL_RTL (fndecl) = DECL_RTL (decl);
6113 parmtypes = TREE_CHAIN (parmtypes);
6115 DECL_LANG_SPECIFIC (decl) = tmp_lang_decl;
6118 else if (DECL_EXTERNAL (decl))
6120 else if (TREE_STATIC (decl) && type != error_mark_node)
6122 /* Cleanups for static variables are handled by `finish_file'. */
6123 if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE)
6124 expand_static_init (decl, init);
6125 else if (TYPE_NEEDS_DESTRUCTOR (type))
6126 static_aggregates = perm_tree_cons (NULL_TREE, decl,
6129 /* Make entry in appropriate vector. */
6130 if (flag_gc && type_needs_gc_entry (type))
6131 build_static_gc_entry (decl, type);
6135 /* This is a declared decl which must live until the
6136 end of the binding contour. It may need a cleanup. */
6138 /* Recompute the RTL of a local array now
6139 if it used to be an incomplete type. */
6140 if (was_incomplete && ! TREE_STATIC (decl))
6142 /* If we used it already as memory, it must stay in memory. */
6143 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
6144 /* If it's still incomplete now, no init will save it. */
6145 if (DECL_SIZE (decl) == NULL_TREE)
6146 DECL_INITIAL (decl) = NULL_TREE;
6149 else if (! TREE_ASM_WRITTEN (decl)
6150 && (TYPE_SIZE (type) != NULL_TREE
6151 || TREE_CODE (type) == ARRAY_TYPE))
6153 /* Do this here, because we did not expand this decl's
6154 rtl in start_decl. */
6155 if (DECL_RTL (decl) == NULL_RTX)
6159 expand_decl_cleanup (NULL_TREE, cleanup);
6160 /* Cleanup used up here. */
6161 cleanup = NULL_TREE;
6165 if (DECL_SIZE (decl) && type != error_mark_node)
6167 /* Compute and store the initial value. */
6168 expand_decl_init (decl);
6170 if (init || TYPE_NEEDS_CONSTRUCTING (type))
6172 emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
6173 expand_aggr_init (decl, init, 0);
6176 /* Set this to 0 so we can tell whether an aggregate
6177 which was initialized was ever used. */
6178 if (TYPE_NEEDS_CONSTRUCTING (type))
6179 TREE_USED (decl) = 0;
6181 /* Store the cleanup, if there was one. */
6184 if (! expand_decl_cleanup (decl, cleanup))
6185 cp_error ("parser lost in parsing declaration of `%D'", decl);
6191 /* Undo call to `pushclass' that was done in `start_decl'
6192 due to initialization of qualified member variable.
6193 I.e., Foo::x = 10; */
6195 tree context = DECL_CONTEXT (decl);
6197 && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
6198 && (TREE_CODE (decl) == VAR_DECL
6199 /* We also have a pushclass done that we need to undo here
6200 if we're at top level and declare a method. */
6201 || (TREE_CODE (decl) == FUNCTION_DECL
6202 /* If size hasn't been set, we're still defining it,
6203 and therefore inside the class body; don't pop
6204 the binding level.. */
6205 && TYPE_SIZE (context) != NULL_TREE
6206 /* The binding level gets popped elsewhere for a
6207 friend declaration inside another class. */
6209 && TYPE_IDENTIFIER (context) == current_class_name
6211 && context == current_class_type
6221 /* Resume permanent allocation, if not within a function. */
6222 /* The corresponding push_obstacks_nochange is in start_decl,
6223 start_method, groktypename, and in grokfield. */
6228 TREE_READONLY (decl) = 1;
6231 cadillac_finish_decl (decl);
6235 expand_static_init (decl, init)
6239 tree oldstatic = value_member (decl, static_aggregates);
6242 if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
6243 cp_error ("multiple initializations given for `%D'", decl);
6245 else if (current_binding_level != global_binding_level)
6247 /* Emit code to perform this initialization but once. */
6250 /* Remember this information until end of file. */
6251 push_obstacks (&permanent_obstack, &permanent_obstack);
6253 /* Emit code to perform this initialization but once. */
6254 temp = get_temp_name (integer_type_node, 1);
6255 rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
6256 expand_start_cond (build_binary_op (EQ_EXPR, temp,
6257 integer_zero_node, 1), 0);
6258 expand_assignment (temp, integer_one_node, 0, 0);
6259 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6261 expand_aggr_init (decl, init, 0);
6262 do_pending_stack_adjust ();
6265 expand_assignment (decl, init, 0, 0);
6267 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
6269 static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
6270 TREE_STATIC (static_aggregates) = 1;
6273 /* Resume old (possibly temporary) allocation. */
6278 /* This code takes into account memory allocation
6279 policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING
6280 does not hold for this object, then we must make permanent
6281 the storage currently in the temporary obstack. */
6282 if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
6283 preserve_initializer ();
6284 static_aggregates = perm_tree_cons (init, decl, static_aggregates);
6288 /* Make TYPE a complete type based on INITIAL_VALUE.
6289 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
6290 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
6293 complete_array_type (type, initial_value, do_default)
6294 tree type, initial_value;
6297 register tree maxindex = NULL_TREE;
6302 /* Note MAXINDEX is really the maximum index,
6303 one less than the size. */
6304 if (TREE_CODE (initial_value) == STRING_CST)
6305 maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
6306 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
6309 = list_length (CONSTRUCTOR_ELTS (initial_value));
6310 maxindex = build_int_2 (nelts - 1, - (nelts == 0));
6314 /* Make an error message unless that happened already. */
6315 if (initial_value != error_mark_node)
6318 /* Prevent further error messages. */
6319 maxindex = build_int_2 (0, 0);
6326 maxindex = build_int_2 (0, 0);
6332 TYPE_DOMAIN (type) = build_index_type (maxindex);
6333 if (!TREE_TYPE (maxindex))
6334 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
6337 /* Lay out the type now that we can get the real answer. */
6344 /* Return zero if something is declared to be a member of type
6345 CTYPE when in the context of CUR_TYPE. STRING is the error
6346 message to print in that case. Otherwise, quietly return 1. */
6348 member_function_or_else (ctype, cur_type, string)
6349 tree ctype, cur_type;
6352 if (ctype && ctype != cur_type)
6354 error (string, TYPE_NAME_STRING (ctype));
6360 /* Subroutine of `grokdeclarator'. */
6362 /* Generate errors possibly applicable for a given set of specifiers.
6363 This is for ARM $7.1.2. */
6365 bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
6368 int virtualp, quals, friendp, raises, inlinep;
6371 cp_error ("`%D' declared as a `virtual' %s", object, type);
6373 cp_error ("`%D' declared as an `inline' %s", object, type);
6375 cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", object, type);
6377 cp_error_at ("invalid friend declaration", object);
6379 cp_error_at ("invalid raises declaration", object);
6382 /* CTYPE is class type, or null if non-class.
6383 TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
6385 DECLARATOR is the function's name.
6386 VIRTUALP is truthvalue of whether the function is virtual or not.
6387 FLAGS are to be passed through to `grokclassfn'.
6388 QUALS are qualifiers indicating whether the function is `const'
6390 RAISES is a list of exceptions that this function can raise.
6391 CHECK is 1 if we must find this method in CTYPE, 0 if we should
6392 not look, and -1 if we should not call `grokclassfn' at all. */
6394 grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, check, publicp)
6398 enum overload_flags flags;
6403 int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
6406 cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
6407 ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
6413 type = build_exception_variant (ctype, type, raises);
6414 raises = TYPE_RAISES_EXCEPTIONS (type);
6416 decl = build_lang_decl (FUNCTION_DECL, declarator, type);
6417 /* propagate volatile out from type to decl */
6418 if (TYPE_VOLATILE (type))
6419 TREE_THIS_VOLATILE (decl) = 1;
6421 /* Should probably propagate const out from type to decl I bet (mrs). */
6424 DECL_STATIC_FUNCTION_P (decl) = 1;
6425 DECL_CONTEXT (decl) = ctype;
6426 DECL_CLASS_CONTEXT (decl) = ctype;
6430 TREE_PUBLIC (decl) = 1;
6432 DECL_EXTERNAL (decl) = 1;
6433 if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
6435 cp_error ("%smember function `%D' cannot have `%T' method qualifier",
6436 (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
6440 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
6441 grok_op_properties (decl, virtualp, check < 0);
6443 /* Caller will do the rest of this. */
6447 if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
6450 /* Just handle constructors here. We could do this
6451 inside the following if stmt, but I think
6452 that the code is more legible by breaking this
6453 case out. See comments below for what each of
6454 the following calls is supposed to do. */
6455 DECL_CONSTRUCTOR_P (decl) = 1;
6457 grokclassfn (ctype, declarator, decl, flags, quals);
6459 check_classfn (ctype, declarator, decl);
6460 grok_ctor_properties (ctype, decl);
6463 /* FIXME: this should only need to look at IDENTIFIER_GLOBAL_VALUE. */
6464 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
6465 if (tmp == NULL_TREE)
6466 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
6467 else if (TREE_CODE (tmp) != TREE_CODE (decl))
6468 cp_error ("inconsistent declarations for `%D'", decl);
6471 duplicate_decls (decl, tmp);
6473 /* avoid creating circularities. */
6474 DECL_CHAIN (decl) = NULL_TREE;
6476 make_decl_rtl (decl, NULL_PTR, 1);
6483 /* Function gets the ugly name, field gets the nice one.
6484 This call may change the type of the function (because
6485 of default parameters)! */
6486 if (ctype != NULL_TREE)
6487 grokclassfn (ctype, cname, decl, flags, quals);
6489 if (ctype != NULL_TREE && check)
6490 check_classfn (ctype, cname, decl);
6492 if (ctype == NULL_TREE || check)
6495 /* Now install the declaration of this function so that
6496 others may find it (esp. its DECL_FRIENDLIST).
6497 Pretend we are at top level, we will get true
6498 reference later, perhaps.
6500 FIXME: This should only need to look at IDENTIFIER_GLOBAL_VALUE. */
6501 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
6502 if (tmp == NULL_TREE)
6503 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
6504 else if (TREE_CODE (tmp) != TREE_CODE (decl))
6505 cp_error ("inconsistent declarations for `%D'", decl);
6508 duplicate_decls (decl, tmp);
6510 /* avoid creating circularities. */
6511 DECL_CHAIN (decl) = NULL_TREE;
6513 make_decl_rtl (decl, NULL_PTR, 1);
6515 /* If this declaration supersedes the declaration of
6516 a method declared virtual in the base class, then
6517 mark this field as being virtual as well. */
6519 tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
6520 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
6522 for (i = 0; i < n_baselinks; i++)
6524 tree base_binfo = TREE_VEC_ELT (binfos, i);
6525 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)) || flag_all_virtual == 1)
6527 tmp = get_first_matching_virtual (base_binfo, decl,
6528 flags == DTOR_FLAG);
6531 /* If this function overrides some virtual in some base
6532 class, then the function itself is also necessarily
6533 virtual, even if the user didn't explicitly say so. */
6534 DECL_VIRTUAL_P (decl) = 1;
6536 /* The TMP we really want is the one from the deepest
6537 baseclass on this path, taking care not to
6538 duplicate if we have already found it (via another
6539 path to its virtual baseclass. */
6542 cp_error ("method `%D' may not be declared static", decl);
6543 cp_error_at ("(since `%D' declared virtual in base class.)", tmp);
6549 /* Disable this as we want the most recent fndecl, not the most
6551 if ((TYPE_USES_VIRTUAL_BASECLASSES (BINFO_TYPE (base_binfo))
6552 || TYPE_USES_MULTIPLE_INHERITANCE (ctype))
6553 && BINFO_TYPE (base_binfo) != DECL_CONTEXT (tmp))
6554 tmp = get_first_matching_virtual (TYPE_BINFO (DECL_CONTEXT (tmp)),
6555 decl, flags == DTOR_FLAG);
6557 if (value_member (tmp, DECL_VINDEX (decl)) == NULL_TREE)
6559 /* The argument types may have changed... */
6560 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
6561 tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
6563 argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
6564 TREE_CHAIN (argtypes));
6565 /* But the return type has not. */
6566 type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
6569 type = build_exception_variant (ctype, type, raises);
6570 raises = TYPE_RAISES_EXCEPTIONS (type);
6572 TREE_TYPE (decl) = type;
6574 = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
6582 if (DECL_VINDEX (decl) == NULL_TREE)
6583 DECL_VINDEX (decl) = error_mark_node;
6584 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
6585 if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
6586 /* If this function is derived from a template, don't
6587 make it public. This shouldn't be here, but there's
6588 no good way to override the interface pragmas for one
6589 function or class only. Bletch. */
6590 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE
6591 && (write_virtuals == 2
6592 || (write_virtuals == 3
6593 && CLASSTYPE_INTERFACE_KNOWN (ctype))))
6594 TREE_PUBLIC (decl) = 1;
6601 grokvardecl (type, declarator, specbits, initialized)
6604 RID_BIT_TYPE specbits;
6609 if (TREE_CODE (type) == OFFSET_TYPE)
6611 /* If you declare a static member so that it
6612 can be initialized, the code will reach here. */
6613 tree field = lookup_field (TYPE_OFFSET_BASETYPE (type),
6615 if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
6617 tree basetype = TYPE_OFFSET_BASETYPE (type);
6618 error ("`%s' is not a static member of class `%s'",
6619 IDENTIFIER_POINTER (declarator),
6620 TYPE_NAME_STRING (basetype));
6621 type = TREE_TYPE (type);
6622 decl = build_lang_field_decl (VAR_DECL, declarator, type);
6623 DECL_CONTEXT (decl) = basetype;
6624 DECL_CLASS_CONTEXT (decl) = basetype;
6628 tree f_type = TREE_TYPE (field);
6629 tree o_type = TREE_TYPE (type);
6631 if (TYPE_SIZE (f_type) == NULL_TREE)
6633 if (TREE_CODE (f_type) != TREE_CODE (o_type)
6634 || (TREE_CODE (f_type) == ARRAY_TYPE
6635 && TREE_TYPE (f_type) != TREE_TYPE (o_type)))
6636 error ("redeclaration of type for `%s'",
6637 IDENTIFIER_POINTER (declarator));
6638 else if (TYPE_SIZE (o_type) != NULL_TREE)
6639 TREE_TYPE (field) = type;
6641 else if (f_type != o_type)
6642 error ("redeclaration of type for `%s'",
6643 IDENTIFIER_POINTER (declarator));
6645 if (initialized && DECL_INITIAL (decl)
6646 /* Complain about multiply-initialized
6647 member variables, but don't be faked
6648 out if initializer is faked up from `empty_init_node'. */
6649 && (TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
6650 || CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) != NULL_TREE))
6651 error_with_aggr_type (DECL_CONTEXT (decl),
6652 "multiple initializations of static member `%s::%s'",
6653 IDENTIFIER_POINTER (DECL_NAME (decl)));
6657 decl = build_decl (VAR_DECL, declarator, type);
6659 if (RIDBIT_SETP (RID_EXTERN, specbits))
6661 DECL_THIS_EXTERN (decl) = 1;
6662 DECL_EXTERNAL (decl) = !initialized;
6665 /* In class context, static means one per class,
6666 public access, and static storage. */
6667 if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
6668 && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
6670 TREE_PUBLIC (decl) = 1;
6671 TREE_STATIC (decl) = 1;
6672 DECL_EXTERNAL (decl) = !initialized;
6674 /* At top level, either `static' or no s.c. makes a definition
6675 (perhaps tentative), and absence of `static' makes it public. */
6676 else if (current_binding_level == global_binding_level)
6678 TREE_PUBLIC (decl) = RIDBIT_NOTSETP (RID_STATIC, specbits);
6679 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
6681 /* Not at top level, only `static' makes a static definition. */
6684 TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
6685 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
6690 /* Create a canonical pointer to member function type. */
6693 build_ptrmemfunc_type (type)
6700 /* If a canonical type already exists for this type, use it. We use
6701 this method instead of type_hash_canon, because it only does a
6702 simple equality check on the list of field members. */
6704 if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
6707 push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
6709 u = make_lang_type (UNION_TYPE);
6710 fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
6711 fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, delta_type_node);
6712 finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
6713 TYPE_NAME (u) = NULL_TREE;
6715 t = make_lang_type (RECORD_TYPE);
6717 /* Let the front-end know this is a pointer to member function. */
6718 TYPE_PTRMEMFUNC_FLAG(t) = 1;
6720 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, delta_type_node);
6721 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, delta_type_node);
6722 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
6723 finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
6727 /* Zap out the name so that the back-end will give us the debugging
6728 information for this anonymous RECORD_TYPE. */
6729 TYPE_NAME (t) = NULL_TREE;
6731 TYPE_SET_PTRMEMFUNC_TYPE (type, t);
6733 /* Seems to be wanted. */
6734 CLASSTYPE_GOT_SEMICOLON (t) = 1;
6738 /* Given declspecs and a declarator,
6739 determine the name and type of the object declared
6740 and construct a ..._DECL node for it.
6741 (In one case we can return a ..._TYPE node instead.
6742 For invalid input we sometimes return 0.)
6744 DECLSPECS is a chain of tree_list nodes whose value fields
6745 are the storage classes and type specifiers.
6747 DECL_CONTEXT says which syntactic context this declaration is in:
6748 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
6749 FUNCDEF for a function definition. Like NORMAL but a few different
6750 error messages in each case. Return value may be zero meaning
6751 this definition is too screwy to try to parse.
6752 MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
6753 handle member functions (which have FIELD context).
6754 Return value may be zero meaning this definition is too screwy to
6756 PARM for a parameter declaration (either within a function prototype
6757 or before a function body). Make a PARM_DECL, or return void_type_node.
6758 TYPENAME if for a typename (in a cast or sizeof).
6759 Don't make a DECL node; just return the ..._TYPE node.
6760 FIELD for a struct or union field; make a FIELD_DECL.
6761 BITFIELD for a field with specified width.
6762 INITIALIZED is 1 if the decl has an initializer.
6764 In the TYPENAME case, DECLARATOR is really an absolute declarator.
6765 It may also be so in the PARM case, for a prototype where the
6766 argument type is specified but not the name.
6768 This function is where the complicated C meanings of `static'
6769 and `extern' are interpreted.
6771 For C++, if there is any monkey business to do, the function which
6772 calls this one must do it, i.e., prepending instance variables,
6773 renaming overloaded function names, etc.
6775 Note that for this C++, it is an error to define a method within a class
6776 which does not belong to that class.
6778 Except in the case where SCOPE_REFs are implicitly known (such as
6779 methods within a class being redundantly qualified),
6780 declarations which involve SCOPE_REFs are returned as SCOPE_REFs
6781 (class_name::decl_name). The caller must also deal with this.
6783 If a constructor or destructor is seen, and the context is FIELD,
6784 then the type gains the attribute TREE_HAS_x. If such a declaration
6785 is erroneous, NULL_TREE is returned.
6787 QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
6788 function, these are the qualifiers to give to the `this' pointer.
6790 May return void_type_node if the declarator turned out to be a friend.
6791 See grokfield for details. */
6793 enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
6796 grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
6799 enum decl_context decl_context;
6803 RID_BIT_TYPE specbits;
6806 tree type = NULL_TREE;
6810 int virtualp, friendp, inlinep, staticp;
6811 int explicit_int = 0;
6812 int explicit_char = 0;
6813 int opaque_typedef = 0;
6814 tree typedef_decl = NULL_TREE;
6816 tree typedef_type = NULL_TREE;
6817 int funcdef_flag = 0;
6818 enum tree_code innermost_code = ERROR_MARK;
6820 int size_varies = 0;
6821 /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
6822 All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
6823 tree init = NULL_TREE;
6825 /* Keep track of what sort of function is being processed
6826 so that we can warn about default return values, or explicit
6827 return values which do not match prescribed defaults. */
6828 enum return_types return_type = return_normal;
6830 tree dname = NULL_TREE;
6831 tree ctype = current_class_type;
6832 tree ctor_return_type = NULL_TREE;
6833 enum overload_flags flags = NO_SPECIAL;
6834 int seen_scope_ref = 0;
6835 tree quals = NULL_TREE;
6837 RIDBIT_RESET_ALL (specbits);
6838 if (decl_context == FUNCDEF)
6839 funcdef_flag = 1, decl_context = NORMAL;
6840 else if (decl_context == MEMFUNCDEF)
6841 funcdef_flag = -1, decl_context = FIELD;
6842 else if (decl_context == BITFIELD)
6843 bitfield = 1, decl_context = FIELD;
6845 if (flag_traditional && allocation_temporary_p ())
6846 end_temporary_allocation ();
6848 /* Look inside a declarator for the name being declared
6849 and get it as a string, for an error message. */
6851 tree type, last = NULL_TREE;
6852 register tree decl = declarator;
6856 switch (TREE_CODE (decl))
6860 decl = TREE_OPERAND (decl, 0);
6863 case BIT_NOT_EXPR: /* for C++ destructors! */
6865 tree name = TREE_OPERAND (decl, 0);
6866 tree rename = NULL_TREE;
6868 my_friendly_assert (flags == NO_SPECIAL, 152);
6870 return_type = return_dtor;
6871 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
6872 if (ctype == NULL_TREE)
6874 if (current_class_type == NULL_TREE)
6876 error ("destructors must be member functions");
6881 tree t = constructor_name (current_class_name);
6888 tree t = constructor_name (ctype);
6895 error ("destructor `%s' must match class name `%s'",
6896 IDENTIFIER_POINTER (name),
6897 IDENTIFIER_POINTER (rename));
6898 TREE_OPERAND (decl, 0) = rename;
6904 case ADDR_EXPR: /* C++ reference declaration */
6909 innermost_code = TREE_CODE (decl);
6911 decl = TREE_OPERAND (decl, 0);
6915 if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
6917 /* This is actually a variable declaration using constructor
6918 syntax. We need to call start_decl and finish_decl so we
6919 can get the variable initialized... */
6922 /* We need to insinuate ourselves into the declarator in place
6923 of the CALL_EXPR. */
6924 TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
6926 declarator = TREE_OPERAND (decl, 0);
6928 init = TREE_OPERAND (decl, 1);
6930 decl = start_decl (declarator, declspecs, 1, NULL_TREE);
6931 finish_decl (decl, init, NULL_TREE, 1);
6934 innermost_code = TREE_CODE (decl);
6935 decl = TREE_OPERAND (decl, 0);
6936 if (decl_context == FIELD && ctype == NULL_TREE)
6937 ctype = current_class_type;
6938 if (ctype != NULL_TREE
6939 && decl != NULL_TREE && flags != DTOR_FLAG
6940 && decl == constructor_name (ctype))
6942 return_type = return_ctor;
6943 ctor_return_type = ctype;
6948 case IDENTIFIER_NODE:
6950 name = IDENTIFIER_POINTER (decl);
6957 /* Parse error puts this typespec where
6958 a declarator should go. */
6959 error ("declarator name missing");
6960 dname = TYPE_NAME (decl);
6961 if (dname && TREE_CODE (dname) == TYPE_DECL)
6962 dname = DECL_NAME (dname);
6963 name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
6964 declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
6969 my_friendly_assert (flags == NO_SPECIAL, 154);
6970 flags = TYPENAME_FLAG;
6971 name = "operator <typename>"; /* We don't know the type yet. */
6972 /* Go to the absdcl. */
6973 decl = TREE_OPERAND (decl, 0);
6974 return_type = return_conversion;
6980 if (seen_scope_ref == 1)
6981 error ("multiple `::' terms in declarator invalid");
6983 seen_scope_ref += 1;
6985 /* Perform error checking, and convert class names to types.
6986 We may call grokdeclarator multiple times for the same
6987 tree structure, so only do the conversion once. In this
6988 case, we have exactly what we want for `ctype'. */
6989 tree cname = TREE_OPERAND (decl, 0);
6990 if (cname == NULL_TREE)
6992 /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */
6993 else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname))
6994 || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE)
6996 else if (! is_aggr_typedef (cname, 1))
6998 TREE_OPERAND (decl, 0) = NULL_TREE;
7000 /* Must test TREE_OPERAND (decl, 1), in case user gives
7001 us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */
7002 else if (TREE_OPERAND (decl, 1)
7003 && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
7005 TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
7007 else if (ctype == NULL_TREE)
7009 ctype = IDENTIFIER_TYPE_VALUE (cname);
7010 TREE_OPERAND (decl, 0) = ctype;
7012 else if (TREE_COMPLEXITY (decl) == current_class_depth)
7013 TREE_OPERAND (decl, 0) = ctype;
7016 if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname),
7019 cp_error ("type `%T' is not derived from type `%T'",
7020 IDENTIFIER_TYPE_VALUE (cname), ctype);
7021 TREE_OPERAND (decl, 0) = NULL_TREE;
7025 ctype = IDENTIFIER_TYPE_VALUE (cname);
7026 TREE_OPERAND (decl, 0) = ctype;
7030 decl = TREE_OPERAND (decl, 1);
7033 if (TREE_CODE (decl) == IDENTIFIER_NODE
7034 && constructor_name (ctype) == decl)
7036 return_type = return_ctor;
7037 ctor_return_type = ctype;
7039 else if (TREE_CODE (decl) == BIT_NOT_EXPR
7040 && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
7041 && constructor_name (ctype) == TREE_OPERAND (decl, 0))
7043 return_type = return_dtor;
7044 ctor_return_type = ctype;
7046 decl = TREE_OPERAND (decl, 0);
7057 return 0; /* We used to do a 155 abort here. */
7063 /* A function definition's declarator must have the form of
7064 a function declarator. */
7066 if (funcdef_flag && innermost_code != CALL_EXPR)
7069 /* Anything declared one level down from the top level
7070 must be one of the parameters of a function
7071 (because the body is at least two levels down). */
7073 /* This heuristic cannot be applied to C++ nodes! Fixed, however,
7074 by not allowing C++ class definitions to specify their parameters
7075 with xdecls (must be spec.d in the parmlist).
7077 Since we now wait to push a class scope until we are sure that
7078 we are in a legitimate method context, we must set oldcname
7079 explicitly (since current_class_name is not yet alive). */
7081 if (decl_context == NORMAL
7082 && current_binding_level->level_chain == global_binding_level)
7083 decl_context = PARM;
7085 /* Look through the decl specs and record which ones appear.
7086 Some typespecs are defined as built-in typenames.
7087 Others, the ones that are modifiers of other types,
7088 are represented by bits in SPECBITS: set the bits for
7089 the modifiers that appear. Storage class keywords are also in SPECBITS.
7091 If there is a typedef name or a type, store the type in TYPE.
7092 This includes builtin typedefs such as `int'.
7094 Set EXPLICIT_INT if the type is `int' or `char' and did not
7095 come from a user typedef.
7097 Set LONGLONG if `long' is mentioned twice.
7099 For C++, constructors and destructors have their own fast treatment. */
7101 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
7106 /* Certain parse errors slip through. For example,
7107 `int class;' is not caught by the parser. Try
7108 weakly to recover here. */
7109 if (TREE_CODE (spec) != TREE_LIST)
7112 id = TREE_VALUE (spec);
7114 if (TREE_CODE (id) == IDENTIFIER_NODE)
7116 if (id == ridpointers[(int) RID_INT])
7119 error ("extraneous `int' ignored");
7123 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7127 if (id == ridpointers[(int) RID_CHAR])
7130 error ("extraneous `char' ignored");
7134 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7138 if (id == ridpointers[(int) RID_WCHAR])
7141 error ("extraneous `__wchar_t' ignored");
7144 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
7148 /* C++ aggregate types. */
7149 if (IDENTIFIER_HAS_TYPE_VALUE (id))
7152 cp_error ("multiple declarations `%T' and `%T'", type, id);
7154 type = IDENTIFIER_TYPE_VALUE (id);
7158 for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
7160 if (ridpointers[i] == id)
7162 if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
7166 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
7170 error ("`long long long' is too long for GCC");
7174 else if (RIDBIT_SETP (i, specbits))
7175 warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
7176 RIDBIT_SET (i, specbits);
7182 error ("two or more data types in declaration of `%s'", name);
7183 else if (TREE_CODE (id) == IDENTIFIER_NODE)
7185 register tree t = lookup_name (id, 1);
7186 if (!t || TREE_CODE (t) != TYPE_DECL)
7187 error ("`%s' fails to be a typedef or built in type",
7188 IDENTIFIER_POINTER (id));
7191 type = TREE_TYPE (t);
7195 else if (TREE_CODE (id) != ERROR_MARK)
7196 /* Can't change CLASS nodes into RECORD nodes here! */
7202 typedef_type = type;
7204 /* No type at all: default to `int', and set EXPLICIT_INT
7205 because it was not a user-defined typedef.
7206 Except when we have a `typedef' inside a signature, in
7207 which case the type defaults to `unknown type' and is
7208 instantiated when assigning to a signature pointer or ref. */
7210 if (type == NULL_TREE)
7213 if (return_type == return_dtor)
7214 type = void_type_node;
7215 else if (return_type == return_ctor)
7216 type = TYPE_POINTER_TO (ctor_return_type);
7217 else if (current_class_type
7218 && IS_SIGNATURE (current_class_type)
7219 && (RIDBIT_SETP (RID_TYPEDEF, specbits)
7220 || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7221 && (decl_context == FIELD || decl_context == NORMAL))
7225 type = copy_node (opaque_type_node);
7229 if (funcdef_flag && warn_return_type
7230 && return_type == return_normal
7231 && ! (RIDBIT_SETP (RID_SIGNED, specbits)
7232 || RIDBIT_SETP (RID_UNSIGNED, specbits)
7233 || RIDBIT_SETP (RID_LONG, specbits)
7234 || RIDBIT_SETP (RID_SHORT, specbits)))
7235 warn_about_return_type = 1;
7236 /* Save warning until we know what is really going on. */
7237 type = integer_type_node;
7240 else if (return_type == return_dtor)
7242 error ("return type specification for destructor invalid");
7243 type = void_type_node;
7245 else if (return_type == return_ctor)
7247 error ("return type specification for constructor invalid");
7248 type = TYPE_POINTER_TO (ctor_return_type);
7253 /* Now process the modifiers that were specified
7254 and check for invalid combinations. */
7256 /* Long double is a special combination. */
7258 if (RIDBIT_SETP (RID_LONG, specbits)
7259 && TYPE_MAIN_VARIANT (type) == double_type_node)
7261 RIDBIT_RESET (RID_LONG, specbits);
7262 type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
7263 TYPE_VOLATILE (type));
7266 /* Check all other uses of type modifiers. */
7268 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7269 || RIDBIT_SETP (RID_SIGNED, specbits)
7270 || RIDBIT_SETP (RID_LONG, specbits)
7271 || RIDBIT_SETP (RID_SHORT, specbits))
7275 if (TREE_CODE (type) == REAL_TYPE)
7276 error ("short, signed or unsigned invalid for `%s'", name);
7277 else if (TREE_CODE (type) != INTEGER_TYPE || type == wchar_type_node)
7278 error ("long, short, signed or unsigned invalid for `%s'", name);
7279 else if (RIDBIT_SETP (RID_LONG, specbits)
7280 && RIDBIT_SETP (RID_SHORT, specbits))
7281 error ("long and short specified together for `%s'", name);
7282 else if ((RIDBIT_SETP (RID_LONG, specbits)
7283 || RIDBIT_SETP (RID_SHORT, specbits))
7285 error ("long or short specified with char for `%s'", name);
7286 else if ((RIDBIT_SETP (RID_LONG, specbits)
7287 || RIDBIT_SETP (RID_SHORT, specbits))
7288 && TREE_CODE (type) == REAL_TYPE)
7289 error ("long or short specified with floating type for `%s'", name);
7290 else if (RIDBIT_SETP (RID_SIGNED, specbits)
7291 && RIDBIT_SETP (RID_UNSIGNED, specbits))
7292 error ("signed and unsigned given together for `%s'", name);
7296 if (!explicit_int && !explicit_char && pedantic)
7298 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
7300 if (flag_pedantic_errors)
7305 /* Discard the type modifiers if they are invalid. */
7308 RIDBIT_RESET (RID_UNSIGNED, specbits);
7309 RIDBIT_RESET (RID_SIGNED, specbits);
7310 RIDBIT_RESET (RID_LONG, specbits);
7311 RIDBIT_RESET (RID_SHORT, specbits);
7316 /* Decide whether an integer type is signed or not.
7317 Optionally treat bitfields as signed by default. */
7318 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
7319 /* Traditionally, all bitfields are unsigned. */
7320 || (bitfield && flag_traditional)
7321 || (bitfield && ! flag_signed_bitfields
7322 && (explicit_int || explicit_char
7323 /* A typedef for plain `int' without `signed'
7324 can be controlled just like plain `int'. */
7325 || ! (typedef_decl != NULL_TREE
7326 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
7327 && TREE_CODE (type) != ENUMERAL_TYPE
7328 && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
7331 type = long_long_unsigned_type_node;
7332 else if (RIDBIT_SETP (RID_LONG, specbits))
7333 type = long_unsigned_type_node;
7334 else if (RIDBIT_SETP (RID_SHORT, specbits))
7335 type = short_unsigned_type_node;
7336 else if (type == char_type_node)
7337 type = unsigned_char_type_node;
7338 else if (typedef_decl)
7339 type = unsigned_type (type);
7341 type = unsigned_type_node;
7343 else if (RIDBIT_SETP (RID_SIGNED, specbits)
7344 && type == char_type_node)
7345 type = signed_char_type_node;
7347 type = long_long_integer_type_node;
7348 else if (RIDBIT_SETP (RID_LONG, specbits))
7349 type = long_integer_type_node;
7350 else if (RIDBIT_SETP (RID_SHORT, specbits))
7351 type = short_integer_type_node;
7353 /* Set CONSTP if this declaration is `const', whether by
7354 explicit specification or via a typedef.
7355 Likewise for VOLATILEP. */
7357 constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
7358 volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
7360 inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
7362 warning ("duplicate `const'");
7364 warning ("duplicate `volatile'");
7365 virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
7367 /* operators new and delete are implicitly static. */
7368 if (RIDBIT_SETP (RID_STATIC, specbits))
7369 staticp = 1 + (decl_context == FIELD);
7371 if (virtualp && staticp == 2)
7373 cp_error ("member `%D' cannot be declared both virtual and static",
7377 friendp = RIDBIT_SETP (RID_FRIEND, specbits);
7378 RIDBIT_RESET (RID_VIRTUAL, specbits);
7379 RIDBIT_RESET (RID_FRIEND, specbits);
7381 if (RIDBIT_SETP (RID_MUTABLE, specbits))
7383 if (decl_context == PARM)
7385 error ("non-member `%s' cannot be declared mutable", name);
7386 RIDBIT_RESET (RID_MUTABLE, specbits);
7388 else if (friendp || decl_context == TYPENAME)
7390 error ("non-object member `%s' cannot be declared mutable", name);
7391 RIDBIT_RESET (RID_MUTABLE, specbits);
7395 error ("static `%s' cannot be declared mutable", name);
7396 RIDBIT_RESET (RID_MUTABLE, specbits);
7399 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7401 error ("non-object member `%s' cannot be declared mutable", name);
7402 RIDBIT_RESET (RID_MUTABLE, specbits);
7404 /* Because local typedefs are parsed twice, we don't want this
7406 else if (decl_context != FIELD)
7408 error ("non-member `%s' cannot be declared mutable", name);
7409 RIDBIT_RESET (RID_MUTABLE, specbits);
7414 /* Warn if two storage classes are given. Default to `auto'. */
7416 if (RIDBIT_ANY_SET (specbits))
7418 if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
7419 if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
7420 if (decl_context == PARM && nclasses > 0)
7421 error ("storage class specifiers invalid in parameter declarations");
7422 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
7424 if (decl_context == PARM)
7425 error ("typedef declaration invalid in parameter declaration");
7428 if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
7429 if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
7432 /* Give error if `virtual' is used outside of class declaration. */
7433 if (virtualp && current_class_name == NULL_TREE)
7435 error ("virtual outside class declaration");
7438 if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
7440 error ("only members can be declared mutable");
7441 RIDBIT_RESET (RID_MUTABLE, specbits);
7444 /* Static anonymous unions are dealt with here. */
7445 if (staticp && decl_context == TYPENAME
7446 && TREE_CODE (declspecs) == TREE_LIST
7447 && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
7448 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
7449 decl_context = FIELD;
7451 /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
7452 is used in a signature member function declaration. */
7453 if (decl_context == FIELD
7454 && IS_SIGNATURE (current_class_type)
7455 && RIDBIT_NOTSETP(RID_TYPEDEF, specbits)
7456 && !SIGNATURE_GROKKING_TYPEDEF (current_class_type))
7460 error ("`const' specified for signature member function `%s'", name);
7465 error ("`volatile' specified for signature member function `%s'", name);
7470 error ("`inline' specified for signature member function `%s'", name);
7471 /* Later, we'll make signature member functions inline. */
7476 error ("`friend' declaration in signature definition");
7481 error ("`virtual' specified for signature member function `%s'", name);
7482 /* Later, we'll make signature member functions virtual. */
7487 /* Warn about storage classes that are invalid for certain
7488 kinds of declarations (parameters, typenames, etc.). */
7491 error ("multiple storage classes in declaration of `%s'", name);
7492 else if (decl_context != NORMAL && nclasses > 0)
7494 if (decl_context == PARM
7495 && (RIDBIT_SETP (RID_REGISTER, specbits)
7496 || RIDBIT_SETP (RID_AUTO, specbits)))
7498 else if (decl_context == FIELD
7499 && RIDBIT_SETP (RID_TYPEDEF, specbits))
7501 /* Processing a typedef declaration nested within a class type
7503 register tree scanner;
7504 register tree previous_declspec;
7508 error ("typedef declaration includes an initializer");
7510 /* To process a class-local typedef declaration, we descend down
7511 the chain of declspecs looking for the `typedef' spec. When we
7512 find it, we splice it out of the chain of declspecs, and then
7513 recursively call `grokdeclarator' with the original declarator
7514 and with the newly adjusted declspecs. This call should return
7515 a FIELD_DECL node with the TREE_TYPE (and other parts) set
7516 appropriately. We can then just change the TREE_CODE on that
7517 from FIELD_DECL to TYPE_DECL and we're done. */
7519 for (previous_declspec = NULL_TREE, scanner = declspecs;
7521 previous_declspec = scanner, scanner = TREE_CHAIN (scanner))
7523 if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF])
7526 if (previous_declspec)
7527 TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner);
7529 declspecs = TREE_CHAIN (scanner);
7531 /* In the recursive call to grokdeclarator we need to know
7532 whether we are working on a signature-local typedef. */
7533 if (IS_SIGNATURE (current_class_type))
7534 SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1;
7537 grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE);
7539 if (loc_typedecl != error_mark_node)
7541 register int i = sizeof (struct lang_decl_flags) / sizeof (int);
7544 TREE_SET_CODE (loc_typedecl, TYPE_DECL);
7546 pi = (int *) permalloc (sizeof (struct lang_decl_flags));
7549 DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
7552 if (IS_SIGNATURE (current_class_type))
7554 SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0;
7555 if (loc_typedecl != error_mark_node && opaque_typedef)
7556 SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
7559 return loc_typedecl;
7561 else if (decl_context == FIELD
7562 && (! IS_SIGNATURE (current_class_type))
7563 /* C++ allows static class elements */
7564 && RIDBIT_SETP (RID_STATIC, specbits))
7565 /* C++ also allows inlines and signed and unsigned elements,
7566 but in those cases we don't come in here. */
7570 if (decl_context == FIELD)
7572 tree tmp = TREE_OPERAND (declarator, 0);
7573 register int op = IDENTIFIER_OPNAME_P (tmp);
7574 error ("storage class specified for %s `%s'",
7575 IS_SIGNATURE (current_class_type)
7577 ? "signature member operator"
7578 : "signature member function")
7579 : (op ? "member operator" : "structure field"),
7580 op ? operator_name_string (tmp) : name);
7583 error ((decl_context == PARM
7584 ? "storage class specified for parameter `%s'"
7585 : "storage class specified for typename"), name);
7586 RIDBIT_RESET (RID_REGISTER, specbits);
7587 RIDBIT_RESET (RID_AUTO, specbits);
7588 RIDBIT_RESET (RID_EXTERN, specbits);
7590 if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
7592 RIDBIT_RESET (RID_STATIC, specbits);
7597 else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
7599 if (current_binding_level == global_binding_level)
7601 /* It's common practice (and completely legal) to have a const
7602 be initialized and declared extern. */
7604 warning ("`%s' initialized and declared `extern'", name);
7607 error ("`%s' has both `extern' and initializer", name);
7609 else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
7610 && current_binding_level != global_binding_level)
7611 error ("nested function `%s' declared `extern'", name);
7612 else if (current_binding_level == global_binding_level)
7614 if (RIDBIT_SETP (RID_AUTO, specbits))
7615 error ("top-level declaration of `%s' specifies `auto'", name);
7617 if (RIDBIT_SETP (RID_REGISTER, specbits))
7618 error ("top-level declaration of `%s' specifies `register'", name);
7621 /* I'm not sure under what circumstances we should turn
7622 on the extern bit, and under what circumstances we should
7623 warn if other bits are turned on. */
7624 if (decl_context == NORMAL
7625 && RIDBIT_NOSETP (RID_EXTERN, specbits)
7626 && ! root_lang_context_p ())
7628 RIDBIT_SET (RID_EXTERN, specbits);
7633 /* Now figure out the structure of the declarator proper.
7634 Descend through it, creating more complex types, until we reach
7635 the declared identifier (or NULL_TREE, in an absolute declarator). */
7637 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
7639 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
7640 an INDIRECT_REF (for *...),
7641 a CALL_EXPR (for ...(...)),
7642 an identifier (for the name being declared)
7643 or a null pointer (for the place in an absolute declarator
7644 where the name was omitted).
7645 For the last two cases, we have just exited the loop.
7647 For C++ it could also be
7648 a SCOPE_REF (for class :: ...). In this case, we have converted
7649 sensible names to types, and those are the values we use to
7650 qualify the member name.
7651 an ADDR_EXPR (for &...),
7652 a BIT_NOT_EXPR (for destructors)
7653 a TYPE_EXPR (for operator typenames)
7655 At this point, TYPE is the type of elements of an array,
7656 or for a function to return, or for a pointer to point to.
7657 After this sequence of ifs, TYPE is the type of the
7658 array or function or pointer, and DECLARATOR has had its
7659 outermost layer removed. */
7661 if (TREE_CODE (type) == ERROR_MARK)
7663 if (TREE_CODE (declarator) == SCOPE_REF)
7664 declarator = TREE_OPERAND (declarator, 1);
7666 declarator = TREE_OPERAND (declarator, 0);
7669 if (quals != NULL_TREE
7670 && (declarator == NULL_TREE
7671 || TREE_CODE (declarator) != SCOPE_REF))
7673 if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
7674 ctype = TYPE_METHOD_BASETYPE (type);
7675 if (ctype != NULL_TREE)
7677 #if 0 /* not yet, should get fixed properly later */
7678 tree dummy = make_type_decl (NULL_TREE, type);
7680 tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
7682 ctype = grok_method_quals (ctype, dummy, quals);
7683 type = TREE_TYPE (dummy);
7687 switch (TREE_CODE (declarator))
7691 register tree itype = NULL_TREE;
7692 register tree size = TREE_OPERAND (declarator, 1);
7694 declarator = TREE_OPERAND (declarator, 0);
7696 /* Check for some types that there cannot be arrays of. */
7698 if (TYPE_MAIN_VARIANT (type) == void_type_node)
7700 cp_error ("declaration of `%D' as array of voids", dname);
7701 type = error_mark_node;
7704 if (TREE_CODE (type) == FUNCTION_TYPE)
7706 cp_error ("declaration of `%D' as array of functions", dname);
7707 type = error_mark_node;
7710 /* ARM $8.4.3: Since you can't have a pointer to a reference,
7711 you can't have arrays of references. If we allowed them,
7712 then we'd be saying x[i] is legal for an array x, but
7713 then you'd have to ask: what does `*(x + i)' mean? */
7714 if (TREE_CODE (type) == REFERENCE_TYPE)
7716 if (decl_context == TYPENAME)
7717 cp_error ("cannot make arrays of references");
7719 cp_error ("declaration of `%D' as array of references",
7721 type = error_mark_node;
7724 if (TREE_CODE (type) == OFFSET_TYPE)
7726 cp_error ("declaration of `%D' as array of data members",
7728 type = error_mark_node;
7731 if (TREE_CODE (type) == METHOD_TYPE)
7733 cp_error ("declaration of `%D' as array of function members",
7735 type = error_mark_node;
7738 if (size == error_mark_node)
7739 type = error_mark_node;
7741 if (type == error_mark_node)
7746 /* Must suspend_momentary here because the index
7747 type may need to live until the end of the function.
7748 For example, it is used in the declaration of a
7749 variable which requires destructing at the end of
7750 the function; then build_vec_delete will need this
7752 int yes = suspend_momentary ();
7753 /* might be a cast */
7754 if (TREE_CODE (size) == NOP_EXPR
7755 && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
7756 size = TREE_OPERAND (size, 0);
7758 /* If this is a template parameter, it'll be constant, but
7759 we don't know what the value is yet. */
7760 if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
7761 goto dont_grok_size;
7763 if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
7764 && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
7766 cp_error ("size of array `%D' has non-integer type",
7768 size = integer_one_node;
7770 if (TREE_READONLY_DECL_P (size))
7771 size = decl_constant_value (size);
7772 if (pedantic && integer_zerop (size))
7773 cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
7774 if (TREE_CONSTANT (size))
7776 constant_expression_warning (size);
7777 if (INT_CST_LT (size, integer_zero_node))
7779 cp_error ("size of array `%D' is negative", dname);
7780 size = integer_one_node;
7782 itype = build_index_type (size_binop (MINUS_EXPR, size,
7788 cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", dname);
7791 build_binary_op (MINUS_EXPR, size, integer_one_node, 1);
7792 /* Make sure the array size remains visibly nonconstant
7793 even if it is (eg) a const variable with known value. */
7795 itype = variable_size (itype);
7796 itype = build_index_type (itype);
7798 resume_momentary (yes);
7801 /* Build the array type itself, then merge any constancy or
7802 volatility into the target type. We must do it in this order
7803 to ensure that the TYPE_MAIN_VARIANT field of the array type
7804 is set correctly. */
7806 type = build_cplus_array_type (type, itype);
7807 if (constp || volatilep)
7808 /* Should this be c_build_type_variant? -jason */
7809 type = build_type_variant (type, constp, volatilep);
7819 /* Declaring a function type.
7820 Make sure we have a valid type for the function to return. */
7822 /* Is this an error? Should they be merged into TYPE here? */
7823 if (pedantic && (constp || volatilep))
7824 pedwarn ("function declared to return const or volatile result");
7826 /* Merge any constancy or volatility into the target type
7829 if (constp || volatilep)
7831 type = build_type_variant (type, constp, volatilep);
7832 if (IS_AGGR_TYPE (type))
7833 build_pointer_type (type);
7839 /* Warn about some types functions can't return. */
7841 if (TREE_CODE (type) == FUNCTION_TYPE)
7843 error ("`%s' declared as function returning a function", name);
7844 type = integer_type_node;
7846 if (TREE_CODE (type) == ARRAY_TYPE)
7848 error ("`%s' declared as function returning an array", name);
7849 type = integer_type_node;
7852 if (ctype == NULL_TREE
7853 && decl_context == FIELD
7854 && (friendp == 0 || dname == current_class_name))
7855 ctype = current_class_type;
7857 if (ctype && flags == TYPENAME_FLAG)
7858 TYPE_HAS_CONVERSION (ctype) = 1;
7859 if (ctype && constructor_name (ctype) == dname)
7861 /* We are within a class's scope. If our declarator name
7862 is the same as the class name, and we are defining
7863 a function, then it is a constructor/destructor, and
7864 therefore returns a void type. */
7866 if (flags == DTOR_FLAG)
7868 /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may
7869 not be declared const or volatile. A destructor
7870 may not be static. */
7872 error ("destructor cannot be static member function");
7873 if (TYPE_READONLY (type))
7875 error ("destructors cannot be declared `const'");
7876 return void_type_node;
7878 if (TYPE_VOLATILE (type))
7880 error ("destructors cannot be declared `volatile'");
7881 return void_type_node;
7883 if (decl_context == FIELD)
7885 if (! member_function_or_else (ctype, current_class_type,
7886 "destructor for alien class `%s' cannot be a member"))
7887 return void_type_node;
7890 else /* it's a constructor. */
7892 /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may
7893 not be declared const or volatile. A constructor may
7894 not be virtual. A constructor may not be static. */
7896 error ("constructor cannot be static member function");
7899 pedwarn ("constructors cannot be declared virtual");
7902 if (TYPE_READONLY (type))
7904 error ("constructors cannot be declared `const'");
7905 return void_type_node;
7907 if (TYPE_VOLATILE (type))
7909 error ("constructors cannot be declared `volatile'");
7910 return void_type_node;
7913 int inlinep, staticp;
7914 inlinep = RIDBIT_SETP (RID_INLINE, specbits);
7915 staticp = RIDBIT_SETP (RID_STATIC, specbits);
7916 RIDBIT_RESET (RID_INLINE, specbits);
7917 RIDBIT_RESET (RID_STATIC, specbits);
7918 if (RIDBIT_ANY_SET (specbits))
7919 error ("return value type specifier for constructor ignored");
7921 RIDBIT_SET (RID_INLINE, specbits);
7923 RIDBIT_SET (RID_STATIC, specbits);
7925 type = TYPE_POINTER_TO (ctype);
7926 if (decl_context == FIELD &&
7927 IS_SIGNATURE (current_class_type))
7929 error ("constructor not allowed in signature");
7930 return void_type_node;
7932 else if (decl_context == FIELD)
7934 if (! member_function_or_else (ctype, current_class_type,
7935 "constructor for alien class `%s' cannot be member"))
7936 return void_type_node;
7937 TYPE_HAS_CONSTRUCTOR (ctype) = 1;
7938 if (return_type != return_ctor)
7942 if (decl_context == FIELD)
7945 else if (friendp && virtualp)
7947 /* Cannot be both friend and virtual. */
7948 error ("virtual functions cannot be friends");
7949 RIDBIT_RESET (RID_FRIEND, specbits);
7953 if (decl_context == NORMAL && friendp)
7954 error ("friend declaration not in class definition");
7956 /* Pick up type qualifiers which should be applied to `this'. */
7957 quals = TREE_OPERAND (declarator, 2);
7959 /* Traditionally, declaring return type float means double. */
7961 if (flag_traditional
7962 && TYPE_MAIN_VARIANT (type) == float_type_node)
7964 type = build_type_variant (double_type_node,
7965 TYPE_READONLY (type),
7966 TYPE_VOLATILE (type));
7969 /* Construct the function type and go to the next
7970 inner layer of declarator. */
7974 tree inner_parms = TREE_OPERAND (declarator, 1);
7975 tree inner_decl = TREE_OPERAND (declarator, 0);
7977 declarator = TREE_OPERAND (declarator, 0);
7979 if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
7980 inner_decl = TREE_OPERAND (inner_decl, 1);
7982 /* Say it's a definition only for the CALL_EXPR
7983 closest to the identifier. */
7986 (TREE_CODE (inner_decl) == IDENTIFIER_NODE
7987 || TREE_CODE (inner_decl) == TYPE_EXPR)) ? funcdef_flag : 0;
7989 /* FIXME: This is where default args should be fully
7992 arg_types = grokparms (inner_parms, funcdef_p);
7997 /* Get past destructors, etc.
7998 We know we have one because FLAGS will be non-zero.
8000 Complain about improper parameter lists here. */
8001 if (TREE_CODE (declarator) == BIT_NOT_EXPR)
8003 declarator = TREE_OPERAND (declarator, 0);
8005 if (strict_prototype == 0 && arg_types == NULL_TREE)
8006 arg_types = void_list_node;
8007 else if (arg_types == NULL_TREE
8008 || arg_types != void_list_node)
8010 error ("destructors cannot be specified with parameters");
8011 arg_types = void_list_node;
8016 /* ANSI seems to say that `const int foo ();'
8017 does not make the function foo const. */
8018 type = build_function_type (type,
8019 flag_traditional ? 0 : arg_types);
8025 /* Filter out pointers-to-references and references-to-references.
8026 We can get these if a TYPE_DECL is used. */
8028 if (TREE_CODE (type) == REFERENCE_TYPE)
8030 error ("cannot declare %s to references",
8031 TREE_CODE (declarator) == ADDR_EXPR
8032 ? "references" : "pointers");
8033 declarator = TREE_OPERAND (declarator, 0);
8037 /* Merge any constancy or volatility into the target type
8040 if (constp || volatilep)
8042 /* A const or volatile signature pointer/reference is
8043 pointing to a const or volatile object, i.e., the
8044 `optr' is const or volatile, respectively, not the
8045 signature pointer/reference itself. */
8046 if (! IS_SIGNATURE (type))
8048 type = build_type_variant (type, constp, volatilep);
8049 if (IS_AGGR_TYPE (type))
8050 build_pointer_type (type);
8056 if (IS_SIGNATURE (type))
8058 if (TREE_CODE (declarator) == ADDR_EXPR)
8060 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE)
8061 warning ("empty signature `%s' used in signature reference declaration",
8062 TYPE_NAME_STRING(type));
8064 type = build_signature_reference_type (type,
8067 sorry ("signature reference");
8073 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE)
8074 warning ("empty signature `%s' used in signature pointer declaration",
8075 TYPE_NAME_STRING(type));
8076 type = build_signature_pointer_type (type,
8082 else if (TREE_CODE (declarator) == ADDR_EXPR)
8084 if (TREE_CODE (type) == FUNCTION_TYPE)
8086 error ("cannot declare references to functions; use pointer to function instead");
8087 type = build_pointer_type (type);
8091 if (TYPE_MAIN_VARIANT (type) == void_type_node)
8092 error ("invalid type: `void &'");
8094 type = build_reference_type (type);
8097 else if (TREE_CODE (type) == METHOD_TYPE)
8099 type = build_ptrmemfunc_type (build_pointer_type (type));
8102 type = build_pointer_type (type);
8104 /* Process a list of type modifier keywords (such as
8105 const or volatile) that were given inside the `*' or `&'. */
8107 if (TREE_TYPE (declarator))
8109 register tree typemodlist;
8111 for (typemodlist = TREE_TYPE (declarator); typemodlist;
8112 typemodlist = TREE_CHAIN (typemodlist))
8114 if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
8116 else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
8121 error ("invalid type modifier within %s declarator",
8122 TREE_CODE (declarator) == ADDR_EXPR
8123 ? "reference" : "pointer");
8127 warning ("duplicate `const'");
8129 warning ("duplicate `volatile'");
8131 declarator = TREE_OPERAND (declarator, 0);
8137 /* We have converted type names to NULL_TREE if the
8138 name was bogus, or to a _TYPE node, if not.
8140 The variable CTYPE holds the type we will ultimately
8141 resolve to. The code here just needs to build
8142 up appropriate member types. */
8143 tree sname = TREE_OPERAND (declarator, 1);
8144 /* Destructors can have their visibilities changed as well. */
8145 if (TREE_CODE (sname) == BIT_NOT_EXPR)
8146 sname = TREE_OPERAND (sname, 0);
8148 if (TREE_COMPLEXITY (declarator) == 0)
8149 /* This needs to be here, in case we are called
8150 multiple times. */ ;
8151 else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
8152 /* don't fall out into global scope. Hides real bug? --eichin */ ;
8153 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
8155 /* I'm not really sure what pushclass calls this popclass
8156 corresponds to. One is in build_push_scope and that has
8157 been changed to a push_nested_class call, that's why I
8158 try to use pop_nested_class here instead.
8160 pop_nested_class (1);
8161 TREE_COMPLEXITY (declarator) = current_class_depth;
8164 my_friendly_abort (16);
8166 if (TREE_OPERAND (declarator, 0) == NULL_TREE)
8168 /* We had a reference to a global decl, or
8169 perhaps we were given a non-aggregate typedef,
8170 in which case we cleared this out, and should just
8171 keep going as though it wasn't there. */
8175 ctype = TREE_OPERAND (declarator, 0);
8177 if (sname == NULL_TREE)
8180 if (TREE_CODE (sname) == IDENTIFIER_NODE)
8182 /* This is the `standard' use of the scoping operator:
8183 basetype :: member . */
8185 if (TREE_CODE (type) == FUNCTION_TYPE)
8187 if (current_class_type == NULL_TREE
8188 || TYPE_MAIN_VARIANT (ctype) == current_class_type
8190 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8191 TREE_TYPE (type), TYPE_ARG_TYPES (type));
8194 error ("cannot declare member function `%s::%s' within this class",
8195 TYPE_NAME_STRING (ctype), name);
8196 return void_type_node;
8199 else if (TYPE_MAIN_VARIANT (ctype) == current_class_type)
8202 warning ("extra qualification `%s' on member `%s' ignored",
8203 TYPE_NAME_STRING (ctype), name);
8204 type = build_offset_type (ctype, type);
8206 else if (TYPE_SIZE (ctype) != NULL_TREE
8207 || (RIDBIT_SETP (RID_TYPEDEF, specbits)))
8210 /* have to move this code elsewhere in this function.
8211 this code is used for i.e., typedef int A::M; M *pm; */
8213 if (explicit_int == -1 && decl_context == FIELD
8214 && funcdef_flag == 0)
8216 /* The code in here should only be used to build
8217 stuff that will be grokked as access decls. */
8218 t = lookup_field (ctype, sname, 0, 0);
8221 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
8222 DECL_INITIAL (t) = init;
8225 /* No such field, try member functions. */
8226 t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
8229 if (flags == DTOR_FLAG)
8231 else if (CLASSTYPE_METHOD_VEC (ctype)
8232 && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
8234 /* Don't include destructor with constructors. */
8235 t = DECL_CHAIN (TREE_VALUE (t));
8237 error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname));
8238 t = build_tree_list (NULL_TREE, t);
8240 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
8241 DECL_INITIAL (t) = init;
8245 if (flags == TYPENAME_FLAG)
8246 cp_error ("type conversion is not a member of structure `%T'", ctype);
8249 ("field `%D' is not a member of structure `%T'",
8253 if (current_class_type)
8255 if (TYPE_MAIN_VARIANT (ctype) != current_class_type)
8257 cp_error ("cannot declare member `%T::%s' within `%T'",
8258 ctype, name, current_class_type);
8259 return void_type_node;
8261 else if (extra_warnings)
8262 cp_warning ("extra qualification `%T' on member `%s' ignored",
8265 type = build_offset_type (ctype, type);
8267 else if (uses_template_parms (ctype))
8270 if (TREE_CODE (type) == FUNCTION_TYPE)
8272 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8274 TYPE_ARG_TYPES (type));
8280 cp_error ("structure `%T' not yet defined", ctype);
8281 return error_mark_node;
8286 else if (TREE_CODE (sname) == TYPE_EXPR)
8288 /* A TYPE_EXPR will change types out from under us.
8289 So do the TYPE_EXPR now, and make this SCOPE_REF
8290 inner to the TYPE_EXPR's CALL_EXPR.
8292 This does not work if we don't get a CALL_EXPR back.
8293 I did not think about error recovery, hence the
8294 my_friendly_abort. */
8296 /* Get the CALL_EXPR. */
8297 sname = grokoptypename (sname, 0);
8298 my_friendly_assert (TREE_CODE (sname) == CALL_EXPR, 157);
8299 type = TREE_TYPE (TREE_OPERAND (sname, 0));
8300 /* Scope the CALL_EXPR's name. */
8301 TREE_OPERAND (declarator, 1) = TREE_OPERAND (sname, 0);
8302 /* Put the SCOPE_EXPR in the CALL_EXPR's innermost position. */
8303 TREE_OPERAND (sname, 0) = declarator;
8304 /* Now work from the CALL_EXPR. */
8308 else if (TREE_CODE (sname) == SCOPE_REF)
8309 my_friendly_abort (17);
8313 declarator = TREE_OPERAND (declarator, 1);
8314 if (declarator && TREE_CODE (declarator) == CALL_EXPR)
8315 /* In this case, we will deal with it later. */
8319 if (TREE_CODE (type) == FUNCTION_TYPE)
8320 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
8322 type = build_offset_type (ctype, type);
8329 declarator = TREE_OPERAND (declarator, 0);
8333 declarator = grokoptypename (declarator, 0);
8334 if (explicit_int != -1)
8336 tree stype = TREE_TYPE (TREE_OPERAND (declarator, 0));
8337 if (comp_target_types (type, stype, 1) == 0)
8338 cp_error ("`operator %T' declared to return `%T'", stype,
8341 cp_pedwarn ("return type specified for `operator %T'", type);
8344 type = TREE_TYPE (TREE_OPERAND (declarator, 0));
8350 declarator = NULL_TREE;
8354 declarator = NULL_TREE;
8358 my_friendly_abort (158);
8362 /* Now TYPE has the actual type. */
8364 /* If this is declaring a typedef name, return a TYPE_DECL. */
8366 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8370 /* Note that the grammar rejects storage classes
8371 in typenames, fields or parameters. */
8372 if (constp || volatilep)
8373 type = build_type_variant (type, constp, volatilep);
8375 /* If the user declares "struct {...} foo" then `foo' will have
8376 an anonymous name. Fill that name in now. Nothing can
8377 refer to it, so nothing needs know about the name change.
8378 The TYPE_NAME field was filled in by build_struct_xref. */
8379 if (type != error_mark_node
8381 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8382 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
8384 /* replace the anonymous name with the real name everywhere. */
8385 lookup_tag_reverse (type, declarator);
8386 TYPE_IDENTIFIER (type) = declarator;
8388 if (TYPE_LANG_SPECIFIC (type))
8389 TYPE_WAS_ANONYMOUS (type) = 1;
8392 tree d = TYPE_NAME (type), c = DECL_CONTEXT (d);
8395 set_nested_typename (d, 0, declarator, type);
8396 else if (TREE_CODE (c) == FUNCTION_DECL)
8397 set_nested_typename (d, DECL_ASSEMBLER_NAME (c),
8400 set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type);
8404 #if 0 /* not yet, should get fixed properly later */
8405 decl = make_type_decl (declarator, type);
8407 decl = build_decl (TYPE_DECL, declarator, type);
8409 if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
8411 cp_error_at ("typedef name may not be class-qualified", decl);
8412 TREE_TYPE (decl) = error_mark_node;
8416 if (ctype == NULL_TREE)
8418 if (TREE_CODE (type) != METHOD_TYPE)
8419 cp_error_at ("invalid type qualifier for non-method type", decl);
8421 ctype = TYPE_METHOD_BASETYPE (type);
8423 if (ctype != NULL_TREE)
8424 grok_method_quals (ctype, decl, quals);
8427 if (RIDBIT_SETP (RID_SIGNED, specbits)
8428 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
8429 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
8431 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8433 error ("non-object member `%s' cannot be declared mutable", name);
8439 /* Detect the case of an array type of unspecified size
8440 which came, as such, direct from a typedef name.
8441 We must copy the type, so that each identifier gets
8442 a distinct type, so that each identifier's size can be
8443 controlled separately by its own initializer. */
8445 if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
8446 && TYPE_DOMAIN (type) == NULL_TREE)
8448 type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
8451 /* If this is a type name (such as, in a cast or sizeof),
8452 compute the type and return it now. */
8454 if (decl_context == TYPENAME)
8456 /* Note that the grammar rejects storage classes
8457 in typenames, fields or parameters. */
8458 if (constp || volatilep)
8459 if (IS_SIGNATURE (type))
8460 error ("`const' or `volatile' specified with signature type");
8462 type = build_type_variant (type, constp, volatilep);
8464 /* Special case: "friend class foo" looks like a TYPENAME context. */
8467 /* A friendly class? */
8468 if (current_class_type)
8469 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
8471 error("trying to make class `%s' a friend of global scope",
8472 TYPE_NAME_STRING (type));
8473 type = void_type_node;
8477 #if 0 /* not yet, should get fixed properly later */
8478 tree dummy = make_type_decl (declarator, type);
8480 tree dummy = build_decl (TYPE_DECL, declarator, type);
8482 if (ctype == NULL_TREE)
8484 my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
8485 ctype = TYPE_METHOD_BASETYPE (type);
8487 grok_method_quals (ctype, dummy, quals);
8488 type = TREE_TYPE (dummy);
8493 else if (declarator == NULL_TREE && decl_context != PARM
8494 && TREE_CODE (type) != UNION_TYPE
8497 cp_error ("abstract declarator `%T' used as declaration", type);
8498 declarator = make_anon_name ();
8501 /* `void' at top level (not within pointer)
8502 is allowed only in typedefs or type names.
8503 We don't complain about parms either, but that is because
8504 a better error message can be made later. */
8506 if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
8508 if (TREE_CODE (declarator) == IDENTIFIER_NODE)
8510 if (IDENTIFIER_OPNAME_P (declarator))
8511 #if 0 /* How could this happen? */
8512 error ("operator `%s' declared void",
8513 operator_name_string (declarator));
8515 my_friendly_abort (356);
8518 error ("variable or field `%s' declared void", name);
8521 error ("variable or field declared void");
8522 type = integer_type_node;
8525 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
8526 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
8531 if (decl_context == PARM)
8533 tree parmtype = type;
8536 error ("cannot use `::' in parameter declaration");
8538 /* A parameter declared as an array of T is really a pointer to T.
8539 One declared as a function is really a pointer to a function.
8540 One declared as a member is really a pointer to member.
8542 Don't be misled by references. */
8544 if (TREE_CODE (type) == REFERENCE_TYPE)
8545 type = TREE_TYPE (type);
8547 if (TREE_CODE (type) == ARRAY_TYPE)
8549 if (parmtype == type)
8551 /* Transfer const-ness of array into that of type
8553 type = build_pointer_type
8554 (build_type_variant (TREE_TYPE (type), constp, volatilep));
8555 volatilep = constp = 0;
8558 type = build_pointer_type (TREE_TYPE (type));
8560 else if (TREE_CODE (type) == FUNCTION_TYPE)
8561 type = build_pointer_type (type);
8562 else if (TREE_CODE (type) == OFFSET_TYPE)
8563 type = build_pointer_type (type);
8565 if (TREE_CODE (parmtype) == REFERENCE_TYPE)
8567 /* Transfer const-ness of reference into that of type pointed to. */
8568 type = build_type_variant (build_reference_type (type), constp, volatilep);
8569 constp = volatilep = 0;
8572 decl = build_decl (PARM_DECL, declarator, type);
8574 bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
8575 inlinep, friendp, raises != NULL_TREE);
8576 if (current_class_type
8577 && IS_SIGNATURE (current_class_type))
8580 error ("parameter of signature member function declared `inline'");
8581 if (RIDBIT_SETP (RID_AUTO, specbits))
8582 error ("parameter of signature member function declared `auto'");
8583 if (RIDBIT_SETP (RID_REGISTER, specbits))
8584 error ("parameter of signature member function declared `register'");
8587 /* Compute the type actually passed in the parmlist,
8588 for the case where there is no prototype.
8589 (For example, shorts and chars are passed as ints.)
8590 When there is a prototype, this is overridden later. */
8592 DECL_ARG_TYPE (decl) = type;
8593 if (TYPE_MAIN_VARIANT (type) == float_type_node)
8594 DECL_ARG_TYPE (decl) = build_type_variant (double_type_node,
8595 TYPE_READONLY (type),
8596 TYPE_VOLATILE (type));
8597 else if (C_PROMOTING_INTEGER_TYPE_P (type))
8601 /* Retain unsignedness if traditional or if not really
8603 if (TREE_UNSIGNED (type)
8604 && (flag_traditional
8605 || TYPE_PRECISION (type)
8606 == TYPE_PRECISION (integer_type_node)))
8607 argtype = unsigned_type_node;
8609 argtype = integer_type_node;
8610 DECL_ARG_TYPE (decl) = build_type_variant (argtype,
8611 TYPE_READONLY (type),
8612 TYPE_VOLATILE (type));
8615 else if (decl_context == FIELD)
8617 if (type == error_mark_node)
8619 /* Happens when declaring arrays of sizes which
8620 are error_mark_node, for example. */
8623 else if (TREE_CODE (type) == FUNCTION_TYPE)
8629 if (ctype == NULL_TREE)
8630 ctype = current_class_type;
8632 if (ctype == NULL_TREE)
8634 cp_error ("can't make `%D' into a method -- not in a class",
8636 return void_type_node;
8639 /* ``A union may [ ... ] not [ have ] virtual functions.''
8641 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
8643 cp_error ("function `%D' declared virtual inside a union",
8645 return void_type_node;
8648 if (declarator == ansi_opname[(int) NEW_EXPR]
8649 || declarator == ansi_opname[(int) DELETE_EXPR])
8653 cp_error ("`%D' cannot be declared virtual, since it is always static",
8658 else if (staticp < 2)
8659 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8660 TREE_TYPE (type), TYPE_ARG_TYPES (type));
8663 /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
8664 publicp = (RIDBIT_SETP (RID_EXTERN, specbits)
8665 || (ctype != NULL_TREE && funcdef_flag >= 0)
8668 && RIDBIT_NOTSETP (RID_STATIC, specbits)
8669 && RIDBIT_NOTSETP (RID_INLINE, specbits)));
8670 decl = grokfndecl (ctype, type, declarator,
8671 virtualp, flags, quals,
8672 raises, friendp ? -1 : 0, publicp);
8673 DECL_INLINE (decl) = inlinep;
8675 else if (TREE_CODE (type) == METHOD_TYPE)
8677 /* All method decls are public, so tell grokfndecl to set
8678 TREE_PUBLIC, also. */
8679 decl = grokfndecl (ctype, type, declarator,
8680 virtualp, flags, quals,
8681 raises, friendp ? -1 : 0, 1);
8682 DECL_INLINE (decl) = inlinep;
8684 else if (TREE_CODE (type) == RECORD_TYPE
8685 && CLASSTYPE_DECLARED_EXCEPTION (type))
8687 /* Handle a class-local exception declaration. */
8688 decl = build_lang_field_decl (VAR_DECL, declarator, type);
8689 if (ctype == NULL_TREE)
8690 ctype = current_class_type;
8691 finish_exception_decl (TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
8692 ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype), decl);
8693 return void_type_node;
8695 else if (TYPE_SIZE (type) == NULL_TREE && !staticp
8696 && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
8698 error ("field `%s' has incomplete type",
8699 IDENTIFIER_POINTER (declarator));
8701 /* If we're instantiating a template, tell them which
8702 instantiation made the field's type be incomplete. */
8703 if (current_class_type
8704 && TYPE_NAME (current_class_type)
8705 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type)))
8706 && declspecs && TREE_VALUE (declspecs)
8707 && TREE_TYPE (TREE_VALUE (declspecs)) == type)
8708 error (" in instantiation of template `%s'",
8709 TYPE_NAME_STRING (current_class_type));
8711 type = error_mark_node;
8718 error ("`%s' is neither function nor method; cannot be declared friend",
8719 IDENTIFIER_POINTER (declarator));
8727 /* Friends are treated specially. */
8728 if (ctype == current_class_type)
8729 warning ("member functions are implicitly friends of their class");
8733 if (decl && DECL_NAME (decl))
8734 t = do_friend (ctype, declarator, decl,
8735 last_function_parms, flags, quals);
8736 if (t && funcdef_flag)
8739 return void_type_node;
8743 /* Structure field. It may not be a function, except for C++ */
8745 if (decl == NULL_TREE)
8747 /* ANSI C++ June 5 1992 WP 9.2.2 and 9.4.2. A member-declarator
8748 cannot have an initializer, and a static member declaration must
8749 be defined elsewhere. */
8753 error ("static member `%s' must be defined separately from its declaration",
8754 IDENTIFIER_POINTER (declarator));
8755 /* Note that initialization of const members is prohibited
8756 by the draft ANSI standard, though it appears to be in
8757 common practice. 12.6.2: The argument list is used to
8758 initialize the named nonstatic member.... This (or an
8759 aggregate) is the only way to initialize nonstatic const
8760 and reference members. */
8762 pedwarn ("ANSI C++ forbids initialization of %s `%s'",
8763 constp ? "const member" : "member",
8764 IDENTIFIER_POINTER (declarator));
8767 if (staticp || (constp && initialized))
8769 /* C++ allows static class members.
8770 All other work for this is done by grokfield.
8771 This VAR_DECL is built by build_lang_field_decl.
8772 All other VAR_DECLs are built by build_decl. */
8773 decl = build_lang_field_decl (VAR_DECL, declarator, type);
8774 if (staticp || TREE_CODE (type) == ARRAY_TYPE)
8775 TREE_STATIC (decl) = 1;
8776 /* In class context, static means public access. */
8777 TREE_PUBLIC (decl) = 1;
8778 DECL_EXTERNAL (decl) = !initialized;
8782 decl = build_lang_field_decl (FIELD_DECL, declarator, type);
8783 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8785 DECL_MUTABLE_P (decl) = 1;
8786 RIDBIT_RESET (RID_MUTABLE, specbits);
8790 bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
8791 inlinep, friendp, raises != NULL_TREE);
8794 else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
8796 int was_overloaded = 0;
8797 tree original_name = declarator;
8803 if (RIDBIT_SETP (RID_AUTO, specbits)
8804 || RIDBIT_SETP (RID_REGISTER, specbits))
8805 error ("invalid storage class for function `%s'", name);
8807 /* Function declaration not at top level.
8808 Storage classes other than `extern' are not allowed
8809 and `extern' makes no difference. */
8810 if (current_binding_level != global_binding_level
8811 && (RIDBIT_SETP (RID_STATIC, specbits) || RIDBIT_SETP (RID_INLINE, specbits))
8813 pedwarn ("invalid storage class for function `%s'", name);
8815 if (ctype == NULL_TREE)
8819 error ("virtual non-class function `%s'", name);
8823 if (current_lang_name == lang_name_cplusplus
8824 && ! (IDENTIFIER_LENGTH (original_name) == 4
8825 && IDENTIFIER_POINTER (original_name)[0] == 'm'
8826 && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
8827 && ! (IDENTIFIER_LENGTH (original_name) > 10
8828 && IDENTIFIER_POINTER (original_name)[0] == '_'
8829 && IDENTIFIER_POINTER (original_name)[1] == '_'
8830 && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
8832 /* Plain overloading: will not be grok'd by grokclassfn. */
8833 declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
8837 else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
8838 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
8839 TREE_TYPE (type), TYPE_ARG_TYPES (type));
8841 /* Record presence of `static'. In C++, `inline' is like `static'.
8842 Methods of classes should be public, unless we're dropping them
8843 into some other file, so we don't clear TREE_PUBLIC for them. */
8846 && CLASSTYPE_INTERFACE_KNOWN (ctype)
8847 && ! CLASSTYPE_INTERFACE_ONLY (ctype))
8848 || !(RIDBIT_SETP (RID_STATIC, specbits)
8849 || RIDBIT_SETP (RID_INLINE, specbits)));
8851 decl = grokfndecl (ctype, type, original_name,
8852 virtualp, flags, quals,
8854 processing_template_decl ? 0 : friendp ? 2 : 1,
8857 if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
8858 DECL_ASSEMBLER_NAME (decl) = declarator;
8862 int illegal_static = 0;
8864 /* Don't allow a static member function in a class, and forbid
8865 declaring main to be static. */
8866 if (TREE_CODE (type) == METHOD_TYPE)
8868 cp_error_at ("cannot declare member function `%D' to have static linkage", decl);
8871 else if (! was_overloaded
8873 && IDENTIFIER_LENGTH (original_name) == 4
8874 && IDENTIFIER_POINTER (original_name)[0] == 'm'
8875 && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
8877 error ("cannot declare function `main' to have static linkage");
8880 else if (current_function_decl)
8882 /* FIXME need arm citation */
8883 error ("cannot declare static function inside another function");
8890 RIDBIT_RESET (RID_STATIC, specbits);
8894 /* Record presence of `inline', if it is reasonable. */
8897 tree last = tree_last (TYPE_ARG_TYPES (type));
8899 if (! was_overloaded
8901 && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
8902 error ("cannot inline function `main'");
8903 else if (last && last != void_list_node)
8904 cp_warning ("cannot inline function `%D' which takes `...'", original_name);
8906 /* Assume that otherwise the function can be inlined. */
8907 DECL_INLINE (decl) = 1;
8909 if (RIDBIT_SETP (RID_EXTERN, specbits))
8911 current_extern_inline = 1;
8912 if (flag_ansi || pedantic || flag_pedantic_errors)
8913 pedwarn ("ANSI C++ does not permit `extern inline'");
8917 DECL_OVERLOADED (decl) = 1;
8921 /* It's a variable. */
8923 /* An uninitialized decl with `extern' is a reference. */
8924 decl = grokvardecl (type, declarator, specbits, initialized);
8925 bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
8926 inlinep, friendp, raises != NULL_TREE);
8932 cp_error ("static member `%D' re-declared as static",
8935 RIDBIT_RESET (RID_STATIC, specbits);
8937 if (RIDBIT_SETP (RID_EXTERN, specbits))
8939 cp_error ("cannot explicitly declare member `%#D' to have extern linkage",
8941 RIDBIT_RESET (RID_EXTERN, specbits);
8946 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8948 error ("`%s' cannot be declared mutable", name);
8951 /* Record `register' declaration for warnings on &
8952 and in case doing stupid register allocation. */
8954 if (RIDBIT_SETP (RID_REGISTER, specbits))
8955 DECL_REGISTER (decl) = 1;
8957 /* Record constancy and volatility. */
8960 TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
8963 TREE_SIDE_EFFECTS (decl) = 1;
8964 TREE_THIS_VOLATILE (decl) = 1;
8971 /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
8972 An empty exprlist is a parmlist. An exprlist which
8973 contains only identifiers at the global level
8974 is a parmlist. Otherwise, it is an exprlist. */
8976 parmlist_is_exprlist (exprs)
8979 if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
8982 if (current_binding_level == global_binding_level)
8984 /* At the global level, if these are all identifiers,
8985 then it is a parmlist. */
8988 if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
8990 exprs = TREE_CHAIN (exprs);
8997 /* Subroutine of `grokparms'. In a fcn definition, arg types must
9000 C++: also subroutine of `start_function'. */
9002 require_complete_types_for_parms (parms)
9007 tree type = TREE_TYPE (parms);
9008 if (TYPE_SIZE (type) == NULL_TREE)
9010 if (DECL_NAME (parms))
9011 error ("parameter `%s' has incomplete type",
9012 IDENTIFIER_POINTER (DECL_NAME (parms)));
9014 error ("parameter has incomplete type");
9015 TREE_TYPE (parms) = error_mark_node;
9018 /* If the arg types are incomplete in a declaration,
9019 they must include undefined tags.
9020 These tags can never be defined in the scope of the declaration,
9021 so the types can never be completed,
9022 and no call can be compiled successfully. */
9023 /* This is not the right behavior for C++, but not having
9024 it is also probably wrong. */
9027 /* Now warn if is a pointer to an incomplete type. */
9028 while (TREE_CODE (type) == POINTER_TYPE
9029 || TREE_CODE (type) == REFERENCE_TYPE)
9030 type = TREE_TYPE (type);
9031 type = TYPE_MAIN_VARIANT (type);
9032 if (TYPE_SIZE (type) == NULL_TREE)
9034 if (DECL_NAME (parm) != NULL_TREE)
9035 warning ("parameter `%s' points to incomplete type",
9036 IDENTIFIER_POINTER (DECL_NAME (parm)));
9038 warning ("parameter points to incomplete type");
9042 parms = TREE_CHAIN (parms);
9046 /* Decode the list of parameter types for a function type.
9047 Given the list of things declared inside the parens,
9048 return a list of types.
9050 The list we receive can have three kinds of elements:
9051 an IDENTIFIER_NODE for names given without types,
9052 a TREE_LIST node for arguments given as typespecs or names with typespecs,
9053 or void_type_node, to mark the end of an argument list
9054 when additional arguments are not permitted (... was not used).
9056 FUNCDEF_FLAG is nonzero for a function definition, 0 for
9057 a mere declaration. A nonempty identifier-list gets an error message
9058 when FUNCDEF_FLAG is zero.
9059 If FUNCDEF_FLAG is 1, then parameter types must be complete.
9060 If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
9062 If all elements of the input list contain types,
9063 we return a list of the types.
9064 If all elements contain no type (except perhaps a void_type_node
9065 at the end), we return a null list.
9066 If some have types and some do not, it is an error, and we
9069 Also set last_function_parms to either
9070 a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
9071 A list of names is converted to a chain of PARM_DECLs
9072 by store_parm_decls so that ultimately it is always a chain of decls.
9074 Note that in C++, parameters can take default values. These default
9075 values are in the TREE_PURPOSE field of the TREE_LIST. It is
9076 an error to specify default values which are followed by parameters
9077 that have no default values, or an ELLIPSES. For simplicities sake,
9078 only parameters which are specified with their types can take on
9082 grokparms (first_parm, funcdef_flag)
9086 tree result = NULL_TREE;
9087 tree decls = NULL_TREE;
9089 if (first_parm != NULL_TREE
9090 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
9093 pedwarn ("parameter names (without types) in function declaration");
9094 last_function_parms = first_parm;
9097 else if (first_parm != NULL_TREE
9098 && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
9099 && TREE_VALUE (first_parm) != void_type_node)
9100 my_friendly_abort (145);
9103 /* Types were specified. This is a list of declarators
9104 each represented as a TREE_LIST node. */
9105 register tree parm, chain;
9106 int any_init = 0, any_error = 0, saw_void = 0;
9108 if (first_parm != NULL_TREE)
9110 tree last_result = NULL_TREE;
9111 tree last_decl = NULL_TREE;
9113 for (parm = first_parm; parm != NULL_TREE; parm = chain)
9115 tree type, list_node = parm;
9116 register tree decl = TREE_VALUE (parm);
9117 tree init = TREE_PURPOSE (parm);
9119 chain = TREE_CHAIN (parm);
9120 /* @@ weak defense against parse errors. */
9121 if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
9123 /* Give various messages as the need arises. */
9124 if (TREE_CODE (decl) == STRING_CST)
9125 error ("invalid string constant `%s'",
9126 TREE_STRING_POINTER (decl));
9127 else if (TREE_CODE (decl) == INTEGER_CST)
9128 error ("invalid integer constant in parameter list, did you forget to give parameter name?");
9132 if (decl != void_type_node)
9134 /* @@ May need to fetch out a `raises' here. */
9135 decl = grokdeclarator (TREE_VALUE (decl),
9136 TREE_PURPOSE (decl),
9137 PARM, init != NULL_TREE, NULL_TREE);
9140 type = TREE_TYPE (decl);
9141 if (TYPE_MAIN_VARIANT (type) == void_type_node)
9142 decl = void_type_node;
9143 else if (TREE_CODE (type) == METHOD_TYPE)
9145 if (DECL_NAME (decl))
9146 /* Cannot use `error_with_decl' here because
9147 we don't have DECL_CONTEXT set up yet. */
9148 error ("parameter `%s' invalidly declared method type",
9149 IDENTIFIER_POINTER (DECL_NAME (decl)));
9151 error ("parameter invalidly declared method type");
9152 type = build_pointer_type (type);
9153 TREE_TYPE (decl) = type;
9155 else if (TREE_CODE (type) == OFFSET_TYPE)
9157 if (DECL_NAME (decl))
9158 error ("parameter `%s' invalidly declared offset type",
9159 IDENTIFIER_POINTER (DECL_NAME (decl)));
9161 error ("parameter invalidly declared offset type");
9162 type = build_pointer_type (type);
9163 TREE_TYPE (decl) = type;
9165 else if (TREE_CODE (type) == RECORD_TYPE
9166 && TYPE_LANG_SPECIFIC (type)
9167 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
9169 abstract_virtuals_error (decl, type);
9170 any_error = 1; /* seems like a good idea */
9172 else if (TREE_CODE (type) == RECORD_TYPE
9173 && TYPE_LANG_SPECIFIC (type)
9174 && IS_SIGNATURE (type))
9176 signature_error (decl, type);
9177 any_error = 1; /* seems like a good idea */
9181 if (decl == void_type_node)
9183 if (result == NULL_TREE)
9185 result = void_list_node;
9186 last_result = result;
9190 TREE_CHAIN (last_result) = void_list_node;
9191 last_result = void_list_node;
9195 && (chain != void_list_node || TREE_CHAIN (chain)))
9196 error ("`void' in parameter list must be entire list");
9200 /* Since there is a prototype, args are passed in their own types. */
9201 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
9202 #ifdef PROMOTE_PROTOTYPES
9203 if ((TREE_CODE (type) == INTEGER_TYPE
9204 || TREE_CODE (type) == ENUMERAL_TYPE)
9205 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
9206 DECL_ARG_TYPE (decl) = integer_type_node;
9213 if (TREE_CODE (init) == SAVE_EXPR)
9214 PARM_DECL_EXPR (init) = 1;
9215 else if (TREE_CODE (init) == VAR_DECL)
9217 if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
9219 /* ``Local variables may not be used in default
9220 argument expressions.'' dpANSI C++ 8.2.6 */
9221 /* If extern int i; within a function is not
9222 considered a local variable, then this code is
9224 cp_error ("local variable `%D' may not be used as a default argument", init);
9227 else if (TREE_READONLY_DECL_P (init))
9228 init = decl_constant_value (init);
9231 init = require_instantiated_type (type, init, integer_zero_node);
9235 error ("all trailing parameters must have default arguments");
9242 if (decls == NULL_TREE)
9249 TREE_CHAIN (last_decl) = decl;
9252 if (TREE_PERMANENT (list_node))
9254 TREE_PURPOSE (list_node) = init;
9255 TREE_VALUE (list_node) = type;
9256 TREE_CHAIN (list_node) = NULL_TREE;
9259 list_node = saveable_tree_cons (init, type, NULL_TREE);
9260 if (result == NULL_TREE)
9263 last_result = result;
9267 TREE_CHAIN (last_result) = list_node;
9268 last_result = list_node;
9272 TREE_CHAIN (last_result) = NULL_TREE;
9273 /* If there are no parameters, and the function does not end
9274 with `...', then last_decl will be NULL_TREE. */
9275 if (last_decl != NULL_TREE)
9276 TREE_CHAIN (last_decl) = NULL_TREE;
9280 last_function_parms = decls;
9282 /* In a fcn definition, arg types must be complete. */
9283 if (funcdef_flag > 0)
9284 require_complete_types_for_parms (last_function_parms);
9289 /* These memoizing functions keep track of special properties which
9290 a class may have. `grok_ctor_properties' notices whether a class
9291 has a constructor of the form X(X&), and also complains
9292 if the class has a constructor of the form X(X).
9293 `grok_op_properties' takes notice of the various forms of
9294 operator= which are defined, as well as what sorts of type conversion
9295 may apply. Both functions take a FUNCTION_DECL as an argument. */
9297 grok_ctor_properties (ctype, decl)
9300 tree parmtypes = FUNCTION_ARG_CHAIN (decl);
9301 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
9303 /* When a type has virtual baseclasses, a magical first int argument is
9304 added to any ctor so we can tell if the class has been initialized
9305 yet. This could screw things up in this function, so we deliberately
9306 ignore the leading int if we're in that situation. */
9308 && TREE_VALUE (parmtypes) == integer_type_node
9309 && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
9311 parmtypes = TREE_CHAIN (parmtypes);
9312 parmtype = TREE_VALUE (parmtypes);
9315 if (TREE_CODE (parmtype) == REFERENCE_TYPE
9316 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
9318 if (TREE_CHAIN (parmtypes) == NULL_TREE
9319 || TREE_CHAIN (parmtypes) == void_list_node
9320 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
9322 TYPE_HAS_INIT_REF (ctype) = 1;
9323 if (TYPE_READONLY (TREE_TYPE (parmtype)))
9324 TYPE_HAS_CONST_INIT_REF (ctype) = 1;
9327 TYPE_GETS_INIT_AGGR (ctype) = 1;
9329 else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
9331 if (TREE_CHAIN (parmtypes) != NULL_TREE
9332 && TREE_CHAIN (parmtypes) == void_list_node)
9333 cp_error ("invalid constructor; you probably meant `%T (%T&)'",
9335 SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
9336 TYPE_GETS_INIT_AGGR (ctype) = 1;
9338 else if (TREE_CODE (parmtype) == VOID_TYPE
9339 || TREE_PURPOSE (parmtypes) != NULL_TREE)
9340 TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
9343 /* An operator with this name can be either unary or binary. */
9344 int ambi_op_p (name)
9347 return (name == ansi_opname [(int) INDIRECT_REF]
9348 || name == ansi_opname [(int) ADDR_EXPR]
9349 || name == ansi_opname [(int) NEGATE_EXPR]
9350 || name == ansi_opname[(int) POSTINCREMENT_EXPR]
9351 || name == ansi_opname[(int) POSTDECREMENT_EXPR]
9352 || name == ansi_opname [(int) CONVERT_EXPR]);
9355 /* An operator with this name can only be unary. */
9356 int unary_op_p (name)
9359 return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
9360 || name == ansi_opname [(int) BIT_NOT_EXPR]
9361 || name == ansi_opname [(int) COMPONENT_REF]
9362 || OPERATOR_TYPENAME_P (name));
9365 /* Do a little sanity-checking on how they declared their operator. */
9367 grok_op_properties (decl, virtualp, friendp)
9369 int virtualp, friendp;
9371 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
9372 int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
9373 tree name = DECL_NAME (decl);
9377 for (t = current_class_type; t; t = TYPE_NEXT_VARIANT (t))
9379 if (name == ansi_opname[(int) MODIFY_EXPR])
9380 TYPE_HAS_ASSIGNMENT (t) = 1;
9381 else if (name == ansi_opname[(int) CALL_EXPR])
9382 TYPE_OVERLOADS_CALL_EXPR (t) = 1;
9383 else if (name == ansi_opname[(int) ARRAY_REF])
9384 TYPE_OVERLOADS_ARRAY_REF (t) = 1;
9385 else if (name == ansi_opname[(int) COMPONENT_REF]
9386 || name == ansi_opname[(int) MEMBER_REF])
9387 TYPE_OVERLOADS_ARROW (t) = 1;
9388 else if (name == ansi_opname[(int) NEW_EXPR])
9390 if (TREE_CHAIN (argtypes) == void_list_node)
9391 TREE_GETS_NEW (t) = 1;
9393 TREE_GETS_PLACED_NEW (t) = 1;
9395 else if (name == ansi_opname[(int) DELETE_EXPR])
9396 TREE_GETS_DELETE (t) = 1;
9398 else if (name == ansi_opname[(int) VEC_NEW_EXPR])
9399 TREE_GETS_NEW (t) = 1;
9400 else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
9401 TREE_GETS_DELETE (t) = 1;
9405 if (name == ansi_opname[(int) NEW_EXPR])
9408 /* When the compiler encounters the definition of A::operator new, it
9409 doesn't look at the class declaration to find out if it's static. */
9410 my_friendly_assert (!methodp, 355);
9413 /* Take care of function decl if we had syntax errors. */
9414 if (argtypes == NULL_TREE)
9416 build_function_type (ptr_type_node,
9417 hash_tree_chain (integer_type_node,
9420 decl = coerce_new_type (TREE_TYPE (decl));
9423 else if (name == ansi_opname[(int) VEC_NEW_EXPR])
9427 else if (name == ansi_opname[(int) DELETE_EXPR])
9430 my_friendly_assert (!methodp, 355);
9433 if (argtypes == NULL_TREE)
9435 build_function_type (void_type_node,
9436 hash_tree_chain (ptr_type_node,
9439 decl = coerce_delete_type (TREE_TYPE (decl));
9442 else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
9448 /* An operator function must either be a non-static member function
9449 or have at least one parameter of a class, a reference to a class,
9450 an enumeration, or a reference to an enumeration. 13.4.0.6 */
9453 if (OPERATOR_TYPENAME_P (name)
9454 || name == ansi_opname[(int) CALL_EXPR]
9455 || name == ansi_opname[(int) MODIFY_EXPR]
9456 || name == ansi_opname[(int) COMPONENT_REF]
9457 || name == ansi_opname[(int) ARRAY_REF])
9458 cp_error ("`%D' must be a nonstatic member function", decl);
9464 for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
9466 tree arg = TREE_VALUE (p);
9467 if (TREE_CODE (arg) == REFERENCE_TYPE)
9468 arg = TREE_TYPE (arg);
9470 /* This lets bad template code slip through. */
9471 if (IS_AGGR_TYPE (arg)
9472 || TREE_CODE (arg) == ENUMERAL_TYPE
9473 || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
9477 ("`%D' must have an argument of class or enumerated type",
9484 if (name == ansi_opname[(int) CALL_EXPR]
9485 || name == ansi_opname[(int) METHOD_CALL_EXPR])
9486 return; /* no restrictions on args */
9488 if (name == ansi_opname[(int) MODIFY_EXPR])
9492 if (list_length (argtypes) != 3 && methodp)
9494 cp_error ("`%D' must take exactly one argument", decl);
9497 parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
9499 if (TREE_CODE (parmtype) == REFERENCE_TYPE
9500 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype))
9501 == current_class_type)
9503 TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
9504 if (TYPE_READONLY (TREE_TYPE (parmtype)))
9505 TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
9508 else if (name == ansi_opname[(int) COND_EXPR])
9511 pedwarn ("ANSI C++ prohibits overloading operator ?:");
9512 if (list_length (argtypes) != 4)
9513 cp_error ("`%D' must take exactly three arguments", decl);
9515 else if (ambi_op_p (name))
9517 if (list_length (argtypes) == 2)
9519 else if (list_length (argtypes) == 3)
9521 if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
9522 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
9523 && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
9526 cp_error ("postfix `%D' must take `int' as its argument",
9530 ("postfix `%D' must take `int' as its second argument",
9537 cp_error ("`%D' must take either zero or one argument", decl);
9539 cp_error ("`%D' must take either one or two arguments", decl);
9542 else if (unary_op_p (name))
9544 if (list_length (argtypes) != 2)
9547 cp_error ("`%D' must take `void'", decl);
9549 cp_error ("`%D' must take exactly one argument", decl);
9552 else /* if (binary_op_p (name)) */
9554 if (list_length (argtypes) != 3)
9557 cp_error ("`%D' must take exactly one argument", decl);
9559 cp_error ("`%D' must take exactly two arguments", decl);
9565 for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
9566 if (TREE_PURPOSE (argtypes))
9568 TREE_PURPOSE (argtypes) = NULL_TREE;
9569 if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
9570 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
9573 cp_pedwarn ("`%D' cannot have default arguments", decl);
9576 cp_error ("`%D' cannot have default arguments", decl);
9581 /* Get the struct, enum or union (CODE says which) with tag NAME.
9582 Define the tag as a forward-reference if it is not defined.
9584 C++: If a class derivation is given, process it here, and report
9585 an error if multiple derivation declarations are not identical.
9587 If this is a definition, come in through xref_tag and only look in
9588 the current frame for the name (since C++ allows new names in any
9591 /* avoid rewriting all callers of xref_tag */
9592 static int xref_next_defn = 0;
9595 xref_defn_tag (code_type_node, name, binfo)
9596 tree code_type_node;
9602 if (class_binding_level)
9606 /* we need to build a new IDENTIFIER_NODE for name which nukes
9609 n1 = IDENTIFIER_LOCAL_VALUE (current_class_name);
9611 n1 = DECL_NAME (n1);
9613 n1 = current_class_name;
9615 n1 = TYPE_NAME(current_class_type);
9617 n1 = DECL_NESTED_TYPENAME(n1);
9619 n1 = current_class_name;
9621 buf = (char *) alloca (4 + IDENTIFIER_LENGTH (n1)
9622 + IDENTIFIER_LENGTH (name));
9624 sprintf (buf, "%s::%s", IDENTIFIER_POINTER (n1),
9625 IDENTIFIER_POINTER (name));
9626 ncp = get_identifier (buf);
9629 printf("*** %s ***\n", IDENTIFIER_POINTER (ncp));
9632 IDENTIFIER_LOCAL_VALUE (name) =
9633 build_lang_decl (TYPE_DECL, ncp, NULL_TREE);
9635 rv = xref_tag (code_type_node, name, binfo, 0);
9636 if (! ANON_AGGRNAME_P (name))
9638 register tree type_decl = build_lang_decl (TYPE_DECL, ncp, rv);
9639 #ifdef DWARF_DEBUGGING_INFO
9640 /* Mark the TYPE_DECL node created just above as a gratuitous one
9641 so that dwarfout.c will know not to generate a TAG_typedef DIE
9643 if (write_symbols == DWARF_DEBUG)
9644 DECL_IGNORED_P (type_decl) = 1;
9645 #endif /* DWARF_DEBUGGING_INFO */
9646 pushdecl_top_level (type_decl);
9651 rv = xref_tag (code_type_node, name, binfo, 0);
9658 xref_tag (code_type_node, name, binfo, globalize)
9659 tree code_type_node;
9663 enum tag_types tag_code;
9664 enum tree_code code;
9667 register tree ref, t;
9668 struct binding_level *b = inner_binding_level;
9670 tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
9675 case exception_type:
9676 case signature_type:
9678 len = list_length (binfo);
9684 cp_error ("derived union `%T' invalid", name);
9690 code = ENUMERAL_TYPE;
9693 my_friendly_abort (18);
9696 /* If a cross reference is requested, look up the type
9697 already defined for this tag and return it. */
9698 if (t = IDENTIFIER_TYPE_VALUE(name))
9700 if (TREE_CODE(t) != code) t = NULL_TREE;
9704 /* If we know we are defining this tag, only look it up in this scope
9705 * and don't try to find it as a type. */
9707 if (t && TYPE_CONTEXT(t) && strstr(IDENTIFIER_POINTER(name), "::"))
9710 ref = lookup_tag (code, name, b, 1);
9717 ref = lookup_tag (code, name, b, 0);
9721 /* Try finding it as a type declaration. If that wins, use it. */
9722 ref = lookup_name (name, 1);
9723 if (ref && TREE_CODE (ref) == TYPE_DECL
9724 && TREE_CODE (TREE_TYPE (ref)) == code)
9725 ref = TREE_TYPE (ref);
9731 push_obstacks_nochange ();
9735 /* If no such tag is yet defined, create a forward-reference node
9736 and record it as the "definition".
9737 When a real declaration of this type is found,
9738 the forward-reference will be altered into a real type. */
9740 /* In C++, since these migrate into the global scope, we must
9741 build them on the permanent obstack. */
9743 temp = allocation_temporary_p ();
9745 end_temporary_allocation ();
9747 if (code == ENUMERAL_TYPE)
9749 ref = make_node (ENUMERAL_TYPE);
9751 /* Give the type a default layout like unsigned int
9752 to avoid crashing if it does not get defined. */
9753 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
9754 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
9755 TREE_UNSIGNED (ref) = 1;
9756 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
9757 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
9758 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
9760 /* Enable us to recognize when a type is created in class context.
9761 To do nested classes correctly, this should probably be cleared
9762 out when we leave this classes scope. Currently this in only
9763 done in `start_enum'. */
9765 pushtag (name, ref, globalize);
9767 cadillac_start_enum (ref);
9769 else if (tag_code == exception_type)
9771 ref = make_lang_type (code);
9772 /* Enable us to recognize when an exception type is created in
9773 class context. To do nested classes correctly, this should
9774 probably be cleared out when we leave this class's scope. */
9775 CLASSTYPE_DECLARED_EXCEPTION (ref) = 1;
9776 pushtag (name, ref, globalize);
9778 cadillac_start_struct (ref);
9782 extern tree pending_vtables;
9783 struct binding_level *old_b = class_binding_level;
9786 ref = make_lang_type (code);
9788 /* A signature type will contain the fields of the signature
9789 table. Therefore, it's not only an interface. */
9790 if (tag_code == signature_type)
9792 SET_SIGNATURE (ref);
9793 CLASSTYPE_INTERFACE_ONLY (ref) = 0;
9794 CLASSTYPE_INTERFACE_UNKNOWN (ref) = 0;
9797 /* Record how to set the access of this class's
9798 virtual functions. If write_virtuals == 2 or 3, then
9799 inline virtuals are ``extern inline''. */
9800 switch (write_virtuals)
9807 needs_writing = !! value_member (name, pending_vtables);
9810 needs_writing = ! CLASSTYPE_INTERFACE_ONLY (ref)
9811 && CLASSTYPE_INTERFACE_KNOWN (ref);
9817 /* Signatures don't have a vtable. As long as we don't have default
9818 implementations, they behave as if `write_virtuals' were 3. */
9819 if (tag_code == signature_type)
9820 CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
9822 CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing;
9824 #ifdef NONNESTED_CLASSES
9825 /* Class types don't nest the way enums do. */
9826 class_binding_level = (struct binding_level *)0;
9828 pushtag (name, ref, globalize);
9829 class_binding_level = old_b;
9832 cadillac_start_struct (ref);
9837 if (IS_AGGR_TYPE_CODE (code))
9839 if (IS_AGGR_TYPE (ref)
9840 && ((tag_code == exception_type)
9841 != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1)))
9843 cp_error ("type `%T' is both exception and aggregate type", ref);
9844 CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type);
9848 /* If it no longer looks like a nested type, make sure it's
9850 if (b == global_binding_level && !class_binding_level
9851 && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
9852 IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
9857 tree tt2 = TYPE_BINFO_BASETYPES (ref);
9859 if (TYPE_BINFO_BASETYPES (ref))
9860 for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
9861 if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
9863 cp_error ("redeclaration of derivation chain of type `%#T'",
9868 if (tt1 == NULL_TREE)
9869 /* The user told us something we already knew. */
9872 /* In C++, since these migrate into the global scope, we must
9873 build them on the permanent obstack. */
9874 end_temporary_allocation ();
9880 /* In the declaration `A : X, Y, ... Z' we mark all the types
9881 (A, X, Y, ..., Z) so we can check for duplicates. */
9884 SET_CLASSTYPE_MARKED (ref);
9885 BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
9887 for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
9889 /* The base of a derived struct is public by default. */
9891 = (TREE_PURPOSE (binfo) == (tree)access_public
9892 || TREE_PURPOSE (binfo) == (tree)access_public_virtual
9893 || (tag_code != class_type
9894 && (TREE_PURPOSE (binfo) == (tree)access_default
9895 || TREE_PURPOSE (binfo) == (tree)access_default_virtual)));
9896 int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected;
9898 = (TREE_PURPOSE (binfo) == (tree)access_private_virtual
9899 || TREE_PURPOSE (binfo) == (tree)access_public_virtual
9900 || TREE_PURPOSE (binfo) == (tree)access_default_virtual);
9901 tree basetype = TREE_TYPE (TREE_VALUE (binfo));
9904 GNU_xref_hier (IDENTIFIER_POINTER (name),
9905 IDENTIFIER_POINTER (TREE_VALUE (binfo)),
9906 via_public, via_virtual, 0);
9908 if (basetype && TREE_CODE (basetype) == TYPE_DECL)
9909 basetype = TREE_TYPE (basetype);
9910 if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
9912 error ("base type `%s' fails to be a struct or class type",
9913 IDENTIFIER_POINTER (TREE_VALUE (binfo)));
9917 /* This code replaces similar code in layout_basetypes. */
9918 else if (TYPE_SIZE (basetype) == NULL_TREE)
9920 cp_error ("base class `%T' has incomplete type", basetype);
9926 if (CLASSTYPE_MARKED (basetype))
9928 if (basetype == ref)
9929 cp_error ("recursive type `%T' undefined", basetype);
9931 cp_error ("duplicate base type `%T' invalid", basetype);
9935 /* Note that the BINFO records which describe individual
9936 inheritances are *not* shared in the lattice! They
9937 cannot be shared because a given baseclass may be
9938 inherited with different `accessibility' by different
9939 derived classes. (Each BINFO record describing an
9940 individual inheritance contains flags which say what
9941 the `accessibility' of that particular inheritance is.) */
9943 base_binfo = make_binfo (integer_zero_node, basetype,
9944 TYPE_BINFO_VTABLE (basetype),
9945 TYPE_BINFO_VIRTUALS (basetype), 0);
9947 TREE_VEC_ELT (binfos, i) = base_binfo;
9948 TREE_VIA_PUBLIC (base_binfo) = via_public;
9949 TREE_VIA_PROTECTED (base_binfo) = via_protected;
9950 TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
9952 SET_CLASSTYPE_MARKED (basetype);
9954 /* XYZZY TEST VIRTUAL BASECLASSES */
9955 if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE
9956 && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
9957 && via_virtual == 0)
9959 warning ("making type `%s' a virtual baseclass",
9960 TYPE_NAME_STRING (basetype));
9964 /* We are free to modify these bits because they are meaningless
9965 at top level, and BASETYPE is a top-level type. */
9966 if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
9968 TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
9969 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
9972 TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
9973 TREE_GETS_NEW (ref) |= TREE_GETS_NEW (basetype);
9974 TREE_GETS_PLACED_NEW (ref) |= TREE_GETS_PLACED_NEW (basetype);
9975 TREE_GETS_DELETE (ref) |= TREE_GETS_DELETE (basetype);
9976 CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
9981 TREE_VEC_LENGTH (binfos) = i;
9983 BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
9986 TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
9988 TYPE_USES_MULTIPLE_INHERITANCE (ref)
9989 = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
9990 if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
9991 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
9993 /* Unmark all the types. */
9995 CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
9996 CLEAR_CLASSTYPE_MARKED (ref);
10001 /* Until the type is defined, tentatively accept whatever
10002 structure tag the user hands us. */
10003 if (TYPE_SIZE (ref) == NULL_TREE
10004 && ref != current_class_type
10005 /* Have to check this, in case we have contradictory tag info. */
10006 && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
10008 if (tag_code == class_type)
10009 CLASSTYPE_DECLARED_CLASS (ref) = 1;
10010 else if (tag_code == record_type || tag_code == signature_type)
10011 CLASSTYPE_DECLARED_CLASS (ref) = 0;
10019 static tree current_local_enum = NULL_TREE;
10021 /* Begin compiling the definition of an enumeration type.
10022 NAME is its name (or null if anonymous).
10023 Returns the type object, as yet incomplete.
10024 Also records info about it so that build_enumerator
10025 may be used to declare the individual values as they are read. */
10031 register tree enumtype = NULL_TREE;
10032 struct binding_level *b = inner_binding_level;
10034 /* If this is the real definition for a previous forward reference,
10035 fill in the contents in the same object that used to be the
10036 forward reference. */
10038 if (name != NULL_TREE)
10039 enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
10041 if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
10042 cp_error ("multiple definition of enum `%T'", enumtype);
10045 enumtype = make_node (ENUMERAL_TYPE);
10046 pushtag (name, enumtype, 0);
10049 if (current_class_type)
10050 TREE_ADDRESSABLE (b->tags) = 1;
10051 current_local_enum = NULL_TREE;
10053 if (TYPE_VALUES (enumtype) != NULL_TREE)
10054 /* Completely replace its old definition.
10055 The old enumerators remain defined, however. */
10056 TYPE_VALUES (enumtype) = NULL_TREE;
10058 /* Initially, set up this enum as like `int'
10059 so that we can create the enumerators' declarations and values.
10060 Later on, the precision of the type may be changed and
10061 it may be laid out again. */
10063 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
10064 TYPE_SIZE (enumtype) = NULL_TREE;
10065 fixup_unsigned_type (enumtype);
10067 /* We copy this value because enumerated type constants
10068 are really of the type of the enumerator, not integer_type_node. */
10069 enum_next_value = copy_node (integer_zero_node);
10071 GNU_xref_decl (current_function_decl, enumtype);
10075 /* After processing and defining all the values of an enumeration type,
10076 install their decls in the enumeration type and finish it off.
10077 ENUMTYPE is the type object and VALUES a list of name-value pairs.
10078 Returns ENUMTYPE. */
10081 finish_enum (enumtype, values)
10082 register tree enumtype, values;
10084 register tree pair, tem;
10085 register HOST_WIDE_INT maxvalue = 0;
10086 register HOST_WIDE_INT minvalue = 0;
10087 register HOST_WIDE_INT i;
10089 TYPE_VALUES (enumtype) = values;
10091 /* Calculate the maximum value of any enumerator in this type. */
10095 /* Speed up the main loop by performing some precalculations */
10097 HOST_WIDE_INT value = TREE_INT_CST_LOW (TREE_VALUE (values));
10098 TREE_TYPE (TREE_VALUE (values)) = enumtype;
10099 minvalue = maxvalue = value;
10101 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
10103 value = TREE_INT_CST_LOW (TREE_VALUE (pair));
10104 if (value > maxvalue)
10106 else if (value < minvalue)
10108 TREE_TYPE (TREE_VALUE (pair)) = enumtype;
10112 if (flag_short_enums)
10114 /* Determine the precision this type needs, lay it out, and define it. */
10116 for (i = maxvalue; i; i >>= 1)
10117 TYPE_PRECISION (enumtype)++;
10119 if (!TYPE_PRECISION (enumtype))
10120 TYPE_PRECISION (enumtype) = 1;
10122 /* Cancel the laying out previously done for the enum type,
10123 so that fixup_unsigned_type will do it over. */
10124 TYPE_SIZE (enumtype) = NULL_TREE;
10126 fixup_unsigned_type (enumtype);
10129 TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue;
10131 /* An enum can have some negative values; then it is signed. */
10134 TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue;
10135 TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1;
10136 TREE_UNSIGNED (enumtype) = 0;
10139 cadillac_finish_enum (enumtype);
10141 /* Fix up all variant types of this enum type. */
10142 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
10144 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
10145 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
10146 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
10147 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
10148 TYPE_MODE (tem) = TYPE_MODE (enumtype);
10149 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
10150 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
10151 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
10154 /* Finish debugging output for this type. */
10156 /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
10157 information should *not* be generated? I think not. */
10158 if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
10160 rest_of_type_compilation (enumtype, global_bindings_p ());
10165 /* Build and install a CONST_DECL for one value of the
10166 current enumeration type (one that was begun with start_enum).
10167 Return a tree-list containing the name and its value.
10168 Assignment of sequential values by default is handled here. */
10171 build_enumerator (name, value)
10175 /* Change this to zero if we find VALUE is not shareable. */
10178 /* Remove no-op casts from the value. */
10180 STRIP_TYPE_NOPS (value);
10182 /* Validate and default VALUE. */
10183 if (value != NULL_TREE)
10185 if (TREE_READONLY_DECL_P (value))
10187 value = decl_constant_value (value);
10191 if (TREE_CODE (value) == INTEGER_CST)
10193 value = default_conversion (value);
10194 constant_expression_warning (value);
10198 error ("enumerator value for `%s' not integer constant",
10199 IDENTIFIER_POINTER (name));
10204 /* The order of things is reversed here so that we
10205 can check for possible sharing of enum values,
10206 to keep that from happening. */
10207 /* Default based on previous value. */
10208 if (value == NULL_TREE)
10209 value = enum_next_value;
10211 /* Remove no-op casts from the value. */
10213 STRIP_TYPE_NOPS (value);
10215 /* Make up for hacks in cp-lex.c. */
10216 if (value == integer_zero_node)
10217 value = build_int_2 (0, 0);
10218 else if (value == integer_one_node)
10219 value = build_int_2 (1, 0);
10220 else if (TREE_CODE (value) == INTEGER_CST
10222 || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
10224 value = copy_node (value);
10225 TREE_TYPE (value) = integer_type_node;
10228 result = saveable_tree_cons (name, value, NULL_TREE);
10230 /* C++ associates enums with global, function, or class declarations. */
10232 /* There are a number of cases we need to be aware of here:
10233 current_class_type current_function_decl
10234 * global enums NULL NULL
10235 * fn-local enum NULL SET
10236 * class-local enum SET NULL
10237 * class->fn->enum SET SET
10238 * fn->class->enum SET SET
10240 Those last two make life interesting. If it's a fn-local enum which is
10241 itself inside a class, we need the enum to go into the fn's decls (our
10242 second case below). But if it's a class-local enum and the class itself
10243 is inside a function, we need that enum to go into the decls for the
10244 class. To achieve this last goal, we must see if, when both
10245 current_class_decl and current_function_decl are set, the class was
10246 declared inside that function. If so, we know to put the enum into
10247 the class's scope. */
10249 if ((current_class_type && ! current_function_decl)
10250 || (current_class_type && current_function_decl
10251 && TYPE_CONTEXT (current_class_type) == current_function_decl))
10253 /* This enum declaration is local to the class, so we must put
10254 it in that class's list of decls. */
10255 decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
10256 DECL_INITIAL (decl) = value;
10257 TREE_READONLY (decl) = 1;
10258 pushdecl_class_level (decl);
10259 TREE_CHAIN (decl) = current_local_enum;
10260 current_local_enum = decl;
10264 /* It's a global enum, or it's local to a function. (Note local to
10265 a function could mean local to a class method. */
10266 decl = build_decl (CONST_DECL, name, integer_type_node);
10267 DECL_INITIAL (decl) = value;
10270 GNU_xref_decl (current_function_decl, decl);
10273 /* Set basis for default for next value. */
10274 enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
10275 integer_one_node, PLUS_EXPR);
10276 if (enum_next_value == integer_one_node)
10277 enum_next_value = copy_node (enum_next_value);
10283 grok_enum_decls (type, decl)
10286 tree d = current_local_enum;
10288 if (d == NULL_TREE)
10293 TREE_TYPE (d) = type;
10294 if (TREE_CHAIN (d) == NULL_TREE)
10296 TREE_CHAIN (d) = decl;
10299 d = TREE_CHAIN (d);
10302 decl = current_local_enum;
10303 current_local_enum = NULL_TREE;
10308 /* Create the FUNCTION_DECL for a function definition.
10309 DECLSPECS and DECLARATOR are the parts of the declaration;
10310 they describe the function's name and the type it returns,
10311 but twisted together in a fashion that parallels the syntax of C.
10313 This function creates a binding context for the function body
10314 as well as setting up the FUNCTION_DECL in current_function_decl.
10316 Returns 1 on success. If the DECLARATOR is not suitable for a function
10317 (it defines a datum instead), we return 0, which tells
10318 yyparse to report a parse error.
10320 For C++, we must first check whether that datum makes any sense.
10321 For example, "class A local_a(1,2);" means that variable local_a
10322 is an aggregate of type A, which should have a constructor
10323 applied to it with the argument list [1, 2].
10325 @@ There is currently no way to retrieve the storage
10326 @@ allocated to FUNCTION (or all of its parms) if we return
10327 @@ something we had previously. */
10330 start_function (declspecs, declarator, raises, pre_parsed_p)
10331 tree declarator, declspecs, raises;
10334 extern tree EHS_decl;
10335 tree decl1, olddecl;
10336 tree ctype = NULL_TREE;
10339 extern int have_extern_spec;
10340 extern int used_extern_spec;
10341 int doing_friend = 0;
10343 if (flag_handle_exceptions && EHS_decl == NULL_TREE)
10344 init_exception_processing_1 ();
10346 /* Sanity check. */
10347 my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
10348 my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
10350 /* Assume, until we see it does. */
10351 current_function_returns_value = 0;
10352 current_function_returns_null = 0;
10353 warn_about_return_type = 0;
10354 current_extern_inline = 0;
10355 current_function_assigns_this = 0;
10356 current_function_just_assigned_this = 0;
10357 current_function_parms_stored = 0;
10358 original_result_rtx = NULL_RTX;
10359 current_function_obstack_index = 0;
10360 current_function_obstack_usage = 0;
10362 clear_temp_name ();
10364 /* This should only be done once on the top most decl. */
10365 if (have_extern_spec && !used_extern_spec)
10367 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
10368 used_extern_spec = 1;
10373 decl1 = declarator;
10375 if (! DECL_ARGUMENTS (decl1)
10376 && !DECL_STATIC_FUNCTION_P (decl1)
10377 && DECL_CONTEXT (decl1)
10378 && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))
10379 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))))
10381 cp_error ("redeclaration of `%#D'", decl1);
10382 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
10383 cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
10384 else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
10385 cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
10388 last_function_parms = DECL_ARGUMENTS (decl1);
10389 last_function_parm_tags = NULL_TREE;
10390 fntype = TREE_TYPE (decl1);
10391 if (TREE_CODE (fntype) == METHOD_TYPE)
10392 ctype = TYPE_METHOD_BASETYPE (fntype);
10394 /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a
10395 class is in the (lexical) scope of the class in which it is
10397 if (!ctype && DECL_FRIEND_P (decl1))
10399 ctype = DECL_CLASS_CONTEXT (decl1);
10401 /* CTYPE could be null here if we're dealing with a template;
10402 for example, `inline friend float foo()' inside a template
10403 will have no CTYPE set. */
10404 if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
10410 if ( !(DECL_VINDEX (decl1)
10411 && write_virtuals >= 2
10412 && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)))
10413 current_extern_inline = TREE_PUBLIC (decl1) && DECL_INLINE (decl1);
10415 raises = TYPE_RAISES_EXCEPTIONS (fntype);
10417 /* In a fcn definition, arg types must be complete. */
10418 require_complete_types_for_parms (last_function_parms);
10422 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises);
10423 /* If the declarator is not suitable for a function definition,
10424 cause a syntax error. */
10425 if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
10427 fntype = TREE_TYPE (decl1);
10429 restype = TREE_TYPE (fntype);
10430 if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
10431 && ! CLASSTYPE_GOT_SEMICOLON (restype))
10433 cp_error ("semicolon missing after declaration of `%#T'", restype);
10434 shadow_tag (build_tree_list (NULL_TREE, restype));
10435 CLASSTYPE_GOT_SEMICOLON (restype) = 1;
10436 if (TREE_CODE (fntype) == FUNCTION_TYPE)
10437 fntype = build_function_type (integer_type_node,
10438 TYPE_ARG_TYPES (fntype));
10440 fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
10442 TYPE_ARG_TYPES (fntype));
10443 TREE_TYPE (decl1) = fntype;
10446 if (TREE_CODE (fntype) == METHOD_TYPE)
10447 ctype = TYPE_METHOD_BASETYPE (fntype);
10448 else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
10449 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
10450 && DECL_CONTEXT (decl1) == NULL_TREE)
10452 /* If this doesn't return integer_type, complain. */
10453 if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
10455 warning ("return type for `main' changed to integer type");
10456 TREE_TYPE (decl1) = fntype = default_function_type;
10458 warn_about_return_type = 0;
10462 /* Warn if function was previously implicitly declared
10463 (but not if we warned then). */
10464 if (! warn_implicit
10465 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
10466 cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
10468 current_function_decl = decl1;
10471 cadillac_start_function (decl1);
10473 announce_function (decl1);
10475 if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE)
10477 if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
10478 error_with_aggr_type (TREE_TYPE (fntype),
10479 "return-type `%s' is an incomplete type");
10481 error ("return-type is an incomplete type");
10483 /* Make it return void instead, but don't change the
10484 type of the DECL_RESULT, in case we have a named return value. */
10487 = build_cplus_method_type (build_type_variant (ctype,
10488 TREE_READONLY (decl1),
10489 TREE_SIDE_EFFECTS (decl1)),
10491 FUNCTION_ARG_CHAIN (decl1));
10494 = build_function_type (void_type_node,
10495 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
10496 DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TREE_TYPE (fntype));
10499 if (warn_about_return_type)
10500 warning ("return-type defaults to `int'");
10502 /* Make the init_value nonzero so pushdecl knows this is not tentative.
10503 error_mark_node is replaced below (in poplevel) with the BLOCK. */
10504 DECL_INITIAL (decl1) = error_mark_node;
10506 /* Didn't get anything from C. */
10507 olddecl = NULL_TREE;
10509 /* This function exists in static storage.
10510 (This does not mean `static' in the C sense!) */
10511 TREE_STATIC (decl1) = 1;
10513 /* If this function belongs to an interface, it is public.
10514 If it belongs to someone else's interface, it is also external.
10515 It doesn't matter whether it's inline or not. */
10516 if (interface_unknown == 0)
10518 TREE_PUBLIC (decl1) = 1;
10519 DECL_EXTERNAL (decl1) = (interface_only
10520 || (DECL_INLINE (decl1)
10521 && ! flag_implement_inlines));
10524 /* This is a definition, not a reference.
10525 So normally clear DECL_EXTERNAL.
10526 However, `extern inline' acts like a declaration except for
10527 defining how to inline. So set DECL_EXTERNAL in that case. */
10528 DECL_EXTERNAL (decl1) = current_extern_inline;
10530 /* Now see if this is the implementation of a declared function. */
10531 if (ctype == NULL_TREE && current_lang_name == lang_name_cplusplus
10532 && !DECL_CONTEXT (decl1))
10534 olddecl = lookup_name_current_level (DECL_NAME (decl1));
10535 if (olddecl && TREE_CODE (olddecl) != FUNCTION_DECL)
10536 olddecl = NULL_TREE;
10537 if (olddecl && DECL_NAME (decl1) != DECL_NAME (olddecl))
10539 /* Collision between user and internal naming scheme. */
10540 olddecl = lookup_name_current_level (DECL_ASSEMBLER_NAME (decl1));
10541 if (olddecl == NULL_TREE)
10544 if (olddecl && olddecl != decl1
10545 && DECL_NAME (decl1) == DECL_NAME (olddecl))
10547 if (TREE_CODE (olddecl) == FUNCTION_DECL
10548 && decls_match (decl1, olddecl))
10550 olddecl = DECL_MAIN_VARIANT (olddecl);
10551 /* The following copy is needed to handle forcing a function's
10552 linkage to obey the linkage of the original decl. */
10553 DECL_ASSEMBLER_NAME (decl1) = DECL_ASSEMBLER_NAME (olddecl);
10554 DECL_OVERLOADED (decl1) = DECL_OVERLOADED (olddecl);
10555 if (! DECL_BUILT_IN (olddecl) && DECL_INITIAL (olddecl))
10556 redeclaration_error_message (decl1, olddecl);
10557 if (duplicate_decls (decl1, olddecl))
10560 olddecl = NULL_TREE;
10563 olddecl = NULL_TREE;
10567 /* Record the decl so that the function name is defined.
10568 If we already have a decl for this name, and it is a FUNCTION_DECL,
10569 use the old decl. */
10572 current_function_decl = olddecl;
10573 else if (pre_parsed_p == 0)
10575 current_function_decl = pushdecl (decl1);
10576 if (TREE_CODE (current_function_decl) == TREE_LIST)
10578 /* @@ revert to modified original declaration. */
10579 decl1 = DECL_MAIN_VARIANT (decl1);
10580 current_function_decl = decl1;
10584 decl1 = current_function_decl;
10585 DECL_MAIN_VARIANT (decl1) = decl1;
10587 fntype = TREE_TYPE (decl1);
10590 current_function_decl = decl1;
10592 if (DECL_OVERLOADED (decl1))
10593 decl1 = push_overloaded_decl (decl1, 1);
10595 if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
10597 if (TREE_CODE (fntype) == METHOD_TYPE)
10598 TREE_TYPE (decl1) = fntype
10599 = build_function_type (TREE_TYPE (fntype),
10600 TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
10601 last_function_parms = TREE_CHAIN (last_function_parms);
10602 DECL_ARGUMENTS (decl1) = last_function_parms;
10605 restype = TREE_TYPE (fntype);
10608 current_binding_level->parm_flag = 1;
10610 /* Save the parm names or decls from this function's declarator
10611 where store_parm_decls will find them. */
10612 current_function_parms = last_function_parms;
10613 current_function_parm_tags = last_function_parm_tags;
10615 GNU_xref_function (decl1, current_function_parms);
10617 make_function_rtl (decl1);
10621 push_nested_class (ctype, 1);
10623 /* If we're compiling a friend function, neither of the variables
10624 current_class_decl nor current_class_type will have values. */
10625 if (! doing_friend)
10627 /* We know that this was set up by `grokclassfn'.
10628 We do not wait until `store_parm_decls', since evil
10629 parse errors may never get us to that point. Here
10630 we keep the consistency between `current_class_type'
10631 and `current_class_decl'. */
10632 current_class_decl = last_function_parms;
10633 my_friendly_assert (current_class_decl != NULL_TREE
10634 && TREE_CODE (current_class_decl) == PARM_DECL, 162);
10635 if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
10637 tree variant = TREE_TYPE (TREE_TYPE (current_class_decl));
10638 if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE)
10640 /* Can't call build_indirect_ref here, because it has special
10641 logic to return C_C_D given this argument. */
10642 C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
10643 CLASSTYPE_INST_VAR (ctype) = C_C_D;
10647 C_C_D = CLASSTYPE_INST_VAR (ctype);
10648 /* `current_class_decl' is different for every
10649 function we compile. */
10650 TREE_OPERAND (C_C_D, 0) = current_class_decl;
10652 TREE_READONLY (C_C_D) = TYPE_READONLY (variant);
10653 TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant);
10654 TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant);
10657 C_C_D = current_class_decl;
10662 if (DECL_STATIC_FUNCTION_P (decl1))
10663 push_nested_class (DECL_CONTEXT (decl1), 2);
10665 push_memoized_context (0, 1);
10668 /* Allocate further tree nodes temporarily during compilation
10669 of this function only. Tiemann moved up here from bottom of fn. */
10670 temporary_allocation ();
10672 /* Promote the value to int before returning it. */
10673 if (C_PROMOTING_INTEGER_TYPE_P (restype))
10675 /* It retains unsignedness if traditional or if it isn't
10676 really getting wider. */
10677 if (TREE_UNSIGNED (restype)
10678 && (flag_traditional
10679 || TYPE_PRECISION (restype)
10680 == TYPE_PRECISION (integer_type_node)))
10681 restype = unsigned_type_node;
10683 restype = integer_type_node;
10685 if (DECL_RESULT (decl1) == NULL_TREE)
10686 DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, restype);
10688 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)))
10690 dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10691 ctor_label = NULL_TREE;
10695 dtor_label = NULL_TREE;
10696 if (DECL_CONSTRUCTOR_P (decl1))
10697 ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
10700 /* If this fcn was already referenced via a block-scope `extern' decl
10701 (or an implicit decl), propagate certain information about the usage. */
10702 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
10703 TREE_ADDRESSABLE (decl1) = 1;
10708 /* Store the parameter declarations into the current function declaration.
10709 This is called after parsing the parameter declarations, before
10710 digesting the body of the function.
10712 Also install to binding contour return value identifier, if any. */
10715 store_parm_decls ()
10717 register tree fndecl = current_function_decl;
10718 register tree parm;
10719 int parms_have_cleanups = 0;
10722 /* This is either a chain of PARM_DECLs (when a prototype is used). */
10723 tree specparms = current_function_parms;
10725 /* This is a list of types declared among parms in a prototype. */
10726 tree parmtags = current_function_parm_tags;
10728 /* This is a chain of any other decls that came in among the parm
10729 declarations. If a parm is declared with enum {foo, bar} x;
10730 then CONST_DECLs for foo and bar are put here. */
10731 tree nonparms = NULL_TREE;
10733 if (current_binding_level == global_binding_level)
10734 fatal ("parse errors have confused me too much");
10736 /* Initialize RTL machinery. */
10737 init_function_start (fndecl, input_filename, lineno);
10739 /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
10740 declare_function_name ();
10742 /* Create a binding level for the parms. */
10743 expand_start_bindings (0);
10745 /* Prepare to catch raises, if appropriate. */
10746 if (flag_handle_exceptions)
10748 /* Get this cleanup to be run last, since it
10749 is a call to `longjmp'. */
10750 setup_exception_throw_decl ();
10751 eh_decl = current_binding_level->names;
10752 current_binding_level->names = TREE_CHAIN (current_binding_level->names);
10754 if (flag_handle_exceptions)
10755 expand_start_try (integer_one_node, 0, 1);
10757 if (specparms != NULL_TREE)
10759 /* This case is when the function was defined with an ANSI prototype.
10760 The parms already have decls, so we need not do anything here
10761 except record them as in effect
10762 and complain if any redundant old-style parm decls were written. */
10764 register tree next;
10766 /* Must clear this because it might contain TYPE_DECLs declared
10768 storedecls (NULL_TREE);
10769 for (parm = nreverse (specparms); parm; parm = next)
10771 next = TREE_CHAIN (parm);
10772 if (TREE_CODE (parm) == PARM_DECL)
10774 tree cleanup = maybe_build_cleanup (parm);
10775 if (DECL_NAME (parm) == NULL_TREE)
10778 cp_error_at ("parameter name omitted", parm);
10780 /* for C++, this is not an error. */
10784 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
10785 cp_error ("parameter `%D' declared void", parm);
10788 /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
10789 A parameter is assumed not to have any side effects.
10790 If this should change for any reason, then this
10791 will have to wrap the bashed reference type in a save_expr.
10793 Also, if the parameter type is declared to be an X
10794 and there is an X(X&) constructor, we cannot lay it
10795 into the stack (any more), so we make this parameter
10796 look like it is really of reference type. Functions
10797 which pass parameters to this function will know to
10798 create a temporary in their frame, and pass a reference
10801 if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
10802 && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
10803 SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
10809 expand_decl (parm);
10810 expand_decl_cleanup (parm, cleanup);
10811 parms_have_cleanups = 1;
10816 /* If we find an enum constant or a type tag,
10817 put it aside for the moment. */
10818 TREE_CHAIN (parm) = NULL_TREE;
10819 nonparms = chainon (nonparms, parm);
10823 /* Get the decls in their original chain order
10824 and record in the function. This is all and only the
10825 PARM_DECLs that were pushed into scope by the loop above. */
10826 DECL_ARGUMENTS (fndecl) = getdecls ();
10828 storetags (chainon (parmtags, gettags ()));
10831 DECL_ARGUMENTS (fndecl) = NULL_TREE;
10833 /* Now store the final chain of decls for the arguments
10834 as the decl-chain of the current lexical scope.
10835 Put the enumerators in as well, at the front so that
10836 DECL_ARGUMENTS is not modified. */
10838 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
10840 /* Initialize the RTL code for the function. */
10841 DECL_SAVED_INSNS (fndecl) = NULL_RTX;
10842 expand_function_start (fndecl, parms_have_cleanups);
10844 if (flag_handle_exceptions)
10846 /* Make the throw decl visible at this level, just
10847 not in the way of the parameters. */
10848 pushdecl (eh_decl);
10849 expand_decl_init (eh_decl);
10852 /* Create a binding contour which can be used to catch
10853 cleanup-generated temporaries. Also, if the return value needs or
10854 has initialization, deal with that now. */
10855 if (parms_have_cleanups)
10858 expand_start_bindings (0);
10861 current_function_parms_stored = 1;
10865 maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
10866 expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup);
10869 /* If this function is `main', emit a call to `__main'
10870 to run global initializers, etc. */
10871 if (DECL_NAME (fndecl)
10872 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
10873 && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
10874 && DECL_CONTEXT (fndecl) == NULL_TREE)
10876 expand_main_function ();
10879 expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
10883 output_builtin_tdesc_entries ();
10887 /* Bind a name and initialization to the return value of
10888 the current function. */
10890 store_return_init (return_id, init)
10891 tree return_id, init;
10893 tree decl = DECL_RESULT (current_function_decl);
10896 /* Give this error as many times as there are occurrences,
10897 so that users can use Emacs compilation buffers to find
10898 and fix all such places. */
10899 error ("ANSI C++ does not permit named return values");
10901 if (return_id != NULL_TREE)
10903 if (DECL_NAME (decl) == NULL_TREE)
10905 DECL_NAME (decl) = return_id;
10906 DECL_ASSEMBLER_NAME (decl) = return_id;
10909 error ("return identifier `%s' already in place",
10910 IDENTIFIER_POINTER (DECL_NAME (decl)));
10913 /* Can't let this happen for constructors. */
10914 if (DECL_CONSTRUCTOR_P (current_function_decl))
10916 error ("can't redefine default return value for constructors");
10920 /* If we have a named return value, put that in our scope as well. */
10921 if (DECL_NAME (decl) != NULL_TREE)
10923 /* If this named return value comes in a register,
10924 put it in a pseudo-register. */
10925 if (DECL_REGISTER (decl))
10927 original_result_rtx = DECL_RTL (decl);
10928 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
10931 /* Let `finish_decl' know that this initializer is ok. */
10932 DECL_INITIAL (decl) = init;
10934 finish_decl (decl, init, 0, 0);
10939 /* Generate code for default X() constructor. */
10941 build_default_constructor (fndecl)
10944 int i = CLASSTYPE_N_BASECLASSES (current_class_type);
10945 tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
10946 tree fields = TYPE_FIELDS (current_class_type);
10947 tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
10949 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
10950 parm = TREE_CHAIN (parm);
10951 parm = DECL_REFERENCE_SLOT (parm);
10955 tree basetype = TREE_VEC_ELT (binfos, i);
10956 if (TYPE_HAS_INIT_REF (basetype))
10958 tree name = TYPE_NAME (basetype);
10959 if (TREE_CODE (name) == TYPE_DECL)
10960 name = DECL_NAME (name);
10961 current_base_init_list = tree_cons (name, parm, current_base_init_list);
10964 for (; fields; fields = TREE_CHAIN (fields))
10967 if (TREE_STATIC (fields))
10969 if (TREE_CODE (fields) != FIELD_DECL)
10971 if (DECL_NAME (fields))
10973 if (VFIELD_NAME_P (DECL_NAME (fields)))
10975 if (VBASE_NAME_P (DECL_NAME (fields)))
10978 /* True for duplicate members. */
10979 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields)
10983 init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields);
10984 init = build_tree_list (NULL_TREE, init);
10986 current_member_init_list
10987 = tree_cons (DECL_NAME (fields), init, current_member_init_list);
10992 /* Finish up a function declaration and compile that function
10993 all the way to assembler language output. The free the storage
10994 for the function definition.
10996 This is called after parsing the body of the function definition.
10997 LINENO is the current line number.
10999 C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
11000 (and expand_end_bindings) must be made to take care of the binding
11001 contour for the base initializers. This is only relevant for
11005 finish_function (lineno, call_poplevel)
11009 register tree fndecl = current_function_decl;
11010 tree fntype, ctype = NULL_TREE;
11011 rtx head, last_parm_insn, mark;
11012 extern int sets_exception_throw_decl;
11013 /* Label to use if this function is supposed to return a value. */
11014 tree no_return_label = NULL_TREE;
11015 tree decls = NULL_TREE;
11017 /* When we get some parse errors, we can end up without a
11018 current_function_decl, so cope. */
11019 if (fndecl == NULL_TREE)
11022 fntype = TREE_TYPE (fndecl);
11024 /* TREE_READONLY (fndecl) = 1;
11025 This caused &foo to be of type ptr-to-const-function
11026 which then got a warning when stored in a ptr-to-function variable. */
11028 /* This happens on strange parse errors. */
11029 if (! current_function_parms_stored)
11032 store_parm_decls ();
11035 if (write_symbols != NO_DEBUG && TREE_CODE (fntype) != METHOD_TYPE)
11037 tree ttype = target_type (fntype);
11040 if (IS_AGGR_TYPE (ttype))
11041 /* Let debugger know it should output info for this type. */
11042 note_debug_info_needed (ttype);
11044 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
11046 ttype = target_type (TREE_TYPE (parmdecl));
11047 if (IS_AGGR_TYPE (ttype))
11048 /* Let debugger know it should output info for this type. */
11049 note_debug_info_needed (ttype);
11053 /* Clean house because we will need to reorder insns here. */
11054 do_pending_stack_adjust ();
11058 tree binfo = TYPE_BINFO (current_class_type);
11059 tree cond = integer_one_node;
11060 tree exprstmt, vfields;
11061 tree in_charge_node = lookup_name (in_charge_identifier, 0);
11063 int ok_to_optimize_dtor = 0;
11065 if (current_function_assigns_this)
11066 cond = build (NE_EXPR, integer_type_node,
11067 current_class_decl, integer_zero_node);
11070 int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
11072 /* If this destructor is empty, then we don't need to check
11073 whether `this' is NULL in some cases. */
11074 mark = get_last_insn ();
11075 last_parm_insn = get_first_nonparm_insn ();
11077 if ((flag_this_is_variable & 1) == 0)
11078 ok_to_optimize_dtor = 1;
11079 else if (mark == last_parm_insn)
11080 ok_to_optimize_dtor
11081 = (n_baseclasses == 0
11082 || (n_baseclasses == 1
11083 && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
11086 /* These initializations might go inline. Protect
11087 the binding level of the parms. */
11089 expand_start_bindings (0);
11091 if (current_function_assigns_this)
11093 current_function_assigns_this = 0;
11094 current_function_just_assigned_this = 0;
11097 /* Generate the code to call destructor on base class.
11098 If this destructor belongs to a class with virtual
11099 functions, then set the virtual function table
11100 pointer to represent the type of our base class. */
11102 /* This side-effect makes call to `build_delete' generate the
11103 code we have to have at the end of this destructor. */
11104 TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
11106 /* These are two cases where we cannot delegate deletion. */
11107 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
11108 || TREE_GETS_DELETE (current_class_type))
11109 exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
11110 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11112 exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
11113 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11115 /* If we did not assign to this, then `this' is non-zero at
11116 the end of a destructor. As a special optimization, don't
11117 emit test if this is an empty destructor. If it does nothing,
11118 it does nothing. If it calls a base destructor, the base
11119 destructor will perform the test. */
11121 if (exprstmt != error_mark_node
11122 && (TREE_CODE (exprstmt) != NOP_EXPR
11123 || TREE_OPERAND (exprstmt, 0) != integer_zero_node
11124 || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
11126 expand_label (dtor_label);
11127 if (cond != integer_one_node)
11128 expand_start_cond (cond, 0);
11129 if (exprstmt != void_zero_node)
11130 /* Don't call `expand_expr_stmt' if we're not going to do
11131 anything, since -Wall will give a diagnostic. */
11132 expand_expr_stmt (exprstmt);
11134 /* Run destructor on all virtual baseclasses. */
11135 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11137 tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
11138 expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
11139 in_charge_node, integer_two_node), 0);
11142 if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
11144 tree ptr = convert_pointer_to_vbase (vbases, current_class_decl);
11145 expand_expr_stmt (build_delete (TYPE_POINTER_TO (BINFO_TYPE (vbases)),
11146 ptr, integer_zero_node,
11147 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
11149 vbases = TREE_CHAIN (vbases);
11151 expand_end_cond ();
11154 do_pending_stack_adjust ();
11155 if (cond != integer_one_node)
11156 expand_end_cond ();
11159 TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
11161 virtual_size = c_sizeof (current_class_type);
11163 /* At the end, call delete if that's what's requested. */
11164 if (TREE_GETS_DELETE (current_class_type))
11165 /* This NOP_EXPR means we are in a static call context. */
11168 (build_indirect_ref
11169 (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type),
11172 ansi_opname[(int) DELETE_EXPR],
11173 tree_cons (NULL_TREE, current_class_decl,
11174 build_tree_list (NULL_TREE, virtual_size)),
11175 NULL_TREE, LOOKUP_NORMAL);
11176 else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11177 exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
11180 exprstmt = NULL_TREE;
11184 cond = build (BIT_AND_EXPR, integer_type_node,
11185 in_charge_node, integer_one_node);
11186 expand_start_cond (cond, 0);
11187 expand_expr_stmt (exprstmt);
11188 expand_end_cond ();
11191 /* End of destructor. */
11192 expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0);
11193 poplevel (2, 0, 0); /* XXX change to 1 */
11195 /* Back to the top of destructor. */
11196 /* Dont execute destructor code if `this' is NULL. */
11197 mark = get_last_insn ();
11198 last_parm_insn = get_first_nonparm_insn ();
11199 if (last_parm_insn == NULL_RTX)
11200 last_parm_insn = mark;
11202 last_parm_insn = previous_insn (last_parm_insn);
11204 /* Make all virtual function table pointers in non-virtual base
11205 classes point to CURRENT_CLASS_TYPE's virtual function
11207 init_vtbl_ptrs (binfo, 1, 0);
11208 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11209 expand_expr_stmt (build_vbase_vtables_init (binfo, binfo,
11210 C_C_D, current_class_decl, 0));
11211 if (! ok_to_optimize_dtor)
11213 cond = build_binary_op (NE_EXPR,
11214 current_class_decl, integer_zero_node, 1);
11215 expand_start_cond (cond, 0);
11217 if (mark != get_last_insn ())
11218 reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
11219 if (! ok_to_optimize_dtor)
11220 expand_end_cond ();
11222 else if (current_function_assigns_this)
11224 /* Does not need to call emit_base_init, because
11225 that is done (if needed) just after assignment to this
11228 if (DECL_CONSTRUCTOR_P (current_function_decl))
11230 expand_label (ctor_label);
11231 ctor_label = NULL_TREE;
11235 decls = getdecls ();
11236 if (flag_handle_exceptions == 2)
11237 deactivate_exception_cleanups ();
11238 expand_end_bindings (decls, decls != NULL_TREE, 0);
11239 poplevel (decls != NULL_TREE, 0, 0);
11241 c_expand_return (current_class_decl);
11243 else if (TYPE_MAIN_VARIANT (TREE_TYPE (
11244 DECL_RESULT (current_function_decl))) != void_type_node
11245 && return_label != NULL_RTX)
11246 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11248 current_function_assigns_this = 0;
11249 current_function_just_assigned_this = 0;
11250 base_init_insns = NULL_RTX;
11252 else if (DECL_CONSTRUCTOR_P (fndecl))
11254 tree allocated_this;
11255 tree cond, thenclause;
11256 /* Allow constructor for a type to get a new instance of the object
11257 using `build_new'. */
11258 tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
11259 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
11261 DECL_RETURNS_FIRST_ARG (fndecl) = 1;
11263 if (flag_this_is_variable > 0)
11265 cond = build_binary_op (EQ_EXPR,
11266 current_class_decl, integer_zero_node, 1);
11267 thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
11268 build_new (NULL_TREE, current_class_type, void_type_node, 0));
11269 if (flag_handle_exceptions == 2)
11271 tree cleanup, cleanup_deallocate;
11274 /* This is the size of the virtual object pointed to by
11275 allocated_this. In this case, it is simple. */
11276 virtual_size = c_sizeof (current_class_type);
11278 allocated_this = build_decl (VAR_DECL, NULL_TREE, ptr_type_node);
11279 DECL_REGISTER (allocated_this) = 1;
11280 DECL_INITIAL (allocated_this) = error_mark_node;
11281 expand_decl (allocated_this);
11282 expand_decl_init (allocated_this);
11283 /* How we cleanup `this' if an exception was raised before
11284 we are ready to bail out. */
11285 cleanup = TREE_GETS_DELETE (current_class_type)
11286 ? build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, allocated_this, virtual_size, NULL_TREE)
11287 /* The size of allocated_this is wrong, and hence the
11288 second argument to operator delete will be wrong. */
11289 : build_delete (TREE_TYPE (allocated_this), allocated_this,
11290 integer_three_node,
11291 LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 1);
11293 = build_modify_expr (current_class_decl, NOP_EXPR, integer_zero_node);
11294 cleanup = tree_cons (NULL_TREE, cleanup,
11295 build_tree_list (NULL_TREE, cleanup_deallocate));
11297 expand_decl_cleanup (allocated_this,
11298 build (COND_EXPR, integer_type_node,
11299 build (NE_EXPR, integer_type_node,
11300 allocated_this, integer_zero_node),
11301 build_compound_expr (cleanup),
11302 integer_zero_node));
11306 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
11308 /* must keep the first insn safe. */
11309 head = get_insns ();
11311 /* this note will come up to the top with us. */
11312 mark = get_last_insn ();
11314 if (flag_this_is_variable > 0)
11316 expand_start_cond (cond, 0);
11317 expand_expr_stmt (thenclause);
11318 if (flag_handle_exceptions == 2)
11319 expand_assignment (allocated_this, current_class_decl, 0, 0);
11320 expand_end_cond ();
11324 if (DECL_NAME (fndecl) == NULL_TREE
11325 && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
11326 build_default_constructor (fndecl);
11329 /* Emit insns from `emit_base_init' which sets up virtual
11330 function table pointer(s). */
11331 emit_insns (base_init_insns);
11332 base_init_insns = NULL_RTX;
11334 /* This is where the body of the constructor begins.
11335 If there were no insns in this function body, then the
11336 last_parm_insn is also the last insn.
11338 If optimization is enabled, last_parm_insn may move, so
11339 we don't hold on to it (across emit_base_init). */
11340 last_parm_insn = get_first_nonparm_insn ();
11341 if (last_parm_insn == NULL_RTX)
11342 last_parm_insn = mark;
11344 last_parm_insn = previous_insn (last_parm_insn);
11346 if (mark != get_last_insn ())
11347 reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
11349 /* This is where the body of the constructor ends. */
11350 expand_label (ctor_label);
11351 ctor_label = NULL_TREE;
11352 if (flag_handle_exceptions == 2)
11354 expand_assignment (allocated_this, integer_zero_node, 0, 0);
11356 deactivate_exception_cleanups ();
11359 pop_implicit_try_blocks (NULL_TREE);
11363 expand_end_bindings (decls = getdecls (), decls != NULL_TREE, 0);
11364 poplevel (decls != NULL_TREE, 1, 0);
11367 c_expand_return (current_class_decl);
11369 current_function_assigns_this = 0;
11370 current_function_just_assigned_this = 0;
11372 else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
11373 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
11374 && DECL_CONTEXT (fndecl) == NULL_TREE)
11376 /* Make it so that `main' always returns 0 by default. */
11378 c_expand_return (integer_one_node);
11380 c_expand_return (integer_zero_node);
11383 else if (return_label != NULL_RTX
11384 && current_function_return_value == NULL_TREE
11385 && ! DECL_NAME (DECL_RESULT (current_function_decl)))
11386 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11389 expand_gc_prologue_and_epilogue ();
11391 /* That's the end of the vtable decl's life. Need to mark it such
11392 if doing stupid register allocation.
11394 Note that current_vtable_decl is really an INDIRECT_REF
11395 on top of a VAR_DECL here. */
11396 if (obey_regdecls && current_vtable_decl)
11397 use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0)));
11399 /* If this function is supposed to return a value, ensure that
11400 we do not fall into the cleanups by mistake. The end of our
11401 function will look like this:
11403 user code (may have return stmt somewhere)
11404 goto no_return_label
11409 NOTE_INSN_FUNCTION_END
11413 If the user omits a return stmt in the USER CODE section, we
11414 will have a control path which reaches NOTE_INSN_FUNCTION_END.
11415 Otherwise, we won't. */
11416 if (no_return_label)
11418 DECL_CONTEXT (no_return_label) = fndecl;
11419 DECL_INITIAL (no_return_label) = error_mark_node;
11420 DECL_SOURCE_FILE (no_return_label) = input_filename;
11421 DECL_SOURCE_LINE (no_return_label) = lineno;
11422 expand_goto (no_return_label);
11427 /* remove the binding contour which is used
11428 to catch cleanup-generated temporaries. */
11429 expand_end_bindings (0, 0, 0);
11430 poplevel (0, 0, 0);
11434 /* Emit label at beginning of cleanup code for parameters. */
11435 emit_label (cleanup_label);
11438 /* Cheap hack to get better code from GNU C++. Remove when cse is fixed. */
11439 if (exception_throw_decl && sets_exception_throw_decl == 0)
11440 expand_assignment (exception_throw_decl, integer_zero_node, 0, 0);
11443 if (flag_handle_exceptions)
11446 expand_start_except (0, 0);
11447 expand_end_except ();
11450 /* Get return value into register if that's where it's supposed to be. */
11451 if (original_result_rtx)
11452 fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
11454 /* Finish building code that will trigger warnings if users forget
11455 to make their functions return values. */
11456 if (no_return_label || cleanup_label)
11457 emit_jump (return_label);
11458 if (no_return_label)
11460 /* We don't need to call `expand_*_return' here because we
11461 don't need any cleanups here--this path of code is only
11462 for error checking purposes. */
11463 expand_label (no_return_label);
11466 /* reset scope for C++: if we were in the scope of a class,
11467 then when we finish this function, we are not longer so.
11468 This cannot be done until we know for sure that no more
11469 class members will ever be referenced in this function
11470 (i.e., calls to destructors). */
11471 if (current_class_name)
11473 ctype = current_class_type;
11474 pop_nested_class (1);
11477 pop_memoized_context (1);
11479 /* Forget about all overloaded functions defined in
11480 this scope which go away. */
11481 while (overloads_to_forget)
11483 IDENTIFIER_GLOBAL_VALUE (TREE_PURPOSE (overloads_to_forget))
11484 = TREE_VALUE (overloads_to_forget);
11485 overloads_to_forget = TREE_CHAIN (overloads_to_forget);
11488 /* Generate rtl for function exit. */
11489 expand_function_end (input_filename, lineno, 1);
11491 /* This must come after expand_function_end because cleanups might
11492 have declarations (from inline functions) that need to go into
11493 this function's blocks. */
11494 if (current_binding_level->parm_flag != 1)
11495 my_friendly_abort (122);
11496 poplevel (1, 0, 1);
11498 /* Must mark the RESULT_DECL as being in this function. */
11499 DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
11501 /* Obey `register' declarations if `setjmp' is called in this fn. */
11502 if (flag_traditional && current_function_calls_setjmp)
11503 setjmp_protect (DECL_INITIAL (fndecl));
11505 /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
11506 to the FUNCTION_DECL node itself. */
11507 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
11509 /* So we can tell if jump_optimize sets it to 1. */
11512 /* ??? Compensate for Sun brain damage in dealing with data segments
11515 && (DECL_CONSTRUCTOR_P (fndecl)
11516 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
11517 && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype)))
11518 DECL_INLINE (fndecl) = 0;
11520 if (DECL_EXTERNAL (fndecl)
11521 /* This function is just along for the ride. If we can make
11522 it inline, that's great. Otherwise, just punt it. */
11523 && (DECL_INLINE (fndecl) == 0
11525 || function_cannot_inline_p (fndecl)))
11527 extern int rtl_dump_and_exit;
11528 int old_rtl_dump_and_exit = rtl_dump_and_exit;
11529 int inline_spec = DECL_INLINE (fndecl);
11531 /* This throws away the code for FNDECL. */
11532 rtl_dump_and_exit = 1;
11533 /* This throws away the memory of the code for FNDECL. */
11534 if (flag_no_inline)
11535 DECL_INLINE (fndecl) = 0;
11536 rest_of_compilation (fndecl);
11537 rtl_dump_and_exit = old_rtl_dump_and_exit;
11538 DECL_INLINE (fndecl) = inline_spec;
11542 /* Run the optimizers and output the assembler code for this
11544 rest_of_compilation (fndecl);
11547 if (ctype && TREE_ASM_WRITTEN (fndecl))
11548 note_debug_info_needed (ctype);
11550 current_function_returns_null |= can_reach_end;
11552 /* Since we don't normally go through c_expand_return for constructors,
11553 this normally gets the wrong value.
11554 Also, named return values have their return codes emitted after
11555 NOTE_INSN_FUNCTION_END, confusing jump.c. */
11556 if (DECL_CONSTRUCTOR_P (fndecl)
11557 || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
11558 current_function_returns_null = 0;
11560 if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
11561 cp_warning ("`noreturn' function `%D' does return", fndecl);
11562 else if ((warn_return_type || pedantic)
11563 && current_function_returns_null
11564 && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
11566 /* If this function returns non-void and control can drop through,
11568 cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
11570 /* With just -W, complain only if function returns both with
11571 and without a value. */
11572 else if (extra_warnings
11573 && current_function_returns_value && current_function_returns_null)
11574 warning ("this function may return with or without a value");
11576 /* Free all the tree nodes making up this function. */
11577 /* Switch back to allocating nodes permanently
11578 until we start another function. */
11579 permanent_allocation (1);
11582 cadillac_finish_function (fndecl);
11584 if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
11586 /* Stop pointing to the local nodes about to be freed. */
11587 /* But DECL_INITIAL must remain nonzero so we know this
11588 was an actual function definition. */
11589 DECL_INITIAL (fndecl) = error_mark_node;
11590 if (! DECL_CONSTRUCTOR_P (fndecl)
11591 || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
11592 DECL_ARGUMENTS (fndecl) = NULL_TREE;
11595 /* Let the error reporting routines know that we're outside a function. */
11596 current_function_decl = NULL_TREE;
11597 named_label_uses = NULL_TREE;
11600 /* Create the FUNCTION_DECL for a function definition.
11601 LINE1 is the line number that the definition absolutely begins on.
11602 LINE2 is the line number that the name of the function appears on.
11603 DECLSPECS and DECLARATOR are the parts of the declaration;
11604 they describe the return type and the name of the function,
11605 but twisted together in a fashion that parallels the syntax of C.
11607 This function creates a binding context for the function body
11608 as well as setting up the FUNCTION_DECL in current_function_decl.
11610 Returns a FUNCTION_DECL on success.
11612 If the DECLARATOR is not suitable for a function (it defines a datum
11613 instead), we return 0, which tells yyparse to report a parse error.
11615 May return void_type_node indicating that this method is actually
11616 a friend. See grokfield for more details.
11618 Came here with a `.pushlevel' .
11620 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
11621 CHANGES TO CODE IN `grokfield'. */
11623 start_method (declspecs, declarator, raises)
11624 tree declarator, declspecs, raises;
11626 tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises);
11628 /* Something too ugly to handle. */
11629 if (fndecl == NULL_TREE)
11632 /* Pass friends other than inline friend functions back. */
11633 if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
11636 if (TREE_CODE (fndecl) != FUNCTION_DECL)
11637 /* Not a function, tell parser to report parse error. */
11640 if (IS_SIGNATURE (current_class_type))
11642 IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
11643 /* In case we need this info later. */
11644 HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1;
11647 if (DECL_IN_AGGR_P (fndecl))
11649 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
11651 if (DECL_CONTEXT (fndecl))
11652 cp_error ("`%D' is already defined in class %s", fndecl,
11653 TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
11655 return void_type_node;
11658 /* If we're expanding a template, a function must be explicitly declared
11659 inline if we're to compile it now. If it isn't, we have to wait to see
11660 whether it's needed, and whether an override exists. */
11661 if (flag_default_inline && !processing_template_defn)
11662 DECL_INLINE (fndecl) = 1;
11664 /* We read in the parameters on the maybepermanent_obstack,
11665 but we won't be getting back to them until after we
11666 may have clobbered them. So the call to preserve_data
11667 will keep them safe. */
11670 if (! DECL_FRIEND_P (fndecl))
11672 if (DECL_CHAIN (fndecl) != NULL_TREE)
11674 /* Need a fresh node here so that we don't get circularity
11675 when we link these together. If FNDECL was a friend, then
11676 `pushdecl' does the right thing, which is nothing wrt its
11677 current value of DECL_CHAIN. */
11678 fndecl = copy_node (fndecl);
11680 if (TREE_CHAIN (fndecl))
11682 fndecl = copy_node (fndecl);
11683 TREE_CHAIN (fndecl) = NULL_TREE;
11686 if (DECL_CONSTRUCTOR_P (fndecl))
11687 grok_ctor_properties (current_class_type, fndecl);
11688 else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
11689 grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
11692 finish_decl (fndecl, NULL_TREE, NULL_TREE, 0);
11694 /* Make a place for the parms */
11696 current_binding_level->parm_flag = 1;
11698 DECL_IN_AGGR_P (fndecl) = 1;
11702 /* Go through the motions of finishing a function definition.
11703 We don't compile this method until after the whole class has
11706 FINISH_METHOD must return something that looks as though it
11707 came from GROKFIELD (since we are defining a method, after all).
11709 This is called after parsing the body of the function definition.
11710 STMTS is the chain of statements that makes up the function body.
11712 DECL is the ..._DECL that `start_method' provided. */
11715 finish_method (decl)
11718 register tree fndecl = decl;
11720 tree context = DECL_CONTEXT (fndecl);
11722 register tree link;
11724 if (TYPE_MAIN_VARIANT (decl) == void_type_node)
11727 old_initial = DECL_INITIAL (fndecl);
11729 /* Undo the level for the parms (from start_method).
11730 This is like poplevel, but it causes nothing to be
11731 saved. Saving information here confuses symbol-table
11732 output routines. Besides, this information will
11733 be correctly output when this method is actually
11736 /* Clear out the meanings of the local variables of this level;
11737 also record in each decl which block it belongs to. */
11739 for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
11741 if (DECL_NAME (link) != NULL_TREE)
11742 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
11743 my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
11744 DECL_CONTEXT (link) = NULL_TREE;
11747 /* Restore all name-meanings of the outer levels
11748 that were shadowed by this level. */
11750 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
11751 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11752 for (link = current_binding_level->class_shadowed;
11753 link; link = TREE_CHAIN (link))
11754 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11755 for (link = current_binding_level->type_shadowed;
11756 link; link = TREE_CHAIN (link))
11757 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
11759 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
11760 (HOST_WIDE_INT) current_binding_level->level_chain,
11761 current_binding_level->parm_flag,
11762 current_binding_level->keep,
11763 current_binding_level->tag_transparent);
11765 poplevel (0, 0, 0);
11767 DECL_INITIAL (fndecl) = old_initial;
11769 /* We used to check if the context of FNDECL was different from
11770 current_class_type as another way to get inside here. This didn't work
11771 for String.cc in libg++. */
11772 if (DECL_FRIEND_P (fndecl))
11774 CLASSTYPE_INLINE_FRIENDS (current_class_type)
11775 = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
11776 decl = void_type_node;
11782 /* Called when a new struct TYPE is defined.
11783 If this structure or union completes the type of any previous
11784 variable declaration, lay it out and output its rtl. */
11787 hack_incomplete_structures (type)
11792 if (current_binding_level->n_incomplete == 0)
11795 if (!type) /* Don't do this for class templates. */
11798 for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
11799 if (TREE_TYPE (decl) == type
11800 || (TREE_TYPE (decl)
11801 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
11802 && TREE_TYPE (TREE_TYPE (decl)) == type))
11804 if (TREE_CODE (decl) == TYPE_DECL)
11805 layout_type (TREE_TYPE (decl));
11808 int toplevel = global_binding_level == current_binding_level;
11809 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
11810 && TREE_TYPE (TREE_TYPE (decl)) == type)
11811 layout_type (TREE_TYPE (decl));
11812 layout_decl (decl, 0);
11813 rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
11816 expand_decl (decl);
11817 expand_decl_cleanup (decl, maybe_build_cleanup (decl));
11818 expand_decl_init (decl);
11821 my_friendly_assert (current_binding_level->n_incomplete > 0, 164);
11822 --current_binding_level->n_incomplete;
11826 /* Nonzero if presently building a cleanup. Needed because
11827 SAVE_EXPRs are not the right things to use inside of cleanups.
11828 They are only ever evaluated once, where the cleanup
11829 might be evaluated several times. In this case, a later evaluation
11830 of the cleanup might fill in the SAVE_EXPR_RTL, and it will
11831 not be valid for an earlier cleanup. */
11833 int building_cleanup;
11835 /* If DECL is of a type which needs a cleanup, build that cleanup here.
11836 We don't build cleanups if just going for syntax checking, since
11837 fixup_cleanups does not know how to not handle them.
11839 Don't build these on the momentary obstack; they must live
11840 the life of the binding contour. */
11842 maybe_build_cleanup (decl)
11845 tree type = TREE_TYPE (decl);
11846 if (TYPE_NEEDS_DESTRUCTOR (type))
11848 int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
11850 int old_building_cleanup = building_cleanup;
11851 building_cleanup = 1;
11853 if (TREE_CODE (decl) != PARM_DECL)
11854 temp = suspend_momentary ();
11856 if (TREE_CODE (type) == ARRAY_TYPE)
11860 mark_addressable (decl);
11861 rval = build_unary_op (ADDR_EXPR, decl, 0);
11864 /* Optimize for space over speed here. */
11865 if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
11866 || flag_expensive_optimizations)
11867 flags |= LOOKUP_NONVIRTUAL;
11869 /* Use TYPE_MAIN_VARIANT so we don't get a warning about
11870 calling delete on a `const' variable. */
11871 if (TYPE_READONLY (TREE_TYPE (TREE_TYPE (rval))))
11872 rval = build1 (NOP_EXPR, TYPE_POINTER_TO (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (rval)))), rval);
11874 rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0);
11876 if (TYPE_USES_VIRTUAL_BASECLASSES (type)
11877 && ! TYPE_HAS_DESTRUCTOR (type))
11878 rval = build_compound_expr (tree_cons (NULL_TREE, rval,
11879 build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
11881 current_binding_level->have_cleanups = 1;
11882 current_binding_level->more_exceptions_ok = 0;
11884 if (TREE_CODE (decl) != PARM_DECL)
11885 resume_momentary (temp);
11887 building_cleanup = old_building_cleanup;
11894 /* Expand a C++ expression at the statement level.
11895 This is needed to ferret out nodes which have UNKNOWN_TYPE.
11896 The C++ type checker should get all of these out when
11897 expressions are combined with other, type-providing, expressions,
11898 leaving only orphan expressions, such as:
11900 &class::bar; / / takes its address, but does nothing with it.
11904 cplus_expand_expr_stmt (exp)
11907 if (TREE_TYPE (exp) == unknown_type_node)
11909 if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
11910 error ("address of overloaded function with no contextual type information");
11911 else if (TREE_CODE (exp) == COMPONENT_REF)
11912 warning ("useless reference to a member function name, did you forget the ()?");
11916 int remove_implicit_immediately = 0;
11918 if (TREE_CODE (exp) == FUNCTION_DECL)
11920 cp_warning ("reference, not call, to function `%D'", exp);
11921 warning ("at this point in file");
11923 if (TREE_RAISES (exp))
11925 my_friendly_assert (flag_handle_exceptions, 165);
11926 if (flag_handle_exceptions == 2)
11928 if (! current_binding_level->more_exceptions_ok)
11930 extern struct nesting *nesting_stack, *block_stack;
11932 remove_implicit_immediately
11933 = (nesting_stack != block_stack);
11934 cplus_expand_start_try (1);
11936 current_binding_level->have_exceptions = 1;
11940 expand_expr_stmt (break_out_cleanups (exp));
11942 if (remove_implicit_immediately)
11943 pop_implicit_try_blocks (NULL_TREE);
11946 /* Clean up any pending cleanups. This happens when a function call
11947 returns a cleanup-needing value that nobody uses. */
11948 expand_cleanups_to (NULL_TREE);
11951 /* When a stmt has been parsed, this function is called.
11953 Currently, this function only does something within a
11954 constructor's scope: if a stmt has just assigned to this,
11955 and we are in a derived class, we call `emit_base_init'. */
11960 extern struct nesting *cond_stack, *loop_stack, *case_stack;
11963 if (current_function_assigns_this
11964 || ! current_function_just_assigned_this)
11966 if (DECL_CONSTRUCTOR_P (current_function_decl))
11968 /* Constructors must wait until we are out of control
11969 zones before calling base constructors. */
11970 if (cond_stack || loop_stack || case_stack)
11972 emit_insns (base_init_insns);
11973 check_base_init (current_class_type);
11975 current_function_assigns_this = 1;
11978 cadillac_finish_stmt ();
11982 pop_implicit_try_blocks (decl)
11987 my_friendly_assert (current_binding_level->parm_flag == 3, 166);
11988 current_binding_level->names = TREE_CHAIN (decl);
11991 while (current_binding_level->parm_flag == 3)
11993 tree name = get_identifier ("(compiler error)");
11994 tree orig_ex_type = current_exception_type;
11995 tree orig_ex_decl = current_exception_decl;
11996 tree orig_ex_obj = current_exception_object;
11997 tree decl = cplus_expand_end_try (2);
11999 /* @@ It would be nice to make all these point
12000 to exactly the same handler. */
12001 /* Start hidden EXCEPT. */
12002 cplus_expand_start_except (name, decl);
12004 cplus_expand_reraise (NULL_TREE);
12005 current_exception_type = orig_ex_type;
12006 current_exception_decl = orig_ex_decl;
12007 current_exception_object = orig_ex_obj;
12008 /* This will reraise for us. */
12009 cplus_expand_end_except (error_mark_node);
12014 TREE_CHAIN (decl) = current_binding_level->names;
12015 current_binding_level->names = decl;
12019 /* Push a cleanup onto the current binding contour that will cause
12020 ADDR to be cleaned up, in the case that an exception propagates
12021 through its binding contour. */
12024 push_exception_cleanup (addr)
12027 tree decl = build_decl (VAR_DECL, get_identifier (EXCEPTION_CLEANUP_NAME), ptr_type_node);
12030 decl = pushdecl (decl);
12031 DECL_REGISTER (decl) = 1;
12032 store_init_value (decl, addr);
12033 expand_decl (decl);
12034 expand_decl_init (decl);
12036 cleanup = build (COND_EXPR, integer_type_node,
12037 build (NE_EXPR, integer_type_node,
12038 decl, integer_zero_node),
12039 build_delete (TREE_TYPE (addr), decl,
12040 lookup_name (in_charge_identifier, 0),
12041 LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0),
12042 integer_zero_node);
12043 expand_decl_cleanup (decl, cleanup);
12046 /* For each binding contour, emit code that deactivates the
12047 exception cleanups. All other cleanups are left as they were. */
12050 deactivate_exception_cleanups ()
12052 struct binding_level *b = current_binding_level;
12053 tree xyzzy = get_identifier (EXCEPTION_CLEANUP_NAME);
12054 while (b != class_binding_level)
12056 if (b->parm_flag == 3)
12058 tree decls = b->names;
12061 if (DECL_NAME (decls) == xyzzy)
12062 expand_assignment (decls, integer_zero_node, 0, 0);
12063 decls = TREE_CHAIN (decls);
12066 b = b->level_chain;
12070 /* Change a static member function definition into a FUNCTION_TYPE, instead
12071 of the METHOD_TYPE that we create when it's originally parsed. */
12073 revert_static_member_fn (fn, decl, argtypes)
12074 tree *fn, *decl, *argtypes;
12076 tree tmp, function = *fn;
12078 *argtypes = TREE_CHAIN (*argtypes);
12079 tmp = build_function_type (TREE_TYPE (function), *argtypes);
12080 tmp = build_type_variant (tmp, TYPE_READONLY (function),
12081 TYPE_VOLATILE (function));
12082 tmp = build_exception_variant (TYPE_METHOD_BASETYPE (function), tmp,
12083 TYPE_RAISES_EXCEPTIONS (function));
12084 TREE_TYPE (*decl) = tmp;
12086 DECL_STATIC_FUNCTION_P (*decl) = 1;