Using AST nodes with clang dynamic matchers

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using AST nodes with clang dynamic matchers

Sumner, Brian via cfe-dev
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using AST nodes with clang dynamic matchers

Sumner, Brian via cfe-dev
+Sam for ideas

On Wed, Mar 8, 2017 at 6:23 PM David Come via cfe-dev <[hidden email]> 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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using AST nodes with clang dynamic matchers

Sumner, Brian via cfe-dev

Hello,

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,
      &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 <[hidden email]> 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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...