【问题标题】:Omitted code blocks from clang AST for ObjectiveC省略了用于 ObjectiveC 的 clang AST 的代码块
【发布时间】:2016-06-17 07:44:26
【问题描述】:

我正在为 .m 文件上的 Objective C 代码生成 AST 命令大致类似于clang-check -ast-dump /source/file.m &> /output/file.txt

它有一个错误说

Error while trying to load a compilation database: Could not auto-detect compilation database for file '/source/file.m' 

No compilation database found in /source or any parent directory 

json-compilation-database: Error while opening JSON database: No such file or directory

Running without flags.

In file included from /source .. fatal error:'UIKit/UIKit.h' file not found

我不确定这是否与上面抛出的错误有关,但我的许多 CompoundStmt 块都是空的。如果它们包含 C 或 C++ 代码,则它们会反映在 CompoundStmt 中,但当它包含 NSString *query = [NSString stringWithFormat:@"select * from peopleInfo where peopleInfoID=%d, self.recordIDToEdit] 甚至 NSString *abc = "ABC" 之类的代码时则不会反映

【问题讨论】:

  • 你成功了吗?即使在生成编译命令文件后,我也会收到错误消息。 fatal error: no handler registered for module format 'obj' LLVM ERROR: unknown module format

标签: ios objective-c clang llvm-clang clang-static-analyzer


【解决方案1】:

你需要生成一个叫做编译数据库的东西。对于 Clang,它将是一个 json 文件(默认名称:compile_commands.json)

您可以阅读它here

基于 C++ 抽象语法树的工具需要完整的信息如何 解析翻译单元。通常这些信息是隐含的 在构建系统中可用,但作为构建的一部分运行工具 系统不一定是最好的解决方案。

编译数据库是一个 JSON 文件,它由一个数组组成 “命令对象”,其中每个命令对象指定一种方式 翻译单元在项目中编译。

示例 json 文件如下所示:

[
  {
    "directory": "/source",
    "command": "clang++ <file>.m",
    "file": "/source/div0.c"
  }
]

您可以阅读herehere,了解如何设置编译数据库。

【讨论】:

    猜你喜欢
    • 2017-01-16
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    相关资源
    最近更新 更多