how to use AST Consumer to modify loops in source code?

Hi,
i want to change all the loops in the source code.
how can i do it with ASTConsumer class?

i want to visit each loop and after making some changes to its body and declaration i want to write it back to the AST.
if writing back to AST is not possible using plugin method for clang than at least i want to extract each loop in the source code.

i have gone through the plugin code given in the clang/examples…

Hi,
i want to change all the loops in the source code.
how can i do it with ASTConsumer class?

i want to visit each loop and after making some changes to its body and declaration i want to write it back to the AST.

The AST can't be safely modified in this way. It's effectively immutable once it has been created.

if writing back to AST is not possible using plugin method for clang than at least i want to extract each loop in the source code.

i have gone through the plugin code given in the clang/examples.........

You can write an ASTConsumer that identifies each of the loops, then perform source-to-source translation on them (as in, e.g., the Objective-C rewriter in RewriteObjC.cpp) . More involved loop transforms at the AST level would require more invasive changes to Clang.

What exactly are you trying to do?

  - Doug