[cfe-dev] No way to get the File for a CompileCommand?

Alastair Rankine alastair at girtby.net
Mon Apr 21 17:35:05 PDT 2014


On Apr 17, 2014, at 8:25 PM, Michael Bolin <bolinfest at gmail.com> wrote:

> 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.

HTH,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140421/200db426/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 163 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140421/200db426/attachment.sig>


More information about the cfe-dev mailing list