3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-26 18:45:33 +00:00
z3/src/api/java/Symbol.java
Nikolaj Bjorner ade9b2830a various partial fixes for issue #143
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
2015-07-10 08:16:57 -07:00

105 lines
2.3 KiB
Java

/**
Copyright (c) 2012-2014 Microsoft Corporation
Module Name:
Symbol.java
Abstract:
Author:
@author Christoph Wintersteiger (cwinter) 2012-03-15
Notes:
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.Z3_symbol_kind;
/**
* Symbols are used to name several term and type constructors.
**/
public class Symbol extends Z3Object
{
/**
* The kind of the symbol (int or string)
**/
protected Z3_symbol_kind getKind()
{
return Z3_symbol_kind.fromInt(Native.getSymbolKind(getContext().nCtx(),
getNativeObject()));
}
/**
* Indicates whether the symbol is of Int kind
**/
public boolean isIntSymbol()
{
return getKind() == Z3_symbol_kind.Z3_INT_SYMBOL;
}
/**
* Indicates whether the symbol is of string kind.
**/
public boolean isStringSymbol()
{
return getKind() == Z3_symbol_kind.Z3_STRING_SYMBOL;
}
public boolean equals(Object o)
{
Symbol casted = null;
try {
casted = Symbol.class.cast(o);
}
catch (ClassCastException e) {
return false;
}
return this.getNativeObject() == casted.getNativeObject();
}
/**
* A string representation of the symbol.
**/
public String toString()
{
try
{
if (isIntSymbol())
return Integer.toString(((IntSymbol) this).getInt());
else if (isStringSymbol())
return ((StringSymbol) this).getString();
else
return new String(
"Z3Exception: Unknown symbol kind encountered.");
} catch (Z3Exception ex)
{
return new String("Z3Exception: " + ex.getMessage());
}
}
/**
* Symbol constructor
**/
protected Symbol(Context ctx, long obj)
{
super(ctx, obj);
}
static Symbol create(Context ctx, long obj)
{
switch (Z3_symbol_kind.fromInt(Native.getSymbolKind(ctx.nCtx(), obj)))
{
case Z3_INT_SYMBOL:
return new IntSymbol(ctx, obj);
case Z3_STRING_SYMBOL:
return new StringSymbol(ctx, obj);
default:
throw new Z3Exception("Unknown symbol kind encountered");
}
}
}