0

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"

Jeremy Kuah
  • 519
  • 1
  • 6
  • 18
  • did you manage to make this work? I'm getting an error even after generating the compile commands files. ```fatal error: no handler registered for module format 'obj' LLVM ERROR: unknown module format ``` – Andrespch Mar 29 '19 at 09:39

1 Answers1

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.

Nishant Sharma
  • 683
  • 9
  • 16