SARIFDiagnostic.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- SARIFDiagnostic.h - SARIF Diagnostic Formatting -----*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This is a utility class that provides support for constructing a SARIF object
  15. // containing diagnostics.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_FRONTEND_SARIFDIAGNOSTIC_H
  19. #define LLVM_CLANG_FRONTEND_SARIFDIAGNOSTIC_H
  20. #include "clang/Basic/Sarif.h"
  21. #include "clang/Frontend/DiagnosticRenderer.h"
  22. #include "llvm/ADT/StringRef.h"
  23. namespace clang {
  24. class SARIFDiagnostic : public DiagnosticRenderer {
  25. public:
  26. SARIFDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
  27. DiagnosticOptions *DiagOpts, SarifDocumentWriter *Writer);
  28. ~SARIFDiagnostic() = default;
  29. SARIFDiagnostic &operator=(const SARIFDiagnostic &&) = delete;
  30. SARIFDiagnostic(SARIFDiagnostic &&) = delete;
  31. SARIFDiagnostic &operator=(const SARIFDiagnostic &) = delete;
  32. SARIFDiagnostic(const SARIFDiagnostic &) = delete;
  33. protected:
  34. void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
  35. DiagnosticsEngine::Level Level, StringRef Message,
  36. ArrayRef<CharSourceRange> Ranges,
  37. DiagOrStoredDiag D) override;
  38. void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
  39. DiagnosticsEngine::Level Level,
  40. ArrayRef<CharSourceRange> Ranges) override;
  41. void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
  42. SmallVectorImpl<CharSourceRange> &Ranges,
  43. ArrayRef<FixItHint> Hints) override {}
  44. void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override;
  45. void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
  46. StringRef ModuleName) override;
  47. void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
  48. StringRef ModuleName) override;
  49. private:
  50. // Shared between SARIFDiagnosticPrinter and this renderer.
  51. SarifDocumentWriter *Writer;
  52. SarifResult addLocationToResult(SarifResult Result, FullSourceLoc Loc,
  53. PresumedLoc PLoc,
  54. ArrayRef<CharSourceRange> Ranges,
  55. const Diagnostic &Diag);
  56. SarifRule addDiagnosticLevelToRule(SarifRule Rule,
  57. DiagnosticsEngine::Level Level);
  58. llvm::StringRef emitFilename(StringRef Filename, const SourceManager &SM);
  59. };
  60. } // end namespace clang
  61. #endif
  62. #ifdef __GNUC__
  63. #pragma GCC diagnostic pop
  64. #endif