From 056abd2059c65a3e908193aeae16fad98017437c Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 2 Dec 2012 13:20:44 +0000 Subject: Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2): http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974 --- lib/ASTMatchers/ASTMatchersInternal.cpp | 66 ++++++++++++--------------------- 1 file changed, 24 insertions(+), 42 deletions(-) (limited to 'lib/ASTMatchers/ASTMatchersInternal.cpp') diff --git a/lib/ASTMatchers/ASTMatchersInternal.cpp b/lib/ASTMatchers/ASTMatchersInternal.cpp index 69c5190..408195d 100644 --- a/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -18,18 +18,29 @@ namespace clang { namespace ast_matchers { namespace internal { +void BoundNodesMap::copyTo(BoundNodesTreeBuilder *Builder) const { + for (IDToNodeMap::const_iterator It = NodeMap.begin(); + It != NodeMap.end(); + ++It) { + Builder->setBinding(It->first, It->second); + } +} + +void BoundNodesMap::copyTo(BoundNodesMap *Other) const { + copy(NodeMap.begin(), NodeMap.end(), + inserter(Other->NodeMap, Other->NodeMap.begin())); +} + BoundNodesTree::BoundNodesTree() {} BoundNodesTree::BoundNodesTree( - const std::map& DeclBindings, - const std::map& StmtBindings, + const BoundNodesMap& Bindings, const std::vector RecursiveBindings) - : DeclBindings(DeclBindings), StmtBindings(StmtBindings), + : Bindings(Bindings), RecursiveBindings(RecursiveBindings) {} void BoundNodesTree::copyTo(BoundNodesTreeBuilder* Builder) const { - copyBindingsTo(DeclBindings, Builder); - copyBindingsTo(StmtBindings, Builder); + Bindings.copyTo(Builder); for (std::vector::const_iterator I = RecursiveBindings.begin(), E = RecursiveBindings.end(); @@ -38,63 +49,34 @@ void BoundNodesTree::copyTo(BoundNodesTreeBuilder* Builder) const { } } -template -void BoundNodesTree::copyBindingsTo( - const T& Bindings, BoundNodesTreeBuilder* Builder) const { - for (typename T::const_iterator I = Bindings.begin(), - E = Bindings.end(); - I != E; ++I) { - Builder->setBinding(I->first, I->second); - } -} - void BoundNodesTree::visitMatches(Visitor* ResultVisitor) { - std::map AggregatedDeclBindings; - std::map AggregatedStmtBindings; - visitMatchesRecursively(ResultVisitor, AggregatedDeclBindings, - AggregatedStmtBindings); + BoundNodesMap AggregatedBindings; + visitMatchesRecursively(ResultVisitor, AggregatedBindings); } void BoundNodesTree:: visitMatchesRecursively(Visitor* ResultVisitor, - std::map - AggregatedDeclBindings, - std::map - AggregatedStmtBindings) { - copy(DeclBindings.begin(), DeclBindings.end(), - inserter(AggregatedDeclBindings, AggregatedDeclBindings.begin())); - copy(StmtBindings.begin(), StmtBindings.end(), - inserter(AggregatedStmtBindings, AggregatedStmtBindings.begin())); + const BoundNodesMap& AggregatedBindings) { + BoundNodesMap CombinedBindings(AggregatedBindings); + Bindings.copyTo(&CombinedBindings); if (RecursiveBindings.empty()) { - ResultVisitor->visitMatch(BoundNodes(AggregatedDeclBindings, - AggregatedStmtBindings)); + ResultVisitor->visitMatch(BoundNodes(CombinedBindings)); } else { for (unsigned I = 0; I < RecursiveBindings.size(); ++I) { RecursiveBindings[I].visitMatchesRecursively(ResultVisitor, - AggregatedDeclBindings, - AggregatedStmtBindings); + CombinedBindings); } } } BoundNodesTreeBuilder::BoundNodesTreeBuilder() {} -void BoundNodesTreeBuilder::setBinding(const std::string &Id, - const Decl *Node) { - DeclBindings[Id] = Node; -} - -void BoundNodesTreeBuilder::setBinding(const std::string &Id, - const Stmt *Node) { - StmtBindings[Id] = Node; -} - void BoundNodesTreeBuilder::addMatch(const BoundNodesTree& Bindings) { RecursiveBindings.push_back(Bindings); } BoundNodesTree BoundNodesTreeBuilder::build() const { - return BoundNodesTree(DeclBindings, StmtBindings, RecursiveBindings); + return BoundNodesTree(Bindings, RecursiveBindings); } } // end namespace internal -- cgit v1.1