省略了来自clang的代码块AST for ObjectiveC [英] Omitted code blocks from clang AST for ObjectiveC
问题描述
我在.m文件上生成目标C代码的AST
该命令大致类似于 clang-check -ast-dump /source/file.m& /output/file.txt
I was generating AST for Objective C code on a .m file
The command is roughly like 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
I'm not sure if it's related to the error thrown above, but many of my CompoundStmt blocks are empty. If they contain C or C++ code then they are reflected in the CompoundStmt, but not when it contains code like NSString *query = [NSString stringWithFormat:@"select * from peopleInfo where peopleInfoID=%d, self.recordIDToEdit]
or even NSString *abc = "ABC"
推荐答案
你需要生成一个称为编译数据库的东西。对于Clang它将是一个json文件(默认名称:compile_commands.json)
You need to generate something called a compilation database. For Clang it will be a json file (default name: compile_commands.json)
此处。
基于C ++抽象语法树的工具需要完整的信息如何
来解析翻译单元通常这个信息是隐式的
在构建系统中可用,但运行工具作为一部分build
系统不一定是最好的解决方案。
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.
编译数据库是一个JSON文件,它由
命令对象,其中每个命令对象指定在项目中编译
翻译单元的一种方式。
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.
看起来像:
[
{
"directory": "/source",
"command": "clang++ <file>.m",
"file": "/source/div0.c"
}
]
您可以在这里阅读 和此处如何设置编译数据库。
You can read here and here on how to setup a compilation database.
这篇关于省略了来自clang的代码块AST for ObjectiveC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!