Using AST nodes with clang dynamic matchers


I'm building a tool to find AST nodes according to an user provided file using a custom language. I'm also using clang dynamic matchers to find interesting nodes within functions CFG and do a bunch of thing. I would like to re-use one of the node I found previously in one of the clang matchers.

There is equalsNode for static matchers but it obviously does not work with clang dynamic matchers.

My idea would be to circumvent the problem by introducing into the matcher (once created from the string) already bounded nodes and use equalsBoundNode. But I can't find a way to do it.

This could be handy to re-use in clang-query one match result into another one (some kind of persistent matching)

Do you see another way to achieve what I wish to ?

My last resort will be to change clang source code (assuming I'm successful) and let my tool rely on it but I would really like to stick to vanilla clang.



+Sam for ideas


I found a way to to what I want using Parser::NamedValueMap. The following code works well

struct CALLBACK : public clang::ast_matchers::MatchFinder::MatchCallback {``` //… }; int main() { // V is a visitor and v.fct is a CXXMethodDecl*`

dynamic::Diagnostics Diag;
Parser::NamedValueMap named_map;

auto eq_node = equalsNode(v.fct);

named_map["TEST"] = VariantMatcher::SingleMatcher(eq_node);

Optional<DynTypedMatcher> unbound_matcher = Parser::parseMatcherExpression(
llvm::StringRef("cxxMemberCallExpr(callee(TEST))"), nullptr, &named_map,
if (!unbound_matcher) {
std::cout << "erreur creation unbind"
<< "\n";

auto final_matcher = unbound_matcher->tryBind("pipo");

ast_matchers::MatchFinder Finder;
Finder.addDynamicMatcher(*final_matcher, &cb);