File indexing completed on 2024-04-21 05:38:47
0001 /* 0002 SPDX-FileCopyrightText: 2019 Christian Gagneraud <chgans@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef CLAZY_FIX_IT_EXPORTER_H 0008 #define CLAZY_FIX_IT_EXPORTER_H 0009 0010 #include <clang/Basic/Diagnostic.h> 0011 #include <clang/Tooling/Core/Diagnostic.h> 0012 0013 namespace clang 0014 { 0015 class FixItOptions; 0016 } 0017 0018 class FixItExporter : public clang::DiagnosticConsumer 0019 { 0020 public: 0021 explicit FixItExporter(clang::DiagnosticsEngine &DiagEngine, 0022 clang::SourceManager &SourceMgr, 0023 const clang::LangOptions &LangOpts, 0024 const std::string &exportFixes, 0025 bool isClazyStandalone); 0026 0027 ~FixItExporter() override; 0028 0029 bool IncludeInDiagnosticCounts() const override; 0030 0031 void BeginSourceFile(const clang::LangOptions &LangOpts, const clang::Preprocessor *PP = nullptr) override; 0032 0033 void EndSourceFile() override; 0034 0035 void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) override; 0036 0037 void Export(); 0038 0039 /// Emit a diagnostic via the adapted diagnostic client. 0040 void Diag(clang::SourceLocation Loc, unsigned DiagID); 0041 0042 private: 0043 clang::DiagnosticsEngine &DiagEngine; 0044 clang::SourceManager &SourceMgr; 0045 const clang::LangOptions &LangOpts; 0046 const std::string exportFixes; 0047 DiagnosticConsumer *Client = nullptr; 0048 std::unique_ptr<DiagnosticConsumer> Owner; 0049 bool m_recordNotes = false; 0050 clang::tooling::Diagnostic ConvertDiagnostic(const clang::Diagnostic &Info); 0051 clang::tooling::Replacement ConvertFixIt(const clang::FixItHint &Hint); 0052 }; 0053 0054 #endif // CLAZY_FIX_IT_EXPORTER_H