blob: aed83ea84fb48e1fa9a664747e0a9bac649a79f6 [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
Chris Lattner6948ae62008-11-18 07:04:44 +000023void PathDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
24 const DiagnosticInfo &Info) {
Ted Kremenek14f14572008-03-27 03:49:32 +000025
26 // Create a PathDiagnostic with a single piece.
27
Ted Kremenekf309cf92008-04-22 16:15:03 +000028 PathDiagnostic* D = new PathDiagnostic();
Ted Kremenek14f14572008-03-27 03:49:32 +000029
Chris Lattner8c7f00f2008-11-18 04:44:58 +000030 const char *LevelStr;
Ted Kremenekaa3e5372008-03-27 06:16:40 +000031 switch (DiagLevel) {
Chris Lattner8c7f00f2008-11-18 04:44:58 +000032 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 Kremenek14f14572008-03-27 03:49:32 +000037 }
Ted Kremenekaa3e5372008-03-27 06:16:40 +000038
Chris Lattner6948ae62008-11-18 07:04:44 +000039 std::string Msg = FormatDiagnostic(Info);
Ted Kremenekaa3e5372008-03-27 06:16:40 +000040
Chris Lattner6948ae62008-11-18 07:04:44 +000041 PathDiagnosticPiece *P =
42 new PathDiagnosticPiece(Info.getLocation(), LevelStr+Msg);
Ted Kremenekaa3e5372008-03-27 06:16:40 +000043
Chris Lattner6948ae62008-11-18 07:04:44 +000044 for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i)
45 P->addRange(Info.getRange(i));
Ted Kremenekf309cf92008-04-22 16:15:03 +000046 D->push_front(P);
Ted Kremenek14f14572008-03-27 03:49:32 +000047
Ted Kremenekaa3e5372008-03-27 06:16:40 +000048 HandlePathDiagnostic(D);
Ted Kremenek14f14572008-03-27 03:49:32 +000049}