to_string: abbreviate [->i..j] and [=i..j] expressed using [*i..j]

* src/ltlast/bunop.hh (is_bunop, is_Star): New functions.
* src/ltlast/multop.hh (is_And, is_Or): Fix constness.
(is_Concat, is_Fusion): New functions.
* src/ltlast/unop.hh (is_unop, is_X, is_F, is_G, is_GF, is_FG):
Fix constness.
(is_Not): New function.
* src/ltlvisit/tostring.cc (strip_star_not, match_goto,
emit_bunop_child, resugar_concat): New methods.
(visit(bunop)): Rewrite without calling format().  Detect the
[->i..j] pattern.
(visit(multop)): Call resugar_concat to detect [=i..j] patterns.
This commit is contained in:
Alexandre Duret-Lutz 2012-04-13 23:01:28 +02:00
parent e109f21ce4
commit 39417037d7
4 changed files with 287 additions and 35 deletions

View file

@ -1,4 +1,4 @@
// Copyright (C) 2010, 2011 Laboratoire de Recherche et Développement
// Copyright (C) 2010, 2011, 2012 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
@ -120,6 +120,45 @@ namespace spot
unsigned max_;
};
/// \brief Cast \a f into a bunop.
///
/// Cast \a f into a bunop iff it is a bunop instance. Return 0
/// otherwise. This is faster than \c dynamic_cast.
inline
bunop*
is_bunop(const formula* f)
{
if (f->kind() != formula::BUnOp)
return 0;
return static_cast<bunop*>(const_cast<formula*>(f));
}
/// \brief Cast \a f into a bunop if it has type \a op.
///
/// Cast \a f into a bunop iff it is a bunop instance with operator \a op.
/// Returns 0 otherwise.
inline
bunop*
is_bunop(const formula* f, bunop::type op)
{
if (f->kind() != formula::BUnOp)
return 0;
bunop* bo = static_cast<bunop*>(const_cast<formula*>(f));
if (bo->op() != op)
return 0;
return bo;
}
/// \brief Cast \a f into a bunop if it is a Star.
///
/// Return 0 otherwise.
inline
bunop*
is_Star(const formula* f)
{
return is_bunop(f, bunop::Star);
}
}
}
#endif // SPOT_LTLAST_BUNOP_HH

View file

@ -216,7 +216,7 @@ namespace spot
/// Return 0 otherwise.
inline
multop*
is_And(formula* f)
is_And(const formula* f)
{
return is_multop(f, multop::And);
}
@ -226,10 +226,30 @@ namespace spot
/// Return 0 otherwise.
inline
multop*
is_Or(formula* f)
is_Or(const formula* f)
{
return is_multop(f, multop::Or);
}
/// \brief Cast \a f into a multop if it is a Concat.
///
/// Return 0 otherwise.
inline
multop*
is_Concat(const formula* f)
{
return is_multop(f, multop::Concat);
}
/// \brief Cast \a f into a multop if it is a Fusion.
///
/// Return 0 otherwise.
inline
multop*
is_Fusion(const formula* f)
{
return is_multop(f, multop::Fusion);
}
}
}

View file

@ -131,11 +131,11 @@ namespace spot
/// otherwise. This is faster than \c dynamic_cast.
inline
unop*
is_unop(formula* f)
is_unop(const formula* f)
{
if (f->kind() != formula::UnOp)
return 0;
return static_cast<unop*>(f);
return static_cast<unop*>(const_cast<formula*>(f));
}
/// \brief Cast \a f into a unop if it has type \a op.
@ -144,22 +144,32 @@ namespace spot
/// Returns 0 otherwise.
inline
unop*
is_unop(formula* f, unop::type op)
is_unop(const formula* f, unop::type op)
{
if (f->kind() != formula::UnOp)
return 0;
unop* uo = static_cast<unop*>(f);
unop* uo = static_cast<unop*>(const_cast<formula*>(f));
if (uo->op() != op)
return 0;
return uo;
}
/// \brief Cast \a f into a unop if it is a Not.
///
/// Return 0 otherwise.
inline
unop*
is_Not(const formula* f)
{
return is_unop(f, unop::Not);
}
/// \brief Cast \a f into a unop if it is a X.
///
/// Return 0 otherwise.
inline
unop*
is_X(formula* f)
is_X(const formula* f)
{
return is_unop(f, unop::X);
}
@ -169,7 +179,7 @@ namespace spot
/// Return 0 otherwise.
inline
unop*
is_F(formula* f)
is_F(const formula* f)
{
return is_unop(f, unop::F);
}
@ -179,7 +189,7 @@ namespace spot
/// Return 0 otherwise.
inline
unop*
is_G(formula* f)
is_G(const formula* f)
{
return is_unop(f, unop::G);
}
@ -189,7 +199,7 @@ namespace spot
/// Return 0 otherwise.
inline
unop*
is_GF(formula* f)
is_GF(const formula* f)
{
unop* op = is_G(f);
if (!op)
@ -202,7 +212,7 @@ namespace spot
/// Return 0 otherwise.
inline
unop*
is_FG(formula* f)
is_FG(const formula* f)
{
unop* op = is_F(f);
if (!op)