]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.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 / Checkers / DebugCheckers.cpp
1 //==- DebugCheckers.cpp - Debugging Checkers ---------------------*- 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 a checkers that display debugging information.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ClangSACheckers.h"
15 #include "clang/StaticAnalyzer/Core/Checker.h"
16 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
17 #include "clang/Analysis/Analyses/LiveVariables.h"
18
19 using namespace clang;
20 using namespace ento;
21
22 //===----------------------------------------------------------------------===//
23 // LiveVariablesDumper
24 //===----------------------------------------------------------------------===//
25
26 namespace {
27 class LiveVariablesDumper : public Checker<check::ASTCodeBody> {
28 public:
29   void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
30                         BugReporter &BR) const {
31     if (LiveVariables* L = mgr.getAnalysis<LiveVariables>(D)) {
32       L->dumpBlockLiveness(mgr.getSourceManager());
33     }
34   }
35 };
36 }
37
38 void ento::registerLiveVariablesDumper(CheckerManager &mgr) {
39   mgr.registerChecker<LiveVariablesDumper>();
40 }
41
42 //===----------------------------------------------------------------------===//
43 // CFGViewer
44 //===----------------------------------------------------------------------===//
45
46 namespace {
47 class CFGViewer : public Checker<check::ASTCodeBody> {
48 public:
49   void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
50                         BugReporter &BR) const {
51     if (CFG *cfg = mgr.getCFG(D)) {
52       cfg->viewCFG(mgr.getLangOptions());
53     }
54   }
55 };
56 }
57
58 void ento::registerCFGViewer(CheckerManager &mgr) {
59   mgr.registerChecker<CFGViewer>();
60 }
61
62 //===----------------------------------------------------------------------===//
63 // CFGDumper
64 //===----------------------------------------------------------------------===//
65
66 namespace {
67 class CFGDumper : public Checker<check::ASTCodeBody> {
68 public:
69   void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
70                         BugReporter &BR) const {
71     if (CFG *cfg = mgr.getCFG(D)) {
72       cfg->dump(mgr.getLangOptions());
73     }
74   }
75 };
76 }
77
78 void ento::registerCFGDumper(CheckerManager &mgr) {
79   mgr.registerChecker<CFGDumper>();
80 }