|
24 | 24 | class StpBooleanFormulaManager
|
25 | 25 | // extends AbstractBooleanFormulaManager<TFormulaInfo, TType, TEnv, TFuncDecl> {
|
26 | 26 | extends AbstractBooleanFormulaManager<Long, Long, Long, Long> {
|
27 |
| - |
| 27 | + private final VC vc; |
28 | 28 | protected StpBooleanFormulaManager(StpFormulaCreator pCreator) {
|
29 | 29 | super(pCreator);
|
30 |
| - // TODO Auto-generated constructor stub |
| 30 | + |
| 31 | + vc = pCreator.getVC(); |
31 | 32 | }
|
32 | 33 |
|
33 | 34 | @Override
|
34 | 35 | protected Long makeVariableImpl(String pVar) {
|
35 |
| - // TODO Auto-generated method stub |
36 |
| - return null; |
| 36 | + long boolType = getFormulaCreator().getBoolType(); |
| 37 | + return getFormulaCreator().makeVariable(boolType, pVar); |
37 | 38 | }
|
38 | 39 |
|
39 | 40 | @Override
|
40 | 41 | protected Long makeBooleanImpl(boolean pValue) {
|
41 |
| - // TODO Auto-generated method stub |
42 |
| - return null; |
| 42 | + Expr result = null; |
| 43 | + if (pValue) { |
| 44 | + result = StpJavaApi.vc_trueExpr(vc); |
| 45 | + } else { |
| 46 | + result = StpJavaApi.vc_falseExpr(vc); |
| 47 | + } |
| 48 | + return Expr.getCPtr(result); |
43 | 49 | }
|
44 | 50 |
|
45 | 51 | @Override
|
46 | 52 | protected Long not(Long pParam1) {
|
47 |
| - // TODO Auto-generated method stub |
48 |
| - return null; |
| 53 | + Expr result = StpJavaApi.vc_notExpr(vc, new Expr(pParam1, true)); |
| 54 | + return Expr.getCPtr(result); |
| 55 | + |
49 | 56 | }
|
50 | 57 |
|
51 | 58 | @Override
|
52 | 59 | protected Long and(Long pParam1, Long pParam2) {
|
53 |
| - // TODO Auto-generated method stub |
54 |
| - return null; |
| 60 | + Expr result = StpJavaApi.vc_andExpr(vc, new Expr(pParam1, true), new Expr(pParam2, true)); |
| 61 | + return Expr.getCPtr(result); |
55 | 62 | }
|
56 | 63 |
|
57 | 64 | @Override
|
58 | 65 | protected Long or(Long pParam1, Long pParam2) {
|
59 |
| - // TODO Auto-generated method stub |
60 |
| - return null; |
| 66 | + Expr result = StpJavaApi.vc_orExpr(vc, new Expr(pParam1, true), new Expr(pParam2, true)); |
| 67 | + return Expr.getCPtr(result); |
61 | 68 | }
|
62 | 69 |
|
63 | 70 | @Override
|
64 | 71 | protected Long xor(Long pParam1, Long pParam2) {
|
65 |
| - // TODO Auto-generated method stub |
66 |
| - return null; |
| 72 | + Expr result = StpJavaApi.vc_xorExpr(vc, new Expr(pParam1, true), new Expr(pParam2, true)); |
| 73 | + return Expr.getCPtr(result); |
67 | 74 | }
|
68 | 75 |
|
69 | 76 | @Override
|
70 | 77 | protected Long equivalence(Long pBits1, Long pBits2) {
|
71 |
| - // TODO Auto-generated method stub |
72 |
| - return null; |
| 78 | + // Expr result = StpJavaApi.vc_eqExpr(vc, new Expr(pBits1, true), new Expr(pBits2, true)); |
| 79 | + |
| 80 | + // if and only if |
| 81 | + Expr result = StpJavaApi.vc_iffExpr(vc, new Expr(pBits1, true), new Expr(pBits2, true)); |
| 82 | + |
| 83 | + return Expr.getCPtr(result); |
73 | 84 | }
|
74 | 85 |
|
75 | 86 | @Override
|
76 | 87 | protected boolean isTrue(Long pBits) {
|
77 |
| - // TODO Auto-generated method stub |
78 |
| - return false; |
| 88 | + |
| 89 | + int result = StpJavaApi.vc_isBool(new Expr(pBits, true)); |
| 90 | + if (result == 1) { |
| 91 | + return true; |
| 92 | + } else { |
| 93 | + return false; |
| 94 | + } |
| 95 | + // else if (result == 0) { |
| 96 | + // return false; |
| 97 | + // }else { //-1 is not boolean |
| 98 | + // throw new Exception("The Formaula is not boolean"); |
| 99 | + // } |
79 | 100 | }
|
80 | 101 |
|
81 | 102 | @Override
|
82 | 103 | protected boolean isFalse(Long pBits) {
|
83 |
| - // TODO Auto-generated method stub |
84 |
| - return false; |
| 104 | + int result = StpJavaApi.vc_isBool(new Expr(pBits, true)); |
| 105 | + if (result == 0) { |
| 106 | + return true; |
| 107 | + } else { |
| 108 | + return false; |
| 109 | + } |
85 | 110 | }
|
86 | 111 |
|
| 112 | + /*** |
| 113 | + * @return either a Bit Vector or Boolean depending on the type of formulas |
| 114 | + * @param pCond must be boolean |
| 115 | + * @param pF1 and @param pF2 must have the same type |
| 116 | + * |
| 117 | + */ |
87 | 118 | @Override
|
88 | 119 | protected Long ifThenElse(Long pCond, Long pF1, Long pF2) {
|
89 |
| - // TODO Auto-generated method stub |
90 |
| - return null; |
| 120 | + // TODO Enforce the rules stated in the doc comment above |
| 121 | + Expr result = |
| 122 | + StpJavaApi.vc_iteExpr(vc, new Expr(pCond, true), new Expr(pF1, true), new Expr(pF2, true)); |
| 123 | + return Expr.getCPtr(result); |
91 | 124 | }
|
92 |
| - |
93 | 125 | }
|
0 commit comments