Author: Kazu Hirata Date: 2024-09-08T09:50:34-07:00 New Revision: 668cbd84099c82f9c34e220a019db2f5f50f4320
URL: https://github.com/llvm/llvm-project/commit/668cbd84099c82f9c34e220a019db2f5f50f4320 DIFF: https://github.com/llvm/llvm-project/commit/668cbd84099c82f9c34e220a019db2f5f50f4320.diff LOG: [Frontend] Use range-based for loops (NFC) (#107757) Added: Modified: clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp Removed: ################################################################################ diff --git a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 326920c7915537..8cdb463e2c99f2 100644 --- a/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -4080,19 +4080,17 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, // Create local declarations to avoid rewriting all closure decl ref exprs. // First, emit a declaration for all "by ref" decls. - for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E; - ++I) { + for (ValueDecl *VD : BlockByRefDecls) { S += " "; - std::string Name = (*I)->getNameAsString(); + std::string Name = VD->getNameAsString(); std::string TypeString; - RewriteByRefString(TypeString, Name, (*I)); + RewriteByRefString(TypeString, Name, VD); TypeString += " *"; Name = TypeString + Name; - S += Name + " = __cself->" + (*I)->getNameAsString() + "; // bound by ref\n"; + S += Name + " = __cself->" + VD->getNameAsString() + "; // bound by ref\n"; } // Next, emit a declaration for all "by copy" declarations. - for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E; - ++I) { + for (ValueDecl *VD : BlockByCopyDecls) { S += " "; // Handle nested closure invocation. For example: // @@ -4104,21 +4102,20 @@ std::string RewriteModernObjC::SynthesizeBlockFunc(BlockExpr *CE, int i, // myImportedClosure(); // import and invoke the closure // }; // - if (isTopLevelBlockPointerType((*I)->getType())) { - RewriteBlockPointerTypeVariable(S, (*I)); + if (isTopLevelBlockPointerType(VD->getType())) { + RewriteBlockPointerTypeVariable(S, VD); S += " = ("; - RewriteBlockPointerType(S, (*I)->getType()); + RewriteBlockPointerType(S, VD->getType()); S += ")"; - S += "__cself->" + (*I)->getNameAsString() + "; // bound by copy\n"; - } - else { - std::string Name = (*I)->getNameAsString(); - QualType QT = (*I)->getType(); - if (HasLocalVariableExternalStorage(*I)) + S += "__cself->" + VD->getNameAsString() + "; // bound by copy\n"; + } else { + std::string Name = VD->getNameAsString(); + QualType QT = VD->getType(); + if (HasLocalVariableExternalStorage(VD)) QT = Context->getPointerType(QT); QT.getAsStringInternal(Name, Context->getPrintingPolicy()); - S += Name + " = __cself->" + - (*I)->getNameAsString() + "; // bound by copy\n"; + S += Name + " = __cself->" + VD->getNameAsString() + + "; // bound by copy\n"; } } std::string RewrittenStr = RewrittenBlockExprs[CE]; @@ -4188,10 +4185,9 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, if (BlockDeclRefs.size()) { // Output all "by copy" declarations. - for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E; - ++I) { + for (ValueDecl *VD : BlockByCopyDecls) { S += " "; - std::string FieldName = (*I)->getNameAsString(); + std::string FieldName = VD->getNameAsString(); std::string ArgName = "_" + FieldName; // Handle nested closure invocation. For example: // @@ -4203,12 +4199,12 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, // myImportedBlock(); // import and invoke the closure // }; // - if (isTopLevelBlockPointerType((*I)->getType())) { + if (isTopLevelBlockPointerType(VD->getType())) { S += "struct __block_impl *"; Constructor += ", void *" + ArgName; } else { - QualType QT = (*I)->getType(); - if (HasLocalVariableExternalStorage(*I)) + QualType QT = VD->getType(); + if (HasLocalVariableExternalStorage(VD)) QT = Context->getPointerType(QT); QT.getAsStringInternal(FieldName, Context->getPrintingPolicy()); QT.getAsStringInternal(ArgName, Context->getPrintingPolicy()); @@ -4217,14 +4213,13 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, S += FieldName + ";\n"; } // Output all "by ref" declarations. - for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E; - ++I) { + for (ValueDecl *VD : BlockByRefDecls) { S += " "; - std::string FieldName = (*I)->getNameAsString(); + std::string FieldName = VD->getNameAsString(); std::string ArgName = "_" + FieldName; { std::string TypeString; - RewriteByRefString(TypeString, FieldName, (*I)); + RewriteByRefString(TypeString, FieldName, VD); TypeString += " *"; FieldName = TypeString + FieldName; ArgName = TypeString + ArgName; @@ -4236,24 +4231,21 @@ std::string RewriteModernObjC::SynthesizeBlockImpl(BlockExpr *CE, Constructor += ", int flags=0)"; // Initialize all "by copy" arguments. bool firsTime = true; - for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E; - ++I) { - std::string Name = (*I)->getNameAsString(); - if (firsTime) { - Constructor += " : "; - firsTime = false; - } - else - Constructor += ", "; - if (isTopLevelBlockPointerType((*I)->getType())) - Constructor += Name + "((struct __block_impl *)_" + Name + ")"; - else - Constructor += Name + "(_" + Name + ")"; + for (const ValueDecl *VD : BlockByCopyDecls) { + std::string Name = VD->getNameAsString(); + if (firsTime) { + Constructor += " : "; + firsTime = false; + } else + Constructor += ", "; + if (isTopLevelBlockPointerType(VD->getType())) + Constructor += Name + "((struct __block_impl *)_" + Name + ")"; + else + Constructor += Name + "(_" + Name + ")"; } // Initialize all "by ref" arguments. - for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E; - ++I) { - std::string Name = (*I)->getNameAsString(); + for (const ValueDecl *VD : BlockByRefDecls) { + std::string Name = VD->getNameAsString(); if (firsTime) { Constructor += " : "; firsTime = false; @@ -5277,47 +5269,43 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, if (BlockDeclRefs.size()) { Expr *Exp; // Output all "by copy" declarations. - for (auto I = BlockByCopyDecls.begin(), E = BlockByCopyDecls.end(); I != E; - ++I) { - if (isObjCType((*I)->getType())) { + for (ValueDecl *VD : BlockByCopyDecls) { + if (isObjCType(VD->getType())) { // FIXME: Conform to ABI ([[obj retain] autorelease]). - FD = SynthBlockInitFunctionDecl((*I)->getName()); + FD = SynthBlockInitFunctionDecl(VD->getName()); Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), VK_LValue, SourceLocation()); - if (HasLocalVariableExternalStorage(*I)) { - QualType QT = (*I)->getType(); + if (HasLocalVariableExternalStorage(VD)) { + QualType QT = VD->getType(); QT = Context->getPointerType(QT); Exp = UnaryOperator::Create(const_cast<ASTContext &>(*Context), Exp, UO_AddrOf, QT, VK_PRValue, OK_Ordinary, SourceLocation(), false, FPOptionsOverride()); } - } else if (isTopLevelBlockPointerType((*I)->getType())) { - FD = SynthBlockInitFunctionDecl((*I)->getName()); + } else if (isTopLevelBlockPointerType(VD->getType())) { + FD = SynthBlockInitFunctionDecl(VD->getName()); Arg = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), VK_LValue, SourceLocation()); Exp = NoTypeInfoCStyleCastExpr(Context, Context->VoidPtrTy, CK_BitCast, Arg); } else { - FD = SynthBlockInitFunctionDecl((*I)->getName()); + FD = SynthBlockInitFunctionDecl(VD->getName()); Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), VK_LValue, SourceLocation()); - if (HasLocalVariableExternalStorage(*I)) { - QualType QT = (*I)->getType(); + if (HasLocalVariableExternalStorage(VD)) { + QualType QT = VD->getType(); QT = Context->getPointerType(QT); Exp = UnaryOperator::Create(const_cast<ASTContext &>(*Context), Exp, UO_AddrOf, QT, VK_PRValue, OK_Ordinary, SourceLocation(), false, FPOptionsOverride()); } - } InitExprs.push_back(Exp); } // Output all "by ref" declarations. - for (auto I = BlockByRefDecls.begin(), E = BlockByRefDecls.end(); I != E; - ++I) { - ValueDecl *ND = (*I); + for (ValueDecl *ND : BlockByRefDecls) { std::string Name(ND->getNameAsString()); std::string RecName; RewriteByRefString(RecName, Name, ND, true); @@ -5329,7 +5317,7 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, assert(RD && "SynthBlockInitExpr(): Can't find RecordDecl"); QualType castT = Context->getPointerType(Context->getTagDeclType(RD)); - FD = SynthBlockInitFunctionDecl((*I)->getName()); + FD = SynthBlockInitFunctionDecl(ND->getName()); Exp = new (Context) DeclRefExpr(*Context, FD, false, FD->getType(), VK_LValue, SourceLocation()); bool isNestedCapturedVar = false; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits