1 //== CheckerVisitor.h - Abstract visitor for checkers ------------*- C++ -*--=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines CheckerVisitor.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_ANALYSIS_CHECKERVISITOR
15 #define LLVM_CLANG_ANALYSIS_CHECKERVISITOR
16 #include "clang/Checker/PathSensitive/Checker.h"
20 //===----------------------------------------------------------------------===//
21 // Checker visitor interface. Used by subclasses of Checker to specify their
22 // own checker visitor logic.
23 //===----------------------------------------------------------------------===//
25 /// CheckerVisitor - This class implements a simple visitor for Stmt subclasses.
26 /// Since Expr derives from Stmt, this also includes support for visiting Exprs.
27 template<typename ImplClass
>
28 class CheckerVisitor
: public Checker
{
30 virtual void _PreVisit(CheckerContext
&C
, const Stmt
*S
) {
34 virtual void _PostVisit(CheckerContext
&C
, const Stmt
*S
) {
38 void PreVisit(CheckerContext
&C
, const Stmt
*S
) {
39 switch (S
->getStmtClass()) {
41 assert(false && "Unsupport statement.");
43 case Stmt::CompoundAssignOperatorClass
:
44 static_cast<ImplClass
*>(this)->PreVisitBinaryOperator(C
,
45 static_cast<const BinaryOperator
*>(S
));
48 #define PREVISIT(NAME, FALLBACK) \
49 case Stmt::NAME ## Class:\
50 static_cast<ImplClass*>(this)->PreVisit ## NAME(C,static_cast<const NAME*>(S));\
52 #include "clang/Checker/PathSensitive/CheckerVisitor.def"
56 void PostVisit(CheckerContext
&C
, const Stmt
*S
) {
57 switch (S
->getStmtClass()) {
59 assert(false && "Unsupport statement.");
61 case Stmt::CompoundAssignOperatorClass
:
62 static_cast<ImplClass
*>(this)->PostVisitBinaryOperator(C
,
63 static_cast<const BinaryOperator
*>(S
));
66 #define POSTVISIT(NAME, FALLBACK) \
67 case Stmt::NAME ## Class:\
68 static_cast<ImplClass*>(this)->\
69 PostVisit ## NAME(C,static_cast<const NAME*>(S));\
71 #include "clang/Checker/PathSensitive/CheckerVisitor.def"
75 void PreVisitGenericCall(CheckerContext
&C
, const CallExpr
*CE
) {
76 static_cast<ImplClass
*>(this)->PreVisitStmt(C
, CE
);
78 void PostVisitGenericCall(CheckerContext
&C
, const CallExpr
*CE
) {
79 static_cast<ImplClass
*>(this)->PostVisitStmt(C
, CE
);
82 void PreVisitStmt(CheckerContext
&C
, const Stmt
*S
) {
83 *C
.respondsToCallback
= false;
86 void PostVisitStmt(CheckerContext
&C
, const Stmt
*S
) {
87 *C
.respondsToCallback
= false;
90 void PreVisitCastExpr(CheckerContext
&C
, const CastExpr
*E
) {
91 static_cast<ImplClass
*>(this)->PreVisitStmt(C
, E
);
94 #define PREVISIT(NAME, FALLBACK) \
95 void PreVisit ## NAME(CheckerContext &C, const NAME* S) {\
96 static_cast<ImplClass*>(this)->PreVisit ## FALLBACK(C, S);\
98 #define POSTVISIT(NAME, FALLBACK) \
99 void PostVisit ## NAME(CheckerContext &C, const NAME* S) {\
100 static_cast<ImplClass*>(this)->PostVisit ## FALLBACK(C, S);\
102 #include "clang/Checker/PathSensitive/CheckerVisitor.def"
105 } // end clang namespace