aboutsummaryrefslogtreecommitdiff
path: root/clangd/index/Index.cpp
blob: f609056f6391aee9ab59618e2f736407f984a918 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//===--- 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/ADT/StringExtras.h"
#include "llvm/Support/SHA1.h"

namespace clang {
namespace clangd {

SymbolID::SymbolID(llvm::StringRef USR)
    : HashValue(llvm::SHA1::hash(arrayRefFromStringRef(USR))) {}

llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SymbolID &ID) {
  OS << toHex(llvm::toStringRef(ID.HashValue));
  return OS;
}

void operator>>(llvm::StringRef Str, SymbolID &ID) {
  std::string HexString = fromHex(Str);
  assert(HexString.size() == 20);
  std::copy(HexString.begin(), HexString.end(), ID.HashValue.begin());
}

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