From: Fariborz Jahanian Date: Mon, 26 Apr 2010 23:51:25 +0000 (+0000) Subject: New method to construct/destruct ivars that have non-trivial default X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=184d7900e0202ac468710b731e42075129bb6000;p=clang New method to construct/destruct ivars that have non-trivial default constructors or destructors, not used yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102403 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 415d169743..71e6b6d96a 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -955,6 +955,9 @@ public: llvm::SmallVectorImpl &Ivars); void CollectNonClassIvars(const ObjCInterfaceDecl *OI, llvm::SmallVectorImpl &Ivars); + void CollectIvarsToConstructOrDestruct(const ObjCInterfaceDecl *OI, + llvm::SmallVectorImpl &Ivars, + bool construct=true); unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI); void CollectInheritedProtocols(const Decl *CDecl, llvm::SmallPtrSet &Protocols); diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 41ba4c2d71..94d6891453 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -811,6 +811,55 @@ void ASTContext::CollectInheritedProtocols(const Decl *CDecl, } } +/// CollectIvarsToConstructOrDestruct - Collect those ivars which require +/// construction (construct=true) or destruction (construct=false) +/// +void ASTContext::CollectIvarsToConstructOrDestruct(const ObjCInterfaceDecl *OI, + llvm::SmallVectorImpl &Ivars, + bool construct) { + if (!getLangOptions().CPlusPlus) + return; + for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(), + E = OI->ivar_end(); I != E; ++I) { + ObjCIvarDecl *Iv = (*I); + if (const RecordType *RT = Iv->getType()->getAs()) { + if (const CXXRecordDecl *RD = dyn_cast(RT->getDecl())) + if (construct && !RD->hasTrivialConstructor() || + !construct && !RD->hasTrivialDestructor()) + Ivars.push_back(*I); + } + } + + // Find ivars to construct/destruct in class extension. + if (const ObjCCategoryDecl *CDecl = OI->getClassExtension()) { + for (ObjCCategoryDecl::ivar_iterator I = CDecl->ivar_begin(), + E = CDecl->ivar_end(); I != E; ++I) { + ObjCIvarDecl *Iv = (*I); + if (const RecordType *RT = Iv->getType()->getAs()) { + if (const CXXRecordDecl *RD = dyn_cast(RT->getDecl())) + if (construct && !RD->hasTrivialConstructor() || + !construct && !RD->hasTrivialDestructor()) + Ivars.push_back(*I); + } + } + } + + // Also add any ivar defined in this class's implementation. This + // includes synthesized ivars. + if (ObjCImplementationDecl *ImplDecl = OI->getImplementation()) { + for (ObjCImplementationDecl::ivar_iterator I = ImplDecl->ivar_begin(), + E = ImplDecl->ivar_end(); I != E; ++I) { + ObjCIvarDecl *Iv = (*I); + if (const RecordType *RT = Iv->getType()->getAs()) { + if (const CXXRecordDecl *RD = dyn_cast(RT->getDecl())) + if (construct && !RD->hasTrivialConstructor() || + !construct && !RD->hasTrivialDestructor()) + Ivars.push_back(*I); + } + } + } +} + unsigned ASTContext::CountNonClassIvars(const ObjCInterfaceDecl *OI) { unsigned count = 0; // Count ivars declared in class extension.