///
/// 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,
/// 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
/// 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
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,