use SPOT_ASSERT instead of assert

For #184.

* spot/graph/graph.hh, spot/kripke/kripkegraph.hh,
spot/misc/bitvect.hh, spot/misc/common.hh, spot/misc/fixpool.hh,
spot/misc/mspool.hh, spot/misc/timer.hh, spot/tl/formula.hh,
spot/twa/acc.hh, spot/twa/taatgba.hh, spot/twa/twa.hh,
spot/twa/twagraph.hh, spot/twaalgos/emptiness_stats.hh,
spot/twaalgos/mask.hh, spot/twaalgos/ndfs_result.hxx,
spot/twaalgos/sccinfo.hh, spot/twaalgos/translate.hh: Replace
assert() by SPOT_ASSERT(), or an exception, or nothing, depending
on the case.
* tests/sanity/style.test: Flag all asserts in headers.
* HACKING: Discuss assertions.
This commit is contained in:
Alexandre Duret-Lutz 2016-07-24 23:26:59 +02:00
parent 9f7bf5ab2d
commit 20cf43b3ea
19 changed files with 163 additions and 124 deletions

19
HACKING
View file

@ -346,6 +346,22 @@ Exporting symbols
* Read http://www.akkadia.org/drepper/dsohowto.pdf for more * Read http://www.akkadia.org/drepper/dsohowto.pdf for more
information about how shared libraries work and why. information about how shared libraries work and why.
Assertions
----------
* There are different types of assertions. Plain assert() is OK for
invariants or post-conditions. When asserting a pre-condition,
carefully consider who the caller might be: if it can be in
user-code (either in C++ or Python), throw an exception
(std::runtime_error, std::invalid_argument, and spot::parse_error
are the three exception types catched by the Python bindings).
* Do not call assert() in public *.hh files: even if the installed
libspot has been compiled with -DNDEBUG, the *.hh files will be
recompiled by users, probably without -DNDEBUG. So use
SPOT_ASSERT() instead of assert(), this ensure asserts are only
used inside libspot for debug builds.
Comments Comments
-------- --------
@ -361,7 +377,8 @@ Comments
Formating Formating
--------- ---------
* Braces are always on their own line. * Braces around instruction blocks are always on their own line.
Braces around initializers lists need not be on their own.
* Text within braces is two-space indented. * Text within braces is two-space indented.

View file

