19 #include "llvm/ADT/STLExtras.h" 22 using namespace clang;
48 std::shared_ptr<Preprocessor> PP;
49 std::shared_ptr<IndexingContext> IndexCtx;
52 IndexASTConsumer(std::shared_ptr<Preprocessor> PP,
53 std::shared_ptr<IndexingContext> IndexCtx)
54 : PP(std::move(PP)), IndexCtx(std::move(IndexCtx)) {}
57 void Initialize(
ASTContext &Context)
override {
58 IndexCtx->setASTContext(Context);
59 IndexCtx->getDataConsumer().initialize(Context);
60 IndexCtx->getDataConsumer().setPreprocessor(PP);
64 return IndexCtx->indexDeclGroupRef(DG);
71 void HandleTopLevelDeclInObjCContainer(
DeclGroupRef DG)
override {
72 IndexCtx->indexDeclGroupRef(DG);
75 void HandleTranslationUnit(
ASTContext &Ctx)
override {
80 std::shared_ptr<IndexingContext> IndexCtx;
83 IndexPPCallbacks(std::shared_ptr<IndexingContext> IndexCtx)
84 : IndexCtx(std::move(IndexCtx)) {}
92 void MacroDefined(
const Token &MacroNameTok,
109 class IndexActionBase {
111 std::shared_ptr<IndexDataConsumer> DataConsumer;
112 std::shared_ptr<IndexingContext> IndexCtx;
114 IndexActionBase(std::shared_ptr<IndexDataConsumer> dataConsumer,
116 : DataConsumer(std::move(dataConsumer)),
119 std::unique_ptr<IndexASTConsumer>
125 std::unique_ptr<PPCallbacks> createIndexPPCallbacks() {
126 return llvm::make_unique<IndexPPCallbacks>(IndexCtx);
130 DataConsumer->finish();
136 IndexAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
138 : IndexActionBase(std::move(DataConsumer), Opts) {}
142 StringRef InFile)
override {
143 return createIndexASTConsumer(CI);
151 void EndSourceFileAction()
override {
158 bool IndexActionFailed =
false;
161 WrappingIndexAction(std::unique_ptr<FrontendAction> WrappedAction,
162 std::shared_ptr<IndexDataConsumer> DataConsumer,
165 IndexActionBase(std::move(DataConsumer), Opts) {}
169 StringRef InFile)
override {
171 if (!OtherConsumer) {
172 IndexActionFailed =
true;
176 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
177 Consumers.push_back(std::move(OtherConsumer));
178 Consumers.push_back(createIndexASTConsumer(CI));
179 return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
188 void EndSourceFileAction()
override {
191 if (!IndexActionFailed)
198 std::unique_ptr<FrontendAction>
201 std::unique_ptr<FrontendAction> WrappedAction) {
203 return llvm::make_unique<WrappingIndexAction>(std::move(WrappedAction),
204 std::move(DataConsumer),
206 return llvm::make_unique<IndexAction>(std::move(DataConsumer), Opts);
235 for (
const Decl *D : Decls)
240 std::unique_ptr<PPCallbacks>
242 return llvm::make_unique<IndexPPCallbacks>(
243 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...
Decl - This represents one declaration (or definition), e.g.
virtual bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations, SourceLocation Loc, ASTNodeInfo ASTNode)
A description of the current definition of a macro.
bool indexTopLevelDecl(const Decl *D)
virtual bool handleModuleOccurence(const ImportDecl *ImportD, SymbolRoleSet Roles, SourceLocation Loc)
void setASTContext(ASTContext &ctx)
This interface provides a way to observe the actions of the preprocessor as it does its thing...
One of these records is kept for each identifier that is lexed.
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.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
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 ...
bool BeginSourceFileAction(CompilerInstance &CI) override
Callback at the start of processing a single input.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Defines the clang::Preprocessor interface.
virtual void EndSourceFileAction()
Callback at the end of processing a single input.
Information about a module that has been loaded by the ASTReader.
void EndSourceFileAction() override
Callback at the end of processing a single input.
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.
Encodes a location in the source.
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...
Describes a module import declaration, which makes the contents of the named module visible in the cu...
const MacroInfo * getMacroInfo() const
Dataflow Directional Tag Classes.
virtual bool handleMacroOccurence(const IdentifierInfo *Name, const MacroInfo *MI, SymbolRoleSet Roles, SourceLocation Loc)
Reads an AST files chain containing the contents of a translation unit.
A frontend action which simply wraps some other runtime-specified frontend action.
Encapsulates the data about a macro definition (e.g.
std::shared_ptr< Preprocessor > getPreprocessorPtr() const
const ASTContext & getASTContext() const
Defines the PPCallbacks interface.
static void indexTranslationUnit(ASTUnit &Unit, IndexingContext &IndexCtx)
std::unique_ptr< FrontendAction > createIndexingAction(std::shared_ptr< IndexDataConsumer > DataConsumer, IndexingOptions Opts, std::unique_ptr< FrontendAction > WrappedAction)
Creates a frontend action that indexes all symbols (macros and AST decls).
Preprocessor & getPreprocessor() const
Return the current preprocessor.
void indexTopLevelDecls(ASTContext &Ctx, ArrayRef< const Decl *> Decls, IndexDataConsumer &DataConsumer, IndexingOptions Opts)
Recursively indexes Decls.
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
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)