<div class="gmail_quote">On Fri, Jul 6, 2012 at 2:33 PM, Satya Prakash Prasad <span dir="ltr"><<a href="mailto:satyaprakash.prasad@gmail.com" target="_blank">satyaprakash.prasad@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks for the information as provided, but I get output like below:<br>
<br>
(CallExpr 0x1a85c480 'int'<br>
  (ImplicitCastExpr 0x1a85c468 'int (*)(const char *restrict, ...)'<br>
<FunctionToPointerDecay><br>
    (DeclRefExpr 0x1a85c3e8 'int (const char *restrict, ...)' lvalue<br>
Function 0x1a84e8e0 'printf' 'int (const char *restrict, ...)'))<br>
  (ImplicitCastExpr 0x1a85c4b8 'const char *' <ArrayToPointerDecay><br>
    (StringLiteral 0x1a85c388 'const char [13]' lvalue "In inc [%d]\n"))<br>
  (ImplicitCastExpr 0x1a85c4d0 'int' <LValueToRValue><br>
    (DeclRefExpr 0x1a85c3c0 'int' lvalue ParmVar 0x1a85c100 'p' 'int &')))<br>
<br>
Kindly note that my requirement is to print the C++ code itself like<br>
dumpAll() method generated for above for below C++ code:<br></blockquote><div><br></div><div>If you want to print the C++ code that produce the AST, you'll want to get the SourceRange, and use SourceManager's getCharacterData() method to get the underlying data - that will get you the C++ code as it was written by the user.</div>
<div><br></div><div>Cheers,</div><div>/Manuel </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
p++;<br>
<br>
Similarly for other like:<br>
<br>
dumpAll()<br>
<br>
(CallExpr 0x1a85dec8 'int'<br>
  (ImplicitCastExpr 0x1a85deb0 'int (*)(const char *restrict, ...)'<br>
<FunctionToPointerDecay><br>
    (DeclRefExpr 0x1a85de88 'int (const char *restrict, ...)' lvalue<br>
Function 0x1a84e8e0 'printf' 'int (const char *restrict, ...)'))<br>
  (ImplicitCastExpr 0x1a85df08 'const char *' <ArrayToPointerDecay><br>
    (StringLiteral 0x1a85cdd8 'const char [19]' lvalue "y = [%d] z = [%d]\n"))<br>
  (ImplicitCastExpr 0x1a85df20 'int' <LValueToRValue><br>
    (DeclRefExpr 0x1a85ce18 'int' lvalue Var 0x1a85c6f0 'y' 'int'))<br>
  (ImplicitCastExpr 0x1a85df38 'int' <LValueToRValue><br>
    (DeclRefExpr 0x1a85de60 'int' lvalue Var 0x1a85c760 'z' 'int')))<br>
<br>
While C++ Code:<br>
<div class="im HOEnZb"><br>
printf("y = [%d] z = [%d]\n", y , z);<br>
<br>
</div><div class="im HOEnZb">Thanks in advance.<br>
<br>
Regards,<br>
Prakash<br>
<br>
<br>
</div><div class="HOEnZb"><div class="h5">On Fri, Jul 6, 2012 at 4:22 PM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:<br>
> On Fri, Jul 6, 2012 at 12:25 PM, Satya Prakash Prasad<br>
> <<a href="mailto:satyaprakash.prasad@gmail.com">satyaprakash.prasad@gmail.com</a>> wrote:<br>
>><br>
>> I made some progress with whatever support I received from this<br>
>> discussion forum. Thanks to all who responded to my request. My<br>
>> requirement now is to find a way I can print CLANG AST code to C++ / C<br>
>> human readable statements:<br>
>><br>
>>     bool VisitStmt(Stmt *s) {<br>
>>         if (isa<CompoundStmt>(s)) {<br>
>>                 CompoundStmt *S = cast<CompoundStmt>(s);<br>
>>                 for (CompoundStmt::body_iterator  I = S->body_begin(),<br>
>> E = S->body_end(); I != E; ++I)<br>
>>                 {<br>
>>                         Stmt *i =  cast<Stmt>(*I);<br>
>>                         //How can I print the C++ / C statement which<br>
>> CLANG is processing<br>
><br>
><br>
> You can use i->dumpAll() if you want to see what's going on.<br>
><br>
> Cheers,<br>
> /Manuel<br>
><br>
>><br>
>>                 }<br>
>>         }<br>
>><br>
>>         return true;<br>
>>     }<br>
>><br>
>> Regards,<br>
>> Prakash<br>
>><br>
>> _______________________________________________<br>
>> cfe-dev mailing list<br>
>> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
><br>
</div></div></blockquote></div><br>