From: Aaron Ballman Date: Fri, 14 Mar 2014 18:08:33 +0000 (+0000) Subject: [C++11] Replacing CapturedStmt iterators capture_begin() and capture_end() with itera... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a858d6926e205f93b6fa49c9bd83e4e31c009af;p=clang [C++11] Replacing CapturedStmt iterators capture_begin() and capture_end() with iterator_range captures(). Updating all of the usages of the iterators with range-based for loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203953 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 9243b137e0..e71a4999b6 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -2048,6 +2048,15 @@ public: /// \brief An iterator that walks over the captures. typedef Capture *capture_iterator; typedef const Capture *const_capture_iterator; + typedef llvm::iterator_range capture_range; + typedef llvm::iterator_range capture_const_range; + + capture_range captures() { + return capture_range(capture_begin(), capture_end()); + } + capture_const_range captures() const { + return capture_const_range(capture_begin(), capture_end()); + } /// \brief Retrieve an iterator pointing to the first capture. capture_iterator capture_begin() { return getStoredCaptures(); } diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index ec5ee8b071..4c6318cc6e 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -1100,15 +1100,14 @@ Stmt::child_range CapturedStmt::children() { } bool CapturedStmt::capturesVariable(const VarDecl *Var) const { - for (const_capture_iterator I = capture_begin(), - E = capture_end(); I != E; ++I) { - if (!I->capturesVariable()) + for (const auto &I : captures()) { + if (!I.capturesVariable()) continue; // This does not handle variable redeclarations. This should be // extended to capture variables with redeclarations, for example // a thread-private variable in OpenMP. - if (I->getCapturedVar() == Var) + if (I.getCapturedVar() == Var) return true; } diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index b83e8fa5ca..f5110ea43a 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -399,13 +399,11 @@ void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) { S->getCapturedDecl()->setBody(S->getCapturedStmt()); // Captures - for (CapturedStmt::capture_iterator I = S->capture_begin(), - E = S->capture_end(); - I != E; ++I) { - I->VarAndKind.setPointer(ReadDeclAs(Record, Idx)); - I->VarAndKind + for (auto &I : S->captures()) { + I.VarAndKind.setPointer(ReadDeclAs(Record, Idx)); + I.VarAndKind .setInt(static_cast(Record[Idx++])); - I->Loc = ReadSourceLocation(Record, Idx); + I.Loc = ReadSourceLocation(Record, Idx); } } diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index 796d02b596..17de845d3b 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -309,15 +309,13 @@ void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) { Writer.AddStmt(S->getCapturedStmt()); // Captures - for (CapturedStmt::capture_iterator I = S->capture_begin(), - E = S->capture_end(); - I != E; ++I) { - if (I->capturesThis()) + for (const auto &I : S->captures()) { + if (I.capturesThis()) Writer.AddDeclRef(0, Record); else - Writer.AddDeclRef(I->getCapturedVar(), Record); - Record.push_back(I->getCaptureKind()); - Writer.AddSourceLocation(I->getLocation(), Record); + Writer.AddDeclRef(I.getCapturedVar(), Record); + Record.push_back(I.getCaptureKind()); + Writer.AddSourceLocation(I.getLocation(), Record); } Code = serialization::STMT_CAPTURED;