[clang-tools-extra] r341369 - [clangd] Move buildStaticIndex() to SymbolYAML
Kirill Bobyrev via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 4 08:10:40 PDT 2018
Author: omtcyfz
Date: Tue Sep 4 08:10:40 2018
New Revision: 341369
URL: http://llvm.org/viewvc/llvm-project?rev=341369&view=rev
Log:
[clangd] Move buildStaticIndex() to SymbolYAML
`buildStaticIndex()` is used by two other tools that I'm building, now
it's useful outside of `tool/ClangdMain.cpp`.
Also, slightly refactor the code while moving it to the different source
file.
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D51626
Modified:
clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
clang-tools-extra/trunk/clangd/index/SymbolYAML.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
Modified: clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp?rev=341369&r1=341368&r2=341369&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp Tue Sep 4 08:10:40 2018
@@ -9,6 +9,7 @@
#include "SymbolYAML.h"
#include "Index.h"
+#include "dex/DexIndex.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Errc.h"
@@ -25,18 +26,18 @@ using clang::clangd::Symbol;
using clang::clangd::SymbolID;
using clang::clangd::SymbolLocation;
using clang::index::SymbolInfo;
-using clang::index::SymbolLanguage;
using clang::index::SymbolKind;
+using clang::index::SymbolLanguage;
// Helper to (de)serialize the SymbolID. We serialize it as a hex string.
struct NormalizedSymbolID {
NormalizedSymbolID(IO &) {}
- NormalizedSymbolID(IO &, const SymbolID& ID) {
+ NormalizedSymbolID(IO &, const SymbolID &ID) {
llvm::raw_string_ostream OS(HexString);
OS << ID;
}
- SymbolID denormalize(IO&) {
+ SymbolID denormalize(IO &) {
SymbolID ID;
HexString >> ID;
return ID;
@@ -167,7 +168,7 @@ Symbol SymbolFromYAML(llvm::yaml::Input
return S;
}
-void SymbolsToYAML(const SymbolSlab& Symbols, llvm::raw_ostream &OS) {
+void SymbolsToYAML(const SymbolSlab &Symbols, llvm::raw_ostream &OS) {
llvm::yaml::Output Yout(OS);
for (Symbol S : Symbols) // copy: Yout<< requires mutability.
Yout << S;
@@ -181,5 +182,18 @@ std::string SymbolToYAML(Symbol Sym) {
return OS.str();
}
+std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFile,
+ bool UseDex) {
+ auto Buffer = llvm::MemoryBuffer::getFile(SymbolFile);
+ if (!Buffer) {
+ llvm::errs() << "Can't open " << SymbolFile << "\n";
+ return nullptr;
+ }
+ auto Slab = symbolsFromYAML(Buffer.get()->getBuffer());
+
+ return UseDex ? dex::DexIndex::build(std::move(Slab))
+ : MemIndex::build(std::move(Slab), RefSlab());
+}
+
} // namespace clangd
} // namespace clang
Modified: clang-tools-extra/trunk/clangd/index/SymbolYAML.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolYAML.h?rev=341369&r1=341368&r2=341369&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/SymbolYAML.h (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolYAML.h Tue Sep 4 08:10:40 2018
@@ -41,6 +41,12 @@ std::string SymbolToYAML(Symbol Sym);
// The YAML result is safe to concatenate if you have multiple symbol slabs.
void SymbolsToYAML(const SymbolSlab &Symbols, llvm::raw_ostream &OS);
+// Build an in-memory static index for global symbols from a symbol file.
+// The size of global symbols should be relatively small, so that all symbols
+// can be managed in memory.
+std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFile,
+ bool UseDex = true);
+
} // namespace clangd
} // namespace clang
Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=341369&r1=341368&r2=341369&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Tue Sep 4 08:10:40 2018
@@ -39,24 +39,6 @@ namespace {
enum class PCHStorageFlag { Disk, Memory };
-// Build an in-memory static index for global symbols from a YAML-format file.
-// The size of global symbols should be relatively small, so that all symbols
-// can be managed in memory.
-std::unique_ptr<SymbolIndex> buildStaticIndex(llvm::StringRef YamlSymbolFile) {
- auto Buffer = llvm::MemoryBuffer::getFile(YamlSymbolFile);
- if (!Buffer) {
- llvm::errs() << "Can't open " << YamlSymbolFile << "\n";
- return nullptr;
- }
- auto Slab = symbolsFromYAML(Buffer.get()->getBuffer());
- SymbolSlab::Builder SymsBuilder;
- for (auto Sym : Slab)
- SymsBuilder.insert(Sym);
-
- return UseDex ? dex::DexIndex::build(std::move(SymsBuilder).build())
- : MemIndex::build(std::move(SymsBuilder).build(), RefSlab());
-}
-
} // namespace
static llvm::cl::opt<Path> CompileCommandsDir(
@@ -298,7 +280,7 @@ int main(int argc, char *argv[]) {
Opts.BuildDynamicSymbolIndex = EnableIndex;
std::unique_ptr<SymbolIndex> StaticIdx;
if (EnableIndex && !YamlSymbolFile.empty()) {
- StaticIdx = buildStaticIndex(YamlSymbolFile);
+ StaticIdx = loadIndex(YamlSymbolFile, UseDex);
Opts.StaticIndex = StaticIdx.get();
}
Opts.AsyncThreadsCount = WorkerThreadsCount;
More information about the cfe-commits
mailing list