diff options
author | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
commit | 056abd2059c65a3e908193aeae16fad98017437c (patch) | |
tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /lib/ASTMatchers/ASTMatchersInternal.cpp | |
parent | cc73504950eb7b5dff2dded9bedd67bc36d64641 (diff) | |
download | FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.zip FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.tar.gz |
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):
http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974
Diffstat (limited to 'lib/ASTMatchers/ASTMatchersInternal.cpp')
-rw-r--r-- | lib/ASTMatchers/ASTMatchersInternal.cpp | 66 |
1 files changed, 24 insertions, 42 deletions
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<std::string, const Decl*>& DeclBindings, - const std::map<std::string, const Stmt*>& StmtBindings, + const BoundNodesMap& Bindings, const std::vector<BoundNodesTree> 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<BoundNodesTree>::const_iterator I = RecursiveBindings.begin(), E = RecursiveBindings.end(); @@ -38,63 +49,34 @@ void BoundNodesTree::copyTo(BoundNodesTreeBuilder* Builder) const { } } -template <typename T> -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<std::string, const Decl*> AggregatedDeclBindings; - std::map<std::string, const Stmt*> AggregatedStmtBindings; - visitMatchesRecursively(ResultVisitor, AggregatedDeclBindings, - AggregatedStmtBindings); + BoundNodesMap AggregatedBindings; + visitMatchesRecursively(ResultVisitor, AggregatedBindings); } void BoundNodesTree:: visitMatchesRecursively(Visitor* ResultVisitor, - std::map<std::string, const Decl*> - AggregatedDeclBindings, - std::map<std::string, const Stmt*> - 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 |