[cfe-dev] Using AST nodes with clang dynamic matchers
David Come via cfe-dev
cfe-dev at lists.llvm.org
Tue Mar 14 08:35:19 PDT 2017
Hello,
I found a way to to what I want usingParser::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,
&Diag);
if (!unbound_matcher) {
std::cout << "erreur creation unbind"
<< "\n";
}
auto final_matcher = unbound_matcher->tryBind("pipo");
ast_matchers::MatchFinder Finder;
CALLBACK cb;
Finder.addDynamicMatcher(*final_matcher, &cb);
Finder.matchAST(ast_context);
}
David
On 09/03/2017 10:20, Manuel Klimek wrote:
> +Sam for ideas
>
> On Wed, Mar 8, 2017 at 6:23 PM David Come via cfe-dev
> <cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>> wrote:
>
> Hello,
>
> 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.
>
>
> Thanks,
>
> David.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170314/686cbca6/attachment.html>
More information about the cfe-dev
mailing list