[PATCH] Add an optional mapping from source paths to source contents.

Manuel Klimek klimek at google.com
Thu Nov 7 10:28:12 PST 2013


Hi gribozavr,

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

http://llvm-reviews.chandlerc.com/D2121

Files:
  include/clang-c/CXCompilationDatabase.h
  include/clang/Tooling/CompilationDatabase.h
  tools/libclang/CXCompilationDatabase.cpp

Index: include/clang-c/CXCompilationDatabase.h
===================================================================
--- include/clang-c/CXCompilationDatabase.h
+++ include/clang-c/CXCompilationDatabase.h
@@ -142,6 +142,24 @@
 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);
+
+/**
  * @}
  */
 
Index: include/clang/Tooling/CompilationDatabase.h
===================================================================
--- include/clang/Tooling/CompilationDatabase.h
+++ include/clang/Tooling/CompilationDatabase.h
@@ -50,6 +50,10 @@
 
   /// \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.
+  std::vector<std::pair<std::string, std::string> > MappedSources;
 };
 
 /// \brief Interface for compilation databases.
Index: tools/libclang/CXCompilationDatabase.cpp
===================================================================
--- tools/libclang/CXCompilationDatabase.cpp
+++ tools/libclang/CXCompilationDatabase.cpp
@@ -136,5 +136,41 @@
   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"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2121.1.patch
Type: text/x-patch
Size: 2677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131107/e52f2d13/attachment.bin>


More information about the cfe-commits mailing list