18 using namespace clang;
19 using namespace clang::index;
21 void IndexDataConsumer::_anchor() {}
49 : IndexCtx(IndexCtx) {}
54 IndexCtx.getDataConsumer().initialize(Context);
58 return IndexCtx.indexDeclGroupRef(DG);
65 void HandleTopLevelDeclInObjCContainer(
DeclGroupRef DG)
override {
66 IndexCtx.indexDeclGroupRef(DG);
69 void HandleTranslationUnit(
ASTContext &Ctx)
override {
73 class IndexActionBase {
75 std::shared_ptr<IndexDataConsumer> DataConsumer;
78 IndexActionBase(std::shared_ptr<IndexDataConsumer> dataConsumer,
80 : DataConsumer(std::move(dataConsumer)),
81 IndexCtx(Opts, *DataConsumer) {}
83 std::unique_ptr<IndexASTConsumer> createIndexASTConsumer() {
84 return llvm::make_unique<IndexASTConsumer>(IndexCtx);
88 DataConsumer->finish();
94 IndexAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
96 : IndexActionBase(std::move(DataConsumer), Opts) {}
100 StringRef InFile)
override {
101 return createIndexASTConsumer();
104 void EndSourceFileAction()
override {
111 bool IndexActionFailed =
false;
114 WrappingIndexAction(std::unique_ptr<FrontendAction> WrappedAction,
115 std::shared_ptr<IndexDataConsumer> DataConsumer,
118 IndexActionBase(std::move(DataConsumer), Opts) {}
122 StringRef InFile)
override;
123 void EndSourceFileAction()
override;
128 void WrappingIndexAction::EndSourceFileAction() {
131 if (!IndexActionFailed)
135 std::unique_ptr<ASTConsumer>
136 WrappingIndexAction::CreateASTConsumer(
CompilerInstance &CI, StringRef InFile) {
138 if (!OtherConsumer) {
139 IndexActionFailed =
true;
143 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
144 Consumers.push_back(std::move(OtherConsumer));
145 Consumers.push_back(createIndexASTConsumer());
146 return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
149 std::unique_ptr<FrontendAction>
152 std::unique_ptr<FrontendAction> WrappedAction) {
154 return llvm::make_unique<WrappingIndexAction>(std::move(WrappedAction),
155 std::move(DataConsumer),
157 return llvm::make_unique<IndexAction>(std::move(DataConsumer), Opts);
171 std::shared_ptr<IndexDataConsumer> DataConsumer,
177 DataConsumer->finish();
181 std::shared_ptr<IndexDataConsumer> DataConsumer,
186 DataConsumer->initialize(Ctx);
187 for (
const Decl *D : Decls)
189 DataConsumer->finish();
194 std::shared_ptr<IndexDataConsumer> DataConsumer,
199 DataConsumer->initialize(Ctx);
204 DataConsumer->finish();
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
virtual bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles, ArrayRef< SymbolRelation > Relations, FileID FID, unsigned Offset, ASTNodeInfo ASTNode)
Decl - This represents one declaration (or definition), e.g.
bool indexTopLevelDecl(const Decl *D)
void setASTContext(ASTContext &ctx)
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.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
llvm::iterator_range< ModuleDeclIterator > getModuleFileLevelDecls(ModuleFile &Mod)
ASTContext & getContext()
Retrieve the AST context that this AST reader supplements.
void indexTopLevelDecls(ASTContext &Ctx, ArrayRef< const Decl * > Decls, std::shared_ptr< IndexDataConsumer > DataConsumer, IndexingOptions Opts)
Defines the clang::Preprocessor interface.
virtual bool handleModuleOccurence(const ImportDecl *ImportD, SymbolRoleSet Roles, FileID FID, unsigned Offset)
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.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
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 ASTContext & getASTContext() const
Describes a module import declaration, which makes the contents of the named module visible in the cu...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
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.
void indexASTUnit(ASTUnit &Unit, std::shared_ptr< IndexDataConsumer > DataConsumer, IndexingOptions Opts)
static void indexTranslationUnit(ASTUnit &Unit, IndexingContext &IndexCtx)
virtual bool handleMacroOccurence(const IdentifierInfo *Name, const MacroInfo *MI, SymbolRoleSet Roles, FileID FID, unsigned Offset)
std::unique_ptr< FrontendAction > createIndexingAction(std::shared_ptr< IndexDataConsumer > DataConsumer, IndexingOptions Opts, std::unique_ptr< FrontendAction > WrappedAction)
static bool topLevelDeclVisitor(void *context, const Decl *D)
Defines the clang::FrontendAction interface and various convenience abstract classes (clang::ASTFront...
void indexModuleFile(serialization::ModuleFile &Mod, ASTReader &Reader, std::shared_ptr< IndexDataConsumer > DataConsumer, IndexingOptions Opts)