[cfe-dev] Basic source-to-source transformation with Clang

Satya Prakash Prasad satyaprakash.prasad at gmail.com
Fri Jun 22 03:06:16 PDT 2012

Thanks John for the clarification.

Can you please let me know how to then create clang instance for C++ input file?

Also I am trying to write a code that would detect regular statements"

    bool VisitStmt(Stmt *s) {
        if (isa<CompoundStmt>(s)) {
                CompoundStmt *S = cast<CompoundStmt>(s);
                for (CompoundStmt::body_iterator  I = S->body_begin(),
E = S->body_end(); I != E; ++I)
                        Stmt *i =  cast<Stmt>(*I);
                        std::cout << i->getStmtClassName();

For a sample C++ code like below:

int main()
        int i = 0;
        int y,z;
        printf("y = [%d] z = [%d]\n", y , z); //regular code
        return 0;

But it is not giving any output? So how do we detect what typeof
statement we are processing?

Thanks in advance.


On Fri, Jun 22, 2012 at 6:47 AM, John McCall <rjmccall at apple.com> wrote:
> On Jun 20, 2012, at 1:15 AM, Satya Prakash Prasad wrote:
>> Thanks for your response but I am using g++ compiler:
>> g++ rewritersample.cpp -fno-rtti -D__STDC_LIMIT_MACROS
>> -D__STDC_CONSTANT_MACROS -o rewritersample \
>>                -Illvm/build/include <paths>
>> -Lllvm/build/Release+Asserts/lib(s)
>> Is there any compiler option that I need to add?
>> Please let me know how to overcome the problem?
> I meant that the clang instance your program creates is compiling its input as C,
> not that you are compiling your program as C.
> John.

More information about the cfe-dev mailing list