<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">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.<br>
<br>
28.04.2017 19:37, Anthony Lefort via cfe-dev пишет:<br>
</div>
<blockquote
cite="mid:D558136F0D05A5449E7712778DA0D5E02210CD7A@EXCH1.corp.castsoftware.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:"Arial Narrow";
panose-1:2 11 6 6 2 2 2 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m a software developer and in my company
we use clang to parse c++ code.<o:p></o:p></p>
<p class="MsoNormal">I’m in trouble to go to a call back when
I’m using an AST matcher.<o:p></o:p></p>
<p class="MsoNormal">Here is the problem:<o:p></o:p></p>
<p class="MsoNormal">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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here a sample of a source code<o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">clang::ast_matchers::</span><span
style="font-size:9.5pt;font-family:Consolas;color:#4EC9B0">MatchFinder</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">matcherFinder;</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">matcherFinder.addMatcher(binaryOperatorMatcher</span><span
style="font-size:9.5pt;font-family:Consolas;color:#B4B4B4">,</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:#569CD6">new</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:#4EC9B0">MatchCallback</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">(</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">[&cleanListField](cla::</span><span
style="font-size:9.5pt;font-family:Consolas;color:#4EC9B0">MatchFinder</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">::</span><span
style="font-size:9.5pt;font-family:Consolas;color:#4EC9B0">MatchResult</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:#569CD6">const</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">&
matchRes)</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">{</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:#569CD6">auto</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">binaryOperator
= matchRes.Nodes.getNodeAs<clang::</span><span
style="font-size:9.5pt;font-family:Consolas;color:#4EC9B0">Stmt</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">>(binaryOperatorNode);</span><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">binaryOperator->dumpColor();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:black">
}));<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:black">
matcherFinder.match((*constructor),
constructor->getASTContext());<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.5pt;font-family:Consolas;color:gainsboro">
</span><span
style="font-size:9.5pt;font-family:Consolas;color:#57A64A">//matcherFinder.matchAST(constructor->getASTContext());<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.5pt;font-family:Consolas;color:#57A64A"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">As we can see in
the example, the subtree root is a
clang::CXXConstructorDecl.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">Thanks you in
advance.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">Best regards.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><span
style="font-size:9.0pt;font-family:"Arial
Narrow",sans-serif" lang="EN-GB">Anthony LEFORT</span></b><span
style="font-size:9.0pt;font-family:"Arial
Narrow",sans-serif" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:7.5pt;font-family:"Arial",sans-serif;color:gray"
lang="EN-GB">Software engineer</span><span
style="font-size:12.0pt;font-family:"Times New
Roman",serif" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:7.5pt;font-family:"Arial",sans-serif;color:gray"
lang="EN-GB">3 rue Marcel Allégot</span><span lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:7.5pt;font-family:"Arial",sans-serif;color:gray"
lang="EN-GB">92190 Meudon - France</span><span lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:7.5pt;font-family:"Arial",sans-serif"
lang="EN-GB">CAST,
<span style="color:gray">Leader in Automated Application
Intelligence</span><o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:7.5pt;font-family:"Arial",sans-serif;color:gray"
lang="EN-GB">Achieve Insight. Deliver Excellence.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:12.0pt;font-family:"Times New
Roman",serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:8.0pt;font-family:"Arial",sans-serif"
lang="FR"><a moz-do-not-send="true"
href="http://www.castsoftware.com/"><span
style="font-size:7.5pt;font-family:"Calibri",sans-serif;color:purple"
lang="EN-GB">www.castsoftware.com</span></a></span><span
lang="FR">
</span><span
style="font-size:8.0pt;font-family:"Arial",sans-serif;color:gray"
lang="EN-GB">|
</span><span
style="font-size:7.5pt;font-family:"Arial",sans-serif;color:gray"
lang="EN-GB">Gain visibility into application quality to
proactively manage risk and improve team performance.</span><span
style="font-size:8.0pt;font-family:"Arial",sans-serif;color:gray"
lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br>
<p><br>
</p>
<pre class="moz-signature" cols="72">--
Best regards,
Aleksei Sidorin,
SRR, Samsung Electronics
</pre>
</body>
</html>