[cfe-dev] searching for nested for-loops

Anja Gerbes anja.gerbes at googlemail.com
Fri Jul 11 14:13:05 PDT 2014


Hi all,

i have a question. This Code finds all For-Loop in a Cpp-File and gives
LIKWID_MARKER_START(); and LIKWID_MARKER_STOP(); as output.

Now i want to search inside a for loop for nested for loops if this will
find a nested forloop i dont want to set the text.

i just want to set the text in the outer for loop, not the inner for loop.

How i can do that in clang?


    bool VisitStmt(Stmt *s) {

        if (isa<ForStmt>(s))
        {

        ForStmt *ForStatement = cast<ForStmt>(s);
        SourceLocation ST = ForStatement->getSourceRange().getBegin();
           stringstream SSBefore;
           SSBefore << "LIKWID_MARKER_START();\n";

           TheRewriter.InsertText(ST, SSBefore.str(), true, true);

            stringstream SSAfter;
            ST = ForStatement->getLocEnd().getLocWithOffset(1);
            SSAfter << "\nLIKWID_MARKER_STOP();";

            TheRewriter.InsertText(ST, SSAfter.str(), true, true);
        }

    }

Bye
Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140711/7c08188a/attachment.html>


More information about the cfe-dev mailing list