r213737 - ASTMatchers: Bound node results are always const, make selectFirst's template argument implicitly const.

Benjamin Kramer benny.kra at googlemail.com
Wed Jul 23 04:41:44 PDT 2014


Author: d0k
Date: Wed Jul 23 06:41:44 2014
New Revision: 213737

URL: http://llvm.org/viewvc/llvm-project?rev=213737&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h
    cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h?rev=213737&r1=213736&r2=213737&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h Wed Jul 23 06:41:44 2014
@@ -210,16 +210,14 @@ match(MatcherT Matcher, const ast_type_t
 ///
 /// This is useful in combanation with \c match():
 /// \code
-///   Decl *D = selectFirst<Decl>("id", match(Matcher.bind("id"),
-///                                           Node, Context));
+///   const Decl *D = selectFirst<Decl>("id", match(Matcher.bind("id"),
+///                                                 Node, Context));
 /// \endcode
 template <typename NodeT>
-NodeT *
+const NodeT *
 selectFirst(StringRef BoundTo, const SmallVectorImpl<BoundNodes> &Results) {
-  for (SmallVectorImpl<BoundNodes>::const_iterator I = Results.begin(),
-                                                   E = Results.end();
-       I != E; ++I) {
-    if (NodeT *Node = I->getNodeAs<NodeT>(BoundTo))
+  for (const BoundNodes &N : Results) {
+    if (const NodeT *Node = N.getNodeAs<NodeT>(BoundTo))
       return Node;
   }
   return nullptr;

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=213737&r1=213736&r2=213737&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Wed Jul 23 06:41:44 2014
@@ -4163,8 +4163,8 @@ public:
 
   virtual bool run(const BoundNodes *Nodes, ASTContext *Context) {
     const T *Node = Nodes->getNodeAs<T>(Id);
-    return selectFirst<const T>(InnerId,
-                                match(InnerMatcher, *Node, *Context)) !=nullptr;
+    return selectFirst<T>(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<T>(Node);
-    return selectFirst<const T>(
+    return selectFirst<T>(
                "", 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<T>(Node);
-    return selectFirst<const T>(
+    return selectFirst<T>(
                "", match(decl(hasParent(
                              decl(has(decl(equalsNode(TypedNode)))).bind(""))),
                          *Node, Context)) != nullptr;





More information about the cfe-commits mailing list