3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-10-28 10:19:23 +00:00

Dispose of intermediate Z3Objects created in dotnet api. (#5901)

* Dispose of intermediate Z3Objects created in dotnet api.

* Set C# LangVersion to 8.0.

* Fix build errors.

* Fix warning about empty using statement.

* Fix Xor to only dispose of objects that it creates internally.
This commit is contained in:
Matt Thornton 2022-03-17 15:08:05 +00:00 committed by GitHub
parent bdf7de1703
commit 4e0a2f5968
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 360 additions and 142 deletions

View file

@ -22,7 +22,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Microsoft.Z3
{
/// <summary>
@ -41,24 +40,48 @@ namespace Microsoft.Z3
#region Operators
private static ArithExpr MkNum(ArithExpr e, int i) { return (ArithExpr)e.Context.MkNumeral(i, e.Context.MkIntSort()); }
private static ArithExpr MkNum(ArithExpr e, int i)
{
using var sort = e.Context.MkIntSort();
return (ArithExpr)e.Context.MkNumeral(i, sort);
}
private static ArithExpr MkNum(ArithExpr e, double d) { return (ArithExpr)e.Context.MkNumeral(d.ToString(), e.Context.MkRealSort()); }
private static ArithExpr MkNum(ArithExpr e, double d)
{
using var sort = e.Context.MkRealSort();
return (ArithExpr)e.Context.MkNumeral(d.ToString(), sort);
}
/// <summary> Operator overloading for arithmetical division operator (over reals) </summary>
public static ArithExpr operator /(ArithExpr a, ArithExpr b) { return a.Context.MkDiv(a, b); }
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator /(ArithExpr a, int b) { return a / MkNum(a, b); }
public static ArithExpr operator /(ArithExpr a, int b)
{
using var denominator = MkNum(a, b);
return a / denominator;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator /(ArithExpr a, double b) { return a / MkNum(a, b); }
public static ArithExpr operator /(ArithExpr a, double b)
{
using var denominator = MkNum(a, b);
return a / denominator;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator /(int a, ArithExpr b) { return MkNum(b, a) / b; }
public static ArithExpr operator /(int a, ArithExpr b)
{
using var numerator = MkNum(b, a);
return numerator / b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator /(double a, ArithExpr b) { return MkNum(b, a) / b; }
public static ArithExpr operator /(double a, ArithExpr b)
{
using var numerator = MkNum(b, a);
return numerator / b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator -(ArithExpr a) { return a.Context.MkUnaryMinus(a); }
@ -67,106 +90,218 @@ namespace Microsoft.Z3
public static ArithExpr operator -(ArithExpr a, ArithExpr b) { return a.Context.MkSub(a, b); }
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator -(ArithExpr a, int b) { return a - MkNum(a, b); }
public static ArithExpr operator -(ArithExpr a, int b)
{
using var rhs = MkNum(a, b);
return a - rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator -(ArithExpr a, double b) { return a - MkNum(a, b); }
public static ArithExpr operator -(ArithExpr a, double b)
{
using var rhs = MkNum(a, b);
return a - rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator -(int a, ArithExpr b) { return MkNum(b, a) - b; }
public static ArithExpr operator -(int a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs - b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator -(double a, ArithExpr b) { return MkNum(b, a) - b; }
public static ArithExpr operator -(double a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs - b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator +(ArithExpr a, ArithExpr b) { return a.Context.MkAdd(a, b); }
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator +(ArithExpr a, int b) { return a + MkNum(a, b); }
public static ArithExpr operator +(ArithExpr a, int b)
{
using var rhs = MkNum(a, b);
return a + rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator +(ArithExpr a, double b) { return a + MkNum(a, b); }
public static ArithExpr operator +(ArithExpr a, double b)
{
using var rhs = MkNum(a, b);
return a + rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator +(int a, ArithExpr b) { return MkNum(b, a) + b; }
public static ArithExpr operator +(int a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs + b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator +(double a, ArithExpr b) { return MkNum(b, a) + b; }
public static ArithExpr operator +(double a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs + b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator *(ArithExpr a, ArithExpr b) { return a.Context.MkMul(a, b); }
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator *(ArithExpr a, int b) { return a * MkNum(a, b); }
public static ArithExpr operator *(ArithExpr a, int b)
{
using var rhs = MkNum(a, b);
return a * rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator *(ArithExpr a, double b) { return a * MkNum(a, b); }
public static ArithExpr operator *(ArithExpr a, double b)
{
using var rhs = MkNum(a, b);
return a * rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator *(int a, ArithExpr b) { return MkNum(b, a) * b; }
public static ArithExpr operator *(int a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs * b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static ArithExpr operator *(double a, ArithExpr b) { return MkNum(b, a) * b; }
public static ArithExpr operator *(double a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs * b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <=(ArithExpr a, ArithExpr b) { return a.Context.MkLe(a, b); }
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <=(ArithExpr a, int b) { return a <= MkNum(a, b); }
public static BoolExpr operator <=(ArithExpr a, int b)
{
using var rhs = MkNum(a, b);
return a <= rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <=(ArithExpr a, double b) { return a <= MkNum(a, b); }
public static BoolExpr operator <=(ArithExpr a, double b)
{
using var rhs = MkNum(a, b);
return a <= rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <=(int a, ArithExpr b) { return MkNum(b, a) <= b; }
public static BoolExpr operator <=(int a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs <= b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <=(double a, ArithExpr b) { return MkNum(b, a) <= b; }
public static BoolExpr operator <=(double a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs <= b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <(ArithExpr a, ArithExpr b) { return a.Context.MkLt(a, b); }
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <(ArithExpr a, int b) { return a < MkNum(a, b); }
public static BoolExpr operator <(ArithExpr a, int b)
{
using var rhs = MkNum(a, b);
return a < rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <(ArithExpr a, double b) { return a < MkNum(a, b); }
public static BoolExpr operator <(ArithExpr a, double b)
{
using var rhs = MkNum(a, b);
return a < rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <(int a, ArithExpr b) { return MkNum(b, a) < b; }
public static BoolExpr operator <(int a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs < b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator <(double a, ArithExpr b) { return MkNum(b, a) < b; }
public static BoolExpr operator <(double a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs < b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >(ArithExpr a, ArithExpr b) { return a.Context.MkGt(a, b); }
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >(ArithExpr a, int b) { return a > MkNum(a, b); }
public static BoolExpr operator >(ArithExpr a, int b)
{
using var rhs = MkNum(a, b);
return a > rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >(ArithExpr a, double b) { return a > MkNum(a, b); }
public static BoolExpr operator >(ArithExpr a, double b)
{
using var rhs = MkNum(a, b);
return a > rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >(int a, ArithExpr b) { return MkNum(b, a) > b; }
public static BoolExpr operator >(int a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs > b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >(double a, ArithExpr b) { return MkNum(b, a) > b; }
public static BoolExpr operator >(double a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs > b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(ArithExpr a, ArithExpr b) { return a.Context.MkGe(a, b); }
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(ArithExpr a, int b) { return a >= MkNum(a, b); }
public static BoolExpr operator >=(ArithExpr a, int b)
{
using var rhs = MkNum(a, b);
return a >= rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(ArithExpr a, double b) { return a >= MkNum(a, b); }
public static BoolExpr operator >=(ArithExpr a, double b)
{
using var rhs = MkNum(a, b);
return a >= rhs;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(int a, ArithExpr b) { return MkNum(b, a) >= b; }
public static BoolExpr operator >=(int a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs >= b;
}
/// <summary> Operator overloading for arithmetical operator </summary>
public static BoolExpr operator >=(double a, ArithExpr b) { return MkNum(b, a) >= b; }
public static BoolExpr operator >=(double a, ArithExpr b)
{
using var lhs = MkNum(b, a);
return lhs >= b;
}
#endregion
}