blob: 45057e64f31fe931a0343a22798dfee510cf0fbc [file] [log] [blame]
Ted Kremenek45021952009-02-14 17:08:39 +00001//== 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_ANALYSIS_SIMPLE_CONSTRAINT_MANAGER_H
15#define LLVM_CLANG_ANALYSIS_SIMPLE_CONSTRAINT_MANAGER_H
16
Ted Kremenek1309f9a2010-01-25 04:41:41 +000017#include "clang/Checker/PathSensitive/ConstraintManager.h"
18#include "clang/Checker/PathSensitive/GRState.h"
Ted Kremenek45021952009-02-14 17:08:39 +000019
20namespace clang {
21
22class SimpleConstraintManager : public ConstraintManager {
Ted Kremenek32a58082010-01-05 00:15:18 +000023 GRSubEngine &SU;
Ted Kremenek45021952009-02-14 17:08:39 +000024public:
Ted Kremenek32a58082010-01-05 00:15:18 +000025 SimpleConstraintManager(GRSubEngine &subengine) : SU(subengine) {}
Mike Stump1eb44332009-09-09 15:08:12 +000026 virtual ~SimpleConstraintManager();
27
Ted Kremeneka591bc02009-06-18 22:57:13 +000028 //===------------------------------------------------------------------===//
29 // Common implementation for the interface provided by ConstraintManager.
30 //===------------------------------------------------------------------===//
Ted Kremenekf1b82272009-06-18 23:20:05 +000031
32 bool canReasonAbout(SVal X) const;
33
Ted Kremenek5b9bd212009-09-11 22:07:28 +000034 const GRState *Assume(const GRState *state, DefinedSVal Cond,
35 bool Assumption);
Ted Kremenekf1b82272009-06-18 23:20:05 +000036
Ted Kremeneka591bc02009-06-18 22:57:13 +000037 const GRState *Assume(const GRState *state, Loc Cond, bool Assumption);
Ted Kremenek45021952009-02-14 17:08:39 +000038
Ted Kremeneka591bc02009-06-18 22:57:13 +000039 const GRState *Assume(const GRState *state, NonLoc Cond, bool Assumption);
Ted Kremenek45021952009-02-14 17:08:39 +000040
Jordy Roseba0f61c2010-06-18 22:49:11 +000041 const GRState *AssumeSymRel(const GRState *state,
42 const SymExpr *LHS,
43 BinaryOperator::Opcode op,
44 const llvm::APSInt& Int);
Mike Stump1eb44332009-09-09 15:08:12 +000045
Ted Kremenek5b9bd212009-09-11 22:07:28 +000046 const GRState *AssumeInBound(const GRState *state, DefinedSVal Idx,
47 DefinedSVal UpperBound,
Ted Kremeneka591bc02009-06-18 22:57:13 +000048 bool Assumption);
Mike Stump1eb44332009-09-09 15:08:12 +000049
Ted Kremeneka591bc02009-06-18 22:57:13 +000050protected:
Mike Stump1eb44332009-09-09 15:08:12 +000051
Ted Kremeneka591bc02009-06-18 22:57:13 +000052 //===------------------------------------------------------------------===//
53 // Interface that subclasses must implement.
54 //===------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +000055
Jordy Roseba0f61c2010-06-18 22:49:11 +000056 // Each of these is of the form "$sym+Adj <> V", where "<>" is the comparison
57 // operation for the method being invoked.
Ted Kremeneka591bc02009-06-18 22:57:13 +000058 virtual const GRState *AssumeSymNE(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000059 const llvm::APSInt& V,
60 const llvm::APSInt& Adjustment) = 0;
Ted Kremenek45021952009-02-14 17:08:39 +000061
Ted Kremeneka591bc02009-06-18 22:57:13 +000062 virtual const GRState *AssumeSymEQ(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000063 const llvm::APSInt& V,
64 const llvm::APSInt& Adjustment) = 0;
Ted Kremenek45021952009-02-14 17:08:39 +000065
Ted Kremeneka591bc02009-06-18 22:57:13 +000066 virtual const GRState *AssumeSymLT(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000067 const llvm::APSInt& V,
68 const llvm::APSInt& Adjustment) = 0;
Ted Kremenek45021952009-02-14 17:08:39 +000069
Ted Kremeneka591bc02009-06-18 22:57:13 +000070 virtual const GRState *AssumeSymGT(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000071 const llvm::APSInt& V,
72 const llvm::APSInt& Adjustment) = 0;
Ted Kremenek45021952009-02-14 17:08:39 +000073
Ted Kremeneka591bc02009-06-18 22:57:13 +000074 virtual const GRState *AssumeSymLE(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000075 const llvm::APSInt& V,
76 const llvm::APSInt& Adjustment) = 0;
Ted Kremenek45021952009-02-14 17:08:39 +000077
Ted Kremeneka591bc02009-06-18 22:57:13 +000078 virtual const GRState *AssumeSymGE(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000079 const llvm::APSInt& V,
80 const llvm::APSInt& Adjustment) = 0;
Mike Stump1eb44332009-09-09 15:08:12 +000081
Ted Kremeneka591bc02009-06-18 22:57:13 +000082 //===------------------------------------------------------------------===//
83 // Internal implementation.
84 //===------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +000085
Ted Kremeneka591bc02009-06-18 22:57:13 +000086 const GRState *AssumeAux(const GRState *state, Loc Cond,bool Assumption);
Mike Stump1eb44332009-09-09 15:08:12 +000087
Ted Kremeneka591bc02009-06-18 22:57:13 +000088 const GRState *AssumeAux(const GRState *state, NonLoc Cond, bool Assumption);
Ted Kremenek45021952009-02-14 17:08:39 +000089};
90
91} // end clang namespace
92
Ted Kremenek669c0e12009-02-15 18:24:51 +000093#endif