TextDiagnosticBuffer.cpp revision 4bd2e145168bf379f6753b2de7d8ffa562198599
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"
16using namespace clang;
17
18/// HandleDiagnostic - Store the errors, warnings, and notes that are
19/// reported.
20///
21void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic::Level Level,
22                                            const DiagnosticInfo &Info) {
23  llvm::SmallString<100> Buf;
24  Info.FormatDiagnostic(Buf);
25  switch (Level) {
26  default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
27  case Diagnostic::Note:
28    Notes.push_back(std::make_pair(Info.getLocation(), Buf.str()));
29    break;
30  case Diagnostic::Warning:
31    Warnings.push_back(std::make_pair(Info.getLocation(), Buf.str()));
32    break;
33  case Diagnostic::Error:
34  case Diagnostic::Fatal:
35    Errors.push_back(std::make_pair(Info.getLocation(), Buf.str()));
36    break;
37  }
38}
39