Rename formula::ref and formula::unref as formula::clone

and formula::destroy.

* src/ltlast/atomic_prop.cc, src/ltlast/automatop.cc,
src/ltlast/binop.cc, src/ltlast/formula.hh, src/ltlast/formula.cc,
src/ltlast/multop.cc, src/ltlast/unop.cc, src/ltlenv/declenv.cc,
src/ltlvisit/basicreduce.cc, src/ltlvisit/clone.cc,
src/ltlvisit/destroy.cc, src/ltlvisit/nenoform.cc,
src/ltlvisit/randomltl.cc, src/ltlvisit/reduce.cc,
src/tgbatest/randtgba.cc: Adjust.
This commit is contained in:
Alexandre Duret-Lutz 2009-11-08 11:41:46 +01:00
parent 8e4e692e7f
commit b0888257f8
16 changed files with 63 additions and 54 deletions

View file

@ -1,3 +1,16 @@
2009-11-08 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Rename formula::ref and formula::unref as formula::clone
and formula::destroy.
* src/ltlast/atomic_prop.cc, src/ltlast/automatop.cc,
src/ltlast/binop.cc, src/ltlast/formula.hh, src/ltlast/formula.cc,
src/ltlast/multop.cc, src/ltlast/unop.cc, src/ltlenv/declenv.cc,
src/ltlvisit/basicreduce.cc, src/ltlvisit/clone.cc,
src/ltlvisit/destroy.cc, src/ltlvisit/nenoform.cc,
src/ltlvisit/randomltl.cc, src/ltlvisit/reduce.cc,
src/tgbatest/randtgba.cc: Adjust.
2009-11-07 Alexandre Duret-Lutz <adl@lrde.epita.fr> 2009-11-07 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Change the way references are counted to speedup cloning. Change the way references are counted to speedup cloning.

View file

@ -1,4 +1,4 @@
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2003, 2004, 2005, 2009 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
// et Marie Curie. // et Marie Curie.
// //
@ -78,11 +78,11 @@ namespace spot
map::iterator i = instances.find(p); map::iterator i = instances.find(p);
if (i != instances.end()) if (i != instances.end())
{ {
return static_cast<atomic_prop*>(i->second->ref()); return static_cast<atomic_prop*>(i->second->clone());
} }
atomic_prop* ap = new atomic_prop(name, env); atomic_prop* ap = new atomic_prop(name, env);
instances[p] = ap; instances[p] = ap;
return static_cast<atomic_prop*>(ap->ref()); return static_cast<atomic_prop*>(ap->clone());
} }
unsigned unsigned

View file

@ -50,7 +50,7 @@ namespace spot
// Dereference children. // Dereference children.
for (unsigned n = 0; n < size(); ++n) for (unsigned n = 0; n < size(); ++n)
formula::unref(nth(n)); formula::destroy(nth(n));
delete children_; delete children_;
} }
@ -79,13 +79,13 @@ namespace spot
{ {
// The instance already exists. // The instance already exists.
for (vec::iterator vi = v->begin(); vi != v->end(); ++vi) for (vec::iterator vi = v->begin(); vi != v->end(); ++vi)
formula::unref(*vi); formula::destroy(*vi);
delete v; delete v;
return static_cast<automatop*>(i->second->ref()); return static_cast<automatop*>(i->second->clone());
} }
automatop* res = new automatop(nfa, v, negated); automatop* res = new automatop(nfa, v, negated);
instances[p] = res; instances[p] = res;
return static_cast<automatop*>(res->ref()); return static_cast<automatop*>(res->clone());
} }
unsigned unsigned

View file

@ -48,8 +48,8 @@ namespace spot
instances.erase(i); instances.erase(i);
// Dereference children. // Dereference children.
formula::unref(first()); formula::destroy(first());
formula::unref(second()); formula::destroy(second());
} }
void void
@ -143,13 +143,13 @@ namespace spot
if (i != instances.end()) if (i != instances.end())
{ {
// This instance already exists. // This instance already exists.
formula::unref(first); formula::destroy(first);
formula::unref(second); formula::destroy(second);
return static_cast<binop*>(i->second->ref()); return static_cast<binop*>(i->second->clone());
} }
binop* ap = new binop(op, first, second); binop* ap = new binop(op, first, second);
instances[p] = ap; instances[p] = ap;
return static_cast<binop*>(ap->ref()); return static_cast<binop*>(ap->clone());
} }
unsigned unsigned

View file

