blob: b30ab5d66fff5edf92b047d28723cee39455e581 [file] [log] [blame]
Shih-wei Liao462aefd2010-06-04 15:32:04 -07001#include "slang_diagnostic_buffer.hpp"
2
3#include "llvm/ADT/SmallString.h" /* for llvm::SmallString */
4
5#include "clang/Basic/SourceManager.h" /* for class clang::SourceManager */
6#include "clang/Basic/SourceLocation.h" /* for class clang::SourceLocation, class clang::FullSourceLoc and class clang::PresumedLoc */
7
8namespace slang {
9
10DiagnosticBuffer::DiagnosticBuffer() : mSOS(NULL) {
11 mSOS = new llvm::raw_string_ostream(mDiags);
12 return;
13}
14
15void DiagnosticBuffer::HandleDiagnostic(Diagnostic::Level DiagLevel, const DiagnosticInfo &Info) {
16 const FullSourceLoc& FSLoc = Info.getLocation();
17 llvm::SmallString<100> Buf; /* 100 is enough for storing general diagnosis message */
18
Kirk Stewartb1b053d2010-06-15 16:37:01 -070019 if (FSLoc.isValid()) {
20 FSLoc.print(*mSOS, FSLoc.getManager());
21 (*mSOS) << ": ";
Shih-wei Liao462aefd2010-06-04 15:32:04 -070022 }
23
24 switch(DiagLevel) {
25 case Diagnostic::Note:
26 (*mSOS) << "note: ";
27 break;
28
29 case Diagnostic::Warning:
30 (*mSOS) << "warning: ";
31 break;
32
33 case Diagnostic::Error:
34 (*mSOS) << "error: ";
35 break;
36
37 case Diagnostic::Fatal:
38 (*mSOS) << "fatal: ";
39 break;
40
41 default:
42 assert(0 && "Diagnostic not handled during diagnostic buffering!");
43 break;
44 }
45
46
47 Info.FormatDiagnostic(Buf);
48 (*mSOS) << Buf.str() << '\n';
49
50 return;
51}
52
53DiagnosticBuffer::~DiagnosticBuffer() {
54 if(mSOS != NULL)
55 delete mSOS;
56 return;
57}
58
59} /* namespace slang */