]> granicus.if.org Git - clang/commitdiff
switch TemplateOrInstantiation to be a PointerUnion, which
authorChris Lattner <sabre@nondot.org>
Sun, 29 Mar 2009 07:03:59 +0000 (07:03 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 29 Mar 2009 07:03:59 +0000 (07:03 +0000)
simplifies some code.

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

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

index 389ffaec68e4a2e3481f2746ea9596f45c0cd8f8..5ff6910bb0f13c9bcade28872161c36d79137249 100644 (file)
@@ -243,11 +243,10 @@ class CXXRecordDecl : public RecordDecl {
   /// 
   /// 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 @@ public:
   /// 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 @@ public:
   /// 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
index 2858d479bbbb31164b5768e1572bc6d875990a71..0fd83efa20a77411ba9671ad8395a9f386909447 100644 (file)
@@ -179,24 +179,6 @@ void CXXRecordDecl::addConversionFunction(ASTContext &Context,
   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,