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 #include "llvm/Support/ErrorHandling.h" 17 using namespace clang; 18 19 /// HandleDiagnostic - Store the errors, warnings, and notes that are 20 /// reported. 21 /// 22 void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level, 23 const Diagnostic &Info) { 24 // Default implementation (Warnings/errors count). 25 DiagnosticConsumer::HandleDiagnostic(Level, Info); 26 27 llvm::SmallString<100> Buf; 28 Info.FormatDiagnostic(Buf); 29 switch (Level) { 30 default: llvm_unreachable( 31 "Diagnostic not handled during diagnostic buffering!"); 32 case DiagnosticsEngine::Note: 33 Notes.push_back(std::make_pair(Info.getLocation(), Buf.str())); 34 break; 35 case DiagnosticsEngine::Warning: 36 Warnings.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 45 void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { 46 // FIXME: Flush the diagnostics in order. 47 for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it) 48 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, 49 it->second.c_str())); 50 for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it) 51 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, 52 it->second.c_str())); 53 for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it) 54 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, 55 it->second.c_str())); 56 } 57 58 DiagnosticConsumer *TextDiagnosticBuffer::clone(DiagnosticsEngine &) const { 59 return new TextDiagnosticBuffer(); 60 } 61