[cfe-dev] Missing statements in the Clang print AST

Dmitri Gribenko gribozavr at gmail.com
Fri Jan 18 02:46:03 PST 2013


On Fri, Jan 18, 2013 at 12:39 PM, Miguel Aguilar
<miguel.aguilar at ice.rwth-aachen.de> wrote:
> Hi Dimitri,
>
> I wanted to be sure that the functions in the AST have the complete body of
> the original code. By using the -ast-dump I got the following:
>
> void main() (CompoundStmt 0x57fca90 <pc/consumer.cc:28:1, line:42:1>
>   (DeclStmt 0x57fc110 <line:29:3, col:10>
>     (0x57fc030 "int n")
>     (0x57fc0a0 "int j"))
>   (ForStmt 0x57fca50 <line:37:3, line:41:3>
>     (DeclStmt 0x57fc358 <line:37:8, col:15>
>       (0x57fc2e0 "int i =
>         (IntegerLiteral 0x57fc338 <col:14> 'int' 0)"))
>     (<<<NULL>>>)
>     (BinaryOperator 0x57fc3f0 <col:17, col:19> '_Bool' '<'
>       (ImplicitCastExpr 0x57fc3c0 <col:17> 'int' <LValueToRValue>
>         (DeclRefExpr 0x57fc370 <col:17> 'int' lvalue Var 0x57fc2e0 'i'
> 'int'))
>       (ImplicitCastExpr 0x57fc3d8 <col:19> 'int' <LValueToRValue>
>         (DeclRefExpr 0x57fc398 <col:19> 'int' lvalue Var 0x57fc030 'n'
> 'int')))
>     (UnaryOperator 0x57fc440 <col:22, col:23> 'int' postfix '++'
>       (DeclRefExpr 0x57fc418 <col:22> 'int' lvalue Var 0x57fc2e0 'i' 'int'))
>     (CompoundStmt 0x57fc5d0 <line:38:3, line:41:3>)))
>
> However, here I don't see the function call to the "printf" and the
> statement "s = 5". Any ideas?

Did you show us the complete source code file?  Do you get any errors
if you remove -ast-dump?  (For example, errors about undeclared
'printf'?)  If there are errors, then what you see is the AST after
error recovery.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/



More information about the cfe-dev mailing list