@ -373,7 +373,7 @@ namespace spot
if (src_.succ_tail == this->t_) if (src_.succ_tail == this->t_)
{ {
src_.succ_tail = prev_; src_.succ_tail = prev_;
assert(next == 0); SPOT_ASSERT(next == 0);
} }
// Erased edges have themselves as next_succ. // Erased edges have themselves as next_succ.
@ -678,14 +678,12 @@ namespace spot
state_storage_t& state_storage_t&
state_storage(state s) state_storage(state s)
{ {
assert(s < states_.size());
return states_[s]; return states_[s];
} }
const state_storage_t& const state_storage_t&
state_storage(state s) const state_storage(state s) const
{ {
assert(s < states_.size());
return states_[s]; return states_[s];
} }
///@} ///@}
@ -698,14 +696,12 @@ namespace spot
typename state_storage_t::data_t& typename state_storage_t::data_t&
state_data(state s) state_data(state s)
{ {
assert(s < states_.size());
return states_[s].data(); return states_[s].data();
} }
const typename state_storage_t::data_t& const typename state_storage_t::data_t&
state_data(state s) const state_data(state s) const
{ {
assert(s < states_.size());
return states_[s].data(); return states_[s].data();
} }
///@} ///@}
@ -718,14 +714,12 @@ namespace spot
edge_storage_t& edge_storage_t&
edge_storage(edge s) edge_storage(edge s)
{ {
assert(s < edges_.size());
return edges_[s]; return edges_[s];
} }
const edge_storage_t& const edge_storage_t&
edge_storage(edge s) const edge_storage(edge s) const
{ {
assert(s < edges_.size());
return edges_[s]; return edges_[s];
} }
///@} ///@}
@ -738,14 +732,12 @@ namespace spot
typename edge_storage_t::data_t& typename edge_storage_t::data_t&
edge_data(edge s) edge_data(edge s)
{ {
assert(s < edges_.size());
return edges_[s].data(); return edges_[s].data();
} }
const typename edge_storage_t::data_t& const typename edge_storage_t::data_t&
edge_data(edge s) const edge_data(edge s) const
{ {
assert(s < edges_.size());
return edges_[s].data(); return edges_[s].data();
} }
///@} ///@}
@ -759,13 +751,11 @@ namespace spot
edge edge
new_edge(state src, out_state dst, Args&&... args) new_edge(state src, out_state dst, Args&&... args)
{ {
assert(src < states_.size());
edge t = edges_.size(); edge t = edges_.size();
edges_.emplace_back(dst, 0, src, std::forward<Args>(args)...); edges_.emplace_back(dst, 0, src, std::forward<Args>(args)...);
edge st = states_[src].succ_tail; edge st = states_[src].succ_tail;
assert(st < t || !st); SPOT_ASSERT(st < t || !st);
if (!st) if (!st)
states_[src].succ = t; states_[src].succ = t;
else else
@ -777,14 +767,14 @@ namespace spot
/// Convert a storage reference into a state number /// Convert a storage reference into a state number
state index_of_state(const state_storage_t& ss) const state index_of_state(const state_storage_t& ss) const
{ {
assert(!states_.empty()); SPOT_ASSERT(!states_.empty());
return &ss - &states_.front(); return &ss - &states_.front();
} }
/// Conveart a storage reference into an edge number /// Conveart a storage reference into an edge number
edge index_of_edge(const edge_storage_t& tt) const edge index_of_edge(const edge_storage_t& tt) const
{ {
assert(!edges_.empty()); SPOT_ASSERT(!edges_.empty());
return &tt - &edges_.front(); return &tt - &edges_.front();
} }
@ -1012,7 +1002,7 @@ namespace spot
/// any iteration on the successor of a state is performed. /// any iteration on the successor of a state is performed.
void rename_states_(const std::vector<unsigned>& newst) void rename_states_(const std::vector<unsigned>& newst)
{ {
assert(newst.size() == states_.size()); SPOT_ASSERT(newst.size() == states_.size());
unsigned tend = edges_.size(); unsigned tend = edges_.size();
for (unsigned t = 1; t < tend; t++) for (unsigned t = 1; t < tend; t++)
{ {
@ -1028,8 +1018,8 @@ namespace spot
/// \param used_states the number of states used (after renumbering) /// \param used_states the number of states used (after renumbering)
void defrag_states(std::vector<unsigned>&& newst, unsigned used_states) void defrag_states(std::vector<unsigned>&& newst, unsigned used_states)
{ {
assert(newst.size() == states_.size()); SPOT_ASSERT(newst.size() == states_.size());
assert(used_states > 0); SPOT_ASSERT(used_states > 0);
//std::cerr << "\nbefore defrag\n"; //std::cerr << "\nbefore defrag\n";
//dump_storage(std::cerr); //dump_storage(std::cerr);
@ -1080,7 +1070,7 @@ namespace spot
tr.next_succ = newidx[tr.next_succ]; tr.next_succ = newidx[tr.next_succ];
tr.dst = newst[tr.dst]; tr.dst = newst[tr.dst];
tr.src = newst[tr.src]; tr.src = newst[tr.src];
assert(tr.dst != -1U); SPOT_ASSERT(tr.dst != -1U);
} }
// Adjust succ and succ_tails pointers in all states. // Adjust succ and succ_tails pointers in all states.

View file

@ -42,7 +42,7 @@ namespace spot
virtual int compare(const spot::state* other) const override virtual int compare(const spot::state* other) const override
{ {
auto o = down_cast<const kripke_graph_state*>(other); auto o = down_cast<const kripke_graph_state*>(other);
assert(o); SPOT_ASSERT(o);
// Do not simply return "other - this", it might not fit in an int. // Do not simply return "other - this", it might not fit in an int.
if (o < this) if (o < this)
@ -129,7 +129,7 @@ namespace spot
virtual kripke_graph_state* dst() const override virtual kripke_graph_state* dst() const override
{ {
assert(!done()); SPOT_ASSERT(!done());
return const_cast<kripke_graph_state*> return const_cast<kripke_graph_state*>
(&g_->state_data(g_->edge_storage(p_).dst)); (&g_->state_data(g_->edge_storage(p_).dst));
} }
@ -169,7 +169,9 @@ namespace spot
void set_init_state(graph_t::state s) void set_init_state(graph_t::state s)
{ {
assert(s < num_states()); if (SPOT_UNLIKELY(s >= num_states()))
throw std::invalid_argument
("set_init_state() called with nonexisiting state");
init_number_ = s; init_number_ = s;
} }
@ -193,8 +195,8 @@ namespace spot
succ_iter(const spot::state* st) const override succ_iter(const spot::state* st) const override
{ {
auto s = down_cast<const typename graph_t::state_storage_t*>(st); auto s = down_cast<const typename graph_t::state_storage_t*>(st);
assert(s); SPOT_ASSERT(s);
assert(!s->succ || g_.is_valid_edge(s->succ)); SPOT_ASSERT(!s->succ || g_.is_valid_edge(s->succ));
if (this->iter_cache_) if (this->iter_cache_)
{ {
@ -212,7 +214,7 @@ namespace spot
state_number(const state* st) const state_number(const state* st) const
{ {
auto s = down_cast<const typename graph_t::state_storage_t*>(st); auto s = down_cast<const typename graph_t::state_storage_t*>(st);
assert(s); SPOT_ASSERT(s);
return s - &g_.state_storage(0); return s - &g_.state_storage(0);
} }

View file

@ -191,7 +191,7 @@ namespace spot
bool get(size_t pos) const bool get(size_t pos) const
{ {
assert(pos < size_); SPOT_ASSERT(pos < size_);
const size_t bpb = 8 * sizeof(block_t); const size_t bpb = 8 * sizeof(block_t);
return storage_[pos / bpb] & (1UL << (pos % bpb)); return storage_[pos / bpb] & (1UL << (pos % bpb));
} }
@ -248,21 +248,21 @@ namespace spot
void set(size_t pos) void set(size_t pos)
{ {
assert(pos < size_); SPOT_ASSERT(pos < size_);
const size_t bpb = 8 * sizeof(block_t); const size_t bpb = 8 * sizeof(block_t);
storage_[pos / bpb] |= 1UL << (pos % bpb); storage_[pos / bpb] |= 1UL << (pos % bpb);
} }
void clear(size_t pos) void clear(size_t pos)
{ {
assert(pos < size_); SPOT_ASSERT(pos < size_);
const size_t bpb = 8 * sizeof(block_t); const size_t bpb = 8 * sizeof(block_t);
storage_[pos / bpb] &= ~(1UL << (pos % bpb)); storage_[pos / bpb] &= ~(1UL << (pos % bpb));
} }
void flip(size_t pos) void flip(size_t pos)
{ {
assert(pos < size_); SPOT_ASSERT(pos < size_);
const size_t bpb = 8 * sizeof(block_t); const size_t bpb = 8 * sizeof(block_t);
storage_[pos / bpb] ^= (1UL << (pos % bpb)); storage_[pos / bpb] ^= (1UL << (pos % bpb));
} }
@ -270,7 +270,7 @@ namespace spot
bitvect& operator|=(const bitvect& other) bitvect& operator|=(const bitvect& other)
{ {
assert(other.size_ <= size_); SPOT_ASSERT(other.size_ <= size_);
unsigned m = std::min(other.block_count_, block_count_); unsigned m = std::min(other.block_count_, block_count_);
for (size_t i = 0; i < m; ++i) for (size_t i = 0; i < m; ++i)
storage_[i] |= other.storage_[i]; storage_[i] |= other.storage_[i];
@ -279,7 +279,7 @@ namespace spot
bitvect& operator&=(const bitvect& other) bitvect& operator&=(const bitvect& other)
{ {
assert(other.size_ <= size_); SPOT_ASSERT(other.size_ <= size_);
unsigned m = std::min(other.block_count_, block_count_); unsigned m = std::min(other.block_count_, block_count_);
for (size_t i = 0; i < m; ++i) for (size_t i = 0; i < m; ++i)
storage_[i] &= other.storage_[i]; storage_[i] &= other.storage_[i];
@ -288,7 +288,7 @@ namespace spot
bitvect& operator^=(const bitvect& other) bitvect& operator^=(const bitvect& other)
{ {
assert(other.size_ <= size_); SPOT_ASSERT(other.size_ <= size_);
unsigned m = std::min(other.block_count_, block_count_); unsigned m = std::min(other.block_count_, block_count_);
for (size_t i = 0; i < m; ++i) for (size_t i = 0; i < m; ++i)
storage_[i] ^= other.storage_[i]; storage_[i] ^= other.storage_[i];
@ -297,7 +297,7 @@ namespace spot
bitvect& operator-=(const bitvect& other) bitvect& operator-=(const bitvect& other)
{ {
assert(other.block_count_ <= block_count_); SPOT_ASSERT(other.block_count_ <= block_count_);
for (size_t i = 0; i < other.block_count_; ++i) for (size_t i = 0; i < other.block_count_; ++i)
storage_[i] &= ~other.storage_[i]; storage_[i] &= ~other.storage_[i];
return *this; return *this;
@ -305,7 +305,7 @@ namespace spot
bool is_subset_of(const bitvect& other) const bool is_subset_of(const bitvect& other) const
{ {
assert(other.block_count_ >= block_count_); SPOT_ASSERT(other.block_count_ >= block_count_);
size_t i; size_t i;
const size_t bpb = 8 * sizeof(bitvect::block_t); const size_t bpb = 8 * sizeof(bitvect::block_t);
@ -391,8 +391,8 @@ namespace spot
// to \a end (excluded). // to \a end (excluded).
bitvect* extract_range(size_t begin, size_t end) bitvect* extract_range(size_t begin, size_t end)
{ {
assert(begin <= end); SPOT_ASSERT(begin <= end);
assert(end <= size()); SPOT_ASSERT(end <= size());
size_t count = end - begin; size_t count = end - begin;
bitvect* res = make_bitvect(count); bitvect* res = make_bitvect(count);
res->make_empty(); res->make_empty();
@ -423,13 +423,13 @@ namespace spot
++indexb; ++indexb;
res->push_back(storage_[indexb], bpb); res->push_back(storage_[indexb], bpb);
count -= bpb; count -= bpb;
assert(indexb != indexe || count == 0); SPOT_ASSERT(indexb != indexe || count == 0);
} }
if (count > 0) if (count > 0)
{ {
++indexb; ++indexb;
assert(indexb == indexe); SPOT_ASSERT(indexb == indexe);
assert(count == end % bpb); SPOT_ASSERT(count == end % bpb);
res->push_back(storage_[indexb], count); res->push_back(storage_[indexb], count);
} }
} }
@ -495,7 +495,7 @@ namespace spot
/// Return the bit-vector at \a index. /// Return the bit-vector at \a index.
bitvect& at(const size_t index) bitvect& at(const size_t index)
{ {
assert(index < size_); SPOT_ASSERT(index < size_);
return *reinterpret_cast<bitvect*>(storage() + index * bvsize_); return *reinterpret_cast<bitvect*>(storage() + index * bvsize_);
} }
@ -510,7 +510,7 @@ namespace spot
/// Return the bit-vector at \a index. /// Return the bit-vector at \a index.
const bitvect& at(const size_t index) const const bitvect& at(const size_t index) const
{ {
assert(index < size_); SPOT_ASSERT(index < size_);
return *reinterpret_cast<const bitvect*>(storage() + index * bvsize_); return *reinterpret_cast<const bitvect*>(storage() + index * bvsize_);
} }

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014, 2015 Laboratoire de Recherche et // Copyright (C) 2013, 2014, 2015, 2016 Laboratoire de Recherche et
// Développement de l'Epita (LRDE). // 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.
@ -58,6 +58,18 @@
#define SPOT_DLL #define SPOT_DLL
#endif #endif
// We should not call assert() in headers. For the rare cases where
// we do really want to call assert(), use spot_assert__ instead.
// Else use SPOT_ASSERT so the assert() are removed from user's
// builds.
#define spot_assert__ assert
#if defined(SPOT_BUILD) or defined(SPOT_DEBUG)
#define SPOT_ASSERT(x) spot_assert__(x)
#else
#define SPOT_ASSERT(x) while (0)
#endif
// SPOT_API is used for the public API symbols. It either DLL imports // SPOT_API is used for the public API symbols. It either DLL imports
// or DLL exports (or does nothing for static build) SPOT_LOCAL is // or DLL exports (or does nothing for static build) SPOT_LOCAL is
// used for non-api symbols that may occur in header files. // used for non-api symbols that may occur in header files.
@ -94,7 +106,7 @@
// The extra parentheses in assert() is so that this // The extra parentheses in assert() is so that this
// pattern is not caught by the style checker. // pattern is not caught by the style checker.
#define SPOT_UNREACHABLE() do { \ #define SPOT_UNREACHABLE() do { \
assert(!("unreachable code reached")); \ SPOT_ASSERT(!("unreachable code reached")); \
SPOT_UNREACHABLE_BUILTIN(); \ SPOT_UNREACHABLE_BUILTIN(); \
} while (0) } while (0)

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2011, 2015 Laboratoire de Recherche et Développement // Copyright (C) 2011, 2015, 2016 Laboratoire de Recherche et
// de l'Epita (LRDE) // 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.
// //
@ -95,7 +95,7 @@ namespace spot
void void
deallocate (const void* ptr) deallocate (const void* ptr)
{ {
assert(ptr); SPOT_ASSERT(ptr);
block_* b = reinterpret_cast<block_*>(const_cast<void*>(ptr)); block_* b = reinterpret_cast<block_*>(const_cast<void*>(ptr));
b->next = freelist_; b->next = freelist_;
freelist_ = b; freelist_ = b;

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2011, 2013, 2015 Laboratoire de Recherche et Developpement // Copyright (C) 2011, 2013, 2015, 2016 Laboratoire de Recherche et
// de l'Epita (LRDE) // Developpement de l'Epita (LRDE)
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
// //
@ -107,7 +107,7 @@ namespace spot
void void
deallocate (const void* ptr, size_t size) deallocate (const void* ptr, size_t size)
{ {
assert(ptr); SPOT_ASSERT(ptr);
size = fixsize(size); size = fixsize(size);
block_* b = reinterpret_cast<block_*>(const_cast<void*>(ptr)); block_* b = reinterpret_cast<block_*>(const_cast<void*>(ptr));
block_*& f = freelist_[size]; block_*& f = freelist_[size];

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2009, 2011, 2012, 2013, 2014, 2015 Laboratoire de // Copyright (C) 2009, 2011, 2012, 2013, 2014, 2015, 2016 Laboratoire de
// Recherche et Développement de l'Epita (LRDE). // Recherche et Développement de l'Epita (LRDE).
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2004 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
@ -91,7 +91,7 @@ namespace spot
void void
start() start()
{ {
assert(!running); SPOT_ASSERT(!running);
running = true; running = true;
#ifdef SPOT_HAVE_TIMES #ifdef SPOT_HAVE_TIMES
struct tms tmp; struct tms tmp;
@ -115,7 +115,7 @@ namespace spot
#else #else
total_.utime += clock() - start_.utime; total_.utime += clock() - start_.utime;
#endif #endif
assert(running); SPOT_ASSERT(running);
running = false; running = false;
} }
@ -194,8 +194,9 @@ namespace spot
cancel(const std::string& name) cancel(const std::string& name)
{ {
tm_type::iterator i = tm.find(name); tm_type::iterator i = tm.find(name);
assert(i != tm.end()); if (SPOT_UNLIKELY(i == tm.end()))
assert(0 < i->second.second); throw std::invalid_argument("timer_map::cancel(): unknown name");
SPOT_ASSERT(0 < i->second.second);
if (0 == --i->second.second) if (0 == --i->second.second)
tm.erase(i); tm.erase(i);
} }
@ -205,7 +206,8 @@ namespace spot
timer(const std::string& name) const timer(const std::string& name) const
{ {
tm_type::const_iterator i = tm.find(name); tm_type::const_iterator i = tm.find(name);
assert(i != tm.end()); if (SPOT_UNLIKELY(i == tm.end()))
throw std::invalid_argument("timer_map::timer(): unknown name");
return i->second.first; return i->second.first;
} }

View file

@ -191,7 +191,9 @@ namespace spot
{ {
if (op_ != o) if (op_ != o)
return nullptr; return nullptr;
assert(size_ == 1); if (SPOT_UNLIKELY(size_ != 1))
throw std::invalid_argument
("get_child_of() expecting single-child node");
return nth(0); return nth(0);
} }
@ -211,14 +213,18 @@ namespace spot
/// \see formula::min /// \see formula::min
unsigned min() const unsigned min() const
{ {
assert(op_ == op::FStar || op_ == op::Star); if (SPOT_UNLIKELY(op_ != op::FStar && op_ != op::Star))
throw std::invalid_argument
("min() only works on Star and FStar nodes");
return min_; return min_;
} }
/// \see formula::max /// \see formula::max
unsigned max() const unsigned max() const
{ {
assert(op_ == op::FStar || op_ == op::Star); if (SPOT_UNLIKELY(op_ != op::FStar && op_ != op::Star))
throw std::invalid_argument
("max() only works on Star and FStar nodes");
return max_; return max_;
} }
@ -580,8 +586,8 @@ namespace spot
bool bool
operator()(const fnode* left, const fnode* right) const operator()(const fnode* left, const fnode* right) const
{ {
assert(left); SPOT_ASSERT(left);
assert(right); SPOT_ASSERT(right);
if (left == right) if (left == right)
return false; return false;

View file

@ -58,13 +58,13 @@ namespace spot
bool operator==(unsigned o) const bool operator==(unsigned o) const
{ {
assert(o == 0U); SPOT_ASSERT(o == 0U);
return id == o; return id == o;
} }
bool operator!=(unsigned o) const bool operator!=(unsigned o) const
{ {
assert(o == 0U); SPOT_ASSERT(o == 0U);
return id != o; return id != o;
} }
@ -1115,7 +1115,7 @@ namespace spot
mark_t mark(unsigned u) const mark_t mark(unsigned u) const
{ {
assert(u < num_sets()); SPOT_ASSERT(u < num_sets());
return 1U << u; return 1U << u;
} }

View file

@ -209,7 +209,7 @@ namespace spot
virtual std::string format_state(const spot::state* s) const override virtual std::string format_state(const spot::state* s) const override
{ {
const spot::set_state* se = down_cast<const spot::set_state*>(s); const spot::set_state* se = down_cast<const spot::set_state*>(s);
assert(se); SPOT_ASSERT(se);
const state_set* ss = se->get_state(); const state_set* ss = se->get_state();
return format_state_set(ss); return format_state_set(ss);
} }
@ -279,7 +279,7 @@ namespace spot
if (ss->size() == 1) if (ss->size() == 1)
{ {
i2 = state_name_map_.find(*i1); i2 = state_name_map_.find(*i1);
assert(i2 != state_name_map_.end()); SPOT_ASSERT(i2 != state_name_map_.end());
return "{" + label_to_string(i2->second) + "}"; return "{" + label_to_string(i2->second) + "}";
} }
else else
@ -288,7 +288,7 @@ namespace spot
while (i1 != ss->end()) while (i1 != ss->end())
{ {
i2 = state_name_map_.find(*i1++); i2 = state_name_map_.find(*i1++);
assert(i2 != state_name_map_.end()); SPOT_ASSERT(i2 != state_name_map_.end());
res += label_to_string(i2->second); res += label_to_string(i2->second);
res += ","; res += ",";
} }

View file

@ -129,7 +129,7 @@ namespace spot
bool bool
operator()(const state* left, const state* right) const operator()(const state* left, const state* right) const
{ {
assert(left); SPOT_ASSERT(left);
return left->compare(right) < 0; return left->compare(right) < 0;
} }
}; };
@ -152,7 +152,7 @@ namespace spot
bool bool
operator()(const state* left, const state* right) const operator()(const state* left, const state* right) const
{ {
assert(left); SPOT_ASSERT(left);
return 0 == left->compare(right); return 0 == left->compare(right);
} }
}; };
@ -176,7 +176,7 @@ namespace spot
size_t size_t
operator()(const state* that) const operator()(const state* that) const
{ {
assert(that); SPOT_ASSERT(that);
return that->hash(); return that->hash();
} }
}; };
@ -280,7 +280,7 @@ namespace spot
operator()(shared_state left, operator()(shared_state left,
shared_state right) const shared_state right) const
{ {
assert(left); SPOT_ASSERT(left);
return left->compare(right.get()) < 0; return left->compare(right.get()) < 0;
} }
}; };
@ -308,7 +308,7 @@ namespace spot
operator()(shared_state left, operator()(shared_state left,
shared_state right) const shared_state right) const
{ {
assert(left); SPOT_ASSERT(left);
return 0 == left->compare(right.get()); return 0 == left->compare(right.get());
} }
}; };
@ -336,7 +336,7 @@ namespace spot
size_t size_t
operator()(shared_state that) const operator()(shared_state that) const
{ {
assert(that); SPOT_ASSERT(that);
return that->hash(); return that->hash();
} }
}; };

View file

@ -45,7 +45,7 @@ namespace spot
virtual int compare(const spot::state* other) const override virtual int compare(const spot::state* other) const override
{ {
auto o = down_cast<const twa_graph_state*>(other); auto o = down_cast<const twa_graph_state*>(other);
assert(o); SPOT_ASSERT(o);
// Do not simply return "other - this", it might not fit in an int. // Do not simply return "other - this", it might not fit in an int.
if (o < this) if (o < this)
@ -145,19 +145,19 @@ namespace spot
virtual const twa_graph_state* dst() const override virtual const twa_graph_state* dst() const override
{ {
assert(!done()); SPOT_ASSERT(!done());
return &g_->state_data(g_->edge_storage(p_).dst); return &g_->state_data(g_->edge_storage(p_).dst);
} }
virtual bdd cond() const override virtual bdd cond() const override
{ {
assert(!done()); SPOT_ASSERT(!done());
return g_->edge_data(p_).cond; return g_->edge_data(p_).cond;
} }
virtual acc_cond::mark_t acc() const override virtual acc_cond::mark_t acc() const override
{ {
assert(!done()); SPOT_ASSERT(!done());
return g_->edge_data(p_).acc; return g_->edge_data(p_).acc;
} }
@ -251,7 +251,9 @@ namespace spot
void set_init_state(state_num s) void set_init_state(state_num s)
{ {
assert(s < num_states()); if (SPOT_UNLIKELY(s >= num_states()))
throw std::invalid_argument
("set_init_state() called with nonexisiting state");
init_number_ = s; init_number_ = s;
} }
@ -278,8 +280,8 @@ namespace spot
succ_iter(const state* st) const override succ_iter(const state* st) const override
{ {
auto s = down_cast<const typename graph_t::state_storage_t*>(st); auto s = down_cast<const typename graph_t::state_storage_t*>(st);
assert(s); SPOT_ASSERT(s);
assert(!s->succ || g_.is_valid_edge(s->succ)); SPOT_ASSERT(!s->succ || g_.is_valid_edge(s->succ));
if (this->iter_cache_) if (this->iter_cache_)
{ {
@ -296,7 +298,7 @@ namespace spot
state_number(const state* st) const state_number(const state* st) const
{ {
auto s = down_cast<const typename graph_t::state_storage_t*>(st); auto s = down_cast<const typename graph_t::state_storage_t*>(st);
assert(s); SPOT_ASSERT(s);
return s - &g_.state_storage(0); return s - &g_.state_storage(0);
} }
@ -451,7 +453,11 @@ namespace spot
acc_cond::mark_t state_acc_sets(unsigned s) const acc_cond::mark_t state_acc_sets(unsigned s) const
{ {
assert((bool)prop_state_acc() || num_sets() == 0); if (SPOT_UNLIKELY(!((bool)prop_state_acc() || num_sets() == 0)))
throw std::runtime_error
("state_acc_sets() should only be called on "
"automata with state-based acceptance");
for (auto& t: g_.out(s)) for (auto& t: g_.out(s))
// Stop at the first edge, since the remaining should be // Stop at the first edge, since the remaining should be
// labeled identically. // labeled identically.
@ -461,7 +467,10 @@ namespace spot
bool state_is_accepting(unsigned s) const bool state_is_accepting(unsigned s) const
{ {
assert((bool)prop_state_acc() || num_sets() == 0); if (SPOT_UNLIKELY(!((bool)prop_state_acc() || num_sets() == 0)))
throw std::runtime_error
("state_is_accepting() should only be called on "
"automata with state-based acceptance");
for (auto& t: g_.out(s)) for (auto& t: g_.out(s))
// Stop at the first edge, since the remaining should be // Stop at the first edge, since the remaining should be
// labeled identically. // labeled identically.

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2015 Laboratoire de Recherche et Développement de // Copyright (C) 2015, 2016 Laboratoire de Recherche et Développement de
// l'Epita (LRDE). // l'Epita (LRDE).
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 // Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6
// (LIP6), département Systèmes Répartis Coopératifs (SRC), Université // (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
@ -43,7 +43,7 @@ namespace spot
get(const char* str) const get(const char* str) const
{ {
auto i = stats.find(str); auto i = stats.find(str);
assert(i != stats.end()); SPOT_ASSERT(i != stats.end());
return (this->*i->second)(); return (this->*i->second)();
} }
@ -163,7 +163,7 @@ namespace spot
void void
dec_depth(unsigned n = 1) dec_depth(unsigned n = 1)
{ {
assert(depth_ >= n); SPOT_ASSERT(depth_ >= n);
depth_ -= n; depth_ -= n;
} }

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2015 Laboratoire de Recherche et Développement // Copyright (C) 2015, 2016 Laboratoire de Recherche et Développement
// de l'Epita (LRDE). // de l'Epita (LRDE).
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
@ -66,7 +66,7 @@ namespace spot
todo.pop_back(); todo.pop_back();
unsigned new_src = seen[old_src]; unsigned new_src = seen[old_src];
assert(new_src != -1U); SPOT_ASSERT(new_src != -1U);
for (auto& t: old->out(old_src)) for (auto& t: old->out(old_src))
{ {
@ -112,7 +112,7 @@ namespace spot
trans(t.src, cond, acc, t.dst); trans(t.src, cond, acc, t.dst);
// Having the same number of states should assure that state ids are // Having the same number of states should assure that state ids are
// equivilent in old and cpy. // equivilent in old and cpy.
assert(t.src < cpy->num_states() && t.dst < cpy->num_states()); SPOT_ASSERT(t.src < cpy->num_states() && t.dst < cpy->num_states());
if (cond != bddfalse) if (cond != bddfalse)
cpy->new_edge(t.src, t.dst, cond, acc); cpy->new_edge(t.src, t.dst, cond, acc);
} }

View file

@ -109,7 +109,7 @@ namespace spot
const stack_type& stb = ms_->get_st_blue(); const stack_type& stb = ms_->get_st_blue();
const stack_type& str = ms_->get_st_red(); const stack_type& str = ms_->get_st_red();
assert(!stb.empty()); SPOT_ASSERT(!stb.empty());
acc_cond::mark_t covered_acc = 0U; acc_cond::mark_t covered_acc = 0U;
accepting_transitions_list acc_trans; accepting_transitions_list acc_trans;
@ -128,8 +128,8 @@ namespace spot
i = stb.begin(); i = stb.begin();
transition t = { i->s->clone(), j->label, j->acc, transition t = { i->s->clone(), j->label, j->acc,
j->s->clone() }; j->s->clone() };
assert(h_.has_been_visited(t.source)); SPOT_ASSERT(h_.has_been_visited(t.source));
assert(h_.has_been_visited(t.dest)); SPOT_ASSERT(h_.has_been_visited(t.dest));
acc_trans.push_back(t); acc_trans.push_back(t);
} }
else else
@ -148,8 +148,8 @@ namespace spot
{ {
transition t = { i->s->clone(), j->label, j->acc, transition t = { i->s->clone(), j->label, j->acc,
j->s->clone() }; j->s->clone() };
assert(h_.has_been_visited(t.source)); SPOT_ASSERT(h_.has_been_visited(t.source));
assert(h_.has_been_visited(t.dest)); SPOT_ASSERT(h_.has_been_visited(t.dest));
acc_trans.push_back(t); acc_trans.push_back(t);
covered_acc |= j->acc; covered_acc |= j->acc;
} }
@ -160,8 +160,8 @@ namespace spot
{ {
transition t = { i->s->clone(), j->label, j->acc, transition t = { i->s->clone(), j->label, j->acc,
j->s->clone() }; j->s->clone() };
assert(h_.has_been_visited(t.source)); SPOT_ASSERT(h_.has_been_visited(t.source));
assert(h_.has_been_visited(t.dest)); SPOT_ASSERT(h_.has_been_visited(t.dest));
acc_trans.push_back(t); acc_trans.push_back(t);
covered_acc |= j->acc; covered_acc |= j->acc;
} }
@ -174,8 +174,8 @@ namespace spot
{ {
transition t = { i->s->clone(), j->label, j->acc, transition t = { i->s->clone(), j->label, j->acc,
j->s->clone() }; j->s->clone() };
assert(h_.has_been_visited(t.source)); SPOT_ASSERT(h_.has_been_visited(t.source));
assert(h_.has_been_visited(t.dest)); SPOT_ASSERT(h_.has_been_visited(t.dest));
acc_trans.push_back(t); acc_trans.push_back(t);
covered_acc |= j->acc; covered_acc |= j->acc;
} }
@ -186,13 +186,13 @@ namespace spot
if (!a_->acc().accepting(covered_acc)) if (!a_->acc().accepting(covered_acc))
{ {
bool b = dfs(start, acc_trans, covered_acc); bool b = dfs(start, acc_trans, covered_acc);
assert(b); SPOT_ASSERT(b);
(void) b; (void) b;
} }
start->destroy(); start->destroy();
assert(!acc_trans.empty()); SPOT_ASSERT(!acc_trans.empty());
auto run = std::make_shared<twa_run>(automaton()); auto run = std::make_shared<twa_run>(automaton());
// construct run->cycle from acc_trans. // construct run->cycle from acc_trans.
@ -254,7 +254,7 @@ namespace spot
bool dfs(const state* target, accepting_transitions_list& acc_trans, bool dfs(const state* target, accepting_transitions_list& acc_trans,
acc_cond::mark_t& covered_acc) acc_cond::mark_t& covered_acc)
{ {
assert(h_.has_been_visited(target)); SPOT_ASSERT(h_.has_been_visited(target));
stack_type st1; stack_type st1;
state_set seen, dead; state_set seen, dead;
@ -303,8 +303,8 @@ namespace spot
{ {
transition t = { f.s->clone(), label, acc, transition t = { f.s->clone(), label, acc,
s_prime->clone() }; s_prime->clone() };
assert(h_.has_been_visited(t.source)); SPOT_ASSERT(h_.has_been_visited(t.source));
assert(h_.has_been_visited(t.dest)); SPOT_ASSERT(h_.has_been_visited(t.dest));
acc_trans.push_back(t); acc_trans.push_back(t);
covered_acc |= acc; covered_acc |= acc;
if (a_->acc().accepting(covered_acc)) if (a_->acc().accepting(covered_acc))
@ -345,8 +345,8 @@ namespace spot
transition t = { st1.front().s->clone(), transition t = { st1.front().s->clone(),
f_dest.label, f_dest.acc, f_dest.label, f_dest.acc,
f_dest.s->clone() }; f_dest.s->clone() };
assert(h_.has_been_visited(t.source)); SPOT_ASSERT(h_.has_been_visited(t.source));
assert(h_.has_been_visited(t.dest)); SPOT_ASSERT(h_.has_been_visited(t.dest));
acc_trans.push_back(t); acc_trans.push_back(t);
covered_acc |= f_dest.acc; covered_acc |= f_dest.acc;
if (a_->acc().accepting(covered_acc)) if (a_->acc().accepting(covered_acc))
@ -446,7 +446,7 @@ namespace spot
const state* res = s.search(start->clone(), path); const state* res = s.search(start->clone(), path);
if (res) if (res)
{ {
assert(res->compare(target) == 0); SPOT_ASSERT(res->compare(target) == 0);
return true; return true;
} }
else else
@ -531,7 +531,7 @@ namespace spot
void construct_cycle(twa_run_ptr run, void construct_cycle(twa_run_ptr run,
const accepting_transitions_list& acc_trans) const accepting_transitions_list& acc_trans)
{ {
assert(!acc_trans.empty()); SPOT_ASSERT(!acc_trans.empty());
transition current = acc_trans.front(); transition current = acc_trans.front();
// insert the first accepting transition in the cycle // insert the first accepting transition in the cycle
ndfsr_trace << "the initial accepting transition is from " ndfsr_trace << "the initial accepting transition is from "
@ -579,10 +579,10 @@ namespace spot
min_path<true> s(this, a_, target, h_); min_path<true> s(this, a_, target, h_);
const state* res = s.search(current.dest->clone(), run->cycle); const state* res = s.search(current.dest->clone(), run->cycle);
// init current to the corresponding transition. // init current to the corresponding transition.
assert(res); SPOT_ASSERT(res);
ndfsr_trace << a_->format_state(res) << " reached" << std::endl; ndfsr_trace << a_->format_state(res) << " reached" << std::endl;
i = target.find(res); i = target.find(res);
assert(i != target.end()); SPOT_ASSERT(i != target.end());
} }
else else
{ {
@ -611,8 +611,8 @@ namespace spot
target.emplace(begin, tmp); target.emplace(begin, tmp);
min_path<true> s(this, a_, target, h_); min_path<true> s(this, a_, target, h_);
const state* res = s.search(current.dest->clone(), run->cycle); const state* res = s.search(current.dest->clone(), run->cycle);
assert(res); SPOT_ASSERT(res);
assert(res->compare(begin) == 0); SPOT_ASSERT(res->compare(begin) == 0);
(void)res; (void)res;
} }
} }
@ -648,7 +648,7 @@ namespace spot
// This initial state is outside the cycle. Compute the prefix. // This initial state is outside the cycle. Compute the prefix.
min_path<false> s(this, a_, target, h_); min_path<false> s(this, a_, target, h_);
cycle_entry_point = s.search(prefix_start, run->prefix); cycle_entry_point = s.search(prefix_start, run->prefix);
assert(cycle_entry_point); SPOT_ASSERT(cycle_entry_point);
cycle_entry_point = cycle_entry_point->clone(); cycle_entry_point = cycle_entry_point->clone();
} }
@ -658,7 +658,7 @@ namespace spot
cycle_ep_it != run->cycle.end() cycle_ep_it != run->cycle.end()
&& cycle_entry_point->compare(cycle_ep_it->s); ++cycle_ep_it) && cycle_entry_point->compare(cycle_ep_it->s); ++cycle_ep_it)
continue; continue;
assert(cycle_ep_it != run->cycle.end()); SPOT_ASSERT(cycle_ep_it != run->cycle.end());
cycle_entry_point->destroy(); cycle_entry_point->destroy();
// Now shift the cycle so it starts on cycle_entry_point. // Now shift the cycle so it starts on cycle_entry_point.

View file

@ -1,6 +1,6 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2014, 2015 Laboratoire de Recherche et Développement // Copyright (C) 2014, 2015, 2016 Laboratoire de Recherche et
// de l'Epita. // Développement de l'Epita.
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
// //
@ -108,7 +108,6 @@ namespace spot
const scc_node& node(unsigned scc) const const scc_node& node(unsigned scc) const
{ {
assert(scc < node_.size());
return node_[scc]; return node_[scc];
} }
@ -132,7 +131,6 @@ namespace spot
unsigned scc_of(unsigned st) const unsigned scc_of(unsigned st) const
{ {
assert(st < sccof_.size());
return sccof_[st]; return sccof_[st];
} }
@ -162,7 +160,7 @@ namespace spot
/// \brief Get number of the SCC containing the initial state. /// \brief Get number of the SCC containing the initial state.
unsigned initial() const unsigned initial() const
{ {
assert(scc_count() - 1 == scc_of(aut_->get_init_state_number())); SPOT_ASSERT(scc_count() - 1 == scc_of(aut_->get_init_state_number()));
return scc_count() - 1; return scc_count() - 1;
} }

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2013, 2014, 2015 Laboratoire de Recherche et // Copyright (C) 2013, 2014, 2015, 2016 Laboratoire de Recherche et
// Développement de l'Epita (LRDE). // 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.
@ -50,7 +50,7 @@ namespace spot
translator(tl_simplifier* simpl, const option_map* opt = nullptr) translator(tl_simplifier* simpl, const option_map* opt = nullptr)
: postprocessor(opt), simpl_(simpl), simpl_owned_(nullptr) : postprocessor(opt), simpl_(simpl), simpl_owned_(nullptr)
{ {
assert(simpl); SPOT_ASSERT(simpl);
setup_opt(opt); setup_opt(opt);
} }

View file

@ -301,7 +301,10 @@ for dir in "$TOP/spot" "$TOP/bin" "$TOP/tests"; do
*) *)
$GREP '#.*include.*priv/' $tmp && $GREP '#.*include.*priv/' $tmp &&
diag 'Do not include private headers in public headers.' diag 'Do not include private headers in public headers.'
$GREP -v '#' $tmp | $GREP 'assert[ ]*(.*)' &&
diag 'Use SPOT_ASSERT() instead of assert() in public headers.'
;; ;;
esac esac
;; ;;
*.cc) *.cc)
@ -313,7 +316,7 @@ for dir in "$TOP/spot" "$TOP/bin" "$TOP/tests"; do
diag 'Private definitions must be in anonymous namespace.' diag 'Private definitions must be in anonymous namespace.'
fi fi
e$GREP ' ' $tmp && e$GREP ' ' $tmp &&
diag 'Use spaces instead of tabular.' diag 'Use spaces instead of tabs.'
;; ;;
esac esac
case $file in case $file in