8#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOLCOLLECTOR_H
9#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOLCOLLECTOR_H
18#include "clang/AST/ASTContext.h"
19#include "clang/AST/Decl.h"
20#include "clang/Basic/SourceLocation.h"
21#include "clang/Basic/SourceManager.h"
22#include "clang/Index/IndexDataConsumer.h"
23#include "clang/Index/IndexSymbol.h"
24#include "clang/Sema/CodeCompleteConsumer.h"
25#include "llvm/ADT/ArrayRef.h"
26#include "llvm/ADT/DenseMap.h"
97 std::function<bool(
const SourceManager &, FileID)>
FileFilter =
nullptr;
105 const Options &Opts,
bool IsMainFileSymbol);
131 ArrayRef<index::SymbolRelation> Relations,
133 index::IndexDataConsumer::ASTNodeInfo
ASTNode)
override;
136 index::SymbolRoleSet Roles,
137 SourceLocation
Loc)
override;
154 bool IsMainFileSymbol);
155 void addDefinition(
const NamedDecl &,
const Symbol &DeclSymbol);
156 void processRelations(
const NamedDecl &ND,
const SymbolID &ID,
157 ArrayRef<index::SymbolRelation> Relations);
159 std::optional<SymbolLocation> getTokenLocation(SourceLocation TokLoc);
161 std::optional<std::string> getIncludeHeader(
const Symbol &S, FileID);
165 const MacroInfo *MI,
const SourceManager &SM);
171 llvm::DenseMap<SymbolID, FileID> IncludeFiles;
174 llvm::DenseSet<FileID> FilesWithObjCConstructs;
175 void setIncludeLocation(
const Symbol &S, SourceLocation);
177 llvm::DenseSet<const IdentifierInfo *> IndexedMacros;
186 Preprocessor *PP =
nullptr;
187 std::shared_ptr<GlobalCodeCompletionAllocator> CompletionAllocator;
188 std::unique_ptr<CodeCompletionTUInfo> CompletionTUInfo;
193 index::SymbolRoleSet Roles;
197 void addRef(SymbolID ID,
const SymbolRef &SR);
199 llvm::DenseSet<SymbolID> ReferencedSymbols;
205 llvm::DenseMap<const Decl *, const Decl *> CanonicalDecls;
207 llvm::DenseMap<FileID, bool> FilesToIndexCache;
210 class HeaderFileURICache;
211 std::unique_ptr<HeaderFileURICache> HeaderFileURIs;
212 llvm::DenseMap<const Decl *, SymbolID> DeclToIDCache;
213 llvm::DenseMap<const MacroInfo *, SymbolID> MacroToIDCache;
const FunctionDecl * Decl
Maps a definition location onto an #include file, based on a set of filename rules.
RefSlab::Builder is a mutable container that can 'freeze' to RefSlab.
An efficient structure of storing large set of symbol references in memory.
RelationSlab::Builder is a mutable container that can 'freeze' to RelationSlab.
Collect declarations (symbols) from an AST.
bool shouldIndexFile(FileID FID)
Returns true if we are interested in references and declarations from FID.
static bool shouldCollectSymbol(const NamedDecl &ND, const ASTContext &ASTCtx, const Options &Opts, bool IsMainFileSymbol)
Returns true is ND should be collected.
static const Decl * getRefContainer(const Decl *Enclosing, const SymbolCollector::Options &Opts)
void setPreprocessor(Preprocessor &PP)
bool handleDeclOccurrence(const Decl *D, index::SymbolRoleSet Roles, ArrayRef< index::SymbolRelation > Relations, SourceLocation Loc, index::IndexDataConsumer::ASTNodeInfo ASTNode) override
RelationSlab takeRelations()
void handleMacros(const MainFileMacros &MacroRefsToIndex)
void initialize(ASTContext &Ctx) override
bool handleMacroOccurrence(const IdentifierInfo *Name, const MacroInfo *MI, index::SymbolRoleSet Roles, SourceLocation Loc) override
void setPreprocessor(std::shared_ptr< Preprocessor > PP) override
SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
An immutable symbol container that stores a set of symbols.
RefKind
Describes the kind of a cross-reference.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Simplified description of a clang AST node.
bool CollectMacro
Collect macros.
std::string FallbackDir
When symbol paths cannot be resolved to absolute paths (e.g.
const CanonicalIncludes * Includes
If set, this is used to map symbol #include path to a potentially different #include path.
RefKind RefFilter
The symbol ref kinds that will be collected.
bool CollectMainFileSymbols
Collect symbols local to main-files, such as static functions, symbols inside an anonymous namespace,...
bool StoreAllDocumentation
If set to true, SymbolCollector will collect doc for all symbols.
bool CollectMainFileRefs
Collect references to main-file symbols.
bool RefsInHeaders
If set to true, SymbolCollector will collect all refs (from main file and included headers); otherwis...
bool CollectReserved
Collect symbols with reserved names, like __Vector_base.
std::function< bool(const SourceManager &, FileID)> FileFilter
If this is set, only collect symbols/references from a file if FileFilter(SM, FID) is true.
The class presents a C++ symbol, e.g.