@@ -222,6 +222,7 @@ struct GTY(()) lang_identifier {
cxx_binding *bindings;
tree class_template_info;
tree label_value;
+ tree local_class_scope_type;
};
/* In an IDENTIFIER_NODE, nonzero if this identifier is actually a
@@ -448,13 +449,15 @@ typedef enum impl_conv_void {
#define IDENTIFIER_BINDING(NODE) \
(LANG_IDENTIFIER_CAST (NODE)->bindings)
-/* TREE_TYPE only indicates on local and class scope the current
- type. For namespace scope, the presence of a type in any namespace
- is indicated with global_type_node, and the real type behind must
- be found through lookup. */
+/* For namespace scope, the presence of a type in any namespace is
+ indicated with global_type_node, and the real type behind must be
+ found through lookup. For local and class scope, we can grab the
+ type from the identifier directly. */
#define IDENTIFIER_TYPE_VALUE(NODE) identifier_type_value (NODE)
-#define REAL_IDENTIFIER_TYPE_VALUE(NODE) TREE_TYPE (NODE)
-#define SET_IDENTIFIER_TYPE_VALUE(NODE,TYPE) (TREE_TYPE (NODE) = (TYPE))
+#define REAL_IDENTIFIER_TYPE_VALUE(NODE) \
+ (LANG_IDENTIFIER_CAST (NODE)->local_class_scope_type)
+#define SET_IDENTIFIER_TYPE_VALUE(NODE,TYPE) \
+ (REAL_IDENTIFIER_TYPE_VALUE (NODE) = (TYPE))
#define IDENTIFIER_HAS_TYPE_VALUE(NODE) (IDENTIFIER_TYPE_VALUE (NODE) ? 1 : 0)
#define IDENTIFIER_LABEL_VALUE(NODE) \
@@ -1104,7 +1107,10 @@ struct GTY(()) language_function {
#define error_operand_p(NODE) \
((NODE) == error_mark_node \
- || ((NODE) && TREE_TYPE ((NODE)) == error_mark_node))
+ || ((NODE) \
+ && ((TREE_CODE (NODE) == IDENTIFIER_NODE \
+ ? REAL_IDENTIFIER_TYPE_VALUE (NODE) \
+ : TREE_TYPE (NODE)) == error_mark_node)))
/* TRUE if a tree code represents a statement. */
extern bool statement_code_p[MAX_TREE_CODES];
@@ -2121,8 +2127,10 @@ struct GTY((variable_size)) lang_decl {
/* If FN is a conversion operator, the type to which it converts.
Otherwise, NULL_TREE. */
-#define DECL_CONV_FN_TYPE(FN) \
- (DECL_CONV_FN_P (FN) ? TREE_TYPE (DECL_NAME (FN)) : NULL_TREE)
+#define DECL_CONV_FN_TYPE(FN) \
+ (DECL_CONV_FN_P (FN) \
+ ? REAL_IDENTIFIER_TYPE_VALUE (DECL_NAME (FN)) \
+ : NULL_TREE)
/* Nonzero if NODE, which is a TEMPLATE_DECL, is a template
conversion operator to a type dependent on the innermost template
@@ -5897,7 +5897,8 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
if (type != error_mark_node
&& MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
{
- if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
+ if (REAL_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl))
+ && TREE_TYPE (decl) != type)
warning (0, "shadowing previous type declaration of %q#D", decl);
set_identifier_type_value (DECL_NAME (decl), decl);
}
@@ -7501,7 +7502,10 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
if (error_operand_p (size))
return error_mark_node;
- type = TREE_TYPE (size);
+ type = (TREE_CODE (size) == IDENTIFIER_NODE
+ ? REAL_IDENTIFIER_TYPE_VALUE (size)
+ : TREE_TYPE (size));
+
/* type_dependent_expression_p? */
if (!dependent_type_p (type))
{
@@ -8124,7 +8128,7 @@ grokdeclarator (const cp_declarator *declarator,
{
gcc_assert (flags == NO_SPECIAL);
flags = TYPENAME_FLAG;
- ctor_return_type = TREE_TYPE (dname);
+ ctor_return_type = REAL_IDENTIFIER_TYPE_VALUE (dname);
sfk = sfk_conversion;
if (is_typename_at_global_scope (dname))
name = identifier_to_locale (IDENTIFIER_POINTER (dname));
@@ -10707,7 +10711,7 @@ grok_op_properties (tree decl, bool complain)
warn again about out-of-class definitions. */
&& class_type == current_class_type)
{
- tree t = TREE_TYPE (name);
+ tree t = REAL_IDENTIFIER_TYPE_VALUE (name);
int ref = (TREE_CODE (t) == REFERENCE_TYPE);
if (ref)
@@ -1964,7 +1964,10 @@ constrain_visibility_for_template (tree decl, tree targs)
tree arg = TREE_VEC_ELT (args, i-1);
if (TYPE_P (arg))
vis = type_visibility (arg);
- else if (TREE_TYPE (arg) && POINTER_TYPE_P (TREE_TYPE (arg)))
+ else if (TREE_CODE (arg) == IDENTIFIER_NODE
+ ? (REAL_IDENTIFIER_TYPE_VALUE (arg)
+ && POINTER_TYPE_P (REAL_IDENTIFIER_TYPE_VALUE (arg)))
+ : (TREE_TYPE (arg) && POINTER_TYPE_P (TREE_TYPE (arg))))
{
STRIP_NOPS (arg);
if (TREE_CODE (arg) == ADDR_EXPR)
@@ -2072,7 +2075,7 @@ determine_visibility (tree decl)
{
/* Under -fvisibility-ms-compat, types are visible by default,
even though their contents aren't. */
- tree underlying_type = TREE_TYPE (DECL_NAME (decl));
+ tree underlying_type = REAL_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl));
int underlying_vis = type_visibility (underlying_type);
if (underlying_vis == VISIBILITY_ANON
|| (CLASS_TYPE_P (underlying_type)
@@ -2083,16 +2086,17 @@ determine_visibility (tree decl)
}
else if (TREE_CODE (decl) == VAR_DECL && DECL_TINFO_P (decl))
{
+ tree id_type = REAL_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl));
+
/* tinfo visibility is based on the type it's for. */
- constrain_visibility
- (decl, type_visibility (TREE_TYPE (DECL_NAME (decl))));
+ constrain_visibility (decl, type_visibility (id_type));
/* Give the target a chance to override the visibility associated
with DECL. */
if (TREE_PUBLIC (decl)
&& !DECL_REALLY_EXTERN (decl)
- && CLASS_TYPE_P (TREE_TYPE (DECL_NAME (decl)))
- && !CLASSTYPE_VISIBILITY_SPECIFIED (TREE_TYPE (DECL_NAME (decl))))
+ && CLASS_TYPE_P (id_type)
+ && !CLASSTYPE_VISIBILITY_SPECIFIED (id_type))
targetm.cxx.determine_class_data_visibility (decl);
}
else if (use_template)
@@ -2449,7 +2453,7 @@ import_export_decl (tree decl)
}
else if (TREE_CODE (decl) == VAR_DECL && DECL_TINFO_P (decl))
{
- tree type = TREE_TYPE (DECL_NAME (decl));
+ tree type = REAL_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl));
if (CLASS_TYPE_P (type))
{
class_type = type;
@@ -1011,7 +1011,7 @@ dump_decl (tree t, int flags)
{
pp_cxx_ws_string (cxx_pp, "operator");
/* Not exactly IDENTIFIER_TYPE_VALUE. */
- dump_type (TREE_TYPE (t), flags);
+ dump_type (REAL_IDENTIFIER_TYPE_VALUE (t), flags);
break;
}
else
@@ -1094,16 +1094,20 @@ write_template_prefix (const tree node)
if (find_substitution (substitution))
return;
+ type = (TREE_CODE (templ) == IDENTIFIER_NODE
+ ? REAL_IDENTIFIER_TYPE_VALUE (templ)
+ : TREE_TYPE (templ));
+
/* In G++ 3.2, the name of the template template parameter was used. */
- if (TREE_TYPE (templ)
- && TREE_CODE (TREE_TYPE (templ)) == TEMPLATE_TEMPLATE_PARM
+ if (type
+ && TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM
&& !abi_version_at_least (2))
G.need_abi_warning = true;
- if (TREE_TYPE (templ)
- && TREE_CODE (TREE_TYPE (templ)) == TEMPLATE_TEMPLATE_PARM
+ if (type
+ && TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM
&& abi_version_at_least (2))
- write_template_param (TREE_TYPE (templ));
+ write_template_param (type);
else
{
write_prefix (context);
@@ -1128,7 +1132,7 @@ static void
write_unqualified_id (tree identifier)
{
if (IDENTIFIER_TYPENAME_P (identifier))
- write_conversion_operator_name (TREE_TYPE (identifier));
+ write_conversion_operator_name (REAL_IDENTIFIER_TYPE_VALUE (identifier));
else if (IDENTIFIER_OPNAME_P (identifier))
{
int i;
@@ -3321,7 +3325,8 @@ static GTY ((param_is (union tree_node))) htab_t conv_type_names;
static hashval_t
hash_type (const void *val)
{
- return (hashval_t) TYPE_UID (TREE_TYPE ((const_tree) val));
+ tree t = CONST_CAST_TREE ((const_tree) val);
+ return (hashval_t) TYPE_UID (REAL_IDENTIFIER_TYPE_VALUE (t));
}
/* Compare VAL1 (a node in the table) with VAL2 (a TYPE). */
@@ -3329,7 +3334,8 @@ hash_type (const void *val)
static int
compare_type (const void *val1, const void *val2)
{
- return TREE_TYPE ((const_tree) val1) == (const_tree) val2;
+ return (REAL_IDENTIFIER_TYPE_VALUE (CONST_CAST_TREE ((const_tree) val1))
+ == CONST_CAST_TREE ((const_tree) val2));
}
/* Return an identifier for the mangled unqualified name for a
@@ -3363,7 +3369,7 @@ mangle_conv_op_name_for_type (const tree type)
/* Hang TYPE off the identifier so it can be found easily later
when performing conversions. */
- TREE_TYPE (identifier) = type;
+ REAL_IDENTIFIER_TYPE_VALUE (identifier) = type;
/* Set bits on the identifier so we know later it's a conversion. */
IDENTIFIER_OPNAME_P (identifier) = 1;
@@ -3001,7 +3001,7 @@ do_class_using_decl (tree scope, tree name)
scope_dependent_p = dependent_type_p (scope);
name_dependent_p = (scope_dependent_p
|| (IDENTIFIER_TYPENAME_P (name)
- && dependent_type_p (TREE_TYPE (name))));
+ && dependent_type_p (REAL_IDENTIFIER_TYPE_VALUE (name))));
bases_dependent_p = false;
if (processing_template_decl)
@@ -3040,8 +3040,8 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data)
return NULL_TREE;
case IDENTIFIER_NODE:
- cp_walk_tree (&TREE_TYPE (t), &find_parameter_packs_r, ppd,
- ppd->visited);
+ cp_walk_tree (&REAL_IDENTIFIER_TYPE_VALUE (t), &find_parameter_packs_r,
+ ppd, ppd->visited);
*walk_subtrees = 0;
return NULL_TREE;
@@ -6600,7 +6600,9 @@ lookup_template_function (tree fns, tree arglist)
return fns;
}
- type = TREE_TYPE (fns);
+ type = (TREE_CODE (fns) == IDENTIFIER_NODE
+ ? REAL_IDENTIFIER_TYPE_VALUE (fns)
+ : TREE_TYPE (fns));
if (TREE_CODE (fns) == OVERLOAD || !type)
type = unknown_type_node;
@@ -11246,6 +11248,21 @@ tsubst_qualified_id (tree qualified_id, tree args,
return expr;
}
+/* tsubst for IDENTIFIER_NODEs. */
+
+static tree
+tsubst_identifier (tree t, tree args, tsubst_flags_t complain, tree in_decl)
+{
+ if (IDENTIFIER_TYPENAME_P (t))
+ {
+ tree new_type = tsubst (REAL_IDENTIFIER_TYPE_VALUE (t),
+ args, complain, in_decl);
+ return mangle_conv_op_name_for_type (new_type);
+ }
+ else
+ return t;
+}
+
/* Like tsubst, but deals with expressions. This function just replaces
template parms; to finish processing the resultant expression, use
tsubst_expr. */
@@ -11660,13 +11677,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
return tsubst (t, args, complain, in_decl);
case IDENTIFIER_NODE:
- if (IDENTIFIER_TYPENAME_P (t))
- {
- tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
- return mangle_conv_op_name_for_type (new_type);
- }
- else
- return t;
+ return tsubst_identifier (t, args, complain, in_decl);
case CONSTRUCTOR:
/* This is handled by tsubst_copy_and_build. */
@@ -12477,11 +12488,7 @@ tsubst_copy_and_build (tree t,
bool non_integral_constant_expression_p;
const char *error_msg;
- if (IDENTIFIER_TYPENAME_P (t))
- {
- tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
- t = mangle_conv_op_name_for_type (new_type);
- }
+ t = tsubst_identifier (t, args, complain, in_decl);
/* Look up the name. */
decl = lookup_name (t);
@@ -18500,6 +18507,9 @@ any_template_arguments_need_structural_equality_p (tree args)
continue;
else if (TYPE_P (arg) && TYPE_STRUCTURAL_EQUALITY_P (arg))
return true;
+ else if (TREE_CODE (arg) == IDENTIFIER_NODE)
+ return (REAL_IDENTIFIER_TYPE_VALUE (arg)
+ && TYPE_STRUCTURAL_EQUALITY_P (REAL_IDENTIFIER_TYPE_VALUE (arg)));
else if (!TYPE_P (arg) && TREE_TYPE (arg)
&& TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (arg)))
return true;
@@ -309,7 +309,7 @@ repo_emit_p (tree decl)
if (DECL_VTABLE_OR_VTT_P (decl))
type = DECL_CONTEXT (decl);
else if (DECL_TINFO_P (decl))
- type = TREE_TYPE (DECL_NAME (decl));
+ type = REAL_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl));
if (!DECL_TEMPLATE_INSTANTIATION (decl)
&& (!TYPE_LANG_SPECIFIC (type)
|| !CLASSTYPE_TEMPLATE_INSTANTIATION (type)))
@@ -426,7 +426,7 @@ get_tinfo_decl (tree type)
d = build_lang_decl (VAR_DECL, name, ti->type);
SET_DECL_ASSEMBLER_NAME (d, name);
/* Remember the type it is for. */
- TREE_TYPE (name) = type;
+ REAL_IDENTIFIER_TYPE_VALUE (name) = type;
DECL_TINFO_P (d) = 1;
DECL_ARTIFICIAL (d) = 1;
DECL_IGNORED_P (d) = 1;
@@ -876,7 +876,7 @@ tinfo_base_init (tinfo_s *ti, tree target)
/* Determine the name of the variable -- and remember with which
type it is associated. */
name_name = mangle_typeinfo_string_for_type (target);
- TREE_TYPE (name_name) = target;
+ REAL_IDENTIFIER_TYPE_VALUE (name_name) = target;
name_decl = build_lang_decl (VAR_DECL, name_name, name_type);
SET_DECL_ASSEMBLER_NAME (name_decl, name_name);
@@ -1538,7 +1538,7 @@ emit_support_tinfos (void)
bool
emit_tinfo_decl (tree decl)
{
- tree type = TREE_TYPE (DECL_NAME (decl));
+ tree type = REAL_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl));
int in_library = typeinfo_in_lib_p (type);
gcc_assert (DECL_TINFO_P (decl));
@@ -1259,7 +1259,7 @@ lookup_member (tree xbasetype, tree name, int protect, bool want_type)
if (rval && is_overloaded_fn (rval))
rval = build_baselink (rval_binfo, basetype_path, rval,
(IDENTIFIER_TYPENAME_P (name)
- ? TREE_TYPE (name): NULL_TREE));
+ ? REAL_IDENTIFIER_TYPE_VALUE (name): NULL_TREE));
return rval;
}
@@ -1397,7 +1397,7 @@ lookup_fnfields_1 (tree type, tree name)
return fn ? CLASSTYPE_DESTRUCTOR_SLOT : -1;
}
if (IDENTIFIER_TYPENAME_P (name))
- return lookup_conversion_operator (type, TREE_TYPE (name));
+ return lookup_conversion_operator (type, REAL_IDENTIFIER_TYPE_VALUE (name));
/* Skip the conversion operators. */
for (i = CLASSTYPE_FIRST_CONVERSION_SLOT;
@@ -2825,7 +2825,7 @@ finish_id_expression (tree id_expression,
|| (!dependent_type_p (scope)
&& !(TREE_CODE (id_expression) == IDENTIFIER_NODE
&& IDENTIFIER_TYPENAME_P (id_expression)
- && dependent_type_p (TREE_TYPE (id_expression))))))
+ && dependent_type_p (REAL_IDENTIFIER_TYPE_VALUE (id_expression))))))
{
/* If the qualifying type is non-dependent (and the name
does not name a conversion operator to a dependent
@@ -3029,7 +3029,9 @@ finish_id_expression (tree id_expression,
type. */
else if (!is_overloaded_fn (decl))
dependent_p
- = dependent_type_p (TREE_TYPE (decl));
+ = dependent_type_p (TREE_CODE (decl) == IDENTIFIER_NODE
+ ? REAL_IDENTIFIER_TYPE_VALUE (decl)
+ : TREE_TYPE (decl));
/* For a set of overloaded functions, check each of the
functions. */
else
@@ -2452,7 +2452,9 @@ finish_class_member_access_expr (tree object, tree name, bool template_p,
if (!objc_is_public (object, name))
return error_mark_node;
- object_type = TREE_TYPE (object);
+ object_type = (TREE_CODE (object) == IDENTIFIER_NODE
+ ? REAL_IDENTIFIER_TYPE_VALUE (object)
+ : TREE_TYPE (object));
if (processing_template_decl)
{