1 /* Process declarations and variables for C compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* Process declarations and symbol lookup for C front end.
24 Also constructs types; the standard scalar types at initialization,
25 and structure, union, array and enum types when they are declared. */
27 /* ??? not all decl nodes are given the most useful possible
28 line numbers. For example, the CONST_DECLs for enum values. */
38 #include <sys/types.h>
43 #define obstack_chunk_alloc xmalloc
44 #define obstack_chunk_free free
46 extern tree builtin_return_address_fndecl;
48 extern struct obstack permanent_obstack;
50 extern int current_class_depth;
52 extern tree cleanups_this_call;
54 extern tree static_ctors, static_dtors;
56 /* Stack of places to restore the search obstack back to. */
58 /* Obstack used for remembering local class declarations (like
59 enums and static (const) members. */
61 static struct obstack decl_obstack;
62 static struct stack_level *decl_stack;
64 #ifndef CHAR_TYPE_SIZE
65 #define CHAR_TYPE_SIZE BITS_PER_UNIT
68 #ifndef SHORT_TYPE_SIZE
69 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
73 #define INT_TYPE_SIZE BITS_PER_WORD
76 #ifndef LONG_TYPE_SIZE
77 #define LONG_TYPE_SIZE BITS_PER_WORD
80 #ifndef LONG_LONG_TYPE_SIZE
81 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
84 #ifndef WCHAR_UNSIGNED
85 #define WCHAR_UNSIGNED 0
88 #ifndef FLOAT_TYPE_SIZE
89 #define FLOAT_TYPE_SIZE BITS_PER_WORD
92 #ifndef DOUBLE_TYPE_SIZE
93 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
96 #ifndef LONG_DOUBLE_TYPE_SIZE
97 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
100 #ifndef BOOL_TYPE_SIZE
101 #ifdef SLOW_BYTE_ACCESS
102 #define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (BITS_PER_WORD) : (BITS_PER_UNIT))
104 #define BOOL_TYPE_SIZE BITS_PER_UNIT
108 /* We let tm.h override the types used here, to handle trivial differences
109 such as the choice of unsigned int or long unsigned int for size_t.
110 When machines start needing nontrivial differences in the size type,
111 it would be best to do something here to figure out automatically
112 from other information what type to use. */
115 #define SIZE_TYPE "long unsigned int"
119 #define PTRDIFF_TYPE "long int"
123 #define WCHAR_TYPE "int"
126 static tree grokparms PROTO((tree, int));
127 static tree lookup_nested_type PROTO((tree, tree));
128 static char *redeclaration_error_message PROTO((tree, tree));
129 static void grok_op_properties PROTO((tree, int, int));
130 extern void* push_eh_context PROTO(());
131 extern void pop_eh_context PROTO((void *));
134 PROTO((char *, tree, enum built_in_function, void (*)(), char *));
136 /* a node which has tree code ERROR_MARK, and whose type is itself.
137 All erroneous expressions are replaced with this node. All functions
138 that accept nodes as arguments should avoid generating error messages
139 if this node is one of the arguments, since it is undesirable to get
140 multiple error messages from one error in the input. */
142 tree error_mark_node;
144 /* Erroneous argument lists can use this *IFF* they do not modify it. */
145 tree error_mark_list;
147 /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
149 tree short_integer_type_node;
150 tree integer_type_node;
151 tree long_integer_type_node;
152 tree long_long_integer_type_node;
154 tree short_unsigned_type_node;
155 tree unsigned_type_node;
156 tree long_unsigned_type_node;
157 tree long_long_unsigned_type_node;
159 tree ptrdiff_type_node;
161 tree unsigned_char_type_node;
162 tree signed_char_type_node;
164 tree wchar_type_node;
165 tree signed_wchar_type_node;
166 tree unsigned_wchar_type_node;
168 tree wchar_decl_node;
170 tree float_type_node;
171 tree double_type_node;
172 tree long_double_type_node;
174 tree intQI_type_node;
175 tree intHI_type_node;
176 tree intSI_type_node;
177 tree intDI_type_node;
179 tree unsigned_intQI_type_node;
180 tree unsigned_intHI_type_node;
181 tree unsigned_intSI_type_node;
182 tree unsigned_intDI_type_node;
184 /* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */
186 tree void_type_node, void_list_node;
189 /* Nodes for types `void *' and `const void *'. */
191 tree ptr_type_node, const_ptr_type_node;
193 /* Nodes for types `char *' and `const char *'. */
195 tree string_type_node, const_string_type_node;
197 /* Type `char[256]' or something like it.
198 Used when an array of char is needed and the size is irrelevant. */
200 tree char_array_type_node;
202 /* Type `int[256]' or something like it.
203 Used when an array of int needed and the size is irrelevant. */
205 tree int_array_type_node;
207 /* Type `wchar_t[256]' or something like it.
208 Used when a wide string literal is created. */
210 tree wchar_array_type_node;
212 /* The bool data type, and constants */
213 tree boolean_type_node, boolean_true_node, boolean_false_node;
215 /* type `int ()' -- used for implicit declaration of functions. */
217 tree default_function_type;
219 /* function types `double (double)' and `double (double, double)', etc. */
221 tree double_ftype_double, double_ftype_double_double;
222 tree int_ftype_int, long_ftype_long;
224 /* Function type `void (void *, void *, int)' and similar ones. */
226 tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
228 /* Function type `char *(char *, char *)' and similar ones */
229 tree string_ftype_ptr_ptr, int_ftype_string_string;
231 /* Function type `size_t (const char *)' */
232 tree sizet_ftype_string;
234 /* Function type `int (const void *, const void *, size_t)' */
235 tree int_ftype_cptr_cptr_sizet;
238 tree vtable_entry_type;
239 tree delta_type_node;
241 /* Old rtti stuff. */
242 tree __baselist_desc_type_node;
243 tree __i_desc_type_node, __m_desc_type_node;
244 tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
246 tree __t_desc_type_node, __tp_desc_type_node;
247 tree __access_mode_type_node;
248 tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node;
249 tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node;
250 tree __ptmf_desc_type_node, __ptmd_desc_type_node;
252 /* Not needed yet? May be needed one day? */
253 tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type;
254 tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type;
255 tree __ptmf_desc_array_type, __ptmd_desc_array_type;
258 tree class_star_type_node;
259 tree class_type_node, record_type_node, union_type_node, enum_type_node;
260 tree unknown_type_node;
261 tree opaque_type_node, signature_type_node;
262 tree sigtable_entry_type;
263 tree maybe_gc_cleanup;
265 /* Array type `vtable_entry_type[]' */
268 /* In a destructor, the point at which all derived class destroying
269 has been done, just before any base class destroying will be done. */
273 /* In a destructor, the last insn emitted after the start of the
274 function and the parms. */
278 /* In a constructor, the point at which we are ready to return
279 the pointer to the initialized object. */
283 /* A FUNCTION_DECL which can call `abort'. Not necessarily the
284 one that the user will declare, but sufficient to be called
285 by routines that want to abort the program. */
289 extern rtx cleanup_label, return_label;
291 /* If original DECL_RESULT of current function was a register,
292 but due to being an addressable named return value, would up
293 on the stack, this variable holds the named return value's
294 original location. */
295 rtx original_result_rtx;
297 /* Sequence of insns which represents base initialization. */
300 /* C++: Keep these around to reduce calls to `get_identifier'.
301 Identifiers for `this' in member functions and the auto-delete
302 parameter for destructors. */
303 tree this_identifier, in_charge_identifier;
304 /* Used in pointer to member functions, in vtables, and in sigtables. */
305 tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
306 tree pfn_or_delta2_identifier, tag_identifier;
307 tree vb_off_identifier, vt_off_identifier;
309 /* A list (chain of TREE_LIST nodes) of named label uses.
310 The TREE_PURPOSE field is the list of variables defined
311 the the label's scope defined at the point of use.
312 The TREE_VALUE field is the LABEL_DECL used.
313 The TREE_TYPE field holds `current_binding_level' at the
314 point of the label's use.
316 Used only for jumps to as-yet undefined labels, since
317 jumps to defined labels can have their validity checked
320 static tree named_label_uses;
322 /* A list of objects which have constructors or destructors
323 which reside in the global scope. The decl is stored in
324 the TREE_VALUE slot and the initializer is stored
325 in the TREE_PURPOSE slot. */
326 tree static_aggregates;
330 /* Two expressions that are constants with value zero.
331 The first is of type `int', the second of type `void *'. */
333 tree integer_zero_node;
334 tree null_pointer_node;
336 /* A node for the integer constants 1, 2, and 3. */
338 tree integer_one_node, integer_two_node, integer_three_node;
340 /* Nonzero if we have seen an invalid cross reference
341 to a struct, union, or enum, but not yet printed the message. */
343 tree pending_invalid_xref;
344 /* File and line to appear in the eventual error message. */
345 char *pending_invalid_xref_file;
346 int pending_invalid_xref_line;
348 /* While defining an enum type, this is 1 plus the last enumerator
351 static tree enum_next_value;
353 /* Nonzero means that there was overflow computing enum_next_value. */
355 static int enum_overflow;
357 /* Parsing a function declarator leaves a list of parameter names
358 or a chain or parameter decls here. */
360 tree last_function_parms;
362 /* Parsing a function declarator leaves here a chain of structure
363 and enum types declared in the parmlist. */
365 static tree last_function_parm_tags;
367 /* After parsing the declarator that starts a function definition,
368 `start_function' puts here the list of parameter names or chain of decls.
369 `store_parm_decls' finds it here. */
371 static tree current_function_parms;
373 /* Similar, for last_function_parm_tags. */
374 static tree current_function_parm_tags;
376 /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
377 that have names. Here so we can clear out their names' definitions
378 at the end of the function. */
380 static tree named_labels;
382 /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */
384 static tree shadowed_labels;
386 #if 0 /* Not needed by C++ */
387 /* Nonzero when store_parm_decls is called indicates a varargs function.
388 Value not meaningful after store_parm_decls. */
390 static int c_function_varargs;
393 /* The FUNCTION_DECL for the function currently being compiled,
394 or 0 if between functions. */
395 tree current_function_decl;
397 /* Set to 0 at beginning of a function definition, set to 1 if
398 a return statement that specifies a return value is seen. */
400 int current_function_returns_value;
402 /* Set to 0 at beginning of a function definition, set to 1 if
403 a return statement with no argument is seen. */
405 int current_function_returns_null;
407 /* Set to 0 at beginning of a function definition, and whenever
408 a label (case or named) is defined. Set to value of expression
409 returned from function when that value can be transformed into
410 a named return value. */
412 tree current_function_return_value;
414 /* Set to nonzero by `grokdeclarator' for a function
415 whose return type is defaulted, if warnings for this are desired. */
417 static int warn_about_return_type;
419 /* Nonzero means give `double' the same size as `float'. */
421 extern int flag_short_double;
423 /* Nonzero means don't recognize any builtin functions. */
425 extern int flag_no_builtin;
427 /* Nonzero means don't recognize the non-ANSI builtin functions.
430 extern int flag_no_nonansi_builtin;
432 /* Nonzero means enable obscure ANSI features and disable GNU extensions
433 that might cause ANSI-compliant code to be miscompiled. */
435 extern int flag_ansi;
437 /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
439 extern int flag_huge_objects;
441 /* Nonzero if we want to conserve space in the .o files. We do this
442 by putting uninitialized data and runtime initialized data into
443 .common instead of .data at the expense of not flagging multiple
445 extern int flag_conserve_space;
447 /* Pointers to the base and current top of the language name stack. */
449 extern tree *current_lang_base, *current_lang_stack;
451 /* C and C++ flags are in decl2.c. */
453 /* Set to 0 at beginning of a constructor, set to 1
454 if that function does an allocation before referencing its
455 instance variable. */
456 int current_function_assigns_this;
457 int current_function_just_assigned_this;
459 /* Set to 0 at beginning of a function. Set non-zero when
460 store_parm_decls is called. Don't call store_parm_decls
461 if this flag is non-zero! */
462 int current_function_parms_stored;
464 /* Current end of entries in the gc obstack for stack pointer variables. */
466 int current_function_obstack_index;
468 /* Flag saying whether we have used the obstack in this function or not. */
470 int current_function_obstack_usage;
472 /* Flag used when debugging spew.c */
474 extern int spew_debug;
476 /* This is a copy of the class_shadowed list of the previous class binding
477 contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs
478 when entering another class scope (i.e. a cache miss). */
479 extern tree previous_class_values;
482 /* Allocate a level of searching. */
484 push_decl_level (stack, obstack)
485 struct stack_level *stack;
486 struct obstack *obstack;
488 struct stack_level tem;
491 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
494 /* For each binding contour we allocate a binding_level structure
495 * which records the names defined in that contour.
498 * 1) one for each function definition,
499 * where internal declarations of the parameters appear.
500 * 2) one for each compound statement,
501 * to record its declarations.
503 * The current meaning of a name can be found by searching the levels from
504 * the current one out to the global one.
506 * Off to the side, may be the class_binding_level. This exists
507 * only to catch class-local declarations. It is otherwise
510 * Also there may be binding levels that catch cleanups that
511 * must be run when exceptions occur.
514 /* Note that the information in the `names' component of the global contour
515 is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */
519 /* A chain of _DECL nodes for all variables, constants, functions,
520 * and typedef types. These are in the reverse of the order supplied.
524 /* A list of structure, union and enum definitions,
525 * for looking up tag names.
526 * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
527 * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
528 * or ENUMERAL_TYPE node.
530 * C++: the TREE_VALUE nodes can be simple types for component_bindings.
535 /* For each level, a list of shadowed outer-level local definitions
536 to be restored when this level is popped.
537 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
538 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
541 /* Same, for IDENTIFIER_CLASS_VALUE. */
544 /* Same, for IDENTIFIER_TYPE_VALUE. */
547 /* For each level (except not the global one),
548 a chain of BLOCK nodes for all the levels
549 that were entered and exited one level down. */
552 /* The BLOCK node for this level, if one has been preallocated.
553 If 0, the BLOCK is allocated (if needed) when the level is popped. */
556 /* The binding level which this one is contained in (inherits from). */
557 struct binding_level *level_chain;
559 /* List of decls in `names' that have incomplete
560 structure or union types. */
563 /* List of VAR_DECLS saved from a previous for statement.
564 These would be dead in ANSI-conforming code, but might
565 be referenced in traditional code. */
566 tree dead_vars_from_for;
568 /* 1 for the level that holds the parameters of a function.
569 2 for the level that holds a class declaration.
570 3 for levels that hold parameter declarations. */
571 unsigned parm_flag : 4;
573 /* 1 means make a BLOCK for this level regardless of all else.
574 2 for temporary binding contours created by the compiler. */
577 /* Nonzero if this level "doesn't exist" for tags. */
578 unsigned tag_transparent : 1;
580 /* Nonzero if this level can safely have additional
581 cleanup-needing variables added to it. */
582 unsigned more_cleanups_ok : 1;
583 unsigned have_cleanups : 1;
585 /* Nonzero if we should accept any name as an identifier in
586 this scope. This happens in some template definitions. */
587 unsigned accept_any : 1;
589 /* Nonzero if this level is for completing a template class definition
590 inside a binding level that temporarily binds the parameters. This
591 means that definitions here should not be popped off when unwinding
592 this binding level. (Not actually implemented this way,
594 unsigned pseudo_global : 1;
596 /* This is set for a namespace binding level. */
597 unsigned namespace_p : 1;
599 /* True if this level is that of a for-statement. */
600 unsigned is_for_scope : 1;
602 /* One bit left for this word. */
604 #if defined(DEBUG_CP_BINDING_LEVELS)
605 /* Binding depth at which this level began. */
606 unsigned binding_depth;
607 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
610 #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
612 /* The (non-class) binding level currently in effect. */
614 static struct binding_level *current_binding_level;
616 /* The binding level of the current class, if any. */
618 static struct binding_level *class_binding_level;
620 /* The current (class or non-class) binding level currently in effect. */
622 #define inner_binding_level \
623 (class_binding_level ? class_binding_level : current_binding_level)
625 /* A chain of binding_level structures awaiting reuse. */
627 static struct binding_level *free_binding_level;
629 /* The outermost binding level, for names of file scope.
630 This is created when the compiler is started and exists
631 through the entire run. */
633 static struct binding_level *global_binding_level;
635 /* Binding level structures are initialized by copying this one. */
637 static struct binding_level clear_binding_level;
639 /* Nonzero means unconditionally make a BLOCK for the next level pushed. */
641 static int keep_next_level_flag;
643 #if defined(DEBUG_CP_BINDING_LEVELS)
644 static int binding_depth = 0;
645 static int is_class_level = 0;
652 for (i = 0; i < binding_depth*2; i++)
655 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
657 static tree pushdecl_with_scope PROTO((tree, struct binding_level *));
660 push_binding_level (newlevel, tag_transparent, keep)
661 struct binding_level *newlevel;
662 int tag_transparent, keep;
664 /* Add this level to the front of the chain (stack) of levels that
666 *newlevel = clear_binding_level;
667 if (class_binding_level)
669 newlevel->level_chain = class_binding_level;
670 class_binding_level = (struct binding_level *)0;
674 newlevel->level_chain = current_binding_level;
676 current_binding_level = newlevel;
677 newlevel->tag_transparent = tag_transparent;
678 newlevel->more_cleanups_ok = 1;
679 newlevel->keep = keep;
680 #if defined(DEBUG_CP_BINDING_LEVELS)
681 newlevel->binding_depth = binding_depth;
683 fprintf (stderr, "push %s level 0x%08x line %d\n",
684 (is_class_level) ? "class" : "block", newlevel, lineno);
687 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
693 if (class_binding_level)
694 current_binding_level = class_binding_level;
696 if (global_binding_level)
698 /* cannot pop a level, if there are none left to pop. */
699 if (current_binding_level == global_binding_level)
700 my_friendly_abort (123);
702 /* Pop the current level, and free the structure for reuse. */
703 #if defined(DEBUG_CP_BINDING_LEVELS)
706 fprintf (stderr, "pop %s level 0x%08x line %d\n",
707 (is_class_level) ? "class" : "block",
708 current_binding_level, lineno);
709 if (is_class_level != (current_binding_level == class_binding_level))
710 #if 0 /* XXX Don't abort when we're watching how things are being managed. */
715 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
719 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
721 register struct binding_level *level = current_binding_level;
722 current_binding_level = current_binding_level->level_chain;
723 level->level_chain = free_binding_level;
724 #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
725 if (level->binding_depth != binding_depth)
727 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
728 free_binding_level = level;
730 class_binding_level = current_binding_level;
731 if (class_binding_level->parm_flag != 2)
732 class_binding_level = 0;
733 while (current_binding_level->parm_flag == 2)
734 current_binding_level = current_binding_level->level_chain;
739 suspend_binding_level ()
741 if (class_binding_level)
742 current_binding_level = class_binding_level;
744 if (global_binding_level)
746 /* cannot suspend a level, if there are none left to suspend. */
747 if (current_binding_level == global_binding_level)
748 my_friendly_abort (123);
750 /* Suspend the current level. */
751 #if defined(DEBUG_CP_BINDING_LEVELS)
754 fprintf (stderr, "suspend %s level 0x%08x line %d\n",
755 (is_class_level) ? "class" : "block",
756 current_binding_level, lineno);
757 if (is_class_level != (current_binding_level == class_binding_level))
758 #if 0 /* XXX Don't abort when we're watching how things are being managed. */
763 fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
767 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
769 register struct binding_level *level = current_binding_level;
770 current_binding_level = current_binding_level->level_chain;
771 #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
772 if (level->binding_depth != binding_depth)
774 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
776 class_binding_level = current_binding_level;
777 if (class_binding_level->parm_flag != 2)
778 class_binding_level = 0;
779 while (current_binding_level->parm_flag == 2)
780 current_binding_level = current_binding_level->level_chain;
785 resume_binding_level (b)
786 struct binding_level *b;
788 if (class_binding_level)
791 /* These are here because we cannot deal with shadows yet. */
792 sorry ("cannot resume a namespace inside class");
795 b->level_chain = class_binding_level;
796 class_binding_level = (struct binding_level *)0;
802 /* These are here because we cannot deal with shadows yet. */
803 if (b->level_chain != current_binding_level)
805 sorry ("cannot resume a namespace inside a different namespace");
809 b->level_chain = current_binding_level;
811 current_binding_level = b;
812 #if defined(DEBUG_CP_BINDING_LEVELS)
813 b->binding_depth = binding_depth;
815 fprintf (stderr, "resume %s level 0x%08x line %d\n",
816 (is_class_level) ? "class" : "block", b, lineno);
819 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
822 /* Nonzero if we are currently in the global binding level. */
827 return current_binding_level == global_binding_level;
830 /* Nonzero if we are currently in a toplevel binding level. This
831 means either the global binding level or a namespace in a toplevel
835 toplevel_bindings_p ()
837 struct binding_level *b = current_binding_level;
841 if (b == global_binding_level)
843 if (! b->namespace_p)
849 /* Nonzero if this is a namespace scope. */
852 namespace_bindings_p ()
854 return current_binding_level->namespace_p;
860 keep_next_level_flag = 1;
863 /* Nonzero if the current level needs to have a BLOCK made. */
868 return (current_binding_level->blocks != NULL_TREE
869 || current_binding_level->keep
870 || current_binding_level->names != NULL_TREE
871 || (current_binding_level->tags != NULL_TREE
872 && !current_binding_level->tag_transparent));
875 /* Identify this binding level as a level of parameters. */
878 declare_parm_level ()
880 current_binding_level->parm_flag = 1;
884 declare_uninstantiated_type_level ()
886 current_binding_level->accept_any = 1;
890 uninstantiated_type_level_p ()
892 return current_binding_level->accept_any;
896 declare_pseudo_global_level ()
898 current_binding_level->pseudo_global = 1;
902 declare_namespace_level ()
904 current_binding_level->namespace_p = 1;
908 pseudo_global_level_p ()
910 return current_binding_level->pseudo_global;
914 set_class_shadows (shadows)
917 class_binding_level->class_shadowed = shadows;
920 /* Enter a new binding level.
921 If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
922 not for that of tags. */
925 pushlevel (tag_transparent)
928 register struct binding_level *newlevel = NULL_BINDING_LEVEL;
930 /* If this is the top level of a function,
931 just make sure that NAMED_LABELS is 0.
932 They should have been set to 0 at the end of the previous function. */
934 if (current_binding_level == global_binding_level)
935 my_friendly_assert (named_labels == NULL_TREE, 134);
937 /* Reuse or create a struct for this binding level. */
939 #if defined(DEBUG_CP_BINDING_LEVELS)
941 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
942 if (free_binding_level)
943 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
945 newlevel = free_binding_level;
946 free_binding_level = free_binding_level->level_chain;
950 /* Create a new `struct binding_level'. */
951 newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
953 push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
954 GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
955 keep_next_level_flag = 0;
959 note_level_for_for ()
961 current_binding_level->is_for_scope = 1;
965 pushlevel_temporary (tag_transparent)
968 pushlevel (tag_transparent);
969 current_binding_level->keep = 2;
972 /* Note we don't call push_momentary() here. Otherwise, it would cause
973 cleanups to be allocated on the momentary obstack, and they will be
974 overwritten by the next statement. */
976 expand_start_bindings (0);
979 /* Exit a binding level.
980 Pop the level off, and restore the state of the identifier-decl mappings
981 that were in effect when this level was entered.
983 If KEEP == 1, this level had explicit declarations, so
984 and create a "block" (a BLOCK node) for the level
985 to record its declarations and subblocks for symbol table output.
987 If KEEP == 2, this level's subblocks go to the front,
988 not the back of the current binding level. This happens,
989 for instance, when code for constructors and destructors
990 need to generate code at the end of a function which must
991 be moved up to the front of the function.
993 If FUNCTIONBODY is nonzero, this level is the body of a function,
994 so create a block as if KEEP were set and also clear out all
997 If REVERSE is nonzero, reverse the order of decls before putting
998 them into the BLOCK. */
1001 poplevel (keep, reverse, functionbody)
1007 /* The chain of decls was accumulated in reverse order.
1008 Put it into forward order, just for cleanliness. */
1010 int tmp = functionbody;
1011 int implicit_try_block = current_binding_level->parm_flag == 3;
1012 int real_functionbody = current_binding_level->keep == 2
1013 ? ((functionbody = 0), tmp) : functionbody;
1014 tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
1015 tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
1016 tree block = NULL_TREE;
1018 int block_previously_created;
1020 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
1021 (HOST_WIDE_INT) current_binding_level->level_chain,
1022 current_binding_level->parm_flag,
1023 current_binding_level->keep,
1024 current_binding_level->tag_transparent);
1026 if (current_binding_level->keep == 1)
1029 /* This warning is turned off because it causes warnings for
1030 declarations like `extern struct foo *x'. */
1032 /* Warn about incomplete structure types in this level. */
1033 for (link = tags; link; link = TREE_CHAIN (link))
1034 if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE)
1036 tree type = TREE_VALUE (link);
1038 switch (TREE_CODE (type))
1041 errmsg = "`struct %s' incomplete in scope ending here";
1044 errmsg = "`union %s' incomplete in scope ending here";
1047 errmsg = "`enum %s' incomplete in scope ending here";
1050 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1051 error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
1053 /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */
1054 error (errmsg, TYPE_NAME_STRING (type));
1058 /* Get the decls in the order they were written.
1059 Usually current_binding_level->names is in reverse order.
1060 But parameter decls were previously put in forward order. */
1063 current_binding_level->names
1064 = decls = nreverse (current_binding_level->names);
1066 decls = current_binding_level->names;
1068 /* Output any nested inline functions within this block
1069 if they weren't already output. */
1071 for (decl = decls; decl; decl = TREE_CHAIN (decl))
1072 if (TREE_CODE (decl) == FUNCTION_DECL
1073 && ! TREE_ASM_WRITTEN (decl)
1074 && DECL_INITIAL (decl) != NULL_TREE
1075 && TREE_ADDRESSABLE (decl)
1076 && decl_function_context (decl) == current_function_decl)
1078 /* If this decl was copied from a file-scope decl
1079 on account of a block-scope extern decl,
1080 propagate TREE_ADDRESSABLE to the file-scope decl. */
1081 if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
1082 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
1085 push_function_context ();
1086 output_inline_function (decl);
1087 pop_function_context ();
1091 /* If there were any declarations or structure tags in that level,
1092 or if this level is a function body,
1093 create a BLOCK to record them for the life of this function. */
1096 block_previously_created = (current_binding_level->this_block != NULL_TREE);
1097 if (block_previously_created)
1098 block = current_binding_level->this_block;
1099 else if (keep == 1 || functionbody)
1100 block = make_node (BLOCK);
1101 if (block != NULL_TREE)
1103 if (block_previously_created)
1105 if (decls || tags || subblocks)
1107 if (BLOCK_VARS (block) || BLOCK_TYPE_TAGS (block))
1109 warning ("internal compiler error: debugging info corrupted");
1111 BLOCK_VARS (block) = decls;
1112 BLOCK_TYPE_TAGS (block) = tags;
1114 /* We can have previous subblocks and new subblocks when
1115 doing fixup_gotos with complex cleanups. We chain the new
1116 subblocks onto the end of any pre-existing subblocks. */
1117 BLOCK_SUBBLOCKS (block) = chainon (BLOCK_SUBBLOCKS (block),
1120 /* If we created the block earlier on, and we are just
1121 diddling it now, then it already should have a proper
1122 BLOCK_END_NOTE value associated with it. */
1126 BLOCK_VARS (block) = decls;
1127 BLOCK_TYPE_TAGS (block) = tags;
1128 BLOCK_SUBBLOCKS (block) = subblocks;
1129 /* Otherwise, for a new block, install a new BLOCK_END_NOTE value. */
1130 remember_end_note (block);
1134 /* In each subblock, record that this is its superior. */
1137 for (link = subblocks; link; link = TREE_CHAIN (link))
1138 BLOCK_SUPERCONTEXT (link) = block;
1140 /* Clear out the meanings of the local variables of this level. */
1142 for (link = current_binding_level->dead_vars_from_for;
1143 link != NULL_TREE; link = TREE_CHAIN (link))
1145 if (DECL_DEAD_FOR_LOCAL (link))
1147 tree id = DECL_NAME (link);
1148 if (IDENTIFIER_LOCAL_VALUE (id) == link)
1149 IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link);
1153 if (current_binding_level->is_for_scope && flag_new_for_scope == 1)
1155 for (link = decls; link; link = TREE_CHAIN (link))
1157 if (TREE_CODE (link) == VAR_DECL)
1158 DECL_DEAD_FOR_LOCAL (link) = 1;
1163 for (link = decls; link; link = TREE_CHAIN (link))
1165 if (DECL_NAME (link) != NULL_TREE)
1167 /* If the ident. was used or addressed via a local extern decl,
1168 don't forget that fact. */
1169 if (DECL_EXTERNAL (link))
1171 if (TREE_USED (link))
1172 TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
1173 if (TREE_ADDRESSABLE (link))
1174 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1176 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
1181 /* Restore all name-meanings of the outer levels
1182 that were shadowed by this level. */
1184 if (current_binding_level->is_for_scope && flag_new_for_scope == 1)
1186 struct binding_level *outer = current_binding_level->level_chain;
1187 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1189 tree id = TREE_PURPOSE (link);
1190 tree decl = IDENTIFIER_LOCAL_VALUE (id);
1191 if (DECL_DEAD_FOR_LOCAL (decl))
1192 DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link);
1194 IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link);
1197 /* Save declarations made in a 'for' statement so we can support pre-ANSI
1198 'for' scoping semantics. */
1200 /* We append the current names of for-variables to those from previous
1201 declarations, so that when we get around to do an poplevel
1202 on the OUTER level, we restore the any shadowed readl bindings.
1203 Note that the new names are put first on the combined list,
1204 so they get to be restored first. This is important if there are
1205 two for-loops using the same for-variable in the same block.
1206 The binding we really want restored is whatever binding was shadowed
1207 by the *first* for-variable, not the binding shadowed by the
1208 second for-variable (which would be the first for-variable). */
1209 outer->dead_vars_from_for
1210 = chainon (current_binding_level->names, outer->dead_vars_from_for);
1214 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1215 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1217 for (link = current_binding_level->class_shadowed;
1218 link; link = TREE_CHAIN (link))
1219 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1220 for (link = current_binding_level->type_shadowed;
1221 link; link = TREE_CHAIN (link))
1222 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1224 /* If the level being exited is the top level of a function,
1225 check over all the labels. */
1229 /* If this is the top level block of a function,
1230 the vars are the function's parameters.
1231 Don't leave them in the BLOCK because they are
1232 found in the FUNCTION_DECL instead. */
1234 BLOCK_VARS (block) = 0;
1236 /* Clear out the definitions of all label names,
1237 since their scopes end here. */
1239 for (link = named_labels; link; link = TREE_CHAIN (link))
1241 register tree label = TREE_VALUE (link);
1243 if (DECL_INITIAL (label) == NULL_TREE)
1245 cp_error_at ("label `%D' used but not defined", label);
1246 /* Avoid crashing later. */
1247 define_label (input_filename, 1, DECL_NAME (label));
1249 else if (warn_unused && !TREE_USED (label))
1250 cp_warning_at ("label `%D' defined but not used", label);
1251 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
1253 /* Put the labels into the "variables" of the
1254 top-level block, so debugger can see them. */
1255 TREE_CHAIN (label) = BLOCK_VARS (block);
1256 BLOCK_VARS (block) = label;
1259 named_labels = NULL_TREE;
1262 /* Any uses of undefined labels now operate under constraints
1263 of next binding contour. */
1265 struct binding_level *level_chain;
1266 level_chain = current_binding_level->level_chain;
1270 for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
1271 if (TREE_TYPE (labels) == (tree)current_binding_level)
1273 TREE_TYPE (labels) = (tree)level_chain;
1274 TREE_PURPOSE (labels) = level_chain->names;
1279 tmp = current_binding_level->keep;
1281 pop_binding_level ();
1283 DECL_INITIAL (current_function_decl) = block;
1286 if (!block_previously_created)
1287 current_binding_level->blocks
1288 = chainon (current_binding_level->blocks, block);
1290 /* If we did not make a block for the level just exited,
1291 any blocks made for inner levels
1292 (since they cannot be recorded as subblocks in that level)
1293 must be carried forward so they will later become subblocks
1294 of something else. */
1298 current_binding_level->blocks
1299 = chainon (subblocks, current_binding_level->blocks);
1301 current_binding_level->blocks
1302 = chainon (current_binding_level->blocks, subblocks);
1305 /* Take care of compiler's internal binding structures. */
1309 /* We did not call push_momentary for this
1310 binding contour, so there is nothing to pop. */
1313 expand_end_bindings (getdecls (), keep, 1);
1314 /* Each and every BLOCK node created here in `poplevel' is important
1315 (e.g. for proper debugging information) so if we created one
1316 earlier, mark it as "used". */
1318 TREE_USED (block) = 1;
1319 block = poplevel (keep, reverse, real_functionbody);
1322 /* Each and every BLOCK node created here in `poplevel' is important
1323 (e.g. for proper debugging information) so if we created one
1324 earlier, mark it as "used". */
1326 TREE_USED (block) = 1;
1330 /* Resume a binding level for a namespace. */
1333 struct binding_level *b;
1337 resume_binding_level (b);
1339 /* Resume the variable caches. */
1340 decls = current_binding_level->names;
1342 /* Restore the meanings of the local variables of this level. */
1344 for (link = decls; link; link = TREE_CHAIN (link))
1346 if (DECL_NAME (link) != NULL_TREE)
1347 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link;
1349 /* If this is a TYPE_DECL, push it into the type value slot. */
1350 if (TREE_CODE (link) == TYPE_DECL)
1351 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link));
1355 /* Delete the node BLOCK from the current binding level.
1356 This is used for the block inside a stmt expr ({...})
1357 so that the block can be reinserted where appropriate. */
1360 delete_block (block)
1364 if (current_binding_level->blocks == block)
1365 current_binding_level->blocks = TREE_CHAIN (block);
1366 for (t = current_binding_level->blocks; t;)
1368 if (TREE_CHAIN (t) == block)
1369 TREE_CHAIN (t) = TREE_CHAIN (block);
1373 TREE_CHAIN (block) = NULL_TREE;
1374 /* Clear TREE_USED which is always set by poplevel.
1375 The flag is set again if insert_block is called. */
1376 TREE_USED (block) = 0;
1379 /* Insert BLOCK at the end of the list of subblocks of the
1380 current binding level. This is used when a BIND_EXPR is expanded,
1381 to handle the BLOCK node inside the BIND_EXPR. */
1384 insert_block (block)
1387 TREE_USED (block) = 1;
1388 current_binding_level->blocks
1389 = chainon (current_binding_level->blocks, block);
1392 /* Add BLOCK to the current list of blocks for this binding contour. */
1394 add_block_current_level (block)
1397 current_binding_level->blocks
1398 = chainon (current_binding_level->blocks, block);
1401 /* Set the BLOCK node for the innermost scope
1402 (the one we are currently in). */
1406 register tree block;
1408 current_binding_level->this_block = block;
1411 /* Do a pushlevel for class declarations. */
1415 register struct binding_level *newlevel;
1417 /* Reuse or create a struct for this binding level. */
1418 #if defined(DEBUG_CP_BINDING_LEVELS)
1420 #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
1421 if (free_binding_level)
1422 #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
1424 newlevel = free_binding_level;
1425 free_binding_level = free_binding_level->level_chain;
1429 /* Create a new `struct binding_level'. */
1430 newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
1433 #if defined(DEBUG_CP_BINDING_LEVELS)
1435 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1437 push_binding_level (newlevel, 0, 0);
1439 decl_stack = push_decl_level (decl_stack, &decl_obstack);
1440 class_binding_level = current_binding_level;
1441 class_binding_level->parm_flag = 2;
1442 /* We have just pushed into a new binding level. Now, fake out the rest
1443 of the compiler. Set the `current_binding_level' back to point to
1444 the most closely containing non-class binding level. */
1447 current_binding_level = current_binding_level->level_chain;
1449 while (current_binding_level->parm_flag == 2);
1452 /* ...and a poplevel for class declarations. FORCE is used to force
1453 clearing out of CLASS_VALUEs after a class definition. */
1455 poplevel_class (force)
1458 register struct binding_level *level = class_binding_level;
1459 tree block = NULL_TREE;
1462 my_friendly_assert (level != 0, 354);
1464 decl_stack = pop_stack_level (decl_stack);
1465 for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
1466 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1467 /* If we're leaving a toplevel class, don't bother to do the setting
1468 of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot
1469 shouldn't even be used when current_class_type isn't set, and second,
1470 if we don't touch it here, we're able to use the cache effect if the
1471 next time we're entering a class scope, it is the same class. */
1472 if (current_class_depth != 1 || force)
1473 for (shadowed = level->class_shadowed;
1475 shadowed = TREE_CHAIN (shadowed))
1476 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1478 /* Remember to save what IDENTIFIER's were bound in this scope so we
1479 can recover from cache misses. */
1480 previous_class_values = class_binding_level->class_shadowed;
1481 for (shadowed = level->type_shadowed;
1483 shadowed = TREE_CHAIN (shadowed))
1484 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
1486 GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
1487 (HOST_WIDE_INT) class_binding_level->level_chain,
1488 class_binding_level->parm_flag,
1489 class_binding_level->keep,
1490 class_binding_level->tag_transparent);
1492 if (class_binding_level->parm_flag != 2)
1493 class_binding_level = (struct binding_level *)0;
1495 /* Now, pop out of the the binding level which we created up in the
1496 `pushlevel_class' routine. */
1497 #if defined(DEBUG_CP_BINDING_LEVELS)
1499 #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
1501 pop_binding_level ();
1506 /* For debugging. */
1507 int no_print_functions = 0;
1508 int no_print_builtins = 0;
1511 print_binding_level (lvl)
1512 struct binding_level *lvl;
1516 fprintf (stderr, " blocks=");
1517 fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
1518 fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
1519 list_length (lvl->incomplete), lvl->parm_flag, lvl->keep);
1520 if (lvl->tag_transparent)
1521 fprintf (stderr, " tag-transparent");
1522 if (lvl->more_cleanups_ok)
1523 fprintf (stderr, " more-cleanups-ok");
1524 if (lvl->have_cleanups)
1525 fprintf (stderr, " have-cleanups");
1526 fprintf (stderr, "\n");
1529 fprintf (stderr, " names:\t");
1530 /* We can probably fit 3 names to a line? */
1531 for (t = lvl->names; t; t = TREE_CHAIN (t))
1533 if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL))
1535 if (no_print_builtins
1536 && (TREE_CODE(t) == TYPE_DECL)
1537 && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
1540 /* Function decls tend to have longer names. */
1541 if (TREE_CODE (t) == FUNCTION_DECL)
1548 fprintf (stderr, "\n\t");
1551 print_node_brief (stderr, "", t, 0);
1552 if (TREE_CODE (t) == ERROR_MARK)
1556 fprintf (stderr, "\n");
1560 fprintf (stderr, " tags:\t");
1562 for (t = lvl->tags; t; t = TREE_CHAIN (t))
1564 if (TREE_PURPOSE (t) == NULL_TREE)
1566 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1573 fprintf (stderr, "\n\t");
1576 if (TREE_PURPOSE (t) == NULL_TREE)
1578 print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
1579 fprintf (stderr, ">");
1581 else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
1582 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1585 print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
1586 print_node_brief (stderr, "", TREE_VALUE (t), 0);
1587 fprintf (stderr, ">");
1591 fprintf (stderr, "\n");
1595 fprintf (stderr, " shadowed:");
1596 for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
1598 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1600 fprintf (stderr, "\n");
1602 if (lvl->class_shadowed)
1604 fprintf (stderr, " class-shadowed:");
1605 for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
1607 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1609 fprintf (stderr, "\n");
1611 if (lvl->type_shadowed)
1613 fprintf (stderr, " type-shadowed:");
1614 for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
1617 fprintf (stderr, "\n\t");
1618 print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
1620 print_node_brief (stderr, " ", TREE_VALUE (t), 0);
1622 fprintf (stderr, " (none)");
1623 fprintf (stderr, ">");
1625 fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
1628 fprintf (stderr, "\n");
1633 print_other_binding_stack (stack)
1634 struct binding_level *stack;
1636 struct binding_level *level;
1637 for (level = stack; level != global_binding_level; level = level->level_chain)
1639 fprintf (stderr, "binding level ");
1640 fprintf (stderr, HOST_PTR_PRINTF, level);
1641 fprintf (stderr, "\n");
1642 print_binding_level (level);
1647 print_binding_stack ()
1649 struct binding_level *b;
1650 fprintf (stderr, "current_binding_level=");
1651 fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
1652 fprintf (stderr, "\nclass_binding_level=");
1653 fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
1654 fprintf (stderr, "\nglobal_binding_level=");
1655 fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
1656 fprintf (stderr, "\n");
1657 if (class_binding_level)
1659 for (b = class_binding_level; b; b = b->level_chain)
1660 if (b == current_binding_level)
1663 b = class_binding_level;
1665 b = current_binding_level;
1668 b = current_binding_level;
1669 print_other_binding_stack (b);
1670 fprintf (stderr, "global:\n");
1671 print_binding_level (global_binding_level);
1674 extern char * first_global_object_name;
1676 /* Get a unique name for each call to this routine for unnamed namespaces.
1677 Mostly copied from get_file_function_name. */
1681 static int temp_name_counter = 0;
1685 if (first_global_object_name)
1686 p = first_global_object_name;
1687 else if (main_input_filename)
1688 p = main_input_filename;
1692 #define UNNAMED_NAMESPACE_FORMAT "__%s_%d"
1694 buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p));
1696 sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++);
1698 /* Don't need to pull weird characters out of global names. */
1699 if (p != first_global_object_name)
1701 for (p = buf+11; *p; p++)
1702 if (! ((*p >= '0' && *p <= '9')
1703 #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
1704 #ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */
1708 #ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */
1711 #ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */
1714 || (*p >= 'A' && *p <= 'Z')
1715 || (*p >= 'a' && *p <= 'z')))
1719 return get_identifier (buf);
1722 /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we
1723 select a name that is unique to this compilation unit. */
1725 push_namespace (name)
1728 extern tree current_namespace;
1729 tree old_id = get_namespace_id ();
1735 /* Create a truly ugly name! */
1736 name = get_unique_name ();
1739 d = build_lang_decl (NAMESPACE_DECL, name, void_type_node);
1741 /* Mark them as external, so redeclaration_error_message doesn't think
1742 they are duplicates. */
1744 DECL_EXTERNAL (d) = 1;
1747 if (NAMESPACE_LEVEL (d) == 0)
1749 /* This is new for this compilation unit. */
1751 declare_namespace_level ();
1752 NAMESPACE_LEVEL (d) = current_binding_level;
1755 resume_level (NAMESPACE_LEVEL (d));
1757 /* This code is just is bit old now... */
1758 current_namespace = tree_cons (NULL_TREE, name, current_namespace);
1759 buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0)
1760 + IDENTIFIER_LENGTH (name));
1761 sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "",
1762 IDENTIFIER_POINTER (name));
1763 TREE_PURPOSE (current_namespace) = get_identifier (buf);
1766 /* Pop from the scope of the current namespace. */
1770 extern tree current_namespace;
1772 current_namespace = TREE_CHAIN (current_namespace);
1774 /* Just in case we get out of sync. */
1775 if (! namespace_bindings_p ())
1778 decls = current_binding_level->names;
1780 /* Clear out the meanings of the local variables of this level. */
1782 for (link = decls; link; link = TREE_CHAIN (link))
1784 if (DECL_NAME (link) != NULL_TREE)
1786 /* If the ident. was used or addressed via a local extern decl,
1787 don't forget that fact. */
1788 if (DECL_EXTERNAL (link))
1790 if (TREE_USED (link))
1791 TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
1792 if (TREE_ADDRESSABLE (link))
1793 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
1795 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
1799 /* Restore all name-meanings of the outer levels
1800 that were shadowed by this level. */
1802 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
1803 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1804 for (link = current_binding_level->class_shadowed;
1805 link; link = TREE_CHAIN (link))
1806 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1807 for (link = current_binding_level->type_shadowed;
1808 link; link = TREE_CHAIN (link))
1809 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
1811 /* suspend a level. */
1812 suspend_binding_level ();
1815 /* Subroutines for reverting temporarily to top-level for instantiation
1816 of templates and such. We actually need to clear out the class- and
1817 local-value slots of all identifiers, so that only the global values
1818 are at all visible. Simply setting current_binding_level to the global
1819 scope isn't enough, because more binding levels may be pushed. */
1820 struct saved_scope {
1821 struct binding_level *old_binding_level;
1823 struct saved_scope *prev;
1824 tree class_name, class_type, function_decl;
1825 tree base_init_list, member_init_list;
1826 struct binding_level *class_bindings;
1827 tree previous_class_type;
1828 tree *lang_base, *lang_stack, lang_name;
1832 static struct saved_scope *current_saved_scope;
1833 extern tree prev_class_type;
1836 push_to_top_level ()
1838 extern int current_lang_stacksize;
1839 struct saved_scope *s =
1840 (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
1841 struct binding_level *b = current_binding_level;
1842 tree old_bindings = NULL_TREE;
1844 /* Have to include global_binding_level, because class-level decls
1845 aren't listed anywhere useful. */
1846 for (; b; b = b->level_chain)
1850 if (b == global_binding_level)
1853 for (t = b->names; t; t = TREE_CHAIN (t))
1855 tree binding, t1, t2 = t;
1856 tree id = DECL_ASSEMBLER_NAME (t2);
1859 || (!IDENTIFIER_LOCAL_VALUE (id)
1860 && !IDENTIFIER_CLASS_VALUE (id)))
1863 for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
1864 if (TREE_VEC_ELT (t1, 0) == id)
1867 binding = make_tree_vec (4);
1870 my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
1871 TREE_VEC_ELT (binding, 0) = id;
1872 TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
1873 TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
1874 TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
1875 IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
1876 IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
1878 TREE_CHAIN (binding) = old_bindings;
1879 old_bindings = binding;
1883 /* Unwind type-value slots back to top level. */
1884 for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
1885 SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
1887 /* Clear out class-level bindings cache. */
1888 if (current_binding_level == global_binding_level
1889 && previous_class_type != NULL_TREE)
1892 previous_class_type = NULL_TREE;
1895 s->old_binding_level = current_binding_level;
1896 current_binding_level = global_binding_level;
1898 s->class_name = current_class_name;
1899 s->class_type = current_class_type;
1900 s->function_decl = current_function_decl;
1901 s->base_init_list = current_base_init_list;
1902 s->member_init_list = current_member_init_list;
1903 s->class_bindings = class_binding_level;
1904 s->previous_class_type = previous_class_type;
1905 s->lang_stack = current_lang_stack;
1906 s->lang_base = current_lang_base;
1907 s->lang_stacksize = current_lang_stacksize;
1908 s->lang_name = current_lang_name;
1909 s->named_labels = named_labels;
1910 current_class_name = current_class_type = NULL_TREE;
1911 current_function_decl = NULL_TREE;
1912 class_binding_level = (struct binding_level *)0;
1913 previous_class_type = NULL_TREE;
1914 current_lang_stacksize = 10;
1915 current_lang_stack = current_lang_base
1916 = (tree *) xmalloc (current_lang_stacksize * sizeof (tree));
1917 current_lang_name = lang_name_cplusplus;
1918 strict_prototype = strict_prototypes_lang_cplusplus;
1919 named_labels = NULL_TREE;
1921 s->prev = current_saved_scope;
1922 s->old_bindings = old_bindings;
1923 current_saved_scope = s;
1927 pop_from_top_level ()
1929 extern int current_lang_stacksize;
1930 struct saved_scope *s = current_saved_scope;
1933 if (previous_class_type)
1934 previous_class_type = NULL_TREE;
1936 current_binding_level = s->old_binding_level;
1937 current_saved_scope = s->prev;
1938 for (t = s->old_bindings; t; t = TREE_CHAIN (t))
1940 tree id = TREE_VEC_ELT (t, 0);
1943 IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
1944 IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
1945 IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
1948 current_class_name = s->class_name;
1949 current_class_type = s->class_type;
1950 current_base_init_list = s->base_init_list;
1951 current_member_init_list = s->member_init_list;
1952 current_function_decl = s->function_decl;
1953 class_binding_level = s->class_bindings;
1954 previous_class_type = s->previous_class_type;
1955 free (current_lang_base);
1956 current_lang_base = s->lang_base;
1957 current_lang_stack = s->lang_stack;
1958 current_lang_name = s->lang_name;
1959 current_lang_stacksize = s->lang_stacksize;
1960 if (current_lang_name == lang_name_cplusplus)
1961 strict_prototype = strict_prototypes_lang_cplusplus;
1962 else if (current_lang_name == lang_name_c)
1963 strict_prototype = strict_prototypes_lang_c;
1964 named_labels = s->named_labels;
1969 /* Push a definition of struct, union or enum tag "name".
1970 into binding_level "b". "type" should be the type node,
1971 We assume that the tag "name" is not already defined.
1973 Note that the definition may really be just a forward reference.
1974 In that case, the TYPE_SIZE will be a NULL_TREE.
1976 C++ gratuitously puts all these tags in the name space. */
1978 /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
1979 record the shadowed value for this binding contour. TYPE is
1980 the type that ID maps to. */
1983 set_identifier_type_value_with_scope (id, type, b)
1986 struct binding_level *b;
1988 if (b != global_binding_level)
1990 tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
1992 = tree_cons (id, old_type_value, b->type_shadowed);
1994 SET_IDENTIFIER_TYPE_VALUE (id, type);
1997 /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
2000 set_identifier_type_value (id, type)
2004 set_identifier_type_value_with_scope (id, type, inner_binding_level);
2007 /* Subroutine "set_nested_typename" builds the nested-typename of
2008 the type decl in question. (Argument CLASSNAME can actually be
2009 a function as well, if that's the smallest containing scope.) */
2012 set_nested_typename (decl, classname, name, type)
2013 tree decl, classname, name, type;
2016 my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
2018 /* No need to do this for anonymous names, since they're unique. */
2019 if (ANON_AGGRNAME_P (name))
2021 DECL_NESTED_TYPENAME (decl) = name;
2025 if (classname == NULL_TREE)
2026 classname = get_identifier ("");
2028 my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
2029 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
2030 buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
2031 + IDENTIFIER_LENGTH (name));
2032 sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
2033 IDENTIFIER_POINTER (name));
2034 DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
2035 TREE_MANGLED (DECL_NESTED_TYPENAME (decl)) = 1;
2037 /* Create an extra decl so that the nested name will have a type value
2038 where appropriate. */
2040 tree nested, type_decl;
2041 nested = DECL_NESTED_TYPENAME (decl);
2042 type_decl = build_decl (TYPE_DECL, nested, type);
2043 DECL_NESTED_TYPENAME (type_decl) = nested;
2044 SET_DECL_ARTIFICIAL (type_decl);
2045 /* Mark the TYPE_DECL node created just above as a gratuitous one so that
2046 dwarfout.c will know not to generate a TAG_typedef DIE for it, and
2047 sdbout.c won't try to output a .def for "::foo". */
2048 DECL_IGNORED_P (type_decl) = 1;
2050 /* Remove this when local classes are fixed. */
2051 SET_IDENTIFIER_TYPE_VALUE (nested, type);
2053 pushdecl_nonclass_level (type_decl);
2057 /* Pop off extraneous binding levels left over due to syntax errors.
2059 We don't pop past namespaces, as they might be valid. */
2063 #ifdef DEBUG_CP_BINDING_LEVELS
2064 fprintf (stderr, "XXX entering pop_everything ()\n");
2066 while (! toplevel_bindings_p () && ! pseudo_global_level_p ())
2068 if (class_binding_level)
2069 pop_nested_class (1);
2073 #ifdef DEBUG_CP_BINDING_LEVELS
2074 fprintf (stderr, "XXX leaving pop_everything ()\n");
2078 #if 0 /* not yet, should get fixed properly later */
2079 /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
2080 Other routines shouldn't use build_decl directly; they'll produce
2081 incorrect results with `-g' unless they duplicate this code.
2083 This is currently needed mainly for dbxout.c, but we can make
2084 use of it in method.c later as well. */
2086 make_type_decl (name, type)
2090 decl = build_decl (TYPE_DECL, name, type);
2091 if (TYPE_NAME (type) == name)
2092 /* Class/union/enum definition, or a redundant typedef for same. */
2094 id = get_identifier (build_overload_name (type, 1, 1));
2095 DECL_ASSEMBLER_NAME (decl) = id;
2097 else if (TYPE_NAME (type) != NULL_TREE)
2098 /* Explicit typedef, or implicit typedef for template expansion. */
2099 DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
2102 /* XXX: Typedef for unnamed struct; some other situations.
2103 TYPE_NAME is null; what's right here? */
2109 /* Push a tag name NAME for struct/class/union/enum type TYPE.
2110 Normally put into into the inner-most non-tag-transparent scope,
2111 but if GLOBALIZE is true, put it in the inner-most non-class scope.
2112 The latter is needed for implicit declarations. */
2115 pushtag (name, type, globalize)
2119 register struct binding_level *b;
2123 b = inner_binding_level;
2124 while (b->tag_transparent
2125 || (globalize && b->parm_flag == 2))
2128 if (toplevel_bindings_p ())
2129 b->tags = perm_tree_cons (name, type, b->tags);
2131 b->tags = saveable_tree_cons (name, type, b->tags);
2135 context = type ? TYPE_CONTEXT (type) : NULL_TREE;
2136 if (! context && ! globalize)
2137 context = current_scope ();
2139 c_decl = TREE_CODE (context) == FUNCTION_DECL
2140 ? context : TYPE_MAIN_DECL (context);
2143 /* Record the identifier as the type's name if it has none. */
2144 if (TYPE_NAME (type) == NULL_TREE)
2145 TYPE_NAME (type) = name;
2148 /* Do C++ gratuitous typedefing. */
2149 if (IDENTIFIER_TYPE_VALUE (name) != type)
2154 if (b->parm_flag != 2
2155 || TYPE_SIZE (current_class_type) != NULL_TREE)
2157 d = lookup_nested_type (type, c_decl);
2162 #if 0 /* not yet, should get fixed properly later */
2163 d = make_type_decl (name, type);
2165 d = build_decl (TYPE_DECL, name, type);
2166 DECL_ASSEMBLER_NAME (d) = current_namespace_id (DECL_ASSEMBLER_NAME (d));
2168 SET_DECL_ARTIFICIAL (d);
2169 #ifdef DWARF_DEBUGGING_INFO
2170 if (write_symbols == DWARF_DEBUG)
2172 /* Mark the TYPE_DECL node we created just above as an
2173 gratuitous one. We need to do this so that dwarfout.c
2174 will understand that it is not supposed to output a
2175 TAG_typedef DIE for it. */
2176 DECL_IGNORED_P (d) = 1;
2178 #endif /* DWARF_DEBUGGING_INFO */
2179 set_identifier_type_value_with_scope (name, type, b);
2184 TYPE_NAME (type) = d;
2186 /* If it is anonymous, then we are called from pushdecl,
2187 and we don't want to infinitely recurse. */
2188 if (! ANON_AGGRNAME_P (name))
2190 if (b->parm_flag == 2)
2191 d = pushdecl_class_level (d);
2193 d = pushdecl_with_scope (d, b);
2198 /* Make nested declarations go into class-level scope. */
2200 d = build_decl (TYPE_DECL, name, type);
2201 SET_DECL_ARTIFICIAL (d);
2202 #ifdef DWARF_DEBUGGING_INFO
2203 if (write_symbols == DWARF_DEBUG)
2205 /* Mark the TYPE_DECL node we created just above as an
2206 gratuitous one. We need to do this so that dwarfout.c
2207 will understand that it is not supposed to output a
2208 TAG_typedef DIE for it. */
2209 DECL_IGNORED_P (d) = 1;
2211 #endif /* DWARF_DEBUGGING_INFO */
2213 TYPE_MAIN_DECL (type) = d;
2215 /* Make sure we're in this type's scope when we push the
2216 decl for a template, otherwise class_binding_level will
2217 be NULL and we'll end up dying inside of
2218 push_class_level_binding. */
2219 if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
2220 pushclass (type, 0);
2221 d = pushdecl_class_level (d);
2222 if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
2227 if (write_symbols != DWARF_DEBUG)
2229 if (ANON_AGGRNAME_P (name))
2230 DECL_IGNORED_P (d) = 1;
2233 if (context == NULL_TREE)
2234 /* Non-nested class. */
2235 set_nested_typename (d, NULL_TREE, name, type);
2236 else if (context && TREE_CODE (context) == FUNCTION_DECL)
2237 /* Function-nested class. */
2238 set_nested_typename (d, DECL_ASSEMBLER_NAME (c_decl),
2240 else /* if (context && IS_AGGR_TYPE (context)) */
2241 /* Class-nested class. */
2242 set_nested_typename (d, DECL_NESTED_TYPENAME (c_decl),
2245 DECL_CONTEXT (d) = context;
2246 TYPE_CONTEXT (type) = DECL_CONTEXT (d);
2247 DECL_ASSEMBLER_NAME (d)
2248 = get_identifier (build_overload_name (type, 1, 1));
2251 if (b->parm_flag == 2)
2253 TREE_NONLOCAL_FLAG (type) = 1;
2254 if (TYPE_SIZE (current_class_type) == NULL_TREE)
2255 CLASSTYPE_TAGS (current_class_type) = b->tags;
2259 if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2260 /* Use the canonical TYPE_DECL for this node. */
2261 TYPE_STUB_DECL (type) = TYPE_NAME (type);
2264 /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
2265 will be the tagged type we just added to the current
2266 binding level. This fake NULL-named TYPE_DECL node helps
2267 dwarfout.c to know when it needs to output a
2268 representation of a tagged type, and it also gives us a
2269 convenient place to record the "scope start" address for
2272 #if 0 /* not yet, should get fixed properly later */
2273 tree d = make_type_decl (NULL_TREE, type);
2275 tree d = build_decl (TYPE_DECL, NULL_TREE, type);
2277 TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
2281 /* Counter used to create anonymous type names. */
2282 static int anon_cnt = 0;
2284 /* Return an IDENTIFIER which can be used as a name for
2285 anonymous structs and unions. */
2291 sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
2292 return get_identifier (buf);
2295 /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
2296 This keeps dbxout from getting confused. */
2300 register struct binding_level *b;
2302 static int last_cnt = 0;
2304 /* Fast out if no new anon names were declared. */
2305 if (last_cnt == anon_cnt)
2308 b = current_binding_level;
2309 while (b->tag_transparent)
2314 /* A NULL purpose means we have already processed all tags
2315 from here to the end of the list. */
2316 if (TREE_PURPOSE (tags) == NULL_TREE)
2318 if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
2319 TREE_PURPOSE (tags) = NULL_TREE;
2320 tags = TREE_CHAIN (tags);
2322 last_cnt = anon_cnt;
2325 /* Subroutine of duplicate_decls: return truthvalue of whether
2326 or not types of these decls match.
2328 For C++, we must compare the parameter list so that `int' can match
2329 `int&' in a parameter position, but `int&' is not confused with
2332 decls_match (newdecl, olddecl)
2333 tree newdecl, olddecl;
2337 if (TREE_CODE (newdecl) == FUNCTION_DECL
2338 && TREE_CODE (olddecl) == FUNCTION_DECL)
2340 tree f1 = TREE_TYPE (newdecl);
2341 tree f2 = TREE_TYPE (olddecl);
2342 tree p1 = TYPE_ARG_TYPES (f1);
2343 tree p2 = TYPE_ARG_TYPES (f2);
2345 /* When we parse a static member function definition,
2346 we put together a FUNCTION_DECL which thinks its type
2347 is METHOD_TYPE. Change that to FUNCTION_TYPE, and
2349 if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
2350 revert_static_member_fn (&newdecl, &f1, &p1);
2351 else if (TREE_CODE (f2) == METHOD_TYPE
2352 && DECL_STATIC_FUNCTION_P (newdecl))
2353 revert_static_member_fn (&olddecl, &f2, &p2);
2355 /* Here we must take care of the case where new default
2356 parameters are specified. Also, warn if an old
2357 declaration becomes ambiguous because default
2358 parameters may cause the two to be ambiguous. */
2359 if (TREE_CODE (f1) != TREE_CODE (f2))
2361 if (TREE_CODE (f1) == OFFSET_TYPE)
2362 cp_compiler_error ("`%D' redeclared as member function", newdecl);
2364 cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
2368 if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1))
2370 if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c
2373 types_match = self_promoting_args_p (p1);
2374 if (p1 == void_list_node)
2375 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
2377 else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c
2378 && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE)
2380 types_match = self_promoting_args_p (p2);
2381 TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
2384 types_match = compparms (p1, p2, 3);
2389 else if (TREE_CODE (newdecl) == TEMPLATE_DECL
2390 && TREE_CODE (olddecl) == TEMPLATE_DECL)
2392 tree newargs = DECL_TEMPLATE_PARMS (newdecl);
2393 tree oldargs = DECL_TEMPLATE_PARMS (olddecl);
2394 int i, len = TREE_VEC_LENGTH (newargs);
2396 if (TREE_VEC_LENGTH (oldargs) != len)
2399 for (i = 0; i < len; i++)
2401 tree newarg = TREE_VALUE (TREE_VEC_ELT (newargs, i));
2402 tree oldarg = TREE_VALUE (TREE_VEC_ELT (oldargs, i));
2403 if (TREE_CODE (newarg) != TREE_CODE (oldarg))
2405 else if (TREE_CODE (newarg) == TYPE_DECL)
2407 else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1))
2411 if (DECL_TEMPLATE_IS_CLASS (newdecl)
2412 != DECL_TEMPLATE_IS_CLASS (olddecl))
2414 else if (DECL_TEMPLATE_IS_CLASS (newdecl))
2417 types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
2418 DECL_TEMPLATE_RESULT (newdecl));
2422 if (TREE_TYPE (newdecl) == error_mark_node)
2423 types_match = TREE_TYPE (olddecl) == error_mark_node;
2424 else if (TREE_TYPE (olddecl) == NULL_TREE)
2425 types_match = TREE_TYPE (newdecl) == NULL_TREE;
2426 else if (TREE_TYPE (newdecl) == NULL_TREE)
2428 /* Qualifiers must match, and they may be present on either, the type
2430 else if ((TREE_READONLY (newdecl)
2431 || TYPE_READONLY (TREE_TYPE (newdecl)))
2432 == (TREE_READONLY (olddecl)
2433 || TYPE_READONLY (TREE_TYPE (olddecl)))
2434 && (TREE_THIS_VOLATILE (newdecl)
2435 || TYPE_VOLATILE (TREE_TYPE (newdecl)))
2436 == (TREE_THIS_VOLATILE (olddecl)
2437 || TYPE_VOLATILE (TREE_TYPE (olddecl))))
2438 types_match = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (newdecl)),
2439 TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)), 1);
2447 /* If NEWDECL is `static' and an `extern' was seen previously,
2448 warn about it. (OLDDECL may be NULL_TREE; NAME contains
2449 information about previous usage as an `extern'.)
2451 Note that this does not apply to the C++ case of declaring
2452 a variable `extern const' and then later `const'.
2454 Don't complain if -traditional, since traditional compilers
2457 Don't complain about built-in functions, since they are beyond
2458 the user's control. */
2461 warn_extern_redeclared_static (newdecl, olddecl)
2462 tree newdecl, olddecl;
2466 static char *explicit_extern_static_warning
2467 = "`%D' was declared `extern' and later `static'";
2468 static char *implicit_extern_static_warning
2469 = "`%D' was declared implicitly `extern' and later `static'";
2471 if (flag_traditional
2472 || TREE_CODE (newdecl) == TYPE_DECL)
2475 name = DECL_ASSEMBLER_NAME (newdecl);
2476 if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl))
2478 /* It's okay to redeclare an ANSI built-in function as static,
2479 or to declare a non-ANSI built-in function as anything. */
2480 if (! (TREE_CODE (newdecl) == FUNCTION_DECL
2481 && olddecl != NULL_TREE
2482 && TREE_CODE (olddecl) == FUNCTION_DECL
2483 && (DECL_BUILT_IN (olddecl)
2484 || DECL_BUILT_IN_NONANSI (olddecl))))
2486 cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name)
2487 ? implicit_extern_static_warning
2488 : explicit_extern_static_warning, newdecl);
2489 if (olddecl != NULL_TREE)
2490 cp_pedwarn_at ("previous declaration of `%D'", olddecl);
2495 /* Handle when a new declaration NEWDECL has the same name as an old
2496 one OLDDECL in the same binding contour. Prints an error message
2499 If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
2500 Otherwise, return 0. */
2503 duplicate_decls (newdecl, olddecl)
2504 register tree newdecl, olddecl;
2506 extern struct obstack permanent_obstack;
2507 unsigned olddecl_uid = DECL_UID (olddecl);
2508 int olddecl_friend = 0, types_match = 0;
2509 int new_defines_function;
2510 tree previous_c_decl = NULL_TREE;
2512 if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd')
2513 DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl);
2515 types_match = decls_match (newdecl, olddecl);
2517 if (TREE_CODE (olddecl) != TREE_LIST)
2518 olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
2520 /* If either the type of the new decl or the type of the old decl is an
2521 error_mark_node, then that implies that we have already issued an
2522 error (earlier) for some bogus type specification, and in that case,
2523 it is rather pointless to harass the user with yet more error message
2524 about the same declaration, so well just pretent the types match here. */
2525 if ((TREE_TYPE (newdecl)
2526 && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
2527 || (TREE_TYPE (olddecl)
2528 && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
2531 if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
2532 && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
2533 /* If -traditional, avoid error for redeclaring fcn
2534 after implicit decl. */
2536 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2537 && DECL_ARTIFICIAL (olddecl)
2538 && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))
2540 /* If you declare a built-in or predefined function name as static,
2541 the old definition is overridden, but optionally warn this was a
2542 bad choice of name. Ditto for overloads. */
2543 if (! DECL_PUBLIC (newdecl)
2544 || (TREE_CODE (newdecl) == FUNCTION_DECL
2545 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)))
2548 cp_warning ("shadowing %s function `%#D'",
2549 DECL_BUILT_IN (olddecl) ? "built-in" : "library",
2551 /* Discard the old built-in function. */
2554 else if (! types_match)
2556 if (TREE_CODE (newdecl) != FUNCTION_DECL)
2558 /* If the built-in is not ansi, then programs can override
2559 it even globally without an error. */
2560 if (! DECL_BUILT_IN (olddecl))
2561 cp_warning ("library function `%#D' redeclared as non-function `%#D'",
2565 cp_error ("declaration of `%#D'", newdecl);
2566 cp_error ("conflicts with built-in declaration `%#D'",
2572 cp_warning ("declaration of `%#D'", newdecl);
2573 cp_warning ("conflicts with built-in declaration `%#D'",
2577 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2579 if ((TREE_CODE (newdecl) == FUNCTION_DECL
2580 && TREE_CODE (olddecl) == TEMPLATE_DECL
2581 && ! DECL_TEMPLATE_IS_CLASS (olddecl))
2582 || (TREE_CODE (olddecl) == FUNCTION_DECL
2583 && TREE_CODE (newdecl) == TEMPLATE_DECL
2584 && ! DECL_TEMPLATE_IS_CLASS (newdecl)))
2587 cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
2588 if (TREE_CODE (olddecl) == TREE_LIST)
2589 olddecl = TREE_VALUE (olddecl);
2590 cp_error_at ("previous declaration of `%#D'", olddecl);
2592 /* New decl is completely inconsistent with the old one =>
2593 tell caller to replace the old one. */
2597 else if (!types_match)
2599 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2601 /* The name of a class template may not be declared to refer to
2602 any other template, class, function, object, namespace, value,
2603 or type in the same scope. */
2604 if (DECL_TEMPLATE_IS_CLASS (olddecl)
2605 || DECL_TEMPLATE_IS_CLASS (newdecl))
2607 cp_error ("declaration of template `%#D'", newdecl);
2608 cp_error_at ("conflicts with previous declaration `%#D'",
2613 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2615 if (DECL_LANGUAGE (newdecl) == lang_c
2616 && DECL_LANGUAGE (olddecl) == lang_c)
2618 cp_error ("declaration of C function `%#D' conflicts with",
2620 cp_error_at ("previous declaration `%#D' here", olddecl);
2622 else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2623 TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 3))
2625 cp_error ("new declaration `%#D'", newdecl);
2626 cp_error_at ("ambiguates old declaration `%#D'", olddecl);
2632 /* Already complained about this, so don't do so again. */
2633 else if (current_class_type == NULL_TREE
2634 || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
2636 cp_error ("conflicting types for `%#D'", newdecl);
2637 cp_error_at ("previous declaration as `%#D'", olddecl);
2642 char *errmsg = redeclaration_error_message (newdecl, olddecl);
2645 cp_error (errmsg, newdecl);
2646 if (DECL_NAME (olddecl) != NULL_TREE)
2647 cp_error_at ((DECL_INITIAL (olddecl)
2648 && current_binding_level == global_binding_level)
2649 ? "`%#D' previously defined here"
2650 : "`%#D' previously declared here", olddecl);
2652 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2653 && DECL_INITIAL (olddecl) != NULL_TREE
2654 && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
2655 && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
2657 /* Prototype decl follows defn w/o prototype. */
2658 cp_warning_at ("prototype for `%#D'", newdecl);
2659 cp_warning_at ("follows non-prototype definition here", olddecl);
2661 else if (TREE_CODE (olddecl) == FUNCTION_DECL
2662 && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2664 /* extern "C" int foo ();
2665 int foo () { bar (); }
2667 if (current_lang_stack == current_lang_base)
2668 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2671 cp_error_at ("previous declaration of `%#D' with %L linkage",
2672 olddecl, DECL_LANGUAGE (olddecl));
2673 cp_error ("conflicts with new declaration with %L linkage",
2674 DECL_LANGUAGE (newdecl));
2678 if (TREE_CODE (olddecl) == FUNCTION_DECL)
2680 tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
2681 tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
2684 if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
2685 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
2687 for (; t1 && t1 != void_list_node;
2688 t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
2689 if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
2691 if (1 == simple_cst_equal (TREE_PURPOSE (t1),
2696 cp_pedwarn ("default argument given for parameter %d of `%#D'",
2698 cp_pedwarn_at ("after previous specification in `%#D'",
2704 cp_error ("default argument given for parameter %d of `%#D'",
2706 cp_error_at ("conflicts with previous specification in `%#D'",
2711 if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl))
2713 #if 0 /* I think this will be correct, but it's really annoying. We should
2714 fix the compiler to find vtables by indirection so it isn't
2715 necessary. (jason 8/25/95) */
2716 if (DECL_VINDEX (olddecl) && ! DECL_ABSTRACT_VIRTUAL_P (olddecl))
2718 cp_pedwarn ("virtual function `%#D' redeclared inline",
2720 cp_pedwarn_at ("previous non-inline declaration here",
2725 if (TREE_ADDRESSABLE (olddecl))
2727 cp_pedwarn ("`%#D' was used before it was declared inline",
2729 cp_pedwarn_at ("previous non-inline declaration here",
2734 /* These bits are logically part of the type for non-functions. */
2735 else if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
2736 || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))
2738 cp_pedwarn ("type qualifiers for `%#D'", newdecl);
2739 cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl);
2743 /* If new decl is `static' and an `extern' was seen previously,
2745 warn_extern_redeclared_static (newdecl, olddecl);
2747 /* We have committed to returning 1 at this point. */
2748 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2750 /* Now that functions must hold information normally held
2751 by field decls, there is extra work to do so that
2752 declaration information does not get destroyed during
2754 if (DECL_VINDEX (olddecl))
2755 DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2756 if (DECL_CONTEXT (olddecl))
2757 DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2758 if (DECL_CLASS_CONTEXT (olddecl))
2759 DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
2760 if (DECL_CHAIN (newdecl) == NULL_TREE)
2761 DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2762 if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
2763 DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
2764 DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
2765 DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
2766 DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl);
2769 /* Deal with C++: must preserve virtual function table size. */
2770 if (TREE_CODE (olddecl) == TYPE_DECL)
2772 register tree newtype = TREE_TYPE (newdecl);
2773 register tree oldtype = TREE_TYPE (olddecl);
2775 DECL_NESTED_TYPENAME (newdecl) = DECL_NESTED_TYPENAME (olddecl);
2777 if (newtype != error_mark_node && oldtype != error_mark_node
2778 && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2780 CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
2781 CLASSTYPE_FRIEND_CLASSES (newtype)
2782 = CLASSTYPE_FRIEND_CLASSES (oldtype);
2785 /* why assert here? Just because debugging information is
2787 /* it happens on something like:
2788 typedef struct Thing {
2793 my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl),
2798 /* Special handling ensues if new decl is a function definition. */
2799 new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
2800 && DECL_INITIAL (newdecl) != NULL_TREE);
2802 /* Optionally warn about more than one declaration for the same name,
2803 but don't warn about a function declaration followed by a definition. */
2804 if (warn_redundant_decls
2805 && ! DECL_ARTIFICIAL (olddecl)
2806 && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2807 /* Don't warn about extern decl followed by (tentative) definition. */
2808 && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
2810 cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
2811 cp_warning_at ("previous declaration of `%D'", olddecl);
2814 /* Copy all the DECL_... slots specified in the new decl
2815 except for any that we copy here from the old type. */
2819 /* Automatically handles default parameters. */
2820 tree oldtype = TREE_TYPE (olddecl);
2823 /* Make sure we put the new type in the same obstack as the old one. */
2825 push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
2828 push_obstacks_nochange ();
2829 end_temporary_allocation ();
2832 /* Merge the data types specified in the two decls. */
2833 newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2835 if (TREE_CODE (newdecl) == VAR_DECL)
2836 DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2837 /* Do this after calling `common_type' so that default
2838 parameters don't confuse us. */
2839 else if (TREE_CODE (newdecl) == FUNCTION_DECL
2840 && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
2841 != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
2843 tree ctype = NULL_TREE;
2844 ctype = DECL_CLASS_CONTEXT (newdecl);
2845 TREE_TYPE (newdecl) = build_exception_variant (newtype,
2846 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
2847 TREE_TYPE (olddecl) = build_exception_variant (newtype,
2848 TYPE_RAISES_EXCEPTIONS (oldtype));
2850 if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
2852 cp_error ("declaration of `%D' throws different exceptions...",
2854 cp_error_at ("...from previous declaration here", olddecl);
2857 TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2859 /* Lay the type out, unless already done. */
2860 if (oldtype != TREE_TYPE (newdecl)
2861 && TREE_TYPE (newdecl) != error_mark_node)
2862 layout_type (TREE_TYPE (newdecl));
2864 if (TREE_CODE (newdecl) == VAR_DECL
2865 || TREE_CODE (newdecl) == PARM_DECL
2866 || TREE_CODE (newdecl) == RESULT_DECL
2867 || TREE_CODE (newdecl) == FIELD_DECL
2868 || TREE_CODE (newdecl) == TYPE_DECL)
2869 layout_decl (newdecl, 0);
2871 /* Merge the type qualifiers. */
2872 if (TREE_READONLY (newdecl))
2873 TREE_READONLY (olddecl) = 1;
2874 if (TREE_THIS_VOLATILE (newdecl))
2875 TREE_THIS_VOLATILE (olddecl) = 1;
2877 /* Merge the initialization information. */
2878 if (DECL_INITIAL (newdecl) == NULL_TREE
2879 && DECL_INITIAL (olddecl) != NULL_TREE)
2881 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2882 DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
2883 DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
2886 /* Merge the section attribute.
2887 We want to issue an error if the sections conflict but that must be
2888 done later in decl_attributes since we are called before attributes
2890 if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
2891 DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
2893 /* Keep the old rtl since we can safely use it, unless it's the
2894 call to abort() used for abstract virtuals. */
2895 if ((DECL_LANG_SPECIFIC (olddecl)
2896 && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
2897 || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
2898 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2902 /* If cannot merge, then use the new type and qualifiers,
2903 and don't preserve the old rtl. */
2906 /* Clean out any memory we had of the old declaration. */
2907 tree oldstatic = value_member (olddecl, static_aggregates);
2909 TREE_VALUE (oldstatic) = error_mark_node;
2911 TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
2912 TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
2913 TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
2914 TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
2917 /* Merge the storage class information. */
2918 DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
2919 TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
2920 TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
2921 if (! DECL_EXTERNAL (olddecl))
2922 DECL_EXTERNAL (newdecl) = 0;
2924 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2926 DECL_C_STATIC (newdecl) |= DECL_C_STATIC (olddecl);
2927 DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
2928 DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
2931 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2933 DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl);
2935 /* If either decl says `inline', this fn is inline, unless its
2936 definition was passed already. */
2937 if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
2938 DECL_INLINE (olddecl) = 1;
2939 DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
2943 DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl);
2944 DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl);
2945 DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
2946 DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
2947 DECL_RTL (olddecl) = DECL_RTL (newdecl);
2949 if (new_defines_function)
2950 /* If defining a function declared with other language
2951 linkage, use the previously declared language linkage. */
2952 DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
2955 /* If redeclaring a builtin function, and not a definition,
2956 it stays built in. */
2957 if (DECL_BUILT_IN (olddecl))
2959 DECL_BUILT_IN (newdecl) = 1;
2960 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2961 /* If we're keeping the built-in definition, keep the rtl,
2962 regardless of declaration matches. */
2963 DECL_RTL (newdecl) = DECL_RTL (olddecl);
2966 DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
2968 DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
2969 if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)))
2970 /* Previously saved insns go together with
2971 the function's previous definition. */
2972 DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2973 /* Don't clear out the arguments if we're redefining a function. */
2974 if (DECL_ARGUMENTS (olddecl))
2975 DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
2977 if (DECL_LANG_SPECIFIC (olddecl))
2978 DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl);
2981 if (TREE_CODE (newdecl) == NAMESPACE_DECL)
2983 NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
2986 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2988 if (DECL_TEMPLATE_INFO (olddecl)->length)
2989 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
2990 DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl);
2991 DECL_TEMPLATE_INSTANTIATIONS (newdecl)
2992 = DECL_TEMPLATE_INSTANTIATIONS (olddecl);
2993 if (DECL_CHAIN (newdecl) == NULL_TREE)
2994 DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
2997 /* Now preserve various other info from the definition. */
2998 TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
2999 TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
3000 DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
3001 DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl);
3003 /* Don't really know how much of the language-specific
3004 values we should copy from old to new. */
3005 if (DECL_LANG_SPECIFIC (olddecl))
3007 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
3008 DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
3009 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
3012 if (TREE_CODE (newdecl) == FUNCTION_DECL)
3015 struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
3016 struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
3018 function_size = sizeof (struct tree_decl);
3020 bcopy ((char *) newdecl + sizeof (struct tree_common),
3021 (char *) olddecl + sizeof (struct tree_common),
3022 function_size - sizeof (struct tree_common));
3024 /* Can we safely free the storage used by newdecl? */
3026 #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
3027 & ~ obstack_alignment_mask (&permanent_obstack))
3029 if ((char *)newdecl + ROUND (function_size)
3030 + ROUND (sizeof (struct lang_decl))
3031 == obstack_next_free (&permanent_obstack))
3033 DECL_MAIN_VARIANT (newdecl) = olddecl;
3034 DECL_LANG_SPECIFIC (olddecl) = ol;
3035 bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
3037 obstack_free (&permanent_obstack, newdecl);
3039 else if (LANG_DECL_PERMANENT (ol))
3041 if (DECL_MAIN_VARIANT (olddecl) == olddecl)
3043 /* Save these lang_decls that would otherwise be lost. */
3044 extern tree free_lang_decl_chain;
3045 tree free_lang_decl = (tree) ol;
3046 TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
3047 free_lang_decl_chain = free_lang_decl;
3057 bcopy ((char *) newdecl + sizeof (struct tree_common),
3058 (char *) olddecl + sizeof (struct tree_common),
3059 sizeof (struct tree_decl) - sizeof (struct tree_common)
3060 + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
3063 DECL_UID (olddecl) = olddecl_uid;
3065 DECL_FRIEND_P (olddecl) = 1;
3070 /* Record a decl-node X as belonging to the current lexical scope.
3071 Check for errors (such as an incompatible declaration for the same
3072 name already seen in the same scope).
3074 Returns either X or an old decl for the same name.
3075 If an old decl is returned, it may have been smashed
3076 to agree with what X says. */
3083 #if 0 /* not yet, should get fixed properly later */
3086 register tree name = DECL_ASSEMBLER_NAME (x);
3088 register struct binding_level *b = current_binding_level;
3091 static int nglobals; int len;
3093 len = list_length (global_binding_level->names);
3095 my_friendly_abort (8);
3096 else if (len > nglobals)
3100 if (x != current_function_decl
3101 /* Don't change DECL_CONTEXT of virtual methods. */
3102 && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x))
3103 && ! DECL_CONTEXT (x))
3104 DECL_CONTEXT (x) = current_function_decl;
3105 /* A local declaration for a function doesn't constitute nesting. */
3106 if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
3107 DECL_CONTEXT (x) = 0;
3109 #if 0 /* not yet, should get fixed properly later */
3110 /* For functions and class static data, we currently look up the encoded
3111 form of the name. For types, we want the real name. The former will
3112 probably be changed soon, according to MDT. */
3113 if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
3114 name = DECL_ASSEMBLER_NAME (x);
3116 name = DECL_NAME (x);
3118 /* Type are looked up using the DECL_NAME, as that is what the rest of the
3119 compiler wants to use. */
3120 if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL
3121 || TREE_CODE (x) == NAMESPACE_DECL)
3122 name = DECL_NAME (x);
3130 t = lookup_name_current_level (name);
3131 if (t == error_mark_node)
3133 /* error_mark_node is 0 for a while during initialization! */
3135 cp_error_at ("`%#D' used prior to declaration", x);
3138 else if (t != NULL_TREE)
3140 file = DECL_SOURCE_FILE (t);
3141 line = DECL_SOURCE_LINE (t);
3142 if (TREE_CODE (x) == VAR_DECL && DECL_DEAD_FOR_LOCAL (x))
3144 else if (TREE_CODE (t) == PARM_DECL)
3146 if (DECL_CONTEXT (t) == NULL_TREE)
3147 fatal ("parse errors have confused me too much");
3149 /* Check for duplicate params. */
3150 if (duplicate_decls (x, t))
3153 else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c)
3154 || (TREE_CODE (x) == TEMPLATE_DECL
3155 && ! DECL_TEMPLATE_IS_CLASS (x)))
3156 && is_overloaded_fn (t))
3157 /* don't do anything just yet */;
3158 else if (t == wchar_decl_node)
3160 if (pedantic && ! DECL_IN_SYSTEM_HEADER (x))
3161 cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x));
3163 /* Throw away the redeclaration. */
3166 else if (TREE_CODE (t) != TREE_CODE (x))
3168 if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
3169 || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)))
3171 /* We do nothing special here, because C++ does such nasty
3172 things with TYPE_DECLs. Instead, just let the TYPE_DECL
3173 get shadowed, and know that if we need to find a TYPE_DECL
3174 for a given name, we can look in the IDENTIFIER_TYPE_VALUE
3175 slot of the identifier. */
3178 else if (duplicate_decls (x, t))
3181 else if (duplicate_decls (x, t))
3184 /* This is turned off until I have time to do it right (bpk). */
3186 /* Also warn if they did a prototype with `static' on it, but
3187 then later left the `static' off. */
3188 if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
3190 if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
3195 cp_warning ("`static' missing from declaration of `%D'",
3197 warning_with_file_and_line (file, line,
3198 "previous declaration of `%s'",
3199 decl_as_string (t, 0));
3202 /* Now fix things so it'll do what they expect. */
3203 if (current_function_decl)
3204 TREE_PUBLIC (current_function_decl) = 0;
3206 /* Due to interference in memory reclamation (X may be
3207 obstack-deallocated at this point), we must guard against
3208 one really special case. [jason: This should be handled
3209 by start_function] */
3210 if (current_function_decl == x)
3211 current_function_decl = t;
3213 if (TREE_CODE (t) == TYPE_DECL)
3214 SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t));
3215 else if (TREE_CODE (t) == FUNCTION_DECL)
3216 check_default_args (t);
3222 if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x))
3224 t = push_overloaded_decl (x, 1);
3225 if (t != x || DECL_LANGUAGE (x) == lang_c)
3228 else if (TREE_CODE (x) == TEMPLATE_DECL && ! DECL_TEMPLATE_IS_CLASS (x))
3229 return push_overloaded_decl (x, 0);
3231 /* If declaring a type as a typedef, and the type has no known
3232 typedef name, install this TYPE_DECL as its typedef name. */
3233 if (TREE_CODE (x) == TYPE_DECL)
3235 tree type = TREE_TYPE (x);
3236 tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
3238 if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
3240 /* If these are different names, and we're at the global
3241 binding level, make two equivalent definitions. */
3243 if (global_bindings_p ())
3244 TYPE_NAME (type) = x;
3248 tree tname = DECL_NAME (name);
3250 /* This is a disgusting kludge for dealing with UPTs. */
3251 if (global_bindings_p () && ANON_AGGRNAME_P (tname))
3253 /* do gratuitous C++ typedefing, and make sure that
3254 we access this type either through TREE_TYPE field
3255 or via the tags list. */
3256 TYPE_NAME (TREE_TYPE (x)) = x;
3257 pushtag (tname, TREE_TYPE (x), 0);
3260 my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
3262 /* Don't set nested_typename on template type parms, for instance.
3263 Any artificial decls that need DECL_NESTED_TYPENAME will have it
3265 if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x))
3266 set_nested_typename (x, current_class_name, DECL_NAME (x), type);
3268 if (type != error_mark_node
3270 && TYPE_IDENTIFIER (type))
3271 set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
3274 /* Multiple external decls of the same identifier ought to match.
3276 We get warnings about inline functions where they are defined.
3277 We get warnings about other functions from push_overloaded_decl.
3279 Avoid duplicate warnings where they are used. */
3280 if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
3284 if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
3285 && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
3286 || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
3287 decl = IDENTIFIER_GLOBAL_VALUE (name);
3292 /* If different sort of thing, we already gave an error. */
3293 && TREE_CODE (decl) == TREE_CODE (x)
3294 && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1))
3296 cp_pedwarn ("type mismatch with previous external decl", x);
3297 cp_pedwarn_at ("previous external decl of `%#D'", decl);
3301 /* In PCC-compatibility mode, extern decls of vars with no current decl
3302 take effect at top level no matter where they are. */
3303 if (flag_traditional && DECL_EXTERNAL (x)
3304 && lookup_name (name, 0) == NULL_TREE)
3305 b = global_binding_level;
3307 /* This name is new in its binding level.
3308 Install the new declaration and return it. */
3309 if (b == global_binding_level)
3311 /* Install a global value. */
3313 /* If the first global decl has external linkage,
3314 warn if we later see static one. */
3315 if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && DECL_PUBLIC (x))
3316 TREE_PUBLIC (name) = 1;
3318 /* Don't install an artificial TYPE_DECL if we already have
3319 another _DECL with that name. */
3320 if (TREE_CODE (x) != TYPE_DECL
3322 || ! DECL_ARTIFICIAL (x))
3323 IDENTIFIER_GLOBAL_VALUE (name) = x;
3325 /* Don't forget if the function was used via an implicit decl. */
3326 if (IDENTIFIER_IMPLICIT_DECL (name)
3327 && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
3330 /* Don't forget if its address was taken in that way. */
3331 if (IDENTIFIER_IMPLICIT_DECL (name)
3332 && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
3333 TREE_ADDRESSABLE (x) = 1;
3335 /* Warn about mismatches against previous implicit decl. */
3336 if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
3337 /* If this real decl matches the implicit, don't complain. */
3338 && ! (TREE_CODE (x) == FUNCTION_DECL
3339 && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
3341 ("`%D' was previously implicitly declared to return `int'", x);
3343 /* If new decl is `static' and an `extern' was seen previously,
3345 if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
3346 warn_extern_redeclared_static (x, t);
3350 /* Here to install a non-global value. */
3351 tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
3352 tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
3354 /* Don't install an artificial TYPE_DECL if we already have
3355 another _DECL with that name. */
3356 if (TREE_CODE (x) != TYPE_DECL
3358 || ! DECL_ARTIFICIAL (x))
3360 b->shadowed = tree_cons (name, oldlocal, b->shadowed);
3361 IDENTIFIER_LOCAL_VALUE (name) = x;
3364 /* If this is a TYPE_DECL, push it into the type value slot. */
3365 if (TREE_CODE (x) == TYPE_DECL)
3366 set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
3368 /* Clear out any TYPE_DECL shadowed by a namespace so that
3369 we won't think this is a type. The C struct hack doesn't
3370 go through namespaces. */
3371 if (TREE_CODE (x) == NAMESPACE_DECL)
3372 set_identifier_type_value_with_scope (name, NULL_TREE, b);
3374 /* If this is an extern function declaration, see if we
3375 have a global definition or declaration for the function. */
3376 if (oldlocal == NULL_TREE
3377 && DECL_EXTERNAL (x)
3378 && oldglobal != NULL_TREE
3379 && TREE_CODE (x) == FUNCTION_DECL
3380 && TREE_CODE (oldglobal) == FUNCTION_DECL)
3382 /* We have one. Their types must agree. */
3383 if (decls_match (x, oldglobal))
3387 cp_warning ("extern declaration of `%#D' doesn't match", x);
3388 cp_warning_at ("global declaration `%#D'", oldglobal);
3391 /* If we have a local external declaration,
3392 and no file-scope declaration has yet been seen,
3393 then if we later have a file-scope decl it must not be static. */
3394 if (oldlocal == NULL_TREE
3395 && oldglobal == NULL_TREE
3396 && DECL_EXTERNAL (x)
3399 TREE_PUBLIC (name) = 1;
3402 if (DECL_FROM_INLINE (x))
3403 /* Inline decls shadow nothing. */;
3405 /* Warn if shadowing an argument at the top level of the body. */
3406 else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
3407 && TREE_CODE (oldlocal) == PARM_DECL
3408 && TREE_CODE (x) != PARM_DECL)
3410 /* Go to where the parms should be and see if we
3412 struct binding_level *b = current_binding_level->level_chain;
3418 if (b->parm_flag == 1)
3419 cp_error ("declaration of `%#D' shadows a parameter", name);
3421 else if (warn_shadow && oldlocal != NULL_TREE && b->is_for_scope
3422 && !DECL_DEAD_FOR_LOCAL (oldlocal))
3424 warning ("variable `%s' shadows local",
3425 IDENTIFIER_POINTER (name));
3426 cp_warning_at (" this is the shadowed declaration", oldlocal);
3428 /* Maybe warn if shadowing something else. */
3429 else if (warn_shadow && !DECL_EXTERNAL (x)
3430 /* No shadow warnings for internally generated vars. */
3431 && ! DECL_ARTIFICIAL (x)
3432 /* No shadow warnings for vars made for inlining. */
3433 && ! DECL_FROM_INLINE (x))
3435 char *warnstring = NULL;
3437 if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
3438 warnstring = "declaration of `%s' shadows a parameter";
3439 else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
3440 && current_class_decl
3441 && !TREE_STATIC (name))
3442 warnstring = "declaration of `%s' shadows a member of `this'";
3443 else if (oldlocal != NULL_TREE)
3444 warnstring = "declaration of `%s' shadows previous local";
3445 else if (oldglobal != NULL_TREE)
3446 warnstring = "declaration of `%s' shadows global declaration";
3449 warning (warnstring, IDENTIFIER_POINTER (name));
3453 if (TREE_CODE (x) == FUNCTION_DECL)
3454 check_default_args (x);
3456 /* Keep count of variables in this level with incomplete type. */
3457 if (TREE_CODE (x) == VAR_DECL
3458 && TREE_TYPE (x) != error_mark_node
3459 && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
3460 && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
3461 /* RTTI TD entries are created while defining the type_info. */
3462 || (TYPE_LANG_SPECIFIC (TREE_TYPE (x))
3463 && TYPE_BEING_DEFINED (TREE_TYPE (x)))))
3464 b->incomplete = tree_cons (NULL_TREE, x, b->incomplete);
3467 /* Put decls on list in reverse order.
3468 We will reverse them later if necessary. */
3469 TREE_CHAIN (x) = b->names;
3471 if (! (b != global_binding_level || TREE_PERMANENT (x)))
3472 my_friendly_abort (124);
3477 /* Same as pushdecl, but define X in binding-level LEVEL. */
3480 pushdecl_with_scope (x, level)
3482 struct binding_level *level;
3484 register struct binding_level *b = current_binding_level;
3486 current_binding_level = level;
3488 current_binding_level = b;
3492 /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
3495 pushdecl_top_level (x)
3498 register struct binding_level *b = inner_binding_level;
3499 register tree t = pushdecl_with_scope (x, global_binding_level);
3501 /* Now, the type_shadowed stack may screw us. Munge it so it does
3503 if (TREE_CODE (x) == TYPE_DECL)
3505 tree name = DECL_NAME (x);
3507 tree *ptr = (tree *)0;
3508 for (; b != global_binding_level; b = b->level_chain)
3510 tree shadowed = b->type_shadowed;
3511 for (; shadowed; shadowed = TREE_CHAIN (shadowed))
3512 if (TREE_PURPOSE (shadowed) == name)
3514 ptr = &TREE_VALUE (shadowed);
3515 /* Can't break out of the loop here because sometimes
3516 a binding level will have duplicate bindings for
3517 PT names. It's gross, but I haven't time to fix it. */
3520 newval = TREE_TYPE (x);
3521 if (ptr == (tree *)0)
3523 /* @@ This shouldn't be needed. My test case "zstring.cc" trips
3524 up here if this is changed to an assertion. --KR */
3525 SET_IDENTIFIER_TYPE_VALUE (name, newval);
3530 /* Disabled this 11/10/92, since there are many cases which
3531 behave just fine when *ptr doesn't satisfy either of these.
3532 For example, nested classes declared as friends of their enclosing
3533 class will not meet this criteria. (bpk) */
3534 my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141);
3542 /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
3545 push_overloaded_decl_top_level (x, forget)
3549 struct binding_level *b = current_binding_level;
3551 current_binding_level = global_binding_level;
3552 push_overloaded_decl (x, forget);
3553 current_binding_level = b;
3556 /* Make the declaration of X appear in CLASS scope. */
3558 pushdecl_class_level (x)
3561 /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class
3562 scope looks for the pre-mangled name. */
3563 register tree name = DECL_NAME (x);
3567 if (TYPE_BEING_DEFINED (current_class_type))
3569 /* Check for inconsistent use of this name in the class body.
3570 Types, enums, and static vars are checked here; other
3571 members are checked in finish_struct. */
3572 tree icv = IDENTIFIER_CLASS_VALUE (name);
3575 /* Don't complain about inherited names. */
3576 && id_in_current_class (name)
3577 /* Or shadowed tags. */
3578 && !(TREE_CODE (icv) == TYPE_DECL
3579 && DECL_CONTEXT (icv) == current_class_type))
3581 cp_error ("declaration of identifier `%D' as `%#D'", name, x);
3582 cp_error_at ("conflicts with previous use in class as `%#D'",
3587 push_class_level_binding (name, x);
3588 if (TREE_CODE (x) == TYPE_DECL)
3590 set_identifier_type_value (name, TREE_TYPE (x));
3592 /* Don't set nested_typename on template type parms, for instance.
3593 Any artificial decls that need DECL_NESTED_TYPENAME will have it
3595 if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x))
3596 set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
3602 /* This function is used to push the mangled decls for nested types into
3603 the appropriate scope. Previously pushdecl_top_level was used, but that
3604 is incorrect for members of local classes. */
3606 pushdecl_nonclass_level (x)
3609 struct binding_level *b = current_binding_level;
3612 /* Get out of class scope -- this isn't necessary, because class scope
3613 doesn't make it into current_binding_level. */
3614 while (b->parm_flag == 2)
3617 my_friendly_assert (b->parm_flag != 2, 180);
3620 /* Get out of template binding levels */
3621 while (b->pseudo_global)
3624 pushdecl_with_scope (x, b);
3627 /* Make the declaration(s) of X appear in CLASS scope
3628 under the name NAME. */
3630 push_class_level_binding (name, x)
3634 if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)
3635 && purpose_member (name, class_binding_level->class_shadowed))
3638 maybe_push_cache_obstack ();
3639 class_binding_level->class_shadowed
3640 = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
3641 class_binding_level->class_shadowed);
3643 IDENTIFIER_CLASS_VALUE (name) = x;
3644 obstack_ptr_grow (&decl_obstack, x);
3647 /* Tell caller how to interpret a TREE_LIST which contains
3648 chains of FUNCTION_DECLS. */
3650 overloaded_globals_p (list)
3653 my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
3655 /* Don't commit caller to seeing them as globals. */
3656 if (TREE_NONLOCAL_FLAG (list))
3658 /* Do commit caller to seeing them as globals. */
3659 if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
3661 /* Do commit caller to not seeing them as globals. */
3665 /* DECL is a FUNCTION_DECL which may have other definitions already in
3666 place. We get around this by making the value of the identifier point
3667 to a list of all the things that want to be referenced by that name. It
3668 is then up to the users of that name to decide what to do with that
3671 DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
3672 slot. It is dealt with the same way.
3674 The value returned may be a previous declaration if we guessed wrong
3675 about what language DECL should belong to (C or C++). Otherwise,
3676 it's always DECL (and never something that's not a _DECL). */
3678 push_overloaded_decl (decl, forgettable)
3682 tree orig_name = DECL_NAME (decl);
3684 int doing_global = (global_bindings_p () || ! forgettable
3685 || flag_traditional || pseudo_global_level_p ());
3689 old = IDENTIFIER_GLOBAL_VALUE (orig_name);
3690 if (old && TREE_CODE (old) == FUNCTION_DECL
3691 && DECL_ARTIFICIAL (old)
3692 && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old)))
3694 if (duplicate_decls (decl, old))
3701 old = IDENTIFIER_LOCAL_VALUE (orig_name);
3703 if (! purpose_member (orig_name, current_binding_level->shadowed))
3705 current_binding_level->shadowed
3706 = tree_cons (orig_name, old, current_binding_level->shadowed);
3714 /* We cache the value of builtin functions as ADDR_EXPRs
3715 in the name space. Convert it to some kind of _DECL after
3716 remembering what to forget. */
3717 if (TREE_CODE (old) == ADDR_EXPR)
3718 old = TREE_OPERAND (old, 0);
3721 if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
3723 tree t = TREE_TYPE (old);
3724 if (IS_AGGR_TYPE (t) && warn_shadow)
3725 cp_warning ("`%#D' hides constructor for `%#T'", decl, t);
3728 else if (is_overloaded_fn (old))
3732 for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp))
3733 if (decl == tmp || duplicate_decls (decl, tmp))
3738 cp_error_at ("previous non-function declaration `%#D'", old);
3739 cp_error ("conflicts with function declaration `%#D'", decl);
3744 if (old || TREE_CODE (decl) == TEMPLATE_DECL)
3746 if (old && is_overloaded_fn (old))
3747 DECL_CHAIN (decl) = get_first_fn (old);
3749 DECL_CHAIN (decl) = NULL_TREE;
3750 old = tree_cons (orig_name, decl, NULL_TREE);
3751 TREE_TYPE (old) = unknown_type_node;
3754 /* orig_name is not ambiguous. */
3758 IDENTIFIER_GLOBAL_VALUE (orig_name) = old;
3760 IDENTIFIER_LOCAL_VALUE (orig_name) = old;
3765 /* Generate an implicit declaration for identifier FUNCTIONID
3766 as a function of type int (). Print a warning if appropriate. */
3769 implicitly_declare (functionid)
3773 int temp = allocation_temporary_p ();
3775 push_obstacks_nochange ();
3777 /* Save the decl permanently so we can warn if definition follows.
3778 In ANSI C, warn_implicit is usually false, so the saves little space.
3779 But in C++, it's usually true, hence the extra code. */
3780 if (temp && (flag_traditional || !warn_implicit || toplevel_bindings_p ()))
3781 end_temporary_allocation ();
3783 /* We used to reuse an old implicit decl here,
3784 but this loses with inline functions because it can clobber
3785 the saved decl chains. */
3786 decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
3788 DECL_EXTERNAL (decl) = 1;
3789 TREE_PUBLIC (decl) = 1;
3791 /* ANSI standard says implicit declarations are in the innermost block.
3792 So we record the decl in the standard fashion.
3793 If flag_traditional is set, pushdecl does it top-level. */
3795 rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
3798 /* Only one warning per identifier. */
3799 && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
3801 cp_pedwarn ("implicit declaration of function `%#D'", decl);
3804 SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
3811 /* Return zero if the declaration NEWDECL is valid
3812 when the declaration OLDDECL (assumed to be for the same name)
3813 has already been seen.
3814 Otherwise return an error message format string with a %s
3815 where the identifier should go. */
3818 redeclaration_error_message (newdecl, olddecl)
3819 tree newdecl, olddecl;
3821 if (TREE_CODE (newdecl) == TYPE_DECL)
3823 /* Because C++ can put things into name space for free,
3824 constructs like "typedef struct foo { ... } foo"
3825 would look like an erroneous redeclaration. */
3826 if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
3829 return "redefinition of `%#D'";
3831 else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3833 /* If this is a pure function, its olddecl will actually be
3834 the original initialization to `0' (which we force to call
3835 abort()). Don't complain about redefinition in this case. */
3836 if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
3839 /* We'll complain about linkage mismatches in
3840 warn_extern_redeclared_static. */
3842 /* defining the same name twice is no good. */
3843 if (DECL_INITIAL (olddecl) != NULL_TREE
3844 && DECL_INITIAL (newdecl) != NULL_TREE)
3846 if (DECL_NAME (olddecl) == NULL_TREE)
3847 return "`%#D' not declared in class";
3849 return "redefinition of `%#D'";
3853 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
3855 if (DECL_INITIAL (olddecl) && DECL_INITIAL (newdecl))
3856 return "redefinition of `%#D'";
3859 else if (current_binding_level == global_binding_level)
3861 /* Objects declared at top level: */
3862 /* If at least one is a reference, it's ok. */
3863 if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3865 /* Reject two definitions. */
3866 return "redefinition of `%#D'";
3870 /* Objects declared with block scope: */
3871 /* Reject two definitions, and reject a definition
3872 together with an external reference. */
3873 if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3874 return "redeclaration of `%#D'";
3879 /* Get the LABEL_DECL corresponding to identifier ID as a label.
3880 Create one if none exists so far for the current function.
3881 This function is called for both label definitions and label references. */
3887 register tree decl = IDENTIFIER_LABEL_VALUE (id);
3889 if (current_function_decl == NULL_TREE)
3891 error ("label `%s' referenced outside of any function",
3892 IDENTIFIER_POINTER (id));
3896 if ((decl == NULL_TREE
3897 || DECL_SOURCE_LINE (decl) == 0)
3898 && (named_label_uses == NULL_TREE
3899 || TREE_PURPOSE (named_label_uses) != current_binding_level->names
3900 || TREE_VALUE (named_label_uses) != decl))
3903 = tree_cons (current_binding_level->names, decl, named_label_uses);
3904 TREE_TYPE (named_label_uses) = (tree)current_binding_level;
3907 /* Use a label already defined or ref'd with this name. */
3908 if (decl != NULL_TREE)
3910 /* But not if it is inherited and wasn't declared to be inheritable. */
3911 if (DECL_CONTEXT (decl) != current_function_decl
3912 && ! C_DECLARED_LABEL_FLAG (decl))
3913 return shadow_label (id);
3917 decl = build_decl (LABEL_DECL, id, void_type_node);
3919 /* A label not explicitly declared must be local to where it's ref'd. */
3920 DECL_CONTEXT (decl) = current_function_decl;
3922 DECL_MODE (decl) = VOIDmode;
3924 /* Say where one reference is to the label,
3925 for the sake of the error if it is not defined. */
3926 DECL_SOURCE_LINE (decl) = lineno;
3927 DECL_SOURCE_FILE (decl) = input_filename;
3929 SET_IDENTIFIER_LABEL_VALUE (id, decl);
3931 named_labels = tree_cons (NULL_TREE, decl, named_labels);
3932 TREE_VALUE (named_label_uses) = decl;
3937 /* Make a label named NAME in the current function,
3938 shadowing silently any that may be inherited from containing functions
3939 or containing scopes.
3941 Note that valid use, if the label being shadowed
3942 comes from another scope in the same function,
3943 requires calling declare_nonlocal_label right away. */
3949 register tree decl = IDENTIFIER_LABEL_VALUE (name);
3951 if (decl != NULL_TREE)
3953 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3954 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3955 SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
3958 return lookup_label (name);
3961 /* Define a label, specifying the location in the source file.
3962 Return the LABEL_DECL node for the label, if the definition is valid.
3963 Otherwise return 0. */
3966 define_label (filename, line, name)
3971 tree decl = lookup_label (name);
3973 /* After labels, make any new cleanups go into their
3974 own new (temporary) binding contour. */
3975 current_binding_level->more_cleanups_ok = 0;
3977 /* If label with this name is known from an outer context, shadow it. */
3978 if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
3980 shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
3981 SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
3982 decl = lookup_label (name);
3985 if (name == get_identifier ("wchar_t"))
3986 cp_pedwarn ("label named wchar_t");
3988 if (DECL_INITIAL (decl) != NULL_TREE)
3990 cp_error ("duplicate label `%D'", decl);
3998 /* Mark label as having been defined. */
3999 DECL_INITIAL (decl) = error_mark_node;
4000 /* Say where in the source. */
4001 DECL_SOURCE_FILE (decl) = filename;
4002 DECL_SOURCE_LINE (decl) = line;
4004 for (prev = NULL_TREE, uses = named_label_uses;
4006 prev = uses, uses = TREE_CHAIN (uses))
4007 if (TREE_VALUE (uses) == decl)
4009 struct binding_level *b = current_binding_level;
4012 tree new_decls = b->names;
4013 tree old_decls = ((tree)b == TREE_TYPE (uses)
4014 ? TREE_PURPOSE (uses) : NULL_TREE);
4015 while (new_decls != old_decls)
4017 if (TREE_CODE (new_decls) == VAR_DECL
4018 /* Don't complain about crossing initialization
4019 of internal entities. They can't be accessed,
4020 and they should be cleaned up
4021 by the time we get to the label. */
4022 && ! DECL_ARTIFICIAL (new_decls)
4023 && ((DECL_INITIAL (new_decls) != NULL_TREE
4024 && DECL_INITIAL (new_decls) != error_mark_node)
4025 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
4028 cp_error ("jump to label `%D'", decl);
4030 cp_error_at (" crosses initialization of `%#D'",
4033 new_decls = TREE_CHAIN (new_decls);
4035 if ((tree)b == TREE_TYPE (uses))
4041 TREE_CHAIN (prev) = TREE_CHAIN (uses);
4043 named_label_uses = TREE_CHAIN (uses);
4045 current_function_return_value = NULL_TREE;
4052 struct binding_level *level;
4053 struct cp_switch *next;
4056 static struct cp_switch *switch_stack;
4062 = (struct cp_switch *) oballoc (sizeof (struct cp_switch));
4063 p->level = current_binding_level;
4064 p->next = switch_stack;
4071 switch_stack = switch_stack->next;
4074 /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */
4075 /* XXX Note decl is never actually used. (bpk) */
4077 define_case_label (decl)
4080 tree cleanup = last_cleanup_this_contour ();
4081 struct binding_level *b = current_binding_level;
4086 static int explained = 0;
4087 cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
4088 warning ("where case label appears here");
4091 warning ("(enclose actions of previous case statements requiring");
4092 warning ("destructors in their own binding contours.)");
4097 for (; b && b != switch_stack->level; b = b->level_chain)
4099 tree new_decls = b->names;
4100 for (; new_decls; new_decls = TREE_CHAIN (new_decls))
4102 if (TREE_CODE (new_decls) == VAR_DECL
4103 /* Don't complain about crossing initialization
4104 of internal entities. They can't be accessed,
4105 and they should be cleaned up
4106 by the time we get to the label. */
4107 && ! DECL_ARTIFICIAL (new_decls)
4108 && ((DECL_INITIAL (new_decls) != NULL_TREE
4109 && DECL_INITIAL (new_decls) != error_mark_node)
4110 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
4113 error ("jump to case label");
4115 cp_error_at (" crosses initialization of `%#D'",
4121 /* After labels, make any new cleanups go into their
4122 own new (temporary) binding contour. */
4124 current_binding_level->more_cleanups_ok = 0;
4125 current_function_return_value = NULL_TREE;
4128 /* Return the list of declarations of the current level.
4129 Note that this list is in reverse order unless/until
4130 you nreverse it; and when you do nreverse it, you must
4131 store the result back using `storedecls' or you will lose. */
4136 return current_binding_level->names;
4139 /* Return the list of type-tags (for structs, etc) of the current level. */
4144 return current_binding_level->tags;
4147 /* Store the list of declarations of the current level.
4148 This is done for the parameter declarations of a function being defined,
4149 after they are modified in the light of any missing parameters. */
4155 current_binding_level->names = decls;
4158 /* Similarly, store the list of tags of the current level. */
4164 current_binding_level->tags = tags;
4167 /* Given NAME, an IDENTIFIER_NODE,
4168 return the structure (or union or enum) definition for that name.
4169 Searches binding levels from BINDING_LEVEL up to the global level.
4170 If THISLEVEL_ONLY is nonzero, searches only the specified context
4171 (but skips any tag-transparent contexts to find one that is
4172 meaningful for tags).
4173 FORM says which kind of type the caller wants;
4174 it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
4175 If the wrong kind of type is found, and it's not a template, an error is
4179 lookup_tag (form, name, binding_level, thislevel_only)
4180 enum tree_code form;
4181 struct binding_level *binding_level;
4185 register struct binding_level *level;
4187 for (level = binding_level; level; level = level->level_chain)
4190 if (ANON_AGGRNAME_P (name))
4191 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
4193 /* There's no need for error checking here, because
4194 anon names are unique throughout the compilation. */
4195 if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
4196 return TREE_VALUE (tail);
4199 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
4201 if (TREE_PURPOSE (tail) == name)
4203 enum tree_code code = TREE_CODE (TREE_VALUE (tail));
4204 /* Should tighten this up; it'll probably permit
4205 UNION_TYPE and a struct template, for example. */
4207 && !(form != ENUMERAL_TYPE
4208 && (code == TEMPLATE_DECL
4209 || code == UNINSTANTIATED_P_TYPE)))
4212 /* Definition isn't the kind we were looking for. */
4213 cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
4217 return TREE_VALUE (tail);
4220 if (thislevel_only && ! level->tag_transparent)
4222 if (current_class_type && level->level_chain == global_binding_level)
4224 /* Try looking in this class's tags before heading into
4225 global binding level. */
4226 tree context = current_class_type;
4229 switch (TREE_CODE_CLASS (TREE_CODE (context)))
4233 these_tags = CLASSTYPE_TAGS (context);
4234 if (ANON_AGGRNAME_P (name))
4237 if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
4239 return TREE_VALUE (tail);
4240 these_tags = TREE_CHAIN (these_tags);
4245 if (TREE_PURPOSE (these_tags) == name)
4247 if (TREE_CODE (TREE_VALUE (these_tags)) != form)
4249 cp_error ("`%#D' redeclared as %C in class scope",
4250 TREE_VALUE (tail), form);
4253 return TREE_VALUE (tail);
4255 these_tags = TREE_CHAIN (these_tags);
4257 /* If this type is not yet complete, then don't
4258 look at its context. */
4259 if (TYPE_SIZE (context) == NULL_TREE)
4261 /* Go to next enclosing type, if any. */
4262 context = DECL_CONTEXT (TYPE_NAME (context));
4265 context = DECL_CONTEXT (context);
4268 my_friendly_abort (10);
4280 set_current_level_tags_transparency (tags_transparent)
4281 int tags_transparent;
4283 current_binding_level->tag_transparent = tags_transparent;
4286 /* Given a type, find the tag that was defined for it and return the tag name.
4287 Otherwise return 0. However, the value can never be 0
4288 in the cases in which this is used.
4290 C++: If NAME is non-zero, this is the new name to install. This is
4291 done when replacing anonymous tags with real tag names. */
4294 lookup_tag_reverse (type, name)
4298 register struct binding_level *level;
4300 for (level = current_binding_level; level; level = level->level_chain)
4303 for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
4305 if (TREE_VALUE (tail) == type)
4308 TREE_PURPOSE (tail) = name;
4309 return TREE_PURPOSE (tail);
4316 /* Given type TYPE which was not declared in C++ language context,
4317 attempt to find a name by which it is referred. */
4319 typedecl_for_tag (tag)
4322 struct binding_level *b = current_binding_level;
4324 if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
4325 return TYPE_NAME (tag);
4329 tree decls = b->names;
4332 if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
4334 decls = TREE_CHAIN (decls);
4343 /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
4344 Return the type value, or NULL_TREE if not found. */
4346 lookup_nested_type (type, context)
4350 if (context == NULL_TREE)
4354 switch (TREE_CODE (context))
4358 tree ctype = TREE_TYPE (context);
4359 tree match = value_member (type, CLASSTYPE_TAGS (ctype));
4361 return TREE_VALUE (match);
4362 context = DECL_CONTEXT (context);
4364 /* When we have a nested class whose member functions have
4365 local types (e.g., a set of enums), we'll arrive here
4366 with the DECL_CONTEXT as the actual RECORD_TYPE node for
4367 the enclosing class. Instead, we want to make sure we
4368 come back in here with the TYPE_DECL, not the RECORD_TYPE. */
4369 if (context && TREE_CODE (context) == RECORD_TYPE)
4370 context = TREE_CHAIN (context);
4374 if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
4375 return lookup_name (TYPE_IDENTIFIER (type), 1);
4378 my_friendly_abort (12);
4384 /* Look up NAME in the NAMESPACE. */
4386 lookup_namespace_name (namespace, name)
4387 tree namespace, name;
4389 struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace);
4392 for (x = NULL_TREE; b && !x; b = b->level_chain)
4394 for (x = b->names; x; x = TREE_CHAIN (x))
4395 if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name)
4397 /* Must find directly in the namespace. */
4403 /* Look up NAME in the current binding level and its superiors in the
4404 namespace of variables, functions and typedefs. Return a ..._DECL
4405 node of some kind representing its definition if there is only one
4406 such declaration, or return a TREE_LIST with all the overloaded
4407 definitions if there are many, or return 0 if it is undefined.
4409 If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
4410 If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
4411 Otherwise we prefer non-TYPE_DECLs. */
4414 lookup_name_real (name, prefer_type, nonclass)
4416 int prefer_type, nonclass;
4420 tree from_obj = NULL_TREE;
4422 if (prefer_type == -2)
4424 extern int looking_for_typename;
4428 prefer_type = looking_for_typename;
4432 else if (got_object != error_mark_node)
4437 if (type == error_mark_node)
4438 return error_mark_node;
4439 else if (type == void_type_node)
4440 val = IDENTIFIER_GLOBAL_VALUE (name);
4441 else if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
4442 /* TFIXME -- don't do this for UPTs in new model. */
4443 || TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
4445 if (prefer_type > 0)
4446 val = create_nested_upt (type, name);
4450 else if (TREE_CODE (type) == NAMESPACE_DECL)
4452 val = lookup_namespace_name (type, name);
4454 else if (! IS_AGGR_TYPE (type))
4455 /* Someone else will give an error about this if needed. */
4457 else if (TYPE_BEING_DEFINED (type))
4459 val = IDENTIFIER_CLASS_VALUE (name);
4460 if (val && DECL_CONTEXT (val) != type)
4462 struct binding_level *b = class_binding_level;
4463 for (val = NULL_TREE; b; b = b->level_chain)
4465 tree t = purpose_member (name, b->class_shadowed);
4466 if (t && TREE_VALUE (t)
4467 && DECL_CONTEXT (TREE_VALUE (t)) == type)
4469 val = TREE_VALUE (t);
4474 if (val == NULL_TREE
4475 && CLASSTYPE_LOCAL_TYPEDECLS (type))
4476 val = lookup_field (type, name, 0, 1);
4478 else if (type == current_class_type)
4479 val = IDENTIFIER_CLASS_VALUE (name);
4481 val = lookup_field (type, name, 0, prefer_type);
4489 /* This special lookup only applies to types. */
4490 else if (got_object && val && TREE_CODE (val) == TYPE_DECL)
4494 if (current_binding_level != global_binding_level
4495 && IDENTIFIER_LOCAL_VALUE (name))
4496 val = IDENTIFIER_LOCAL_VALUE (name);
4497 /* In C++ class fields are between local and global scope,
4498 just before the global scope. */
4499 else if (current_class_type && ! nonclass)
4501 val = IDENTIFIER_CLASS_VALUE (name);
4502 if (val == NULL_TREE
4503 && TYPE_BEING_DEFINED (current_class_type)
4504 && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
4505 /* Try to find values from base classes if we are presently
4506 defining a type. We are presently only interested in
4508 val = lookup_field (current_class_type, name, 0, 1);
4510 /* yylex() calls this with -2, since we should never start digging for
4511 the nested name at the point where we haven't even, for example,
4512 created the COMPONENT_REF or anything like that. */
4513 if (val == NULL_TREE)
4514 val = lookup_nested_field (name, ! yylex);
4516 if (val == NULL_TREE)
4517 val = IDENTIFIER_GLOBAL_VALUE (name);
4520 val = IDENTIFIER_GLOBAL_VALUE (name);
4525 if (from_obj && from_obj != val)
4526 cp_error ("lookup in the scope of `%#T' does not match lookup in the current scope",
4529 if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template)
4530 || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0)
4532 else if (IDENTIFIER_HAS_TYPE_VALUE (name))
4533 val = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
4534 else if (TREE_TYPE (val) == error_mark_node)
4535 val = error_mark_node;
4544 lookup_name_nonclass (name)
4547 return lookup_name_real (name, 0, 1);
4551 lookup_name (name, prefer_type)
4555 return lookup_name_real (name, prefer_type, 0);
4558 /* Similar to `lookup_name' but look only at current binding level. */
4561 lookup_name_current_level (name)
4564 register tree t = NULL_TREE;
4566 if (current_binding_level == global_binding_level)
4568 t = IDENTIFIER_GLOBAL_VALUE (name);
4570 /* extern "C" function() */
4571 if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
4574 else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
4576 struct binding_level *b = current_binding_level;
4579 for (t = b->names; t; t = TREE_CHAIN (t))
4580 if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name)
4594 /* Arrange for the user to get a source line number, even when the
4595 compiler is going down in flames, so that she at least has a
4596 chance of working around problems in the compiler. We used to
4597 call error(), but that let the segmentation fault continue
4598 through; now, it's much more passive by asking them to send the
4599 maintainers mail about the problem. */
4605 signal (SIGSEGV, SIG_DFL);
4607 signal (SIGIOT, SIG_DFL);
4610 signal (SIGILL, SIG_DFL);
4613 signal (SIGABRT, SIG_DFL);
4616 signal (SIGBUS, SIG_DFL);
4618 my_friendly_abort (0);
4621 /* Array for holding types considered "built-in". These types
4622 are output in the module in which `main' is defined. */
4623 static tree *builtin_type_tdescs_arr;
4624 static int builtin_type_tdescs_len, builtin_type_tdescs_max;
4626 /* Push the declarations of builtin types into the namespace.
4627 RID_INDEX, if < RID_MAX is the index of the builtin type
4628 in the array RID_POINTERS. NAME is the name used when looking
4629 up the builtin type. TYPE is the _TYPE node for the builtin type. */
4632 record_builtin_type (rid_index, name, type)
4637 tree rname = NULL_TREE, tname = NULL_TREE;
4640 if ((int) rid_index < (int) RID_MAX)
4641 rname = ridpointers[(int) rid_index];
4643 tname = get_identifier (name);
4645 TYPE_BUILT_IN (type) = 1;
4649 #if 0 /* not yet, should get fixed properly later */
4650 tdecl = pushdecl (make_type_decl (tname, type));
4652 tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
4654 set_identifier_type_value (tname, NULL_TREE);
4655 if ((int) rid_index < (int) RID_MAX)
4656 IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
4658 if (rname != NULL_TREE)
4660 if (tname != NULL_TREE)
4662 set_identifier_type_value (rname, NULL_TREE);
4663 IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
4667 #if 0 /* not yet, should get fixed properly later */
4668 tdecl = pushdecl (make_type_decl (rname, type));
4670 tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
4672 set_identifier_type_value (rname, NULL_TREE);
4678 if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
4680 builtin_type_tdescs_max *= 2;
4681 builtin_type_tdescs_arr
4682 = (tree *)xrealloc (builtin_type_tdescs_arr,
4683 builtin_type_tdescs_max * sizeof (tree));
4685 builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
4686 if (TREE_CODE (type) != POINTER_TYPE)
4688 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4689 = build_pointer_type (type);
4690 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4691 = build_pointer_type (build_type_variant (type, 1, 0));
4693 if (TREE_CODE (type) != VOID_TYPE)
4695 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4696 = build_reference_type (type);
4697 builtin_type_tdescs_arr[builtin_type_tdescs_len++]
4698 = build_reference_type (build_type_variant (type, 1, 0));
4704 output_builtin_tdesc_entries ()
4706 extern struct obstack permanent_obstack;
4708 /* If there's more than one main in this file, don't crash. */
4709 if (builtin_type_tdescs_arr == 0)
4712 push_obstacks (&permanent_obstack, &permanent_obstack);
4713 while (builtin_type_tdescs_len > 0)
4715 tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
4716 tree tdesc = build_t_desc (type, 0);
4717 TREE_ASM_WRITTEN (tdesc) = 0;
4718 build_t_desc (type, 2);
4720 free (builtin_type_tdescs_arr);
4721 builtin_type_tdescs_arr = 0;
4725 /* Push overloaded decl, in global scope, with one argument so it
4726 can be used as a callback from define_function. */
4728 push_overloaded_decl_1 (x)
4731 push_overloaded_decl (x, 0);
4737 tree auto_function (name, type, code)
4739 enum built_in_function code;
4741 return define_function
4742 (IDENTIFIER_POINTER (name), type, code, (void (*)())push_overloaded_decl_1,
4743 IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type),
4747 /* Create the predefined scalar types of C,
4748 and some nodes representing standard constants (0, 1, (void *)0).
4749 Initialize the global binding level.
4750 Make definitions for built-in primitive functions. */
4753 init_decl_processing ()
4756 register tree endlink, int_endlink, double_endlink, ptr_endlink;
4758 /* Either char* or void*. */
4759 tree traditional_ptr_type_node;
4760 /* Data type of memcpy. */
4762 #if 0 /* Not yet. */
4763 /* Data type of strncpy. */
4766 int wchar_type_size;
4768 tree array_domain_type;
4769 extern int flag_strict_prototype;
4771 /* Have to make these distinct before we try using them. */
4772 lang_name_cplusplus = get_identifier ("C++");
4773 lang_name_c = get_identifier ("C");
4775 if (flag_strict_prototype == 2)
4778 strict_prototypes_lang_c = strict_prototypes_lang_cplusplus;
4781 strict_prototypes_lang_c = flag_strict_prototype;
4784 current_lang_name = lang_name_c;
4786 current_function_decl = NULL_TREE;
4787 named_labels = NULL_TREE;
4788 named_label_uses = NULL_TREE;
4789 current_binding_level = NULL_BINDING_LEVEL;
4790 free_binding_level = NULL_BINDING_LEVEL;
4792 /* Because most segmentation signals can be traced back into user
4793 code, catch them and at least give the user a chance of working
4794 around compiler bugs. */
4795 signal (SIGSEGV, signal_catch);
4797 /* We will also catch aborts in the back-end through signal_catch and
4798 give the user a chance to see where the error might be, and to defeat
4799 aborts in the back-end when there have been errors previously in their
4802 signal (SIGIOT, signal_catch);
4805 signal (SIGILL, signal_catch);
4808 signal (SIGABRT, signal_catch);
4811 signal (SIGBUS, signal_catch);
4814 gcc_obstack_init (&decl_obstack);
4817 builtin_type_tdescs_max = 100;
4818 builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
4821 /* Must lay these out before anything else gets laid out. */
4822 error_mark_node = make_node (ERROR_MARK);
4823 TREE_PERMANENT (error_mark_node) = 1;
4824 TREE_TYPE (error_mark_node) = error_mark_node;
4825 error_mark_list = build_tree_list (error_mark_node, error_mark_node);
4826 TREE_TYPE (error_mark_list) = error_mark_node;
4828 /* Make the binding_level structure for global names. */
4830 global_binding_level = current_binding_level;
4832 this_identifier = get_identifier (THIS_NAME);
4833 in_charge_identifier = get_identifier (IN_CHARGE_NAME);
4834 pfn_identifier = get_identifier (VTABLE_PFN_NAME);
4835 index_identifier = get_identifier (VTABLE_INDEX_NAME);
4836 delta_identifier = get_identifier (VTABLE_DELTA_NAME);
4837 delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
4838 pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
4839 if (flag_handle_signatures)
4841 tag_identifier = get_identifier (SIGTABLE_TAG_NAME);
4842 vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME);
4843 vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME);
4846 /* Define `int' and `char' first so that dbx will output them first. */
4848 integer_type_node = make_signed_type (INT_TYPE_SIZE);
4849 record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
4851 /* Define `char', which is like either `signed char' or `unsigned char'
4852 but not the same as either. */
4856 ? make_signed_type (CHAR_TYPE_SIZE)
4857 : make_unsigned_type (CHAR_TYPE_SIZE));
4858 record_builtin_type (RID_CHAR, "char", char_type_node);
4860 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
4861 record_builtin_type (RID_LONG, "long int", long_integer_type_node);
4863 unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
4864 record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
4866 long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
4867 record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
4868 record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
4870 long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
4871 record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
4873 long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
4874 record_builtin_type (RID_MAX, "long long unsigned int",
4875 long_long_unsigned_type_node);
4876 record_builtin_type (RID_MAX, "long long unsigned",
4877 long_long_unsigned_type_node);
4879 /* `unsigned long' is the standard type for sizeof.
4880 Traditionally, use a signed type.
4881 Note that stddef.h uses `unsigned long',
4882 and this must agree, even of long and int are the same size. */
4884 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
4885 if (flag_traditional && TREE_UNSIGNED (sizetype))
4886 sizetype = signed_type (sizetype);
4889 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
4891 TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
4892 TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
4893 TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
4894 TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
4895 TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
4896 TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
4897 TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
4899 short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
4900 record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
4901 short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
4902 record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
4903 record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
4905 /* Define both `signed char' and `unsigned char'. */
4906 signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
4907 record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
4908 unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
4909 record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
4911 /* These are types that type_for_size and type_for_mode use. */
4912 intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
4913 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
4914 intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
4915 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
4916 intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
4917 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
4918 intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
4919 pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
4920 unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
4921 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
4922 unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
4923 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
4924 unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
4925 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
4926 unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
4927 pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
4929 float_type_node = make_node (REAL_TYPE);
4930 TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
4931 record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
4932 layout_type (float_type_node);
4934 double_type_node = make_node (REAL_TYPE);
4935 if (flag_short_double)
4936 TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
4938 TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
4939 record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
4940 layout_type (double_type_node);
4942 long_double_type_node = make_node (REAL_TYPE);
4943 TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
4944 record_builtin_type (RID_MAX, "long double", long_double_type_node);
4945 layout_type (long_double_type_node);
4947 integer_zero_node = build_int_2 (0, 0);
4948 TREE_TYPE (integer_zero_node) = integer_type_node;
4949 integer_one_node = build_int_2 (1, 0);
4950 TREE_TYPE (integer_one_node) = integer_type_node;
4951 integer_two_node = build_int_2 (2, 0);
4952 TREE_TYPE (integer_two_node) = integer_type_node;
4953 integer_three_node = build_int_2 (3, 0);
4954 TREE_TYPE (integer_three_node) = integer_type_node;
4956 boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
4957 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
4958 record_builtin_type (RID_BOOL, "bool", boolean_type_node);
4959 boolean_false_node = build_int_2 (0, 0);
4960 TREE_TYPE (boolean_false_node) = boolean_type_node;
4961 boolean_true_node = build_int_2 (1, 0);
4962 TREE_TYPE (boolean_true_node) = boolean_type_node;
4964 /* These are needed by stor-layout.c. */
4965 size_zero_node = size_int (0);
4966 size_one_node = size_int (1);
4968 void_type_node = make_node (VOID_TYPE);
4969 record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
4970 layout_type (void_type_node); /* Uses integer_zero_node. */
4971 void_list_node = build_tree_list (NULL_TREE, void_type_node);
4972 TREE_PARMLIST (void_list_node) = 1;
4974 null_pointer_node = build_int_2 (0, 0);
4975 TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
4976 layout_type (TREE_TYPE (null_pointer_node));
4978 /* Used for expressions that do nothing, but are not errors. */
4979 void_zero_node = build_int_2 (0, 0);
4980 TREE_TYPE (void_zero_node) = void_type_node;
4982 string_type_node = build_pointer_type (char_type_node);
4983 const_string_type_node =
4984 build_pointer_type (build_type_variant (char_type_node, 1, 0));
4985 record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
4987 /* Make a type to be the domain of a few array types
4988 whose domains don't really matter.
4989 200 is small enough that it always fits in size_t
4990 and large enough that it can hold most function names for the
4991 initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */
4992 array_domain_type = build_index_type (build_int_2 (200, 0));
4994 /* make a type for arrays of characters.
4995 With luck nothing will ever really depend on the length of this
4997 char_array_type_node
4998 = build_array_type (char_type_node, array_domain_type);
4999 /* Likewise for arrays of ints. */
5001 = build_array_type (integer_type_node, array_domain_type);
5003 /* This is just some anonymous class type. Nobody should ever
5004 need to look inside this envelope. */
5005 class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
5007 default_function_type
5008 = build_function_type (integer_type_node, NULL_TREE);
5009 build_pointer_type (default_function_type);
5011 ptr_type_node = build_pointer_type (void_type_node);
5012 const_ptr_type_node =
5013 build_pointer_type (build_type_variant (void_type_node, 1, 0));
5014 record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
5015 endlink = void_list_node;
5016 int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
5017 double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
5018 ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
5021 = build_function_type (double_type_node, double_endlink);
5023 double_ftype_double_double
5024 = build_function_type (double_type_node,
5025 tree_cons (NULL_TREE, double_type_node,
5029 = build_function_type (integer_type_node, int_endlink);
5032 = build_function_type (long_integer_type_node,
5033 tree_cons (NULL_TREE, long_integer_type_node,
5036 void_ftype_ptr_ptr_int
5037 = build_function_type (void_type_node,
5038 tree_cons (NULL_TREE, ptr_type_node,
5039 tree_cons (NULL_TREE, ptr_type_node,
5042 int_ftype_cptr_cptr_sizet
5043 = build_function_type (integer_type_node,
5044 tree_cons (NULL_TREE, const_ptr_type_node,
5045 tree_cons (NULL_TREE, const_ptr_type_node,
5046 tree_cons (NULL_TREE,
5050 void_ftype_ptr_int_int
5051 = build_function_type (void_type_node,
5052 tree_cons (NULL_TREE, ptr_type_node,
5053 tree_cons (NULL_TREE, integer_type_node,
5056 string_ftype_ptr_ptr /* strcpy prototype */
5057 = build_function_type (string_type_node,
5058 tree_cons (NULL_TREE, string_type_node,
5059 tree_cons (NULL_TREE,
5060 const_string_type_node,
5065 strncpy_ftype /* strncpy prototype */
5066 = build_function_type (string_type_node,
5067 tree_cons (NULL_TREE, string_type_node,
5068 tree_cons (NULL_TREE, const_string_type_node,
5069 tree_cons (NULL_TREE,
5074 int_ftype_string_string /* strcmp prototype */
5075 = build_function_type (integer_type_node,
5076 tree_cons (NULL_TREE, const_string_type_node,
5077 tree_cons (NULL_TREE,
5078 const_string_type_node,
5081 sizet_ftype_string /* strlen prototype */
5082 = build_function_type (sizetype,
5083 tree_cons (NULL_TREE, const_string_type_node,
5086 traditional_ptr_type_node
5087 = (flag_traditional ? string_type_node : ptr_type_node);
5089 memcpy_ftype /* memcpy prototype */
5090 = build_function_type (traditional_ptr_type_node,
5091 tree_cons (NULL_TREE, ptr_type_node,
5092 tree_cons (NULL_TREE, const_ptr_type_node,
5093 tree_cons (NULL_TREE,
5097 if (flag_huge_objects)
5098 delta_type_node = long_integer_type_node;
5100 delta_type_node = short_integer_type_node;
5102 builtin_function ("__builtin_constant_p", int_ftype_int,
5103 BUILT_IN_CONSTANT_P, NULL_PTR);
5105 builtin_return_address_fndecl =
5106 builtin_function ("__builtin_return_address",
5107 build_function_type (ptr_type_node,
5108 tree_cons (NULL_TREE,
5111 BUILT_IN_RETURN_ADDRESS, NULL_PTR);
5113 builtin_function ("__builtin_frame_address",
5114 build_function_type (ptr_type_node,
5115 tree_cons (NULL_TREE,
5118 BUILT_IN_FRAME_ADDRESS, NULL_PTR);
5121 builtin_function ("__builtin_alloca",
5122 build_function_type (ptr_type_node,
5123 tree_cons (NULL_TREE,
5126 BUILT_IN_ALLOCA, "alloca");
5127 /* Define alloca, ffs as builtins.
5128 Declare _exit just to mark it as volatile. */
5129 if (! flag_no_builtin && !flag_no_nonansi_builtin)
5131 temp = builtin_function ("alloca",
5132 build_function_type (ptr_type_node,
5133 tree_cons (NULL_TREE,
5136 BUILT_IN_ALLOCA, NULL_PTR);
5137 /* Suppress error if redefined as a non-function. */
5138 DECL_BUILT_IN_NONANSI (temp) = 1;
5139 temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
5140 /* Suppress error if redefined as a non-function. */
5141 DECL_BUILT_IN_NONANSI (temp) = 1;
5142 temp = builtin_function ("_exit", build_function_type (void_type_node,
5144 NOT_BUILT_IN, NULL_PTR);
5145 TREE_THIS_VOLATILE (temp) = 1;
5146 TREE_SIDE_EFFECTS (temp) = 1;
5147 /* Suppress error if redefined as a non-function. */
5148 DECL_BUILT_IN_NONANSI (temp) = 1;
5151 builtin_function ("__builtin_abs", int_ftype_int,
5152 BUILT_IN_ABS, NULL_PTR);
5153 builtin_function ("__builtin_fabs", double_ftype_double,
5154 BUILT_IN_FABS, NULL_PTR);
5155 builtin_function ("__builtin_labs", long_ftype_long,
5156 BUILT_IN_LABS, NULL_PTR);
5157 builtin_function ("__builtin_ffs", int_ftype_int,
5158 BUILT_IN_FFS, NULL_PTR);
5159 builtin_function ("__builtin_fsqrt", double_ftype_double,
5160 BUILT_IN_FSQRT, NULL_PTR);
5161 builtin_function ("__builtin_sin", double_ftype_double,
5162 BUILT_IN_SIN, "sin");
5163 builtin_function ("__builtin_cos", double_ftype_double,
5164 BUILT_IN_COS, "cos");
5165 builtin_function ("__builtin_saveregs",
5166 build_function_type (ptr_type_node, NULL_TREE),
5167 BUILT_IN_SAVEREGS, NULL_PTR);
5168 /* EXPAND_BUILTIN_VARARGS is obsolete. */
5170 builtin_function ("__builtin_varargs",
5171 build_function_type (ptr_type_node,
5172 tree_cons (NULL_TREE,
5175 BUILT_IN_VARARGS, NULL_PTR);
5177 builtin_function ("__builtin_classify_type", default_function_type,
5178 BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
5179 builtin_function ("__builtin_next_arg",
5180 build_function_type (ptr_type_node, NULL_TREE),
5181 BUILT_IN_NEXT_ARG, NULL_PTR);
5182 builtin_function ("__builtin_args_info",
5183 build_function_type (integer_type_node,
5184 tree_cons (NULL_TREE,
5187 BUILT_IN_ARGS_INFO, NULL_PTR);
5189 /* Untyped call and return. */
5190 builtin_function ("__builtin_apply_args",
5191 build_function_type (ptr_type_node, NULL_TREE),
5192 BUILT_IN_APPLY_ARGS, NULL_PTR);
5194 temp = tree_cons (NULL_TREE,
5195 build_pointer_type (build_function_type (void_type_node,
5197 tree_cons (NULL_TREE,
5199 tree_cons (NULL_TREE,
5202 builtin_function ("__builtin_apply",
5203 build_function_type (ptr_type_node, temp),
5204 BUILT_IN_APPLY, NULL_PTR);
5205 builtin_function ("__builtin_return",
5206 build_function_type (void_type_node,
5207 tree_cons (NULL_TREE,
5210 BUILT_IN_RETURN, NULL_PTR);
5212 /* Currently under experimentation. */
5213 builtin_function ("__builtin_memcpy", memcpy_ftype,
5214 BUILT_IN_MEMCPY, "memcpy");
5215 builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
5216 BUILT_IN_MEMCMP, "memcmp");
5217 builtin_function ("__builtin_strcmp", int_ftype_string_string,
5218 BUILT_IN_STRCMP, "strcmp");
5219 builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
5220 BUILT_IN_STRCPY, "strcpy");
5223 builtin_function ("__builtin_strncpy", strncpy_ftype,
5224 BUILT_IN_STRNCPY, "strncpy");
5226 builtin_function ("__builtin_strlen", sizet_ftype_string,
5227 BUILT_IN_STRLEN, "strlen");
5229 if (!flag_no_builtin)
5231 #if 0 /* These do not work well with libg++. */
5232 builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
5233 builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
5234 builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
5236 builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
5237 builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
5239 builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR);
5240 builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
5244 builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR);
5246 builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR);
5247 builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
5248 builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
5250 /* Declare these functions volatile
5251 to avoid spurious "control drops through" warnings. */
5252 temp = builtin_function ("abort",
5253 build_function_type (void_type_node, endlink),
5254 NOT_BUILT_IN, NULL_PTR);
5255 TREE_THIS_VOLATILE (temp) = 1;
5256 TREE_SIDE_EFFECTS (temp) = 1;
5257 /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
5259 DECL_BUILT_IN_NONANSI (temp) = 1;
5260 temp = builtin_function ("exit", build_function_type (void_type_node,
5262 NOT_BUILT_IN, NULL_PTR);
5263 TREE_THIS_VOLATILE (temp) = 1;
5264 TREE_SIDE_EFFECTS (temp) = 1;
5265 DECL_BUILT_IN_NONANSI (temp) = 1;
5269 /* Support for these has not been written in either expand_builtin
5270 or build_function_call. */
5271 builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR);
5272 builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR);
5273 builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
5275 builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, NULL_PTR);
5276 builtin_function ("__builtin_fmod", double_ftype_double_double,
5277 BUILT_IN_FMOD, NULL_PTR);
5278 builtin_function ("__builtin_frem", double_ftype_double_double,
5279 BUILT_IN_FREM, NULL_PTR);
5280 builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET,
5282 builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
5284 builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
5288 /* C++ extensions */
5290 unknown_type_node = make_node (UNKNOWN_TYPE);
5291 #if 0 /* not yet, should get fixed properly later */
5292 pushdecl (make_type_decl (get_identifier ("unknown type"),
5293 unknown_type_node));
5295 decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
5296 unknown_type_node));
5297 /* Make sure the "unknown type" typedecl gets ignored for debug info. */
5298 DECL_IGNORED_P (decl) = 1;
5299 TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
5301 TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
5302 TYPE_ALIGN (unknown_type_node) = 1;
5303 TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
5304 /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
5305 TREE_TYPE (unknown_type_node) = unknown_type_node;
5306 /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
5307 TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
5308 TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
5310 /* This is for handling opaque types in signatures. */
5311 opaque_type_node = copy_node (ptr_type_node);
5312 TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
5313 record_builtin_type (RID_MAX, 0, opaque_type_node);
5315 /* This is special for C++ so functions can be overloaded. */
5317 = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
5318 wchar_type_size = TYPE_PRECISION (wchar_type_node);
5319 signed_wchar_type_node = make_signed_type (wchar_type_size);
5320 unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
5322 = TREE_UNSIGNED (wchar_type_node)
5323 ? unsigned_wchar_type_node
5324 : signed_wchar_type_node;
5325 record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
5327 /* Artificial declaration of wchar_t -- can be bashed */
5328 wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"),
5330 pushdecl (wchar_decl_node);
5332 /* This is for wide string constants. */
5333 wchar_array_type_node
5334 = build_array_type (wchar_type_node, array_domain_type);
5336 /* This is a hack that should go away when we deliver the
5340 builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, NULL_PTR);
5341 pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
5344 if (flag_vtable_thunks)
5346 /* Make sure we get a unique function type, so we can give
5347 its pointer type a name. (This wins for gdb.) */
5348 tree vfunc_type = make_node (FUNCTION_TYPE);
5349 TREE_TYPE (vfunc_type) = integer_type_node;
5350 TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
5351 layout_type (vfunc_type);
5353 vtable_entry_type = build_pointer_type (vfunc_type);
5357 vtable_entry_type = make_lang_type (RECORD_TYPE);
5358 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
5360 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
5362 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
5364 finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
5367 /* Make this part of an invisible union. */
5368 fields[3] = copy_node (fields[2]);
5369 TREE_TYPE (fields[3]) = delta_type_node;
5370 DECL_NAME (fields[3]) = delta2_identifier;
5371 DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
5372 DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
5373 TREE_UNSIGNED (fields[3]) = 0;
5374 TREE_CHAIN (fields[2]) = fields[3];
5375 vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
5377 record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
5380 = build_array_type (vtable_entry_type, NULL_TREE);
5381 layout_type (vtbl_type_node);
5382 vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0);
5383 record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
5385 /* Simplify life by making a "sigtable_entry_type". Give its
5386 fields names so that the debugger can use them. */
5388 if (flag_handle_signatures)
5390 sigtable_entry_type = make_lang_type (RECORD_TYPE);
5391 fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier,
5393 fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier,
5395 fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier,
5397 fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier,
5399 fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
5402 /* Set the alignment to the max of the alignment of ptr_type_node and
5403 delta_type_node. Double alignment wastes a word on the Sparc. */
5404 finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4,
5405 (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node))
5409 /* Make this part of an invisible union. */
5410 fields[5] = copy_node (fields[4]);
5411 TREE_TYPE (fields[5]) = delta_type_node;
5412 DECL_NAME (fields[5]) = vt_off_identifier;
5413 DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node);
5414 DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node);
5415 TREE_UNSIGNED (fields[5]) = 0;
5416 TREE_CHAIN (fields[4]) = fields[5];
5418 sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
5419 record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
5425 /* Must build __t_desc type. Currently, type descriptors look like this:
5432 struct __t_desc *points_to;
5433 int ivars_count, meths_count;
5434 struct __i_desc *ivars[];
5435 struct __m_desc *meths[];
5436 struct __t_desc *parents[];
5437 struct __t_desc *vbases[];
5441 ...as per Linton's paper. */
5443 __t_desc_type_node = make_lang_type (RECORD_TYPE);
5444 __i_desc_type_node = make_lang_type (RECORD_TYPE);
5445 __m_desc_type_node = make_lang_type (RECORD_TYPE);
5446 __t_desc_array_type =
5447 build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE);
5448 __i_desc_array_type =
5449 build_array_type (build_pointer_type (__i_desc_type_node), NULL_TREE);
5450 __m_desc_array_type =
5451 build_array_type (build_pointer_type (__m_desc_type_node), NULL_TREE);
5453 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
5455 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
5456 unsigned_type_node);
5457 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
5458 unsigned_type_node);
5459 fields[3] = build_lang_field_decl (FIELD_DECL,
5460 get_identifier ("points_to"),
5461 build_pointer_type (__t_desc_type_node));
5462 fields[4] = build_lang_field_decl (FIELD_DECL,
5463 get_identifier ("ivars_count"),
5465 fields[5] = build_lang_field_decl (FIELD_DECL,
5466 get_identifier ("meths_count"),
5468 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
5469 build_pointer_type (__i_desc_array_type));
5470 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
5471 build_pointer_type (__m_desc_array_type));
5472 fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
5473 build_pointer_type (__t_desc_array_type));
5474 fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
5475 build_pointer_type (__t_desc_array_type));
5476 fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
5477 build_pointer_type (integer_type_node));
5478 finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
5480 /* ivar descriptors look like this:
5486 struct __t_desc *type;
5490 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
5492 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
5494 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
5495 build_pointer_type (__t_desc_type_node));
5496 finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2,
5499 /* method descriptors look like this:
5505 struct __t_desc *vcontext;
5506 struct __t_desc *return_type;
5509 short required_parms;
5510 struct __t_desc *parm_types[];
5514 fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
5516 fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
5518 fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
5519 build_pointer_type (__t_desc_type_node));
5520 fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
5521 build_pointer_type (__t_desc_type_node));
5522 fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
5523 build_pointer_type (default_function_type));
5524 fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
5525 short_integer_type_node);
5526 fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
5527 short_integer_type_node);
5528 fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
5529 build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE)));
5530 finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7,
5536 int i = builtin_type_tdescs_len;
5539 tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
5540 TREE_ASM_WRITTEN (tdesc) = 1;
5541 TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
5544 #endif /*flag_rtti*/
5547 current_lang_name = lang_name_cplusplus;
5549 auto_function (ansi_opname[(int) NEW_EXPR],
5550 build_function_type (ptr_type_node,
5551 tree_cons (NULL_TREE, sizetype,
5554 auto_function (ansi_opname[(int) VEC_NEW_EXPR],
5555 build_function_type (ptr_type_node,
5556 tree_cons (NULL_TREE, sizetype,
5559 auto_function (ansi_opname[(int) DELETE_EXPR],
5560 build_function_type (void_type_node,
5561 tree_cons (NULL_TREE, ptr_type_node,
5564 auto_function (ansi_opname[(int) VEC_DELETE_EXPR],
5565 build_function_type (void_type_node,
5566 tree_cons (NULL_TREE, ptr_type_node,
5571 = define_function ("__pure_virtual",
5572 build_function_type (void_type_node, void_list_node),
5573 NOT_BUILT_IN, 0, 0);
5575 /* Perform other language dependent initializations. */
5576 init_class_processing ();
5577 init_init_processing ();
5578 init_search_processing ();
5580 if (flag_handle_exceptions)
5581 init_exception_processing ();
5583 init_gc_processing ();
5586 flag_inline_functions = 0;
5588 /* This causes unnecessary emission of inline functions. */
5589 flag_default_inline = 0;
5594 if (! SUPPORTS_WEAK)
5597 /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */
5598 declare_function_name ();
5600 /* Prepare to check format strings against argument lists. */
5601 init_function_format_info ();
5604 /* initialize type descriptor type node of various rtti type. */
5611 tdecl = lookup_name (get_identifier ("type_info"), 0);
5612 if (tdecl == NULL_TREE)
5614 __t_desc_type_node = TREE_TYPE(tdecl);
5615 __tp_desc_type_node = build_pointer_type (__t_desc_type_node);
5618 tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0);
5619 if (tdecl == NULL_TREE)
5621 __baselist_desc_type_node = TREE_TYPE (tdecl);
5624 tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0);
5625 if (tdecl == NULL_TREE)
5627 __bltn_desc_type_node = TREE_TYPE (tdecl);
5629 tdecl = lookup_name (get_identifier ("__user_type_info"), 0);
5630 if (tdecl == NULL_TREE)
5632 __user_desc_type_node = TREE_TYPE (tdecl);
5634 tdecl = lookup_name (get_identifier ("__class_type_info"), 0);
5635 if (tdecl == NULL_TREE)
5637 __class_desc_type_node = TREE_TYPE (tdecl);
5639 tdecl = lookup_field (__class_desc_type_node,
5640 get_identifier ("access_mode"), 0, 0);
5641 if (tdecl == NULL_TREE)
5643 __access_mode_type_node = TREE_TYPE (tdecl);
5645 tdecl = lookup_name (get_identifier ("__attr_type_info"), 0);
5646 if (tdecl == NULL_TREE)
5648 __attr_desc_type_node = TREE_TYPE (tdecl);
5650 tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0);
5651 if (tdecl == NULL_TREE)
5653 __ptr_desc_type_node = TREE_TYPE (tdecl);
5655 tdecl = lookup_name (get_identifier ("__func_type_info"), 0);
5656 if (tdecl == NULL_TREE)
5658 __func_desc_type_node = TREE_TYPE (tdecl);
5660 tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0);
5661 if (tdecl == NULL_TREE)
5663 __ptmf_desc_type_node = TREE_TYPE (tdecl);
5665 tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0);
5666 if (tdecl == NULL_TREE)
5668 __ptmd_desc_type_node = TREE_TYPE (tdecl);
5672 /* Make a definition for a builtin function named NAME and whose data type
5673 is TYPE. TYPE should be a function type with argument types.
5674 FUNCTION_CODE tells later passes how to compile calls to this function.
5675 See tree.h for its possible values.
5677 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
5678 the name to be called if we can't opencode the function. */
5681 define_function (name, type, function_code, pfn, library_name)
5684 enum built_in_function function_code;
5688 tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
5689 DECL_EXTERNAL (decl) = 1;
5690 TREE_PUBLIC (decl) = 1;
5691 DECL_ARTIFICIAL (decl) = 1;
5693 /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
5694 we cannot change DECL_ASSEMBLER_NAME until we have installed this
5695 function in the namespace. */
5696 if (pfn) (*pfn) (decl);
5698 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
5699 make_function_rtl (decl);
5700 if (function_code != NOT_BUILT_IN)
5702 DECL_BUILT_IN (decl) = 1;
5703 DECL_FUNCTION_CODE (decl) = function_code;
5708 /* Called when a declaration is seen that contains no names to declare.
5709 If its type is a reference to a structure, union or enum inherited
5710 from a containing scope, shadow that tag name for the current scope
5711 with a forward reference.
5712 If its type defines a new named structure or union
5713 or defines an enum, it is valid but we need not do anything here.
5714 Otherwise, it is an error.
5716 C++: may have to grok the declspecs to learn about static,
5717 complain for anonymous unions. */
5720 shadow_tag (declspecs)
5724 tree ob_modifier = NULL_TREE;
5726 register enum tree_code code, ok_code = ERROR_MARK;
5727 register tree t = NULL_TREE;
5729 for (link = declspecs; link; link = TREE_CHAIN (link))
5731 register tree value = TREE_VALUE (link);
5733 code = TREE_CODE (value);
5734 if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
5736 my_friendly_assert (TYPE_NAME (value) != NULL_TREE, 261);
5738 if (code == ENUMERAL_TYPE && TYPE_SIZE (value) == 0)
5739 cp_error ("forward declaration of `%#T'", value);
5745 else if (value == ridpointers[(int) RID_STATIC]
5746 || value == ridpointers[(int) RID_EXTERN]
5747 || value == ridpointers[(int) RID_AUTO]
5748 || value == ridpointers[(int) RID_REGISTER]
5749 || value == ridpointers[(int) RID_INLINE]
5750 || value == ridpointers[(int) RID_VIRTUAL]
5751 || value == ridpointers[(int) RID_EXPLICIT])
5752 ob_modifier = value;
5755 /* This is where the variables in an anonymous union are
5756 declared. An anonymous union declaration looks like:
5758 because there is no declarator after the union, the parser
5759 sends that declaration here. */
5760 if (ok_code == UNION_TYPE
5762 && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
5763 && ANON_AGGRNAME_P (TYPE_NAME (t)))
5764 || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
5765 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
5767 /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have
5768 function members. */
5769 if (TYPE_FIELDS (t))
5771 tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0,
5772 NULL_TREE, NULL_TREE);
5773 finish_anon_union (decl);
5776 error ("anonymous union cannot have a function member");
5780 /* Anonymous unions are objects, that's why we only check for
5781 inappropriate specifiers in this branch. */
5785 if (ob_modifier == ridpointers[(int) RID_INLINE]
5786 || ob_modifier == ridpointers[(int) RID_VIRTUAL])
5787 cp_error ("`%D' can only be specified for functions", ob_modifier);
5788 else if (ob_modifier == ridpointers[(int) RID_EXPLICIT])
5789 cp_error ("`%D' can only be specified for constructors",
5792 cp_error ("`%D' can only be specified for objects and functions",
5797 pedwarn ("abstract declarator used as declaration");
5798 else if (found_tag > 1)
5799 pedwarn ("multiple types in one declaration");
5803 /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
5806 groktypename (typename)
5809 if (TREE_CODE (typename) != TREE_LIST)
5811 return grokdeclarator (TREE_VALUE (typename),
5812 TREE_PURPOSE (typename),
5813 TYPENAME, 0, NULL_TREE, NULL_TREE);
5816 /* Decode a declarator in an ordinary declaration or data definition.
5817 This is called as soon as the type information and variable name
5818 have been parsed, before parsing the initializer if any.
5819 Here we create the ..._DECL node, fill in its type,
5820 and put it on the list of decls for the current context.
5821 The ..._DECL node is returned as the value.
5823 Exception: for arrays where the length is not specified,
5824 the type is left null, to be filled in by `cp_finish_decl'.
5826 Function definitions do not come here; they go to start_function
5827 instead. However, external and forward declarations of functions
5828 do go through here. Structure field declarations are done by
5829 grokfield and not through here. */
5831 /* Set this to zero to debug not using the temporary obstack
5832 to parse initializers. */
5833 int debug_temp_inits = 1;
5836 start_decl (declarator, declspecs, initialized, raises)
5837 tree declarator, declspecs;
5842 register tree type, tem;
5844 extern int have_extern_spec;
5845 extern int used_extern_spec;
5847 int init_written = initialized;
5849 /* This should only be done once on the top most decl. */
5850 if (have_extern_spec && !used_extern_spec)
5852 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"),
5854 used_extern_spec = 1;
5857 decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises,
5859 if (decl == NULL_TREE || decl == void_type_node)
5862 type = TREE_TYPE (decl);
5864 /* Don't lose if destructors must be executed at file-level. */
5865 if (TREE_STATIC (decl)
5866 && TYPE_NEEDS_DESTRUCTOR (type)
5867 && !TREE_PERMANENT (decl))
5869 push_obstacks (&permanent_obstack, &permanent_obstack);
5870 decl = copy_node (decl);
5871 if (TREE_CODE (type) == ARRAY_TYPE)
5873 tree itype = TYPE_DOMAIN (type);
5874 if (itype && ! TREE_PERMANENT (itype))
5876 itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
5877 type = build_cplus_array_type (TREE_TYPE (type), itype);
5878 TREE_TYPE (decl) = type;
5884 /* Corresponding pop_obstacks is done in `cp_finish_decl'. */
5885 push_obstacks_nochange ();
5888 = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
5889 ? DECL_CLASS_CONTEXT (decl)
5890 : DECL_CONTEXT (decl);
5892 if (processing_template_decl)
5895 if (TREE_CODE (decl) == FUNCTION_DECL)
5897 /* Declarator is a call_expr; extract arguments from it, since
5898 grokdeclarator didn't do it. */
5900 args = copy_to_permanent (last_function_parms);
5901 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
5903 tree t = TREE_TYPE (decl);
5905 t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
5906 if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE)
5908 t = build_pointer_type (t); /* base type of `this' */
5910 /* I suspect this is wrong. */
5911 t = build_type_variant (t, flag_this_is_variable <= 0,
5912 0); /* type of `this' */
5914 t = build_type_variant (t, 0, 0); /* type of `this' */
5916 t = build (PARM_DECL, t, this_identifier);
5917 TREE_CHAIN (t) = args;
5921 DECL_ARGUMENTS (decl) = args;
5923 d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
5924 TREE_PUBLIC (d) = TREE_PUBLIC (decl);
5925 TREE_STATIC (d) = TREE_STATIC (decl);
5926 DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl)
5927 && !(context && !DECL_THIS_EXTERN (decl)));
5928 DECL_TEMPLATE_RESULT (d) = decl;
5932 /* If this type of object needs a cleanup, and control may
5933 jump past it, make a new binding level so that it is cleaned
5934 up only when it is initialized first. */
5935 if (TYPE_NEEDS_DESTRUCTOR (type)
5936 && current_binding_level->more_cleanups_ok == 0)
5937 pushlevel_temporary (1);
5940 /* Is it valid for this decl to have an initializer at all?
5941 If not, set INITIALIZED to zero, which will indirectly
5942 tell `cp_finish_decl' to ignore the initializer once it is parsed. */
5943 switch (TREE_CODE (decl))
5946 /* typedef foo = bar means give foo the same type as bar.
5947 We haven't parsed bar yet, so `cp_finish_decl' will fix that up.
5948 Any other case of an initialization in a TYPE_DECL is an error. */
5949 if (pedantic || list_length (declspecs) > 1)
5951 cp_error ("typedef `%D' is initialized", decl);
5957 cp_error ("function `%#D' is initialized like a variable", decl);
5962 /* Don't allow initializations for incomplete types except for
5963 arrays which might be completed by the initialization. */
5964 if (type == error_mark_node)
5965 ; /* Don't complain again. */
5966 else if (TYPE_SIZE (type) != NULL_TREE)
5967 ; /* A complete type is ok. */
5968 else if (TREE_CODE (type) != ARRAY_TYPE)
5970 cp_error ("variable `%#D' has initializer but incomplete type",
5974 else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE)
5976 cp_error ("elements of array `%#D' have incomplete type", decl);
5982 && TREE_CODE (decl) != TYPE_DECL
5983 && TREE_CODE (decl) != TEMPLATE_DECL
5984 && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
5986 if (TYPE_SIZE (type) == NULL_TREE)
5988 cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
5990 /* Change the type so that assemble_variable will give
5991 DECL an rtl we can live with: (mem (const_int 0)). */
5992 TREE_TYPE (decl) = error_mark_node;
5993 type = error_mark_node;
5997 /* If any base type in the hierarchy of TYPE needs a constructor,
5998 then we set initialized to 1. This way any nodes which are
5999 created for the purposes of initializing this aggregate
6000 will live as long as it does. This is necessary for global
6001 aggregates which do not have their initializers processed until
6002 the end of the file. */
6003 initialized = TYPE_NEEDS_CONSTRUCTING (type);
6009 if (! toplevel_bindings_p ()
6010 && DECL_EXTERNAL (decl))
6011 cp_warning ("declaration of `%#D' has `extern' and is initialized",
6013 DECL_EXTERNAL (decl) = 0;
6014 if ( toplevel_bindings_p ())
6015 TREE_STATIC (decl) = 1;
6017 /* Tell `pushdecl' this is an initialized decl
6018 even though we don't yet have the initializer expression.
6019 Also tell `cp_finish_decl' it may store the real initializer. */
6020 DECL_INITIAL (decl) = error_mark_node;
6023 if (context && TYPE_SIZE (context) != NULL_TREE)
6025 if (TREE_CODE (decl) == VAR_DECL)
6027 tree field = lookup_field (context, DECL_NAME (decl), 0, 0);
6028 if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
6029 cp_error ("`%#D' is not a static member of `%#T'", decl, context);
6030 else if (duplicate_decls (decl, field))
6035 tree field = check_classfn (context, NULL_TREE, decl);
6036 if (field && duplicate_decls (decl, field))
6040 /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */
6041 if (DECL_LANG_SPECIFIC (decl))
6042 DECL_IN_AGGR_P (decl) = 0;
6043 if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context))
6044 SET_DECL_TEMPLATE_SPECIALIZATION (decl);
6046 /* Stupid stupid stupid stupid (jason 7/21/95) */
6047 if (pedantic && DECL_EXTERNAL (decl)
6048 && ! DECL_TEMPLATE_SPECIALIZATION (decl))
6049 cp_pedwarn ("declaration of `%#D' outside of class is not definition",
6052 pushclass (context, 2);
6055 /* Add this decl to the current binding level, but not if it
6056 comes from another scope, e.g. a static member variable.
6057 TEM may equal DECL or it may be a previous decl of the same name. */
6059 if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
6060 || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
6061 || TREE_CODE (type) == LANG_TYPE)
6064 tem = pushdecl (decl);
6066 /* Tell the back-end to use or not use .common as appropriate. If we say
6067 -fconserve-space, we want this to save space, at the expense of wrong
6068 semantics. If we say -fno-conserve-space, we want this to produce
6069 errors about redefs; to do this we force variables into the data
6070 segment. Common storage is okay for non-public uninitialized data;
6071 the linker can't match it with storage from other files, and we may
6072 save some disk space. */
6073 DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem);
6076 /* We don't do this yet for GNU C++. */
6077 /* For a local variable, define the RTL now. */
6078 if (! toplevel_bindings_p ()
6079 /* But not if this is a duplicate decl
6080 and we preserved the rtl from the previous one
6081 (which may or may not happen). */
6082 && DECL_RTL (tem) == NULL_RTX)
6084 if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
6086 else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
6087 && DECL_INITIAL (tem) != NULL_TREE)
6092 if (TREE_CODE (decl) == TEMPLATE_DECL)
6094 tree result = DECL_TEMPLATE_RESULT (decl);
6095 if (DECL_CONTEXT (result) != NULL_TREE)
6098 type = DECL_CONTEXT (result);
6100 if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE)
6102 cp_error ("declaration of `%D' in non-template type `%T'",
6107 if (TREE_CODE (result) == FUNCTION_DECL)
6109 else if (TREE_CODE (result) == VAR_DECL)
6112 tree tmpl = UPT_TEMPLATE (type);
6114 fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
6115 print_node_brief (stderr, "", DECL_NAME (tem), 0);
6116 fprintf (stderr, " to class %s\n",
6117 IDENTIFIER_POINTER (DECL_NAME (tmpl)));
6118 DECL_TEMPLATE_MEMBERS (tmpl)
6119 = perm_tree_cons (DECL_NAME (tem), tem,
6120 DECL_TEMPLATE_MEMBERS (tmpl));
6123 sorry ("static data member templates");
6128 my_friendly_abort (13);
6130 else if (TREE_CODE (result) == FUNCTION_DECL)
6131 /*tem = push_overloaded_decl (tem, 0)*/;
6132 else if (TREE_CODE (result) == VAR_DECL)
6134 cp_error ("data template `%#D' must be member of a class template",
6138 else if (TREE_CODE (result) == TYPE_DECL)
6140 cp_error ("invalid template `%#D'", result);
6144 my_friendly_abort (14);
6148 && ! (TREE_CODE (tem) == PARM_DECL
6149 || (TREE_READONLY (tem)
6150 && (TREE_CODE (tem) == VAR_DECL
6151 || TREE_CODE (tem) == FIELD_DECL))))
6153 /* When parsing and digesting the initializer,
6154 use temporary storage. Do this even if we will ignore the value. */
6155 if (toplevel_bindings_p () && debug_temp_inits)
6157 if (TYPE_NEEDS_CONSTRUCTING (type)
6158 || TREE_CODE (type) == REFERENCE_TYPE)
6159 /* In this case, the initializer must lay down in permanent
6160 storage, since it will be saved until `finish_file' is run. */
6163 temporary_allocation ();
6168 cadillac_start_decl (tem);
6175 make_temporary_for_reference (decl, ctor_call, init, cleanupp)
6176 tree decl, ctor_call, init;
6179 tree type = TREE_TYPE (decl);
6180 tree target_type = TREE_TYPE (type);
6185 tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
6186 if (TREE_CODE (tmp_addr) == NOP_EXPR)
6187 tmp_addr = TREE_OPERAND (tmp_addr, 0);
6188 my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146);
6189 tmp = TREE_OPERAND (tmp_addr, 0);
6193 tmp = get_temp_name (target_type, toplevel_bindings_p ());
6194 tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
6197 TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
6198 DECL_INITIAL (decl) = convert (build_pointer_type (target_type), tmp_addr);
6199 TREE_TYPE (DECL_INITIAL (decl)) = type;
6200 if (TYPE_NEEDS_CONSTRUCTING (target_type))
6202 if (toplevel_bindings_p ())
6204 /* lay this variable out now. Otherwise `output_addressed_constants'
6205 gets confused by its initializer. */
6206 make_decl_rtl (tmp, NULL_PTR, 1);
6207 static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
6211 if (ctor_call != NULL_TREE)
6214 init = build_method_call (tmp, constructor_name_full (target_type),
6215 build_tree_list (NULL_TREE, init),
6216 NULL_TREE, LOOKUP_NORMAL);
6217 DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
6218 DECL_INITIAL (decl));
6219 *cleanupp = maybe_build_cleanup (tmp);
6224 DECL_INITIAL (tmp) = init;
6225 TREE_STATIC (tmp) = toplevel_bindings_p ();
6226 cp_finish_decl (tmp, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
6228 if (TREE_STATIC (tmp))
6229 preserve_initializer ();
6233 /* Handle initialization of references.
6234 These three arguments from from `cp_finish_decl', and have the
6235 same meaning here that they do there. */
6236 /* quotes on semantics can be found in ARM 8.4.3. */
6238 grok_reference_init (decl, type, init, cleanupp)
6239 tree decl, type, init;
6244 if (init == NULL_TREE)
6246 if ((DECL_LANG_SPECIFIC (decl) == 0
6247 || DECL_IN_AGGR_P (decl) == 0)
6248 && ! DECL_THIS_EXTERN (decl))
6250 cp_error ("`%D' declared as reference but not initialized", decl);
6251 if (TREE_CODE (decl) == VAR_DECL)
6252 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
6257 if (init == error_mark_node)
6260 if (TREE_CODE (type) == REFERENCE_TYPE
6261 && TREE_CODE (init) == CONSTRUCTOR)
6263 cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
6267 if (TREE_CODE (init) == TREE_LIST)
6268 init = build_compound_expr (init);
6270 if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE)
6271 init = convert_from_reference (init);
6273 if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
6274 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
6276 /* Note: default conversion is only called in very special cases. */
6277 init = default_conversion (init);
6280 tmp = convert_to_reference
6281 (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL, decl);
6283 if (tmp == error_mark_node)
6285 else if (tmp != NULL_TREE)
6287 tree subtype = TREE_TYPE (type);
6290 /* Associate the cleanup with the reference so that we
6291 don't get burned by "aggressive" cleanup policy. */
6292 if (TYPE_NEEDS_DESTRUCTOR (subtype))
6294 if (TREE_CODE (init) == WITH_CLEANUP_EXPR)
6296 *cleanupp = TREE_OPERAND (init, 2);
6297 TREE_OPERAND (init, 2) = error_mark_node;
6301 if (TREE_CODE (tmp) == ADDR_EXPR)
6302 tmp = TREE_OPERAND (tmp, 0);
6303 if (TREE_CODE (tmp) == TARGET_EXPR)
6305 *cleanupp = build_delete
6306 (build_pointer_type (subtype),
6307 build_unary_op (ADDR_EXPR, TREE_OPERAND (tmp, 0), 0),
6308 integer_two_node, LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0);
6309 TREE_OPERAND (tmp, 2) = error_mark_node;
6314 DECL_INITIAL (decl) = save_expr (init);
6318 cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
6322 /* ?? Can this be optimized in some cases to
6323 hand back the DECL_INITIAL slot?? */
6324 if (TYPE_SIZE (TREE_TYPE (type)))
6326 init = convert_from_reference (decl);
6327 if (TREE_PERMANENT (decl))
6328 init = copy_to_permanent (init);
6329 SET_DECL_REFERENCE_SLOT (decl, init);
6332 if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
6334 expand_static_init (decl, DECL_INITIAL (decl));
6335 DECL_INITIAL (decl) = NULL_TREE;
6340 if (TREE_CODE (decl) == VAR_DECL)
6341 SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
6345 /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from
6346 mucking with forces it does not comprehend (i.e. initialization with a
6347 constructor). If we are at global scope and won't go into COMMON, fill
6348 it in with a dummy CONSTRUCTOR to force the variable into .data;
6349 otherwise we can use error_mark_node. */
6352 obscure_complex_init (decl, init)
6355 if (! flag_no_inline && TREE_STATIC (decl))
6357 if (extract_init (decl, init))
6361 if (toplevel_bindings_p () && ! DECL_COMMON (decl))
6362 DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE,
6365 DECL_INITIAL (decl) = error_mark_node;
6370 /* Finish processing of a declaration;
6371 install its line number and initial value.
6372 If the length of an array type is not known before,
6373 it must be determined now, from the initial value, or it is an error.
6375 Call `pop_obstacks' iff NEED_POP is nonzero.
6377 For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers
6378 for aggregates that have constructors alive on the permanent obstack,
6379 so that the global initializing functions can be written at the end.
6381 INIT0 holds the value of an initializer that should be allowed to escape
6384 FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0
6385 if the (init) syntax was used.
6387 For functions that take default parameters, DECL points to its
6388 "maximal" instantiation. `cp_finish_decl' must then also declared its
6389 subsequently lower and lower forms of instantiation, checking for
6390 ambiguity as it goes. This can be sped up later. */
6393 cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
6400 tree cleanup = NULL_TREE, ttype;
6402 int temporary = allocation_temporary_p ();
6403 char *asmspec = NULL;
6404 int was_readonly = 0;
6406 /* If this is 0, then we did not change obstacks. */
6410 error ("assignment (not initialization) in declaration");
6414 /* If a name was specified, get the string. */
6416 asmspec = TREE_STRING_POINTER (asmspec_tree);
6418 /* If the type of the thing we are declaring either has
6419 a constructor, or has a virtual function table pointer,
6420 AND its initialization was accepted by `start_decl',
6421 then we stayed on the permanent obstack through the
6422 declaration, otherwise, changed obstacks as GCC would. */
6424 type = TREE_TYPE (decl);
6426 if (type == error_mark_node)
6428 if (toplevel_bindings_p () && temporary)
6429 end_temporary_allocation ();
6434 was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
6436 /* Take care of TYPE_DECLs up front. */
6437 if (TREE_CODE (decl) == TYPE_DECL)
6439 if (init && DECL_INITIAL (decl))
6441 /* typedef foo = bar; store the type of bar as the type of foo. */
6442 TREE_TYPE (decl) = type = TREE_TYPE (init);
6443 DECL_INITIAL (decl) = init = NULL_TREE;
6445 if (type != error_mark_node
6446 && IS_AGGR_TYPE (type) && DECL_NAME (decl))
6448 if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
6449 cp_warning ("shadowing previous type declaration of `%#D'", decl);
6450 set_identifier_type_value (DECL_NAME (decl), type);
6451 CLASSTYPE_GOT_SEMICOLON (type) = 1;
6453 GNU_xref_decl (current_function_decl, decl);
6454 rest_of_decl_compilation (decl, NULL_PTR,
6455 DECL_CONTEXT (decl) == NULL_TREE, 0);
6458 if (TREE_CODE (decl) != FUNCTION_DECL)
6460 ttype = target_type (type);
6462 Leave this out until we can figure out why it was
6463 needed/desirable in the first place. Then put a comment
6464 here explaining why. Or just delete the code if no ill
6466 if (TYPE_NAME (ttype)
6467 && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
6468 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
6470 tree old_id = TYPE_IDENTIFIER (ttype);
6471 char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
6472 /* Need to preserve template data for UPT nodes. */
6473 tree old_template = IDENTIFIER_TEMPLATE (old_id);
6475 bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
6476 IDENTIFIER_LENGTH (old_id) + 1);
6477 old_id = get_identifier (newname);
6478 lookup_tag_reverse (ttype, old_id);
6479 TYPE_IDENTIFIER (ttype) = old_id;
6480 IDENTIFIER_TEMPLATE (old_id) = old_template;
6485 if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
6486 && TYPE_NEEDS_CONSTRUCTING (type))
6489 /* Currently, GNU C++ puts constants in text space, making them
6490 impossible to initialize. In the future, one would hope for
6491 an operating system which understood the difference between
6492 initialization and the running of a program. */
6494 TREE_READONLY (decl) = 0;
6497 if (TREE_CODE (decl) == FIELD_DECL)
6499 if (init && init != error_mark_node)
6500 my_friendly_assert (TREE_PERMANENT (init), 147);
6504 /* This must override the asm specifier which was placed
6505 by grokclassfn. Lay this out fresh. */
6506 DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
6507 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
6508 make_decl_rtl (decl, asmspec, 0);
6511 /* If `start_decl' didn't like having an initialization, ignore it now. */
6512 else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
6514 else if (DECL_EXTERNAL (decl))
6516 else if (TREE_CODE (type) == REFERENCE_TYPE
6517 || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
6519 if (TREE_STATIC (decl))
6520 make_decl_rtl (decl, NULL_PTR,
6521 toplevel_bindings_p ()
6522 || pseudo_global_level_p ());
6523 grok_reference_init (decl, type, init, &cleanup);
6527 GNU_xref_decl (current_function_decl, decl);
6529 if (TREE_CODE (decl) == FIELD_DECL)
6531 else if (TREE_CODE (decl) == CONST_DECL)
6533 my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
6535 DECL_INITIAL (decl) = init;
6537 /* This will keep us from needing to worry about our obstacks. */
6538 my_friendly_assert (init != NULL_TREE, 149);
6543 if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
6545 if (TREE_CODE (type) == ARRAY_TYPE)
6546 init = digest_init (type, init, (tree *) 0);
6547 else if (TREE_CODE (init) == CONSTRUCTOR)
6549 if (TYPE_NON_AGGREGATE_CLASS (type))
6551 cp_error ("`%D' must be initialized by constructor, not by `{...}'",
6553 init = error_mark_node;
6556 goto dont_use_constructor;
6561 dont_use_constructor:
6562 if (TREE_CODE (init) != TREE_VEC)
6563 init = store_init_value (decl, init);
6567 /* We must hide the initializer so that expand_decl
6568 won't try to do something it does not understand. */
6569 init = obscure_complex_init (decl, init);
6571 else if (DECL_EXTERNAL (decl))
6573 else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
6574 && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
6577 while (TREE_CODE (ctype) == ARRAY_TYPE)
6578 ctype = TREE_TYPE (ctype);
6579 if (! TYPE_NEEDS_CONSTRUCTING (ctype))
6581 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
6582 cp_error ("structure `%D' with uninitialized const members", decl);
6583 if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
6584 cp_error ("structure `%D' with uninitialized reference members",
6588 if (TREE_CODE (decl) == VAR_DECL
6589 && !DECL_INITIAL (decl)
6590 && !TYPE_NEEDS_CONSTRUCTING (type)
6591 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
6592 cp_error ("uninitialized const `%D'", decl);
6594 if (TYPE_SIZE (type) != NULL_TREE
6595 && TYPE_NEEDS_CONSTRUCTING (type))
6596 init = obscure_complex_init (decl, NULL_TREE);
6598 else if (TREE_CODE (decl) == VAR_DECL
6599 && TREE_CODE (type) != REFERENCE_TYPE
6600 && (TYPE_READONLY (type) || TREE_READONLY (decl)))
6602 /* ``Unless explicitly declared extern, a const object does not have
6603 external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
6604 However, if it's `const int foo = 1; const int foo;', don't complain
6605 about the second decl, since it does have an initializer before.
6606 We deliberately don't complain about arrays, because they're
6607 supposed to be initialized by a constructor. */
6608 if (! DECL_INITIAL (decl)
6609 && TREE_CODE (type) != ARRAY_TYPE
6610 && (!pedantic || !current_class_type))
6611 cp_error ("uninitialized const `%#D'", decl);
6614 /* For top-level declaration, the initial value was read in
6615 the temporary obstack. MAXINDEX, rtl, etc. to be made below
6616 must go in the permanent obstack; but don't discard the
6617 temporary data yet. */
6619 if (toplevel_bindings_p () && temporary)
6620 end_temporary_allocation ();
6622 /* Deduce size of array from initialization, if not already known. */
6624 if (TREE_CODE (type) == ARRAY_TYPE
6625 && TYPE_DOMAIN (type) == NULL_TREE
6626 && TREE_CODE (decl) != TYPE_DECL)
6629 = (TREE_STATIC (decl)
6630 /* Even if pedantic, an external linkage array
6631 may have incomplete type at first. */
6632 ? pedantic && ! DECL_EXTERNAL (decl)
6633 : !DECL_EXTERNAL (decl));
6634 tree initializer = init ? init : DECL_INITIAL (decl);
6635 int failure = complete_array_type (type, initializer, do_default);
6638 cp_error ("initializer fails to determine size of `%D'", decl);
6643 cp_error ("array size missing in `%D'", decl);
6644 /* If a `static' var's size isn't known, make it extern as
6645 well as static, so it does not get allocated. If it's not
6646 `static', then don't mark it extern; finish_incomplete_decl
6647 will give it a default size and it will get allocated. */
6648 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
6649 DECL_EXTERNAL (decl) = 1;
6652 if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
6653 && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
6655 cp_error ("zero-size array `%D'", decl);
6657 layout_decl (decl, 0);
6660 if (TREE_CODE (decl) == VAR_DECL)
6662 if (DECL_SIZE (decl) == NULL_TREE
6663 && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
6664 layout_decl (decl, 0);
6666 if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
6668 /* A static variable with an incomplete type:
6669 that is an error if it is initialized.
6670 Otherwise, let it through, but if it is not `extern'
6671 then it may cause an error message later. */
6672 if (DECL_INITIAL (decl) != NULL_TREE)
6673 cp_error ("storage size of `%D' isn't known", decl);
6676 else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
6678 /* An automatic variable with an incomplete type: that is an error.
6679 Don't talk about array types here, since we took care of that
6680 message in grokdeclarator. */
6681 cp_error ("storage size of `%D' isn't known", decl);
6682 TREE_TYPE (decl) = error_mark_node;
6684 else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
6685 /* Let debugger know it should output info for this type. */
6686 note_debug_info_needed (ttype);
6688 if (TREE_STATIC (decl) && DECL_CONTEXT (decl)
6689 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't')
6690 note_debug_info_needed (DECL_CONTEXT (decl));
6692 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
6693 && DECL_SIZE (decl) != NULL_TREE
6694 && ! TREE_CONSTANT (DECL_SIZE (decl)))
6696 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
6697 constant_expression_warning (DECL_SIZE (decl));
6699 cp_error ("storage size of `%D' isn't constant", decl);
6702 if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
6704 int yes = suspend_momentary ();
6706 /* If INIT comes from a functional cast, use the cleanup
6707 we built for that. Otherwise, make our own cleanup. */
6708 if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
6709 && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
6711 cleanup = TREE_OPERAND (init, 2);
6712 init = TREE_OPERAND (init, 0);
6713 current_binding_level->have_cleanups = 1;
6716 cleanup = maybe_build_cleanup (decl);
6717 resume_momentary (yes);
6720 /* PARM_DECLs get cleanups, too. */
6721 else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
6724 end_temporary_allocation ();
6725 cleanup = maybe_build_cleanup (decl);
6727 resume_temporary_allocation ();
6730 /* Output the assembler code and/or RTL code for variables and functions,
6731 unless the type is an undefined structure or union.
6732 If not, it will get done when the type is completed. */
6734 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
6735 || TREE_CODE (decl) == RESULT_DECL)
6737 /* ??? FIXME: What about nested classes? */
6738 int toplev = toplevel_bindings_p () || pseudo_global_level_p ();
6740 = ((flag_traditional
6741 || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
6742 && allocation_temporary_p ());
6745 end_temporary_allocation ();
6747 if (TREE_CODE (decl) == VAR_DECL
6748 && ! toplevel_bindings_p ()
6749 && ! TREE_STATIC (decl)
6750 && type_needs_gc_entry (type))
6751 DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
6753 if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
6754 make_decl_rtl (decl, NULL_PTR, toplev);
6755 else if (TREE_CODE (decl) == VAR_DECL
6756 && TREE_READONLY (decl)
6757 && DECL_INITIAL (decl) != NULL_TREE
6758 && DECL_INITIAL (decl) != error_mark_node
6759 && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
6761 DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
6764 DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
6767 && TREE_STATIC (decl)
6768 && ! TREE_SIDE_EFFECTS (decl)
6769 && ! TREE_PUBLIC (decl)
6770 && ! DECL_EXTERNAL (decl)
6771 && ! TYPE_NEEDS_DESTRUCTOR (type)
6772 && DECL_MODE (decl) != BLKmode)
6774 /* If this variable is really a constant, then fill its DECL_RTL
6775 slot with something which won't take up storage.
6776 If something later should take its address, we can always give
6777 it legitimate RTL at that time. */
6778 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
6779 store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
6780 TREE_ASM_WRITTEN (decl) = 1;
6782 else if (toplev && ! TREE_PUBLIC (decl))
6784 /* If this is a static const, change its apparent linkage
6785 if it belongs to a #pragma interface. */
6786 if (!interface_unknown)
6788 TREE_PUBLIC (decl) = 1;
6789 DECL_EXTERNAL (decl) = interface_only;
6791 make_decl_rtl (decl, asmspec, toplev);
6794 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6796 else if (TREE_CODE (decl) == VAR_DECL
6797 && DECL_LANG_SPECIFIC (decl)
6798 && DECL_IN_AGGR_P (decl))
6800 if (TREE_STATIC (decl))
6802 if (init == NULL_TREE
6803 #ifdef DEFAULT_STATIC_DEFS
6804 /* If this code is dead, then users must
6805 explicitly declare static member variables
6806 outside the class def'n as well. */
6807 && TYPE_NEEDS_CONSTRUCTING (type)
6811 DECL_EXTERNAL (decl) = 1;
6812 make_decl_rtl (decl, asmspec, 1);
6815 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6818 /* Just a constant field. Should not need any rtl. */
6822 rest_of_decl_compilation (decl, asmspec, toplev, 0);
6825 resume_temporary_allocation ();
6827 if (type != error_mark_node
6828 && TYPE_LANG_SPECIFIC (type)
6829 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
6830 abstract_virtuals_error (decl, type);
6831 else if ((TREE_CODE (type) == FUNCTION_TYPE
6832 || TREE_CODE (type) == METHOD_TYPE)
6833 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6834 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
6835 abstract_virtuals_error (decl, TREE_TYPE (type));
6837 if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
6838 signature_error (decl, type);
6839 else if ((TREE_CODE (type) == FUNCTION_TYPE
6840 || TREE_CODE (type) == METHOD_TYPE)
6841 && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
6842 && IS_SIGNATURE (TREE_TYPE (type)))
6843 signature_error (decl, TREE_TYPE (type));
6845 if (TREE_CODE (decl) == FUNCTION_DECL)
6847 else if (DECL_EXTERNAL (decl))
6849 else if (TREE_STATIC (decl) && type != error_mark_node)
6851 /* Cleanups for static variables are handled by `finish_file'. */
6852 if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE
6853 || TYPE_NEEDS_DESTRUCTOR (type))
6854 expand_static_init (decl, init);
6856 /* Make entry in appropriate vector. */
6857 if (flag_gc && type_needs_gc_entry (type))
6858 build_static_gc_entry (decl, type);
6862 extern int temp_slot_level;
6863 extern int target_temp_slot_level;
6864 tree old_cleanups = cleanups_this_call;
6865 int old_temp_level = target_temp_slot_level;
6867 /* This is a declared decl which must live until the
6868 end of the binding contour. It may need a cleanup. */
6870 /* Recompute the RTL of a local array now
6871 if it used to be an incomplete type. */
6872 if (was_incomplete && ! TREE_STATIC (decl))
6874 /* If we used it already as memory, it must stay in memory. */
6875 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
6876 /* If it's still incomplete now, no init will save it. */
6877 if (DECL_SIZE (decl) == NULL_TREE)
6878 DECL_INITIAL (decl) = NULL_TREE;
6881 else if (! TREE_ASM_WRITTEN (decl)
6882 && (TYPE_SIZE (type) != NULL_TREE
6883 || TREE_CODE (type) == ARRAY_TYPE))
6885 /* Do this here, because we did not expand this decl's
6886 rtl in start_decl. */
6887 if (DECL_RTL (decl) == NULL_RTX)
6891 /* XXX: Why don't we use decl here? */
6892 /* Ans: Because it was already expanded? */
6893 if (! cp_expand_decl_cleanup (NULL_TREE, cleanup))
6894 cp_error ("parser lost in parsing declaration of `%D'",
6896 /* Cleanup used up here. */
6897 cleanup = NULL_TREE;
6903 target_temp_slot_level = temp_slot_level;
6905 if (DECL_SIZE (decl) && type != error_mark_node)
6907 /* Compute and store the initial value. */
6908 expand_decl_init (decl);
6910 if (init || TYPE_NEEDS_CONSTRUCTING (type))
6912 emit_line_note (DECL_SOURCE_FILE (decl),
6913 DECL_SOURCE_LINE (decl));
6914 expand_aggr_init (decl, init, 0, flags);
6917 /* Set this to 0 so we can tell whether an aggregate which
6918 was initialized was ever used. Don't do this if it has a
6919 destructor, so we don't complain about the 'resource
6920 allocation is initialization' idiom. */
6921 if (TYPE_NEEDS_CONSTRUCTING (type)
6922 && cleanup == NULL_TREE
6923 && DECL_NAME (decl))
6924 TREE_USED (decl) = 0;
6926 /* Store the cleanup, if there was one. */
6929 if (! cp_expand_decl_cleanup (decl, cleanup))
6930 cp_error ("parser lost in parsing declaration of `%D'",
6934 /* Cleanup any temporaries needed for the initial value. */
6935 expand_cleanups_to (old_cleanups);
6938 target_temp_slot_level = old_temp_level;
6942 /* Undo call to `pushclass' that was done in `start_decl'
6943 due to initialization of qualified member variable.
6944 I.e., Foo::x = 10; */
6946 tree context = DECL_REAL_CONTEXT (decl);
6948 && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
6949 && (TREE_CODE (decl) == VAR_DECL
6950 /* We also have a pushclass done that we need to undo here
6951 if we're at top level and declare a method. */
6952 || (TREE_CODE (decl) == FUNCTION_DECL
6953 /* If size hasn't been set, we're still defining it,
6954 and therefore inside the class body; don't pop
6955 the binding level.. */
6956 && TYPE_SIZE (context) != NULL_TREE
6957 /* The binding level gets popped elsewhere for a
6958 friend declaration inside another class. */
6960 && TYPE_IDENTIFIER (context) == current_class_name
6962 && context == current_class_type
6970 /* If requested, warn about definitions of large data objects. */
6972 if (warn_larger_than
6973 && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
6974 && !DECL_EXTERNAL (decl))
6976 register tree decl_size = DECL_SIZE (decl);
6978 if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
6980 unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT;
6982 if (units > larger_than_size)
6983 warning_with_decl (decl, "size of `%s' is %u bytes", units);
6989 /* Resume permanent allocation, if not within a function. */
6990 /* The corresponding push_obstacks_nochange is in start_decl,
6991 start_method, groktypename, and in grokfield. */
6996 TREE_READONLY (decl) = 1;
6999 cadillac_finish_decl (decl);
7002 /* This is here for a midend callback from c-common.c */
7004 finish_decl (decl, init, asmspec_tree)
7008 cp_finish_decl (decl, init, asmspec_tree, 1, 0);
7012 expand_static_init (decl, init)
7016 tree oldstatic = value_member (decl, static_aggregates);
7020 if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
7021 cp_error ("multiple initializations given for `%D'", decl);
7023 else if (! toplevel_bindings_p () && ! pseudo_global_level_p ())
7025 /* Emit code to perform this initialization but once. */
7028 extern int temp_slot_level;
7029 extern int target_temp_slot_level;
7033 /* Remember this information until end of file. */
7034 push_obstacks (&permanent_obstack, &permanent_obstack);
7036 /* Emit code to perform this initialization but once. */
7037 temp = get_temp_name (integer_type_node, 1);
7038 rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
7039 expand_start_cond (build_binary_op (EQ_EXPR, temp,
7040 integer_zero_node, 1), 0);
7041 old_cleanups = cleanups_this_call;
7042 old_temp_level = target_temp_slot_level;
7045 target_temp_slot_level = temp_slot_level;
7047 expand_assignment (temp, integer_one_node, 0, 0);
7048 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))
7049 || (init && TREE_CODE (init) == TREE_LIST))
7051 expand_aggr_init (decl, init, 0, 0);
7052 do_pending_stack_adjust ();
7055 expand_assignment (decl, init, 0, 0);
7057 /* Cleanup any temporaries needed for the initial value. */
7058 expand_cleanups_to (old_cleanups);
7061 target_temp_slot_level = old_temp_level;
7063 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
7065 tree cleanup, fcall;
7066 static tree Atexit = 0;
7069 tree atexit_fndecl, PFV, pfvlist;
7070 /* Remember this information until end of file. */
7071 push_obstacks (&permanent_obstack, &permanent_obstack);
7072 PFV = build_pointer_type (build_function_type
7073 (void_type_node, void_list_node));
7075 pfvlist = tree_cons (NULL_TREE, PFV, void_list_node);
7077 push_lang_context (lang_name_c);
7079 builtin_function ("atexit",
7080 build_function_type (void_type_node,
7082 NOT_BUILT_IN, NULL_PTR);
7083 assemble_external (atexit_fndecl);
7084 Atexit = default_conversion (atexit_fndecl);
7085 pop_lang_context ();
7089 cleanup = start_anon_func ();
7090 expand_expr_stmt (build_cleanup (decl));
7092 mark_addressable (cleanup);
7093 cleanup = build_unary_op (ADDR_EXPR, cleanup, 0);
7094 fcall = build_function_call (Atexit, tree_cons (NULL_TREE, cleanup, NULL_TREE));
7095 expand_expr_stmt (fcall);
7099 if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
7101 static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
7102 TREE_STATIC (static_aggregates) = 1;
7105 /* Resume old (possibly temporary) allocation. */
7110 /* This code takes into account memory allocation
7111 policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING
7112 does not hold for this object, then we must make permanent
7113 the storage currently in the temporary obstack. */
7114 if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
7115 preserve_initializer ();
7116 static_aggregates = perm_tree_cons (init, decl, static_aggregates);
7120 /* Make TYPE a complete type based on INITIAL_VALUE.
7121 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
7122 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
7125 complete_array_type (type, initial_value, do_default)
7126 tree type, initial_value;
7129 register tree maxindex = NULL_TREE;
7134 /* Note MAXINDEX is really the maximum index,
7135 one less than the size. */
7136 if (TREE_CODE (initial_value) == STRING_CST)
7139 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
7140 maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
7143 else if (TREE_CODE (initial_value) == CONSTRUCTOR)
7145 tree elts = CONSTRUCTOR_ELTS (initial_value);
7146 maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node);
7147 for (; elts; elts = TREE_CHAIN (elts))
7149 if (TREE_PURPOSE (elts))
7150 maxindex = TREE_PURPOSE (elts);
7152 maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node);
7154 maxindex = copy_node (maxindex);
7158 /* Make an error message unless that happened already. */
7159 if (initial_value != error_mark_node)
7162 /* Prevent further error messages. */
7163 maxindex = build_int_2 (0, 0);
7170 maxindex = build_int_2 (0, 0);
7178 TYPE_DOMAIN (type) = build_index_type (maxindex);
7179 if (! TREE_TYPE (maxindex))
7180 TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
7182 itype = TREE_TYPE (initial_value);
7185 if (itype && !TYPE_DOMAIN (itype))
7186 TYPE_DOMAIN (itype) = TYPE_DOMAIN (type);
7187 /* The type of the main variant should never be used for arrays
7188 of different sizes. It should only ever be completed with the
7189 size of the array. */
7190 if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)))
7191 TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = TYPE_DOMAIN (type);
7194 /* Lay out the type now that we can get the real answer. */
7201 /* Return zero if something is declared to be a member of type
7202 CTYPE when in the context of CUR_TYPE. STRING is the error
7203 message to print in that case. Otherwise, quietly return 1. */
7205 member_function_or_else (ctype, cur_type, string)
7206 tree ctype, cur_type;
7209 if (ctype && ctype != cur_type)
7211 error (string, TYPE_NAME_STRING (ctype));
7217 /* Subroutine of `grokdeclarator'. */
7219 /* Generate errors possibly applicable for a given set of specifiers.
7220 This is for ARM $7.1.2. */
7222 bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
7225 int virtualp, quals, friendp, raises, inlinep;
7228 cp_error ("`%D' declared as a `virtual' %s", object, type);
7230 cp_error ("`%D' declared as an `inline' %s", object, type);
7232 cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
7235 cp_error_at ("invalid friend declaration", object);
7237 cp_error_at ("invalid exception specifications", object);
7240 /* CTYPE is class type, or null if non-class.
7241 TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
7243 DECLARATOR is the function's name.
7244 VIRTUALP is truthvalue of whether the function is virtual or not.
7245 FLAGS are to be passed through to `grokclassfn'.
7246 QUALS are qualifiers indicating whether the function is `const'
7248 RAISES is a list of exceptions that this function can raise.
7249 CHECK is 1 if we must find this method in CTYPE, 0 if we should
7250 not look, and -1 if we should not call `grokclassfn' at all. */
7252 grokfndecl (ctype, type, declarator, virtualp, flags, quals,
7253 raises, attrlist, check, publicp, inlinep)
7257 enum overload_flags flags;
7258 tree quals, raises, attrlist;
7259 int check, publicp, inlinep;
7262 int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
7265 cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
7266 ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
7272 type = build_exception_variant (type, raises);
7273 raises = TYPE_RAISES_EXCEPTIONS (type);
7275 decl = build_lang_decl (FUNCTION_DECL, declarator, type);
7276 /* propagate volatile out from type to decl */
7277 if (TYPE_VOLATILE (type))
7278 TREE_THIS_VOLATILE (decl) = 1;
7280 /* Should probably propagate const out from type to decl I bet (mrs). */
7283 DECL_STATIC_FUNCTION_P (decl) = 1;
7284 DECL_CONTEXT (decl) = ctype;
7285 DECL_CLASS_CONTEXT (decl) = ctype;
7288 /* All function decls start out public; we'll fix their linkage later (at
7289 definition or EOF) if appropriate. */
7290 TREE_PUBLIC (decl) = 1;
7292 if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main"))
7295 error ("cannot declare `main' to be inline");
7297 error ("cannot declare `main' to be static");
7303 DECL_C_STATIC (decl) = 1;
7306 DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1;
7308 DECL_EXTERNAL (decl) = 1;
7309 if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
7311 cp_error ("%smember function `%D' cannot have `%T' method qualifier",
7312 (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
7316 if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
7317 grok_op_properties (decl, virtualp, check < 0);
7319 /* Caller will do the rest of this. */
7323 if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
7326 /* Just handle constructors here. We could do this
7327 inside the following if stmt, but I think
7328 that the code is more legible by breaking this
7329 case out. See comments below for what each of
7330 the following calls is supposed to do. */
7331 DECL_CONSTRUCTOR_P (decl) = 1;
7333 grokclassfn (ctype, declarator, decl, flags, quals);
7335 check_classfn (ctype, declarator, decl);
7336 if (! grok_ctor_properties (ctype, decl))
7339 if (check == 0 && ! current_function_decl)
7341 /* FIXME: this should only need to look at
7342 IDENTIFIER_GLOBAL_VALUE. */
7343 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
7344 if (tmp == NULL_TREE)
7345 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
7346 else if (TREE_CODE (tmp) != TREE_CODE (decl))
7347 cp_error ("inconsistent declarations for `%D'", decl);
7350 duplicate_decls (decl, tmp);
7352 /* avoid creating circularities. */
7353 DECL_CHAIN (decl) = NULL_TREE;
7355 make_decl_rtl (decl, NULL_PTR, 1);
7362 /* Function gets the ugly name, field gets the nice one.
7363 This call may change the type of the function (because
7364 of default parameters)! */
7365 if (ctype != NULL_TREE)
7366 grokclassfn (ctype, cname, decl, flags, quals);
7368 if (ctype != NULL_TREE && check)
7369 check_classfn (ctype, cname, decl);
7371 if (ctype == NULL_TREE || check)
7374 /* Now install the declaration of this function so that others may
7375 find it (esp. its DECL_FRIENDLIST). Don't do this for local class
7377 if (! current_function_decl)
7379 /* FIXME: this should only need to look at
7380 IDENTIFIER_GLOBAL_VALUE. */
7381 tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
7382 if (tmp == NULL_TREE)
7383 IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
7384 else if (TREE_CODE (tmp) != TREE_CODE (decl))
7385 cp_error ("inconsistent declarations for `%D'", decl);
7388 duplicate_decls (decl, tmp);
7390 /* avoid creating circularities. */
7391 DECL_CHAIN (decl) = NULL_TREE;
7395 cplus_decl_attributes (decl, TREE_PURPOSE (attrlist),
7396 TREE_VALUE (attrlist));
7397 make_decl_rtl (decl, NULL_PTR, 1);
7400 /* If this declaration supersedes the declaration of
7401 a method declared virtual in the base class, then
7402 mark this field as being virtual as well. */
7404 tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
7405 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
7407 for (i = 0; i < n_baselinks; i++)
7409 tree base_binfo = TREE_VEC_ELT (binfos, i);
7410 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo))
7411 || flag_all_virtual == 1)
7413 tmp = get_matching_virtual (base_binfo, decl,
7414 flags == DTOR_FLAG);
7417 /* If this function overrides some virtual in some base
7418 class, then the function itself is also necessarily
7419 virtual, even if the user didn't explicitly say so. */
7420 DECL_VIRTUAL_P (decl) = 1;
7422 /* The TMP we really want is the one from the deepest
7423 baseclass on this path, taking care not to
7424 duplicate if we have already found it (via another
7425 path to its virtual baseclass. */
7428 cp_error ("method `%D' may not be declared static",
7430 cp_error_at ("(since `%D' declared virtual in base class.)",
7437 /* The argument types may have changed... */
7438 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
7439 tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
7441 argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
7442 TREE_CHAIN (argtypes));
7443 /* But the return type has not. */
7444 type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
7447 type = build_exception_variant (type, raises);
7448 raises = TYPE_RAISES_EXCEPTIONS (type);
7450 TREE_TYPE (decl) = type;
7452 = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
7461 if (DECL_VINDEX (decl) == NULL_TREE)
7462 DECL_VINDEX (decl) = error_mark_node;
7463 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
7464 if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
7465 /* If this function is derived from a template, don't
7466 make it public. This shouldn't be here, but there's
7467 no good way to override the interface pragmas for one
7468 function or class only. Bletch. */
7469 && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE
7470 && (write_virtuals == 2
7471 || (write_virtuals == 3
7472 && CLASSTYPE_INTERFACE_KNOWN (ctype))))
7473 TREE_PUBLIC (decl) = 1;
7480 grokvardecl (type, declarator, specbits, initialized, constp)
7483 RID_BIT_TYPE specbits;
7489 if (TREE_CODE (type) == OFFSET_TYPE)
7491 /* If you declare a static member so that it
7492 can be initialized, the code will reach here. */
7493 tree basetype = TYPE_OFFSET_BASETYPE (type);
7494 type = TREE_TYPE (type);
7495 decl = build_lang_field_decl (VAR_DECL, declarator, type);
7496 DECL_CONTEXT (decl) = basetype;
7497 DECL_CLASS_CONTEXT (decl) = basetype;
7498 DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator);
7501 decl = build_decl (VAR_DECL, declarator, type);
7503 DECL_ASSEMBLER_NAME (decl) = current_namespace_id (DECL_ASSEMBLER_NAME (decl));
7505 if (RIDBIT_SETP (RID_EXTERN, specbits))
7507 DECL_THIS_EXTERN (decl) = 1;
7508 DECL_EXTERNAL (decl) = !initialized;
7511 /* In class context, static means one per class,
7512 public access, and static storage. */
7513 if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
7514 && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
7516 TREE_PUBLIC (decl) = 1;
7517 TREE_STATIC (decl) = 1;
7518 DECL_EXTERNAL (decl) = 0;
7520 /* At top level, either `static' or no s.c. makes a definition
7521 (perhaps tentative), and absence of `static' makes it public. */
7522 else if (toplevel_bindings_p ())
7524 TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits)
7525 && (DECL_THIS_EXTERN (decl) || ! constp));
7526 TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
7528 /* Not at top level, only `static' makes a static definition. */
7531 TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
7532 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
7537 /* Create a canonical pointer to member function type. */
7540 build_ptrmemfunc_type (type)
7547 /* If a canonical type already exists for this type, use it. We use
7548 this method instead of type_hash_canon, because it only does a
7549 simple equality check on the list of field members. */
7551 if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
7554 push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
7556 u = make_lang_type (UNION_TYPE);
7557 IS_AGGR_TYPE (u) = 0;
7558 fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
7559 fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier,
7561 finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
7562 TYPE_NAME (u) = NULL_TREE;
7564 t = make_lang_type (RECORD_TYPE);
7566 /* Let the front-end know this is a pointer to member function. */
7567 TYPE_PTRMEMFUNC_FLAG (t) = 1;
7568 /* and not really an aggregate. */
7569 IS_AGGR_TYPE (t) = 0;
7571 fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
7573 fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
7575 fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
7576 finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
7580 /* Zap out the name so that the back-end will give us the debugging
7581 information for this anonymous RECORD_TYPE. */
7582 TYPE_NAME (t) = NULL_TREE;
7584 TYPE_SET_PTRMEMFUNC_TYPE (type, t);
7586 /* Seems to be wanted. */
7587 CLASSTYPE_GOT_SEMICOLON (t) = 1;
7591 /* Given declspecs and a declarator,
7592 determine the name and type of the object declared
7593 and construct a ..._DECL node for it.
7594 (In one case we can return a ..._TYPE node instead.
7595 For invalid input we sometimes return 0.)
7597 DECLSPECS is a chain of tree_list nodes whose value fields
7598 are the storage classes and type specifiers.
7600 DECL_CONTEXT says which syntactic context this declaration is in:
7601 NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
7602 FUNCDEF for a function definition. Like NORMAL but a few different
7603 error messages in each case. Return value may be zero meaning
7604 this definition is too screwy to try to parse.
7605 MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
7606 handle member functions (which have FIELD context).
7607 Return value may be zero meaning this definition is too screwy to
7609 PARM for a parameter declaration (either within a function prototype
7610 or before a function body). Make a PARM_DECL, or return void_type_node.
7611 CATCHPARM for a parameter declaration before a catch clause.
7612 TYPENAME if for a typename (in a cast or sizeof).
7613 Don't make a DECL node; just return the ..._TYPE node.
7614 FIELD for a struct or union field; make a FIELD_DECL.
7615 BITFIELD for a field with specified width.
7616 INITIALIZED is 1 if the decl has an initializer.
7618 In the TYPENAME case, DECLARATOR is really an absolute declarator.
7619 It may also be so in the PARM case, for a prototype where the
7620 argument type is specified but not the name.
7622 This function is where the complicated C meanings of `static'
7623 and `extern' are interpreted.
7625 For C++, if there is any monkey business to do, the function which
7626 calls this one must do it, i.e., prepending instance variables,
7627 renaming overloaded function names, etc.
7629 Note that for this C++, it is an error to define a method within a class
7630 which does not belong to that class.
7632 Except in the case where SCOPE_REFs are implicitly known (such as
7633 methods within a class being redundantly qualified),
7634 declarations which involve SCOPE_REFs are returned as SCOPE_REFs
7635 (class_name::decl_name). The caller must also deal with this.
7637 If a constructor or destructor is seen, and the context is FIELD,
7638 then the type gains the attribute TREE_HAS_x. If such a declaration
7639 is erroneous, NULL_TREE is returned.
7641 QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member
7642 function, these are the qualifiers to give to the `this' pointer.
7644 May return void_type_node if the declarator turned out to be a friend.
7645 See grokfield for details. */
7647 enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
7650 grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrlist)
7653 enum decl_context decl_context;
7655 tree raises, attrlist;
7657 RID_BIT_TYPE specbits;
7660 tree type = NULL_TREE;
7664 int virtualp, explicitp, friendp, inlinep, staticp;
7665 int explicit_int = 0;
7666 int explicit_char = 0;
7667 int opaque_typedef = 0;
7668 tree typedef_decl = NULL_TREE;
7670 tree typedef_type = NULL_TREE;
7671 int funcdef_flag = 0;
7672 enum tree_code innermost_code = ERROR_MARK;
7674 int size_varies = 0;
7675 tree decl_machine_attr = NULL_TREE;
7676 /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
7677 All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */
7678 tree init = NULL_TREE;
7680 /* Keep track of what sort of function is being processed
7681 so that we can warn about default return values, or explicit
7682 return values which do not match prescribed defaults. */
7683 enum return_types return_type = return_normal;
7685 tree dname = NULL_TREE;
7686 tree ctype = current_class_type;
7687 tree ctor_return_type = NULL_TREE;
7688 enum overload_flags flags = NO_SPECIAL;
7689 tree quals = NULL_TREE;
7691 RIDBIT_RESET_ALL (specbits);
7692 if (decl_context == FUNCDEF)
7693 funcdef_flag = 1, decl_context = NORMAL;
7694 else if (decl_context == MEMFUNCDEF)
7695 funcdef_flag = -1, decl_context = FIELD;
7696 else if (decl_context == BITFIELD)
7697 bitfield = 1, decl_context = FIELD;
7699 if (flag_traditional && allocation_temporary_p ())
7700 end_temporary_allocation ();
7702 /* Look inside a declarator for the name being declared
7703 and get it as a string, for an error message. */
7705 tree *next = &declarator;
7709 while (next && *next)
7712 switch (TREE_CODE (decl))
7716 next = &TREE_OPERAND (decl, 0);
7719 case BIT_NOT_EXPR: /* for C++ destructors! */
7721 tree name = TREE_OPERAND (decl, 0);
7722 tree rename = NULL_TREE;
7724 my_friendly_assert (flags == NO_SPECIAL, 152);
7726 return_type = return_dtor;
7727 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
7728 if (ctype == NULL_TREE)
7730 if (current_class_type == NULL_TREE)
7732 error ("destructors must be member functions");
7737 tree t = constructor_name (current_class_name);
7744 tree t = constructor_name (ctype);
7751 error ("destructor `%s' must match class name `%s'",
7752 IDENTIFIER_POINTER (name),
7753 IDENTIFIER_POINTER (rename));
7754 TREE_OPERAND (decl, 0) = rename;
7760 case ADDR_EXPR: /* C++ reference declaration */
7765 innermost_code = TREE_CODE (decl);
7766 next = &TREE_OPERAND (decl, 0);
7770 if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
7772 /* This is actually a variable declaration using constructor
7773 syntax. We need to call start_decl and cp_finish_decl so we
7774 can get the variable initialized... */
7776 *next = TREE_OPERAND (decl, 0);
7777 init = TREE_OPERAND (decl, 1);
7779 decl = start_decl (declarator, declspecs, 1, NULL_TREE);
7780 finish_decl (decl, init, NULL_TREE);
7783 innermost_code = TREE_CODE (decl);
7784 if (decl_context == FIELD && ctype == NULL_TREE)
7785 ctype = current_class_type;
7786 if (ctype && TREE_OPERAND (decl, 0) == ctype)
7787 TREE_OPERAND (decl, 0) = constructor_name (ctype);
7788 next = &TREE_OPERAND (decl, 0);
7790 if (ctype != NULL_TREE
7791 && decl != NULL_TREE && flags != DTOR_FLAG
7792 && decl == constructor_name (ctype))
7794 return_type = return_ctor;
7795 ctor_return_type = ctype;
7800 case IDENTIFIER_NODE:
7806 cp_error ("declarator-id missing; using reserved word `%D'",
7808 name = IDENTIFIER_POINTER (dname);
7810 if (! IDENTIFIER_OPNAME_P (dname)
7811 /* Linux headers use '__op'. Arrgh. */
7812 || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))
7813 name = IDENTIFIER_POINTER (dname);
7816 if (IDENTIFIER_TYPENAME_P (dname))
7818 my_friendly_assert (flags == NO_SPECIAL, 154);
7819 flags = TYPENAME_FLAG;
7820 ctor_return_type = TREE_TYPE (dname);
7821 return_type = return_conversion;
7823 name = operator_name_string (dname);
7830 /* Perform error checking, and decide on a ctype. */
7831 tree cname = TREE_OPERAND (decl, 0);
7832 if (cname == NULL_TREE)
7834 else if (! is_aggr_type (cname, 1))
7835 TREE_OPERAND (decl, 0) = NULL_TREE;
7836 /* Must test TREE_OPERAND (decl, 1), in case user gives
7837 us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */
7838 else if (TREE_OPERAND (decl, 1)
7839 && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
7841 else if (ctype == NULL_TREE)
7843 else if (TREE_COMPLEXITY (decl) == current_class_depth)
7844 TREE_OPERAND (decl, 0) = ctype;
7847 if (! UNIQUELY_DERIVED_FROM_P (cname, ctype))
7849 cp_error ("type `%T' is not derived from type `%T'",
7851 TREE_OPERAND (decl, 0) = NULL_TREE;
7858 && TREE_OPERAND (decl, 1) == constructor_name_full (ctype))
7859 TREE_OPERAND (decl, 1) = constructor_name (ctype);
7860 next = &TREE_OPERAND (decl, 1);
7864 if (TREE_CODE (decl) == IDENTIFIER_NODE
7865 && constructor_name (ctype) == decl)
7867 return_type = return_ctor;
7868 ctor_return_type = ctype;
7870 else if (TREE_CODE (decl) == BIT_NOT_EXPR
7871 && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
7872 && (constructor_name (ctype) == TREE_OPERAND (decl, 0)
7873 || constructor_name_full (ctype) == TREE_OPERAND (decl, 0)))
7875 return_type = return_dtor;
7876 ctor_return_type = ctype;
7878 TREE_OPERAND (decl, 0) = constructor_name (ctype);
7879 next = &TREE_OPERAND (decl, 0);
7890 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 't')
7892 /* Parse error puts this typespec where
7893 a declarator should go. */
7894 error ("typename specified as declarator-id");
7895 if (current_class_type)
7896 cp_error (" perhaps you want `%T' for a constructor",
7897 current_class_name);
7898 dname = TYPE_IDENTIFIER (decl);
7899 name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
7900 declspecs = temp_tree_cons (NULL_TREE, integer_type_node,
7906 cp_compiler_error ("`%D' as declarator", decl);
7907 return 0; /* We used to do a 155 abort here. */
7914 /* A function definition's declarator must have the form of
7915 a function declarator. */
7917 if (funcdef_flag && innermost_code != CALL_EXPR)
7920 if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG)
7921 && innermost_code != CALL_EXPR
7922 && ! (ctype && declspecs == NULL_TREE))
7924 cp_error ("declaration of `%D' as non-function", dname);
7925 return void_type_node;
7928 /* Anything declared one level down from the top level
7929 must be one of the parameters of a function
7930 (because the body is at least two levels down). */
7932 /* This heuristic cannot be applied to C++ nodes! Fixed, however,
7933 by not allowing C++ class definitions to specify their parameters
7934 with xdecls (must be spec.d in the parmlist).
7936 Since we now wait to push a class scope until we are sure that
7937 we are in a legitimate method context, we must set oldcname
7938 explicitly (since current_class_name is not yet alive).
7940 We also want to avoid calling this a PARM if it is in a namespace. */
7942 if (decl_context == NORMAL && ! namespace_bindings_p ())
7944 struct binding_level *b = current_binding_level;
7945 current_binding_level = b->level_chain;
7946 if (current_binding_level != 0 && toplevel_bindings_p ())
7947 decl_context = PARM;
7948 current_binding_level = b;
7951 /* Look through the decl specs and record which ones appear.
7952 Some typespecs are defined as built-in typenames.
7953 Others, the ones that are modifiers of other types,
7954 are represented by bits in SPECBITS: set the bits for
7955 the modifiers that appear. Storage class keywords are also in SPECBITS.
7957 If there is a typedef name or a type, store the type in TYPE.
7958 This includes builtin typedefs such as `int'.
7960 Set EXPLICIT_INT if the type is `int' or `char' and did not
7961 come from a user typedef.
7963 Set LONGLONG if `long' is mentioned twice.
7965 For C++, constructors and destructors have their own fast treatment. */
7967 for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
7972 /* Certain parse errors slip through. For example,
7973 `int class;' is not caught by the parser. Try
7974 weakly to recover here. */
7975 if (TREE_CODE (spec) != TREE_LIST)
7978 id = TREE_VALUE (spec);
7980 if (TREE_CODE (id) == IDENTIFIER_NODE)
7982 if (id == ridpointers[(int) RID_INT]
7983 || id == ridpointers[(int) RID_CHAR]
7984 || id == ridpointers[(int) RID_BOOL]
7985 || id == ridpointers[(int) RID_WCHAR])
7989 if (id == ridpointers[(int) RID_BOOL])
7990 error ("`bool' is now a keyword");
7992 cp_error ("extraneous `%T' ignored", id);
7996 if (id == ridpointers[(int) RID_INT])
7998 else if (id == ridpointers[(int) RID_CHAR])
8000 type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
8004 /* C++ aggregate types. */
8005 if (IDENTIFIER_HAS_TYPE_VALUE (id))
8008 cp_error ("multiple declarations `%T' and `%T'", type, id);
8010 type = IDENTIFIER_TYPE_VALUE (id);
8014 for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++)
8016 if (ridpointers[i] == id)
8018 if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
8020 if (pedantic && ! in_system_header)
8021 pedwarn ("ANSI C++ does not support `long long'");
8023 error ("`long long long' is too long for GCC");
8027 else if (RIDBIT_SETP (i, specbits))
8028 pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
8029 RIDBIT_SET (i, specbits);
8035 error ("two or more data types in declaration of `%s'", name);
8036 else if (TREE_CODE (id) == IDENTIFIER_NODE)
8038 register tree t = lookup_name (id, 1);
8039 if (!t || TREE_CODE (t) != TYPE_DECL)
8040 error ("`%s' fails to be a typedef or built in type",
8041 IDENTIFIER_POINTER (id));
8044 type = TREE_TYPE (t);
8045 decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id);
8049 else if (TREE_CODE (id) != ERROR_MARK)
8050 /* Can't change CLASS nodes into RECORD nodes here! */
8056 typedef_type = type;
8058 /* No type at all: default to `int', and set EXPLICIT_INT
8059 because it was not a user-defined typedef.
8060 Except when we have a `typedef' inside a signature, in
8061 which case the type defaults to `unknown type' and is
8062 instantiated when assigning to a signature pointer or ref. */
8064 if (type == NULL_TREE
8065 && (RIDBIT_SETP (RID_SIGNED, specbits)
8066 || RIDBIT_SETP (RID_UNSIGNED, specbits)
8067 || RIDBIT_SETP (RID_LONG, specbits)
8068 || RIDBIT_SETP (RID_SHORT, specbits)))
8070 /* These imply 'int'. */
8071 type = integer_type_node;
8075 if (type == NULL_TREE)
8078 if (return_type == return_dtor)
8079 type = void_type_node;
8080 else if (return_type == return_ctor)
8081 type = build_pointer_type (ctor_return_type);
8082 else if (return_type == return_conversion)
8083 type = ctor_return_type;
8084 else if (current_class_type
8085 && IS_SIGNATURE (current_class_type)
8086 && (RIDBIT_SETP (RID_TYPEDEF, specbits)
8087 || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
8088 && (decl_context == FIELD || decl_context == NORMAL))
8092 type = copy_node (opaque_type_node);
8094 /* access declaration */
8095 else if (decl_context == FIELD && declarator
8096 && TREE_CODE (declarator) == SCOPE_REF)
8097 type = void_type_node;
8102 if (warn_return_type
8103 && return_type == return_normal)
8104 /* Save warning until we know what is really going on. */
8105 warn_about_return_type = 1;
8107 else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8108 pedwarn ("ANSI C++ forbids typedef which does not specify a type");
8109 else if (declspecs == NULL_TREE &&
8110 (innermost_code != CALL_EXPR || pedantic))
8111 cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class",
8113 type = integer_type_node;
8116 else if (return_type == return_dtor)
8118 error ("return type specification for destructor invalid");
8119 type = void_type_node;
8121 else if (return_type == return_ctor)
8123 error ("return type specification for constructor invalid");
8124 type = build_pointer_type (ctor_return_type);
8126 else if (return_type == return_conversion)
8128 if (comptypes (type, ctor_return_type, 1) == 0)
8129 cp_error ("operator `%T' declared to return `%T'",
8130 ctor_return_type, type);
8132 cp_pedwarn ("return type specified for `operator %T'",
8135 type = ctor_return_type;
8137 /* Catch typedefs that only specify a type, like 'typedef int;'. */
8138 else if (RIDBIT_SETP (RID_TYPEDEF, specbits) && declarator == NULL_TREE)
8140 /* Template "this is a type" syntax; just ignore for now. */
8141 if (processing_template_defn)
8142 return void_type_node;
8147 /* Now process the modifiers that were specified
8148 and check for invalid combinations. */
8150 /* Long double is a special combination. */
8152 if (RIDBIT_SETP (RID_LONG, specbits)
8153 && TYPE_MAIN_VARIANT (type) == double_type_node)
8155 RIDBIT_RESET (RID_LONG, specbits);
8156 type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
8157 TYPE_VOLATILE (type));
8160 /* Check all other uses of type modifiers. */
8162 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
8163 || RIDBIT_SETP (RID_SIGNED, specbits)
8164 || RIDBIT_SETP (RID_LONG, specbits)
8165 || RIDBIT_SETP (RID_SHORT, specbits))
8169 if (TREE_CODE (type) == REAL_TYPE)
8170 error ("short, signed or unsigned invalid for `%s'", name);
8171 else if (TREE_CODE (type) != INTEGER_TYPE)
8172 error ("long, short, signed or unsigned invalid for `%s'", name);
8173 else if (RIDBIT_SETP (RID_LONG, specbits)
8174 && RIDBIT_SETP (RID_SHORT, specbits))
8175 error ("long and short specified together for `%s'", name);
8176 else if ((RIDBIT_SETP (RID_LONG, specbits)
8177 || RIDBIT_SETP (RID_SHORT, specbits))
8179 error ("long or short specified with char for `%s'", name);
8180 else if ((RIDBIT_SETP (RID_LONG, specbits)
8181 || RIDBIT_SETP (RID_SHORT, specbits))
8182 && TREE_CODE (type) == REAL_TYPE)
8183 error ("long or short specified with floating type for `%s'", name);
8184 else if (RIDBIT_SETP (RID_SIGNED, specbits)
8185 && RIDBIT_SETP (RID_UNSIGNED, specbits))
8186 error ("signed and unsigned given together for `%s'", name);
8190 if (!explicit_int && !explicit_char && pedantic)
8192 pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
8194 if (flag_pedantic_errors)
8199 /* Discard the type modifiers if they are invalid. */
8202 RIDBIT_RESET (RID_UNSIGNED, specbits);
8203 RIDBIT_RESET (RID_SIGNED, specbits);
8204 RIDBIT_RESET (RID_LONG, specbits);
8205 RIDBIT_RESET (RID_SHORT, specbits);
8210 /* Decide whether an integer type is signed or not.
8211 Optionally treat bitfields as signed by default. */
8212 if (RIDBIT_SETP (RID_UNSIGNED, specbits)
8213 /* Traditionally, all bitfields are unsigned. */
8214 || (bitfield && flag_traditional)
8215 || (bitfield && ! flag_signed_bitfields
8216 && (explicit_int || explicit_char
8217 /* A typedef for plain `int' without `signed'
8218 can be controlled just like plain `int'. */
8219 || ! (typedef_decl != NULL_TREE
8220 && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
8221 && TREE_CODE (type) != ENUMERAL_TYPE
8222 && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
8225 type = long_long_unsigned_type_node;
8226 else if (RIDBIT_SETP (RID_LONG, specbits))
8227 type = long_unsigned_type_node;
8228 else if (RIDBIT_SETP (RID_SHORT, specbits))
8229 type = short_unsigned_type_node;
8230 else if (type == char_type_node)
8231 type = unsigned_char_type_node;
8232 else if (typedef_decl)
8233 type = unsigned_type (type);
8235 type = unsigned_type_node;
8237 else if (RIDBIT_SETP (RID_SIGNED, specbits)
8238 && type == char_type_node)
8239 type = signed_char_type_node;
8241 type = long_long_integer_type_node;
8242 else if (RIDBIT_SETP (RID_LONG, specbits))
8243 type = long_integer_type_node;
8244 else if (RIDBIT_SETP (RID_SHORT, specbits))
8245 type = short_integer_type_node;
8247 /* Set CONSTP if this declaration is `const', whether by
8248 explicit specification or via a typedef.
8249 Likewise for VOLATILEP. */
8251 constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
8252 volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
8254 inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
8256 /* This sort of redundancy is blessed in a footnote to the Sep 94 WP. */
8258 warning ("duplicate `const'");
8260 warning ("duplicate `volatile'");
8262 virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
8263 RIDBIT_RESET (RID_VIRTUAL, specbits);
8264 explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0;
8265 RIDBIT_RESET (RID_EXPLICIT, specbits);
8267 if (RIDBIT_SETP (RID_STATIC, specbits))
8268 staticp = 1 + (decl_context == FIELD);
8270 if (virtualp && staticp == 2)
8272 cp_error ("member `%D' cannot be declared both virtual and static",
8276 friendp = RIDBIT_SETP (RID_FRIEND, specbits);
8277 RIDBIT_RESET (RID_FRIEND, specbits);
8279 if (RIDBIT_SETP (RID_MUTABLE, specbits))
8281 if (decl_context == PARM)
8283 error ("non-member `%s' cannot be declared `mutable'", name);
8284 RIDBIT_RESET (RID_MUTABLE, specbits);
8286 else if (friendp || decl_context == TYPENAME)
8288 error ("non-object member `%s' cannot be declared `mutable'", name);
8289 RIDBIT_RESET (RID_MUTABLE, specbits);
8292 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8294 error ("non-object member `%s' cannot be declared `mutable'", name);
8295 RIDBIT_RESET (RID_MUTABLE, specbits);
8297 /* Because local typedefs are parsed twice, we don't want this
8299 else if (decl_context != FIELD)
8301 error ("non-member `%s' cannot be declared `mutable'", name);
8302 RIDBIT_RESET (RID_MUTABLE, specbits);
8307 /* Warn if two storage classes are given. Default to `auto'. */
8309 if (RIDBIT_ANY_SET (specbits))
8311 if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
8312 if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
8313 if (decl_context == PARM && nclasses > 0)
8314 error ("storage class specifiers invalid in parameter declarations");
8315 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
8317 if (decl_context == PARM)
8318 error ("typedef declaration invalid in parameter declaration");
8321 if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
8322 if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
8325 /* Give error if `virtual' is used outside of class declaration. */
8327 && (current_class_name == NULL_TREE || decl_context != FIELD))
8329 error ("virtual outside class declaration");
8332 if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
8334 error ("only members can be declared mutable");
8335 RIDBIT_RESET (RID_MUTABLE, specbits);
8338 /* Static anonymous unions are dealt with here. */
8339 if (staticp && decl_context == TYPENAME
8340 && TREE_CODE (declspecs) == TREE_LIST
8341 && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
8342 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
8343 decl_context = FIELD;
8345 /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
8346 is used in a signature member function declaration. */
8347 if (decl_context == FIELD
8348 && IS_SIGNATURE (current_class_type)
8349 && RIDBIT_NOTSETP(RID_TYPEDEF, specbits)
8350 && !SIGNATURE_GROKKING_TYPEDEF (current_class_type))
8354 error ("`const' specified for signature member function `%s'", name);
8359 error ("`volatile' specified for signature member function `%s'",
8365 error ("`inline' specified for signature member function `%s'", name);
8366 /* Later, we'll make signature member functions inline. */
8371 error ("`friend' declaration in signature definition");
8376 error ("`virtual' specified for signature member function `%s'",
8378 /* Later, we'll make signature member functions virtual. */
8383 /* Warn about storage classes that are invalid for certain
8384 kinds of declarations (parameters, typenames, etc.). */
8387 error ("multiple storage classes in declaration of `%s'", name);
8388 else if (decl_context != NORMAL && nclasses > 0)
8390 if ((decl_context == PARM || decl_context == CATCHPARM)
8391 && (RIDBIT_SETP (RID_REGISTER, specbits)
8392 || RIDBIT_SETP (RID_AUTO, specbits)))
8394 else if (decl_context == FIELD
8395 && RIDBIT_SETP (RID_TYPEDEF, specbits))
8397 /* Processing a typedef declaration nested within a class type
8399 register tree scanner;
8400 register tree previous_declspec;
8404 error ("typedef declaration includes an initializer");
8406 /* To process a class-local typedef declaration, we descend down
8407 the chain of declspecs looking for the `typedef' spec. When
8408 we find it, we replace it with `static', and then recursively
8409 call `grokdeclarator' with the original declarator and with
8410 the newly adjusted declspecs. This call should return a
8411 FIELD_DECL node with the TREE_TYPE (and other parts) set
8412 appropriately. We can then just change the TREE_CODE on that
8413 from FIELD_DECL to TYPE_DECL and we're done. */
8415 for (previous_declspec = NULL_TREE, scanner = declspecs;
8417 previous_declspec = scanner, scanner = TREE_CHAIN (scanner))
8419 if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF])
8423 if (previous_declspec)
8424 TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner);
8426 declspecs = TREE_CHAIN (scanner);
8428 declspecs = tree_cons (NULL_TREE, ridpointers[(int) RID_STATIC],
8431 /* In the recursive call to grokdeclarator we need to know
8432 whether we are working on a signature-local typedef. */
8433 if (IS_SIGNATURE (current_class_type))
8434 SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1;
8437 grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE, NULL_TREE);
8439 if (previous_declspec)
8440 TREE_CHAIN (previous_declspec) = scanner;
8442 if (loc_typedecl != error_mark_node)
8444 register int i = sizeof (struct lang_decl_flags) / sizeof (int);
8447 TREE_SET_CODE (loc_typedecl, TYPE_DECL);
8448 /* This is the same field as DECL_ARGUMENTS, which is set for
8449 function typedefs by the above grokdeclarator. */
8450 DECL_NESTED_TYPENAME (loc_typedecl) = 0;
8452 pi = (int *) permalloc (sizeof (struct lang_decl_flags));
8455 DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
8458 if (IS_SIGNATURE (current_class_type))
8460 SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0;
8461 if (loc_typedecl != error_mark_node && opaque_typedef)
8462 SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
8465 return loc_typedecl;
8467 else if (decl_context == FIELD
8468 && (! IS_SIGNATURE (current_class_type)
8469 || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
8470 /* C++ allows static class elements */
8471 && RIDBIT_SETP (RID_STATIC, specbits))
8472 /* C++ also allows inlines and signed and unsigned elements,
8473 but in those cases we don't come in here. */
8477 if (decl_context == FIELD)
8479 tree tmp = NULL_TREE;
8480 register int op = 0;
8484 tmp = TREE_OPERAND (declarator, 0);
8485 op = IDENTIFIER_OPNAME_P (tmp);
8487 error ("storage class specified for %s `%s'",
8488 IS_SIGNATURE (current_class_type)
8490 ? "signature member operator"
8491 : "signature member function")
8492 : (op ? "member operator" : "field"),
8493 op ? operator_name_string (tmp) : name);
8496 error (((decl_context == PARM || decl_context == CATCHPARM)
8497 ? "storage class specified for parameter `%s'"
8498 : "storage class specified for typename"), name);
8499 RIDBIT_RESET (RID_REGISTER, specbits);
8500 RIDBIT_RESET (RID_AUTO, specbits);
8501 RIDBIT_RESET (RID_EXTERN, specbits);
8503 if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
8505 RIDBIT_RESET (RID_STATIC, specbits);
8510 else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
8512 if (toplevel_bindings_p ())
8514 /* It's common practice (and completely valid) to have a const
8515 be initialized and declared extern. */
8517 warning ("`%s' initialized and declared `extern'", name);
8520 error ("`%s' has both `extern' and initializer", name);
8522 else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
8523 && ! toplevel_bindings_p ())
8524 error ("nested function `%s' declared `extern'", name);
8525 else if (toplevel_bindings_p ())
8527 if (RIDBIT_SETP (RID_AUTO, specbits))
8528 error ("top-level declaration of `%s' specifies `auto'", name);
8530 if (RIDBIT_SETP (RID_REGISTER, specbits))
8531 error ("top-level declaration of `%s' specifies `register'", name);
8534 /* I'm not sure under what circumstances we should turn
8535 on the extern bit, and under what circumstances we should
8536 warn if other bits are turned on. */
8537 if (decl_context == NORMAL
8538 && RIDBIT_NOSETP (RID_EXTERN, specbits)
8539 && ! root_lang_context_p ())
8541 RIDBIT_SET (RID_EXTERN, specbits);
8546 /* Now figure out the structure of the declarator proper.
8547 Descend through it, creating more complex types, until we reach
8548 the declared identifier (or NULL_TREE, in an absolute declarator). */
8550 while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
8552 /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
8553 an INDIRECT_REF (for *...),
8554 a CALL_EXPR (for ...(...)),
8555 an identifier (for the name being declared)
8556 or a null pointer (for the place in an absolute declarator
8557 where the name was omitted).
8558 For the last two cases, we have just exited the loop.
8560 For C++ it could also be
8561 a SCOPE_REF (for class :: ...). In this case, we have converted
8562 sensible names to types, and those are the values we use to
8563 qualify the member name.
8564 an ADDR_EXPR (for &...),
8565 a BIT_NOT_EXPR (for destructors)
8567 At this point, TYPE is the type of elements of an array,
8568 or for a function to return, or for a pointer to point to.
8569 After this sequence of ifs, TYPE is the type of the
8570 array or function or pointer, and DECLARATOR has had its
8571 outermost layer removed. */
8573 if (TREE_CODE (type) == ERROR_MARK)
8575 if (TREE_CODE (declarator) == SCOPE_REF)
8576 declarator = TREE_OPERAND (declarator, 1);
8578 declarator = TREE_OPERAND (declarator, 0);
8581 if (quals != NULL_TREE
8582 && (declarator == NULL_TREE
8583 || TREE_CODE (declarator) != SCOPE_REF))
8585 if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
8586 ctype = TYPE_METHOD_BASETYPE (type);
8587 if (ctype != NULL_TREE)
8589 #if 0 /* not yet, should get fixed properly later */
8590 tree dummy = make_type_decl (NULL_TREE, type);
8592 tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
8594 ctype = grok_method_quals (ctype, dummy, quals);
8595 type = TREE_TYPE (dummy);
8599 switch (TREE_CODE (declarator))
8603 register tree itype = NULL_TREE;
8604 register tree size = TREE_OPERAND (declarator, 1);
8605 /* The index is a signed object `sizetype' bits wide. */
8606 tree index_type = signed_type (sizetype);
8608 declarator = TREE_OPERAND (declarator, 0);
8610 /* Check for some types that there cannot be arrays of. */
8612 if (TYPE_MAIN_VARIANT (type) == void_type_node)
8614 cp_error ("declaration of `%D' as array of voids", dname);
8615 type = error_mark_node;
8618 if (TREE_CODE (type) == FUNCTION_TYPE)
8620 cp_error ("declaration of `%D' as array of functions", dname);
8621 type = error_mark_node;
8624 /* ARM $8.4.3: Since you can't have a pointer to a reference,
8625 you can't have arrays of references. If we allowed them,
8626 then we'd be saying x[i] is valid for an array x, but
8627 then you'd have to ask: what does `*(x + i)' mean? */
8628 if (TREE_CODE (type) == REFERENCE_TYPE)
8630 if (decl_context == TYPENAME)
8631 cp_error ("cannot make arrays of references");
8633 cp_error ("declaration of `%D' as array of references",
8635 type = error_mark_node;
8638 if (TREE_CODE (type) == OFFSET_TYPE)
8640 cp_error ("declaration of `%D' as array of data members",
8642 type = error_mark_node;
8645 if (TREE_CODE (type) == METHOD_TYPE)
8647 cp_error ("declaration of `%D' as array of function members",
8649 type = error_mark_node;
8652 if (size == error_mark_node)
8653 type = error_mark_node;
8655 if (type == error_mark_node)
8660 /* Must suspend_momentary here because the index
8661 type may need to live until the end of the function.
8662 For example, it is used in the declaration of a
8663 variable which requires destructing at the end of
8664 the function; then build_vec_delete will need this
8666 int yes = suspend_momentary ();
8667 /* might be a cast */
8668 if (TREE_CODE (size) == NOP_EXPR
8669 && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
8670 size = TREE_OPERAND (size, 0);
8672 /* If this is a template parameter, it'll be constant, but
8673 we don't know what the value is yet. */
8674 if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
8675 goto dont_grok_size;
8677 if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
8678 && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
8680 cp_error ("size of array `%D' has non-integer type",
8682 size = integer_one_node;
8684 if (TREE_READONLY_DECL_P (size))
8685 size = decl_constant_value (size);
8686 if (pedantic && integer_zerop (size))
8687 cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
8688 if (TREE_CONSTANT (size))
8690 int old_flag_pedantic_errors = flag_pedantic_errors;
8691 int old_pedantic = pedantic;
8692 pedantic = flag_pedantic_errors = 1;
8693 /* Always give overflow errors on array subscripts. */
8694 constant_expression_warning (size);
8695 pedantic = old_pedantic;
8696 flag_pedantic_errors = old_flag_pedantic_errors;
8697 if (INT_CST_LT (size, integer_zero_node))
8699 cp_error ("size of array `%D' is negative", dname);
8700 size = integer_one_node;
8708 cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
8711 cp_pedwarn ("ANSI C++ forbids variable-size array");
8713 /* Make sure the array size remains visibly nonconstant
8714 even if it is (eg) a const variable with known value. */
8720 fold (build_binary_op (MINUS_EXPR,
8721 convert (index_type, size),
8722 convert (index_type,
8723 integer_one_node), 1));
8724 if (! TREE_CONSTANT (itype))
8725 itype = variable_size (itype);
8726 itype = build_index_type (itype);
8727 resume_momentary (yes);
8730 /* Build the array type itself, then merge any constancy or
8731 volatility into the target type. We must do it in this order
8732 to ensure that the TYPE_MAIN_VARIANT field of the array type
8733 is set correctly. */
8735 type = build_cplus_array_type (type, itype);
8736 if (constp || volatilep)
8737 type = cp_build_type_variant (type, constp, volatilep);
8747 tree inner_parms = TREE_OPERAND (declarator, 1);
8748 tree inner_decl = TREE_OPERAND (declarator, 0);
8750 /* Declaring a function type.
8751 Make sure we have a valid type for the function to return. */
8753 /* Is this an error? Should they be merged into TYPE here? */
8754 if (pedantic && (constp || volatilep))
8755 pedwarn ("function declared to return const or volatile result");
8757 /* Merge any constancy or volatility into the function return
8760 if (constp || volatilep)
8762 type = cp_build_type_variant (type, constp, volatilep);
8763 if (IS_AGGR_TYPE (type))
8764 build_pointer_type (type);
8770 /* Warn about some types functions can't return. */
8772 if (TREE_CODE (type) == FUNCTION_TYPE)
8774 error ("`%s' declared as function returning a function", name);
8775 type = integer_type_node;
8777 if (TREE_CODE (type) == ARRAY_TYPE)
8779 error ("`%s' declared as function returning an array", name);
8780 type = integer_type_node;
8783 if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
8784 inner_decl = TREE_OPERAND (inner_decl, 1);
8786 /* Pick up type qualifiers which should be applied to `this'. */
8787 quals = TREE_OPERAND (declarator, 2);
8789 /* Say it's a definition only for the CALL_EXPR
8790 closest to the identifier. */
8792 inner_decl && (TREE_CODE (inner_decl) == IDENTIFIER_NODE
8793 || TREE_CODE (inner_decl) == BIT_NOT_EXPR);
8795 if (ctype == NULL_TREE
8796 && decl_context == FIELD
8798 && (friendp == 0 || dname == current_class_name))
8799 ctype = current_class_type;
8801 if (ctype && return_type == return_conversion)
8802 TYPE_HAS_CONVERSION (ctype) = 1;
8803 if (ctype && constructor_name (ctype) == dname)
8805 /* We are within a class's scope. If our declarator name
8806 is the same as the class name, and we are defining
8807 a function, then it is a constructor/destructor, and
8808 therefore returns a void type. */
8810 if (flags == DTOR_FLAG)
8812 /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may
8813 not be declared const or volatile. A destructor
8814 may not be static. */
8816 error ("destructor cannot be static member function");
8819 error ("destructors cannot be declared `const' or `volatile'");
8820 return void_type_node;
8822 if (decl_context == FIELD)
8824 if (! member_function_or_else (ctype, current_class_type,
8825 "destructor for alien class `%s' cannot be a member"))
8826 return void_type_node;
8829 else /* it's a constructor. */
8833 /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may
8834 not be declared const or volatile. A constructor may
8835 not be virtual. A constructor may not be static. */
8837 error ("constructor cannot be static member function");
8840 pedwarn ("constructors cannot be declared virtual");
8845 error ("constructors cannot be declared `const' or `volatile'");
8846 return void_type_node;
8849 RID_BIT_TYPE tmp_bits;
8850 bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE));
8851 RIDBIT_RESET (RID_INLINE, tmp_bits);
8852 RIDBIT_RESET (RID_STATIC, tmp_bits);
8853 if (RIDBIT_ANY_SET (tmp_bits))
8854 error ("return value type specifier for constructor ignored");
8856 type = build_pointer_type (ctype);
8857 if (decl_context == FIELD &&
8858 IS_SIGNATURE (current_class_type))
8860 error ("constructor not allowed in signature");
8861 return void_type_node;
8863 else if (decl_context == FIELD)
8865 if (! member_function_or_else (ctype, current_class_type,
8866 "constructor for alien class `%s' cannot be member"))
8867 return void_type_node;
8868 TYPE_HAS_CONSTRUCTOR (ctype) = 1;
8869 if (return_type != return_ctor)
8873 if (decl_context == FIELD)
8879 error ("can't initialize friend function `%s'", name);
8882 /* Cannot be both friend and virtual. */
8883 error ("virtual functions cannot be friends");
8884 RIDBIT_RESET (RID_FRIEND, specbits);
8887 if (decl_context == NORMAL)
8888 error ("friend declaration not in class definition");
8889 if (current_function_decl && funcdef_flag)
8890 cp_error ("can't define friend function `%s' in a local class definition",
8894 /* Traditionally, declaring return type float means double. */
8896 if (flag_traditional
8897 && TYPE_MAIN_VARIANT (type) == float_type_node)
8899 type = build_type_variant (double_type_node,
8900 TYPE_READONLY (type),
8901 TYPE_VOLATILE (type));
8904 /* Construct the function type and go to the next
8905 inner layer of declarator. */
8907 declarator = TREE_OPERAND (declarator, 0);
8909 /* FIXME: This is where default args should be fully
8912 arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0);
8916 /* Get past destructors, etc.
8917 We know we have one because FLAGS will be non-zero.
8919 Complain about improper parameter lists here. */
8920 if (TREE_CODE (declarator) == BIT_NOT_EXPR)
8922 declarator = TREE_OPERAND (declarator, 0);
8924 if (strict_prototype == 0 && arg_types == NULL_TREE)
8925 arg_types = void_list_node;
8926 else if (arg_types == NULL_TREE
8927 || arg_types != void_list_node)
8929 error ("destructors cannot be specified with parameters");
8930 arg_types = void_list_node;
8935 /* ANSI seems to say that `const int foo ();'
8936 does not make the function foo const. */
8937 type = build_function_type (type,
8938 flag_traditional ? 0 : arg_types);
8944 /* Filter out pointers-to-references and references-to-references.
8945 We can get these if a TYPE_DECL is used. */
8947 if (TREE_CODE (type) == REFERENCE_TYPE)
8949 error ("cannot declare %s to references",
8950 TREE_CODE (declarator) == ADDR_EXPR
8951 ? "references" : "pointers");
8952 declarator = TREE_OPERAND (declarator, 0);
8956 if (TREE_CODE (type) == OFFSET_TYPE
8957 && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE
8958 || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE))
8960 cp_error ("cannot declare pointer to `%#T' member",
8962 type = TREE_TYPE (type);
8965 /* Merge any constancy or volatility into the target type
8968 if (constp || volatilep)
8970 /* A const or volatile signature pointer/reference is
8971 pointing to a const or volatile object, i.e., the
8972 `optr' is const or volatile, respectively, not the
8973 signature pointer/reference itself. */
8974 if (! IS_SIGNATURE (type))
8976 type = cp_build_type_variant (type, constp, volatilep);
8977 if (IS_AGGR_TYPE (type))
8978 build_pointer_type (type);
8984 if (IS_SIGNATURE (type))
8986 if (TREE_CODE (declarator) == ADDR_EXPR)
8988 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
8989 && TYPE_SIZE (type))
8990 cp_warning ("empty signature `%T' used in signature reference declaration",
8993 type = build_signature_reference_type (type,
8996 sorry ("signature reference");
9002 if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
9003 && TYPE_SIZE (type))
9004 cp_warning ("empty signature `%T' used in signature pointer declaration",
9006 type = build_signature_pointer_type (type,
9012 else if (TREE_CODE (declarator) == ADDR_EXPR)
9014 if (TREE_CODE (type) == FUNCTION_TYPE)
9016 error ("cannot declare references to functions; use pointer to function instead");
9017 type = build_pointer_type (type);
9021 if (TYPE_MAIN_VARIANT (type) == void_type_node)
9022 error ("invalid type: `void &'");
9024 type = build_reference_type (type);
9027 else if (TREE_CODE (type) == METHOD_TYPE)
9029 type = build_ptrmemfunc_type (build_pointer_type (type));
9032 type = build_pointer_type (type);
9034 /* Process a list of type modifier keywords (such as
9035 const or volatile) that were given inside the `*' or `&'. */
9037 if (TREE_TYPE (declarator))
9039 register tree typemodlist;
9041 for (typemodlist = TREE_TYPE (declarator); typemodlist;
9042 typemodlist = TREE_CHAIN (typemodlist))
9044 if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
9046 else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
9051 error ("invalid type modifier within %s declarator",
9052 TREE_CODE (declarator) == ADDR_EXPR
9053 ? "reference" : "pointer");
9057 pedwarn ("duplicate `const'");
9059 pedwarn ("duplicate `volatile'");
9060 if (TREE_CODE (declarator) == ADDR_EXPR
9061 && (constp || volatilep))
9064 pedwarn ("discarding `const' applied to a reference");
9066 pedwarn ("discarding `volatile' applied to a reference");
9067 constp = volatilep = 0;
9070 declarator = TREE_OPERAND (declarator, 0);
9076 /* We have converted type names to NULL_TREE if the
9077 name was bogus, or to a _TYPE node, if not.
9079 The variable CTYPE holds the type we will ultimately
9080 resolve to. The code here just needs to build
9081 up appropriate member types. */
9082 tree sname = TREE_OPERAND (declarator, 1);
9083 /* Destructors can have their visibilities changed as well. */
9084 if (TREE_CODE (sname) == BIT_NOT_EXPR)
9085 sname = TREE_OPERAND (sname, 0);
9087 if (TREE_COMPLEXITY (declarator) == 0)
9088 /* This needs to be here, in case we are called
9089 multiple times. */ ;
9090 else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
9091 /* don't fall out into global scope. Hides real bug? --eichin */ ;
9092 else if (TREE_COMPLEXITY (declarator) == current_class_depth)
9094 /* This pop_nested_class corresponds to the
9095 push_nested_class used to push into class scope for
9096 parsing the argument list of a function decl, in
9098 pop_nested_class (1);
9099 TREE_COMPLEXITY (declarator) = current_class_depth;
9102 my_friendly_abort (16);
9104 if (TREE_OPERAND (declarator, 0) == NULL_TREE)
9106 /* We had a reference to a global decl, or
9107 perhaps we were given a non-aggregate typedef,
9108 in which case we cleared this out, and should just
9109 keep going as though it wasn't there. */
9113 ctype = TREE_OPERAND (declarator, 0);
9115 if (sname == NULL_TREE)
9118 if (TREE_CODE (sname) == IDENTIFIER_NODE)
9120 /* This is the `standard' use of the scoping operator:
9121 basetype :: member . */
9123 if (ctype == current_class_type)
9129 Is this ill-formed? */
9132 cp_pedwarn ("extra qualification `%T::' on member `%s' ignored",
9135 else if (TREE_CODE (type) == FUNCTION_TYPE)
9137 if (current_class_type == NULL_TREE
9139 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
9140 TREE_TYPE (type), TYPE_ARG_TYPES (type));
9143 cp_error ("cannot declare member function `%T::%s' within `%T'",
9144 ctype, name, current_class_type);
9145 return void_type_node;
9148 else if (TYPE_SIZE (ctype) != NULL_TREE
9149 || (RIDBIT_SETP (RID_TYPEDEF, specbits)))
9152 /* have to move this code elsewhere in this function.
9153 this code is used for i.e., typedef int A::M; M *pm;
9155 It is? How? jason 10/2/94 */
9157 if (explicit_int == -1 && decl_context == FIELD
9158 && funcdef_flag == 0)
9160 /* The code in here should only be used to build
9161 stuff that will be grokked as access decls. */
9162 t = lookup_field (ctype, sname, 0, 0);
9165 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
9166 DECL_INITIAL (t) = init;
9169 /* No such field, try member functions. */
9170 t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
9173 if (flags == DTOR_FLAG)
9175 else if (CLASSTYPE_METHOD_VEC (ctype)
9176 && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
9178 /* Don't include destructor with constructors. */
9179 t = DECL_CHAIN (TREE_VALUE (t));
9181 cp_error ("`%T' does not have any constructors",
9183 t = build_tree_list (NULL_TREE, t);
9185 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
9186 DECL_INITIAL (t) = init;
9191 ("field `%D' is not a member of structure `%T'",
9195 if (current_class_type)
9197 cp_error ("cannot declare member `%T::%s' within `%T'",
9198 ctype, name, current_class_type);
9199 return void_type_node;
9201 type = build_offset_type (ctype, type);
9203 else if (uses_template_parms (ctype))
9206 if (TREE_CODE (type) == FUNCTION_TYPE)
9208 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
9210 TYPE_ARG_TYPES (type));
9216 cp_error ("structure `%T' not yet defined", ctype);
9217 return error_mark_node;
9222 else if (TREE_CODE (sname) == SCOPE_REF)
9223 my_friendly_abort (17);
9227 declarator = TREE_OPERAND (declarator, 1);
9228 if (declarator && TREE_CODE (declarator) == CALL_EXPR)
9229 /* In this case, we will deal with it later. */
9233 if (TREE_CODE (type) == FUNCTION_TYPE)
9234 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
9236 type = build_offset_type (ctype, type);
9243 declarator = TREE_OPERAND (declarator, 0);
9249 declarator = NULL_TREE;
9253 declarator = NULL_TREE;
9257 my_friendly_abort (158);
9263 error ("only constructors can be declared `explicit'");
9267 /* Now TYPE has the actual type. */
9269 /* If this is declaring a typedef name, return a TYPE_DECL. */
9271 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9275 error ("const `%s' cannot be declared `mutable'", name);
9276 RIDBIT_RESET (RID_MUTABLE, specbits);
9280 error ("static `%s' cannot be declared `mutable'", name);
9281 RIDBIT_RESET (RID_MUTABLE, specbits);
9285 if (RIDBIT_SETP (RID_TYPEDEF, specbits))
9289 /* Note that the grammar rejects storage classes
9290 in typenames, fields or parameters. */
9291 if (constp || volatilep)
9292 type = cp_build_type_variant (type, constp, volatilep);
9294 /* If the user declares "struct {...} foo" then `foo' will have
9295 an anonymous name. Fill that name in now. Nothing can
9296 refer to it, so nothing needs know about the name change.
9297 The TYPE_NAME field was filled in by build_struct_xref. */
9298 if (type != error_mark_node
9300 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9301 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
9303 /* replace the anonymous name with the real name everywhere. */
9304 lookup_tag_reverse (type, declarator);
9305 TYPE_IDENTIFIER (type) = declarator;
9307 if (TYPE_LANG_SPECIFIC (type))
9308 TYPE_WAS_ANONYMOUS (type) = 1;
9311 tree d = TYPE_NAME (type), c = DECL_CONTEXT (d);
9314 set_nested_typename (d, 0, declarator, type);
9315 else if (TREE_CODE (c) == FUNCTION_DECL)
9316 set_nested_typename (d, DECL_ASSEMBLER_NAME (c),
9319 set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type);
9321 DECL_ASSEMBLER_NAME (d) = DECL_NAME (d);
9322 DECL_ASSEMBLER_NAME (d)
9323 = get_identifier (build_overload_name (type, 1, 1));
9327 #if 0 /* not yet, should get fixed properly later */
9328 decl = make_type_decl (declarator, type);
9330 decl = build_decl (TYPE_DECL, declarator, type);
9332 if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
9334 cp_error_at ("typedef name may not be class-qualified", decl);
9339 if (ctype == NULL_TREE)
9341 if (TREE_CODE (type) != METHOD_TYPE)
9342 cp_error_at ("invalid type qualifier for non-method type", decl);
9344 ctype = TYPE_METHOD_BASETYPE (type);
9346 if (ctype != NULL_TREE)
9347 grok_method_quals (ctype, decl, quals);
9350 if (RIDBIT_SETP (RID_SIGNED, specbits)
9351 || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
9352 C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
9354 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9356 error ("non-object member `%s' cannot be declared mutable", name);
9362 /* Detect the case of an array type of unspecified size
9363 which came, as such, direct from a typedef name.
9364 We must copy the type, so that each identifier gets
9365 a distinct type, so that each identifier's size can be
9366 controlled separately by its own initializer. */
9368 if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
9369 && TYPE_DOMAIN (type) == NULL_TREE)
9371 type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
9374 /* If this is a type name (such as, in a cast or sizeof),
9375 compute the type and return it now. */
9377 if (decl_context == TYPENAME)
9379 /* Note that the grammar rejects storage classes
9380 in typenames, fields or parameters. */
9381 if (constp || volatilep)
9382 if (IS_SIGNATURE (type))
9383 error ("`const' or `volatile' specified with signature type");
9385 type = cp_build_type_variant (type, constp, volatilep);
9387 /* Special case: "friend class foo" looks like a TYPENAME context. */
9392 cp_error ("`volatile' specified for friend class declaration");
9397 cp_error ("`inline' specified for friend class declaration");
9401 /* Only try to do this stuff if we didn't already give up. */
9402 if (type != integer_type_node)
9404 /* A friendly class? */
9405 if (current_class_type)
9406 make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
9408 error ("trying to make class `%s' a friend of global scope",
9409 TYPE_NAME_STRING (type));
9410 type = void_type_node;
9415 #if 0 /* not yet, should get fixed properly later */
9416 tree dummy = make_type_decl (declarator, type);
9418 tree dummy = build_decl (TYPE_DECL, declarator, type);
9420 if (ctype == NULL_TREE)
9422 my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
9423 ctype = TYPE_METHOD_BASETYPE (type);
9425 grok_method_quals (ctype, dummy, quals);
9426 type = TREE_TYPE (dummy);
9431 else if (declarator == NULL_TREE && decl_context != PARM
9432 && decl_context != CATCHPARM
9433 && TREE_CODE (type) != UNION_TYPE
9436 cp_error ("abstract declarator `%T' used as declaration", type);
9437 declarator = make_anon_name ();
9440 /* `void' at top level (not within pointer)
9441 is allowed only in typedefs or type names.
9442 We don't complain about parms either, but that is because
9443 a better error message can be made later. */
9445 if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
9448 error ("unnamed variable or field declared void");
9449 else if (TREE_CODE (declarator) == IDENTIFIER_NODE)
9451 if (IDENTIFIER_OPNAME_P (declarator))
9452 #if 0 /* How could this happen? */
9453 error ("operator `%s' declared void",
9454 operator_name_string (declarator));
9456 my_friendly_abort (356);
9459 error ("variable or field `%s' declared void", name);
9462 error ("variable or field declared void");
9463 type = integer_type_node;
9466 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
9467 or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
9472 if (decl_context == PARM)
9475 error ("cannot use `::' in parameter declaration");
9477 /* A parameter declared as an array of T is really a pointer to T.
9478 One declared as a function is really a pointer to a function.
9479 One declared as a member is really a pointer to member. */
9481 if (TREE_CODE (type) == ARRAY_TYPE)
9483 /* Transfer const-ness of array into that of type pointed to. */
9484 type = build_pointer_type
9485 (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
9486 volatilep = constp = 0;
9488 else if (TREE_CODE (type) == FUNCTION_TYPE)
9489 type = build_pointer_type (type);
9490 else if (TREE_CODE (type) == OFFSET_TYPE)
9491 type = build_pointer_type (type);
9492 else if (type == void_type_node && declarator)
9494 error ("declaration of `%s' as void", name);
9498 decl = build_decl (PARM_DECL, declarator, type);
9500 bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
9501 inlinep, friendp, raises != NULL_TREE);
9502 if (current_class_type
9503 && IS_SIGNATURE (current_class_type))
9506 error ("parameter of signature member function declared `inline'");
9507 if (RIDBIT_SETP (RID_AUTO, specbits))
9508 error ("parameter of signature member function declared `auto'");
9509 if (RIDBIT_SETP (RID_REGISTER, specbits))
9510 error ("parameter of signature member function declared `register'");
9513 /* Compute the type actually passed in the parmlist,
9514 for the case where there is no prototype.
9515 (For example, shorts and chars are passed as ints.)
9516 When there is a prototype, this is overridden later. */
9518 DECL_ARG_TYPE (decl) = type_promotes_to (type);
9520 else if (decl_context == FIELD)
9522 if (type == error_mark_node)
9524 /* Happens when declaring arrays of sizes which
9525 are error_mark_node, for example. */
9528 else if (TREE_CODE (type) == FUNCTION_TYPE)
9532 /* We catch the others as conflicts with the builtin
9534 if (friendp && declarator == ridpointers[(int) RID_SIGNED])
9536 cp_error ("function `%D' cannot be declared friend",
9543 if (ctype == NULL_TREE)
9544 ctype = current_class_type;
9546 if (ctype == NULL_TREE)
9548 cp_error ("can't make `%D' into a method -- not in a class",
9550 return void_type_node;
9553 /* ``A union may [ ... ] not [ have ] virtual functions.''
9555 if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
9557 cp_error ("function `%D' declared virtual inside a union",
9559 return void_type_node;
9562 if (declarator == ansi_opname[(int) NEW_EXPR]
9563 || declarator == ansi_opname[(int) VEC_NEW_EXPR]
9564 || declarator == ansi_opname[(int) DELETE_EXPR]
9565 || declarator == ansi_opname[(int) VEC_DELETE_EXPR])
9569 cp_error ("`%D' cannot be declared virtual, since it is always static",
9574 else if (staticp < 2)
9575 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
9576 TREE_TYPE (type), TYPE_ARG_TYPES (type));
9579 /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
9580 publicp = (! friendp
9581 || RIDBIT_SETP (RID_EXTERN, specbits)
9582 || ! (funcdef_flag < 0 || inlinep));
9583 decl = grokfndecl (ctype, type, declarator,
9584 virtualp, flags, quals, raises, attrlist,
9585 friendp ? -1 : 0, publicp, inlinep);
9586 if (decl == NULL_TREE)
9588 decl = build_decl_attribute_variant (decl, decl_machine_attr);
9591 DECL_NONCONVERTING_P (decl) = 1;
9593 else if (TREE_CODE (type) == METHOD_TYPE)
9595 /* We only get here for friend declarations of
9596 members of other classes. */
9597 /* All method decls are public, so tell grokfndecl to set
9598 TREE_PUBLIC, also. */
9599 decl = grokfndecl (ctype, type, declarator,
9600 virtualp, flags, quals, raises, attrlist,
9601 friendp ? -1 : 0, 1, 0);
9602 if (decl == NULL_TREE)
9605 else if (TYPE_SIZE (type) == NULL_TREE && !staticp
9606 && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
9609 cp_error ("field `%D' has incomplete type", declarator);
9611 cp_error ("name `%T' has incomplete type", type);
9613 /* If we're instantiating a template, tell them which
9614 instantiation made the field's type be incomplete. */
9615 if (current_class_type
9616 && TYPE_NAME (current_class_type)
9617 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type)))
9618 && declspecs && TREE_VALUE (declspecs)
9619 && TREE_TYPE (TREE_VALUE (declspecs)) == type)
9620 cp_error (" in instantiation of template `%T'",
9621 current_class_type);
9623 type = error_mark_node;
9630 error ("`%s' is neither function nor method; cannot be declared friend",
9631 IDENTIFIER_POINTER (declarator));
9639 /* Friends are treated specially. */
9640 if (ctype == current_class_type)
9641 warning ("member functions are implicitly friends of their class");
9645 if (decl && DECL_NAME (decl))
9646 t = do_friend (ctype, declarator, decl,
9647 last_function_parms, flags, quals);
9648 if (t && funcdef_flag)
9651 return void_type_node;
9655 /* Structure field. It may not be a function, except for C++ */
9657 if (decl == NULL_TREE)
9661 /* Motion 10 at San Diego: If a static const integral data
9662 member is initialized with an integral constant
9663 expression, the initializer may appear either in the
9664 declaration (within the class), or in the definition,
9665 but not both. If it appears in the class, the member is
9666 a member constant. The file-scope definition is always
9673 cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
9676 else if (! INTEGRAL_TYPE_P (type))
9677 cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type);
9681 /* Note that initialization of const members is prohibited
9682 by the draft ANSI standard, though it appears to be in
9683 common practice. 12.6.2: The argument list is used to
9684 initialize the named nonstatic member.... This (or an
9685 initializer list) is the only way to initialize
9686 nonstatic const and reference members. */
9687 else if (pedantic || ! constp)
9688 cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
9689 constp ? "const member" : "member", declarator);
9692 if (staticp || (constp && initialized))
9694 /* ANSI C++ Apr '95 wp 9.2 */
9695 if (staticp && declarator == current_class_name)
9696 cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class",
9699 /* C++ allows static class members.
9700 All other work for this is done by grokfield.
9701 This VAR_DECL is built by build_lang_field_decl.
9702 All other VAR_DECLs are built by build_decl. */
9703 decl = build_lang_field_decl (VAR_DECL, declarator, type);
9704 TREE_STATIC (decl) = 1;
9705 /* In class context, 'static' means public access. */
9706 TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp;
9710 decl = build_lang_field_decl (FIELD_DECL, declarator, type);
9711 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9713 DECL_MUTABLE_P (decl) = 1;
9714 RIDBIT_RESET (RID_MUTABLE, specbits);
9718 bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
9719 inlinep, friendp, raises != NULL_TREE);
9722 else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
9724 tree original_name = declarator;
9730 if (RIDBIT_SETP (RID_AUTO, specbits))
9731 error ("storage class `auto' invalid for function `%s'", name);
9732 else if (RIDBIT_SETP (RID_REGISTER, specbits))
9733 error ("storage class `register' invalid for function `%s'", name);
9735 /* Function declaration not at top level.
9736 Storage classes other than `extern' are not allowed
9737 and `extern' makes no difference. */
9738 if (! toplevel_bindings_p ()
9739 && ! processing_template_decl
9740 && (RIDBIT_SETP (RID_STATIC, specbits)
9741 || RIDBIT_SETP (RID_INLINE, specbits))
9744 if (RIDBIT_SETP (RID_STATIC, specbits))
9745 pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name);
9747 pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name);
9750 if (ctype == NULL_TREE)
9754 error ("virtual non-class function `%s'", name);
9758 if (current_lang_name == lang_name_cplusplus
9759 && ! (IDENTIFIER_LENGTH (original_name) == 4
9760 && IDENTIFIER_POINTER (original_name)[0] == 'm'
9761 && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
9762 && ! (IDENTIFIER_LENGTH (original_name) > 10
9763 && IDENTIFIER_POINTER (original_name)[0] == '_'
9764 && IDENTIFIER_POINTER (original_name)[1] == '_'
9765 && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
9766 /* Plain overloading: will not be grok'd by grokclassfn. */
9767 declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
9769 else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
9770 type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
9771 TREE_TYPE (type), TYPE_ARG_TYPES (type));
9773 /* Record presence of `static'. In C++, `inline' implies `static'. */
9774 publicp = (ctype != NULL_TREE
9775 || RIDBIT_SETP (RID_EXTERN, specbits)
9776 || (!RIDBIT_SETP (RID_STATIC, specbits)
9777 && !RIDBIT_SETP (RID_INLINE, specbits)));
9779 decl = grokfndecl (ctype, type, original_name,
9780 virtualp, flags, quals, raises, attrlist,
9781 processing_template_decl ? 0 : friendp ? 2 : 1,
9783 if (decl == NULL_TREE)
9786 if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
9787 DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator);
9791 int illegal_static = 0;
9793 /* Don't allow a static member function in a class, and forbid
9794 declaring main to be static. */
9795 if (TREE_CODE (type) == METHOD_TYPE)
9797 cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl);
9800 else if (current_function_decl)
9802 /* FIXME need arm citation */
9803 error ("cannot declare static function inside another function");
9810 RIDBIT_RESET (RID_STATIC, specbits);
9816 /* It's a variable. */
9818 if (decl_context == CATCHPARM)
9823 error ("cannot use `::' in parameter declaration");
9826 /* A parameter declared as an array of T is really a pointer to T.
9827 One declared as a function is really a pointer to a function.
9828 One declared as a member is really a pointer to member. */
9830 if (TREE_CODE (type) == ARRAY_TYPE)
9832 /* Transfer const-ness of array into that of type pointed to. */
9833 type = build_pointer_type
9834 (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
9835 volatilep = constp = 0;
9837 else if (TREE_CODE (type) == FUNCTION_TYPE)
9838 type = build_pointer_type (type);
9839 else if (TREE_CODE (type) == OFFSET_TYPE)
9840 type = build_pointer_type (type);
9843 /* An uninitialized decl with `extern' is a reference. */
9844 decl = grokvardecl (type, declarator, specbits, initialized, constp);
9845 bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
9846 inlinep, friendp, raises != NULL_TREE);
9850 DECL_CONTEXT (decl) = ctype;
9853 cp_pedwarn ("static member `%D' re-declared as static", decl);
9855 RIDBIT_RESET (RID_STATIC, specbits);
9857 if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl))
9859 cp_error ("static member `%D' declared `register'", decl);
9860 RIDBIT_RESET (RID_REGISTER, specbits);
9862 if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic)
9864 cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage",
9866 RIDBIT_RESET (RID_EXTERN, specbits);
9871 if (RIDBIT_SETP (RID_MUTABLE, specbits))
9873 error ("`%s' cannot be declared mutable", name);
9876 /* Record `register' declaration for warnings on &
9877 and in case doing stupid register allocation. */
9879 if (RIDBIT_SETP (RID_REGISTER, specbits))
9880 DECL_REGISTER (decl) = 1;
9882 if (RIDBIT_SETP (RID_EXTERN, specbits))
9883 DECL_THIS_EXTERN (decl) = 1;
9885 if (RIDBIT_SETP (RID_STATIC, specbits))
9886 DECL_THIS_STATIC (decl) = 1;
9888 /* Record constancy and volatility. */
9891 TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
9894 TREE_SIDE_EFFECTS (decl) = 1;
9895 TREE_THIS_VOLATILE (decl) = 1;
9902 /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
9903 An empty exprlist is a parmlist. An exprlist which
9904 contains only identifiers at the global level
9905 is a parmlist. Otherwise, it is an exprlist. */
9907 parmlist_is_exprlist (exprs)
9910 if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
9913 if (toplevel_bindings_p ())
9915 /* At the global level, if these are all identifiers,
9916 then it is a parmlist. */
9919 if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
9921 exprs = TREE_CHAIN (exprs);
9928 /* Subroutine of `grokparms'. In a fcn definition, arg types must
9931 C++: also subroutine of `start_function'. */
9933 require_complete_types_for_parms (parms)
9938 tree type = TREE_TYPE (parms);
9939 if (TYPE_SIZE (type) == NULL_TREE)
9941 if (DECL_NAME (parms))
9942 error ("parameter `%s' has incomplete type",
9943 IDENTIFIER_POINTER (DECL_NAME (parms)));
9945 error ("parameter has incomplete type");
9946 TREE_TYPE (parms) = error_mark_node;
9949 /* If the arg types are incomplete in a declaration,
9950 they must include undefined tags.
9951 These tags can never be defined in the scope of the declaration,
9952 so the types can never be completed,
9953 and no call can be compiled successfully. */
9954 /* This is not the right behavior for C++, but not having
9955 it is also probably wrong. */
9958 /* Now warn if is a pointer to an incomplete type. */
9959 while (TREE_CODE (type) == POINTER_TYPE
9960 || TREE_CODE (type) == REFERENCE_TYPE)
9961 type = TREE_TYPE (type);
9962 type = TYPE_MAIN_VARIANT (type);
9963 if (TYPE_SIZE (type) == NULL_TREE)
9965 if (DECL_NAME (parm) != NULL_TREE)
9966 warning ("parameter `%s' points to incomplete type",
9967 IDENTIFIER_POINTER (DECL_NAME (parm)));
9969 warning ("parameter points to incomplete type");
9973 parms = TREE_CHAIN (parms);
9977 /* Decode the list of parameter types for a function type.
9978 Given the list of things declared inside the parens,
9979 return a list of types.
9981 The list we receive can have three kinds of elements:
9982 an IDENTIFIER_NODE for names given without types,
9983 a TREE_LIST node for arguments given as typespecs or names with typespecs,
9984 or void_type_node, to mark the end of an argument list
9985 when additional arguments are not permitted (... was not used).
9987 FUNCDEF_FLAG is nonzero for a function definition, 0 for
9988 a mere declaration. A nonempty identifier-list gets an error message
9989 when FUNCDEF_FLAG is zero.
9990 If FUNCDEF_FLAG is 1, then parameter types must be complete.
9991 If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
9993 If all elements of the input list contain types,
9994 we return a list of the types.
9995 If all elements contain no type (except perhaps a void_type_node
9996 at the end), we return a null list.
9997 If some have types and some do not, it is an error, and we
10000 Also set last_function_parms to either
10001 a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
10002 A list of names is converted to a chain of PARM_DECLs
10003 by store_parm_decls so that ultimately it is always a chain of decls.
10005 Note that in C++, parameters can take default values. These default
10006 values are in the TREE_PURPOSE field of the TREE_LIST. It is
10007 an error to specify default values which are followed by parameters
10008 that have no default values, or an ELLIPSES. For simplicities sake,
10009 only parameters which are specified with their types can take on
10013 grokparms (first_parm, funcdef_flag)
10017 tree result = NULL_TREE;
10018 tree decls = NULL_TREE;
10020 if (first_parm != NULL_TREE
10021 && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
10023 if (! funcdef_flag)
10024 pedwarn ("parameter names (without types) in function declaration");
10025 last_function_parms = first_parm;
10028 else if (first_parm != NULL_TREE
10029 && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
10030 && TREE_VALUE (first_parm) != void_type_node)
10031 my_friendly_abort (145);
10034 /* Types were specified. This is a list of declarators
10035 each represented as a TREE_LIST node. */
10036 register tree parm, chain;
10037 int any_init = 0, any_error = 0, saw_void = 0;
10039 if (first_parm != NULL_TREE)
10041 tree last_result = NULL_TREE;
10042 tree last_decl = NULL_TREE;
10044 for (parm = first_parm; parm != NULL_TREE; parm = chain)
10046 tree type, list_node = parm;
10047 register tree decl = TREE_VALUE (parm);
10048 tree init = TREE_PURPOSE (parm);
10050 chain = TREE_CHAIN (parm);
10051 /* @@ weak defense against parse errors. */
10052 if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
10054 /* Give various messages as the need arises. */
10055 if (TREE_CODE (decl) == STRING_CST)
10056 error ("invalid string constant `%s'",
10057 TREE_STRING_POINTER (decl));
10058 else if (TREE_CODE (decl) == INTEGER_CST)
10059 error ("invalid integer constant in parameter list, did you forget to give parameter name?");
10063 if (decl != void_type_node)
10065 /* @@ May need to fetch out a `raises' here. */
10066 decl = grokdeclarator (TREE_VALUE (decl),
10067 TREE_PURPOSE (decl),
10068 PARM, init != NULL_TREE,
10069 NULL_TREE, NULL_TREE);
10072 type = TREE_TYPE (decl);
10073 if (TYPE_MAIN_VARIANT (type) == void_type_node)
10074 decl = void_type_node;
10075 else if (TREE_CODE (type) == METHOD_TYPE)
10077 if (DECL_NAME (decl))
10078 /* Cannot use `error_with_decl' here because
10079 we don't have DECL_CONTEXT set up yet. */
10080 error ("parameter `%s' invalidly declared method type",
10081 IDENTIFIER_POINTER (DECL_NAME (decl)));
10083 error ("parameter invalidly declared method type");
10084 type = build_pointer_type (type);
10085 TREE_TYPE (decl) = type;
10087 else if (TREE_CODE (type) == OFFSET_TYPE)
10089 if (DECL_NAME (decl))
10090 error ("parameter `%s' invalidly declared offset type",
10091 IDENTIFIER_POINTER (DECL_NAME (decl)));
10093 error ("parameter invalidly declared offset type");
10094 type = build_pointer_type (type);
10095 TREE_TYPE (decl) = type;
10097 else if (TREE_CODE (type) == RECORD_TYPE
10098 && TYPE_LANG_SPECIFIC (type)
10099 && CLASSTYPE_ABSTRACT_VIRTUALS (type))
10101 abstract_virtuals_error (decl, type);
10102 any_error = 1; /* seems like a good idea */
10104 else if (TREE_CODE (type) == RECORD_TYPE
10105 && TYPE_LANG_SPECIFIC (type)
10106 && IS_SIGNATURE (type))
10108 signature_error (decl, type);
10109 any_error = 1; /* seems like a good idea */
10113 if (decl == void_type_node)
10115 if (result == NULL_TREE)
10117 result = void_list_node;
10118 last_result = result;
10122 TREE_CHAIN (last_result) = void_list_node;
10123 last_result = void_list_node;
10127 && (chain != void_list_node || TREE_CHAIN (chain)))
10128 error ("`void' in parameter list must be entire list");
10132 /* Since there is a prototype, args are passed in their own types. */
10133 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
10134 #ifdef PROMOTE_PROTOTYPES
10135 if ((TREE_CODE (type) == INTEGER_TYPE
10136 || TREE_CODE (type) == ENUMERAL_TYPE)
10137 && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
10138 DECL_ARG_TYPE (decl) = integer_type_node;
10145 if (TREE_CODE (init) == SAVE_EXPR)
10146 PARM_DECL_EXPR (init) = 1;
10147 else if (TREE_CODE (init) == VAR_DECL
10148 || TREE_CODE (init) == PARM_DECL)
10150 if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
10152 /* ``Local variables may not be used in default
10153 argument expressions.'' dpANSI C++ 8.2.6 */
10154 /* If extern int i; within a function is not
10155 considered a local variable, then this code is
10157 cp_error ("local variable `%D' may not be used as a default argument", init);
10160 else if (TREE_READONLY_DECL_P (init))
10161 init = decl_constant_value (init);
10164 init = require_instantiated_type (type, init, integer_zero_node);
10166 #if 0 /* This is too early to check; trailing parms might be merged in by
10167 duplicate_decls. */
10170 error ("all trailing parameters must have default arguments");
10178 if (decls == NULL_TREE)
10185 TREE_CHAIN (last_decl) = decl;
10188 if (TREE_PERMANENT (list_node))
10190 TREE_PURPOSE (list_node) = init;
10191 TREE_VALUE (list_node) = type;
10192 TREE_CHAIN (list_node) = NULL_TREE;
10195 list_node = saveable_tree_cons (init, type, NULL_TREE);
10196 if (result == NULL_TREE)
10198 result = list_node;
10199 last_result = result;
10203 TREE_CHAIN (last_result) = list_node;
10204 last_result = list_node;
10208 TREE_CHAIN (last_result) = NULL_TREE;
10209 /* If there are no parameters, and the function does not end
10210 with `...', then last_decl will be NULL_TREE. */
10211 if (last_decl != NULL_TREE)
10212 TREE_CHAIN (last_decl) = NULL_TREE;
10216 last_function_parms = decls;
10218 /* In a fcn definition, arg types must be complete. */
10219 if (funcdef_flag > 0)
10220 require_complete_types_for_parms (last_function_parms);
10225 /* These memoizing functions keep track of special properties which
10226 a class may have. `grok_ctor_properties' notices whether a class
10227 has a constructor of the form X(X&), and also complains
10228 if the class has a constructor of the form X(X).
10229 `grok_op_properties' takes notice of the various forms of
10230 operator= which are defined, as well as what sorts of type conversion
10231 may apply. Both functions take a FUNCTION_DECL as an argument. */
10233 grok_ctor_properties (ctype, decl)
10236 tree parmtypes = FUNCTION_ARG_CHAIN (decl);
10237 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
10239 /* When a type has virtual baseclasses, a magical first int argument is
10240 added to any ctor so we can tell if the class has been initialized
10241 yet. This could screw things up in this function, so we deliberately
10242 ignore the leading int if we're in that situation. */
10244 && TREE_VALUE (parmtypes) == integer_type_node
10245 && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
10247 parmtypes = TREE_CHAIN (parmtypes);
10248 parmtype = TREE_VALUE (parmtypes);
10251 if (TREE_CODE (parmtype) == REFERENCE_TYPE
10252 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
10254 if (TREE_CHAIN (parmtypes) == NULL_TREE
10255 || TREE_CHAIN (parmtypes) == void_list_node
10256 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
10258 TYPE_HAS_INIT_REF (ctype) = 1;
10259 if (TYPE_READONLY (TREE_TYPE (parmtype)))
10260 TYPE_HAS_CONST_INIT_REF (ctype) = 1;
10263 TYPE_GETS_INIT_AGGR (ctype) = 1;
10265 else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
10267 if (TREE_CHAIN (parmtypes) != NULL_TREE
10268 && TREE_CHAIN (parmtypes) == void_list_node)
10270 cp_error ("invalid constructor; you probably meant `%T (%T&)'",
10272 SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
10277 TYPE_GETS_INIT_AGGR (ctype) = 1;
10279 else if (TREE_CODE (parmtype) == VOID_TYPE
10280 || TREE_PURPOSE (parmtypes) != NULL_TREE)
10281 TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
10286 /* An operator with this name can be either unary or binary. */
10291 return (name == ansi_opname [(int) INDIRECT_REF]
10292 || name == ansi_opname [(int) ADDR_EXPR]
10293 || name == ansi_opname [(int) NEGATE_EXPR]
10294 || name == ansi_opname[(int) POSTINCREMENT_EXPR]
10295 || name == ansi_opname[(int) POSTDECREMENT_EXPR]
10296 || name == ansi_opname [(int) CONVERT_EXPR]);
10299 /* An operator with this name can only be unary. */
10304 return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
10305 || name == ansi_opname [(int) BIT_NOT_EXPR]
10306 || name == ansi_opname [(int) COMPONENT_REF]
10307 || OPERATOR_TYPENAME_P (name));
10310 /* Do a little sanity-checking on how they declared their operator. */
10312 grok_op_properties (decl, virtualp, friendp)
10314 int virtualp, friendp;
10316 tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
10317 int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
10318 tree name = DECL_NAME (decl);
10320 if (current_class_type == NULL_TREE)
10325 if (name == ansi_opname[(int) MODIFY_EXPR])
10326 TYPE_HAS_ASSIGNMENT (current_class_type) = 1;
10327 else if (name == ansi_opname[(int) CALL_EXPR])
10328 TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1;
10329 else if (name == ansi_opname[(int) ARRAY_REF])
10330 TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1;
10331 else if (name == ansi_opname[(int) COMPONENT_REF]
10332 || name == ansi_opname[(int) MEMBER_REF])
10333 TYPE_OVERLOADS_ARROW (current_class_type) = 1;
10334 else if (name == ansi_opname[(int) NEW_EXPR])
10335 TYPE_GETS_NEW (current_class_type) |= 1;
10336 else if (name == ansi_opname[(int) DELETE_EXPR])
10337 TYPE_GETS_DELETE (current_class_type) |= 1;
10338 else if (name == ansi_opname[(int) VEC_NEW_EXPR])
10339 TYPE_GETS_NEW (current_class_type) |= 2;
10340 else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
10341 TYPE_GETS_DELETE (current_class_type) |= 2;
10344 if (name == ansi_opname[(int) NEW_EXPR]
10345 || name == ansi_opname[(int) VEC_NEW_EXPR])
10347 /* When the compiler encounters the definition of A::operator new, it
10348 doesn't look at the class declaration to find out if it's static. */
10350 revert_static_member_fn (&decl, NULL, NULL);
10352 /* Take care of function decl if we had syntax errors. */
10353 if (argtypes == NULL_TREE)
10355 build_function_type (ptr_type_node,
10356 hash_tree_chain (integer_type_node,
10359 TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
10361 else if (name == ansi_opname[(int) DELETE_EXPR]
10362 || name == ansi_opname[(int) VEC_DELETE_EXPR])
10365 revert_static_member_fn (&decl, NULL, NULL);
10367 if (argtypes == NULL_TREE)
10369 build_function_type (void_type_node,
10370 hash_tree_chain (ptr_type_node,
10374 TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
10376 if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR]
10377 && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))
10378 != void_list_node))
10379 TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1;
10384 /* An operator function must either be a non-static member function
10385 or have at least one parameter of a class, a reference to a class,
10386 an enumeration, or a reference to an enumeration. 13.4.0.6 */
10387 if (! methodp || DECL_STATIC_FUNCTION_P (decl))
10389 if (OPERATOR_TYPENAME_P (name)
10390 || name == ansi_opname[(int) CALL_EXPR]
10391 || name == ansi_opname[(int) MODIFY_EXPR]
10392 || name == ansi_opname[(int) COMPONENT_REF]
10393 || name == ansi_opname[(int) ARRAY_REF])
10394 cp_error ("`%D' must be a nonstatic member function", decl);
10399 if (DECL_STATIC_FUNCTION_P (decl))
10400 cp_error ("`%D' must be either a non-static member function or a non-member function", decl);
10403 for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
10405 tree arg = TREE_VALUE (p);
10406 if (TREE_CODE (arg) == REFERENCE_TYPE)
10407 arg = TREE_TYPE (arg);
10409 /* This lets bad template code slip through. */
10410 if (IS_AGGR_TYPE (arg)
10411 || TREE_CODE (arg) == ENUMERAL_TYPE
10412 || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
10416 ("`%D' must have an argument of class or enumerated type",
10423 if (name == ansi_opname[(int) CALL_EXPR]
10424 || name == ansi_opname[(int) METHOD_CALL_EXPR])
10425 return; /* no restrictions on args */
10427 if (IDENTIFIER_TYPENAME_P (name))
10429 tree t = TREE_TYPE (name);
10430 if (TREE_CODE (t) == VOID_TYPE)
10431 pedwarn ("void is not a valid type conversion operator");
10432 else if (! friendp)
10434 int ref = (TREE_CODE (t) == REFERENCE_TYPE);
10437 t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
10439 if (t == current_class_type)
10440 what = "the same type";
10441 else if (IS_AGGR_TYPE (t)
10442 && DERIVED_FROM_P (t, current_class_type))
10443 what = "a base class";
10446 warning ("conversion to %s%s will never use a type conversion operator",
10447 ref ? "a reference to " : "", what);
10451 if (name == ansi_opname[(int) MODIFY_EXPR])
10455 if (list_length (argtypes) != 3 && methodp)
10457 cp_error ("`%D' must take exactly one argument", decl);
10460 parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
10462 if (copy_assignment_arg_p (parmtype, virtualp)
10465 TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
10466 if (TREE_CODE (parmtype) != REFERENCE_TYPE
10467 || TYPE_READONLY (TREE_TYPE (parmtype)))
10468 TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
10469 #if 0 /* Too soon; done in grok_function_init */
10470 if (DECL_ABSTRACT_VIRTUAL_P (decl))
10471 TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
10475 else if (name == ansi_opname[(int) COND_EXPR])
10478 pedwarn ("ANSI C++ prohibits overloading operator ?:");
10479 if (list_length (argtypes) != 4)
10480 cp_error ("`%D' must take exactly three arguments", decl);
10482 else if (ambi_op_p (name))
10484 if (list_length (argtypes) == 2)
10486 else if (list_length (argtypes) == 3)
10488 if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
10489 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
10490 && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
10493 cp_error ("postfix `%D' must take `int' as its argument",
10497 ("postfix `%D' must take `int' as its second argument",
10504 cp_error ("`%D' must take either zero or one argument", decl);
10506 cp_error ("`%D' must take either one or two arguments", decl);
10509 else if (unary_op_p (name))
10511 if (list_length (argtypes) != 2)
10514 cp_error ("`%D' must take `void'", decl);
10516 cp_error ("`%D' must take exactly one argument", decl);
10519 else /* if (binary_op_p (name)) */
10521 if (list_length (argtypes) != 3)
10524 cp_error ("`%D' must take exactly one argument", decl);
10526 cp_error ("`%D' must take exactly two arguments", decl);
10532 for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
10533 if (TREE_PURPOSE (argtypes))
10535 TREE_PURPOSE (argtypes) = NULL_TREE;
10536 if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
10537 || name == ansi_opname[(int) POSTDECREMENT_EXPR])
10540 cp_pedwarn ("`%D' cannot have default arguments", decl);
10543 cp_error ("`%D' cannot have default arguments", decl);
10548 /* Get the struct, enum or union (CODE says which) with tag NAME.
10549 Define the tag as a forward-reference if it is not defined.
10551 C++: If a class derivation is given, process it here, and report
10552 an error if multiple derivation declarations are not identical.
10554 If this is a definition, come in through xref_tag and only look in
10555 the current frame for the name (since C++ allows new names in any
10559 xref_tag (code_type_node, name, binfo, globalize)
10560 tree code_type_node;
10564 enum tag_types tag_code;
10565 enum tree_code code;
10568 register tree ref, t;
10569 struct binding_level *b = inner_binding_level;
10571 tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
10576 case signature_type:
10577 code = RECORD_TYPE;
10583 code = ENUMERAL_TYPE;
10586 my_friendly_abort (18);
10589 /* If a cross reference is requested, look up the type
10590 already defined for this tag and return it. */
10591 if (TREE_CODE_CLASS (TREE_CODE (name)) == 't')
10594 name = TYPE_NESTED_NAME (t);
10597 t = IDENTIFIER_TYPE_VALUE (name);
10598 if (t && TREE_CODE (t) != code)
10603 /* If we know we are defining this tag, only look it up in this scope
10604 * and don't try to find it as a type. */
10605 if (t && TYPE_CONTEXT(t) && TREE_MANGLED (name))
10608 ref = lookup_tag (code, name, b, 1);
10615 ref = lookup_tag (code, name, b, 0);
10619 /* Try finding it as a type declaration. If that wins, use it. */
10620 ref = lookup_name (name, 1);
10621 if (ref && TREE_CODE (ref) == TYPE_DECL
10622 && TREE_CODE (TREE_TYPE (ref)) == code)
10623 ref = TREE_TYPE (ref);
10629 push_obstacks_nochange ();
10633 /* If no such tag is yet defined, create a forward-reference node
10634 and record it as the "definition".
10635 When a real declaration of this type is found,
10636 the forward-reference will be altered into a real type. */
10638 /* In C++, since these migrate into the global scope, we must
10639 build them on the permanent obstack. */
10641 temp = allocation_temporary_p ();
10643 end_temporary_allocation ();
10645 if (code == ENUMERAL_TYPE)
10647 ref = make_node (ENUMERAL_TYPE);
10649 /* Give the type a default layout like unsigned int
10650 to avoid crashing if it does not get defined. */
10651 TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
10652 TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
10653 TREE_UNSIGNED (ref) = 1;
10654 TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
10655 TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
10656 TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
10658 /* Enable us to recognize when a type is created in class context.
10659 To do nested classes correctly, this should probably be cleared
10660 out when we leave this classes scope. Currently this in only
10661 done in `start_enum'. */
10663 pushtag (name, ref, globalize);
10665 cadillac_start_enum (ref);
10669 struct binding_level *old_b = class_binding_level;
10671 ref = make_lang_type (code);
10673 if (tag_code == signature_type)
10675 SET_SIGNATURE (ref);
10676 /* Since a signature type will be turned into the type
10677 of signature tables, it's not only an interface. */
10678 CLASSTYPE_INTERFACE_ONLY (ref) = 0;
10679 SET_CLASSTYPE_INTERFACE_KNOWN (ref);
10680 /* A signature doesn't have a vtable. */
10681 CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
10684 #ifdef NONNESTED_CLASSES
10685 /* Class types don't nest the way enums do. */
10686 class_binding_level = (struct binding_level *)0;
10688 pushtag (name, ref, globalize);
10689 class_binding_level = old_b;
10692 cadillac_start_struct (ref);
10697 /* If it no longer looks like a nested type, make sure it's
10698 in global scope. */
10699 if (b == global_binding_level && !class_binding_level
10700 && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
10701 IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
10707 tree tt2 = TYPE_BINFO_BASETYPES (ref);
10709 if (TYPE_BINFO_BASETYPES (ref))
10710 for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
10711 if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
10713 cp_error ("redeclaration of derivation chain of type `%#T'",
10718 if (tt1 == NULL_TREE)
10719 /* The user told us something we already knew. */
10722 /* In C++, since these migrate into the global scope, we must
10723 build them on the permanent obstack. */
10724 end_temporary_allocation ();
10730 xref_basetypes (code_type_node, name, ref, binfo);
10734 /* Until the type is defined, tentatively accept whatever
10735 structure tag the user hands us. */
10736 if (TYPE_SIZE (ref) == NULL_TREE
10737 && ref != current_class_type
10738 /* Have to check this, in case we have contradictory tag info. */
10739 && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
10741 if (tag_code == class_type)
10742 CLASSTYPE_DECLARED_CLASS (ref) = 1;
10743 else if (tag_code == record_type || tag_code == signature_type)
10744 CLASSTYPE_DECLARED_CLASS (ref) = 0;
10753 xref_basetypes (code_type_node, name, ref, binfo)
10754 tree code_type_node;
10758 /* In the declaration `A : X, Y, ... Z' we mark all the types
10759 (A, X, Y, ..., Z) so we can check for duplicates. */
10762 enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
10764 if (tag_code == union_type)
10766 cp_error ("derived union `%T' invalid", ref);
10770 len = list_length (binfo);
10771 push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref));
10773 SET_CLASSTYPE_MARKED (ref);
10774 BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
10776 for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
10778 /* The base of a derived struct is public by default. */
10780 = (TREE_PURPOSE (binfo) == access_public_node
10781 || TREE_PURPOSE (binfo) == access_public_virtual_node
10782 || (tag_code != class_type
10783 && (TREE_PURPOSE (binfo) == access_default_node
10784 || TREE_PURPOSE (binfo) == access_default_virtual_node)));
10785 int via_protected = TREE_PURPOSE (binfo) == access_protected_node;
10787 = (TREE_PURPOSE (binfo) == access_private_virtual_node
10788 || TREE_PURPOSE (binfo) == access_public_virtual_node
10789 || TREE_PURPOSE (binfo) == access_default_virtual_node);
10790 tree basetype = TREE_VALUE (binfo);
10793 GNU_xref_hier (IDENTIFIER_POINTER (name),
10794 IDENTIFIER_POINTER (TREE_VALUE (binfo)),
10795 via_public, via_virtual, 0);
10797 if (basetype && TREE_CODE (basetype) == TYPE_DECL)
10798 basetype = TREE_TYPE (basetype);
10799 if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
10801 cp_error ("base type `%T' fails to be a struct or class type",
10802 TREE_VALUE (binfo));
10806 /* This code replaces similar code in layout_basetypes. */
10807 else if (TYPE_INCOMPLETE (basetype))
10809 cp_error ("base class `%T' has incomplete type", basetype);
10815 if (CLASSTYPE_MARKED (basetype))
10817 if (basetype == ref)
10818 cp_error ("recursive type `%T' undefined", basetype);
10820 cp_error ("duplicate base type `%T' invalid", basetype);
10824 /* Note that the BINFO records which describe individual
10825 inheritances are *not* shared in the lattice! They
10826 cannot be shared because a given baseclass may be
10827 inherited with different `accessibility' by different
10828 derived classes. (Each BINFO record describing an
10829 individual inheritance contains flags which say what
10830 the `accessibility' of that particular inheritance is.) */
10832 base_binfo = make_binfo (integer_zero_node, basetype,
10833 TYPE_BINFO_VTABLE (basetype),
10834 TYPE_BINFO_VIRTUALS (basetype), NULL_TREE);
10836 TREE_VEC_ELT (binfos, i) = base_binfo;
10837 TREE_VIA_PUBLIC (base_binfo) = via_public;
10838 TREE_VIA_PROTECTED (base_binfo) = via_protected;
10839 TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
10840 BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref);
10842 SET_CLASSTYPE_MARKED (basetype);
10844 /* XYZZY TEST VIRTUAL BASECLASSES */
10845 if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE
10846 && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
10847 && via_virtual == 0)
10849 warning ("making type `%s' a virtual baseclass",
10850 TYPE_NAME_STRING (basetype));
10854 /* We are free to modify these bits because they are meaningless
10855 at top level, and BASETYPE is a top-level type. */
10856 if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
10858 TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
10859 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
10862 TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
10863 TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype);
10864 TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
10865 CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
10870 TREE_VEC_LENGTH (binfos) = i;
10872 BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
10875 TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
10877 TYPE_USES_MULTIPLE_INHERITANCE (ref)
10878 = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
10879 if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
10880 TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
10882 /* Unmark all the types. */
10884 CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
10885 CLEAR_CLASSTYPE_MARKED (ref);
10891 static tree current_local_enum = NULL_TREE;
10893 /* Begin compiling the definition of an enumeration type.
10894 NAME is its name (or null if anonymous).
10895 Returns the type object, as yet incomplete.
10896 Also records info about it so that build_enumerator
10897 may be used to declare the individual values as they are read. */
10903 register tree enumtype = NULL_TREE;
10904 struct binding_level *b = inner_binding_level;
10906 /* If this is the real definition for a previous forward reference,
10907 fill in the contents in the same object that used to be the
10908 forward reference. */
10910 if (name != NULL_TREE)
10911 enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
10913 if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
10914 cp_error ("multiple definition of enum `%T'", enumtype);
10917 enumtype = make_node (ENUMERAL_TYPE);
10918 pushtag (name, enumtype, 0);
10921 if (current_class_type)
10922 TREE_ADDRESSABLE (b->tags) = 1;
10923 current_local_enum = NULL_TREE;
10925 #if 0 /* This stuff gets cleared in finish_enum anyway. */
10926 if (TYPE_VALUES (enumtype) != NULL_TREE)
10927 /* Completely replace its old definition.
10928 The old enumerators remain defined, however. */
10929 TYPE_VALUES (enumtype) = NULL_TREE;
10931 /* Initially, set up this enum as like `int'
10932 so that we can create the enumerators' declarations and values.
10933 Later on, the precision of the type may be changed and
10934 it may be laid out again. */
10936 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
10937 TYPE_SIZE (enumtype) = NULL_TREE;
10938 fixup_signed_type (enumtype);
10941 /* We copy this value because enumerated type constants
10942 are really of the type of the enumerator, not integer_type_node. */
10943 enum_next_value = copy_node (integer_zero_node);
10946 GNU_xref_decl (current_function_decl, enumtype);
10950 /* After processing and defining all the values of an enumeration type,
10951 install their decls in the enumeration type and finish it off.
10952 ENUMTYPE is the type object and VALUES a list of name-value pairs.
10953 Returns ENUMTYPE. */
10956 finish_enum (enumtype, values)
10957 register tree enumtype, values;
10959 register tree minnode, maxnode;
10960 /* Calculate the maximum value of any enumerator in this type. */
10964 register tree pair;
10965 register tree value = DECL_INITIAL (TREE_VALUE (values));
10967 /* Speed up the main loop by performing some precalculations */
10968 TREE_TYPE (TREE_VALUE (values)) = enumtype;
10969 TREE_TYPE (value) = enumtype;
10970 TREE_VALUE (values) = value;
10971 minnode = maxnode = value;
10973 for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
10975 value = DECL_INITIAL (TREE_VALUE (pair));
10976 TREE_TYPE (TREE_VALUE (pair)) = enumtype;
10977 TREE_TYPE (value) = enumtype;
10978 TREE_VALUE (pair) = value;
10979 if (tree_int_cst_lt (maxnode, value))
10981 else if (tree_int_cst_lt (value, minnode))
10986 maxnode = minnode = integer_zero_node;
10988 TYPE_VALUES (enumtype) = values;
10991 int unsignedp = tree_int_cst_sgn (minnode) >= 0;
10992 int lowprec = min_precision (minnode, unsignedp);
10993 int highprec = min_precision (maxnode, unsignedp);
10994 int precision = MAX (lowprec, highprec);
10996 TYPE_SIZE (enumtype) = NULL_TREE;
10998 /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */
11000 TYPE_PRECISION (enumtype) = precision;
11002 fixup_unsigned_type (enumtype);
11004 fixup_signed_type (enumtype);
11006 if (flag_short_enums || precision > TYPE_PRECISION (integer_type_node))
11007 /* Use the width of the narrowest normal C type which is wide enough. */
11008 TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size
11011 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
11013 TYPE_SIZE (enumtype) = 0;
11014 layout_type (enumtype);
11018 cadillac_finish_enum (enumtype);
11023 /* Fix up all variant types of this enum type. */
11024 for (tem = TYPE_MAIN_VARIANT (enumtype); tem;
11025 tem = TYPE_NEXT_VARIANT (tem))
11027 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
11028 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
11029 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
11030 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
11031 TYPE_MODE (tem) = TYPE_MODE (enumtype);
11032 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
11033 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
11034 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
11038 /* Finish debugging output for this type. */
11040 /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
11041 information should *not* be generated? I think not. */
11042 if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
11044 rest_of_type_compilation (enumtype, global_bindings_p ());
11049 /* Build and install a CONST_DECL for one value of the
11050 current enumeration type (one that was begun with start_enum).
11051 Return a tree-list containing the name and its value.
11052 Assignment of sequential values by default is handled here. */
11055 build_enumerator (name, value)
11059 /* Change this to zero if we find VALUE is not shareable. */
11062 /* Remove no-op casts from the value. */
11064 STRIP_TYPE_NOPS (value);
11066 /* Validate and default VALUE. */
11067 if (value != NULL_TREE)
11069 if (TREE_READONLY_DECL_P (value))
11071 value = decl_constant_value (value);
11075 if (TREE_CODE (value) == INTEGER_CST)
11077 value = default_conversion (value);
11078 constant_expression_warning (value);
11082 cp_error ("enumerator value for `%D' not integer constant", name);
11087 /* The order of things is reversed here so that we
11088 can check for possible sharing of enum values,
11089 to keep that from happening. */
11090 /* Default based on previous value. */
11091 if (value == NULL_TREE)
11093 value = enum_next_value;
11095 cp_error ("overflow in enumeration values at `%D'", name);
11098 /* Remove no-op casts from the value. */
11100 STRIP_TYPE_NOPS (value);
11102 /* Make up for hacks in lex.c. */
11103 if (value == integer_zero_node)
11104 value = build_int_2 (0, 0);
11105 else if (value == integer_one_node)
11106 value = build_int_2 (1, 0);
11107 else if (TREE_CODE (value) == INTEGER_CST
11109 || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
11111 value = copy_node (value);
11112 TREE_TYPE (value) = integer_type_node;
11115 /* C++ associates enums with global, function, or class declarations. */
11117 decl = current_scope ();
11118 if (decl && decl == current_class_type)
11120 /* This enum declaration is local to the class, so we must put
11121 it in that class's list of decls. */
11122 decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
11123 DECL_INITIAL (decl) = value;
11124 TREE_READONLY (decl) = 1;
11125 pushdecl_class_level (decl);
11126 TREE_CHAIN (decl) = current_local_enum;
11127 current_local_enum = decl;
11131 /* It's a global enum, or it's local to a function. (Note local to
11132 a function could mean local to a class method. */
11133 decl = build_decl (CONST_DECL, name, integer_type_node);
11134 DECL_INITIAL (decl) = value;
11137 GNU_xref_decl (current_function_decl, decl);
11140 /* Set basis for default for next value. */
11141 enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
11142 integer_one_node, PLUS_EXPR);
11143 enum_overflow = tree_int_cst_lt (enum_next_value, value);
11145 if (enum_next_value == integer_one_node)
11146 enum_next_value = copy_node (enum_next_value);
11148 result = saveable_tree_cons (name, decl, NULL_TREE);
11153 grok_enum_decls (type, decl)
11156 tree d = current_local_enum;
11158 if (d == NULL_TREE)
11163 TREE_TYPE (d) = type;
11164 if (TREE_CHAIN (d) == NULL_TREE)
11166 TREE_CHAIN (d) = decl;
11169 d = TREE_CHAIN (d);
11172 decl = current_local_enum;
11173 current_local_enum = NULL_TREE;
11178 /* Create the FUNCTION_DECL for a function definition.
11179 DECLSPECS and DECLARATOR are the parts of the declaration;
11180 they describe the function's name and the type it returns,
11181 but twisted together in a fashion that parallels the syntax of C.
11183 This function creates a binding context for the function body
11184 as well as setting up the FUNCTION_DECL in current_function_decl.
11186 Returns 1 on success. If the DECLARATOR is not suitable for a function
11187 (it defines a datum instead), we return 0, which tells
11188 yyparse to report a parse error.
11190 For C++, we must first check whether that datum makes any sense.
11191 For example, "class A local_a(1,2);" means that variable local_a
11192 is an aggregate of type A, which should have a constructor
11193 applied to it with the argument list [1, 2].
11195 @@ There is currently no way to retrieve the storage
11196 @@ allocated to FUNCTION (or all of its parms) if we return
11197 @@ something we had previously. */
11200 start_function (declspecs, declarator, raises, attrs, pre_parsed_p)
11201 tree declspecs, declarator, raises, attrs;
11204 tree decl1, olddecl;
11205 tree ctype = NULL_TREE;
11208 extern int have_extern_spec;
11209 extern int used_extern_spec;
11210 int doing_friend = 0;
11212 /* Sanity check. */
11213 my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
11214 my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
11216 /* Assume, until we see it does. */
11217 current_function_returns_value = 0;
11218 current_function_returns_null = 0;
11219 warn_about_return_type = 0;
11221 shadowed_labels = 0;
11222 current_function_assigns_this = 0;
11223 current_function_just_assigned_this = 0;
11224 current_function_parms_stored = 0;
11225 original_result_rtx = NULL_RTX;
11226 current_function_obstack_index = 0;
11227 current_function_obstack_usage = 0;
11228 base_init_expr = NULL_TREE;
11229 protect_list = NULL_TREE;
11230 current_base_init_list = NULL_TREE;
11231 current_member_init_list = NULL_TREE;
11232 ctor_label = dtor_label = NULL_TREE;
11234 clear_temp_name ();
11236 /* This should only be done once on the top most decl. */
11237 if (have_extern_spec && !used_extern_spec)
11239 declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
11240 used_extern_spec = 1;
11245 decl1 = declarator;
11247 if (! DECL_ARGUMENTS (decl1)
11248 && !DECL_STATIC_FUNCTION_P (decl1)
11249 && DECL_CONTEXT (decl1)
11250 && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))
11251 && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))))
11253 cp_error ("redeclaration of `%#D'", decl1);
11254 if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
11255 cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
11256 else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
11257 cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
11260 /* This can happen if a template class is instantiated as part of the
11261 specialization of a member function which is defined in the class
11262 template. We should just use the specialization, but for now give an
11264 if (DECL_INITIAL (decl1) != NULL_TREE)
11266 cp_error_at ("specialization of `%#D' not supported", decl1);
11267 cp_error ("when defined in the class template body", decl1);
11270 last_function_parms = DECL_ARGUMENTS (decl1);
11271 last_function_parm_tags = NULL_TREE;
11272 fntype = TREE_TYPE (decl1);
11273 if (TREE_CODE (fntype) == METHOD_TYPE)
11274 ctype = TYPE_METHOD_BASETYPE (fntype);
11276 /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a
11277 class is in the (lexical) scope of the class in which it is
11279 if (!ctype && DECL_FRIEND_P (decl1))
11281 ctype = DECL_CLASS_CONTEXT (decl1);
11283 /* CTYPE could be null here if we're dealing with a template;
11284 for example, `inline friend float foo()' inside a template
11285 will have no CTYPE set. */
11286 if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
11292 raises = TYPE_RAISES_EXCEPTIONS (fntype);
11294 /* In a fcn definition, arg types must be complete. */
11295 require_complete_types_for_parms (last_function_parms);
11297 /* In case some arg types were completed since the declaration was
11298 parsed, fix up the decls. */
11300 tree t = last_function_parms;
11301 for (; t; t = TREE_CHAIN (t))
11302 layout_decl (t, 0);
11307 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises,
11309 /* If the declarator is not suitable for a function definition,
11310 cause a syntax error. */
11311 if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
11313 fntype = TREE_TYPE (decl1);
11315 restype = TREE_TYPE (fntype);
11316 if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
11317 && ! CLASSTYPE_GOT_SEMICOLON (restype))
11319 cp_error ("semicolon missing after declaration of `%#T'", restype);
11320 shadow_tag (build_tree_list (NULL_TREE, restype));
11321 CLASSTYPE_GOT_SEMICOLON (restype) = 1;
11322 if (TREE_CODE (fntype) == FUNCTION_TYPE)
11323 fntype = build_function_type (integer_type_node,
11324 TYPE_ARG_TYPES (fntype));
11326 fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
11328 TYPE_ARG_TYPES (fntype));
11329 TREE_TYPE (decl1) = fntype;
11332 if (TREE_CODE (fntype) == METHOD_TYPE)
11333 ctype = TYPE_METHOD_BASETYPE (fntype);
11334 else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
11335 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
11336 && DECL_CONTEXT (decl1) == NULL_TREE)
11338 /* If this doesn't return integer_type, complain. */
11339 if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
11341 if (pedantic || warn_return_type)
11342 pedwarn ("return type for `main' changed to integer type");
11343 TREE_TYPE (decl1) = fntype = default_function_type;
11345 warn_about_return_type = 0;
11349 /* Warn if function was previously implicitly declared
11350 (but not if we warned then). */
11351 if (! warn_implicit
11352 && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
11353 cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
11355 current_function_decl = decl1;
11358 cadillac_start_function (decl1);
11360 announce_function (decl1);
11362 if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE)
11364 if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
11365 error_with_aggr_type (TREE_TYPE (fntype),
11366 "return-type `%s' is an incomplete type");
11368 error ("return-type is an incomplete type");
11370 /* Make it return void instead, but don't change the
11371 type of the DECL_RESULT, in case we have a named return value. */
11374 = build_cplus_method_type (build_type_variant (ctype,
11375 TREE_READONLY (decl1),
11376 TREE_SIDE_EFFECTS (decl1)),
11378 FUNCTION_ARG_CHAIN (decl1));
11381 = build_function_type (void_type_node,
11382 TYPE_ARG_TYPES (TREE_TYPE (decl1)));
11383 DECL_RESULT (decl1)
11384 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype)));
11385 TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype));
11386 TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype));
11389 if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype))
11390 && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype)))
11391 abstract_virtuals_error (decl1, TREE_TYPE (fntype));
11393 if (warn_about_return_type)
11394 warning ("return-type defaults to `int'");
11396 /* Make the init_value nonzero so pushdecl knows this is not tentative.
11397 error_mark_node is replaced below (in poplevel) with the BLOCK. */
11398 DECL_INITIAL (decl1) = error_mark_node;
11400 /* Didn't get anything from C. */
11401 olddecl = NULL_TREE;
11403 /* This function exists in static storage.
11404 (This does not mean `static' in the C sense!) */
11405 TREE_STATIC (decl1) = 1;
11407 /* Record the decl so that the function name is defined.
11408 If we already have a decl for this name, and it is a FUNCTION_DECL,
11409 use the old decl. */
11411 if (pre_parsed_p == 0)
11413 current_function_decl = decl1 = pushdecl (decl1);
11414 DECL_MAIN_VARIANT (decl1) = decl1;
11415 fntype = TREE_TYPE (decl1);
11418 current_function_decl = decl1;
11420 if (DECL_INTERFACE_KNOWN (decl1))
11422 if (DECL_NOT_REALLY_EXTERN (decl1))
11423 DECL_EXTERNAL (decl1) = 0;
11425 /* If this function belongs to an interface, it is public.
11426 If it belongs to someone else's interface, it is also external.
11427 It doesn't matter whether it's inline or not. */
11428 else if (interface_unknown == 0)
11430 if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1))
11431 DECL_EXTERNAL (decl1)
11433 || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines));
11435 DECL_EXTERNAL (decl1) = 0;
11436 DECL_NOT_REALLY_EXTERN (decl1) = 0;
11437 DECL_INTERFACE_KNOWN (decl1) = 1;
11441 /* This is a definition, not a reference.
11442 So clear DECL_EXTERNAL. */
11443 DECL_EXTERNAL (decl1) = 0;
11445 if (DECL_THIS_INLINE (decl1) && ! DECL_INTERFACE_KNOWN (decl1))
11446 DECL_DEFER_OUTPUT (decl1) = 1;
11449 DECL_INTERFACE_KNOWN (decl1) = 1;
11450 if (DECL_C_STATIC (decl1))
11451 TREE_PUBLIC (decl1) = 0;
11455 if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
11457 if (TREE_CODE (fntype) == METHOD_TYPE)
11458 TREE_TYPE (decl1) = fntype
11459 = build_function_type (TREE_TYPE (fntype),
11460 TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
11461 last_function_parms = TREE_CHAIN (last_function_parms);
11462 DECL_ARGUMENTS (decl1) = last_function_parms;
11465 restype = TREE_TYPE (fntype);
11469 push_nested_class (ctype, 1);
11471 /* If we're compiling a friend function, neither of the variables
11472 current_class_decl nor current_class_type will have values. */
11473 if (! doing_friend)
11475 /* We know that this was set up by `grokclassfn'.
11476 We do not wait until `store_parm_decls', since evil
11477 parse errors may never get us to that point. Here
11478 we keep the consistency between `current_class_type'
11479 and `current_class_decl'. */
11480 tree t = last_function_parms;
11482 my_friendly_assert (t != NULL_TREE
11483 && TREE_CODE (t) == PARM_DECL, 162);
11485 if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
11487 int i = suspend_momentary ();
11489 /* Fool build_indirect_ref. */
11490 current_class_decl = NULL_TREE;
11491 C_C_D = build_indirect_ref (t, NULL_PTR);
11492 current_class_decl = t;
11493 resume_momentary (i);
11496 /* We're having a signature pointer here. */
11497 C_C_D = current_class_decl = t;
11503 if (DECL_STATIC_FUNCTION_P (decl1))
11504 push_nested_class (DECL_CONTEXT (decl1), 2);
11506 push_memoized_context (0, 1);
11507 current_class_decl = C_C_D = NULL_TREE;
11511 current_binding_level->parm_flag = 1;
11513 /* Save the parm names or decls from this function's declarator
11514 where store_parm_decls will find them. */
11515 current_function_parms = last_function_parms;
11516 current_function_parm_tags = last_function_parm_tags;
11518 GNU_xref_function (decl1, current_function_parms);
11521 cplus_decl_attributes (decl1, NULL_TREE, attrs);
11522 make_function_rtl (decl1);
11524 /* Allocate further tree nodes temporarily during compilation
11525 of this function only. Tiemann moved up here from bottom of fn. */
11526 temporary_allocation ();
11528 /* Promote the value to int before returning it. */
11529 if (C_PROMOTING_INTEGER_TYPE_P (restype))
11531 /* It retains unsignedness if traditional or if it isn't
11532 really getting wider. */
11533 if (TREE_UNSIGNED (restype)
11534 && (flag_traditional
11535 || TYPE_PRECISION (restype)
11536 == TYPE_PRECISION (integer_type_node)))
11537 restype = unsigned_type_node;
11539 restype = integer_type_node;
11541 if (DECL_RESULT (decl1) == NULL_TREE)
11543 DECL_RESULT (decl1)
11544 = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype));
11545 TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (restype);
11546 TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype);
11549 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1))
11550 && DECL_LANGUAGE (decl1) == lang_cplusplus)
11552 dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11553 ctor_label = NULL_TREE;
11557 dtor_label = NULL_TREE;
11558 if (DECL_CONSTRUCTOR_P (decl1))
11559 ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
11562 /* If this fcn was already referenced via a block-scope `extern' decl
11563 (or an implicit decl), propagate certain information about the usage. */
11564 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
11565 TREE_ADDRESSABLE (decl1) = 1;
11571 expand_start_early_try_stmts ()
11575 expand_start_try_stmts ();
11576 insns = get_insns ();
11578 store_in_parms (insns);
11582 store_in_parms (insns)
11585 rtx last_parm_insn;
11587 last_parm_insn = get_first_nonparm_insn ();
11588 if (last_parm_insn == NULL_RTX)
11589 emit_insns (insns);
11591 emit_insns_before (insns, previous_insn (last_parm_insn));
11594 /* Store the parameter declarations into the current function declaration.
11595 This is called after parsing the parameter declarations, before
11596 digesting the body of the function.
11598 Also install to binding contour return value identifier, if any. */
11601 store_parm_decls ()
11603 register tree fndecl = current_function_decl;
11604 register tree parm;
11605 int parms_have_cleanups = 0;
11607 /* This is either a chain of PARM_DECLs (when a prototype is used). */
11608 tree specparms = current_function_parms;
11610 /* This is a list of types declared among parms in a prototype. */
11611 tree parmtags = current_function_parm_tags;
11613 /* This is a chain of any other decls that came in among the parm
11614 declarations. If a parm is declared with enum {foo, bar} x;
11615 then CONST_DECLs for foo and bar are put here. */
11616 tree nonparms = NULL_TREE;
11618 if (toplevel_bindings_p ())
11619 fatal ("parse errors have confused me too much");
11621 /* Initialize RTL machinery. */
11622 init_function_start (fndecl, input_filename, lineno);
11624 /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */
11625 declare_function_name ();
11627 /* Create a binding level for the parms. */
11628 expand_start_bindings (0);
11630 if (specparms != NULL_TREE)
11632 /* This case is when the function was defined with an ANSI prototype.
11633 The parms already have decls, so we need not do anything here
11634 except record them as in effect
11635 and complain if any redundant old-style parm decls were written. */
11637 register tree next;
11639 /* Must clear this because it might contain TYPE_DECLs declared
11641 storedecls (NULL_TREE);
11642 for (parm = nreverse (specparms); parm; parm = next)
11644 next = TREE_CHAIN (parm);
11645 if (TREE_CODE (parm) == PARM_DECL)
11647 tree cleanup = maybe_build_cleanup (parm);
11648 if (DECL_NAME (parm) == NULL_TREE)
11651 cp_error_at ("parameter name omitted", parm);
11653 /* for C++, this is not an error. */
11657 else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
11658 cp_error ("parameter `%D' declared void", parm);
11661 /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
11662 A parameter is assumed not to have any side effects.
11663 If this should change for any reason, then this
11664 will have to wrap the bashed reference type in a save_expr.
11666 Also, if the parameter type is declared to be an X
11667 and there is an X(X&) constructor, we cannot lay it
11668 into the stack (any more), so we make this parameter
11669 look like it is really of reference type. Functions
11670 which pass parameters to this function will know to
11671 create a temporary in their frame, and pass a reference
11674 if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
11675 && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
11676 SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
11682 expand_decl (parm);
11683 if (! cp_expand_decl_cleanup (parm, cleanup))
11684 cp_error ("parser lost in parsing declaration of `%D'",
11686 parms_have_cleanups = 1;
11691 /* If we find an enum constant or a type tag,
11692 put it aside for the moment. */
11693 TREE_CHAIN (parm) = NULL_TREE;
11694 nonparms = chainon (nonparms, parm);
11698 /* Get the decls in their original chain order
11699 and record in the function. This is all and only the
11700 PARM_DECLs that were pushed into scope by the loop above. */
11701 DECL_ARGUMENTS (fndecl) = getdecls ();
11703 storetags (chainon (parmtags, gettags ()));
11706 DECL_ARGUMENTS (fndecl) = NULL_TREE;
11708 /* Now store the final chain of decls for the arguments
11709 as the decl-chain of the current lexical scope.
11710 Put the enumerators in as well, at the front so that
11711 DECL_ARGUMENTS is not modified. */
11713 storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
11715 /* Initialize the RTL code for the function. */
11716 DECL_SAVED_INSNS (fndecl) = NULL_RTX;
11717 expand_function_start (fndecl, parms_have_cleanups);
11719 /* Create a binding contour which can be used to catch
11720 cleanup-generated temporaries. Also, if the return value needs or
11721 has initialization, deal with that now. */
11722 if (parms_have_cleanups)
11725 expand_start_bindings (0);
11728 current_function_parms_stored = 1;
11732 maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
11733 if (! cp_expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup))
11734 cp_error ("parser lost in parsing declaration of `%D'", fndecl);
11737 /* If this function is `main', emit a call to `__main'
11738 to run global initializers, etc. */
11739 if (DECL_NAME (fndecl)
11740 && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
11741 && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
11742 && DECL_CONTEXT (fndecl) == NULL_TREE)
11744 expand_main_function ();
11747 expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
11750 /* done at a different time */
11752 output_builtin_tdesc_entries ();
11756 /* Take care of exception handling things. */
11757 if (flag_handle_exceptions)
11762 /* Mark the start of a stack unwinder if we need one. */
11763 start_eh_unwinder ();
11765 /* Do the starting of the exception specifications, if we have any. */
11766 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl)))
11767 expand_start_eh_spec ();
11769 insns = get_insns ();
11773 store_in_parms (insns);
11775 last_dtor_insn = get_last_insn ();
11778 /* Bind a name and initialization to the return value of
11779 the current function. */
11781 store_return_init (return_id, init)
11782 tree return_id, init;
11784 tree decl = DECL_RESULT (current_function_decl);
11787 /* Give this error as many times as there are occurrences,
11788 so that users can use Emacs compilation buffers to find
11789 and fix all such places. */
11790 pedwarn ("ANSI C++ does not permit named return values");
11792 if (return_id != NULL_TREE)
11794 if (DECL_NAME (decl) == NULL_TREE)
11796 DECL_NAME (decl) = return_id;
11797 DECL_ASSEMBLER_NAME (decl) = return_id;
11800 error ("return identifier `%s' already in place",
11801 IDENTIFIER_POINTER (DECL_NAME (decl)));
11804 /* Can't let this happen for constructors. */
11805 if (DECL_CONSTRUCTOR_P (current_function_decl))
11807 error ("can't redefine default return value for constructors");
11811 /* If we have a named return value, put that in our scope as well. */
11812 if (DECL_NAME (decl) != NULL_TREE)
11814 /* If this named return value comes in a register,
11815 put it in a pseudo-register. */
11816 if (DECL_REGISTER (decl))
11818 original_result_rtx = DECL_RTL (decl);
11819 DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
11822 /* Let `cp_finish_decl' know that this initializer is ok. */
11823 DECL_INITIAL (decl) = init;
11825 cp_finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
11830 /* Finish up a function declaration and compile that function
11831 all the way to assembler language output. The free the storage
11832 for the function definition.
11834 This is called after parsing the body of the function definition.
11835 LINENO is the current line number.
11837 C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
11838 (and expand_end_bindings) must be made to take care of the binding
11839 contour for the base initializers. This is only relevant for
11843 finish_function (lineno, call_poplevel, nested)
11848 register tree fndecl = current_function_decl;
11849 tree fntype, ctype = NULL_TREE;
11850 rtx last_parm_insn, insns;
11851 /* Label to use if this function is supposed to return a value. */
11852 tree no_return_label = NULL_TREE;
11853 tree decls = NULL_TREE;
11855 /* When we get some parse errors, we can end up without a
11856 current_function_decl, so cope. */
11857 if (fndecl == NULL_TREE)
11860 fntype = TREE_TYPE (fndecl);
11862 /* TREE_READONLY (fndecl) = 1;
11863 This caused &foo to be of type ptr-to-const-function
11864 which then got a warning when stored in a ptr-to-function variable. */
11866 /* This happens on strange parse errors. */
11867 if (! current_function_parms_stored)
11870 store_parm_decls ();
11873 if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/)
11875 tree ttype = target_type (fntype);
11878 if (IS_AGGR_TYPE (ttype))
11879 /* Let debugger know it should output info for this type. */
11880 note_debug_info_needed (ttype);
11882 for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
11884 ttype = target_type (TREE_TYPE (parmdecl));
11885 if (IS_AGGR_TYPE (ttype))
11886 /* Let debugger know it should output info for this type. */
11887 note_debug_info_needed (ttype);
11891 /* Clean house because we will need to reorder insns here. */
11892 do_pending_stack_adjust ();
11896 tree binfo = TYPE_BINFO (current_class_type);
11897 tree cond = integer_one_node;
11898 tree exprstmt, vfields;
11899 tree in_charge_node = lookup_name (in_charge_identifier, 0);
11901 int ok_to_optimize_dtor = 0;
11902 int empty_dtor = get_last_insn () == last_dtor_insn;
11904 if (current_function_assigns_this)
11905 cond = build (NE_EXPR, boolean_type_node,
11906 current_class_decl, integer_zero_node);
11909 int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
11911 /* If this destructor is empty, then we don't need to check
11912 whether `this' is NULL in some cases. */
11913 if ((flag_this_is_variable & 1) == 0)
11914 ok_to_optimize_dtor = 1;
11915 else if (empty_dtor)
11916 ok_to_optimize_dtor
11917 = (n_baseclasses == 0
11918 || (n_baseclasses == 1
11919 && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
11922 /* These initializations might go inline. Protect
11923 the binding level of the parms. */
11925 expand_start_bindings (0);
11927 if (current_function_assigns_this)
11929 current_function_assigns_this = 0;
11930 current_function_just_assigned_this = 0;
11933 /* Generate the code to call destructor on base class.
11934 If this destructor belongs to a class with virtual
11935 functions, then set the virtual function table
11936 pointer to represent the type of our base class. */
11938 /* This side-effect makes call to `build_delete' generate the
11939 code we have to have at the end of this destructor. */
11940 TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
11942 /* These are two cases where we cannot delegate deletion. */
11943 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
11944 || TYPE_GETS_REG_DELETE (current_class_type))
11945 exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
11946 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11948 exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
11949 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
11951 /* If we did not assign to this, then `this' is non-zero at
11952 the end of a destructor. As a special optimization, don't
11953 emit test if this is an empty destructor. If it does nothing,
11954 it does nothing. If it calls a base destructor, the base
11955 destructor will perform the test. */
11957 if (exprstmt != error_mark_node
11958 && (TREE_CODE (exprstmt) != NOP_EXPR
11959 || TREE_OPERAND (exprstmt, 0) != integer_zero_node
11960 || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
11962 expand_label (dtor_label);
11963 if (cond != integer_one_node)
11964 expand_start_cond (cond, 0);
11965 if (exprstmt != void_zero_node)
11966 /* Don't call `expand_expr_stmt' if we're not going to do
11967 anything, since -Wall will give a diagnostic. */
11968 expand_expr_stmt (exprstmt);
11970 /* Run destructor on all virtual baseclasses. */
11971 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
11973 tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
11974 expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
11975 in_charge_node, integer_two_node), 0);
11978 if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
11980 tree ptr = convert_pointer_to_vbase (BINFO_TYPE (vbases), current_class_decl);
11981 expand_expr_stmt (build_delete (build_pointer_type (BINFO_TYPE (vbases)),
11982 ptr, integer_zero_node,
11983 LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
11985 vbases = TREE_CHAIN (vbases);
11987 expand_end_cond ();
11990 do_pending_stack_adjust ();
11991 if (cond != integer_one_node)
11992 expand_end_cond ();
11995 TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
11997 virtual_size = c_sizeof (current_class_type);
11999 /* At the end, call delete if that's what's requested. */
12000 if (TYPE_GETS_REG_DELETE (current_class_type))
12001 /* This NOP_EXPR means we are in a static call context. */
12004 (build_indirect_ref
12005 (build1 (NOP_EXPR, build_pointer_type (current_class_type),
12008 ansi_opname[(int) DELETE_EXPR],
12009 tree_cons (NULL_TREE, current_class_decl,
12010 build_tree_list (NULL_TREE, virtual_size)),
12011 NULL_TREE, LOOKUP_NORMAL);
12012 else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
12013 exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
12016 exprstmt = NULL_TREE;
12020 cond = build (BIT_AND_EXPR, integer_type_node,
12021 in_charge_node, integer_one_node);
12022 expand_start_cond (cond, 0);
12023 expand_expr_stmt (exprstmt);
12024 expand_end_cond ();
12027 /* End of destructor. */
12028 expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0);
12029 poplevel (2, 0, 0); /* XXX change to 1 */
12031 /* Back to the top of destructor. */
12032 /* Dont execute destructor code if `this' is NULL. */
12036 /* If the dtor is empty, and we know there is not possible way we could
12037 use any vtable entries, before they are possibly set by a base class
12038 dtor, we don't have to setup the vtables, as we know that any base
12039 class dtoring will set up any vtables it needs. We avoid MI,
12040 because one base class dtor can do a virtual dispatch to an
12041 overridden function that would need to have a non-related vtable set
12042 up, we cannot avoid setting up vtables in that case. We could
12043 change this to see if there is just one vtable. */
12044 if (! empty_dtor || TYPE_USES_COMPLEX_INHERITANCE (current_class_type))
12046 /* Make all virtual function table pointers in non-virtual base
12047 classes point to CURRENT_CLASS_TYPE's virtual function
12049 expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_decl);
12051 if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
12052 expand_indirect_vtbls_init (binfo, C_C_D, current_class_decl, 0);
12055 if (! ok_to_optimize_dtor)
12057 cond = build_binary_op (NE_EXPR,
12058 current_class_decl, integer_zero_node, 1);
12059 expand_start_cond (cond, 0);
12062 insns = get_insns ();
12065 last_parm_insn = get_first_nonparm_insn ();
12066 if (last_parm_insn == NULL_RTX)
12067 last_parm_insn = get_last_insn ();
12069 last_parm_insn = previous_insn (last_parm_insn);
12071 emit_insns_after (insns, last_parm_insn);
12073 if (! ok_to_optimize_dtor)
12074 expand_end_cond ();
12076 else if (current_function_assigns_this)
12078 /* Does not need to call emit_base_init, because
12079 that is done (if needed) just after assignment to this
12082 if (DECL_CONSTRUCTOR_P (current_function_decl))
12084 end_protect_partials ();
12085 expand_label (ctor_label);
12086 ctor_label = NULL_TREE;
12090 decls = getdecls ();
12091 expand_end_bindings (decls, decls != NULL_TREE, 0);
12092 poplevel (decls != NULL_TREE, 0, 0);
12094 c_expand_return (current_class_decl);
12096 else if (TYPE_MAIN_VARIANT (TREE_TYPE (
12097 DECL_RESULT (current_function_decl))) != void_type_node
12098 && return_label != NULL_RTX)
12099 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
12101 current_function_assigns_this = 0;
12102 current_function_just_assigned_this = 0;
12103 base_init_expr = NULL_TREE;
12105 else if (DECL_CONSTRUCTOR_P (fndecl))
12107 tree allocated_this;
12108 tree cond, thenclause;
12109 /* Allow constructor for a type to get a new instance of the object
12110 using `build_new'. */
12111 tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
12112 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
12114 DECL_RETURNS_FIRST_ARG (fndecl) = 1;
12116 if (flag_this_is_variable > 0)
12118 cond = build_binary_op (EQ_EXPR,
12119 current_class_decl, integer_zero_node, 1);
12120 thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
12121 build_new (NULL_TREE, current_class_type, void_type_node, 0));
12124 CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
12128 if (flag_this_is_variable > 0)
12130 expand_start_cond (cond, 0);
12131 expand_expr_stmt (thenclause);
12132 expand_end_cond ();
12136 if (DECL_NAME (fndecl) == NULL_TREE
12137 && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
12138 build_default_constructor (fndecl);
12141 /* Emit insns from `emit_base_init' which sets up virtual
12142 function table pointer(s). */
12143 if (base_init_expr)
12145 expand_expr_stmt (base_init_expr);
12146 base_init_expr = NULL_TREE;
12149 insns = get_insns ();
12152 /* This is where the body of the constructor begins.
12153 If there were no insns in this function body, then the
12154 last_parm_insn is also the last insn.
12156 If optimization is enabled, last_parm_insn may move, so
12157 we don't hold on to it (across emit_base_init). */
12158 last_parm_insn = get_first_nonparm_insn ();
12159 if (last_parm_insn == NULL_RTX)
12160 last_parm_insn = get_last_insn ();
12162 last_parm_insn = previous_insn (last_parm_insn);
12164 emit_insns_after (insns, last_parm_insn);
12166 end_protect_partials ();
12168 /* This is where the body of the constructor ends. */
12169 expand_label (ctor_label);
12170 ctor_label = NULL_TREE;
12174 decls = getdecls ();
12175 expand_end_bindings (decls, decls != NULL_TREE, 0);
12176 poplevel (decls != NULL_TREE, 1, 0);
12179 c_expand_return (current_class_decl);
12181 current_function_assigns_this = 0;
12182 current_function_just_assigned_this = 0;
12184 else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
12185 && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
12186 && DECL_CONTEXT (fndecl) == NULL_TREE)
12188 /* Make it so that `main' always returns 0 by default. */
12190 c_expand_return (integer_one_node);
12192 c_expand_return (integer_zero_node);
12195 else if (return_label != NULL_RTX
12196 && current_function_return_value == NULL_TREE
12197 && ! DECL_NAME (DECL_RESULT (current_function_decl)))
12198 no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
12201 expand_gc_prologue_and_epilogue ();
12203 /* If this function is supposed to return a value, ensure that
12204 we do not fall into the cleanups by mistake. The end of our
12205 function will look like this:
12207 user code (may have return stmt somewhere)
12208 goto no_return_label
12213 NOTE_INSN_FUNCTION_END
12217 If the user omits a return stmt in the USER CODE section, we
12218 will have a control path which reaches NOTE_INSN_FUNCTION_END.
12219 Otherwise, we won't. */
12220 if (no_return_label)
12222 DECL_CONTEXT (no_return_label) = fndecl;
12223 DECL_INITIAL (no_return_label) = error_mark_node;
12224 DECL_SOURCE_FILE (no_return_label) = input_filename;
12225 DECL_SOURCE_LINE (no_return_label) = lineno;
12226 expand_goto (no_return_label);
12231 /* remove the binding contour which is used
12232 to catch cleanup-generated temporaries. */
12233 expand_end_bindings (0, 0, 0);
12234 poplevel (0, 0, 0);
12238 /* Emit label at beginning of cleanup code for parameters. */
12239 emit_label (cleanup_label);
12241 /* Get return value into register if that's where it's supposed to be. */
12242 if (original_result_rtx)
12243 fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
12245 /* Finish building code that will trigger warnings if users forget
12246 to make their functions return values. */
12247 if (no_return_label || cleanup_label)
12248 emit_jump (return_label);
12249 if (no_return_label)
12251 /* We don't need to call `expand_*_return' here because we
12252 don't need any cleanups here--this path of code is only
12253 for error checking purposes. */
12254 expand_label (no_return_label);
12257 /* Generate rtl for function exit. */
12258 expand_function_end (input_filename, lineno, 1);
12260 if (flag_handle_exceptions)
12261 expand_exception_blocks ();
12263 /* This must come after expand_function_end because cleanups might
12264 have declarations (from inline functions) that need to go into
12265 this function's blocks. */
12266 if (current_binding_level->parm_flag != 1)
12267 my_friendly_abort (122);
12268 poplevel (1, 0, 1);
12270 /* reset scope for C++: if we were in the scope of a class,
12271 then when we finish this function, we are not longer so.
12272 This cannot be done until we know for sure that no more
12273 class members will ever be referenced in this function
12274 (i.e., calls to destructors). */
12275 if (current_class_name)
12277 ctype = current_class_type;
12278 pop_nested_class (1);
12281 pop_memoized_context (1);
12283 /* Must mark the RESULT_DECL as being in this function. */
12284 DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
12286 /* Obey `register' declarations if `setjmp' is called in this fn. */
12287 if (flag_traditional && current_function_calls_setjmp)
12288 setjmp_protect (DECL_INITIAL (fndecl));
12290 /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
12291 to the FUNCTION_DECL node itself. */
12292 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
12294 /* So we can tell if jump_optimize sets it to 1. */
12297 /* Run the optimizers and output the assembler code for this function. */
12298 rest_of_compilation (fndecl);
12300 if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl))
12302 /* Set DECL_EXTERNAL so that assemble_external will be called as
12303 necessary. We'll clear it again in finish_file. */
12304 if (! DECL_EXTERNAL (fndecl))
12305 DECL_NOT_REALLY_EXTERN (fndecl) = 1;
12306 DECL_EXTERNAL (fndecl) = 1;
12307 mark_inline_for_output (fndecl);
12310 if (ctype && TREE_ASM_WRITTEN (fndecl))
12311 note_debug_info_needed (ctype);
12313 current_function_returns_null |= can_reach_end;
12315 /* Since we don't normally go through c_expand_return for constructors,
12316 this normally gets the wrong value.
12317 Also, named return values have their return codes emitted after
12318 NOTE_INSN_FUNCTION_END, confusing jump.c. */
12319 if (DECL_CONSTRUCTOR_P (fndecl)
12320 || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
12321 current_function_returns_null = 0;
12323 if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
12324 cp_warning ("`noreturn' function `%D' does return", fndecl);
12325 else if ((warn_return_type || pedantic)
12326 && current_function_returns_null
12327 && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
12329 /* If this function returns non-void and control can drop through,
12331 cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
12333 /* With just -W, complain only if function returns both with
12334 and without a value. */
12335 else if (extra_warnings
12336 && current_function_returns_value && current_function_returns_null)
12337 warning ("this function may return with or without a value");
12339 /* Free all the tree nodes making up this function. */
12340 /* Switch back to allocating nodes permanently
12341 until we start another function. */
12343 permanent_allocation (1);
12346 cadillac_finish_function (fndecl);
12348 if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
12350 /* Stop pointing to the local nodes about to be freed. */
12351 /* But DECL_INITIAL must remain nonzero so we know this
12352 was an actual function definition. */
12353 DECL_INITIAL (fndecl) = error_mark_node;
12354 if (! DECL_CONSTRUCTOR_P (fndecl)
12355 || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
12356 DECL_ARGUMENTS (fndecl) = NULL_TREE;
12359 if (DECL_STATIC_CONSTRUCTOR (fndecl))
12360 static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors);
12361 if (DECL_STATIC_DESTRUCTOR (fndecl))
12362 static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors);
12366 /* Let the error reporting routines know that we're outside a
12367 function. For a nested function, this value is used in
12368 pop_cp_function_context and then reset via pop_function_context. */
12369 current_function_decl = NULL_TREE;
12372 named_label_uses = NULL_TREE;
12373 current_class_decl = NULL_TREE;
12376 /* Create the FUNCTION_DECL for a function definition.
12377 LINE1 is the line number that the definition absolutely begins on.
12378 LINE2 is the line number that the name of the function appears on.
12379 DECLSPECS and DECLARATOR are the parts of the declaration;
12380 they describe the return type and the name of the function,
12381 but twisted together in a fashion that parallels the syntax of C.
12383 This function creates a binding context for the function body
12384 as well as setting up the FUNCTION_DECL in current_function_decl.
12386 Returns a FUNCTION_DECL on success.
12388 If the DECLARATOR is not suitable for a function (it defines a datum
12389 instead), we return 0, which tells yyparse to report a parse error.
12391 May return void_type_node indicating that this method is actually
12392 a friend. See grokfield for more details.
12394 Came here with a `.pushlevel' .
12396 DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
12397 CHANGES TO CODE IN `grokfield'. */
12399 start_method (declspecs, declarator, raises)
12400 tree declarator, declspecs, raises;
12402 tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises,
12405 /* Something too ugly to handle. */
12406 if (fndecl == NULL_TREE)
12409 /* Pass friends other than inline friend functions back. */
12410 if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
12413 if (TREE_CODE (fndecl) != FUNCTION_DECL)
12414 /* Not a function, tell parser to report parse error. */
12417 if (IS_SIGNATURE (current_class_type))
12419 IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
12420 /* In case we need this info later. */
12421 HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1;
12424 if (DECL_IN_AGGR_P (fndecl))
12426 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
12428 if (DECL_CONTEXT (fndecl))
12429 cp_error ("`%D' is already defined in class %s", fndecl,
12430 TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
12432 return void_type_node;
12435 DECL_THIS_INLINE (fndecl) = 1;
12437 if (flag_default_inline)
12438 DECL_INLINE (fndecl) = 1;
12440 if (processing_template_defn)
12442 SET_DECL_IMPLICIT_INSTANTIATION (fndecl);
12443 repo_template_used (fndecl);
12446 /* We read in the parameters on the maybepermanent_obstack,
12447 but we won't be getting back to them until after we
12448 may have clobbered them. So the call to preserve_data
12449 will keep them safe. */
12452 if (! DECL_FRIEND_P (fndecl))
12454 if (DECL_CHAIN (fndecl) != NULL_TREE)
12456 /* Need a fresh node here so that we don't get circularity
12457 when we link these together. If FNDECL was a friend, then
12458 `pushdecl' does the right thing, which is nothing wrt its
12459 current value of DECL_CHAIN. */
12460 fndecl = copy_node (fndecl);
12462 if (TREE_CHAIN (fndecl))
12464 fndecl = copy_node (fndecl);
12465 TREE_CHAIN (fndecl) = NULL_TREE;
12468 if (DECL_CONSTRUCTOR_P (fndecl))
12470 if (! grok_ctor_properties (current_class_type, fndecl))
12471 return void_type_node;
12473 else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
12474 grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
12477 cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0);
12479 /* Make a place for the parms */
12481 current_binding_level->parm_flag = 1;
12483 DECL_IN_AGGR_P (fndecl) = 1;
12487 /* Go through the motions of finishing a function definition.
12488 We don't compile this method until after the whole class has
12491 FINISH_METHOD must return something that looks as though it
12492 came from GROKFIELD (since we are defining a method, after all).
12494 This is called after parsing the body of the function definition.
12495 STMTS is the chain of statements that makes up the function body.
12497 DECL is the ..._DECL that `start_method' provided. */
12500 finish_method (decl)
12503 register tree fndecl = decl;
12506 register tree link;
12508 if (TYPE_MAIN_VARIANT (decl) == void_type_node)
12511 old_initial = DECL_INITIAL (fndecl);
12513 /* Undo the level for the parms (from start_method).
12514 This is like poplevel, but it causes nothing to be
12515 saved. Saving information here confuses symbol-table
12516 output routines. Besides, this information will
12517 be correctly output when this method is actually
12520 /* Clear out the meanings of the local variables of this level;
12521 also record in each decl which block it belongs to. */
12523 for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
12525 if (DECL_NAME (link) != NULL_TREE)
12526 IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
12527 my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
12528 DECL_CONTEXT (link) = NULL_TREE;
12531 /* Restore all name-meanings of the outer levels
12532 that were shadowed by this level. */
12534 for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
12535 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
12536 for (link = current_binding_level->class_shadowed;
12537 link; link = TREE_CHAIN (link))
12538 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
12539 for (link = current_binding_level->type_shadowed;
12540 link; link = TREE_CHAIN (link))
12541 IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
12543 GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
12544 (HOST_WIDE_INT) current_binding_level->level_chain,
12545 current_binding_level->parm_flag,
12546 current_binding_level->keep,
12547 current_binding_level->tag_transparent);
12549 poplevel (0, 0, 0);
12551 DECL_INITIAL (fndecl) = old_initial;
12553 /* We used to check if the context of FNDECL was different from
12554 current_class_type as another way to get inside here. This didn't work
12555 for String.cc in libg++. */
12556 if (DECL_FRIEND_P (fndecl))
12558 CLASSTYPE_INLINE_FRIENDS (current_class_type)
12559 = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
12560 decl = void_type_node;
12566 /* Called when a new struct TYPE is defined.
12567 If this structure or union completes the type of any previous
12568 variable declaration, lay it out and output its rtl. */
12571 hack_incomplete_structures (type)
12576 if (current_binding_level->incomplete == NULL_TREE)
12579 if (!type) /* Don't do this for class templates. */
12582 for (list = ¤t_binding_level->incomplete; *list; )
12584 tree decl = TREE_VALUE (*list);
12585 if (decl && TREE_TYPE (decl) == type
12586 || (TREE_TYPE (decl)
12587 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
12588 && TREE_TYPE (TREE_TYPE (decl)) == type))
12590 int toplevel = toplevel_bindings_p ();
12591 if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
12592 && TREE_TYPE (TREE_TYPE (decl)) == type)
12593 layout_type (TREE_TYPE (decl));
12594 layout_decl (decl, 0);
12595 rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
12599 expand_decl (decl);
12600 cleanup = maybe_build_cleanup (decl);
12601 expand_decl_init (decl);
12602 if (! cp_expand_decl_cleanup (decl, cleanup))
12603 cp_error ("parser lost in parsing declaration of `%D'",
12606 *list = TREE_CHAIN (*list);
12609 list = &TREE_CHAIN (*list);
12613 /* If DECL is of a type which needs a cleanup, build that cleanup here.
12614 We don't build cleanups if just going for syntax checking, since
12615 fixup_cleanups does not know how to not handle them.
12617 Don't build these on the momentary obstack; they must live
12618 the life of the binding contour. */
12620 maybe_build_cleanup (decl)
12623 tree type = TREE_TYPE (decl);
12624 if (TYPE_NEEDS_DESTRUCTOR (type))
12626 int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
12629 if (TREE_CODE (decl) != PARM_DECL)
12630 temp = suspend_momentary ();
12632 if (TREE_CODE (type) == ARRAY_TYPE)
12636 mark_addressable (decl);
12637 rval = build_unary_op (ADDR_EXPR, decl, 0);
12640 /* Optimize for space over speed here. */
12641 if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
12642 || flag_expensive_optimizations)
12643 flags |= LOOKUP_NONVIRTUAL;
12645 rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0);
12647 if (TYPE_USES_VIRTUAL_BASECLASSES (type)
12648 && ! TYPE_HAS_DESTRUCTOR (type))
12649 rval = build_compound_expr (tree_cons (NULL_TREE, rval,
12650 build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
12652 /* Since this is a cleanup, UNSAVE it now. */
12653 rval = unsave_expr (rval);
12655 if (TREE_CODE (decl) != PARM_DECL)
12656 resume_momentary (temp);
12663 /* Expand a C++ expression at the statement level.
12664 This is needed to ferret out nodes which have UNKNOWN_TYPE.
12665 The C++ type checker should get all of these out when
12666 expressions are combined with other, type-providing, expressions,
12667 leaving only orphan expressions, such as:
12669 &class::bar; / / takes its address, but does nothing with it.
12673 cplus_expand_expr_stmt (exp)
12676 extern int temp_slot_level;
12677 extern int target_temp_slot_level;
12678 tree old_cleanups = cleanups_this_call;
12679 int old_temp_level = target_temp_slot_level;
12680 push_temp_slots ();
12681 push_temp_slots ();
12682 target_temp_slot_level = temp_slot_level;
12684 if (TREE_TYPE (exp) == unknown_type_node)
12686 if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
12687 error ("address of overloaded function with no contextual type information");
12688 else if (TREE_CODE (exp) == COMPONENT_REF)
12689 warning ("useless reference to a member function name, did you forget the ()?");
12693 int remove_implicit_immediately = 0;
12695 if (TREE_CODE (exp) == FUNCTION_DECL)
12697 cp_warning ("reference, not call, to function `%D'", exp);
12698 warning ("at this point in file");
12702 /* We should do this eventually, but right now this causes regex.o from
12703 libg++ to miscompile, and tString to core dump. */
12704 exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp);
12706 expand_expr_stmt (break_out_cleanups (exp));
12709 /* Clean up any pending cleanups. This happens when a function call
12710 returns a cleanup-needing value that nobody uses. */
12711 expand_cleanups_to (old_cleanups);
12714 target_temp_slot_level = old_temp_level;
12715 /* There might something left from building the trees. */
12716 if (cleanups_this_call)
12718 expand_cleanups_to (NULL_TREE);
12720 free_temp_slots ();
12723 /* When a stmt has been parsed, this function is called.
12725 Currently, this function only does something within a
12726 constructor's scope: if a stmt has just assigned to this,
12727 and we are in a derived class, we call `emit_base_init'. */
12732 extern struct nesting *cond_stack, *loop_stack, *case_stack;
12735 if (current_function_assigns_this
12736 || ! current_function_just_assigned_this)
12738 if (DECL_CONSTRUCTOR_P (current_function_decl))
12740 /* Constructors must wait until we are out of control
12741 zones before calling base constructors. */
12742 if (cond_stack || loop_stack || case_stack)
12744 expand_expr_stmt (base_init_expr);
12745 check_base_init (current_class_type);
12747 current_function_assigns_this = 1;
12750 cadillac_finish_stmt ();
12753 /* Change a static member function definition into a FUNCTION_TYPE, instead
12754 of the METHOD_TYPE that we create when it's originally parsed.
12756 WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES
12757 (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of
12758 other decls. Either pass the addresses of local variables or NULL. */
12761 revert_static_member_fn (decl, fn, argtypes)
12762 tree *decl, *fn, *argtypes;
12765 tree function = fn ? *fn : TREE_TYPE (*decl);
12766 tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function);
12768 if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args))))
12769 cp_error ("static member function `%#D' declared const", *decl);
12770 if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args))))
12771 cp_error ("static member function `%#D' declared volatile", *decl);
12773 args = TREE_CHAIN (args);
12774 tmp = build_function_type (TREE_TYPE (function), args);
12775 tmp = build_type_variant (tmp, TYPE_READONLY (function),
12776 TYPE_VOLATILE (function));
12777 tmp = build_exception_variant (tmp,
12778 TYPE_RAISES_EXCEPTIONS (function));
12779 TREE_TYPE (*decl) = tmp;
12780 if (DECL_ARGUMENTS (*decl))
12781 DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl));
12782 DECL_STATIC_FUNCTION_P (*decl) = 1;
12790 id_in_current_class (id)
12793 return !!purpose_member (id, class_binding_level->class_shadowed);
12800 int warn_about_return_type;
12802 int just_assigned_this;
12804 int temp_name_counter;
12806 tree shadowed_labels;
12809 rtx last_dtor_insn;
12811 tree base_init_list;
12812 tree member_init_list;
12813 tree base_init_expr;
12817 struct cp_function *next;
12818 struct binding_level *binding_level;
12824 struct cp_function *cp_function_chain;
12826 extern int temp_name_counter;
12828 /* Save and reinitialize the variables
12829 used during compilation of a C++ function. */
12832 push_cp_function_context (context)
12835 struct cp_function *p
12836 = (struct cp_function *) xmalloc (sizeof (struct cp_function));
12838 push_function_context_to (context);
12840 p->next = cp_function_chain;
12841 cp_function_chain = p;
12843 p->named_labels = named_labels;
12844 p->shadowed_labels = shadowed_labels;
12845 p->returns_value = current_function_returns_value;
12846 p->returns_null = current_function_returns_null;
12847 p->warn_about_return_type = warn_about_return_type;
12848 p->binding_level = current_binding_level;
12849 p->ctor_label = ctor_label;
12850 p->dtor_label = dtor_label;
12851 p->last_dtor_insn = last_dtor_insn;
12852 p->assigns_this = current_function_assigns_this;
12853 p->just_assigned_this = current_function_just_assigned_this;
12854 p->parms_stored = current_function_parms_stored;
12855 p->result_rtx = original_result_rtx;
12856 p->base_init_expr = base_init_expr;
12857 p->protect_list = protect_list;
12858 p->temp_name_counter = temp_name_counter;
12859 p->base_init_list = current_base_init_list;
12860 p->member_init_list = current_member_init_list;
12861 p->class_decl = current_class_decl;
12864 p->eh_context = push_eh_context ();
12867 /* Restore the variables used during compilation of a C++ function. */
12870 pop_cp_function_context (context)
12873 struct cp_function *p = cp_function_chain;
12876 /* Bring back all the labels that were shadowed. */
12877 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
12878 if (DECL_NAME (TREE_VALUE (link)) != 0)
12879 SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)),
12880 TREE_VALUE (link));
12883 if (DECL_SAVED_INSNS (current_function_decl) == 0)
12885 /* Stop pointing to the local nodes about to be freed. */
12886 /* But DECL_INITIAL must remain nonzero so we know this
12887 was an actual function definition. */
12888 DECL_INITIAL (current_function_decl) = error_mark_node;
12889 DECL_ARGUMENTS (current_function_decl) = 0;
12893 pop_function_context_from (context);
12895 cp_function_chain = p->next;
12897 named_labels = p->named_labels;
12898 shadowed_labels = p->shadowed_labels;
12899 current_function_returns_value = p->returns_value;
12900 current_function_returns_null = p->returns_null;
12901 warn_about_return_type = p->warn_about_return_type;
12902 current_binding_level = p->binding_level;
12903 ctor_label = p->ctor_label;
12904 dtor_label = p->dtor_label;
12905 last_dtor_insn = p->last_dtor_insn;
12906 protect_list = p->protect_list;
12907 current_function_assigns_this = p->assigns_this;
12908 current_function_just_assigned_this = p->just_assigned_this;
12909 current_function_parms_stored = p->parms_stored;
12910 original_result_rtx = p->result_rtx;
12911 base_init_expr = p->base_init_expr;
12912 temp_name_counter = p->temp_name_counter;
12913 current_base_init_list = p->base_init_list;
12914 current_member_init_list = p->member_init_list;
12915 current_class_decl = p->class_decl;
12918 pop_eh_context (p->eh_context);
12923 /* FSF LOCAL dje prefix attributes */
12924 /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
12925 lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
12927 The head of the declspec list is stored in DECLSPECS.
12928 The head of the attribute list is stored in PREFIX_ATTRIBUTES.
12930 Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
12931 the list elements. We drop the containing TREE_LIST nodes and link the
12932 resulting attributes together the way decl_attributes expects them. */
12935 split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
12937 tree *declspecs, *prefix_attributes;
12939 tree t, s, a, next, specs, attrs;
12941 /* This can happen in c++ (eg: decl: typespec initdecls ';'). */
12942 if (specs_attrs != NULL_TREE
12943 && TREE_CODE (specs_attrs) != TREE_LIST)
12945 *declspecs = specs_attrs;
12946 *prefix_attributes = NULL_TREE;
12950 /* Remember to keep the lists in the same order, element-wise. */
12952 specs = s = NULL_TREE;
12953 attrs = a = NULL_TREE;
12954 for (t = specs_attrs; t; t = next)
12956 next = TREE_CHAIN (t);
12957 /* Declspecs have a non-NULL TREE_VALUE. */
12958 if (TREE_VALUE (t) != NULL_TREE)
12960 if (specs == NULL_TREE)
12964 TREE_CHAIN (s) = t;
12970 if (attrs == NULL_TREE)
12971 attrs = a = TREE_PURPOSE (t);
12974 TREE_CHAIN (a) = TREE_PURPOSE (t);
12975 a = TREE_PURPOSE (t);
12980 /* Terminate the lists. */
12981 if (s != NULL_TREE)
12982 TREE_CHAIN (s) = NULL_TREE;
12983 if (a != NULL_TREE)
12984 TREE_CHAIN (a) = NULL_TREE;
12987 *declspecs = specs;
12988 *prefix_attributes = attrs;
12991 /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
12992 This function is used by the parser when a rule will accept attributes
12993 in a particular position, but we don't want to support that just yet.
12995 A warning is issued for every ignored attribute. */
12998 strip_attrs (specs_attrs)
13003 split_specs_attrs (specs_attrs, &specs, &attrs);
13007 warning ("`%s' attribute ignored",
13008 IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
13009 attrs = TREE_CHAIN (attrs);
13014 /* END FSF LOCAL */