Commit fdedded1 by Devang Patel Committed by Devang Patel

decl.c (finish_enum): Merge two 'for' loops.

        * decl.c (finish_enum): Merge two 'for' loops. Copy value node if required.
        Postpone enum setting for template decls.
        (build_enumerator): Delay copying value node until finish_enum (). Remove
        #if 0'ed code.
        * pt.c (tsubst_enum): Set TREE_TYPE and copy value node.
        (tsubst_copy): Add check for enum type.

From-SVN: r63487
parent eeec05e1
2003-02-26 Devang Patel <dpatel@apple.com>
* decl.c (finish_enum): Merge two 'for' loops. Copy value node if required.
Postpone enum setting for template decls.
(build_enumerator): Delay copying value node until finish_enum (). Remove
#if 0'ed code.
* pt.c (tsubst_enum): Set TREE_TYPE and copy value node.
(tsubst_copy): Add check for enum type.
2003-02-25 Mark Mitchell <mark@codesourcery.com> 2003-02-25 Mark Mitchell <mark@codesourcery.com>
PR c++/9683 PR c++/9683
......
...@@ -13062,15 +13062,6 @@ finish_enum (tree enumtype) ...@@ -13062,15 +13062,6 @@ finish_enum (tree enumtype)
/* We built up the VALUES in reverse order. */ /* We built up the VALUES in reverse order. */
TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype)); TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
/* [dcl.enum]
Following the closing brace of an enum-specifier, each
enumerator has the type of its enumeration. Prior to the
closing brace, the type of each enumerator is the type of
its initializing value. */
for (pair = TYPE_VALUES (enumtype); pair; pair = TREE_CHAIN (pair))
TREE_TYPE (TREE_VALUE (pair)) = enumtype;
/* For an enum defined in a template, all further processing is /* For an enum defined in a template, all further processing is
postponed until the template is instantiated. */ postponed until the template is instantiated. */
if (processing_template_decl) if (processing_template_decl)
...@@ -13080,31 +13071,51 @@ finish_enum (tree enumtype) ...@@ -13080,31 +13071,51 @@ finish_enum (tree enumtype)
return; return;
} }
/* Figure out what the minimum and maximum values of the enumerators
are. */
if (TYPE_VALUES (enumtype)) if (TYPE_VALUES (enumtype))
{ {
/* Initialize min and max values and figure out actual values in
following 'for' loop. */
minnode = maxnode = NULL_TREE; minnode = maxnode = NULL_TREE;
for (pair = TYPE_VALUES (enumtype); /* [dcl.enum]
pair;
pair = TREE_CHAIN (pair)) Following the closing brace of an enum-specifier, each
enumerator has the type of its enumeration. Prior to the
closing brace, the type of each enumerator is the type of
its initializing value. */
for (pair = TYPE_VALUES (enumtype); pair; pair = TREE_CHAIN (pair))
{ {
tree value; tree value;
value = DECL_INITIAL (TREE_VALUE (pair)); /* If we are going to reset type then copy node first.
It cannot be shared now. */
if (TREE_TYPE (TREE_VALUE (pair)) != enumtype)
{
if (DECL_INITIAL (TREE_VALUE (pair)))
DECL_INITIAL (TREE_VALUE (pair)) =
copy_node (DECL_INITIAL (TREE_VALUE (pair)));
TREE_TYPE (TREE_VALUE (pair)) = enumtype;
}
if (!minnode) if (!processing_template_decl)
minnode = maxnode = value; {
else if (tree_int_cst_lt (maxnode, value)) /* Adjust min and max value. */
maxnode = value; value = DECL_INITIAL (TREE_VALUE (pair));
else if (tree_int_cst_lt (value, minnode))
minnode = value; if (!minnode)
minnode = maxnode = value;
else if (tree_int_cst_lt (maxnode, value))
maxnode = value;
else if (tree_int_cst_lt (value, minnode))
minnode = value;
}
} }
} }
else else
minnode = maxnode = integer_zero_node; minnode = maxnode = integer_zero_node;
/* Compute the number of bits require to represent all values of the /* Compute the number of bits require to represent all values of the
enumeration. We must do this before the type of MINNODE and enumeration. We must do this before the type of MINNODE and
MAXNODE are transformed, since min_precision relies on the MAXNODE are transformed, since min_precision relies on the
...@@ -13174,7 +13185,6 @@ build_enumerator (tree name, tree value, tree enumtype) ...@@ -13174,7 +13185,6 @@ build_enumerator (tree name, tree value, tree enumtype)
tree decl; tree decl;
tree context; tree context;
tree type; tree type;
tree values;
/* Remove no-op casts from the value. */ /* Remove no-op casts from the value. */
if (value) if (value)
...@@ -13223,24 +13233,8 @@ build_enumerator (tree name, tree value, tree enumtype) ...@@ -13223,24 +13233,8 @@ build_enumerator (tree name, tree value, tree enumtype)
/* Remove no-op casts from the value. */ /* Remove no-op casts from the value. */
if (value) if (value)
STRIP_TYPE_NOPS (value); STRIP_TYPE_NOPS (value);
#if 0
/* To fix MAX_VAL enum consts. (bkoz) */
TREE_TYPE (value) = integer_type_node;
#endif
} }
/* We always have to copy here; not all INTEGER_CSTs are unshared.
Even in other cases, we will later (in finish_enum) be setting
the type of VALUE. But, we don't need to make a copy if this
VALUE is one of the enumeration constants for this same
enumeration type. */
for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
if (TREE_VALUE (values) == value)
break;
/* If we didn't break out of the loop, then we do need a copy. */
if (!values && value)
value = copy_node (value);
/* C++ associates enums with global, function, or class declarations. */ /* C++ associates enums with global, function, or class declarations. */
context = current_scope (); context = current_scope ();
......
...@@ -7143,6 +7143,10 @@ tsubst_copy (t, args, complain, in_decl) ...@@ -7143,6 +7143,10 @@ tsubst_copy (t, args, complain, in_decl)
= tsubst_aggr_type (TREE_TYPE (t), args, complain, in_decl, = tsubst_aggr_type (TREE_TYPE (t), args, complain, in_decl,
/*entering_scope=*/0); /*entering_scope=*/0);
/* Not yet available. */
if (!enum_type || enum_type == (TREE_TYPE (t)))
return t;
for (v = TYPE_VALUES (enum_type); for (v = TYPE_VALUES (enum_type);
v != NULL_TREE; v != NULL_TREE;
v = TREE_CHAIN (v)) v = TREE_CHAIN (v))
...@@ -11065,7 +11069,12 @@ tsubst_enum (tag, newtag, args) ...@@ -11065,7 +11069,12 @@ tsubst_enum (tag, newtag, args)
for (e = TYPE_VALUES (tag); e; e = TREE_CHAIN (e)) for (e = TYPE_VALUES (tag); e; e = TREE_CHAIN (e))
{ {
tree value; tree value;
/* Copy node and set type */
if (DECL_INITIAL (TREE_VALUE (e)))
DECL_INITIAL (TREE_VALUE (e)) = copy_node (DECL_INITIAL (TREE_VALUE (e)));
TREE_TYPE (TREE_VALUE (e)) = tag;
/* Note that in a template enum, the TREE_VALUE is the /* Note that in a template enum, the TREE_VALUE is the
CONST_DECL, not the corresponding INTEGER_CST. */ CONST_DECL, not the corresponding INTEGER_CST. */
value = tsubst_expr (DECL_INITIAL (TREE_VALUE (e)), value = tsubst_expr (DECL_INITIAL (TREE_VALUE (e)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment