[cfe-dev] ignoring*() and hasParent() matchers

Michael Jabbour via cfe-dev cfe-dev at lists.llvm.org
Thu Jul 5 14:50:22 PDT 2018


I ended up writing my matcher like this:

integerLiteral(
  expr().bind("literal"),       //inline bind call using a redundant
node matcher
  hasAncestor(                  //climb up the AST to the nearest
varDeclancestor
   
varDecl(hasInitializer(ignoringParenCasts(equalsBoundNode("literal"))))   
//check that this varDecl satisfies the original condition
  )
)

Any feedback is appreciated, as I am completely new to LibTooling...

P.S.: The actual matcher I am working on is far more complicated.
Inverting it (i.e. using my very first example) would result in much
more difficult problems. Although this seems like a roundabout hack, it
might be effective when nested inside matchers that have already been tested

Thanks,

Mike


On 05/07/2018 7:31 PM, Michael Jabbour wrote:
>
> Hello all,
>
> When using has*() it is sometimes desirable to use
> ignoringParenCasts(), for example (from the docs):
>
> varDecl(hasInitializer(ignoringParenCasts(integerLiteral())))
>
> Is there any way to get the same effect when hasParent(), e.g.:
>
> integerLiteral(hasParent(ignoringParenCasts(varDecl())))
>
> Obviously this does not work, but what is the best way to achieve a
> similar effect?
>
> cheers,
>
> Mike
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180706/fad4f67f/attachment.html>


More information about the cfe-dev mailing list