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 {
std::shared_ptr<Preprocessor> PP;
std::shared_ptr<IndexingContext> IndexCtx;
IndexCtx->setASTContext(Context);
IndexCtx->getDataConsumer().initialize(Context);
IndexCtx->getDataConsumer().setPreprocessor(PP);
+ PP->addPPCallbacks(std::make_unique<IndexPPCallbacks>(IndexCtx));
}
bool HandleTopLevelDecl(DeclGroupRef DG) override {
}
};
-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 {
protected:
std::shared_ptr<IndexDataConsumer> DataConsumer;
IndexCtx);
}
- std::unique_ptr<PPCallbacks> createIndexPPCallbacks() {
- return std::make_unique<IndexPPCallbacks>(IndexCtx);
- }
-
void finish() {
DataConsumer->finish();
}
return createIndexASTConsumer(CI);
}
- bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
- CI.getPreprocessor().addPPCallbacks(createIndexPPCallbacks());
- return true;
- }
-
void EndSourceFileAction() override {
FrontendAction::EndSourceFileAction();
finish();
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 {
// Invoke wrapped action's method.
WrapperFrontendAction::EndSourceFileAction();