* src/ltlvisit/length.hh (length_boolone): New function.
* src/ltlvisit/length.cc (length_boolone): Implement it using...
(length_boolone_visitor): ... this new visitor.
* src/ltltest/randltl.cc: Use length_boolone() to check the result
of the random generator, and ignore any formula larger (in
length()) than opt_f. This fix a bug where the random formula
generator would sometime produce formula larger than requested,
because of the trivial rewriting of {f}[]->e as e|!f.
* src/ltltest/length.cc: Add option -b to call length_boolone().
* src/ltltest/length.test: Test length_boolone().
120 lines
2.6 KiB
C++
120 lines
2.6 KiB
C++
// Copyright (C) 2010, 2012 Laboratoire de Recherche et Développement de
|
|
// l'Epita (LRDE).
|
|
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 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.
|
|
//
|
|
// Spot is free software; you can redistribute it and/or modify it
|
|
// under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Spot is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
// License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Spot; see the file COPYING. If not, write to the Free
|
|
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
// 02111-1307, USA.
|
|
|
|
#include "length.hh"
|
|
#include "ltlvisit/postfix.hh"
|
|
#include "ltlast/multop.hh"
|
|
#include "ltlast/unop.hh"
|
|
|
|
namespace spot
|
|
{
|
|
namespace ltl
|
|
{
|
|
namespace
|
|
{
|
|
class length_visitor: public postfix_visitor
|
|
{
|
|
public:
|
|
length_visitor()
|
|
: result_(0)
|
|
{
|
|
}
|
|
|
|
int
|
|
result() const
|
|
{
|
|
return result_;
|
|
}
|
|
|
|
virtual void
|
|
visit(multop* mo)
|
|
{
|
|
unsigned s = mo->size();
|
|
for (unsigned i = 0; i < s; ++i)
|
|
mo->nth(i)->accept(*this);
|
|
// "a & b & c" should count for 5, even though it is
|
|
// stored as And(a,b,c).
|
|
result_ += s - 1;
|
|
}
|
|
|
|
virtual void
|
|
doit_default(formula*)
|
|
{
|
|
++result_;
|
|
}
|
|
|
|
protected:
|
|
int result_; // size of the formula
|
|
};
|
|
|
|
class length_boolone_visitor: public length_visitor
|
|
{
|
|
|
|
virtual void
|
|
visit(unop* uo)
|
|
{
|
|
++result_;
|
|
// Boolean formula have length one.
|
|
if (!uo->is_boolean())
|
|
uo->child()->accept(*this);
|
|
}
|
|
|
|
virtual void
|
|
visit(multop* mo)
|
|
{
|
|
// Boolean formula have length one.
|
|
if (mo->is_boolean())
|
|
{
|
|
++result_;
|
|
return;
|
|
}
|
|
|
|
unsigned s = mo->size();
|
|
for (unsigned i = 0; i < s; ++i)
|
|
mo->nth(i)->accept(*this);
|
|
// "a & b & c" should count for 5, even though it is
|
|
// stored as And(a,b,c).
|
|
result_ += s - 1;
|
|
}
|
|
|
|
};
|
|
}
|
|
|
|
int
|
|
length(const formula* f)
|
|
{
|
|
length_visitor v;
|
|
const_cast<formula*>(f)->accept(v);
|
|
return v.result();
|
|
}
|
|
|
|
int
|
|
length_boolone(const formula* f)
|
|
{
|
|
length_boolone_visitor v;
|
|
const_cast<formula*>(f)->accept(v);
|
|
return v.result();
|
|
}
|
|
|
|
}
|
|
}
|