Home | History | Annotate | Download | only in Frontend
      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 
     14 #include "clang/Frontend/TextDiagnosticBuffer.h"
     15 #include "llvm/ADT/SmallString.h"
     16 using namespace clang;
     17 
     18 /// HandleDiagnostic - Store the errors, warnings, and notes that are
     19 /// reported.
     20 ///
     21 void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic::Level Level,
     22                                             const DiagnosticInfo &Info) {
     23   // Default implementation (Warnings/errors count).
     24   DiagnosticClient::HandleDiagnostic(Level, Info);
     25 
     26   llvm::SmallString<100> Buf;
     27   Info.FormatDiagnostic(Buf);
     28   switch (Level) {
     29   default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
     30   case Diagnostic::Note:
     31     Notes.push_back(std::make_pair(Info.getLocation(), Buf.str()));
     32     break;
     33   case Diagnostic::Warning:
     34     Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str()));
     35     break;
     36   case Diagnostic::Error:
     37   case Diagnostic::Fatal:
     38     Errors.push_back(std::make_pair(Info.getLocation(), Buf.str()));
     39     break;
     40   }
     41 }
     42 
     43 void TextDiagnosticBuffer::FlushDiagnostics(Diagnostic &Diags) const {
     44   // FIXME: Flush the diagnostics in order.
     45   for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it)
     46     Diags.Report(Diags.getCustomDiagID(Diagnostic::Error, it->second.c_str()));
     47   for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it)
     48     Diags.Report(Diags.getCustomDiagID(Diagnostic::Warning,it->second.c_str()));
     49   for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it)
     50     Diags.Report(Diags.getCustomDiagID(Diagnostic::Note, it->second.c_str()));
     51 }
     52