No way to get the File for a CompileCommand?

I am looking at the docs for the CompilationDatabase (http://clang.llvm.org/doxygen/group__COMPILATIONDB.html), which I am creating via a compile_commands.json file.

It looks like I can dump all of the entries via clang_CompilationDatabase_getAllCompileCommands(), and for each entry, I can get its directory and its command, but not the file itself? Is this deliberate, or just something that has not been implemented yet?

I could also parse compile_commands.json with an ordinary JSON library to get all of the entries, but that seems like it should not be necessary.

Thanks!
Michael

I’m not an expert but the comments for getCompileCommands look relevant:

/// \brief Returns all compile commands in which the specified file was
/// compiled.
///
/// This includes compile comamnds that span multiple source files.
/// For example, consider a project with the following compilations:
/// $ clang++ -o test a.cc b.cc t.cc
/// $ clang++ -o production a.cc b.cc -DPRODUCTION
/// A compilation database representing the project would return both command
/// lines for a.cc and b.cc and only the first command line for t.cc.
virtual std::vector getCompileCommands(
StringRef FilePath) const = 0;

In other words, it seems that what you want is not possible, by design.

As an alternative you could iterate through all of the source files returned by getAllFiles(), and for each one call getCompileCommands(). Note that this should be relatively efficient due to the use of a string map in the JSONCompilationDatabase.

HTH,

I am looking at the docs for the CompilationDatabase (
http://clang.llvm.org/doxygen/group__COMPILATIONDB.html), which I am
creating via a compile_commands.json file.

It looks like I can dump all of the entries
via clang_CompilationDatabase_getAllCompileCommands(), and for each entry,
I can get its directory and its command, but not the file itself? Is this
deliberate, or just something that has not been implemented yet?

I'm not an expert but the comments for getCompileCommands look relevant:

  /// \brief Returns all compile commands in which the specified file was
  /// compiled.
  ///
  /// This includes compile comamnds that span multiple source files.
  /// For example, consider a project with the following compilations:
  /// $ clang++ -o test a.cc b.cc t.cc
  /// $ clang++ -o production a.cc b.cc -DPRODUCTION
  /// A compilation database representing the project would return both
command
  /// lines for a.cc and b.cc and only the first command line for t.cc.
  virtual std::vector<CompileCommand> getCompileCommands(
    StringRef FilePath) const = 0;

In other words, it seems that what you want is not possible, by design.

As an alternative you could iterate through all of the source files
returned by getAllFiles(), and for each one call getCompileCommands(). Note
that this should be relatively efficient due to the use of a string map in
the JSONCompilationDatabase.

+1. Problem is that getAllFiles seems to be missing from the libclang
interface...