mirror of
https://github.com/Z3Prover/z3
synced 2025-04-26 02:25:32 +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
|
@ -20,28 +20,29 @@ package com.microsoft.z3;
|
|||
/**
|
||||
* Enumeration sorts.
|
||||
**/
|
||||
public class EnumSort extends Sort
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EnumSort<R> extends Sort
|
||||
{
|
||||
/**
|
||||
* The function declarations of the constants in the enumeration.
|
||||
* @throws Z3Exception on error
|
||||
**/
|
||||
public FuncDecl[] getConstDecls()
|
||||
public FuncDecl<EnumSort<R>>[] getConstDecls()
|
||||
{
|
||||
int n = Native.getDatatypeSortNumConstructors(getContext().nCtx(), getNativeObject());
|
||||
FuncDecl[] t = new FuncDecl[n];
|
||||
FuncDecl<?>[] t = new FuncDecl[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
t[i] = new FuncDecl(getContext(), Native.getDatatypeSortConstructor(getContext().nCtx(), getNativeObject(), i));
|
||||
return t;
|
||||
t[i] = new FuncDecl<>(getContext(), Native.getDatatypeSortConstructor(getContext().nCtx(), getNativeObject(), i));
|
||||
return (FuncDecl<EnumSort<R>>[]) t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the inx'th constant declaration in the enumeration.
|
||||
* @throws Z3Exception on error
|
||||
**/
|
||||
public FuncDecl getConstDecl(int inx)
|
||||
public FuncDecl<EnumSort<R>> getConstDecl(int inx)
|
||||
{
|
||||
return new FuncDecl(getContext(), Native.getDatatypeSortConstructor(getContext().nCtx(), getNativeObject(), inx));
|
||||
return new FuncDecl<>(getContext(), Native.getDatatypeSortConstructor(getContext().nCtx(), getNativeObject(), inx));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,13 +50,13 @@ public class EnumSort extends Sort
|
|||
* @throws Z3Exception on error
|
||||
* @return an Expr[]
|
||||
**/
|
||||
public Expr[] getConsts()
|
||||
public Expr<EnumSort<R>>[] getConsts()
|
||||
{
|
||||
FuncDecl[] cds = getConstDecls();
|
||||
Expr[] t = new Expr[cds.length];
|
||||
FuncDecl<?>[] cds = getConstDecls();
|
||||
Expr<?>[] t = new Expr[cds.length];
|
||||
for (int i = 0; i < t.length; i++)
|
||||
t[i] = getContext().mkApp(cds[i]);
|
||||
return t;
|
||||
return (Expr<EnumSort<R>>[]) t;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +64,7 @@ public class EnumSort extends Sort
|
|||
* @throws Z3Exception on error
|
||||
* @return an Expr
|
||||
**/
|
||||
public Expr getConst(int inx)
|
||||
public Expr<EnumSort<R>> getConst(int inx)
|
||||
{
|
||||
return getContext().mkApp(getConstDecl(inx));
|
||||
}
|
||||
|
@ -72,12 +73,13 @@ public class EnumSort extends Sort
|
|||
* The test predicates for the constants in the enumeration.
|
||||
* @throws Z3Exception on error
|
||||
**/
|
||||
public FuncDecl[] getTesterDecls()
|
||||
@SuppressWarnings("unchecked")
|
||||
public FuncDecl<BoolSort>[] getTesterDecls()
|
||||
{
|
||||
int n = Native.getDatatypeSortNumConstructors(getContext().nCtx(), getNativeObject());
|
||||
FuncDecl[] t = new FuncDecl[n];
|
||||
FuncDecl<BoolSort>[] t = new FuncDecl[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
t[i] = new FuncDecl(getContext(), Native.getDatatypeSortRecognizer(getContext().nCtx(), getNativeObject(), i));
|
||||
t[i] = new FuncDecl<>(getContext(), Native.getDatatypeSortRecognizer(getContext().nCtx(), getNativeObject(), i));
|
||||
return t;
|
||||
}
|
||||
|
||||
|
@ -85,9 +87,9 @@ public class EnumSort extends Sort
|
|||
* Retrieves the inx'th tester/recognizer declaration in the enumeration.
|
||||
* @throws Z3Exception on error
|
||||
**/
|
||||
public FuncDecl getTesterDecl(int inx)
|
||||
public FuncDecl<BoolSort> getTesterDecl(int inx)
|
||||
{
|
||||
return new FuncDecl(getContext(), Native.getDatatypeSortRecognizer(getContext().nCtx(), getNativeObject(), inx));
|
||||
return new FuncDecl<>(getContext(), Native.getDatatypeSortRecognizer(getContext().nCtx(), getNativeObject(), inx));
|
||||
}
|
||||
|
||||
EnumSort(Context ctx, Symbol name, Symbol[] enumNames)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue