18 #include "llvm/ADT/STLExtras.h" 21 using namespace clang;
27 std::shared_ptr<IndexingContext> IndexCtx;
30 IndexPPCallbacks(std::shared_ptr<IndexingContext> IndexCtx)
31 : IndexCtx(
std::move(IndexCtx)) {}
39 void MacroDefined(
const Token &MacroNameTok,
57 std::shared_ptr<IndexDataConsumer> DataConsumer;
58 std::shared_ptr<IndexingContext> IndexCtx;
59 std::shared_ptr<Preprocessor> PP;
60 std::function<bool(const Decl *)> ShouldSkipFunctionBody;
63 IndexASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
65 std::shared_ptr<Preprocessor> PP,
66 std::function<
bool(
const Decl *)> ShouldSkipFunctionBody)
67 : DataConsumer(
std::move(DataConsumer)),
70 ShouldSkipFunctionBody(
std::move(ShouldSkipFunctionBody)) {
71 assert(this->DataConsumer !=
nullptr);
72 assert(this->PP !=
nullptr);
76 void Initialize(
ASTContext &Context)
override {
77 IndexCtx->setASTContext(Context);
78 IndexCtx->getDataConsumer().initialize(Context);
79 IndexCtx->getDataConsumer().setPreprocessor(PP);
80 PP->addPPCallbacks(std::make_unique<IndexPPCallbacks>(IndexCtx));
84 return IndexCtx->indexDeclGroupRef(DG);
91 void HandleTopLevelDeclInObjCContainer(
DeclGroupRef DG)
override {
92 IndexCtx->indexDeclGroupRef(DG);
95 void HandleTranslationUnit(
ASTContext &Ctx)
override {
96 DataConsumer->finish();
99 bool shouldSkipFunctionBody(
Decl *D)
override {
100 return ShouldSkipFunctionBody(D);
105 std::shared_ptr<IndexDataConsumer> DataConsumer;
109 IndexAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
111 : DataConsumer(
std::move(DataConsumer)), Opts(Opts) {
112 assert(this->DataConsumer !=
nullptr);
117 StringRef InFile)
override {
118 return std::make_unique<IndexASTConsumer>(
120 [](
const Decl *) {
return false; });
127 std::shared_ptr<IndexDataConsumer> DataConsumer,
129 std::function<
bool(
const Decl *)> ShouldSkipFunctionBody) {
130 return std::make_unique<IndexASTConsumer>(DataConsumer, Opts, PP,
131 ShouldSkipFunctionBody);
134 std::unique_ptr<FrontendAction>
137 assert(DataConsumer !=
nullptr);
138 return std::make_unique<IndexAction>(std::move(DataConsumer), Opts);
152 for (
const auto &M : PP.
macros())
185 for (
const Decl *D : Decls)
190 std::unique_ptr<PPCallbacks>
192 return std::make_unique<IndexPPCallbacks>(
193 std::make_shared<IndexingContext>(Opts, Consumer));
virtual void setPreprocessor(std::shared_ptr< Preprocessor > PP)
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
const Preprocessor & getPreprocessor() const
static void indexPreprocessorMacros(const Preprocessor &PP, IndexDataConsumer &DataConsumer)
Decl - This represents one declaration (or definition), e.g.
A description of the current definition of a macro.
bool indexTopLevelDecl(const Decl *D)
bool IndexMacrosInPreprocessor
void setASTContext(ASTContext &ctx)
This interface provides a way to observe the actions of the preprocessor as it does its thing...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Utility class for loading a ASTContext from an AST file.
void indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer, IndexingOptions Opts)
Recursively indexes all decls in the AST.
Token - This structure provides full information about a lexed token.
std::shared_ptr< Preprocessor > getPreprocessorPtr()
void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader, IndexDataConsumer &DataConsumer, IndexingOptions Opts)
Recursively indexes all top-level decls in the module.
llvm::iterator_range< ModuleDeclIterator > getModuleFileLevelDecls(ModuleFile &Mod)
ASTContext & getContext()
Retrieve the AST context that this AST reader supplements.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Defines the clang::Preprocessor interface.
Information about a module that has been loaded by the ASTReader.
virtual bool handleMacroOccurrence(const IdentifierInfo *Name, const MacroInfo *MI, SymbolRoleSet Roles, SourceLocation Loc)
virtual void initialize(ASTContext &Ctx)
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
std::unique_ptr< FrontendAction > createIndexingAction(std::shared_ptr< IndexDataConsumer > DataConsumer, const IndexingOptions &Opts)
Creates a frontend action that indexes all symbols (macros and AST decls).
IdentifierInfo * getIdentifierInfo() const
Abstract base class to use for AST consumer-based frontend actions.
bool visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn)
Iterate over local declarations (locally parsed if this is a parsed source file or the loaded declara...
const MacroInfo * getMacroInfo() const
Dataflow Directional Tag Classes.
Reads an AST files chain containing the contents of a translation unit.
void indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP, ArrayRef< const Decl *> Decls, IndexDataConsumer &DataConsumer, IndexingOptions Opts)
Recursively indexes Decls.
std::unique_ptr< ASTConsumer > createIndexingASTConsumer(std::shared_ptr< IndexDataConsumer > DataConsumer, const IndexingOptions &Opts, std::shared_ptr< Preprocessor > PP, std::function< bool(const Decl *)> ShouldSkipFunctionBody)
Creates an ASTConsumer that indexes all symbols (macros and AST decls).
llvm::iterator_range< macro_iterator > macros(bool IncludeExternalMacros=true) const
std::shared_ptr< Preprocessor > getPreprocessorPtr() const
Preprocessor & getPreprocessor() const
Retrieve the preprocessor.
const ASTContext & getASTContext() const
Defines the PPCallbacks interface.
static void indexTranslationUnit(ASTUnit &Unit, IndexingContext &IndexCtx)
std::unique_ptr< PPCallbacks > indexMacrosCallback(IndexDataConsumer &Consumer, IndexingOptions Opts)
Creates a PPCallbacks that indexes macros and feeds macros to Consumer.
static bool topLevelDeclVisitor(void *context, const Decl *D)
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.