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::Remark: 00039 Remarks.push_back(std::make_pair(Info.getLocation(), Buf.str())); 00040 break; 00041 case DiagnosticsEngine::Error: 00042 case DiagnosticsEngine::Fatal: 00043 Errors.push_back(std::make_pair(Info.getLocation(), Buf.str())); 00044 break; 00045 } 00046 } 00047 00048 void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const { 00049 // FIXME: Flush the diagnostics in order. 00050 for (const_iterator it = err_begin(), ie = err_end(); it != ie; ++it) 00051 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0")) 00052 << it->second; 00053 for (const_iterator it = warn_begin(), ie = warn_end(); it != ie; ++it) 00054 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Warning, "%0")) 00055 << it->second; 00056 for (const_iterator it = remark_begin(), ie = remark_end(); it != ie; ++it) 00057 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Remark, "%0")) 00058 << it->second; 00059 for (const_iterator it = note_begin(), ie = note_end(); it != ie; ++it) 00060 Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0")) 00061 << it->second; 00062 } 00063