Argyrios Kyrtzidis | ebd4f52 | 2010-12-03 00:58:14 +0000 | [diff] [blame] | 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 | |
Ted Kremenek | 2114258 | 2010-12-23 19:38:26 +0000 | [diff] [blame] | 14 | #include "clang/StaticAnalyzer/PathDiagnosticClients.h" |
| 15 | #include "clang/StaticAnalyzer/BugReporter/PathDiagnostic.h" |
Argyrios Kyrtzidis | ebd4f52 | 2010-12-03 00:58:14 +0000 | [diff] [blame] | 16 | #include "clang/Lex/Preprocessor.h" |
| 17 | #include "llvm/Support/raw_ostream.h" |
| 18 | using namespace clang; |
Ted Kremenek | 9ef6537 | 2010-12-23 07:20:52 +0000 | [diff] [blame] | 19 | using namespace ento; |
Argyrios Kyrtzidis | ebd4f52 | 2010-12-03 00:58:14 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
| 22 | namespace { |
| 23 | |
Argyrios Kyrtzidis | a599ae8 | 2010-12-03 01:17:19 +0000 | [diff] [blame] | 24 | /// \brief Simple path diagnostic client used for outputting as diagnostic notes |
Argyrios Kyrtzidis | ebd4f52 | 2010-12-03 00:58:14 +0000 | [diff] [blame] | 25 | /// the sequence of events. |
| 26 | class TextPathDiagnostics : public PathDiagnosticClient { |
| 27 | const std::string OutputFile; |
| 28 | Diagnostic &Diag; |
| 29 | |
| 30 | public: |
| 31 | TextPathDiagnostics(const std::string& output, Diagnostic &diag) |
| 32 | : OutputFile(output), Diag(diag) {} |
| 33 | |
| 34 | void HandlePathDiagnostic(const PathDiagnostic* D); |
| 35 | |
| 36 | void FlushDiagnostics(llvm::SmallVectorImpl<std::string> *FilesMade) { } |
| 37 | |
| 38 | virtual llvm::StringRef getName() const { |
| 39 | return "TextPathDiagnostics"; |
| 40 | } |
| 41 | |
Argyrios Kyrtzidis | 774dfbb | 2010-12-03 02:03:26 +0000 | [diff] [blame] | 42 | PathGenerationScheme getGenerationScheme() const { return Minimal; } |
Argyrios Kyrtzidis | ebd4f52 | 2010-12-03 00:58:14 +0000 | [diff] [blame] | 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 | PathDiagnosticClient* |
Ted Kremenek | 9ef6537 | 2010-12-23 07:20:52 +0000 | [diff] [blame] | 51 | ento::createTextPathDiagnosticClient(const std::string& out, |
| 52 | const Preprocessor &PP) { |
Argyrios Kyrtzidis | ebd4f52 | 2010-12-03 00:58:14 +0000 | [diff] [blame] | 53 | return new TextPathDiagnostics(out, PP.getDiagnostics()); |
| 54 | } |
| 55 | |
| 56 | void TextPathDiagnostics::HandlePathDiagnostic(const PathDiagnostic* D) { |
| 57 | if (!D) |
| 58 | return; |
| 59 | |
| 60 | if (D->empty()) { |
| 61 | delete D; |
| 62 | return; |
| 63 | } |
| 64 | |
Argyrios Kyrtzidis | ebd4f52 | 2010-12-03 00:58:14 +0000 | [diff] [blame] | 65 | for (PathDiagnostic::const_iterator I=D->begin(), E=D->end(); I != E; ++I) { |
Argyrios Kyrtzidis | 774dfbb | 2010-12-03 02:03:26 +0000 | [diff] [blame] | 66 | unsigned diagID = Diag.getDiagnosticIDs()->getCustomDiagID( |
| 67 | DiagnosticIDs::Note, I->getString()); |
| 68 | Diag.Report(I->getLocation().asLocation(), diagID); |
Argyrios Kyrtzidis | ebd4f52 | 2010-12-03 00:58:14 +0000 | [diff] [blame] | 69 | } |
| 70 | } |