forked from OSchip/llvm-project
[libclang] Introduce clang_VirtualFileOverlay_setCaseSensitivity that exposes the VFS option
to set the case-sensitivity for lookups. rdar://16374696 llvm-svn: 204303
This commit is contained in:
parent
ecf2256dfe
commit
a9ab4d46bb
clang
include/clang-c
tools/libclang
unittests/libclang
|
@ -58,6 +58,16 @@ clang_VirtualFileOverlay_addFileMapping(CXVirtualFileOverlay,
|
|||
const char *virtualPath,
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -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_getBuildSessionTimestamp(void) {
|
|||
|
||||
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(CXVirtualFileOverlay VFO,
|
|||
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(CXVirtualFileOverlay VFO, unsigned,
|
|||
|
||||
llvm::SmallString<256> Buf;
|
||||
llvm::raw_svector_ostream OS(Buf);
|
||||
JSONVFSPrinter Printer(OS);
|
||||
JSONVFSPrinter Printer(OS, VFO);
|
||||
Printer.print(Entries);
|
||||
|
||||
StringRef Data = OS.str();
|
||||
|
|
|
@ -294,4 +294,5 @@ clang_ModuleMapDescriptor_writeToBuffer
|
|||
clang_VirtualFileOverlay_addFileMapping
|
||||
clang_VirtualFileOverlay_create
|
||||
clang_VirtualFileOverlay_dispose
|
||||
clang_VirtualFileOverlay_setCaseSensitivity
|
||||
clang_VirtualFileOverlay_writeToBuffer
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue