From: Craig Topper Date: Mon, 25 Aug 2014 04:15:02 +0000 (+0000) Subject: Use range based for loops to avoid needing to re-mention SmallPtrSet size. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=708e338843871a05df49df9ea9ebb5529c7b146d;p=clang Use range based for loops to avoid needing to re-mention SmallPtrSet size. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216370 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index e4ff7d5e93..01e80253c4 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -700,11 +700,9 @@ void ObjCMigrateASTConsumer::migrateProtocolConformance(ASTContext &Ctx, Ctx.CollectInheritedProtocols(IDecl, ExplicitProtocols); llvm::SmallVector PotentialImplicitProtocols; - for (llvm::SmallPtrSet::iterator I = - ObjCProtocolDecls.begin(), - E = ObjCProtocolDecls.end(); I != E; ++I) - if (!ExplicitProtocols.count(*I)) - PotentialImplicitProtocols.push_back(*I); + for (ObjCProtocolDecl *ProtDecl : ObjCProtocolDecls) + if (!ExplicitProtocols.count(ProtDecl)) + PotentialImplicitProtocols.push_back(ProtDecl); if (PotentialImplicitProtocols.empty()) return; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 3a15096815..718719a904 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -6673,11 +6673,9 @@ void getIntersectionOfProtocols(ASTContext &Context, llvm::SmallPtrSet RHSInheritedProtocols; Context.CollectInheritedProtocols(RHS->getInterface(), RHSInheritedProtocols); - for (llvm::SmallPtrSet::iterator I = - RHSInheritedProtocols.begin(), - E = RHSInheritedProtocols.end(); I != E; ++I) - if (InheritedProtocolSet.count((*I))) - IntersectionOfProtocols.push_back((*I)); + for (ObjCProtocolDecl *ProtDecl : RHSInheritedProtocols) + if (InheritedProtocolSet.count(ProtDecl)) + IntersectionOfProtocols.push_back(ProtDecl); } } diff --git a/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 4fe8f74cd1..3936727910 100644 --- a/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -4067,9 +4067,7 @@ void RewriteModernObjC::RewriteIvarOffsetSymbols(ObjCInterfaceDecl *CDecl, return; llvm::DenseSet > GroupSymbolOutput; - for (llvm::SmallPtrSet::iterator i = Ivars.begin(), - e = Ivars.end(); i != e; i++) { - ObjCIvarDecl *IvarDecl = (*i); + for (ObjCIvarDecl *IvarDecl : Ivars) { const ObjCInterfaceDecl *IDecl = IvarDecl->getContainingInterface(); unsigned GroupNo = 0; if (IvarDecl->isBitField()) { @@ -4253,14 +4251,12 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, S += "(" + StructRef; S += "*dst, " + StructRef; S += "*src) {"; - for (llvm::SmallPtrSet::iterator I = ImportedBlockDecls.begin(), - E = ImportedBlockDecls.end(); I != E; ++I) { - ValueDecl *VD = (*I); + for (ValueDecl *VD : ImportedBlockDecls) { S += "_Block_object_assign((void*)&dst->"; - S += (*I)->getNameAsString(); + S += VD->getNameAsString(); S += ", (void*)src->"; - S += (*I)->getNameAsString(); - if (BlockByRefDeclsPtrSet.count((*I))) + S += VD->getNameAsString(); + if (BlockByRefDeclsPtrSet.count(VD)) S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);"; else if (VD->getType()->isBlockPointerType()) S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);"; @@ -4274,12 +4270,10 @@ std::string RewriteModernObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, S += "_block_dispose_" + utostr(i); S += "(" + StructRef; S += "*src) {"; - for (llvm::SmallPtrSet::iterator I = ImportedBlockDecls.begin(), - E = ImportedBlockDecls.end(); I != E; ++I) { - ValueDecl *VD = (*I); + for (ValueDecl *VD : ImportedBlockDecls) { S += "_Block_object_dispose((void*)src->"; - S += (*I)->getNameAsString(); - if (BlockByRefDeclsPtrSet.count((*I))) + S += VD->getNameAsString(); + if (BlockByRefDeclsPtrSet.count(VD)) S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);"; else if (VD->getType()->isBlockPointerType()) S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);"; @@ -5975,10 +5969,9 @@ void RewriteModernObjC::HandleTranslationUnit(ASTContext &C) { // Here's a great place to add any extra declarations that may be needed. // Write out meta data for each @protocol(). - for (llvm::SmallPtrSet::iterator I = ProtocolExprDecls.begin(), - E = ProtocolExprDecls.end(); I != E; ++I) { - RewriteObjCProtocolMetaData(*I, Preamble); - Write_ProtocolExprReferencedMetadata(Context, (*I), Preamble); + for (ObjCProtocolDecl *ProtDecl : ProtocolExprDecls) { + RewriteObjCProtocolMetaData(ProtDecl, Preamble); + Write_ProtocolExprReferencedMetadata(Context, ProtDecl, Preamble); } InsertText(SM->getLocForStartOfFile(MainFileID), Preamble, false); diff --git a/lib/Frontend/Rewrite/RewriteObjC.cpp b/lib/Frontend/Rewrite/RewriteObjC.cpp index e96ff78c60..695d342edb 100644 --- a/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -3382,14 +3382,12 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, S += "(" + StructRef; S += "*dst, " + StructRef; S += "*src) {"; - for (llvm::SmallPtrSet::iterator I = ImportedBlockDecls.begin(), - E = ImportedBlockDecls.end(); I != E; ++I) { - ValueDecl *VD = (*I); + for (ValueDecl *VD : ImportedBlockDecls) { S += "_Block_object_assign((void*)&dst->"; - S += (*I)->getNameAsString(); + S += VD->getNameAsString(); S += ", (void*)src->"; - S += (*I)->getNameAsString(); - if (BlockByRefDeclsPtrSet.count((*I))) + S += VD->getNameAsString(); + if (BlockByRefDeclsPtrSet.count(VD)) S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);"; else if (VD->getType()->isBlockPointerType()) S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);"; @@ -3403,12 +3401,10 @@ std::string RewriteObjC::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i, S += "_block_dispose_" + utostr(i); S += "(" + StructRef; S += "*src) {"; - for (llvm::SmallPtrSet::iterator I = ImportedBlockDecls.begin(), - E = ImportedBlockDecls.end(); I != E; ++I) { - ValueDecl *VD = (*I); + for (ValueDecl *VD : ImportedBlockDecls) { S += "_Block_object_dispose((void*)src->"; - S += (*I)->getNameAsString(); - if (BlockByRefDeclsPtrSet.count((*I))) + S += VD->getNameAsString(); + if (BlockByRefDeclsPtrSet.count(VD)) S += ", " + utostr(BLOCK_FIELD_IS_BYREF) + "/*BLOCK_FIELD_IS_BYREF*/);"; else if (VD->getType()->isBlockPointerType()) S += ", " + utostr(BLOCK_FIELD_IS_BLOCK) + "/*BLOCK_FIELD_IS_BLOCK*/);"; @@ -4967,9 +4963,8 @@ void RewriteObjC::HandleTranslationUnit(ASTContext &C) { // Here's a great place to add any extra declarations that may be needed. // Write out meta data for each @protocol(). - for (llvm::SmallPtrSet::iterator I = ProtocolExprDecls.begin(), - E = ProtocolExprDecls.end(); I != E; ++I) - RewriteObjCProtocolMetaData(*I, "", "", Preamble); + for (ObjCProtocolDecl *ProtDecl : ProtocolExprDecls) + RewriteObjCProtocolMetaData(ProtDecl, "", "", Preamble); InsertText(SM->getLocForStartOfFile(MainFileID), Preamble, false); if (ClassImplementation.size() || CategoryImplementation.size()) @@ -5657,12 +5652,11 @@ void RewriteObjCFragileABI::RewriteMetaDataIntoBuffer(std::string &Result) { if (ProtocolExprDecls.size()) { Result += "#pragma section(\".objc_protocol$B\",long,read,write)\n"; Result += "#pragma data_seg(push, \".objc_protocol$B\")\n"; - for (llvm::SmallPtrSet::iterator I = ProtocolExprDecls.begin(), - E = ProtocolExprDecls.end(); I != E; ++I) { + for (ObjCProtocolDecl *ProtDecl : ProtocolExprDecls) { Result += "static struct _objc_protocol *_POINTER_OBJC_PROTOCOL_"; - Result += (*I)->getNameAsString(); + Result += ProtDecl->getNameAsString(); Result += " = &_OBJC_PROTOCOL_"; - Result += (*I)->getNameAsString(); + Result += ProtDecl->getNameAsString(); Result += ";\n"; } Result += "#pragma data_seg(pop)\n\n"; diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 576cf84dbb..0f0d06d56c 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -8209,16 +8209,14 @@ void ASTReader::finishPendingActions() { // Objective-C protocol definitions, or any redeclarable templates, make sure // that all redeclarations point to the definitions. Note that this can only // happen now, after the redeclaration chains have been fully wired. - for (llvm::SmallPtrSet::iterator D = PendingDefinitions.begin(), - DEnd = PendingDefinitions.end(); - D != DEnd; ++D) { - if (TagDecl *TD = dyn_cast(*D)) { + for (Decl *D : PendingDefinitions) { + if (TagDecl *TD = dyn_cast(D)) { if (const TagType *TagT = dyn_cast(TD->getTypeForDecl())) { // Make sure that the TagType points at the definition. const_cast(TagT)->decl = TD; } - if (auto RD = dyn_cast(*D)) { + if (auto RD = dyn_cast(D)) { for (auto R : RD->redecls()) cast(R)->DefinitionData = RD->DefinitionData; } @@ -8226,7 +8224,7 @@ void ASTReader::finishPendingActions() { continue; } - if (auto ID = dyn_cast(*D)) { + if (auto ID = dyn_cast(D)) { // Make sure that the ObjCInterfaceType points at the definition. const_cast(cast(ID->TypeForDecl)) ->Decl = ID; @@ -8237,14 +8235,14 @@ void ASTReader::finishPendingActions() { continue; } - if (auto PD = dyn_cast(*D)) { + if (auto PD = dyn_cast(D)) { for (auto R : PD->redecls()) R->Data = PD->Data; continue; } - auto RTD = cast(*D)->getCanonicalDecl(); + auto RTD = cast(D)->getCanonicalDecl(); for (auto R : RTD->redecls()) R->Common = RTD->Common; }