clang-tools 19.0.0git
Classes | Public Member Functions | Static Public Member Functions | List of all members
clang::clangd::SymbolCollector Class Reference

Collect declarations (symbols) from an AST. More...

#include <SymbolCollector.h>

Inheritance diagram for clang::clangd::SymbolCollector:
Inheritance graph


class  HeaderFileURICache
struct  Options

Public Member Functions

 SymbolCollector (Options Opts)
 ~SymbolCollector ()
void initialize (ASTContext &Ctx) override
void setPreprocessor (std::shared_ptr< Preprocessor > PP) override
void setPreprocessor (Preprocessor &PP)
bool handleDeclOccurrence (const Decl *D, index::SymbolRoleSet Roles, ArrayRef< index::SymbolRelation > Relations, SourceLocation Loc, index::IndexDataConsumer::ASTNodeInfo ASTNode) override
bool handleMacroOccurrence (const IdentifierInfo *Name, const MacroInfo *MI, index::SymbolRoleSet Roles, SourceLocation Loc) override
void handleMacros (const MainFileMacros &MacroRefsToIndex)
SymbolSlab takeSymbols ()
RefSlab takeRefs ()
RelationSlab takeRelations ()
bool shouldIndexFile (FileID FID)
 Returns true if we are interested in references and declarations from FID.
void finish () override

Static Public Member Functions

static bool shouldCollectSymbol (const NamedDecl &ND, const ASTContext &ASTCtx, const Options &Opts, bool IsMainFileSymbol)
 Returns true is ND should be collected.
static const DeclgetRefContainer (const Decl *Enclosing, const SymbolCollector::Options &Opts)

Detailed Description

Collect declarations (symbols) from an AST.

It collects most declarations except:

References to main-file symbols are not collected.

See also shouldCollectSymbol(...).

Clients (e.g. clangd) can use SymbolCollector together with index::indexTopLevelDecls to retrieve all symbols when the source file is changed.

Definition at line 58 of file SymbolCollector.h.

Constructor & Destructor Documentation

◆ SymbolCollector()

clang::clangd::SymbolCollector::SymbolCollector ( Options  Opts)

Definition at line 450 of file SymbolCollector.cpp.

◆ ~SymbolCollector()

clang::clangd::SymbolCollector::~SymbolCollector ( )

Member Function Documentation

◆ finish()

void clang::clangd::SymbolCollector::finish ( )

◆ getRefContainer()

const Decl * clang::clangd::SymbolCollector::getRefContainer ( const Decl Enclosing,
const SymbolCollector::Options Opts 

Definition at line 518 of file SymbolCollector.cpp.

References shouldCollectSymbol().

Referenced by handleDeclOccurrence().

◆ handleDeclOccurrence()

bool clang::clangd::SymbolCollector::handleDeclOccurrence ( const Decl D,
index::SymbolRoleSet  Roles,
ArrayRef< index::SymbolRelation >  Relations,
SourceLocation  Loc,
index::IndexDataConsumer::ASTNodeInfo  ASTNode 

◆ handleMacroOccurrence()

bool clang::clangd::SymbolCollector::handleMacroOccurrence ( const IdentifierInfo *  Name,
const MacroInfo *  MI,
index::SymbolRoleSet  Roles,
SourceLocation  Loc 

◆ handleMacros()

void clang::clangd::SymbolCollector::handleMacros ( const MainFileMacros MacroRefsToIndex)

◆ initialize()

void clang::clangd::SymbolCollector::initialize ( ASTContext &  Ctx)

Definition at line 453 of file SymbolCollector.cpp.

◆ setPreprocessor() [1/2]

void clang::clangd::SymbolCollector::setPreprocessor ( Preprocessor &  PP)

Definition at line 136 of file SymbolCollector.h.

◆ setPreprocessor() [2/2]

void clang::clangd::SymbolCollector::setPreprocessor ( std::shared_ptr< Preprocessor >  PP)

Definition at line 133 of file SymbolCollector.h.

◆ shouldCollectSymbol()

bool clang::clangd::SymbolCollector::shouldCollectSymbol ( const NamedDecl &  ND,
const ASTContext &  ASTCtx,
const Options Opts,
bool  IsMainFileSymbol 

Returns true is ND should be collected.

Definition at line 462 of file SymbolCollector.cpp.

References clang::clangd::hasReservedName(), and clang::clangd::hasReservedScope().

Referenced by clang::clangd::getIndexableLocalDecls(), getRefContainer(), and handleDeclOccurrence().

◆ shouldIndexFile()

bool clang::clangd::SymbolCollector::shouldIndexFile ( FileID  FID)

Returns true if we are interested in references and declarations from FID.

If this function return false, bodies of functions inside those files will be skipped to decrease indexing time.

Definition at line 1080 of file SymbolCollector.cpp.

References clang::clangd::SymbolCollector::Options::FileFilter.

Referenced by handleMacroOccurrence().

◆ takeRefs()

RefSlab clang::clangd::SymbolCollector::takeRefs ( )

Definition at line 151 of file SymbolCollector.h.

◆ takeRelations()

RelationSlab clang::clangd::SymbolCollector::takeRelations ( )

Definition at line 152 of file SymbolCollector.h.

◆ takeSymbols()

SymbolSlab clang::clangd::SymbolCollector::takeSymbols ( )

Definition at line 150 of file SymbolCollector.h.

The documentation for this class was generated from the following files: