#define MK_CONST EXPR_MANAGER->mkConst
#define UNSUPPORTED PARSER_STATE->unimplementedFeature
+#define ENSURE_BV_SIZE(k, f) \
+{ \
+ unsigned size = BitVectorType(f.getType()).getSize(); \
+ if(k > size) { \
+ f = MK_EXPR(MK_CONST(BitVectorZeroExtend(k - size)), f); \
+ } else if (k < size) { \
+ f = MK_EXPR(MK_CONST(BitVectorExtract(k - 1, 0)), f); \
+ } \
+}
+
}/* @parser::postinclude */
/**
bvTerm[CVC4::Expr& f]
@init {
Expr f2;
+ std::vector<Expr> args;
}
/* BV xor */
: BVXOR_TOK LPAREN formula[f] COMMA formula[f2] RPAREN
| BVUMINUS_TOK LPAREN formula[f] RPAREN
{ f = MK_EXPR(CVC4::kind::BITVECTOR_NEG, f); }
/* BV addition */
- | BVPLUS_TOK LPAREN k=numeral COMMA formula[f]
- ( COMMA formula[f2] { f = MK_EXPR(CVC4::kind::BITVECTOR_PLUS, f, f2); } )+ RPAREN
- { unsigned size = BitVectorType(f.getType()).getSize();
- if(k == 0) {
- PARSER_STATE->parseError("BVPLUS(k,_,_,...) must have k > 0");
- }
- if(k > size) {
- f = MK_EXPR(MK_CONST(BitVectorZeroExtend(k)), f);
- } else if(k < size) {
- f = MK_EXPR(MK_CONST(BitVectorExtract(k - 1, 0)), f);
+ | BVPLUS_TOK LPAREN k=numeral COMMA formula[f] { args.push_back(f); }
+ ( COMMA formula[f2] { args.push_back(f2); } )+ RPAREN
+ {
+ if (k <= 0) {
+ PARSER_STATE->parseError("BVPLUS(k,_,_) must have k > 0");
+ }
+ for (unsigned i = 0; i < args.size(); ++ i) {
+ ENSURE_BV_SIZE(k, args[i]);
}
+ f = MK_EXPR(CVC4::kind::BITVECTOR_PLUS, args);
}
/* BV subtraction */
| BVSUB_TOK LPAREN k=numeral COMMA formula[f] COMMA formula[f2] RPAREN
- { f = MK_EXPR(CVC4::kind::BITVECTOR_SUB, f, f2);
- if(k == 0) {
+ {
+ if (k <= 0) {
PARSER_STATE->parseError("BVSUB(k,_,_) must have k > 0");
- }
- unsigned size = BitVectorType(f.getType()).getSize();
- if(k > size) {
- f = MK_EXPR(MK_CONST(BitVectorZeroExtend(k)), f);
- } else if(k < size) {
- f = MK_EXPR(MK_CONST(BitVectorExtract(k - 1, 0)), f);
- }
+ }
+ ENSURE_BV_SIZE(k, f);
+ ENSURE_BV_SIZE(k, f2);
+ f = MK_EXPR(CVC4::kind::BITVECTOR_SUB, f, f2);
}
/* BV multiplication */
| BVMULT_TOK LPAREN k=numeral COMMA formula[f] COMMA formula[f2] RPAREN
- { f = MK_EXPR(CVC4::kind::BITVECTOR_MULT, f, f2);
- if(k == 0) {
+ {
+ if (k <= 0) {
PARSER_STATE->parseError("BVMULT(k,_,_) must have k > 0");
}
- unsigned size = BitVectorType(f.getType()).getSize();
- if(k > size) {
- f = MK_EXPR(MK_CONST(BitVectorZeroExtend(k)), f);
- } else if(k < size) {
- f = MK_EXPR(MK_CONST(BitVectorExtract(k - 1, 0)), f);
- }
+ ENSURE_BV_SIZE(k, f);
+ ENSURE_BV_SIZE(k, f2);
+ f = MK_EXPR(CVC4::kind::BITVECTOR_MULT, f, f2);
}
/* BV unsigned division */
| BVUDIV_TOK LPAREN formula[f] COMMA formula[f2] RPAREN
typerule BITVECTOR_COMP ::CVC4::theory::bv::BitVectorCompRule
-typerule BITVECTOR_MULT ::CVC4::theory::bv::BitVectorArithRule
-typerule BITVECTOR_PLUS ::CVC4::theory::bv::BitVectorArithRule
-typerule BITVECTOR_SUB ::CVC4::theory::bv::BitVectorArithRule
-typerule BITVECTOR_NEG ::CVC4::theory::bv::BitVectorArithRule
+typerule BITVECTOR_MULT ::CVC4::theory::bv::BitVectorFixedWidthTypeRule
+typerule BITVECTOR_PLUS ::CVC4::theory::bv::BitVectorFixedWidthTypeRule
+typerule BITVECTOR_SUB ::CVC4::theory::bv::BitVectorFixedWidthTypeRule
+typerule BITVECTOR_NEG ::CVC4::theory::bv::BitVectorFixedWidthTypeRule
typerule BITVECTOR_UDIV ::CVC4::theory::bv::BitVectorFixedWidthTypeRule
typerule BITVECTOR_UREM ::CVC4::theory::bv::BitVectorFixedWidthTypeRule
}
};
-class BitVectorArithRule {
-public:
- inline static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check)
- throw (TypeCheckingExceptionPrivate, AssertionException) {
- unsigned maxWidth = 0;
- TNode::iterator it = n.begin();
- TNode::iterator it_end = n.end();
- // TODO: optimize unary neg
- for (; it != it_end; ++ it) {
- TypeNode t = (*it).getType(check);
- if (check && !t.isBitVector()) {
- throw TypeCheckingExceptionPrivate(n, "expecting bit-vector terms");
- }
- maxWidth = std::max( maxWidth, t.getBitVectorSize() );
- }
- return nodeManager->mkBitVectorType(maxWidth);
- }
-};
-
class BitVectorFixedWidthTypeRule {
public:
inline static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check)