From 005f92f53c99ce8e701e44115c94216b108ea021 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 29 Mar 2009 07:03:59 +0000 Subject: [PATCH] switch TemplateOrInstantiation to be a PointerUnion, which 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 | 22 +++++++++++++--------- lib/AST/DeclCXX.cpp | 18 ------------------ 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 389ffaec68..5ff6910bb0 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -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 TemplateOrInstantiation; + /// RecordDecl from which the member class was instantiated. + llvm::PointerUnionTemplateOrInstantiation; protected: CXXRecordDecl(Kind K, TagKind TK, DeclContext *DC, @@ -395,13 +394,14 @@ public: /// the CXXRecordDecl X::A. When a complete definition of /// X::A is required, it will be instantiated from the /// declaration returned by getInstantiatedFromMemberClass(). - CXXRecordDecl *getInstantiatedFromMemberClass(); + CXXRecordDecl *getInstantiatedFromMemberClass() { + return TemplateOrInstantiation.dyn_cast(); + } /// \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(); + } - 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 diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index 2858d479bb..0fd83efa20 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -179,24 +179,6 @@ void CXXRecordDecl::addConversionFunction(ASTContext &Context, Conversions.addOverload(ConvDecl); } -CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() { - if (TemplateOrInstantiation.getInt() == 1) - return cast_or_null(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( - TemplateOrInstantiation.getPointer()); - return 0; -} - CXXMethodDecl * CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation L, DeclarationName N, -- 2.40.0