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

Richard legalize at xmission.com
Thu May 28 08:19:42 PDT 2015

In article <1432806087.2498925.280264065.1368E918 at webmail.messagingengine.com>,
    Gabor Kozar <kozargabor at fastmail.fm> writes:

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

Why do you say that?  All the information is available from within
CompoundStmt provided I have the other two matchers.  That's what I
currently do now in the callback -- walk the CompoundStmt looking for
the two consecutive statements that match my criteria (simplified and
hard-coded for my case):

  CompoundStmt::const_body_iterator BeforeIt = Compound->body_begin();
  CompoundStmt::const_body_iterator AfterIt = Compound->body_begin();
  for (++AfterIt;
       AfterIt != Compound->body_end() && *BeforeIt != Ret;
       ++BeforeIt, ++AfterIt) {
    if (auto *If = dyn_cast<IfStmt>(*BeforeIt)) {
      if (*AfterIt == Ret) {
        // ...

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
"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>

More information about the cfe-dev mailing list