Omitted code blocks from clang AST for ObjectiveC

随声附和 提交于 2020-01-06 16:18:57

问题


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

It had an error that said

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

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"


回答1:


You need to generate something called a compilation database. For Clang it will be a json file (default name: compile_commands.json)

You can read about it 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.

A sample json file will look like:

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

You can read here and here on how to setup a compilation database.



来源:https://stackoverflow.com/questions/37875881/omitted-code-blocks-from-clang-ast-for-objectivec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!