mirror of
https://github.com/Z3Prover/z3
synced 2025-04-27 10:55:50 +00:00
Merge branch 'master' of github.com:dennis714/z3
This commit is contained in:
commit
345c0c796b
127 changed files with 551 additions and 411 deletions
143
src/api/python/CMakeLists.txt
Normal file
143
src/api/python/CMakeLists.txt
Normal file
|
@ -0,0 +1,143 @@
|
|||
message(STATUS "Emitting rules to build Z3 python bindings")
|
||||
###############################################################################
|
||||
# Add target to build python bindings for the build directory
|
||||
###############################################################################
|
||||
# This allows the python bindings to be used directly from the build directory
|
||||
set(z3py_files
|
||||
z3/__init__.py
|
||||
z3/z3.py
|
||||
z3/z3num.py
|
||||
z3/z3poly.py
|
||||
z3/z3printer.py
|
||||
z3/z3rcf.py
|
||||
z3test.py
|
||||
z3/z3types.py
|
||||
z3/z3util.py
|
||||
)
|
||||
|
||||
set(z3py_bindings_build_dest "${CMAKE_BINARY_DIR}/python")
|
||||
file(MAKE_DIRECTORY "${z3py_bindings_build_dest}")
|
||||
file(MAKE_DIRECTORY "${z3py_bindings_build_dest}/z3")
|
||||
|
||||
set(build_z3_python_bindings_target_depends "")
|
||||
foreach (z3py_file ${z3py_files})
|
||||
add_custom_command(OUTPUT "${z3py_bindings_build_dest}/${z3py_file}"
|
||||
COMMAND "${CMAKE_COMMAND}" "-E" "copy"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${z3py_file}"
|
||||
"${z3py_bindings_build_dest}/${z3py_file}"
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${z3py_file}"
|
||||
COMMENT "Copying \"${z3py_file}\" to ${z3py_bindings_build_dest}/${z3py_file}"
|
||||
)
|
||||
list(APPEND build_z3_python_bindings_target_depends "${z3py_bindings_build_dest}/${z3py_file}")
|
||||
endforeach()
|
||||
|
||||
# Generate z3core.py
|
||||
add_custom_command(OUTPUT "${z3py_bindings_build_dest}/z3/z3core.py"
|
||||
COMMAND "${PYTHON_EXECUTABLE}"
|
||||
"${CMAKE_SOURCE_DIR}/scripts/update_api.py"
|
||||
${Z3_FULL_PATH_API_HEADER_FILES_TO_SCAN}
|
||||
"--z3py-output-dir"
|
||||
"${z3py_bindings_build_dest}"
|
||||
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 z3core.py"
|
||||
${ADD_CUSTOM_COMMAND_USES_TERMINAL_ARG}
|
||||
)
|
||||
list(APPEND build_z3_python_bindings_target_depends "${z3py_bindings_build_dest}/z3/z3core.py")
|
||||
|
||||
# Generate z3consts.py
|
||||
add_custom_command(OUTPUT "${z3py_bindings_build_dest}/z3/z3consts.py"
|
||||
COMMAND "${PYTHON_EXECUTABLE}"
|
||||
"${CMAKE_SOURCE_DIR}/scripts/mk_consts_files.py"
|
||||
${Z3_FULL_PATH_API_HEADER_FILES_TO_SCAN}
|
||||
"--z3py-output-dir"
|
||||
"${z3py_bindings_build_dest}"
|
||||
DEPENDS
|
||||
${Z3_FULL_PATH_API_HEADER_FILES_TO_SCAN}
|
||||
"${CMAKE_SOURCE_DIR}/scripts/mk_consts_files.py"
|
||||
${Z3_GENERATED_FILE_EXTRA_DEPENDENCIES}
|
||||
COMMENT "Generating z3consts.py"
|
||||
${ADD_CUSTOM_COMMAND_USES_TERMINAL_ARG}
|
||||
)
|
||||
list(APPEND build_z3_python_bindings_target_depends "${z3py_bindings_build_dest}/z3/z3consts.py")
|
||||
|
||||
if (UNIX)
|
||||
set(LINK_COMMAND "create_symlink")
|
||||
else()
|
||||
set(LINK_COMMAND "copy")
|
||||
endif()
|
||||
|
||||
# Link libz3 into the python directory so bindings work out of the box
|
||||
add_custom_command(OUTPUT "${z3py_bindings_build_dest}/libz3${CMAKE_SHARED_MODULE_SUFFIX}"
|
||||
COMMAND "${CMAKE_COMMAND}" "-E" "${LINK_COMMAND}"
|
||||
"${CMAKE_BINARY_DIR}/libz3${CMAKE_SHARED_MODULE_SUFFIX}"
|
||||
"${z3py_bindings_build_dest}/libz3${CMAKE_SHARED_MODULE_SUFFIX}"
|
||||
DEPENDS libz3
|
||||
COMMENT "Linking libz3 into python directory"
|
||||
)
|
||||
|
||||
# Convenient top-level target
|
||||
add_custom_target(build_z3_python_bindings
|
||||
ALL
|
||||
DEPENDS
|
||||
${build_z3_python_bindings_target_depends}
|
||||
"${z3py_bindings_build_dest}/libz3${CMAKE_SHARED_MODULE_SUFFIX}"
|
||||
)
|
||||
|
||||
###############################################################################
|
||||
# Install
|
||||
###############################################################################
|
||||
option(INSTALL_PYTHON_BINDINGS "Install Python bindings when invoking install target" ON)
|
||||
if (INSTALL_PYTHON_BINDINGS)
|
||||
message(STATUS "Emitting rules to install Z3 python bindings")
|
||||
# Try to guess the installation path for the bindings
|
||||
if (NOT DEFINED CMAKE_INSTALL_PYTHON_PKG_DIR)
|
||||
message(STATUS "CMAKE_INSTALL_PYTHON_PKG_DIR not set. Trying to guess")
|
||||
execute_process(
|
||||
COMMAND "${PYTHON_EXECUTABLE}" "-c"
|
||||
"import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())"
|
||||
RESULT_VARIABLE exit_code
|
||||
OUTPUT_VARIABLE CMAKE_INSTALL_PYTHON_PKG_DIR
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
if (NOT ("${exit_code}" EQUAL 0))
|
||||
message(FATAL_ERROR "Failed to determine your Python package directory")
|
||||
endif()
|
||||
message(STATUS "Detected Python package directory: \"${CMAKE_INSTALL_PYTHON_PKG_DIR}\"")
|
||||
# Set a cache variable that the user can modify if needed
|
||||
set(CMAKE_INSTALL_PYTHON_PKG_DIR
|
||||
"${CMAKE_INSTALL_PYTHON_PKG_DIR}"
|
||||
CACHE PATH
|
||||
"Path to install python bindings. This can be relative or absolute.")
|
||||
mark_as_advanced(CMAKE_INSTALL_PYTHON_PKG_DIR)
|
||||
else()
|
||||
message(STATUS "CMAKE_INSTALL_PYTHON_PKG_DIR already set (\"${CMAKE_INSTALL_PYTHON_PKG_DIR}\")"
|
||||
". Not trying to guess.")
|
||||
endif()
|
||||
|
||||
# Check if path exists under the install prefix if it is absolute. If the
|
||||
# path is relative it will be installed under the install prefix so there
|
||||
# if nothing to check
|
||||
if (IS_ABSOLUTE "${CMAKE_INSTALL_PYTHON_PKG_DIR}")
|
||||
string(FIND "${CMAKE_INSTALL_PYTHON_PKG_DIR}" "${CMAKE_INSTALL_PREFIX}" position)
|
||||
if (NOT ("${position}" EQUAL 0))
|
||||
message(WARNING "The directory to install the python bindings \"${CMAKE_INSTALL_PYTHON_PKG_DIR}\" "
|
||||
"is not under the install prefix \"${CMAKE_INSTALL_PREFIX}\"."
|
||||
" Running the install target may lead to a broken installation. "
|
||||
"To change the install directory modify the CMAKE_INSTALL_PYTHON_PKG_DIR cache variable."
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
# Using DESTDIR still seems to work even if we use an absolute path
|
||||
message(STATUS "Python bindings will be installed to \"${CMAKE_INSTALL_PYTHON_PKG_DIR}\"")
|
||||
install(FILES ${build_z3_python_bindings_target_depends}
|
||||
DESTINATION "${CMAKE_INSTALL_PYTHON_PKG_DIR}/z3"
|
||||
)
|
||||
else()
|
||||
message(STATUS "Not emitting rules to install Z3 python bindings")
|
||||
endif()
|
|
@ -50,6 +50,7 @@ from fractions import Fraction
|
|||
import sys
|
||||
import io
|
||||
import math
|
||||
import copy
|
||||
|
||||
if sys.version < '3':
|
||||
def _is_int(v):
|
||||
|
@ -288,6 +289,9 @@ class AstRef(Z3PPObject):
|
|||
if self.ctx.ref() is not None:
|
||||
Z3_dec_ref(self.ctx.ref(), self.as_ast())
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return _to_ast_ref(self.ast, self.ctx)
|
||||
|
||||
def __str__(self):
|
||||
return obj_to_string(self)
|
||||
|
||||
|
@ -4357,6 +4361,11 @@ class Datatype:
|
|||
self.name = name
|
||||
self.constructors = []
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
r = Datatype(self.name, self.ctx)
|
||||
r.constructors = copy.deepcopy(self.constructors)
|
||||
return r
|
||||
|
||||
def declare_core(self, name, rec_name, *args):
|
||||
if __debug__:
|
||||
_z3_assert(isinstance(name, str), "String expected")
|
||||
|
@ -4647,11 +4656,17 @@ class ParamsRef:
|
|||
|
||||
Consider using the function `args2params` to create instances of this object.
|
||||
"""
|
||||
def __init__(self, ctx=None):
|
||||
def __init__(self, ctx=None, params=None):
|
||||
self.ctx = _get_ctx(ctx)
|
||||
self.params = Z3_mk_params(self.ctx.ref())
|
||||
if params is None:
|
||||
self.params = Z3_mk_params(self.ctx.ref())
|
||||
else:
|
||||
self.params = params
|
||||
Z3_params_inc_ref(self.ctx.ref(), self.params)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return ParamsRef(self.ctx, self.params)
|
||||
|
||||
def __del__(self):
|
||||
if self.ctx.ref() is not None:
|
||||
Z3_params_dec_ref(self.ctx.ref(), self.params)
|
||||
|
@ -4711,6 +4726,9 @@ class ParamDescrsRef:
|
|||
self.descr = descr
|
||||
Z3_param_descrs_inc_ref(self.ctx.ref(), self.descr)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return ParamsDescrsRef(self.descr, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.ctx.ref() is not None:
|
||||
Z3_param_descrs_dec_ref(self.ctx.ref(), self.descr)
|
||||
|
@ -4772,6 +4790,9 @@ class Goal(Z3PPObject):
|
|||
self.goal = Z3_mk_goal(self.ctx.ref(), models, unsat_cores, proofs)
|
||||
Z3_goal_inc_ref(self.ctx.ref(), self.goal)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return Goal(False, False, False, self.ctx, self.goal)
|
||||
|
||||
def __del__(self):
|
||||
if self.goal is not None and self.ctx.ref() is not None:
|
||||
Z3_goal_dec_ref(self.ctx.ref(), self.goal)
|
||||
|
@ -5034,6 +5055,9 @@ class AstVector(Z3PPObject):
|
|||
self.ctx = ctx
|
||||
Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return AstVector(self.vector, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.vector is not None and self.ctx.ref() is not None:
|
||||
Z3_ast_vector_dec_ref(self.ctx.ref(), self.vector)
|
||||
|
@ -5169,6 +5193,9 @@ class AstMap:
|
|||
self.ctx = ctx
|
||||
Z3_ast_map_inc_ref(self.ctx.ref(), self.map)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return AstMap(self.map, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.map is not None and self.ctx.ref() is not None:
|
||||
Z3_ast_map_dec_ref(self.ctx.ref(), self.map)
|
||||
|
@ -5284,6 +5311,9 @@ class FuncEntry:
|
|||
self.ctx = ctx
|
||||
Z3_func_entry_inc_ref(self.ctx.ref(), self.entry)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return FuncEntry(self.entry, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.ctx.ref() is not None:
|
||||
Z3_func_entry_dec_ref(self.ctx.ref(), self.entry)
|
||||
|
@ -5390,6 +5420,9 @@ class FuncInterp(Z3PPObject):
|
|||
if self.f is not None:
|
||||
Z3_func_interp_inc_ref(self.ctx.ref(), self.f)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return FuncInterp(self.f, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.f is not None and self.ctx.ref() is not None:
|
||||
Z3_func_interp_dec_ref(self.ctx.ref(), self.f)
|
||||
|
@ -5500,6 +5533,9 @@ class ModelRef(Z3PPObject):
|
|||
self.ctx = ctx
|
||||
Z3_model_inc_ref(self.ctx.ref(), self.model)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return ModelRef(self.m, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.ctx.ref() is not None:
|
||||
Z3_model_dec_ref(self.ctx.ref(), self.model)
|
||||
|
@ -5776,6 +5812,9 @@ class Statistics:
|
|||
self.ctx = ctx
|
||||
Z3_stats_inc_ref(self.ctx.ref(), self.stats)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return Statistics(self.stats, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.ctx.ref() is not None:
|
||||
Z3_stats_dec_ref(self.ctx.ref(), self.stats)
|
||||
|
@ -5910,6 +5949,9 @@ class CheckSatResult:
|
|||
def __init__(self, r):
|
||||
self.r = r
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return CheckSatResult(self.r)
|
||||
|
||||
def __eq__(self, other):
|
||||
return isinstance(other, CheckSatResult) and self.r == other.r
|
||||
|
||||
|
@ -5949,6 +5991,9 @@ class Solver(Z3PPObject):
|
|||
self.solver = solver
|
||||
Z3_solver_inc_ref(self.ctx.ref(), self.solver)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return Solver(self.solver, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.solver is not None and self.ctx.ref() is not None:
|
||||
Z3_solver_dec_ref(self.ctx.ref(), self.solver)
|
||||
|
@ -6369,6 +6414,9 @@ class Fixedpoint(Z3PPObject):
|
|||
Z3_fixedpoint_inc_ref(self.ctx.ref(), self.fixedpoint)
|
||||
self.vars = []
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return FixedPoint(self.fixedpoint, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.fixedpoint is not None and self.ctx.ref() is not None:
|
||||
Z3_fixedpoint_dec_ref(self.ctx.ref(), self.fixedpoint)
|
||||
|
@ -6743,6 +6791,9 @@ class Optimize(Z3PPObject):
|
|||
self.optimize = Z3_mk_optimize(self.ctx.ref())
|
||||
Z3_optimize_inc_ref(self.ctx.ref(), self.optimize)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return Optimize(self.optimize, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.optimize is not None and self.ctx.ref() is not None:
|
||||
Z3_optimize_dec_ref(self.ctx.ref(), self.optimize)
|
||||
|
@ -6895,6 +6946,9 @@ class ApplyResult(Z3PPObject):
|
|||
self.ctx = ctx
|
||||
Z3_apply_result_inc_ref(self.ctx.ref(), self.result)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return ApplyResult(self.result, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.ctx.ref() is not None:
|
||||
Z3_apply_result_dec_ref(self.ctx.ref(), self.result)
|
||||
|
@ -7023,6 +7077,9 @@ class Tactic:
|
|||
raise Z3Exception("unknown tactic '%s'" % tactic)
|
||||
Z3_tactic_inc_ref(self.ctx.ref(), self.tactic)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return Tactic(self.tactic, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.tactic is not None and self.ctx.ref() is not None:
|
||||
Z3_tactic_dec_ref(self.ctx.ref(), self.tactic)
|
||||
|
@ -7295,6 +7352,9 @@ class Probe:
|
|||
raise Z3Exception("unknown probe '%s'" % probe)
|
||||
Z3_probe_inc_ref(self.ctx.ref(), self.probe)
|
||||
|
||||
def __deepcopy__(self, memo={}):
|
||||
return Probe(self.probe, self.ctx)
|
||||
|
||||
def __del__(self):
|
||||
if self.probe is not None and self.ctx.ref() is not None:
|
||||
Z3_probe_dec_ref(self.ctx.ref(), self.probe)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue