|
@@ -23,6 +23,36 @@ using namespace clang::index;
|
|
|
|
|
|
namespace {
|
|
namespace {
|
|
|
|
|
|
|
|
+class IndexPPCallbacks final : public PPCallbacks {
|
|
|
|
+ std::shared_ptr<IndexingContext> IndexCtx;
|
|
|
|
+
|
|
|
|
+public:
|
|
|
|
+ IndexPPCallbacks(std::shared_ptr<IndexingContext> IndexCtx)
|
|
|
|
+ : IndexCtx(std::move(IndexCtx)) {}
|
|
|
|
+
|
|
|
|
+ void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
|
|
|
|
+ SourceRange Range, const MacroArgs *Args) override {
|
|
|
|
+ IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
+ Range.getBegin(), *MD.getMacroInfo());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void MacroDefined(const Token &MacroNameTok,
|
|
|
|
+ const MacroDirective *MD) override {
|
|
|
|
+ IndexCtx->handleMacroDefined(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
+ MacroNameTok.getLocation(),
|
|
|
|
+ *MD->getMacroInfo());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD,
|
|
|
|
+ const MacroDirective *Undef) override {
|
|
|
|
+ if (!MD.getMacroInfo()) // Ignore noop #undef.
|
|
|
|
+ return;
|
|
|
|
+ IndexCtx->handleMacroUndefined(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
+ MacroNameTok.getLocation(),
|
|
|
|
+ *MD.getMacroInfo());
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
class IndexASTConsumer final : public ASTConsumer {
|
|
class IndexASTConsumer final : public ASTConsumer {
|
|
std::shared_ptr<Preprocessor> PP;
|
|
std::shared_ptr<Preprocessor> PP;
|
|
std::shared_ptr<IndexingContext> IndexCtx;
|
|
std::shared_ptr<IndexingContext> IndexCtx;
|
|
@@ -37,6 +67,7 @@ protected:
|
|
IndexCtx->setASTContext(Context);
|
|
IndexCtx->setASTContext(Context);
|
|
IndexCtx->getDataConsumer().initialize(Context);
|
|
IndexCtx->getDataConsumer().initialize(Context);
|
|
IndexCtx->getDataConsumer().setPreprocessor(PP);
|
|
IndexCtx->getDataConsumer().setPreprocessor(PP);
|
|
|
|
+ PP->addPPCallbacks(std::make_unique<IndexPPCallbacks>(IndexCtx));
|
|
}
|
|
}
|
|
|
|
|
|
bool HandleTopLevelDecl(DeclGroupRef DG) override {
|
|
bool HandleTopLevelDecl(DeclGroupRef DG) override {
|
|
@@ -55,36 +86,6 @@ protected:
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
-class IndexPPCallbacks final : public PPCallbacks {
|
|
|
|
- std::shared_ptr<IndexingContext> IndexCtx;
|
|
|
|
-
|
|
|
|
-public:
|
|
|
|
- IndexPPCallbacks(std::shared_ptr<IndexingContext> IndexCtx)
|
|
|
|
- : IndexCtx(std::move(IndexCtx)) {}
|
|
|
|
-
|
|
|
|
- void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
|
|
|
|
- SourceRange Range, const MacroArgs *Args) override {
|
|
|
|
- IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
- Range.getBegin(), *MD.getMacroInfo());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void MacroDefined(const Token &MacroNameTok,
|
|
|
|
- const MacroDirective *MD) override {
|
|
|
|
- IndexCtx->handleMacroDefined(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
- MacroNameTok.getLocation(),
|
|
|
|
- *MD->getMacroInfo());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD,
|
|
|
|
- const MacroDirective *Undef) override {
|
|
|
|
- if (!MD.getMacroInfo()) // Ignore noop #undef.
|
|
|
|
- return;
|
|
|
|
- IndexCtx->handleMacroUndefined(*MacroNameTok.getIdentifierInfo(),
|
|
|
|
- MacroNameTok.getLocation(),
|
|
|
|
- *MD.getMacroInfo());
|
|
|
|
- }
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
class IndexActionBase {
|
|
class IndexActionBase {
|
|
protected:
|
|
protected:
|
|
std::shared_ptr<IndexDataConsumer> DataConsumer;
|
|
std::shared_ptr<IndexDataConsumer> DataConsumer;
|
|
@@ -101,10 +102,6 @@ protected:
|
|
IndexCtx);
|
|
IndexCtx);
|
|
}
|
|
}
|
|
|
|
|
|
- std::unique_ptr<PPCallbacks> createIndexPPCallbacks() {
|
|
|
|
- return std::make_unique<IndexPPCallbacks>(IndexCtx);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
void finish() {
|
|
void finish() {
|
|
DataConsumer->finish();
|
|
DataConsumer->finish();
|
|
}
|
|
}
|
|
@@ -122,11 +119,6 @@ protected:
|
|
return createIndexASTConsumer(CI);
|
|
return createIndexASTConsumer(CI);
|
|
}
|
|
}
|
|
|
|
|
|
- bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
|
|
|
|
- CI.getPreprocessor().addPPCallbacks(createIndexPPCallbacks());
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
void EndSourceFileAction() override {
|
|
void EndSourceFileAction() override {
|
|
FrontendAction::EndSourceFileAction();
|
|
FrontendAction::EndSourceFileAction();
|
|
finish();
|
|
finish();
|
|
@@ -158,12 +150,6 @@ protected:
|
|
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
|
|
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
|
|
}
|
|
}
|
|
|
|
|
|
- bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
|
|
|
|
- WrapperFrontendAction::BeginSourceFileAction(CI);
|
|
|
|
- CI.getPreprocessor().addPPCallbacks(createIndexPPCallbacks());
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
void EndSourceFileAction() override {
|
|
void EndSourceFileAction() override {
|
|
// Invoke wrapped action's method.
|
|
// Invoke wrapped action's method.
|
|
WrapperFrontendAction::EndSourceFileAction();
|
|
WrapperFrontendAction::EndSourceFileAction();
|