aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2003-02-26 14:14:24 -0800
committerDevang Patel <dpatel@gcc.gnu.org>2003-02-26 14:14:24 -0800
commitfdedded1bdb452dbf3bb2a62673ae238260258ff (patch)
treefc38680b655982d2f6210efb42c64a722484b673 /gcc
parenteeec05e1dbd553dc97695ac6bb91112c42599d30 (diff)
downloadgcc-fdedded1bdb452dbf3bb2a62673ae238260258ff.zip
gcc-fdedded1bdb452dbf3bb2a62673ae238260258ff.tar.gz
gcc-fdedded1bdb452dbf3bb2a62673ae238260258ff.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/decl.c70
-rw-r--r--gcc/cp/pt.c11
3 files changed, 51 insertions, 39 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index caa078c..b896fb3 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+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>
PR c++/9683
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index b249e5c..de63181 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13062,15 +13062,6 @@ finish_enum (tree enumtype)
/* We built up the VALUES in reverse order. */
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
postponed until the template is instantiated. */
if (processing_template_decl)
@@ -13080,31 +13071,51 @@ finish_enum (tree enumtype)
return;
}
- /* Figure out what the minimum and maximum values of the enumerators
- are. */
if (TYPE_VALUES (enumtype))
{
+ /* Initialize min and max values and figure out actual values in
+ following 'for' loop. */
minnode = maxnode = NULL_TREE;
- for (pair = TYPE_VALUES (enumtype);
- pair;
- pair = TREE_CHAIN (pair))
+ /* [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 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)
- minnode = maxnode = value;
- else if (tree_int_cst_lt (maxnode, value))
- maxnode = value;
- else if (tree_int_cst_lt (value, minnode))
- minnode = value;
+ if (!processing_template_decl)
+ {
+ /* Adjust min and max value. */
+ value = DECL_INITIAL (TREE_VALUE (pair));
+
+ 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
minnode = maxnode = integer_zero_node;
+
/* Compute the number of bits require to represent all values of the
enumeration. We must do this before the type of MINNODE and
MAXNODE are transformed, since min_precision relies on the
@@ -13174,7 +13185,6 @@ build_enumerator (tree name, tree value, tree enumtype)
tree decl;
tree context;
tree type;
- tree values;
/* Remove no-op casts from the value. */
if (value)
@@ -13223,24 +13233,8 @@ build_enumerator (tree name, tree value, tree enumtype)
/* Remove no-op casts from the value. */
if (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. */
context = current_scope ();
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 9336d96..c0ec51d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -7143,6 +7143,10 @@ tsubst_copy (t, args, complain, in_decl)
= tsubst_aggr_type (TREE_TYPE (t), args, complain, in_decl,
/*entering_scope=*/0);
+ /* Not yet available. */
+ if (!enum_type || enum_type == (TREE_TYPE (t)))
+ return t;
+
for (v = TYPE_VALUES (enum_type);
v != NULL_TREE;
v = TREE_CHAIN (v))
@@ -11065,7 +11069,12 @@ tsubst_enum (tag, newtag, args)
for (e = TYPE_VALUES (tag); e; e = TREE_CHAIN (e))
{
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
CONST_DECL, not the corresponding INTEGER_CST. */
value = tsubst_expr (DECL_INITIAL (TREE_VALUE (e)),