randltl: some code cleanup
* src/ltlvisit/randomltl.cc, src/ltlvisit/randomltl.hh: Throw invalid_argument exceptions consistently (not std::string), and use forwarding constructors to avoid the construct() method. * src/bin/randltl.cc: Catch the above exceptions. Destroy the opts variable right after its use, so that we don't need explicit destructor calls. * src/ltltest/rand.test: Add a test.
This commit is contained in:
parent
72c7ad9fcd
commit
4ffb0cb98d
4 changed files with 117 additions and 127 deletions
|
|
@ -245,7 +245,11 @@ main(int argc, char** argv)
|
||||||
program_name);
|
program_name);
|
||||||
|
|
||||||
spot::srand(opt_seed);
|
spot::srand(opt_seed);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
spot::ltl::randltlgenerator rg
|
||||||
|
(aprops,
|
||||||
|
[&] (){
|
||||||
spot::option_map opts;
|
spot::option_map opts;
|
||||||
opts.set("output", output);
|
opts.set("output", output);
|
||||||
opts.set("tree_size_min", opt_tree_size.min);
|
opts.set("tree_size_min", opt_tree_size.min);
|
||||||
|
|
@ -253,41 +257,41 @@ main(int argc, char** argv)
|
||||||
opts.set("opt_wf", opt_wf);
|
opts.set("opt_wf", opt_wf);
|
||||||
opts.set("opt_seed", opt_seed);
|
opts.set("opt_seed", opt_seed);
|
||||||
opts.set("simplification_level", simplification_level);
|
opts.set("simplification_level", simplification_level);
|
||||||
spot::ltl::randltlgenerator rg(aprops, opts, opt_pL, opt_pS, opt_pB);
|
return opts;
|
||||||
|
}(), opt_pL, opt_pS, opt_pB);
|
||||||
|
|
||||||
if (opt_dump_priorities)
|
if (opt_dump_priorities)
|
||||||
{
|
{
|
||||||
switch (output)
|
switch (output)
|
||||||
{
|
{
|
||||||
case OUTPUTLTL:
|
case OUTPUTLTL:
|
||||||
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 OUTPUTBOOL:
|
||||||
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 OUTPUTPSL:
|
||||||
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);
|
||||||
// Fall through.
|
// Fall through.
|
||||||
case OUTPUTSERE:
|
case OUTPUTSERE:
|
||||||
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);
|
||||||
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_sere_bool_priorities(std::cout);
|
rg.dump_sere_bool_priorities(std::cout);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error(2, 0, "internal error: unknown type of output");
|
error(2, 0, "internal error: unknown type of output");
|
||||||
}
|
}
|
||||||
opts.~option_map();
|
|
||||||
destroy_atomic_prop_set(aprops);
|
destroy_atomic_prop_set(aprops);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
@ -295,12 +299,10 @@ main(int argc, char** argv)
|
||||||
while (opt_formulas < 0 || opt_formulas--)
|
while (opt_formulas < 0 || opt_formulas--)
|
||||||
{
|
{
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
spot::ltl::randltlgenerator rg2(aprops, opts);
|
|
||||||
const spot::ltl::formula* f = rg.next();
|
const spot::ltl::formula* f = rg.next();
|
||||||
if (!f)
|
if (!f)
|
||||||
{
|
{
|
||||||
opts.~option_map();
|
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", MAX_TRIALS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -309,7 +311,17 @@ main(int argc, char** argv)
|
||||||
f->destroy();
|
f->destroy();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
catch (const std::runtime_error& e)
|
||||||
|
{
|
||||||
|
destroy_atomic_prop_set(aprops);
|
||||||
|
error(2, 0, "%s", e.what());
|
||||||
|
}
|
||||||
|
catch (const std::invalid_argument& e)
|
||||||
|
{
|
||||||
|
destroy_atomic_prop_set(aprops);
|
||||||
|
error(2, 0, "%s", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
destroy_atomic_prop_set(aprops);
|
destroy_atomic_prop_set(aprops);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -136,3 +136,7 @@ run 0 $randltl -n5 2 -o test-all.ltl
|
||||||
run 0 $randltl -n5 2 -o test-%L.ltl
|
run 0 $randltl -n5 2 -o test-%L.ltl
|
||||||
cat test-1.ltl test-2.ltl test-3.ltl test-4.ltl test-5.ltl > test-cmp.ltl
|
cat test-1.ltl test-2.ltl test-3.ltl test-4.ltl test-5.ltl > test-cmp.ltl
|
||||||
diff test-cmp.ltl test-all.ltl
|
diff test-cmp.ltl test-all.ltl
|
||||||
|
|
||||||
|
|
||||||
|
$randltl 2 --ltl-prio=X 2>stderr && exit 1
|
||||||
|
grep 'failed to parse LTL priorities near X' stderr
|
||||||
|
|
|
||||||
|
|
@ -404,12 +404,11 @@ namespace spot
|
||||||
update_sums();
|
update_sums();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
randltlgenerator::randltlgenerator(atomic_prop_set aprops,
|
||||||
randltlgenerator::construct(atomic_prop_set aprops, option_map& opts,
|
const option_map& opts,
|
||||||
char* opt_pL,
|
char* opt_pL,
|
||||||
char* opt_pS,
|
char* opt_pS,
|
||||||
char* opt_pB)
|
char* opt_pB)
|
||||||
|
|
||||||
{
|
{
|
||||||
aprops_ = aprops;
|
aprops_ = aprops;
|
||||||
output_ = opts.get("output", OUTPUTLTL);
|
output_ = opts.get("output", OUTPUTLTL);
|
||||||
|
|
@ -429,10 +428,10 @@ namespace spot
|
||||||
case OUTPUTLTL:
|
case OUTPUTLTL:
|
||||||
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 "
|
||||||
"LTL output");
|
"LTL output");
|
||||||
if (opt_pB)
|
if (opt_pB)
|
||||||
throw std::invalid_argument("Cannot set boolean priorities with "\
|
throw std::invalid_argument("Cannot set boolean priorities with "
|
||||||
"LTL output");
|
"LTL output");
|
||||||
tok_pL = rf_->parse_options(opt_pL);
|
tok_pL = rf_->parse_options(opt_pL);
|
||||||
break;
|
break;
|
||||||
|
|
@ -440,10 +439,10 @@ namespace spot
|
||||||
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)
|
||||||
throw std::invalid_argument("Cannot set ltl priorities with "\
|
throw std::invalid_argument("Cannot set ltl priorities with "
|
||||||
"Boolean output");
|
"Boolean output");
|
||||||
if (opt_pS)
|
if (opt_pS)
|
||||||
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 OUTPUTSERE:
|
||||||
|
|
@ -451,7 +450,7 @@ namespace spot
|
||||||
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);
|
||||||
if (opt_pL)
|
if (opt_pL)
|
||||||
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 OUTPUTPSL:
|
||||||
|
|
@ -464,11 +463,13 @@ namespace spot
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok_pL)
|
if (tok_pL)
|
||||||
throw("failed to parse LTL priorities near '" + std::string(tok_pL));
|
throw std::invalid_argument("failed to parse LTL priorities near "
|
||||||
|
+ std::string(tok_pL));
|
||||||
if (tok_pS)
|
if (tok_pS)
|
||||||
throw("failed to parse SERE priorities near " + std::string(tok_pS));
|
throw std::invalid_argument("failed to parse SERE priorities near "
|
||||||
|
+ std::string(tok_pS));
|
||||||
if (tok_pB)
|
if (tok_pB)
|
||||||
throw("failed to parse Boolean priorities near "
|
throw std::invalid_argument("failed to parse Boolean priorities near "
|
||||||
+ std::string(tok_pB));
|
+ std::string(tok_pB));
|
||||||
|
|
||||||
spot::srand(opt_seed_);
|
spot::srand(opt_seed_);
|
||||||
|
|
@ -476,34 +477,15 @@ namespace spot
|
||||||
ltl_simplifier simpl_(simpl_opts);
|
ltl_simplifier simpl_(simpl_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
randltlgenerator::randltlgenerator(int aprops_n, option_map& opts,
|
randltlgenerator::randltlgenerator(int aprops_n,
|
||||||
|
const option_map& opts,
|
||||||
char* opt_pL,
|
char* opt_pL,
|
||||||
char* opt_pS,
|
char* opt_pS,
|
||||||
char* opt_pB)
|
char* opt_pB)
|
||||||
|
: randltlgenerator(create_atomic_prop_set(aprops_n), opts,
|
||||||
|
opt_pL, opt_pS, opt_pB)
|
||||||
{
|
{
|
||||||
atomic_prop_set aprops_;
|
|
||||||
default_environment& e =
|
|
||||||
default_environment::instance();
|
|
||||||
for (int i = 0; i < aprops_n; ++i)
|
|
||||||
{
|
|
||||||
std::ostringstream p;
|
|
||||||
p << 'p' << i;
|
|
||||||
aprops_.insert(static_cast<const atomic_prop*>
|
|
||||||
(e.require(p.str())));
|
|
||||||
}
|
}
|
||||||
construct(aprops_, opts, opt_pL, opt_pS, opt_pB);
|
|
||||||
}
|
|
||||||
|
|
||||||
randltlgenerator::randltlgenerator(atomic_prop_set aprops,
|
|
||||||
option_map& opts,
|
|
||||||
char* opt_pL,
|
|
||||||
char* opt_pS,
|
|
||||||
char* opt_pB)
|
|
||||||
|
|
||||||
{
|
|
||||||
construct(aprops, opts, opt_pL, opt_pS, opt_pB);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
randltlgenerator::~randltlgenerator()
|
randltlgenerator::~randltlgenerator()
|
||||||
{
|
{
|
||||||
|
|
@ -512,6 +494,7 @@ namespace spot
|
||||||
for (auto i: unique_set_)
|
for (auto i: unique_set_)
|
||||||
i->destroy();
|
i->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
const formula* randltlgenerator::next()
|
const formula* randltlgenerator::next()
|
||||||
{
|
{
|
||||||
unsigned trials = MAX_TRIALS;
|
unsigned trials = MAX_TRIALS;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// -*- coding: utf-8 -*-
|
// -*- coding: utf-8 -*-
|
||||||
// Copyright (C) 2010, 2011, 2012, 2013, 2014 Laboratoire de Recherche
|
// Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015 Laboratoire de
|
||||||
// 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
|
||||||
// et Marie Curie.
|
// et Marie Curie.
|
||||||
|
|
@ -311,34 +311,25 @@ namespace spot
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
randltlgenerator(int aprops_n, 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,
|
||||||
char* opt_pB = nullptr);
|
char* opt_pB = nullptr);
|
||||||
|
|
||||||
randltlgenerator(atomic_prop_set aprops, option_map& opts,
|
randltlgenerator(atomic_prop_set aprops, const option_map& opts,
|
||||||
char* opt_pL = nullptr,
|
char* opt_pL = nullptr,
|
||||||
char* opt_pS = nullptr,
|
char* opt_pS = nullptr,
|
||||||
char* opt_pB = nullptr);
|
char* opt_pB = nullptr);
|
||||||
|
|
||||||
void construct(atomic_prop_set aprops, option_map& opts,
|
|
||||||
char* opt_pL, char* opt_pS,
|
|
||||||
char* opt_pB);
|
|
||||||
|
|
||||||
~randltlgenerator();
|
~randltlgenerator();
|
||||||
|
|
||||||
const spot::ltl::formula* next();
|
const spot::ltl::formula* next();
|
||||||
|
|
||||||
void dump_ltl_priorities(std::ostream& os);
|
void dump_ltl_priorities(std::ostream& os);
|
||||||
|
|
||||||
void dump_bool_priorities(std::ostream& os);
|
void dump_bool_priorities(std::ostream& os);
|
||||||
|
|
||||||
void dump_psl_priorities(std::ostream& os);
|
void dump_psl_priorities(std::ostream& os);
|
||||||
|
|
||||||
void dump_sere_priorities(std::ostream& os);
|
void dump_sere_priorities(std::ostream& os);
|
||||||
|
|
||||||
void dump_sere_bool_priorities(std::ostream& os);
|
void dump_sere_bool_priorities(std::ostream& os);
|
||||||
|
|
||||||
void remove_some_props(atomic_prop_set& s);
|
void remove_some_props(atomic_prop_set& s);
|
||||||
|
|
||||||
const formula* GF_n();
|
const formula* GF_n();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue