<html>
<head></head>
<body>
<p>Thank you ver much both of you, it really helps:</p>
<blockquote class="replyBlock" style="border-left: 2px solid #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>All of the ways you cite make sense. What you want really depends on what kind of control you want. Note that you can always easily start with AST matchers to find higher level things you're interested in, and then drill down through the AST nodes by calling the methods or even by using a RecursiveASTVisitor on a node...</div></blockquote><p> Ok, Manuel. I need to study this a bit more to catch on the best way for me, but it's good to know I can merge both strategies.</p>
<blockquote class="replyBlock" style="border-left: 2px solid #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="font-size: 12.727272033691406px;">I have put together quickly the matcher that I believe suits your needs, just so that you can see how it works:<br /><br />namespace clang {<br />namespace ast_matchers {<br /><br />using namespace clang::ast_matchers::internal;<br /><br />AST_MATCHER(CXXConstructorDecl, defaultNonTrivialCtor)<br />{<br />    return Node.isThisDeclarationADefinition()<br />        && Node.isDefaultConstructor()<br />        && (Node.getNumCtorInitializers() != 0 || !Node.hasTrivialBody());<br />}<br /><br />} // ast_matchers<br />} // clang<br /><br /></div><p><span style="font-size: 12.727272033691406px;">(Don't forget to include ASTMatchers.h, ASTMatchersInternal.h and ASTMatchersMacros.h)</span></p>
</blockquote><p>Thank you for your time Gábor. I have put this, but I don't know why it doesn't fetch any nodes at all... Could you test this?</p>
<blockquote class="replyBlock" style="border-left: 2px solid #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="font-size: 12.727272033691406px;">constructorDecl(isDefinition(), parameterCountIs(0),<br />        anyOf(hasAnyConstructorInitializer(anything()), has(compoundStmt(has(stmt())))));</div><div style="font-size: 12.727272033691406px;"><div>(I did a quick test, and seems to work as intended, but you should make sure to test it thoroughly yourself.)</div></div></blockquote><p>I have put this as well and this time does it works, but indeed it needs something more, because if we have:</p>
<p>class A{<br/>
public:<br/>
A(){}<br/>
... <br/>
};</p>
<p>class B: public A{<br/>
public:<br/>
B(){}<br/>
...<br/>
};</p>
<p>An implicit node is detected: the default constructor of class A in the list of constructors in default constructor of class B. So, I tried to fix this doing  this:</p>
<p><span style="font-size: 12.727272033691406px;">constructorDecl(isDefinition(), parameterCountIs(0),</span><br style="font-size: 12.727272033691406px;" /><span style="font-size: 12.727272033691406px;">        anyOf(hasAnyConstructorInitializer(<strong>unless(withInitializer(constructorDecl(isImplicit())))</strong>)), has(compoundStmt(has(stmt())))));</span></p>
<p><span style="font-size: 12.727272033691406px;">But, I newbie in this and it doesn't work as constructorDecl returns a Decl and withInitializer a Expr (i think). How could I do this? Sorry for this, but I would like to have at least an example complete. </span></p>
<p><span style="font-size: 12.727272033691406px;">In addition, I would like to work only with the code that is explicit and for example when I try to match "methodDecl(isOverride())" a lot of implicit </span><span style="font-size: 12.727272033691406px;">methods</span><span style="font-size: 12.727272033691406px;">  </span><span style="font-size: 12.727272033691406px;">(and even methods from other files apart of mine) are detected with this matcher. How can I avoid this?</span></p>
<p><span style="font-size: 12.727272033691406px;">Thanks,</span></p>
<p><span style="font-size: 12.727272033691406px;">Pedro.</span></p>
<div><em>El dia 19 abr 2013 13:50, Manuel Klimek <klimek@google.com> escribió:</em></div><blockquote class="replyBlock" style="border-left: 2px solid #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr">On Fri, Apr 19, 2013 at 12:18 PM, Pedro Delgado Perez <span dir="ltr"><<a href="mailto:pedro.delgadoperez@mail.uca.es" target="_blank">pedro.delgadoperez@mail.uca.es</a>></span> wrote:<br /><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0 0 0 .8ex; border-left: 1px #ccc solid; padding-left: 1ex;"><div><p>Hi again,</p>
<p>Well, I've just understood that not all the methods in a class have a matcher related. For instance, I'm trying to match the default constructor declaration of a class:</p>
<p>class Foo {<br />public:<br /><strong>Foo(){}</strong><br />Foo(int a){... ...}<br />}</p>
<br/>
<p>And in CXXConstructorDecl we have isDefaultConstructor(), but I can't find an AST_MATCHER to do this. So, I suppose I would have to implement a new AST_MATCHER like this:</p>
<p><em>AST_MATCHER(CXXConstructorDecl, isDefaultConstructor){</em><br /><em>return Node.isDefaultConstructor();</em><br /><em>}</em></p>
<p>Wouldn't it? But, this happens often, so... would you recommend me use AST_MATCHERS? Or it would be better to do something like it is explained in <a href="http://clang.llvm.org/docs/RAVFrontendAction.html" target="_blank">http://clang.llvm.org/docs/RAVFrontendAction.html</a> ? This way, I can directly use the methods in the classes. For instance:</p>
<pre style="overflow-x: auto; overflow-y: hidden; border: thin dotted #0c3762; margin: 0px 0px 12px; padding: 0.8em; background-color: #f0f0f0; color: #333333;"> bool VisitCXXConstructorDecl(CXXConstructorDecl *Declaration) {    if (Declaration->isDefaultConstructor()) {</pre><p>I have to visit a lot of kind of nodes with different features, not only this. </p>
</div></blockquote><div>All of the ways you cite make sense. What you want really depends on what kind of control you want. Note that you can always easily start with AST matchers to find higher level things you're interested in, and then drill down through the AST nodes by calling the methods or even by using a RecursiveASTVisitor on a node...</div><div>Cheers,</div><div>/Manuel</div><div> </div><blockquote class="gmail_quote" style="margin: 0 0 0 .8ex; border-left: 1px #ccc solid; padding-left: 1ex;"><div><p>Please, I need a path to get down to work.</p>
<p>Thanks in advance,</p>
<div class="im"><p>Pedro.</p>
<br/>
<div><em>El dia 19 abr 2013 01:58, Gábor Kozár <<a href="mailto:kozargabor@gmail.com" target="_blank">kozargabor@gmail.com</a>> escribió:</em></div><blockquote style="border-left: 2px solid #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr"><div><div><div>Hi,<br /><br /></div><p>What version are you using? The matchers isOverride() and isVirtual() I know for certain were not in version 3.2, and can only be found on SVN (in this file: <a href="http://llvm.org/svn/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h" target="_blank">http://llvm.org/svn/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h</a>).</p>
</div><p>Nonetheless, you can implement them all very easily manually, or just indeed copy their implementation from the link above. Also, instead of isDefaultConstructor(), you could use argumentCountIs(0).</p>
</div><p>Gabor</p>
</div><div class="gmail_extra"><br /><br /><div class="gmail_quote">2013/4/18 Pedro Delgado Perez <span dir="ltr"><<a href="mailto:pedro.delgadoperez@mail.uca.es" target="_blank">pedro.delgadoperez@mail.uca.es</a>></span><br /><blockquote class="gmail_quote" style="margin: 0 0 0 .8ex; border-left: 1px #ccc solid; padding-left: 1ex;"><div><p>Hi,</p>
<p>I'm newbie using ASTMatchers and I'm trying to learn little by little how to use them.</p>
<p>I was basing on the matcher <span style="color: #333333; font-family: monospace; font-size: 12px; line-height: 17px; text-align: justify;">recordDecl(hasName("Foo"),</span><span style="color: #333333; font-family: monospace; font-size: 12px; line-height: 17px; text-align: justify; background-color: #e2e2e2;"> </span><span style="color: #333333; font-family: monospace; font-size: 12px; line-height: 17px; text-align: justify;">isDerivedFrom("Bar")) </span>shown in <a href="http://clang.llvm.org/docs/LibASTMatchers.html" target="_blank">http://clang.llvm.org/docs/LibASTMatchers.html</a> trying to include new features. For instance, I tried to look for classes which have at least one virtual method:</p>
<p><span style="color: #333333; font-family: monospace; font-size: 12px; line-height: 17px; text-align: justify;">recordDecl(hasName("Foo"),</span><span style="color: #333333; font-family: monospace; font-size: 12px; line-height: 17px; text-align: justify; background-color: #e2e2e2;"> </span><span style="color: #333333; font-family: monospace; font-size: 12px; line-height: 17px; text-align: justify;">isDerivedFrom("Bar"), hasMethod(isVirtual()))</span></p>
<p>Or I tried to match protected overriden methods:</p>
<p><span style="color: #333333; font-family: monospace; font-size: 12px; line-height: 17px; text-align: justify;">methodDecl(allOf(isProtected(), isOverride()</span><span style="color: #333333; font-family: monospace; font-size: 12px; line-height: 17px; text-align: justify;">);</span></p>
<p>But neither of them worked as it couldn't find "isOverride" and "isVirtual" identifiers. I was trying a lot of combinations, but I can't understand this well.</p>
<p>Finally, I tried to look for the the default constructor of a certain class:</p>
<p><span style="color: #333333; font-family: monospace; font-size: 12px; line-height: 17px; text-align: justify;">constructorDecl(hasName("Foo"), isDefaultConstructor())</span></p>
<p>but this is wrong. What I'm doing bad? Please, any information you give me will be fine to me to understand how to use matchers.</p>
<p>Thanks in advance,</p>
<p>Pedro.</p>
<br/>
</div><br/>
<p>_______________________________________________<br />cfe-dev mailing list<br /><a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a></p>
</blockquote></div></div><p><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a></p>
</blockquote></div></div><br/>
<p>_______________________________________________<br/>
cfe-dev mailing list<br/>
cfe-dev@cs.uiuc.edu</p>
</blockquote></div></div></div><p><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a></p>
</blockquote>
</body>
</html>