LogDiagnosticPrinter.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- LogDiagnosticPrinter.h - Log Diagnostic Client ---------*- 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. #ifndef LLVM_CLANG_FRONTEND_LOGDIAGNOSTICPRINTER_H
  14. #define LLVM_CLANG_FRONTEND_LOGDIAGNOSTICPRINTER_H
  15. #include "clang/Basic/Diagnostic.h"
  16. #include "clang/Basic/SourceLocation.h"
  17. #include "llvm/ADT/SmallVector.h"
  18. #include "llvm/ADT/StringRef.h"
  19. namespace clang {
  20. class DiagnosticOptions;
  21. class LangOptions;
  22. class LogDiagnosticPrinter : public DiagnosticConsumer {
  23. struct DiagEntry {
  24. /// The primary message line of the diagnostic.
  25. std::string Message;
  26. /// The source file name, if available.
  27. std::string Filename;
  28. /// The source file line number, if available.
  29. unsigned Line;
  30. /// The source file column number, if available.
  31. unsigned Column;
  32. /// The ID of the diagnostic.
  33. unsigned DiagnosticID;
  34. /// The Option Flag for the diagnostic
  35. std::string WarningOption;
  36. /// The level of the diagnostic.
  37. DiagnosticsEngine::Level DiagnosticLevel;
  38. };
  39. void EmitDiagEntry(llvm::raw_ostream &OS,
  40. const LogDiagnosticPrinter::DiagEntry &DE);
  41. // Conditional ownership (when StreamOwner is non-null, it's keeping OS
  42. // alive). We might want to replace this with a wrapper for conditional
  43. // ownership eventually - it seems to pop up often enough.
  44. raw_ostream &OS;
  45. std::unique_ptr<raw_ostream> StreamOwner;
  46. const LangOptions *LangOpts;
  47. IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
  48. SourceLocation LastWarningLoc;
  49. FullSourceLoc LastLoc;
  50. SmallVector<DiagEntry, 8> Entries;
  51. std::string MainFilename;
  52. std::string DwarfDebugFlags;
  53. public:
  54. LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags,
  55. std::unique_ptr<raw_ostream> StreamOwner);
  56. void setDwarfDebugFlags(StringRef Value) {
  57. DwarfDebugFlags = std::string(Value);
  58. }
  59. void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override {
  60. LangOpts = &LO;
  61. }
  62. void EndSourceFile() override;
  63. void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
  64. const Diagnostic &Info) override;
  65. };
  66. } // end namespace clang
  67. #endif
  68. #ifdef __GNUC__
  69. #pragma GCC diagnostic pop
  70. #endif