I want to modify C source code like this: I wany to modify loop condition in AST, how can I do this?
for example:
for(int i = 0; i < 10; i ++){...}
change to :
for (int i = 0; i < 1; i ++){...}
I get the forStmt from AST by ASTMatcher in clang tools and i also get the conditon:
auto cond = forstmt -> getCond();
if(cond){
if(auto bo = dyn_cast<BinaryOperator>(cond)){
auto borhs = bo -> getRHS();
if (auto condvar = dyn_cast<IntegerLiteral>(borhs)){
// how can i modify this condvar and dump ast to out.ast file?
string var_value = condvar -> getValue().toString(10, 1);
}
}
}