3

I need a sample code to learn how to Generate C++ Code from clang::ASTContext.

I created ast from c++ code and I made some changes in AST and now I want to Generate Code again.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Saman Parser
  • 148
  • 14

1 Answers1

0

you cant use Stmt class's print method to generate code from a ast.

virtual bool VisitStmt(Stmt *st){
    std::string SStr;
    llvm::raw_string_ostream S(SStr);
    st->printPretty(S, nullptr, PrintingPolicy(LangOptions()));
    const std::string &Str = S.str();
    llvm::errs() << "---------begin----------\n";
    llvm::errs() << Str << "\n";
    llvm::errs() << "---------end----------\n";
}
xawi2000
  • 152
  • 1
  • 4