clang-tools 8.0.0

Merge.h
Go to the documentation of this file.
1 //===--- Merge.h -------------------------------------------------*- C++-*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
12
13 #include "Index.h"
14
15 namespace clang {
16 namespace clangd {
17
18 // Merge symbols L and R, preferring data from L in case of conflict.
19 // The two symbols must have the same ID.
20 // Returned symbol may contain data owned by either source.
21 Symbol mergeSymbol(const Symbol &L, const Symbol &R);
22
23 // MergedIndex is a composite index based on two provided Indexes:
24 // - the Dynamic index covers few files, but is relatively up-to-date.
25 // - the Static index covers a bigger set of files, but is relatively stale.
26 // The returned index attempts to combine results, and avoid duplicates.
27 //
28 // FIXME: We don't have a mechanism in Index to track deleted symbols and
29 // refs in dirty files, so the merged index may return stale symbols
30 // and refs from Static index.
31 class MergedIndex : public SymbolIndex {
32 const SymbolIndex *Dynamic, *Static;
33
34 public:
35 // The constructor does not access the symbols.
36 // It's safe to inherit from this class and pass pointers to derived members.
37 MergedIndex(const SymbolIndex *Dynamic, const SymbolIndex *Static)
38 : Dynamic(Dynamic), Static(Static) {}
39
40 bool fuzzyFind(const FuzzyFindRequest &,
41 llvm::function_ref<void(const Symbol &)>) const override;
42 void lookup(const LookupRequest &,
43 llvm::function_ref<void(const Symbol &)>) const override;
44 void refs(const RefsRequest &,
45 llvm::function_ref<void(const Ref &)>) const override;
46 size_t estimateMemoryUsage() const override {
47 return Dynamic->estimateMemoryUsage() + Static->estimateMemoryUsage();
48 }
49 };
50
51 } // namespace clangd
52 } // namespace clang
53
54 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_MERGE_H
clang::clangd::MergedIndex::estimateMemoryUsage
size_t estimateMemoryUsage() const override
Returns estimated size of index (in bytes).
Definition: Merge.h:46
Index.h
clang::clangd::SymbolIndex
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:487
clang::clangd::MergedIndex::MergedIndex
MergedIndex(const SymbolIndex *Dynamic, const SymbolIndex *Static)
Definition: Merge.h:37
clang::clangd::Ref
Definition: Index.h:373
clang::clangd::RefsRequest
Definition: Index.h:476
clang::clangd::FuzzyFindRequest
Definition: Index.h:436
clang::clangd::MergedIndex::lookup
void lookup(const LookupRequest &, llvm::function_ref< void(const Symbol &)>) const override
Looks up symbols with any of the given symbol IDs and applies Callback on each matched symbol...
Definition: Merge.cpp:65
clang::clangd::mergeSymbol
Symbol mergeSymbol(const Symbol &L, const Symbol &R)
Definition: Merge.cpp:119
clang::clangd::Symbol
Definition: Index.h:160
clang::clangd::LookupRequest
Definition: Index.h:472
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::clangd::MergedIndex::refs
void refs(const RefsRequest &, llvm::function_ref< void(const Ref &)>) const override
Finds all occurrences (e.g.
Definition: Merge.cpp:87
clang::clangd::SymbolIndex::estimateMemoryUsage
virtual size_t estimateMemoryUsage() const =0
Returns estimated size of index (in bytes).
clang::clangd::MergedIndex::fuzzyFind
bool fuzzyFind(const FuzzyFindRequest &, llvm::function_ref< void(const Symbol &)>) const override
Matches symbols in the index fuzzily and applies Callback on each matched symbol before returning...
Definition: Merge.cpp:25
clang::clangd::MergedIndex
Definition: Merge.h:31