]> granicus.if.org Git - clang/commitdiff
introduce a new ASTContext::getCanonicalType method. This is the first
authorChris Lattner <sabre@nondot.org>
Sun, 6 Apr 2008 22:41:35 +0000 (22:41 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 6 Apr 2008 22:41:35 +0000 (22:41 +0000)
step towards fixing PR2189.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49291 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
lib/AST/ASTContext.cpp

index 897cd414c240120907a9f32146e6c0a482f2e81e..bddd3d651bdfa2dda4d671f26b3e225bff6e1f00 100644 (file)
@@ -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,
index a68fea469d19e3364cc9de543228aa5cef973845..0b513ecbd194539773928f9c3c59a96e88fda2c1 100644 (file)
@@ -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,