gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 00:53:17 24 4
gpt4 key购买 nike

我正在为 .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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com