TextDiagnosticBuffer.cpp revision d6471f7c1921c7802804ce3ff6fe9768310f72b9
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This is a concrete diagnostic client, which buffers the diagnostic messages.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14e1bd4e6d7c5b13462f83245865f7d9e9b6ea8486Daniel Dunbar#include "clang/Frontend/TextDiagnosticBuffer.h"
15f4c839657742b823cea1a95b18422f1ba74d3dddChris Lattner#include "llvm/ADT/SmallString.h"
16548f6c8e8010b181cb151df92f0a989363cb993eDavid Blaikie#include "llvm/Support/ErrorHandling.h"
175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang;
185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1994b1dd2368dc9eeedf2794db654deae225fac763Douglas Gregor/// HandleDiagnostic - Store the errors, warnings, and notes that are
2094b1dd2368dc9eeedf2794db654deae225fac763Douglas Gregor/// reported.
211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump///
22d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikievoid TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
230a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner                                            const DiagnosticInfo &Info) {
24f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis  // Default implementation (Warnings/errors count).
25f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis  DiagnosticClient::HandleDiagnostic(Level, Info);
26f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis
274cbe3b64be7b1b312e4e555e8c93ef8e5bd3a820Daniel Dunbar  llvm::SmallString<100> Buf;
284cbe3b64be7b1b312e4e555e8c93ef8e5bd3a820Daniel Dunbar  Info.FormatDiagnostic(Buf);
295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Level) {
30b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie  default: llvm_unreachable(
31b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie                         "Diagnostic not handled during diagnostic buffering!");
32d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  case DiagnosticsEngine::Note:
334cbe3b64be7b1b312e4e555e8c93ef8e5bd3a820Daniel Dunbar    Notes.push_back(std::make_pair(Info.getLocation(), Buf.str()));
34233f74b29b2864d5984e13f3ae10a21404ef82e8Douglas Gregor    break;
35d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  case DiagnosticsEngine::Warning:
364cbe3b64be7b1b312e4e555e8c93ef8e5bd3a820Daniel Dunbar    Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str()));
375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
38d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  case DiagnosticsEngine::Error:
39d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  case DiagnosticsEngine::Fatal:
404cbe3b64be7b1b312e4e555e8c93ef8e5bd3a820Daniel Dunbar    Errors.push_back(std::make_pair(Info.getLocation(), Buf.str()));
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
44c238955f09f3bce9386e6553d5d12f79e8cc2b08Daniel Dunbar
45d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikievoid TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
46c238955f09f3bce9386e6553d5d12f79e8cc2b08Daniel Dunbar  // FIXME: Flush the diagnostics in order.
47c238955f09f3bce9386e6553d5d12f79e8cc2b08Daniel Dunbar  for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it)
48d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error,
49d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie                 it->second.c_str()));
50c238955f09f3bce9386e6553d5d12f79e8cc2b08Daniel Dunbar  for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it)
51d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning,
52d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie                 it->second.c_str()));
53c238955f09f3bce9386e6553d5d12f79e8cc2b08Daniel Dunbar  for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it)
54d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note,
55d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie                 it->second.c_str()));
56c238955f09f3bce9386e6553d5d12f79e8cc2b08Daniel Dunbar}
57