randomltl: avoid #define

As this pollutes the user's namespace.

* spot/tl/randomltl.hh: Use class-level enum and constexpr instead
of #define.
* spot/tl/randomltl.cc, python/spot/__init__.py, bin/randltl.cc,
tests/python/dualize.py, tests/python/sum.py: Adjust usage.
This commit is contained in:
Alexandre Duret-Lutz 2018-05-16 17:38:59 +02:00
parent 565e25502c
commit fc0ed01a45
6 changed files with 33 additions and 37 deletions

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2012, 2013, 2014, 2015, 2016 Laboratoire de Recherche // Copyright (C) 2012, 2013, 2014, 2015, 2016, 2018 Laboratoire de Recherche
// et Développement de l'Epita (LRDE). // et Développement de l'Epita (LRDE).
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
@ -142,7 +142,8 @@ static struct opt_t
spot::atomic_prop_set aprops; spot::atomic_prop_set aprops;
}* opt; }* opt;
static int output = OUTPUTLTL; static spot::randltlgenerator::output_type output =
spot::randltlgenerator::LTL;
static char* opt_pL = nullptr; static char* opt_pL = nullptr;
static char* opt_pS = nullptr; static char* opt_pS = nullptr;
static char* opt_pB = nullptr; static char* opt_pB = nullptr;
@ -161,22 +162,22 @@ parse_opt(int key, char* arg, struct argp_state* as)
switch (key) switch (key)
{ {
case 'B': case 'B':
output = OUTPUTBOOL; output = spot::randltlgenerator::Bool;
break; break;
case 'L': case 'L':
output = OUTPUTLTL; output = spot::randltlgenerator::LTL;
break; break;
case 'n': case 'n':
opt_formulas = to_int(arg); opt_formulas = to_int(arg);
break; break;
case 'P': case 'P':
output = OUTPUTPSL; output = spot::randltlgenerator::PSL;
break; break;
case OPT_R: case OPT_R:
parse_r(arg); parse_r(arg);
break; break;
case 'S': case 'S':
output = OUTPUTSERE; output = spot::randltlgenerator::SERE;
break; break;
case OPT_BOOLEAN_PRIORITIES: case OPT_BOOLEAN_PRIORITIES:
opt_pB = arg; opt_pB = arg;
@ -275,23 +276,23 @@ main(int argc, char** argv)
{ {
switch (output) switch (output)
{ {
case OUTPUTLTL: case spot::randltlgenerator::LTL:
std::cout << std::cout <<
"Use --ltl-priorities to set the following LTL priorities:\n"; "Use --ltl-priorities to set the following LTL priorities:\n";
rg.dump_ltl_priorities(std::cout); rg.dump_ltl_priorities(std::cout);
break; break;
case OUTPUTBOOL: case spot::randltlgenerator::Bool:
std::cout << std::cout <<
"Use --boolean-priorities to set the following Boolean " "Use --boolean-priorities to set the following Boolean "
"formula priorities:\n"; "formula priorities:\n";
rg.dump_bool_priorities(std::cout); rg.dump_bool_priorities(std::cout);
break; break;
case OUTPUTPSL: case spot::randltlgenerator::PSL:
std::cout << std::cout <<
"Use --ltl-priorities to set the following LTL priorities:\n"; "Use --ltl-priorities to set the following LTL priorities:\n";
rg.dump_psl_priorities(std::cout); rg.dump_psl_priorities(std::cout);
SPOT_FALLTHROUGH; SPOT_FALLTHROUGH;
case OUTPUTSERE: case spot::randltlgenerator::SERE:
std::cout << std::cout <<
"Use --sere-priorities to set the following SERE priorities:\n"; "Use --sere-priorities to set the following SERE priorities:\n";
rg.dump_sere_priorities(std::cout); rg.dump_sere_priorities(std::cout);
@ -300,8 +301,6 @@ main(int argc, char** argv)
"formula priorities:\n"; "formula priorities:\n";
rg.dump_sere_bool_priorities(std::cout); rg.dump_sere_bool_priorities(std::cout);
break; break;
default:
error(2, 0, "internal error: unknown type of output");
} }
exit(0); exit(0);
} }
@ -313,7 +312,7 @@ main(int argc, char** argv)
if (!f) if (!f)
{ {
error(2, 0, "failed to generate a new unique formula after %d " \ error(2, 0, "failed to generate a new unique formula after %d " \
"trials", MAX_TRIALS); "trials", spot::randltlgenerator::MAX_TRIALS);
} }
else else
{ {

View file

@ -851,10 +851,10 @@ def randltl(ap, n=-1, **kwargs):
""" """
opts = option_map() opts = option_map()
output_map = { output_map = {
"ltl": OUTPUTLTL, "ltl": randltlgenerator.LTL,
"psl": OUTPUTPSL, "psl": randltlgenerator.PSL,
"bool": OUTPUTBOOL, "bool": randltlgenerator.Bool,
"sere": OUTPUTSERE "sere": randltlgenerator.SERE
} }
if isinstance(ap, list): if isinstance(ap, list):
@ -889,18 +889,18 @@ def randltl(ap, n=-1, **kwargs):
dump_priorities = kwargs.get("dump_priorities", False) dump_priorities = kwargs.get("dump_priorities", False)
if dump_priorities: if dump_priorities:
dumpstream = ostringstream() dumpstream = ostringstream()
if output == OUTPUTLTL: if output == randltlgenerator.LTL:
print('Use argument ltl_priorities=STRING to set the following ' print('Use argument ltl_priorities=STRING to set the following '
'LTL priorities:\n') 'LTL priorities:\n')
rg.dump_ltl_priorities(dumpstream) rg.dump_ltl_priorities(dumpstream)
print(dumpstream.str()) print(dumpstream.str())
elif output == OUTPUTBOOL: elif output == randltlgenerator.Bool:
print('Use argument boolean_priorities=STRING to set the ' print('Use argument boolean_priorities=STRING to set the '
'following Boolean formula priorities:\n') 'following Boolean formula priorities:\n')
rg.dump_bool_priorities(dumpstream) rg.dump_bool_priorities(dumpstream)
print(dumpstream.str()) print(dumpstream.str())
elif output == OUTPUTPSL or output == OUTPUTSERE: elif output == randltlgenerator.PSL or output == randltlgenerator.SERE:
if output != OUTPUTSERE: if output != randltlgenerator.SERE:
print('Use argument ltl_priorities=STRING to set the ' print('Use argument ltl_priorities=STRING to set the '
'following LTL priorities:\n') 'following LTL priorities:\n')
rg.dump_psl_priorities(dumpstream) rg.dump_psl_priorities(dumpstream)
@ -933,7 +933,7 @@ def randltl(ap, n=-1, **kwargs):
if f is None: if f is None:
sys.stderr.write("Warning: could not generate a new " sys.stderr.write("Warning: could not generate a new "
"unique formula after {} trials.\n" "unique formula after {} trials.\n"
.format(MAX_TRIALS)) .format(randltlgenerator.MAX_TRIALS))
raise StopIteration raise StopIteration
self.i += 1 self.i += 1
return f return f

View file

@ -411,7 +411,7 @@ namespace spot
simpl_(tl_simplifier_options{opt_simpl_level_}) simpl_(tl_simplifier_options{opt_simpl_level_})
{ {
aprops_ = aprops; aprops_ = aprops;
output_ = opts.get("output", OUTPUTLTL); output_ = opts.get("output", randltlgenerator::LTL);
opt_seed_ = opts.get("seed", 0); opt_seed_ = opts.get("seed", 0);
opt_tree_size_min_ = opts.get("tree_size_min", 15); opt_tree_size_min_ = opts.get("tree_size_min", 15);
opt_tree_size_max_ = opts.get("tree_size_max", 15); opt_tree_size_max_ = opts.get("tree_size_max", 15);
@ -424,7 +424,7 @@ namespace spot
switch (output_) switch (output_)
{ {
case OUTPUTLTL: case randltlgenerator::LTL:
rf_ = new random_ltl(&aprops_); rf_ = new random_ltl(&aprops_);
if (opt_pS) if (opt_pS)
throw std::invalid_argument("Cannot set sere priorities with " throw std::invalid_argument("Cannot set sere priorities with "
@ -434,7 +434,7 @@ namespace spot
"LTL output"); "LTL output");
tok_pL = rf_->parse_options(opt_pL); tok_pL = rf_->parse_options(opt_pL);
break; break;
case OUTPUTBOOL: case randltlgenerator::Bool:
rf_ = new random_boolean(&aprops_); rf_ = new random_boolean(&aprops_);
tok_pB = rf_->parse_options(opt_pB); tok_pB = rf_->parse_options(opt_pB);
if (opt_pL) if (opt_pL)
@ -444,7 +444,7 @@ namespace spot
throw std::invalid_argument("Cannot set sere priorities " throw std::invalid_argument("Cannot set sere priorities "
"with Boolean output"); "with Boolean output");
break; break;
case OUTPUTSERE: case randltlgenerator::SERE:
rf_ = rs_ = new random_sere(&aprops_); rf_ = rs_ = new random_sere(&aprops_);
tok_pS = rs_->parse_options(opt_pS); tok_pS = rs_->parse_options(opt_pS);
tok_pB = rs_->rb.parse_options(opt_pB); tok_pB = rs_->rb.parse_options(opt_pB);
@ -452,7 +452,7 @@ namespace spot
throw std::invalid_argument("Cannot set ltl priorities " throw std::invalid_argument("Cannot set ltl priorities "
"with SERE output"); "with SERE output");
break; break;
case OUTPUTPSL: case randltlgenerator::PSL:
rf_ = rp_ = new random_psl(&aprops_); rf_ = rp_ = new random_psl(&aprops_);
rs_ = &rp_->rs; rs_ = &rp_->rs;
tok_pL = rp_->parse_options(opt_pL); tok_pL = rp_->parse_options(opt_pL);

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Laboratoire de // Copyright (C) 2010-2016, 2018 Laboratoire de
// Recherche et Développement de l'Epita (LRDE). // Recherche et Développement de l'Epita (LRDE).
// Copyright (C) 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre // département Systèmes Répartis Coopératifs (SRC), Université Pierre
@ -30,12 +30,6 @@
#include <spot/misc/hash.hh> #include <spot/misc/hash.hh>
#include <spot/tl/simplify.hh> #include <spot/tl/simplify.hh>
#define OUTPUTBOOL 1
#define OUTPUTLTL 2
#define OUTPUTSERE 3
#define OUTPUTPSL 4
#define MAX_TRIALS 100000
namespace spot namespace spot
{ {
/// \ingroup tl_io /// \ingroup tl_io
@ -305,6 +299,9 @@ namespace spot
public: public:
enum output_type { Bool, LTL, SERE, PSL };
static constexpr unsigned MAX_TRIALS = 100000U;
randltlgenerator(int aprops_n, const option_map& opts, randltlgenerator(int aprops_n, const option_map& opts,
char* opt_pL = nullptr, char* opt_pL = nullptr,
char* opt_pS = nullptr, char* opt_pS = nullptr,

View file

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
# -*- mode: python; coding: utf-8 -*- # -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017 Laboratoire de Recherche et Développement de # Copyright (C) 2017, 2018 Laboratoire de Recherche et Développement de
# l'EPITA. # l'EPITA.
# #
# This file is part of Spot, a model checking library. # This file is part of Spot, a model checking library.
@ -585,7 +585,7 @@ State: 5
--END--""" --END--"""
opts = spot.option_map() opts = spot.option_map()
opts.set('output', spot.OUTPUTLTL) opts.set('output', spot.randltlgenerator.LTL)
opts.set('tree_size_min', 15) opts.set('tree_size_min', 15)
opts.set('tree_size_max', 15) opts.set('tree_size_max', 15)
opts.set('seed', 0) opts.set('seed', 0)

View file

@ -34,7 +34,7 @@ except RuntimeError:
opts = spot.option_map() opts = spot.option_map()
opts.set('output', spot.OUTPUTLTL) opts.set('output', spot.randltlgenerator.LTL)
opts.set('tree_size_min', 15) opts.set('tree_size_min', 15)
opts.set('tree_size_max', 15) opts.set('tree_size_max', 15)
opts.set('wf', False) opts.set('wf', False)