Commit 7d27fd37 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

* iface/gspn/gspn.cc, src/ltlvisit/basicreduce.cc,

src/ltlvisit/destroy.cc, src/ltlvisit/dotty.cc,
src/ltlvisit/dump.cc, src/ltlvisit/length.cc,
src/ltlvisit/nenoform.cc, src/ltlvisit/reduce.cc,
src/ltlvisit/syntimpl.cc, src/ltlvisit/tostring.cc,
src/tgba/formula2bdd.cc, src/tgba/tgbabddconcreteproduct.cc,
src/tgba/tgbatba.cc, src/tgbaalgos/dotty.cc,
src/tgbaalgos/dupexp.cc, src/tgbaalgos/lbtt.cc,
src/tgbaalgos/ltl2tgba_lacim.cc, src/tgbaalgos/neverclaim.cc,
src/tgbaalgos/save.cc, src/tgbaalgos/stats.cc,
src/tgbaalgos/gtec/nsheap.cc, src/tgbaalgos/gtec/nsheap.hh:
Declare private classes and helper function in anonymous namespaces.
* HACKING, src/sanity/style.test: Document and check this.
Also check for trailing { after namespace or class.
* src/ltlast/predecl.hh, src/ltlast/visitor.hh,
src/tgba/tgbareduc.hh: Fix trailing {.
parent 5176caf4
2004-10-18 Alexandre Duret-Lutz <adl@src.lip6.fr>
* iface/gspn/gspn.cc, src/ltlvisit/basicreduce.cc,
src/ltlvisit/destroy.cc, src/ltlvisit/dotty.cc,
src/ltlvisit/dump.cc, src/ltlvisit/length.cc,
src/ltlvisit/nenoform.cc, src/ltlvisit/reduce.cc,
src/ltlvisit/syntimpl.cc, src/ltlvisit/tostring.cc,
src/tgba/formula2bdd.cc, src/tgba/tgbabddconcreteproduct.cc,
src/tgba/tgbatba.cc, src/tgbaalgos/dotty.cc,
src/tgbaalgos/dupexp.cc, src/tgbaalgos/lbtt.cc,
src/tgbaalgos/ltl2tgba_lacim.cc, src/tgbaalgos/neverclaim.cc,
src/tgbaalgos/save.cc, src/tgbaalgos/stats.cc,
src/tgbaalgos/gtec/nsheap.cc, src/tgbaalgos/gtec/nsheap.hh:
Declare private classes and helper function in anonymous namespaces.
* HACKING, src/sanity/style.test: Document and check this.
Also check for trailing { after namespace or class.
* src/ltlast/predecl.hh, src/ltlast/visitor.hh,
src/tgba/tgbareduc.hh: Fix trailing {.
2004-10-15 Alexandre Duret-Lutz <adl@src.lip6.fr>
* src/tgbaalgos/gtec/ce.cc: Reinstall change from 2004-09-21.
......
......@@ -249,3 +249,9 @@ Other style recommandations
Prefer <iosfwd> when predeclarations are sufficient, and then
use for instance use just <ostream> in the corresponding .cc file.
(A plain <iostream> is needed when using std::cout, std::cerr, etc.)
* Always declare helper functions and other local class definitions
(used in a single .cc files) in anonymous namespaces. (The risk
otherwise is to declare two classes with the same name: the linker
will ignore one of the two silently. The resulting bugs are often
difficult to understand.)
This diff is collapsed.
......@@ -29,8 +29,10 @@
#ifndef SPOT_LTLAST_PREDECL_HH
# define SPOT_LTLAST_PREDECL_HH
namespace spot {
namespace ltl {
namespace spot
{
namespace ltl
{
struct visitor;
struct const_visitor;
......
......@@ -26,9 +26,10 @@
#include "predecl.hh"
namespace spot {
namespace ltl {
namespace spot
{
namespace ltl
{
/// \brief Formula visitor that can modify the formula.
///
/// Writing visitors is the prefered way
......
This diff is collapsed.
// Copyright (C) 2003 Laboratoire d'Informatique de Paris 6 (LIP6),
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
......@@ -25,16 +25,18 @@ namespace spot
{
namespace ltl
{
class destroy_visitor : public postfix_visitor
namespace
{
public:
virtual void
doit_default(formula* c)
class destroy_visitor: public postfix_visitor
{
formula::unref(c);
}
};
public:
virtual void
doit_default(formula* c)
{
formula::unref(c);
}
};
}
void
destroy(const formula* f)
......
......@@ -29,99 +29,101 @@ namespace spot
{
namespace ltl
{
class dotty_visitor : public const_visitor
namespace
{
public:
typedef Sgi::hash_map<const formula*, int, ptr_hash<formula> > map;
dotty_visitor(std::ostream& os, map& m)
: os_(os), father_(-1), node_(m)
class dotty_visitor: public const_visitor
{
}
public:
typedef Sgi::hash_map<const formula*, int, ptr_hash<formula> > map;
dotty_visitor(std::ostream& os, map& m)
: os_(os), father_(-1), node_(m)
{
}
virtual
~dotty_visitor()
{
}
virtual
~dotty_visitor()
{
}
void
visit(const atomic_prop* ap)
{
draw_node_(ap, ap->name(), true);
}
void
visit(const atomic_prop* ap)
{
draw_node_(ap, ap->name(), true);
}
void
visit(const constant* c)
{
draw_node_(c, c->val_name(), true);
}
void
visit(const constant* c)
{
draw_node_(c, c->val_name(), true);
}
void
visit(const binop* bo)
{
if (draw_node_(bo, bo->op_name()))
{
dotty_visitor v(*this);
bo->first()->accept(v);
bo->second()->accept(*this);
}
}
void
visit(const binop* bo)
{
if (draw_node_(bo, bo->op_name()))
{
dotty_visitor v(*this);
bo->first()->accept(v);
bo->second()->accept(*this);
}
}
void
visit(const unop* uo)
{
if (draw_node_(uo, uo->op_name()))
uo->child()->accept(*this);
}
void
visit(const unop* uo)
{
if (draw_node_(uo, uo->op_name()))
uo->child()->accept(*this);
}
void
visit(const multop* mo)
{
if (!draw_node_(mo, mo->op_name()))
return;
unsigned max = mo->size();
for (unsigned n = 0; n < max; ++n)
{
dotty_visitor v(*this);
mo->nth(n)->accept(v);
}
}
private:
std::ostream& os_;
int father_;
map& node_;
void
visit(const multop* mo)
{
if (!draw_node_(mo, mo->op_name()))
return;
unsigned max = mo->size();
for (unsigned n = 0; n < max; ++n)
{
dotty_visitor v(*this);
mo->nth(n)->accept(v);
}
}
private:
std::ostream& os_;
int father_;
map& node_;
bool
draw_node_(const formula* f, const std::string& str, bool rec = false)
{
map::iterator i = node_.find(f);
int node;
bool node_exists = false;
if (i != node_.end())
{
node = i->second;
node_exists = true;
}
else
{
node = node_.size();
node_[f] = node;
}
// the link
if (father_ >= 0)
os_ << " " << father_ << " -> " << node << ";" << std::endl;
father_ = node;
// the node
if (node_exists)
return false;
os_ << " " << node
<< " [label=\"" << str << "\"";
if (rec)
os_ << ", shape=box";
os_ << "];" << std::endl;
return true;
}
};
bool
draw_node_(const formula* f, const std::string& str, bool rec = false)
{
map::iterator i = node_.find(f);
int node;
bool node_exists = false;
if (i != node_.end())
{
node = i->second;
node_exists = true;
}
else
{
node = node_.size();
node_[f] = node;
}
// the link
if (father_ >= 0)
os_ << " " << father_ << " -> " << node << ";" << std::endl;
father_ = node;
// the node
if (node_exists)
return false;
os_ << " " << node
<< " [label=\"" << str << "\"";
if (rec)
os_ << ", shape=box";
os_ << "];" << std::endl;
return true;
}
};
}
std::ostream&
dotty(std::ostream& os, const formula* f)
......
......@@ -28,66 +28,68 @@ namespace spot
{
namespace ltl
{
class dump_visitor : public const_visitor
namespace
{
public:
dump_visitor(std::ostream& os)
: os_(os)
class dump_visitor: public const_visitor
{
}
public:
dump_visitor(std::ostream& os)
: os_(os)
{
}
virtual
~dump_visitor()
{
}
virtual
~dump_visitor()
{
}
void
visit(const atomic_prop* ap)
{
os_ << "AP(" << ap->name() << ")";
}
void
visit(const atomic_prop* ap)
{
os_ << "AP(" << ap->name() << ")";
}
void
visit(const constant* c)
{
os_ << "constant(" << c->val_name() << ")";
}
void
visit(const constant* c)
{
os_ << "constant(" << c->val_name() << ")";
}
void
visit(const binop* bo)
{
os_ << "binop(" << bo->op_name() << ", ";
bo->first()->accept(*this);
os_ << ", ";
bo->second()->accept(*this);
os_ << ")";
}
void
visit(const binop* bo)
{
os_ << "binop(" << bo->op_name() << ", ";
bo->first()->accept(*this);
os_ << ", ";
bo->second()->accept(*this);
os_ << ")";
}
void
visit(const unop* uo)
{
os_ << "unop(" << uo->op_name() << ", ";
uo->child()->accept(*this);
os_ << ")";
}
void
visit(const unop* uo)
{
os_ << "unop(" << uo->op_name() << ", ";
uo->child()->accept(*this);
os_ << ")";
}
void
visit(const multop* mo)
{
os_ << "multop(" << mo->op_name() << ", ";
unsigned max = mo->size();
mo->nth(0)->accept(*this);
for (unsigned n = 1; n < max; ++n)
{
os_ << ", ";
mo->nth(n)->accept(*this);
}
os_ << ")";
}
private:
std::ostream& os_;
};
void
visit(const multop* mo)
{
os_ << "multop(" << mo->op_name() << ", ";
unsigned max = mo->size();
mo->nth(0)->accept(*this);
for (unsigned n = 1; n < max; ++n)
{
os_ << ", ";
mo->nth(n)->accept(*this);
}
os_ << ")";
}
private:
std::ostream& os_;
};
}
std::ostream&
dump(std::ostream& os, const formula* f)
......
......@@ -27,62 +27,64 @@ namespace spot
{
namespace ltl
{
class length_visitor : public const_visitor
namespace
{
public:
length_visitor()
class length_visitor: public const_visitor
{
result_ = 0;
}
public:
virtual
~length_visitor()
{
}
length_visitor()
{
result_ = 0;
}
int
result() const
{
return result_;
}
virtual
~length_visitor()
{
}
void
visit(const atomic_prop*)
{
result_ = 1;
}
int
result() const
{
return result_;
}
void
visit(const constant*)
{
result_ = 1;
}
void
visit(const atomic_prop*)
{
result_ = 1;
}
void
visit(const unop* uo)
{
result_ = 1 + length(uo->child());
}
void
visit(const constant*)
{
result_ = 1;
}
void
visit(const binop* bo)
{
result_ = 1 + length(bo->first()) + length(bo->second());
}
void
visit(const unop* uo)
{
result_ = 1 + length(uo->child());
}
void
visit(const multop* mo)
{
unsigned mos = mo->size();
for (unsigned i = 0; i < mos; ++i)
result_ += length(mo->nth(i));
}
void
visit(const binop* bo)
{
result_ = 1 + length(bo->first()) + length(bo->second());
}
protected:
int result_; // size of the formula
};
void
visit(const multop* mo)
{
unsigned mos = mo->size();
for (unsigned i = 0; i < mos; ++i)
result_ += length(mo->nth(i));
}
protected:
int result_; // size of the formula
};
}
int
length(const formula* f)
......
......@@ -27,166 +27,170 @@ namespace spot
{
namespace ltl
{
class negative_normal_form_visitor : public visitor
namespace
{
public:
negative_normal_form_visitor(bool negated)
: negated_(negated)
{
}
virtual
~negative_normal_form_visitor()
{
}
formula* result() const
{
return result_;
}
void
visit(atomic_prop* ap)
{
formula* f = ap->ref();
if (negated_)
result_ = unop::instance(unop::Not, f);
else
result_ = f;
}
void
visit(constant* c)
{
if (!negated_)
{
result_ = c;
return;
}
switch (c->val())
{
case constant::True:
result_ = constant::false_instance();
return;
case constant::False:
result_ = constant::true_instance();
return;
}
/* Unreachable code. */
assert(0);
}
void
visit(unop* uo)
{
formula* f = uo->child();
switch (uo->op())
{
case unop::Not:
result_ = recurse_(f, negated_ ^ true);
return;
case unop::X:
/* !Xa == X!a */
result_ = unop::instance(unop::X, recurse(f));
return;
case unop::F:
/* !Fa == G!a */
result_ = unop::instance(negated_ ? unop::G : unop::F, recurse(f));
return;
case unop::G:
/* !Ga == F!a */
result_ = unop::instance(negated_ ? unop::F : unop::G, recurse(f));
return;
}
/* Unreachable code. */
assert(0);
}
void
visit(binop* bo)
{
formula* f1 = bo->first();
formula* f2 = bo->second();
switch (bo->op())
{
case binop::Xor:
/* !(a ^ b) == a <=> b */
result_ = binop::instance(negated_ ? binop::Equiv : binop::Xor,
recurse_(f1, false),
recurse_(f2, false));
return;
case binop::Equiv:
/* !(a <=> b) == a ^ b */
result_ = binop::instance(negated_ ? binop::Xor : binop::Equiv,
recurse_(f1, false),
recurse_(f2, false));
return;
case binop::Implies:
if (negated_)