本文整理汇总了Java中gov.nasa.jpf.constraints.types.NumericType类的典型用法代码示例。如果您正苦于以下问题:Java NumericType类的具体用法?Java NumericType怎么用?Java NumericType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NumericType类属于gov.nasa.jpf.constraints.types包,在下文中一共展示了NumericType类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeIntegerCast
import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
private <F,T,TT extends Type<T>>
Expr makeIntegerCast(IntExpr castedExpr, IntegerType<F> from, TT to) throws Z3Exception {
try {
if(to instanceof BVIntegerType) {
BVIntegerType<?> bvTo = (BVIntegerType<?>)to;
return ctx.mkInt2BV(bvTo.getNumBits(), castedExpr);
}
if(to instanceof IntegerType) {
Expr tmp = castedExpr;
castedExpr = null; // prevent disposal
return tmp;
}
if(to instanceof NumericType) {
return ctx.mkInt2Real(castedExpr);
}
throw new IllegalStateException("Cannot handle integer cast to " + to);
}
finally {
safeDispose(castedExpr);
}
}
示例2: visit
import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
@Override
public <E> Expr visit(
NumericCompound<E> n, Void data) {
Expr left = null, right = null;
try {
left = visit(n.getLeft());
right = visit(n.getRight());
NumericType<E> type = (NumericType<E>)n.getType();
if(type instanceof BVIntegerType)
return makeBitvectorNumericCompound(n.getOperator(), type.isSigned(), (BitVecExpr)left, (BitVecExpr)right);
return makeArithmeticNumericCompound(n.getOperator(), (ArithExpr)left, (ArithExpr)right);
}
catch(Z3Exception ex) {
throw new RuntimeException(ex);
}
finally {
safeDispose(left, right);
}
}
示例3: evaluate
import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
@Override
public E evaluate(Valuation values) {
E lv = left.evaluate(values);
E rv = right.evaluate(values);
NumericType<E> type = (NumericType<E>)getType();
switch (operator) {
case PLUS:
return type.plus(lv, rv);
case MINUS:
return type.minus(lv, rv);
case MUL:
return type.mul(lv, rv);
case DIV:
return type.div(lv, rv);
case REM:
return type.mod(lv, rv);
default:
throw new IllegalStateException("Unknown numeric operator " + operator);
}
}
示例4: visit
import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
@Override
public <E> Expression<?> visit(Constant<E> c, Boolean data) {
if(!data)
return c;
Expression<Boolean> asBool = c.as(BuiltinTypes.BOOL);
if(asBool != null)
return ExpressionUtil.boolConst(!asBool.evaluate(null));
Type<E> t = c.getType();
if(t instanceof NumericType) {
NumericType<E> nt = (NumericType<E>)t;
return Constant.create(nt, nt.negate(c.getValue()));
}
throw new IllegalStateException("Cannot simplify: expression of type " + c.getType() + " is neither boolean nor numeric");
}
示例5: doEvaluate
import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
private static <L,R> int doEvaluate(Expression<L> left, Expression<R> right, Valuation values) {
NumericType<L> lt = (NumericType<L>)left.getType();
NumericType<R> rt = (NumericType<R>)right.getType();
L lv = left.evaluate(values);
R rv = right.evaluate(values);
BigDecimal lnum = lt.decimalValue(lv), rnum = rt.decimalValue(rv);
return lnum.compareTo(rnum);
}
示例6: makeRealCast
import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
private <F,T,TT extends Type<T>>
Expr makeRealCast(RealExpr castedExpr, NumericType<F> from, TT to) throws Z3Exception {
try {
if(to instanceof BVIntegerType) {
BVIntegerType<?> bvTo = (BVIntegerType<?>)to;
IntExpr intTmp = null;
try {
intTmp = makeReal2IntTrunc(castedExpr);
return ctx.mkInt2BV(bvTo.getNumBits(), intTmp);
}
finally {
uncheckedDispose(intTmp);
}
}
if(to instanceof IntegerType) {
return makeReal2IntTrunc(castedExpr);
}
if(to instanceof NumericType) {
Expr tmp = castedExpr;
castedExpr = null; // prevent disposal
return tmp;
}
throw new IllegalStateException("Cannot handle integer cast to " + to);
}
finally {
safeDispose(castedExpr);
}
}
示例7: translateTypeCast
import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
public Expression<?> translateTypeCast(Tree n) {
requireType(n, TYPE_CAST);
NumericType<?> toType = (NumericType<?>)translateType(n.getChild(0));
Expression<?> fromExpr = translateArithmeticExpression(n);
return CastExpression.create(fromExpr, toType);
}
示例8: compare
import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
private static <L,R> int compare(Expression<L> left, Expression<R> right, Valuation val) {
L lv = left.evaluate(val);
R rv = right.evaluate(val);
NumericType<L> ltype = (NumericType<L>)left.getType();
NumericType<R> rtype = (NumericType<R>)right.getType();
if (ltype.equals(rtype)) {
return ltype.compare(lv, (L) rv);
}
BigDecimal lNum = ltype.decimalValue(lv);
BigDecimal rNum = rtype.decimalValue(rv);
return lNum.compareTo(rNum);
}
示例9: evaluate
import gov.nasa.jpf.constraints.types.NumericType; //导入依赖的package包/类
@Override
public E evaluate(Valuation values) {
E num = negated.evaluate(values);
NumericType<E> type = (NumericType<E>)getType();
return type.negate(num);
}