python: implicit str->formula conversion
* python/spot/impl.i, python/spot/__init__.py: Implement it. * NEWS: Mention it. * tests/python/atva16-fig2a.ipynb, tests/python/atva16-fig2b.ipynb, tests/python/formulas.ipynb, tests/python/ltsmin-dve.ipynb, tests/python/ltsmin-pml.ipynb, tests/python/stutter-inv.ipynb, doc/org/tut02.org: Modernize.
This commit is contained in:
parent
5c1d9c492c
commit
6a808492c1
10 changed files with 168 additions and 210 deletions
|
|
@ -675,26 +675,18 @@ def translate(formula, *args, dict=_bdd_dict):
|
|||
formula.translate = translate
|
||||
|
||||
|
||||
def contains(left, right):
|
||||
from spot.impl import contains as contains_impl
|
||||
if type(left) is str:
|
||||
left = formula(left)
|
||||
if type(right) is str:
|
||||
right = formula(right)
|
||||
return contains_impl(left, right)
|
||||
# Wrap C++-functions into lambdas so that they get converted into
|
||||
# instance methods (i.e., self passed as first argument
|
||||
# automatically), because only user-defined functions are converted as
|
||||
# instance methods.
|
||||
def _add_formula(meth, name = None):
|
||||
setattr(formula, name or meth, (lambda self, *args, **kwargs:
|
||||
globals()[meth](self, *args, **kwargs)))
|
||||
|
||||
def are_equivalent(left, right):
|
||||
from spot.impl import are_equivalent as equiv
|
||||
if type(left) is str:
|
||||
left = formula(left)
|
||||
if type(right) is str:
|
||||
right = formula(right)
|
||||
return equiv(left, right)
|
||||
|
||||
formula.contains = contains
|
||||
formula.equivalent_to = are_equivalent
|
||||
twa.contains = contains
|
||||
twa.equivalent_to = are_equivalent
|
||||
_add_formula('contains')
|
||||
_add_formula('are_equivalent', 'equivalent_to')
|
||||
|
||||
|
||||
def postprocess(automaton, *args, formula=None):
|
||||
"""Post process an automaton.
|
||||
|
|
|
|||
|
|
@ -365,7 +365,8 @@ namespace swig
|
|||
// default to None on the Python side.
|
||||
%typemap(in) spot::formula {
|
||||
void *tmp;
|
||||
int res = SWIG_ConvertPtr($input, &tmp, $descriptor(spot::formula*), 0);
|
||||
int res = SWIG_ConvertPtr($input, &tmp, $descriptor(spot::formula*),
|
||||
SWIG_POINTER_IMPLICIT_CONV);
|
||||
if (!SWIG_IsOK(res)) {
|
||||
%argument_fail(res, "spot::formula", $symname, $argnum);
|
||||
}
|
||||
|
|
@ -377,9 +378,10 @@ namespace swig
|
|||
// if tmp == nullptr, then the default value of $1 is fine.
|
||||
}
|
||||
|
||||
%typemap(typecheck) spot::formula {
|
||||
%typemap(typecheck, precedence=2000) spot::formula {
|
||||
$1 = SWIG_CheckState(SWIG_ConvertPtr($input, nullptr,
|
||||
$descriptor(spot::formula*), 0));
|
||||
$descriptor(spot::formula*),
|
||||
SWIG_POINTER_IMPLICIT_CONV));
|
||||
}
|
||||
|
||||
%typemap(out) spot::formula {
|
||||
|
|
@ -427,6 +429,7 @@ namespace swig
|
|||
%include <spot/misc/trival.hh>
|
||||
|
||||
%implicitconv std::vector<spot::formula>;
|
||||
%implicitconv spot::formula;
|
||||
|
||||
%include <spot/tl/formula.hh>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue