Ted Kremenek | d3abcdf | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 1 | //===--- PathDiagnostic.cpp - Path-Specific Diagnostic Handling -*- C++ -*-===// |
| 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 file defines the PathDiagnostic-related interfaces. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Analysis/PathDiagnostic.h" |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallString.h" |
Ted Kremenek | 120187d | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 16 | #include <sstream> |
Ted Kremenek | d3abcdf | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
| 19 | PathDiagnostic::~PathDiagnostic() { |
| 20 | for (iterator I = begin(), E = end(); I != E; ++I) delete &*I; |
| 21 | } |
| 22 | |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 23 | void PathDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel, |
| 24 | const DiagnosticInfo &Info) { |
Ted Kremenek | d3abcdf | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 25 | |
| 26 | // Create a PathDiagnostic with a single piece. |
| 27 | |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 28 | PathDiagnostic* D = new PathDiagnostic(); |
Ted Kremenek | d3abcdf | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 29 | |
Chris Lattner | e837f93 | 2008-11-18 04:44:58 +0000 | [diff] [blame] | 30 | const char *LevelStr; |
Ted Kremenek | 120187d | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 31 | switch (DiagLevel) { |
Chris Lattner | e837f93 | 2008-11-18 04:44:58 +0000 | [diff] [blame] | 32 | default: assert(0 && "Unknown diagnostic type!"); |
| 33 | case Diagnostic::Note: LevelStr = "note: "; break; |
| 34 | case Diagnostic::Warning: LevelStr = "warning: "; break; |
| 35 | case Diagnostic::Error: LevelStr = "error: "; break; |
Ted Kremenek | d3abcdf | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 36 | } |
Ted Kremenek | 120187d | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 37 | |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 38 | llvm::SmallString<100> StrC; |
| 39 | StrC += LevelStr; |
| 40 | Info.FormatDiagnostic(StrC); |
Ted Kremenek | 120187d | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 41 | |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 42 | PathDiagnosticPiece *P = |
Chris Lattner | f4c8396 | 2008-11-19 06:51:40 +0000 | [diff] [blame] | 43 | new PathDiagnosticPiece(Info.getLocation(), |
| 44 | std::string(StrC.begin(), StrC.end())); |
Ted Kremenek | 120187d | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 45 | |
Chris Lattner | 0a14eee | 2008-11-18 07:04:44 +0000 | [diff] [blame] | 46 | for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i) |
| 47 | P->addRange(Info.getRange(i)); |
Ted Kremenek | 5585114 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 48 | D->push_front(P); |
Ted Kremenek | d3abcdf | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 49 | |
Ted Kremenek | 120187d | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 50 | HandlePathDiagnostic(D); |
Ted Kremenek | d3abcdf | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 51 | } |