14#include "llvm/ADT/StringRef.h"
28 const char *OwningFile =
29 S.Definition ? S.Definition.FileURI : S.CanonicalDeclaration.FileURI;
46 unsigned DynamicCount = 0;
47 unsigned StaticCount = 0;
48 unsigned MergedCount = 0;
50 unsigned StaticDropped = 0;
51 More |= Dynamic->fuzzyFind(Req, [&](
const Symbol &S) {
57 llvm::DenseSet<SymbolID> ReportedDynSymbols;
59 auto DynamicContainsFile = Dynamic->indexedFiles();
60 More |= Static->fuzzyFind(Req, [&](
const Symbol &S) {
62 auto DynS = Dyn.
find(S.
ID);
64 if (DynS != Dyn.
end()) {
66 ReportedDynSymbols.insert(S.
ID);
72 if (isIndexAuthoritative(DynamicContainsFile, S)) {
83 SPAN_ATTACH(Tracer,
"static_dropped", StaticDropped);
85 for (
const Symbol &S : Dyn)
86 if (!ReportedDynSymbols.count(S.
ID))
97 Dynamic->lookup(Req, [&](
const Symbol &S) { B.insert(S); });
99 auto RemainingIDs = Req.
IDs;
101 auto DynamicContainsFile = Dynamic->indexedFiles();
102 Static->lookup(Req, [&](
const Symbol &S) {
104 if (
const Symbol *Sym = B.find(S.
ID)) {
105 RemainingIDs.erase(S.
ID);
111 if (isIndexAuthoritative(DynamicContainsFile, S))
116 RemainingIDs.erase(S.
ID);
120 for (
const auto &ID : RemainingIDs)
121 if (
const Symbol *Sym = B.find(ID))
126 llvm::function_ref<
void(
const Ref &)>
Callback)
const {
129 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
134 More |= Dynamic->refs(Req, [&](
const Ref &O) {
136 assert(Remaining != 0);
139 if (Remaining == 0 && More)
141 auto DynamicContainsFile = Dynamic->indexedFiles();
144 bool StaticHadMore = Static->refs(Req, [&](
const Ref &O) {
148 if (Remaining == 0) {
155 return More || StaticHadMore;
163 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
168 More |= Dynamic->containedRefs(Req, [&](
const auto &O) {
170 assert(Remaining != 0);
173 if (Remaining == 0 && More)
175 auto DynamicContainsFile = Dynamic->indexedFiles();
178 bool StaticHadMore = Static->containedRefs(Req, [&](
const auto &O) {
182 if (Remaining == 0) {
189 return More || StaticHadMore;
194 return [DynamicContainsFile{Dynamic->indexedFiles()},
195 StaticContainsFile{Static->indexedFiles()}](llvm::StringRef FileURI) {
196 return DynamicContainsFile(FileURI) | StaticContainsFile(FileURI);
203 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
207 llvm::DenseSet<std::pair<SymbolID, SymbolID>> SeenRelations;
210 SeenRelations.insert(std::make_pair(Subject,
Object.ID));
217 !SeenRelations.count(std::make_pair(Subject,
Object.ID))) {
227 uint32_t Remaining = Req.
Limit.value_or(std::numeric_limits<uint32_t>::max());
231 llvm::DenseSet<std::pair<SymbolID, SymbolID>> SeenRelations;
232 Dynamic->reverseRelations(
235 SeenRelations.insert(std::make_pair(Subject,
Object.ID));
240 Static->reverseRelations(
243 !SeenRelations.count(std::make_pair(Subject,
Object.ID))) {
258 constexpr static const char *CodegenSuffixes[] = {
".proto"};
259 return llvm::any_of(CodegenSuffixes, [&](llvm::StringRef Suffix) {
260 return llvm::StringRef(Loc.FileURI).ends_with(Suffix);
263 return HasCodeGenSuffix(L) && !HasCodeGenSuffix(R);
267 assert(L.
ID == R.
ID);
277 Symbol S = PreferR ? R : L;
278 const Symbol &O = PreferR ? L : R;
295 bool IsClass = S.
SymInfo.Kind == index::SymbolKind::Class ||
296 S.
SymInfo.Kind == index::SymbolKind::Struct ||
297 S.
SymInfo.Kind == index::SymbolKind::Union;
308 if (SI.IncludeHeader == OI.IncludeHeader) {
310 SI.References += OI.References;
311 SI.SupportedDirectives |= OI.SupportedDirectives;
315 if (!Found && MergeIncludes)
317 OI.supportedDirectives());
#define SPAN_ATTACH(S, Name, Expr)
Attach a key-value pair to a Span event.
void relations(const RelationsRequest &, llvm::function_ref< void(const SymbolID &, const Symbol &)>) const override
bool containedRefs(const ContainedRefsRequest &, llvm::function_ref< void(const ContainedRefsResult &)>) const override
Find all symbols that are referenced by a symbol and apply Callback on each result.
bool refs(const RefsRequest &, llvm::function_ref< void(const Ref &)>) const override
Finds all occurrences (e.g.
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.
void reverseRelations(const RelationsRequest &, llvm::function_ref< void(const SymbolID &, const Symbol &)>) const override
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.
llvm::unique_function< IndexContents(llvm::StringRef) const > indexedFiles() const override
llvm::unique_function< IndexContents(llvm::StringRef) const > IndexedFiles
Returns function which checks if the specified file was used to build this index or not.
SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
void insert(const Symbol &S)
Adds a symbol, overwriting any existing one with the same ID.
An immutable symbol container that stores a set of symbols.
const_iterator end() const
const_iterator find(const SymbolID &SymID) const
Records an event whose duration is the lifetime of the Span object.
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
IndexContents
Describes what data is covered by an index.
Symbol mergeSymbol(const Symbol &L, const Symbol &R)
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
static bool prefer(const SymbolLocation &L, const SymbolLocation &R)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::optional< uint32_t > Limit
If set, limit the number of refers returned from the index.
llvm::DenseSet< SymbolID > IDs
Represents a symbol occurrence in the source file.
SymbolLocation Location
The source location where the symbol is named.
std::optional< uint32_t > Limit
If set, limit the number of refers returned from the index.
std::optional< uint32_t > Limit
If set, limit the number of relations returned from the index.
The class presents a C++ symbol, e.g.
SymbolLocation Definition
The location of the symbol's definition, if one was found.
llvm::StringRef Type
Raw representation of the OpaqueType of the symbol, used for scoring purposes.
llvm::StringRef Documentation
Documentation including comment for the symbol declaration.
index::SymbolInfo SymInfo
The symbol information, like symbol kind.
llvm::SmallVector< IncludeHeaderWithReferences, 1 > IncludeHeaders
One Symbol can potentially be included via different headers.
llvm::StringRef Signature
A brief description of the symbol that can be appended in the completion candidate list.
unsigned References
The number of translation units that reference this symbol from their main file.
llvm::StringRef ReturnType
Type when this symbol is used in an expression.
SymbolLocation CanonicalDeclaration
The location of the preferred declaration of the symbol.
llvm::StringRef CompletionSnippetSuffix
What to insert when completing this symbol, after the symbol name.
SymbolID ID
The ID of the symbol.
SymbolOrigin Origin
Where this symbol came from. Usually an index provides a constant value.