blob: 81cd4ec3a74277c532ec6bd6874dbefba0338630 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This is a concrete diagnostic client, which buffers the diagnostic messages.
11//
12//===----------------------------------------------------------------------===//
13
Nico Weberfd54ebc2008-08-05 23:33:20 +000014#include "clang/Driver/TextDiagnosticBuffer.h"
Chris Lattnerf4c83962008-11-19 06:51:40 +000015#include "llvm/ADT/SmallString.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016using namespace clang;
17
Douglas Gregor94b1dd22008-10-24 04:54:22 +000018/// HandleDiagnostic - Store the errors, warnings, and notes that are
19/// reported.
Reid Spencer5f016e22007-07-11 17:01:13 +000020///
Chris Lattner0a14eee2008-11-18 07:04:44 +000021void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic::Level Level,
22 const DiagnosticInfo &Info) {
Chris Lattnerf4c83962008-11-19 06:51:40 +000023 llvm::SmallString<100> StrC;
24 Info.FormatDiagnostic(StrC);
25 std::string Str(StrC.begin(), StrC.end());
Reid Spencer5f016e22007-07-11 17:01:13 +000026 switch (Level) {
27 default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
Douglas Gregor233f74b2008-09-11 02:46:36 +000028 case Diagnostic::Note:
Chris Lattner59ddeab2009-01-16 23:06:35 +000029 Notes.push_back(std::make_pair(Info.getLocation(), Str));
Douglas Gregor233f74b2008-09-11 02:46:36 +000030 break;
Reid Spencer5f016e22007-07-11 17:01:13 +000031 case Diagnostic::Warning:
Chris Lattner59ddeab2009-01-16 23:06:35 +000032 Warnings.push_back(std::make_pair(Info.getLocation(), Str));
Reid Spencer5f016e22007-07-11 17:01:13 +000033 break;
34 case Diagnostic::Error:
Ben Laurie64ea69f2009-02-17 17:32:22 +000035 case Diagnostic::Fatal:
Chris Lattner59ddeab2009-01-16 23:06:35 +000036 Errors.push_back(std::make_pair(Info.getLocation(), Str));
Reid Spencer5f016e22007-07-11 17:01:13 +000037 break;
38 }
39}