spot/src/ltlast/formula_tree.cc
Alexandre Duret-Lutz 2beacc3924 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");
2014-06-27 15:55:26 +02:00

82 lines
2.7 KiB
C++

// -*- coding: utf-8 -*-
// Copyright (C) 2009, 2012, 2013, 2014 Laboratoire de Recherche et
// Développement de l'Epita (LRDE).
//
// 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 3 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 this program. If not, see <http://www.gnu.org/licenses/>.
#include "config.h"
#include <cassert>
#include "formula_tree.hh"
#include "allnodes.hh"
namespace spot
{
namespace ltl
{
namespace formula_tree
{
const formula*
instanciate(const node_ptr np, const std::vector<const formula*>& v)
{
if (node_atomic* n = dynamic_cast<node_atomic*>(np.get()))
return n->i == True ? constant::true_instance() :
n->i == False ? constant::false_instance() : v.at(n->i)->clone();
if (node_unop* n = dynamic_cast<node_unop*>(np.get()))
return unop::instance(n->op, instanciate(n->child, v));
if (node_nfa* n = dynamic_cast<node_nfa*>(np.get()))
{
automatop::vec* va = new automatop::vec;
std::vector<node_ptr>::const_iterator i = n->children.begin();
while (i != n->children.end())
va->push_back(instanciate(*i++, v));
return automatop::instance(n->nfa, va, false);
}
if (node_binop* n = dynamic_cast<node_binop*>(np.get()))
return binop::instance(n->op,
instanciate(n->lhs, v),
instanciate(n->rhs, v));
if (node_multop* n = dynamic_cast<node_multop*>(np.get()))
return multop::instance(n->op,
instanciate(n->lhs, v),
instanciate(n->rhs, v));
SPOT_UNREACHABLE();
}
size_t
arity(const node_ptr np)
{
if (node_atomic* n = dynamic_cast<node_atomic*>(np.get()))
return std::max(n->i + 1, 0);
if (node_unop* n = dynamic_cast<node_unop*>(np.get()))
return arity(n->child);
if (node_nfa* n = dynamic_cast<node_nfa*>(np.get()))
{
size_t res = 0;
std::vector<node_ptr>::const_iterator i = n->children.begin();
while (i != n->children.end())
res = std::max(arity(*i++), res);
return res;
}
if (node_binop* n = dynamic_cast<node_binop*>(np.get()))
return std::max(arity(n->lhs), arity(n->rhs));
if (node_multop* n = dynamic_cast<node_multop*>(np.get()))
return std::max(arity(n->lhs), arity(n->rhs));
SPOT_UNREACHABLE();
}
}
}
}