Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 1 | #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 | |
| 8 | namespace slang { |
| 9 | |
| 10 | DiagnosticBuffer::DiagnosticBuffer() : mSOS(NULL) { |
| 11 | mSOS = new llvm::raw_string_ostream(mDiags); |
| 12 | return; |
| 13 | } |
| 14 | |
| 15 | void 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 Stewart | b1b053d | 2010-06-15 16:37:01 -0700 | [diff] [blame] | 19 | if (FSLoc.isValid()) { |
| 20 | FSLoc.print(*mSOS, FSLoc.getManager()); |
| 21 | (*mSOS) << ": "; |
Shih-wei Liao | 462aefd | 2010-06-04 15:32:04 -0700 | [diff] [blame] | 22 | } |
| 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 | |
| 53 | DiagnosticBuffer::~DiagnosticBuffer() { |
| 54 | if(mSOS != NULL) |
| 55 | delete mSOS; |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | } /* namespace slang */ |