3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-06-25 01:50:33 +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:
Addison Crump 2020-11-30 12:04:54 -06:00 committed by GitHub
parent bb24b3f2be
commit 3bca1fbcd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 2724 additions and 588 deletions

View file

@ -19,12 +19,11 @@ Notes:
package com.microsoft.z3;
import com.microsoft.z3.enumerations.Z3_ast_kind;
/**
* Lambda expressions.
*/public class Lambda extends ArrayExpr
*/
public class Lambda<R extends Sort> extends ArrayExpr<Sort, R>
{
/**
@ -70,9 +69,10 @@ import com.microsoft.z3.enumerations.Z3_ast_kind;
*
* @throws Z3Exception
**/
public Expr getBody()
@SuppressWarnings("unchecked")
public Expr<R> getBody()
{
return Expr.create(getContext(), Native.getQuantifierBody(getContext()
return (Expr<R>) Expr.create(getContext(), Native.getQuantifierBody(getContext()
.nCtx(), getNativeObject()));
}
@ -81,17 +81,17 @@ import com.microsoft.z3.enumerations.Z3_ast_kind;
* Translates (copies) the quantifier to the Context {@code ctx}.
*
* @param ctx A context
*
*
* @return A copy of the quantifier which is associated with {@code ctx}
* @throws Z3Exception on error
**/
public Lambda translate(Context ctx)
public Lambda<R> translate(Context ctx)
{
return (Lambda) super.translate(ctx);
return (Lambda<R>) super.translate(ctx);
}
public static Lambda of(Context ctx, Sort[] sorts, Symbol[] names, Expr body)
public static <R extends Sort> Lambda<R> of(Context ctx, Sort[] sorts, Symbol[] names, Expr<R> body)
{
ctx.checkContextMatch(sorts);
ctx.checkContextMatch(names);
@ -106,7 +106,7 @@ import com.microsoft.z3.enumerations.Z3_ast_kind;
Symbol.arrayToNative(names),
body.getNativeObject());
return new Lambda(ctx, nativeObject);
return new Lambda<>(ctx, nativeObject);
}
/**
@ -115,14 +115,14 @@ import com.microsoft.z3.enumerations.Z3_ast_kind;
* @param body Body of the lambda expression.
*/
public static Lambda of(Context ctx, Expr[] bound, Expr body) {
public static <R extends Sort> Lambda<R> of(Context ctx, Expr<?>[] bound, Expr<R> body) {
ctx.checkContextMatch(body);
long nativeObject = Native.mkLambdaConst(ctx.nCtx(),
AST.arrayLength(bound), AST.arrayToNative(bound),
body.getNativeObject());
return new Lambda(ctx, nativeObject);
return new Lambda<>(ctx, nativeObject);
}