19 #include "llvm/ADT/STLExtras.h" 22 using namespace clang;
49 std::shared_ptr<Preprocessor> PP;
50 std::shared_ptr<IndexingContext> IndexCtx;
53 IndexASTConsumer(std::shared_ptr<Preprocessor> PP,
54 std::shared_ptr<IndexingContext> IndexCtx)
55 : PP(std::move(PP)), IndexCtx(std::move(IndexCtx)) {}
58 void Initialize(
ASTContext &Context)
override {
59 IndexCtx->setASTContext(Context);
60 IndexCtx->getDataConsumer().initialize(Context);
61 IndexCtx->getDataConsumer().setPreprocessor(PP);
65 return IndexCtx->indexDeclGroupRef(DG);
72 void HandleTopLevelDeclInObjCContainer(
DeclGroupRef DG)
override {
73 IndexCtx->indexDeclGroupRef(DG);
76 void HandleTranslationUnit(
ASTContext &Ctx)
override {
81 std::shared_ptr<IndexingContext> IndexCtx;
84 IndexPPCallbacks(std::shared_ptr<IndexingContext> IndexCtx)
85 : IndexCtx(std::move(IndexCtx)) {}
93 void MacroDefined(
const Token &MacroNameTok,
110 class IndexActionBase {
112 std::shared_ptr<IndexDataConsumer> DataConsumer;
113 std::shared_ptr<IndexingContext> IndexCtx;
115 IndexActionBase(std::shared_ptr<IndexDataConsumer> dataConsumer,
117 : DataConsumer(std::move(dataConsumer)),
120 std::unique_ptr<IndexASTConsumer>
126 std::unique_ptr<PPCallbacks> createIndexPPCallbacks() {
127 return llvm::make_unique<IndexPPCallbacks>(IndexCtx);
131 DataConsumer->finish();
137 IndexAction(std::shared_ptr<IndexDataConsumer> DataConsumer,
139 : IndexActionBase(std::move(DataConsumer), Opts) {}
143 StringRef InFile)
override {
144 return createIndexASTConsumer(CI);
152 void EndSourceFileAction()
override {
159 bool IndexActionFailed =
false;
162 WrappingIndexAction(std::unique_ptr<FrontendAction> WrappedAction,
163 std::shared_ptr<IndexDataConsumer> DataConsumer,
166 IndexActionBase(std::move(DataConsumer), Opts) {}
170 StringRef InFile)
override {
172 if (!OtherConsumer) {
173 IndexActionFailed =
true;
177 std::vector<std::unique_ptr<ASTConsumer>> Consumers;
178 Consumers.push_back(std::move(OtherConsumer));
179 Consumers.push_back(createIndexASTConsumer(CI));
180 return llvm::make_unique<MultiplexConsumer>(std::move(Consumers));
189 void EndSourceFileAction()
override {
192 if (!IndexActionFailed)
199 std::unique_ptr<FrontendAction>
202 std::unique_ptr<FrontendAction> WrappedAction) {
204 return llvm::make_unique<WrappingIndexAction>(std::move(WrappedAction),
205 std::move(DataConsumer),
207 return llvm::make_unique<IndexAction>(std::move(DataConsumer), Opts);
221 for (
const auto &M : PP.
macros())
224 M.first, MD->getMacroInfo(),
254 for (
const Decl *D : Decls)
259 std::unique_ptr<PPCallbacks>
261 return llvm::make_unique<IndexPPCallbacks>(
262 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.
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)
bool IndexMacrosInPreprocessor
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()
Describes a module or submodule.
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.
virtual bool handleModuleOccurence(const ImportDecl *ImportD, const Module *Mod, SymbolRoleSet Roles, SourceLocation Loc)
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.
void indexTopLevelDecls(ASTContext &Ctx, Preprocessor &PP, ArrayRef< const Decl *> Decls, IndexDataConsumer &DataConsumer, IndexingOptions Opts)
Recursively indexes Decls.
llvm::iterator_range< macro_iterator > macros(bool IncludeExternalMacros=true) const
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
Preprocessor & getPreprocessor() const
Retrieve the preprocessor.
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.
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)
Engages in a tight little dance with the lexer to efficiently preprocess tokens.