clang-tools 8.0.0

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:
[legend]
Collaboration diagram for clang::clangd::SymbolCollector:
[legend]

## Classes
struct | Options

## Public Member Functions
| SymbolCollector (Options Opts)
void | initialize (ASTContext &Ctx) override
void | setPreprocessor (std::shared_ptr< Preprocessor > PP) override
bool | handleDeclOccurence (const Decl *D, index::SymbolRoleSet Roles, ArrayRef< index::SymbolRelation > Relations, SourceLocation Loc, index::IndexDataConsumer::ASTNodeInfo ASTNode) override
bool | handleMacroOccurence (const IdentifierInfo *Name, const MacroInfo *MI, index::SymbolRoleSet Roles, SourceLocation Loc) override
SymbolSlab | takeSymbols ()
RefSlab | takeRefs ()
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. More...

## Detailed Description

Collect declarations (symbols) from an AST.

It collects most declarations except:

- Implicit declarations
- Anonymous declarations (anonymous enum/class/struct, etc)
- Declarations in anonymous namespaces in headers
- Local declarations (in function bodies, blocks, etc)
- Template specializations
- Library-specific private declarations (e.g. private declaration generated by protobuf compiler)

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 44 of file SymbolCollector.h.

## Constructor & Destructor Documentation

## ◆ SymbolCollector()

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

Definition at line 232 of file SymbolCollector.cpp.

## Member Function Documentation

## ◆ finish()

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

Definition at line 439 of file SymbolCollector.cpp.

Referenced by takeRefs().

## ◆ handleDeclOccurence()

bool clang::clangd::SymbolCollector::handleDeclOccurence | ( | const Decl * | D,
|  | index::SymbolRoleSet | Roles,
|  | ArrayRef< index::SymbolRelation > | Relations,
|  | SourceLocation | Loc,
|  | index::IndexDataConsumer::ASTNodeInfo | ASTNode
| ) |  |
| override

Definition at line 293 of file SymbolCollector.cpp.

References D, and shouldCollectSymbol().

Referenced by setPreprocessor().

## ◆ handleMacroOccurence()

bool clang::clangd::SymbolCollector::handleMacroOccurence | ( | const IdentifierInfo * | Name,
|  | const MacroInfo * | MI,
|  | index::SymbolRoleSet | Roles,
|  | SourceLocation | Loc
| ) |  |
| override

Definition at line 367 of file SymbolCollector.cpp.

Referenced by setPreprocessor().

## ◆ initialize()

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

Definition at line 234 of file SymbolCollector.cpp.

References Ctx.

## ◆ setPreprocessor()

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

Definition at line 92 of file SymbolCollector.h.

References D, handleDeclOccurence(), handleMacroOccurence(), Loc, and Name.

## ◆ shouldCollectSymbol()

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

Returns true is `ND` should be collected.

Definition at line 241 of file SymbolCollector.cpp.

References clang::clangd::SymbolCollector::Options::CollectMainFileSymbols, clang::clangd::Enum, and clang::clangd::Namespace.

Referenced by handleDeclOccurence().

## ◆ takeRefs()

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

Definition at line 107 of file SymbolCollector.h.

References finish().

## ◆ takeSymbols()

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

Definition at line 106 of file SymbolCollector.h.

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

- SymbolCollector.h
- SymbolCollector.cpp