clang API Documentation
00001 //===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This is a concrete diagnostic client, which buffers the diagnostic messages. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "clang/Frontend/TextDiagnosticBuffer.h" 00015 #include "llvm/ADT/SmallString.h" 00016 #include "llvm/Support/ErrorHandling.h" 00017 using namespace clang; 00018 00019 /// HandleDiagnostic - Store the errors, warnings, and notes that are 00020 /// reported. 00021 /// 00022 void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level, 00023 const Diagnostic &Info) { 00024 // Default implementation (Warnings/errors count). 00025 DiagnosticConsumer::HandleDiagnostic(Level, Info); 00026 00027 SmallString<100> Buf; 00028 Info.FormatDiagnostic(Buf); 00029 switch (Level) { 00030 default: llvm_unreachable( 00031 "Diagnostic not handled during diagnostic buffering!"); 00032 case DiagnosticsEngine::Note: 00033 Notes.push_back(std::make_pair(Info.getLocation(), Buf.str())); 00034 break; 00035 case DiagnosticsEngine::Warning: 00036 Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str())); 00037 break; 00038 case DiagnosticsEngine::Error: 00039 case DiagnosticsEngine::Fatal: 00040 Errors.push_back(std::make_pair(Info.getLocation(), Buf.str())); 00041 break; 00042 } 00043 } 00044 00045 void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { 00046 // FIXME: Flush the diagnostics in order. 00047 for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it) 00048 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, 00049 it->second.c_str())); 00050 for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it) 00051 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, 00052 it->second.c_str())); 00053 for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it) 00054 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, 00055 it->second.c_str())); 00056 } 00057 00058 DiagnosticConsumer *TextDiagnosticBuffer::clone(DiagnosticsEngine &) const { 00059 return new TextDiagnosticBuffer(); 00060 }