blob: 971e751b8dc3539712f5c9628ccd93bce21b69e3 [file] [log] [blame]
Ted Kremenek14f14572008-03-27 03:49:32 +00001//===--- 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 Kremenekaa3e5372008-03-27 06:16:40 +000015#include <sstream>
Ted Kremenek14f14572008-03-27 03:49:32 +000016
17using namespace clang;
18
19PathDiagnostic::~PathDiagnostic() {
20 for (iterator I = begin(), E = end(); I != E; ++I) delete &*I;
21}
22
23void 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 Kremenekf309cf92008-04-22 16:15:03 +000034 PathDiagnostic* D = new PathDiagnostic();
Ted Kremenek14f14572008-03-27 03:49:32 +000035
Chris Lattner8c7f00f2008-11-18 04:44:58 +000036 const char *LevelStr;
Ted Kremenekaa3e5372008-03-27 06:16:40 +000037 switch (DiagLevel) {
Chris Lattner8c7f00f2008-11-18 04:44:58 +000038 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 Kremenek14f14572008-03-27 03:49:32 +000043 }
Ted Kremenekaa3e5372008-03-27 06:16:40 +000044
Nico Weberd2a6ac92008-08-10 19:59:06 +000045 std::string Msg = FormatDiagnostic(Diags, DiagLevel, ID, Strs, NumStrs);
Ted Kremenekaa3e5372008-03-27 06:16:40 +000046
Chris Lattner8c7f00f2008-11-18 04:44:58 +000047 PathDiagnosticPiece* P = new PathDiagnosticPiece(Pos, LevelStr+Msg);
Ted Kremenekaa3e5372008-03-27 06:16:40 +000048
Ted Kremenek14f14572008-03-27 03:49:32 +000049 while (NumRanges) {
50 P->addRange(*Ranges);
51 --NumRanges;
52 ++Ranges;
53 }
54
Ted Kremenekf309cf92008-04-22 16:15:03 +000055 D->push_front(P);
Ted Kremenek14f14572008-03-27 03:49:32 +000056
Ted Kremenekaa3e5372008-03-27 06:16:40 +000057 HandlePathDiagnostic(D);
Ted Kremenek14f14572008-03-27 03:49:32 +000058}