[cfe-dev] Trouble to use MatchFinder::match
Aleksei Sidorin via cfe-dev
cfe-dev at lists.llvm.org
Mon May 1 01:10:36 PDT 2017
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::MatchFindermatcherFinder;
>
> matcherFinder.addMatcher(binaryOperatorMatcher,newMatchCallback(
>
> [&cleanListField](cla::MatchFinder::MatchResultconst& matchRes)
>
> {
>
> autobinaryOperator =
> 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 <http://www.castsoftware.com/>| Gain visibility
> into application quality to proactively manage risk and improve team
> performance.
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
--
Best regards,
Aleksei Sidorin,
SRR, Samsung Electronics
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170501/49d958d2/attachment.html>
More information about the cfe-dev
mailing list