]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/lib/StaticAnalyzer/Core/TextPathDiagnostics.cpp
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / tools / clang / lib / StaticAnalyzer / Core / TextPathDiagnostics.cpp
1 //===--- TextPathDiagnostics.cpp - Text Diagnostics for Paths ---*- 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 TextPathDiagnostics object.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
15 #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
16 #include "clang/Lex/Preprocessor.h"
17 #include "llvm/Support/raw_ostream.h"
18 using namespace clang;
19 using namespace ento;
20 using namespace llvm;
21
22 namespace {
23
24 /// \brief Simple path diagnostic client used for outputting as diagnostic notes
25 /// the sequence of events.
26 class TextPathDiagnostics : public PathDiagnosticConsumer {
27   const std::string OutputFile;
28   DiagnosticsEngine &Diag;
29
30 public:
31   TextPathDiagnostics(const std::string& output, DiagnosticsEngine &diag)
32     : OutputFile(output), Diag(diag) {}
33
34   void HandlePathDiagnosticImpl(const PathDiagnostic* D);
35
36   void FlushDiagnostics(SmallVectorImpl<std::string> *FilesMade) { }
37   
38   virtual StringRef getName() const {
39     return "TextPathDiagnostics";
40   }
41
42   PathGenerationScheme getGenerationScheme() const { return Minimal; }
43   bool supportsLogicalOpControlFlow() const { return true; }
44   bool supportsAllBlockEdges() const { return true; }
45   virtual bool useVerboseDescription() const { return true; }
46 };
47
48 } // end anonymous namespace
49
50 PathDiagnosticConsumer*
51 ento::createTextPathDiagnosticConsumer(const std::string& out,
52                                      const Preprocessor &PP) {
53   return new TextPathDiagnostics(out, PP.getDiagnostics());
54 }
55
56 void TextPathDiagnostics::HandlePathDiagnosticImpl(const PathDiagnostic* D) {
57   if (!D)
58     return;
59
60   if (D->empty()) {
61     delete D;
62     return;
63   }
64
65   for (PathDiagnostic::const_iterator I=D->begin(), E=D->end(); I != E; ++I) {
66     unsigned diagID = Diag.getDiagnosticIDs()->getCustomDiagID(
67                                            DiagnosticIDs::Note, I->getString());
68     Diag.Report(I->getLocation().asLocation(), diagID);
69   }
70 }