TextDiagnosticBuffer.cpp revision 1eb4433ac451dc16f4133a88af2d002ac26c58ef
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> StrC;
24  Info.FormatDiagnostic(StrC);
25  std::string Str(StrC.begin(), StrC.end());
26  switch (Level) {
27  default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
28  case Diagnostic::Note:
29    Notes.push_back(std::make_pair(Info.getLocation(), Str));
30    break;
31  case Diagnostic::Warning:
32    Warnings.push_back(std::make_pair(Info.getLocation(), Str));
33    break;
34  case Diagnostic::Error:
35  case Diagnostic::Fatal:
36    Errors.push_back(std::make_pair(Info.getLocation(), Str));
37    break;
38  }
39}
40