<div class="gmail_quote">On Wed Nov 19 2014 at 3:38:44 PM Georg Altmann <<a href="mailto:georg.altmann@informatik.stud.uni-erlangen.de">georg.altmann@informatik.stud.uni-erlangen.de</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you for the quick reply.<br>
<br>
I found a partial solution to my problem. I dug down into the AST<br>
matching code and noticed RecursiveASTVisitor did not recurse into<br>
CapturedStmt in CilkSpawnDecl. So I did the patch<br>
<br>
<br>
diff --git a/include/clang/AST/<u></u>RecursiveASTVisitor.h<br>
b/include/clang/AST/<u></u>RecursiveASTVisitor.h<br>
index 35eec69..a16e772 100755<br>
--- a/include/clang/AST/<u></u>RecursiveASTVisitor.h<br>
+++ b/include/clang/AST/<u></u>RecursiveASTVisitor.h<br>
@@ -1305,6 +1305,7 @@ DEF_TRAVERSE_DECL(<u></u>CapturedDecl, {<br>
   })<br>
<br>
 DEF_TRAVERSE_DECL(<u></u>CilkSpawnDecl, {<br>
+    TRY_TO(TraverseStmt(D-><u></u>getCapturedStmt()));<br>
   })<br>
<br>
 DEF_TRAVERSE_DECL(EmptyDecl, { })<br>
<br>
<br>
Again, this is what I want to match:<br>
The AST:<br>
|-CompoundStmt<br>
| `-CilkSpawnExpr<br>
|   |-CilkSpawnDecl<br>
|   | `-CapturedStmt<br>
|   |   |-CapturedDecl<br>
|   |   | `-ImplicitParamDecl<br>
|   |   |-ExprWithCleanups<br>
|   |   | `-CallExpr<br>
--------------^ this guy<br>
<br>
<br>
After the patch, these match now:<br>
<br>
// 1) matches<br>
compoundStmt(<br>
  has(cilkSpawnExpr(<br>
   has(cilkSpawnDecl(<br>
     has(capturedStmt()))))))<br>
