- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 LibTooling 进行一些分析。我知道如何遍历 AST 并将一些文本插入某处。例如,
Rewriter mywriter;
mywriter.InsertTextAfter(func->getLocEnd(),"Hello");
现在我想知道有没有办法保存代码? (天气保存到原始文件或生成新文件)
因为在分析之后,我只能在终端上读取结果,这对我来说还不够。
最佳答案
它应该在您的 ASTFrontEndAction 对象中的 EndSourceFileAction() 函数中完成
// For each source file provided to the tool, a new FrontendAction is created.
class MyFrontendAction : public ASTFrontendAction {
public:
MyFrontendAction() {}
void EndSourceFileAction() override {
SourceManager &SM = TheRewriter.getSourceMgr();
llvm::errs() << "** EndSourceFileAction for: "
<< SM.getFileEntryForID(SM.getMainFileID())->getName() << "\n";
// Now emit the rewritten buffer.
// TheRewriter.getEditBuffer(SM.getMainFileID()).write(llvm::outs()); --> this will output to screen as what you got.
std::error_code error_code;
llvm::raw_fd_ostream outFile("output.txt", error_code, llvm::sys::fs::F_None);
TheRewriter.getEditBuffer(SM.getMainFileID()).write(outFile); // --> this will write the result to outFile
outFile.close();
}
//as normal, make sure it matches your ASTConsumer constructor
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef file) override {
llvm::errs() << "** Creating AST consumer for: " << file << "\n";
TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
return llvm::make_unique<MyASTConsumer>(TheRewriter,&CI.getASTContext());
}
在这种情况下,output.txt 就是您想要的输出文件。
关于c++ - Clang 使用 LibTooling Rewriter 生成新文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43157172/
我试图从我的 mac 上的源代码构建 libxml2。 所以我使用 mac 端口安装了 autoconf libtool 和 automake autoconf 和 automake 似乎按预期工作正
有人可以告诉我 libtool 的 .lai 文件的用途吗? 另请参阅What are libtool's .la file for? 最佳答案 .lai 是将作为 .la 文件安装的文件的扩展名。换
我有一个使用 autotools 设置的项目来构建一个 C++ 库,包括 Python 与 Boost.Python 的绑定(bind)。我的系统上有一个 Boost.Python 二进制文件,我想链
我正在尝试automake OrientDb C++ 库,但遇到了一些错误。 Makefile.am:10: error: Libtool library used but 'LIBTOOL' is
这个问题在这里已经有了答案: Libtool library used but `LIBTOOL' is undefined? (4 个回答) 4年前关闭。 我正在尝试按照本教程在 centos 上安
我想使用 Make install 命令,我已经安装了所有要求,如 yasm、nasm、curl、ant、rsync 和 autotools:autoconf、automake、aclocal、pkg
我正在尝试将 libcsv 转换为使用 libtool,这样我就可以在 mac os x 上使用它而无需破坏 makefile。当我尝试运行从工具生成的 makefile 时,出现以下错误: ~/
我正在尝试编译和安装 phpredis 存储库的 php7 分支,但出现以下错误: /bin/sh /root/phpredis/libtool --mode=compile cc
我尝试在 Centos 5.11(内核 2.6.18-409.el5)上安装 USBIP,但是当我输入“make”时总是出现这个错误: make[1]: Entering directory "/ro
我正在运行 Linux,Ubuntu 10.04。 这不是我第一次尝试使用自动工具。我做了很多研究并遵循了很多教程:这是我想做的,我尝试过的以及我面临的问题。 目标 : 使用 libtool、auto
我正在尝试为运行 busybox 1.13 的 ARM 嵌入式计算机构建 expat (2.0.0) XML 解析库,在 ./configure 期间,我收到错误: checking if libto
我在 ubuntu lucid 上使用 libtool 2.2.6b,在 ubuntu precision 上使用 libtool 2.4.2。清醒时,我的项目将正确链接。准确地说,它无法链接。这是演
我正在用 C++ 开发一个项目,我希望在其中实现添加插件的功能。编译过程由 Autotools 处理。我设法正确设置了文件结构,主项目和插件都被编译了,但是由于某种原因,在运行 make instal
$ autoreconf -fi src/Makefile.am:43: Libtool library used but `LIBTOOL' is undefined src/Makefile.am
目前我正在将一个成功构建的库与选项链接起来 libtool --mode=link g++ -version-info 1:0 这导致一个名为的库 libxxx.so.1.0.0 到目前为止一切正常。
我已经下载了一些旧项目的源代码。我正在尝试构建它: ./bootstrap && ./configure 它工作正常,但是: make /bin/sh ../libtool --mode=comp
我对 libtool 的东西很陌生。我的问题是构建我的项目需要 libtool 1.5,但我的系统(debian、squeeze)上的默认 libtool 是 2.2。我所做的是从源代码安装 libt
我正在编译使用 libtool 进行编译的 courier-authlib-0.66.1。我修改了所有 Makefile 以删除 --mode=link 行中的 CFLAGS 和 CXXFLAGS,因
我想使用 GNU Autotools 构建一个使用 ZipArchive 的共享库,但我遇到了这个问题: 警告:链接器路径没有库 -lziparch 的真实文件。 我有能力使该库在何时自动链接 你链接
我有一个项目涉及 共享库即:mylib.so (测试)程序使用这些共享库,即:test_mylib 当我尝试运行时 gdb在 test_mylib ,它打印: "test_mylib": not in
我是一名优秀的程序员,十分优秀!