aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorJason Merrill <jason@gcc.gnu.org>2004-02-24 13:23:25 -0500
committerJason Merrill <jason@gcc.gnu.org>2004-02-24 13:23:25 -0500
commit896c3aa346912570aacfa51834145311de94632b (patch)
tree10d698360ffb12ad09cb08c4d3925aebb79ecd40 /gcc/tree.c
parent58565a33ed8ca46cd1d3745f96786f3b4b0ebda3 (diff)
downloadgcc-896c3aa346912570aacfa51834145311de94632b.zip
gcc-896c3aa346912570aacfa51834145311de94632b.tar.gz
gcc-896c3aa346912570aacfa51834145311de94632b.tar.bz2
tree.c (check_qualified_type): New fn.
* tree.c (check_qualified_type): New fn. (get_qualified_type): Use it. If type already has the desired quals, just return it. * tree.h: Declare it. * cp/tree.c (build_exception_variant): Use it. From-SVN: r78376
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index d2b79bc..3913b55 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -2967,6 +2967,19 @@ set_type_quals (tree type, int type_quals)
TYPE_RESTRICT (type) = (type_quals & TYPE_QUAL_RESTRICT) != 0;
}
+/* Returns true iff cand is equivalent to base with type_quals. */
+
+bool
+check_qualified_type (tree cand, tree base, int type_quals)
+{
+ return (TYPE_QUALS (cand) == type_quals
+ && TYPE_NAME (cand) == TYPE_NAME (base)
+ /* Apparently this is needed for Objective-C. */
+ && TYPE_CONTEXT (cand) == TYPE_CONTEXT (base)
+ && attribute_list_equal (TYPE_ATTRIBUTES (cand),
+ TYPE_ATTRIBUTES (base)));
+}
+
/* Return a version of the TYPE, qualified as indicated by the
TYPE_QUALS, if one exists. If no qualified version exists yet,
return NULL_TREE. */
@@ -2976,13 +2989,14 @@ get_qualified_type (tree type, int type_quals)
{
tree t;
+ if (TYPE_QUALS (type) == type_quals)
+ return type;
+
/* Search the chain of variants to see if there is already one there just
like the one we need to have. If so, use that existing one. We must
preserve the TYPE_NAME, since there is code that depends on this. */
for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
- if (TYPE_QUALS (t) == type_quals && TYPE_NAME (t) == TYPE_NAME (type)
- && TYPE_CONTEXT (t) == TYPE_CONTEXT (type)
- && attribute_list_equal (TYPE_ATTRIBUTES (t), TYPE_ATTRIBUTES (type)))
+ if (check_qualified_type (t, type, type_quals))
return t;
return NULL_TREE;