从ObjectiveC的clang AST中省略了代码块

时间:2016-06-17 07:44:27

标签: 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块都是空的。如果它们包含C或C ++代码,那么它们会反映在CompoundStmt中,但是当它包含NSString *query = [NSString stringWithFormat:@"select * from peopleInfo where peopleInfoID=%d, self.recordIDToEdit]甚至NSString *abc = "ABC"

之类的代码时

1 个答案:

答案 0 :(得分:1)

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

您可以阅读here

  

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

     

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

示例json文件如下所示:

{"param1":"value1", "param2":"value2", "param3": {"username": "admin", "password": "123"}}

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

相关问题