nicovank created this revision. Herald added subscribers: carlosgalvezp, xazax.hun. Herald added a project: All. nicovank added reviewers: alexfh, aaron.ballman, njames93. nicovank published this revision for review. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
I am writing a prototype check that needs source file and line numbers to map code to external data. As far as I know, the only way to achieve that is to expose the SourceManager which is so far only used to emit diagnostics. Test Plan: On a blank new check, `MatchedDecl->getBeginLoc().dump(Context->getSourceManager());` does properly show the matched declaration's origin filename and line number. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D127886 Files: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h +++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h @@ -121,6 +121,9 @@ /// This is called from the \c ClangTidyCheck base class. void setSourceManager(SourceManager *SourceMgr); + /// Gets the \c SourceManager from the used \c DiagnosticsEngine. + SourceManager &getSourceManager(); + /// Should be called when starting to process new translation unit. void setCurrentFile(StringRef File); Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -221,6 +221,10 @@ DiagEngine->setSourceManager(SourceMgr); } +SourceManager &ClangTidyContext::getSourceManager() { + return DiagEngine->getSourceManager(); +} + void ClangTidyContext::setCurrentFile(StringRef File) { CurrentFile = std::string(File); CurrentOptions = getOptionsForFile(CurrentFile);
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h +++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h @@ -121,6 +121,9 @@ /// This is called from the \c ClangTidyCheck base class. void setSourceManager(SourceManager *SourceMgr); + /// Gets the \c SourceManager from the used \c DiagnosticsEngine. + SourceManager &getSourceManager(); + /// Should be called when starting to process new translation unit. void setCurrentFile(StringRef File); Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp =================================================================== --- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -221,6 +221,10 @@ DiagEngine->setSourceManager(SourceMgr); } +SourceManager &ClangTidyContext::getSourceManager() { + return DiagEngine->getSourceManager(); +} + void ClangTidyContext::setCurrentFile(StringRef File) { CurrentFile = std::string(File); CurrentOptions = getOptionsForFile(CurrentFile);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits