summaryrefslogtreecommitdiffstats
path: root/include/clang/Analysis/PathSensitive/CheckerVisitor.h
blob: 37ec8def50b35da5f246b0505cebc5f1e4f9738c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//== CheckerVisitor.h - Abstract visitor for checkers ------------*- C++ -*--=//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file defines CheckerVisitor.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_ANALYSIS_CHECKERVISITOR
#define LLVM_CLANG_ANALYSIS_CHECKERVISITOR
#include "clang/Analysis/PathSensitive/Checker.h"

namespace clang {

//===----------------------------------------------------------------------===//
// Checker visitor interface.  Used by subclasses of Checker to specify their
// own checker visitor logic.
//===----------------------------------------------------------------------===//

/// CheckerVisitor - This class implements a simple visitor for Stmt subclasses.
/// Since Expr derives from Stmt, this also includes support for visiting Exprs.
template<typename ImplClass>
class CheckerVisitor : public Checker {
public:
  virtual void _PreVisit(CheckerContext &C, const Stmt *S) {
    PreVisit(C, S);
  }
  
  virtual void _PostVisit(CheckerContext &C, const Stmt *S) {
    PostVisit(C, S);
  }

  void PreVisit(CheckerContext &C, const Stmt *S) {
    switch (S->getStmtClass()) {
      default:
        assert(false && "Unsupport statement.");
        return;

      case Stmt::ImplicitCastExprClass:
      case Stmt::ExplicitCastExprClass:
      case Stmt::CStyleCastExprClass:
        static_cast<ImplClass*>(this)->PreVisitCastExpr(C,
                                               static_cast<const CastExpr*>(S));
        break;

      case Stmt::CompoundAssignOperatorClass:
        static_cast<ImplClass*>(this)->PreVisitBinaryOperator(C,
                                         static_cast<const BinaryOperator*>(S));
        break;

#define PREVISIT(NAME, FALLBACK) \
case Stmt::NAME ## Class:\
static_cast<ImplClass*>(this)->PreVisit ## NAME(C,static_cast<const NAME*>(S));\
break;
#include "clang/Analysis/PathSensitive/CheckerVisitor.def"
    }
  }
  
  void PostVisit(CheckerContext &C, const Stmt *S) {
    switch (S->getStmtClass()) {
      default:
        assert(false && "Unsupport statement.");
        return;
      case Stmt::CompoundAssignOperatorClass:
        static_cast<ImplClass*>(this)->PostVisitBinaryOperator(C,
                                         static_cast<const BinaryOperator*>(S));
        break;

#define POSTVISIT(NAME, FALLBACK) \
case Stmt::NAME ## Class:\
static_cast<ImplClass*>(this)->\
PostVisit ## NAME(C,static_cast<const NAME*>(S));\
break;
#include "clang/Analysis/PathSensitive/CheckerVisitor.def"
    }
  }

  void PreVisitStmt(CheckerContext &C, const Stmt *S) {}
  void PostVisitStmt(CheckerContext &C, const Stmt *S) {}
  
#define PREVISIT(NAME, FALLBACK) \
void PreVisit ## NAME(CheckerContext &C, const NAME* S) {\
  PreVisit ## FALLBACK(C, S);\
}
#include "clang/Analysis/PathSensitive/CheckerVisitor.def"
      
#define POSTVISIT(NAME, FALLBACK) \
void PostVisit ## NAME(CheckerContext &C, const NAME* S) {\
  PostVisit ## FALLBACK(C, S);\
}
#include "clang/Analysis/PathSensitive/CheckerVisitor.def"
};

} // end clang namespace

#endif
OpenPOWER on IntegriCloud