On Apr 26, 2010, at 4:51 PM, Fariborz Jahanian wrote: > Author: fjahanian > Date: Mon Apr 26 18:51:25 2010 > New Revision: 102403 > > URL: http://llvm.org/viewvc/llvm-project?rev=102403&view=rev > Log: > New method to construct/destruct ivars that have non-trivial default > constructors or destructors, not used yet.
Some comments below. > > Modified: > cfe/trunk/include/clang/AST/ASTContext.h > cfe/trunk/lib/AST/ASTContext.cpp > > Modified: cfe/trunk/include/clang/AST/ASTContext.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=102403&r1=102402&r2=102403&view=diff > ============================================================================== > --- cfe/trunk/include/clang/AST/ASTContext.h (original) > +++ cfe/trunk/include/clang/AST/ASTContext.h Mon Apr 26 18:51:25 2010 > @@ -955,6 +955,9 @@ > llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars); > void CollectNonClassIvars(const ObjCInterfaceDecl *OI, > llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars); > + void CollectIvarsToConstructOrDestruct(const ObjCInterfaceDecl *OI, > + llvm::SmallVectorImpl<ObjCIvarDecl*> > &Ivars, > + bool construct=true); > unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI); > void CollectInheritedProtocols(const Decl *CDecl, > llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols); Seems strange to me that this is in ASTContext rather than Sema, since creating the actual initialization will have to be done in Sema. > Modified: cfe/trunk/lib/AST/ASTContext.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=102403&r1=102402&r2=102403&view=diff > ============================================================================== > --- cfe/trunk/lib/AST/ASTContext.cpp (original) > +++ cfe/trunk/lib/AST/ASTContext.cpp Mon Apr 26 18:51:25 2010 > @@ -811,6 +811,55 @@ > } > } > > +/// CollectIvarsToConstructOrDestruct - Collect those ivars which require > +/// construction (construct=true) or destruction (construct=false) > +/// > +void ASTContext::CollectIvarsToConstructOrDestruct(const ObjCInterfaceDecl > *OI, > + llvm::SmallVectorImpl<ObjCIvarDecl*> &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<RecordType>()) { We also need to find ivars that are arrays of class type; I suggest using getBaseElementType(Iv->getType()). > + if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(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()) { Can there be multiple class extensions? I've forgotten. > + 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<RecordType>()) { Same comment w.r.t. arrays. > + if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(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<RecordType>()) { Arrays again. > + if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl())) > + if (construct && !RD->hasTrivialConstructor() || > + !construct && !RD->hasTrivialDestructor()) > + Ivars.push_back(*I); > + } > + } > + } > +} > + - Doug _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
