clang: include/clang/StaticAnalyzer/Core/PathSensitive/SValVisitor.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALVISITOR_H

15#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SVALVISITOR_H

16

20

22

23namespace ento {

24

25

26

27template <typename ImplClass, typename RetTy = void> class SValVisitor {

28 ImplClass &derived() { return *static_cast<ImplClass *>(this); }

29

30public:

32

33 switch (V.getKind()) {

34#define BASIC_SVAL(Id, Parent) \

35 case SVal::Id##Kind: \

36 return derived().Visit##Id(V.castAs());

37#define LOC_SVAL(Id, Parent) \

38 case SVal::Loc##Id##Kind: \

39 return derived().Visit##Id(V.castAsloc::Id());

40#define NONLOC_SVAL(Id, Parent) \

41 case SVal::NonLoc##Id##Kind: \

42 return derived().Visit##Id(V.castAsnonloc::Id());

43#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"

44 }

45 llvm_unreachable("Unknown SVal kind!");

46 }

47

48

49#define BASIC_SVAL(Id, Parent) \

50 RetTy Visit##Id(Id V) { return derived().Visit##Parent(V.castAs()); }

51#define ABSTRACT_SVAL(Id, Parent) BASIC_SVAL(Id, Parent)

52#define LOC_SVAL(Id, Parent) \

53 RetTy Visit##Id(loc::Id V) { return derived().VisitLoc(V.castAs()); }

54#define NONLOC_SVAL(Id, Parent) \

55 RetTy Visit##Id(nonloc::Id V) { \

56 return derived().VisitNonLoc(V.castAs()); \

57 }

58#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.def"

59

60

62};

63

64

65

66template <typename ImplClass, typename RetTy = void> class SymExprVisitor {

67public:

68

69#define DISPATCH(CLASS) \

70 return static_cast<ImplClass *>(this)->Visit ## CLASS(cast(S))

71

73

74 switch (S->getKind()) {

75#define SYMBOL(Id, Parent) \

76 case SymExpr::Id ## Kind: DISPATCH(Id);

77#include "clang/StaticAnalyzer/Core/PathSensitive/Symbols.def"

78 }

79 llvm_unreachable("Unknown SymExpr kind!");

80 }

81

82

83

84#define SYMBOL(Id, Parent) RetTy Visit ## Id(const Id *S) { DISPATCH(Parent); }

85#define ABSTRACT_SYMBOL(Id, Parent) SYMBOL(Id, Parent)

86#include "clang/StaticAnalyzer/Core/PathSensitive/Symbols.def"

87

88

90

91#undef DISPATCH

92};

93

94

95

96template <typename ImplClass, typename RetTy = void> class MemRegionVisitor {

97public:

98

99#define DISPATCH(CLASS) \

100 return static_cast<ImplClass *>(this)->Visit ## CLASS(cast(R))

101

103

105#define REGION(Id, Parent) case MemRegion::Id ## Kind: DISPATCH(Id);

106#include "clang/StaticAnalyzer/Core/PathSensitive/Regions.def"

107 }

108 llvm_unreachable("Unknown MemRegion kind!");

109 }

110

111

112

113#define REGION(Id, Parent) \

114 RetTy Visit ## Id(const Id *R) { DISPATCH(Parent); }

115#define ABSTRACT_REGION(Id, Parent) \

116 REGION(Id, Parent)

117#include "clang/StaticAnalyzer/Core/PathSensitive/Regions.def"

118

119

121

122#undef DISPATCH

123};

124

125

126

127template <typename ImplClass, typename RetTy = void>

131public:

135};

136

137}

138

139}

140

141#endif

FullSValVisitor - a convenient mixed visitor for all three: SVal, SymExpr and MemRegion subclasses.

MemRegionVisitor - this class implements a simple visitor for MemRegion subclasses.

RetTy Visit(const MemRegion *R)

RetTy VisitMemRegion(const MemRegion *R)

MemRegion - The root abstract class for all memory regions.

SValVisitor - this class implements a simple visitor for SVal subclasses.

SVal - This represents a symbolic expression, which can be either an L-value or an R-value.

SymExprVisitor - this class implements a simple visitor for SymExpr subclasses.

RetTy VisitSymExpr(SymbolRef S)

The JSON file list parser is used to communicate input to InstallAPI.