ios - 省略了 ObjectiveC 的 clang AST 中的代码块

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

我正在为 .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 block 都是空的。如果它们包含 C 或 C++ 代码,那么它们会反射(reflect)在 CompoundStmt 中,但当它包含类似 NSString *query = [NSString stringWithFormat:@"select * from peopleInfo where peopleInfoID=%d, self.recordIDToEdit]< 的代码时则不会 甚至 NSString *abc = "ABC"

最佳答案

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

你可以阅读它here .

Tools based on the C++ Abstract Syntax Tree need full information how to parse a translation unit. Usually this information is implicitly available in the build system, but running tools as part of the build system is not necessarily the best solution.

A compilation database is a JSON file, which consist of an array of “command objects”, where each command object specifies one way a translation unit is compiled in the project.

示例 json 文件如下所示:

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

您可以阅读 herehere关于如何设置编译数据库。

关于ios - 省略了 ObjectiveC 的 clang AST 中的代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37875881/

相关文章:

objective-c - 在 iOS 上创建复合 ScrollView 的最佳方法是什么

ios - 在 iOS 5 设备上测试应用内购买

ios - 苹果 watch : Is this a good way to allow apple watch app to grab new data?

C:为什么 LLVM 从左到右评估 printf 而 GCC 从右到左评估?

c++ - enable_shared_from_this 不适用于 xcode 5

ios - 即时更改模糊效果样式

ios - 当应用程序重新启动时,核心数据中的数据不持久

ios - 将长字符串插入到 UILabel 中,通过切割由\n 分隔的每个子字符串的尾部

iphone - 数组中缺少 UIView

objective-c - Xcode 4.4.1 & 核心情节 : Apple LLVM compiler error when compiling Core Plot demo apps