[analyzer] Move the files in lib/StaticAnalyzer to lib/StaticAnalyzer/Core.
[clang.git] / lib / StaticAnalyzer / Core / TextPathDiagnostics.cpp
blob9ca378f2d410a0c28926f7fc71d28fe03c4bf518
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.
12 //===----------------------------------------------------------------------===//
14 #include "clang/StaticAnalyzer/PathDiagnosticClients.h"
15 #include "clang/StaticAnalyzer/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;
22 namespace {
24 /// \brief Simple path diagnostic client used for outputting as diagnostic notes
25 /// the sequence of events.
26 class TextPathDiagnostics : public PathDiagnosticClient {
27 const std::string OutputFile;
28 Diagnostic &Diag;
30 public:
31 TextPathDiagnostics(const std::string& output, Diagnostic &diag)
32 : OutputFile(output), Diag(diag) {}
34 void HandlePathDiagnostic(const PathDiagnostic* D);
36 void FlushDiagnostics(llvm::SmallVectorImpl<std::string> *FilesMade) { }
38 virtual llvm::StringRef getName() const {
39 return "TextPathDiagnostics";
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; }
48 } // end anonymous namespace
50 PathDiagnosticClient*
51 ento::createTextPathDiagnosticClient(const std::string& out,
52 const Preprocessor &PP) {
53 return new TextPathDiagnostics(out, PP.getDiagnostics());
56 void TextPathDiagnostics::HandlePathDiagnostic(const PathDiagnostic* D) {
57 if (!D)
58 return;
60 if (D->empty()) {
61 delete D;
62 return;
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);