3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-12 12:08:18 +00:00
z3/src/api/java/Params.java
Thomas Haas a3d00ce356
Improved Java phantom references (#7131)
* Reworked phantom reference handling.
 - Replaced IDecRefQueue with a new Z3ReferenceQueue class
 - Z3ReferenceQueue manages custom subclasses of phantom references in a doubly-linked list
 - Replaced all subclasses of IDecRefQueue with subclasses of Z3ReferenceQueue.Reference. These custom reference classes are embedded in the class they reference count.
 - Context now owns a single Z3ReferenceQueue for all types of references.

* Made Statistics.Entry a static subclass

* Made Context.close idempotent (as recommended)

* Update CMakeLists.txt for building the Java API.

* Updated CMakeLists.txt again.

* Use correct SuppressWarning annotation to silence the compiler

* Formatting
2024-02-21 08:39:58 -08:00

150 lines
3.5 KiB
Java

/**
Copyright (c) 2012-2014 Microsoft Corporation
Module Name:
Params.java
Abstract:
Author:
@author Christoph Wintersteiger (cwinter) 2012-03-15
Notes:
**/
package com.microsoft.z3;
import java.lang.ref.ReferenceQueue;
/**
* A ParameterSet represents a configuration in the form of Symbol/value pairs.
**/
public class Params extends Z3Object {
/**
* Adds a parameter setting.
**/
public void add(Symbol name, boolean value)
{
Native.paramsSetBool(getContext().nCtx(), getNativeObject(),
name.getNativeObject(), (value));
}
/**
* Adds a parameter setting.
**/
public void add(Symbol name, double value)
{
Native.paramsSetDouble(getContext().nCtx(), getNativeObject(),
name.getNativeObject(), value);
}
/**
* Adds a parameter setting.
**/
public void add(Symbol name, String value)
{
Native.paramsSetSymbol(getContext().nCtx(), getNativeObject(),
name.getNativeObject(),
getContext().mkSymbol(value).getNativeObject());
}
/**
* Adds a parameter setting.
**/
public void add(Symbol name, Symbol value)
{
Native.paramsSetSymbol(getContext().nCtx(), getNativeObject(),
name.getNativeObject(), value.getNativeObject());
}
/**
* Adds a parameter setting.
**/
public void add(String name, boolean value)
{
Native.paramsSetBool(getContext().nCtx(), getNativeObject(),
getContext().mkSymbol(name).getNativeObject(), value);
}
/**
* Adds a parameter setting.
**/
public void add(String name, int value)
{
Native.paramsSetUint(getContext().nCtx(), getNativeObject(), getContext()
.mkSymbol(name).getNativeObject(), value);
}
/**
* Adds a parameter setting.
**/
public void add(String name, double value)
{
Native.paramsSetDouble(getContext().nCtx(), getNativeObject(), getContext()
.mkSymbol(name).getNativeObject(), value);
}
/**
* Adds a parameter setting.
**/
public void add(String name, Symbol value)
{
Native.paramsSetSymbol(getContext().nCtx(), getNativeObject(), getContext()
.mkSymbol(name).getNativeObject(), value.getNativeObject());
}
/**
* Adds a parameter setting.
**/
public void add(String name, String value)
{
Native.paramsSetSymbol(getContext().nCtx(), getNativeObject(),
getContext().mkSymbol(name).getNativeObject(),
getContext().mkSymbol(value).getNativeObject());
}
/**
* A string representation of the parameter set.
**/
@Override
public String toString()
{
return Native.paramsToString(getContext().nCtx(), getNativeObject());
}
Params(Context ctx)
{
super(ctx, Native.mkParams(ctx.nCtx()));
}
@Override
void incRef() {
Native.paramsIncRef(getContext().nCtx(), getNativeObject());
}
@Override
void addToReferenceQueue() {
getContext().getReferenceQueue().storeReference(this, ParamsRef::new);
}
private static class ParamsRef extends Z3ReferenceQueue.Reference<Params> {
private ParamsRef(Params referent, ReferenceQueue<Z3Object> q) {
super(referent, q);
}
@Override
void decRef(Context ctx, long z3Obj) {
Native.paramsDecRef(ctx.nCtx(), z3Obj);
}
}
}