Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java type generics #4832

Merged
merged 27 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
19d83e3
Generify, needs some testing and review
addisoncrump Nov 28, 2020
da9c2ed
Remove unnecessary change
addisoncrump Nov 28, 2020
7c30c50
Whoops, ? capture that type
addisoncrump Nov 28, 2020
c1096ad
Misread the docs, whoops
addisoncrump Nov 28, 2020
9173296
More permissible arithmetic operations
addisoncrump Nov 28, 2020
9ad727d
Implement believed Optimize generics
addisoncrump Nov 28, 2020
b6b42c9
Missed a few generics
addisoncrump Nov 28, 2020
8904764
More permissible expr for arrays in parameters
addisoncrump Nov 28, 2020
92f5f2d
More permissible expr for bitvecs in parameters
addisoncrump Nov 28, 2020
9d4aa7c
More permissible expr for bools in parameters
addisoncrump Nov 28, 2020
dd80510
More permissible expr for fps in parameters
addisoncrump Nov 28, 2020
e154a47
More permissible expr for fprms in parameters
addisoncrump Nov 28, 2020
37da41d
More permissible expr for ints in parameters
addisoncrump Nov 28, 2020
f7f43a8
More permissible expr for reals in parameters
addisoncrump Nov 28, 2020
e3d7a9b
Undo breaking name conflict due to type erasure; see notes
addisoncrump Nov 28, 2020
372de12
Whoops, fix typing of ReExpr
addisoncrump Nov 28, 2020
7894e69
Sort corrections for Re, Seq
addisoncrump Nov 28, 2020
5f58655
More permissible expr for regular expressions in parameters
addisoncrump Nov 28, 2020
67e4ef8
Fix name conflict between sequences and regular expressions; see notes
addisoncrump Nov 28, 2020
714e8f7
Minor typo, big implications!
addisoncrump Nov 28, 2020
e47e996
Make Constructor consistent, associate captured types with other unkn…
addisoncrump Nov 29, 2020
d975295
More expressive; outputs of multiple datatype definitions are only kn…
addisoncrump Nov 29, 2020
cf0289e
Be less dumb and just type it a little differently
addisoncrump Nov 29, 2020
c5a1737
Update examples, make sure to type Expr and FuncDecl sort returns
addisoncrump Nov 29, 2020
ca8a595
General fixups
addisoncrump Nov 29, 2020
4e14a1c
Downgrade java version, make it only for the generic support, remove …
addisoncrump Nov 30, 2020
82a0d4f
Turns out Java 8 hadn't figured out how to do stream generics yet. Di…
addisoncrump Nov 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/java/JavaExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ void quantifierExample1(Context ctx)
System.out.println("QuantifierExample");
Log.append("QuantifierExample");

Sort[] types = new Sort[3];
IntSort[] types = new IntSort[3];
NikolajBjorner marked this conversation as resolved.
Show resolved Hide resolved
IntExpr[] xs = new IntExpr[3];
Symbol[] names = new Symbol[3];
IntExpr[] vars = new IntExpr[3];
Expand Down Expand Up @@ -1398,7 +1398,7 @@ public void bitvectorExample1(Context ctx) throws TestFailedException
System.out.println("BitvectorExample1");
Log.append("BitvectorExample1");

Sort bv_type = ctx.mkBitVecSort(32);
BitVecSort bv_type = ctx.mkBitVecSort(32);
BitVecExpr x = (BitVecExpr) ctx.mkConst("x", bv_type);
BitVecNum zero = (BitVecNum) ctx.mkNumeral("0", bv_type);
BitVecNum ten = ctx.mkBV(10, 32);
Expand All @@ -1420,7 +1420,7 @@ public void bitvectorExample2(Context ctx) throws TestFailedException
Log.append("BitvectorExample2");

/* construct x ^ y - 103 == x * y */
Sort bv_type = ctx.mkBitVecSort(32);
BitVecSort bv_type = ctx.mkBitVecSort(32);
BitVecExpr x = ctx.mkBVConst("x", 32);
BitVecExpr y = ctx.mkBVConst("y", 32);
BitVecExpr x_xor_y = ctx.mkBVXOR(x, y);
Expand Down
2 changes: 1 addition & 1 deletion src/api/java/AST.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static AST create(Context ctx, long obj)
switch (Z3_ast_kind.fromInt(Native.getAstKind(ctx.nCtx(), obj)))
{
case Z3_FUNC_DECL_AST:
return new FuncDecl(ctx, obj);
return new FuncDecl<>(ctx, obj);
case Z3_QUANTIFIER_AST:
return new Quantifier(ctx, obj);
case Z3_SORT_AST:
Expand Down
22 changes: 11 additions & 11 deletions src/api/java/ASTVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public AST[] ToArray()
/**
* Translates the AST vector into an Expr[]
* */
public Expr[] ToExprArray() {
public Expr<?>[] ToExprArray() {
int n = size();
Expr[] res = new Expr[n];
Expr<?>[] res = new Expr[n];
for (int i = 0; i < n; i++)
res[i] = Expr.create(getContext(), get(i).getNativeObject());
return res;
Expand Down Expand Up @@ -161,36 +161,36 @@ public BitVecExpr[] ToBitVecExprArray()
/**
* Translates the AST vector into an ArithExpr[]
* */
public ArithExpr[] ToArithExprExprArray()
public ArithExpr<?>[] ToArithExprExprArray()
{
int n = size();
ArithExpr[] res = new ArithExpr[n];
ArithExpr<?>[] res = new ArithExpr[n];
for (int i = 0; i < n; i++)
res[i] = (ArithExpr)Expr.create(getContext(), get(i).getNativeObject());
res[i] = (ArithExpr<?>)Expr.create(getContext(), get(i).getNativeObject());
return res;
}

/**
* Translates the AST vector into an ArrayExpr[]
* */
public ArrayExpr[] ToArrayExprArray()
public ArrayExpr<?, ?>[] ToArrayExprArray()
{
int n = size();
ArrayExpr[] res = new ArrayExpr[n];
ArrayExpr<?, ?>[] res = new ArrayExpr[n];
for (int i = 0; i < n; i++)
res[i] = (ArrayExpr)Expr.create(getContext(), get(i).getNativeObject());
res[i] = (ArrayExpr<?, ?>)Expr.create(getContext(), get(i).getNativeObject());
return res;
}

/**
* Translates the AST vector into an DatatypeExpr[]
* */
public DatatypeExpr[] ToDatatypeExprArray()
public DatatypeExpr<?>[] ToDatatypeExprArray()
{
int n = size();
DatatypeExpr[] res = new DatatypeExpr[n];
DatatypeExpr<?>[] res = new DatatypeExpr[n];
for (int i = 0; i < n; i++)
res[i] = (DatatypeExpr)Expr.create(getContext(), get(i).getNativeObject());
res[i] = (DatatypeExpr<?>)Expr.create(getContext(), get(i).getNativeObject());
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/java/ArithExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Arithmetic expressions (int/real)
**/
public class ArithExpr extends Expr
public class ArithExpr<R extends ArithSort> extends Expr<R>
{
/**
* Constructor for ArithExpr
Expand Down
2 changes: 1 addition & 1 deletion src/api/java/ArrayExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Array expressions
**/
public class ArrayExpr extends Expr
public class ArrayExpr<D extends Sort, R extends Sort> extends Expr<ArraySort<D, R>>
{
/**
* Constructor for ArrayExpr
Expand Down
15 changes: 8 additions & 7 deletions src/api/java/ArraySort.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
/**
* Array sorts.
**/
public class ArraySort extends Sort
@SuppressWarnings("unchecked")
public class ArraySort<D extends Sort, R extends Sort> extends Sort
{
/**
* The domain of the array sort.
* @throws Z3Exception
* @throws Z3Exception on error
* @return a sort
**/
public Sort getDomain()
public D getDomain()
{
return Sort.create(getContext(),
return (D) Sort.create(getContext(),
Native.getArraySortDomain(getContext().nCtx(), getNativeObject()));
}

Expand All @@ -40,9 +41,9 @@ public Sort getDomain()
* @throws Z3Exception on error
* @return a sort
**/
public Sort getRange()
public R getRange()
{
return Sort.create(getContext(),
return (R) Sort.create(getContext(),
Native.getArraySortRange(getContext().nCtx(), getNativeObject()));
}

Expand All @@ -51,13 +52,13 @@ public Sort getRange()
super(ctx, obj);
}

ArraySort(Context ctx, Sort domain, Sort range)
ArraySort(Context ctx, D domain, R range)
{
super(ctx, Native.mkArraySort(ctx.nCtx(), domain.getNativeObject(),
range.getNativeObject()));
}

ArraySort(Context ctx, Sort[] domains, Sort range)
ArraySort(Context ctx, Sort[] domains, R range)
{
super(ctx, Native.mkArraySortN(ctx.nCtx(), domains.length, AST.arrayToNative(domains),
range.getNativeObject()));
Expand Down
2 changes: 1 addition & 1 deletion src/api/java/BitVecExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Bit-vector expressions
**/
public class BitVecExpr extends Expr
public class BitVecExpr extends Expr<BitVecSort>
{

/**
Expand Down
2 changes: 1 addition & 1 deletion src/api/java/BoolExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Boolean expressions
**/
public class BoolExpr extends Expr {
public class BoolExpr extends Expr<BoolSort> {

/**
* Constructor for BoolExpr
Expand Down
14 changes: 7 additions & 7 deletions src/api/java/Constructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,43 @@ public int getNumFields()
* @throws Z3Exception
* @throws Z3Exception on error
**/
public FuncDecl ConstructorDecl()
public FuncDecl<?> ConstructorDecl()
{
Native.LongPtr constructor = new Native.LongPtr();
Native.LongPtr tester = new Native.LongPtr();
long[] accessors = new long[n];
Native.queryConstructor(getContext().nCtx(), getNativeObject(), n, constructor, tester, accessors);
return new FuncDecl(getContext(), constructor.value);
return new FuncDecl<>(getContext(), constructor.value);
}

/**
* The function declaration of the tester.
* @throws Z3Exception
* @throws Z3Exception on error
**/
public FuncDecl getTesterDecl()
public FuncDecl<BoolSort> getTesterDecl()
{
Native.LongPtr constructor = new Native.LongPtr();
Native.LongPtr tester = new Native.LongPtr();
long[] accessors = new long[n];
Native.queryConstructor(getContext().nCtx(), getNativeObject(), n, constructor, tester, accessors);
return new FuncDecl(getContext(), tester.value);
return new FuncDecl<>(getContext(), tester.value);
}

/**
* The function declarations of the accessors
* @throws Z3Exception
* @throws Z3Exception on error
**/
public FuncDecl[] getAccessorDecls()
public FuncDecl<?>[] getAccessorDecls()
{
Native.LongPtr constructor = new Native.LongPtr();
Native.LongPtr tester = new Native.LongPtr();
long[] accessors = new long[n];
Native.queryConstructor(getContext().nCtx(), getNativeObject(), n, constructor, tester, accessors);
FuncDecl[] t = new FuncDecl[n];
FuncDecl<?>[] t = new FuncDecl[n];
for (int i = 0; i < n; i++)
t[i] = new FuncDecl(getContext(), accessors[i]);
t[i] = new FuncDecl<>(getContext(), accessors[i]);
return t;
}

Expand Down
Loading