mirror of
https://github.com/Z3Prover/z3
synced 2025-05-11 09:44:43 +00:00
Java type generics (#4832)
* Generify, needs some testing and review * Remove unnecessary change * Whoops, ? capture that type * Misread the docs, whoops * More permissible arithmetic operations * Implement believed Optimize generics * Missed a few generics * More permissible expr for arrays in parameters * More permissible expr for bitvecs in parameters * More permissible expr for bools in parameters * More permissible expr for fps in parameters * More permissible expr for fprms in parameters * More permissible expr for ints in parameters * More permissible expr for reals in parameters * Undo breaking name conflict due to type erasure; see notes * Whoops, fix typing of ReExpr * Sort corrections for Re, Seq * More permissible expr for regular expressions in parameters * Fix name conflict between sequences and regular expressions; see notes * Minor typo, big implications! * Make Constructor consistent, associate captured types with other unknown capture types for datatype consistency * More expressive; outputs of multiple datatype definitions are only known to be sort, not capture, and Constructor.of should make a capture * Be less dumb and just type it a little differently * Update examples, make sure to type Expr and FuncDecl sort returns * General fixups * Downgrade java version, make it only for the generic support, remove var and Expr[]::new construction * Turns out Java 8 hadn't figured out how to do stream generics yet. Didn't even show up in my IDE, weird
This commit is contained in:
parent
bb24b3f2be
commit
3bca1fbcd8
45 changed files with 2724 additions and 588 deletions
|
@ -24,7 +24,7 @@ import com.microsoft.z3.enumerations.Z3_parameter_kind;
|
|||
/**
|
||||
* Function declarations.
|
||||
**/
|
||||
public class FuncDecl extends AST
|
||||
public class FuncDecl<R extends Sort> extends AST
|
||||
{
|
||||
/**
|
||||
* Object comparison.
|
||||
|
@ -34,7 +34,7 @@ public class FuncDecl extends AST
|
|||
{
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof FuncDecl)) return false;
|
||||
FuncDecl other = (FuncDecl) o;
|
||||
FuncDecl<?> other = (FuncDecl<?>) o;
|
||||
|
||||
return
|
||||
(getContext().nCtx() == other.getContext().nCtx()) &&
|
||||
|
@ -66,9 +66,10 @@ public class FuncDecl extends AST
|
|||
* @return A copy of the function declaration which is associated with {@code ctx}
|
||||
* @throws Z3Exception on error
|
||||
**/
|
||||
public FuncDecl translate(Context ctx)
|
||||
@SuppressWarnings("unchecked")
|
||||
public FuncDecl<R> translate(Context ctx)
|
||||
{
|
||||
return (FuncDecl) super.translate(ctx);
|
||||
return (FuncDecl<R>) super.translate(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,10 +107,10 @@ public class FuncDecl extends AST
|
|||
/**
|
||||
* The range of the function declaration
|
||||
**/
|
||||
public Sort getRange()
|
||||
@SuppressWarnings("unchecked")
|
||||
public R getRange()
|
||||
{
|
||||
|
||||
return Sort.create(getContext(),
|
||||
return (R) Sort.create(getContext(),
|
||||
Native.getRange(getContext().nCtx(), getNativeObject()));
|
||||
}
|
||||
|
||||
|
@ -178,7 +179,7 @@ public class FuncDecl extends AST
|
|||
getNativeObject(), i)));
|
||||
break;
|
||||
case Z3_PARAMETER_FUNC_DECL:
|
||||
res[i] = new Parameter(k, new FuncDecl(getContext(),
|
||||
res[i] = new Parameter(k, new FuncDecl<>(getContext(),
|
||||
Native.getDeclFuncDeclParameter(getContext().nCtx(),
|
||||
getNativeObject(), i)));
|
||||
break;
|
||||
|
@ -197,7 +198,7 @@ public class FuncDecl extends AST
|
|||
/**
|
||||
* Function declarations can have Parameters associated with them.
|
||||
**/
|
||||
public class Parameter
|
||||
public static class Parameter
|
||||
{
|
||||
private Z3_parameter_kind kind;
|
||||
private int i;
|
||||
|
@ -205,7 +206,7 @@ public class FuncDecl extends AST
|
|||
private Symbol sym;
|
||||
private Sort srt;
|
||||
private AST ast;
|
||||
private FuncDecl fd;
|
||||
private FuncDecl<?> fd;
|
||||
private String r;
|
||||
|
||||
/**
|
||||
|
@ -261,7 +262,7 @@ public class FuncDecl extends AST
|
|||
/**
|
||||
* The FunctionDeclaration value of the parameter.
|
||||
**/
|
||||
public FuncDecl getFuncDecl()
|
||||
public FuncDecl<?> getFuncDecl()
|
||||
{
|
||||
if (getParameterKind() != Z3_parameter_kind.Z3_PARAMETER_FUNC_DECL)
|
||||
throw new Z3Exception("parameter is not a function declaration");
|
||||
|
@ -316,7 +317,7 @@ public class FuncDecl extends AST
|
|||
this.ast = a;
|
||||
}
|
||||
|
||||
Parameter(Z3_parameter_kind k, FuncDecl fd)
|
||||
Parameter(Z3_parameter_kind k, FuncDecl<?> fd)
|
||||
{
|
||||
this.kind = k;
|
||||
this.fd = fd;
|
||||
|
@ -335,14 +336,14 @@ public class FuncDecl extends AST
|
|||
|
||||
}
|
||||
|
||||
FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range)
|
||||
FuncDecl(Context ctx, Symbol name, Sort[] domain, R range)
|
||||
{
|
||||
super(ctx, Native.mkFuncDecl(ctx.nCtx(), name.getNativeObject(),
|
||||
AST.arrayLength(domain), AST.arrayToNative(domain),
|
||||
range.getNativeObject()));
|
||||
}
|
||||
|
||||
FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range, boolean is_rec)
|
||||
FuncDecl(Context ctx, Symbol name, Sort[] domain, R range, boolean is_rec)
|
||||
{
|
||||
super(ctx, Native.mkRecFuncDecl(ctx.nCtx(), name.getNativeObject(),
|
||||
AST.arrayLength(domain), AST.arrayToNative(domain),
|
||||
|
@ -350,8 +351,7 @@ public class FuncDecl extends AST
|
|||
|
||||
}
|
||||
|
||||
FuncDecl(Context ctx, String prefix, Sort[] domain, Sort range)
|
||||
|
||||
FuncDecl(Context ctx, String prefix, Sort[] domain, R range)
|
||||
{
|
||||
super(ctx, Native.mkFreshFuncDecl(ctx.nCtx(), prefix,
|
||||
AST.arrayLength(domain), AST.arrayToNative(domain),
|
||||
|
@ -371,7 +371,7 @@ public class FuncDecl extends AST
|
|||
/**
|
||||
* Create expression that applies function to arguments.
|
||||
**/
|
||||
public Expr apply(Expr ... args)
|
||||
public Expr<R> apply(Expr<?> ... args)
|
||||
{
|
||||
getContext().checkContextMatch(args);
|
||||
return Expr.create(getContext(), this, args);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue