mirror of
				https://github.com/Z3Prover/z3
				synced 2025-10-28 10:19:23 +00:00 
			
		
		
		
	Java FPA API overhaul
Signed-off-by: Christoph M. Wintersteiger <cwinter@microsoft.com>
This commit is contained in:
		
							parent
							
								
									ee2c9095c6
								
							
						
					
					
						commit
						7fe9ad5cb4
					
				
					 16 changed files with 25 additions and 89 deletions
				
			
		|  | @ -2212,24 +2212,24 @@ class JavaExample | |||
|     { | ||||
|         System.out.println("FloatingPointExample2"); | ||||
|         Log.append("FloatingPointExample2"); | ||||
|          | ||||
|         FPSort double_sort = ctx.mkFPSort(11, 53); | ||||
|         FPRMSort rm_sort = ctx.mkFPRoundingModeSort(); | ||||
|          | ||||
|         FPRMExpr rm = (FPRMExpr)ctx.mkConst(ctx.mkSymbol("rm"), rm_sort); | ||||
|         BitVecExpr x = (BitVecExpr)ctx.mkConst(ctx.mkSymbol("x"), ctx.mkBitVecSort(64)); | ||||
|         RealExpr real_val = ctx.mkReal(42); | ||||
|         FPExpr y = (FPExpr)ctx.mkConst(ctx.mkSymbol("y"), double_sort);             | ||||
|         FPExpr fp_val = ctx.mkFP(42, double_sort); | ||||
|          | ||||
|         BoolExpr c1 = ctx.mkEq(x, ctx.mkFPToIEEEBV(fp_val)); | ||||
|         BoolExpr c2 = ctx.mkEq(x, ctx.mkBV(42, 64)); | ||||
|         BoolExpr c3 = ctx.mkEq(fp_val, ctx.mkFPToFP(rm, real_val, double_sort)); | ||||
|         BoolExpr c4 = ctx.mkAnd(c1, c2); | ||||
|         System.out.println("c3 = " + c3); | ||||
|         BoolExpr c1 = ctx.mkEq(y, fp_val); | ||||
|         BoolExpr c2 = ctx.mkEq(x, ctx.mkFPToBV(rm, y, 64, false)); | ||||
|         BoolExpr c3 = ctx.mkEq(x, ctx.mkBV(42, 64)); | ||||
|         BoolExpr c4 = ctx.mkEq(ctx.mkNumeral(42, ctx.getRealSort()), ctx.mkFPToReal(fp_val)); | ||||
|         BoolExpr c5 = ctx.mkAnd(c1, c2, c3, c4); | ||||
|         System.out.println("c5 = " + c5); | ||||
| 
 | ||||
|         /* Generic solver */ | ||||
|         Solver s = ctx.mkSolver(); | ||||
|         s.add(c3); | ||||
|         s.add(c5); | ||||
| 
 | ||||
|         if (s.check() != Status.SATISFIABLE) | ||||
|             throw new TestFailedException(); | ||||
|  |  | |||
|  | @ -213,10 +213,8 @@ public class AST extends Z3Object | |||
|     void incRef(long o) throws Z3Exception | ||||
|     { | ||||
|         // Console.WriteLine("AST IncRef()"); | ||||
|         if (getContext() == null) | ||||
|             throw new Z3Exception("inc() called on null context"); | ||||
|         if (o == 0) | ||||
|             throw new Z3Exception("inc() called on null AST"); | ||||
|         if (getContext() == null || o == 0) | ||||
|             return; | ||||
|         getContext().ast_DRQ().incAndClear(getContext(), o); | ||||
|         super.incRef(o); | ||||
|     } | ||||
|  | @ -224,10 +222,8 @@ public class AST extends Z3Object | |||
|     void decRef(long o) throws Z3Exception | ||||
|     { | ||||
|         // Console.WriteLine("AST DecRef()"); | ||||
|         if (getContext() == null) | ||||
|             throw new Z3Exception("dec() called on null context"); | ||||
|         if (o == 0) | ||||
|             throw new Z3Exception("dec() called on null AST"); | ||||
|         if (getContext() == null || o == 0) | ||||
|             return; | ||||
|         getContext().ast_DRQ().add(o); | ||||
|         super.decRef(o); | ||||
|     } | ||||
|  |  | |||
|  | @ -25,11 +25,6 @@ public class ArithExpr extends Expr | |||
| 	/** | ||||
| 	 * Constructor for ArithExpr </summary> | ||||
| 	 **/ | ||||
| 	protected ArithExpr(Context ctx) | ||||
| 	{ | ||||
| 		super(ctx); | ||||
| 	} | ||||
| 
 | ||||
| 	ArithExpr(Context ctx, long obj) throws Z3Exception | ||||
| 	{ | ||||
| 		super(ctx, obj); | ||||
|  |  | |||
|  | @ -26,11 +26,6 @@ public class ArrayExpr extends Expr | |||
| 	/** | ||||
| 	 * Constructor for ArrayExpr </summary> | ||||
| 	 **/ | ||||
| 	protected ArrayExpr(Context ctx) | ||||
| 	{ | ||||
| 		super(ctx); | ||||
| 	} | ||||
| 
 | ||||
| 	ArrayExpr(Context ctx, long obj) throws Z3Exception | ||||
| 	{ | ||||
| 		super(ctx, obj); | ||||
|  |  | |||
|  | @ -35,11 +35,6 @@ public class BitVecExpr extends Expr | |||
| 	/** | ||||
| 	 * Constructor for BitVecExpr </summary> | ||||
| 	 **/ | ||||
| 	BitVecExpr(Context ctx) | ||||
| 	{ | ||||
| 		super(ctx); | ||||
| 	} | ||||
| 
 | ||||
| 	BitVecExpr(Context ctx, long obj) throws Z3Exception | ||||
| 	{ | ||||
| 		super(ctx, obj); | ||||
|  |  | |||
|  | @ -22,14 +22,6 @@ package com.microsoft.z3; | |||
|  **/ | ||||
| public class BoolExpr extends Expr | ||||
| { | ||||
| 	/** | ||||
| 	 * Constructor for BoolExpr </summary> | ||||
| 	 **/ | ||||
| 	protected BoolExpr(Context ctx) | ||||
| 	{ | ||||
| 		super(ctx); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Constructor for BoolExpr </summary> | ||||
| 	 * @throws Z3Exception  | ||||
|  |  | |||
|  | @ -504,14 +504,10 @@ public class Context extends IDisposable | |||
|      **/ | ||||
|     public Expr mkConst(Symbol name, Sort range) throws Z3Exception | ||||
|     { | ||||
| 
 | ||||
|         checkContextMatch(name); | ||||
|         checkContextMatch(range); | ||||
| 
 | ||||
|         return Expr.create( | ||||
|                 this, | ||||
|                 Native.mkConst(nCtx(), name.getNativeObject(), | ||||
|                         range.getNativeObject())); | ||||
|         return Expr.create(this, Native.mkConst(nCtx(), name.getNativeObject(), range.getNativeObject())); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  |  | |||
|  | @ -25,11 +25,6 @@ public class DatatypeExpr extends Expr | |||
| 	/** | ||||
| 	 * Constructor for DatatypeExpr </summary> | ||||
| 	 **/ | ||||
| 	protected DatatypeExpr(Context ctx) | ||||
| 	{ | ||||
| 		super(ctx); | ||||
| 	} | ||||
| 
 | ||||
| 	DatatypeExpr(Context ctx, long obj) throws Z3Exception | ||||
| 	{ | ||||
| 		super(ctx, obj); | ||||
|  |  | |||
|  | @ -60,7 +60,7 @@ public class EnumSort extends Sort | |||
| 
 | ||||
| 	EnumSort(Context ctx, Symbol name, Symbol[] enumNames) throws Z3Exception | ||||
| 	{ | ||||
| 		super(ctx); | ||||
| 		super(ctx, 0); | ||||
| 
 | ||||
| 		int n = enumNames.length; | ||||
| 		long[] n_constdecls = new long[n]; | ||||
|  |  | |||
|  | @ -2092,24 +2092,12 @@ public class Expr extends AST | |||
| 		return Native.getIndexValue(getContext().nCtx(), getNativeObject()); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Constructor for Expr | ||||
| 	 **/ | ||||
| 	protected Expr(Context ctx) | ||||
| 	{ | ||||
| 		super(ctx); | ||||
| 		{ | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Constructor for Expr | ||||
| 	 **/ | ||||
| 	protected Expr(Context ctx, long obj) throws Z3Exception | ||||
| 	{ | ||||
| 		super(ctx, obj); | ||||
| 		{ | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	void checkNativeObject(long obj) throws Z3Exception | ||||
|  | @ -2135,8 +2123,7 @@ public class Expr extends AST | |||
| 		if (k == Z3_ast_kind.Z3_QUANTIFIER_AST) | ||||
| 			return new Quantifier(ctx, obj); | ||||
| 		long s = Native.getSort(ctx.nCtx(), obj); | ||||
| 		Z3_sort_kind sk = Z3_sort_kind | ||||
| 				.fromInt(Native.getSortKind(ctx.nCtx(), s)); | ||||
| 		Z3_sort_kind sk = Z3_sort_kind.fromInt(Native.getSortKind(ctx.nCtx(), s)); | ||||
| 
 | ||||
| 		if (Native.isAlgebraicNumber(ctx.nCtx(), obj)) // is this a numeral ast? | ||||
| 			return new AlgebraicNum(ctx, obj); | ||||
|  |  | |||
|  | @ -25,11 +25,6 @@ public class IntExpr extends ArithExpr | |||
| 	/** | ||||
| 	 * Constructor for IntExpr </summary> | ||||
| 	 **/ | ||||
| 	protected IntExpr(Context ctx) throws Z3Exception | ||||
| 	{ | ||||
| 		super(ctx); | ||||
| 	} | ||||
| 
 | ||||
| 	IntExpr(Context ctx, long obj) throws Z3Exception | ||||
| 	{ | ||||
| 		super(ctx, obj); | ||||
|  |  | |||
|  | @ -88,7 +88,7 @@ public class ListSort extends Sort | |||
| 
 | ||||
|     ListSort(Context ctx, Symbol name, Sort elemSort) throws Z3Exception | ||||
|     { | ||||
|         super(ctx); | ||||
|         super(ctx, 0); | ||||
| 
 | ||||
|         Native.LongPtr inil = new Native.LongPtr(), iisnil = new Native.LongPtr(); | ||||
|         Native.LongPtr icons = new Native.LongPtr(), iiscons = new Native.LongPtr(); | ||||
|  |  | |||
|  | @ -149,7 +149,7 @@ public class Quantifier extends BoolExpr | |||
|             Expr body, int weight, Pattern[] patterns, Expr[] noPatterns, | ||||
|             Symbol quantifierID, Symbol skolemID) throws Z3Exception | ||||
|     { | ||||
|         super(ctx); | ||||
|         super(ctx, 0); | ||||
| 
 | ||||
|         getContext().checkContextMatch(patterns); | ||||
|         getContext().checkContextMatch(noPatterns); | ||||
|  | @ -185,7 +185,7 @@ public class Quantifier extends BoolExpr | |||
|             int weight, Pattern[] patterns, Expr[] noPatterns, | ||||
|             Symbol quantifierID, Symbol skolemID) throws Z3Exception | ||||
|     { | ||||
|         super(ctx); | ||||
|         super(ctx, 0); | ||||
| 
 | ||||
|         getContext().checkContextMatch(noPatterns); | ||||
|         getContext().checkContextMatch(patterns); | ||||
|  |  | |||
|  | @ -25,11 +25,6 @@ public class RealExpr extends ArithExpr | |||
|     /** | ||||
|      * Constructor for RealExpr </summary> | ||||
|      **/ | ||||
|     protected RealExpr(Context ctx) | ||||
|     { | ||||
|         super(ctx); | ||||
|     } | ||||
| 
 | ||||
|     RealExpr(Context ctx, long obj) throws Z3Exception | ||||
|     { | ||||
|         super(ctx, obj); | ||||
|  |  | |||
|  | @ -98,18 +98,9 @@ public class Sort extends AST | |||
|     /** | ||||
|      * Sort constructor | ||||
|      **/ | ||||
|     protected Sort(Context ctx) throws Z3Exception | ||||
|     { | ||||
|         super(ctx); | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     Sort(Context ctx, long obj) throws Z3Exception | ||||
|     { | ||||
|         super(ctx, obj); | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     void checkNativeObject(long obj) throws Z3Exception | ||||
|  | @ -143,6 +134,10 @@ public class Sort extends AST | |||
|             return new FiniteDomainSort(ctx, obj); | ||||
|         case Z3_RELATION_SORT: | ||||
|             return new RelationSort(ctx, obj); | ||||
|         case Z3_FLOATING_POINT_SORT: | ||||
|         	return new FPSort(ctx, obj); | ||||
|         case Z3_ROUNDING_MODE_SORT: | ||||
|     		return new FPRMSort(ctx, obj); | ||||
|         default: | ||||
|             throw new Z3Exception("Unknown sort kind"); | ||||
|         } | ||||
|  |  | |||
|  | @ -59,7 +59,7 @@ public class TupleSort extends Sort | |||
|     TupleSort(Context ctx, Symbol name, int numFields, Symbol[] fieldNames, | ||||
|             Sort[] fieldSorts) throws Z3Exception | ||||
|     { | ||||
|         super(ctx); | ||||
|         super(ctx, 0); | ||||
| 
 | ||||
|         Native.LongPtr t = new Native.LongPtr(); | ||||
|         setNativeObject(Native.mkTupleSort(ctx.nCtx(), name.getNativeObject(), | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue