[cfe-dev] Basic source-to-source transformation with Clang
Satya Prakash Prasad
satyaprakash.prasad at gmail.com
Fri Jul 6 05:33:12 PDT 2012
Thanks for the information as provided, but I get output like below:
(CallExpr 0x1a85c480 'int'
(ImplicitCastExpr 0x1a85c468 'int (*)(const char *restrict, ...)'
<FunctionToPointerDecay>
(DeclRefExpr 0x1a85c3e8 'int (const char *restrict, ...)' lvalue
Function 0x1a84e8e0 'printf' 'int (const char *restrict, ...)'))
(ImplicitCastExpr 0x1a85c4b8 'const char *' <ArrayToPointerDecay>
(StringLiteral 0x1a85c388 'const char [13]' lvalue "In inc [%d]\n"))
(ImplicitCastExpr 0x1a85c4d0 'int' <LValueToRValue>
(DeclRefExpr 0x1a85c3c0 'int' lvalue ParmVar 0x1a85c100 'p' 'int &')))
Kindly note that my requirement is to print the C++ code itself like
dumpAll() method generated for above for below C++ code:
p++;
Similarly for other like:
dumpAll()
(CallExpr 0x1a85dec8 'int'
(ImplicitCastExpr 0x1a85deb0 'int (*)(const char *restrict, ...)'
<FunctionToPointerDecay>
(DeclRefExpr 0x1a85de88 'int (const char *restrict, ...)' lvalue
Function 0x1a84e8e0 'printf' 'int (const char *restrict, ...)'))
(ImplicitCastExpr 0x1a85df08 'const char *' <ArrayToPointerDecay>
(StringLiteral 0x1a85cdd8 'const char [19]' lvalue "y = [%d] z = [%d]\n"))
(ImplicitCastExpr 0x1a85df20 'int' <LValueToRValue>
(DeclRefExpr 0x1a85ce18 'int' lvalue Var 0x1a85c6f0 'y' 'int'))
(ImplicitCastExpr 0x1a85df38 'int' <LValueToRValue>
(DeclRefExpr 0x1a85de60 'int' lvalue Var 0x1a85c760 'z' 'int')))
While C++ Code:
printf("y = [%d] z = [%d]\n", y , z);
Thanks in advance.
Regards,
Prakash
On Fri, Jul 6, 2012 at 4:22 PM, Manuel Klimek <klimek at google.com> wrote:
> On Fri, Jul 6, 2012 at 12:25 PM, Satya Prakash Prasad
> <satyaprakash.prasad at gmail.com> wrote:
>>
>> I made some progress with whatever support I received from this
>> discussion forum. Thanks to all who responded to my request. My
>> requirement now is to find a way I can print CLANG AST code to C++ / C
>> human readable 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);
>> //How can I print the C++ / C statement which
>> CLANG is processing
>
>
> You can use i->dumpAll() if you want to see what's going on.
>
> Cheers,
> /Manuel
>
>>
>> }
>> }
>>
>> return true;
>> }
>>
>> Regards,
>> Prakash
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
More information about the cfe-dev
mailing list