gpt4 book ai didi

c++ - 如何从 clang::ASTContext 生成代码

转载 作者:太空狗 更新时间:2023-10-29 23:17:44 25 4
gpt4 key购买 nike

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

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

最佳答案

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

关于c++ - 如何从 clang::ASTContext 生成代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16591856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com