TextDiagnosticBuffer.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- TextDiagnosticBuffer.h - Buffer Text Diagnostics ---------*- 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 buffers the diagnostic messages.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICBUFFER_H
  18. #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICBUFFER_H
  19. #include "clang/Basic/Diagnostic.h"
  20. #include "clang/Basic/SourceLocation.h"
  21. #include <cstddef>
  22. #include <string>
  23. #include <utility>
  24. #include <vector>
  25. namespace clang {
  26. class TextDiagnosticBuffer : public DiagnosticConsumer {
  27. public:
  28. using DiagList = std::vector<std::pair<SourceLocation, std::string>>;
  29. using iterator = DiagList::iterator;
  30. using const_iterator = DiagList::const_iterator;
  31. private:
  32. DiagList Errors, Warnings, Remarks, Notes;
  33. /// All - All diagnostics in the order in which they were generated. That
  34. /// order likely doesn't correspond to user input order, but it at least
  35. /// keeps notes in the right places. Each pair in the vector is a diagnostic
  36. /// level and an index into the corresponding DiagList above.
  37. std::vector<std::pair<DiagnosticsEngine::Level, size_t>> All;
  38. public:
  39. const_iterator err_begin() const { return Errors.begin(); }
  40. const_iterator err_end() const { return Errors.end(); }
  41. const_iterator warn_begin() const { return Warnings.begin(); }
  42. const_iterator warn_end() const { return Warnings.end(); }
  43. const_iterator remark_begin() const { return Remarks.begin(); }
  44. const_iterator remark_end() const { return Remarks.end(); }
  45. const_iterator note_begin() const { return Notes.begin(); }
  46. const_iterator note_end() const { return Notes.end(); }
  47. void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
  48. const Diagnostic &Info) override;
  49. /// FlushDiagnostics - Flush the buffered diagnostics to an given
  50. /// diagnostic engine.
  51. void FlushDiagnostics(DiagnosticsEngine &Diags) const;
  52. };
  53. } // namespace clang
  54. #endif // LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICBUFFER_H
  55. #ifdef __GNUC__
  56. #pragma GCC diagnostic pop
  57. #endif