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 | |
| 23 | void PathDiagnosticClient::HandleDiagnostic(Diagnostic &Diags, |
| 24 | Diagnostic::Level DiagLevel, |
| 25 | FullSourceLoc Pos, |
| 26 | diag::kind ID, |
| 27 | const std::string *Strs, |
| 28 | unsigned NumStrs, |
| 29 | const SourceRange *Ranges, |
| 30 | unsigned NumRanges) { |
| 31 | |
| 32 | // Create a PathDiagnostic with a single piece. |
| 33 | |
Ted Kremenek | f309cf9 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 34 | PathDiagnostic* D = new PathDiagnostic(); |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 35 | |
Chris Lattner | 8c7f00f | 2008-11-18 04:44:58 +0000 | [diff] [blame] | 36 | const char *LevelStr; |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 37 | switch (DiagLevel) { |
Chris Lattner | 8c7f00f | 2008-11-18 04:44:58 +0000 | [diff] [blame] | 38 | default: assert(0 && "Unknown diagnostic type!"); |
| 39 | case Diagnostic::Note: LevelStr = "note: "; break; |
| 40 | case Diagnostic::Warning: LevelStr = "warning: "; break; |
| 41 | case Diagnostic::Error: LevelStr = "error: "; break; |
| 42 | case Diagnostic::Fatal: LevelStr = "fatal error: "; break; |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 43 | } |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 44 | |
Nico Weber | d2a6ac9 | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 45 | std::string Msg = FormatDiagnostic(Diags, DiagLevel, ID, Strs, NumStrs); |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 46 | |
Chris Lattner | 8c7f00f | 2008-11-18 04:44:58 +0000 | [diff] [blame] | 47 | PathDiagnosticPiece* P = new PathDiagnosticPiece(Pos, LevelStr+Msg); |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 48 | |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 49 | while (NumRanges) { |
| 50 | P->addRange(*Ranges); |
| 51 | --NumRanges; |
| 52 | ++Ranges; |
| 53 | } |
| 54 | |
Ted Kremenek | f309cf9 | 2008-04-22 16:15:03 +0000 | [diff] [blame] | 55 | D->push_front(P); |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 56 | |
Ted Kremenek | aa3e537 | 2008-03-27 06:16:40 +0000 | [diff] [blame] | 57 | HandlePathDiagnostic(D); |
Ted Kremenek | 14f1457 | 2008-03-27 03:49:32 +0000 | [diff] [blame] | 58 | } |