TextDiagnosticBuffer.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This is a concrete diagnostic client, which buffers the diagnostic messages.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Frontend/TextDiagnosticBuffer.h"
  14. #include "llvm/ADT/SmallString.h"
  15. #include "llvm/Support/ErrorHandling.h"
  16. using namespace clang;
  17. /// HandleDiagnostic - Store the errors, warnings, and notes that are
  18. /// reported.
  19. ///
  20. void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
  21. const Diagnostic &Info) {
  22. // Default implementation (Warnings/errors count).
  23. DiagnosticConsumer::HandleDiagnostic(Level, Info);
  24. SmallString<100> Buf;
  25. Info.FormatDiagnostic(Buf);
  26. switch (Level) {
  27. default: llvm_unreachable(
  28. "Diagnostic not handled during diagnostic buffering!");
  29. case DiagnosticsEngine::Note:
  30. Notes.push_back(std::make_pair(Info.getLocation(), Buf.str()));
  31. break;
  32. case DiagnosticsEngine::Warning:
  33. Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str()));
  34. break;
  35. case DiagnosticsEngine::Remark:
  36. Remarks.push_back(std::make_pair(Info.getLocation(), Buf.str()));
  37. break;
  38. case DiagnosticsEngine::Error:
  39. case DiagnosticsEngine::Fatal:
  40. Errors.push_back(std::make_pair(Info.getLocation(), Buf.str()));
  41. break;
  42. }
  43. }
  44. void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
  45. // FIXME: Flush the diagnostics in order.
  46. for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it)
  47. Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0"))
  48. << it->second;
  49. for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it)
  50. Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, "%0"))
  51. << it->second;
  52. for (const_iterator it = remark_begin(), ie = remark_end(); it != ie; ++it)
  53. Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Remark, "%0"))
  54. << it->second;
  55. for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it)
  56. Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0"))
  57. << it->second;
  58. }