Quantcast

Trouble to use MatchFinder::match

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

Trouble to use MatchFinder::match

Lang Hames via cfe-dev

Hi,

 

I’m a software developer and in my company we use clang to parse c++ code.

I’m in trouble to go to a call back when I’m using an AST matcher.

Here is the problem:

I already use the function “ clang::ast_matchers::MatchFinder::matchAST(ASTContext&)” and it works perfectly. But, in a particular case, I would like to match only within a subtree so I try to use “ clang::ast_matchers::MatchFinder::match(constT &node, ASTContext&)” but I never reach my callback.

 

Here a sample of a source code

        clang::ast_matchers::MatchFinder matcherFinder;

        matcherFinder.addMatcher(binaryOperatorMatcher, new MatchCallback(

            [&cleanListField](cla::MatchFinder::MatchResult const & matchRes)

        {

            auto binaryOperator = matchRes.Nodes.getNodeAs<clang::Stmt>(binaryOperatorNode);

            binaryOperator->dumpColor();

        }));

        matcherFinder.match((*constructor), constructor->getASTContext());

        //matcherFinder.matchAST(constructor->getASTContext());

 

As we can see in the example, the subtree root is a clang::CXXConstructorDecl.

 

Thanks you in advance.

 

Best regards.

 

Anthony LEFORT

Software engineer

3 rue Marcel Allégot

92190 Meudon - France

 

CAST, Leader in Automated Application Intelligence

Achieve Insight. Deliver Excellence.

 

www.castsoftware.com | Gain visibility into application quality to proactively manage risk and improve team performance.

 

 

 

 


_______________________________________________
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: Trouble to use MatchFinder::match

Lang Hames via cfe-dev
If a matcher is applied to concrete AST node instead of the whole context, it matches strictly this given node. To match child nodes, enclose your matcher with hasDescendant() or forEachDescendant() matcher.

28.04.2017 19:37, Anthony Lefort via cfe-dev пишет:

Hi,

 

I’m a software developer and in my company we use clang to parse c++ code.

I’m in trouble to go to a call back when I’m using an AST matcher.

Here is the problem:

I already use the function “ clang::ast_matchers::MatchFinder::matchAST(ASTContext&)” and it works perfectly. But, in a particular case, I would like to match only within a subtree so I try to use “ clang::ast_matchers::MatchFinder::match(constT &node, ASTContext&)” but I never reach my callback.

 

Here a sample of a source code

        clang::ast_matchers::MatchFinder matcherFinder;

        matcherFinder.addMatcher(binaryOperatorMatcher, new MatchCallback(

            [&cleanListField](cla::MatchFinder::MatchResult const & matchRes)

        {

            auto binaryOperator = matchRes.Nodes.getNodeAs<clang::Stmt>(binaryOperatorNode);

            binaryOperator->dumpColor();

        }));

        matcherFinder.match((*constructor), constructor->getASTContext());

        //matcherFinder.matchAST(constructor->getASTContext());

 

As we can see in the example, the subtree root is a clang::CXXConstructorDecl.

 

Thanks you in advance.

 

Best regards.

 

Anthony LEFORT

Software engineer

3 rue Marcel Allégot

92190 Meudon - France

 

CAST, Leader in Automated Application Intelligence

Achieve Insight. Deliver Excellence.

 

www.castsoftware.com | Gain visibility into application quality to proactively manage risk and improve team performance.

 

 

 

 



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


-- 
Best regards,
Aleksei Sidorin,
SRR, Samsung Electronics

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