@ -1,4 +1,4 @@
// Copyright (C) 2003, 2005 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2003, 2005, 2009 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
// et Marie Curie. // et Marie Curie.
// //
@ -27,7 +27,7 @@ namespace spot
namespace ltl namespace ltl
{ {
formula* formula*
formula::ref() formula::clone()
{ {
ref_(); ref_();
return this; return this;
@ -38,7 +38,7 @@ namespace spot
} }
void void
formula::unref(formula* f) formula::destroy(formula* f)
{ {
if (f->unref_()) if (f->unref_())
delete f; delete f;

View file

@ -79,17 +79,13 @@ namespace spot
/// \brief clone this node /// \brief clone this node
/// ///
/// This increments the reference counter of this node (if one is /// This increments the reference counter of this node (if one is
/// used). You should almost never use this method directly as /// used).
/// it doesn't touch the children. If you want to clone a formula* clone();
/// whole formula, use spot::ltl::clone() instead.
formula* ref();
/// \brief release this node /// \brief release this node
/// ///
/// This decrements the reference counter of this node (if one is /// This decrements the reference counter of this node (if one is
/// used) and can free the object. You should almost never use /// used) and can free the object.
/// this method directly as it doesn't touch the children. If you static void destroy(formula* f);
/// want to release a whole formula, use spot::ltl::destroy() instead.
static void unref(formula* f);
/// Return a canonic representation of the formula /// Return a canonic representation of the formula
const std::string& dump() const; const std::string& dump() const;

View file

@ -55,7 +55,7 @@ namespace spot
// Dereference children. // Dereference children.
for (unsigned n = 0; n < size(); ++n) for (unsigned n = 0; n < size(); ++n)
formula::unref(nth(n)); formula::destroy(nth(n));
delete children_; delete children_;
} }
@ -130,8 +130,8 @@ namespace spot
{ {
unsigned ps = p->size(); unsigned ps = p->size();
for (unsigned n = 0; n < ps; ++n) for (unsigned n = 0; n < ps; ++n)
inlined.push_back(p->nth(n)->ref()); inlined.push_back(p->nth(n)->clone());
formula::unref(*i); formula::destroy(*i);
i = v->erase(i); i = v->erase(i);
} }
else else
@ -145,7 +145,7 @@ namespace spot
std::sort(v->begin(), v->end(), formula_ptr_less_than()); std::sort(v->begin(), v->end(), formula_ptr_less_than());
// Remove duplicates. We can't use std::unique(), because we // Remove duplicates. We can't use std::unique(), because we
// must unref() any formula we drop. // must destroy() any formula we drop.
{ {
formula* last = 0; formula* last = 0;
vec::iterator i = v->begin(); vec::iterator i = v->begin();
@ -153,7 +153,7 @@ namespace spot
{ {
if (*i == last) if (*i == last)
{ {
formula::unref(*i); formula::destroy(*i);
i = v->erase(i); i = v->erase(i);
} }
else else
@ -193,9 +193,9 @@ namespace spot
{ {
// The instance already exists. // The instance already exists.
for (vec::iterator vi = v->begin(); vi != v->end(); ++vi) for (vec::iterator vi = v->begin(); vi != v->end(); ++vi)
formula::unref(*vi); formula::destroy(*vi);
delete v; delete v;
return static_cast<multop*>(i->second->ref()); return static_cast<multop*>(i->second->clone());
} }
// This is the first instance of this formula. // This is the first instance of this formula.
@ -203,7 +203,7 @@ namespace spot
// Record the instance in the map, // Record the instance in the map,
multop* ap = new multop(op, v); multop* ap = new multop(op, v);
instances[p] = ap; instances[p] = ap;
return ap->ref(); return ap->clone();
} }
formula* formula*

View file

@ -46,7 +46,7 @@ namespace spot
instances.erase(i); instances.erase(i);
// Dereference child. // Dereference child.
formula::unref(child()); formula::destroy(child());
} }
void void
@ -110,12 +110,12 @@ namespace spot
if (i != instances.end()) if (i != instances.end())
{ {
// This instance already exists. // This instance already exists.
formula::unref(child); formula::destroy(child);
return static_cast<unop*>(i->second->ref()); return static_cast<unop*>(i->second->clone());
} }
unop* ap = new unop(op, child); unop* ap = new unop(op, child);
instances[p] = ap; instances[p] = ap;
return static_cast<unop*>(ap->ref()); return static_cast<unop*>(ap->clone());
} }
unsigned unsigned

View file

@ -1,4 +1,4 @@
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2004, 2009 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
// et Marie Curie. // et Marie Curie.
// //
@ -51,8 +51,7 @@ namespace spot
prop_map::iterator i = props_.find(prop_str); prop_map::iterator i = props_.find(prop_str);
if (i == props_.end()) if (i == props_.end())
return 0; return 0;
// It's an atomic_prop, so we do not have to use the clone() visitor. return i->second->clone();
return i->second->ref();
} }
const std::string& const std::string&

