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

Manuel Klimek klimek at google.com
Tue Apr 22 06:13:06 PDT 2014


On Tue, Apr 22, 2014 at 2:35 AM, Alastair Rankine <alastair at girtby.net>wrote:

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

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


>
> HTH,
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140422/76040447/attachment.html>


More information about the cfe-dev mailing list