如何从clang::ASTContext生成代码

how to Generate code from clang::ASTContext

本文关键字:代码 ASTContext clang      更新时间:2023-10-16

我需要一个示例代码来学习如何从clang::ASTContext生成c++代码。

我从c++代码中创建了ast,并在ast中做了一些更改,现在我想再次生成代码。

不能使用Stmt类的print方法从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";
}