[cfe-dev] how to implement "statement P is followed by statement Q" matcher?

Gabor Kozar kozargabor at fastmail.fm
Thu May 28 02:41:27 PDT 2015

I don't think you'd really be able to do this with matchers without
major modifications to the matcher architecture.

Your best bet would be - I believe - to only have the ifStmt(...) as
your matcher, and do the "isFollowedBy" logic in the callback. You'll
also need to bind the containing CompoundStmt.

Best regards,

Gábor 'ShdNx' Kozár http://gaborkozar.me

On Tue, May 26, 2015, at 21:25, Richard wrote:
> I recently had to go through a bit of manual coding in order to match
> this in clang-tidy:
> if (expr) return true; return false;
> What I really wanted was to be able to write something like this:
> compoundStmt( isFollowedBy( ifStmt(
> hasThen(returnStmt(has(booleanLiteral(equals(true))))),
> unless(hasElse(anything()))),
> returnStmt(has(booleanLiteral(equals(false)))) ) )
> There are matchers that tell me if a compound statment has **any**
> substatement, but there aren't any matchers that allow me to specify
> the order in which related statements appear within a compound
> statement.
> (Aside: note the heavy-handed use of the has() matcher above on a
> returnStmt. There's no way to access the return expression directly on
> a returnStmt.)
> In my case I really needed an "isFollowedBy" style matcher, because I
> didn't want to match this:
> if (expr) return true; doSomethingElse(); return false;
> However, I can easily see people wanting to match a compound statement
> that has two related statements in a particular order, but possibly
> with other statements in between.
> I'm interested in hearing thoughts on such a squential matcher
> "isFollowedBy" and how I would implement such a thing. So far my
> forays into matchers have been really small and I haven't yet learned
> the subtleties or the full vocabulary of the matcher macros.
> PS: Mail filters are blocking my messages, so ignore this, its only
>     for them. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
>     Phasellus consequat ullamcorper mollis. Sed blandit semper tortor
>     ultricies dictum. Proin hendrerit et quam in sagittis. Maecenas
>     vel blandit ante, in auctor sem. Phasellus condimentum leo vel
>     finibus viverra. Duis fermentum sollicitudin est, ac iaculis
>     lectus auctor vel. Nam condimentum nulla feugiat, venenatis nibh
>     a, elementum nulla. Nulla vitae malesuada eros. Nulla cursus
>     maximus ligula non hendrerit.
> Curabitur lobortis nulla vel sapien posuere, id aliquam orci bibendum.
> Vestibulum at vulputate risus. Proin in purus commodo, tempus lectus
> vitae, faucibus nunc. Aenean congue faucibus elit, sit amet facilisis
> nibh ultrices eget. Nam pulvinar leo ac nunc ultricies, nec tincidunt
> nulla tincidunt. Etiam placerat felis tellus, ut ultricies nunc
> ultricies quis. In placerat sapien nec ultricies mattis. Integer sed
> tempor orci, ac imperdiet orci. Integer ac augue et augue convallis
> faucibus.
> --
> "The Direct3D Graphics Pipeline" free book
> <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum
> <http://ComputerGraphicsMuseum.org> The Terminals Wiki
> <http://terminals.classiccmp.org> Legalize Adulthood! (my blog)
> <http://LegalizeAdulthood.wordpress.com>
> _________________________________________________
> 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/20150528/86c2cf75/attachment.html>

More information about the cfe-dev mailing list