diff options
Diffstat (limited to 'clang-tools-extra/include-fixer/InMemorySymbolIndex.cpp')
-rw-r--r-- | clang-tools-extra/include-fixer/InMemorySymbolIndex.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/clang-tools-extra/include-fixer/InMemorySymbolIndex.cpp b/clang-tools-extra/include-fixer/InMemorySymbolIndex.cpp new file mode 100644 index 00000000000..388bab20cb1 --- /dev/null +++ b/clang-tools-extra/include-fixer/InMemorySymbolIndex.cpp @@ -0,0 +1,47 @@ +//===-- InMemorySymbolIndex.cpp--------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "InMemorySymbolIndex.h" + +using clang::find_all_symbols::SymbolInfo; + +namespace clang { +namespace include_fixer { + +InMemorySymbolIndex::InMemorySymbolIndex( + const std::map<std::string, std::vector<std::string>> &LookupTable) { + for (const auto &Entry : LookupTable) { + llvm::StringRef Identifier(Entry.first); + llvm::SmallVector<llvm::StringRef, 8> Names; + Identifier.split(Names, "::"); + for (const auto &Header : Entry.second) { + std::vector<SymbolInfo::Context> Contexts; + for (auto IdentiferContext = Names.rbegin() + 1; + IdentiferContext != Names.rend(); ++IdentiferContext) { + Contexts.emplace_back(SymbolInfo::ContextType::Namespace, + *IdentiferContext); + } + + SymbolInfo Symbol(Names.back(), SymbolInfo::SymbolKind::Class, Header, + Contexts, 1); + this->LookupTable[Symbol.getName()].push_back(Symbol); + } + } +} + +std::vector<SymbolInfo> +InMemorySymbolIndex::search(llvm::StringRef Identifier) { + auto I = LookupTable.find(Identifier); + if (I != LookupTable.end()) + return I->second; + return {}; +} + +} // namespace include_fixer +} // namespace clang |