SimpleConstraintManager.h revision 8bef8238181a30e52dea380789a7e2d760eac532
1//== SimpleConstraintManager.h ----------------------------------*- 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//  Code shared between BasicConstraintManager and RangeConstraintManager.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_GR_SIMPLE_CONSTRAINT_MANAGER_H
15#define LLVM_CLANG_GR_SIMPLE_CONSTRAINT_MANAGER_H
16
17#include "clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h"
18#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
19
20namespace clang {
21
22namespace ento {
23
24class SimpleConstraintManager : public ConstraintManager {
25  SubEngine &SU;
26public:
27  SimpleConstraintManager(SubEngine &subengine) : SU(subengine) {}
28  virtual ~SimpleConstraintManager();
29
30  //===------------------------------------------------------------------===//
31  // Common implementation for the interface provided by ConstraintManager.
32  //===------------------------------------------------------------------===//
33
34  ProgramStateRef assume(ProgramStateRef state, DefinedSVal Cond,
35                        bool Assumption);
36
37  ProgramStateRef assume(ProgramStateRef state, Loc Cond, bool Assumption);
38
39  ProgramStateRef assume(ProgramStateRef state, NonLoc Cond, bool Assumption);
40
41  ProgramStateRef assumeSymRel(ProgramStateRef state,
42                              const SymExpr *LHS,
43                              BinaryOperator::Opcode op,
44                              const llvm::APSInt& Int);
45
46protected:
47
48  //===------------------------------------------------------------------===//
49  // Interface that subclasses must implement.
50  //===------------------------------------------------------------------===//
51
52  // Each of these is of the form "$sym+Adj <> V", where "<>" is the comparison
53  // operation for the method being invoked.
54  virtual ProgramStateRef assumeSymNE(ProgramStateRef state, SymbolRef sym,
55                                     const llvm::APSInt& V,
56                                     const llvm::APSInt& Adjustment) = 0;
57
58  virtual ProgramStateRef assumeSymEQ(ProgramStateRef state, SymbolRef sym,
59                                     const llvm::APSInt& V,
60                                     const llvm::APSInt& Adjustment) = 0;
61
62  virtual ProgramStateRef assumeSymLT(ProgramStateRef state, SymbolRef sym,
63                                     const llvm::APSInt& V,
64                                     const llvm::APSInt& Adjustment) = 0;
65
66  virtual ProgramStateRef assumeSymGT(ProgramStateRef state, SymbolRef sym,
67                                     const llvm::APSInt& V,
68                                     const llvm::APSInt& Adjustment) = 0;
69
70  virtual ProgramStateRef assumeSymLE(ProgramStateRef state, SymbolRef sym,
71                                     const llvm::APSInt& V,
72                                     const llvm::APSInt& Adjustment) = 0;
73
74  virtual ProgramStateRef assumeSymGE(ProgramStateRef state, SymbolRef sym,
75                                     const llvm::APSInt& V,
76                                     const llvm::APSInt& Adjustment) = 0;
77
78  //===------------------------------------------------------------------===//
79  // Internal implementation.
80  //===------------------------------------------------------------------===//
81
82  bool canReasonAbout(SVal X) const;
83
84  ProgramStateRef assumeAux(ProgramStateRef state,
85                                Loc Cond,
86                                bool Assumption);
87
88  ProgramStateRef assumeAux(ProgramStateRef state,
89                                NonLoc Cond,
90                                bool Assumption);
91
92  ProgramStateRef assumeAuxForSymbol(ProgramStateRef State,
93                                         SymbolRef Sym,
94                                         bool Assumption);
95};
96
97} // end GR namespace
98
99} // end clang namespace
100
101#endif
102