summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/index
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2019-01-07 15:45:19 +0000
committerIlya Biryukov <ibiryukov@google.com>2019-01-07 15:45:19 +0000
commitf2001aa74394885dc178c5997b83687acb4f55e4 (patch)
tree80666e16bbebadef8f35d1d962e09da8a7812d13 /clang-tools-extra/clangd/index
parent25d3de8a0ac4d65f2ac9820ba62a372414780649 (diff)
downloadbcm5719-llvm-f2001aa74394885dc178c5997b83687acb4f55e4.tar.gz
bcm5719-llvm-f2001aa74394885dc178c5997b83687acb4f55e4.zip
[clangd] Remove 'using namespace llvm' from .cpp files. NFC
The new guideline is to qualify with 'llvm::' explicitly both in '.h' and '.cpp' files. This simplifies moving the code between header and source files and is easier to keep consistent. llvm-svn: 350531
Diffstat (limited to 'clang-tools-extra/clangd/index')
-rw-r--r--clang-tools-extra/clangd/index/Background.cpp61
-rw-r--r--clang-tools-extra/clangd/index/CanonicalIncludes.cpp32
-rw-r--r--clang-tools-extra/clangd/index/FileIndex.cpp17
-rw-r--r--clang-tools-extra/clangd/index/Index.cpp45
-rw-r--r--clang-tools-extra/clangd/index/IndexAction.cpp13
-rw-r--r--clang-tools-extra/clangd/index/MemIndex.cpp12
-rw-r--r--clang-tools-extra/clangd/index/Merge.cpp17
-rw-r--r--clang-tools-extra/clangd/index/Serialization.cpp138
-rw-r--r--clang-tools-extra/clangd/index/SymbolCollector.cpp33
-rw-r--r--clang-tools-extra/clangd/index/SymbolID.cpp28
-rw-r--r--clang-tools-extra/clangd/index/YAMLSerialization.cpp35
-rw-r--r--clang-tools-extra/clangd/index/dex/Dex.cpp33
-rw-r--r--clang-tools-extra/clangd/index/dex/Iterator.cpp17
-rw-r--r--clang-tools-extra/clangd/index/dex/PostingList.cpp29
-rw-r--r--clang-tools-extra/clangd/index/dex/Trigram.cpp13
-rw-r--r--clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp161
16 files changed, 352 insertions, 332 deletions
diff --git a/clang-tools-extra/clangd/index/Background.cpp b/clang-tools-extra/clangd/index/Background.cpp
index 5db2d39f631..6a3eace664e 100644
--- a/clang-tools-extra/clangd/index/Background.cpp
+++ b/clang-tools-extra/clangd/index/Background.cpp
@@ -35,7 +35,6 @@
#include <string>
#include <thread>
-using namespace llvm;
namespace clang {
namespace clangd {
namespace {
@@ -119,11 +118,11 @@ createFileFilter(const llvm::StringMap<FileDigest> &FileDigests,
} // namespace
BackgroundIndex::BackgroundIndex(
- Context BackgroundContext, StringRef ResourceDir,
+ Context BackgroundContext, llvm::StringRef ResourceDir,
const FileSystemProvider &FSProvider, const GlobalCompilationDatabase &CDB,
BackgroundIndexStorage::Factory IndexStorageFactory,
size_t BuildIndexPeriodMs, size_t ThreadPoolSize)
- : SwapIndex(make_unique<MemIndex>()), ResourceDir(ResourceDir),
+ : SwapIndex(llvm::make_unique<MemIndex>()), ResourceDir(ResourceDir),
FSProvider(FSProvider), CDB(CDB),
BackgroundContext(std::move(BackgroundContext)),
BuildIndexPeriodMs(BuildIndexPeriodMs),
@@ -163,7 +162,7 @@ void BackgroundIndex::stop() {
void BackgroundIndex::run() {
WithContext Background(BackgroundContext.clone());
while (true) {
- Optional<Task> Task;
+ llvm::Optional<Task> Task;
ThreadPriority Priority;
{
std::unique_lock<std::mutex> Lock(QueueMu);
@@ -260,15 +259,15 @@ void BackgroundIndex::enqueueTask(Task T, ThreadPriority Priority) {
}
/// Given index results from a TU, only update files in \p FilesToUpdate.
-void BackgroundIndex::update(StringRef MainFile, IndexFileIn Index,
- const StringMap<FileDigest> &FilesToUpdate,
+void BackgroundIndex::update(llvm::StringRef MainFile, IndexFileIn Index,
+ const llvm::StringMap<FileDigest> &FilesToUpdate,
BackgroundIndexStorage *IndexStorage) {
// Partition symbols/references into files.
struct File {
- DenseSet<const Symbol *> Symbols;
- DenseSet<const Ref *> Refs;
+ llvm::DenseSet<const Symbol *> Symbols;
+ llvm::DenseSet<const Ref *> Refs;
};
- StringMap<File> Files;
+ llvm::StringMap<File> Files;
URIToFileCache URICache(MainFile);
for (const auto &Sym : *Index.Symbols) {
if (Sym.CanonicalDeclaration) {
@@ -287,7 +286,7 @@ void BackgroundIndex::update(StringRef MainFile, IndexFileIn Index,
Files[DefPath].Symbols.insert(&Sym);
}
}
- DenseMap<const Ref *, SymbolID> RefToIDs;
+ llvm::DenseMap<const Ref *, SymbolID> RefToIDs;
for (const auto &SymRefs : *Index.Refs) {
for (const auto &R : SymRefs.second) {
auto Path = URICache.resolve(R.Location.FileURI);
@@ -301,7 +300,7 @@ void BackgroundIndex::update(StringRef MainFile, IndexFileIn Index,
// Build and store new slabs for each updated file.
for (const auto &F : Files) {
- StringRef Path = F.first();
+ llvm::StringRef Path = F.first();
vlog("Update symbols in {0}", Path);
SymbolSlab::Builder Syms;
RefSlab::Builder Refs;
@@ -362,22 +361,22 @@ void BackgroundIndex::buildIndex() {
}
}
-Error BackgroundIndex::index(tooling::CompileCommand Cmd,
- BackgroundIndexStorage *IndexStorage) {
+llvm::Error BackgroundIndex::index(tooling::CompileCommand Cmd,
+ BackgroundIndexStorage *IndexStorage) {
trace::Span Tracer("BackgroundIndex");
SPAN_ATTACH(Tracer, "file", Cmd.Filename);
- SmallString<128> AbsolutePath;
- if (sys::path::is_absolute(Cmd.Filename)) {
+ llvm::SmallString<128> AbsolutePath;
+ if (llvm::sys::path::is_absolute(Cmd.Filename)) {
AbsolutePath = Cmd.Filename;
} else {
AbsolutePath = Cmd.Directory;
- sys::path::append(AbsolutePath, Cmd.Filename);
+ llvm::sys::path::append(AbsolutePath, Cmd.Filename);
}
auto FS = FSProvider.getFileSystem();
auto Buf = FS->getBufferForFile(AbsolutePath);
if (!Buf)
- return errorCodeToError(Buf.getError());
+ return llvm::errorCodeToError(Buf.getError());
auto Hash = digest(Buf->get()->getBuffer());
// Take a snapshot of the digests to avoid locking for each file in the TU.
@@ -386,31 +385,31 @@ Error BackgroundIndex::index(tooling::CompileCommand Cmd,
std::lock_guard<std::mutex> Lock(DigestsMu);
if (IndexedFileDigests.lookup(AbsolutePath) == Hash) {
vlog("No need to index {0}, already up to date", AbsolutePath);
- return Error::success();
+ return llvm::Error::success();
}
DigestsSnapshot = IndexedFileDigests;
}
- log("Indexing {0} (digest:={1})", Cmd.Filename, toHex(Hash));
+ log("Indexing {0} (digest:={1})", Cmd.Filename, llvm::toHex(Hash));
ParseInputs Inputs;
Inputs.FS = std::move(FS);
Inputs.FS->setCurrentWorkingDirectory(Cmd.Directory);
Inputs.CompileCommand = std::move(Cmd);
auto CI = buildCompilerInvocation(Inputs);
if (!CI)
- return createStringError(inconvertibleErrorCode(),
- "Couldn't build compiler invocation");
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Couldn't build compiler invocation");
IgnoreDiagnostics IgnoreDiags;
auto Clang = prepareCompilerInstance(
std::move(CI), /*Preamble=*/nullptr, std::move(*Buf),
std::make_shared<PCHContainerOperations>(), Inputs.FS, IgnoreDiags);
if (!Clang)
- return createStringError(inconvertibleErrorCode(),
- "Couldn't build compiler instance");
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Couldn't build compiler instance");
SymbolCollector::Options IndexOpts;
- StringMap<FileDigest> FilesToUpdate;
+ llvm::StringMap<FileDigest> FilesToUpdate;
IndexOpts.FileFilter = createFileFilter(DigestsSnapshot, FilesToUpdate);
IndexFileIn Index;
auto Action = createStaticIndexingAction(
@@ -425,15 +424,17 @@ Error BackgroundIndex::index(tooling::CompileCommand Cmd,
const FrontendInputFile &Input = Clang->getFrontendOpts().Inputs.front();
if (!Action->BeginSourceFile(*Clang, Input))
- return createStringError(inconvertibleErrorCode(),
- "BeginSourceFile() failed");
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "BeginSourceFile() failed");
if (!Action->Execute())
- return createStringError(inconvertibleErrorCode(), "Execute() failed");
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Execute() failed");
Action->EndSourceFile();
if (Clang->hasDiagnostics() &&
Clang->getDiagnostics().hasUncompilableErrorOccurred()) {
- return createStringError(inconvertibleErrorCode(),
- "IndexingAction failed: has uncompilable errors");
+ return llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "IndexingAction failed: has uncompilable errors");
}
assert(Index.Symbols && Index.Refs && Index.Sources
@@ -460,7 +461,7 @@ Error BackgroundIndex::index(tooling::CompileCommand Cmd,
reset(
IndexedSymbols.buildIndex(IndexType::Light, DuplicateHandling::Merge));
- return Error::success();
+ return llvm::Error::success();
}
} // namespace clangd
diff --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
index 0cc44feb2ac..7351b861a22 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -13,49 +13,50 @@
#include "llvm/Support/Path.h"
#include <algorithm>
-using namespace llvm;
namespace clang {
namespace clangd {
namespace {
const char IWYUPragma[] = "// IWYU pragma: private, include ";
} // namespace
-void CanonicalIncludes::addPathSuffixMapping(StringRef Suffix,
- StringRef CanonicalPath) {
- int Components =
- std::distance(sys::path::begin(Suffix), sys::path::end(Suffix));
+void CanonicalIncludes::addPathSuffixMapping(llvm::StringRef Suffix,
+ llvm::StringRef CanonicalPath) {
+ int Components = std::distance(llvm::sys::path::begin(Suffix),
+ llvm::sys::path::end(Suffix));
MaxSuffixComponents = std::max(MaxSuffixComponents, Components);
SuffixHeaderMapping[Suffix] = CanonicalPath;
}
-void CanonicalIncludes::addMapping(StringRef Path, StringRef CanonicalPath) {
+void CanonicalIncludes::addMapping(llvm::StringRef Path,
+ llvm::StringRef CanonicalPath) {
FullPathMapping[Path] = CanonicalPath;
}
-void CanonicalIncludes::addSymbolMapping(StringRef QualifiedName,
- StringRef CanonicalPath) {
+void CanonicalIncludes::addSymbolMapping(llvm::StringRef QualifiedName,
+ llvm::StringRef CanonicalPath) {
this->SymbolMapping[QualifiedName] = CanonicalPath;
}
-StringRef CanonicalIncludes::mapHeader(ArrayRef<std::string> Headers,
- StringRef QualifiedName) const {
+llvm::StringRef
+CanonicalIncludes::mapHeader(llvm::ArrayRef<std::string> Headers,
+ llvm::StringRef QualifiedName) const {
assert(!Headers.empty());
auto SE = SymbolMapping.find(QualifiedName);
if (SE != SymbolMapping.end())
return SE->second;
// Find the first header such that the extension is not '.inc', and isn't a
// recognized non-header file
- auto I = llvm::find_if(Headers, [](StringRef Include) {
+ auto I = llvm::find_if(Headers, [](llvm::StringRef Include) {
// Skip .inc file whose including header file should
// be #included instead.
return !Include.endswith(".inc");
});
if (I == Headers.end())
return Headers[0]; // Fallback to the declaring header.
- StringRef Header = *I;
+ llvm::StringRef Header = *I;
// If Header is not expected be included (e.g. .cc file), we fall back to
// the declaring header.
- StringRef Ext = sys::path::extension(Header).trim('.');
+ llvm::StringRef Ext = llvm::sys::path::extension(Header).trim('.');
// Include-able headers must have precompile type. Treat files with
// non-recognized extenstions (TY_INVALID) as headers.
auto ExtType = driver::types::lookupTypeForExtension(Ext);
@@ -68,7 +69,8 @@ StringRef CanonicalIncludes::mapHeader(ArrayRef<std::string> Headers,
return MapIt->second;
int Components = 1;
- for (auto It = sys::path::rbegin(Header), End = sys::path::rend(Header);
+ for (auto It = llvm::sys::path::rbegin(Header),
+ End = llvm::sys::path::rend(Header);
It != End && Components <= MaxSuffixComponents; ++It, ++Components) {
auto SubPath = Header.substr(It->data() - Header.begin());
auto MappingIt = SuffixHeaderMapping.find(SubPath);
@@ -85,7 +87,7 @@ collectIWYUHeaderMaps(CanonicalIncludes *Includes) {
PragmaCommentHandler(CanonicalIncludes *Includes) : Includes(Includes) {}
bool HandleComment(Preprocessor &PP, SourceRange Range) override {
- StringRef Text =
+ llvm::StringRef Text =
Lexer::getSourceText(CharSourceRange::getCharRange(Range),
PP.getSourceManager(), PP.getLangOpts());
if (!Text.consume_front(IWYUPragma))
diff --git a/clang-tools-extra/clangd/index/FileIndex.cpp b/clang-tools-extra/clangd/index/FileIndex.cpp
index b944c72d850..d3e3596dbec 100644
--- a/clang-tools-extra/clangd/index/FileIndex.cpp
+++ b/clang-tools-extra/clangd/index/FileIndex.cpp
@@ -24,13 +24,12 @@
#include "llvm/ADT/StringRef.h"
#include <memory>
-using namespace llvm;
namespace clang {
namespace clangd {
static std::pair<SymbolSlab, RefSlab>
indexSymbols(ASTContext &AST, std::shared_ptr<Preprocessor> PP,
- ArrayRef<Decl *> DeclsToIndex, bool IsIndexMainAST) {
+ llvm::ArrayRef<Decl *> DeclsToIndex, bool IsIndexMainAST) {
SymbolCollector::Options CollectorOpts;
// FIXME(ioeric): we might also want to collect include headers. We would need
// to make sure all includes are canonicalized (with CanonicalIncludes), which
@@ -116,7 +115,7 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle) {
std::vector<Symbol> SymsStorage;
switch (DuplicateHandle) {
case DuplicateHandling::Merge: {
- DenseMap<SymbolID, Symbol> Merged;
+ llvm::DenseMap<SymbolID, Symbol> Merged;
for (const auto &Slab : SymbolSlabs) {
for (const auto &Sym : *Slab) {
auto I = Merged.try_emplace(Sym.ID, Sym);
@@ -143,9 +142,9 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle) {
}
std::vector<Ref> RefsStorage; // Contiguous ranges for each SymbolID.
- DenseMap<SymbolID, ArrayRef<Ref>> AllRefs;
+ llvm::DenseMap<SymbolID, llvm::ArrayRef<Ref>> AllRefs;
{
- DenseMap<SymbolID, SmallVector<Ref, 4>> MergedRefs;
+ llvm::DenseMap<SymbolID, llvm::SmallVector<Ref, 4>> MergedRefs;
size_t Count = 0;
for (const auto &RefSlab : RefSlabs)
for (const auto &Sym : *RefSlab) {
@@ -161,8 +160,8 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle) {
llvm::copy(SymRefs, back_inserter(RefsStorage));
AllRefs.try_emplace(
Sym.first,
- ArrayRef<Ref>(&RefsStorage[RefsStorage.size() - SymRefs.size()],
- SymRefs.size()));
+ llvm::ArrayRef<Ref>(&RefsStorage[RefsStorage.size() - SymRefs.size()],
+ SymRefs.size()));
}
}
@@ -177,13 +176,13 @@ FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle) {
switch (Type) {
case IndexType::Light:
return llvm::make_unique<MemIndex>(
- make_pointee_range(AllSymbols), std::move(AllRefs),
+ llvm::make_pointee_range(AllSymbols), std::move(AllRefs),
std::make_tuple(std::move(SymbolSlabs), std::move(RefSlabs),
std::move(RefsStorage), std::move(SymsStorage)),
StorageSize);
case IndexType::Heavy:
return llvm::make_unique<dex::Dex>(
- make_pointee_range(AllSymbols), std::move(AllRefs),
+ llvm::make_pointee_range(AllSymbols), std::move(AllRefs),
std::make_tuple(std::move(SymbolSlabs), std::move(RefSlabs),
std::move(RefsStorage), std::move(SymsStorage)),
StorageSize);
diff --git a/clang-tools-extra/clangd/index/Index.cpp b/clang-tools-extra/clangd/index/Index.cpp
index dd4b5eb32a7..4036d671827 100644
--- a/clang-tools-extra/clangd/index/Index.cpp
+++ b/clang-tools-extra/clangd/index/Index.cpp
@@ -14,7 +14,6 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
-using namespace llvm;
namespace clang {
namespace clangd {
@@ -35,14 +34,14 @@ void SymbolLocation::Position::setColumn(uint32_t Col) {
Column = Col;
}
-raw_ostream &operator<<(raw_ostream &OS, const SymbolLocation &L) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolLocation &L) {
if (!L)
return OS << "(none)";
return OS << L.FileURI << "[" << L.Start.line() << ":" << L.Start.column()
<< "-" << L.End.line() << ":" << L.End.column() << ")";
}
-raw_ostream &operator<<(raw_ostream &OS, SymbolOrigin O) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SymbolOrigin O) {
if (O == SymbolOrigin::Unknown)
return OS << "unknown";
constexpr static char Sigils[] = "ADSM4567";
@@ -52,7 +51,7 @@ raw_ostream &operator<<(raw_ostream &OS, SymbolOrigin O) {
return OS;
}
-raw_ostream &operator<<(raw_ostream &OS, Symbol::SymbolFlag F) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, Symbol::SymbolFlag F) {
if (F == Symbol::None)
return OS << "None";
std::string s;
@@ -60,10 +59,10 @@ raw_ostream &operator<<(raw_ostream &OS, Symbol::SymbolFlag F) {
s += "deprecated|";
if (F & Symbol::IndexedForCodeCompletion)
s += "completion|";
- return OS << StringRef(s).rtrim('|');
+ return OS << llvm::StringRef(s).rtrim('|');
}
-raw_ostream &operator<<(raw_ostream &OS, const Symbol &S) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Symbol &S) {
return OS << S.Scope << S.Name;
}
@@ -85,8 +84,8 @@ SymbolSlab::const_iterator SymbolSlab::find(const SymbolID &ID) const {
}
// Copy the underlying data of the symbol into the owned arena.
-static void own(Symbol &S, UniqueStringSaver &Strings) {
- visitStrings(S, [&](StringRef &V) { V = Strings.save(V); });
+static void own(Symbol &S, llvm::UniqueStringSaver &Strings) {
+ visitStrings(S, [&](llvm::StringRef &V) { V = Strings.save(V); });
}
void SymbolSlab::Builder::insert(const Symbol &S) {
@@ -106,14 +105,14 @@ SymbolSlab SymbolSlab::Builder::build() && {
llvm::sort(Symbols,
[](const Symbol &L, const Symbol &R) { return L.ID < R.ID; });
// We may have unused strings from overwritten symbols. Build a new arena.
- BumpPtrAllocator NewArena;
- UniqueStringSaver Strings(NewArena);
+ llvm::BumpPtrAllocator NewArena;
+ llvm::UniqueStringSaver Strings(NewArena);
for (auto &S : Symbols)
own(S, Strings);
return SymbolSlab(std::move(NewArena), std::move(Symbols));
}
-raw_ostream &operator<<(raw_ostream &OS, RefKind K) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, RefKind K) {
if (K == RefKind::Unknown)
return OS << "Unknown";
static const std::vector<const char *> Messages = {"Decl", "Def", "Ref"};
@@ -129,7 +128,7 @@ raw_ostream &operator<<(raw_ostream &OS, RefKind K) {
return OS;
}
-raw_ostream &operator<<(raw_ostream &OS, const Ref &R) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Ref &R) {
return OS << R.Location << ":" << R.Kind;
}
@@ -143,7 +142,7 @@ void RefSlab::Builder::insert(const SymbolID &ID, const Ref &S) {
RefSlab RefSlab::Builder::build() && {
// We can reuse the arena, as it only has unique strings and we need them all.
// Reallocate refs on the arena to reduce waste and indirections when reading.
- std::vector<std::pair<SymbolID, ArrayRef<Ref>>> Result;
+ std::vector<std::pair<SymbolID, llvm::ArrayRef<Ref>>> Result;
Result.reserve(Refs.size());
size_t NumRefs = 0;
for (auto &Sym : Refs) {
@@ -155,7 +154,7 @@ RefSlab RefSlab::Builder::build() && {
NumRefs += SymRefs.size();
auto *Array = Arena.Allocate<Ref>(SymRefs.size());
std::uninitialized_copy(SymRefs.begin(), SymRefs.end(), Array);
- Result.emplace_back(Sym.first, ArrayRef<Ref>(Array, SymRefs.size()));
+ Result.emplace_back(Sym.first, llvm::ArrayRef<Ref>(Array, SymRefs.size()));
}
return RefSlab(std::move(Result), std::move(Arena), NumRefs);
}
@@ -174,8 +173,8 @@ std::shared_ptr<SymbolIndex> SwapIndex::snapshot() const {
return Index;
}
-bool fromJSON(const json::Value &Parameters, FuzzyFindRequest &Request) {
- json::ObjectMapper O(Parameters);
+bool fromJSON(const llvm::json::Value &Parameters, FuzzyFindRequest &Request) {
+ llvm::json::ObjectMapper O(Parameters);
int64_t Limit;
bool OK =
O && O.map("Query", Request.Query) && O.map("Scopes", Request.Scopes) &&
@@ -187,27 +186,27 @@ bool fromJSON(const json::Value &Parameters, FuzzyFindRequest &Request) {
return OK;
}
-json::Value toJSON(const FuzzyFindRequest &Request) {
- return json::Object{
+llvm::json::Value toJSON(const FuzzyFindRequest &Request) {
+ return llvm::json::Object{
{"Query", Request.Query},
- {"Scopes", json::Array{Request.Scopes}},
+ {"Scopes", llvm::json::Array{Request.Scopes}},
{"AnyScope", Request.AnyScope},
{"Limit", Request.Limit},
{"RestrictForCodeCompletion", Request.RestrictForCodeCompletion},
- {"ProximityPaths", json::Array{Request.ProximityPaths}},
+ {"ProximityPaths", llvm::json::Array{Request.ProximityPaths}},
};
}
bool SwapIndex::fuzzyFind(const FuzzyFindRequest &R,
- function_ref<void(const Symbol &)> CB) const {
+ llvm::function_ref<void(const Symbol &)> CB) const {
return snapshot()->fuzzyFind(R, CB);
}
void SwapIndex::lookup(const LookupRequest &R,
- function_ref<void(const Symbol &)> CB) const {
+ llvm::function_ref<void(const Symbol &)> CB) const {
return snapshot()->lookup(R, CB);
}
void SwapIndex::refs(const RefsRequest &R,
- function_ref<void(const Ref &)> CB) const {
+ llvm::function_ref<void(const Ref &)> CB) const {
return snapshot()->refs(R, CB);
}
size_t SwapIndex::estimateMemoryUsage() const {
diff --git a/clang-tools-extra/clangd/index/IndexAction.cpp b/clang-tools-extra/clangd/index/IndexAction.cpp
index 63e1155f318..a6df64b7be3 100644
--- a/clang-tools-extra/clangd/index/IndexAction.cpp
+++ b/clang-tools-extra/clangd/index/IndexAction.cpp
@@ -4,7 +4,6 @@
#include "clang/Index/IndexingAction.h"
#include "clang/Tooling/Tooling.h"
-using namespace llvm;
namespace clang {
namespace clangd {
namespace {
@@ -63,10 +62,10 @@ public:
// Add edges from including files to includes.
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
- StringRef FileName, bool IsAngled,
+ llvm::StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange, const FileEntry *File,
- StringRef SearchPath, StringRef RelativePath,
- const Module *Imported,
+ llvm::StringRef SearchPath,
+ llvm::StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
auto IncludeURI = toURI(File);
if (!IncludeURI)
@@ -116,8 +115,8 @@ public:
Includes(std::move(Includes)),
PragmaHandler(collectIWYUHeaderMaps(this->Includes.get())) {}
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
- StringRef InFile) override {
+ std::unique_ptr<ASTConsumer>
+ CreateASTConsumer(CompilerInstance &CI, llvm::StringRef InFile) override {
CI.getPreprocessor().addCommentHandler(PragmaHandler.get());
if (IncludeGraphCallback != nullptr)
CI.getPreprocessor().addPPCallbacks(
@@ -137,7 +136,7 @@ public:
const auto &CI = getCompilerInstance();
if (CI.hasDiagnostics() &&
CI.getDiagnostics().hasUncompilableErrorOccurred()) {
- errs() << "Skipping TU due to uncompilable errors\n";
+ llvm::errs() << "Skipping TU due to uncompilable errors\n";
return;
}
SymbolsCallback(Collector->takeSymbols());
diff --git a/clang-tools-extra/clangd/index/MemIndex.cpp b/clang-tools-extra/clangd/index/MemIndex.cpp
index 42340e8eeb9..35352e6e686 100644
--- a/clang-tools-extra/clangd/index/MemIndex.cpp
+++ b/clang-tools-extra/clangd/index/MemIndex.cpp
@@ -13,7 +13,6 @@
#include "Quality.h"
#include "Trace.h"
-using namespace llvm;
namespace clang {
namespace clangd {
@@ -25,8 +24,9 @@ std::unique_ptr<SymbolIndex> MemIndex::build(SymbolSlab Slab, RefSlab Refs) {
BackingDataSize);
}
-bool MemIndex::fuzzyFind(const FuzzyFindRequest &Req,
- function_ref<void(const Symbol &)> Callback) const {
+bool MemIndex::fuzzyFind(
+ const FuzzyFindRequest &Req,
+ llvm::function_ref<void(const Symbol &)> Callback) const {
assert(!StringRef(Req.Query).contains("::") &&
"There must be no :: in query.");
trace::Span Tracer("MemIndex fuzzyFind");
@@ -39,7 +39,7 @@ bool MemIndex::fuzzyFind(const FuzzyFindRequest &Req,
const Symbol *Sym = Pair.second;
// Exact match against all possible scopes.
- if (!Req.AnyScope && !is_contained(Req.Scopes, Sym->Scope))
+ if (!Req.AnyScope && !llvm::is_contained(Req.Scopes, Sym->Scope))
continue;
if (Req.RestrictForCodeCompletion &&
!(Sym->Flags & Symbol::IndexedForCodeCompletion))
@@ -57,7 +57,7 @@ bool MemIndex::fuzzyFind(const FuzzyFindRequest &Req,
}
void MemIndex::lookup(const LookupRequest &Req,
- function_ref<void(const Symbol &)> Callback) const {
+ llvm::function_ref<void(const Symbol &)> Callback) const {
trace::Span Tracer("MemIndex lookup");
for (const auto &ID : Req.IDs) {
auto I = Index.find(ID);
@@ -67,7 +67,7 @@ void MemIndex::lookup(const LookupRequest &Req,
}
void MemIndex::refs(const RefsRequest &Req,
- function_ref<void(const Ref &)> Callback) const {
+ llvm::function_ref<void(const Ref &)> Callback) const {
trace::Span Tracer("MemIndex refs");
for (const auto &ReqID : Req.IDs) {
auto SymRefs = Refs.find(ReqID);
diff --git a/clang-tools-extra/clangd/index/Merge.cpp b/clang-tools-extra/clangd/index/Merge.cpp
index 0510b7ad3ac..f599d757aa8 100644
--- a/clang-tools-extra/clangd/index/Merge.cpp
+++ b/clang-tools-extra/clangd/index/Merge.cpp
@@ -14,7 +14,6 @@
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/raw_ostream.h"
-using namespace llvm;
namespace clang {
namespace clangd {
@@ -23,8 +22,9 @@ namespace clangd {
// - find the generating file from each Symbol which is Static-only
// - ask Dynamic if it has that file (needs new SymbolIndex method)
// - if so, drop the Symbol.
-bool MergedIndex::fuzzyFind(const FuzzyFindRequest &Req,
- function_ref<void(const Symbol &)> Callback) const {
+bool MergedIndex::fuzzyFind(
+ const FuzzyFindRequest &Req,
+ llvm::function_ref<void(const Symbol &)> Callback) const {
// We can't step through both sources in parallel. So:
// 1) query all dynamic symbols, slurping results into a slab
// 2) query the static symbols, for each one:
@@ -43,7 +43,7 @@ bool MergedIndex::fuzzyFind(const FuzzyFindRequest &Req,
});
SymbolSlab Dyn = std::move(DynB).build();
- DenseSet<SymbolID> SeenDynamicSymbols;
+ llvm::DenseSet<SymbolID> SeenDynamicSymbols;
More |= Static->fuzzyFind(Req, [&](const Symbol &S) {
auto DynS = Dyn.find(S.ID);
++StaticCount;
@@ -62,8 +62,9 @@ bool MergedIndex::fuzzyFind(const FuzzyFindRequest &Req,
return More;
}
-void MergedIndex::lookup(const LookupRequest &Req,
- function_ref<void(const Symbol &)> Callback) const {
+void MergedIndex::lookup(
+ const LookupRequest &Req,
+ llvm::function_ref<void(const Symbol &)> Callback) const {
trace::Span Tracer("MergedIndex lookup");
SymbolSlab::Builder B;
@@ -84,7 +85,7 @@ void MergedIndex::lookup(const LookupRequest &Req,
}
void MergedIndex::refs(const RefsRequest &Req,
- function_ref<void(const Ref &)> Callback) const {
+ llvm::function_ref<void(const Ref &)> Callback) const {
trace::Span Tracer("MergedIndex refs");
// We don't want duplicated refs from the static/dynamic indexes,
// and we can't reliably duplicate them because offsets may differ slightly.
@@ -94,7 +95,7 @@ void MergedIndex::refs(const RefsRequest &Req,
// FIXME: The heuristic fails if the dynamic index contains a file, but all
// refs were removed (we will report stale ones from the static index).
// Ultimately we should explicit check which index has the file instead.
- StringSet<> DynamicIndexFileURIs;
+ llvm::StringSet<> DynamicIndexFileURIs;
Dynamic->refs(Req, [&](const Ref &O) {
DynamicIndexFileURIs.insert(O.Location.FileURI);
Callback(O);
diff --git a/clang-tools-extra/clangd/index/Serialization.cpp b/clang-tools-extra/clangd/index/Serialization.cpp
index 1d17a42c486..a4f99b1cb29 100644
--- a/clang-tools-extra/clangd/index/Serialization.cpp
+++ b/clang-tools-extra/clangd/index/Serialization.cpp
@@ -17,12 +17,12 @@
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
-using namespace llvm;
namespace clang {
namespace clangd {
namespace {
-Error makeError(const Twine &Msg) {
- return make_error<StringError>(Msg, inconvertibleErrorCode());
+llvm::Error makeError(const llvm::Twine &Msg) {
+ return llvm::make_error<llvm::StringError>(Msg,
+ llvm::inconvertibleErrorCode());
}
// IO PRIMITIVES
@@ -40,14 +40,14 @@ class Reader {
bool Err = false;
public:
- Reader(StringRef Data) : Begin(Data.begin()), End(Data.end()) {}
+ Reader(llvm::StringRef Data) : Begin(Data.begin()), End(Data.end()) {}
// The "error" bit is set by reading past EOF or reading invalid data.
// When in an error state, reads may return zero values: callers should check.
bool err() const { return Err; }
// Did we read all the data, or encounter an error?
bool eof() const { return Begin == End || Err; }
// All the data we didn't read yet.
- StringRef rest() const { return StringRef(Begin, End - Begin); }
+ llvm::StringRef rest() const { return llvm::StringRef(Begin, End - Begin); }
uint8_t consume8() {
if (LLVM_UNLIKELY(Begin == End)) {
@@ -62,17 +62,17 @@ public:
Err = true;
return 0;
}
- auto Ret = support::endian::read32le(Begin);
+ auto Ret = llvm::support::endian::read32le(Begin);
Begin += 4;
return Ret;
}
- StringRef consume(int N) {
+ llvm::StringRef consume(int N) {
if (LLVM_UNLIKELY(Begin + N > End)) {
Err = true;
- return StringRef();
+ return llvm::StringRef();
}
- StringRef Ret(Begin, N);
+ llvm::StringRef Ret(Begin, N);
Begin += N;
return Ret;
}
@@ -90,28 +90,28 @@ public:
return Val;
}
- StringRef consumeString(ArrayRef<StringRef> Strings) {
+ llvm::StringRef consumeString(llvm::ArrayRef<llvm::StringRef> Strings) {
auto StringIndex = consumeVar();
if (LLVM_UNLIKELY(StringIndex >= Strings.size())) {
Err = true;
- return StringRef();
+ return llvm::StringRef();
}
return Strings[StringIndex];
}
SymbolID consumeID() {
- StringRef Raw = consume(SymbolID::RawSize); // short if truncated.
+ llvm::StringRef Raw = consume(SymbolID::RawSize); // short if truncated.
return LLVM_UNLIKELY(err()) ? SymbolID() : SymbolID::fromRaw(Raw);
}
};
-void write32(uint32_t I, raw_ostream &OS) {
+void write32(uint32_t I, llvm::raw_ostream &OS) {
char buf[4];
- support::endian::write32le(buf, I);
+ llvm::support::endian::write32le(buf, I);
OS.write(buf, sizeof(buf));
}
-void writeVar(uint32_t I, raw_ostream &OS) {
+void writeVar(uint32_t I, llvm::raw_ostream &OS) {
constexpr static uint8_t More = 1 << 7;
if (LLVM_LIKELY(I < 1 << 7)) {
OS.write(I);
@@ -142,10 +142,10 @@ void writeVar(uint32_t I, raw_ostream &OS) {
// Maps each string to a canonical representation.
// Strings remain owned externally (e.g. by SymbolSlab).
class StringTableOut {
- DenseSet<StringRef> Unique;
- std::vector<StringRef> Sorted;
+ llvm::DenseSet<llvm::StringRef> Unique;
+ std::vector<llvm::StringRef> Sorted;
// Since strings are interned, look up can be by pointer.
- DenseMap<std::pair<const char *, size_t>, unsigned> Index;
+ llvm::DenseMap<std::pair<const char *, size_t>, unsigned> Index;
public:
StringTableOut() {
@@ -154,22 +154,22 @@ public:
Unique.insert("");
}
// Add a string to the table. Overwrites S if an identical string exists.
- void intern(StringRef &S) { S = *Unique.insert(S).first; };
+ void intern(llvm::StringRef &S) { S = *Unique.insert(S).first; };
// Finalize the table and write it to OS. No more strings may be added.
- void finalize(raw_ostream &OS) {
+ void finalize(llvm::raw_ostream &OS) {
Sorted = {Unique.begin(), Unique.end()};
llvm::sort(Sorted);
for (unsigned I = 0; I < Sorted.size(); ++I)
Index.try_emplace({Sorted[I].data(), Sorted[I].size()}, I);
std::string RawTable;
- for (StringRef S : Sorted) {
+ for (llvm::StringRef S : Sorted) {
RawTable.append(S);
RawTable.push_back(0);
}
- if (zlib::isAvailable()) {
- SmallString<1> Compressed;
- cantFail(zlib::compress(RawTable, Compressed));
+ if (llvm::zlib::isAvailable()) {
+ llvm::SmallString<1> Compressed;
+ llvm::cantFail(llvm::zlib::compress(RawTable, Compressed));
write32(RawTable.size(), OS);
OS << Compressed;
} else {
@@ -178,7 +178,7 @@ public:
}
}
// Get the ID of an string, which must be interned. Table must be finalized.
- unsigned index(StringRef S) const {
+ unsigned index(llvm::StringRef S) const {
assert(!Sorted.empty() && "table not finalized");
assert(Index.count({S.data(), S.size()}) && "string not interned");
return Index.find({S.data(), S.size()})->second;
@@ -186,33 +186,33 @@ public:
};
struct StringTableIn {
- BumpPtrAllocator Arena;
- std::vector<StringRef> Strings;
+ llvm::BumpPtrAllocator Arena;
+ std::vector<llvm::StringRef> Strings;
};
-Expected<StringTableIn> readStringTable(StringRef Data) {
+llvm::Expected<StringTableIn> readStringTable(llvm::StringRef Data) {
Reader R(Data);
size_t UncompressedSize = R.consume32();
if (R.err())
return makeError("Truncated string table");
- StringRef Uncompressed;
- SmallString<1> UncompressedStorage;
+ llvm::StringRef Uncompressed;
+ llvm::SmallString<1> UncompressedStorage;
if (UncompressedSize == 0) // No compression
Uncompressed = R.rest();
else {
- if (Error E = llvm::zlib::uncompress(R.rest(), UncompressedStorage,
- UncompressedSize))
+ if (llvm::Error E = llvm::zlib::uncompress(R.rest(), UncompressedStorage,
+ UncompressedSize))
return std::move(E);
Uncompressed = UncompressedStorage;
}
StringTableIn Table;
- StringSaver Saver(Table.Arena);
+ llvm::StringSaver Saver(Table.Arena);
R = Reader(Uncompressed);
for (Reader R(Uncompressed); !R.eof();) {
auto Len = R.rest().find(0);
- if (Len == StringRef::npos)
+ if (Len == llvm::StringRef::npos)
return makeError("Bad string table: not null terminated");
Table.Strings.push_back(Saver.save(R.consume(Len)));
R.consume8();
@@ -229,7 +229,7 @@ Expected<StringTableIn> readStringTable(StringRef Data) {
// - most numbers encode as varint
void writeLocation(const SymbolLocation &Loc, const StringTableOut &Strings,
- raw_ostream &OS) {
+ llvm::raw_ostream &OS) {
writeVar(Strings.index(Loc.FileURI), OS);
for (const auto &Endpoint : {Loc.Start, Loc.End}) {
writeVar(Endpoint.line(), OS);
@@ -237,7 +237,8 @@ void writeLocation(const SymbolLocation &Loc, const StringTableOut &Strings,
}
}
-SymbolLocation readLocation(Reader &Data, ArrayRef<StringRef> Strings) {
+SymbolLocation readLocation(Reader &Data,
+ llvm::ArrayRef<llvm::StringRef> Strings) {
SymbolLocation Loc;
Loc.FileURI = Data.consumeString(Strings).data();
for (auto *Endpoint : {&Loc.Start, &Loc.End}) {
@@ -261,7 +262,8 @@ IncludeGraphNode readIncludeGraphNode(Reader &Data,
}
void writeIncludeGraphNode(const IncludeGraphNode &IGN,
- const StringTableOut &Strings, raw_ostream &OS) {
+ const StringTableOut &Strings,
+ llvm::raw_ostream &OS) {
OS.write(IGN.IsTU);
writeVar(Strings.index(IGN.URI), OS);
llvm::StringRef Hash(reinterpret_cast<const char *>(IGN.Digest.data()),
@@ -273,7 +275,7 @@ void writeIncludeGraphNode(const IncludeGraphNode &IGN,
}
void writeSymbol(const Symbol &Sym, const StringTableOut &Strings,
- raw_ostream &OS) {
+ llvm::raw_ostream &OS) {
OS << Sym.ID.raw(); // TODO: once we start writing xrefs and posting lists,
// symbol IDs should probably be in a string table.
OS.write(static_cast<uint8_t>(Sym.SymInfo.Kind));
@@ -300,7 +302,7 @@ void writeSymbol(const Symbol &Sym, const StringTableOut &Strings,
WriteInclude(Include);
}
-Symbol readSymbol(Reader &Data, ArrayRef<StringRef> Strings) {
+Symbol readSymbol(Reader &Data, llvm::ArrayRef<llvm::StringRef> Strings) {
Symbol Sym;
Sym.ID = Data.consumeID();
Sym.SymInfo.Kind = static_cast<index::SymbolKind>(Data.consume8());
@@ -332,8 +334,8 @@ Symbol readSymbol(Reader &Data, ArrayRef<StringRef> Strings) {
// - Ref[NumRefs]
// Fields of Ref are encoded in turn, see implementation.
-void writeRefs(const SymbolID &ID, ArrayRef<Ref> Refs,
- const StringTableOut &Strings, raw_ostream &OS) {
+void writeRefs(const SymbolID &ID, llvm::ArrayRef<Ref> Refs,
+ const StringTableOut &Strings, llvm::raw_ostream &OS) {
OS << ID.raw();
writeVar(Refs.size(), OS);
for (const auto &Ref : Refs) {
@@ -342,8 +344,8 @@ void writeRefs(const SymbolID &ID, ArrayRef<Ref> Refs,
}
}
-std::pair<SymbolID, std::vector<Ref>> readRefs(Reader &Data,
- ArrayRef<StringRef> Strings) {
+std::pair<SymbolID, std::vector<Ref>>
+readRefs(Reader &Data, llvm::ArrayRef<llvm::StringRef> Strings) {
std::pair<SymbolID, std::vector<Ref>> Result;
Result.first = Data.consumeID();
Result.second.resize(Data.consumeVar());
@@ -368,17 +370,18 @@ std::pair<SymbolID, std::vector<Ref>> readRefs(Reader &Data,
// data. Later we may want to support some backward compatibility.
constexpr static uint32_t Version = 8;
-Expected<IndexFileIn> readRIFF(StringRef Data) {
+llvm::Expected<IndexFileIn> readRIFF(llvm::StringRef Data) {
auto RIFF = riff::readFile(Data);
if (!RIFF)
return RIFF.takeError();
if (RIFF->Type != riff::fourCC("CdIx"))
return makeError("wrong RIFF type");
- StringMap<StringRef> Chunks;
+ llvm::StringMap<llvm::StringRef> Chunks;
for (const auto &Chunk : RIFF->Chunks)
- Chunks.try_emplace(StringRef(Chunk.ID.data(), Chunk.ID.size()), Chunk.Data);
+ Chunks.try_emplace(llvm::StringRef(Chunk.ID.data(), Chunk.ID.size()),
+ Chunk.Data);
- for (StringRef RequiredChunk : {"meta", "stri"})
+ for (llvm::StringRef RequiredChunk : {"meta", "stri"})
if (!Chunks.count(RequiredChunk))
return makeError("missing required chunk " + RequiredChunk);
@@ -439,14 +442,14 @@ void visitStrings(IncludeGraphNode &IGN, const Callback &CB) {
CB(Include);
}
-void writeRIFF(const IndexFileOut &Data, raw_ostream &OS) {
+void writeRIFF(const IndexFileOut &Data, llvm::raw_ostream &OS) {
assert(Data.Symbols && "An index file without symbols makes no sense!");
riff::File RIFF;
RIFF.Type = riff::fourCC("CdIx");
- SmallString<4> Meta;
+ llvm::SmallString<4> Meta;
{
- raw_svector_ostream MetaOS(Meta);
+ llvm::raw_svector_ostream MetaOS(Meta);
write32(Version, MetaOS);
}
RIFF.Chunks.push_back({riff::fourCC("meta"), Meta});
@@ -455,13 +458,15 @@ void writeRIFF(const IndexFileOut &Data, raw_ostream &OS) {
std::vector<Symbol> Symbols;
for (const auto &Sym : *Data.Symbols) {
Symbols.emplace_back(Sym);
- visitStrings(Symbols.back(), [&](StringRef &S) { Strings.intern(S); });
+ visitStrings(Symbols.back(),
+ [&](llvm::StringRef &S) { Strings.intern(S); });
}
std::vector<IncludeGraphNode> Sources;
if (Data.Sources)
for (const auto &Source : *Data.Sources) {
Sources.push_back(Source.getValue());
- visitStrings(Sources.back(), [&](StringRef &S) { Strings.intern(S); });
+ visitStrings(Sources.back(),
+ [&](llvm::StringRef &S) { Strings.intern(S); });
}
std::vector<std::pair<SymbolID, std::vector<Ref>>> Refs;
@@ -469,7 +474,7 @@ void writeRIFF(const IndexFileOut &Data, raw_ostream &OS) {
for (const auto &Sym : *Data.Refs) {
Refs.emplace_back(Sym);
for (auto &Ref : Refs.back().second) {
- StringRef File = Ref.Location.FileURI;
+ llvm::StringRef File = Ref.Location.FileURI;
Strings.intern(File);
Ref.Location.FileURI = File.data();
}
@@ -478,14 +483,14 @@ void writeRIFF(const IndexFileOut &Data, raw_ostream &OS) {
std::string StringSection;
{
- raw_string_ostream StringOS(StringSection);
+ llvm::raw_string_ostream StringOS(StringSection);
Strings.finalize(StringOS);
}
RIFF.Chunks.push_back({riff::fourCC("stri"), StringSection});
std::string SymbolSection;
{
- raw_string_ostream SymbolOS(SymbolSection);
+ llvm::raw_string_ostream SymbolOS(SymbolSection);
for (const auto &Sym : Symbols)
writeSymbol(Sym, Strings, SymbolOS);
}
@@ -494,7 +499,7 @@ void writeRIFF(const IndexFileOut &Data, raw_ostream &OS) {
std::string RefsSection;
if (Data.Refs) {
{
- raw_string_ostream RefsOS(RefsSection);
+ llvm::raw_string_ostream RefsOS(RefsSection);
for (const auto &Sym : Refs)
writeRefs(Sym.first, Sym.second, Strings, RefsOS);
}
@@ -504,7 +509,7 @@ void writeRIFF(const IndexFileOut &Data, raw_ostream &OS) {
std::string SrcsSection;
{
{
- raw_string_ostream SrcsOS(SrcsSection);
+ llvm::raw_string_ostream SrcsOS(SrcsSection);
for (const auto &SF : Sources)
writeIncludeGraphNode(SF, Strings, SrcsOS);
}
@@ -517,10 +522,10 @@ void writeRIFF(const IndexFileOut &Data, raw_ostream &OS) {
} // namespace
// Defined in YAMLSerialization.cpp.
-void writeYAML(const IndexFileOut &, raw_ostream &);
-Expected<IndexFileIn> readYAML(StringRef);
+void writeYAML(const IndexFileOut &, llvm::raw_ostream &);
+llvm::Expected<IndexFileIn> readYAML(llvm::StringRef);
-raw_ostream &operator<<(raw_ostream &OS, const IndexFileOut &O) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const IndexFileOut &O) {
switch (O.Format) {
case IndexFileFormat::RIFF:
writeRIFF(O, OS);
@@ -532,22 +537,23 @@ raw_ostream &operator<<(raw_ostream &OS, const IndexFileOut &O) {
return OS;
}
-Expected<IndexFileIn> readIndexFile(StringRef Data) {
+llvm::Expected<IndexFileIn> readIndexFile(llvm::StringRef Data) {
if (Data.startswith("RIFF")) {
return readRIFF(Data);
} else if (auto YAMLContents = readYAML(Data)) {
return std::move(*YAMLContents);
} else {
return makeError("Not a RIFF file and failed to parse as YAML: " +
- toString(YAMLContents.takeError()));
+ llvm::toString(YAMLContents.takeError()));
}
}
-std::unique_ptr<SymbolIndex> loadIndex(StringRef SymbolFilename, bool UseDex) {
+std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFilename,
+ bool UseDex) {
trace::Span OverallTracer("LoadIndex");
- auto Buffer = MemoryBuffer::getFile(SymbolFilename);
+ auto Buffer = llvm::MemoryBuffer::getFile(SymbolFilename);
if (!Buffer) {
- errs() << "Can't open " << SymbolFilename << "\n";
+ llvm::errs() << "Can't open " << SymbolFilename << "\n";
return nullptr;
}
@@ -561,7 +567,7 @@ std::unique_ptr<SymbolIndex> loadIndex(StringRef SymbolFilename, bool UseDex) {
if (I->Refs)
Refs = std::move(*I->Refs);
} else {
- errs() << "Bad Index: " << toString(I.takeError()) << "\n";
+ llvm::errs() << "Bad Index: " << llvm::toString(I.takeError()) << "\n";
return nullptr;
}
}
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 1e5478c74ae..cdc6aa5c01f 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -29,7 +29,6 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
-using namespace llvm;
namespace clang {
namespace clangd {
namespace {
@@ -60,9 +59,9 @@ std::string toURI(const SourceManager &SM, llvm::StringRef Path,
}
// We don't perform is_absolute check in an else branch because makeAbsolute
// might return a relative path on some InMemoryFileSystems.
- if (!sys::path::is_absolute(AbsolutePath) && !Opts.FallbackDir.empty())
- sys::fs::make_absolute(Opts.FallbackDir, AbsolutePath);
- sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/true);
+ if (!llvm::sys::path::is_absolute(AbsolutePath) && !Opts.FallbackDir.empty())
+ llvm::sys::fs::make_absolute(Opts.FallbackDir, AbsolutePath);
+ llvm::sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/true);
return URI::create(AbsolutePath).toString();
}
@@ -102,7 +101,7 @@ bool isPrivateProtoDecl(const NamedDecl &ND) {
// will include OUTER_INNER and exclude some_enum_constant.
// FIXME: the heuristic relies on naming style (i.e. no underscore in
// user-defined names) and can be improved.
- return (ND.getKind() != Decl::EnumConstant) || any_of(Name, islower);
+ return (ND.getKind() != Decl::EnumConstant) || llvm::any_of(Name, islower);
}
// We only collect #include paths for symbols that are suitable for global code
@@ -130,9 +129,9 @@ bool shouldCollectIncludePath(index::SymbolKind Kind) {
/// Gets a canonical include (URI of the header or <header> or "header") for
/// header of \p Loc.
/// Returns None if fails to get include header for \p Loc.
-Optional<std::string> getIncludeHeader(StringRef QName, const SourceManager &SM,
- SourceLocation Loc,
- const SymbolCollector::Options &Opts) {
+llvm::Optional<std::string>
+getIncludeHeader(llvm::StringRef QName, const SourceManager &SM,
+ SourceLocation Loc, const SymbolCollector::Options &Opts) {
std::vector<std::string> Headers;
// Collect the #include stack.
while (true) {
@@ -148,7 +147,7 @@ Optional<std::string> getIncludeHeader(StringRef QName, const SourceManager &SM,
}
if (Headers.empty())
return None;
- StringRef Header = Headers[0];
+ llvm::StringRef Header = Headers[0];
if (Opts.Includes) {
Header = Opts.Includes->mapHeader(Headers, QName);
if (Header.startswith("<") || Header.startswith("\""))
@@ -186,11 +185,11 @@ bool shouldIndexFile(const SourceManager &SM, FileID FID,
}
// Return the symbol location of the token at \p TokLoc.
-Optional<SymbolLocation> getTokenLocation(SourceLocation TokLoc,
- const SourceManager &SM,
- const SymbolCollector::Options &Opts,
- const clang::LangOptions &LangOpts,
- std::string &FileURIStorage) {
+llvm::Optional<SymbolLocation>
+getTokenLocation(SourceLocation TokLoc, const SourceManager &SM,
+ const SymbolCollector::Options &Opts,
+ const clang::LangOptions &LangOpts,
+ std::string &FileURIStorage) {
auto Path = SM.getFilename(TokLoc);
if (Path.empty())
return None;
@@ -299,7 +298,7 @@ bool SymbolCollector::shouldCollectSymbol(const NamedDecl &ND,
// Always return true to continue indexing.
bool SymbolCollector::handleDeclOccurence(
const Decl *D, index::SymbolRoleSet Roles,
- ArrayRef<index::SymbolRelation> Relations, SourceLocation Loc,
+ llvm::ArrayRef<index::SymbolRelation> Relations, SourceLocation Loc,
index::IndexDataConsumer::ASTNodeInfo ASTNode) {
assert(ASTCtx && PP.get() && "ASTContext and Preprocessor must be set.");
assert(CompletionAllocator && CompletionTUInfo);
@@ -461,8 +460,8 @@ void SymbolCollector::finish() {
}
const auto &SM = ASTCtx->getSourceManager();
- DenseMap<FileID, std::string> URICache;
- auto GetURI = [&](FileID FID) -> Optional<std::string> {
+ llvm::DenseMap<FileID, std::string> URICache;
+ auto GetURI = [&](FileID FID) -> llvm::Optional<std::string> {
auto Found = URICache.find(FID);
if (Found == URICache.end()) {
if (auto *FileEntry = SM.getFileEntryForID(FID)) {
diff --git a/clang-tools-extra/clangd/index/SymbolID.cpp b/clang-tools-extra/clangd/index/SymbolID.cpp
index 0ab74810a92..1fd427445f7 100644
--- a/clang-tools-extra/clangd/index/SymbolID.cpp
+++ b/clang-tools-extra/clangd/index/SymbolID.cpp
@@ -10,40 +10,42 @@
#include "SymbolID.h"
#include "llvm/Support/SHA1.h"
-using namespace llvm;
namespace clang {
namespace clangd {
-SymbolID::SymbolID(StringRef USR) {
- auto Hash = llvm::SHA1::hash(arrayRefFromStringRef(USR));
+SymbolID::SymbolID(llvm::StringRef USR) {
+ auto Hash = llvm::SHA1::hash(llvm::arrayRefFromStringRef(USR));
static_assert(sizeof(Hash) >= RawSize, "RawSize larger than SHA1");
memcpy(HashValue.data(), Hash.data(), RawSize);
}
llvm::StringRef SymbolID::raw() const {
- return StringRef(reinterpret_cast<const char *>(HashValue.data()), RawSize);
+ return llvm::StringRef(reinterpret_cast<const char *>(HashValue.data()),
+ RawSize);
}
-SymbolID SymbolID::fromRaw(StringRef Raw) {
+SymbolID SymbolID::fromRaw(llvm::StringRef Raw) {
SymbolID ID;
assert(Raw.size() == RawSize);
memcpy(ID.HashValue.data(), Raw.data(), RawSize);
return ID;
}
-std::string SymbolID::str() const { return toHex(raw()); }
+std::string SymbolID::str() const { return llvm::toHex(raw()); }
-Expected<SymbolID> SymbolID::fromStr(StringRef Str) {
+llvm::Expected<SymbolID> SymbolID::fromStr(llvm::StringRef Str) {
if (Str.size() != RawSize * 2)
- return createStringError(inconvertibleErrorCode(), "Bad ID length");
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Bad ID length");
for (char C : Str)
- if (!isHexDigit(C))
- return createStringError(inconvertibleErrorCode(), "Bad hex ID");
- return fromRaw(fromHex(Str));
+ if (!llvm::isHexDigit(C))
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Bad hex ID");
+ return fromRaw(llvm::fromHex(Str));
}
-raw_ostream &operator<<(raw_ostream &OS, const SymbolID &ID) {
- return OS << toHex(ID.raw());
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolID &ID) {
+ return OS << llvm::toHex(ID.raw());
}
llvm::hash_code hash_value(const SymbolID &ID) {
diff --git a/clang-tools-extra/clangd/index/YAMLSerialization.cpp b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
index d3ffdddcaa4..27ed299e395 100644
--- a/clang-tools-extra/clangd/index/YAMLSerialization.cpp
+++ b/clang-tools-extra/clangd/index/YAMLSerialization.cpp
@@ -28,8 +28,6 @@
#include "llvm/Support/raw_ostream.h"
#include <cstdint>
-using namespace llvm;
-
LLVM_YAML_IS_SEQUENCE_VECTOR(clang::clangd::Symbol::IncludeHeaderWithReferences)
LLVM_YAML_IS_SEQUENCE_VECTOR(clang::clangd::Ref)
@@ -38,8 +36,8 @@ using RefBundle =
std::pair<clang::clangd::SymbolID, std::vector<clang::clangd::Ref>>;
// This is a pale imitation of std::variant<Symbol, RefBundle>
struct VariantEntry {
- Optional<clang::clangd::Symbol> Symbol;
- Optional<RefBundle> Refs;
+ llvm::Optional<clang::clangd::Symbol> Symbol;
+ llvm::Optional<RefBundle> Refs;
};
// A class helps YAML to serialize the 32-bit encoded position (Line&Column),
// as YAMLIO can't directly map bitfields.
@@ -66,14 +64,14 @@ using clang::index::SymbolLanguage;
struct NormalizedSymbolID {
NormalizedSymbolID(IO &) {}
NormalizedSymbolID(IO &, const SymbolID &ID) {
- raw_string_ostream OS(HexString);
+ llvm::raw_string_ostream OS(HexString);
OS << ID;
}
SymbolID denormalize(IO &I) {
auto ID = SymbolID::fromStr(HexString);
if (!ID) {
- I.setError(toString(ID.takeError()));
+ I.setError(llvm::toString(ID.takeError()));
return SymbolID();
}
return *ID;
@@ -294,8 +292,8 @@ template <> struct MappingTraits<VariantEntry> {
namespace clang {
namespace clangd {
-void writeYAML(const IndexFileOut &O, raw_ostream &OS) {
- yaml::Output Yout(OS);
+void writeYAML(const IndexFileOut &O, llvm::raw_ostream &OS) {
+ llvm::yaml::Output Yout(OS);
for (const auto &Sym : *O.Symbols) {
VariantEntry Entry;
Entry.Symbol = Sym;
@@ -309,17 +307,18 @@ void writeYAML(const IndexFileOut &O, raw_ostream &OS) {
}
}
-Expected<IndexFileIn> readYAML(StringRef Data) {
+llvm::Expected<IndexFileIn> readYAML(llvm::StringRef Data) {
SymbolSlab::Builder Symbols;
RefSlab::Builder Refs;
- BumpPtrAllocator Arena; // store the underlying data of Position::FileURI.
- UniqueStringSaver Strings(Arena);
- yaml::Input Yin(Data, &Strings);
+ llvm::BumpPtrAllocator
+ Arena; // store the underlying data of Position::FileURI.
+ llvm::UniqueStringSaver Strings(Arena);
+ llvm::yaml::Input Yin(Data, &Strings);
do {
VariantEntry Variant;
Yin >> Variant;
if (Yin.error())
- return errorCodeToError(Yin.error());
+ return llvm::errorCodeToError(Yin.error());
if (Variant.Symbol)
Symbols.insert(*Variant.Symbol);
if (Variant.Refs)
@@ -336,20 +335,20 @@ Expected<IndexFileIn> readYAML(StringRef Data) {
std::string toYAML(const Symbol &S) {
std::string Buf;
{
- raw_string_ostream OS(Buf);
- yaml::Output Yout(OS);
+ llvm::raw_string_ostream OS(Buf);
+ llvm::yaml::Output Yout(OS);
Symbol Sym = S; // copy: Yout<< requires mutability.
Yout << Sym;
}
return Buf;
}
-std::string toYAML(const std::pair<SymbolID, ArrayRef<Ref>> &Data) {
+std::string toYAML(const std::pair<SymbolID, llvm::ArrayRef<Ref>> &Data) {
RefBundle Refs = {Data.first, Data.second};
std::string Buf;
{
- raw_string_ostream OS(Buf);
- yaml::Output Yout(OS);
+ llvm::raw_string_ostream OS(Buf);
+ llvm::yaml::Output Yout(OS);
Yout << Refs;
}
return Buf;
diff --git a/clang-tools-extra/clangd/index/dex/Dex.cpp b/clang-tools-extra/clangd/index/dex/Dex.cpp
index 8d64e1b48c9..157d4668856 100644
--- a/clang-tools-extra/clangd/index/dex/Dex.cpp
+++ b/clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -20,7 +20,6 @@
#include <algorithm>
#include <queue>
-using namespace llvm;
namespace clang {
namespace clangd {
namespace dex {
@@ -50,7 +49,7 @@ std::vector<Token> generateSearchTokens(const Symbol &Sym) {
std::vector<Token> Result = generateIdentifierTrigrams(Sym.Name);
Result.emplace_back(Token::Kind::Scope, Sym.Scope);
// Skip token generation for symbols with unknown declaration location.
- if (!StringRef(Sym.CanonicalDeclaration.FileURI).empty())
+ if (!llvm::StringRef(Sym.CanonicalDeclaration.FileURI).empty())
for (const auto &ProximityURI :
generateProximityURIs(Sym.CanonicalDeclaration.FileURI))
Result.emplace_back(Token::Kind::ProximityURI, ProximityURI);
@@ -60,14 +59,14 @@ std::vector<Token> generateSearchTokens(const Symbol &Sym) {
}
// Constructs BOOST iterators for Path Proximities.
-std::unique_ptr<Iterator>
-createFileProximityIterator(ArrayRef<std::string> ProximityPaths,
- const DenseMap<Token, PostingList> &InvertedIndex,
- const Corpus &Corpus) {
+std::unique_ptr<Iterator> createFileProximityIterator(
+ llvm::ArrayRef<std::string> ProximityPaths,
+ const llvm::DenseMap<Token, PostingList> &InvertedIndex,
+ const Corpus &Corpus) {
std::vector<std::unique_ptr<Iterator>> BoostingIterators;
// Deduplicate parent URIs extracted from the ProximityPaths.
- StringSet<> ParentURIs;
- StringMap<SourceParams> Sources;
+ llvm::StringSet<> ParentURIs;
+ llvm::StringMap<SourceParams> Sources;
for (const auto &Path : ProximityPaths) {
Sources[Path] = SourceParams();
auto PathURI = URI::create(Path);
@@ -124,7 +123,7 @@ void Dex::buildIndex() {
}
// Populate TempInvertedIndex with lists for index symbols.
- DenseMap<Token, std::vector<DocID>> TempInvertedIndex;
+ llvm::DenseMap<Token, std::vector<DocID>> TempInvertedIndex;
for (DocID SymbolRank = 0; SymbolRank < Symbols.size(); ++SymbolRank) {
const auto *Sym = Symbols[SymbolRank];
for (const auto &Token : generateSearchTokens(*Sym))
@@ -147,7 +146,7 @@ std::unique_ptr<Iterator> Dex::iterator(const Token &Tok) const {
/// while applying Callback to each symbol in the order of decreasing quality
/// of the matched symbols.
bool Dex::fuzzyFind(const FuzzyFindRequest &Req,
- function_ref<void(const Symbol &)> Callback) const {
+ llvm::function_ref<void(const Symbol &)> Callback) const {
assert(!StringRef(Req.Query).contains("::") &&
"There must be no :: in query.");
trace::Span Tracer("Dex fuzzyFind");
@@ -190,7 +189,7 @@ bool Dex::fuzzyFind(const FuzzyFindRequest &Req,
// FIXME(kbobyrev): Tune this ratio.
if (Req.Limit)
Root = Corpus.limit(move(Root), *Req.Limit * 100);
- SPAN_ATTACH(Tracer, "query", to_string(*Root));
+ SPAN_ATTACH(Tracer, "query", llvm::to_string(*Root));
vlog("Dex query tree: {0}", *Root);
using IDAndScore = std::pair<DocID, float>;
@@ -204,7 +203,7 @@ bool Dex::fuzzyFind(const FuzzyFindRequest &Req,
for (const auto &IDAndScore : IDAndScores) {
const DocID SymbolDocID = IDAndScore.first;
const auto *Sym = Symbols[SymbolDocID];
- const Optional<float> Score = Filter.match(Sym->Name);
+ const llvm::Optional<float> Score = Filter.match(Sym->Name);
if (!Score)
continue;
// Combine Fuzzy Matching score, precomputed symbol quality and boosting
@@ -225,7 +224,7 @@ bool Dex::fuzzyFind(const FuzzyFindRequest &Req,
}
void Dex::lookup(const LookupRequest &Req,
- function_ref<void(const Symbol &)> Callback) const {
+ llvm::function_ref<void(const Symbol &)> Callback) const {
trace::Span Tracer("Dex lookup");
for (const auto &ID : Req.IDs) {
auto I = LookupTable.find(ID);
@@ -235,7 +234,7 @@ void Dex::lookup(const LookupRequest &Req,
}
void Dex::refs(const RefsRequest &Req,
- function_ref<void(const Ref &)> Callback) const {
+ llvm::function_ref<void(const Ref &)> Callback) const {
trace::Span Tracer("Dex refs");
for (const auto &ID : Req.IDs)
for (const auto &Ref : Refs.lookup(ID))
@@ -254,13 +253,13 @@ size_t Dex::estimateMemoryUsage() const {
return Bytes + BackingDataSize;
}
-std::vector<std::string> generateProximityURIs(StringRef URIPath) {
+std::vector<std::string> generateProximityURIs(llvm::StringRef URIPath) {
std::vector<std::string> Result;
auto ParsedURI = URI::parse(URIPath);
assert(ParsedURI &&
"Non-empty argument of generateProximityURIs() should be a valid "
"URI.");
- StringRef Body = ParsedURI->body();
+ llvm::StringRef Body = ParsedURI->body();
// FIXME(kbobyrev): Currently, this is a heuristic which defines the maximum
// size of resulting vector. Some projects might want to have higher limit if
// the file hierarchy is deeper. For the generic case, it would be useful to
@@ -273,7 +272,7 @@ std::vector<std::string> generateProximityURIs(StringRef URIPath) {
while (!Body.empty() && --Limit > 0) {
// FIXME(kbobyrev): Parsing and encoding path to URIs is not necessary and
// could be optimized.
- Body = sys::path::parent_path(Body, sys::path::Style::posix);
+ Body = llvm::sys::path::parent_path(Body, llvm::sys::path::Style::posix);
URI TokenURI(ParsedURI->scheme(), ParsedURI->authority(), Body);
if (!Body.empty())
Result.emplace_back(TokenURI.toString());
diff --git a/clang-tools-extra/clangd/index/dex/Iterator.cpp b/clang-tools-extra/clangd/index/dex/Iterator.cpp
index 9e62c155ee7..0b132b94c43 100644
--- a/clang-tools-extra/clangd/index/dex/Iterator.cpp
+++ b/clang-tools-extra/clangd/index/dex/Iterator.cpp
@@ -13,7 +13,6 @@
#include <cassert>
#include <numeric>
-using namespace llvm;
namespace clang {
namespace clangd {
namespace dex {
@@ -77,7 +76,7 @@ public:
}
private:
- raw_ostream &dump(raw_ostream &OS) const override {
+ llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
OS << "(& ";
auto Separator = "";
for (const auto &Child : Children) {
@@ -198,7 +197,7 @@ public:
}
private:
- raw_ostream &dump(raw_ostream &OS) const override {
+ llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
OS << "(| ";
auto Separator = "";
for (const auto &Child : Children) {
@@ -246,7 +245,9 @@ public:
size_t estimateSize() const override { return Size; }
private:
- raw_ostream &dump(raw_ostream &OS) const override { return OS << "true"; }
+ llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
+ return OS << "true";
+ }
DocID Index = 0;
/// Size of the underlying virtual PostingList.
@@ -271,7 +272,9 @@ public:
size_t estimateSize() const override { return 0; }
private:
- raw_ostream &dump(raw_ostream &OS) const override { return OS << "false"; }
+ llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
+ return OS << "false";
+ }
};
/// Boost iterator is a wrapper around its child which multiplies scores of
@@ -294,7 +297,7 @@ public:
size_t estimateSize() const override { return Child->estimateSize(); }
private:
- raw_ostream &dump(raw_ostream &OS) const override {
+ llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
return OS << "(* " << Factor << ' ' << *Child << ')';
}
@@ -334,7 +337,7 @@ public:
}
private:
- raw_ostream &dump(raw_ostream &OS) const override {
+ llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
return OS << "(LIMIT " << Limit << " " << *Child << ')';
}
diff --git a/clang-tools-extra/clangd/index/dex/PostingList.cpp b/clang-tools-extra/clangd/index/dex/PostingList.cpp
index a0c8afdf08a..eb2e4757d43 100644
--- a/clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ b/clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -13,7 +13,6 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/MathExtras.h"
-using namespace llvm;
namespace clang {
namespace clangd {
namespace dex {
@@ -24,7 +23,7 @@ namespace {
/// them on-the-fly when the contents of chunk are to be seen.
class ChunkIterator : public Iterator {
public:
- explicit ChunkIterator(const Token *Tok, ArrayRef<Chunk> Chunks)
+ explicit ChunkIterator(const Token *Tok, llvm::ArrayRef<Chunk> Chunks)
: Tok(Tok), Chunks(Chunks), CurrentChunk(Chunks.begin()) {
if (!Chunks.empty()) {
DecompressedChunk = CurrentChunk->decompress();
@@ -71,7 +70,7 @@ public:
}
private:
- raw_ostream &dump(raw_ostream &OS) const override {
+ llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override {
if (Tok != nullptr)
return OS << *Tok;
OS << '[';
@@ -113,13 +112,13 @@ private:
}
const Token *Tok;
- ArrayRef<Chunk> Chunks;
+ llvm::ArrayRef<Chunk> Chunks;
/// Iterator over chunks.
/// If CurrentChunk is valid, then DecompressedChunk is
/// CurrentChunk->decompress() and CurrentID is a valid (non-end) iterator
/// into it.
decltype(Chunks)::const_iterator CurrentChunk;
- SmallVector<DocID, Chunk::PayloadSize + 1> DecompressedChunk;
+ llvm::SmallVector<DocID, Chunk::PayloadSize + 1> DecompressedChunk;
/// Iterator over DecompressedChunk.
decltype(DecompressedChunk)::iterator CurrentID;
@@ -130,11 +129,11 @@ static constexpr size_t BitsPerEncodingByte = 7;
/// Writes a variable length DocID into the buffer and updates the buffer size.
/// If it doesn't fit, returns false and doesn't write to the buffer.
-bool encodeVByte(DocID Delta, MutableArrayRef<uint8_t> &Payload) {
+bool encodeVByte(DocID Delta, llvm::MutableArrayRef<uint8_t> &Payload) {
assert(Delta != 0 && "0 is not a valid PostingList delta.");
// Calculate number of bytes Delta encoding would take by examining the
// meaningful bits.
- unsigned Width = 1 + findLastSet(Delta) / BitsPerEncodingByte;
+ unsigned Width = 1 + llvm::findLastSet(Delta) / BitsPerEncodingByte;
if (Width > Payload.size())
return false;
@@ -166,12 +165,12 @@ bool encodeVByte(DocID Delta, MutableArrayRef<uint8_t> &Payload) {
/// DocIDs 42 47 7000
/// gaps 5 6958
/// Encoding (raw number) 00000101 10110110 00101110
-std::vector<Chunk> encodeStream(ArrayRef<DocID> Documents) {
+std::vector<Chunk> encodeStream(llvm::ArrayRef<DocID> Documents) {
assert(!Documents.empty() && "Can't encode empty sequence.");
std::vector<Chunk> Result;
Result.emplace_back();
DocID Last = Result.back().Head = Documents.front();
- MutableArrayRef<uint8_t> RemainingPayload = Result.back().Payload;
+ llvm::MutableArrayRef<uint8_t> RemainingPayload = Result.back().Payload;
for (DocID Doc : Documents.drop_front()) {
if (!encodeVByte(Doc - Last, RemainingPayload)) { // didn't fit, flush chunk
Result.emplace_back();
@@ -185,7 +184,7 @@ std::vector<Chunk> encodeStream(ArrayRef<DocID> Documents) {
/// Reads variable length DocID from the buffer and updates the buffer size. If
/// the stream is terminated, return None.
-Optional<DocID> readVByte(ArrayRef<uint8_t> &Bytes) {
+llvm::Optional<DocID> readVByte(llvm::ArrayRef<uint8_t> &Bytes) {
if (Bytes.front() == 0 || Bytes.empty())
return None;
DocID Result = 0;
@@ -203,9 +202,9 @@ Optional<DocID> readVByte(ArrayRef<uint8_t> &Bytes) {
} // namespace
-SmallVector<DocID, Chunk::PayloadSize + 1> Chunk::decompress() const {
- SmallVector<DocID, Chunk::PayloadSize + 1> Result{Head};
- ArrayRef<uint8_t> Bytes(Payload);
+llvm::SmallVector<DocID, Chunk::PayloadSize + 1> Chunk::decompress() const {
+ llvm::SmallVector<DocID, Chunk::PayloadSize + 1> Result{Head};
+ llvm::ArrayRef<uint8_t> Bytes(Payload);
DocID Delta;
for (DocID Current = Head; !Bytes.empty(); Current += Delta) {
auto MaybeDelta = readVByte(Bytes);
@@ -214,10 +213,10 @@ SmallVector<DocID, Chunk::PayloadSize + 1> Chunk::decompress() const {
Delta = *MaybeDelta;
Result.push_back(Current + Delta);
}
- return SmallVector<DocID, Chunk::PayloadSize + 1>{Result};
+ return llvm::SmallVector<DocID, Chunk::PayloadSize + 1>{Result};
}
-PostingList::PostingList(ArrayRef<DocID> Documents)
+PostingList::PostingList(llvm::ArrayRef<DocID> Documents)
: Chunks(encodeStream(Documents)) {}
std::unique_ptr<Iterator> PostingList::iterator(const Token *Tok) const {
diff --git a/clang-tools-extra/clangd/index/dex/Trigram.cpp b/clang-tools-extra/clangd/index/dex/Trigram.cpp
index 7779e8b8ba8..2ba0ad18cc7 100644
--- a/clang-tools-extra/clangd/index/dex/Trigram.cpp
+++ b/clang-tools-extra/clangd/index/dex/Trigram.cpp
@@ -17,16 +17,15 @@
#include <queue>
#include <string>
-using namespace llvm;
namespace clang {
namespace clangd {
namespace dex {
-std::vector<Token> generateIdentifierTrigrams(StringRef Identifier) {
+std::vector<Token> generateIdentifierTrigrams(llvm::StringRef Identifier) {
// Apply fuzzy matching text segmentation.
std::vector<CharRole> Roles(Identifier.size());
calculateRoles(Identifier,
- makeMutableArrayRef(Roles.data(), Identifier.size()));
+ llvm::makeMutableArrayRef(Roles.data(), Identifier.size()));
std::string LowercaseIdentifier = Identifier.lower();
@@ -48,7 +47,7 @@ std::vector<Token> generateIdentifierTrigrams(StringRef Identifier) {
}
}
- DenseSet<Token> UniqueTrigrams;
+ llvm::DenseSet<Token> UniqueTrigrams;
auto Add = [&](std::string Chars) {
UniqueTrigrams.insert(Token(Token::Kind::Trigram, Chars));
@@ -85,7 +84,7 @@ std::vector<Token> generateIdentifierTrigrams(StringRef Identifier) {
return {UniqueTrigrams.begin(), UniqueTrigrams.end()};
}
-std::vector<Token> generateQueryTrigrams(StringRef Query) {
+std::vector<Token> generateQueryTrigrams(llvm::StringRef Query) {
if (Query.empty())
return {};
std::string LowercaseQuery = Query.lower();
@@ -94,9 +93,9 @@ std::vector<Token> generateQueryTrigrams(StringRef Query) {
// Apply fuzzy matching text segmentation.
std::vector<CharRole> Roles(Query.size());
- calculateRoles(Query, makeMutableArrayRef(Roles.data(), Query.size()));
+ calculateRoles(Query, llvm::makeMutableArrayRef(Roles.data(), Query.size()));
- DenseSet<Token> UniqueTrigrams;
+ llvm::DenseSet<Token> UniqueTrigrams;
std::string Chars;
for (unsigned I = 0; I < Query.size(); ++I) {
if (Roles[I] != Head && Roles[I] != Tail)
diff --git a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
index 795173c74ad..5a0b6d97122 100644
--- a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -22,14 +22,13 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Signals.h"
-using namespace llvm;
-using namespace clang;
-using namespace clangd;
-
+namespace clang {
+namespace clangd {
namespace {
-cl::opt<std::string> IndexPath("index-path", cl::desc("Path to the index"),
- cl::Positional, cl::Required);
+llvm::cl::opt<std::string> IndexPath("index-path",
+ llvm::cl::desc("Path to the index"),
+ llvm::cl::Positional, llvm::cl::Required);
static const std::string Overview = R"(
This is an **experimental** interactive tool to process user-provided search
@@ -40,16 +39,16 @@ and manually construct non-trivial test cases.
Type use "help" request to get information about the details.
)";
-void reportTime(StringRef Name, function_ref<void()> F) {
+void reportTime(llvm::StringRef Name, llvm::function_ref<void()> F) {
const auto TimerStart = std::chrono::high_resolution_clock::now();
F();
const auto TimerStop = std::chrono::high_resolution_clock::now();
const auto Duration = std::chrono::duration_cast<std::chrono::milliseconds>(
TimerStop - TimerStart);
- outs() << formatv("{0} took {1:ms+n}.\n", Name, Duration);
+ llvm::outs() << llvm::formatv("{0} took {1:ms+n}.\n", Name, Duration);
}
-std::vector<SymbolID> getSymbolIDsFromIndex(StringRef QualifiedName,
+std::vector<SymbolID> getSymbolIDsFromIndex(llvm::StringRef QualifiedName,
const SymbolIndex *Index) {
FuzzyFindRequest Request;
// Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
@@ -77,9 +76,9 @@ std::vector<SymbolID> getSymbolIDsFromIndex(StringRef QualifiedName,
// Creating a Command populates parser options, parseAndRun() resets them.
class Command {
// By resetting the parser options, we lost the standard -help flag.
- cl::opt<bool, false, cl::parser<bool>> Help{
- "help", cl::desc("Display available options"), cl::ValueDisallowed,
- cl::cat(cl::GeneralCategory)};
+ llvm::cl::opt<bool, false, llvm::cl::parser<bool>> Help{
+ "help", llvm::cl::desc("Display available options"),
+ llvm::cl::ValueDisallowed, llvm::cl::cat(llvm::cl::GeneralCategory)};
virtual void run() = 0;
protected:
@@ -87,24 +86,25 @@ protected:
public:
virtual ~Command() = default;
- virtual void parseAndRun(ArrayRef<const char *> Argv, const char *Overview,
- const SymbolIndex &Index) {
+ virtual void parseAndRun(llvm::ArrayRef<const char *> Argv,
+ const char *Overview, const SymbolIndex &Index) {
std::string ParseErrs;
- raw_string_ostream OS(ParseErrs);
- bool Ok =
- cl::ParseCommandLineOptions(Argv.size(), Argv.data(), Overview, &OS);
+ llvm::raw_string_ostream OS(ParseErrs);
+ bool Ok = llvm::cl::ParseCommandLineOptions(Argv.size(), Argv.data(),
+ Overview, &OS);
if (Help.getNumOccurrences() > 0) {
// Avoid printing parse errors in this case.
// (Well, in theory. A bunch get printed to llvm::errs() regardless!)
- cl::PrintHelpMessage();
+ llvm::cl::PrintHelpMessage();
} else {
- outs() << OS.str();
+ llvm::outs() << OS.str();
if (Ok) {
this->Index = &Index;
reportTime(Argv[0], [&] { run(); });
}
}
- cl::ResetCommandLineParser(); // must do this before opts are destroyed.
+ llvm::cl::ResetCommandLineParser(); // must do this before opts are
+ // destroyed.
}
};
@@ -118,20 +118,20 @@ public:
// * print out tokens with least dense posting lists
class FuzzyFind : public Command {
- cl::opt<std::string> Query{
+ llvm::cl::opt<std::string> Query{
"query",
- cl::Positional,
- cl::Required,
- cl::desc("Query string to be fuzzy-matched"),
+ llvm::cl::Positional,
+ llvm::cl::Required,
+ llvm::cl::desc("Query string to be fuzzy-matched"),
};
- cl::opt<std::string> Scopes{
+ llvm::cl::opt<std::string> Scopes{
"scopes",
- cl::desc("Allowed symbol scopes (comma-separated list)"),
+ llvm::cl::desc("Allowed symbol scopes (comma-separated list)"),
};
- cl::opt<unsigned> Limit{
+ llvm::cl::opt<unsigned> Limit{
"limit",
- cl::init(10),
- cl::desc("Max results to display"),
+ llvm::cl::init(10),
+ llvm::cl::desc("Max results to display"),
};
void run() override {
@@ -139,42 +139,45 @@ class FuzzyFind : public Command {
Request.Limit = Limit;
Request.Query = Query;
if (Scopes.getNumOccurrences() > 0) {
- SmallVector<StringRef, 8> Scopes;
- StringRef(this->Scopes).split(Scopes, ',');
+ llvm::SmallVector<llvm::StringRef, 8> Scopes;
+ llvm::StringRef(this->Scopes).split(Scopes, ',');
Request.Scopes = {Scopes.begin(), Scopes.end()};
}
Request.AnyScope = Request.Scopes.empty();
// FIXME(kbobyrev): Print symbol final scores to see the distribution.
static const auto OutputFormat = "{0,-4} | {1,-40} | {2,-25}\n";
- outs() << formatv(OutputFormat, "Rank", "Symbol ID", "Symbol Name");
+ llvm::outs() << llvm::formatv(OutputFormat, "Rank", "Symbol ID",
+ "Symbol Name");
size_t Rank = 0;
Index->fuzzyFind(Request, [&](const Symbol &Sym) {
- outs() << formatv(OutputFormat, Rank++, Sym.ID.str(),
- Sym.Scope + Sym.Name);
+ llvm::outs() << llvm::formatv(OutputFormat, Rank++, Sym.ID.str(),
+ Sym.Scope + Sym.Name);
});
}
};
class Lookup : public Command {
- cl::opt<std::string> ID{
+ llvm::cl::opt<std::string> ID{
"id",
- cl::Positional,
- cl::desc("Symbol ID to look up (hex)"),
+ llvm::cl::Positional,
+ llvm::cl::desc("Symbol ID to look up (hex)"),
};
- cl::opt<std::string> Name{
- "name", cl::desc("Qualified name to look up."),
+ llvm::cl::opt<std::string> Name{
+ "name",
+ llvm::cl::desc("Qualified name to look up."),
};
void run() override {
if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
- outs() << "Missing required argument: please provide id or -name.\n";
+ llvm::outs()
+ << "Missing required argument: please provide id or -name.\n";
return;
}
std::vector<SymbolID> IDs;
if (ID.getNumOccurrences()) {
auto SID = SymbolID::fromStr(ID);
if (!SID) {
- outs() << toString(SID.takeError()) << "\n";
+ llvm::outs() << llvm::toString(SID.takeError()) << "\n";
return;
}
IDs.push_back(*SID);
@@ -187,60 +190,65 @@ class Lookup : public Command {
bool FoundSymbol = false;
Index->lookup(Request, [&](const Symbol &Sym) {
FoundSymbol = true;
- outs() << toYAML(Sym);
+ llvm::outs() << toYAML(Sym);
});
if (!FoundSymbol)
- outs() << "not found\n";
+ llvm::outs() << "not found\n";
}
};
class Refs : public Command {
- cl::opt<std::string> ID{
- "id", cl::Positional,
- cl::desc("Symbol ID of the symbol being queried (hex)."),
+ llvm::cl::opt<std::string> ID{
+ "id",
+ llvm::cl::Positional,
+ llvm::cl::desc("Symbol ID of the symbol being queried (hex)."),
};
- cl::opt<std::string> Name{
- "name", cl::desc("Qualified name of the symbol being queried."),
+ llvm::cl::opt<std::string> Name{
+ "name",
+ llvm::cl::desc("Qualified name of the symbol being queried."),
};
- cl::opt<std::string> Filter{
- "filter", cl::init(".*"),
- cl::desc(
+ llvm::cl::opt<std::string> Filter{
+ "filter",
+ llvm::cl::init(".*"),
+ llvm::cl::desc(
"Print all results from files matching this regular expression."),
};
void run() override {
if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
- outs() << "Missing required argument: please provide id or -name.\n";
+ llvm::outs()
+ << "Missing required argument: please provide id or -name.\n";
return;
}
std::vector<SymbolID> IDs;
if (ID.getNumOccurrences()) {
auto SID = SymbolID::fromStr(ID);
if (!SID) {
- outs() << toString(SID.takeError()) << "\n";
+ llvm::outs() << llvm::toString(SID.takeError()) << "\n";
return;
}
IDs.push_back(*SID);
} else {
IDs = getSymbolIDsFromIndex(Name, Index);
if (IDs.size() > 1) {
- outs() << formatv("The name {0} is ambiguous, found {1} different "
- "symbols. Please use id flag to disambiguate.\n",
- Name, IDs.size());
+ llvm::outs() << llvm::formatv(
+ "The name {0} is ambiguous, found {1} different "
+ "symbols. Please use id flag to disambiguate.\n",
+ Name, IDs.size());
return;
}
}
RefsRequest RefRequest;
RefRequest.IDs.insert(IDs.begin(), IDs.end());
- Regex RegexFilter(Filter);
+ llvm::Regex RegexFilter(Filter);
Index->refs(RefRequest, [&RegexFilter](const Ref &R) {
auto U = URI::parse(R.Location.FileURI);
if (!U) {
- outs() << U.takeError();
+ llvm::outs() << U.takeError();
return;
}
if (RegexFilter.match(U->body()))
- outs() << R << "\n";
+ llvm::outs() << R << "\n";
});
}
};
@@ -257,16 +265,20 @@ struct {
llvm::make_unique<Refs>},
};
-std::unique_ptr<SymbolIndex> openIndex(StringRef Index) {
+std::unique_ptr<SymbolIndex> openIndex(llvm::StringRef Index) {
return loadIndex(Index, /*UseDex=*/true);
}
} // namespace
+} // namespace clangd
+} // namespace clang
int main(int argc, const char *argv[]) {
- cl::ParseCommandLineOptions(argc, argv, Overview);
- cl::ResetCommandLineParser(); // We reuse it for REPL commands.
- sys::PrintStackTraceOnErrorSignal(argv[0]);
+ using namespace clang::clangd;
+
+ llvm::cl::ParseCommandLineOptions(argc, argv, Overview);
+ llvm::cl::ResetCommandLineParser(); // We reuse it for REPL commands.
+ llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
std::unique_ptr<SymbolIndex> Index;
reportTime("Dex build", [&]() {
@@ -274,28 +286,29 @@ int main(int argc, const char *argv[]) {
});
if (!Index) {
- outs() << "Failed to open the index.\n";
+ llvm::outs() << "Failed to open the index.\n";
return -1;
}
- LineEditor LE("dexp");
+ llvm::LineEditor LE("dexp");
- while (Optional<std::string> Request = LE.readLine()) {
+ while (llvm::Optional<std::string> Request = LE.readLine()) {
// Split on spaces and add required null-termination.
std::replace(Request->begin(), Request->end(), ' ', '\0');
- SmallVector<StringRef, 8> Args;
- StringRef(*Request).split(Args, '\0', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+ llvm::SmallVector<llvm::StringRef, 8> Args;
+ llvm::StringRef(*Request).split(Args, '\0', /*MaxSplit=*/-1,
+ /*KeepEmpty=*/false);
if (Args.empty())
continue;
if (Args.front() == "help") {
- outs() << "dexp - Index explorer\nCommands:\n";
+ llvm::outs() << "dexp - Index explorer\nCommands:\n";
for (const auto &C : CommandInfo)
- outs() << formatv("{0,16} - {1}\n", C.Name, C.Description);
- outs() << "Get detailed command help with e.g. `find -help`.\n";
+ llvm::outs() << llvm::formatv("{0,16} - {1}\n", C.Name, C.Description);
+ llvm::outs() << "Get detailed command help with e.g. `find -help`.\n";
continue;
}
- SmallVector<const char *, 8> FakeArgv;
- for (StringRef S : Args)
+ llvm::SmallVector<const char *, 8> FakeArgv;
+ for (llvm::StringRef S : Args)
FakeArgv.push_back(S.data()); // Terminated by separator or end of string.
bool Recognized = false;
@@ -307,7 +320,7 @@ int main(int argc, const char *argv[]) {
}
}
if (!Recognized)
- outs() << "Unknown command. Try 'help'.\n";
+ llvm::outs() << "Unknown command. Try 'help'.\n";
}
return 0;
OpenPOWER on IntegriCloud