View file

@ -1,4 +1,4 @@
// Copyright (C) 2004, 2007, 2008 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2004, 2007, 2008, 2009 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
// et Marie Curie. // et Marie Curie.
// //
@ -76,7 +76,7 @@ namespace spot
void void
visit(atomic_prop* ap) visit(atomic_prop* ap)
{ {
formula* f = ap->ref(); formula* f = ap->clone();
result_ = f; result_ = f;
} }

View file

@ -43,13 +43,13 @@ namespace spot
void void
clone_visitor::visit(atomic_prop* ap) clone_visitor::visit(atomic_prop* ap)
{ {
result_ = ap->ref(); result_ = ap->clone();
} }
void void
clone_visitor::visit(constant* c) clone_visitor::visit(constant* c)
{ {
result_ = c->ref(); result_ = c->clone();
} }
void void
@ -93,7 +93,7 @@ namespace spot
formula* formula*
clone(const formula* f) clone(const formula* f)
{ {
formula* res = const_cast<formula*>(f)->ref(); formula* res = const_cast<formula*>(f)->clone();
return res; return res;
} }
} }

View file

@ -28,7 +28,7 @@ namespace spot
void void
destroy(const formula* f) destroy(const formula* f)
{ {
formula::unref(const_cast<formula*>(f)); formula::destroy(const_cast<formula*>(f));
} }
} }
} }

View file

@ -1,4 +1,4 @@
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6), // Copyright (C) 2003, 2004, 2009 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
// et Marie Curie. // et Marie Curie.
// //
@ -50,7 +50,7 @@ namespace spot
void void
visit(atomic_prop* ap) visit(atomic_prop* ap)
{ {
formula* f = ap->ref(); formula* f = ap->clone();
if (negated_) if (negated_)
result_ = unop::instance(unop::Not, f); result_ = unop::instance(unop::Not, f);
else else

View file

@ -1,4 +1,4 @@
// Copyright (C) 2005, 2008 Laboratoire d'Informatique de Paris 6 // Copyright (C) 2005, 2008, 2009 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é
// Pierre et Marie Curie. // Pierre et Marie Curie.
// //
@ -40,7 +40,7 @@ namespace spot
(void) n; (void) n;
atomic_prop_set::const_iterator i = rl->ap()->begin(); atomic_prop_set::const_iterator i = rl->ap()->begin();
std::advance(i, mrand(rl->ap()->size())); std::advance(i, mrand(rl->ap()->size()));
return (*i)->ref(); return (*i)->clone();
} }
formula* formula*

View file

@ -1,4 +1,4 @@
// Copyright (C) 2004, 2006, 2007, 2008 Laboratoire d'Informatique de // Copyright (C) 2004, 2006, 2007, 2008, 2009 Laboratoire d'Informatique de
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC), // Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie. // Université Pierre et Marie Curie.
// //
@ -59,7 +59,7 @@ namespace spot
void void
visit(atomic_prop* ap) visit(atomic_prop* ap)
{ {
formula* f = ap->ref(); formula* f = ap->clone();
result_ = f; result_ = f;
} }

View file

@ -1,4 +1,4 @@
// Copyright (C) 2004, 2005, 2008 Laboratoire d'Informatique de Paris // Copyright (C) 2004, 2005, 2008, 2009 Laboratoire d'Informatique de Paris
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC), // 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie. // Université Pierre et Marie Curie.
// //
@ -876,7 +876,8 @@ main(int argc, char** argv)
spot::ltl::atomic_prop_collect(f); spot::ltl::atomic_prop_collect(f);
for (spot::ltl::atomic_prop_set::iterator i = tmp->begin(); for (spot::ltl::atomic_prop_set::iterator i = tmp->begin();
i != tmp->end(); ++i) i != tmp->end(); ++i)
apf->insert(dynamic_cast<spot::ltl::atomic_prop*>((*i)->ref())); apf->insert(dynamic_cast<spot::ltl::atomic_prop*>
((*i)->clone()));
spot::ltl::destroy(f); spot::ltl::destroy(f);
delete tmp; delete tmp;
} }
@ -890,7 +891,7 @@ main(int argc, char** argv)
for (spot::ltl::atomic_prop_set::iterator i = ap->begin(); for (spot::ltl::atomic_prop_set::iterator i = ap->begin();
i != ap->end(); ++i) i != ap->end(); ++i)
apf->insert(dynamic_cast<spot::ltl::atomic_prop*>((*i)->ref())); apf->insert(dynamic_cast<spot::ltl::atomic_prop*>((*i)->clone()));
if (!opt_S) if (!opt_S)
{ {