diff options
| author | Haojian Wu <hokein@google.com> | 2017-12-12 15:42:10 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2017-12-12 15:42:10 +0000 |
| commit | 4c1394d67d77b63c73e3ebeae1f123e4ac35dbef (patch) | |
| tree | 8b2187c825e4a9aa9e213babda9f36b9ce0c7bb3 /clang-tools-extra/clangd/index/Index.cpp | |
| parent | ca2a8cea2f6fc437a2a6ca7b8c6539087519fd83 (diff) | |
| download | bcm5719-llvm-4c1394d67d77b63c73e3ebeae1f123e4ac35dbef.tar.gz bcm5719-llvm-4c1394d67d77b63c73e3ebeae1f123e4ac35dbef.zip | |
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
Diffstat (limited to 'clang-tools-extra/clangd/index/Index.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/index/Index.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/index/Index.cpp b/clang-tools-extra/clangd/index/Index.cpp new file mode 100644 index 00000000000..1914cf57df2 --- /dev/null +++ b/clang-tools-extra/clangd/index/Index.cpp @@ -0,0 +1,49 @@ +//===--- Index.cpp -----------------------------------------------*- C++-*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "Index.h" + +#include "llvm/Support/SHA1.h" + +namespace clang { +namespace clangd { + +namespace { +ArrayRef<uint8_t> toArrayRef(StringRef S) { + return {reinterpret_cast<const uint8_t *>(S.data()), S.size()}; +} +} // namespace + +SymbolID::SymbolID(llvm::StringRef USR) + : HashValue(llvm::SHA1::hash(toArrayRef(USR))) {} + +SymbolSlab::const_iterator SymbolSlab::begin() const { + return Symbols.begin(); +} + +SymbolSlab::const_iterator SymbolSlab::end() const { + return Symbols.end(); +} + +SymbolSlab::const_iterator SymbolSlab::find(const SymbolID& SymID) const { + return Symbols.find(SymID); +} + +void SymbolSlab::freeze() { + Frozen = true; +} + +void SymbolSlab::insert(Symbol S) { + assert(!Frozen && + "Can't insert a symbol after the slab has been frozen!"); + Symbols[S.ID] = std::move(S); +} + +} // namespace clangd +} // namespace clang |

