Commit dce0855f authored by Roberto Raggi's avatar Roberto Raggi

Show how to replace AST nodes.

parent e43e09ee
......@@ -49,6 +49,7 @@
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
class Rewrite
......@@ -194,6 +195,19 @@ protected:
return false;
virtual bool visit(CppCastExpressionAST *ast) {
// Replace the C++ cast expression (e.g. static_cast<foo>(a)) with
// the one generated by the pretty printer.
std::ostringstream o;
PrettyPrinter pp(control(), o);
remove(ast->firstToken(), ast->lastToken());
const std::string str = o.str();
insertTextBefore(ast->firstToken(), str.c_str());
insertTextBefore(ast->firstToken(), "/* #REF# beautiful cast */ ");
return false;
int main(int argc, char *argv[])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment