mirror of
https://github.com/Z3Prover/z3
synced 2025-04-26 02:25:32 +00:00
merge
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
commit
b482dbd589
379 changed files with 7440 additions and 3352 deletions
|
@ -87,12 +87,10 @@ public class AST extends Z3Object implements Comparable<AST>
|
|||
**/
|
||||
public AST translate(Context ctx)
|
||||
{
|
||||
|
||||
if (getContext() == ctx) {
|
||||
return this;
|
||||
} else {
|
||||
return new AST(ctx, Native.translate(getContext().nCtx(),
|
||||
getNativeObject(), ctx.nCtx()));
|
||||
return create(ctx, Native.translate(getContext().nCtx(), getNativeObject(), ctx.nCtx()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
236
src/api/java/CMakeLists.txt
Normal file
236
src/api/java/CMakeLists.txt
Normal file
|
@ -0,0 +1,236 @@
|
|||
find_package(Java REQUIRED)
|
||||
find_package(JNI REQUIRED)
|
||||
include(UseJava)
|
||||
|
||||
# Sanity check for dirty source tree
|
||||
foreach (file_name "enumerations" "Native.cpp" "Native.java")
|
||||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
|
||||
message(FATAL_ERROR "\"${CMAKE_CURRENT_SOURCE_DIR}/${file_name}\""
|
||||
${z3_polluted_tree_msg})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(Z3_JAVA_PACKAGE_NAME "com.microsoft.z3")
|
||||
|
||||
# Rule to generate ``Native.java`` and ``Native.cpp``
|
||||
set(Z3_JAVA_NATIVE_JAVA "${CMAKE_CURRENT_BINARY_DIR}/Native.java")
|
||||
set(Z3_JAVA_NATIVE_CPP "${CMAKE_CURRENT_BINARY_DIR}/Native.cpp")
|
||||
add_custom_command(OUTPUT "${Z3_JAVA_NATIVE_JAVA}" "${Z3_JAVA_NATIVE_CPP}"
|
||||
COMMAND "${PYTHON_EXECUTABLE}"
|
||||
"${CMAKE_SOURCE_DIR}/scripts/update_api.py"
|
||||
${Z3_FULL_PATH_API_HEADER_FILES_TO_SCAN}
|
||||
"--java-output-dir"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
"--java-package-name"
|
||||
${Z3_JAVA_PACKAGE_NAME}
|
||||
DEPENDS
|
||||
${Z3_FULL_PATH_API_HEADER_FILES_TO_SCAN}
|
||||
"${CMAKE_SOURCE_DIR}/scripts/update_api.py"
|
||||
${Z3_GENERATED_FILE_EXTRA_DEPENDENCIES}
|
||||
# FIXME: When update_api.py no longer uses ``mk_util`` drop this dependency
|
||||
"${CMAKE_SOURCE_DIR}/scripts/mk_util.py"
|
||||
COMMENT "Generating \"${Z3_JAVA_NATIVE_JAVA}\" and \"${Z3_JAVA_NATIVE_CPP}\""
|
||||
${ADD_CUSTOM_COMMAND_USES_TERMINAL_ARG}
|
||||
)
|
||||
|
||||
# Add rule to build native code that provides a bridge between
|
||||
# ``Native.java`` and libz3's interfac3.
|
||||
add_library(z3java SHARED ${Z3_JAVA_NATIVE_CPP})
|
||||
target_link_libraries(z3java PRIVATE libz3)
|
||||
# FIXME:
|
||||
# Not sure if using all the flags used by the Z3 components is really necessary
|
||||
# here. At the bare minimum setting _AMD64_ depending on the target is
|
||||
# necessary but seeing as the Python build system uses all the flags used for building
|
||||
# Z3's components to build ``Native.cpp`` lets do the same for now.
|
||||
target_compile_options(z3java PRIVATE ${Z3_COMPONENT_CXX_FLAGS})
|
||||
target_compile_definitions(z3java PRIVATE ${Z3_COMPONENT_CXX_DEFINES})
|
||||
target_include_directories(z3java PRIVATE
|
||||
"${CMAKE_SOURCE_DIR}/src/api"
|
||||
"${CMAKE_BINARY_DIR}/src/api"
|
||||
${JNI_INCLUDE_DIRS}
|
||||
)
|
||||
# FIXME: Should this library have SONAME and VERSION set?
|
||||
|
||||
# This prevents CMake from automatically defining ``z3java_EXPORTS``
|
||||
set_property(TARGET z3java PROPERTY DEFINE_SYMBOL "")
|
||||
|
||||
# Rule to generate the ``com.microsoft.z3.enumerations`` package
|
||||
# FIXME: This list of files is fragile
|
||||
set(Z3_JAVA_ENUMERATION_PACKAGE_FILES
|
||||
Z3_ast_kind.java
|
||||
Z3_ast_print_mode.java
|
||||
Z3_decl_kind.java
|
||||
Z3_error_code.java
|
||||
Z3_goal_prec.java
|
||||
Z3_lbool.java
|
||||
Z3_param_kind.java
|
||||
Z3_parameter_kind.java
|
||||
Z3_sort_kind.java
|
||||
Z3_symbol_kind.java
|
||||
)
|
||||
set(Z3_JAVA_ENUMERATION_PACKAGE_FILES_FULL_PATH "")
|
||||
foreach (enum_file ${Z3_JAVA_ENUMERATION_PACKAGE_FILES})
|
||||
list(APPEND Z3_JAVA_ENUMERATION_PACKAGE_FILES_FULL_PATH
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/enumerations/${enum_file}"
|
||||
)
|
||||
endforeach()
|
||||
add_custom_command(OUTPUT ${Z3_JAVA_ENUMERATION_PACKAGE_FILES_FULL_PATH}
|
||||
COMMAND "${PYTHON_EXECUTABLE}"
|
||||
"${CMAKE_SOURCE_DIR}/scripts/mk_consts_files.py"
|
||||
${Z3_FULL_PATH_API_HEADER_FILES_TO_SCAN}
|
||||
"--java-output-dir"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
"--java-package-name"
|
||||
${Z3_JAVA_PACKAGE_NAME}
|
||||
DEPENDS
|
||||
${Z3_FULL_PATH_API_HEADER_FILES_TO_SCAN}
|
||||
"${CMAKE_SOURCE_DIR}/scripts/mk_consts_files.py"
|
||||
${Z3_GENERATED_FILE_EXTRA_DEPENDENCIES}
|
||||
COMMENT "Generating ${Z3_JAVA_PACKAGE_NAME}.enumerations package"
|
||||
${ADD_CUSTOM_COMMAND_USES_TERMINAL_ARG}
|
||||
)
|
||||
|
||||
set(Z3_JAVA_JAR_SOURCE_FILES
|
||||
AlgebraicNum.java
|
||||
ApplyResultDecRefQueue.java
|
||||
ApplyResult.java
|
||||
ArithExpr.java
|
||||
ArithSort.java
|
||||
ArrayExpr.java
|
||||
ArraySort.java
|
||||
ASTDecRefQueue.java
|
||||
AST.java
|
||||
AstMapDecRefQueue.java
|
||||
ASTMap.java
|
||||
AstVectorDecRefQueue.java
|
||||
ASTVector.java
|
||||
BitVecExpr.java
|
||||
BitVecNum.java
|
||||
BitVecSort.java
|
||||
BoolExpr.java
|
||||
BoolSort.java
|
||||
ConstructorDecRefQueue.java
|
||||
Constructor.java
|
||||
ConstructorListDecRefQueue.java
|
||||
ConstructorList.java
|
||||
Context.java
|
||||
DatatypeExpr.java
|
||||
DatatypeSort.java
|
||||
EnumSort.java
|
||||
Expr.java
|
||||
FiniteDomainExpr.java
|
||||
FiniteDomainNum.java
|
||||
FiniteDomainSort.java
|
||||
FixedpointDecRefQueue.java
|
||||
Fixedpoint.java
|
||||
FPExpr.java
|
||||
FPNum.java
|
||||
FPRMExpr.java
|
||||
FPRMNum.java
|
||||
FPRMSort.java
|
||||
FPSort.java
|
||||
FuncDecl.java
|
||||
FuncInterpDecRefQueue.java
|
||||
FuncInterpEntryDecRefQueue.java
|
||||
FuncInterp.java
|
||||
Global.java
|
||||
GoalDecRefQueue.java
|
||||
Goal.java
|
||||
IDecRefQueue.java
|
||||
InterpolationContext.java
|
||||
IntExpr.java
|
||||
IntNum.java
|
||||
IntSort.java
|
||||
IntSymbol.java
|
||||
ListSort.java
|
||||
Log.java
|
||||
ModelDecRefQueue.java
|
||||
Model.java
|
||||
OptimizeDecRefQueue.java
|
||||
Optimize.java
|
||||
ParamDescrsDecRefQueue.java
|
||||
ParamDescrs.java
|
||||
ParamsDecRefQueue.java
|
||||
Params.java
|
||||
Pattern.java
|
||||
ProbeDecRefQueue.java
|
||||
Probe.java
|
||||
Quantifier.java
|
||||
RatNum.java
|
||||
RealExpr.java
|
||||
RealSort.java
|
||||
ReExpr.java
|
||||
RelationSort.java
|
||||
ReSort.java
|
||||
SeqExpr.java
|
||||
SeqSort.java
|
||||
SetSort.java
|
||||
SolverDecRefQueue.java
|
||||
Solver.java
|
||||
Sort.java
|
||||
StatisticsDecRefQueue.java
|
||||
Statistics.java
|
||||
Status.java
|
||||
StringSymbol.java
|
||||
Symbol.java
|
||||
TacticDecRefQueue.java
|
||||
Tactic.java
|
||||
TupleSort.java
|
||||
UninterpretedSort.java
|
||||
Version.java
|
||||
Z3Exception.java
|
||||
Z3Object.java
|
||||
)
|
||||
set(Z3_JAVA_JAR_SOURCE_FILES_FULL_PATH "")
|
||||
foreach (java_src_file ${Z3_JAVA_JAR_SOURCE_FILES})
|
||||
list(APPEND Z3_JAVA_JAR_SOURCE_FILES_FULL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${java_src_file}")
|
||||
endforeach()
|
||||
# Add generated files to list
|
||||
list(APPEND Z3_JAVA_JAR_SOURCE_FILES_FULL_PATH
|
||||
${Z3_JAVA_NATIVE_JAVA}
|
||||
${Z3_JAVA_ENUMERATION_PACKAGE_FILES_FULL_PATH}
|
||||
)
|
||||
|
||||
# Convenient top-level target
|
||||
add_custom_target(build_z3_java_bindings
|
||||
ALL
|
||||
DEPENDS
|
||||
z3java
|
||||
z3JavaJar
|
||||
)
|
||||
|
||||
# Rule to build ``com.microsoft.z3.jar``
|
||||
# TODO: Should we set ``CMAKE_JNI_TARGET`` to ``TRUE``?
|
||||
add_jar(z3JavaJar
|
||||
SOURCES ${Z3_JAVA_JAR_SOURCE_FILES_FULL_PATH}
|
||||
OUTPUT_NAME ${Z3_JAVA_PACKAGE_NAME}
|
||||
OUTPUT_DIR "${CMAKE_BINARY_DIR}"
|
||||
VERSION "${Z3_VERSION}"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Install
|
||||
###############################################################################
|
||||
option(INSTALL_JAVA_BINDINGS "Install Java bindings when invoking install target" ON)
|
||||
if (INSTALL_JAVA_BINDINGS)
|
||||
# Provide cache variables for the install locations that the user can change.
|
||||
# This defaults to ``/usr/local/java`` which seems to be the location for ``.jar``
|
||||
# files on Linux distributions
|
||||
set(Z3_JAVA_JAR_INSTALLDIR
|
||||
"${CMAKE_INSTALL_DATAROOTDIR}/java"
|
||||
CACHE
|
||||
PATH
|
||||
"Directory to install Z3 Java jar file relative to install prefix"
|
||||
)
|
||||
# FIXME: I don't think this the right installation location
|
||||
set(Z3_JAVA_JNI_LIB_INSTALLDIR
|
||||
"${CMAKE_INSTALL_LIBDIR}"
|
||||
CACHE
|
||||
PATH
|
||||
"Directory to install Z3 Java JNI bridge library relative to install prefix"
|
||||
)
|
||||
install(TARGETS z3java DESTINATION "${Z3_JAVA_JNI_LIB_INSTALLDIR}")
|
||||
# Note: Don't use ``DESTINATION`` here as the version of ``UseJava.cmake`` shipped
|
||||
# with CMake 2.8.12.2 handles that incorrectly.
|
||||
install_jar(z3JavaJar "${Z3_JAVA_JAR_INSTALLDIR}")
|
||||
endif()
|
|
@ -25,6 +25,12 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* The main interaction with Z3 happens via the Context.
|
||||
* For applications that spawn an unbounded number of contexts,
|
||||
* the proper use is within a try-with-resources
|
||||
* scope so that the Context object gets garbage collected in
|
||||
* a predictable way. Contexts maintain all data-structures
|
||||
* related to terms and formulas that are created relative
|
||||
* to them.
|
||||
**/
|
||||
public class Context implements AutoCloseable {
|
||||
private final long m_ctx;
|
||||
|
|
|
@ -194,14 +194,7 @@ public class Expr extends AST
|
|||
**/
|
||||
public Expr translate(Context ctx)
|
||||
{
|
||||
if (getContext() == ctx) {
|
||||
return this;
|
||||
} else {
|
||||
return Expr.create(
|
||||
ctx,
|
||||
Native.translate(getContext().nCtx(), getNativeObject(),
|
||||
ctx.nCtx()));
|
||||
}
|
||||
return (Expr) super.translate(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1297,6 +1290,15 @@ public class Expr extends AST
|
|||
return Native.getString(getContext().nCtx(), getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether expression is a concatenation
|
||||
* @return a boolean
|
||||
*/
|
||||
public boolean isConcat()
|
||||
{
|
||||
return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_SEQ_CONCAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the term is a binary equivalence modulo namings.
|
||||
* Remarks: This binary predicate is used in proof terms. It captures
|
||||
|
|
|
@ -88,6 +88,7 @@ public class Fixedpoint extends Z3Object
|
|||
/**
|
||||
* Add rule into the fixedpoint solver.
|
||||
*
|
||||
* @param rule implication (Horn clause) representing rule
|
||||
* @param name Nullable rule name.
|
||||
* @throws Z3Exception
|
||||
**/
|
||||
|
@ -178,6 +179,7 @@ public class Fixedpoint extends Z3Object
|
|||
/**
|
||||
* Update named rule into in the fixedpoint solver.
|
||||
*
|
||||
* @param rule implication (Horn clause) representing rule
|
||||
* @param name Nullable rule name.
|
||||
* @throws Z3Exception
|
||||
**/
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
Copyright (c) 2012-2014 Microsoft Corporation
|
||||
|
||||
|
||||
Module Name:
|
||||
|
||||
FuncDecl.java
|
||||
|
@ -12,8 +12,8 @@ Author:
|
|||
@author Christoph Wintersteiger (cwinter) 2012-03-15
|
||||
|
||||
Notes:
|
||||
|
||||
**/
|
||||
|
||||
**/
|
||||
|
||||
package com.microsoft.z3;
|
||||
|
||||
|
@ -59,6 +59,18 @@ public class FuncDecl extends AST
|
|||
return Native.getFuncDeclId(getContext().nCtx(), getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates (copies) the function declaration to the Context {@code ctx}.
|
||||
* @param ctx A context
|
||||
*
|
||||
* @return A copy of the function declaration which is associated with {@code ctx}
|
||||
* @throws Z3Exception on error
|
||||
**/
|
||||
public FuncDecl translate(Context ctx)
|
||||
{
|
||||
return (FuncDecl) super.translate(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* The arity of the function declaration
|
||||
**/
|
||||
|
@ -68,7 +80,7 @@ public class FuncDecl extends AST
|
|||
}
|
||||
|
||||
/**
|
||||
* The size of the domain of the function declaration
|
||||
* The size of the domain of the function declaration
|
||||
* @see #getArity
|
||||
**/
|
||||
public int getDomainSize()
|
||||
|
@ -324,7 +336,7 @@ public class FuncDecl extends AST
|
|||
}
|
||||
|
||||
FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range)
|
||||
|
||||
|
||||
{
|
||||
super(ctx, Native.mkFuncDecl(ctx.nCtx(), name.getNativeObject(),
|
||||
AST.arrayLength(domain), AST.arrayToNative(domain),
|
||||
|
@ -333,7 +345,7 @@ public class FuncDecl extends AST
|
|||
}
|
||||
|
||||
FuncDecl(Context ctx, String prefix, Sort[] domain, Sort range)
|
||||
|
||||
|
||||
{
|
||||
super(ctx, Native.mkFreshFuncDecl(ctx.nCtx(), prefix,
|
||||
AST.arrayLength(domain), AST.arrayToNative(domain),
|
||||
|
@ -351,7 +363,7 @@ public class FuncDecl extends AST
|
|||
}
|
||||
|
||||
/**
|
||||
* Create expression that applies function to arguments.
|
||||
* Create expression that applies function to arguments.
|
||||
**/
|
||||
public Expr apply(Expr ... args)
|
||||
{
|
||||
|
|
|
@ -145,6 +145,19 @@ public class Quantifier extends BoolExpr
|
|||
.nCtx(), getNativeObject()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates (copies) the quantifier to the Context {@code ctx}.
|
||||
*
|
||||
* @param ctx A context
|
||||
*
|
||||
* @return A copy of the quantifier which is associated with {@code ctx}
|
||||
* @throws Z3Exception on error
|
||||
**/
|
||||
public Quantifier translate(Context ctx)
|
||||
{
|
||||
return (Quantifier) super.translate(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a quantified expression.
|
||||
*
|
||||
|
|
|
@ -87,6 +87,19 @@ public class Sort extends AST
|
|||
return Native.sortToString(getContext().nCtx(), getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates (copies) the sort to the Context {@code ctx}.
|
||||
*
|
||||
* @param ctx A context
|
||||
*
|
||||
* @return A copy of the sort which is associated with {@code ctx}
|
||||
* @throws Z3Exception on error
|
||||
**/
|
||||
public Sort translate(Context ctx)
|
||||
{
|
||||
return (Sort) super.translate(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort constructor
|
||||
**/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue