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 for (IDToNodeMap::const_iterator I = NodeMap.begin(),
33 Other->NodeMap[I->first] = I->second;
37 BoundNodesTree::BoundNodesTree() {}
39 BoundNodesTree::BoundNodesTree(
40 const BoundNodesMap& Bindings,
41 const std::vector<BoundNodesTree> RecursiveBindings)
43 RecursiveBindings(RecursiveBindings) {}
45 void BoundNodesTree::copyTo(BoundNodesTreeBuilder* Builder) const {
46 Bindings.copyTo(Builder);
47 for (std::vector<BoundNodesTree>::const_iterator
48 I = RecursiveBindings.begin(),
49 E = RecursiveBindings.end();
51 Builder->addMatch(*I);
55 void BoundNodesTree::visitMatches(Visitor* ResultVisitor) {
56 BoundNodesMap AggregatedBindings;
57 visitMatchesRecursively(ResultVisitor, AggregatedBindings);
61 visitMatchesRecursively(Visitor* ResultVisitor,
62 const BoundNodesMap& AggregatedBindings) {
63 BoundNodesMap CombinedBindings(AggregatedBindings);
64 Bindings.copyTo(&CombinedBindings);
65 if (RecursiveBindings.empty()) {
66 ResultVisitor->visitMatch(BoundNodes(CombinedBindings));
68 for (unsigned I = 0; I < RecursiveBindings.size(); ++I) {
69 RecursiveBindings[I].visitMatchesRecursively(ResultVisitor,
75 BoundNodesTreeBuilder::BoundNodesTreeBuilder() {}
77 void BoundNodesTreeBuilder::addMatch(const BoundNodesTree& Bindings) {
78 RecursiveBindings.push_back(Bindings);
81 BoundNodesTree BoundNodesTreeBuilder::build() const {
82 return BoundNodesTree(Bindings, RecursiveBindings);
85 } // end namespace internal
86 } // end namespace ast_matchers
87 } // end namespace clang