Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:55

0001 //===--- SARIFDiagnostic.h - SARIF Diagnostic Formatting -----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This is a utility class that provides support for constructing a SARIF object
0010 // containing diagnostics.
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   // Shared between SARIFDiagnosticPrinter and this renderer.
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 } // end namespace clang
0073 
0074 #endif