[cfe-dev] AST Matcher for Decl subclass CilkSpawnDecl
Manuel Klimek
klimek at google.com
Tue Nov 18 07:29:04 PST 2014
On Tue Nov 18 2014 at 3:42:46 PM Georg Altmann <
georg.altmann at informatik.stud.uni-erlangen.de> wrote:
> Hi,
>
> I am working on a modified version of clang for Intel Cilk Plus, from
> https://github.com/cilkplus
> based on clang 3.4.
>
> They added
>
> class CilkSpawnDecl : public Decl {
> // ...
> public:
> // ...
> /// \brief Returns the associated CapturedStmt.
> CapturedStmt *getCapturedStmt() { return CapturedSpawn; }
> const CapturedStmt *getCapturedStmt() const { return CapturedSpawn; }
> // ...
> };
>
> However there don't seem to be any releated AST matchers and I need to
> match
>
> |-CompoundStmt
> | `-CilkSpawnExpr
> | |-CilkSpawnDecl
> | | `-CapturedStmt
> | | |-CapturedDecl
> | | | `-ImplicitParamDecl
> | | |-ExprWithCleanups
> | | | `-CallExpr
> ------------^ this guy
>
> which does not seem to be possible without a customized matcher for
> CilkSpawnDecl.
>
> I would like to define a AST Traversal Matcher, so I can do something
> like this
>
> compoundStmt(
> has(cilkSpawnExpr(
> has(cilkSpawnDecl(
> hasCapturedStmt(
> ^ has(exprWithCleanups(has(callExpr))))))))
> `-- How?
>
>
> I already defined cilkSpawnExpr and cilkSpawnDecl by using
> VariadicDynCastAllOfMatcher which is working great.
> Yet, I still need hasCapturedStmt and I can't get my head around the AST
> matcher internals. I guess, I somehow need to define a matcher that
> takes a CilkSpawnDecl node and returns true if getCapturedStmt() != 0, e.g.
>
> match(CilkSpawnDecl const& spawnDecl) {
> if (spawnDecl.getCapturedStmt())
> return true;
> else
> return false;
> }
>
> But how do I define hasCapturedStmt() so that has(exprWithCleanups(...))
> can act on the children of CapturedStmt?
> I.e. how does an AST matcher hand down the list of children to the
> following matcher expressions?
>
> I looked at the macro AST_MATCHER_P but I'm unsure about ParamType,
> ASTMatchFinder and BoundNodesTreeBuilder. Can I use that?
>
Yes. Take a look at for example:
http://reviews.llvm.org/diffusion/L/browse/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h;222237$3536
AST_MATCHER_P(ElaboratedType, hasQualifier,
internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
if (const NestedNameSpecifier *Qualifier = Node.getQualifier())
return InnerMatcher.matches(*Qualifier, Finder, Builder);
return false;
}
You basically want to adapt this to your use case...
>
> Thanks!
>
> Georg
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141118/1e0e178b/attachment.html>
More information about the cfe-dev
mailing list