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

Chris Lattner sabre at nondot.org
Sun Mar 29 00:04:00 PDT 2009


Author: lattner
Date: Sun Mar 29 02:03:59 2009
New Revision: 67993

URL: http://llvm.org/viewvc/llvm-project?rev=67993&view=rev
Log:
switch TemplateOrInstantiation to be a PointerUnion, which 
simplifies some code.

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

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sun Mar 29 02:03:59 2009
@@ -243,11 +243,10 @@
   /// 
   /// For non-templates, this value will be NULL. For record
   /// declarations that describe a class template, this will be a
-  /// pointer to a ClassTemplateDecl (the bit is 0). For member
+  /// pointer to a ClassTemplateDecl. For member
   /// classes of class template specializations, this will be the
-  /// RecordDecl from which the member class was instantiated (the bit
-  /// is 1).
-  llvm::PointerIntPair<Decl*, 1> TemplateOrInstantiation;
+  /// RecordDecl from which the member class was instantiated.
+  llvm::PointerUnion<ClassTemplateDecl*, CXXRecordDecl*>TemplateOrInstantiation;
 
 protected:
   CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC,
@@ -395,13 +394,14 @@
   /// the CXXRecordDecl X<T>::A. When a complete definition of
   /// X<int>::A is required, it will be instantiated from the
   /// declaration returned by getInstantiatedFromMemberClass().
-  CXXRecordDecl *getInstantiatedFromMemberClass();
+  CXXRecordDecl *getInstantiatedFromMemberClass() {
+    return TemplateOrInstantiation.dyn_cast<CXXRecordDecl*>();
+  }
 
   /// \brief Specify that this record is an instantiation of the
   /// member class RD.
   void setInstantiationOfMemberClass(CXXRecordDecl *RD) { 
-    TemplateOrInstantiation.setInt(1);
-    TemplateOrInstantiation.setPointer(RD);
+    TemplateOrInstantiation = RD;
   }
 
   /// \brief Retrieves the class template that is described by this
@@ -415,9 +415,13 @@
   /// CXXRecordDecl that from a ClassTemplateDecl, while
   /// getDescribedClassTemplate() retrieves the ClassTemplateDecl from
   /// a CXXRecordDecl.
-  ClassTemplateDecl *getDescribedClassTemplate();
+  ClassTemplateDecl *getDescribedClassTemplate() {
+    return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl*>();
+  }
 
-  void setDescribedClassTemplate(ClassTemplateDecl *Template);
+  void setDescribedClassTemplate(ClassTemplateDecl *Template) {
+    TemplateOrInstantiation = Template;
+  }
 
   /// viewInheritance - Renders and displays an inheritance diagram
   /// for this C++ class and all of its base classes (transitively) using

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

==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Sun Mar 29 02:03:59 2009
@@ -179,24 +179,6 @@
   Conversions.addOverload(ConvDecl);
 }
 
-CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() {
-  if (TemplateOrInstantiation.getInt() == 1)
-    return cast_or_null<CXXRecordDecl>(TemplateOrInstantiation.getPointer());
-  return 0;
-}
-
-void CXXRecordDecl::setDescribedClassTemplate(ClassTemplateDecl *Template) {
-  TemplateOrInstantiation.setInt(0);
-  TemplateOrInstantiation.setPointer(Template);
-}
-
-ClassTemplateDecl *CXXRecordDecl::getDescribedClassTemplate() {
-  if (TemplateOrInstantiation.getInt() == 0)
-    return cast_or_null<ClassTemplateDecl>(
-                                     TemplateOrInstantiation.getPointer());
-  return 0;
-}
-
 CXXMethodDecl *
 CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
                       SourceLocation L, DeclarationName N,





More information about the cfe-commits mailing list