1 //===--- ASTMatchersInternal.cpp - Structural query framework -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implements the base layer of the matcher framework.
12 //===----------------------------------------------------------------------===//
14 #include "clang/ASTMatchers/ASTMatchers.h"
15 #include "clang/ASTMatchers/ASTMatchersInternal.h"
18 namespace ast_matchers {
21 void BoundNodesMap::copyTo(BoundNodesTreeBuilder *Builder) const {
22 for (IDToNodeMap::const_iterator It = NodeMap.begin();
25 Builder->setBinding(It->first, It->second);
29 void BoundNodesMap::copyTo(BoundNodesMap *Other) const {
30 copy(NodeMap.begin(), NodeMap.end(),
31 inserter(Other->NodeMap, Other->NodeMap.begin()));
34 BoundNodesTree::BoundNodesTree() {}
36 BoundNodesTree::BoundNodesTree(
37 const BoundNodesMap& Bindings,
38 const std::vector<BoundNodesTree> RecursiveBindings)
40 RecursiveBindings(RecursiveBindings) {}
42 void BoundNodesTree::copyTo(BoundNodesTreeBuilder* Builder) const {
43 Bindings.copyTo(Builder);
44 for (std::vector<BoundNodesTree>::const_iterator
45 I = RecursiveBindings.begin(),
46 E = RecursiveBindings.end();
48 Builder->addMatch(*I);
52 void BoundNodesTree::visitMatches(Visitor* ResultVisitor) {
53 BoundNodesMap AggregatedBindings;
54 visitMatchesRecursively(ResultVisitor, AggregatedBindings);
58 visitMatchesRecursively(Visitor* ResultVisitor,
59 const BoundNodesMap& AggregatedBindings) {
60 BoundNodesMap CombinedBindings(AggregatedBindings);
61 Bindings.copyTo(&CombinedBindings);
62 if (RecursiveBindings.empty()) {
63 ResultVisitor->visitMatch(BoundNodes(CombinedBindings));
65 for (unsigned I = 0; I < RecursiveBindings.size(); ++I) {
66 RecursiveBindings[I].visitMatchesRecursively(ResultVisitor,
72 BoundNodesTreeBuilder::BoundNodesTreeBuilder() {}
74 void BoundNodesTreeBuilder::addMatch(const BoundNodesTree& Bindings) {
75 RecursiveBindings.push_back(Bindings);
78 BoundNodesTree BoundNodesTreeBuilder::build() const {
79 return BoundNodesTree(Bindings, RecursiveBindings);
82 } // end namespace internal
83 } // end namespace ast_matchers
84 } // end namespace clang