diff --git a/ChangeLog b/ChangeLog index af2421f8d..53164cc31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-05-26 Alexandre Duret-Lutz + + * src/ltlvisit/basereduc.cc, src/ltlvisit/reducform.cc: Use + dynamic_cast instead of node_type_form_visitor, this is usually + smaller. + * src/ltlvisit/reducform.hh, + src/ltlvisit/forminf.cc (node_type_form_visitor): Delete. + * src/sanity/style.test: Two more checks. + 2004-05-25 Alexandre Duret-Lutz * src/ltlvisit/formlength.cc: Rename as ... diff --git a/src/ltlvisit/basereduc.cc b/src/ltlvisit/basereduc.cc index 2f4bddacf..93d46760a 100644 --- a/src/ltlvisit/basereduc.cc +++ b/src/ltlvisit/basereduc.cc @@ -81,7 +81,7 @@ namespace spot case unop::X: // X(true) = true // X(false) = false - if (node_type(result_) == (node_type_form_visitor::Const)) + if (dynamic_cast(result_)) return; // XGF(f) = GF(f) @@ -123,10 +123,9 @@ namespace spot return; case unop::F: - // F(true) = true // F(false) = false - if (node_type(result_) == (node_type_form_visitor::Const)) + if (dynamic_cast(result_)) return; // FX(a) = XF(a) @@ -177,10 +176,9 @@ namespace spot return; case unop::G: - // G(true) = true // G(false) = false - if (node_type(result_) == (node_type_form_visitor::Const)) + if (dynamic_cast(result_)) return; // G(a R b) = G(b) @@ -249,8 +247,6 @@ namespace spot formula* f1 = bo->first(); formula* f2 = bo->second(); formula* ftmp = NULL; - node_type_form_visitor v1; - node_type_form_visitor v2; unop* fu1 = NULL; unop* fu2 = NULL; switch (bo->op()) @@ -275,7 +271,7 @@ namespace spot // a U false = false // a U true = true - if (node_type(f2) == (node_type_form_visitor::Const)) + if (dynamic_cast(f2)) { result_ = f2; return; @@ -308,7 +304,7 @@ namespace spot // a R false = false // a R true = true - if (node_type(f2) == (node_type_form_visitor::Const)) + if (dynamic_cast(f2)) { result_ = f2; return; @@ -358,9 +354,6 @@ namespace spot multop::vec* tmpOther = new multop::vec; - unop* uo = NULL; - unop* uo2 = NULL; - binop* bo = NULL; formula* ftmp = NULL; for (unsigned i = 0; i < mos; ++i) @@ -375,47 +368,43 @@ namespace spot { if (*i == NULL) continue; - switch (node_type(*i)) + unop* uo = dynamic_cast(*i); + binop* bo = dynamic_cast(*i); + if (uo) { - - case node_type_form_visitor::Unop: - - // Xa & Xb = X(a & b) - uo = dynamic_cast(*i); if (uo && uo->op() == unop::X) { + // Xa & Xb = X(a & b) tmpX->push_back(basic_reduce_form(uo->child())); - break; } - - // FG(a) & FG(b) = FG(a & b) - if (is_FG(*i)) + else if (is_FG(*i)) { - uo2 = dynamic_cast(uo->child()); + // FG(a) & FG(b) = FG(a & b) + unop* uo2 = dynamic_cast(uo->child()); tmpFG->push_back(basic_reduce_form(uo2->child())); - break; } - tmpOther->push_back(basic_reduce_form(*i)); - break; - - case node_type_form_visitor::Binop: - - // (a U b) & (c U b) = (a & c) U b - if (dynamic_cast(*i)->op() == binop::U) + else { + tmpOther->push_back(basic_reduce_form(*i)); + } + } + else if (bo) + { + if (bo->op() == binop::U) + { + // (a U b) & (c U b) = (a & c) U b ftmp = dynamic_cast(*i)->second(); tmpUright = new multop::vec; for (multop::vec::iterator j = i; j != res->end(); j++) { if (!*j) continue; - if (node_type(*j) == node_type_form_visitor::Binop - && dynamic_cast(*j)->op() == binop::U - && ftmp == dynamic_cast(*j)->second()) + binop* bo2 = dynamic_cast(*j); + if (bo2 && bo2->op() == binop::U + && ftmp == bo2->second()) { - bo = dynamic_cast(*j); tmpUright - ->push_back(basic_reduce_form(bo->first())); + ->push_back(basic_reduce_form(bo2->first())); if (j != i) { destroy(*j); @@ -430,25 +419,22 @@ namespace spot And, tmpUright), basic_reduce_form(ftmp))); - break; } - - // (a R b) & (a R c) = a R (b & c) - if (dynamic_cast(*i)->op() == binop::R) + else if (bo->op() == binop::R) { + // (a R b) & (a R c) = a R (b & c) ftmp = dynamic_cast(*i)->first(); tmpRright = new multop::vec; for (multop::vec::iterator j = i; j != res->end(); j++) { if (!*j) continue; - if (node_type(*j) == node_type_form_visitor::Binop - && dynamic_cast(*j)->op() == binop::R - && ftmp == dynamic_cast(*j)->first()) + binop* bo2 = dynamic_cast(*j); + if (bo2 && bo2->op() == binop::R + && ftmp == bo2->first()) { - bo = dynamic_cast(*j); tmpRright - ->push_back(basic_reduce_form(bo->second())); + ->push_back(basic_reduce_form(bo2->second())); if (j != i) { destroy(*j); @@ -462,19 +448,21 @@ namespace spot multop:: instance(multop::And, tmpRright))); - break; } + else + { + tmpOther->push_back(basic_reduce_form(*i)); + } + } + else + { tmpOther->push_back(basic_reduce_form(*i)); - break; - default: - tmpOther->push_back(basic_reduce_form(*i)); - break; } destroy(*i); } - delete(tmpGF); - tmpGF = NULL; + delete tmpGF; + tmpGF = 0; break; @@ -484,47 +472,43 @@ namespace spot { if (!*i) continue; - switch (node_type(*i)) + unop* uo = dynamic_cast(*i); + binop* bo = dynamic_cast(*i); + if (uo) { - - case node_type_form_visitor::Unop: - - // Xa | Xb = X(a | b) - uo = dynamic_cast(*i); if (uo && uo->op() == unop::X) { + // Xa | Xb = X(a | b) tmpX->push_back(basic_reduce_form(uo->child())); - break; } - - // GF(a) | GF(b) = GF(a | b) - if (is_GF(*i)) + else if (is_GF(*i)) { - uo2 = dynamic_cast(uo->child()); + // GF(a) | GF(b) = GF(a | b) + unop* uo2 = dynamic_cast(uo->child()); tmpGF->push_back(basic_reduce_form(uo2->child())); - break; } - tmpOther->push_back(basic_reduce_form(*i)); - break; - - case node_type_form_visitor::Binop: - - // (a U b) | (a U c) = a U (b | c) - if (dynamic_cast(*i)->op() == binop::U) + else { - ftmp = dynamic_cast(*i)->first(); + tmpOther->push_back(basic_reduce_form(*i)); + } + } + else if (bo) + { + if (bo->op() == binop::U) + { + // (a U b) | (a U c) = a U (b | c) + ftmp = bo->first(); tmpUright = new multop::vec; for (multop::vec::iterator j = i; j != res->end(); j++) { if (!*j) continue; - if (node_type(*j) == node_type_form_visitor::Binop - && dynamic_cast(*j)->op() == binop::U - && ftmp == dynamic_cast(*j)->first()) + binop* bo2 = dynamic_cast(*j); + if (bo2 && bo2->op() == binop::U + && ftmp == bo2->first()) { - bo = dynamic_cast(*j); tmpUright - ->push_back(basic_reduce_form(bo->second())); + ->push_back(basic_reduce_form(bo2->second())); if (j != i) { destroy(*j); @@ -537,23 +521,20 @@ namespace spot multop:: instance(multop::Or, tmpUright))); - break; } - - // (a R b) | (c R b) = (a | c) R b - if (dynamic_cast(*i)->op() == binop::R) + else if (bo->op() == binop::R) { + // (a R b) | (c R b) = (a | c) R b ftmp = dynamic_cast(*i)->second(); tmpRright = new multop::vec; for (multop::vec::iterator j = i; j != res->end(); j++) { if (!*j) continue; - if (node_type(*j) == node_type_form_visitor::Binop - && dynamic_cast(*j)->op() == binop::R - && ftmp == dynamic_cast(*j)->second()) + binop* bo2 = dynamic_cast(*j); + if (bo2 && bo2->op() == binop::R + && ftmp == bo2->second()) { - bo = dynamic_cast(*j); tmpRright ->push_back(basic_reduce_form(bo->first())); if (j != i) @@ -569,40 +550,44 @@ namespace spot instance(multop::Or, tmpRright), basic_reduce_form(ftmp))); - break; } + else + { + tmpOther->push_back(basic_reduce_form(*i)); + } + } + else + { tmpOther->push_back(basic_reduce_form(*i)); - break; - default: - tmpOther->push_back(basic_reduce_form(*i)); - break; } destroy(*i); } - delete(tmpFG); - tmpFG = NULL; + delete tmpFG; + tmpFG = 0; break; } - res->clear(); - delete(res); + delete res; if (tmpX->size()) tmpOther->push_back(unop::instance(unop::X, multop::instance(mo->op(), tmpX))); - else delete(tmpX); + else + delete tmpX; if (tmpU->size()) tmpOther->push_back(multop::instance(mo->op(), tmpU)); - else delete(tmpU); + else + delete tmpU; if (tmpR->size()) tmpOther->push_back(multop::instance(mo->op(), tmpR)); - else delete(tmpR); + else + delete tmpR; if ((tmpGF != NULL) && (tmpGF->size())) diff --git a/src/ltlvisit/forminf.cc b/src/ltlvisit/forminf.cc index 81633999b..5589cf739 100644 --- a/src/ltlvisit/forminf.cc +++ b/src/ltlvisit/forminf.cc @@ -58,53 +58,6 @@ namespace spot return false; } - node_type_form_visitor::node_type_form_visitor(){} - - node_type_form_visitor::type - node_type_form_visitor::result() const - { - return result_; - } - - void - node_type_form_visitor::visit(const atomic_prop*) - { - result_ = node_type_form_visitor::Atom; - } - - void - node_type_form_visitor::visit(const constant*) - { - result_ = node_type_form_visitor::Const; - } - - void - node_type_form_visitor::visit(const unop*) - { - result_ = node_type_form_visitor::Unop; - } - - void - node_type_form_visitor::visit(const binop*) - { - result_ = node_type_form_visitor::Binop; - } - - void - node_type_form_visitor::visit(const multop*) - { - result_ = node_type_form_visitor::Multop; - } - - node_type_form_visitor::type - node_type(const formula* f) - { - node_type_form_visitor v; - assert(f != NULL); - const_cast(f)->accept(v); - return v.result(); - } - class form_eventual_universal_visitor : public const_visitor { public: @@ -578,7 +531,8 @@ namespace spot return false; } - bool infneg_form(const formula* f1, const formula* f2, int n) + bool + infneg_form(const formula* f1, const formula* f2, int n) { const formula* ftmp1; const formula* ftmp2; diff --git a/src/ltlvisit/reducform.cc b/src/ltlvisit/reducform.cc index ed15ae029..856fe46f8 100644 --- a/src/ltlvisit/reducform.cc +++ b/src/ltlvisit/reducform.cc @@ -144,14 +144,15 @@ namespace spot return; } /* a < b => a U (b U c) = (b U c) */ - if (node_type(f2) == node_type_form_visitor::Binop - && dynamic_cast(f2)->op() == binop::U - && inf_form(f1, dynamic_cast(f2)->first())) - { - result_ = f2; - destroy(f1); - return; - } + { + binop* bo = dynamic_cast(f2); + if (bo && bo->op() == binop::U && inf_form(f1, bo->first())) + { + result_ = f2; + destroy(f1); + return; + } + } break; case binop::R: @@ -170,16 +171,16 @@ namespace spot return; } /* b < a => a R (b R c) = b R c */ - if (node_type(f2) == node_type_form_visitor::Binop - && dynamic_cast(f2)->op() == binop::R - && inf_form(dynamic_cast(f2)->first(), f1)) - { - result_ = f2; - destroy(f1); - return; - } + { + binop* bo = dynamic_cast(f2); + if (bo && bo->op() == binop::R && inf_form(bo->first(), f1)) + { + result_ = f2; + destroy(f1); + return; + } + } break; - } } result_ = binop::instance(bo->op(), f1, f2); diff --git a/src/ltlvisit/reducform.hh b/src/ltlvisit/reducform.hh index 8c4ff2217..2fd5a7245 100644 --- a/src/ltlvisit/reducform.hh +++ b/src/ltlvisit/reducform.hh @@ -74,24 +74,6 @@ namespace spot /// FIXME: Describe what universal formulae are. Cite paper. bool is_universal(const formula* f); - /// Type the first node of a formula. - class node_type_form_visitor : public const_visitor - { - public: - enum type { Atom, Const, Unop, Binop, Multop }; - node_type_form_visitor(); - virtual ~node_type_form_visitor(){}; - type result() const; - void visit(const atomic_prop* ap); - void visit(const constant* c); - void visit(const unop* uo); - void visit(const binop* bo); - void visit(const multop* mo); - protected: - type result_; - }; - node_type_form_visitor::type node_type(const formula* f); - /// Whether a formula starts with GF. bool is_GF(const formula* f); /// Whether a formula starts with FG. diff --git a/src/sanity/style.test b/src/sanity/style.test index 5a57c53ce..1b54d4cd6 100755 --- a/src/sanity/style.test +++ b/src/sanity/style.test @@ -44,6 +44,9 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do grep '[ ]if (.*).*;' $tmp && diag 'if body should be on another line.' + grep '[ ]else.*;' $tmp && + diag 'else body should be on another line.' + grep '[ ]while(' $tmp && diag 'Missing space after "while"' @@ -104,6 +107,12 @@ for dir in "${INCDIR-..}" "${INCDIR-..}"/../iface; do grep '{.*{' $tmp && diag 'No two { on the same line.' + grep -e 'delete[ ]*[(][^(]*[)];' $tmp && + diag 'No useless parentheses after delete.' + + grep -e 'return[ ]*[(][^(]*[)];' $tmp && + diag 'No useless parentheses after delete.' + $fail && echo "$file" >>failures done done