TextDiagnosticPrinter.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- TextDiagnosticPrinter.h - Text 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. //
  14. // This is a concrete diagnostic client, which prints the diagnostics to
  15. // standard error.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICPRINTER_H
  19. #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICPRINTER_H
  20. #include "clang/Basic/Diagnostic.h"
  21. #include "clang/Basic/LLVM.h"
  22. #include "llvm/ADT/IntrusiveRefCntPtr.h"
  23. #include <memory>
  24. namespace clang {
  25. class DiagnosticOptions;
  26. class LangOptions;
  27. class TextDiagnostic;
  28. class TextDiagnosticPrinter : public DiagnosticConsumer {
  29. raw_ostream &OS;
  30. IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
  31. /// Handle to the currently active text diagnostic emitter.
  32. std::unique_ptr<TextDiagnostic> TextDiag;
  33. /// A string to prefix to error messages.
  34. std::string Prefix;
  35. unsigned OwnsOutputStream : 1;
  36. public:
  37. TextDiagnosticPrinter(raw_ostream &os, DiagnosticOptions *diags,
  38. bool OwnsOutputStream = false);
  39. ~TextDiagnosticPrinter() override;
  40. /// setPrefix - Set the diagnostic printer prefix string, which will be
  41. /// printed at the start of any diagnostics. If empty, no prefix string is
  42. /// used.
  43. void setPrefix(std::string Value) { Prefix = std::move(Value); }
  44. void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override;
  45. void EndSourceFile() override;
  46. void HandleDiagnostic(DiagnosticsEngine::Level Level,
  47. const Diagnostic &Info) override;
  48. };
  49. } // end namespace clang
  50. #endif
  51. #ifdef __GNUC__
  52. #pragma GCC diagnostic pop
  53. #endif