Ted Kremenek | 14f1457 | 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" |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 15 | #include <sstream> |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 16 | |
| 17 | using namespace clang; |
| 18 | |
| 19 | PathDiagnostic::~PathDiagnostic() { |
| 20 | for (iterator I = begin(), E = end(); I != E; ++I) delete &*I; |
| 21 | } |
| 22 | |
Chris Lattner | 6948ae6 | 2008-11-18 07:04:44 +0000 | [diff] [blame^] | 23 | void PathDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel, |
| 24 | const DiagnosticInfo &Info) { |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 25 | |
| 26 | // Create a PathDiagnostic with a single piece. |
| 27 | |
Ted Kremenek | f309cf9 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 28 | PathDiagnostic* D = new PathDiagnostic(); |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 29 | |
Chris Lattner | 8c7f00f | 2008-11-18 04:44:58 +0000 | [diff] [blame] | 30 | const char *LevelStr; |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 31 | switch (DiagLevel) { |
Chris Lattner | 8c7f00f | 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; |
| 36 | case Diagnostic::Fatal: LevelStr = "fatal error: "; break; |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 37 | } |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 38 | |
Chris Lattner | 6948ae6 | 2008-11-18 07:04:44 +0000 | [diff] [blame^] | 39 | std::string Msg = FormatDiagnostic(Info); |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 40 | |
Chris Lattner | 6948ae6 | 2008-11-18 07:04:44 +0000 | [diff] [blame^] | 41 | PathDiagnosticPiece *P = |
| 42 | new PathDiagnosticPiece(Info.getLocation(), LevelStr+Msg); |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 43 | |
Chris Lattner | 6948ae6 | 2008-11-18 07:04:44 +0000 | [diff] [blame^] | 44 | for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i) |
| 45 | P->addRange(Info.getRange(i)); |
Ted Kremenek | f309cf9 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 46 | D->push_front(P); |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 47 | |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 48 | HandlePathDiagnostic(D); |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 49 | } |