[cfe-commits] r49291 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp

Chris Lattner sabre at nondot.org
Sun Apr 6 15:41:35 PDT 2008


Author: lattner
Date: Sun Apr  6 17:41:35 2008
New Revision: 49291

URL: http://llvm.org/viewvc/llvm-project?rev=49291&view=rev
Log:
introduce a new ASTContext::getCanonicalType method.  This is the first
step towards fixing PR2189.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=49291&r1=49290&r2=49291&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sun Apr  6 17:41:35 2008
@@ -287,6 +287,14 @@
   //                            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,

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=49291&r1=49290&r2=49291&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Apr  6 17:41:35 2008
@@ -931,6 +931,19 @@
 //                              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,





More information about the cfe-commits mailing list