3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-03-09 23:00:30 +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

@ -22,13 +22,14 @@ package com.microsoft.z3;
* Each entry in the finite map represents the value of a function given a set
* of arguments.
**/
public class FuncInterp extends Z3Object {
@SuppressWarnings("unchecked")
public class FuncInterp<R extends Sort> extends Z3Object {
/**
* An Entry object represents an element in the finite map used to encode a
* function interpretation.
**/
public static class Entry extends Z3Object {
public static class Entry<R extends Sort> extends Z3Object {
/**
* Return the (symbolic) value of this entry.
@ -36,9 +37,9 @@ public class FuncInterp extends Z3Object {
* @throws Z3Exception
* @throws Z3Exception on error
**/
public Expr getValue()
public Expr<R> getValue()
{
return Expr.create(getContext(),
return (Expr<R>) Expr.create(getContext(),
Native.funcEntryGetValue(getContext().nCtx(), getNativeObject()));
}
@ -57,10 +58,10 @@ public class FuncInterp extends Z3Object {
* @throws Z3Exception
* @throws Z3Exception on error
**/
public Expr[] getArgs()
public Expr<?>[] getArgs()
{
int n = getNumArgs();
Expr[] res = new Expr[n];
Expr<?>[] res = new Expr[n];
for (int i = 0; i < n; i++)
res[i] = Expr.create(getContext(), Native.funcEntryGetArg(
getContext().nCtx(), getNativeObject(), i));
@ -75,7 +76,7 @@ public class FuncInterp extends Z3Object {
{
int n = getNumArgs();
String res = "[";
Expr[] args = getArgs();
Expr<?>[] args = getArgs();
for (int i = 0; i < n; i++)
res += args[i] + ", ";
return res + getValue() + "]";
@ -112,12 +113,12 @@ public class FuncInterp extends Z3Object {
* @throws Z3Exception
* @throws Z3Exception on error
**/
public Entry[] getEntries()
public Entry<R>[] getEntries()
{
int n = getNumEntries();
Entry[] res = new Entry[n];
Entry<R>[] res = new Entry[n];
for (int i = 0; i < n; i++)
res[i] = new Entry(getContext(), Native.funcInterpGetEntry(getContext()
res[i] = new Entry<>(getContext(), Native.funcInterpGetEntry(getContext()
.nCtx(), getNativeObject(), i));
return res;
}
@ -129,9 +130,9 @@ public class FuncInterp extends Z3Object {
* @throws Z3Exception on error
* @return an Expr
**/
public Expr getElse()
public Expr<R> getElse()
{
return Expr.create(getContext(),
return (Expr<R>) Expr.create(getContext(),
Native.funcInterpGetElse(getContext().nCtx(), getNativeObject()));
}
@ -152,12 +153,12 @@ public class FuncInterp extends Z3Object {
{
String res = "";
res += "[";
for (Entry e : getEntries())
for (Entry<R> e : getEntries())
{
int n = e.getNumArgs();
if (n > 1)
res += "[";
Expr[] args = e.getArgs();
Expr<?>[] args = e.getArgs();
for (int i = 0; i < n; i++)
{
if (i != 0)