From 3f0e0402d8cd40b428f975f1a3607dbbd94d2ca6 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 6 Nov 2013 00:27:07 +0000 Subject: [PATCH] Introduce BoundNodes::getMap. The purpose of this function is to allow clients of the dynamic AST matcher to enumerate each binding. Differential Revision: http://llvm-reviews.chandlerc.com/D2095 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194112 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/ASTMatchers/ASTMatchers.h | 10 ++++++++++ include/clang/ASTMatchers/ASTMatchersInternal.h | 6 +++++- unittests/ASTMatchers/ASTMatchersTest.cpp | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index d158dd763c..40442c774b 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -86,6 +86,16 @@ public: } /// @} + /// \brief Type of mapping from binding identifiers to bound nodes. This type + /// is an associative container with a key type of \c std::string and a value + /// type of \c clang::ast_type_traits::DynTypedNode + typedef internal::BoundNodesMap::IDToNodeMap IDToNodeMap; + + /// \brief Retrieve mapping from binding identifiers to bound nodes. + const IDToNodeMap &getMap() const { + return MyBoundNodes.getMap(); + } + private: /// \brief Create BoundNodes from a pre-filled map of bindings. BoundNodes(internal::BoundNodesMap &MyBoundNodes) diff --git a/include/clang/ASTMatchers/ASTMatchersInternal.h b/include/clang/ASTMatchers/ASTMatchersInternal.h index 3d078259e0..6dd7c1f3c8 100644 --- a/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -98,7 +98,6 @@ public: return NodeMap < Other.NodeMap; } -private: /// \brief A map from IDs to the bound nodes. /// /// Note that we're using std::map here, as for memoization: @@ -106,6 +105,11 @@ private: /// - we need an assignment operator typedef std::map IDToNodeMap; + const IDToNodeMap &getMap() const { + return NodeMap; + } + +private: IDToNodeMap NodeMap; }; diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 556b0b896e..a848d55f98 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -659,6 +659,7 @@ public: } virtual bool run(const BoundNodes *Nodes) { + const BoundNodes::IDToNodeMap &M = Nodes->getMap(); if (Nodes->getNodeAs(Id)) { ++Count; if (const NamedDecl *Named = Nodes->getNodeAs(Id)) { @@ -668,8 +669,13 @@ public: llvm::raw_string_ostream OS(Name); NNS->print(OS, PrintingPolicy(LangOptions())); } + BoundNodes::IDToNodeMap::const_iterator I = M.find(Id); + EXPECT_NE(M.end(), I); + if (I != M.end()) + EXPECT_EQ(Nodes->getNodeAs(Id), I->second.get()); return true; } + EXPECT_TRUE(M.count(Id) == 0 || M.find(Id)->second.template get() == 0); return false; } -- 2.40.0