diff options
author | obrien <obrien@FreeBSD.org> | 1999-09-19 11:00:01 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 1999-09-19 11:00:01 +0000 |
commit | caa7271ba9ec2e12a164b399796237de1e1cf7e6 (patch) | |
tree | d634ef65b3ec009d39d7ce54527a3ad3af8c2c13 | |
parent | 4e55baf141a54399067daaae2c4421d2c37089a9 (diff) | |
download | FreeBSD-src-caa7271ba9ec2e12a164b399796237de1e1cf7e6.zip FreeBSD-src-caa7271ba9ec2e12a164b399796237de1e1cf7e6.tar.gz |
Bring BDE's printf format error fixes into EGCS.
-rw-r--r-- | contrib/gcc/cp/decl.c | 8060 | ||||
-rw-r--r-- | contrib/gcc/cp/ptree.c | 63 |
2 files changed, 4483 insertions, 3640 deletions
diff --git a/contrib/gcc/cp/decl.c b/contrib/gcc/cp/decl.c index 72aa996..79a207d 100644 --- a/contrib/gcc/cp/decl.c +++ b/contrib/gcc/cp/decl.c @@ -1,6 +1,6 @@ /* Process declarations and variables for C compiler. - Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. - Hacked by Michael Tiemann (tiemann@cygnus.com) + Copyright (C) 1988, 92-97, 1998 Free Software Foundation, Inc. + Contributed by Michael Tiemann (tiemann@cygnus.com) This file is part of GNU CC. @@ -19,6 +19,8 @@ along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* $FreeBSD$ */ + /* Process declarations and symbol lookup for C front end. Also constructs types; the standard scalar types at initialization, @@ -27,17 +29,20 @@ Boston, MA 02111-1307, USA. */ /* ??? not all decl nodes are given the most useful possible line numbers. For example, the CONST_DECLs for enum values. */ -#include <stdio.h> #include "config.h" +#include "system.h" #include "tree.h" #include "rtl.h" #include "flags.h" #include "cp-tree.h" #include "decl.h" #include "lex.h" -#include <sys/types.h> #include <signal.h> #include "obstack.h" +#include "defaults.h" +#include "output.h" +#include "except.h" +#include "toplev.h" #define obstack_chunk_alloc xmalloc #define obstack_chunk_free free @@ -45,19 +50,25 @@ Boston, MA 02111-1307, USA. */ extern tree builtin_return_address_fndecl; extern struct obstack permanent_obstack; +extern struct obstack* saveable_obstack; extern int current_class_depth; -extern tree cleanups_this_call; - extern tree static_ctors, static_dtors; +extern int static_labelno; + +extern tree current_namespace; +extern tree global_namespace; + +extern void (*print_error_function) PROTO((char *)); + /* Stack of places to restore the search obstack back to. */ /* Obstack used for remembering local class declarations (like enums and static (const) members. */ #include "stack.h" -static struct obstack decl_obstack; +struct obstack decl_obstack; static struct stack_level *decl_stack; #ifndef CHAR_TYPE_SIZE @@ -98,9 +109,9 @@ static struct stack_level *decl_stack; #ifndef BOOL_TYPE_SIZE #ifdef SLOW_BYTE_ACCESS -#define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (BITS_PER_WORD) : (BITS_PER_UNIT)) +#define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (POINTER_SIZE) : (CHAR_TYPE_SIZE)) #else -#define BOOL_TYPE_SIZE BITS_PER_UNIT +#define BOOL_TYPE_SIZE CHAR_TYPE_SIZE #endif #endif @@ -125,12 +136,54 @@ static struct stack_level *decl_stack; static tree grokparms PROTO((tree, int)); static tree lookup_nested_type PROTO((tree, tree)); static char *redeclaration_error_message PROTO((tree, tree)); -static void grok_op_properties PROTO((tree, int, int)); - -tree define_function - PROTO((char *, tree, enum built_in_function, void (*)(), char *)); +static tree push_overloaded_decl PROTO((tree, int)); + +static struct stack_level *push_decl_level PROTO((struct stack_level *, + struct obstack *)); +static void push_binding_level PROTO((struct binding_level *, int, + int)); +static void pop_binding_level PROTO((void)); +static void suspend_binding_level PROTO((void)); +static void resume_binding_level PROTO((struct binding_level *)); +static struct binding_level *make_binding_level PROTO((void)); +static int namespace_bindings_p PROTO((void)); +static void declare_namespace_level PROTO((void)); +static void signal_catch PROTO((int)); +static void storedecls PROTO((tree)); +static void storetags PROTO((tree)); +static void require_complete_types_for_parms PROTO((tree)); +static void push_overloaded_decl_1 PROTO((tree)); +static int ambi_op_p PROTO((tree)); +static int unary_op_p PROTO((tree)); +static tree store_bindings PROTO((tree, tree)); +static tree lookup_tag_reverse PROTO((tree, tree)); +static tree obscure_complex_init PROTO((tree, tree)); +static tree maybe_build_cleanup_1 PROTO((tree, tree)); +static tree lookup_name_real PROTO((tree, int, int, int)); +static void warn_extern_redeclared_static PROTO((tree, tree)); +static void grok_reference_init PROTO((tree, tree, tree)); +static tree grokfndecl PROTO((tree, tree, tree, tree, int, + enum overload_flags, tree, + tree, tree, int, int, int, int, int, int, tree)); +static tree grokvardecl PROTO((tree, tree, RID_BIT_TYPE *, int, int, tree)); +static tree lookup_tag PROTO((enum tree_code, tree, + struct binding_level *, int)); +static void set_identifier_type_value_with_scope + PROTO((tree, tree, struct binding_level *)); +static void set_identifier_local_value_with_scope + PROTO((tree, tree, struct binding_level *)); +static void record_builtin_type PROTO((enum rid, char *, tree)); +static void record_unknown_type PROTO((tree, char *)); +static int member_function_or_else PROTO((tree, tree, char *)); +static void bad_specifiers PROTO((tree, char *, int, int, int, int, + int)); +static void lang_print_error_function PROTO((char *)); + +#if defined (DEBUG_CP_BINDING_LEVELS) +static void indent PROTO((void)); +#endif -/* a node which has tree code ERROR_MARK, and whose type is itself. +/* A node which has tree code ERROR_MARK, and whose type is itself. All erroneous expressions are replaced with this node. All functions that accept nodes as arguments should avoid generating error messages if this node is one of the arguments, since it is undesirable to get @@ -168,24 +221,41 @@ tree float_type_node; tree double_type_node; tree long_double_type_node; +tree complex_integer_type_node; +tree complex_float_type_node; +tree complex_double_type_node; +tree complex_long_double_type_node; + tree intQI_type_node; tree intHI_type_node; tree intSI_type_node; tree intDI_type_node; +tree intTI_type_node; tree unsigned_intQI_type_node; tree unsigned_intHI_type_node; tree unsigned_intSI_type_node; tree unsigned_intDI_type_node; +tree unsigned_intTI_type_node; + +tree java_byte_type_node; +tree java_short_type_node; +tree java_int_type_node; +tree java_long_type_node; +tree java_float_type_node; +tree java_double_type_node; +tree java_char_type_node; +tree java_boolean_type_node; -/* a VOID_TYPE node, and the same, packaged in a TREE_LIST. */ +/* A VOID_TYPE node, and the same, packaged in a TREE_LIST. */ tree void_type_node, void_list_node; tree void_zero_node; /* Nodes for types `void *' and `const void *'. */ -tree ptr_type_node, const_ptr_type_node; +tree ptr_type_node; +tree const_ptr_type_node; /* Nodes for types `char *' and `const char *'. */ @@ -209,38 +279,33 @@ tree wchar_array_type_node; /* The bool data type, and constants */ tree boolean_type_node, boolean_true_node, boolean_false_node; -/* type `int ()' -- used for implicit declaration of functions. */ +/* Type `int ()' -- used for implicit declaration of functions. */ tree default_function_type; -/* function types `double (double)' and `double (double, double)', etc. */ +/* Function types `double (double)' and `double (double, double)', etc. */ -tree double_ftype_double, double_ftype_double_double; -tree int_ftype_int, long_ftype_long; - -/* Function type `void (void *, void *, int)' and similar ones. */ - -tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int; - -/* Function type `char *(char *, char *)' and similar ones */ -tree string_ftype_ptr_ptr, int_ftype_string_string; - -/* Function type `size_t (const char *)' */ -tree sizet_ftype_string; +static tree double_ftype_double, double_ftype_double_double; +static tree int_ftype_int, long_ftype_long; +static tree float_ftype_float; +static tree ldouble_ftype_ldouble; /* Function type `int (const void *, const void *, size_t)' */ -tree int_ftype_cptr_cptr_sizet; +static tree int_ftype_cptr_cptr_sizet; /* C++ extensions */ tree vtable_entry_type; tree delta_type_node; #if 0 -/* Old rtti stuff. */ +/* Old rtti stuff. */ tree __baselist_desc_type_node; tree __i_desc_type_node, __m_desc_type_node; tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; #endif -tree __t_desc_type_node, __tp_desc_type_node; +tree __t_desc_type_node; +#if 0 +tree __tp_desc_type_node; +#endif tree __access_mode_type_node; tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node; tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node; @@ -252,21 +317,44 @@ tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type; tree __ptmf_desc_array_type, __ptmd_desc_array_type; #endif +/* Indicates that there is a type value in some namespace, although + that is not necessarily in scope at the moment. */ + +static tree global_type_node; + tree class_star_type_node; tree class_type_node, record_type_node, union_type_node, enum_type_node; tree unknown_type_node; tree opaque_type_node, signature_type_node; tree sigtable_entry_type; -tree maybe_gc_cleanup; /* Array type `vtable_entry_type[]' */ tree vtbl_type_node; +/* namespace std */ +tree std_node; +int in_std = 0; + +/* Expect only namespace names now. */ +static int only_namespace_names; + /* In a destructor, the point at which all derived class destroying has been done, just before any base class destroying will be done. */ tree dtor_label; +/* In a destructor, the last insn emitted after the start of the + function and the parms. */ + +static rtx last_dtor_insn; + +/* In a constructor, the last insn emitted after the start of the + function and the parms, the exception specification and any + function-try-block. The constructor initializers are emitted after + this insn. */ + +static rtx last_parm_cleanup_insn; + /* In a constructor, the point at which we are ready to return the pointer to the initialized object. */ @@ -284,7 +372,7 @@ extern rtx cleanup_label, return_label; but due to being an addressable named return value, would up on the stack, this variable holds the named return value's original location. */ -rtx original_result_rtx; +static rtx original_result_rtx; /* Sequence of insns which represents base initialization. */ tree base_init_expr; @@ -293,23 +381,40 @@ tree base_init_expr; Identifiers for `this' in member functions and the auto-delete parameter for destructors. */ tree this_identifier, in_charge_identifier; -/* Used in pointer to member functions, in vtables, and in sigtables. */ +tree ctor_identifier, dtor_identifier; +/* Used in pointer to member functions, in vtables, and in sigtables. */ tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier; tree pfn_or_delta2_identifier, tag_identifier; -tree vb_off_identifier, vt_off_identifier; +tree vt_off_identifier; + +struct named_label_list +{ + struct binding_level *binding_level; + tree names_in_scope; + tree label_decl; + char *filename_o_goto; + int lineno_o_goto; + struct named_label_list *next; +}; /* A list (chain of TREE_LIST nodes) of named label uses. The TREE_PURPOSE field is the list of variables defined - the the label's scope defined at the point of use. + in the label's scope defined at the point of use. The TREE_VALUE field is the LABEL_DECL used. The TREE_TYPE field holds `current_binding_level' at the point of the label's use. + BWAHAHAAHAHahhahahahaah. No, no, no, said the little chicken. + + Look at the pretty struct named_label_list. See the pretty struct + with the pretty named fields that describe what they do. See the + pretty lack of gratuitous casts. Notice the code got a lot cleaner. + Used only for jumps to as-yet undefined labels, since jumps to defined labels can have their validity checked by stmt.c. */ -static tree named_label_uses; +static struct named_label_list *named_label_uses = NULL; /* A list of objects which have constructors or destructors which reside in the global scope. The decl is stored in @@ -325,17 +430,14 @@ tree static_aggregates; tree integer_zero_node; tree null_pointer_node; -/* A node for the integer constants 1, 2, and 3. */ +/* The value for __null (NULL), either of type `void *' or, with -ansi, + an integer type of the same size. */ -tree integer_one_node, integer_two_node, integer_three_node; +tree null_node; -/* Nonzero if we have seen an invalid cross reference - to a struct, union, or enum, but not yet printed the message. */ +/* A node for the integer constants 1, 2, and 3. */ -tree pending_invalid_xref; -/* File and line to appear in the eventual error message. */ -char *pending_invalid_xref_file; -int pending_invalid_xref_line; +tree integer_one_node, integer_two_node, integer_three_node; /* While defining an enum type, this is 1 plus the last enumerator constant value. */ @@ -375,13 +477,6 @@ static tree named_labels; static tree shadowed_labels; -#if 0 /* Not needed by C++ */ -/* Nonzero when store_parm_decls is called indicates a varargs function. - Value not meaningful after store_parm_decls. */ - -static int c_function_varargs; -#endif - /* The FUNCTION_DECL for the function currently being compiled, or 0 if between functions. */ tree current_function_decl; @@ -427,7 +522,7 @@ extern int flag_no_nonansi_builtin; extern int flag_ansi; /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) - objects. */ + objects. */ extern int flag_huge_objects; /* Nonzero if we want to conserve space in the .o files. We do this @@ -445,7 +540,7 @@ extern tree *current_lang_base, *current_lang_stack; /* Set to 0 at beginning of a constructor, set to 1 if that function does an allocation before referencing its instance variable. */ -int current_function_assigns_this; +static int current_function_assigns_this; int current_function_just_assigned_this; /* Set to 0 at beginning of a function. Set non-zero when @@ -453,14 +548,6 @@ int current_function_just_assigned_this; if this flag is non-zero! */ int current_function_parms_stored; -/* Current end of entries in the gc obstack for stack pointer variables. */ - -int current_function_obstack_index; - -/* Flag saying whether we have used the obstack in this function or not. */ - -int current_function_obstack_usage; - /* Flag used when debugging spew.c */ extern int spew_debug; @@ -470,8 +557,14 @@ extern int spew_debug; when entering another class scope (i.e. a cache miss). */ extern tree previous_class_values; +/* A expression of value 0 with the same precision as a sizetype + node, but signed. */ +tree signed_size_zero_node; + /* Allocate a level of searching. */ + +static struct stack_level * push_decl_level (stack, obstack) struct stack_level *stack; @@ -484,24 +577,22 @@ push_decl_level (stack, obstack) } /* For each binding contour we allocate a binding_level structure - * which records the names defined in that contour. - * Contours include: - * 0) the global one - * 1) one for each function definition, - * where internal declarations of the parameters appear. - * 2) one for each compound statement, - * to record its declarations. - * - * The current meaning of a name can be found by searching the levels from - * the current one out to the global one. - * - * Off to the side, may be the class_binding_level. This exists - * only to catch class-local declarations. It is otherwise - * nonexistent. - * - * Also there may be binding levels that catch cleanups that - * must be run when exceptions occur. - */ + which records the names defined in that contour. + Contours include: + 0) the global one + 1) one for each function definition, + where internal declarations of the parameters appear. + 2) one for each compound statement, + to record its declarations. + + The current meaning of a name can be found by searching the levels + from the current one out to the global one. + + Off to the side, may be the class_binding_level. This exists only + to catch class-local declarations. It is otherwise nonexistent. + + Also there may be binding levels that catch cleanups that must be + run when exceptions occur. */ /* Note that the information in the `names' component of the global contour is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ @@ -509,21 +600,27 @@ push_decl_level (stack, obstack) struct binding_level { /* A chain of _DECL nodes for all variables, constants, functions, - * and typedef types. These are in the reverse of the order supplied. - */ + and typedef types. These are in the reverse of the order + supplied. */ tree names; - /* A list of structure, union and enum definitions, - * for looking up tag names. - * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, - * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, - * or ENUMERAL_TYPE node. - * - * C++: the TREE_VALUE nodes can be simple types for component_bindings. - * - */ + /* A list of structure, union and enum definitions, for looking up + tag names. + It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, + or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, + or ENUMERAL_TYPE node. + + C++: the TREE_VALUE nodes can be simple types for + component_bindings. */ tree tags; + /* A list of USING_DECL nodes. */ + tree usings; + + /* A list of used namespaces. PURPOSE is the namespace, + VALUE the common ancestor with this binding_level's namespace. */ + tree using_directives; + /* For each level, a list of shadowed outer-level local definitions to be restored when this level is popped. Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and @@ -554,7 +651,7 @@ struct binding_level /* List of VAR_DECLS saved from a previous for statement. These would be dead in ANSI-conforming code, but might - be referenced in traditional code. */ + be referenced in ARM-era code. */ tree dead_vars_from_for; /* 1 for the level that holds the parameters of a function. @@ -574,24 +671,19 @@ struct binding_level unsigned more_cleanups_ok : 1; unsigned have_cleanups : 1; - /* Nonzero if we should accept any name as an identifier in - this scope. This happens in some template definitions. */ - unsigned accept_any : 1; - - /* Nonzero if this level is for completing a template class definition - inside a binding level that temporarily binds the parameters. This - means that definitions here should not be popped off when unwinding - this binding level. (Not actually implemented this way, - unfortunately.) */ + /* Nonzero if this level is for storing the decls for template + parameters and generic decls; these decls will be discarded and + replaced with a TEMPLATE_DECL. */ unsigned pseudo_global : 1; /* This is set for a namespace binding level. */ unsigned namespace_p : 1; - /* True if this level is that of a for-statement. */ + /* True if this level is that of a for-statement where we need to + worry about ambiguous (ARM or ANSI) scope rules. */ unsigned is_for_scope : 1; - /* One bit left for this word. */ + /* Two bits left for this word. */ #if defined(DEBUG_CP_BINDING_LEVELS) /* Binding depth at which this level began. */ @@ -687,7 +779,7 @@ pop_binding_level () if (global_binding_level) { - /* cannot pop a level, if there are none left to pop. */ + /* Cannot pop a level, if there are none left to pop. */ if (current_binding_level == global_binding_level) my_friendly_abort (123); } @@ -699,14 +791,10 @@ pop_binding_level () (is_class_level) ? "class" : "block", current_binding_level, lineno); if (is_class_level != (current_binding_level == class_binding_level)) -#if 0 /* XXX Don't abort when we're watching how things are being managed. */ - abort (); -#else - { - indent (); - fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); - } -#endif + { + indent (); + fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); + } is_class_level = 0; #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ { @@ -735,7 +823,7 @@ suspend_binding_level () if (global_binding_level) { - /* cannot suspend a level, if there are none left to suspend. */ + /* Cannot suspend a level, if there are none left to suspend. */ if (current_binding_level == global_binding_level) my_friendly_abort (123); } @@ -747,24 +835,14 @@ suspend_binding_level () (is_class_level) ? "class" : "block", current_binding_level, lineno); if (is_class_level != (current_binding_level == class_binding_level)) -#if 0 /* XXX Don't abort when we're watching how things are being managed. */ - abort (); -#else - { - indent (); - fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); - } -#endif + { + indent (); + fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); + } is_class_level = 0; #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ { - register struct binding_level *level = current_binding_level; current_binding_level = current_binding_level->level_chain; -#if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */ - if (level->binding_depth != binding_depth) - abort (); -#endif /* defined(DEBUG_CP_BINDING_LEVELS) */ - class_binding_level = current_binding_level; if (class_binding_level->parm_flag != 2) class_binding_level = 0; @@ -773,33 +851,15 @@ suspend_binding_level () } } -void +static void resume_binding_level (b) struct binding_level *b; { - if (class_binding_level) - { -#if 1 - /* These are here because we cannot deal with shadows yet. */ - sorry ("cannot resume a namespace inside class"); - return; -#else - b->level_chain = class_binding_level; - class_binding_level = (struct binding_level *)0; -#endif - } - else - { -#if 1 - /* These are here because we cannot deal with shadows yet. */ - if (b->level_chain != current_binding_level) - { - sorry ("cannot resume a namespace inside a different namespace"); - return; - } -#endif - b->level_chain = current_binding_level; - } + /* Resuming binding levels is meant only for namespaces, + and those cannot nest into classes. */ + my_friendly_assert(!class_binding_level, 386); + /* Also, resuming a non-directly nested namespace is a no-no. */ + my_friendly_assert(b->level_chain == current_binding_level, 386); current_binding_level = b; #if defined(DEBUG_CP_BINDING_LEVELS) b->binding_depth = binding_depth; @@ -811,6 +871,16 @@ resume_binding_level (b) #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ } +/* Create a new `struct binding_level'. */ + +static +struct binding_level * +make_binding_level () +{ + /* NOSTRICT */ + return (struct binding_level *) xmalloc (sizeof (struct binding_level)); +} + /* Nonzero if we are currently in the global binding level. */ int @@ -821,26 +891,20 @@ global_bindings_p () /* Nonzero if we are currently in a toplevel binding level. This means either the global binding level or a namespace in a toplevel - binding level. */ + binding level. + Since there are no non-toplevel namespace levels, this really + means any namespace or pseudo-global level. */ int toplevel_bindings_p () { - struct binding_level *b = current_binding_level; - - while (1) - { - if (b == global_binding_level) - return 1; - if (! b->namespace_p) - return 0; - b=b->level_chain; - } + return current_binding_level->namespace_p + || current_binding_level->pseudo_global; } /* Nonzero if this is a namespace scope. */ -int +static int namespace_bindings_p () { return current_binding_level->namespace_p; @@ -873,24 +937,12 @@ declare_parm_level () } void -declare_uninstantiated_type_level () -{ - current_binding_level->accept_any = 1; -} - -int -uninstantiated_type_level_p () -{ - return current_binding_level->accept_any; -} - -void declare_pseudo_global_level () { current_binding_level->pseudo_global = 1; } -void +static void declare_namespace_level () { current_binding_level->namespace_p = 1; @@ -939,15 +991,15 @@ pushlevel (tag_transparent) } else { - /* Create a new `struct binding_level'. */ - newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level)); + newlevel = make_binding_level (); } + push_binding_level (newlevel, tag_transparent, keep_next_level_flag); GNU_xref_start_scope ((HOST_WIDE_INT) newlevel); keep_next_level_flag = 0; } -int +void note_level_for_for () { current_binding_level->is_for_scope = 1; @@ -1000,7 +1052,6 @@ poplevel (keep, reverse, functionbody) Put it into forward order, just for cleanliness. */ tree decls; int tmp = functionbody; - int implicit_try_block = current_binding_level->parm_flag == 3; int real_functionbody = current_binding_level->keep == 2 ? ((functionbody = 0), tmp) : functionbody; tree tags = functionbody >= 0 ? current_binding_level->tags : 0; @@ -1012,41 +1063,11 @@ poplevel (keep, reverse, functionbody) GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, (HOST_WIDE_INT) current_binding_level->level_chain, current_binding_level->parm_flag, - current_binding_level->keep, - current_binding_level->tag_transparent); + current_binding_level->keep); if (current_binding_level->keep == 1) keep = 1; - /* This warning is turned off because it causes warnings for - declarations like `extern struct foo *x'. */ -#if 0 - /* Warn about incomplete structure types in this level. */ - for (link = tags; link; link = TREE_CHAIN (link)) - if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE) - { - tree type = TREE_VALUE (link); - char *errmsg; - switch (TREE_CODE (type)) - { - case RECORD_TYPE: - errmsg = "`struct %s' incomplete in scope ending here"; - break; - case UNION_TYPE: - errmsg = "`union %s' incomplete in scope ending here"; - break; - case ENUMERAL_TYPE: - errmsg = "`enum %s' incomplete in scope ending here"; - break; - } - if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) - error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type))); - else - /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL. */ - error (errmsg, TYPE_NAME_STRING (type)); - } -#endif /* 0 */ - /* Get the decls in the order they were written. Usually current_binding_level->names is in reverse order. But parameter decls were previously put in forward order. */ @@ -1092,15 +1113,35 @@ poplevel (keep, reverse, functionbody) block = make_node (BLOCK); if (block != NULL_TREE) { - BLOCK_VARS (block) = decls; - BLOCK_TYPE_TAGS (block) = tags; - BLOCK_SUBBLOCKS (block) = subblocks; - /* If we created the block earlier on, and we are just diddling it now, - then it already should have a proper BLOCK_END_NOTE value associated - with it, so avoid trashing that. Otherwise, for a new block, install - a new BLOCK_END_NOTE value. */ - if (! block_previously_created) - remember_end_note (block); + if (block_previously_created) + { + if (decls || tags || subblocks) + { + if (BLOCK_VARS (block) || BLOCK_TYPE_TAGS (block)) + { + warning ("internal compiler error: debugging info corrupted"); + } + BLOCK_VARS (block) = decls; + BLOCK_TYPE_TAGS (block) = tags; + + /* We can have previous subblocks and new subblocks when + doing fixup_gotos with complex cleanups. We chain the new + subblocks onto the end of any pre-existing subblocks. */ + BLOCK_SUBBLOCKS (block) = chainon (BLOCK_SUBBLOCKS (block), + subblocks); + } + /* If we created the block earlier on, and we are just + diddling it now, then it already should have a proper + BLOCK_END_NOTE value associated with it. */ + } + else + { + BLOCK_VARS (block) = decls; + BLOCK_TYPE_TAGS (block) = tags; + BLOCK_SUBBLOCKS (block) = subblocks; + /* Otherwise, for a new block, install a new BLOCK_END_NOTE value. */ + remember_end_note (block); + } } /* In each subblock, record that this is its superior. */ @@ -1111,26 +1152,38 @@ poplevel (keep, reverse, functionbody) /* Clear out the meanings of the local variables of this level. */ - for (link = current_binding_level->dead_vars_from_for; - link != NULL_TREE; link = TREE_CHAIN (link)) - { - if (DECL_DEAD_FOR_LOCAL (link)) - { - tree id = DECL_NAME (link); - if (IDENTIFIER_LOCAL_VALUE (id) == link) - IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link); - } - } - if (current_binding_level->is_for_scope && flag_new_for_scope == 1) { + struct binding_level *outer = current_binding_level->level_chain; for (link = decls; link; link = TREE_CHAIN (link)) { if (TREE_CODE (link) == VAR_DECL) DECL_DEAD_FOR_LOCAL (link) = 1; + else + IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; + } + + /* Save declarations made in a 'for' statement so we can support pre-ANSI + 'for' scoping semantics. */ + + for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) + { + tree id = TREE_PURPOSE (link); + tree decl = IDENTIFIER_LOCAL_VALUE (id); + + if (decl && DECL_DEAD_FOR_LOCAL (decl)) + { + /* In this case keep the dead for-decl visible, + but remember what (if anything) it shadowed. */ + DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link); + TREE_CHAIN (decl) = outer->dead_vars_from_for; + outer->dead_vars_from_for = decl; + } + else + IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link); } } - else + else /* Not special for scope. */ { for (link = decls; link; link = TREE_CHAIN (link)) { @@ -1148,50 +1201,42 @@ poplevel (keep, reverse, functionbody) IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; } } - } - /* Restore all name-meanings of the outer levels - that were shadowed by this level. */ + /* Restore all name-meanings of the outer levels + that were shadowed by this level. */ - if (current_binding_level->is_for_scope && flag_new_for_scope == 1) - { - struct binding_level *outer = current_binding_level->level_chain; - for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) + for (link = current_binding_level->shadowed; + link; link = TREE_CHAIN (link)) + IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + + /* We first restore the regular decls and *then* the dead_vars_from_for + to handle this case: + + int i; // i#1 + { + for (int i; ; ) { ...} // i#2 + int i; // i#3 + } // we are here + + In this case, we want remove the binding for i#3, restoring + that of i#2. Then we want to remove the binding for i#2, + and restore that of i#1. */ + + link = current_binding_level->dead_vars_from_for; + for (; link != NULL_TREE; link = TREE_CHAIN (link)) { - tree id = TREE_PURPOSE (link); - tree decl = IDENTIFIER_LOCAL_VALUE (id); - if (DECL_DEAD_FOR_LOCAL (decl)) - DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link); - else - IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link); + tree id = DECL_NAME (link); + if (IDENTIFIER_LOCAL_VALUE (id) == link) + IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link); } - /* Save declarations made in a 'for' statement so we can support pre-ANSI - 'for' scoping semantics. */ - - /* We append the current names of for-variables to those from previous - declarations, so that when we get around to do an poplevel - on the OUTER level, we restore the any shadowed readl bindings. - Note that the new names are put first on the combined list, - so they get to be restored first. This is important if there are - two for-loops using the same for-variable in the same block. - The binding we really want restored is whatever binding was shadowed - by the *first* for-variable, not the binding shadowed by the - second for-variable (which would be the first for-variable). */ - outer->dead_vars_from_for - = chainon (current_binding_level->names, outer->dead_vars_from_for); + for (link = current_binding_level->class_shadowed; + link; link = TREE_CHAIN (link)) + IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + for (link = current_binding_level->type_shadowed; + link; link = TREE_CHAIN (link)) + SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link)); } - else - { - for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) - IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); - } - for (link = current_binding_level->class_shadowed; - link; link = TREE_CHAIN (link)) - IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); - for (link = current_binding_level->type_shadowed; - link; link = TREE_CHAIN (link)) - IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); /* If the level being exited is the top level of a function, check over all the labels. */ @@ -1238,12 +1283,12 @@ poplevel (keep, reverse, functionbody) level_chain = current_binding_level->level_chain; if (level_chain) { - tree labels; - for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels)) - if (TREE_TYPE (labels) == (tree)current_binding_level) + struct named_label_list *labels; + for (labels = named_label_uses; labels; labels = labels->next) + if (labels->binding_level == current_binding_level) { - TREE_TYPE (labels) = (tree)level_chain; - TREE_PURPOSE (labels) = level_chain->names; + labels->binding_level = level_chain; + labels->names_in_scope = level_chain->names; } } } @@ -1277,11 +1322,6 @@ poplevel (keep, reverse, functionbody) /* Take care of compiler's internal binding structures. */ if (tmp == 2) { -#if 0 - /* We did not call push_momentary for this - binding contour, so there is nothing to pop. */ - pop_momentary (); -#endif expand_end_bindings (getdecls (), keep, 1); /* Each and every BLOCK node created here in `poplevel' is important (e.g. for proper debugging information) so if we created one @@ -1299,31 +1339,6 @@ poplevel (keep, reverse, functionbody) return block; } -/* Resume a binding level for a namespace. */ -void -resume_level (b) - struct binding_level *b; -{ - tree decls, link; - - resume_binding_level (b); - - /* Resume the variable caches. */ - decls = current_binding_level->names; - - /* Restore the meanings of the local variables of this level. */ - - for (link = decls; link; link = TREE_CHAIN (link)) - { - if (DECL_NAME (link) != NULL_TREE) - IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link; - - /* If this is a TYPE_DECL, push it into the type value slot. */ - if (TREE_CODE (link) == TYPE_DECL) - SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link)); - } -} - /* Delete the node BLOCK from the current binding level. This is used for the block inside a stmt expr ({...}) so that the block can be reinserted where appropriate. */ @@ -1361,15 +1376,6 @@ insert_block (block) = chainon (current_binding_level->blocks, block); } -/* Add BLOCK to the current list of blocks for this binding contour. */ -void -add_block_current_level (block) - tree block; -{ - current_binding_level->blocks - = chainon (current_binding_level->blocks, block); -} - /* Set the BLOCK node for the innermost scope (the one we are currently in). */ @@ -1381,6 +1387,7 @@ set_block (block) } /* Do a pushlevel for class declarations. */ + void pushlevel_class () { @@ -1398,8 +1405,7 @@ pushlevel_class () } else { - /* Create a new `struct binding_level'. */ - newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level)); + newlevel = make_binding_level (); } #if defined(DEBUG_CP_BINDING_LEVELS) @@ -1423,6 +1429,7 @@ pushlevel_class () /* ...and a poplevel for class declarations. FORCE is used to force clearing out of CLASS_VALUEs after a class definition. */ + tree poplevel_class (force) int force; @@ -1449,22 +1456,24 @@ poplevel_class (force) else /* Remember to save what IDENTIFIER's were bound in this scope so we can recover from cache misses. */ - previous_class_values = class_binding_level->class_shadowed; + { + previous_class_type = current_class_type; + previous_class_values = class_binding_level->class_shadowed; + } for (shadowed = level->type_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) - IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed); + SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed), TREE_VALUE (shadowed)); GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level, (HOST_WIDE_INT) class_binding_level->level_chain, class_binding_level->parm_flag, - class_binding_level->keep, - class_binding_level->tag_transparent); + class_binding_level->keep); if (class_binding_level->parm_flag != 2) class_binding_level = (struct binding_level *)0; - /* Now, pop out of the the binding level which we created up in the + /* Now, pop out of the binding level which we created up in the `pushlevel_class' routine. */ #if defined(DEBUG_CP_BINDING_LEVELS) is_class_level = 1; @@ -1476,8 +1485,8 @@ poplevel_class (force) } /* For debugging. */ -int no_print_functions = 0; -int no_print_builtins = 0; +static int no_print_functions = 0; +static int no_print_builtins = 0; void print_binding_level (lvl) @@ -1502,11 +1511,11 @@ print_binding_level (lvl) /* We can probably fit 3 names to a line? */ for (t = lvl->names; t; t = TREE_CHAIN (t)) { - if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL)) + if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL)) continue; if (no_print_builtins - && (TREE_CODE(t) == TYPE_DECL) - && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>"))) + && (TREE_CODE (t) == TYPE_DECL) + && (!strcmp (DECL_SOURCE_FILE (t),"<built-in>"))) continue; /* Function decls tend to have longer names. */ @@ -1521,7 +1530,7 @@ print_binding_level (lvl) i = len; } print_node_brief (stderr, "", t, 0); - if (TREE_CODE (t) == ERROR_MARK) + if (t == error_mark_node) break; } if (i) @@ -1585,17 +1594,7 @@ print_binding_level (lvl) fprintf (stderr, " type-shadowed:"); for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t)) { -#if 0 - fprintf (stderr, "\n\t"); - print_node_brief (stderr, "<", TREE_PURPOSE (t), 0); - if (TREE_VALUE (t)) - print_node_brief (stderr, " ", TREE_VALUE (t), 0); - else - fprintf (stderr, " (none)"); - fprintf (stderr, ">"); -#else fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); -#endif } fprintf (stderr, "\n"); } @@ -1643,148 +1642,247 @@ print_binding_stack () print_binding_level (global_binding_level); } -extern char * first_global_object_name; +/* Namespace binding access routines: The namespace_bindings field of + the identifier is polymorphic, with three possible values: + NULL_TREE, a list of CPLUS_BINDINGS, or any other tree_node + indicating the BINDING_VALUE of global_namespace. */ + +/* Check whether the a binding for the name to scope is known. + Assumes that the bindings of the name are already a list + of bindings. Returns the binding found, or NULL_TREE. */ -/* Get a unique name for each call to this routine for unnamed namespaces. - Mostly copied from get_file_function_name. */ static tree -get_unique_name () +find_binding (name, scope) + tree name; + tree scope; { - static int temp_name_counter = 0; - char *buf; - register char *p; - - if (first_global_object_name) - p = first_global_object_name; - else if (main_input_filename) - p = main_input_filename; - else - p = input_filename; + tree iter, prev = NULL_TREE; -#define UNNAMED_NAMESPACE_FORMAT "__%s_%d" + scope = ORIGINAL_NAMESPACE (scope); + + for (iter = IDENTIFIER_NAMESPACE_BINDINGS (name); iter; + iter = TREE_CHAIN (iter)) + { + my_friendly_assert (TREE_CODE (iter) == CPLUS_BINDING, 374); + if (BINDING_SCOPE (iter) == scope) + { + /* Move binding found to the fron of the list, so + subsequent lookups will find it faster. */ + if (prev) + { + TREE_CHAIN (prev) = TREE_CHAIN (iter); + TREE_CHAIN (iter) = IDENTIFIER_NAMESPACE_BINDINGS (name); + IDENTIFIER_NAMESPACE_BINDINGS (name) = iter; + } + return iter; + } + prev = iter; + } + return NULL_TREE; +} - buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p)); +/* Always returns a binding for name in scope. If the + namespace_bindings is not a list, convert it to one first. + If no binding is found, make a new one. */ - sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++); +tree +binding_for_name (name, scope) + tree name; + tree scope; +{ + tree b = IDENTIFIER_NAMESPACE_BINDINGS (name); + tree result; - /* Don't need to pull weird characters out of global names. */ - if (p != first_global_object_name) + scope = ORIGINAL_NAMESPACE (scope); + + if (b && TREE_CODE (b) != CPLUS_BINDING) { - for (p = buf+11; *p; p++) - if (! ((*p >= '0' && *p <= '9') -#if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */ -#ifndef ASM_IDENTIFY_GCC /* this is required if `.' is invalid -- k. raeburn */ - || *p == '.' -#endif -#endif -#ifndef NO_DOLLAR_IN_LABEL /* this for `$'; unlikely, but... -- kr */ - || *p == '$' -#endif -#ifndef NO_DOT_IN_LABEL /* this for `.'; unlikely, but... */ - || *p == '.' -#endif - || (*p >= 'A' && *p <= 'Z') - || (*p >= 'a' && *p <= 'z'))) - *p = '_'; + /* Get rid of optimization for global scope. */ + IDENTIFIER_NAMESPACE_BINDINGS (name) = NULL_TREE; + BINDING_VALUE (binding_for_name (name, global_namespace)) = b; + b = IDENTIFIER_NAMESPACE_BINDINGS (name); } + if (b && (result = find_binding (name, scope))) + return result; + /* Not found, make a new permanent one. */ + push_obstacks (&permanent_obstack, &permanent_obstack); + result = make_node (CPLUS_BINDING); + TREE_CHAIN (result) = b; + IDENTIFIER_NAMESPACE_BINDINGS (name) = result; + BINDING_SCOPE (result) = scope; + BINDING_TYPE (result) = NULL_TREE; + BINDING_VALUE (result) = NULL_TREE; + pop_obstacks (); + return result; +} - return get_identifier (buf); +/* Return the binding value for name in scope, considering that + namespace_binding may or may not be a list of CPLUS_BINDINGS. */ + +tree +namespace_binding (name, scope) + tree name; + tree scope; +{ + tree b = IDENTIFIER_NAMESPACE_BINDINGS (name); + if (b == NULL_TREE) + return NULL_TREE; + if (scope == NULL_TREE) + scope = global_namespace; + if (TREE_CODE (b) != CPLUS_BINDING) + return (scope == global_namespace) ? b : NULL_TREE; + name = find_binding (name,scope); + if (name == NULL_TREE) + return name; + return BINDING_VALUE (name); } -/* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we - select a name that is unique to this compilation unit. */ +/* Set the binding value for name in scope. If modifying the binding + of global_namespace is attempted, try to optimize it. */ + void -push_namespace (name) +set_namespace_binding (name, scope, val) tree name; + tree scope; + tree val; { - extern tree current_namespace; - tree old_id = get_namespace_id (); - char *buf; - tree d = make_node (NAMESPACE_DECL); + tree b; - if (! name) + if (scope == NULL_TREE) + scope = global_namespace; + + if (scope == global_namespace) { - /* Create a truly ugly name! */ - name = get_unique_name (); + b = IDENTIFIER_NAMESPACE_BINDINGS (name); + if (b == NULL_TREE || TREE_CODE (b) != CPLUS_BINDING) + { + IDENTIFIER_NAMESPACE_BINDINGS (name) = val; + return; + } } + b = binding_for_name (name, scope); + BINDING_VALUE (b) = val; +} - DECL_NAME (d) = name; - DECL_ASSEMBLER_NAME (d) = name; - /* pushdecl wants to check the size of it to see if it is incomplete... */ - TREE_TYPE (d) = void_type_node; - /* Mark them as external, so redeclaration_error_message doesn't think - they are duplicates. */ - DECL_EXTERNAL (d) = 1; - d = pushdecl (d); +/* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we + select a name that is unique to this compilation unit. */ - if (NAMESPACE_LEVEL (d) == 0) - { - /* This is new for this compilation unit. */ - pushlevel (0); - declare_namespace_level (); - NAMESPACE_LEVEL (d) = (tree)current_binding_level; +void +push_namespace (name) + tree name; +{ + tree d; + int need_new = 1; + int implicit_use = 0; + int global = 0; + if (!global_namespace) + { + /* This must be ::. */ + my_friendly_assert (name == get_identifier ("::"), 377); + global = 1; + } + else if (!name) + { + /* The name of anonymous namespace is unique for the translation + unit. */ + static tree anon_name = NULL_TREE; + if (!anon_name) + anon_name = get_file_function_name ('N'); + name = anon_name; + d = IDENTIFIER_NAMESPACE_VALUE (name); + if (d) + /* Reopening anonymous namespace. */ + need_new = 0; + implicit_use = 1; + } + else if (current_namespace == global_namespace + && name == DECL_NAME (std_node)) + { + in_std++; + return; } else { - resume_level ((struct binding_level*)NAMESPACE_LEVEL (d)); + /* Check whether this is an extended namespace definition. */ + d = IDENTIFIER_NAMESPACE_VALUE (name); + if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL) + { + need_new = 0; + if (DECL_NAMESPACE_ALIAS (d)) + { + cp_error ("namespace alias `%D' not allowed here, assuming `%D'", + d, DECL_NAMESPACE_ALIAS (d)); + d = DECL_NAMESPACE_ALIAS (d); + } + } } + + if (need_new) + { + /* Make a new namespace, binding the name to it. */ + d = build_lang_decl (NAMESPACE_DECL, name, void_type_node); + /* The global namespace is not pushed, and the global binding + level is set elsewhere. */ + if (!global) + { + d = pushdecl (d); + pushlevel (0); + declare_namespace_level (); + NAMESPACE_LEVEL (d) = current_binding_level; + } + } + else + resume_binding_level (NAMESPACE_LEVEL (d)); - /* This code is just is bit old now... */ - current_namespace = tree_cons (NULL_TREE, name, current_namespace); - buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0) - + IDENTIFIER_LENGTH (name)); - sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "", - IDENTIFIER_POINTER (name)); - TREE_PURPOSE (current_namespace) = get_identifier (buf); + if (implicit_use) + do_using_directive (d); + /* Enter the name space. */ + current_namespace = d; } /* Pop from the scope of the current namespace. */ + void pop_namespace () { - extern tree current_namespace; - tree decls, link; - current_namespace = TREE_CHAIN (current_namespace); - - /* Just in case we get out of sync. */ - if (! namespace_bindings_p ()) - poplevel (0, 0, 0); + if (current_namespace == global_namespace) + { + my_friendly_assert (in_std>0, 980421); + in_std--; + return; + } + current_namespace = CP_DECL_CONTEXT (current_namespace); + /* The binding level is not popped, as it might be re-opened later. */ + suspend_binding_level (); +} - decls = current_binding_level->names; +/* Concatenate the binding levels of all namespaces. */ - /* Clear out the meanings of the local variables of this level. */ +void +cat_namespace_levels() +{ + tree current; + tree last; + struct binding_level *b; - for (link = decls; link; link = TREE_CHAIN (link)) + last = NAMESPACE_LEVEL (global_namespace) -> names; + /* The nested namespaces appear in the names list of their ancestors. */ + for (current = last; current; current = TREE_CHAIN (current)) { - if (DECL_NAME (link) != NULL_TREE) + if (TREE_CODE (current) != NAMESPACE_DECL + || DECL_NAMESPACE_ALIAS (current)) + continue; + if (!DECL_LANG_SPECIFIC (current)) { - /* If the ident. was used or addressed via a local extern decl, - don't forget that fact. */ - if (DECL_EXTERNAL (link)) - { - if (TREE_USED (link)) - TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1; - if (TREE_ADDRESSABLE (link)) - TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1; - } - IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE; + /* Hmm. std. */ + my_friendly_assert (current == std_node, 393); + continue; } + b = NAMESPACE_LEVEL (current); + while (TREE_CHAIN (last)) + last = TREE_CHAIN (last); + TREE_CHAIN (last) = NAMESPACE_LEVEL (current) -> names; } - - /* Restore all name-meanings of the outer levels - that were shadowed by this level. */ - - for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link)) - IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); - for (link = current_binding_level->class_shadowed; - link; link = TREE_CHAIN (link)) - IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); - for (link = current_binding_level->type_shadowed; - link; link = TREE_CHAIN (link)) - IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); - - /* suspend a level. */ - suspend_binding_level (); } /* Subroutines for reverting temporarily to top-level for instantiation @@ -1795,107 +1893,166 @@ pop_namespace () struct saved_scope { struct binding_level *old_binding_level; tree old_bindings; + tree old_namespace; struct saved_scope *prev; tree class_name, class_type, function_decl; - tree base_init_list, member_init_list; struct binding_level *class_bindings; - tree previous_class_type; tree *lang_base, *lang_stack, lang_name; int lang_stacksize; - tree named_labels; + int minimal_parse_mode; + tree last_function_parms; + tree template_parms; + HOST_WIDE_INT processing_template_decl; + tree previous_class_type, previous_class_values; + int processing_specialization; + int processing_explicit_instantiation; }; static struct saved_scope *current_saved_scope; -extern tree prev_class_type; + +/* A chain of the binding vecs created by store_bindings. We create a + whole bunch of these during compilation, on permanent_obstack, so we + can't just throw them away. */ +static tree free_binding_vecs; + +static tree +store_bindings (names, old_bindings) + tree names, old_bindings; +{ + tree t; + for (t = names; t; t = TREE_CHAIN (t)) + { + tree binding, t1, id; + + if (TREE_CODE (t) == TREE_LIST) + id = TREE_PURPOSE (t); + else + id = DECL_NAME (t); + + if (!id + || (!IDENTIFIER_LOCAL_VALUE (id) + && !IDENTIFIER_CLASS_VALUE (id))) + continue; + + for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) + if (TREE_VEC_ELT (t1, 0) == id) + goto skip_it; + + if (free_binding_vecs) + { + binding = free_binding_vecs; + free_binding_vecs = TREE_CHAIN (free_binding_vecs); + } + else + binding = make_tree_vec (4); + + if (id) + { + my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); + TREE_VEC_ELT (binding, 0) = id; + TREE_VEC_ELT (binding, 1) = REAL_IDENTIFIER_TYPE_VALUE (id); + TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id); + TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); + IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE; + IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; + } + TREE_CHAIN (binding) = old_bindings; + old_bindings = binding; + skip_it: + ; + } + return old_bindings; +} void -push_to_top_level () +maybe_push_to_top_level (pseudo) + int pseudo; { extern int current_lang_stacksize; - struct saved_scope *s = - (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); - struct binding_level *b = current_binding_level; + struct saved_scope *s + = (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); + struct binding_level *b = inner_binding_level; tree old_bindings = NULL_TREE; + if (current_function_decl) + push_cp_function_context (NULL_TREE); + + if (previous_class_type) + old_bindings = store_bindings (previous_class_values, old_bindings); + /* Have to include global_binding_level, because class-level decls aren't listed anywhere useful. */ for (; b; b = b->level_chain) { tree t; - if (b == global_binding_level) - continue; - - for (t = b->names; t; t = TREE_CHAIN (t)) - { - tree binding, t1, t2 = t; - tree id = DECL_ASSEMBLER_NAME (t2); + /* Template IDs are inserted into the global level. If they were + inserted into namespace level, finish_file wouldn't find them + when doing pending instantiations. Therefore, don't stop at + namespace level, but continue until :: . */ + if (b == global_binding_level || (pseudo && b->pseudo_global)) + break; - if (!id - || (!IDENTIFIER_LOCAL_VALUE (id) - && !IDENTIFIER_CLASS_VALUE (id))) - continue; + old_bindings = store_bindings (b->names, old_bindings); + /* We also need to check class_shadowed to save class-level type + bindings, since pushclass doesn't fill in b->names. */ + if (b->parm_flag == 2) + old_bindings = store_bindings (b->class_shadowed, old_bindings); - for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) - if (TREE_VEC_ELT (t1, 0) == id) - goto skip_it; - - binding = make_tree_vec (4); - if (id) - { - my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); - TREE_VEC_ELT (binding, 0) = id; - TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id); - TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id); - TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); - IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE; - IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; - } - TREE_CHAIN (binding) = old_bindings; - old_bindings = binding; - skip_it: - ; - } /* Unwind type-value slots back to top level. */ for (t = b->type_shadowed; t; t = TREE_CHAIN (t)) SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); } - /* Clear out class-level bindings cache. */ - if (current_binding_level == global_binding_level - && previous_class_type != NULL_TREE) - { - popclass (-1); - previous_class_type = NULL_TREE; - } s->old_binding_level = current_binding_level; - current_binding_level = global_binding_level; + current_binding_level = b; + s->old_namespace = current_namespace; s->class_name = current_class_name; s->class_type = current_class_type; s->function_decl = current_function_decl; - s->base_init_list = current_base_init_list; - s->member_init_list = current_member_init_list; s->class_bindings = class_binding_level; - s->previous_class_type = previous_class_type; s->lang_stack = current_lang_stack; s->lang_base = current_lang_base; s->lang_stacksize = current_lang_stacksize; s->lang_name = current_lang_name; - s->named_labels = named_labels; + s->minimal_parse_mode = minimal_parse_mode; + s->last_function_parms = last_function_parms; + s->template_parms = current_template_parms; + s->processing_template_decl = processing_template_decl; + s->previous_class_type = previous_class_type; + s->previous_class_values = previous_class_values; + s->processing_specialization = processing_specialization; + s->processing_explicit_instantiation = processing_explicit_instantiation; + current_class_name = current_class_type = NULL_TREE; current_function_decl = NULL_TREE; class_binding_level = (struct binding_level *)0; - previous_class_type = NULL_TREE; current_lang_stacksize = 10; current_lang_stack = current_lang_base = (tree *) xmalloc (current_lang_stacksize * sizeof (tree)); current_lang_name = lang_name_cplusplus; strict_prototype = strict_prototypes_lang_cplusplus; named_labels = NULL_TREE; + shadowed_labels = NULL_TREE; + minimal_parse_mode = 0; + previous_class_type = previous_class_values = NULL_TREE; + processing_specialization = 0; + processing_explicit_instantiation = 0; + current_template_parms = NULL_TREE; + processing_template_decl = 0; + current_namespace = global_namespace; s->prev = current_saved_scope; s->old_bindings = old_bindings; current_saved_scope = s; + + push_obstacks (&permanent_obstack, &permanent_obstack); +} + +void +push_to_top_level () +{ + maybe_push_to_top_level (0); } void @@ -1905,28 +2062,36 @@ pop_from_top_level () struct saved_scope *s = current_saved_scope; tree t; + /* Clear out class-level bindings cache. */ if (previous_class_type) - previous_class_type = NULL_TREE; + { + popclass (-1); + previous_class_type = NULL_TREE; + } + + pop_obstacks (); current_binding_level = s->old_binding_level; current_saved_scope = s->prev; - for (t = s->old_bindings; t; t = TREE_CHAIN (t)) + for (t = s->old_bindings; t; ) { + tree save = t; tree id = TREE_VEC_ELT (t, 0); if (id) { - IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1); + SET_IDENTIFIER_TYPE_VALUE (id, TREE_VEC_ELT (t, 1)); IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2); IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); } + t = TREE_CHAIN (t); + TREE_CHAIN (save) = free_binding_vecs; + free_binding_vecs = save; } + current_namespace = s->old_namespace; current_class_name = s->class_name; current_class_type = s->class_type; - current_base_init_list = s->base_init_list; - current_member_init_list = s->member_init_list; current_function_decl = s->function_decl; class_binding_level = s->class_bindings; - previous_class_type = s->previous_class_type; free (current_lang_base); current_lang_base = s->lang_base; current_lang_stack = s->lang_stack; @@ -1936,9 +2101,19 @@ pop_from_top_level () strict_prototype = strict_prototypes_lang_cplusplus; else if (current_lang_name == lang_name_c) strict_prototype = strict_prototypes_lang_c; - named_labels = s->named_labels; + minimal_parse_mode = s->minimal_parse_mode; + last_function_parms = s->last_function_parms; + current_template_parms = s->template_parms; + processing_template_decl = s->processing_template_decl; + previous_class_type = s->previous_class_type; + previous_class_values = s->previous_class_values; + processing_specialization = s->processing_specialization; + processing_explicit_instantiation = s->processing_explicit_instantiation; free (s); + + if (current_function_decl) + pop_cp_function_context (NULL_TREE); } /* Push a definition of struct, union or enum tag "name". @@ -1948,7 +2123,7 @@ pop_from_top_level () Note that the definition may really be just a forward reference. In that case, the TYPE_SIZE will be a NULL_TREE. - C++ gratuitously puts all these tags in the name space. */ + C++ gratuitously puts all these tags in the name space. */ /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID, record the shadowed value for this binding contour. TYPE is @@ -1960,16 +2135,25 @@ set_identifier_type_value_with_scope (id, type, b) tree type; struct binding_level *b; { - if (b != global_binding_level) + if (!b->namespace_p) { - tree old_type_value = IDENTIFIER_TYPE_VALUE (id); + /* Shadow the marker, not the real thing, so that the marker + gets restored later. */ + tree old_type_value = REAL_IDENTIFIER_TYPE_VALUE (id); b->type_shadowed = tree_cons (id, old_type_value, b->type_shadowed); } + else + { + tree binding = binding_for_name (id, current_namespace); + BINDING_TYPE (binding) = type; + /* Store marker instead of real type. */ + type = global_type_node; + } SET_IDENTIFIER_TYPE_VALUE (id, type); } -/* As set_identifier_type_value_with_scope, but using inner_binding_level. */ +/* As set_identifier_type_value_with_scope, but using inner_binding_level. */ void set_identifier_type_value (id, type) @@ -1979,59 +2163,50 @@ set_identifier_type_value (id, type) set_identifier_type_value_with_scope (id, type, inner_binding_level); } -/* Subroutine "set_nested_typename" builds the nested-typename of - the type decl in question. (Argument CLASSNAME can actually be - a function as well, if that's the smallest containing scope.) */ - static void -set_nested_typename (decl, classname, name, type) - tree decl, classname, name, type; +set_identifier_local_value_with_scope (id, val, b) + tree id, val; + struct binding_level *b; { - char *buf; - my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136); + tree oldlocal; + my_friendly_assert (! b->namespace_p, 980716); - /* No need to do this for anonymous names, since they're unique. */ - if (ANON_AGGRNAME_P (name)) - { - DECL_NESTED_TYPENAME (decl) = name; - return; - } + oldlocal = IDENTIFIER_LOCAL_VALUE (id); + b->shadowed = tree_cons (id, oldlocal, b->shadowed); + IDENTIFIER_LOCAL_VALUE (id) = val; +} - if (classname == NULL_TREE) - classname = get_identifier (""); +void +set_identifier_local_value (id, val) + tree id, val; +{ + set_identifier_local_value_with_scope (id, val, current_binding_level); +} - my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137); - my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138); - buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname) - + IDENTIFIER_LENGTH (name)); - sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname), - IDENTIFIER_POINTER (name)); - DECL_NESTED_TYPENAME (decl) = get_identifier (buf); - TREE_MANGLED (DECL_NESTED_TYPENAME (decl)) = 1; +/* Return the type associated with id. */ - /* Create an extra decl so that the nested name will have a type value - where appropriate. */ - { - tree nested, type_decl; - nested = DECL_NESTED_TYPENAME (decl); - type_decl = build_decl (TYPE_DECL, nested, type); - DECL_NESTED_TYPENAME (type_decl) = nested; - SET_DECL_ARTIFICIAL (type_decl); - /* Mark the TYPE_DECL node created just above as a gratuitous one so that - dwarfout.c will know not to generate a TAG_typedef DIE for it, and - sdbout.c won't try to output a .def for "::foo". */ - DECL_IGNORED_P (type_decl) = 1; - - /* Remove this when local classes are fixed. */ - SET_IDENTIFIER_TYPE_VALUE (nested, type); - - pushdecl_nonclass_level (type_decl); - } +tree +identifier_type_value (id) + tree id; +{ + /* There is no type with that name, anywhere. */ + if (REAL_IDENTIFIER_TYPE_VALUE (id) == NULL_TREE) + return NULL_TREE; + /* This is not the type marker, but the real thing. */ + if (REAL_IDENTIFIER_TYPE_VALUE (id) != global_type_node) + return REAL_IDENTIFIER_TYPE_VALUE (id); + /* Have to search for it. It must be on the global level, now. + Ask lookup_name not to return non-types. */ + id = lookup_name_real (id, 2, 1, 0); + if (id) + return TREE_TYPE (id); + return NULL_TREE; } /* Pop off extraneous binding levels left over due to syntax errors. We don't pop past namespaces, as they might be valid. */ + void pop_everything () { @@ -2050,41 +2225,10 @@ pop_everything () #endif } -#if 0 /* not yet, should get fixed properly later */ -/* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME. - Other routines shouldn't use build_decl directly; they'll produce - incorrect results with `-g' unless they duplicate this code. - - This is currently needed mainly for dbxout.c, but we can make - use of it in method.c later as well. */ -tree -make_type_decl (name, type) - tree name, type; -{ - tree decl, id; - decl = build_decl (TYPE_DECL, name, type); - if (TYPE_NAME (type) == name) - /* Class/union/enum definition, or a redundant typedef for same. */ - { - id = get_identifier (build_overload_name (type, 1, 1)); - DECL_ASSEMBLER_NAME (decl) = id; - } - else if (TYPE_NAME (type) != NULL_TREE) - /* Explicit typedef, or implicit typedef for template expansion. */ - DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type)); - else - { - /* XXX: Typedef for unnamed struct; some other situations. - TYPE_NAME is null; what's right here? */ - } - return decl; -} -#endif - /* Push a tag name NAME for struct/class/union/enum type TYPE. - Normally put into into the inner-most non-tag-transparent scope, + Normally put it into the inner-most non-tag-transparent scope, but if GLOBALIZE is true, put it in the inner-most non-class scope. - The latter is needed for implicit declarations. */ + The latter is needed for implicit declarations. */ void pushtag (name, type, globalize) @@ -2108,117 +2252,124 @@ pushtag (name, type, globalize) if (name) { context = type ? TYPE_CONTEXT (type) : NULL_TREE; - if (! context && ! globalize) - context = current_scope (); + if (! context) + { + tree cs = current_scope (); + + if (! globalize) + context = cs; + else if (cs != NULL_TREE + && TREE_CODE_CLASS (TREE_CODE (cs)) == 't') + /* When declaring a friend class of a local class, we want + to inject the newly named class into the scope + containing the local class, not the namespace scope. */ + context = hack_decl_function_context (get_type_decl (cs)); + } if (context) c_decl = TREE_CODE (context) == FUNCTION_DECL ? context : TYPE_MAIN_DECL (context); -#if 0 - /* Record the identifier as the type's name if it has none. */ - if (TYPE_NAME (type) == NULL_TREE) - TYPE_NAME (type) = name; -#endif - + if (!context) + context = current_namespace; + /* Do C++ gratuitous typedefing. */ if (IDENTIFIER_TYPE_VALUE (name) != type) { - register tree d; - int newdecl = 0; - - if (b->parm_flag != 2 - || TYPE_SIZE (current_class_type) != NULL_TREE) - { - d = lookup_nested_type (type, c_decl); + register tree d = NULL_TREE; + int newdecl = 0, in_class = 0; - if (d == NULL_TREE) - { - newdecl = 1; -#if 0 /* not yet, should get fixed properly later */ - d = make_type_decl (name, type); -#else - d = build_decl (TYPE_DECL, name, type); - DECL_ASSEMBLER_NAME (d) = current_namespace_id (DECL_ASSEMBLER_NAME (d)); -#endif - SET_DECL_ARTIFICIAL (d); -#ifdef DWARF_DEBUGGING_INFO - if (write_symbols == DWARF_DEBUG) - { - /* Mark the TYPE_DECL node we created just above as an - gratuitous one. We need to do this so that dwarfout.c - will understand that it is not supposed to output a - TAG_typedef DIE for it. */ - DECL_IGNORED_P (d) = 1; - } -#endif /* DWARF_DEBUGGING_INFO */ - set_identifier_type_value_with_scope (name, type, b); - } - else - d = TYPE_NAME (d); - - TYPE_NAME (type) = d; - - /* If it is anonymous, then we are called from pushdecl, - and we don't want to infinitely recurse. */ - if (! ANON_AGGRNAME_P (name)) - { - if (b->parm_flag == 2) - d = pushdecl_class_level (d); - else - d = pushdecl_with_scope (d, b); - } - } + if ((b->pseudo_global && b->level_chain->parm_flag == 2) + || b->parm_flag == 2) + in_class = 1; else + d = lookup_nested_type (type, c_decl); + + if (d == NULL_TREE) { - /* Make nested declarations go into class-level scope. */ newdecl = 1; d = build_decl (TYPE_DECL, name, type); + if (current_lang_name == lang_name_java) + TYPE_FOR_JAVA (type) = 1; SET_DECL_ARTIFICIAL (d); -#ifdef DWARF_DEBUGGING_INFO - if (write_symbols == DWARF_DEBUG) + if (! in_class) + set_identifier_type_value_with_scope (name, type, b); + } + else + d = TYPE_MAIN_DECL (d); + + TYPE_NAME (type) = d; + DECL_CONTEXT (d) = FROB_CONTEXT (context); + + if (processing_template_parmlist) + /* You can't declare a new template type in a template + parameter list. But, you can declare a non-template + type: + + template <class A*> struct S; + + is a forward-declaration of `A'. */ + ; + else if (IS_AGGR_TYPE (type) + && (/* If !GLOBALIZE then we are looking at a + definition. It may not be a primary template. + (For example, in: + + template <class T> + struct S1 { class S2 {}; } + + we have to push_template_decl for S2.) */ + (processing_template_decl && !globalize) + /* If we are declaring a friend template class, we + will have GLOBALIZE set, since something like: + + template <class T> + struct S1 { + template <class U> + friend class S2; + }; + + declares S2 to be at global scope. */ + || (processing_template_decl > + template_class_depth (current_class_type)))) + { + d = push_template_decl_real (d, globalize); + /* If the current binding level is the binding level for + the template parameters (see the comment in + begin_template_parm_list) and the enclosing level is + a class scope, and we're not looking at a friend, + push the declaration of the member class into the + class scope. In the friend case, push_template_decl + will already have put the friend into global scope, + if appropriate. */ + if (!globalize && b->pseudo_global && + b->level_chain->parm_flag == 2) { - /* Mark the TYPE_DECL node we created just above as an - gratuitous one. We need to do this so that dwarfout.c - will understand that it is not supposed to output a - TAG_typedef DIE for it. */ - DECL_IGNORED_P (d) = 1; + pushdecl_with_scope (CLASSTYPE_TI_TEMPLATE (type), + b->level_chain); + /* Put this tag on the list of tags for the class, + since that won't happen below because B is not + the class binding level, but is instead the + pseudo-global level. */ + b->level_chain->tags = + saveable_tree_cons (name, type, b->level_chain->tags); + TREE_NONLOCAL_FLAG (type) = 1; + if (TYPE_SIZE (current_class_type) == NULL_TREE) + CLASSTYPE_TAGS (current_class_type) = b->level_chain->tags; } -#endif /* DWARF_DEBUGGING_INFO */ + } - TYPE_MAIN_DECL (type) = d; + if (b->parm_flag == 2) + d = pushdecl_class_level (d); + else + d = pushdecl_with_scope (d, b); - /* Make sure we're in this type's scope when we push the - decl for a template, otherwise class_binding_level will - be NULL and we'll end up dying inside of - push_class_level_binding. */ - if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) - pushclass (type, 0); - d = pushdecl_class_level (d); - if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE) - popclass (0); - } if (newdecl) { - if (write_symbols != DWARF_DEBUG) - { - if (ANON_AGGRNAME_P (name)) - DECL_IGNORED_P (d) = 1; - } + if (ANON_AGGRNAME_P (name)) + DECL_IGNORED_P (d) = 1; - if (context == NULL_TREE) - /* Non-nested class. */ - set_nested_typename (d, NULL_TREE, name, type); - else if (context && TREE_CODE (context) == FUNCTION_DECL) - /* Function-nested class. */ - set_nested_typename (d, DECL_ASSEMBLER_NAME (c_decl), - name, type); - else /* if (context && IS_AGGR_TYPE (context)) */ - /* Class-nested class. */ - set_nested_typename (d, DECL_NESTED_TYPENAME (c_decl), - name, type); - - DECL_CONTEXT (d) = context; TYPE_CONTEXT (type) = DECL_CONTEXT (d); + DECL_ASSEMBLER_NAME (d) = DECL_NAME (d); DECL_ASSEMBLER_NAME (d) = get_identifier (build_overload_name (type, 1, 1)); } @@ -2244,20 +2395,18 @@ pushtag (name, type, globalize) convenient place to record the "scope start" address for the tagged type. */ -#if 0 /* not yet, should get fixed properly later */ - tree d = make_type_decl (NULL_TREE, type); -#else tree d = build_decl (TYPE_DECL, NULL_TREE, type); -#endif TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b); } } /* Counter used to create anonymous type names. */ + static int anon_cnt = 0; /* Return an IDENTIFIER which can be used as a name for anonymous structs and unions. */ + tree make_anon_name () { @@ -2269,6 +2418,7 @@ make_anon_name () /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames. This keeps dbxout from getting confused. */ + void clear_anon_tags () { @@ -2303,6 +2453,7 @@ clear_anon_tags () For C++, we must compare the parameter list so that `int' can match `int&' in a parameter position, but `int&' is not confused with `const int&'. */ + int decls_match (newdecl, olddecl) tree newdecl, olddecl; @@ -2317,6 +2468,11 @@ decls_match (newdecl, olddecl) tree p1 = TYPE_ARG_TYPES (f1); tree p2 = TYPE_ARG_TYPES (f2); + if (DECL_REAL_CONTEXT (newdecl) != DECL_REAL_CONTEXT (olddecl) + && ! (DECL_LANGUAGE (newdecl) == lang_c + && DECL_LANGUAGE (olddecl) == lang_c)) + return 0; + /* When we parse a static member function definition, we put together a FUNCTION_DECL which thinks its type is METHOD_TYPE. Change that to FUNCTION_TYPE, and @@ -2364,33 +2520,15 @@ decls_match (newdecl, olddecl) else if (TREE_CODE (newdecl) == TEMPLATE_DECL && TREE_CODE (olddecl) == TEMPLATE_DECL) { - tree newargs = DECL_TEMPLATE_PARMS (newdecl); - tree oldargs = DECL_TEMPLATE_PARMS (olddecl); - int i, len = TREE_VEC_LENGTH (newargs); - - if (TREE_VEC_LENGTH (oldargs) != len) - return 0; - - for (i = 0; i < len; i++) - { - tree newarg = TREE_VALUE (TREE_VEC_ELT (newargs, i)); - tree oldarg = TREE_VALUE (TREE_VEC_ELT (oldargs, i)); - if (TREE_CODE (newarg) != TREE_CODE (oldarg)) - return 0; - else if (TREE_CODE (newarg) == TYPE_DECL) - /* continue */; - else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1)) - return 0; - } - - if (DECL_TEMPLATE_IS_CLASS (newdecl) - != DECL_TEMPLATE_IS_CLASS (olddecl)) - types_match = 0; - else if (DECL_TEMPLATE_IS_CLASS (newdecl)) - types_match = 1; - else - types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl), - DECL_TEMPLATE_RESULT (newdecl)); + if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), + DECL_TEMPLATE_PARMS (olddecl))) + return 0; + + if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) + types_match = 1; + else + types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl), + DECL_TEMPLATE_RESULT (newdecl)); } else { @@ -2400,8 +2538,20 @@ decls_match (newdecl, olddecl) types_match = TREE_TYPE (newdecl) == NULL_TREE; else if (TREE_TYPE (newdecl) == NULL_TREE) types_match = 0; + /* Qualifiers must match, and they may be present on either, the type + or the decl. */ + else if ((TREE_READONLY (newdecl) + || TYPE_READONLY (TREE_TYPE (newdecl))) + == (TREE_READONLY (olddecl) + || TYPE_READONLY (TREE_TYPE (olddecl))) + && (TREE_THIS_VOLATILE (newdecl) + || TYPE_VOLATILE (TREE_TYPE (newdecl))) + == (TREE_THIS_VOLATILE (olddecl) + || TYPE_VOLATILE (TREE_TYPE (olddecl)))) + types_match = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (newdecl)), + TYPE_MAIN_VARIANT (TREE_TYPE (olddecl)), 1); else - types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1); + types_match = 0; } return types_match; @@ -2414,9 +2564,6 @@ decls_match (newdecl, olddecl) Note that this does not apply to the C++ case of declaring a variable `extern const' and then later `const'. - Don't complain if -traditional, since traditional compilers - don't complain. - Don't complain about built-in functions, since they are beyond the user's control. */ @@ -2431,8 +2578,7 @@ warn_extern_redeclared_static (newdecl, olddecl) static char *implicit_extern_static_warning = "`%D' was declared implicitly `extern' and later `static'"; - if (flag_traditional - || TREE_CODE (newdecl) == TYPE_DECL) + if (TREE_CODE (newdecl) == TYPE_DECL) return; name = DECL_ASSEMBLER_NAME (newdecl); @@ -2464,46 +2610,36 @@ warn_extern_redeclared_static (newdecl, olddecl) int duplicate_decls (newdecl, olddecl) - register tree newdecl, olddecl; + tree newdecl, olddecl; { extern struct obstack permanent_obstack; unsigned olddecl_uid = DECL_UID (olddecl); int olddecl_friend = 0, types_match = 0; - int new_defines_function; - tree previous_c_decl = NULL_TREE; + int new_defines_function = 0; - if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd') - DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl); + if (newdecl == olddecl) + return 1; types_match = decls_match (newdecl, olddecl); - if (TREE_CODE (olddecl) != TREE_LIST) - olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl); - /* If either the type of the new decl or the type of the old decl is an error_mark_node, then that implies that we have already issued an error (earlier) for some bogus type specification, and in that case, it is rather pointless to harass the user with yet more error message - about the same declaration, so well just pretent the types match here. */ - if ((TREE_TYPE (newdecl) - && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK) - || (TREE_TYPE (olddecl) - && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK)) + about the same declaration, so just pretend the types match here. */ + if (TREE_TYPE (newdecl) == error_mark_node + || TREE_TYPE (olddecl) == error_mark_node) types_match = 1; - - if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL - && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl) - /* If -traditional, avoid error for redeclaring fcn - after implicit decl. */ - ; - else if (TREE_CODE (olddecl) == FUNCTION_DECL - && DECL_ARTIFICIAL (olddecl) - && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl))) + + /* Check for redeclaration and other discrepancies. */ + if (TREE_CODE (olddecl) == FUNCTION_DECL + && DECL_ARTIFICIAL (olddecl) + && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl))) { /* If you declare a built-in or predefined function name as static, the old definition is overridden, but optionally warn this was a bad choice of name. Ditto for overloads. */ - if (! DECL_PUBLIC (newdecl) + if (! TREE_PUBLIC (newdecl) || (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))) { @@ -2539,14 +2675,30 @@ duplicate_decls (newdecl, olddecl) } else if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) { + if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl) + && TREE_CODE (newdecl) != TYPE_DECL + && ! (TREE_CODE (newdecl) == TEMPLATE_DECL + && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)) + || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl) + && TREE_CODE (olddecl) != TYPE_DECL + && ! (TREE_CODE (olddecl) == TEMPLATE_DECL + && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) + == TYPE_DECL)))) + { + /* We do nothing special here, because C++ does such nasty + things with TYPE_DECLs. Instead, just let the TYPE_DECL + get shadowed, and know that if we need to find a TYPE_DECL + for a given name, we can look in the IDENTIFIER_TYPE_VALUE + slot of the identifier. */ + return 0; + } + if ((TREE_CODE (newdecl) == FUNCTION_DECL - && TREE_CODE (olddecl) == TEMPLATE_DECL - && ! DECL_TEMPLATE_IS_CLASS (olddecl)) + && DECL_FUNCTION_TEMPLATE_P (olddecl)) || (TREE_CODE (olddecl) == FUNCTION_DECL - && TREE_CODE (newdecl) == TEMPLATE_DECL - && ! DECL_TEMPLATE_IS_CLASS (newdecl))) + && DECL_FUNCTION_TEMPLATE_P (newdecl))) return 0; - + cp_error ("`%#D' redeclared as different kind of symbol", newdecl); if (TREE_CODE (olddecl) == TREE_LIST) olddecl = TREE_VALUE (olddecl); @@ -2563,14 +2715,24 @@ duplicate_decls (newdecl, olddecl) { /* The name of a class template may not be declared to refer to any other template, class, function, object, namespace, value, - or type in the same scope. */ - if (DECL_TEMPLATE_IS_CLASS (olddecl) - || DECL_TEMPLATE_IS_CLASS (newdecl)) + or type in the same scope. */ + if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL + || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) { cp_error ("declaration of template `%#D'", newdecl); cp_error_at ("conflicts with previous declaration `%#D'", olddecl); } + else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL + && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL + && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))), + TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))), 3) + && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), + DECL_TEMPLATE_PARMS (olddecl))) + { + cp_error ("new declaration `%#D'", newdecl); + cp_error_at ("ambiguates old declaration `%#D'", olddecl); + } return 0; } if (TREE_CODE (newdecl) == FUNCTION_DECL) @@ -2600,6 +2762,37 @@ duplicate_decls (newdecl, olddecl) cp_error_at ("previous declaration as `%#D'", olddecl); } } + else if (TREE_CODE (newdecl) == FUNCTION_DECL + && ((DECL_TEMPLATE_SPECIALIZATION (olddecl) + && (!DECL_TEMPLATE_INFO (newdecl) + || (DECL_TI_TEMPLATE (newdecl) + != DECL_TI_TEMPLATE (olddecl)))) + || (DECL_TEMPLATE_SPECIALIZATION (newdecl) + && (!DECL_TEMPLATE_INFO (olddecl) + || (DECL_TI_TEMPLATE (olddecl) + != DECL_TI_TEMPLATE (newdecl)))))) + /* It's OK to have a template specialization and a non-template + with the same type, or to have specializations of two + different templates with the same type. Note that if one is a + specialization, and the other is an instantiation of the same + template, that we do not exit at this point. That situation + can occur if we instantiate a template class, and then + specialize one of its methods. This situation is legal, but + the declarations must be merged in the usual way. */ + return 0; + else if (TREE_CODE (newdecl) == FUNCTION_DECL + && ((DECL_TEMPLATE_INSTANTIATION (olddecl) + && !DECL_USE_TEMPLATE (newdecl)) + || (DECL_TEMPLATE_INSTANTIATION (newdecl) + && !DECL_USE_TEMPLATE (olddecl)))) + /* One of the declarations is a template instantiation, and the + other is not a template at all. That's OK. */ + return 0; + else if (TREE_CODE (newdecl) == NAMESPACE_DECL + && DECL_NAMESPACE_ALIAS (newdecl) + && DECL_NAMESPACE_ALIAS (newdecl) == DECL_NAMESPACE_ALIAS (olddecl)) + /* Redeclaration of namespace alias, ignore it. */ + return 1; else { char *errmsg = redeclaration_error_message (newdecl, olddecl); @@ -2608,7 +2801,7 @@ duplicate_decls (newdecl, olddecl) cp_error (errmsg, newdecl); if (DECL_NAME (olddecl) != NULL_TREE) cp_error_at ((DECL_INITIAL (olddecl) - && current_binding_level == global_binding_level) + && namespace_bindings_p ()) ? "`%#D' previously defined here" : "`%#D' previously declared here", olddecl); } @@ -2638,7 +2831,9 @@ duplicate_decls (newdecl, olddecl) } } - if (TREE_CODE (olddecl) == FUNCTION_DECL) + if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl)) + ; + else if (TREE_CODE (olddecl) == FUNCTION_DECL) { tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl)); tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)); @@ -2666,32 +2861,18 @@ duplicate_decls (newdecl, olddecl) { cp_error ("default argument given for parameter %d of `%#D'", i, newdecl); - cp_error_at ("conflicts with previous specification in `%#D'", + cp_error_at ("after previous specification in `%#D'", olddecl); } } - if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl)) + if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl) + && TREE_ADDRESSABLE (olddecl) && warn_inline) { -#if 0 /* I think this will be correct, but it's really annoying. We should - fix the compiler to find vtables by indirection so it isn't - necessary. (jason 8/25/95) */ - if (DECL_VINDEX (olddecl) && ! DECL_ABSTRACT_VIRTUAL_P (olddecl)) - { - cp_pedwarn ("virtual function `%#D' redeclared inline", - newdecl); - cp_pedwarn_at ("previous non-inline declaration here", - olddecl); - } - else -#endif - if (TREE_ADDRESSABLE (olddecl)) - { - cp_pedwarn ("`%#D' was used before it was declared inline", - newdecl); - cp_pedwarn_at ("previous non-inline declaration here", - olddecl); - } + cp_warning ("`%#D' was used before it was declared inline", + newdecl); + cp_warning_at ("previous non-inline declaration here", + olddecl); } } /* These bits are logically part of the type for non-functions. */ @@ -2707,7 +2888,7 @@ duplicate_decls (newdecl, olddecl) warn about it. */ warn_extern_redeclared_static (newdecl, olddecl); - /* We have committed to returning 1 at this point. */ + /* We have committed to returning 1 at this point. */ if (TREE_CODE (newdecl) == FUNCTION_DECL) { /* Now that functions must hold information normally held @@ -2720,15 +2901,28 @@ duplicate_decls (newdecl, olddecl) DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); if (DECL_CLASS_CONTEXT (olddecl)) DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl); - if (DECL_CHAIN (newdecl) == NULL_TREE) - DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); - if (DECL_NEXT_METHOD (newdecl) == NULL_TREE) - DECL_NEXT_METHOD (newdecl) = DECL_NEXT_METHOD (olddecl); if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl); DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl); + DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl); + DECL_NEEDS_FINAL_OVERRIDER_P (newdecl) |= DECL_NEEDS_FINAL_OVERRIDER_P (olddecl); + new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE; + + /* Optionally warn about more than one declaration for the same + name, but don't warn about a function declaration followed by a + definition. */ + if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl) + && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE) + /* Don't warn about extern decl followed by definition. */ + && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)) + /* Don't warn about friends, let add_friend take care of it. */ + && ! DECL_FRIEND_P (newdecl)) + { + cp_warning ("redundant redeclaration of `%D' in same scope", newdecl); + cp_warning_at ("previous declaration of `%D'", olddecl); + } } /* Deal with C++: must preserve virtual function table size. */ @@ -2737,8 +2931,6 @@ duplicate_decls (newdecl, olddecl) register tree newtype = TREE_TYPE (newdecl); register tree oldtype = TREE_TYPE (olddecl); - DECL_NESTED_TYPENAME (newdecl) = DECL_NESTED_TYPENAME (olddecl); - if (newtype != error_mark_node && oldtype != error_mark_node && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype)) { @@ -2746,39 +2938,30 @@ duplicate_decls (newdecl, olddecl) CLASSTYPE_FRIEND_CLASSES (newtype) = CLASSTYPE_FRIEND_CLASSES (oldtype); } -#if 0 - /* why assert here? Just because debugging information is - messed up? (mrs) */ - /* it happens on something like: - typedef struct Thing { - Thing(); - int x; - } Thing; - */ - my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl), - 139); -#endif - } - - /* Special handling ensues if new decl is a function definition. */ - new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL - && DECL_INITIAL (newdecl) != NULL_TREE); - - /* Optionally warn about more than one declaration for the same name, - but don't warn about a function declaration followed by a definition. */ - if (warn_redundant_decls - && ! DECL_ARTIFICIAL (olddecl) - && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE) - /* Don't warn about extern decl followed by (tentative) definition. */ - && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))) - { - cp_warning ("redundant redeclaration of `%D' in same scope", newdecl); - cp_warning_at ("previous declaration of `%D'", olddecl); } /* Copy all the DECL_... slots specified in the new decl except for any that we copy here from the old type. */ + DECL_MACHINE_ATTRIBUTES (newdecl) + = merge_machine_decl_attributes (olddecl, newdecl); + if (TREE_CODE (newdecl) == TEMPLATE_DECL) + { + if (DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl)) == NULL_TREE) + { + if (! duplicate_decls (DECL_TEMPLATE_RESULT (newdecl), + DECL_TEMPLATE_RESULT (olddecl))) + cp_error ("invalid redeclaration of %D", newdecl); + TREE_TYPE (olddecl) = TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)); + DECL_TEMPLATE_PARMS (olddecl) = DECL_TEMPLATE_PARMS (newdecl); + DECL_TEMPLATE_INFO (olddecl) = DECL_TEMPLATE_INFO (newdecl); + } + DECL_TEMPLATE_SPECIALIZATIONS (newdecl) + = DECL_TEMPLATE_SPECIALIZATIONS (olddecl); + + return 1; + } + if (types_match) { /* Automatically handles default parameters. */ @@ -2805,32 +2988,35 @@ duplicate_decls (newdecl, olddecl) && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)) != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)))) { - tree ctype = NULL_TREE; - ctype = DECL_CLASS_CONTEXT (newdecl); TREE_TYPE (newdecl) = build_exception_variant (newtype, TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))); TREE_TYPE (olddecl) = build_exception_variant (newtype, TYPE_RAISES_EXCEPTIONS (oldtype)); - if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0)) + if ((pedantic || ! DECL_IN_SYSTEM_HEADER (olddecl)) + && DECL_SOURCE_LINE (olddecl) != 0 + && flag_exceptions + && ! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl))) { - cp_error ("declaration of `%D' throws different exceptions...", + cp_pedwarn ("declaration of `%D' throws different exceptions", newdecl); - cp_error_at ("...from previous declaration here", olddecl); + cp_pedwarn_at ("previous declaration here", olddecl); } } TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype; /* Lay the type out, unless already done. */ - if (oldtype != TREE_TYPE (newdecl) - && TREE_TYPE (newdecl) != error_mark_node) + if (newtype != canonical_type_variant (oldtype) + && TREE_TYPE (newdecl) != error_mark_node + && !(processing_template_decl && uses_template_parms (newdecl))) layout_type (TREE_TYPE (newdecl)); - if (TREE_CODE (newdecl) == VAR_DECL - || TREE_CODE (newdecl) == PARM_DECL - || TREE_CODE (newdecl) == RESULT_DECL - || TREE_CODE (newdecl) == FIELD_DECL - || TREE_CODE (newdecl) == TYPE_DECL) + if ((TREE_CODE (newdecl) == VAR_DECL + || TREE_CODE (newdecl) == PARM_DECL + || TREE_CODE (newdecl) == RESULT_DECL + || TREE_CODE (newdecl) == FIELD_DECL + || TREE_CODE (newdecl) == TYPE_DECL) + && !(processing_template_decl && uses_template_parms (newdecl))) layout_decl (newdecl, 0); /* Merge the type qualifiers. */ @@ -2881,20 +3067,55 @@ duplicate_decls (newdecl, olddecl) /* Merge the storage class information. */ DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); + DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl); TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl); if (! DECL_EXTERNAL (olddecl)) DECL_EXTERNAL (newdecl) = 0; - - if (TREE_CODE (newdecl) == FUNCTION_DECL) + + if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl)) { - DECL_C_STATIC (newdecl) = DECL_C_STATIC (olddecl); DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl); DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl); + DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl); + /* Don't really know how much of the language-specific + values we should copy from old to new. */ + DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); + DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl); + DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); + if (DECL_TEMPLATE_INFO (newdecl) == NULL_TREE) + { + DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); + DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl); + } + olddecl_friend = DECL_FRIEND_P (olddecl); } if (TREE_CODE (newdecl) == FUNCTION_DECL) { + if (DECL_TEMPLATE_INSTANTIATION (olddecl) + && !DECL_TEMPLATE_INSTANTIATION (newdecl)) + { + /* If newdecl is not a specialization, then it is not a + template-related function at all. And that means that we + shoud have exited above, returning 0. */ + my_friendly_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl), + 0); + + if (TREE_USED (olddecl)) + /* From [temp.expl.spec]: + + If a template, a member template or the member of a class + template is explicitly specialized then that + specialization shall be declared before the first use of + that specialization that would cause an implicit + instantiation to take place, in every translation unit in + which such a use occurs. */ + cp_error ("explicit specialization of %D after first use", + olddecl); + + SET_DECL_TEMPLATE_SPECIALIZATION (olddecl); + } DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl); /* If either decl says `inline', this fn is inline, unless its @@ -2907,9 +3128,13 @@ duplicate_decls (newdecl, olddecl) { DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl); DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl); + DECL_RTL (olddecl) = DECL_RTL (newdecl); + } + if (! types_match || new_defines_function) + { + /* These need to be copied so that the names are available. */ DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl); DECL_RESULT (olddecl) = DECL_RESULT (newdecl); - DECL_RTL (olddecl) = DECL_RTL (newdecl); } if (new_defines_function) /* If defining a function declared with other language @@ -2948,32 +3173,12 @@ duplicate_decls (newdecl, olddecl) NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl); } - if (TREE_CODE (newdecl) == TEMPLATE_DECL) - { - if (DECL_TEMPLATE_INFO (olddecl)->length) - DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); - DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl); - DECL_TEMPLATE_INSTANTIATIONS (newdecl) - = DECL_TEMPLATE_INSTANTIATIONS (olddecl); - if (DECL_CHAIN (newdecl) == NULL_TREE) - DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl); - } - /* Now preserve various other info from the definition. */ TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); DECL_COMMON (newdecl) = DECL_COMMON (olddecl); DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl); - /* Don't really know how much of the language-specific - values we should copy from old to new. */ - if (DECL_LANG_SPECIFIC (olddecl)) - { - DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); - DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl); - DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); - } - if (TREE_CODE (newdecl) == FUNCTION_DECL) { int function_size; @@ -2991,9 +3196,44 @@ duplicate_decls (newdecl, olddecl) #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \ & ~ obstack_alignment_mask (&permanent_obstack)) - if ((char *)newdecl + ROUND (function_size) - + ROUND (sizeof (struct lang_decl)) - == obstack_next_free (&permanent_obstack)) + if (DECL_TEMPLATE_INSTANTIATION (newdecl)) + { + /* If newdecl is a template instantiation, it is possible that + the following sequence of events has occurred: + + o A friend function was declared in a class template. The + class template was instantiated. + + o The instantiation of the friend declaration was + recorded on the instantiation list, and is newdecl. + + o Later, however, instantiate_class_template called pushdecl + on the newdecl to perform name injection. But, pushdecl in + turn called duplicate_decls when it discovered that another + declaration of a global function with the same name already + existed. + + o Here, in duplicate_decls, we decided to clobber newdecl. + + If we're going to do that, we'd better make sure that + olddecl, and not newdecl, is on the list of + instantiations so that if we try to do the instantiation + again we won't get the clobbered declaration. */ + + tree tmpl = DECL_TI_TEMPLATE (newdecl); + tree decls = DECL_TEMPLATE_SPECIALIZATIONS (tmpl); + + for (; decls; decls = TREE_CHAIN (decls)) + if (TREE_VALUE (decls) == newdecl) + TREE_VALUE (decls) = olddecl; + } + + if (((char *)newdecl + ROUND (function_size) == (char *)nl + && ((char *)newdecl + ROUND (function_size) + + ROUND (sizeof (struct lang_decl)) + == obstack_next_free (&permanent_obstack))) + || ((char *)newdecl + ROUND (function_size) + == obstack_next_free (&permanent_obstack))) { DECL_MAIN_VARIANT (newdecl) = olddecl; DECL_LANG_SPECIFIC (olddecl) = ol; @@ -3001,19 +3241,23 @@ duplicate_decls (newdecl, olddecl) obstack_free (&permanent_obstack, newdecl); } - else if (LANG_DECL_PERMANENT (ol)) + else if (LANG_DECL_PERMANENT (ol) && ol != nl) { if (DECL_MAIN_VARIANT (olddecl) == olddecl) { /* Save these lang_decls that would otherwise be lost. */ extern tree free_lang_decl_chain; tree free_lang_decl = (tree) ol; + + if (DECL_LANG_SPECIFIC (olddecl) == ol) + abort (); + TREE_CHAIN (free_lang_decl) = free_lang_decl_chain; free_lang_decl_chain = free_lang_decl; } else { - /* Storage leak. */ + /* Storage leak. */; } } } @@ -3029,6 +3273,10 @@ duplicate_decls (newdecl, olddecl) if (olddecl_friend) DECL_FRIEND_P (olddecl) = 1; + /* NEWDECL contains the merged attribute lists. + Update OLDDECL to be the same. */ + DECL_MACHINE_ATTRIBUTES (olddecl) = DECL_MACHINE_ATTRIBUTES (newdecl); + return 1; } @@ -3045,54 +3293,41 @@ pushdecl (x) tree x; { register tree t; -#if 0 /* not yet, should get fixed properly later */ - register tree name; -#else register tree name = DECL_ASSEMBLER_NAME (x); -#endif register struct binding_level *b = current_binding_level; -#if 0 - static int nglobals; int len; - - len = list_length (global_binding_level->names); - if (len < nglobals) - my_friendly_abort (8); - else if (len > nglobals) - nglobals = len; -#endif - - if (x != current_function_decl + if (current_function_decl && x != current_function_decl + /* A local declaration for a function doesn't constitute nesting. */ + && (TREE_CODE (x) != FUNCTION_DECL || DECL_INITIAL (x)) /* Don't change DECL_CONTEXT of virtual methods. */ && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x)) && ! DECL_CONTEXT (x)) DECL_CONTEXT (x) = current_function_decl; - /* A local declaration for a function doesn't constitute nesting. */ - if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0) - DECL_CONTEXT (x) = 0; - -#if 0 /* not yet, should get fixed properly later */ - /* For functions and class static data, we currently look up the encoded - form of the name. For types, we want the real name. The former will - probably be changed soon, according to MDT. */ - if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL) - name = DECL_ASSEMBLER_NAME (x); - else - name = DECL_NAME (x); -#else + if (!DECL_CONTEXT (x)) + DECL_CONTEXT (x) = FROB_CONTEXT (current_namespace); + /* Type are looked up using the DECL_NAME, as that is what the rest of the - compiler wants to use. */ + compiler wants to use. */ if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL - || TREE_CODE (x) == NAMESPACE_DECL) + || TREE_CODE (x) == NAMESPACE_DECL || TREE_CODE (x) == TEMPLATE_TYPE_PARM + || TREE_CODE (x) == TEMPLATE_TEMPLATE_PARM) name = DECL_NAME (x); -#endif if (name) { +#if 0 + /* Not needed...see below. */ char *file; int line; - - t = lookup_name_current_level (name); +#endif + if (TREE_CODE (name) == TEMPLATE_ID_EXPR) + name = TREE_OPERAND (name, 0); + + /* Namespace-scoped variables are not found in the current level. */ + if (TREE_CODE (x) == VAR_DECL && DECL_NAMESPACE_SCOPE_P (x)) + t = namespace_binding (name, DECL_CONTEXT (x)); + else + t = lookup_name_current_level (name); if (t == error_mark_node) { /* error_mark_node is 0 for a while during initialization! */ @@ -3102,20 +3337,25 @@ pushdecl (x) else if (t != NULL_TREE) { +#if 0 + /* This is turned off until I have time to do it right (bpk). */ + /* With the code below that uses it... */ file = DECL_SOURCE_FILE (t); line = DECL_SOURCE_LINE (t); - if (TREE_CODE (x) == VAR_DECL && DECL_DEAD_FOR_LOCAL (x)) - ; /* This is OK. */ - else if (TREE_CODE (t) == PARM_DECL) +#endif + if (TREE_CODE (t) == PARM_DECL) { if (DECL_CONTEXT (t) == NULL_TREE) fatal ("parse errors have confused me too much"); + + /* Check for duplicate params. */ + if (duplicate_decls (x, t)) + return t; } else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c) - || (TREE_CODE (x) == TEMPLATE_DECL - && ! DECL_TEMPLATE_IS_CLASS (x))) - && is_overloaded_fn (t)) - /* don't do anything just yet */; + || DECL_FUNCTION_TEMPLATE_P (x)) + && is_overloaded_fn (t)) + /* Don't do anything just yet. */; else if (t == wchar_decl_node) { if (pedantic && ! DECL_IN_SYSTEM_HEADER (x)) @@ -3126,17 +3366,7 @@ pushdecl (x) } else if (TREE_CODE (t) != TREE_CODE (x)) { - if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t)) - || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x))) - { - /* We do nothing special here, because C++ does such nasty - things with TYPE_DECLs. Instead, just let the TYPE_DECL - get shadowed, and know that if we need to find a TYPE_DECL - for a given name, we can look in the IDENTIFIER_TYPE_VALUE - slot of the identifier. */ - ; - } - else if (duplicate_decls (x, t)) + if (duplicate_decls (x, t)) return t; } else if (duplicate_decls (x, t)) @@ -3178,6 +3408,20 @@ pushdecl (x) return t; } + else if (DECL_MAIN_P (x)) + { + /* A redeclaration of main, but not a duplicate of the + previous one. + + [basic.start.main] + + This function shall not be overloaded. */ + cp_error_at ("invalid redeclaration of `%D'", t); + cp_error ("as `%D'", x); + /* We don't try to push this declaration since that + causes a crash. */ + return x; + } } if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x)) @@ -3186,45 +3430,32 @@ pushdecl (x) if (t != x || DECL_LANGUAGE (x) == lang_c) return t; } - else if (TREE_CODE (x) == TEMPLATE_DECL && ! DECL_TEMPLATE_IS_CLASS (x)) + else if (DECL_FUNCTION_TEMPLATE_P (x) && DECL_NAMESPACE_SCOPE_P (x)) return push_overloaded_decl (x, 0); - /* If declaring a type as a typedef, and the type has no known - typedef name, install this TYPE_DECL as its typedef name. */ + /* If declaring a type as a typedef, copy the type (unless we're + at line 0), and install this TYPE_DECL as the new type's typedef + name. See the extensive comment in ../c-decl.c (pushdecl). */ if (TREE_CODE (x) == TYPE_DECL) { tree type = TREE_TYPE (x); - tree name = (type != error_mark_node) ? TYPE_NAME (type) : x; + if (DECL_SOURCE_LINE (x) == 0) + { + if (TYPE_NAME (type) == 0) + TYPE_NAME (type) = x; + } + else if (type != error_mark_node && TYPE_NAME (type) != x) + { + push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); - if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL) - { - /* If these are different names, and we're at the global - binding level, make two equivalent definitions. */ - name = x; - if (global_bindings_p ()) - TYPE_NAME (type) = x; - } - else - { - tree tname = DECL_NAME (name); + DECL_ORIGINAL_TYPE (x) = type; + type = build_type_copy (type); + TYPE_STUB_DECL (type) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x)); + TYPE_NAME (type) = x; + TREE_TYPE (x) = type; - /* This is a disgusting kludge for dealing with UPTs. */ - if (global_bindings_p () && ANON_AGGRNAME_P (tname)) - { - /* do gratuitous C++ typedefing, and make sure that - we access this type either through TREE_TYPE field - or via the tags list. */ - TYPE_NAME (TREE_TYPE (x)) = x; - pushtag (tname, TREE_TYPE (x), 0); - } - } - my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140); - - /* Don't set nested_typename on template type parms, for instance. - Any artificial decls that need DECL_NESTED_TYPENAME will have it - set in pushtag. */ - if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x)) - set_nested_typename (x, current_class_name, DECL_NAME (x), type); + pop_obstacks (); + } if (type != error_mark_node && TYPE_NAME (type) @@ -3241,11 +3472,12 @@ pushdecl (x) if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL) { tree decl; + tree bindings = binding_for_name (name, current_namespace); - if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE - && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name)) - || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name)))) - decl = IDENTIFIER_GLOBAL_VALUE (name); + if (BINDING_VALUE (bindings) != NULL_TREE + && (DECL_EXTERNAL (BINDING_VALUE (bindings)) + || TREE_PUBLIC (BINDING_VALUE (bindings)))) + decl = BINDING_VALUE (bindings); else decl = NULL_TREE; @@ -3259,21 +3491,16 @@ pushdecl (x) } } - /* In PCC-compatibility mode, extern decls of vars with no current decl - take effect at top level no matter where they are. */ - if (flag_traditional && DECL_EXTERNAL (x) - && lookup_name (name, 0) == NULL_TREE) - b = global_binding_level; - /* This name is new in its binding level. Install the new declaration and return it. */ - if (b == global_binding_level) + if (namespace_bindings_p ()) { /* Install a global value. */ + tree bindings = binding_for_name (name, current_namespace); /* If the first global decl has external linkage, warn if we later see static one. */ - if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && DECL_PUBLIC (x)) + if (BINDING_VALUE (bindings) == NULL_TREE && TREE_PUBLIC (x)) TREE_PUBLIC (name) = 1; /* Don't install an artificial TYPE_DECL if we already have @@ -3281,7 +3508,12 @@ pushdecl (x) if (TREE_CODE (x) != TYPE_DECL || t == NULL_TREE || ! DECL_ARTIFICIAL (x)) - IDENTIFIER_GLOBAL_VALUE (name) = x; + { + if (TREE_CODE (x) == FUNCTION_DECL) + my_friendly_assert ((BINDING_VALUE (bindings) == NULL_TREE) + || BINDING_VALUE (bindings) == x, 378); + BINDING_VALUE (bindings) = x; + } /* Don't forget if the function was used via an implicit decl. */ if (IDENTIFIER_IMPLICIT_DECL (name) @@ -3310,17 +3542,14 @@ pushdecl (x) { /* Here to install a non-global value. */ tree oldlocal = IDENTIFIER_LOCAL_VALUE (name); - tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name); + tree oldglobal = binding_for_name (name, current_namespace); /* Don't install an artificial TYPE_DECL if we already have another _DECL with that name. */ if (TREE_CODE (x) != TYPE_DECL || t == NULL_TREE || ! DECL_ARTIFICIAL (x)) - { - b->shadowed = tree_cons (name, oldlocal, b->shadowed); - IDENTIFIER_LOCAL_VALUE (name) = x; - } + set_identifier_local_value_with_scope (name, x, b); /* If this is a TYPE_DECL, push it into the type value slot. */ if (TREE_CODE (x) == TYPE_DECL) @@ -3336,24 +3565,24 @@ pushdecl (x) have a global definition or declaration for the function. */ if (oldlocal == NULL_TREE && DECL_EXTERNAL (x) - && oldglobal != NULL_TREE + && BINDING_VALUE (oldglobal) != NULL_TREE && TREE_CODE (x) == FUNCTION_DECL - && TREE_CODE (oldglobal) == FUNCTION_DECL) + && TREE_CODE (BINDING_VALUE (oldglobal)) == FUNCTION_DECL) { /* We have one. Their types must agree. */ - if (decls_match (x, oldglobal)) + if (decls_match (x, BINDING_VALUE (oldglobal))) /* OK */; else { cp_warning ("extern declaration of `%#D' doesn't match", x); - cp_warning_at ("global declaration `%#D'", oldglobal); + cp_warning_at ("global declaration `%#D'", BINDING_VALUE (oldglobal)); } } /* If we have a local external declaration, and no file-scope declaration has yet been seen, then if we later have a file-scope decl it must not be static. */ if (oldlocal == NULL_TREE - && oldglobal == NULL_TREE + && BINDING_VALUE (oldglobal) == NULL_TREE && DECL_EXTERNAL (x) && TREE_PUBLIC (x)) { @@ -3379,7 +3608,7 @@ pushdecl (x) if (b->parm_flag == 1) cp_error ("declaration of `%#D' shadows a parameter", name); } - else if (oldlocal != NULL_TREE && b->is_for_scope + else if (warn_shadow && oldlocal != NULL_TREE && b->is_for_scope && !DECL_DEAD_FOR_LOCAL (oldlocal)) { warning ("variable `%s' shadows local", @@ -3398,12 +3627,13 @@ pushdecl (x) if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL) warnstring = "declaration of `%s' shadows a parameter"; else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE - && current_class_decl + && current_class_ptr && !TREE_STATIC (name)) warnstring = "declaration of `%s' shadows a member of `this'"; else if (oldlocal != NULL_TREE) warnstring = "declaration of `%s' shadows previous local"; - else if (oldglobal != NULL_TREE) + else if (BINDING_VALUE (oldglobal) != NULL_TREE) + /* XXX shadow warnings in outer-more namespaces */ warnstring = "declaration of `%s' shadows global declaration"; if (warnstring) @@ -3435,29 +3665,47 @@ pushdecl (x) return x; } -/* Same as pushdecl, but define X in binding-level LEVEL. */ +/* Same as pushdecl, but define X in binding-level LEVEL. We rely on the + caller to set DECL_CONTEXT properly. */ static tree pushdecl_with_scope (x, level) tree x; struct binding_level *level; { - register struct binding_level *b = current_binding_level; + register struct binding_level *b; + tree function_decl = current_function_decl; - current_binding_level = level; - x = pushdecl (x); - current_binding_level = b; + current_function_decl = NULL_TREE; + if (level->parm_flag == 2) + { + b = class_binding_level; + class_binding_level = level; + pushdecl_class_level (x); + class_binding_level = b; + } + else + { + b = current_binding_level; + current_binding_level = level; + x = pushdecl (x); + current_binding_level = b; + } + current_function_decl = function_decl; return x; } -/* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, +/* Like pushdecl, only it places X in the current namespace, if appropriate. */ + tree -pushdecl_top_level (x) +pushdecl_namespace_level (x) tree x; { register struct binding_level *b = inner_binding_level; - register tree t = pushdecl_with_scope (x, global_binding_level); + register tree t; + + t = pushdecl_with_scope (x, NAMESPACE_LEVEL (current_namespace)); /* Now, the type_shadowed stack may screw us. Munge it so it does what we want. */ @@ -3487,34 +3735,28 @@ pushdecl_top_level (x) } else { -#if 0 - /* Disabled this 11/10/92, since there are many cases which - behave just fine when *ptr doesn't satisfy either of these. - For example, nested classes declared as friends of their enclosing - class will not meet this criteria. (bpk) */ - my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141); -#endif *ptr = newval; } } return t; } -/* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL, +/* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */ -void -push_overloaded_decl_top_level (x, forget) + +tree +pushdecl_top_level (x) tree x; - int forget; { - struct binding_level *b = current_binding_level; - - current_binding_level = global_binding_level; - push_overloaded_decl (x, forget); - current_binding_level = b; + tree cur_namespace = current_namespace; + current_namespace = global_namespace; + x = pushdecl_namespace_level (x); + current_namespace = cur_namespace; + return x; } /* Make the declaration of X appear in CLASS scope. */ + tree pushdecl_class_level (x) tree x; @@ -3527,21 +3769,24 @@ pushdecl_class_level (x) { if (TYPE_BEING_DEFINED (current_class_type)) { - /* Check for inconsistent use of this name in the class body. + /* A name N used in a class S shall refer to the same declaration + in its context and when re-evaluated in the completed scope of S. + Types, enums, and static vars are checked here; other members are checked in finish_struct. */ tree icv = IDENTIFIER_CLASS_VALUE (name); - if (icv + if (icv && icv != x + && flag_optional_diags /* Don't complain about inherited names. */ && id_in_current_class (name) /* Or shadowed tags. */ - && !(TREE_CODE (icv) == TYPE_DECL + && !(DECL_DECLARES_TYPE_P (icv) && DECL_CONTEXT (icv) == current_class_type)) { - cp_error ("declaration of identifier `%D' as `%#D'", name, x); - cp_error_at ("conflicts with previous use in class as `%#D'", - icv); + cp_pedwarn ("declaration of identifier `%D' as `%#D'", name, x); + cp_pedwarn_at ("conflicts with previous use in class as `%#D'", + icv); } } @@ -3549,49 +3794,47 @@ pushdecl_class_level (x) if (TREE_CODE (x) == TYPE_DECL) { set_identifier_type_value (name, TREE_TYPE (x)); - - /* Don't set nested_typename on template type parms, for instance. - Any artificial decls that need DECL_NESTED_TYPENAME will have it - set in pushtag. */ - if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x)) - set_nested_typename (x, current_class_name, name, TREE_TYPE (x)); } } return x; } +#if 0 /* This function is used to push the mangled decls for nested types into the appropriate scope. Previously pushdecl_top_level was used, but that is incorrect for members of local classes. */ -tree + +void pushdecl_nonclass_level (x) tree x; { struct binding_level *b = current_binding_level; -#if 0 - /* Get out of class scope -- this isn't necessary, because class scope - doesn't make it into current_binding_level. */ - while (b->parm_flag == 2) - b = b->level_chain; -#else my_friendly_assert (b->parm_flag != 2, 180); -#endif +#if 0 /* Get out of template binding levels */ while (b->pseudo_global) b = b->level_chain; +#endif pushdecl_with_scope (x, b); } +#endif /* Make the declaration(s) of X appear in CLASS scope under the name NAME. */ + void push_class_level_binding (name, x) tree name; tree x; { + /* The class_binding_level will be NULL if x is a template + parameter name in a member template. */ + if (!class_binding_level) + return; + if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) && purpose_member (name, class_binding_level->class_shadowed)) return; @@ -3605,22 +3848,55 @@ push_class_level_binding (name, x) obstack_ptr_grow (&decl_obstack, x); } -/* Tell caller how to interpret a TREE_LIST which contains - chains of FUNCTION_DECLS. */ -int -overloaded_globals_p (list) - tree list; +/* Insert another USING_DECL into the current binding level, + returning this declaration. If this is a redeclaration, + do nothing and return NULL_TREE. */ + +tree +push_using_decl (scope, name) + tree scope; + tree name; +{ + tree decl; + + my_friendly_assert (TREE_CODE (scope) == NAMESPACE_DECL, 383); + my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 384); + for (decl = current_binding_level->usings; decl; decl = TREE_CHAIN (decl)) + if (DECL_INITIAL (decl) == scope && DECL_NAME (decl) == name) + break; + if (decl) + return NULL_TREE; + decl = build_lang_decl (USING_DECL, name, void_type_node); + DECL_INITIAL (decl) = scope; + TREE_CHAIN (decl) = current_binding_level->usings; + current_binding_level->usings = decl; + return decl; +} + +/* Add namespace to using_directives. Return NULL_TREE if nothing was + changed (i.e. there was already a directive), or the fresh + TREE_LIST otherwise. */ + +tree +push_using_directive (used) + tree used; { - my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142); + tree ud = current_binding_level->using_directives; + tree iter, ancestor; + + /* Check if we already have this. */ + if (purpose_member (used, ud) != NULL_TREE) + return NULL_TREE; - /* Don't commit caller to seeing them as globals. */ - if (TREE_NONLOCAL_FLAG (list)) - return -1; - /* Do commit caller to seeing them as globals. */ - if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE) - return 1; - /* Do commit caller to not seeing them as globals. */ - return 0; + /* Recursively add all namespaces used. */ + for (iter = DECL_NAMESPACE_USING (used); iter; iter = TREE_CHAIN (iter)) + push_using_directive (TREE_PURPOSE (iter)); + + ancestor = namespace_ancestor (current_decl_namespace (), used); + ud = current_binding_level->using_directives; + ud = perm_tree_cons (used, ancestor, ud); + current_binding_level->using_directives = ud; + return ud; } /* DECL is a FUNCTION_DECL which may have other definitions already in @@ -3635,19 +3911,19 @@ overloaded_globals_p (list) The value returned may be a previous declaration if we guessed wrong about what language DECL should belong to (C or C++). Otherwise, it's always DECL (and never something that's not a _DECL). */ -tree + +static tree push_overloaded_decl (decl, forgettable) tree decl; int forgettable; { tree orig_name = DECL_NAME (decl); tree old; - int doing_global = (global_bindings_p () || ! forgettable - || flag_traditional || pseudo_global_level_p ()); + int doing_global = (namespace_bindings_p () || ! forgettable); if (doing_global) { - old = IDENTIFIER_GLOBAL_VALUE (orig_name); + old = namespace_binding (orig_name, DECL_CONTEXT (decl)); if (old && TREE_CODE (old) == FUNCTION_DECL && DECL_ARTIFICIAL (old) && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old))) @@ -3671,18 +3947,12 @@ push_overloaded_decl (decl, forgettable) if (old) { -#if 0 - /* We cache the value of builtin functions as ADDR_EXPRs - in the name space. Convert it to some kind of _DECL after - remembering what to forget. */ - if (TREE_CODE (old) == ADDR_EXPR) - old = TREE_OPERAND (old, 0); - else -#endif if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) { tree t = TREE_TYPE (old); - if (IS_AGGR_TYPE (t) && warn_shadow) + if (IS_AGGR_TYPE (t) && warn_shadow + && (! DECL_IN_SYSTEM_HEADER (decl) + || ! DECL_IN_SYSTEM_HEADER (old))) cp_warning ("`%#D' hides constructor for `%#T'", decl, t); old = NULL_TREE; } @@ -3690,9 +3960,10 @@ push_overloaded_decl (decl, forgettable) { tree tmp; - for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp)) - if (decl == tmp || duplicate_decls (decl, tmp)) - return tmp; + for (tmp = old; tmp; tmp = OVL_NEXT (tmp)) + if (decl == OVL_CURRENT (tmp) + || duplicate_decls (decl, OVL_CURRENT (tmp))) + return OVL_CURRENT (tmp); } else { @@ -3704,19 +3975,16 @@ push_overloaded_decl (decl, forgettable) if (old || TREE_CODE (decl) == TEMPLATE_DECL) { - if (old && is_overloaded_fn (old)) - DECL_CHAIN (decl) = get_first_fn (old); - else - DECL_CHAIN (decl) = NULL_TREE; - old = tree_cons (orig_name, decl, NULL_TREE); - TREE_TYPE (old) = unknown_type_node; + if (old && TREE_CODE (old) != OVERLOAD) + old = ovl_cons (old, NULL_TREE); + old = ovl_cons (decl, old); } else /* orig_name is not ambiguous. */ old = decl; if (doing_global) - IDENTIFIER_GLOBAL_VALUE (orig_name) = old; + set_namespace_binding (orig_name, current_namespace, old); else IDENTIFIER_LOCAL_VALUE (orig_name) = old; @@ -3738,7 +4006,7 @@ implicitly_declare (functionid) /* Save the decl permanently so we can warn if definition follows. In ANSI C, warn_implicit is usually false, so the saves little space. But in C++, it's usually true, hence the extra code. */ - if (temp && (flag_traditional || !warn_implicit || toplevel_bindings_p ())) + if (temp && (! warn_implicit || toplevel_bindings_p ())) end_temporary_allocation (); /* We used to reuse an old implicit decl here, @@ -3750,8 +4018,7 @@ implicitly_declare (functionid) TREE_PUBLIC (decl) = 1; /* ANSI standard says implicit declarations are in the innermost block. - So we record the decl in the standard fashion. - If flag_traditional is set, pushdecl does it top-level. */ + So we record the decl in the standard fashion. */ pushdecl (decl); rest_of_decl_compilation (decl, NULL_PTR, 0, 0); @@ -3797,10 +4064,16 @@ redeclaration_error_message (newdecl, olddecl) if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl)) return 0; + /* If both functions come from different namespaces, this is not + a redeclaration - this is a conflict with a used function. */ + if (DECL_NAMESPACE_SCOPE_P (olddecl) + && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)) + return "`%D' conflicts with used function"; + /* We'll complain about linkage mismatches in warn_extern_redeclared_static. */ - /* defining the same name twice is no good. */ + /* Defining the same name twice is no good. */ if (DECL_INITIAL (olddecl) != NULL_TREE && DECL_INITIAL (newdecl) != NULL_TREE) { @@ -3813,11 +4086,16 @@ redeclaration_error_message (newdecl, olddecl) } else if (TREE_CODE (newdecl) == TEMPLATE_DECL) { - if (DECL_INITIAL (olddecl) && DECL_INITIAL (newdecl)) + if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL + && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) + && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl))) + || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL + && TYPE_SIZE (TREE_TYPE (newdecl)) + && TYPE_SIZE (TREE_TYPE (olddecl)))) return "redefinition of `%#D'"; return 0; } - else if (current_binding_level == global_binding_level) + else if (toplevel_bindings_p ()) { /* Objects declared at top level: */ /* If at least one is a reference, it's ok. */ @@ -3856,13 +4134,20 @@ lookup_label (id) if ((decl == NULL_TREE || DECL_SOURCE_LINE (decl) == 0) - && (named_label_uses == NULL_TREE - || TREE_PURPOSE (named_label_uses) != current_binding_level->names - || TREE_VALUE (named_label_uses) != decl)) - { - named_label_uses - = tree_cons (current_binding_level->names, decl, named_label_uses); - TREE_TYPE (named_label_uses) = (tree)current_binding_level; + && (named_label_uses == NULL + || named_label_uses->names_in_scope != current_binding_level->names + || named_label_uses->label_decl != decl)) + { + struct named_label_list *new_ent; + new_ent + = (struct named_label_list*)oballoc (sizeof (struct named_label_list)); + new_ent->label_decl = decl; + new_ent->names_in_scope = current_binding_level->names; + new_ent->binding_level = current_binding_level; + new_ent->lineno_o_goto = lineno; + new_ent->filename_o_goto = input_filename; + new_ent->next = named_label_uses; + named_label_uses = new_ent; } /* Use a label already defined or ref'd with this name. */ @@ -3877,6 +4162,9 @@ lookup_label (id) decl = build_decl (LABEL_DECL, id, void_type_node); + /* Make sure every label has an rtx. */ + label_rtx (decl); + /* A label not explicitly declared must be local to where it's ref'd. */ DECL_CONTEXT (decl) = current_function_decl; @@ -3890,7 +4178,7 @@ lookup_label (id) SET_IDENTIFIER_LABEL_VALUE (id, decl); named_labels = tree_cons (NULL_TREE, decl, named_labels); - TREE_VALUE (named_label_uses) = decl; + named_label_uses->label_decl = decl; return decl; } @@ -3913,7 +4201,6 @@ shadow_label (name) { shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); - SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE); } return lookup_label (name); @@ -3929,7 +4216,20 @@ define_label (filename, line, name) int line; tree name; { - tree decl = lookup_label (name); + tree decl; + + if (minimal_parse_mode) + { + push_obstacks (&permanent_obstack, &permanent_obstack); + decl = build_decl (LABEL_DECL, name, void_type_node); + pop_obstacks (); + DECL_SOURCE_LINE (decl) = line; + DECL_SOURCE_FILE (decl) = filename; + add_tree (decl); + return decl; + } + + decl = lookup_label (name); /* After labels, make any new cleanups go into their own new (temporary) binding contour. */ @@ -3953,7 +4253,7 @@ define_label (filename, line, name) } else { - tree uses, prev; + struct named_label_list *uses, *prev; int identified = 0; /* Mark label as having been defined. */ @@ -3962,17 +4262,17 @@ define_label (filename, line, name) DECL_SOURCE_FILE (decl) = filename; DECL_SOURCE_LINE (decl) = line; - for (prev = NULL_TREE, uses = named_label_uses; - uses; - prev = uses, uses = TREE_CHAIN (uses)) - if (TREE_VALUE (uses) == decl) + prev = NULL; + uses = named_label_uses; + while (uses != NULL) + if (uses->label_decl == decl) { struct binding_level *b = current_binding_level; while (b) { tree new_decls = b->names; - tree old_decls = ((tree)b == TREE_TYPE (uses) - ? TREE_PURPOSE (uses) : NULL_TREE); + tree old_decls = (b == uses->binding_level) + ? uses->names_in_scope : NULL_TREE; while (new_decls != old_decls) { if (TREE_CODE (new_decls) == VAR_DECL @@ -3985,23 +4285,35 @@ define_label (filename, line, name) && DECL_INITIAL (new_decls) != error_mark_node) || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) { - if (! identified) - cp_error ("jump to label `%D'", decl); - identified = 1; + if (! identified) + { + cp_error ("jump to label `%D'", decl); + error_with_file_and_line (uses->filename_o_goto, + uses->lineno_o_goto, + " from here"); + identified = 1; + } cp_error_at (" crosses initialization of `%#D'", new_decls); } new_decls = TREE_CHAIN (new_decls); } - if ((tree)b == TREE_TYPE (uses)) + if (b == uses->binding_level) break; b = b->level_chain; } - if (prev) - TREE_CHAIN (prev) = TREE_CHAIN (uses); + if (prev != NULL) + prev->next = uses->next; else - named_label_uses = TREE_CHAIN (uses); + named_label_uses = uses->next; + + uses = uses->next; + } + else + { + prev = uses; + uses = uses->next; } current_function_return_value = NULL_TREE; return decl; @@ -4034,6 +4346,7 @@ pop_switch () /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */ /* XXX Note decl is never actually used. (bpk) */ + void define_case_label (decl) tree decl; @@ -4139,8 +4452,8 @@ storetags (tags) static tree lookup_tag (form, name, binding_level, thislevel_only) enum tree_code form; - struct binding_level *binding_level; tree name; + struct binding_level *binding_level; int thislevel_only; { register struct binding_level *level; @@ -4156,6 +4469,27 @@ lookup_tag (form, name, binding_level, thislevel_only) if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name) return TREE_VALUE (tail); } + else if (level->namespace_p) + /* Do namespace lookup. */ + /* XXX: is this a real lookup, considering using-directives etc. ??? */ + for (tail = current_namespace; 1; tail = CP_DECL_CONTEXT (tail)) + { + tree old = BINDING_TYPE (binding_for_name (name, tail)); + /* If it has an original type, it is a typedef, and we + should not return it. */ + if (old && DECL_ORIGINAL_TYPE (TYPE_NAME (old))) + old = NULL_TREE; + if (old && TREE_CODE (old) != form + && !(form != ENUMERAL_TYPE && TREE_CODE (old) == TEMPLATE_DECL)) + { + cp_error ("`%#D' redeclared as %C", old, form); + return NULL_TREE; + } + if (old) + return old; + if (thislevel_only || tail == global_namespace) + return NULL_TREE; + } else for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) { @@ -4165,21 +4499,30 @@ lookup_tag (form, name, binding_level, thislevel_only) /* Should tighten this up; it'll probably permit UNION_TYPE and a struct template, for example. */ if (code != form - && !(form != ENUMERAL_TYPE - && (code == TEMPLATE_DECL - || code == UNINSTANTIATED_P_TYPE))) - + && !(form != ENUMERAL_TYPE && code == TEMPLATE_DECL)) { /* Definition isn't the kind we were looking for. */ cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail), form); + return NULL_TREE; } return TREE_VALUE (tail); } } if (thislevel_only && ! level->tag_transparent) - return NULL_TREE; - if (current_class_type && level->level_chain == global_binding_level) + { + if (level->pseudo_global) + { + tree t = IDENTIFIER_CLASS_VALUE (name); + if (t && DECL_CLASS_TEMPLATE_P (t)) + return TREE_TYPE (t); + t = IDENTIFIER_NAMESPACE_VALUE (name); + if (t && DECL_CLASS_TEMPLATE_P (t)) + return TREE_TYPE (t); + } + return NULL_TREE; + } + if (current_class_type && level->level_chain->namespace_p) { /* Try looking in this class's tags before heading into global binding level. */ @@ -4208,6 +4551,7 @@ lookup_tag (form, name, binding_level, thislevel_only) { cp_error ("`%#D' redeclared as %C in class scope", TREE_VALUE (tail), form); + return NULL_TREE; } return TREE_VALUE (tail); } @@ -4218,7 +4562,7 @@ lookup_tag (form, name, binding_level, thislevel_only) if (TYPE_SIZE (context) == NULL_TREE) goto no_context; /* Go to next enclosing type, if any. */ - context = DECL_CONTEXT (TYPE_NAME (context)); + context = DECL_CONTEXT (TYPE_MAIN_DECL (context)); break; case 'd': context = DECL_CONTEXT (context); @@ -4235,12 +4579,14 @@ lookup_tag (form, name, binding_level, thislevel_only) return NULL_TREE; } +#if 0 void set_current_level_tags_transparency (tags_transparent) int tags_transparent; { current_binding_level->tag_transparent = tags_transparent; } +#endif /* Given a type, find the tag that was defined for it and return the tag name. Otherwise return 0. However, the value can never be 0 @@ -4271,36 +4617,10 @@ lookup_tag_reverse (type, name) } return NULL_TREE; } - -/* Given type TYPE which was not declared in C++ language context, - attempt to find a name by which it is referred. */ -tree -typedecl_for_tag (tag) - tree tag; -{ - struct binding_level *b = current_binding_level; - - if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL) - return TYPE_NAME (tag); - - while (b) - { - tree decls = b->names; - while (decls) - { - if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag) - break; - decls = TREE_CHAIN (decls); - } - if (decls) - return decls; - b = b->level_chain; - } - return NULL_TREE; -} /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL). Return the type value, or NULL_TREE if not found. */ + static tree lookup_nested_type (type, context) tree type; @@ -4341,22 +4661,233 @@ lookup_nested_type (type, context) } /* Look up NAME in the NAMESPACE. */ + tree lookup_namespace_name (namespace, name) tree namespace, name; { - struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace); - tree x; + struct tree_binding _b; + tree val; + + my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 370); + my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 373); + + val = binding_init (&_b); + if (!qualified_lookup_using_namespace (name, namespace, val, 0)) + return error_mark_node; - for (x = NULL_TREE; b && !x; b = b->level_chain) + if (BINDING_VALUE (val)) { - for (x = b->names; x; x = TREE_CHAIN (x)) - if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name) - break; - /* Must find directly in the namespace. */ - break; + val = BINDING_VALUE (val); + + /* If we have a single function from a using decl, pull it out. */ + if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val)) + val = OVL_FUNCTION (val); + return val; } - return x; + + cp_error ("`%D' undeclared in namespace `%D'", name, namespace); + return error_mark_node; +} + +tree +make_typename_type (context, name) + tree context, name; +{ + tree t, d; + tree fullname; + + if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') + name = TYPE_IDENTIFIER (name); + else if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + + fullname = name; + + if (TREE_CODE (name) == TEMPLATE_ID_EXPR) + { + name = TREE_OPERAND (name, 0); + if (TREE_CODE (name) == TEMPLATE_DECL) + name = TREE_OPERAND (fullname, 0) = DECL_NAME (name); + } + if (TREE_CODE (name) != IDENTIFIER_NODE) + my_friendly_abort (2000); + + if (! uses_template_parms (context) + || currently_open_class (context)) + { + if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR) + { + if (IS_AGGR_TYPE (context)) + t = lookup_field (context, name, 0, 0); + else + t = NULL_TREE; + + if (t == NULL_TREE || TREE_CODE (t) != TEMPLATE_DECL + || TREE_CODE (DECL_RESULT (t)) != TYPE_DECL) + { + cp_error ("no class template named `%#T' in `%#T'", + name, context); + return error_mark_node; + } + + return lookup_template_class (t, TREE_OPERAND (fullname, 1), + NULL_TREE, context); + } + else + { + if (IS_AGGR_TYPE (context)) + t = lookup_field (context, name, 0, 1); + else + t = NULL_TREE; + + if (t == NULL_TREE) + { + cp_error ("no type named `%#T' in `%#T'", name, context); + return error_mark_node; + } + + return TREE_TYPE (t); + } + } + + if (processing_template_decl) + push_obstacks (&permanent_obstack, &permanent_obstack); + t = make_lang_type (TYPENAME_TYPE); + TYPENAME_TYPE_FULLNAME (t) = fullname; + d = build_decl (TYPE_DECL, name, t); + if (processing_template_decl) + pop_obstacks (); + + TYPE_CONTEXT (t) = FROB_CONTEXT (context); + TYPE_NAME (TREE_TYPE (d)) = d; + TYPE_STUB_DECL (TREE_TYPE (d)) = d; + DECL_CONTEXT (d) = FROB_CONTEXT (context); + CLASSTYPE_GOT_SEMICOLON (t) = 1; + + return t; +} + +/* Select the right _DECL from multiple choices. */ + +static tree +select_decl (binding, flags) + tree binding; + int flags; +{ + tree val; + val = BINDING_VALUE (binding); + if (LOOKUP_NAMESPACES_ONLY (flags)) + { + /* We are not interested in types. */ + if (val && TREE_CODE (val) == NAMESPACE_DECL) + return val; + return NULL_TREE; + } + + /* If we could have a type and + we have nothing or we need a type and have none. */ + if (BINDING_TYPE (binding) + && (!val || ((flags & LOOKUP_PREFER_TYPES) + && TREE_CODE (val) != TYPE_DECL))) + val = TYPE_STUB_DECL (BINDING_TYPE (binding)); + /* Don't return non-types if we really prefer types. */ + else if (val && LOOKUP_TYPES_ONLY (flags) && TREE_CODE (val) != TYPE_DECL + && (!looking_for_template || TREE_CODE (val) != TEMPLATE_DECL)) + val = NULL_TREE; + + return val; +} + +/* Unscoped lookup of a global, iterate over namespaces, considering + using namespace statements. */ + +static tree +unqualified_namespace_lookup (name, flags) + tree name; + int flags; +{ + struct tree_binding _binding; + tree b = binding_init (&_binding); + tree initial = current_decl_namespace(); + tree scope = initial; + tree siter; + struct binding_level *level; + tree val = NULL_TREE; + + while (!val) + { + val = binding_for_name (name, scope); + + /* Initialize binding for this context. */ + BINDING_VALUE (b) = BINDING_VALUE (val); + BINDING_TYPE (b) = BINDING_TYPE (val); + + /* Add all _DECLs seen through local using-directives. */ + for (level = current_binding_level; + !level->namespace_p; + level = level->level_chain) + if (!lookup_using_namespace (name, b, level->using_directives, + scope, flags)) + /* Give up because of error. */ + return NULL_TREE; + + /* Add all _DECLs seen through global using-directives. */ + /* XXX local and global using lists should work equally. */ + siter = initial; + while (1) + { + if (!lookup_using_namespace (name, b, DECL_NAMESPACE_USING (siter), + scope, flags)) + /* Give up because of error. */ + return NULL_TREE; + if (siter == scope) break; + siter = CP_DECL_CONTEXT (siter); + } + + val = select_decl (b, flags); + if (scope == global_namespace) + break; + scope = CP_DECL_CONTEXT (scope); + } + return val; +} + +/* Combine prefer_type and namespaces_only into flags. */ + +static int +lookup_flags (prefer_type, namespaces_only) + int prefer_type, namespaces_only; +{ + if (namespaces_only) + return LOOKUP_PREFER_NAMESPACES; + if (prefer_type > 1) + return LOOKUP_PREFER_TYPES; + if (prefer_type > 0) + return LOOKUP_PREFER_BOTH; + return 0; +} + +/* Given a lookup that returned VAL, use FLAGS to decide if we want to + ignore it or not. Subroutine of lookup_name_real. */ + +static tree +qualify_lookup (val, flags) + tree val; + int flags; +{ + if (val == NULL_TREE) + return val; + if ((flags & LOOKUP_PREFER_NAMESPACES) && TREE_CODE (val) == NAMESPACE_DECL) + return val; + if ((flags & LOOKUP_PREFER_TYPES) + && (TREE_CODE (val) == TYPE_DECL + || ((flags & LOOKUP_TEMPLATES_EXPECTED) + && DECL_CLASS_TEMPLATE_P (val)))) + return val; + if (flags & (LOOKUP_PREFER_NAMESPACES | LOOKUP_PREFER_TYPES)) + return NULL_TREE; + return val; } /* Look up NAME in the current binding level and its superiors in the @@ -4365,27 +4896,48 @@ lookup_namespace_name (namespace, name) such declaration, or return a TREE_LIST with all the overloaded definitions if there are many, or return 0 if it is undefined. - If PREFER_TYPE is > 0, we prefer TYPE_DECLs. + If PREFER_TYPE is > 0, we prefer TYPE_DECLs or namespaces. + If PREFER_TYPE is > 1, we reject non-type decls (e.g. namespaces). If PREFER_TYPE is -2, we're being called from yylex(). (UGLY) - Otherwise we prefer non-TYPE_DECLs. */ + Otherwise we prefer non-TYPE_DECLs. -tree -lookup_name_real (name, prefer_type, nonclass) + If NONCLASS is non-zero, we don't look for the NAME in class scope, + using IDENTIFIER_CLASS_VALUE. */ + +static tree +lookup_name_real (name, prefer_type, nonclass, namespaces_only) tree name; - int prefer_type, nonclass; + int prefer_type, nonclass, namespaces_only; { register tree val; int yylex = 0; tree from_obj = NULL_TREE; + tree locval, classval; + int flags; + + /* Hack: copy flag set by parser, if set. */ + if (only_namespace_names) + namespaces_only = 1; if (prefer_type == -2) { extern int looking_for_typename; - tree type; + tree type = NULL_TREE; yylex = 1; prefer_type = looking_for_typename; + flags = lookup_flags (prefer_type, namespaces_only); + /* During parsing, we need to complain. */ + flags |= LOOKUP_COMPLAIN; + /* If the next thing is '<', class templates are types. */ + if (looking_for_template) + flags |= LOOKUP_TEMPLATES_EXPECTED; + + /* std:: becomes :: for now. */ + if (got_scope == std_node) + got_scope = void_type_node; + if (got_scope) type = got_scope; else if (got_object != error_mark_node) @@ -4395,23 +4947,27 @@ lookup_name_real (name, prefer_type, nonclass) { if (type == error_mark_node) return error_mark_node; - else if (type == void_type_node) - val = IDENTIFIER_GLOBAL_VALUE (name); - else if (TREE_CODE (type) == TEMPLATE_TYPE_PARM - /* TFIXME -- don't do this for UPTs in new model. */ - || TREE_CODE (type) == UNINSTANTIATED_P_TYPE) - { - if (prefer_type > 0) - val = create_nested_upt (type, name); - else - val = NULL_TREE; - } - else if (TREE_CODE (type) == NAMESPACE_DECL) + if (TREE_CODE (type) == TYPENAME_TYPE && TREE_TYPE (type)) + type = TREE_TYPE (type); + + if (TYPE_P (type)) + type = complete_type (type); + + if (TREE_CODE (type) == VOID_TYPE) + type = global_namespace; + if (TREE_CODE (type) == NAMESPACE_DECL) { - val = lookup_namespace_name (type, name); + struct tree_binding b; + val = binding_init (&b); + if (!qualified_lookup_using_namespace (name, type, val, flags)) + return NULL_TREE; + val = select_decl (val, flags); } - else if (! IS_AGGR_TYPE (type)) - /* Someone else will give an error about this if needed. */ + else if (! IS_AGGR_TYPE (type) + || TREE_CODE (type) == TEMPLATE_TYPE_PARM + || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM + || TREE_CODE (type) == TYPENAME_TYPE) + /* Someone else will give an error about this if needed. */ val = NULL_TREE; else if (TYPE_BEING_DEFINED (type)) { @@ -4430,68 +4986,128 @@ lookup_name_real (name, prefer_type, nonclass) } } } - if (val == NULL_TREE - && CLASSTYPE_LOCAL_TYPEDECLS (type)) + if (val == NULL_TREE) val = lookup_field (type, name, 0, 1); } else if (type == current_class_type) val = IDENTIFIER_CLASS_VALUE (name); else - val = lookup_field (type, name, 0, prefer_type); + val = lookup_member (type, name, 0, prefer_type); } else val = NULL_TREE; if (got_scope) goto done; - - /* This special lookup only applies to types. */ - else if (got_object && val && TREE_CODE (val) == TYPE_DECL) + else if (got_object && val) from_obj = val; } - - if (current_binding_level != global_binding_level - && IDENTIFIER_LOCAL_VALUE (name)) - val = IDENTIFIER_LOCAL_VALUE (name); + else + flags = lookup_flags (prefer_type, namespaces_only); + + locval = classval = NULL_TREE; + + if (! namespace_bindings_p ()) + locval = qualify_lookup (IDENTIFIER_LOCAL_VALUE (name), flags); + /* In C++ class fields are between local and global scope, just before the global scope. */ - else if (current_class_type && ! nonclass) + if (current_class_type && ! nonclass) { - val = IDENTIFIER_CLASS_VALUE (name); - if (val == NULL_TREE - && TYPE_BEING_DEFINED (current_class_type) - && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type)) + classval = IDENTIFIER_CLASS_VALUE (name); + if (classval == NULL_TREE && TYPE_BEING_DEFINED (current_class_type)) /* Try to find values from base classes if we are presently defining a type. We are presently only interested in TYPE_DECLs. */ - val = lookup_field (current_class_type, name, 0, 1); + classval = lookup_field (current_class_type, name, 0, 1); + + /* Add implicit 'typename' to types from template bases. lookup_field + will do this for us. If classval is actually from an enclosing + scope, lookup_nested_field will get it for us. */ + if (processing_template_decl + && classval && TREE_CODE (classval) == TYPE_DECL + && ! currently_open_class (DECL_CONTEXT (classval)) + && uses_template_parms (current_class_type) + && ! DECL_ARTIFICIAL (classval)) + classval = lookup_field (current_class_type, name, 0, 1); /* yylex() calls this with -2, since we should never start digging for the nested name at the point where we haven't even, for example, created the COMPONENT_REF or anything like that. */ - if (val == NULL_TREE) - val = lookup_nested_field (name, ! yylex); + if (classval == NULL_TREE) + classval = lookup_nested_field (name, ! yylex); + + classval = qualify_lookup (classval, flags); + } - if (val == NULL_TREE) - val = IDENTIFIER_GLOBAL_VALUE (name); + if (locval && classval) + { + if (current_scope () == current_function_decl + && ! hack_decl_function_context (current_function_decl)) + /* Not in a nested function. */ + val = locval; + else + { + /* This is incredibly horrible. The whole concept of + IDENTIFIER_LOCAL_VALUE / IDENTIFIER_CLASS_VALUE / + IDENTIFIER_GLOBAL_VALUE needs to be scrapped for local + classes. */ + tree lctx = hack_decl_function_context (locval); + tree cctx = hack_decl_function_context (classval); + + if (lctx == current_scope ()) + val = locval; + else if (lctx == cctx) + val = classval; + else + /* I don't know which is right; let's just guess for now. */ + val = locval; + } } + else if (locval) + val = locval; + else if (classval) + val = classval; else - val = IDENTIFIER_GLOBAL_VALUE (name); + val = unqualified_namespace_lookup (name, flags); done: if (val) { + /* This should only warn about types used in qualified-ids. */ if (from_obj && from_obj != val) - cp_error ("lookup in the scope of `%#T' does not match lookup in the current scope", - got_object); + { + if (looking_for_typename && TREE_CODE (from_obj) == TYPE_DECL + && TREE_CODE (val) == TYPE_DECL + && TREE_TYPE (from_obj) != TREE_TYPE (val)) + { + cp_pedwarn ("lookup of `%D' in the scope of `%#T' (`%#T')", + name, got_object, TREE_TYPE (from_obj)); + cp_pedwarn (" does not match lookup in the current scope (`%#T')", + TREE_TYPE (val)); + } + + /* We don't change val to from_obj if got_object depends on + template parms because that breaks implicit typename for + destructor calls. */ + if (! uses_template_parms (got_object)) + val = from_obj; + } if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template) || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0) ; + /* Caller wants a class-or-namespace-name. */ + else if (prefer_type == 1 && TREE_CODE (val) == NAMESPACE_DECL) + ; else if (IDENTIFIER_HAS_TYPE_VALUE (name)) - val = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name)); + val = TYPE_MAIN_DECL (IDENTIFIER_TYPE_VALUE (name)); else if (TREE_TYPE (val) == error_mark_node) val = error_mark_node; + + /* If we have a single function from a using decl, pull it out. */ + if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val)) + val = OVL_FUNCTION (val); } else if (from_obj) val = from_obj; @@ -4503,7 +5119,23 @@ tree lookup_name_nonclass (name) tree name; { - return lookup_name_real (name, 0, 1); + return lookup_name_real (name, 0, 1, 0); +} + +tree +lookup_function_nonclass (name, args) + tree name; + tree args; +{ + return lookup_arg_dependent (name, lookup_name_nonclass (name), args); +} + +tree +lookup_name_namespace_only (name) + tree name; +{ + /* type-or-namespace, nonclass, namespace_only */ + return lookup_name_real (name, 1, 1, 1); } tree @@ -4511,7 +5143,7 @@ lookup_name (name, prefer_type) tree name; int prefer_type; { - return lookup_name_real (name, prefer_type, 0); + return lookup_name_real (name, prefer_type, 0, 0); } /* Similar to `lookup_name' but look only at current binding level. */ @@ -4522,9 +5154,9 @@ lookup_name_current_level (name) { register tree t = NULL_TREE; - if (current_binding_level == global_binding_level) + if (current_binding_level->namespace_p) { - t = IDENTIFIER_GLOBAL_VALUE (name); + t = IDENTIFIER_NAMESPACE_VALUE (name); /* extern "C" function() */ if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST) @@ -4535,20 +5167,57 @@ lookup_name_current_level (name) struct binding_level *b = current_binding_level; while (1) { - for (t = b->names; t; t = TREE_CHAIN (t)) - if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name) - goto out; + if (purpose_member (name, b->shadowed)) + return IDENTIFIER_LOCAL_VALUE (name); if (b->keep == 2) b = b->level_chain; else break; } - out: - ; } return t; } + +/* Like lookup_name_current_level, but for types. */ + +tree +lookup_type_current_level (name) + tree name; +{ + register tree t = NULL_TREE; + + my_friendly_assert (! current_binding_level->namespace_p, 980716); + + if (REAL_IDENTIFIER_TYPE_VALUE (name) != NULL_TREE + && REAL_IDENTIFIER_TYPE_VALUE (name) != global_type_node) + { + struct binding_level *b = current_binding_level; + while (1) + { + if (purpose_member (name, b->type_shadowed)) + return REAL_IDENTIFIER_TYPE_VALUE (name); + if (b->keep == 2) + b = b->level_chain; + else + break; + } + } + + return t; +} + +void +begin_only_namespace_names () +{ + only_namespace_names = 1; +} + +void +end_only_namespace_names () +{ + only_namespace_names = 0; +} /* Arrange for the user to get a source line number, even when the compiler is going down in flames, so that she at least has a @@ -4559,7 +5228,7 @@ lookup_name_current_level (name) static void signal_catch (sig) - int sig; + int sig ATTRIBUTE_UNUSED; { signal (SIGSEGV, SIG_DFL); #ifdef SIGIOT @@ -4577,10 +5246,13 @@ signal_catch (sig) my_friendly_abort (0); } +#if 0 +/* Unused -- brendan 970107 */ /* Array for holding types considered "built-in". These types are output in the module in which `main' is defined. */ static tree *builtin_type_tdescs_arr; static int builtin_type_tdescs_len, builtin_type_tdescs_max; +#endif /* Push the declarations of builtin types into the namespace. RID_INDEX, if < RID_MAX is the index of the builtin type @@ -4594,7 +5266,7 @@ record_builtin_type (rid_index, name, type) tree type; { tree rname = NULL_TREE, tname = NULL_TREE; - tree tdecl; + tree tdecl = NULL_TREE; if ((int) rid_index < (int) RID_MAX) rname = ridpointers[(int) rid_index]; @@ -4605,84 +5277,77 @@ record_builtin_type (rid_index, name, type) if (tname) { -#if 0 /* not yet, should get fixed properly later */ - tdecl = pushdecl (make_type_decl (tname, type)); -#else tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); -#endif set_identifier_type_value (tname, NULL_TREE); if ((int) rid_index < (int) RID_MAX) - IDENTIFIER_GLOBAL_VALUE (tname) = tdecl; + /* Built-in types live in the global namespace. */ + SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl); } if (rname != NULL_TREE) { if (tname != NULL_TREE) { set_identifier_type_value (rname, NULL_TREE); - IDENTIFIER_GLOBAL_VALUE (rname) = tdecl; + SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl); } else { -#if 0 /* not yet, should get fixed properly later */ - tdecl = pushdecl (make_type_decl (rname, type)); -#else tdecl = pushdecl (build_decl (TYPE_DECL, rname, type)); -#endif set_identifier_type_value (rname, NULL_TREE); } } +} - if (flag_rtti) - { - if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max) - { - builtin_type_tdescs_max *= 2; - builtin_type_tdescs_arr - = (tree *)xrealloc (builtin_type_tdescs_arr, - builtin_type_tdescs_max * sizeof (tree)); - } - builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type; - if (TREE_CODE (type) != POINTER_TYPE) - { - builtin_type_tdescs_arr[builtin_type_tdescs_len++] - = build_pointer_type (type); - builtin_type_tdescs_arr[builtin_type_tdescs_len++] - = build_pointer_type (build_type_variant (type, 1, 0)); - } - if (TREE_CODE (type) != VOID_TYPE) - { - builtin_type_tdescs_arr[builtin_type_tdescs_len++] - = build_reference_type (type); - builtin_type_tdescs_arr[builtin_type_tdescs_len++] - = build_reference_type (build_type_variant (type, 1, 0)); - } +/* Record one of the standard Java types. + * Declare it as having the given NAME. + * If SIZE > 0, it is the size of one of the integral types; + * otherwise it is the negative of the size of one of the other types. */ + +static tree +record_builtin_java_type (name, size) + char *name; + int size; +{ + tree type, decl; + if (size > 0) + type = make_signed_type (size); + else if (size > -32) + { /* "__java_char" or ""__java_boolean". */ + type = make_unsigned_type (-size); + /*if (size == -1) TREE_SET_CODE (type, BOOLEAN_TYPE);*/ + } + else + { /* "__java_float" or ""__java_double". */ + type = make_node (REAL_TYPE); + TYPE_PRECISION (type) = - size; + layout_type (type); } + record_builtin_type (RID_MAX, name, type); + decl = TYPE_NAME (type); + DECL_IGNORED_P (decl) = 1; + TYPE_FOR_JAVA (type) = 1; + return type; } +/* Push a type into the namespace so that the back-ends ignore it. */ + static void -output_builtin_tdesc_entries () +record_unknown_type (type, name) + tree type; + char *name; { - extern struct obstack permanent_obstack; - - /* If there's more than one main in this file, don't crash. */ - if (builtin_type_tdescs_arr == 0) - return; - - push_obstacks (&permanent_obstack, &permanent_obstack); - while (builtin_type_tdescs_len > 0) - { - tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len]; - tree tdesc = build_t_desc (type, 0); - TREE_ASM_WRITTEN (tdesc) = 0; - build_t_desc (type, 2); - } - free (builtin_type_tdescs_arr); - builtin_type_tdescs_arr = 0; - pop_obstacks (); -} + tree decl = pushdecl (build_decl (TYPE_DECL, get_identifier (name), type)); + /* Make sure the "unknown type" typedecl gets ignored for debug info. */ + DECL_IGNORED_P (decl) = 1; + TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; + TYPE_SIZE (type) = TYPE_SIZE (void_type_node); + TYPE_ALIGN (type) = 1; + TYPE_MODE (type) = TYPE_MODE (void_type_node); +} /* Push overloaded decl, in global scope, with one argument so it can be used as a callback from define_function. */ + static void push_overloaded_decl_1 (x) tree x; @@ -4690,18 +5355,16 @@ push_overloaded_decl_1 (x) push_overloaded_decl (x, 0); } -#define builtin_function(NAME, TYPE, CODE, LIBNAME) \ - define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME) - #ifdef __GNUC__ __inline #endif -tree auto_function (name, type, code) +tree +auto_function (name, type, code) tree name, type; enum built_in_function code; { return define_function - (IDENTIFIER_POINTER (name), type, code, (void (*)())push_overloaded_decl_1, + (IDENTIFIER_POINTER (name), type, code, push_overloaded_decl_1, IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type), 0))); } @@ -4714,25 +5377,33 @@ tree auto_function (name, type, code) void init_decl_processing () { - tree decl; - register tree endlink, int_endlink, double_endlink, ptr_endlink; + register tree endlink, int_endlink, double_endlink, unsigned_endlink; tree fields[20]; - /* Either char* or void*. */ - tree traditional_ptr_type_node; /* Data type of memcpy. */ - tree memcpy_ftype; -#if 0 /* Not yet. */ - /* Data type of strncpy. */ - tree strncpy_ftype; -#endif + tree memcpy_ftype, strlen_ftype; int wchar_type_size; tree temp; tree array_domain_type; extern int flag_strict_prototype; + tree vb_off_identifier = NULL_TREE; + /* Function type `char *(char *, char *)' and similar ones */ + tree string_ftype_ptr_ptr, int_ftype_string_string; + tree sizetype_endlink; + tree ptr_ftype, ptr_ftype_unsigned, ptr_ftype_sizetype; + tree void_ftype, void_ftype_int, void_ftype_ptr, ptr_ftype_void; /* Have to make these distinct before we try using them. */ lang_name_cplusplus = get_identifier ("C++"); lang_name_c = get_identifier ("C"); + lang_name_java = get_identifier ("Java"); + + /* Enter the global namespace. */ + my_friendly_assert (global_namespace == NULL_TREE, 375); + my_friendly_assert (current_lang_name == NULL_TREE, 375); + current_lang_name = lang_name_cplusplus; + push_namespace (get_identifier ("::")); + global_namespace = current_namespace; + current_lang_name = NULL_TREE; if (flag_strict_prototype == 2) { @@ -4747,19 +5418,20 @@ init_decl_processing () current_function_decl = NULL_TREE; named_labels = NULL_TREE; - named_label_uses = NULL_TREE; + named_label_uses = NULL; current_binding_level = NULL_BINDING_LEVEL; free_binding_level = NULL_BINDING_LEVEL; +#ifndef __CYGWIN32__ /* Because most segmentation signals can be traced back into user code, catch them and at least give the user a chance of working - around compiler bugs. */ + around compiler bugs. */ signal (SIGSEGV, signal_catch); /* We will also catch aborts in the back-end through signal_catch and give the user a chance to see where the error might be, and to defeat aborts in the back-end when there have been errors previously in their - code. */ + code. */ #ifdef SIGIOT signal (SIGIOT, signal_catch); #endif @@ -4772,13 +5444,15 @@ init_decl_processing () #ifdef SIGBUS signal (SIGBUS, signal_catch); #endif +#else /* ndef __CYGWIN32__ */ + /* Cygwin32 cannot handle catching signals other than + SIGABRT yet. We hope this will cease to be the case soon. */ +#ifdef SIGABRT + signal (SIGABRT, signal_catch); +#endif +#endif /* ndef __CYGWIN32__ */ gcc_obstack_init (&decl_obstack); - if (flag_rtti) - { - builtin_type_tdescs_max = 100; - builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree)); - } /* Must lay these out before anything else gets laid out. */ error_mark_node = make_node (ERROR_MARK); @@ -4790,9 +5464,14 @@ init_decl_processing () /* Make the binding_level structure for global names. */ pushlevel (0); global_binding_level = current_binding_level; + /* The global level is the namespace level of ::. */ + NAMESPACE_LEVEL (global_namespace) = global_binding_level; + declare_namespace_level (); this_identifier = get_identifier (THIS_NAME); in_charge_identifier = get_identifier (IN_CHARGE_NAME); + ctor_identifier = get_identifier (CTOR_NAME); + dtor_identifier = get_identifier (DTOR_NAME); pfn_identifier = get_identifier (VTABLE_PFN_NAME); index_identifier = get_identifier (VTABLE_INDEX_NAME); delta_identifier = get_identifier (VTABLE_DELTA_NAME); @@ -4813,10 +5492,10 @@ init_decl_processing () /* Define `char', which is like either `signed char' or `unsigned char' but not the same as either. */ - char_type_node = - (flag_signed_char - ? make_signed_type (CHAR_TYPE_SIZE) - : make_unsigned_type (CHAR_TYPE_SIZE)); + char_type_node + = (flag_signed_char + ? make_signed_type (CHAR_TYPE_SIZE) + : make_unsigned_type (CHAR_TYPE_SIZE)); record_builtin_type (RID_CHAR, "char", char_type_node); long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); @@ -4838,32 +5517,21 @@ init_decl_processing () record_builtin_type (RID_MAX, "long long unsigned", long_long_unsigned_type_node); - /* `unsigned long' is the standard type for sizeof. - Traditionally, use a signed type. - Note that stddef.h uses `unsigned long', - and this must agree, even of long and int are the same size. */ - sizetype - = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE))); - if (flag_traditional && TREE_UNSIGNED (sizetype)) - sizetype = signed_type (sizetype); - - ptrdiff_type_node - = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); - - TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype; - TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype; - TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype; - TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype; - TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype; - TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype; - TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype; - short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); record_builtin_type (RID_SHORT, "short int", short_integer_type_node); short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node); record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node); + /* `unsigned long' is the standard type for sizeof. + Note that stddef.h uses `unsigned long', + and this must agree, even if long and int are the same size. */ + set_sizetype + (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)))); + + ptrdiff_type_node + = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); + /* Define both `signed char' and `unsigned char'. */ signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); record_builtin_type (RID_MAX, "signed char", signed_char_type_node); @@ -4879,6 +5547,8 @@ init_decl_processing () pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); + intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, intTI_type_node)); unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); @@ -4887,6 +5557,8 @@ init_decl_processing () pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); + unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode)); + pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intTI_type_node)); float_type_node = make_node (REAL_TYPE); TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; @@ -4906,6 +5578,39 @@ init_decl_processing () record_builtin_type (RID_MAX, "long double", long_double_type_node); layout_type (long_double_type_node); + complex_integer_type_node = make_node (COMPLEX_TYPE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"), + complex_integer_type_node)); + TREE_TYPE (complex_integer_type_node) = integer_type_node; + layout_type (complex_integer_type_node); + + complex_float_type_node = make_node (COMPLEX_TYPE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"), + complex_float_type_node)); + TREE_TYPE (complex_float_type_node) = float_type_node; + layout_type (complex_float_type_node); + + complex_double_type_node = make_node (COMPLEX_TYPE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"), + complex_double_type_node)); + TREE_TYPE (complex_double_type_node) = double_type_node; + layout_type (complex_double_type_node); + + complex_long_double_type_node = make_node (COMPLEX_TYPE); + pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"), + complex_long_double_type_node)); + TREE_TYPE (complex_long_double_type_node) = long_double_type_node; + layout_type (complex_long_double_type_node); + + java_byte_type_node = record_builtin_java_type ("__java_byte", 8); + java_short_type_node = record_builtin_java_type ("__java_short", 16); + java_int_type_node = record_builtin_java_type ("__java_int", 32); + java_long_type_node = record_builtin_java_type ("__java_long", 64); + java_float_type_node = record_builtin_java_type ("__java_float", -32); + java_double_type_node = record_builtin_java_type ("__java_double", -64); + java_char_type_node = record_builtin_java_type ("__java_char", -16); + java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1); + integer_zero_node = build_int_2 (0, 0); TREE_TYPE (integer_zero_node) = integer_type_node; integer_one_node = build_int_2 (1, 0); @@ -4917,6 +5622,9 @@ init_decl_processing () boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); + TYPE_MAX_VALUE (boolean_type_node) = build_int_2 (1, 0); + TREE_TYPE (TYPE_MAX_VALUE (boolean_type_node)) = boolean_type_node; + TYPE_PRECISION (boolean_type_node) = 1; record_builtin_type (RID_BOOL, "bool", boolean_type_node); boolean_false_node = build_int_2 (0, 0); TREE_TYPE (boolean_false_node) = boolean_type_node; @@ -4927,6 +5635,9 @@ init_decl_processing () size_zero_node = size_int (0); size_one_node = size_int (1); + signed_size_zero_node = build_int_2 (0, 0); + TREE_TYPE (signed_size_zero_node) = make_signed_type (TYPE_PRECISION (sizetype)); + void_type_node = make_node (VOID_TYPE); record_builtin_type (RID_VOID, NULL_PTR, void_type_node); layout_type (void_type_node); /* Uses integer_zero_node. */ @@ -4936,15 +5647,17 @@ init_decl_processing () null_pointer_node = build_int_2 (0, 0); TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); layout_type (TREE_TYPE (null_pointer_node)); - + /* Used for expressions that do nothing, but are not errors. */ void_zero_node = build_int_2 (0, 0); TREE_TYPE (void_zero_node) = void_type_node; string_type_node = build_pointer_type (char_type_node); - const_string_type_node = - build_pointer_type (build_type_variant (char_type_node, 1, 0)); + const_string_type_node + = build_pointer_type (build_type_variant (char_type_node, 1, 0)); +#if 0 record_builtin_type (RID_MAX, NULL_PTR, string_type_node); +#endif /* Make a type to be the domain of a few array types whose domains don't really matter. @@ -4953,7 +5666,7 @@ init_decl_processing () initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ array_domain_type = build_index_type (build_int_2 (200, 0)); - /* make a type for arrays of characters. + /* Make a type for arrays of characters. With luck nothing will ever really depend on the length of this array type. */ char_array_type_node @@ -4968,20 +5681,45 @@ init_decl_processing () default_function_type = build_function_type (integer_type_node, NULL_TREE); - build_pointer_type (default_function_type); ptr_type_node = build_pointer_type (void_type_node); - const_ptr_type_node = - build_pointer_type (build_type_variant (void_type_node, 1, 0)); + const_ptr_type_node + = build_pointer_type (build_type_variant (void_type_node, 1, 0)); +#if 0 record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node); +#endif endlink = void_list_node; int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); double_endlink = tree_cons (NULL_TREE, double_type_node, endlink); - ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink); + unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink); + + ptr_ftype = build_function_type (ptr_type_node, NULL_TREE); + ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink); + sizetype_endlink = tree_cons (NULL_TREE, sizetype, endlink); + /* We realloc here because sizetype could be int or unsigned. S'ok. */ + ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink); + + void_ftype = build_function_type (void_type_node, endlink); + void_ftype_int = build_function_type (void_type_node, int_endlink); + void_ftype_ptr + = build_function_type (void_type_node, + tree_cons (NULL_TREE, ptr_type_node, endlink)); + void_ftype_ptr + = build_exception_variant (void_ftype_ptr, + tree_cons (NULL_TREE, NULL_TREE, NULL_TREE)); + + float_ftype_float + = build_function_type (float_type_node, + tree_cons (NULL_TREE, float_type_node, endlink)); double_ftype_double = build_function_type (double_type_node, double_endlink); + ldouble_ftype_ldouble + = build_function_type (long_double_type_node, + tree_cons (NULL_TREE, long_double_type_node, + endlink)); + double_ftype_double_double = build_function_type (double_type_node, tree_cons (NULL_TREE, double_type_node, @@ -4995,12 +5733,6 @@ init_decl_processing () tree_cons (NULL_TREE, long_integer_type_node, endlink)); - void_ftype_ptr_ptr_int - = build_function_type (void_type_node, - tree_cons (NULL_TREE, ptr_type_node, - tree_cons (NULL_TREE, ptr_type_node, - int_endlink))); - int_ftype_cptr_cptr_sizet = build_function_type (integer_type_node, tree_cons (NULL_TREE, const_ptr_type_node, @@ -5009,12 +5741,6 @@ init_decl_processing () sizetype, endlink)))); - void_ftype_ptr_int_int - = build_function_type (void_type_node, - tree_cons (NULL_TREE, ptr_type_node, - tree_cons (NULL_TREE, integer_type_node, - int_endlink))); - string_ftype_ptr_ptr /* strcpy prototype */ = build_function_type (string_type_node, tree_cons (NULL_TREE, string_type_node, @@ -5022,17 +5748,6 @@ init_decl_processing () const_string_type_node, endlink))); -#if 0 - /* Not yet. */ - strncpy_ftype /* strncpy prototype */ - = build_function_type (string_type_node, - tree_cons (NULL_TREE, string_type_node, - tree_cons (NULL_TREE, const_string_type_node, - tree_cons (NULL_TREE, - sizetype, - endlink)))); -#endif - int_ftype_string_string /* strcmp prototype */ = build_function_type (integer_type_node, tree_cons (NULL_TREE, const_string_type_node, @@ -5040,69 +5755,51 @@ init_decl_processing () const_string_type_node, endlink))); - sizet_ftype_string /* strlen prototype */ + strlen_ftype /* strlen prototype */ = build_function_type (sizetype, tree_cons (NULL_TREE, const_string_type_node, endlink)); - traditional_ptr_type_node - = (flag_traditional ? string_type_node : ptr_type_node); - memcpy_ftype /* memcpy prototype */ - = build_function_type (traditional_ptr_type_node, + = build_function_type (ptr_type_node, tree_cons (NULL_TREE, ptr_type_node, tree_cons (NULL_TREE, const_ptr_type_node, - tree_cons (NULL_TREE, - sizetype, - endlink)))); + sizetype_endlink))); if (flag_huge_objects) delta_type_node = long_integer_type_node; else delta_type_node = short_integer_type_node; - builtin_function ("__builtin_constant_p", int_ftype_int, + builtin_function ("__builtin_constant_p", default_function_type, BUILT_IN_CONSTANT_P, NULL_PTR); - builtin_return_address_fndecl = - builtin_function ("__builtin_return_address", - build_function_type (ptr_type_node, - tree_cons (NULL_TREE, - unsigned_type_node, - endlink)), - BUILT_IN_RETURN_ADDRESS, NULL_PTR); + builtin_return_address_fndecl + = builtin_function ("__builtin_return_address", ptr_ftype_unsigned, + BUILT_IN_RETURN_ADDRESS, NULL_PTR); - builtin_function ("__builtin_frame_address", - build_function_type (ptr_type_node, - tree_cons (NULL_TREE, - unsigned_type_node, - endlink)), + builtin_function ("__builtin_frame_address", ptr_ftype_unsigned, BUILT_IN_FRAME_ADDRESS, NULL_PTR); + ptr_ftype_void = build_function_type (ptr_type_node, endlink); + builtin_function ("__builtin_fp", ptr_ftype_void, BUILT_IN_FP, NULL_PTR); + builtin_function ("__builtin_sp", ptr_ftype_void, BUILT_IN_SP, NULL_PTR); - builtin_function ("__builtin_alloca", - build_function_type (ptr_type_node, - tree_cons (NULL_TREE, - sizetype, - endlink)), + builtin_function ("__builtin_alloca", ptr_ftype_sizetype, BUILT_IN_ALLOCA, "alloca"); + builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); /* Define alloca, ffs as builtins. Declare _exit just to mark it as volatile. */ if (! flag_no_builtin && !flag_no_nonansi_builtin) { - temp = builtin_function ("alloca", - build_function_type (ptr_type_node, - tree_cons (NULL_TREE, - sizetype, - endlink)), + temp = builtin_function ("alloca", ptr_ftype_sizetype, BUILT_IN_ALLOCA, NULL_PTR); /* Suppress error if redefined as a non-function. */ DECL_BUILT_IN_NONANSI (temp) = 1; temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); /* Suppress error if redefined as a non-function. */ DECL_BUILT_IN_NONANSI (temp) = 1; - temp = builtin_function ("_exit", build_function_type (void_type_node, - int_endlink), + temp = builtin_function ("_exit", void_ftype_int, NOT_BUILT_IN, NULL_PTR); TREE_THIS_VOLATILE (temp) = 1; TREE_SIDE_EFFECTS (temp) = 1; @@ -5110,65 +5807,48 @@ init_decl_processing () DECL_BUILT_IN_NONANSI (temp) = 1; } - builtin_function ("__builtin_abs", int_ftype_int, - BUILT_IN_ABS, NULL_PTR); - builtin_function ("__builtin_fabs", double_ftype_double, - BUILT_IN_FABS, NULL_PTR); + builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); + builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS, + NULL_PTR); + builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, + NULL_PTR); + builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, + NULL_PTR); builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); - builtin_function ("__builtin_ffs", int_ftype_int, - BUILT_IN_FFS, NULL_PTR); - builtin_function ("__builtin_fsqrt", double_ftype_double, - BUILT_IN_FSQRT, NULL_PTR); - builtin_function ("__builtin_sin", double_ftype_double, - BUILT_IN_SIN, "sin"); - builtin_function ("__builtin_cos", double_ftype_double, - BUILT_IN_COS, "cos"); - builtin_function ("__builtin_saveregs", - build_function_type (ptr_type_node, NULL_TREE), + builtin_function ("__builtin_saveregs", ptr_ftype, BUILT_IN_SAVEREGS, NULL_PTR); -/* EXPAND_BUILTIN_VARARGS is obsolete. */ -#if 0 - builtin_function ("__builtin_varargs", - build_function_type (ptr_type_node, - tree_cons (NULL_TREE, - integer_type_node, - endlink)), - BUILT_IN_VARARGS, NULL_PTR); -#endif builtin_function ("__builtin_classify_type", default_function_type, BUILT_IN_CLASSIFY_TYPE, NULL_PTR); - builtin_function ("__builtin_next_arg", - build_function_type (ptr_type_node, NULL_TREE), + builtin_function ("__builtin_next_arg", ptr_ftype, BUILT_IN_NEXT_ARG, NULL_PTR); - builtin_function ("__builtin_args_info", + builtin_function ("__builtin_args_info", int_ftype_int, + BUILT_IN_ARGS_INFO, NULL_PTR); + builtin_function ("__builtin_setjmp", build_function_type (integer_type_node, - tree_cons (NULL_TREE, - integer_type_node, + tree_cons (NULL_TREE, ptr_type_node, endlink)), - BUILT_IN_ARGS_INFO, NULL_PTR); + BUILT_IN_SETJMP, NULL_PTR); + builtin_function ("__builtin_longjmp", + build_function_type (integer_type_node, + tree_cons (NULL_TREE, ptr_type_node, + tree_cons (NULL_TREE, + integer_type_node, + endlink))), + BUILT_IN_LONGJMP, NULL_PTR); /* Untyped call and return. */ - builtin_function ("__builtin_apply_args", - build_function_type (ptr_type_node, NULL_TREE), + builtin_function ("__builtin_apply_args", ptr_ftype, BUILT_IN_APPLY_ARGS, NULL_PTR); temp = tree_cons (NULL_TREE, build_pointer_type (build_function_type (void_type_node, NULL_TREE)), - tree_cons (NULL_TREE, - ptr_type_node, - tree_cons (NULL_TREE, - sizetype, - endlink))); + tree_cons (NULL_TREE, ptr_ftype_sizetype, NULL_TREE)); builtin_function ("__builtin_apply", build_function_type (ptr_type_node, temp), BUILT_IN_APPLY, NULL_PTR); - builtin_function ("__builtin_return", - build_function_type (void_type_node, - tree_cons (NULL_TREE, - ptr_type_node, - endlink)), + builtin_function ("__builtin_return", void_ftype_ptr, BUILT_IN_RETURN, NULL_PTR); /* Currently under experimentation. */ @@ -5180,47 +5860,64 @@ init_decl_processing () BUILT_IN_STRCMP, "strcmp"); builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, "strcpy"); -#if 0 - /* Not yet. */ - builtin_function ("__builtin_strncpy", strncpy_ftype, - BUILT_IN_STRNCPY, "strncpy"); -#endif - builtin_function ("__builtin_strlen", sizet_ftype_string, + builtin_function ("__builtin_strlen", strlen_ftype, BUILT_IN_STRLEN, "strlen"); + builtin_function ("__builtin_sqrtf", float_ftype_float, + BUILT_IN_FSQRT, "sqrtf"); + builtin_function ("__builtin_fsqrt", double_ftype_double, + BUILT_IN_FSQRT, NULL_PTR); + builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble, + BUILT_IN_FSQRT, "sqrtl"); + builtin_function ("__builtin_sinf", float_ftype_float, + BUILT_IN_SIN, "sinf"); + builtin_function ("__builtin_sin", double_ftype_double, + BUILT_IN_SIN, "sin"); + builtin_function ("__builtin_sinl", ldouble_ftype_ldouble, + BUILT_IN_SIN, "sinl"); + builtin_function ("__builtin_cosf", float_ftype_float, + BUILT_IN_COS, "cosf"); + builtin_function ("__builtin_cos", double_ftype_double, + BUILT_IN_COS, "cos"); + builtin_function ("__builtin_cosl", ldouble_ftype_ldouble, + BUILT_IN_COS, "cosl"); if (!flag_no_builtin) { -#if 0 /* These do not work well with libg++. */ builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); -#endif + builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR); + builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, + NULL_PTR); builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, NULL_PTR); - builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR); + builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, + NULL_PTR); builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, NULL_PTR); -#if 0 - /* Not yet. */ - builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR); -#endif - builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR); + builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR); + builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR); + builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR); + builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT, + NULL_PTR); + builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR); builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); + builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR); + builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR); builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); + builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR); /* Declare these functions volatile to avoid spurious "control drops through" warnings. */ - temp = builtin_function ("abort", - build_function_type (void_type_node, endlink), + temp = builtin_function ("abort", void_ftype, NOT_BUILT_IN, NULL_PTR); TREE_THIS_VOLATILE (temp) = 1; TREE_SIDE_EFFECTS (temp) = 1; /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on them... */ DECL_BUILT_IN_NONANSI (temp) = 1; - temp = builtin_function ("exit", build_function_type (void_type_node, - int_endlink), + temp = builtin_function ("exit", void_ftype_int, NOT_BUILT_IN, NULL_PTR); TREE_THIS_VOLATILE (temp) = 1; TREE_SIDE_EFFECTS (temp) = 1; @@ -5230,42 +5927,39 @@ init_decl_processing () #if 0 /* Support for these has not been written in either expand_builtin or build_function_call. */ - builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0); - builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0); + builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR); + builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR); builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, - 0); - builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0); + NULL_PTR); + builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, + NULL_PTR); builtin_function ("__builtin_fmod", double_ftype_double_double, - BUILT_IN_FMOD, 0); + BUILT_IN_FMOD, NULL_PTR); builtin_function ("__builtin_frem", double_ftype_double_double, - BUILT_IN_FREM, 0); - builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, - 0); + BUILT_IN_FREM, NULL_PTR); + builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, + BUILT_IN_MEMSET, NULL_PTR); builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, - 0); + NULL_PTR); builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, - 0); + NULL_PTR); #endif /* C++ extensions */ unknown_type_node = make_node (UNKNOWN_TYPE); -#if 0 /* not yet, should get fixed properly later */ - pushdecl (make_type_decl (get_identifier ("unknown type"), - unknown_type_node)); -#else - decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"), - unknown_type_node)); - /* Make sure the "unknown type" typedecl gets ignored for debug info. */ - DECL_IGNORED_P (decl) = 1; - TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; -#endif - TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node); - TYPE_ALIGN (unknown_type_node) = 1; - TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node); + record_unknown_type (unknown_type_node, "unknown type"); + /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */ TREE_TYPE (unknown_type_node) = unknown_type_node; - /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */ + + if (flag_ansi) + TREE_TYPE (null_node) = type_for_size (POINTER_SIZE, 0); + else + TREE_TYPE (null_node) = build_pointer_type (unknown_type_node); + + /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same + result. */ TYPE_POINTER_TO (unknown_type_node) = unknown_type_node; TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node; @@ -5274,7 +5968,7 @@ init_decl_processing () TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node; record_builtin_type (RID_MAX, 0, opaque_type_node); - /* This is special for C++ so functions can be overloaded. */ + /* This is special for C++ so functions can be overloaded. */ wchar_type_node = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); wchar_type_size = TYPE_PRECISION (wchar_type_node); @@ -5295,14 +5989,6 @@ init_decl_processing () wchar_array_type_node = build_array_type (wchar_type_node, array_domain_type); - /* This is a hack that should go away when we deliver the - real gc code. */ - if (flag_gc) - { - builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0); - pushdecl (lookup_name (get_identifier ("__gc_main"), 0)); - } - if (flag_vtable_thunks) { /* Make sure we get a unique function type, so we can give @@ -5381,254 +6067,79 @@ init_decl_processing () record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type); } -#if 0 - if (flag_rtti) - { - /* Must build __t_desc type. Currently, type descriptors look like this: + std_node = build_decl (NAMESPACE_DECL, + get_identifier (flag_honor_std ? "fake std":"std"), + void_type_node); + pushdecl (std_node); - struct __t_desc - { - const char *name; - int size; - int bits; - struct __t_desc *points_to; - int ivars_count, meths_count; - struct __i_desc *ivars[]; - struct __m_desc *meths[]; - struct __t_desc *parents[]; - struct __t_desc *vbases[]; - int offsets[]; - }; - - ...as per Linton's paper. */ - - __t_desc_type_node = make_lang_type (RECORD_TYPE); - __i_desc_type_node = make_lang_type (RECORD_TYPE); - __m_desc_type_node = make_lang_type (RECORD_TYPE); - __t_desc_array_type = - build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE); - __i_desc_array_type = - build_array_type (build_pointer_type (__i_desc_type_node), NULL_TREE); - __m_desc_array_type = - build_array_type (build_pointer_type (__m_desc_type_node), NULL_TREE); - - fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), - string_type_node); - fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"), - unsigned_type_node); - fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"), - unsigned_type_node); - fields[3] = build_lang_field_decl (FIELD_DECL, - get_identifier ("points_to"), - build_pointer_type (__t_desc_type_node)); - fields[4] = build_lang_field_decl (FIELD_DECL, - get_identifier ("ivars_count"), - integer_type_node); - fields[5] = build_lang_field_decl (FIELD_DECL, - get_identifier ("meths_count"), - integer_type_node); - fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"), - build_pointer_type (__i_desc_array_type)); - fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"), - build_pointer_type (__m_desc_array_type)); - fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"), - build_pointer_type (__t_desc_array_type)); - fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"), - build_pointer_type (__t_desc_array_type)); - fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"), - build_pointer_type (integer_type_node)); - finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node); - - /* ivar descriptors look like this: - - struct __i_desc - { - const char *name; - int offset; - struct __t_desc *type; - }; - */ - - fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), - string_type_node); - fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"), - integer_type_node); - fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"), - build_pointer_type (__t_desc_type_node)); - finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, - integer_type_node); - - /* method descriptors look like this: - - struct __m_desc - { - const char *name; - int vindex; - struct __t_desc *vcontext; - struct __t_desc *return_type; - void (*address)(); - short parm_count; - short required_parms; - struct __t_desc *parm_types[]; - }; - */ - - fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"), - string_type_node); - fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"), - integer_type_node); - fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"), - build_pointer_type (__t_desc_type_node)); - fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"), - build_pointer_type (__t_desc_type_node)); - fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"), - build_pointer_type (default_function_type)); - fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"), - short_integer_type_node); - fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"), - short_integer_type_node); - fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"), - build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE))); - finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, - integer_type_node); - } - - if (flag_rtti) - { - int i = builtin_type_tdescs_len; - while (i > 0) - { - tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0); - TREE_ASM_WRITTEN (tdesc) = 1; - TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1; - } - } -#endif /*flag_rtti*/ + global_type_node = make_node (LANG_TYPE); + record_unknown_type (global_type_node, "global type"); /* Now, C++. */ current_lang_name = lang_name_cplusplus; - auto_function (ansi_opname[(int) NEW_EXPR], - build_function_type (ptr_type_node, - tree_cons (NULL_TREE, sizetype, - void_list_node)), - NOT_BUILT_IN); - auto_function (ansi_opname[(int) VEC_NEW_EXPR], - build_function_type (ptr_type_node, - tree_cons (NULL_TREE, sizetype, - void_list_node)), - NOT_BUILT_IN); - auto_function (ansi_opname[(int) DELETE_EXPR], - build_function_type (void_type_node, - tree_cons (NULL_TREE, ptr_type_node, - void_list_node)), - NOT_BUILT_IN); - auto_function (ansi_opname[(int) VEC_DELETE_EXPR], - build_function_type (void_type_node, - tree_cons (NULL_TREE, ptr_type_node, - void_list_node)), - NOT_BUILT_IN); + { + tree bad_alloc_type_node, newtype, deltype; + if (flag_honor_std) + push_namespace (get_identifier ("std")); + bad_alloc_type_node = xref_tag + (class_type_node, get_identifier ("bad_alloc"), NULL_TREE, 1); + if (flag_honor_std) + pop_namespace (); + newtype = build_exception_variant + (ptr_ftype_sizetype, build_tree_list (NULL_TREE, bad_alloc_type_node)); + deltype = build_exception_variant + (void_ftype_ptr, build_tree_list (NULL_TREE, NULL_TREE)); + auto_function (ansi_opname[(int) NEW_EXPR], newtype, NOT_BUILT_IN); + auto_function (ansi_opname[(int) VEC_NEW_EXPR], newtype, NOT_BUILT_IN); + auto_function (ansi_opname[(int) DELETE_EXPR], deltype, NOT_BUILT_IN); + auto_function (ansi_opname[(int) VEC_DELETE_EXPR], deltype, NOT_BUILT_IN); + } abort_fndecl - = define_function ("__pure_virtual", - build_function_type (void_type_node, void_list_node), + = define_function ("__pure_virtual", void_ftype, NOT_BUILT_IN, 0, 0); /* Perform other language dependent initializations. */ init_class_processing (); init_init_processing (); init_search_processing (); + if (flag_rtti) + init_rtti_processing (); - if (flag_handle_exceptions) + if (flag_exceptions) init_exception_processing (); - if (flag_gc) - init_gc_processing (); if (flag_no_inline) { flag_inline_functions = 0; -#if 0 - /* This causes unnecessary emission of inline functions. */ - flag_default_inline = 0; -#endif } - if (flag_cadillac) - init_cadillac (); + + if (! supports_one_only ()) + flag_weak = 0; /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ declare_function_name (); /* Prepare to check format strings against argument lists. */ init_function_format_info (); -} - -/* initialize type descriptor type node of various rtti type. */ - -int -init_type_desc() -{ - tree tdecl; - - tdecl = lookup_name (get_identifier ("type_info"), 0); - if (tdecl == NULL_TREE) - return 0; - __t_desc_type_node = TREE_TYPE(tdecl); - __tp_desc_type_node = build_pointer_type (__t_desc_type_node); - -#if 0 - tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0); - if (tdecl == NULL_TREE) - return 0; - __baselist_desc_type_node = TREE_TYPE (tdecl); -#endif - - tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0); - if (tdecl == NULL_TREE) - return 0; - __bltn_desc_type_node = TREE_TYPE (tdecl); - - tdecl = lookup_name (get_identifier ("__user_type_info"), 0); - if (tdecl == NULL_TREE) - return 0; - __user_desc_type_node = TREE_TYPE (tdecl); - - tdecl = lookup_name (get_identifier ("__class_type_info"), 0); - if (tdecl == NULL_TREE) - return 0; - __class_desc_type_node = TREE_TYPE (tdecl); - - tdecl = lookup_field (__class_desc_type_node, - get_identifier ("access_mode"), 0, 0); - if (tdecl == NULL_TREE) - return 0; - __access_mode_type_node = TREE_TYPE (tdecl); - tdecl = lookup_name (get_identifier ("__attr_type_info"), 0); - if (tdecl == NULL_TREE) - return 0; - __attr_desc_type_node = TREE_TYPE (tdecl); - - tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0); - if (tdecl == NULL_TREE) - return 0; - __ptr_desc_type_node = TREE_TYPE (tdecl); - - tdecl = lookup_name (get_identifier ("__func_type_info"), 0); - if (tdecl == NULL_TREE) - return 0; - __func_desc_type_node = TREE_TYPE (tdecl); + /* Show we use EH for cleanups. */ + using_eh_for_cleanups (); - tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0); - if (tdecl == NULL_TREE) - return 0; - __ptmf_desc_type_node = TREE_TYPE (tdecl); + print_error_function = lang_print_error_function; + lang_get_alias_set = &c_get_alias_set; +} - tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0); - if (tdecl == NULL_TREE) - return 0; - __ptmd_desc_type_node = TREE_TYPE (tdecl); +/* Function to print any language-specific context for an error message. */ - return 1; +static void +lang_print_error_function (file) + char *file; +{ + default_print_error_function (file); + maybe_print_template_context (); } + /* Make a definition for a builtin function named NAME and whose data type is TYPE. TYPE should be a function type with argument types. FUNCTION_CODE tells later passes how to compile calls to this function. @@ -5642,7 +6153,7 @@ define_function (name, type, function_code, pfn, library_name) char *name; tree type; enum built_in_function function_code; - void (*pfn)(); + void (*pfn) PROTO((tree)); char *library_name; { tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type); @@ -5650,6 +6161,9 @@ define_function (name, type, function_code, pfn, library_name) TREE_PUBLIC (decl) = 1; DECL_ARTIFICIAL (decl) = 1; + my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 392); + DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); + /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME, we cannot change DECL_ASSEMBLER_NAME until we have installed this function in the namespace. */ @@ -5693,10 +6207,20 @@ shadow_tag (declspecs) code = TREE_CODE (value); if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE) { - my_friendly_assert (TYPE_NAME (value) != NULL_TREE, 261); + my_friendly_assert (TYPE_MAIN_DECL (value) != NULL_TREE, 261); - if (code == ENUMERAL_TYPE && TYPE_SIZE (value) == 0) - cp_error ("forward declaration of `%#T'", value); + if (IS_AGGR_TYPE (value) && CLASSTYPE_USE_TEMPLATE (value)) + { + if (CLASSTYPE_IMPLICIT_INSTANTIATION (value) + && TYPE_SIZE (value) == NULL_TREE) + { + SET_CLASSTYPE_TEMPLATE_SPECIALIZATION (value); + if (processing_template_decl) + push_template_decl (TYPE_MAIN_DECL (value)); + } + else if (CLASSTYPE_TEMPLATE_INSTANTIATION (value)) + cp_error ("specialization after instantiation of `%T'", value); + } t = value; ok_code = code; @@ -5724,16 +6248,38 @@ shadow_tag (declspecs) || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))) { + /* See also grok_x_components. */ + tree *q; + + /* Wipe out memory of synthesized methods */ + TYPE_HAS_CONSTRUCTOR (t) = 0; + TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0; + TYPE_HAS_INIT_REF (t) = 0; + TYPE_HAS_CONST_INIT_REF (t) = 0; + TYPE_HAS_ASSIGN_REF (t) = 0; + TYPE_HAS_ASSIGNMENT (t) = 0; + TYPE_HAS_CONST_ASSIGN_REF (t) = 0; + + q = &TYPE_METHODS (t); + while (*q) + { + if (DECL_ARTIFICIAL (*q)) + *q = TREE_CHAIN (*q); + else + q = &TREE_CHAIN (*q); + } + /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have function members. */ + if (TYPE_METHODS (t)) + error ("an anonymous union cannot have function members"); + if (TYPE_FIELDS (t)) { tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, - NULL_TREE, NULL_TREE); + NULL_TREE); finish_anon_union (decl); } - else - error ("anonymous union cannot have a function member"); } else { @@ -5754,7 +6300,7 @@ shadow_tag (declspecs) } if (found_tag == 0) - pedwarn ("abstract declarator used as declaration"); + cp_error ("abstract declarator used as declaration"); else if (found_tag > 1) pedwarn ("multiple types in one declaration"); } @@ -5770,7 +6316,7 @@ groktypename (typename) return typename; return grokdeclarator (TREE_VALUE (typename), TREE_PURPOSE (typename), - TYPENAME, 0, NULL_TREE, NULL_TREE); + TYPENAME, 0, NULL_TREE); } /* Decode a declarator in an ordinary declaration or data definition. @@ -5793,10 +6339,10 @@ groktypename (typename) int debug_temp_inits = 1; tree -start_decl (declarator, declspecs, initialized, raises) +start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) tree declarator, declspecs; int initialized; - tree raises; + tree attributes, prefix_attributes; { register tree decl; register tree type, tem; @@ -5804,9 +6350,12 @@ start_decl (declarator, declspecs, initialized, raises) extern int have_extern_spec; extern int used_extern_spec; +#if 0 + /* See code below that used this. */ int init_written = initialized; +#endif - /* This should only be done once on the top most decl. */ + /* This should only be done once on the top most decl. */ if (have_extern_spec && !used_extern_spec) { declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), @@ -5814,16 +6363,16 @@ start_decl (declarator, declspecs, initialized, raises) used_extern_spec = 1; } - decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises, + decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, NULL_TREE); - if (decl == NULL_TREE || decl == void_type_node) + if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE) return NULL_TREE; type = TREE_TYPE (decl); /* Don't lose if destructors must be executed at file-level. */ - if (TREE_STATIC (decl) - && TYPE_NEEDS_DESTRUCTOR (type) + if (! processing_template_decl && TREE_STATIC (decl) + && TYPE_NEEDS_DESTRUCTOR (complete_type (type)) && !TREE_PERMANENT (decl)) { push_obstacks (&permanent_obstack, &permanent_obstack); @@ -5841,60 +6390,22 @@ start_decl (declarator, declspecs, initialized, raises) pop_obstacks (); } - /* Corresponding pop_obstacks is done in `cp_finish_decl'. */ - push_obstacks_nochange (); - context = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) ? DECL_CLASS_CONTEXT (decl) : DECL_CONTEXT (decl); - if (processing_template_decl) + if (initialized && context && TREE_CODE (context) == NAMESPACE_DECL + && context != current_namespace && TREE_CODE (decl) == VAR_DECL) { - tree d; - if (TREE_CODE (decl) == FUNCTION_DECL) - { - /* Declarator is a call_expr; extract arguments from it, since - grokdeclarator didn't do it. */ - tree args; - args = copy_to_permanent (last_function_parms); - if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) - { - tree t = TREE_TYPE (decl); - - t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */ - if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE) - { - t = build_pointer_type (t); /* base type of `this' */ -#if 1 - /* I suspect this is wrong. */ - t = build_type_variant (t, flag_this_is_variable <= 0, - 0); /* type of `this' */ -#else - t = build_type_variant (t, 0, 0); /* type of `this' */ -#endif - t = build (PARM_DECL, t, this_identifier); - TREE_CHAIN (t) = args; - args = t; - } - } - DECL_ARGUMENTS (decl) = args; - } - d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl)); - TREE_PUBLIC (d) = TREE_PUBLIC (decl); - TREE_STATIC (d) = TREE_STATIC (decl); - DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl) - && !(context && !DECL_THIS_EXTERN (decl))); - DECL_TEMPLATE_RESULT (d) = decl; - decl = d; + /* When parsing the initializer, lookup should use the object's + namespace. */ + push_decl_namespace (context); } - /* If this type of object needs a cleanup, and control may - jump past it, make a new binding level so that it is cleaned - up only when it is initialized first. */ - if (TYPE_NEEDS_DESTRUCTOR (type) - && current_binding_level->more_cleanups_ok == 0) - pushlevel_temporary (1); + /* We are only interested in class contexts, later. */ + if (context && TREE_CODE (context) == NAMESPACE_DECL) + context = NULL_TREE; if (initialized) /* Is it valid for this decl to have an initializer at all? @@ -5919,51 +6430,30 @@ start_decl (declarator, declspecs, initialized, raises) break; default: - /* Don't allow initializations for incomplete types except for - arrays which might be completed by the initialization. */ - if (type == error_mark_node) - ; /* Don't complain again. */ - else if (TYPE_SIZE (type) != NULL_TREE) - ; /* A complete type is ok. */ - else if (TREE_CODE (type) != ARRAY_TYPE) - { - cp_error ("variable `%#D' has initializer but incomplete type", - decl); - initialized = 0; - } - else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE) + if (! processing_template_decl) { - cp_error ("elements of array `%#D' have incomplete type", decl); - initialized = 0; + if (type != error_mark_node) + { + if (TYPE_SIZE (type) != NULL_TREE + && ! TREE_CONSTANT (TYPE_SIZE (type))) + { + cp_error + ("variable-sized object `%D' may not be initialized", + decl); + initialized = 0; + } + + if (TREE_CODE (type) == ARRAY_TYPE + && TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) + { + cp_error + ("elements of array `%#D' have incomplete type", decl); + initialized = 0; + } + } } } - if (!initialized - && TREE_CODE (decl) != TYPE_DECL - && TREE_CODE (decl) != TEMPLATE_DECL - && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) - { - if (TYPE_SIZE (type) == NULL_TREE) - { - cp_error ("aggregate `%#D' has incomplete type and cannot be initialized", - decl); - /* Change the type so that assemble_variable will give - DECL an rtl we can live with: (mem (const_int 0)). */ - TREE_TYPE (decl) = error_mark_node; - type = error_mark_node; - } - else - { - /* If any base type in the hierarchy of TYPE needs a constructor, - then we set initialized to 1. This way any nodes which are - created for the purposes of initializing this aggregate - will live as long as it does. This is necessary for global - aggregates which do not have their initializers processed until - the end of the file. */ - initialized = TYPE_NEEDS_CONSTRUCTING (type); - } - } - if (initialized) { if (! toplevel_bindings_p () @@ -5971,7 +6461,7 @@ start_decl (declarator, declspecs, initialized, raises) cp_warning ("declaration of `%#D' has `extern' and is initialized", decl); DECL_EXTERNAL (decl) = 0; - if ( toplevel_bindings_p ()) + if (toplevel_bindings_p ()) TREE_STATIC (decl) = 1; /* Tell `pushdecl' this is an initialized decl @@ -5980,130 +6470,106 @@ start_decl (declarator, declspecs, initialized, raises) DECL_INITIAL (decl) = error_mark_node; } - if (context && TYPE_SIZE (context) != NULL_TREE) + if (context && TYPE_SIZE (complete_type (context)) != NULL_TREE) { if (TREE_CODE (decl) == VAR_DECL) { tree field = lookup_field (context, DECL_NAME (decl), 0, 0); if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) cp_error ("`%#D' is not a static member of `%#T'", decl, context); - else if (duplicate_decls (decl, field)) - decl = field; + else + { + if (DECL_CONTEXT (field) != context) + { + cp_pedwarn ("ANSI C++ does not permit `%T::%D' to be defined as `%T::%D'", + DECL_CONTEXT (field), DECL_NAME (decl), + context, DECL_NAME (decl)); + DECL_CONTEXT (decl) = DECL_CONTEXT (field); + } + /* Static data member are tricky; an in-class initialization + still doesn't provide a definition, so the in-class + declaration will have DECL_EXTERNAL set, but will have an + initialization. Thus, duplicate_decls won't warn + about this situation, and so we check here. */ + if (DECL_INITIAL (decl) && DECL_INITIAL (field)) + cp_error ("duplicate initialization of %D", decl); + if (duplicate_decls (decl, field)) + decl = field; + } } else { - tree field = check_classfn (context, NULL_TREE, decl); + tree field = check_classfn (context, decl); if (field && duplicate_decls (decl, field)) decl = field; } /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */ - if (DECL_LANG_SPECIFIC (decl)) - DECL_IN_AGGR_P (decl) = 0; - if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context)) + DECL_IN_AGGR_P (decl) = 0; + if ((DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl)) + || CLASSTYPE_USE_TEMPLATE (context)) SET_DECL_TEMPLATE_SPECIALIZATION (decl); - /* Stupid stupid stupid stupid (jason 7/21/95) */ - if (pedantic && DECL_EXTERNAL (decl) - && ! DECL_TEMPLATE_SPECIALIZATION (decl)) + if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)) cp_pedwarn ("declaration of `%#D' outside of class is not definition", decl); pushclass (context, 2); } + /* Set attributes here so if duplicate decl, will have proper attributes. */ + cplus_decl_attributes (decl, attributes, prefix_attributes); + /* Add this decl to the current binding level, but not if it comes from another scope, e.g. a static member variable. TEM may equal DECL or it may be a previous decl of the same name. */ - if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE) - || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ()) - || TREE_CODE (type) == LANG_TYPE) + if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE + /* Definitions of namespace members outside their namespace are + possible. */ + && TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL) + || (TREE_CODE (decl) == TEMPLATE_DECL && !namespace_bindings_p ()) + || TREE_CODE (type) == LANG_TYPE + /* The declaration of template specializations does not affect + the functions available for overload resolution, so we do not + call pushdecl. */ + || (TREE_CODE (decl) == FUNCTION_DECL + && DECL_TEMPLATE_SPECIALIZATION (decl))) tem = decl; else tem = pushdecl (decl); - - /* Tell the back-end to use or not use .common as appropriate. If we say - -fconserve-space, we want this to save space, at the expense of wrong - semantics. If we say -fno-conserve-space, we want this to produce - errors about redefs; to do this we force variables into the data - segment. Common storage is okay for non-public uninitialized data; - the linker can't match it with storage from other files, and we may - save some disk space. */ - DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem); -#if 0 - /* We don't do this yet for GNU C++. */ - /* For a local variable, define the RTL now. */ - if (! toplevel_bindings_p () - /* But not if this is a duplicate decl - and we preserved the rtl from the previous one - (which may or may not happen). */ - && DECL_RTL (tem) == NULL_RTX) + if (processing_template_decl) { - if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) - expand_decl (tem); - else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE - && DECL_INITIAL (tem) != NULL_TREE) - expand_decl (tem); + if (! current_function_decl) + tem = push_template_decl (tem); + else if (minimal_parse_mode) + DECL_VINDEX (tem) + = build_min_nt (DECL_STMT, copy_to_permanent (declarator), + copy_to_permanent (declspecs), + NULL_TREE); } + + +#if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) + /* Tell the back-end to use or not use .common as appropriate. If we say + -fconserve-space, we want this to save .data space, at the expense of + wrong semantics. If we say -fno-conserve-space, we want this to + produce errors about redefs; to do this we force variables into the + data segment. */ + DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem); #endif - if (TREE_CODE (decl) == TEMPLATE_DECL) - { - tree result = DECL_TEMPLATE_RESULT (decl); - if (DECL_CONTEXT (result) != NULL_TREE) - { - tree type; - type = DECL_CONTEXT (result); + if (! processing_template_decl) + start_decl_1 (tem); - if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE) - { - cp_error ("declaration of `%D' in non-template type `%T'", - decl, type); - return NULL_TREE; - } + /* Corresponding pop_obstacks is done in `cp_finish_decl'. */ + push_obstacks_nochange (); - if (TREE_CODE (result) == FUNCTION_DECL) - return tem; - else if (TREE_CODE (result) == VAR_DECL) - { #if 0 - tree tmpl = UPT_TEMPLATE (type); - - fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__); - print_node_brief (stderr, "", DECL_NAME (tem), 0); - fprintf (stderr, " to class %s\n", - IDENTIFIER_POINTER (DECL_NAME (tmpl))); - DECL_TEMPLATE_MEMBERS (tmpl) - = perm_tree_cons (DECL_NAME (tem), tem, - DECL_TEMPLATE_MEMBERS (tmpl)); - return tem; -#else - sorry ("static data member templates"); - return NULL_TREE; -#endif - } - else - my_friendly_abort (13); - } - else if (TREE_CODE (result) == FUNCTION_DECL) - /*tem = push_overloaded_decl (tem, 0)*/; - else if (TREE_CODE (result) == VAR_DECL) - { - cp_error ("data template `%#D' must be member of a class template", - result); - return NULL_TREE; - } - else if (TREE_CODE (result) == TYPE_DECL) - { - cp_error ("invalid template `%#D'", result); - return NULL_TREE; - } - else - my_friendly_abort (14); - } - + /* We have no way of knowing whether the initializer will need to be + evaluated at run-time or not until we've parsed it, so let's just put + it in the permanent obstack. (jason) */ if (init_written && ! (TREE_CODE (tem) == PARM_DECL || (TREE_READONLY (tem) @@ -6114,7 +6580,8 @@ start_decl (declarator, declspecs, initialized, raises) use temporary storage. Do this even if we will ignore the value. */ if (toplevel_bindings_p () && debug_temp_inits) { - if (TYPE_NEEDS_CONSTRUCTING (type) + if (processing_template_decl + || TYPE_NEEDS_CONSTRUCTING (type) || TREE_CODE (type) == REFERENCE_TYPE) /* In this case, the initializer must lay down in permanent storage, since it will be saved until `finish_file' is run. */ @@ -6123,81 +6590,108 @@ start_decl (declarator, declspecs, initialized, raises) temporary_allocation (); } } - - if (flag_cadillac) - cadillac_start_decl (tem); +#endif return tem; } -#if 0 /* unused */ -static void -make_temporary_for_reference (decl, ctor_call, init, cleanupp) - tree decl, ctor_call, init; - tree *cleanupp; +void +start_decl_1 (decl) + tree decl; { tree type = TREE_TYPE (decl); - tree target_type = TREE_TYPE (type); - tree tmp, tmp_addr; + int initialized = (DECL_INITIAL (decl) != NULL_TREE); - if (ctor_call) - { - tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1)); - if (TREE_CODE (tmp_addr) == NOP_EXPR) - tmp_addr = TREE_OPERAND (tmp_addr, 0); - my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146); - tmp = TREE_OPERAND (tmp_addr, 0); - } - else + /* If this type of object needs a cleanup, and control may + jump past it, make a new binding level so that it is cleaned + up only when it is initialized first. */ + if (TYPE_NEEDS_DESTRUCTOR (type) + && current_binding_level->more_cleanups_ok == 0) + pushlevel_temporary (1); + + if (initialized) + /* Is it valid for this decl to have an initializer at all? + If not, set INITIALIZED to zero, which will indirectly + tell `cp_finish_decl' to ignore the initializer once it is parsed. */ { - tmp = get_temp_name (target_type, toplevel_bindings_p ()); - tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0); + /* Don't allow initializations for incomplete types except for + arrays which might be completed by the initialization. */ + if (type == error_mark_node) + ; /* Don't complain again. */ + else if (TYPE_SIZE (complete_type (type)) != NULL_TREE) + ; /* A complete type is ok. */ + else if (TREE_CODE (type) != ARRAY_TYPE) + { + cp_error ("variable `%#D' has initializer but incomplete type", + decl); + initialized = 0; + type = TREE_TYPE (decl) = error_mark_node; + } + else if (TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) + { + if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)) + cp_error ("elements of array `%#D' have incomplete type", decl); + /* else we already gave an error in start_decl. */ + initialized = 0; + } } - TREE_TYPE (tmp_addr) = build_pointer_type (target_type); - DECL_INITIAL (decl) = convert (build_pointer_type (target_type), tmp_addr); - TREE_TYPE (DECL_INITIAL (decl)) = type; - if (TYPE_NEEDS_CONSTRUCTING (target_type)) + if (!initialized + && TREE_CODE (decl) != TYPE_DECL + && TREE_CODE (decl) != TEMPLATE_DECL + && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) { - if (toplevel_bindings_p ()) + if ((! processing_template_decl || ! uses_template_parms (type)) + && TYPE_SIZE (complete_type (type)) == NULL_TREE) { - /* lay this variable out now. Otherwise `output_addressed_constants' - gets confused by its initializer. */ - make_decl_rtl (tmp, NULL_PTR, 1); - static_aggregates = perm_tree_cons (init, tmp, static_aggregates); + cp_error ("aggregate `%#D' has incomplete type and cannot be initialized", + decl); + /* Change the type so that assemble_variable will give + DECL an rtl we can live with: (mem (const_int 0)). */ + type = TREE_TYPE (decl) = error_mark_node; } else { - if (ctor_call != NULL_TREE) - init = ctor_call; - else - init = build_method_call (tmp, constructor_name_full (target_type), - build_tree_list (NULL_TREE, init), - NULL_TREE, LOOKUP_NORMAL); - DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init, - DECL_INITIAL (decl)); - *cleanupp = maybe_build_cleanup (tmp); + /* If any base type in the hierarchy of TYPE needs a constructor, + then we set initialized to 1. This way any nodes which are + created for the purposes of initializing this aggregate + will live as long as it does. This is necessary for global + aggregates which do not have their initializers processed until + the end of the file. */ + initialized = TYPE_NEEDS_CONSTRUCTING (type); } } - else + +#if 0 + /* We don't do this yet for GNU C++. */ + /* For a local variable, define the RTL now. */ + if (! toplevel_bindings_p () + /* But not if this is a duplicate decl + and we preserved the rtl from the previous one + (which may or may not happen). */ + && DECL_RTL (tem) == NULL_RTX) { - DECL_INITIAL (tmp) = init; - TREE_STATIC (tmp) = toplevel_bindings_p (); - cp_finish_decl (tmp, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING); + if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) + expand_decl (tem); + else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE + && DECL_INITIAL (tem) != NULL_TREE) + expand_decl (tem); } - if (TREE_STATIC (tmp)) - preserve_initializer (); -} #endif + if (! initialized) + DECL_INITIAL (decl) = NULL_TREE; +} + /* Handle initialization of references. - These three arguments from from `cp_finish_decl', and have the - same meaning here that they do there. */ -/* quotes on semantics can be found in ARM 8.4.3. */ + These three arguments are from `cp_finish_decl', and have the + same meaning here that they do there. + + Quotes on semantics can be found in ARM 8.4.3. */ + static void -grok_reference_init (decl, type, init, cleanupp) +grok_reference_init (decl, type, init) tree decl, type, init; - tree *cleanupp; { tree tmp; @@ -6224,6 +6718,10 @@ grok_reference_init (decl, type, init, cleanupp) return; } + if (TREE_TYPE (init) && TREE_CODE (TREE_TYPE (init)) == UNKNOWN_TYPE) + /* decay_conversion is probably wrong for references to functions. */ + init = decay_conversion (instantiate_type (TREE_TYPE (type), init, 1)); + if (TREE_CODE (init) == TREE_LIST) init = build_compound_expr (init); @@ -6238,39 +6736,14 @@ grok_reference_init (decl, type, init, cleanupp) } tmp = convert_to_reference - (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL, decl); + (type, init, CONV_IMPLICIT, + LOOKUP_SPECULATIVELY|LOOKUP_NORMAL|DIRECT_BIND, decl); if (tmp == error_mark_node) goto fail; else if (tmp != NULL_TREE) { - tree subtype = TREE_TYPE (type); init = tmp; - - /* Associate the cleanup with the reference so that we - don't get burned by "aggressive" cleanup policy. */ - if (TYPE_NEEDS_DESTRUCTOR (subtype)) - { - if (TREE_CODE (init) == WITH_CLEANUP_EXPR) - { - *cleanupp = TREE_OPERAND (init, 2); - TREE_OPERAND (init, 2) = error_mark_node; - } - else - { - if (TREE_CODE (tmp) == ADDR_EXPR) - tmp = TREE_OPERAND (tmp, 0); - if (TREE_CODE (tmp) == TARGET_EXPR) - { - *cleanupp = build_delete - (build_pointer_type (subtype), - build_unary_op (ADDR_EXPR, TREE_OPERAND (tmp, 0), 0), - integer_two_node, LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0); - TREE_OPERAND (tmp, 2) = error_mark_node; - } - } - } - DECL_INITIAL (decl) = save_expr (init); } else @@ -6318,10 +6791,12 @@ obscure_complex_init (decl, init) return NULL_TREE; } +#if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) if (toplevel_bindings_p () && ! DECL_COMMON (decl)) DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE, NULL_TREE); else +#endif DECL_INITIAL (decl) = error_mark_node; return init; @@ -6357,11 +6832,12 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) int flags; { register tree type; - tree cleanup = NULL_TREE, ttype; + tree cleanup = NULL_TREE, ttype = NULL_TREE; int was_incomplete; int temporary = allocation_temporary_p (); char *asmspec = NULL; int was_readonly = 0; + int already_used = 0; /* If this is 0, then we did not change obstacks. */ if (! decl) @@ -6375,6 +6851,23 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) if (asmspec_tree) asmspec = TREE_STRING_POINTER (asmspec_tree); + if (init && TREE_CODE (init) == NAMESPACE_DECL) + { + cp_error ("Cannot initialize `%D' to namespace `%D'", + decl, init); + init = NULL_TREE; + } + + if (TREE_CODE (decl) == VAR_DECL + && DECL_CONTEXT (decl) + && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL + && DECL_CONTEXT (decl) != current_namespace + && init) + { + /* Leave the namespace of the object. */ + pop_decl_namespace (); + } + /* If the type of the thing we are declaring either has a constructor, or has a virtual function table pointer, AND its initialization was accepted by `start_decl', @@ -6391,8 +6884,27 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) return; } - was_incomplete = (DECL_SIZE (decl) == NULL_TREE); + if (processing_template_decl) + { + if (init && DECL_INITIAL (decl)) + DECL_INITIAL (decl) = init; + if (minimal_parse_mode && ! DECL_ARTIFICIAL (decl)) + { + tree stmt = DECL_VINDEX (decl); + /* If the decl is declaring a member of a local class (in a + template function), the DECL_VINDEX will either be NULL, + or it will be an actual virtual function index, not a + DECL_STMT. */ + if (stmt != NULL_TREE && TREE_CODE (stmt) == DECL_STMT) + { + DECL_VINDEX (decl) = NULL_TREE; + TREE_OPERAND (stmt, 2) = copy_to_permanent (init); + add_tree (stmt); + } + } + goto finish_end0; + } /* Take care of TYPE_DECLs up front. */ if (TREE_CODE (decl) == TYPE_DECL) { @@ -6411,35 +6923,21 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) CLASSTYPE_GOT_SEMICOLON (type) = 1; } GNU_xref_decl (current_function_decl, decl); + + /* If we have installed this as the canonical typedef for this + type, and that type has not been defined yet, delay emitting + the debug information for it, as we will emit it later. */ + if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl + && TYPE_SIZE (TREE_TYPE (decl)) == NULL_TREE) + TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; + rest_of_decl_compilation (decl, NULL_PTR, - DECL_CONTEXT (decl) == NULL_TREE, 0); + DECL_CONTEXT (decl) == NULL_TREE, at_eof); goto finish_end; } if (TREE_CODE (decl) != FUNCTION_DECL) { ttype = target_type (type); -#if 0 /* WTF? -KR - Leave this out until we can figure out why it was - needed/desirable in the first place. Then put a comment - here explaining why. Or just delete the code if no ill - effects arise. */ - if (TYPE_NAME (ttype) - && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL - && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype))) - { - tree old_id = TYPE_IDENTIFIER (ttype); - char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2); - /* Need to preserve template data for UPT nodes. */ - tree old_template = IDENTIFIER_TEMPLATE (old_id); - newname[0] = '_'; - bcopy (IDENTIFIER_POINTER (old_id), newname + 1, - IDENTIFIER_LENGTH (old_id) + 1); - old_id = get_identifier (newname); - lookup_tag_reverse (ttype, old_id); - TYPE_IDENTIFIER (ttype) = old_id; - IDENTIFIER_TEMPLATE (old_id) = old_template; - } -#endif } if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) @@ -6480,7 +6978,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) make_decl_rtl (decl, NULL_PTR, toplevel_bindings_p () || pseudo_global_level_p ()); - grok_reference_init (decl, type, init, &cleanup); + grok_reference_init (decl, type, init); init = NULL_TREE; } @@ -6620,7 +7118,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) if (TREE_CODE (decl) == VAR_DECL) { if (DECL_SIZE (decl) == NULL_TREE - && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE) + && TYPE_SIZE (complete_type (TREE_TYPE (decl))) != NULL_TREE) layout_decl (decl, 0); if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE) @@ -6645,8 +7143,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) /* Let debugger know it should output info for this type. */ note_debug_info_needed (ttype); - if (TREE_STATIC (decl) && DECL_CONTEXT (decl) - && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't') + if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl)) note_debug_info_needed (DECL_CONTEXT (decl)); if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) @@ -6659,21 +7156,12 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) cp_error ("storage size of `%D' isn't constant", decl); } - if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type)) + if (! DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type) + /* Cleanups for static variables are handled by `finish_file'. */ + && ! TREE_STATIC (decl)) { int yes = suspend_momentary (); - - /* If INIT comes from a functional cast, use the cleanup - we built for that. Otherwise, make our own cleanup. */ - if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR - && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1)) - { - cleanup = TREE_OPERAND (init, 2); - init = TREE_OPERAND (init, 0); - current_binding_level->have_cleanups = 1; - } - else - cleanup = maybe_build_cleanup (decl); + cleanup = maybe_build_cleanup (decl); resume_momentary (yes); } } @@ -6691,24 +7179,96 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) unless the type is an undefined structure or union. If not, it will get done when the type is completed. */ + was_incomplete = (DECL_SIZE (decl) == NULL_TREE); + if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == RESULT_DECL) { /* ??? FIXME: What about nested classes? */ int toplev = toplevel_bindings_p () || pseudo_global_level_p (); int was_temp - = ((flag_traditional - || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type))) + = (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type) && allocation_temporary_p ()); if (was_temp) end_temporary_allocation (); + /* Static data in a function with comdat linkage also has comdat + linkage. */ if (TREE_CODE (decl) == VAR_DECL - && ! toplevel_bindings_p () - && ! TREE_STATIC (decl) - && type_needs_gc_entry (type)) - DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index); + && TREE_STATIC (decl) + /* Don't mess with __FUNCTION__. */ + && ! TREE_ASM_WRITTEN (decl) + && current_function_decl + && DECL_CONTEXT (decl) == current_function_decl + && (DECL_THIS_INLINE (current_function_decl) + || DECL_TEMPLATE_INSTANTIATION (current_function_decl)) + && TREE_PUBLIC (current_function_decl)) + { + /* Rather than try to get this right with inlining, we suppress + inlining of such functions. */ + current_function_cannot_inline + = "function with static variable cannot be inline"; + + /* If flag_weak, we don't need to mess with this, as we can just + make the function weak, and let it refer to its unique local + copy. This works because we don't allow the function to be + inlined. */ + if (! flag_weak) + { + if (DECL_INTERFACE_KNOWN (current_function_decl)) + { + TREE_PUBLIC (decl) = 1; + DECL_EXTERNAL (decl) = DECL_EXTERNAL (current_function_decl); + } + else if (DECL_INITIAL (decl) == NULL_TREE + || DECL_INITIAL (decl) == error_mark_node) + { + TREE_PUBLIC (decl) = 1; + DECL_COMMON (decl) = 1; + } + /* else we lose. We can only do this if we can use common, + which we can't if it has been initialized. */ + + if (TREE_PUBLIC (decl)) + DECL_ASSEMBLER_NAME (decl) + = build_static_name (current_function_decl, DECL_NAME (decl)); + else if (! DECL_ARTIFICIAL (decl)) + { + cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl); + cp_warning_at (" you can work around this by removing the initializer"), decl; + } + } + } + + else if (TREE_CODE (decl) == VAR_DECL + && DECL_LANG_SPECIFIC (decl) + && DECL_COMDAT (decl)) + { + /* Dynamically initialized vars go into common. */ + if (DECL_INITIAL (decl) == NULL_TREE + || DECL_INITIAL (decl) == error_mark_node) + DECL_COMMON (decl) = 1; + else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))) + { + DECL_COMMON (decl) = 1; + DECL_INITIAL (decl) = error_mark_node; + } + else + { + /* Statically initialized vars are weak or comdat, if + supported. */ + if (flag_weak) + make_decl_one_only (decl); + else + { + /* We can't do anything useful; leave vars for explicit + instantiation. */ + DECL_EXTERNAL (decl) = 1; + DECL_NOT_REALLY_EXTERN (decl) = 0; + } + } + } if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) make_decl_rtl (decl, NULL_PTR, toplev); @@ -6751,7 +7311,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) make_decl_rtl (decl, asmspec, toplev); } else - rest_of_decl_compilation (decl, asmspec, toplev, 0); + rest_of_decl_compilation (decl, asmspec, toplev, at_eof); } else if (TREE_CODE (decl) == VAR_DECL && DECL_LANG_SPECIFIC (decl) @@ -6772,14 +7332,14 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) make_decl_rtl (decl, asmspec, 1); } else - rest_of_decl_compilation (decl, asmspec, toplev, 0); + rest_of_decl_compilation (decl, asmspec, toplev, at_eof); } else /* Just a constant field. Should not need any rtl. */ goto finish_end0; } else - rest_of_decl_compilation (decl, asmspec, toplev, 0); + rest_of_decl_compilation (decl, asmspec, toplev, at_eof); if (was_temp) resume_temporary_allocation (); @@ -6804,22 +7364,22 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) if (TREE_CODE (decl) == FUNCTION_DECL) ; - else if (DECL_EXTERNAL (decl)) - ; + else if (DECL_EXTERNAL (decl) + && ! (DECL_LANG_SPECIFIC (decl) + && DECL_NOT_REALLY_EXTERN (decl))) + { + if (init) + DECL_INITIAL (decl) = init; + } else if (TREE_STATIC (decl) && type != error_mark_node) { /* Cleanups for static variables are handled by `finish_file'. */ if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE || TYPE_NEEDS_DESTRUCTOR (type)) expand_static_init (decl, init); - - /* Make entry in appropriate vector. */ - if (flag_gc && type_needs_gc_entry (type)) - build_static_gc_entry (decl, type); } else if (! toplev) { - tree old_cleanups = cleanups_this_call; /* This is a declared decl which must live until the end of the binding contour. It may need a cleanup. */ @@ -6846,7 +7406,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) { /* XXX: Why don't we use decl here? */ /* Ans: Because it was already expanded? */ - if (! cp_expand_decl_cleanup (NULL_TREE, cleanup)) + if (! expand_decl_cleanup (NULL_TREE, cleanup)) cp_error ("parser lost in parsing declaration of `%D'", decl); /* Cleanup used up here. */ @@ -6854,10 +7414,59 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) } } + if (current_binding_level->is_for_scope) + { + struct binding_level *outer = current_binding_level->level_chain; + + /* Check to see if the same name is already bound at + the outer level, either because it was directly declared, + or because a dead for-decl got preserved. In either case, + the code would not have been valid under the ARM + scope rules, so clear is_for_scope for the + current_binding_level. + + Otherwise, we need to preserve the temp slot for decl + to last into the outer binding level. */ + + int handling_dead_for_vars = 0; + tree link = outer->names; + for (; ; link = TREE_CHAIN (link)) + { + if (link == NULL && handling_dead_for_vars == 0) + { + link = outer->dead_vars_from_for; + handling_dead_for_vars = 1; + } + if (link == NULL) + { + if (DECL_IN_MEMORY_P (decl)) + preserve_temp_slots (DECL_RTL (decl)); + break; + } + if (DECL_NAME (link) == DECL_NAME (decl)) + { + if (handling_dead_for_vars) + { + tree shadowing + = purpose_member (DECL_NAME (decl), + current_binding_level->shadowed); + if (shadowing && TREE_VALUE (shadowing) == link) + TREE_VALUE (shadowing) + = DECL_SHADOWED_FOR_VAR (link); + } + current_binding_level->is_for_scope = 0; + break; + } + } + } + + expand_start_target_temps (); + if (DECL_SIZE (decl) && type != error_mark_node) { /* Compute and store the initial value. */ expand_decl_init (decl); + already_used = TREE_USED (decl) || TREE_USED (type); if (init || TYPE_NEEDS_CONSTRUCTING (type)) { @@ -6870,19 +7479,34 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) was initialized was ever used. Don't do this if it has a destructor, so we don't complain about the 'resource allocation is initialization' idiom. */ - if (TYPE_NEEDS_CONSTRUCTING (type) && cleanup == NULL_TREE) + /* Now set attribute((unused)) on types so decls of + that type will be marked used. (see TREE_USED, above.) + This avoids the warning problems this particular code + tried to work around. */ + + if (TYPE_NEEDS_CONSTRUCTING (type) + && ! already_used + && cleanup == NULL_TREE + && DECL_NAME (decl)) TREE_USED (decl) = 0; + if (already_used) + TREE_USED (decl) = 1; + } + + /* Cleanup any temporaries needed for the initial value. */ + expand_end_target_temps (); + + if (DECL_SIZE (decl) && type != error_mark_node) + { /* Store the cleanup, if there was one. */ if (cleanup) { - if (! cp_expand_decl_cleanup (decl, cleanup)) + if (! expand_decl_cleanup (decl, cleanup)) cp_error ("parser lost in parsing declaration of `%D'", decl); } } - /* Cleanup any temporaries needed for the initial value. */ - expand_cleanups_to (old_cleanups); } finish_end0: @@ -6896,18 +7520,12 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) && (TREE_CODE (decl) == VAR_DECL /* We also have a pushclass done that we need to undo here if we're at top level and declare a method. */ - || (TREE_CODE (decl) == FUNCTION_DECL - /* If size hasn't been set, we're still defining it, - and therefore inside the class body; don't pop - the binding level.. */ - && TYPE_SIZE (context) != NULL_TREE - /* The binding level gets popped elsewhere for a - friend declaration inside another class. */ - /* - && TYPE_IDENTIFIER (context) == current_class_name - */ - && context == current_class_type - ))) + || TREE_CODE (decl) == FUNCTION_DECL) + /* If size hasn't been set, we're still defining it, + and therefore inside the class body; don't pop + the binding level.. */ + && TYPE_SIZE (context) != NULL_TREE + && context == current_class_type) popclass (1); } } @@ -6917,6 +7535,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) /* If requested, warn about definitions of large data objects. */ if (warn_larger_than + && ! processing_template_decl && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) && !DECL_EXTERNAL (decl)) { @@ -6941,12 +7560,10 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) if (was_readonly) TREE_READONLY (decl) = 1; - - if (flag_cadillac) - cadillac_finish_decl (decl); } /* This is here for a midend callback from c-common.c */ + void finish_decl (decl, init, asmspec_tree) tree decl, init; @@ -6961,7 +7578,6 @@ expand_static_init (decl, init) tree init; { tree oldstatic = value_member (decl, static_aggregates); - tree old_cleanups; if (oldstatic) { @@ -6973,7 +7589,7 @@ expand_static_init (decl, init) /* Emit code to perform this initialization but once. */ tree temp; - /* Remember this information until end of file. */ + /* Remember this information until end of file. */ push_obstacks (&permanent_obstack, &permanent_obstack); /* Emit code to perform this initialization but once. */ @@ -6981,7 +7597,8 @@ expand_static_init (decl, init) rest_of_decl_compilation (temp, NULL_PTR, 0, 0); expand_start_cond (build_binary_op (EQ_EXPR, temp, integer_zero_node, 1), 0); - old_cleanups = cleanups_this_call; + expand_start_target_temps (); + expand_assignment (temp, integer_one_node, 0, 0); if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)) || (init && TREE_CODE (init) == TREE_LIST)) @@ -6993,7 +7610,43 @@ expand_static_init (decl, init) expand_assignment (decl, init, 0, 0); /* Cleanup any temporaries needed for the initial value. */ - expand_cleanups_to (old_cleanups); + expand_end_target_temps (); + + if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) + { + tree cleanup, fcall; + static tree Atexit = 0; + if (Atexit == 0) + { + tree atexit_fndecl, PFV, pfvlist; + /* Remember this information until end of file. */ + push_obstacks (&permanent_obstack, &permanent_obstack); + PFV = build_pointer_type (build_function_type + (void_type_node, void_list_node)); + + pfvlist = tree_cons (NULL_TREE, PFV, void_list_node); + + push_lang_context (lang_name_c); + atexit_fndecl + = builtin_function ("atexit", + build_function_type (void_type_node, + pfvlist), + NOT_BUILT_IN, NULL_PTR); + assemble_external (atexit_fndecl); + Atexit = default_conversion (atexit_fndecl); + pop_lang_context (); + pop_obstacks (); + } + + cleanup = start_anon_func (); + expand_expr_stmt (build_cleanup (decl)); + end_anon_func (); + mark_addressable (cleanup); + cleanup = build_unary_op (ADDR_EXPR, cleanup, 0); + fcall = build_function_call (Atexit, expr_tree_cons (NULL_TREE, cleanup, NULL_TREE)); + expand_expr_stmt (fcall); + } + expand_end_cond (); if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) { @@ -7001,7 +7654,7 @@ expand_static_init (decl, init) TREE_STATIC (static_aggregates) = 1; } - /* Resume old (possibly temporary) allocation. */ + /* Resume old (possibly temporary) allocation. */ pop_obstacks (); } else @@ -7100,6 +7753,7 @@ complete_array_type (type, initial_value, do_default) /* Return zero if something is declared to be a member of type CTYPE when in the context of CUR_TYPE. STRING is the error message to print in that case. Otherwise, quietly return 1. */ + static int member_function_or_else (ctype, cur_type, string) tree ctype, cur_type; @@ -7117,6 +7771,7 @@ member_function_or_else (ctype, cur_type, string) /* Generate errors possibly applicable for a given set of specifiers. This is for ARM $7.1.2. */ + static void bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) tree object; @@ -7147,18 +7802,23 @@ bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) RAISES is a list of exceptions that this function can raise. CHECK is 1 if we must find this method in CTYPE, 0 if we should not look, and -1 if we should not call `grokclassfn' at all. */ + static tree -grokfndecl (ctype, type, declarator, virtualp, flags, quals, - raises, attrlist, check, publicp, inlinep) +grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, + raises, attrlist, check, friendp, publicp, inlinep, funcdef_flag, + template_count, in_namespace) tree ctype, type; tree declarator; + tree orig_declarator; int virtualp; enum overload_flags flags; tree quals, raises, attrlist; - int check, publicp, inlinep; + int check, friendp, publicp, inlinep, funcdef_flag, template_count; + tree in_namespace; { tree cname, decl; int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; + tree t; if (ctype) cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL @@ -7169,26 +7829,28 @@ grokfndecl (ctype, type, declarator, virtualp, flags, quals, if (raises) { type = build_exception_variant (type, raises); - raises = TYPE_RAISES_EXCEPTIONS (type); } + decl = build_lang_decl (FUNCTION_DECL, declarator, type); - /* propagate volatile out from type to decl */ + /* Propagate volatile out from type to decl. */ if (TYPE_VOLATILE (type)) - TREE_THIS_VOLATILE (decl) = 1; + TREE_THIS_VOLATILE (decl) = 1; + + /* This decl is not from the current namespace. */ + if (in_namespace) + set_decl_namespace (decl, in_namespace); /* Should probably propagate const out from type to decl I bet (mrs). */ if (staticp) { DECL_STATIC_FUNCTION_P (decl) = 1; DECL_CONTEXT (decl) = ctype; - DECL_CLASS_CONTEXT (decl) = ctype; } - /* All function decls start out public; we'll fix their linkage later (at - definition or EOF) if appropriate. */ - TREE_PUBLIC (decl) = 1; + if (ctype) + DECL_CLASS_CONTEXT (decl) = ctype; - if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main")) + if (ctype == NULL_TREE && MAIN_NAME_P (declarator)) { if (inlinep) error ("cannot declare `main' to be inline"); @@ -7198,8 +7860,12 @@ grokfndecl (ctype, type, declarator, virtualp, flags, quals, publicp = 1; } + TREE_PUBLIC (decl) = publicp; if (! publicp) - DECL_C_STATIC (decl) = 1; + { + DECL_INTERFACE_KNOWN (decl) = 1; + DECL_NOT_REALLY_EXTERN (decl) = 1; + } if (inlinep) DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1; @@ -7215,10 +7881,43 @@ grokfndecl (ctype, type, declarator, virtualp, flags, quals, if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) grok_op_properties (decl, virtualp, check < 0); + if (ctype && hack_decl_function_context (decl)) + DECL_NO_STATIC_CHAIN (decl) = 1; + + for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t)) + if (TREE_PURPOSE (t) + && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) + { + add_defarg_fn (decl); + break; + } + + if (friendp + && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR) + { + if (funcdef_flag) + cp_error + ("defining explicit specialization `%D' in friend declaration", + orig_declarator); + else + { + /* A friend declaration of the form friend void f<>(). Record + the information in the TEMPLATE_ID_EXPR. */ + SET_DECL_IMPLICIT_INSTANTIATION (decl); + DECL_TEMPLATE_INFO (decl) + = perm_tree_cons (TREE_OPERAND (orig_declarator, 0), + TREE_OPERAND (orig_declarator, 1), + NULL_TREE); + } + } + /* Caller will do the rest of this. */ if (check < 0) return decl; + if (check && funcdef_flag) + DECL_INITIAL (decl) = error_mark_node; + if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator) { tree tmp; @@ -7230,26 +7929,40 @@ grokfndecl (ctype, type, declarator, virtualp, flags, quals, DECL_CONSTRUCTOR_P (decl) = 1; grokclassfn (ctype, declarator, decl, flags, quals); - if (check) - check_classfn (ctype, declarator, decl); + + decl = check_explicit_specialization (orig_declarator, decl, + template_count, + 2 * (funcdef_flag != 0) + + 4 * (friendp != 0)); + + if ((! TYPE_FOR_JAVA (ctype) || check_java_method (ctype, decl)) + && check) + { + tmp = check_classfn (ctype, decl); + + if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) + tmp = DECL_TEMPLATE_RESULT(tmp); + + if (tmp && DECL_ARTIFICIAL (tmp)) + cp_error ("definition of implicitly-declared `%D'", tmp); + if (tmp && duplicate_decls (decl, tmp)) + return tmp; + } if (! grok_ctor_properties (ctype, decl)) return NULL_TREE; if (check == 0 && ! current_function_decl) { - /* FIXME: this should only need to look at - IDENTIFIER_GLOBAL_VALUE. */ - tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); + /* Assembler names live in the global namespace. */ + tmp = IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)); if (tmp == NULL_TREE) - IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; + SET_IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl), decl); else if (TREE_CODE (tmp) != TREE_CODE (decl)) cp_error ("inconsistent declarations for `%D'", decl); else { duplicate_decls (decl, tmp); decl = tmp; - /* avoid creating circularities. */ - DECL_CHAIN (decl) = NULL_TREE; } make_decl_rtl (decl, NULL_PTR, 1); } @@ -7264,8 +7977,36 @@ grokfndecl (ctype, type, declarator, virtualp, flags, quals, if (ctype != NULL_TREE) grokclassfn (ctype, cname, decl, flags, quals); - if (ctype != NULL_TREE && check) - check_classfn (ctype, cname, decl); + decl = check_explicit_specialization (orig_declarator, decl, + template_count, + 2 * (funcdef_flag != 0) + + 4 * (friendp != 0)); + if (ctype != NULL_TREE + && (! TYPE_FOR_JAVA (ctype) || check_java_method (ctype, decl)) + && check) + { + tmp = check_classfn (ctype, decl); + + if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) + tmp = DECL_TEMPLATE_RESULT (tmp); + + if (tmp && DECL_STATIC_FUNCTION_P (tmp) + && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) + { + /* Remove the `this' parm added by grokclassfn. + XXX Isn't this done in start_function, too? */ + revert_static_member_fn (&decl, NULL, NULL); + last_function_parms = TREE_CHAIN (last_function_parms); + } + if (tmp && DECL_ARTIFICIAL (tmp)) + cp_error ("definition of implicitly-declared `%D'", tmp); + if (tmp) + { + if (!duplicate_decls (decl, tmp)) + my_friendly_abort (892); + return tmp; + } + } if (ctype == NULL_TREE || check) return decl; @@ -7275,19 +8016,25 @@ grokfndecl (ctype, type, declarator, virtualp, flags, quals, methods, though. */ if (! current_function_decl) { - /* FIXME: this should only need to look at - IDENTIFIER_GLOBAL_VALUE. */ - tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); - if (tmp == NULL_TREE) - IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl; - else if (TREE_CODE (tmp) != TREE_CODE (decl)) - cp_error ("inconsistent declarations for `%D'", decl); - else + if (!DECL_TEMPLATE_SPECIALIZATION (decl)) { - duplicate_decls (decl, tmp); - decl = tmp; - /* avoid creating circularities. */ - DECL_CHAIN (decl) = NULL_TREE; + /* We don't do this for specializations since the + equivalent checks will be done later. Also, at this + point the DECL_ASSEMBLER_NAME is not yet fully + accurate. */ + + /* FIXME: this should only need to look at + IDENTIFIER_GLOBAL_VALUE. */ + tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0); + if (tmp == NULL_TREE) + SET_IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl), decl); + else if (TREE_CODE (tmp) != TREE_CODE (decl)) + cp_error ("inconsistent declarations for `%D'", decl); + else + { + duplicate_decls (decl, tmp); + decl = tmp; + } } if (attrlist) @@ -7295,95 +8042,30 @@ grokfndecl (ctype, type, declarator, virtualp, flags, quals, TREE_VALUE (attrlist)); make_decl_rtl (decl, NULL_PTR, 1); } - - /* If this declaration supersedes the declaration of - a method declared virtual in the base class, then - mark this field as being virtual as well. */ - { - tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype)); - int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0; - - for (i = 0; i < n_baselinks; i++) - { - tree base_binfo = TREE_VEC_ELT (binfos, i); - if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)) - || flag_all_virtual == 1) - { - tmp = get_matching_virtual (base_binfo, decl, - flags == DTOR_FLAG); - if (tmp) - { - /* If this function overrides some virtual in some base - class, then the function itself is also necessarily - virtual, even if the user didn't explicitly say so. */ - DECL_VIRTUAL_P (decl) = 1; - - /* The TMP we really want is the one from the deepest - baseclass on this path, taking care not to - duplicate if we have already found it (via another - path to its virtual baseclass. */ - if (staticp) - { - cp_error ("method `%D' may not be declared static", - decl); - cp_error_at ("(since `%D' declared virtual in base class.)", - tmp); - break; - } - virtualp = 1; - - { - /* The argument types may have changed... */ - tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); - tree base_variant = TREE_TYPE (TREE_VALUE (argtypes)); - - argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))), - TREE_CHAIN (argtypes)); - /* But the return type has not. */ - type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes); - if (raises) - { - type = build_exception_variant (type, raises); - raises = TYPE_RAISES_EXCEPTIONS (type); - } - TREE_TYPE (decl) = type; - DECL_VINDEX (decl) - = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl)); - } - break; - } - } - } - } if (virtualp) { + DECL_VIRTUAL_P (decl) = 1; if (DECL_VINDEX (decl) == NULL_TREE) DECL_VINDEX (decl) = error_mark_node; IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; - if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype) - /* If this function is derived from a template, don't - make it public. This shouldn't be here, but there's - no good way to override the interface pragmas for one - function or class only. Bletch. */ - && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE - && (write_virtuals == 2 - || (write_virtuals == 3 - && CLASSTYPE_INTERFACE_KNOWN (ctype)))) - TREE_PUBLIC (decl) = 1; } } return decl; } static tree -grokvardecl (type, declarator, specbits, initialized, constp) +grokvardecl (type, declarator, specbits_in, initialized, constp, in_namespace) tree type; tree declarator; - RID_BIT_TYPE specbits; + RID_BIT_TYPE *specbits_in; int initialized; int constp; + tree in_namespace; { tree decl; + RID_BIT_TYPE specbits; + + specbits = *specbits_in; if (TREE_CODE (type) == OFFSET_TYPE) { @@ -7397,9 +8079,17 @@ grokvardecl (type, declarator, specbits, initialized, constp) DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator); } else - decl = build_decl (VAR_DECL, declarator, type); + { + tree context = in_namespace ? in_namespace : current_namespace; + decl = build_decl (VAR_DECL, declarator, complete_type (type)); + if (context != global_namespace && namespace_bindings_p () + && current_lang_name != lang_name_c) + DECL_ASSEMBLER_NAME (decl) = build_static_name (context, + declarator); + } - DECL_ASSEMBLER_NAME (decl) = current_namespace_id (DECL_ASSEMBLER_NAME (decl)); + if (in_namespace) + set_decl_namespace (decl, in_namespace); if (RIDBIT_SETP (RID_EXTERN, specbits)) { @@ -7409,8 +8099,7 @@ grokvardecl (type, declarator, specbits, initialized, constp) /* In class context, static means one per class, public access, and static storage. */ - if (DECL_FIELD_CONTEXT (decl) != NULL_TREE - && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl))) + if (DECL_CLASS_SCOPE_P (decl)) { TREE_PUBLIC (decl) = 1; TREE_STATIC (decl) = 1; @@ -7433,7 +8122,7 @@ grokvardecl (type, declarator, specbits, initialized, constp) return decl; } -/* Create a canonical pointer to member function type. */ +/* Create a canonical pointer to member function type. */ tree build_ptrmemfunc_type (type) @@ -7462,9 +8151,9 @@ build_ptrmemfunc_type (type) t = make_lang_type (RECORD_TYPE); - /* Let the front-end know this is a pointer to member function. */ + /* Let the front-end know this is a pointer to member function... */ TYPE_PTRMEMFUNC_FLAG (t) = 1; - /* and not really an aggregate. */ + /* ... and not really an aggregate. */ IS_AGGR_TYPE (t) = 0; fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, @@ -7482,7 +8171,7 @@ build_ptrmemfunc_type (type) TYPE_SET_PTRMEMFUNC_TYPE (type, t); - /* Seems to be wanted. */ + /* Seems to be wanted. */ CLASSTYPE_GOT_SEMICOLON (t) = 1; return t; } @@ -7546,12 +8235,12 @@ build_ptrmemfunc_type (type) enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; tree -grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrlist) +grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) tree declspecs; tree declarator; enum decl_context decl_context; int initialized; - tree raises, attrlist; + tree attrlist; { RID_BIT_TYPE specbits; int nclasses = 0; @@ -7563,6 +8252,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli int virtualp, explicitp, friendp, inlinep, staticp; int explicit_int = 0; int explicit_char = 0; + int defaulted_int = 0; int opaque_typedef = 0; tree typedef_decl = NULL_TREE; char *name; @@ -7570,8 +8260,10 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli int funcdef_flag = 0; enum tree_code innermost_code = ERROR_MARK; int bitfield = 0; - int size_varies = 0; +#if 0 + /* See the code below that used this. */ tree decl_machine_attr = NULL_TREE; +#endif /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ tree init = NULL_TREE; @@ -7586,6 +8278,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli tree ctor_return_type = NULL_TREE; enum overload_flags flags = NO_SPECIAL; tree quals = NULL_TREE; + tree raises = NULL_TREE; + int template_count = 0; + tree in_namespace = NULL_TREE; RIDBIT_RESET_ALL (specbits); if (decl_context == FUNCDEF) @@ -7595,228 +8290,263 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli else if (decl_context == BITFIELD) bitfield = 1, decl_context = FIELD; - if (flag_traditional && allocation_temporary_p ()) - end_temporary_allocation (); - /* Look inside a declarator for the name being declared and get it as a string, for an error message. */ { - tree last = NULL_TREE; - register tree decl = declarator; + tree *next = &declarator; + register tree decl; name = NULL; - while (decl) - switch (TREE_CODE (decl)) - { - case COND_EXPR: - ctype = NULL_TREE; - decl = TREE_OPERAND (decl, 0); - break; - - case BIT_NOT_EXPR: /* for C++ destructors! */ + while (next && *next) + { + decl = *next; + switch (TREE_CODE (decl)) { - tree name = TREE_OPERAND (decl, 0); - tree rename = NULL_TREE; - - my_friendly_assert (flags == NO_SPECIAL, 152); - flags = DTOR_FLAG; - return_type = return_dtor; - my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); - if (ctype == NULL_TREE) - { - if (current_class_type == NULL_TREE) - { - error ("destructors must be member functions"); - flags = NO_SPECIAL; - } - else - { - tree t = constructor_name (current_class_name); - if (t != name) - rename = t; - } - } - else - { - tree t = constructor_name (ctype); - if (t != name) - rename = t; - } - - if (rename) - { - error ("destructor `%s' must match class name `%s'", - IDENTIFIER_POINTER (name), - IDENTIFIER_POINTER (rename)); - TREE_OPERAND (decl, 0) = rename; - } - decl = name; - } - break; - - case ADDR_EXPR: /* C++ reference declaration */ - /* fall through */ - case ARRAY_REF: - case INDIRECT_REF: - ctype = NULL_TREE; - innermost_code = TREE_CODE (decl); - last = decl; - decl = TREE_OPERAND (decl, 0); - break; + case COND_EXPR: + ctype = NULL_TREE; + next = &TREE_OPERAND (decl, 0); + break; - case CALL_EXPR: - if (parmlist_is_exprlist (TREE_OPERAND (decl, 1))) + case BIT_NOT_EXPR: /* For C++ destructors! */ { - /* This is actually a variable declaration using constructor - syntax. We need to call start_decl and cp_finish_decl so we - can get the variable initialized... */ - - if (last) - /* We need to insinuate ourselves into the declarator in place - of the CALL_EXPR. */ - TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0); + tree name = TREE_OPERAND (decl, 0); + tree rename = NULL_TREE; + + my_friendly_assert (flags == NO_SPECIAL, 152); + flags = DTOR_FLAG; + return_type = return_dtor; + if (TREE_CODE (name) == TYPE_DECL) + TREE_OPERAND (decl, 0) = name = constructor_name (name); + my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); + if (ctype == NULL_TREE) + { + if (current_class_type == NULL_TREE) + { + error ("destructors must be member functions"); + flags = NO_SPECIAL; + } + else + { + tree t = constructor_name (current_class_name); + if (t != name) + rename = t; + } + } else - declarator = TREE_OPERAND (decl, 0); - - init = TREE_OPERAND (decl, 1); - - decl = start_decl (declarator, declspecs, 1, NULL_TREE); - finish_decl (decl, init, NULL_TREE); - return 0; - } - innermost_code = TREE_CODE (decl); - if (decl_context == FIELD && ctype == NULL_TREE) - ctype = current_class_type; - if (ctype - && TREE_OPERAND (decl, 0) == constructor_name_full (ctype)) - TREE_OPERAND (decl, 0) = constructor_name (ctype); - decl = TREE_OPERAND (decl, 0); - if (ctype != NULL_TREE - && decl != NULL_TREE && flags != DTOR_FLAG - && decl == constructor_name (ctype)) - { - return_type = return_ctor; - ctor_return_type = ctype; - } - ctype = NULL_TREE; - break; - - case IDENTIFIER_NODE: - dname = decl; - decl = NULL_TREE; + { + tree t = constructor_name (ctype); + if (t != name) + rename = t; + } - if (! IDENTIFIER_OPNAME_P (dname) - /* Linux headers use '__op'. Arrgh. */ - || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname)) - name = IDENTIFIER_POINTER (dname); - else - { - if (IDENTIFIER_TYPENAME_P (dname)) + if (rename) { - my_friendly_assert (flags == NO_SPECIAL, 154); - flags = TYPENAME_FLAG; - ctor_return_type = TREE_TYPE (dname); - return_type = return_conversion; + cp_error ("destructor `%T' must match class name `%T'", + name, rename); + TREE_OPERAND (decl, 0) = rename; } - name = operator_name_string (dname); + next = &name; } - break; + break; - case RECORD_TYPE: - case UNION_TYPE: - case ENUMERAL_TYPE: - /* Parse error puts this typespec where - a declarator should go. */ - error ("declarator name missing"); - dname = TYPE_NAME (decl); - if (dname && TREE_CODE (dname) == TYPE_DECL) - dname = DECL_NAME (dname); - name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>"; - declspecs = temp_tree_cons (NULL_TREE, decl, declspecs); - decl = NULL_TREE; - break; + case ADDR_EXPR: /* C++ reference declaration */ + /* Fall through. */ + case ARRAY_REF: + case INDIRECT_REF: + ctype = NULL_TREE; + innermost_code = TREE_CODE (decl); + next = &TREE_OPERAND (decl, 0); + break; - /* C++ extension */ - case SCOPE_REF: - { - /* Perform error checking, and convert class names to types. - We may call grokdeclarator multiple times for the same - tree structure, so only do the conversion once. In this - case, we have exactly what we want for `ctype'. */ - tree cname = TREE_OPERAND (decl, 0); - if (cname == NULL_TREE) - ctype = NULL_TREE; - /* Can't use IS_AGGR_TYPE because CNAME might not be a type. */ - else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname)) - || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE) - ctype = cname; - else if (! is_aggr_typedef (cname, 1)) - { - TREE_OPERAND (decl, 0) = NULL_TREE; - } - /* Must test TREE_OPERAND (decl, 1), in case user gives - us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */ - else if (TREE_OPERAND (decl, 1) - && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) + case CALL_EXPR: + if (parmlist_is_exprlist (TREE_OPERAND (decl, 1))) { - TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname); + /* This is actually a variable declaration using constructor + syntax. We need to call start_decl and cp_finish_decl so we + can get the variable initialized... */ + + *next = TREE_OPERAND (decl, 0); + init = TREE_OPERAND (decl, 1); + + decl = start_decl (declarator, declspecs, 1, NULL_TREE, NULL_TREE); + /* Look for __unused__ attribute */ + if (TREE_USED (TREE_TYPE (decl))) + TREE_USED (decl) = 1; + finish_decl (decl, init, NULL_TREE); + return 0; } - else if (ctype == NULL_TREE) + innermost_code = TREE_CODE (decl); + if (decl_context == FIELD && ctype == NULL_TREE) + ctype = current_class_type; + if (ctype + && TREE_OPERAND (decl, 0) + && (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL + && ((DECL_NAME (TREE_OPERAND (decl, 0)) + == constructor_name_full (ctype)) + || (DECL_NAME (TREE_OPERAND (decl, 0)) + == constructor_name (ctype))))) + TREE_OPERAND (decl, 0) = constructor_name (ctype); + next = &TREE_OPERAND (decl, 0); + decl = *next; + if (ctype != NULL_TREE + && decl != NULL_TREE && flags != DTOR_FLAG + && decl == constructor_name (ctype)) { - ctype = IDENTIFIER_TYPE_VALUE (cname); - TREE_OPERAND (decl, 0) = ctype; + return_type = return_ctor; + ctor_return_type = ctype; } - else if (TREE_COMPLEXITY (decl) == current_class_depth) - TREE_OPERAND (decl, 0) = ctype; - else + ctype = NULL_TREE; + break; + + case TEMPLATE_ID_EXPR: { - if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname), - ctype)) - { - cp_error ("type `%T' is not derived from type `%T'", - IDENTIFIER_TYPE_VALUE (cname), ctype); - TREE_OPERAND (decl, 0) = NULL_TREE; - } + tree fns = TREE_OPERAND (decl, 0); + + if (TREE_CODE (fns) == LOOKUP_EXPR) + fns = TREE_OPERAND (fns, 0); + + if (TREE_CODE (fns) == IDENTIFIER_NODE) + dname = fns; + else if (is_overloaded_fn (fns)) + dname = DECL_NAME (get_first_fn (fns)); else - { - ctype = IDENTIFIER_TYPE_VALUE (cname); - TREE_OPERAND (decl, 0) = ctype; - } + my_friendly_abort (0); } + /* Fall through. */ - if (ctype - && TREE_OPERAND (decl, 1) == constructor_name_full (ctype)) - TREE_OPERAND (decl, 1) = constructor_name (ctype); - decl = TREE_OPERAND (decl, 1); - if (ctype) + case IDENTIFIER_NODE: + if (TREE_CODE (decl) == IDENTIFIER_NODE) + dname = decl; + + next = 0; + + if (is_rid (dname)) { - if (TREE_CODE (decl) == IDENTIFIER_NODE - && constructor_name (ctype) == decl) - { - return_type = return_ctor; - ctor_return_type = ctype; - } - else if (TREE_CODE (decl) == BIT_NOT_EXPR - && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE - && (constructor_name (ctype) == TREE_OPERAND (decl, 0) - || constructor_name_full (ctype) == TREE_OPERAND (decl, 0))) + cp_error ("declarator-id missing; using reserved word `%D'", + dname); + name = IDENTIFIER_POINTER (dname); + } + if (! IDENTIFIER_OPNAME_P (dname) + /* GNU/Linux headers use '__op'. Arrgh. */ + || (IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))) + name = IDENTIFIER_POINTER (dname); + else + { + if (IDENTIFIER_TYPENAME_P (dname)) { - return_type = return_dtor; - ctor_return_type = ctype; - flags = DTOR_FLAG; - decl = TREE_OPERAND (decl, 0) = constructor_name (ctype); + my_friendly_assert (flags == NO_SPECIAL, 154); + flags = TYPENAME_FLAG; + ctor_return_type = TREE_TYPE (dname); + return_type = return_conversion; } + name = operator_name_string (dname); } - } - break; + break; - case ERROR_MARK: - decl = NULL_TREE; - break; + /* C++ extension */ + case SCOPE_REF: + { + /* Perform error checking, and decide on a ctype. */ + tree cname = TREE_OPERAND (decl, 0); + if (cname == NULL_TREE) + ctype = NULL_TREE; + else if (TREE_CODE (cname) == NAMESPACE_DECL) + { + ctype = NULL_TREE; + in_namespace = TREE_OPERAND (decl, 0); + TREE_OPERAND (decl, 0) = NULL_TREE; + } + else if (! is_aggr_type (cname, 1)) + TREE_OPERAND (decl, 0) = NULL_TREE; + /* Must test TREE_OPERAND (decl, 1), in case user gives + us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */ + else if (TREE_OPERAND (decl, 1) + && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) + ctype = cname; + else if (TREE_CODE (cname) == TEMPLATE_TYPE_PARM + || TREE_CODE (cname) == TEMPLATE_TEMPLATE_PARM) + { + cp_error ("`%T::%D' is not a valid declarator", cname, + TREE_OPERAND (decl, 1)); + cp_error (" perhaps you want `typename %T::%D' to make it a type", + cname, TREE_OPERAND (decl, 1)); + return void_type_node; + } + else if (ctype == NULL_TREE) + ctype = cname; + else if (TREE_COMPLEXITY (decl) == current_class_depth) + TREE_OPERAND (decl, 0) = ctype; + else + { + if (! UNIQUELY_DERIVED_FROM_P (cname, ctype)) + { + cp_error ("type `%T' is not derived from type `%T'", + cname, ctype); + TREE_OPERAND (decl, 0) = NULL_TREE; + } + else + ctype = cname; + } - default: - return 0; /* We used to do a 155 abort here. */ - } + if (ctype && TREE_CODE (TREE_OPERAND (decl, 1)) == TYPE_DECL + && ((DECL_NAME (TREE_OPERAND (decl, 1)) + == constructor_name_full (ctype)) + || (DECL_NAME (TREE_OPERAND (decl, 1)) + == constructor_name (ctype)))) + TREE_OPERAND (decl, 1) = constructor_name (ctype); + next = &TREE_OPERAND (decl, 1); + decl = *next; + if (ctype) + { + if (TREE_CODE (decl) == IDENTIFIER_NODE + && constructor_name (ctype) == decl) + { + return_type = return_ctor; + ctor_return_type = ctype; + } + else if (TREE_CODE (decl) == BIT_NOT_EXPR + && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE + && (constructor_name (ctype) == TREE_OPERAND (decl, 0) + || constructor_name_full (ctype) == TREE_OPERAND (decl, 0))) + { + return_type = return_dtor; + ctor_return_type = ctype; + flags = DTOR_FLAG; + TREE_OPERAND (decl, 0) = constructor_name (ctype); + next = &TREE_OPERAND (decl, 0); + } + } + } + break; + + case ERROR_MARK: + next = 0; + break; + + case TYPE_DECL: + /* Parse error puts this typespec where + a declarator should go. */ + cp_error ("`%T' specified as declarator-id", DECL_NAME (decl)); + if (TREE_TYPE (decl) == current_class_type) + cp_error (" perhaps you want `%T' for a constructor", + current_class_name); + dname = DECL_NAME (decl); + name = IDENTIFIER_POINTER (dname); + + /* Avoid giving two errors for this. */ + IDENTIFIER_CLASS_VALUE (dname) = NULL_TREE; + + declspecs = temp_tree_cons (NULL_TREE, integer_type_node, + declspecs); + *next = dname; + next = 0; + break; + + default: + cp_compiler_error ("`%D' as declarator", decl); + return 0; /* We used to do a 155 abort here. */ + } + } if (name == NULL) name = "type name"; } @@ -7849,7 +8579,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli We also want to avoid calling this a PARM if it is in a namespace. */ - if (decl_context == NORMAL && ! namespace_bindings_p ()) + if (decl_context == NORMAL && ! namespace_bindings_p () + && ! pseudo_global_level_p ()) { struct binding_level *b = current_binding_level; current_binding_level = b->level_chain; @@ -7911,7 +8642,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } goto found; } - /* C++ aggregate types. */ + /* C++ aggregate types. */ if (IDENTIFIER_HAS_TYPE_VALUE (id)) { if (type) @@ -7927,9 +8658,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli { if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits)) { - if (pedantic && ! in_system_header) + if (pedantic && ! in_system_header && warn_long_long) pedwarn ("ANSI C++ does not support `long long'"); - else if (longlong) + if (longlong) error ("`long long long' is too long for GCC"); else longlong = 1; @@ -7941,6 +8672,19 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } } } + /* C++ aggregate types. */ + else if (TREE_CODE (id) == TYPE_DECL || TREE_CODE (id) == TEMPLATE_DECL) + { + if (type) + cp_error ("multiple declarations `%T' and `%T'", type, + TREE_TYPE (id)); + else + { + type = TREE_TYPE (id); + TREE_VALUE (spec) = type; + } + goto found; + } if (type) error ("two or more data types in declaration of `%s'", name); else if (TREE_CODE (id) == IDENTIFIER_NODE) @@ -7952,11 +8696,14 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli else { type = TREE_TYPE (t); +#if 0 + /* See the code below that used this. */ decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id); +#endif typedef_decl = t; } } - else if (TREE_CODE (id) != ERROR_MARK) + else if (id != error_mark_node) /* Can't change CLASS nodes into RECORD nodes here! */ type = id; @@ -7965,7 +8712,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli typedef_type = type; - /* No type at all: default to `int', and set EXPLICIT_INT + /* No type at all: default to `int', and set DEFAULTED_INT because it was not a user-defined typedef. Except when we have a `typedef' inside a signature, in which case the type defaults to `unknown type' and is @@ -7979,7 +8726,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli { /* These imply 'int'. */ type = integer_type_node; - explicit_int = 1; + defaulted_int = 1; } if (type == NULL_TREE) @@ -7993,18 +8740,13 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli type = ctor_return_type; else if (current_class_type && IS_SIGNATURE (current_class_type) - && (RIDBIT_SETP (RID_TYPEDEF, specbits) - || SIGNATURE_GROKKING_TYPEDEF (current_class_type)) + && RIDBIT_SETP (RID_TYPEDEF, specbits) && (decl_context == FIELD || decl_context == NORMAL)) { explicit_int = 0; opaque_typedef = 1; type = copy_node (opaque_type_node); } - /* access declaration */ - else if (decl_context == FIELD && declarator - && TREE_CODE (declarator) == SCOPE_REF) - type = void_type_node; else { if (funcdef_flag) @@ -8016,10 +8758,15 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) pedwarn ("ANSI C++ forbids typedef which does not specify a type"); - else if (declspecs == NULL_TREE && - (innermost_code != CALL_EXPR || pedantic)) - cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class", - dname); + else if (innermost_code != CALL_EXPR || pedantic + || (warn_return_type && return_type == return_normal)) + { + if (innermost_code == CALL_EXPR) + cp_pedwarn ("return-type of `%D' defaults to `int'", dname); + else + cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type", + dname); + } type = integer_type_node; } } @@ -8044,13 +8791,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli type = ctor_return_type; } - /* Catch typedefs that only specify a type, like 'typedef int;'. */ - else if (RIDBIT_SETP (RID_TYPEDEF, specbits) && declarator == NULL_TREE) - { - /* Template "this is a type" syntax; just ignore for now. */ - if (processing_template_defn) - return void_type_node; - } ctype = NULL_TREE; @@ -8097,7 +8837,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli else { ok = 1; - if (!explicit_int && !explicit_char && pedantic) + if (!explicit_int && !defaulted_int && !explicit_char && pedantic) { pedwarn ("long, short, signed or unsigned used invalidly for `%s'", name); @@ -8117,13 +8857,18 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } } + if (RIDBIT_SETP (RID_COMPLEX, specbits) + && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) + { + error ("complex invalid for `%s'", name); + RIDBIT_RESET (RID_COMPLEX, specbits); + } + /* Decide whether an integer type is signed or not. Optionally treat bitfields as signed by default. */ if (RIDBIT_SETP (RID_UNSIGNED, specbits) - /* Traditionally, all bitfields are unsigned. */ - || (bitfield && flag_traditional) || (bitfield && ! flag_signed_bitfields - && (explicit_int || explicit_char + && (explicit_int || defaulted_int || explicit_char /* A typedef for plain `int' without `signed' can be controlled just like plain `int'. */ || ! (typedef_decl != NULL_TREE @@ -8154,21 +8899,46 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli else if (RIDBIT_SETP (RID_SHORT, specbits)) type = short_integer_type_node; + if (RIDBIT_SETP (RID_COMPLEX, specbits)) + { + /* If we just have "complex", it is equivalent to + "complex double", but if any modifiers at all are specified it is + the complex form of TYPE. E.g, "complex short" is + "complex short int". */ + + if (defaulted_int && ! longlong + && ! (RIDBIT_SETP (RID_LONG, specbits) + || RIDBIT_SETP (RID_SHORT, specbits) + || RIDBIT_SETP (RID_SIGNED, specbits) + || RIDBIT_SETP (RID_UNSIGNED, specbits))) + type = complex_double_type_node; + else if (type == integer_type_node) + type = complex_integer_type_node; + else if (type == float_type_node) + type = complex_float_type_node; + else if (type == double_type_node) + type = complex_double_type_node; + else if (type == long_double_type_node) + type = complex_long_double_type_node; + else + type = build_complex_type (type); + } + + if (return_type == return_conversion + && (RIDBIT_SETP (RID_CONST, specbits) + || RIDBIT_SETP (RID_VOLATILE, specbits))) + cp_error ("`operator %T' cannot be cv-qualified", + ctor_return_type); + /* Set CONSTP if this declaration is `const', whether by explicit specification or via a typedef. Likewise for VOLATILEP. */ constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type); volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type); + type = build_type_variant (type, 0, 0); staticp = 0; inlinep = !! RIDBIT_SETP (RID_INLINE, specbits); -#if 0 - /* This sort of redundancy is blessed in a footnote to the Sep 94 WP. */ - if (constp > 1) - warning ("duplicate `const'"); - if (volatilep > 1) - warning ("duplicate `volatile'"); -#endif virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits); RIDBIT_RESET (RID_VIRTUAL, specbits); explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0; @@ -8198,20 +8968,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli error ("non-object member `%s' cannot be declared `mutable'", name); RIDBIT_RESET (RID_MUTABLE, specbits); } -#if 0 - if (RIDBIT_SETP (RID_TYPEDEF, specbits)) - { - error ("non-object member `%s' cannot be declared `mutable'", name); - RIDBIT_RESET (RID_MUTABLE, specbits); - } - /* Because local typedefs are parsed twice, we don't want this - message here. */ - else if (decl_context != FIELD) - { - error ("non-member `%s' cannot be declared `mutable'", name); - RIDBIT_RESET (RID_MUTABLE, specbits); - } -#endif } /* Warn if two storage classes are given. Default to `auto'. */ @@ -8248,16 +9004,14 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli /* Static anonymous unions are dealt with here. */ if (staticp && decl_context == TYPENAME && TREE_CODE (declspecs) == TREE_LIST - && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE - && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs)))) + && ANON_UNION_TYPE_P (TREE_VALUE (declspecs))) decl_context = FIELD; /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual' is used in a signature member function declaration. */ if (decl_context == FIELD && IS_SIGNATURE (current_class_type) - && RIDBIT_NOTSETP(RID_TYPEDEF, specbits) - && !SIGNATURE_GROKKING_TYPEDEF (current_class_type)) + && RIDBIT_NOTSETP (RID_TYPEDEF, specbits)) { if (constp) { @@ -8301,82 +9055,10 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli && (RIDBIT_SETP (RID_REGISTER, specbits) || RIDBIT_SETP (RID_AUTO, specbits))) ; + else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) + ; else if (decl_context == FIELD - && RIDBIT_SETP (RID_TYPEDEF, specbits)) - { - /* Processing a typedef declaration nested within a class type - definition. */ - register tree scanner; - register tree previous_declspec; - tree loc_typedecl; - - if (initialized) - error ("typedef declaration includes an initializer"); - - /* To process a class-local typedef declaration, we descend down - the chain of declspecs looking for the `typedef' spec. When - we find it, we replace it with `static', and then recursively - call `grokdeclarator' with the original declarator and with - the newly adjusted declspecs. This call should return a - FIELD_DECL node with the TREE_TYPE (and other parts) set - appropriately. We can then just change the TREE_CODE on that - from FIELD_DECL to TYPE_DECL and we're done. */ - - for (previous_declspec = NULL_TREE, scanner = declspecs; - scanner; - previous_declspec = scanner, scanner = TREE_CHAIN (scanner)) - { - if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF]) - break; - } - - if (previous_declspec) - TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner); - else - declspecs = TREE_CHAIN (scanner); - - declspecs = tree_cons (NULL_TREE, ridpointers[(int) RID_STATIC], - declspecs); - - /* In the recursive call to grokdeclarator we need to know - whether we are working on a signature-local typedef. */ - if (IS_SIGNATURE (current_class_type)) - SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1; - - loc_typedecl = - grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE, NULL_TREE); - - if (previous_declspec) - TREE_CHAIN (previous_declspec) = scanner; - - if (loc_typedecl != error_mark_node) - { - register int i = sizeof (struct lang_decl_flags) / sizeof (int); - register int *pi; - - TREE_SET_CODE (loc_typedecl, TYPE_DECL); - /* This is the same field as DECL_ARGUMENTS, which is set for - function typedefs by the above grokdeclarator. */ - DECL_NESTED_TYPENAME (loc_typedecl) = 0; - - pi = (int *) permalloc (sizeof (struct lang_decl_flags)); - while (i > 0) - pi[--i] = 0; - DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi; - } - - if (IS_SIGNATURE (current_class_type)) - { - SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0; - if (loc_typedecl != error_mark_node && opaque_typedef) - SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1; - } - - return loc_typedecl; - } - else if (decl_context == FIELD - && (! IS_SIGNATURE (current_class_type) - || SIGNATURE_GROKKING_TYPEDEF (current_class_type)) + && ! IS_SIGNATURE (current_class_type) /* C++ allows static class elements */ && RIDBIT_SETP (RID_STATIC, specbits)) /* C++ also allows inlines and signed and unsigned elements, @@ -8391,7 +9073,11 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli if (declarator) { - tmp = TREE_OPERAND (declarator, 0); + /* Avoid trying to get an operand off an identifier node. */ + if (TREE_CODE (declarator) == IDENTIFIER_NODE) + tmp = declarator; + else + tmp = TREE_OPERAND (declarator, 0); op = IDENTIFIER_OPNAME_P (tmp); } error ("storage class specified for %s `%s'", @@ -8436,28 +9122,17 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli { if (RIDBIT_SETP (RID_AUTO, specbits)) error ("top-level declaration of `%s' specifies `auto'", name); -#if 0 - if (RIDBIT_SETP (RID_REGISTER, specbits)) - error ("top-level declaration of `%s' specifies `register'", name); -#endif -#if 0 - /* I'm not sure under what circumstances we should turn - on the extern bit, and under what circumstances we should - warn if other bits are turned on. */ - if (decl_context == NORMAL - && RIDBIT_NOSETP (RID_EXTERN, specbits) - && ! root_lang_context_p ()) - { - RIDBIT_SET (RID_EXTERN, specbits); - } -#endif } + if (nclasses > 0 && friendp) + error ("storage class specifiers invalid in friend function declarations"); + /* Now figure out the structure of the declarator proper. Descend through it, creating more complex types, until we reach the declared identifier (or NULL_TREE, in an absolute declarator). */ - while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE) + while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE + && TREE_CODE (declarator) != TEMPLATE_ID_EXPR) { /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), an INDIRECT_REF (for *...), @@ -8480,7 +9155,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli array or function or pointer, and DECLARATOR has had its outermost layer removed. */ - if (TREE_CODE (type) == ERROR_MARK) + if (type == error_mark_node) { if (TREE_CODE (declarator) == SCOPE_REF) declarator = TREE_OPERAND (declarator, 1); @@ -8496,11 +9171,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli ctype = TYPE_METHOD_BASETYPE (type); if (ctype != NULL_TREE) { -#if 0 /* not yet, should get fixed properly later */ - tree dummy = make_type_decl (NULL_TREE, type); -#else tree dummy = build_decl (TYPE_DECL, NULL_TREE, type); -#endif ctype = grok_method_quals (ctype, dummy, quals); type = TREE_TYPE (dummy); quals = NULL_TREE; @@ -8519,7 +9190,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli /* Check for some types that there cannot be arrays of. */ - if (TYPE_MAIN_VARIANT (type) == void_type_node) + if (TREE_CODE (type) == VOID_TYPE) { cp_error ("declaration of `%D' as array of voids", dname); type = error_mark_node; @@ -8574,15 +9245,21 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli the function; then build_vec_delete will need this value. */ int yes = suspend_momentary (); - /* might be a cast */ + /* Might be a cast. */ if (TREE_CODE (size) == NOP_EXPR && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0))) size = TREE_OPERAND (size, 0); - /* If this is a template parameter, it'll be constant, but - we don't know what the value is yet. */ - if (TREE_CODE (size) == TEMPLATE_CONST_PARM) - goto dont_grok_size; + /* If this involves a template parameter, it'll be + constant, but we don't know what the value is yet. */ + if (processing_template_decl) + { + itype = make_node (INTEGER_TYPE); + TYPE_MIN_VALUE (itype) = size_zero_node; + TYPE_MAX_VALUE (itype) = build_min + (MINUS_EXPR, sizetype, size, integer_one_node); + goto dont_grok_size; + } if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE) @@ -8620,20 +9297,36 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli else cp_pedwarn ("ANSI C++ forbids variable-size array"); } - /* Make sure the array size remains visibly nonconstant - even if it is (eg) a const variable with known value. */ - size_varies = 1; } - dont_grok_size: - itype = - fold (build_binary_op (MINUS_EXPR, - convert (index_type, size), - convert (index_type, - integer_one_node), 1)); + itype + = fold (build_binary_op (MINUS_EXPR, + cp_convert (index_type, size), + cp_convert (index_type, + integer_one_node), 1)); if (! TREE_CONSTANT (itype)) itype = variable_size (itype); - itype = build_index_type (itype); + else if (TREE_OVERFLOW (itype)) + { + error ("overflow in array dimension"); + TREE_OVERFLOW (itype) = 0; + } + + /* If we're a parm, we need to have a permanent type so + mangling checks for re-use will work right. If both the + element and index types are permanent, the array type + will be, too. */ + if (decl_context == PARM + && allocation_temporary_p () && TREE_PERMANENT (type)) + { + push_obstacks (&permanent_obstack, &permanent_obstack); + itype = build_index_type (itype); + pop_obstacks (); + } + else + itype = build_index_type (itype); + + dont_grok_size: resume_momentary (yes); } @@ -8693,15 +9386,23 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) inner_decl = TREE_OPERAND (inner_decl, 1); + if (inner_decl && TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR) + inner_decl = dname; + /* Pick up type qualifiers which should be applied to `this'. */ quals = TREE_OPERAND (declarator, 2); + /* Pick up the exception specifications. */ + raises = TREE_TYPE (declarator); + /* Say it's a definition only for the CALL_EXPR closest to the identifier. */ - funcdecl_p = - inner_decl && (TREE_CODE (inner_decl) == IDENTIFIER_NODE - || TREE_CODE (inner_decl) == BIT_NOT_EXPR); - + funcdecl_p + = inner_decl + && (TREE_CODE (inner_decl) == IDENTIFIER_NODE + || TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR + || TREE_CODE (inner_decl) == BIT_NOT_EXPR); + if (ctype == NULL_TREE && decl_context == FIELD && funcdecl_p @@ -8726,8 +9427,9 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli error ("destructor cannot be static member function"); if (quals) { - error ("destructors cannot be declared `const' or `volatile'"); - return void_type_node; + cp_error ("destructors may not be `%s'", + IDENTIFIER_POINTER (TREE_VALUE (quals))); + quals = NULL_TREE; } if (decl_context == FIELD) { @@ -8736,7 +9438,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli return void_type_node; } } - else /* it's a constructor. */ + else /* It's a constructor. */ { if (explicitp == 1) explicitp = 2; @@ -8752,20 +9454,21 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } if (quals) { - error ("constructors cannot be declared `const' or `volatile'"); - return void_type_node; + cp_error ("constructors may not be `%s'", + IDENTIFIER_POINTER (TREE_VALUE (quals))); + quals = NULL_TREE; } { RID_BIT_TYPE tmp_bits; - bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE)); + bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof (RID_BIT_TYPE)); RIDBIT_RESET (RID_INLINE, tmp_bits); RIDBIT_RESET (RID_STATIC, tmp_bits); if (RIDBIT_ANY_SET (tmp_bits)) error ("return value type specifier for constructor ignored"); } type = build_pointer_type (ctype); - if (decl_context == FIELD && - IS_SIGNATURE (current_class_type)) + if (decl_context == FIELD + && IS_SIGNATURE (current_class_type)) { error ("constructor not allowed in signature"); return void_type_node; @@ -8801,16 +9504,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli name); } - /* Traditionally, declaring return type float means double. */ - - if (flag_traditional - && TYPE_MAIN_VARIANT (type) == float_type_node) - { - type = build_type_variant (double_type_node, - TYPE_READONLY (type), - TYPE_VOLATILE (type)); - } - /* Construct the function type and go to the next inner layer of declarator. */ @@ -8821,31 +9514,39 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0); - if (declarator) + if (declarator && flags == DTOR_FLAG) { - /* Get past destructors, etc. - We know we have one because FLAGS will be non-zero. - - Complain about improper parameter lists here. */ + /* A destructor declared in the body of a class will + be represented as a BIT_NOT_EXPR. But, we just + want the underlying IDENTIFIER. */ if (TREE_CODE (declarator) == BIT_NOT_EXPR) + declarator = TREE_OPERAND (declarator, 0); + + if (strict_prototype == 0 && arg_types == NULL_TREE) + arg_types = void_list_node; + else if (arg_types == NULL_TREE + || arg_types != void_list_node) { - declarator = TREE_OPERAND (declarator, 0); - - if (strict_prototype == 0 && arg_types == NULL_TREE) - arg_types = void_list_node; - else if (arg_types == NULL_TREE - || arg_types != void_list_node) - { - error ("destructors cannot be specified with parameters"); - arg_types = void_list_node; - } + cp_error ("destructors may not have parameters"); + arg_types = void_list_node; + last_function_parms = NULL_TREE; } } - /* ANSI seems to say that `const int foo ();' + /* ANSI says that `const int foo ();' does not make the function foo const. */ - type = build_function_type (type, - flag_traditional ? 0 : arg_types); + type = build_function_type (type, arg_types); + + { + tree t; + for (t = arg_types; t; t = TREE_CHAIN (t)) + if (TREE_PURPOSE (t) + && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) + { + add_defarg_fn (type); + break; + } + } } break; @@ -8928,7 +9629,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } else { - if (TYPE_MAIN_VARIANT (type) == void_type_node) + if (TREE_CODE (type) == VOID_TYPE) error ("invalid type: `void &'"); else type = build_reference_type (type); @@ -8990,6 +9691,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli resolve to. The code here just needs to build up appropriate member types. */ tree sname = TREE_OPERAND (declarator, 1); + tree t; + /* Destructors can have their visibilities changed as well. */ if (TREE_CODE (sname) == BIT_NOT_EXPR) sname = TREE_OPERAND (sname, 0); @@ -8997,10 +9700,29 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli if (TREE_COMPLEXITY (declarator) == 0) /* This needs to be here, in case we are called multiple times. */ ; + else if (TREE_COMPLEXITY (declarator) == -1) + /* Namespace member. */ + pop_decl_namespace (); else if (friendp && (TREE_COMPLEXITY (declarator) < 2)) - /* don't fall out into global scope. Hides real bug? --eichin */ ; + /* Don't fall out into global scope. Hides real bug? --eichin */ ; + else if (! IS_AGGR_TYPE_CODE + (TREE_CODE (TREE_OPERAND (declarator, 0)))) + ; else if (TREE_COMPLEXITY (declarator) == current_class_depth) { + /* Resolve any TYPENAME_TYPEs from the decl-specifier-seq + that refer to ctype. They couldn't be resolved earlier + because we hadn't pushed into the class yet. + Example: resolve 'B<T>::type' in + 'B<typename B<T>::type> B<T>::f () { }'. */ + if (current_template_parms + && uses_template_parms (type) + && uses_template_parms (current_class_type)) + { + tree args = current_template_args (); + type = tsubst (type, args, NULL_TREE); + } + /* This pop_nested_class corresponds to the push_nested_class used to push into class scope for parsing the argument list of a function decl, in @@ -9022,6 +9744,19 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } ctype = TREE_OPERAND (declarator, 0); + t = ctype; + while (t != NULL_TREE) + { + if (CLASSTYPE_TEMPLATE_INFO (t) && + !CLASSTYPE_TEMPLATE_SPECIALIZATION (t)) + template_count += 1; + t = TYPE_MAIN_DECL (t); + if (DECL_LANG_SPECIFIC (t)) + t = DECL_CLASS_CONTEXT (t); + else + t = NULL_TREE; + } + if (sname == NULL_TREE) goto done_scoping; @@ -9055,53 +9790,14 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli return void_type_node; } } - else if (TYPE_SIZE (ctype) != NULL_TREE - || (RIDBIT_SETP (RID_TYPEDEF, specbits))) + else if (RIDBIT_SETP (RID_TYPEDEF, specbits) + || TYPE_SIZE (complete_type (ctype)) != NULL_TREE) { - tree t; - /* have to move this code elsewhere in this function. + /* Have to move this code elsewhere in this function. this code is used for i.e., typedef int A::M; M *pm; It is? How? jason 10/2/94 */ - if (explicit_int == -1 && decl_context == FIELD - && funcdef_flag == 0) - { - /* The code in here should only be used to build - stuff that will be grokked as access decls. */ - t = lookup_field (ctype, sname, 0, 0); - if (t) - { - t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type); - DECL_INITIAL (t) = init; - return t; - } - /* No such field, try member functions. */ - t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0); - if (t) - { - if (flags == DTOR_FLAG) - t = TREE_VALUE (t); - else if (CLASSTYPE_METHOD_VEC (ctype) - && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0)) - { - /* Don't include destructor with constructors. */ - t = DECL_CHAIN (TREE_VALUE (t)); - if (t == NULL_TREE) - cp_error ("`%T' does not have any constructors", - ctype); - t = build_tree_list (NULL_TREE, t); - } - t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type); - DECL_INITIAL (t) = init; - return t; - } - - cp_error - ("field `%D' is not a member of structure `%T'", - sname, ctype); - } - if (current_class_type) { cp_error ("cannot declare member `%T::%s' within `%T'", @@ -9112,14 +9808,13 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } else if (uses_template_parms (ctype)) { - enum tree_code c; if (TREE_CODE (type) == FUNCTION_TYPE) - { - type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), - TREE_TYPE (type), - TYPE_ARG_TYPES (type)); - c = FUNCTION_DECL; - } + type + = build_cplus_method_type (build_type_variant (ctype, + constp, + volatilep), + TREE_TYPE (type), + TYPE_ARG_TYPES (type)); } else { @@ -9192,7 +9887,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } } - if (RIDBIT_SETP (RID_TYPEDEF, specbits)) + if (RIDBIT_SETP (RID_TYPEDEF, specbits) && decl_context != TYPENAME) { tree decl; @@ -9200,45 +9895,61 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli in typenames, fields or parameters. */ if (constp || volatilep) type = cp_build_type_variant (type, constp, volatilep); + if (current_lang_name == lang_name_java) + TYPE_FOR_JAVA (type) = 1; + + if (decl_context == FIELD) + { + if (declarator == current_class_name) + cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class", + declarator); + decl = build_lang_decl (TYPE_DECL, declarator, type); + if (IS_SIGNATURE (current_class_type) && opaque_typedef) + SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1; + } + else + { + /* Make sure this typedef lives as long as its type, + since it might be used as a template parameter. */ + if (type != error_mark_node) + push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); + decl = build_decl (TYPE_DECL, declarator, type); + if (type != error_mark_node) + pop_obstacks (); + } /* If the user declares "struct {...} foo" then `foo' will have an anonymous name. Fill that name in now. Nothing can refer to it, so nothing needs know about the name change. The TYPE_NAME field was filled in by build_struct_xref. */ if (type != error_mark_node + && !TYPE_READONLY (type) && !TYPE_VOLATILE (type) && TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) { - /* replace the anonymous name with the real name everywhere. */ + /* Replace the anonymous name with the real name everywhere. */ lookup_tag_reverse (type, declarator); - TYPE_IDENTIFIER (type) = declarator; + TYPE_NAME (type) = decl; if (TYPE_LANG_SPECIFIC (type)) TYPE_WAS_ANONYMOUS (type) = 1; - { - tree d = TYPE_NAME (type), c = DECL_CONTEXT (d); - - if (!c) - set_nested_typename (d, 0, declarator, type); - else if (TREE_CODE (c) == FUNCTION_DECL) - set_nested_typename (d, DECL_ASSEMBLER_NAME (c), - declarator, type); - else - set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type); + /* XXX Temporarily set the scope. + When returning, start_decl expects it as NULL_TREE, + and will then then set it using pushdecl. */ + my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 980404); + if (current_class_type) + DECL_CONTEXT (decl) = current_class_type; + else + DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); - DECL_ASSEMBLER_NAME (d) = DECL_NAME (d); - DECL_ASSEMBLER_NAME (d) - = get_identifier (build_overload_name (type, 1, 1)); - } + DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl); + DECL_ASSEMBLER_NAME (decl) + = get_identifier (build_overload_name (type, 1, 1)); + DECL_CONTEXT (decl) = NULL_TREE; } -#if 0 /* not yet, should get fixed properly later */ - decl = make_type_decl (declarator, type); -#else - decl = build_decl (TYPE_DECL, declarator, type); -#endif if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE) { cp_error_at ("typedef name may not be class-qualified", decl); @@ -9266,6 +9977,12 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli error ("non-object member `%s' cannot be declared mutable", name); } + bad_specifiers (decl, "type", virtualp, quals != NULL_TREE, + inlinep, friendp, raises != NULL_TREE); + + if (initialized) + error ("typedef declaration includes an initializer"); + return decl; } @@ -9289,10 +10006,12 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli /* Note that the grammar rejects storage classes in typenames, fields or parameters. */ if (constp || volatilep) - if (IS_SIGNATURE (type)) - error ("`const' or `volatile' specified with signature type"); - else - type = cp_build_type_variant (type, constp, volatilep); + { + if (IS_SIGNATURE (type)) + error ("`const' or `volatile' specified with signature type"); + else + type = cp_build_type_variant (type, constp, volatilep); + } /* Special case: "friend class foo" looks like a TYPENAME context. */ if (friendp) @@ -9322,11 +10041,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } else if (quals) { -#if 0 /* not yet, should get fixed properly later */ - tree dummy = make_type_decl (declarator, type); -#else tree dummy = build_decl (TYPE_DECL, declarator, type); -#endif if (ctype == NULL_TREE) { my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159); @@ -9352,19 +10067,14 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli We don't complain about parms either, but that is because a better error message can be made later. */ - if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM) + if (TREE_CODE (type) == VOID_TYPE && decl_context != PARM) { if (! declarator) error ("unnamed variable or field declared void"); else if (TREE_CODE (declarator) == IDENTIFIER_NODE) { if (IDENTIFIER_OPNAME_P (declarator)) -#if 0 /* How could this happen? */ - error ("operator `%s' declared void", - operator_name_string (declarator)); -#else my_friendly_abort (356); -#endif else error ("variable or field `%s' declared void", name); } @@ -9390,7 +10100,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli if (TREE_CODE (type) == ARRAY_TYPE) { - /* Transfer const-ness of array into that of type pointed to. */ + /* Transfer const-ness of array into that of type pointed to. */ type = build_pointer_type (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); volatilep = constp = 0; @@ -9399,13 +10109,13 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli type = build_pointer_type (type); else if (TREE_CODE (type) == OFFSET_TYPE) type = build_pointer_type (type); - else if (type == void_type_node && declarator) + else if (TREE_CODE (type) == VOID_TYPE && declarator) { error ("declaration of `%s' as void", name); return NULL_TREE; } - decl = build_decl (PARM_DECL, declarator, type); + decl = build_decl (PARM_DECL, declarator, complete_type (type)); bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE, inlinep, friendp, raises != NULL_TREE); @@ -9438,6 +10148,16 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli else if (TREE_CODE (type) == FUNCTION_TYPE) { int publicp = 0; + tree function_context; + + /* We catch the others as conflicts with the builtin + typedefs. */ + if (friendp && declarator == ridpointers[(int) RID_SIGNED]) + { + cp_error ("function `%D' cannot be declared friend", + declarator); + friendp = 0; + } if (friendp == 0) { @@ -9478,15 +10198,24 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ - publicp = (! friendp - || RIDBIT_SETP (RID_EXTERN, specbits) - || ! (funcdef_flag < 0 || inlinep)); - decl = grokfndecl (ctype, type, declarator, + function_context = (ctype != NULL_TREE) ? + hack_decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE; + publicp = (! friendp || ! staticp) + && function_context == NULL_TREE; + decl = grokfndecl (ctype, type, + TREE_CODE (declarator) != TEMPLATE_ID_EXPR + ? declarator : dname, + declarator, virtualp, flags, quals, raises, attrlist, - friendp ? -1 : 0, publicp, inlinep); + friendp ? -1 : 0, friendp, publicp, inlinep, + funcdef_flag, template_count, in_namespace); if (decl == NULL_TREE) return NULL_TREE; +#if 0 + /* This clobbers the attrs stored in `decl' from `attrlist'. */ + /* The decl and setting of decl_machine_attr is also turned off. */ decl = build_decl_attribute_variant (decl, decl_machine_attr); +#endif if (explicitp == 2) DECL_NONCONVERTING_P (decl) = 1; @@ -9497,13 +10226,15 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli members of other classes. */ /* All method decls are public, so tell grokfndecl to set TREE_PUBLIC, also. */ - decl = grokfndecl (ctype, type, declarator, + decl = grokfndecl (ctype, type, declarator, declarator, virtualp, flags, quals, raises, attrlist, - friendp ? -1 : 0, 1, 0); + friendp ? -1 : 0, friendp, 1, 0, funcdef_flag, + template_count, in_namespace); if (decl == NULL_TREE) return NULL_TREE; } - else if (TYPE_SIZE (type) == NULL_TREE && !staticp + else if (!staticp && ! processing_template_decl + && TYPE_SIZE (complete_type (type)) == NULL_TREE && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) { if (declarator) @@ -9515,7 +10246,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli instantiation made the field's type be incomplete. */ if (current_class_type && TYPE_NAME (current_class_type) - && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type))) + && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type)) && declspecs && TREE_VALUE (declspecs) && TREE_TYPE (TREE_VALUE (declspecs)) == type) cp_error (" in instantiation of template `%T'", @@ -9545,7 +10276,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli tree t = NULL_TREE; if (decl && DECL_NAME (decl)) t = do_friend (ctype, declarator, decl, - last_function_parms, flags, quals); + last_function_parms, flags, quals, + funcdef_flag); if (t && funcdef_flag) return t; @@ -9559,6 +10291,27 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli { if (initialized) { + if (!staticp) + { + /* An attempt is being made to initialize a non-static + member. But, from [class.mem]: + + 4 A member-declarator can contain a + constant-initializer only if it declares a static + member (_class.static_) of integral or enumeration + type, see _class.static.data_. + + This used to be relatively common practice, but + the rest of the compiler does not correctly + handle the initialization unless the member is + static so we make it static below. */ + cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'", + constp ? "const member" : "member", + declarator); + cp_pedwarn ("making `%D' static", declarator); + staticp = 1; + } + /* Motion 10 at San Diego: If a static const integral data member is initialized with an integral constant expression, the initializer may appear either in the @@ -9566,34 +10319,22 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli but not both. If it appears in the class, the member is a member constant. The file-scope definition is always required. */ - if (staticp) - { - if (pedantic) - { - if (! constp) - cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'", - declarator); - - else if (! INTEGRAL_TYPE_P (type)) - cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type); - } - } - - /* Note that initialization of const members is prohibited - by the draft ANSI standard, though it appears to be in - common practice. 12.6.2: The argument list is used to - initialize the named nonstatic member.... This (or an - initializer list) is the only way to initialize - nonstatic const and reference members. */ - else if (pedantic || ! constp) - cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'", - constp ? "const member" : "member", declarator); + if (! constp) + /* According to Mike Stump, we generate bad code for + this case, so we might as well always make it an + error. */ + cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'", + declarator); + + if (pedantic && ! INTEGRAL_TYPE_P (type) + && !uses_template_parms (type)) + cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", declarator, type); } - if (staticp || (constp && initialized)) + if (staticp) { /* ANSI C++ Apr '95 wp 9.2 */ - if (staticp && declarator == current_class_name) + if (declarator == current_class_name) cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class", declarator); @@ -9604,7 +10345,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli decl = build_lang_field_decl (VAR_DECL, declarator, type); TREE_STATIC (decl) = 1; /* In class context, 'static' means public access. */ - TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp; + TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = 1; } else { @@ -9622,12 +10363,17 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) { - tree original_name = declarator; + tree original_name; int publicp = 0; if (! declarator) return NULL_TREE; + if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR) + original_name = dname; + else + original_name = declarator; + if (RIDBIT_SETP (RID_AUTO, specbits)) error ("storage class `auto' invalid for function `%s'", name); else if (RIDBIT_SETP (RID_REGISTER, specbits)) @@ -9637,7 +10383,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli Storage classes other than `extern' are not allowed and `extern' makes no difference. */ if (! toplevel_bindings_p () - && ! processing_template_decl && (RIDBIT_SETP (RID_STATIC, specbits) || RIDBIT_SETP (RID_INLINE, specbits)) && pedantic) @@ -9657,36 +10402,44 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } if (current_lang_name == lang_name_cplusplus - && ! (IDENTIFIER_LENGTH (original_name) == 4 - && IDENTIFIER_POINTER (original_name)[0] == 'm' - && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0) + && ! processing_template_decl + && ! MAIN_NAME_P (original_name) && ! (IDENTIFIER_LENGTH (original_name) > 10 && IDENTIFIER_POINTER (original_name)[0] == '_' && IDENTIFIER_POINTER (original_name)[1] == '_' && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0)) /* Plain overloading: will not be grok'd by grokclassfn. */ - declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0); + if (name_mangling_version < 1 + || TREE_CODE (declarator) != TEMPLATE_ID_EXPR) + declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0); } else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2) type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type)); - /* Record presence of `static'. In C++, `inline' implies `static'. */ + /* Record presence of `static'. */ publicp = (ctype != NULL_TREE || RIDBIT_SETP (RID_EXTERN, specbits) - || (!RIDBIT_SETP (RID_STATIC, specbits) - && !RIDBIT_SETP (RID_INLINE, specbits))); + || !RIDBIT_SETP (RID_STATIC, specbits)); - decl = grokfndecl (ctype, type, original_name, + decl = grokfndecl (ctype, type, original_name, declarator, virtualp, flags, quals, raises, attrlist, - processing_template_decl ? 0 : friendp ? 2 : 1, - publicp, inlinep); + 1, friendp, + publicp, inlinep, funcdef_flag, + template_count, in_namespace); if (decl == NULL_TREE) return NULL_TREE; - if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c) - DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator); + /* Among other times, could occur from check_explicit_specialization + returning an error_mark_node. */ + if (decl == error_mark_node) + return error_mark_node; + if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c + && (! DECL_USE_TEMPLATE (decl) || + name_mangling_version < 1)) + DECL_ASSEMBLER_NAME (decl) = declarator; + if (staticp == 1) { int illegal_static = 0; @@ -9730,7 +10483,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli if (TREE_CODE (type) == ARRAY_TYPE) { - /* Transfer const-ness of array into that of type pointed to. */ + /* Transfer const-ness of array into that of type + pointed to. */ type = build_pointer_type (cp_build_type_variant (TREE_TYPE (type), constp, volatilep)); volatilep = constp = 0; @@ -9742,7 +10496,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli } /* An uninitialized decl with `extern' is a reference. */ - decl = grokvardecl (type, declarator, specbits, initialized, constp); + decl = grokvardecl (type, declarator, &specbits, + initialized, constp, in_namespace); bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, inlinep, friendp, raises != NULL_TREE); @@ -9804,6 +10559,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrli An empty exprlist is a parmlist. An exprlist which contains only identifiers at the global level is a parmlist. Otherwise, it is an exprlist. */ + int parmlist_is_exprlist (exprs) tree exprs; @@ -9830,14 +10586,18 @@ parmlist_is_exprlist (exprs) be complete. C++: also subroutine of `start_function'. */ + static void require_complete_types_for_parms (parms) tree parms; { + if (processing_template_decl) + return; + while (parms) { tree type = TREE_TYPE (parms); - if (TYPE_SIZE (type) == NULL_TREE) + if (TYPE_SIZE (complete_type (type)) == NULL_TREE) { if (DECL_NAME (parms)) error ("parameter `%s' has incomplete type", @@ -9928,14 +10688,14 @@ grokparms (first_parm, funcdef_flag) } else if (first_parm != NULL_TREE && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST - && TREE_VALUE (first_parm) != void_type_node) + && TREE_CODE (TREE_VALUE (first_parm)) != VOID_TYPE) my_friendly_abort (145); else { /* Types were specified. This is a list of declarators each represented as a TREE_LIST node. */ register tree parm, chain; - int any_init = 0, any_error = 0, saw_void = 0; + int any_init = 0, any_error = 0; if (first_parm != NULL_TREE) { @@ -9944,42 +10704,41 @@ grokparms (first_parm, funcdef_flag) for (parm = first_parm; parm != NULL_TREE; parm = chain) { - tree type, list_node = parm; + tree type = NULL_TREE, list_node = parm; register tree decl = TREE_VALUE (parm); tree init = TREE_PURPOSE (parm); chain = TREE_CHAIN (parm); /* @@ weak defense against parse errors. */ - if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST) + if (TREE_CODE (decl) != VOID_TYPE + && TREE_CODE (decl) != TREE_LIST) { /* Give various messages as the need arises. */ if (TREE_CODE (decl) == STRING_CST) - error ("invalid string constant `%s'", - TREE_STRING_POINTER (decl)); + cp_error ("invalid string constant `%E'", decl); else if (TREE_CODE (decl) == INTEGER_CST) error ("invalid integer constant in parameter list, did you forget to give parameter name?"); continue; } - if (decl != void_type_node) + if (TREE_CODE (decl) != VOID_TYPE) { - /* @@ May need to fetch out a `raises' here. */ decl = grokdeclarator (TREE_VALUE (decl), TREE_PURPOSE (decl), PARM, init != NULL_TREE, - NULL_TREE, NULL_TREE); + NULL_TREE); if (! decl) continue; type = TREE_TYPE (decl); - if (TYPE_MAIN_VARIANT (type) == void_type_node) + if (TREE_CODE (type) == VOID_TYPE) decl = void_type_node; else if (TREE_CODE (type) == METHOD_TYPE) { if (DECL_NAME (decl)) - /* Cannot use `error_with_decl' here because + /* Cannot use the decl here because we don't have DECL_CONTEXT set up yet. */ - error ("parameter `%s' invalidly declared method type", - IDENTIFIER_POINTER (DECL_NAME (decl))); + cp_error ("parameter `%D' invalidly declared method type", + DECL_NAME (decl)); else error ("parameter invalidly declared method type"); type = build_pointer_type (type); @@ -9988,8 +10747,8 @@ grokparms (first_parm, funcdef_flag) else if (TREE_CODE (type) == OFFSET_TYPE) { if (DECL_NAME (decl)) - error ("parameter `%s' invalidly declared offset type", - IDENTIFIER_POINTER (DECL_NAME (decl))); + cp_error ("parameter `%D' invalidly declared offset type", + DECL_NAME (decl)); else error ("parameter invalidly declared offset type"); type = build_pointer_type (type); @@ -10000,18 +10759,18 @@ grokparms (first_parm, funcdef_flag) && CLASSTYPE_ABSTRACT_VIRTUALS (type)) { abstract_virtuals_error (decl, type); - any_error = 1; /* seems like a good idea */ + any_error = 1; /* Seems like a good idea. */ } else if (TREE_CODE (type) == RECORD_TYPE && TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type)) { signature_error (decl, type); - any_error = 1; /* seems like a good idea */ + any_error = 1; /* Seems like a good idea. */ } } - if (decl == void_type_node) + if (TREE_CODE (decl) == VOID_TYPE) { if (result == NULL_TREE) { @@ -10023,7 +10782,6 @@ grokparms (first_parm, funcdef_flag) TREE_CHAIN (last_result) = void_list_node; last_result = void_list_node; } - saw_void = 1; if (chain && (chain != void_list_node || TREE_CHAIN (chain))) error ("`void' in parameter list must be entire list"); @@ -10045,6 +10803,11 @@ grokparms (first_parm, funcdef_flag) any_init++; if (TREE_CODE (init) == SAVE_EXPR) PARM_DECL_EXPR (init) = 1; + else if (processing_template_decl) + ; + /* Unparsed default arg from in-class decl. */ + else if (TREE_CODE (init) == DEFAULT_ARG) + ; else if (TREE_CODE (init) == VAR_DECL || TREE_CODE (init) == PARM_DECL) { @@ -10054,7 +10817,7 @@ grokparms (first_parm, funcdef_flag) argument expressions.'' dpANSI C++ 8.2.6 */ /* If extern int i; within a function is not considered a local variable, then this code is - wrong. */ + wrong. */ cp_error ("local variable `%D' may not be used as a default argument", init); any_error = 1; } @@ -10063,15 +10826,13 @@ grokparms (first_parm, funcdef_flag) } else init = require_instantiated_type (type, init, integer_zero_node); - } -#if 0 /* This is too early to check; trailing parms might be merged in by - duplicate_decls. */ - else if (any_init) - { - error ("all trailing parameters must have default arguments"); - any_error = 1; + if (! processing_template_decl + && init != error_mark_node + && TREE_CODE (init) != DEFAULT_ARG + && ! can_convert_arg (type, TREE_TYPE (init), init)) + cp_pedwarn ("invalid type `%T' for default argument to `%#D'", + TREE_TYPE (init), decl); } -#endif } else init = NULL_TREE; @@ -10086,7 +10847,7 @@ grokparms (first_parm, funcdef_flag) TREE_CHAIN (last_decl) = decl; last_decl = decl; } - if (TREE_PERMANENT (list_node)) + if (! current_function_decl && TREE_PERMANENT (list_node)) { TREE_PURPOSE (list_node) = init; TREE_VALUE (list_node) = type; @@ -10122,7 +10883,40 @@ grokparms (first_parm, funcdef_flag) return result; } + +/* Called from the parser to update an element of TYPE_ARG_TYPES for some + FUNCTION_TYPE with the newly parsed version of its default argument, which + was previously digested as text. See snarf_defarg et al in lex.c. */ + +void +replace_defarg (arg, init) + tree arg, init; +{ + if (! processing_template_decl + && ! can_convert_arg (TREE_VALUE (arg), TREE_TYPE (init), init)) + cp_pedwarn ("invalid type `%T' for default argument to `%T'", + TREE_TYPE (init), TREE_VALUE (arg)); + TREE_PURPOSE (arg) = init; +} +int +copy_args_p (d) + tree d; +{ + tree t = FUNCTION_ARG_CHAIN (d); + if (DECL_CONSTRUCTOR_P (d) + && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (d))) + t = TREE_CHAIN (t); + if (t && TREE_CODE (TREE_VALUE (t)) == REFERENCE_TYPE + && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (t))) + == DECL_CLASS_CONTEXT (d)) + && (TREE_CHAIN (t) == NULL_TREE + || TREE_CHAIN (t) == void_list_node + || TREE_PURPOSE (TREE_CHAIN (t)))) + return 1; + return 0; +} + /* These memoizing functions keep track of special properties which a class may have. `grok_ctor_properties' notices whether a class has a constructor of the form X(X&), and also complains @@ -10130,6 +10924,7 @@ grokparms (first_parm, funcdef_flag) `grok_op_properties' takes notice of the various forms of operator= which are defined, as well as what sorts of type conversion may apply. Both functions take a FUNCTION_DECL as an argument. */ + int grok_ctor_properties (ctype, decl) tree ctype, decl; @@ -10141,41 +10936,33 @@ grok_ctor_properties (ctype, decl) added to any ctor so we can tell if the class has been initialized yet. This could screw things up in this function, so we deliberately ignore the leading int if we're in that situation. */ - if (parmtypes - && TREE_VALUE (parmtypes) == integer_type_node - && TYPE_USES_VIRTUAL_BASECLASSES (ctype)) + if (TYPE_USES_VIRTUAL_BASECLASSES (ctype)) { + my_friendly_assert (parmtypes + && TREE_VALUE (parmtypes) == integer_type_node, + 980529); parmtypes = TREE_CHAIN (parmtypes); parmtype = TREE_VALUE (parmtypes); } if (TREE_CODE (parmtype) == REFERENCE_TYPE - && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype) - { - if (TREE_CHAIN (parmtypes) == NULL_TREE + && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype + && (TREE_CHAIN (parmtypes) == NULL_TREE || TREE_CHAIN (parmtypes) == void_list_node - || TREE_PURPOSE (TREE_CHAIN (parmtypes))) - { - TYPE_HAS_INIT_REF (ctype) = 1; - if (TYPE_READONLY (TREE_TYPE (parmtype))) - TYPE_HAS_CONST_INIT_REF (ctype) = 1; - } - else - TYPE_GETS_INIT_AGGR (ctype) = 1; + || TREE_PURPOSE (TREE_CHAIN (parmtypes)))) + { + TYPE_HAS_INIT_REF (ctype) = 1; + if (TYPE_READONLY (TREE_TYPE (parmtype))) + TYPE_HAS_CONST_INIT_REF (ctype) = 1; } - else if (TYPE_MAIN_VARIANT (parmtype) == ctype) + else if (TYPE_MAIN_VARIANT (parmtype) == ctype + && TREE_CHAIN (parmtypes) != NULL_TREE + && TREE_CHAIN (parmtypes) == void_list_node) { - if (TREE_CHAIN (parmtypes) != NULL_TREE - && TREE_CHAIN (parmtypes) == void_list_node) - { - cp_error ("invalid constructor; you probably meant `%T (%T&)'", - ctype, ctype); - SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); - - return 0; - } - else - TYPE_GETS_INIT_AGGR (ctype) = 1; + cp_error ("invalid constructor; you probably meant `%T (const %T&)'", + ctype, ctype); + SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); + return 0; } else if (TREE_CODE (parmtype) == VOID_TYPE || TREE_PURPOSE (parmtypes) != NULL_TREE) @@ -10185,6 +10972,7 @@ grok_ctor_properties (ctype, decl) } /* An operator with this name can be either unary or binary. */ + static int ambi_op_p (name) tree name; @@ -10198,6 +10986,7 @@ ambi_op_p (name) } /* An operator with this name can only be unary. */ + static int unary_op_p (name) tree name; @@ -10209,7 +10998,8 @@ unary_op_p (name) } /* Do a little sanity-checking on how they declared their operator. */ -static void + +void grok_op_properties (decl, virtualp, friendp) tree decl; int virtualp, friendp; @@ -10252,10 +11042,10 @@ grok_op_properties (decl, virtualp, friendp) /* Take care of function decl if we had syntax errors. */ if (argtypes == NULL_TREE) - TREE_TYPE (decl) = - build_function_type (ptr_type_node, - hash_tree_chain (integer_type_node, - void_list_node)); + TREE_TYPE (decl) + = build_function_type (ptr_type_node, + hash_tree_chain (integer_type_node, + void_list_node)); else TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); } @@ -10266,10 +11056,10 @@ grok_op_properties (decl, virtualp, friendp) revert_static_member_fn (&decl, NULL, NULL); if (argtypes == NULL_TREE) - TREE_TYPE (decl) = - build_function_type (void_type_node, - hash_tree_chain (ptr_type_node, - void_list_node)); + TREE_TYPE (decl) + = build_function_type (void_type_node, + hash_tree_chain (ptr_type_node, + void_list_node)); else { TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); @@ -10301,7 +11091,7 @@ grok_op_properties (decl, virtualp, friendp) cp_error ("`%D' must be either a non-static member function or a non-member function", decl); if (p) - for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p)) + for (; TREE_CODE (TREE_VALUE (p)) != VOID_TYPE ; p = TREE_CHAIN (p)) { tree arg = TREE_VALUE (p); if (TREE_CODE (arg) == REFERENCE_TYPE) @@ -10310,7 +11100,8 @@ grok_op_properties (decl, virtualp, friendp) /* This lets bad template code slip through. */ if (IS_AGGR_TYPE (arg) || TREE_CODE (arg) == ENUMERAL_TYPE - || TREE_CODE (arg) == TEMPLATE_TYPE_PARM) + || TREE_CODE (arg) == TEMPLATE_TYPE_PARM + || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM) goto foundaggr; } cp_error @@ -10321,11 +11112,10 @@ grok_op_properties (decl, virtualp, friendp) } } - if (name == ansi_opname[(int) CALL_EXPR] - || name == ansi_opname[(int) METHOD_CALL_EXPR]) - return; /* no restrictions on args */ + if (name == ansi_opname[(int) CALL_EXPR]) + return; /* No restrictions on args. */ - if (IDENTIFIER_TYPENAME_P (name)) + if (IDENTIFIER_TYPENAME_P (name) && ! DECL_TEMPLATE_INFO (decl)) { tree t = TREE_TYPE (name); if (TREE_CODE (t) == VOID_TYPE) @@ -10339,7 +11129,9 @@ grok_op_properties (decl, virtualp, friendp) if (t == current_class_type) what = "the same type"; + /* Don't force t to be complete here. */ else if (IS_AGGR_TYPE (t) + && TYPE_SIZE (t) && DERIVED_FROM_P (t, current_class_type)) what = "a base class"; @@ -10367,10 +11159,6 @@ grok_op_properties (decl, virtualp, friendp) if (TREE_CODE (parmtype) != REFERENCE_TYPE || TYPE_READONLY (TREE_TYPE (parmtype))) TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1; -#if 0 /* Too soon; done in grok_function_init */ - if (DECL_ABSTRACT_VIRTUAL_P (decl)) - TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1; -#endif } } else if (name == ansi_opname[(int) COND_EXPR]) @@ -10388,6 +11176,7 @@ grok_op_properties (decl, virtualp, friendp) { if ((name == ansi_opname[(int) POSTINCREMENT_EXPR] || name == ansi_opname[(int) POSTDECREMENT_EXPR]) + && ! processing_template_decl && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node) { if (methodp) @@ -10406,6 +11195,31 @@ grok_op_properties (decl, virtualp, friendp) else cp_error ("`%D' must take either one or two arguments", decl); } + + /* More Effective C++ rule 6. */ + if (warn_ecpp + && (name == ansi_opname[(int) POSTINCREMENT_EXPR] + || name == ansi_opname[(int) POSTDECREMENT_EXPR])) + { + tree arg = TREE_VALUE (argtypes); + tree ret = TREE_TYPE (TREE_TYPE (decl)); + if (methodp || TREE_CODE (arg) == REFERENCE_TYPE) + arg = TREE_TYPE (arg); + arg = TYPE_MAIN_VARIANT (arg); + if (list_length (argtypes) == 2) + { + if (TREE_CODE (ret) != REFERENCE_TYPE + || !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), + arg, 1)) + cp_warning ("prefix `%D' should return `%T'", decl, + build_reference_type (arg)); + } + else + { + if (!comptypes (TYPE_MAIN_VARIANT (ret), arg, 1)) + cp_warning ("postfix `%D' should return `%T'", decl, arg); + } + } } else if (unary_op_p (name)) { @@ -10426,7 +11240,25 @@ grok_op_properties (decl, virtualp, friendp) else cp_error ("`%D' must take exactly two arguments", decl); } - } + + /* More Effective C++ rule 7. */ + if (warn_ecpp + && (name == ansi_opname [TRUTH_ANDIF_EXPR] + || name == ansi_opname [TRUTH_ORIF_EXPR] + || name == ansi_opname [COMPOUND_EXPR])) + cp_warning ("user-defined `%D' always evaluates both arguments", + decl); + } + + /* Effective C++ rule 23. */ + if (warn_ecpp + && list_length (argtypes) == 3 + && (name == ansi_opname [PLUS_EXPR] + || name == ansi_opname [MINUS_EXPR] + || name == ansi_opname [TRUNC_DIV_EXPR] + || name == ansi_opname [MULT_EXPR]) + && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE) + cp_warning ("`%D' should return by value", decl); /* 13.4.0.8 */ if (argtypes) @@ -10465,9 +11297,20 @@ xref_tag (code_type_node, name, binfo, globalize) enum tag_types tag_code; enum tree_code code; int temp = 0; - int i; register tree ref, t; struct binding_level *b = inner_binding_level; + int got_type = 0; + tree attributes = NULL_TREE; + + /* If we are called from the parser, code_type_node will sometimes be a + TREE_LIST. This indicates that the user wrote + "class __attribute__ ((foo)) bar". Extract the attributes so we can + use them later. */ + if (TREE_CODE (code_type_node) == TREE_LIST) + { + attributes = TREE_PURPOSE (code_type_node); + code_type_node = TREE_VALUE (code_type_node); + } tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); switch (tag_code) @@ -10489,18 +11332,34 @@ xref_tag (code_type_node, name, binfo, globalize) /* If a cross reference is requested, look up the type already defined for this tag and return it. */ - t = IDENTIFIER_TYPE_VALUE (name); - if (t && TREE_CODE (t) != code) + if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') + { + t = name; + name = TYPE_IDENTIFIER (t); + got_type = 1; + } + else + t = IDENTIFIER_TYPE_VALUE (name); + if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM + && TREE_CODE (t) != TEMPLATE_TEMPLATE_PARM) t = NULL_TREE; if (! globalize) { - /* If we know we are defining this tag, only look it up in this scope - * and don't try to find it as a type. */ - if (t && TYPE_CONTEXT(t) && TREE_MANGLED (name)) + if (pedantic && t && (TREE_CODE (t) == TEMPLATE_TYPE_PARM + || TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)) + { + cp_pedwarn ("redeclaration of template type-parameter `%T'", name); + cp_pedwarn_at (" previously declared here", t); + } + if (t && TYPE_CONTEXT (t) && got_type) ref = t; else - ref = lookup_tag (code, name, b, 1); + { + /* If we know we are defining this tag, only look it up in + this scope and don't try to find it as a type. */ + ref = lookup_tag (code, name, b, 1); + } } else { @@ -10513,6 +11372,15 @@ xref_tag (code_type_node, name, binfo, globalize) { /* Try finding it as a type declaration. If that wins, use it. */ ref = lookup_name (name, 1); + + if (ref != NULL_TREE + && processing_template_decl + && DECL_CLASS_TEMPLATE_P (ref) + && template_class_depth (current_class_type) == 0) + /* Since GLOBALIZE is true, we're declaring a global + template, so we want this type. */ + ref = DECL_RESULT (ref); + if (ref && TREE_CODE (ref) == TYPE_DECL && TREE_CODE (TREE_TYPE (ref)) == code) ref = TREE_TYPE (ref); @@ -10539,6 +11407,8 @@ xref_tag (code_type_node, name, binfo, globalize) if (code == ENUMERAL_TYPE) { + cp_error ("use of enum `%#D' without previous declaration", name); + ref = make_node (ENUMERAL_TYPE); /* Give the type a default layout like unsigned int @@ -10556,8 +11426,6 @@ xref_tag (code_type_node, name, binfo, globalize) done in `start_enum'. */ pushtag (name, ref, globalize); - if (flag_cadillac) - cadillac_start_enum (ref); } else { @@ -10582,50 +11450,27 @@ xref_tag (code_type_node, name, binfo, globalize) #endif pushtag (name, ref, globalize); class_binding_level = old_b; - - if (flag_cadillac) - cadillac_start_struct (ref); } } else { /* If it no longer looks like a nested type, make sure it's - in global scope. */ - if (b == global_binding_level && !class_binding_level - && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE) - IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref); - -#if 0 - if (binfo) + in global scope. + If it is not an IDENTIFIER, this is not a declaration */ + if (b->namespace_p && !class_binding_level + && TREE_CODE (name) == IDENTIFIER_NODE) { - tree tt1 = binfo; - tree tt2 = TYPE_BINFO_BASETYPES (ref); - - if (TYPE_BINFO_BASETYPES (ref)) - for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1)) - if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i)))) - { - cp_error ("redeclaration of derivation chain of type `%#T'", - ref); - break; - } - - if (tt1 == NULL_TREE) - /* The user told us something we already knew. */ - goto just_return; - - /* In C++, since these migrate into the global scope, we must - build them on the permanent obstack. */ - end_temporary_allocation (); + if (IDENTIFIER_NAMESPACE_VALUE (name) == NULL_TREE) + SET_IDENTIFIER_NAMESPACE_VALUE (name, TYPE_NAME (ref)); } -#endif + + if (!globalize && processing_template_decl && IS_AGGR_TYPE (ref)) + redeclare_class_template (ref, current_template_parms); } if (binfo) xref_basetypes (code_type_node, name, ref, binfo); - just_return: - /* Until the type is defined, tentatively accept whatever structure tag the user hands us. */ if (TYPE_SIZE (ref) == NULL_TREE @@ -10641,9 +11486,30 @@ xref_tag (code_type_node, name, binfo, globalize) pop_obstacks (); + TREE_TYPE (ref) = attributes; + return ref; } +tree +xref_tag_from_type (old, id, globalize) + tree old, id; + int globalize; +{ + tree code_type_node; + + if (TREE_CODE (old) == RECORD_TYPE) + code_type_node = (CLASSTYPE_DECLARED_CLASS (old) + ? class_type_node : record_type_node); + else + code_type_node = union_type_node; + + if (id == NULL_TREE) + id = TYPE_IDENTIFIER (old); + + return xref_tag (code_type_node, id, NULL_TREE, globalize); +} + void xref_basetypes (code_type_node, name, ref, binfo) tree code_type_node; @@ -10672,34 +11538,42 @@ xref_basetypes (code_type_node, name, ref, binfo) { /* The base of a derived struct is public by default. */ int via_public - = (TREE_PURPOSE (binfo) == (tree)access_public - || TREE_PURPOSE (binfo) == (tree)access_public_virtual + = (TREE_PURPOSE (binfo) == access_public_node + || TREE_PURPOSE (binfo) == access_public_virtual_node || (tag_code != class_type - && (TREE_PURPOSE (binfo) == (tree)access_default - || TREE_PURPOSE (binfo) == (tree)access_default_virtual))); - int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected; + && (TREE_PURPOSE (binfo) == access_default_node + || TREE_PURPOSE (binfo) == access_default_virtual_node))); + int via_protected + = (TREE_PURPOSE (binfo) == access_protected_node + || TREE_PURPOSE (binfo) == access_protected_virtual_node); int via_virtual - = (TREE_PURPOSE (binfo) == (tree)access_private_virtual - || TREE_PURPOSE (binfo) == (tree)access_public_virtual - || TREE_PURPOSE (binfo) == (tree)access_default_virtual); - tree basetype = TREE_TYPE (TREE_VALUE (binfo)); + = (TREE_PURPOSE (binfo) == access_private_virtual_node + || TREE_PURPOSE (binfo) == access_protected_virtual_node + || TREE_PURPOSE (binfo) == access_public_virtual_node + || TREE_PURPOSE (binfo) == access_default_virtual_node); + tree basetype = TREE_VALUE (binfo); tree base_binfo; - GNU_xref_hier (IDENTIFIER_POINTER (name), - IDENTIFIER_POINTER (TREE_VALUE (binfo)), - via_public, via_virtual, 0); - if (basetype && TREE_CODE (basetype) == TYPE_DECL) basetype = TREE_TYPE (basetype); - if (!basetype || TREE_CODE (basetype) != RECORD_TYPE) + if (!basetype + || (TREE_CODE (basetype) != RECORD_TYPE + && TREE_CODE (basetype) != TYPENAME_TYPE + && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM + && TREE_CODE (basetype) != TEMPLATE_TEMPLATE_PARM)) { cp_error ("base type `%T' fails to be a struct or class type", TREE_VALUE (binfo)); continue; } + + GNU_xref_hier (name, basetype, via_public, via_virtual, 0); + #if 1 - /* This code replaces similar code in layout_basetypes. */ - else if (TYPE_INCOMPLETE (basetype)) + /* This code replaces similar code in layout_basetypes. + We put the complete_type first for implicit `typename'. */ + if (TYPE_SIZE (complete_type (basetype)) == NULL_TREE + && ! (current_template_parms && uses_template_parms (basetype))) { cp_error ("base class `%T' has incomplete type", basetype); continue; @@ -10716,6 +11590,10 @@ xref_basetypes (code_type_node, name, ref, binfo) continue; } + if (TYPE_FOR_JAVA (basetype) + && current_lang_stack == current_lang_base) + TYPE_FOR_JAVA (ref) = 1; + /* Note that the BINFO records which describe individual inheritances are *not* shared in the lattice! They cannot be shared because a given baseclass may be @@ -10735,17 +11613,7 @@ xref_basetypes (code_type_node, name, ref, binfo) BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref); SET_CLASSTYPE_MARKED (basetype); -#if 0 - /* XYZZY TEST VIRTUAL BASECLASSES */ - if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE - && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype) - && via_virtual == 0) - { - warning ("making type `%s' a virtual baseclass", - TYPE_NAME_STRING (basetype)); - via_virtual = 1; - } -#endif + /* We are free to modify these bits because they are meaningless at top level, and BASETYPE is a top-level type. */ if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype)) @@ -10754,7 +11622,6 @@ xref_basetypes (code_type_node, name, ref, binfo) TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; } - TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype); TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype); TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype); CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype); @@ -10783,7 +11650,7 @@ xref_basetypes (code_type_node, name, ref, binfo) } -static tree current_local_enum = NULL_TREE; +tree current_local_enum = NULL_TREE; /* Begin compiling the definition of an enumeration type. NAME is its name (or null if anonymous). @@ -10798,6 +11665,14 @@ start_enum (name) register tree enumtype = NULL_TREE; struct binding_level *b = inner_binding_level; + /* We are wasting space here and putting these on the permanent_obstack so + that typeid(local enum) will work correctly. */ +#if 0 + if (processing_template_decl && current_function_decl) +#endif + + end_temporary_allocation (); + /* If this is the real definition for a previous forward reference, fill in the contents in the same object that used to be the forward reference. */ @@ -10806,36 +11681,23 @@ start_enum (name) enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1); if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE) - cp_error ("multiple definition of enum `%T'", enumtype); + cp_error ("multiple definition of `%#T'", enumtype); else { enumtype = make_node (ENUMERAL_TYPE); pushtag (name, enumtype, 0); } + if (b->pseudo_global) + cp_error ("template declaration of `%#T'", enumtype); + if (current_class_type) TREE_ADDRESSABLE (b->tags) = 1; - current_local_enum = NULL_TREE; - -#if 0 /* This stuff gets cleared in finish_enum anyway. */ - if (TYPE_VALUES (enumtype) != NULL_TREE) - /* Completely replace its old definition. - The old enumerators remain defined, however. */ - TYPE_VALUES (enumtype) = NULL_TREE; - /* Initially, set up this enum as like `int' - so that we can create the enumerators' declarations and values. - Later on, the precision of the type may be changed and - it may be laid out again. */ - - TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); - TYPE_SIZE (enumtype) = NULL_TREE; - fixup_signed_type (enumtype); -#endif + current_local_enum = NULL_TREE; - /* We copy this value because enumerated type constants - are really of the type of the enumerator, not integer_type_node. */ - enum_next_value = copy_node (integer_zero_node); + /* We don't copy this value because build_enumerator needs to do it. */ + enum_next_value = integer_zero_node; enum_overflow = 0; GNU_xref_decl (current_function_decl, enumtype); @@ -10851,36 +11713,52 @@ tree finish_enum (enumtype, values) register tree enumtype, values; { - register tree minnode, maxnode; + register tree minnode = NULL_TREE, maxnode = NULL_TREE; /* Calculate the maximum value of any enumerator in this type. */ if (values) { register tree pair; register tree value = DECL_INITIAL (TREE_VALUE (values)); - - /* Speed up the main loop by performing some precalculations */ - TREE_TYPE (TREE_VALUE (values)) = enumtype; - TREE_TYPE (value) = enumtype; + + if (! processing_template_decl) + { + /* Speed up the main loop by performing some precalculations */ + TREE_TYPE (TREE_VALUE (values)) = enumtype; + TREE_TYPE (value) = enumtype; + minnode = maxnode = value; + } TREE_VALUE (values) = value; - minnode = maxnode = value; for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair)) { value = DECL_INITIAL (TREE_VALUE (pair)); - TREE_TYPE (TREE_VALUE (pair)) = enumtype; - TREE_TYPE (value) = enumtype; + if (! processing_template_decl) + { + TREE_TYPE (TREE_VALUE (pair)) = enumtype; + TREE_TYPE (value) = enumtype; + if (tree_int_cst_lt (maxnode, value)) + maxnode = value; + else if (tree_int_cst_lt (value, minnode)) + minnode = value; + } TREE_VALUE (pair) = value; - if (tree_int_cst_lt (maxnode, value)) - maxnode = value; - else if (tree_int_cst_lt (value, minnode)) - minnode = value; } } else maxnode = minnode = integer_zero_node; - TYPE_VALUES (enumtype) = values; + TYPE_VALUES (enumtype) = nreverse (values); + + if (processing_template_decl) + { + if (current_function_decl) + { + add_tree (build_min (TAG_DEFN, enumtype)); + resume_temporary_allocation (); + } + return enumtype; + } { int unsignedp = tree_int_cst_sgn (minnode) >= 0; @@ -10898,7 +11776,7 @@ finish_enum (enumtype, values) else fixup_signed_type (enumtype); - if (flag_short_enums || precision > TYPE_PRECISION (integer_type_node)) + if (flag_short_enums || (precision > TYPE_PRECISION (integer_type_node))) /* Use the width of the narrowest normal C type which is wide enough. */ TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size (precision, 1)); @@ -10909,9 +11787,6 @@ finish_enum (enumtype, values) layout_type (enumtype); } - if (flag_cadillac) - cadillac_finish_enum (enumtype); - { register tree tem; @@ -10923,6 +11798,7 @@ finish_enum (enumtype, values) TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); TYPE_SIZE (tem) = TYPE_SIZE (enumtype); + TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype); TYPE_MODE (tem) = TYPE_MODE (enumtype); TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); @@ -10931,12 +11807,7 @@ finish_enum (enumtype, values) } /* Finish debugging output for this type. */ -#if 0 - /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging - information should *not* be generated? I think not. */ - if (! DECL_IGNORED_P (TYPE_NAME (enumtype))) -#endif - rest_of_type_compilation (enumtype, global_bindings_p ()); + rest_of_type_compilation (enumtype, namespace_bindings_p ()); return enumtype; } @@ -10951,61 +11822,51 @@ build_enumerator (name, value) tree name, value; { tree decl, result; - /* Change this to zero if we find VALUE is not shareable. */ - int shareable = 1; /* Remove no-op casts from the value. */ if (value) STRIP_TYPE_NOPS (value); - /* Validate and default VALUE. */ - if (value != NULL_TREE) - { - if (TREE_READONLY_DECL_P (value)) - { - value = decl_constant_value (value); - shareable = 0; - } - - if (TREE_CODE (value) == INTEGER_CST) - { - value = default_conversion (value); - constant_expression_warning (value); - } - else - { - cp_error ("enumerator value for `%D' not integer constant", name); - value = NULL_TREE; - } - } - - /* The order of things is reversed here so that we - can check for possible sharing of enum values, - to keep that from happening. */ - /* Default based on previous value. */ - if (value == NULL_TREE) - { - value = enum_next_value; - if (enum_overflow) - cp_error ("overflow in enumeration values at `%D'", name); - } - - /* Remove no-op casts from the value. */ - if (value) - STRIP_TYPE_NOPS (value); - - /* Make up for hacks in lex.c. */ - if (value == integer_zero_node) - value = build_int_2 (0, 0); - else if (value == integer_one_node) - value = build_int_2 (1, 0); - else if (TREE_CODE (value) == INTEGER_CST - && (shareable == 0 - || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE)) - { - value = copy_node (value); - TREE_TYPE (value) = integer_type_node; - } + if (! processing_template_decl) + { + /* Validate and default VALUE. */ + if (value != NULL_TREE) + { + if (TREE_READONLY_DECL_P (value)) + value = decl_constant_value (value); + + if (TREE_CODE (value) == INTEGER_CST) + { + value = default_conversion (value); + constant_expression_warning (value); + } + else + { + cp_error ("enumerator value for `%D' not integer constant", name); + value = NULL_TREE; + } + } + + /* Default based on previous value. */ + if (value == NULL_TREE && ! processing_template_decl) + { + value = enum_next_value; + if (enum_overflow) + cp_error ("overflow in enumeration values at `%D'", name); + } + + /* Remove no-op casts from the value. */ + if (value) + STRIP_TYPE_NOPS (value); + + /* We have to always copy here; not all INTEGER_CSTs are unshared, + and there's no wedding ring. Look at size_int()...*/ + value = copy_node (value); +#if 0 + /* To fix MAX_VAL enum consts. (bkoz) */ + TREE_TYPE (value) = integer_type_node; +#endif + } /* C++ associates enums with global, function, or class declarations. */ @@ -11027,26 +11888,27 @@ build_enumerator (name, value) a function could mean local to a class method. */ decl = build_decl (CONST_DECL, name, integer_type_node); DECL_INITIAL (decl) = value; + TREE_READONLY (decl) = 1; pushdecl (decl); GNU_xref_decl (current_function_decl, decl); } - /* Set basis for default for next value. */ - enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, - integer_one_node, PLUS_EXPR); - enum_overflow = tree_int_cst_lt (enum_next_value, value); - - if (enum_next_value == integer_one_node) - enum_next_value = copy_node (enum_next_value); + if (! processing_template_decl) + { + /* Set basis for default for next value. */ + enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, + integer_one_node, PLUS_EXPR); + enum_overflow = tree_int_cst_lt (enum_next_value, value); + } result = saveable_tree_cons (name, decl, NULL_TREE); return result; } tree -grok_enum_decls (type, decl) - tree type, decl; +grok_enum_decls (decl) + tree decl; { tree d = current_local_enum; @@ -11055,7 +11917,6 @@ grok_enum_decls (type, decl) while (1) { - TREE_TYPE (d) = type; if (TREE_CHAIN (d) == NULL_TREE) { TREE_CHAIN (d) = decl; @@ -11070,6 +11931,8 @@ grok_enum_decls (type, decl) return decl; } +static int function_depth; + /* Create the FUNCTION_DECL for a function definition. DECLSPECS and DECLARATOR are the parts of the declaration; they describe the function's name and the type it returns, @@ -11092,11 +11955,11 @@ grok_enum_decls (type, decl) @@ something we had previously. */ int -start_function (declspecs, declarator, raises, attrs, pre_parsed_p) - tree declspecs, declarator, raises, attrs; +start_function (declspecs, declarator, attrs, pre_parsed_p) + tree declspecs, declarator, attrs; int pre_parsed_p; { - tree decl1, olddecl; + tree decl1; tree ctype = NULL_TREE; tree fntype; tree restype; @@ -11105,10 +11968,10 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) int doing_friend = 0; /* Sanity check. */ - my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160); + my_friendly_assert (TREE_CODE (TREE_VALUE (void_list_node)) == VOID_TYPE, 160); my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161); - /* Assume, until we see it does. */ + /* Assume, until we see it does. */ current_function_returns_value = 0; current_function_returns_null = 0; warn_about_return_type = 0; @@ -11118,17 +11981,15 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) current_function_just_assigned_this = 0; current_function_parms_stored = 0; original_result_rtx = NULL_RTX; - current_function_obstack_index = 0; - current_function_obstack_usage = 0; base_init_expr = NULL_TREE; - protect_list = NULL_TREE; current_base_init_list = NULL_TREE; current_member_init_list = NULL_TREE; ctor_label = dtor_label = NULL_TREE; + static_labelno = 0; clear_temp_name (); - /* This should only be done once on the top most decl. */ + /* This should only be done once on the top most decl. */ if (have_extern_spec && !used_extern_spec) { declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); @@ -11139,31 +12000,25 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) { decl1 = declarator; +#if 0 + /* What was this testing for, exactly? */ if (! DECL_ARGUMENTS (decl1) && !DECL_STATIC_FUNCTION_P (decl1) - && DECL_CONTEXT (decl1) - && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1))) - && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1))))) + && !DECL_ARTIFICIAL (decl1) + && DECL_CLASS_SCOPE_P (decl1) + && TYPE_IDENTIFIER (DECL_CONTEXT (decl1)) + && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (DECL_CONTEXT (decl1)))) { + tree binding = binding_for_name (DECL_NAME (decl1), + current_namespace); cp_error ("redeclaration of `%#D'", decl1); if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))) cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))); - else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1))) - cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1))); - } - - /* This can happen if a template class is instantiated as part of the - specialization of a member function which is defined in the class - template. We should just use the specialization, but for now give an - error. */ - if (DECL_INITIAL (decl1) != NULL_TREE) - { - cp_error_at ("specialization of `%#D' not supported", decl1); - cp_error ("when defined in the class template body", decl1); + else if (BINDING_VALUE (binding)) + cp_error_at ("previous declaration here", BINDING_VALUE (binding)); } +#endif - last_function_parms = DECL_ARGUMENTS (decl1); - last_function_parm_tags = NULL_TREE; fntype = TREE_TYPE (decl1); if (TREE_CODE (fntype) == METHOD_TYPE) ctype = TYPE_METHOD_BASETYPE (fntype); @@ -11184,23 +12039,23 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) doing_friend = 1; } - raises = TYPE_RAISES_EXCEPTIONS (fntype); - /* In a fcn definition, arg types must be complete. */ - require_complete_types_for_parms (last_function_parms); + require_complete_types_for_parms (DECL_ARGUMENTS (decl1)); /* In case some arg types were completed since the declaration was parsed, fix up the decls. */ { - tree t = last_function_parms; + tree t = DECL_ARGUMENTS (decl1); for (; t; t = TREE_CHAIN (t)) layout_decl (t, 0); } + + last_function_parms = DECL_ARGUMENTS (decl1); + last_function_parm_tags = NULL_TREE; } else { - decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises, - NULL_TREE); + decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL_TREE); /* If the declarator is not suitable for a function definition, cause a syntax error. */ if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0; @@ -11212,7 +12067,7 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) && ! CLASSTYPE_GOT_SEMICOLON (restype)) { cp_error ("semicolon missing after declaration of `%#T'", restype); - shadow_tag (build_tree_list (NULL_TREE, restype)); + shadow_tag (build_expr_list (NULL_TREE, restype)); CLASSTYPE_GOT_SEMICOLON (restype) = 1; if (TREE_CODE (fntype) == FUNCTION_TYPE) fntype = build_function_type (integer_type_node, @@ -11226,15 +12081,13 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) if (TREE_CODE (fntype) == METHOD_TYPE) ctype = TYPE_METHOD_BASETYPE (fntype); - else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4 - && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main") - && DECL_CONTEXT (decl1) == NULL_TREE) + else if (DECL_MAIN_P (decl1)) { /* If this doesn't return integer_type, complain. */ if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node) { if (pedantic || warn_return_type) - pedwarn ("return type for `main' changed to integer type"); + pedwarn ("return type for `main' changed to `int'"); TREE_TYPE (decl1) = fntype = default_function_type; } warn_about_return_type = 0; @@ -11248,53 +12101,57 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))); current_function_decl = decl1; + /* Save the parm names or decls from this function's declarator + where store_parm_decls will find them. */ + current_function_parms = last_function_parms; + current_function_parm_tags = last_function_parm_tags; - if (flag_cadillac) - cadillac_start_function (decl1); - else - announce_function (decl1); + announce_function (decl1); - if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE) + if (! processing_template_decl) { - if (IS_AGGR_TYPE (TREE_TYPE (fntype))) - error_with_aggr_type (TREE_TYPE (fntype), - "return-type `%s' is an incomplete type"); - else - error ("return-type is an incomplete type"); - - /* Make it return void instead, but don't change the - type of the DECL_RESULT, in case we have a named return value. */ - if (ctype) - TREE_TYPE (decl1) - = build_cplus_method_type (build_type_variant (ctype, - TREE_READONLY (decl1), - TREE_SIDE_EFFECTS (decl1)), - void_type_node, - FUNCTION_ARG_CHAIN (decl1)); - else - TREE_TYPE (decl1) - = build_function_type (void_type_node, - TYPE_ARG_TYPES (TREE_TYPE (decl1))); - DECL_RESULT (decl1) - = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype))); - TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype)); - TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype)); - } + if (TYPE_SIZE (complete_type (TREE_TYPE (fntype))) == NULL_TREE) + { + cp_error ("return-type `%#T' is an incomplete type", + TREE_TYPE (fntype)); - if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype)) - && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype))) - abstract_virtuals_error (decl1, TREE_TYPE (fntype)); + /* Make it return void instead, but don't change the + type of the DECL_RESULT, in case we have a named return value. */ + if (ctype) + TREE_TYPE (decl1) + = build_cplus_method_type (build_type_variant (ctype, + TREE_READONLY (decl1), + TREE_SIDE_EFFECTS (decl1)), + void_type_node, + FUNCTION_ARG_CHAIN (decl1)); + else + TREE_TYPE (decl1) + = build_function_type (void_type_node, + TYPE_ARG_TYPES (TREE_TYPE (decl1))); + DECL_RESULT (decl1) + = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype))); + TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype)); + TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype)); + } + + if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype)) + && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype))) + abstract_virtuals_error (decl1, TREE_TYPE (fntype)); + } if (warn_about_return_type) - warning ("return-type defaults to `int'"); + pedwarn ("return-type defaults to `int'"); + + /* Effective C++ rule 15. See also c_expand_return. */ + if (warn_ecpp + && DECL_NAME (decl1) == ansi_opname[(int) MODIFY_EXPR] + && TREE_CODE (TREE_TYPE (fntype)) == VOID_TYPE) + cp_warning ("`operator=' should return a reference to `*this'"); /* Make the init_value nonzero so pushdecl knows this is not tentative. error_mark_node is replaced below (in poplevel) with the BLOCK. */ DECL_INITIAL (decl1) = error_mark_node; - /* Didn't get anything from C. */ - olddecl = NULL_TREE; - /* This function exists in static storage. (This does not mean `static' in the C sense!) */ TREE_STATIC (decl1) = 1; @@ -11303,26 +12160,51 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) If we already have a decl for this name, and it is a FUNCTION_DECL, use the old decl. */ - if (pre_parsed_p == 0) - { - current_function_decl = decl1 = pushdecl (decl1); + if (processing_template_decl) + decl1 = push_template_decl (decl1); + else if (pre_parsed_p == 0) + { + /* A specialization is not used to guide overload resolution. */ + if ((flag_guiding_decls + || !DECL_TEMPLATE_SPECIALIZATION (decl1)) + && ! DECL_FUNCTION_MEMBER_P (decl1)) + decl1 = pushdecl (decl1); + else + { + /* We need to set the DECL_CONTEXT. */ + if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1)) + DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1)); + /* And make sure we have enough default args. */ + check_default_args (decl1); + } DECL_MAIN_VARIANT (decl1) = decl1; fntype = TREE_TYPE (decl1); } - else - current_function_decl = decl1; + + current_function_decl = decl1; if (DECL_INTERFACE_KNOWN (decl1)) { + tree ctx = hack_decl_function_context (decl1); + if (DECL_NOT_REALLY_EXTERN (decl1)) DECL_EXTERNAL (decl1) = 0; + + if (ctx != NULL_TREE && DECL_THIS_INLINE (ctx) + && TREE_PUBLIC (ctx)) + /* This is a function in a local class in an extern inline + function. */ + comdat_linkage (decl1); } /* If this function belongs to an interface, it is public. If it belongs to someone else's interface, it is also external. It doesn't matter whether it's inline or not. */ - else if (interface_unknown == 0) + else if (interface_unknown == 0 + && (! DECL_TEMPLATE_INSTANTIATION (decl1) + || flag_alt_external_templates)) { - if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)) + if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1) + || processing_template_decl) DECL_EXTERNAL (decl1) = (interface_only || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines)); @@ -11337,14 +12219,13 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) So clear DECL_EXTERNAL. */ DECL_EXTERNAL (decl1) = 0; - if (DECL_THIS_INLINE (decl1) && ! DECL_INTERFACE_KNOWN (decl1)) + if ((DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)) + && ! DECL_INTERFACE_KNOWN (decl1) + /* Don't try to defer nested functions for now. */ + && ! hack_decl_function_context (decl1)) DECL_DEFER_OUTPUT (decl1) = 1; else - { - DECL_INTERFACE_KNOWN (decl1) = 1; - if (DECL_C_STATIC (decl1)) - TREE_PUBLIC (decl1) = 0; - } + DECL_INTERFACE_KNOWN (decl1) = 1; } if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)) @@ -11353,8 +12234,8 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) TREE_TYPE (decl1) = fntype = build_function_type (TREE_TYPE (fntype), TREE_CHAIN (TYPE_ARG_TYPES (fntype))); - last_function_parms = TREE_CHAIN (last_function_parms); - DECL_ARGUMENTS (decl1) = last_function_parms; + current_function_parms = TREE_CHAIN (current_function_parms); + DECL_ARGUMENTS (decl1) = current_function_parms; ctype = NULL_TREE; } restype = TREE_TYPE (fntype); @@ -11364,15 +12245,15 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) push_nested_class (ctype, 1); /* If we're compiling a friend function, neither of the variables - current_class_decl nor current_class_type will have values. */ + current_class_ptr nor current_class_type will have values. */ if (! doing_friend) { /* We know that this was set up by `grokclassfn'. We do not wait until `store_parm_decls', since evil parse errors may never get us to that point. Here we keep the consistency between `current_class_type' - and `current_class_decl'. */ - tree t = last_function_parms; + and `current_class_ptr'. */ + tree t = current_function_parms; my_friendly_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL, 162); @@ -11382,14 +12263,14 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) int i = suspend_momentary (); /* Fool build_indirect_ref. */ - current_class_decl = NULL_TREE; - C_C_D = build_indirect_ref (t, NULL_PTR); - current_class_decl = t; + current_class_ptr = NULL_TREE; + current_class_ref = build_indirect_ref (t, NULL_PTR); + current_class_ptr = t; resume_momentary (i); } else /* We're having a signature pointer here. */ - C_C_D = current_class_decl = t; + current_class_ref = current_class_ptr = t; } } @@ -11399,40 +12280,27 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) push_nested_class (DECL_CONTEXT (decl1), 2); else push_memoized_context (0, 1); - current_class_decl = C_C_D = NULL_TREE; + current_class_ptr = current_class_ref = NULL_TREE; } pushlevel (0); current_binding_level->parm_flag = 1; - /* Save the parm names or decls from this function's declarator - where store_parm_decls will find them. */ - current_function_parms = last_function_parms; - current_function_parm_tags = last_function_parm_tags; - GNU_xref_function (decl1, current_function_parms); if (attrs) cplus_decl_attributes (decl1, NULL_TREE, attrs); make_function_rtl (decl1); - /* Allocate further tree nodes temporarily during compilation - of this function only. Tiemann moved up here from bottom of fn. */ - temporary_allocation (); - /* Promote the value to int before returning it. */ if (C_PROMOTING_INTEGER_TYPE_P (restype)) - { - /* It retains unsignedness if traditional or if it isn't - really getting wider. */ - if (TREE_UNSIGNED (restype) - && (flag_traditional - || TYPE_PRECISION (restype) - == TYPE_PRECISION (integer_type_node))) - restype = unsigned_type_node; - else - restype = integer_type_node; - } + restype = type_promotes_to (restype); + + /* If this fcn was already referenced via a block-scope `extern' decl + (or an implicit decl), propagate certain information about the usage. */ + if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) + TREE_ADDRESSABLE (decl1) = 1; + if (DECL_RESULT (decl1) == NULL_TREE) { DECL_RESULT (decl1) @@ -11441,6 +12309,22 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype); } + /* Allocate further tree nodes temporarily during compilation + of this function only. Tiemann moved up here from bottom of fn. */ + /* If this is a nested function, then we must continue to allocate RTL + on the permanent obstack in case we need to inline it later. */ + if (! hack_decl_function_context (decl1)) + temporary_allocation (); + + if (processing_template_decl) + { + ++minimal_parse_mode; + last_tree = DECL_SAVED_TREE (decl1) + = build_nt (EXPR_STMT, void_zero_node); + } + + ++function_depth; + if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)) && DECL_LANGUAGE (decl1) == lang_cplusplus) { @@ -11454,36 +12338,18 @@ start_function (declspecs, declarator, raises, attrs, pre_parsed_p) ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); } - /* If this fcn was already referenced via a block-scope `extern' decl - (or an implicit decl), propagate certain information about the usage. */ - if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) - TREE_ADDRESSABLE (decl1) = 1; - return 1; } +/* Called after store_parm_decls for a function-try-block. We need to update + last_parm_cleanup_insn so that the base initializers for a constructor + are run within this block, not before it. */ + void expand_start_early_try_stmts () { - rtx insns; - start_sequence (); expand_start_try_stmts (); - insns = get_insns (); - end_sequence (); - store_in_parms (insns); -} - -void -store_in_parms (insns) - rtx insns; -{ - rtx last_parm_insn; - - last_parm_insn = get_first_nonparm_insn (); - if (last_parm_insn == NULL_RTX) - emit_insns (insns); - else - emit_insns_before (insns, previous_insn (last_parm_insn)); + last_parm_cleanup_insn = get_last_insn (); } /* Store the parameter declarations into the current function declaration. @@ -11498,6 +12364,7 @@ store_parm_decls () register tree fndecl = current_function_decl; register tree parm; int parms_have_cleanups = 0; + tree cleanups = NULL_TREE; /* This is either a chain of PARM_DECLs (when a prototype is used). */ tree specparms = current_function_parms; @@ -11534,22 +12401,18 @@ store_parm_decls () /* Must clear this because it might contain TYPE_DECLs declared at class level. */ storedecls (NULL_TREE); + for (parm = nreverse (specparms); parm; parm = next) { next = TREE_CHAIN (parm); if (TREE_CODE (parm) == PARM_DECL) { - tree cleanup = maybe_build_cleanup (parm); + tree cleanup; if (DECL_NAME (parm) == NULL_TREE) { -#if 0 - cp_error_at ("parameter name omitted", parm); -#else - /* for C++, this is not an error. */ pushdecl (parm); -#endif } - else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node) + else if (TREE_CODE (TREE_TYPE (parm)) == VOID_TYPE) cp_error ("parameter `%D' declared void", parm); else { @@ -11572,13 +12435,14 @@ store_parm_decls () pushdecl (parm); } - if (cleanup) + if (! processing_template_decl + && (cleanup = maybe_build_cleanup (parm), cleanup)) { expand_decl (parm); - if (! cp_expand_decl_cleanup (parm, cleanup)) - cp_error ("parser lost in parsing declaration of `%D'", - parm); parms_have_cleanups = 1; + + /* Keep track of the cleanups. */ + cleanups = tree_cons (parm, cleanup, cleanups); } } else @@ -11609,7 +12473,29 @@ store_parm_decls () /* Initialize the RTL code for the function. */ DECL_SAVED_INSNS (fndecl) = NULL_RTX; - expand_function_start (fndecl, parms_have_cleanups); + if (! processing_template_decl) + expand_function_start (fndecl, parms_have_cleanups); + + current_function_parms_stored = 1; + + /* If this function is `main', emit a call to `__main' + to run global initializers, etc. */ + if (DECL_MAIN_P (fndecl)) + expand_main_function (); + + /* Now that we have initialized the parms, we can start their + cleanups. We cannot do this before, since expand_decl_cleanup + should not be called before the parm can be used. */ + if (cleanups + && ! processing_template_decl) + { + for (cleanups = nreverse (cleanups); cleanups; cleanups = TREE_CHAIN (cleanups)) + { + if (! expand_decl_cleanup (TREE_PURPOSE (cleanups), TREE_VALUE (cleanups))) + cp_error ("parser lost in parsing declaration of `%D'", + TREE_PURPOSE (cleanups)); + } + } /* Create a binding contour which can be used to catch cleanup-generated temporaries. Also, if the return value needs or @@ -11620,57 +12506,20 @@ store_parm_decls () expand_start_bindings (0); } - current_function_parms_stored = 1; - - if (flag_gc) - { - maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node); - if (! cp_expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup)) - cp_error ("parser lost in parsing declaration of `%D'", fndecl); - } - - /* If this function is `main', emit a call to `__main' - to run global initializers, etc. */ - if (DECL_NAME (fndecl) - && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 - && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0 - && DECL_CONTEXT (fndecl) == NULL_TREE) + if (! processing_template_decl && flag_exceptions) { - expand_main_function (); - - if (flag_gc) - expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE), - 0, VOIDmode, 0); -#if 0 - /* done at a different time */ - if (flag_rtti) - output_builtin_tdesc_entries (); -#endif - } - - /* Take care of exception handling things. */ - if (flag_handle_exceptions) - { - rtx insns; - start_sequence (); - - /* Mark the start of a stack unwinder if we need one. */ - start_eh_unwinder (); - /* Do the starting of the exception specifications, if we have any. */ if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) expand_start_eh_spec (); - - insns = get_insns (); - end_sequence (); - - if (insns) - store_in_parms (insns); } + + last_parm_cleanup_insn = get_last_insn (); + last_dtor_insn = get_last_insn (); } /* Bind a name and initialization to the return value of the current function. */ + void store_return_init (return_id, init) tree return_id, init; @@ -11691,8 +12540,7 @@ store_return_init (return_id, init) DECL_ASSEMBLER_NAME (decl) = return_id; } else - error ("return identifier `%s' already in place", - IDENTIFIER_POINTER (DECL_NAME (decl))); + cp_error ("return identifier `%D' already in place", decl); } /* Can't let this happen for constructors. */ @@ -11716,7 +12564,12 @@ store_return_init (return_id, init) /* Let `cp_finish_decl' know that this initializer is ok. */ DECL_INITIAL (decl) = init; pushdecl (decl); - cp_finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING); + + if (minimal_parse_mode) + add_tree (build_min_nt (RETURN_INIT, return_id, + copy_to_permanent (init))); + else + cp_finish_decl (decl, init, NULL_TREE, 0, 0); } } @@ -11731,7 +12584,10 @@ store_return_init (return_id, init) C++: CALL_POPLEVEL is non-zero if an extra call to poplevel (and expand_end_bindings) must be made to take care of the binding contour for the base initializers. This is only relevant for - constructors. */ + constructors. + + NESTED is nonzero if we were in the middle of compiling another function + when we started on this one. */ void finish_function (lineno, call_poplevel, nested) @@ -11751,6 +12607,9 @@ finish_function (lineno, call_poplevel, nested) if (fndecl == NULL_TREE) return; + if (! nested && function_depth > 1) + nested = 1; + fntype = TREE_TYPE (fndecl); /* TREE_READONLY (fndecl) = 1; @@ -11764,382 +12623,391 @@ finish_function (lineno, call_poplevel, nested) store_parm_decls (); } - if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/) + if (processing_template_decl) { - tree ttype = target_type (fntype); - tree parmdecl; - - if (IS_AGGR_TYPE (ttype)) - /* Let debugger know it should output info for this type. */ - note_debug_info_needed (ttype); - - for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) + if (DECL_CONSTRUCTOR_P (fndecl) && call_poplevel) + { + decls = getdecls (); + expand_end_bindings (decls, decls != NULL_TREE, 0); + poplevel (decls != NULL_TREE, 0, 0); + } + } + else + { + if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/) { - ttype = target_type (TREE_TYPE (parmdecl)); + tree ttype = target_type (fntype); + tree parmdecl; + if (IS_AGGR_TYPE (ttype)) /* Let debugger know it should output info for this type. */ note_debug_info_needed (ttype); - } - } - /* Clean house because we will need to reorder insns here. */ - do_pending_stack_adjust (); + for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) + { + ttype = target_type (TREE_TYPE (parmdecl)); + if (IS_AGGR_TYPE (ttype)) + /* Let debugger know it should output info for this type. */ + note_debug_info_needed (ttype); + } + } - if (dtor_label) - { - tree binfo = TYPE_BINFO (current_class_type); - tree cond = integer_one_node; - tree exprstmt, vfields; - tree in_charge_node = lookup_name (in_charge_identifier, 0); - tree virtual_size; - int ok_to_optimize_dtor = 0; + /* Clean house because we will need to reorder insns here. */ + do_pending_stack_adjust (); - if (current_function_assigns_this) - cond = build (NE_EXPR, boolean_type_node, - current_class_decl, integer_zero_node); - else + if (dtor_label) { - int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); + tree binfo = TYPE_BINFO (current_class_type); + tree cond = integer_one_node; + tree exprstmt; + tree in_charge_node = lookup_name (in_charge_identifier, 0); + tree virtual_size; + int ok_to_optimize_dtor = 0; + int empty_dtor = get_last_insn () == last_dtor_insn; - /* If this destructor is empty, then we don't need to check - whether `this' is NULL in some cases. */ - if ((flag_this_is_variable & 1) == 0) - ok_to_optimize_dtor = 1; - else if (get_last_insn () == get_first_nonparm_insn ()) - ok_to_optimize_dtor - = (n_baseclasses == 0 - || (n_baseclasses == 1 - && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); - } + if (current_function_assigns_this) + cond = build (NE_EXPR, boolean_type_node, + current_class_ptr, integer_zero_node); + else + { + int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); + + /* If this destructor is empty, then we don't need to check + whether `this' is NULL in some cases. */ + if ((flag_this_is_variable & 1) == 0) + ok_to_optimize_dtor = 1; + else if (empty_dtor) + ok_to_optimize_dtor + = (n_baseclasses == 0 + || (n_baseclasses == 1 + && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); + } - /* These initializations might go inline. Protect - the binding level of the parms. */ - pushlevel (0); - expand_start_bindings (0); + /* These initializations might go inline. Protect + the binding level of the parms. */ + pushlevel (0); + expand_start_bindings (0); - if (current_function_assigns_this) - { - current_function_assigns_this = 0; - current_function_just_assigned_this = 0; - } + if (current_function_assigns_this) + { + current_function_assigns_this = 0; + current_function_just_assigned_this = 0; + } - /* Generate the code to call destructor on base class. - If this destructor belongs to a class with virtual - functions, then set the virtual function table - pointer to represent the type of our base class. */ + /* Generate the code to call destructor on base class. + If this destructor belongs to a class with virtual + functions, then set the virtual function table + pointer to represent the type of our base class. */ - /* This side-effect makes call to `build_delete' generate the - code we have to have at the end of this destructor. */ - TYPE_HAS_DESTRUCTOR (current_class_type) = 0; + /* This side-effect makes call to `build_delete' generate the + code we have to have at the end of this destructor. */ + TYPE_HAS_DESTRUCTOR (current_class_type) = 0; - /* These are two cases where we cannot delegate deletion. */ - if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) - || TYPE_GETS_REG_DELETE (current_class_type)) - exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node, - LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); - else - exprstmt = build_delete (current_class_type, C_C_D, in_charge_node, - LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0); - - /* If we did not assign to this, then `this' is non-zero at - the end of a destructor. As a special optimization, don't - emit test if this is an empty destructor. If it does nothing, - it does nothing. If it calls a base destructor, the base - destructor will perform the test. */ - - if (exprstmt != error_mark_node - && (TREE_CODE (exprstmt) != NOP_EXPR - || TREE_OPERAND (exprstmt, 0) != integer_zero_node - || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) - { - expand_label (dtor_label); - if (cond != integer_one_node) - expand_start_cond (cond, 0); - if (exprstmt != void_zero_node) - /* Don't call `expand_expr_stmt' if we're not going to do - anything, since -Wall will give a diagnostic. */ - expand_expr_stmt (exprstmt); - - /* Run destructor on all virtual baseclasses. */ - if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) - { - tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); - expand_start_cond (build (BIT_AND_EXPR, integer_type_node, - in_charge_node, integer_two_node), 0); - while (vbases) + /* These are two cases where we cannot delegate deletion. */ + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) + || TYPE_GETS_REG_DELETE (current_class_type)) + exprstmt = build_delete (current_class_type, current_class_ref, integer_zero_node, + LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); + else + exprstmt = build_delete (current_class_type, current_class_ref, in_charge_node, + LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); + + /* If we did not assign to this, then `this' is non-zero at + the end of a destructor. As a special optimization, don't + emit test if this is an empty destructor. If it does nothing, + it does nothing. If it calls a base destructor, the base + destructor will perform the test. */ + + if (exprstmt != error_mark_node + && (TREE_CODE (exprstmt) != NOP_EXPR + || TREE_OPERAND (exprstmt, 0) != integer_zero_node + || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) + { + expand_label (dtor_label); + if (cond != integer_one_node) + expand_start_cond (cond, 0); + if (exprstmt != void_zero_node) + /* Don't call `expand_expr_stmt' if we're not going to do + anything, since -Wall will give a diagnostic. */ + expand_expr_stmt (exprstmt); + + /* Run destructor on all virtual baseclasses. */ + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) { - if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) + tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); + expand_start_cond (build (BIT_AND_EXPR, integer_type_node, + in_charge_node, integer_two_node), 0); + while (vbases) { - tree ptr = convert_pointer_to_vbase (BINFO_TYPE (vbases), current_class_decl); - expand_expr_stmt (build_delete (build_pointer_type (BINFO_TYPE (vbases)), - ptr, integer_zero_node, - LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0)); + if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) + { + tree vb = get_vbase + (BINFO_TYPE (vbases), + TYPE_BINFO (current_class_type)); + expand_expr_stmt + (build_scoped_method_call + (current_class_ref, vb, dtor_identifier, + build_expr_list (NULL_TREE, integer_zero_node))); + } + vbases = TREE_CHAIN (vbases); } - vbases = TREE_CHAIN (vbases); + expand_end_cond (); } - expand_end_cond (); + + do_pending_stack_adjust (); + if (cond != integer_one_node) + expand_end_cond (); } - do_pending_stack_adjust (); - if (cond != integer_one_node) - expand_end_cond (); - } + TYPE_HAS_DESTRUCTOR (current_class_type) = 1; - TYPE_HAS_DESTRUCTOR (current_class_type) = 1; - - virtual_size = c_sizeof (current_class_type); - - /* At the end, call delete if that's what's requested. */ - if (TYPE_GETS_REG_DELETE (current_class_type)) - /* This NOP_EXPR means we are in a static call context. */ - exprstmt = - build_method_call - (build_indirect_ref - (build1 (NOP_EXPR, build_pointer_type (current_class_type), - error_mark_node), - NULL_PTR), - ansi_opname[(int) DELETE_EXPR], - tree_cons (NULL_TREE, current_class_decl, - build_tree_list (NULL_TREE, virtual_size)), - NULL_TREE, LOOKUP_NORMAL); - else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) - exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0, - virtual_size); - else - exprstmt = NULL_TREE; + virtual_size = c_sizeof (current_class_type); - if (exprstmt) - { - cond = build (BIT_AND_EXPR, integer_type_node, - in_charge_node, integer_one_node); - expand_start_cond (cond, 0); - expand_expr_stmt (exprstmt); - expand_end_cond (); - } + /* At the end, call delete if that's what's requested. */ - /* End of destructor. */ - expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0); - poplevel (2, 0, 0); /* XXX change to 1 */ + /* FDIS sez: At the point of definition of a virtual destructor + (including an implicit definition), non-placement operator + delete shall be looked up in the scope of the destructor's + class and if found shall be accessible and unambiguous. - /* Back to the top of destructor. */ - /* Dont execute destructor code if `this' is NULL. */ + This is somewhat unclear, but I take it to mean that if the + class only defines placement deletes we don't do anything here. + So we pass LOOKUP_SPECULATIVELY; delete_sanity will complain + for us if they ever try to delete one of these. */ - start_sequence (); + if (TYPE_GETS_REG_DELETE (current_class_type) + || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + exprstmt = build_op_delete_call + (DELETE_EXPR, current_class_ptr, virtual_size, + LOOKUP_NORMAL | LOOKUP_SPECULATIVELY, NULL_TREE); + else + exprstmt = NULL_TREE; - /* Make all virtual function table pointers in non-virtual base - classes point to CURRENT_CLASS_TYPE's virtual function - tables. */ - expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_decl); - if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) - expand_indirect_vtbls_init (binfo, C_C_D, current_class_decl, 0); - if (! ok_to_optimize_dtor) - { - cond = build_binary_op (NE_EXPR, - current_class_decl, integer_zero_node, 1); - expand_start_cond (cond, 0); - } + if (exprstmt) + { + cond = build (BIT_AND_EXPR, integer_type_node, + in_charge_node, integer_one_node); + expand_start_cond (cond, 0); + expand_expr_stmt (exprstmt); + expand_end_cond (); + } - insns = get_insns (); - end_sequence (); + /* End of destructor. */ + expand_end_bindings (NULL_TREE, getdecls () != NULL_TREE, 0); + poplevel (2, 0, 0); /* XXX change to 1 */ + + /* Back to the top of destructor. */ + /* Don't execute destructor code if `this' is NULL. */ + + start_sequence (); + + /* If the dtor is empty, and we know there is not possible way we + could use any vtable entries, before they are possibly set by + a base class dtor, we don't have to setup the vtables, as we + know that any base class dtoring will set up any vtables it + needs. We avoid MI, because one base class dtor can do a + virtual dispatch to an overridden function that would need to + have a non-related vtable set up, we cannot avoid setting up + vtables in that case. We could change this to see if there is + just one vtable. */ + if (! empty_dtor || TYPE_USES_COMPLEX_INHERITANCE (current_class_type)) + { + /* Make all virtual function table pointers in non-virtual base + classes point to CURRENT_CLASS_TYPE's virtual function + tables. */ + expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_ptr); - last_parm_insn = get_first_nonparm_insn (); - if (last_parm_insn == NULL_RTX) - last_parm_insn = get_last_insn (); - else - last_parm_insn = previous_insn (last_parm_insn); + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + expand_indirect_vtbls_init (binfo, current_class_ref, current_class_ptr); + } + + if (! ok_to_optimize_dtor) + { + cond = build_binary_op (NE_EXPR, + current_class_ptr, integer_zero_node, 1); + expand_start_cond (cond, 0); + } - emit_insns_after (insns, last_parm_insn); + insns = get_insns (); + end_sequence (); - if (! ok_to_optimize_dtor) - expand_end_cond (); - } - else if (current_function_assigns_this) - { - /* Does not need to call emit_base_init, because - that is done (if needed) just after assignment to this - is seen. */ + last_parm_insn = get_first_nonparm_insn (); + if (last_parm_insn == NULL_RTX) + last_parm_insn = get_last_insn (); + else + last_parm_insn = previous_insn (last_parm_insn); - if (DECL_CONSTRUCTOR_P (current_function_decl)) - { - end_protect_partials (); - expand_label (ctor_label); - ctor_label = NULL_TREE; + emit_insns_after (insns, last_parm_insn); - if (call_poplevel) - { - decls = getdecls (); - expand_end_bindings (decls, decls != NULL_TREE, 0); - poplevel (decls != NULL_TREE, 0, 0); - } - c_expand_return (current_class_decl); + if (! ok_to_optimize_dtor) + expand_end_cond (); } - else if (TYPE_MAIN_VARIANT (TREE_TYPE ( - DECL_RESULT (current_function_decl))) != void_type_node - && return_label != NULL_RTX) - no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); + else if (current_function_assigns_this) + { + /* Does not need to call emit_base_init, because + that is done (if needed) just after assignment to this + is seen. */ - current_function_assigns_this = 0; - current_function_just_assigned_this = 0; - base_init_expr = NULL_TREE; - } - else if (DECL_CONSTRUCTOR_P (fndecl)) - { - tree allocated_this; - tree cond, thenclause; - /* Allow constructor for a type to get a new instance of the object - using `build_new'. */ - tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); - CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; + if (DECL_CONSTRUCTOR_P (current_function_decl)) + { + end_protect_partials (); + expand_label (ctor_label); + ctor_label = NULL_TREE; - DECL_RETURNS_FIRST_ARG (fndecl) = 1; + if (call_poplevel) + { + decls = getdecls (); + expand_end_bindings (decls, decls != NULL_TREE, 0); + poplevel (decls != NULL_TREE, 0, 0); + } + /* c_expand_return knows to return 'this' from a constructor. */ + c_expand_return (NULL_TREE); + } + else if (TREE_CODE (TREE_TYPE (DECL_RESULT (current_function_decl))) != VOID_TYPE + && return_label != NULL_RTX) + no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); - if (flag_this_is_variable > 0) - { - cond = build_binary_op (EQ_EXPR, - current_class_decl, integer_zero_node, 1); - thenclause = build_modify_expr (current_class_decl, NOP_EXPR, - build_new (NULL_TREE, current_class_type, void_type_node, 0)); + current_function_assigns_this = 0; + current_function_just_assigned_this = 0; + base_init_expr = NULL_TREE; } + else if (DECL_CONSTRUCTOR_P (fndecl)) + { + tree cond = NULL_TREE, thenclause = NULL_TREE; + /* Allow constructor for a type to get a new instance of the object + using `build_new'. */ + tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); + CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; - CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; + DECL_RETURNS_FIRST_ARG (fndecl) = 1; - start_sequence (); + if (flag_this_is_variable > 0) + { + cond = build_binary_op (EQ_EXPR, + current_class_ptr, integer_zero_node, 1); + thenclause = build_modify_expr (current_class_ptr, NOP_EXPR, + build_new (NULL_TREE, current_class_type, void_type_node, 0)); + } - if (flag_this_is_variable > 0) - { - expand_start_cond (cond, 0); - expand_expr_stmt (thenclause); - expand_end_cond (); - } + CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; -#if 0 - if (DECL_NAME (fndecl) == NULL_TREE - && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE) - build_default_constructor (fndecl); -#endif + start_sequence (); - /* Emit insns from `emit_base_init' which sets up virtual - function table pointer(s). */ - if (base_init_expr) - { - expand_expr_stmt (base_init_expr); - base_init_expr = NULL_TREE; - } + if (flag_this_is_variable > 0) + { + expand_start_cond (cond, 0); + expand_expr_stmt (thenclause); + expand_end_cond (); + } - insns = get_insns (); - end_sequence (); + /* Emit insns from `emit_base_init' which sets up virtual + function table pointer(s). */ + if (base_init_expr) + { + expand_expr_stmt (base_init_expr); + base_init_expr = NULL_TREE; + } - /* This is where the body of the constructor begins. - If there were no insns in this function body, then the - last_parm_insn is also the last insn. + insns = get_insns (); + end_sequence (); - If optimization is enabled, last_parm_insn may move, so - we don't hold on to it (across emit_base_init). */ - last_parm_insn = get_first_nonparm_insn (); - if (last_parm_insn == NULL_RTX) - last_parm_insn = get_last_insn (); - else - last_parm_insn = previous_insn (last_parm_insn); + /* This is where the body of the constructor begins. */ - emit_insns_after (insns, last_parm_insn); + emit_insns_after (insns, last_parm_cleanup_insn); - end_protect_partials (); + end_protect_partials (); - /* This is where the body of the constructor ends. */ - expand_label (ctor_label); - ctor_label = NULL_TREE; + /* This is where the body of the constructor ends. */ + expand_label (ctor_label); + ctor_label = NULL_TREE; - if (call_poplevel) - { - decls = getdecls (); - expand_end_bindings (decls, decls != NULL_TREE, 0); - poplevel (decls != NULL_TREE, 1, 0); - } + if (call_poplevel) + { + decls = getdecls (); + expand_end_bindings (decls, decls != NULL_TREE, 0); + poplevel (decls != NULL_TREE, 1, 0); + } - c_expand_return (current_class_decl); + /* c_expand_return knows to return 'this' from a constructor. */ + c_expand_return (NULL_TREE); - current_function_assigns_this = 0; - current_function_just_assigned_this = 0; - } - else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4 - && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") - && DECL_CONTEXT (fndecl) == NULL_TREE) - { - /* Make it so that `main' always returns 0 by default. */ + current_function_assigns_this = 0; + current_function_just_assigned_this = 0; + } + else if (DECL_MAIN_P (fndecl)) + { + /* Make it so that `main' always returns 0 by default. */ #ifdef VMS - c_expand_return (integer_one_node); + c_expand_return (integer_one_node); #else - c_expand_return (integer_zero_node); + c_expand_return (integer_zero_node); #endif - } - else if (return_label != NULL_RTX - && current_function_return_value == NULL_TREE - && ! DECL_NAME (DECL_RESULT (current_function_decl))) - no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); - - if (flag_gc) - expand_gc_prologue_and_epilogue (); + } + else if (return_label != NULL_RTX + && current_function_return_value == NULL_TREE + && ! DECL_NAME (DECL_RESULT (current_function_decl))) + no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); - /* If this function is supposed to return a value, ensure that - we do not fall into the cleanups by mistake. The end of our - function will look like this: + if (flag_exceptions) + expand_exception_blocks (); - user code (may have return stmt somewhere) - goto no_return_label - cleanup_label: - cleanups - goto return_label - no_return_label: - NOTE_INSN_FUNCTION_END - return_label: - things for return + /* If this function is supposed to return a value, ensure that + we do not fall into the cleanups by mistake. The end of our + function will look like this: + + user code (may have return stmt somewhere) + goto no_return_label + cleanup_label: + cleanups + goto return_label + no_return_label: + NOTE_INSN_FUNCTION_END + return_label: + things for return + + If the user omits a return stmt in the USER CODE section, we + will have a control path which reaches NOTE_INSN_FUNCTION_END. + Otherwise, we won't. */ + if (no_return_label) + { + DECL_CONTEXT (no_return_label) = fndecl; + DECL_INITIAL (no_return_label) = error_mark_node; + DECL_SOURCE_FILE (no_return_label) = input_filename; + DECL_SOURCE_LINE (no_return_label) = lineno; + expand_goto (no_return_label); + } - If the user omits a return stmt in the USER CODE section, we - will have a control path which reaches NOTE_INSN_FUNCTION_END. - Otherwise, we won't. */ - if (no_return_label) - { - DECL_CONTEXT (no_return_label) = fndecl; - DECL_INITIAL (no_return_label) = error_mark_node; - DECL_SOURCE_FILE (no_return_label) = input_filename; - DECL_SOURCE_LINE (no_return_label) = lineno; - expand_goto (no_return_label); - } + if (cleanup_label) + { + /* Remove the binding contour which is used + to catch cleanup-generated temporaries. */ + expand_end_bindings (0, 0, 0); + poplevel (0, 0, 0); - if (cleanup_label) - { - /* remove the binding contour which is used - to catch cleanup-generated temporaries. */ - expand_end_bindings (0, 0, 0); - poplevel (0, 0, 0); - } + /* Emit label at beginning of cleanup code for parameters. */ + emit_label (cleanup_label); + } - if (cleanup_label) - /* Emit label at beginning of cleanup code for parameters. */ - emit_label (cleanup_label); + /* Get return value into register if that's where it's supposed to be. */ + if (original_result_rtx) + fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); - /* Get return value into register if that's where it's supposed to be. */ - if (original_result_rtx) - fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); + /* Finish building code that will trigger warnings if users forget + to make their functions return values. */ + if (no_return_label || cleanup_label) + emit_jump (return_label); + if (no_return_label) + { + /* We don't need to call `expand_*_return' here because we + don't need any cleanups here--this path of code is only + for error checking purposes. */ + expand_label (no_return_label); + } - /* Finish building code that will trigger warnings if users forget - to make their functions return values. */ - if (no_return_label || cleanup_label) - emit_jump (return_label); - if (no_return_label) - { - /* We don't need to call `expand_*_return' here because we - don't need any cleanups here--this path of code is only - for error checking purposes. */ - expand_label (no_return_label); + /* Generate rtl for function exit. */ + expand_function_end (input_filename, lineno, 1); } - /* Generate rtl for function exit. */ - expand_function_end (input_filename, lineno, 1); - - if (flag_handle_exceptions) - expand_exception_blocks (); - /* This must come after expand_function_end because cleanups might have declarations (from inline functions) that need to go into this function's blocks. */ @@ -12147,7 +13015,7 @@ finish_function (lineno, call_poplevel, nested) my_friendly_abort (122); poplevel (1, 0, 1); - /* reset scope for C++: if we were in the scope of a class, + /* Reset scope for C++: if we were in the scope of a class, then when we finish this function, we are not longer so. This cannot be done until we know for sure that no more class members will ever be referenced in this function @@ -12161,79 +13029,115 @@ finish_function (lineno, call_poplevel, nested) pop_memoized_context (1); /* Must mark the RESULT_DECL as being in this function. */ - DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl); - - /* Obey `register' declarations if `setjmp' is called in this fn. */ - if (flag_traditional && current_function_calls_setjmp) - setjmp_protect (DECL_INITIAL (fndecl)); + DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point to the FUNCTION_DECL node itself. */ BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; - /* So we can tell if jump_optimize sets it to 1. */ - can_reach_end = 0; + if (! processing_template_decl) + { + int saved_flag_keep_inline_functions = + flag_keep_inline_functions; - /* Run the optimizers and output the assembler code for this function. */ - rest_of_compilation (fndecl); + /* So we can tell if jump_optimize sets it to 1. */ + can_reach_end = 0; - if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl)) - { - /* Set DECL_EXTERNAL so that assemble_external will be called as - necessary. We'll clear it again in finish_file. */ - if (! DECL_EXTERNAL (fndecl)) - DECL_NOT_REALLY_EXTERN (fndecl) = 1; - DECL_EXTERNAL (fndecl) = 1; - mark_inline_for_output (fndecl); - } + if (DECL_CONTEXT (fndecl) != NULL_TREE + && hack_decl_function_context (fndecl)) + /* Trick rest_of_compilation into not deferring output of this + function, even if it is inline, since the rtl_obstack for + this function is the function_obstack of the enclosing + function and will be deallocated when the enclosing + function is gone. See save_tree_status. */ + flag_keep_inline_functions = 1; + + /* Run the optimizers and output the assembler code for this + function. */ - if (ctype && TREE_ASM_WRITTEN (fndecl)) - note_debug_info_needed (ctype); + if (DECL_ARTIFICIAL (fndecl)) + { + /* Do we really *want* to inline this synthesized method? */ - current_function_returns_null |= can_reach_end; + int save_fif = flag_inline_functions; + flag_inline_functions = 1; - /* Since we don't normally go through c_expand_return for constructors, - this normally gets the wrong value. - Also, named return values have their return codes emitted after - NOTE_INSN_FUNCTION_END, confusing jump.c. */ - if (DECL_CONSTRUCTOR_P (fndecl) - || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) - current_function_returns_null = 0; + /* Turn off DECL_INLINE for the moment so function_cannot_inline_p + will check our size. */ + DECL_INLINE (fndecl) = 0; - if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) - cp_warning ("`noreturn' function `%D' does return", fndecl); - else if ((warn_return_type || pedantic) - && current_function_returns_null - && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node) - { - /* If this function returns non-void and control can drop through, - complain. */ - cp_pedwarn ("control reaches end of non-void function `%D'", fndecl); + rest_of_compilation (fndecl); + flag_inline_functions = save_fif; + } + else + rest_of_compilation (fndecl); + + flag_keep_inline_functions = saved_flag_keep_inline_functions; + + if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl)) + { + /* Set DECL_EXTERNAL so that assemble_external will be called as + necessary. We'll clear it again in finish_file. */ + if (! DECL_EXTERNAL (fndecl)) + DECL_NOT_REALLY_EXTERN (fndecl) = 1; + DECL_EXTERNAL (fndecl) = 1; + mark_inline_for_output (fndecl); + } + + if (ctype && TREE_ASM_WRITTEN (fndecl)) + note_debug_info_needed (ctype); + + current_function_returns_null |= can_reach_end; + + /* Since we don't normally go through c_expand_return for constructors, + this normally gets the wrong value. + Also, named return values have their return codes emitted after + NOTE_INSN_FUNCTION_END, confusing jump.c. */ + if (DECL_CONSTRUCTOR_P (fndecl) + || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) + current_function_returns_null = 0; + + if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) + cp_warning ("`noreturn' function `%D' does return", fndecl); + else if ((warn_return_type || pedantic) + && current_function_returns_null + && TREE_CODE (TREE_TYPE (fntype)) != VOID_TYPE) + { + /* If this function returns non-void and control can drop through, + complain. */ + cp_warning ("control reaches end of non-void function `%D'", fndecl); + } + /* With just -W, complain only if function returns both with + and without a value. */ + else if (extra_warnings + && current_function_returns_value && current_function_returns_null) + warning ("this function may return with or without a value"); } - /* With just -W, complain only if function returns both with - and without a value. */ - else if (extra_warnings - && current_function_returns_value && current_function_returns_null) - warning ("this function may return with or without a value"); + + --function_depth; /* Free all the tree nodes making up this function. */ /* Switch back to allocating nodes permanently until we start another function. */ + if (processing_template_decl) + { + --minimal_parse_mode; + DECL_SAVED_TREE (fndecl) = TREE_CHAIN (DECL_SAVED_TREE (fndecl)); + } + if (! nested) permanent_allocation (1); - if (flag_cadillac) - cadillac_finish_function (fndecl); - if (DECL_SAVED_INSNS (fndecl) == NULL_RTX) { + tree t; + /* Stop pointing to the local nodes about to be freed. */ /* But DECL_INITIAL must remain nonzero so we know this was an actual function definition. */ DECL_INITIAL (fndecl) = error_mark_node; - if (! DECL_CONSTRUCTOR_P (fndecl) - || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype))) - DECL_ARGUMENTS (fndecl) = NULL_TREE; + for (t = DECL_ARGUMENTS (fndecl); t; t = TREE_CHAIN (t)) + DECL_RTL (t) = DECL_INCOMING_RTL (t) = NULL_RTX; } if (DECL_STATIC_CONSTRUCTOR (fndecl)) @@ -12249,8 +13153,9 @@ finish_function (lineno, call_poplevel, nested) current_function_decl = NULL_TREE; } - named_label_uses = NULL_TREE; - current_class_decl = NULL_TREE; + named_label_uses = NULL; + current_class_ptr = NULL_TREE; + current_class_ref = NULL_TREE; } /* Create the FUNCTION_DECL for a function definition. @@ -12275,11 +13180,12 @@ finish_function (lineno, call_poplevel, nested) DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING CHANGES TO CODE IN `grokfield'. */ + tree -start_method (declspecs, declarator, raises) - tree declarator, declspecs, raises; +start_method (declspecs, declarator) + tree declarator, declspecs; { - tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises, + tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, NULL_TREE); /* Something too ugly to handle. */ @@ -12287,7 +13193,7 @@ start_method (declspecs, declarator, raises) return NULL_TREE; /* Pass friends other than inline friend functions back. */ - if (TYPE_MAIN_VARIANT (fndecl) == void_type_node) + if (fndecl == void_type_node) return fndecl; if (TREE_CODE (fndecl) != FUNCTION_DECL) @@ -12295,17 +13201,14 @@ start_method (declspecs, declarator, raises) return NULL_TREE; if (IS_SIGNATURE (current_class_type)) - { - IS_DEFAULT_IMPLEMENTATION (fndecl) = 1; - /* In case we need this info later. */ - HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1; - } + IS_DEFAULT_IMPLEMENTATION (fndecl) = 1; if (DECL_IN_AGGR_P (fndecl)) { if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type) { - if (DECL_CONTEXT (fndecl)) + if (DECL_CONTEXT (fndecl) + && TREE_CODE( DECL_CONTEXT (fndecl)) != NAMESPACE_DECL) cp_error ("`%D' is already defined in class %s", fndecl, TYPE_NAME_STRING (DECL_CONTEXT (fndecl))); } @@ -12317,11 +13220,8 @@ start_method (declspecs, declarator, raises) if (flag_default_inline) DECL_INLINE (fndecl) = 1; - if (processing_template_defn) - { - SET_DECL_IMPLICIT_INSTANTIATION (fndecl); - repo_template_used (fndecl); - } + if (processing_template_decl) + fndecl = push_template_decl (fndecl); /* We read in the parameters on the maybepermanent_obstack, but we won't be getting back to them until after we @@ -12331,14 +13231,6 @@ start_method (declspecs, declarator, raises) if (! DECL_FRIEND_P (fndecl)) { - if (DECL_CHAIN (fndecl) != NULL_TREE) - { - /* Need a fresh node here so that we don't get circularity - when we link these together. If FNDECL was a friend, then - `pushdecl' does the right thing, which is nothing wrt its - current value of DECL_CHAIN. */ - fndecl = copy_node (fndecl); - } if (TREE_CHAIN (fndecl)) { fndecl = copy_node (fndecl); @@ -12385,7 +13277,7 @@ finish_method (decl) register tree link; - if (TYPE_MAIN_VARIANT (decl) == void_type_node) + if (decl == void_type_node) return decl; old_initial = DECL_INITIAL (fndecl); @@ -12418,13 +13310,12 @@ finish_method (decl) IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); for (link = current_binding_level->type_shadowed; link; link = TREE_CHAIN (link)) - IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link); + SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link)); GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, (HOST_WIDE_INT) current_binding_level->level_chain, current_binding_level->parm_flag, - current_binding_level->keep, - current_binding_level->tag_transparent); + current_binding_level->keep); poplevel (0, 0, 0); @@ -12462,7 +13353,7 @@ hack_incomplete_structures (type) for (list = ¤t_binding_level->incomplete; *list; ) { tree decl = TREE_VALUE (*list); - if (decl && TREE_TYPE (decl) == type + if ((decl && TREE_TYPE (decl) == type) || (TREE_TYPE (decl) && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE && TREE_TYPE (TREE_TYPE (decl)) == type)) @@ -12479,7 +13370,7 @@ hack_incomplete_structures (type) expand_decl (decl); cleanup = maybe_build_cleanup (decl); expand_decl_init (decl); - if (! cp_expand_decl_cleanup (decl, cleanup)) + if (! expand_decl_cleanup (decl, cleanup)) cp_error ("parser lost in parsing declaration of `%D'", decl); } @@ -12490,32 +13381,21 @@ hack_incomplete_structures (type) } } -/* Nonzero if presently building a cleanup. Needed because - SAVE_EXPRs are not the right things to use inside of cleanups. - They are only ever evaluated once, where the cleanup - might be evaluated several times. In this case, a later evaluation - of the cleanup might fill in the SAVE_EXPR_RTL, and it will - not be valid for an earlier cleanup. */ - -int building_cleanup; - /* If DECL is of a type which needs a cleanup, build that cleanup here. - We don't build cleanups if just going for syntax checking, since - fixup_cleanups does not know how to not handle them. + See build_delete for information about AUTO_DELETE. Don't build these on the momentary obstack; they must live the life of the binding contour. */ -tree -maybe_build_cleanup (decl) - tree decl; + +static tree +maybe_build_cleanup_1 (decl, auto_delete) + tree decl, auto_delete; { tree type = TREE_TYPE (decl); if (TYPE_NEEDS_DESTRUCTOR (type)) { int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; tree rval; - int old_building_cleanup = building_cleanup; - building_cleanup = 1; if (TREE_CODE (decl) != PARM_DECL) temp = suspend_momentary (); @@ -12533,22 +13413,40 @@ maybe_build_cleanup (decl) || flag_expensive_optimizations) flags |= LOOKUP_NONVIRTUAL; - rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0); + rval = build_delete (TREE_TYPE (rval), rval, auto_delete, flags, 0); if (TYPE_USES_VIRTUAL_BASECLASSES (type) && ! TYPE_HAS_DESTRUCTOR (type)) - rval = build_compound_expr (tree_cons (NULL_TREE, rval, - build_tree_list (NULL_TREE, build_vbase_delete (type, decl)))); + rval = build_compound_expr (expr_tree_cons (NULL_TREE, rval, + build_expr_list (NULL_TREE, build_vbase_delete (type, decl)))); if (TREE_CODE (decl) != PARM_DECL) resume_momentary (temp); - building_cleanup = old_building_cleanup; - return rval; } return 0; } + +/* If DECL is of a type which needs a cleanup, build that cleanup + here. The cleanup does free the storage with a call to delete. */ + +tree +maybe_build_cleanup_and_delete (decl) + tree decl; +{ + return maybe_build_cleanup_1 (decl, integer_three_node); +} + +/* If DECL is of a type which needs a cleanup, build that cleanup + here. The cleanup does not free the storage with a call a delete. */ + +tree +maybe_build_cleanup (decl) + tree decl; +{ + return maybe_build_cleanup_1 (decl, integer_two_node); +} /* Expand a C++ expression at the statement level. This is needed to ferret out nodes which have UNKNOWN_TYPE. @@ -12556,13 +13454,21 @@ maybe_build_cleanup (decl) expressions are combined with other, type-providing, expressions, leaving only orphan expressions, such as: - &class::bar; / / takes its address, but does nothing with it. + &class::bar; / / takes its address, but does nothing with it. */ - */ void cplus_expand_expr_stmt (exp) tree exp; { + if (processing_template_decl) + { + add_tree (build_min_nt (EXPR_STMT, exp)); + return; + } + + /* Arrange for all temps to disappear. */ + expand_start_target_temps (); + if (TREE_TYPE (exp) == unknown_type_node) { if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST) @@ -12572,8 +13478,6 @@ cplus_expand_expr_stmt (exp) } else { - int remove_implicit_immediately = 0; - if (TREE_CODE (exp) == FUNCTION_DECL) { cp_warning ("reference, not call, to function `%D'", exp); @@ -12585,12 +13489,22 @@ cplus_expand_expr_stmt (exp) libg++ to miscompile, and tString to core dump. */ exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp); #endif - expand_expr_stmt (break_out_cleanups (exp)); + + /* Strip unused implicit INDIRECT_REFs of references. */ + if (TREE_CODE (exp) == INDIRECT_REF + && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE) + exp = TREE_OPERAND (exp, 0); + + /* If we don't do this, we end up down inside expand_expr + trying to do TYPE_MODE on the ERROR_MARK, and really + go outside the bounds of the type. */ + if (exp != error_mark_node) + expand_expr_stmt (break_out_cleanups (exp)); } /* Clean up any pending cleanups. This happens when a function call returns a cleanup-needing value that nobody uses. */ - expand_cleanups_to (NULL_TREE); + expand_end_target_temps (); } /* When a stmt has been parsed, this function is called. @@ -12618,9 +13532,6 @@ finish_stmt () check_base_init (current_class_type); } current_function_assigns_this = 1; - - if (flag_cadillac) - cadillac_finish_stmt (); } /* Change a static member function definition into a FUNCTION_TYPE, instead @@ -12679,18 +13590,20 @@ struct cp_function tree shadowed_labels; tree ctor_label; tree dtor_label; - tree protect_list; + rtx last_dtor_insn; + rtx last_parm_cleanup_insn; tree base_init_list; tree member_init_list; tree base_init_expr; - tree class_decl; - tree C_C_D; + tree current_class_ptr; + tree current_class_ref; rtx result_rtx; struct cp_function *next; struct binding_level *binding_level; + int static_labelno; }; -struct cp_function *cp_function_chain; +static struct cp_function *cp_function_chain; extern int temp_name_counter; @@ -12717,17 +13630,19 @@ push_cp_function_context (context) p->binding_level = current_binding_level; p->ctor_label = ctor_label; p->dtor_label = dtor_label; + p->last_dtor_insn = last_dtor_insn; + p->last_parm_cleanup_insn = last_parm_cleanup_insn; p->assigns_this = current_function_assigns_this; p->just_assigned_this = current_function_just_assigned_this; p->parms_stored = current_function_parms_stored; p->result_rtx = original_result_rtx; p->base_init_expr = base_init_expr; - p->protect_list = protect_list; p->temp_name_counter = temp_name_counter; p->base_init_list = current_base_init_list; p->member_init_list = current_member_init_list; - p->class_decl = current_class_decl; - p->C_C_D = C_C_D; + p->current_class_ptr = current_class_ptr; + p->current_class_ref = current_class_ref; + p->static_labelno = static_labelno; } /* Restore the variables used during compilation of a C++ function. */ @@ -12745,17 +13660,6 @@ pop_cp_function_context (context) SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link)); -#if 0 - if (DECL_SAVED_INSNS (current_function_decl) == 0) - { - /* Stop pointing to the local nodes about to be freed. */ - /* But DECL_INITIAL must remain nonzero so we know this - was an actual function definition. */ - DECL_INITIAL (current_function_decl) = error_mark_node; - DECL_ARGUMENTS (current_function_decl) = 0; - } -#endif - pop_function_context_from (context); cp_function_chain = p->next; @@ -12768,7 +13672,8 @@ pop_cp_function_context (context) current_binding_level = p->binding_level; ctor_label = p->ctor_label; dtor_label = p->dtor_label; - protect_list = p->protect_list; + last_dtor_insn = p->last_dtor_insn; + last_parm_cleanup_insn = p->last_parm_cleanup_insn; current_function_assigns_this = p->assigns_this; current_function_just_assigned_this = p->just_assigned_this; current_function_parms_stored = p->parms_stored; @@ -12777,102 +13682,15 @@ pop_cp_function_context (context) temp_name_counter = p->temp_name_counter; current_base_init_list = p->base_init_list; current_member_init_list = p->member_init_list; - current_class_decl = p->class_decl; - C_C_D = p->C_C_D; + current_class_ptr = p->current_class_ptr; + current_class_ref = p->current_class_ref; + static_labelno = p->static_labelno; free (p); } -/* FSF LOCAL dje prefix attributes */ -/* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two - lists. SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE). - - The head of the declspec list is stored in DECLSPECS. - The head of the attribute list is stored in PREFIX_ATTRIBUTES. - - Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of - the list elements. We drop the containing TREE_LIST nodes and link the - resulting attributes together the way decl_attributes expects them. */ - -void -split_specs_attrs (specs_attrs, declspecs, prefix_attributes) - tree specs_attrs; - tree *declspecs, *prefix_attributes; -{ - tree t, s, a, next, specs, attrs; - - /* This can happen in c++ (eg: decl: typespec initdecls ';'). */ - if (specs_attrs != NULL_TREE - && TREE_CODE (specs_attrs) != TREE_LIST) - { - *declspecs = specs_attrs; - *prefix_attributes = NULL_TREE; - return; - } - - /* Remember to keep the lists in the same order, element-wise. */ - - specs = s = NULL_TREE; - attrs = a = NULL_TREE; - for (t = specs_attrs; t; t = next) - { - next = TREE_CHAIN (t); - /* Declspecs have a non-NULL TREE_VALUE. */ - if (TREE_VALUE (t) != NULL_TREE) - { - if (specs == NULL_TREE) - specs = s = t; - else - { - TREE_CHAIN (s) = t; - s = t; - } - } - else - { - if (attrs == NULL_TREE) - attrs = a = TREE_PURPOSE (t); - else - { - TREE_CHAIN (a) = TREE_PURPOSE (t); - a = TREE_PURPOSE (t); - } - } - } - - /* Terminate the lists. */ - if (s != NULL_TREE) - TREE_CHAIN (s) = NULL_TREE; - if (a != NULL_TREE) - TREE_CHAIN (a) = NULL_TREE; - - /* All done. */ - *declspecs = specs; - *prefix_attributes = attrs; -} - -/* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes. - This function is used by the parser when a rule will accept attributes - in a particular position, but we don't want to support that just yet. - - A warning is issued for every ignored attribute. */ - -tree -strip_attrs (specs_attrs) - tree specs_attrs; +int +in_function_p () { - tree specs, attrs; - - split_specs_attrs (specs_attrs, &specs, &attrs); - - while (attrs) - { - warning ("`%s' attribute ignored", - IDENTIFIER_POINTER (TREE_PURPOSE (attrs))); - attrs = TREE_CHAIN (attrs); - } - - return specs; + return function_depth != 0; } -/* END FSF LOCAL */ - diff --git a/contrib/gcc/cp/ptree.c b/contrib/gcc/cp/ptree.c index 4524422..6cbd08a 100644 --- a/contrib/gcc/cp/ptree.c +++ b/contrib/gcc/cp/ptree.c @@ -19,10 +19,12 @@ along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* $FreeBSD$ */ + #include "config.h" +#include "system.h" #include "tree.h" -#include <stdio.h> #include "cp-tree.h" void @@ -66,16 +68,16 @@ print_lang_type (file, node, indent) register tree node; int indent; { - if (TREE_CODE (node) == TEMPLATE_TYPE_PARM) - { - print_node (file, "tinfo", TYPE_VALUES (node), indent + 4); - return; - } - - if (TREE_CODE (node) == UNINSTANTIATED_P_TYPE) + if (TREE_CODE (node) == TEMPLATE_TYPE_PARM + || TREE_CODE (node) == TEMPLATE_TEMPLATE_PARM) { - print_node (file, "template", UPT_TEMPLATE (node), indent + 4); - print_node (file, "parameters", UPT_PARMS (node), indent + 4); + indent_to (file, indent + 3); + fputs ("index ", file); + fprintf (file, HOST_WIDE_INT_PRINT_DEC, TEMPLATE_TYPE_IDX (node)); + fputs (" level ", file); + fprintf (file, HOST_WIDE_INT_PRINT_DEC, TEMPLATE_TYPE_LEVEL (node)); + fputs (" orig_level ", file); + fprintf (file, HOST_WIDE_INT_PRINT_DEC, TEMPLATE_TYPE_ORIG_LEVEL (node)); return; } @@ -98,10 +100,6 @@ print_lang_type (file, node, indent) fputs (" X()", file); if (TYPE_HAS_CONVERSION (node)) fputs (" has-type-conversion", file); - if (TYPE_HAS_INT_CONVERSION (node)) - fputs (" has-int-conversion", file); - if (TYPE_HAS_REAL_CONVERSION (node)) - fputs (" has-float-conversion", file); if (TYPE_HAS_INIT_REF (node)) { if (TYPE_HAS_CONST_INIT_REF (node)) @@ -121,10 +119,6 @@ print_lang_type (file, node, indent) fputs (" has=", file); if (TYPE_HAS_ASSIGN_REF (node)) fputs (" this=(X&)", file); - if (TYPE_OVERLOADS_METHOD_CALL_EXPR (node)) - fputs (" op->()", file); - if (TYPE_GETS_INIT_AGGR (node)) - fputs (" gets X(X, ...)", file); if (TYPE_OVERLOADS_CALL_EXPR (node)) fputs (" op()", file); if (TYPE_OVERLOADS_ARRAY_REF (node)) @@ -158,7 +152,7 @@ print_lang_identifier (file, node, indent) tree node; int indent; { - print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4); + print_node (file, "bindings", IDENTIFIER_NAMESPACE_BINDINGS (node), indent + 4); print_node (file, "class", IDENTIFIER_CLASS_VALUE (node), indent + 4); print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4); print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4); @@ -166,3 +160,34 @@ print_lang_identifier (file, node, indent) print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4); print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4); } + +void +lang_print_xnode (file, node, indent) + FILE *file; + tree node; + int indent; +{ + switch (TREE_CODE (node)) + { + case CPLUS_BINDING: + print_node (file, "scope", BINDING_SCOPE (node), indent+4); + print_node (file, "value", BINDING_VALUE (node), indent+4); + print_node (file, "chain", TREE_CHAIN (node), indent+4); + break; + case OVERLOAD: + print_node (file, "function", OVL_FUNCTION (node), indent+4); + print_node (file, "chain", TREE_CHAIN (node), indent+4); + break; + case TEMPLATE_PARM_INDEX: + indent_to (file, indent + 3); + fputs ("index ", file); + fprintf (file, HOST_WIDE_INT_PRINT_DEC, TEMPLATE_PARM_IDX (node)); + fputs (" level ", file); + fprintf (file, HOST_WIDE_INT_PRINT_DEC, TEMPLATE_PARM_LEVEL (node)); + fputs (" orig_level ", file); + fprintf (file, HOST_WIDE_INT_PRINT_DEC, TEMPLATE_PARM_ORIG_LEVEL (node)); + break; + default: + break; + } +} |