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