[cfe-dev] AST Matcher for Decl subclass CilkSpawnDecl

Georg Altmann georg.altmann at informatik.stud.uni-erlangen.de
Tue Nov 18 06:31:30 PST 2014


I am working on a modified version of clang for Intel Cilk Plus, from
based on clang 3.4.

They added

class CilkSpawnDecl : public Decl {
  // ...
  // ...
  /// \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

| `-CilkSpawnExpr
|   |-CilkSpawnDecl
|   | `-CapturedStmt
|   |   |-CapturedDecl
|   |   | `-ImplicitParamDecl
|   |   |-ExprWithCleanups
|   |   | `-CallExpr
------------^ this guy

which does not seem to be possible without a customized matcher for

I would like to define a AST Traversal Matcher, so I can do something
like this

      ^ 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;
    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?



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141118/b80cf74c/attachment.sig>

More information about the cfe-dev mailing list