#include "CIndexer.h"
#include "CXString.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Driver/Driver.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/YAMLParser.h"
#include <cstdio>
#include <mutex>
#ifdef __CYGWIN__
#include <cygwin/version.h>
#include <sys/cygwin.h>
#define _WIN32 …
#endif
#ifdef _WIN32
#include <windows.h>
#elif defined(_AIX)
#include <errno.h>
#include <sys/ldr.h>
#else
#include <dlfcn.h>
#endif
usingnamespaceclang;
#ifdef _AIX
namespace clang {
namespace {
template <typename LibClangPathType>
void getClangResourcesPathImplAIX(LibClangPathType &LibClangPath) {
int PrevErrno = errno;
size_t BufSize = 2048u;
std::unique_ptr<char[]> Buf;
while (true) {
Buf = std::make_unique<char []>(BufSize);
errno = 0;
int Ret = loadquery(L_GETXINFO, Buf.get(), (unsigned int)BufSize);
if (Ret != -1)
break;
if (errno != ENOMEM)
llvm_unreachable("Encountered an unexpected loadquery() failure");
if ((BufSize & ~((-1u) >> 1u)) != 0u)
llvm::report_fatal_error("BufSize needed for loadquery() too large");
Buf.release();
BufSize <<= 1u;
}
uint64_t EntryAddr =
reinterpret_cast<uintptr_t &>(clang_createTranslationUnit);
ld_xinfo *CurInfo = reinterpret_cast<ld_xinfo *>(Buf.get());
while (true) {
uint64_t CurTextStart = (uint64_t)CurInfo->ldinfo_textorg;
uint64_t CurTextEnd = CurTextStart + CurInfo->ldinfo_textsize;
if (CurTextStart <= EntryAddr && EntryAddr < CurTextEnd)
break;
if (CurInfo->ldinfo_next == 0u)
llvm::report_fatal_error("Cannot locate entry point in "
"the loadquery() results");
CurInfo = reinterpret_cast<ld_xinfo *>(reinterpret_cast<char *>(CurInfo) +
CurInfo->ldinfo_next);
}
LibClangPath += reinterpret_cast<char *>(CurInfo) + CurInfo->ldinfo_filename;
errno = PrevErrno;
}
}
}
#endif
const std::string &CIndexer::getClangResourcesPath() { … }
StringRef CIndexer::getClangToolchainPath() { … }
LibclangInvocationReporter::LibclangInvocationReporter(
CIndexer &Idx, OperationKind Op, unsigned ParseOptions,
llvm::ArrayRef<const char *> Args,
llvm::ArrayRef<std::string> InvocationArgs,
llvm::ArrayRef<CXUnsavedFile> UnsavedFiles) { … }
LibclangInvocationReporter::~LibclangInvocationReporter() { … }