blob: 442f0ca9f7cab5b0349e1609e150c988f64918ae [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
Argyrios Kyrtzidis5a4f98f2010-12-22 18:53:20 +000014#ifndef LLVM_CLANG_GR_SIMPLE_CONSTRAINT_MANAGER_H
15#define LLVM_CLANG_GR_SIMPLE_CONSTRAINT_MANAGER_H
Ted Kremenek45021952009-02-14 17:08:39 +000016
Argyrios Kyrtzidis98cabba2010-12-22 18:51:49 +000017#include "clang/GR/PathSensitive/ConstraintManager.h"
18#include "clang/GR/PathSensitive/GRState.h"
Ted Kremenek45021952009-02-14 17:08:39 +000019
20namespace clang {
21
Argyrios Kyrtzidis5a4f98f2010-12-22 18:53:20 +000022namespace GR {
23
Ted Kremenek45021952009-02-14 17:08:39 +000024class SimpleConstraintManager : public ConstraintManager {
Ted Kremenek32a58082010-01-05 00:15:18 +000025 GRSubEngine &SU;
Ted Kremenek45021952009-02-14 17:08:39 +000026public:
Ted Kremenek32a58082010-01-05 00:15:18 +000027 SimpleConstraintManager(GRSubEngine &subengine) : SU(subengine) {}
Mike Stump1eb44332009-09-09 15:08:12 +000028 virtual ~SimpleConstraintManager();
29
Ted Kremeneka591bc02009-06-18 22:57:13 +000030 //===------------------------------------------------------------------===//
31 // Common implementation for the interface provided by ConstraintManager.
32 //===------------------------------------------------------------------===//
Ted Kremenekf1b82272009-06-18 23:20:05 +000033
34 bool canReasonAbout(SVal X) const;
35
Ted Kremenek28f47b92010-12-01 22:16:56 +000036 const GRState *assume(const GRState *state, DefinedSVal Cond,
Ted Kremenek5b9bd212009-09-11 22:07:28 +000037 bool Assumption);
Ted Kremenekf1b82272009-06-18 23:20:05 +000038
Ted Kremenek28f47b92010-12-01 22:16:56 +000039 const GRState *assume(const GRState *state, Loc Cond, bool Assumption);
Ted Kremenek45021952009-02-14 17:08:39 +000040
Ted Kremenek28f47b92010-12-01 22:16:56 +000041 const GRState *assume(const GRState *state, NonLoc Cond, bool Assumption);
Ted Kremenek45021952009-02-14 17:08:39 +000042
Ted Kremenek28f47b92010-12-01 22:16:56 +000043 const GRState *assumeSymRel(const GRState *state,
Jordy Roseba0f61c2010-06-18 22:49:11 +000044 const SymExpr *LHS,
45 BinaryOperator::Opcode op,
46 const llvm::APSInt& Int);
Mike Stump1eb44332009-09-09 15:08:12 +000047
Ted Kremeneka591bc02009-06-18 22:57:13 +000048protected:
Mike Stump1eb44332009-09-09 15:08:12 +000049
Ted Kremeneka591bc02009-06-18 22:57:13 +000050 //===------------------------------------------------------------------===//
51 // Interface that subclasses must implement.
52 //===------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +000053
Jordy Roseba0f61c2010-06-18 22:49:11 +000054 // Each of these is of the form "$sym+Adj <> V", where "<>" is the comparison
55 // operation for the method being invoked.
Ted Kremenek28f47b92010-12-01 22:16:56 +000056 virtual const GRState *assumeSymNE(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000057 const llvm::APSInt& V,
58 const llvm::APSInt& Adjustment) = 0;
Ted Kremenek45021952009-02-14 17:08:39 +000059
Ted Kremenek28f47b92010-12-01 22:16:56 +000060 virtual const GRState *assumeSymEQ(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000061 const llvm::APSInt& V,
62 const llvm::APSInt& Adjustment) = 0;
Ted Kremenek45021952009-02-14 17:08:39 +000063
Ted Kremenek28f47b92010-12-01 22:16:56 +000064 virtual const GRState *assumeSymLT(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000065 const llvm::APSInt& V,
66 const llvm::APSInt& Adjustment) = 0;
Ted Kremenek45021952009-02-14 17:08:39 +000067
Ted Kremenek28f47b92010-12-01 22:16:56 +000068 virtual const GRState *assumeSymGT(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000069 const llvm::APSInt& V,
70 const llvm::APSInt& Adjustment) = 0;
Ted Kremenek45021952009-02-14 17:08:39 +000071
Ted Kremenek28f47b92010-12-01 22:16:56 +000072 virtual const GRState *assumeSymLE(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000073 const llvm::APSInt& V,
74 const llvm::APSInt& Adjustment) = 0;
Ted Kremenek45021952009-02-14 17:08:39 +000075
Ted Kremenek28f47b92010-12-01 22:16:56 +000076 virtual const GRState *assumeSymGE(const GRState *state, SymbolRef sym,
Jordy Roseba0f61c2010-06-18 22:49:11 +000077 const llvm::APSInt& V,
78 const llvm::APSInt& Adjustment) = 0;
Mike Stump1eb44332009-09-09 15:08:12 +000079
Ted Kremeneka591bc02009-06-18 22:57:13 +000080 //===------------------------------------------------------------------===//
81 // Internal implementation.
82 //===------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +000083
Ted Kremenek28f47b92010-12-01 22:16:56 +000084 const GRState *assumeAux(const GRState *state, Loc Cond,bool Assumption);
Mike Stump1eb44332009-09-09 15:08:12 +000085
Ted Kremenek28f47b92010-12-01 22:16:56 +000086 const GRState *assumeAux(const GRState *state, NonLoc Cond, bool Assumption);
Ted Kremenek45021952009-02-14 17:08:39 +000087};
88
Argyrios Kyrtzidis5a4f98f2010-12-22 18:53:20 +000089} // end GR namespace
90
91} // end clang namespace
Ted Kremenek45021952009-02-14 17:08:39 +000092
Ted Kremenek669c0e12009-02-15 18:24:51 +000093#endif