aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-06 22:41:35 +0000
committerChris Lattner <sabre@nondot.org>2008-04-06 22:41:35 +0000
commit77c9647cae939104c6cb2b6a4dd8ca859d2e5770 (patch)
tree8263d29e2e2a4ed175e6b99c5896f9a9667588a2
parent9d294b9957f57512db8de37452024e82f0fe4f50 (diff)
introduce a new ASTContext::getCanonicalType method. This is the first
step towards fixing PR2189. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49291 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/ASTContext.h8
-rw-r--r--lib/AST/ASTContext.cpp13
2 files changed, 21 insertions, 0 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 897cd414c2..bddd3d651b 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -287,6 +287,14 @@ public:
// Type Operators
//===--------------------------------------------------------------------===//
+ /// getCanonicalType - Return the canonical (structural) type corresponding to
+ /// the specified potentially non-canonical type. The non-canonical version
+ /// of a type may have many "decorated" versions of types. Decorators can
+ /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
+ /// to be free of any of these, allowing two canonical types to be compared
+ /// for exact equality with a simple pointer comparison.
+ QualType getCanonicalType(QualType T);
+
/// getArrayDecayedType - Return the properly qualified result of decaying the
/// specified array type to a pointer. This operation is non-trivial when
/// handling typedefs etc. The canonical type of "T" must be an array type,
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index a68fea469d..0b513ecbd1 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -931,6 +931,19 @@ QualType ASTContext::getPointerDiffType() const {
// Type Operators
//===----------------------------------------------------------------------===//
+/// getCanonicalType - Return the canonical (structural) type corresponding to
+/// the specified potentially non-canonical type. The non-canonical version
+/// of a type may have many "decorated" versions of types. Decorators can
+/// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
+/// to be free of any of these, allowing two canonical types to be compared
+/// for exact equality with a simple pointer comparison.
+QualType ASTContext::getCanonicalType(QualType T) {
+ QualType CanType = T.getTypePtr()->getCanonicalTypeInternal();
+ return QualType(CanType.getTypePtr(),
+ T.getCVRQualifiers() | CanType.getCVRQualifiers());
+}
+
+
/// getArrayDecayedType - Return the properly qualified result of decaying the
/// specified array type to a pointer. This operation is non-trivial when
/// handling typedefs etc. The canonical type of "T" must be an array type,