From: Benjamin Kramer Date: Wed, 23 Jul 2014 11:41:44 +0000 (+0000) Subject: ASTMatchers: Bound node results are always const, make selectFirst's template argumen... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7664558efcfb8cf53e1f4d599c01500e09a5a406;p=platform%2Fupstream%2Fllvm.git ASTMatchers: Bound node results are always const, make selectFirst's template argument implicitly const. This avoids adding const to every user of selectFirst and also allows it to match TypeLocs which BoundNodes doesn't use magic const removal specializations for. No functionality change. llvm-svn: 213737 --- diff --git a/clang/include/clang/ASTMatchers/ASTMatchFinder.h b/clang/include/clang/ASTMatchers/ASTMatchFinder.h index 8af0546..9e90270 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchFinder.h +++ b/clang/include/clang/ASTMatchers/ASTMatchFinder.h @@ -210,16 +210,14 @@ match(MatcherT Matcher, const ast_type_traits::DynTypedNode &Node, /// /// This is useful in combanation with \c match(): /// \code -/// Decl *D = selectFirst("id", match(Matcher.bind("id"), -/// Node, Context)); +/// const Decl *D = selectFirst("id", match(Matcher.bind("id"), +/// Node, Context)); /// \endcode template -NodeT * +const NodeT * selectFirst(StringRef BoundTo, const SmallVectorImpl &Results) { - for (SmallVectorImpl::const_iterator I = Results.begin(), - E = Results.end(); - I != E; ++I) { - if (NodeT *Node = I->getNodeAs(BoundTo)) + for (const BoundNodes &N : Results) { + if (const NodeT *Node = N.getNodeAs(BoundTo)) return Node; } return nullptr; diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index bd7a5a6..d4f8671 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -4163,8 +4163,8 @@ public: virtual bool run(const BoundNodes *Nodes, ASTContext *Context) { const T *Node = Nodes->getNodeAs(Id); - return selectFirst(InnerId, - match(InnerMatcher, *Node, *Context)) !=nullptr; + return selectFirst(InnerId, match(InnerMatcher, *Node, *Context)) != + nullptr; } private: std::string Id; @@ -4221,7 +4221,7 @@ public: // Use the original typed pointer to verify we can pass pointers to subtypes // to equalsNode. const T *TypedNode = cast(Node); - return selectFirst( + return selectFirst( "", match(stmt(hasParent( stmt(has(stmt(equalsNode(TypedNode)))).bind(""))), *Node, Context)) != nullptr; @@ -4230,7 +4230,7 @@ public: // Use the original typed pointer to verify we can pass pointers to subtypes // to equalsNode. const T *TypedNode = cast(Node); - return selectFirst( + return selectFirst( "", match(decl(hasParent( decl(has(decl(equalsNode(TypedNode)))).bind(""))), *Node, Context)) != nullptr;