File indexing completed on 2026-05-10 08:36:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_FRONTEND_SARIFDIAGNOSTIC_H
0015 #define LLVM_CLANG_FRONTEND_SARIFDIAGNOSTIC_H
0016
0017 #include "clang/Basic/Sarif.h"
0018 #include "clang/Frontend/DiagnosticRenderer.h"
0019 #include "llvm/ADT/StringRef.h"
0020
0021 namespace clang {
0022
0023 class SARIFDiagnostic : public DiagnosticRenderer {
0024 public:
0025 SARIFDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
0026 DiagnosticOptions *DiagOpts, SarifDocumentWriter *Writer);
0027
0028 ~SARIFDiagnostic() = default;
0029
0030 SARIFDiagnostic &operator=(const SARIFDiagnostic &&) = delete;
0031 SARIFDiagnostic(SARIFDiagnostic &&) = delete;
0032 SARIFDiagnostic &operator=(const SARIFDiagnostic &) = delete;
0033 SARIFDiagnostic(const SARIFDiagnostic &) = delete;
0034
0035 protected:
0036 void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
0037 DiagnosticsEngine::Level Level, StringRef Message,
0038 ArrayRef<CharSourceRange> Ranges,
0039 DiagOrStoredDiag D) override;
0040
0041 void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
0042 DiagnosticsEngine::Level Level,
0043 ArrayRef<CharSourceRange> Ranges) override;
0044
0045 void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
0046 SmallVectorImpl<CharSourceRange> &Ranges,
0047 ArrayRef<FixItHint> Hints) override {}
0048
0049 void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override;
0050
0051 void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
0052 StringRef ModuleName) override;
0053
0054 void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
0055 StringRef ModuleName) override;
0056
0057 private:
0058
0059 SarifDocumentWriter *Writer;
0060
0061 SarifResult addLocationToResult(SarifResult Result, FullSourceLoc Loc,
0062 PresumedLoc PLoc,
0063 ArrayRef<CharSourceRange> Ranges,
0064 const Diagnostic &Diag);
0065
0066 SarifRule addDiagnosticLevelToRule(SarifRule Rule,
0067 DiagnosticsEngine::Level Level);
0068
0069 llvm::StringRef emitFilename(StringRef Filename, const SourceManager &SM);
0070 };
0071
0072 }
0073
0074 #endif