]> granicus.if.org Git - clang/commitdiff
libclang: Port CIndexer::getClangResourcesPath to PathV2. No functionality change.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 13 Jun 2013 13:56:37 +0000 (13:56 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 13 Jun 2013 13:56:37 +0000 (13:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183901 91177308-0d34-0410-b5e6-96231b3b80d8

tools/libclang/CIndexer.cpp
tools/libclang/CIndexer.h

index d89e0a41984d5b5881d5d7a78973d2dfab1532fe..4cbf0c19510a4fa0edfeb98e3002a44c45483a5c 100644 (file)
 
 using namespace clang;
 
-std::string CIndexer::getClangResourcesPath() {
+const std::string &CIndexer::getClangResourcesPath() {
   // Did we already compute the path?
   if (!ResourcesPath.empty())
-    return ResourcesPath.str();
-  
+    return ResourcesPath;
+
+  SmallString<128> LibClangPath;
+
   // Find the location where this library lives (libclang.dylib).
 #ifdef LLVM_ON_WIN32
   MEMORY_BASIC_INFORMATION mbi;
@@ -66,26 +68,22 @@ std::string CIndexer::getClangResourcesPath() {
 #endif
 #endif
 
-  llvm::sys::Path LibClangPath(path);
-  LibClangPath.eraseComponent();
+  LibClangPath += llvm::sys::path::parent_path(path);
 #else
   // This silly cast below avoids a C++ warning.
   Dl_info info;
   if (dladdr((void *)(uintptr_t)clang_createTranslationUnit, &info) == 0)
     llvm_unreachable("Call to dladdr() failed");
-  
-  llvm::sys::Path LibClangPath(info.dli_fname);
-  
+
   // We now have the CIndex directory, locate clang relative to it.
-  LibClangPath.eraseComponent();
+  LibClangPath += llvm::sys::path::parent_path(info.dli_fname);
 #endif
-  
-  LibClangPath.appendComponent("clang");
-  LibClangPath.appendComponent(CLANG_VERSION_STRING);
+
+  llvm::sys::path::append(LibClangPath, "clang", CLANG_VERSION_STRING);
 
   // Cache our result.
-  ResourcesPath = LibClangPath;
-  return LibClangPath.str();
+  ResourcesPath = LibClangPath.str();
+  return ResourcesPath;
 }
 
 static llvm::sys::Path GetTemporaryPath() {
index 6f000da29dbb816033d9b02449ce688e1d52531d..1b4d5c563228d52caa8b4a46354deb966c251176 100644 (file)
@@ -38,7 +38,7 @@ class CIndexer {
   bool DisplayDiagnostics;
   unsigned Options; // CXGlobalOptFlags.
 
-  llvm::sys::Path ResourcesPath;
+  std::string ResourcesPath;
 
 public:
  CIndexer() : OnlyLocalDecls(false), DisplayDiagnostics(false),
@@ -63,7 +63,7 @@ public:
   }
 
   /// \brief Get the path of the clang resource files.
-  std::string getClangResourcesPath();
+  const std::string &getClangResourcesPath();
 };
 
   /**