AST for For loop

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 6 08:17:50 PDT 2019


On Tue, Aug 6, 2019 at 11:15 AM Monalisa Rout via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
>
> Hello,
> While dumping the AST for For loop, Why do I get  <<<NULL>>> ??
>
> Source code:
> void func()
> {
> for (int i = 0; i < 5; i++)
> break;
> }
>
> AST
>
> FunctionDecl 0x4a4ac10 <D:\Data\Rout\ASTJSONProject\ASTJSONProject\typeof.c:2:1, line:6:1> line:2:6 func 'void ()'
> `-CompoundStmt 0x4a4ae1c <line:3:1, line:6:1>
>   `-ForStmt 0x4a4adf8 <line:4:2, line:5:3>
>     |-DeclStmt 0x4a4ad38 <line:4:7, col:16>
>     | `-VarDecl 0x4a4acd0 <col:7, col:15> col:11 used i 'int' cinit
>     |   `-IntegerLiteral 0x4a4ad10 <col:15> 'int' 0
>     |-<<<NULL>>>
>     |-BinaryOperator 0x4a4ada8 <col:18, col:22> 'int' '<'
>     | |-ImplicitCastExpr 0x4a4ad98 <col:18> 'int' <LValueToRValue>
>     | | `-DeclRefExpr 0x4a4ad50 <col:18> 'int' lvalue Var 0x4a4acd0 'i' 'int'
>     | `-IntegerLiteral 0x4a4ad70 <col:22> 'int' 5
>     |-UnaryOperator 0x4a4ade0 <col:25, col:26> 'int' postfix '++'
>     | `-DeclRefExpr 0x4a4adc0 <col:25> 'int' lvalue Var 0x4a4acd0 'i' 'int'
>     `-BreakStmt 0x4a4adf0 <line:5:3>

The AST dumps child nodes by calling children() on a given AST node.
The ForStmt node always has five child nodes, which are (in order):
init statement, condition variable, condition, increment, and body.
Some of those may be NULL depending on the format of the for loop
(your for loop example has no condition variable, for instance).

HTH!

~Aaron

>
> Regards,
> Mona
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list