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