Commit 2beacc39 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

common: introduce SPOT_UNREACHABLE and SPOT_UNIMPLEMENTED.

* src/misc/common.hh (SPOT_UNIMPLEMENTED, SPOT_UNREACHABLE,
SPOT_UNREACHABLE_BUILTIN): New macros.
* src/bin/dstar2tgba.cc, src/bin/ltlcross.cc,
src/dstarparse/dstar2tgba.cc, src/eltlparse/eltlparse.yy,
src/ltlast/binop.cc, src/ltlast/bunop.cc, src/ltlast/constant.cc,
src/ltlast/formula_tree.cc, src/ltlast/multop.cc, src/ltlast/nfa.cc,
src/ltlast/unop.cc, src/ltlvisit/dotty.cc, src/ltlvisit/lbt.cc,
src/ltlvisit/lunabbrev.cc, src/ltlvisit/mark.cc,
src/ltlvisit/randomltl.cc, src/ltlvisit/simpfg.cc,
src/ltlvisit/simplify.cc, src/ltlvisit/snf.cc, src/ltlvisit/tostring.cc,
src/misc/intvcomp.cc, src/misc/minato.cc, src/tgba/bdddict.cc,
src/tgba/formula2bdd.cc, src/tgba/tgbasafracomplement.cc,
src/tgbaalgos/eltl2tgba_lacim.cc, src/tgbaalgos/ltl2taa.cc,
src/tgbaalgos/ltl2tgba_fm.cc, src/tgbaalgos/ltl2tgba_lacim.cc,
src/tgbaalgos/simulation.cc, src/tgbatest/ltl2tgba.cc:  Use them.
* src/sanity/style.test: Catch assert(0) and assert(!"text");
parent c93b41a2
// -*- coding: utf-8 -*-
// Copyright (C) 2013 Laboratoire de Recherche et Développement
// Copyright (C) 2013, 2014 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -17,6 +17,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <cstdlib>
#include <stdexcept>
#ifndef SPOT_MISC_COMMON_HH
# define SPOT_MISC_COMMON_HH
......@@ -73,4 +76,23 @@
#define SPOT_DELETED = delete
#endif
// Do not use those in code, prefer SPOT_UNREACHABLE() instead.
#if defined __clang__ || defined __GNU__
# define SPOT_UNREACHABLE_BUILTIN() __builtin_unreachable()
# elif defined _MSC_VER
# define SPOT_UNREACHABLE_BUILTIN() __assume(0)
# else
# define SPOT_UNREACHABLE_BUILTIN() abort()
#endif
// The extra parentheses in assert() is so that this
// pattern is not caught by the style checker.
#define SPOT_UNREACHABLE() do { \
assert(!("unreachable code reached")); \
SPOT_UNREACHABLE_BUILTIN(); \
} while (0)
#define SPOT_UNIMPLEMENTED() throw std::runtime_error("unimplemented");
#endif // SPOT_MISC_COMMON_HH
// -*- coding: utf-8 -*-
// Copyright (C) 2011, 2013 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2011, 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
......@@ -506,7 +506,7 @@ namespace spot
self().push_data(get_32_bits());
break;
default:
assert(0);
SPOT_UNREACHABLE();
}
}
}
......
......@@ -157,8 +157,7 @@ namespace spot
todo_.pop();
continue;
}
// Unreachable code.
assert(0);
SPOT_UNREACHABLE();
}
return bddfalse;
}
......
......@@ -240,6 +240,9 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do
egrep '(->|[.])size\(\) [=!]= 0|![a-zA-Z0-9_]*(->|[.])size\(\)|(if |while |assert)\([a-zA-Z0-9_]*(->|[.])size\(\)\)' $tmp &&
diag 'Prefer empty() to check emptiness.'
egrep 'assert\((0|!".*")\)' $tmp &&
diag 'Prefer SPOT_UNREACHABLE or SPOT_UNIMPLEMENTED.'
egrep '^[^=*<]*([+][+]|--);' $tmp &&
diag 'Take good habits: use ++i instead of i++ when you have the choice.'
......
......@@ -529,7 +529,7 @@ namespace spot
std::cerr << "some maps are not empty" << std::endl;
}
dump(std::cerr);
assert(0);
abort();
}
......
// Copyright (C) 2009, 2010, 2012 Laboratoire de Recherche et
// Dveloppement de l'Epita (LRDE).
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2010, 2012, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris
// 6 (LIP6), dpartement Systmes Rpartis Coopratifs (SRC),
// Universit Pierre et Marie Curie.
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
......@@ -62,17 +63,15 @@ namespace spot
res_ = bddfalse;
return;
case constant::EmptyWord:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
virtual void
visit(const bunop*)
{
assert(!"unsupported operator");
return;
SPOT_UNIMPLEMENTED();
}
virtual void
......@@ -87,15 +86,14 @@ namespace spot
case unop::Closure:
case unop::NegClosure:
case unop::NegClosureMarked:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
case unop::Not:
{
res_ = bdd_not(recurse(node->child()));
return;
}
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
virtual void
......@@ -122,16 +120,15 @@ namespace spot
case binop::UConcat:
case binop::EConcat:
case binop::EConcatMarked:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
virtual void
visit(const automatop*)
{
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
virtual void
......@@ -153,7 +150,7 @@ namespace spot
case multop::AndNLM:
case multop::OrRat:
case multop::AndRat:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
assert(op != -1);
unsigned s = node->size();
......
......@@ -1169,26 +1169,26 @@ namespace spot
safra_tree_automaton::automaton_t::const_iterator tr =
a->automaton.find(const_cast<safra_tree*>(s->get_safra()));
if (tr != a->automaton.end())
{
bdd condition = bddfalse;
tgba_safra_complement_succ_iterator::succ_list_t succ_list;
int nb_acceptance_pairs = a->get_nb_acceptance_pairs();
bitvect* e = make_bitvect(nb_acceptance_pairs);
assert(tr != a->automaton.end());
bdd condition = bddfalse;
tgba_safra_complement_succ_iterator::succ_list_t succ_list;
int nb_acceptance_pairs = a->get_nb_acceptance_pairs();
bitvect* e = make_bitvect(nb_acceptance_pairs);
if (!s->get_use_bitset()) // if \delta'(q, a)
if (!s->get_use_bitset()) // if \delta'(q, a)
{
for (auto& p: tr->second)
{
state_complement* s1 = new state_complement(e->clone(), e->clone(),
p.second, false);
state_complement* s2 = new state_complement(e->clone(), e->clone(),
p.second, true);
succ_list.insert(std::make_pair(p.first, s1));
succ_list.insert(std::make_pair(p.first, s2));
}
{
state_complement* s1 = new state_complement(e->clone(), e->clone(),
p.second, false);
state_complement* s2 = new state_complement(e->clone(), e->clone(),
p.second, true);
succ_list.insert(std::make_pair(p.first, s1));
succ_list.insert(std::make_pair(p.first, s2));
}
}
else
else
{
bitvect* l = make_bitvect(nb_acceptance_pairs);
bitvect* u = make_bitvect(nb_acceptance_pairs);
......@@ -1205,22 +1205,23 @@ namespace spot
// \delta'((q, I, J), a) if I'\subseteq J'
if (newI->is_subset_of(*newJ))
{
for (auto& p: tr->second)
{
st = new state_complement(e->clone(), e->clone(), p.second, true);
succ_list.insert(std::make_pair(p.first, st));
}
condition = the_acceptance_cond_;
}
{
for (auto& p: tr->second)
{
st = new state_complement(e->clone(), e->clone(),
p.second, true);
succ_list.insert(std::make_pair(p.first, st));
}
condition = the_acceptance_cond_;
}
else // \delta'((q, I, J), a)
{
for (auto& p: tr->second)
{
st = new state_complement(newI, newJ, p.second, true);
succ_list.insert(std::make_pair(p.first, st));
}
}
{
for (auto& p: tr->second)
{
st = new state_complement(newI, newJ, p.second, true);
succ_list.insert(std::make_pair(p.first, st));
}
}
delete newI;
delete newJ;
#else
......@@ -1230,11 +1231,11 @@ namespace spot
*pending |= *l;
*pending -= *u;
for (auto& p: tr->second)
{
st = new state_complement(pending->clone(), e->clone(),
p.second, true);
succ_list.insert(std::make_pair(p.first, st));
}
{
st = new state_complement(pending->clone(), e->clone(),
p.second, true);
succ_list.insert(std::make_pair(p.first, st));
}
delete pending;
for (unsigned i = 0; i < l->size(); ++i)
......@@ -1244,11 +1245,8 @@ namespace spot
delete u;
delete l;
}
delete e;
return new tgba_safra_complement_succ_iterator(succ_list, condition);
}
assert(!"Safra automaton does not find this node");
return 0;
delete e;
return new tgba_safra_complement_succ_iterator(succ_list, condition);
}
bdd_dict*
......
......@@ -71,10 +71,9 @@ namespace spot
res_ = bddfalse;
return;
case constant::EmptyWord:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
......@@ -103,16 +102,15 @@ namespace spot
case unop::Closure:
case unop::NegClosure:
case unop::NegClosureMarked:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
visit(const bunop*)
{
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
void
......@@ -139,10 +137,9 @@ namespace spot
case binop::UConcat:
case binop::EConcat:
case binop::EConcatMarked:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
......@@ -170,7 +167,7 @@ namespace spot
case multop::AndNLM:
case multop::AndRat:
case multop::OrRat:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
assert(op != -1);
unsigned s = node->size();
......
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2010, 2012, 2013 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2009, 2010, 2012, 2013, 2014 Laboratoire de Recherche
// et Développement de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
......@@ -103,11 +103,9 @@ namespace spot
case constant::False:
return;
case constant::EmptyWord:
assert(!"unsupported operator");
return;
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
......@@ -134,7 +132,7 @@ namespace spot
}
case unop::F:
case unop::G:
assert(0); // TBD
SPOT_UNIMPLEMENTED(); // TBD
return;
case unop::Not:
// Done in recurse
......@@ -144,17 +142,15 @@ namespace spot
case unop::Closure:
case unop::NegClosure:
case unop::NegClosureMarked:
assert(!"unsupported operator");
return;
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
visit(const bunop*)
{
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
void
......@@ -254,14 +250,12 @@ namespace spot
case binop::Xor:
case binop::Implies:
case binop::Equiv:
assert(0); // TBD
case binop::UConcat:
case binop::EConcat:
case binop::EConcatMarked:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
......@@ -335,18 +329,15 @@ namespace spot
case multop::AndNLM:
case multop::AndRat:
case multop::OrRat:
assert(!"unsupported operator");
return;
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
visit(const automatop* node)
visit(const automatop*)
{
(void) node;
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
ltl2taa_visitor
......
......@@ -615,8 +615,7 @@ namespace spot
res_ = now_to_concat();
return;
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
......@@ -631,8 +630,7 @@ namespace spot
case unop::Closure:
case unop::NegClosure:
case unop::NegClosureMarked:
assert(!"not a rational operator");
return;
SPOT_UNREACHABLE(); // Because not rational operator
case unop::Not:
{
// Not can only appear in front of Boolean
......@@ -644,8 +642,7 @@ namespace spot
return;
}
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
......@@ -726,20 +723,19 @@ namespace spot
}
return;
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
visit(const binop*)
{
assert(!"not a rational operator");
SPOT_UNREACHABLE(); // Not a rational operator
}
void
visit(const automatop*)
{
assert(!"not a rational operator");
SPOT_UNREACHABLE(); // Not a rational operator
}
void
......@@ -938,7 +934,7 @@ namespace spot
}
case multop::And:
case multop::Or:
assert(!"not a rational operator");
SPOT_UNREACHABLE(); // Not a rational operator
}
}
......@@ -1238,11 +1234,9 @@ namespace spot
res_ = bddfalse;
return;
case constant::EmptyWord:
assert(!"Not an LTL operator");
return;
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
......@@ -1443,15 +1437,14 @@ namespace spot
break;
case unop::Finish:
assert(!"unsupported operator");
break;
SPOT_UNIMPLEMENTED();
}
}
void
visit(const bunop*)
{
assert(!"Not an LTL operator");
SPOT_UNREACHABLE(); // Not an LTL operator
}
void
......@@ -1468,8 +1461,7 @@ namespace spot
// These operators should only appear in Boolean formulas,
// which must have been dealt with earlier (in
// translate_dict::ltl_to_bdd()).
assert(!"unexpected operator");
break;
SPOT_UNREACHABLE();
case binop::U:
{
bdd f1 = recurse(node->first());
......@@ -1651,7 +1643,7 @@ namespace spot
void
visit(const automatop*)
{
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
void
......@@ -1712,8 +1704,7 @@ namespace spot
case multop::AndNLM:
case multop::AndRat:
case multop::OrRat:
assert(!"Not an LTL operator");
break;
SPOT_UNREACHABLE(); // Not an LTL operator
}
}
......@@ -1839,20 +1830,19 @@ namespace spot
// FIXME: we might need to add Acc[1]
return;
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
visit(const automatop*)
{
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
void
visit(const bunop*)
{
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
void
......
// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2010, 2012 Laboratoire de Recherche et
// Copyright (C) 2009, 2010, 2012, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
......@@ -76,10 +76,9 @@ namespace spot
res_ = bddfalse;
return;
case constant::EmptyWord:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
......@@ -152,16 +151,15 @@ namespace spot
case unop::Closure:
case unop::NegClosure:
case unop::NegClosureMarked:
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
visit(const bunop*)
{
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
void
......@@ -230,17 +228,15 @@ namespace spot
case binop::UConcat:
case binop::EConcat:
case binop::EConcatMarked:
assert(!"unsupported operator");
break;
SPOT_UNIMPLEMENTED();
}
/* Unreachable code. */
assert(0);
SPOT_UNREACHABLE();
}
void
visit(const automatop*)
{
assert(!"unsupported operator");
SPOT_UNIMPLEMENTED();
}
void
......@@ -268,7 +264,7 @@ namespace spot
case multop::AndNLM: