fix some code smells reported by sonarcloud
* bench/dtgbasat/gen.py, bin/autcross.cc, bin/autfilt.cc, bin/common_aoutput.cc, bin/common_aoutput.hh: Various cleanups.
This commit is contained in:
parent
716bb781eb
commit
05edab3f5a
5 changed files with 51 additions and 66 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2013-2022 Laboratoire de Recherche et Développement
|
||||
// Copyright (C) 2013-2023 Laboratoire de Recherche et Développement
|
||||
// de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
|
|
@ -448,7 +448,7 @@ struct canon_aut
|
|||
std::vector<tr_t> edges;
|
||||
std::string acc;
|
||||
|
||||
canon_aut(const spot::const_twa_graph_ptr& aut)
|
||||
explicit canon_aut(const spot::const_twa_graph_ptr& aut)
|
||||
: num_states(aut->num_states())
|
||||
, edges(aut->edge_vector().begin() + 1,
|
||||
aut->edge_vector().end())
|
||||
|
|
@ -755,6 +755,22 @@ product_or(spot::twa_graph_ptr left, spot::twa_graph_ptr right)
|
|||
return spot::product_or(left, right);
|
||||
}
|
||||
|
||||
static spot::twa_graph_ptr
|
||||
word_to_aut(const char* word, const char *argname)
|
||||
{
|
||||
try
|
||||
{
|
||||
return spot::parse_word(word, opt->dict)->as_automaton();
|
||||
}
|
||||
catch (const spot::parse_error& e)
|
||||
{
|
||||
error(2, 0, "failed to parse the argument of --%s:\n%s",
|
||||
argname, e.what());
|
||||
}
|
||||
SPOT_UNREACHABLE();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_opt(int key, char* arg, struct argp_state*)
|
||||
{
|
||||
|
|
@ -776,17 +792,14 @@ parse_opt(int key, char* arg, struct argp_state*)
|
|||
opt_nth = parse_range(arg, 0, std::numeric_limits<int>::max());
|
||||
break;
|
||||
case 'u':
|
||||
opt->uniq = std::unique_ptr<unique_aut_t>(new std::set<canon_aut>());
|
||||
opt->uniq = std::make_unique<unique_aut_t>();
|
||||
break;
|
||||
case 'v':
|
||||
opt_invert = true;
|
||||
break;
|
||||
case 'x':
|
||||
{
|
||||
const char* opt = extra_options.parse_options(arg);
|
||||
if (opt)
|
||||
error(2, 0, "failed to parse --options near '%s'", opt);
|
||||
}
|
||||
if (const char* opt = extra_options.parse_options(arg))
|
||||
error(2, 0, "failed to parse --options near '%s'", opt);
|
||||
break;
|
||||
case OPT_ALIASES:
|
||||
opt_aliases = XARGMATCH("--aliases", arg, aliases_args, aliases_types);
|
||||
|
|
@ -802,16 +815,7 @@ parse_opt(int key, char* arg, struct argp_state*)
|
|||
opt_art_sccs_set = true;
|
||||
break;
|
||||
case OPT_ACCEPT_WORD:
|
||||
try
|
||||
{
|
||||
opt->acc_words.push_back(spot::parse_word(arg, opt->dict)
|
||||
->as_automaton());
|
||||
}
|
||||
catch (const spot::parse_error& e)
|
||||
{
|
||||
error(2, 0, "failed to parse the argument of --accept-word:\n%s",
|
||||
e.what());
|
||||
}
|
||||
opt->acc_words.emplace_back(word_to_aut(arg, "accept-word"));
|
||||
break;
|
||||
case OPT_ACCEPTANCE_IS:
|
||||
{
|
||||
|
|
@ -964,16 +968,7 @@ parse_opt(int key, char* arg, struct argp_state*)
|
|||
"%d should be followed by a comma and WORD", res);
|
||||
arg = endptr + 1;
|
||||
}
|
||||
try
|
||||
{
|
||||
opt->hl_words.emplace_back(spot::parse_word(arg, opt->dict)
|
||||
->as_automaton(), res);
|
||||
}
|
||||
catch (const spot::parse_error& e)
|
||||
{
|
||||
error(2, 0, "failed to parse the argument of --highlight-word:\n%s",
|
||||
e.what());
|
||||
}
|
||||
opt->hl_words.emplace_back(word_to_aut(arg, "highlight-word"), res);
|
||||
}
|
||||
break;
|
||||
case OPT_HIGHLIGHT_LANGUAGES:
|
||||
|
|
@ -1157,16 +1152,7 @@ parse_opt(int key, char* arg, struct argp_state*)
|
|||
opt_art_sccs_set = true;
|
||||
break;
|
||||
case OPT_REJECT_WORD:
|
||||
try
|
||||
{
|
||||
opt->rej_words.push_back(spot::parse_word(arg, opt->dict)
|
||||
->as_automaton());
|
||||
}
|
||||
catch (const spot::parse_error& e)
|
||||
{
|
||||
error(2, 0, "failed to parse the argument of --reject-word:\n%s",
|
||||
e.what());
|
||||
}
|
||||
opt->rej_words.emplace_back(word_to_aut(arg, "reject-word"));
|
||||
break;
|
||||
case OPT_REM_AP:
|
||||
opt->rem_ap.add_ap(arg);
|
||||
|
|
@ -1291,7 +1277,7 @@ namespace
|
|||
static
|
||||
bool match_acceptance(spot::twa_graph_ptr aut)
|
||||
{
|
||||
auto& acc = aut->acc();
|
||||
const spot::acc_cond& acc = aut->acc();
|
||||
switch (opt_acceptance_is)
|
||||
{
|
||||
case ACC_Any:
|
||||
|
|
@ -1346,8 +1332,7 @@ namespace
|
|||
{
|
||||
bool max;
|
||||
bool odd;
|
||||
bool is_p = acc.is_parity(max, odd, true);
|
||||
if (!is_p)
|
||||
if (!acc.is_parity(max, odd, true))
|
||||
return false;
|
||||
switch (opt_acceptance_is)
|
||||
{
|
||||
|
|
@ -1460,7 +1445,7 @@ namespace
|
|||
if (matched && opt_acceptance_is)
|
||||
matched = match_acceptance(aut);
|
||||
|
||||
if (matched && (opt_sccs_set | opt_art_sccs_set))
|
||||
if (matched && (opt_sccs_set || opt_art_sccs_set))
|
||||
{
|
||||
spot::scc_info si(aut);
|
||||
unsigned n = si.scc_count();
|
||||
|
|
@ -1540,14 +1525,14 @@ namespace
|
|||
&& spot::contains(aut, opt->equivalent_pos);
|
||||
|
||||
if (matched && !opt->acc_words.empty())
|
||||
for (auto& word_aut: opt->acc_words)
|
||||
for (const spot::twa_graph_ptr& word_aut: opt->acc_words)
|
||||
if (spot::product(aut, word_aut)->is_empty())
|
||||
{
|
||||
matched = false;
|
||||
break;
|
||||
}
|
||||
if (matched && !opt->rej_words.empty())
|
||||
for (auto& word_aut: opt->rej_words)
|
||||
for (const spot::twa_graph_ptr& word_aut: opt->rej_words)
|
||||
if (!spot::product(aut, word_aut)->is_empty())
|
||||
{
|
||||
matched = false;
|
||||
|
|
@ -1681,13 +1666,13 @@ namespace
|
|||
aut->accepting_run()->highlight(opt_highlight_accepting_run);
|
||||
|
||||
if (!opt->hl_words.empty())
|
||||
for (auto& word_aut: opt->hl_words)
|
||||
for (auto& [word_aut, color]: opt->hl_words)
|
||||
{
|
||||
if (aut->acc().uses_fin_acceptance())
|
||||
error(2, 0,
|
||||
"--highlight-word does not yet work with Fin acceptance");
|
||||
if (auto run = spot::product(aut, word_aut.first)->accepting_run())
|
||||
run->project(aut)->highlight(word_aut.second);
|
||||
if (auto run = spot::product(aut, word_aut)->accepting_run())
|
||||
run->project(aut)->highlight(color);
|
||||
}
|
||||
|
||||
timer.stop();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue