Skip to content

Commit 38b77a9

Browse files
author
Fariborz Jahanian
committed
Move CollectIvarsToConstructOrDestruct to Sema
from AST, consider ivar array of objects (per Doug's comment). llvm-svn: 102446
1 parent 2e3197e commit 38b77a9

File tree

4 files changed

+58
-52
lines changed

4 files changed

+58
-52
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,6 @@ class ASTContext {
957957
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
958958
void CollectNonClassIvars(const ObjCInterfaceDecl *OI,
959959
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars);
960-
void CollectIvarsToConstructOrDestruct(const ObjCInterfaceDecl *OI,
961-
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
962-
bool construct=true);
963960
unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI);
964961
void CollectInheritedProtocols(const Decl *CDecl,
965962
llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);

clang/lib/AST/ASTContext.cpp

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -807,55 +807,6 @@ void ASTContext::CollectInheritedProtocols(const Decl *CDecl,
807807
}
808808
}
809809

810-
/// CollectIvarsToConstructOrDestruct - Collect those ivars which require
811-
/// construction (construct=true) or destruction (construct=false)
812-
///
813-
void ASTContext::CollectIvarsToConstructOrDestruct(const ObjCInterfaceDecl *OI,
814-
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
815-
bool construct) {
816-
if (!getLangOptions().CPlusPlus)
817-
return;
818-
for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
819-
E = OI->ivar_end(); I != E; ++I) {
820-
ObjCIvarDecl *Iv = (*I);
821-
if (const RecordType *RT = Iv->getType()->getAs<RecordType>()) {
822-
if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
823-
if (construct && !RD->hasTrivialConstructor() ||
824-
!construct && !RD->hasTrivialDestructor())
825-
Ivars.push_back(*I);
826-
}
827-
}
828-
829-
// Find ivars to construct/destruct in class extension.
830-
if (const ObjCCategoryDecl *CDecl = OI->getClassExtension()) {
831-
for (ObjCCategoryDecl::ivar_iterator I = CDecl->ivar_begin(),
832-
E = CDecl->ivar_end(); I != E; ++I) {
833-
ObjCIvarDecl *Iv = (*I);
834-
if (const RecordType *RT = Iv->getType()->getAs<RecordType>()) {
835-
if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
836-
if (construct && !RD->hasTrivialConstructor() ||
837-
!construct && !RD->hasTrivialDestructor())
838-
Ivars.push_back(*I);
839-
}
840-
}
841-
}
842-
843-
// Also add any ivar defined in this class's implementation. This
844-
// includes synthesized ivars.
845-
if (ObjCImplementationDecl *ImplDecl = OI->getImplementation()) {
846-
for (ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(),
847-
E = ImplDecl->ivar_end(); I != E; ++I) {
848-
ObjCIvarDecl *Iv = (*I);
849-
if (const RecordType *RT = Iv->getType()->getAs<RecordType>()) {
850-
if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
851-
if (construct && !RD->hasTrivialConstructor() ||
852-
!construct && !RD->hasTrivialDestructor())
853-
Ivars.push_back(*I);
854-
}
855-
}
856-
}
857-
}
858-
859810
unsigned ASTContext::CountNonClassIvars(const ObjCInterfaceDecl *OI) {
860811
unsigned count = 0;
861812
// Count ivars declared in class extension.

clang/lib/Sema/Sema.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,12 @@ class Sema : public Action {
15901590

15911591
/// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
15921592
void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
1593+
1594+
/// CollectIvarsToConstructOrDestruct - Collect those ivars which require
1595+
/// construction (construct=true) or destruction (construct=false)
1596+
void CollectIvarsToConstructOrDestruct(const ObjCInterfaceDecl *OI,
1597+
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
1598+
bool construct=true);
15931599
//===--------------------------------------------------------------------===//
15941600
// Statement Parsing Callbacks: SemaStmt.cpp.
15951601
public:

clang/lib/Sema/SemaDeclObjC.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,3 +1798,55 @@ Sema::DeclPtrTy Sema::ActOnObjCExceptionDecl(Scope *S, Declarator &D) {
17981798
Diag(New->getLocation(), diag::err_block_on_nonlocal);
17991799
return DeclPtrTy::make(New);
18001800
}
1801+
1802+
/// CollectIvarsToConstructOrDestruct - Collect those ivars which require
1803+
/// construction (construct=true) or destruction (construct=false)
1804+
///
1805+
void Sema::CollectIvarsToConstructOrDestruct(const ObjCInterfaceDecl *OI,
1806+
llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars,
1807+
bool construct) {
1808+
if (!getLangOptions().CPlusPlus)
1809+
return;
1810+
for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
1811+
E = OI->ivar_end(); I != E; ++I) {
1812+
ObjCIvarDecl *Iv = (*I);
1813+
QualType QT = Context.getBaseElementType(Iv->getType());
1814+
if (const RecordType *RT = QT->getAs<RecordType>()) {
1815+
if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
1816+
if (construct && !RD->hasTrivialConstructor() ||
1817+
!construct && !RD->hasTrivialDestructor())
1818+
Ivars.push_back(*I);
1819+
}
1820+
}
1821+
1822+
// Find ivars to construct/destruct in class extension.
1823+
if (const ObjCCategoryDecl *CDecl = OI->getClassExtension()) {
1824+
for (ObjCCategoryDecl::ivar_iterator I = CDecl->ivar_begin(),
1825+
E = CDecl->ivar_end(); I != E; ++I) {
1826+
ObjCIvarDecl *Iv = (*I);
1827+
QualType QT = Context.getBaseElementType(Iv->getType());
1828+
if (const RecordType *RT = QT->getAs<RecordType>()) {
1829+
if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
1830+
if (construct && !RD->hasTrivialConstructor() ||
1831+
!construct && !RD->hasTrivialDestructor())
1832+
Ivars.push_back(*I);
1833+
}
1834+
}
1835+
}
1836+
1837+
// Also add any ivar defined in this class's implementation. This
1838+
// includes synthesized ivars.
1839+
if (ObjCImplementationDecl *ImplDecl = OI->getImplementation()) {
1840+
for (ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(),
1841+
E = ImplDecl->ivar_end(); I != E; ++I) {
1842+
ObjCIvarDecl *Iv = (*I);
1843+
QualType QT = Context.getBaseElementType(Iv->getType());
1844+
if (const RecordType *RT = QT->getAs<RecordType>()) {
1845+
if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
1846+
if (construct && !RD->hasTrivialConstructor() ||
1847+
!construct && !RD->hasTrivialDestructor())
1848+
Ivars.push_back(*I);
1849+
}
1850+
}
1851+
}
1852+
}

0 commit comments

Comments
 (0)