-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Frontend] Use range-based for loops (NFC) #107757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_range_for_RewriteModernObjC
Sep 8, 2024
Merged
[Frontend] Use range-based for loops (NFC) #107757
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_001_range_for_RewriteModernObjC
Sep 8, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/107757.diff 1 Files Affected:
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;
|
nikic
approved these changes
Sep 8, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.