how to get loop boundary form ForStmt

I’m new with clang. I want to know how to get loop boundary form ForStmt. For example, for(int i = 0; i!=10;++i) , I want to get the value 0 and 10. Then I can use those value in other template such as intel TBB parallel_for.

I already know that getCond(),getInit() method, but how to get the value?


I’m not an expert but I’d say that you have to make sure you have this very type of init and cond in your ForStmt’s, . Then you can try and get the VarDecl’s nodes, get their child, get the BinaryOperator nodes and get their RHS. With this code: int main() { for(int i = 0; i < 10; ++i) { } } See an AST-dump like this to help you: clang -cc1 -fsyntax-only -ast-dump forstmt.c TranslationUnitDecl 0x47880c0 <> |-TypedefDecl 0x47885c0 <> __int128_t ‘__int128’ |-TypedefDecl 0x4788620 <> __uint128_t ‘unsigned __int128’ |-TypedefDecl 0x4788970 <> __builtin_va_list ‘__va_list_tag [1]’ -FunctionDecl 0x4788a10 <forstmt.c:1:1, line:4:1> main 'int ()' -CompoundStmt 0x4788c78 <line:1:12, line:4:1> -0x4788c38 <line:2:5, line:3:5> |-DeclStmt 0x4788b38 <line:2:9, col:18> | - 0x4788ac0 <col:9, col:17> ‘int’ | - 0x4788b18 <col:17> 'int' |-<<<NULL>>> |- 0x4788bb0 <col:20, col:24> 'int' '<' | |-ImplicitCastExpr 0x4788b98 <col:20> 'int' <LValueToRValue> | | -DeclRefExpr 0x4788b50 col:20 ‘int’ lvalue Var 0x4788ac0 ‘i’ ‘int’ | - 0x4788b78 <col:24> 'int' |-UnaryOperator 0x4788c00 <col:28, col:30> 'int' prefix '++' | -DeclRefExpr 0x4788bd8 col:30 ‘int’ lvalue Var 0x4788ac0 ‘i’ ‘int’ `-CompoundStmt 0x4788c20 <col:33, line:3:5>