r194571 - Add an optional mapping from source paths to source contents.

Manuel Klimek klimek at google.com
Wed Nov 13 05:23:27 PST 2013


Author: klimek
Date: Wed Nov 13 07:23:27 2013
New Revision: 194571

URL: http://llvm.org/viewvc/llvm-project?rev=194571&view=rev
Log:
Add an optional mapping from source paths to source contents.

This allows compilation database implementations for distributed build
systems to hand all data to the client to make parsing independent of
the file system.

Modified:
    cfe/trunk/include/clang-c/CXCompilationDatabase.h
    cfe/trunk/include/clang/Tooling/CompilationDatabase.h
    cfe/trunk/tools/libclang/CXCompilationDatabase.cpp

Modified: cfe/trunk/include/clang-c/CXCompilationDatabase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/CXCompilationDatabase.h?rev=194571&r1=194570&r2=194571&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/CXCompilationDatabase.h (original)
+++ cfe/trunk/include/clang-c/CXCompilationDatabase.h Wed Nov 13 07:23:27 2013
@@ -142,6 +142,24 @@ CINDEX_LINKAGE CXString
 clang_CompileCommand_getArg(CXCompileCommand, unsigned I);
 
 /**
+ * \brief Get the number of source mappings for the compiler invocation.
+ */
+CINDEX_LINKAGE unsigned
+clang_CompileCommand_getNumMappedSources(CXCompileCommand);
+
+/**
+ * \brief Get the I'th mapped source path for the compiler invocation.
+ */
+CINDEX_LINKAGE CXString
+clang_CompileCommand_getMappedSourcePath(CXCompileCommand, unsigned I);
+
+/**
+ * \brief Get the I'th mapped source content for the compiler invocation.
+ */
+CINDEX_LINKAGE CXString
+clang_CompileCommand_getMappedSourceContent(CXCompileCommand, unsigned I);
+
+/**
  * @}
  */
 

Modified: cfe/trunk/include/clang/Tooling/CompilationDatabase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/CompilationDatabase.h?rev=194571&r1=194570&r2=194571&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/CompilationDatabase.h (original)
+++ cfe/trunk/include/clang/Tooling/CompilationDatabase.h Wed Nov 13 07:23:27 2013
@@ -50,6 +50,16 @@ struct CompileCommand {
 
   /// \brief The command line that was executed.
   std::vector<std::string> CommandLine;
+
+  /// \brief An optional mapping from each file's path to its content for all
+  /// files needed for the compilation that are not available via the file
+  /// system.
+  ///
+  /// Note that a tool implementation is required to fall back to the file
+  /// system if a source file is not provided in the mapped sources, as
+  /// compilation databases will usually not provide all files in mapped sources
+  /// for performance reasons.
+  std::vector<std::pair<std::string, std::string> > MappedSources;
 };
 
 /// \brief Interface for compilation databases.
@@ -108,6 +118,10 @@ public:
 
   /// \brief Returns all compile commands for all the files in the compilation
   /// database.
+  ///
+  /// FIXME: Add a layer in Tooling that provides an interface to run a tool
+  /// over all files in a compilation database. Not all build systems have the
+  /// ability to provide a feasible implementation for \c getAllCompileCommands.
   virtual std::vector<CompileCommand> getAllCompileCommands() const = 0;
 };
 

Modified: cfe/trunk/tools/libclang/CXCompilationDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCompilationDatabase.cpp?rev=194571&r1=194570&r2=194571&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXCompilationDatabase.cpp (original)
+++ cfe/trunk/tools/libclang/CXCompilationDatabase.cpp Wed Nov 13 07:23:27 2013
@@ -136,5 +136,41 @@ clang_CompileCommand_getArg(CXCompileCom
   return cxstring::createRef(Cmd->CommandLine[Arg].c_str());
 }
 
+unsigned
+clang_CompileCommand_getNumMappedSources(CXCompileCommand CCmd)
+{
+  if (!CCmd)
+    return 0;
+
+  return static_cast<CompileCommand *>(CCmd)->MappedSources.size();
+}
+
+CXString
+clang_CompileCommand_getMappedSourcePath(CXCompileCommand CCmd, unsigned I)
+{
+  if (!CCmd)
+    return cxstring::createNull();
+
+  CompileCommand *Cmd = static_cast<CompileCommand *>(CCmd);
+
+  if (I >= Cmd->MappedSources.size())
+    return cxstring::createNull();
+
+  return cxstring::createRef(Cmd->MappedSources[I].first.c_str());
+}
+
+CXString
+clang_CompileCommand_getMappedSourceContent(CXCompileCommand CCmd, unsigned I)
+{
+  if (!CCmd)
+    return cxstring::createNull();
+
+  CompileCommand *Cmd = static_cast<CompileCommand *>(CCmd);
+
+  if (I >= Cmd->MappedSources.size())
+    return cxstring::createNull();
+
+  return cxstring::createRef(Cmd->MappedSources[I].second.c_str());
+}
 
 } // end: extern "C"





More information about the cfe-commits mailing list