r204303 - [libclang] Introduce clang_VirtualFileOverlay_setCaseSensitivity that exposes the VFS option

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Mar 19 21:51:50 PDT 2014


Author: akirtzidis
Date: Wed Mar 19 23:51:48 2014
New Revision: 204303

URL: http://llvm.org/viewvc/llvm-project?rev=204303&view=rev
Log:
[libclang] Introduce clang_VirtualFileOverlay_setCaseSensitivity that exposes the VFS option
to set the case-sensitivity for lookups.

rdar://16374696

Modified:
    cfe/trunk/include/clang-c/BuildSystem.h
    cfe/trunk/tools/libclang/BuildSystem.cpp
    cfe/trunk/tools/libclang/libclang.exports
    cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/include/clang-c/BuildSystem.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/BuildSystem.h?rev=204303&r1=204302&r2=204303&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/BuildSystem.h (original)
+++ cfe/trunk/include/clang-c/BuildSystem.h Wed Mar 19 23:51:48 2014
@@ -59,6 +59,16 @@ clang_VirtualFileOverlay_addFileMapping(
                                         const char *realPath);
 
 /**
+ * \brief Set the case sensitivity for the \c CXVirtualFileOverlay object.
+ * The \c CXVirtualFileOverlay object is case-sensitive by default, this
+ * option can be used to override the default.
+ * \returns 0 for success, non-zero to indicate an error.
+ */
+CINDEX_LINKAGE enum CXErrorCode
+clang_VirtualFileOverlay_setCaseSensitivity(CXVirtualFileOverlay,
+											int caseSensitive);
+
+/**
  * \brief Write out the \c CXVirtualFileOverlay object to a char buffer.
  *
  * \param options is reserved, always pass 0.

Modified: cfe/trunk/tools/libclang/BuildSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/BuildSystem.cpp?rev=204303&r1=204302&r2=204303&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/BuildSystem.cpp (original)
+++ cfe/trunk/tools/libclang/BuildSystem.cpp Wed Mar 19 23:51:48 2014
@@ -15,6 +15,7 @@
 #include "CXString.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TimeValue.h"
 #include "llvm/Support/raw_ostream.h"
@@ -28,6 +29,7 @@ unsigned long long clang_getBuildSession
 
 struct CXVirtualFileOverlayImpl {
   std::vector<std::pair<std::string, std::string> > Mappings;
+  Optional<bool> IsCaseSensitive;
 };
 
 CXVirtualFileOverlay clang_VirtualFileOverlay_create(unsigned) {
@@ -57,6 +59,16 @@ clang_VirtualFileOverlay_addFileMapping(
   return CXError_Success;
 }
 
+enum CXErrorCode
+clang_VirtualFileOverlay_setCaseSensitivity(CXVirtualFileOverlay VFO,
+                                            int caseSensitive) {
+  if (!VFO)
+    return CXError_InvalidArguments;
+
+  VFO->IsCaseSensitive = caseSensitive;
+  return CXError_Success;
+}
+
 namespace {
 struct EntryTy {
   std::string VPath;
@@ -69,15 +81,25 @@ struct EntryTy {
 
 class JSONVFSPrinter {
   llvm::raw_ostream &OS;
+  CXVirtualFileOverlay VFO;
 
 public:
-  JSONVFSPrinter(llvm::raw_ostream &OS) : OS(OS) {}
+  JSONVFSPrinter(llvm::raw_ostream &OS, CXVirtualFileOverlay VFO)
+    : OS(OS), VFO(VFO) {}
 
   /// Entries must be sorted.
   void print(ArrayRef<EntryTy> Entries) {
     OS << "{\n"
-          "  'version': 0,\n"
-          "  'roots': [\n";
+          "  'version': 0,\n";
+    if (VFO->IsCaseSensitive.hasValue()) {
+      OS << "  'case-sensitive': '";
+      if (VFO->IsCaseSensitive.getValue())
+        OS << "true";
+      else
+        OS << "false";
+      OS << "',\n";
+    }
+    OS << "  'roots': [\n";
     printDirNodes(Entries, "", 4);
     OS << "  ]\n"
           "}\n";
@@ -184,7 +206,7 @@ clang_VirtualFileOverlay_writeToBuffer(C
 
   llvm::SmallString<256> Buf;
   llvm::raw_svector_ostream OS(Buf);
-  JSONVFSPrinter Printer(OS);
+  JSONVFSPrinter Printer(OS, VFO);
   Printer.print(Entries);
 
   StringRef Data = OS.str();

Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=204303&r1=204302&r2=204303&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Wed Mar 19 23:51:48 2014
@@ -294,4 +294,5 @@ clang_ModuleMapDescriptor_writeToBuffer
 clang_VirtualFileOverlay_addFileMapping
 clang_VirtualFileOverlay_create
 clang_VirtualFileOverlay_dispose
+clang_VirtualFileOverlay_setCaseSensitivity
 clang_VirtualFileOverlay_writeToBuffer

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=204303&r1=204302&r2=204303&view=diff
==============================================================================
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Wed Mar 19 23:51:48 2014
@@ -140,6 +140,29 @@ TEST(libclang, VirtualFileOverlay) {
     T.map("/path/virtual/dir/foo3.h", "/real/foo3.h");
     T.map("/path/virtual/dir/in/subdir/foo4.h", "/real/foo4.h");
   }
+  {
+    const char *contents =
+    "{\n"
+    "  'version': 0,\n"
+    "  'case-sensitive': 'false',\n"
+    "  'roots': [\n"
+    "    {\n"
+    "      'type': 'directory',\n"
+    "      'name': \"/path/virtual\",\n"
+    "      'contents': [\n"
+    "        {\n"
+    "          'type': 'file',\n"
+    "          'name': \"foo.h\",\n"
+    "          'external-contents': \"/real/foo.h\"\n"
+    "        }\n"
+    "      ]\n"
+    "    }\n"
+    "  ]\n"
+    "}\n";
+    TestVFO T(contents);
+    T.map("/path/virtual/foo.h", "/real/foo.h");
+    clang_VirtualFileOverlay_setCaseSensitivity(T.VFO, false);
+  }
 }
 
 TEST(libclang, ModuleMapDescriptor) {





More information about the cfe-commits mailing list