2012-07-06 13:48:52 +08:00
|
|
|
//===--- ASTMatchersInternal.cpp - Structural query framework -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Implements the base layer of the matcher framework.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/ASTMatchers/ASTMatchers.h"
|
|
|
|
#include "clang/ASTMatchers/ASTMatchersInternal.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace ast_matchers {
|
|
|
|
namespace internal {
|
|
|
|
|
2012-08-29 07:26:39 +08:00
|
|
|
void BoundNodesMap::copyTo(BoundNodesTreeBuilder *Builder) const {
|
|
|
|
for (IDToNodeMap::const_iterator It = NodeMap.begin();
|
|
|
|
It != NodeMap.end();
|
|
|
|
++It) {
|
2012-08-31 03:41:06 +08:00
|
|
|
Builder->setBinding(It->first, It->second);
|
2012-08-29 07:26:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoundNodesMap::copyTo(BoundNodesMap *Other) const {
|
2012-11-17 02:39:22 +08:00
|
|
|
for (IDToNodeMap::const_iterator I = NodeMap.begin(),
|
|
|
|
E = NodeMap.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
Other->NodeMap[I->first] = I->second;
|
|
|
|
}
|
2012-08-29 07:26:39 +08:00
|
|
|
}
|
|
|
|
|
2012-07-06 13:48:52 +08:00
|
|
|
BoundNodesTree::BoundNodesTree() {}
|
|
|
|
|
|
|
|
BoundNodesTree::BoundNodesTree(
|
2012-08-29 07:26:39 +08:00
|
|
|
const BoundNodesMap& Bindings,
|
2012-07-06 13:48:52 +08:00
|
|
|
const std::vector<BoundNodesTree> RecursiveBindings)
|
2012-08-29 07:26:39 +08:00
|
|
|
: Bindings(Bindings),
|
2012-07-06 13:48:52 +08:00
|
|
|
RecursiveBindings(RecursiveBindings) {}
|
|
|
|
|
|
|
|
void BoundNodesTree::copyTo(BoundNodesTreeBuilder* Builder) const {
|
2012-08-29 07:26:39 +08:00
|
|
|
Bindings.copyTo(Builder);
|
2012-07-06 13:48:52 +08:00
|
|
|
for (std::vector<BoundNodesTree>::const_iterator
|
|
|
|
I = RecursiveBindings.begin(),
|
|
|
|
E = RecursiveBindings.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
Builder->addMatch(*I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoundNodesTree::visitMatches(Visitor* ResultVisitor) {
|
2012-08-29 07:26:39 +08:00
|
|
|
BoundNodesMap AggregatedBindings;
|
2012-11-12 06:14:55 +08:00
|
|
|
visitMatchesRecursively(ResultVisitor, AggregatedBindings);
|
2012-07-06 13:48:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void BoundNodesTree::
|
|
|
|
visitMatchesRecursively(Visitor* ResultVisitor,
|
2012-11-12 06:14:55 +08:00
|
|
|
const BoundNodesMap& AggregatedBindings) {
|
|
|
|
BoundNodesMap CombinedBindings(AggregatedBindings);
|
|
|
|
Bindings.copyTo(&CombinedBindings);
|
2012-07-06 13:48:52 +08:00
|
|
|
if (RecursiveBindings.empty()) {
|
2012-11-12 06:14:55 +08:00
|
|
|
ResultVisitor->visitMatch(BoundNodes(CombinedBindings));
|
2012-07-06 13:48:52 +08:00
|
|
|
} else {
|
|
|
|
for (unsigned I = 0; I < RecursiveBindings.size(); ++I) {
|
|
|
|
RecursiveBindings[I].visitMatchesRecursively(ResultVisitor,
|
2012-11-12 06:14:55 +08:00
|
|
|
CombinedBindings);
|
2012-07-06 13:48:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundNodesTreeBuilder::BoundNodesTreeBuilder() {}
|
|
|
|
|
|
|
|
void BoundNodesTreeBuilder::addMatch(const BoundNodesTree& Bindings) {
|
|
|
|
RecursiveBindings.push_back(Bindings);
|
|
|
|
}
|
|
|
|
|
|
|
|
BoundNodesTree BoundNodesTreeBuilder::build() const {
|
2012-08-29 07:26:39 +08:00
|
|
|
return BoundNodesTree(Bindings, RecursiveBindings);
|
2012-07-06 13:48:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace internal
|
|
|
|
} // end namespace ast_matchers
|
|
|
|
} // end namespace clang
|