r247468 - [tooling] In CompileCommand, Expose the 'file' that was associated with the command.
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 11 13:43:05 PDT 2015
Author: akirtzidis
Date: Fri Sep 11 15:43:05 2015
New Revision: 247468
URL: http://llvm.org/viewvc/llvm-project?rev=247468&view=rev
Log:
[tooling] In CompileCommand, Expose the 'file' that was associated with the command.
Modified:
cfe/trunk/include/clang-c/CXCompilationDatabase.h
cfe/trunk/include/clang/Tooling/CompilationDatabase.h
cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
cfe/trunk/lib/Tooling/CompilationDatabase.cpp
cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
cfe/trunk/tools/libclang/CXCompilationDatabase.cpp
cfe/trunk/tools/libclang/libclang.exports
Modified: cfe/trunk/include/clang-c/CXCompilationDatabase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/CXCompilationDatabase.h?rev=247468&r1=247467&r2=247468&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/CXCompilationDatabase.h (original)
+++ cfe/trunk/include/clang-c/CXCompilationDatabase.h Fri Sep 11 15:43:05 2015
@@ -126,6 +126,12 @@ CINDEX_LINKAGE CXString
clang_CompileCommand_getDirectory(CXCompileCommand);
/**
+ * \brief Get the filename associated with the CompileCommand.
+ */
+CINDEX_LINKAGE CXString
+clang_CompileCommand_getFilename(CXCompileCommand);
+
+/**
* \brief Get the number of arguments in the compiler invocation.
*
*/
Modified: cfe/trunk/include/clang/Tooling/CompilationDatabase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/CompilationDatabase.h?rev=247468&r1=247467&r2=247468&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/CompilationDatabase.h (original)
+++ cfe/trunk/include/clang/Tooling/CompilationDatabase.h Fri Sep 11 15:43:05 2015
@@ -42,12 +42,18 @@ namespace tooling {
/// \brief Specifies the working directory and command of a compilation.
struct CompileCommand {
CompileCommand() {}
- CompileCommand(Twine Directory, std::vector<std::string> CommandLine)
- : Directory(Directory.str()), CommandLine(std::move(CommandLine)) {}
+ CompileCommand(Twine Directory, Twine Filename,
+ std::vector<std::string> CommandLine)
+ : Directory(Directory.str()),
+ Filename(Filename.str()),
+ CommandLine(std::move(CommandLine)) {}
/// \brief The working directory the command was executed from.
std::string Directory;
+ /// The source file associated with the command.
+ std::string Filename;
+
/// \brief The command line that was executed.
std::vector<std::string> CommandLine;
Modified: cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h?rev=247468&r1=247467&r2=247468&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h (original)
+++ cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h Fri Sep 11 15:43:05 2015
@@ -99,13 +99,14 @@ private:
/// failed.
bool parse(std::string &ErrorMessage);
- // Tuple (directory, commandline) where 'commandline' points to the
+ // Tuple (directory, filename, commandline) where 'commandline' points to the
// corresponding scalar nodes in the YAML stream.
// If the command line contains a single argument, it is a shell-escaped
// command line.
// Otherwise, each entry in the command line vector is a literal
// argument to the compiler.
- typedef std::pair<llvm::yaml::ScalarNode *,
+ typedef std::tuple<llvm::yaml::ScalarNode *,
+ llvm::yaml::ScalarNode *,
std::vector<llvm::yaml::ScalarNode *>> CompileCommandRef;
/// \brief Converts the given array of CompileCommandRefs to CompileCommands.
Modified: cfe/trunk/lib/Tooling/CompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CompilationDatabase.cpp?rev=247468&r1=247467&r2=247468&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/CompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/CompilationDatabase.cpp Fri Sep 11 15:43:05 2015
@@ -299,13 +299,15 @@ FixedCompilationDatabase(Twine Directory
std::vector<std::string> ToolCommandLine(1, "clang-tool");
ToolCommandLine.insert(ToolCommandLine.end(),
CommandLine.begin(), CommandLine.end());
- CompileCommands.emplace_back(Directory, std::move(ToolCommandLine));
+ CompileCommands.emplace_back(Directory, StringRef(),
+ std::move(ToolCommandLine));
}
std::vector<CompileCommand>
FixedCompilationDatabase::getCompileCommands(StringRef FilePath) const {
std::vector<CompileCommand> Result(CompileCommands);
Result[0].CommandLine.push_back(FilePath);
+ Result[0].Filename = FilePath;
return Result;
}
Modified: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp?rev=247468&r1=247467&r2=247468&view=diff
==============================================================================
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp Fri Sep 11 15:43:05 2015
@@ -232,8 +232,11 @@ void JSONCompilationDatabase::getCommand
std::vector<CompileCommand> &Commands) const {
for (int I = 0, E = CommandsRef.size(); I != E; ++I) {
SmallString<8> DirectoryStorage;
- Commands.emplace_back(CommandsRef[I].first->getValue(DirectoryStorage),
- nodeToCommandLine(CommandsRef[I].second));
+ SmallString<32> FilenameStorage;
+ Commands.emplace_back(
+ std::get<0>(CommandsRef[I])->getValue(DirectoryStorage),
+ std::get<1>(CommandsRef[I])->getValue(FilenameStorage),
+ nodeToCommandLine(std::get<2>(CommandsRef[I])));
}
}
@@ -335,7 +338,7 @@ bool JSONCompilationDatabase::parse(std:
llvm::sys::path::native(FileName, NativeFilePath);
}
IndexByFile[NativeFilePath].push_back(
- CompileCommandRef(Directory, *Command));
+ CompileCommandRef(Directory, File, *Command));
MatchTrie.insert(NativeFilePath);
}
return true;
Modified: cfe/trunk/tools/libclang/CXCompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCompilationDatabase.cpp?rev=247468&r1=247467&r2=247468&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCompilationDatabase.cpp (original)
+++ cfe/trunk/tools/libclang/CXCompilationDatabase.cpp Fri Sep 11 15:43:05 2015
@@ -111,6 +111,16 @@ clang_CompileCommand_getDirectory(CXComp
return cxstring::createRef(cmd->Directory.c_str());
}
+CXString
+clang_CompileCommand_getFilename(CXCompileCommand CCmd)
+{
+ if (!CCmd)
+ return cxstring::createNull();
+
+ CompileCommand *cmd = static_cast<CompileCommand *>(CCmd);
+ return cxstring::createRef(cmd->Filename.c_str());
+}
+
unsigned
clang_CompileCommand_getNumArgs(CXCompileCommand CCmd)
{
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=247468&r1=247467&r2=247468&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Fri Sep 11 15:43:05 2015
@@ -297,6 +297,7 @@ clang_CompileCommands_dispose
clang_CompileCommands_getSize
clang_CompileCommands_getCommand
clang_CompileCommand_getDirectory
+clang_CompileCommand_getFilename
clang_CompileCommand_getMappedSourceContent
clang_CompileCommand_getMappedSourcePath
clang_CompileCommand_getNumArgs
More information about the cfe-commits
mailing list