<br>
// 2) matches and binds<br>
compoundStmt(<br>
  has(cilkSpawnExpr(<br>
    has(cilkSpawnDecl(<br>
      has(capturedStmt(<br>
        hasDescendant(<u></u>exprWithCleanups(<br>
          has(callExpr().bind("callExpr"<u></u>))))))))))<br>
<br>
<br>
However this doesn't match, while it should IMHO.<br>
<br>
// 3) does not match<br>
compoundStmt(<br>
  has(cilkSpawnExpr(<br>
    has(cilkSpawnDecl(<br>
        has(capturedStmt(<br>
            has(exprWithCleanups())))))))<br></blockquote><div><br></div><div>Which one in this chain is the one that doesn't match? (remove inner ones until it matches, send result).</div><div><br></div><div>Cheers,</div><div>/Manuel </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
Notice that I used hasDescendant(<u></u>exprWithCleanups()) in 2) and<br>
has(exprWithCleanups()) in 3).<br>
ExprWithCleanups is a direct child of CapturedStmt. Any clue why 2)<br>
doesn't match?<br>
<br>
Thanks,<br>
Georg<br>
<br>
On 18.11.2014 16:29, Manuel Klimek wrote:<br>
><br>
><br>
> On Tue Nov 18 2014 at 3:42:46 PM Georg Altmann<br>
> <<a href="mailto:georg.altmann@informatik.stud.uni-erlangen.de" target="_blank">georg.altmann@informatik.<u></u>stud.uni-erlangen.de</a><br>
> <mailto:<a href="mailto:georg.altmann@informatik.stud.uni-erlangen.de" target="_blank">georg.altmann@<u></u>informatik.stud.uni-erlangen.<u></u>de</a>>> wrote:<br>
><br>
>     Hi,<br>
><br>
>     I am working on a modified version of clang for Intel Cilk Plus, from<br>
>     <a href="https://github.com/cilkplus" target="_blank">https://github.com/cilkplus</a><br>
>     based on clang 3.4.<br>
><br>
>     They added<br>
><br>
>     class CilkSpawnDecl : public Decl {<br>
>       // ...<br>
>       public:<br>
>       // ...<br>
>       /// \brief Returns the associated CapturedStmt.<br>
>       CapturedStmt *getCapturedStmt() { return CapturedSpawn; }<br>
>       const CapturedStmt *getCapturedStmt() const { return CapturedSpawn; }<br>
>       // ...<br>
>     };<br>
><br>
>     However there don't seem to be any releated AST matchers and I need<br>
>     to match<br>
><br>
>     |-CompoundStmt<br>
>     | `-CilkSpawnExpr<br>
>     |   |-CilkSpawnDecl<br>
>     |   | `-CapturedStmt<br>
>     |   |   |-CapturedDecl<br>
>     |   |   | `-ImplicitParamDecl<br>
>     |   |   |-ExprWithCleanups<br>
>     |   |   | `-CallExpr<br>
>     ------------^ this guy<br>
><br>
>     which does not seem to be possible without a customized matcher for<br>
>     CilkSpawnDecl.<br>
><br>
>     I would like to define a AST Traversal Matcher, so I can do something<br>
>     like this<br>
><br>
>     compoundStmt(<br>
>       has(cilkSpawnExpr(<br>
>         has(cilkSpawnDecl(<br>
>           hasCapturedStmt(<br>
>           ^ has(exprWithCleanups(has(__<u></u>callExpr))))))))<br>
>           `-- How?<br>
><br>
><br>
>     I already defined cilkSpawnExpr and cilkSpawnDecl by using<br>
>     VariadicDynCastAllOfMatcher which is working great.<br>
>     Yet, I still need hasCapturedStmt and I can't get my head around the AST<br>
>     matcher internals. I guess, I somehow need to define a matcher that<br>
>     takes a CilkSpawnDecl node and returns true if getCapturedStmt() !=<br>
>     0, e.g.<br>
><br>
>     match(CilkSpawnDecl const& spawnDecl) {<br>
>       if (spawnDecl.getCapturedStmt())<br>
>         return true;<br>
>       else<br>
>         return false;<br>
>     }<br>
><br>
>     But how do I define hasCapturedStmt() so that has(exprWithCleanups(...))<br>
>     can act on the children of CapturedStmt?<br>
>     I.e. how does an AST matcher hand down the list of children to the<br>
>     following matcher expressions?<br>
><br>
>     I looked at the macro AST_MATCHER_P but I'm unsure about ParamType,<br>
>     ASTMatchFinder and BoundNodesTreeBuilder. Can I use that?<br>
><br>
><br>
> Yes. Take a look at for example:<br>
> <a href="http://reviews.llvm.org/diffusion/L/browse/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h;222237$3536" target="_blank">http://reviews.llvm.org/<u></u>diffusion/L/browse/cfe/trunk/<u></u>include/clang/ASTMatchers/<u></u>ASTMatchers.h;222237$3536</a><br>
> AST_MATCHER_P(ElaboratedType, hasQualifier,<br>
>               internal::Matcher<<u></u>NestedNameSpecifier>, InnerMatcher) {<br>
>   if (const NestedNameSpecifier *Qualifier = Node.getQualifier())<br>
>     return InnerMatcher.matches(*<u></u>Qualifier, Finder, Builder);<br>
><br>
>   return false;<br>
> }<br>
><br>
> You basically want to adapt this to your use case...<br>
><br>
><br>
><br>
>     Thanks!<br>
><br>
>     Georg<br>
><br>
><br>
><br>
><br>
>     ______________________________<u></u>___________________<br>
>     cfe-dev mailing list<br>
>     <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a> <mailto:<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a>><br>
>     <a href="http://lists.cs.uiuc.edu/__mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/__<u></u>mailman/listinfo/cfe-dev</a><br>
>     <<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-dev</a>><br>
><br>
<br>
<br>
<br>
</blockquote></div>