* src/ltlvisit/tostring.cc: Reindent and strip out superfluous

spot::ltl:: prefixes.
(to_string(formula)): New function.
* src/ltlvisit/tostring.hh (to_string(formula)): Likewise.
* src/ltltest/tostring.cc: Use this new to_string function to
simplify.
This commit is contained in:
Alexandre Duret-Lutz 2003-05-12 12:41:41 +00:00
parent a49c69555e
commit 8e988470b1
4 changed files with 76 additions and 62 deletions

View file

@ -1,3 +1,12 @@
2003-05-12 Alexandre Duret-Lutz <aduret@src.lip6.fr>
* src/ltlvisit/tostring.cc: Reindent and strip out superfluous
spot::ltl:: prefixes.
(to_string(formula)): New function.
* src/ltlvisit/tostring.hh (to_string(formula)): Likewise.
* src/ltltest/tostring.cc: Use this new to_string function to
simplify.
2003-05-05 Alexandre Duret-Lutz <aduret@src.lip6.fr> 2003-05-05 Alexandre Duret-Lutz <aduret@src.lip6.fr>
* m4/buddy.m4: New file. * m4/buddy.m4: New file.

View file

@ -1,5 +1,4 @@
#include <iostream> #include <iostream>
#include <sstream>
#include "ltlparse/public.hh" #include "ltlparse/public.hh"
#include "ltlvisit/tostring.hh" #include "ltlvisit/tostring.hh"
#include "ltlvisit/equals.hh" #include "ltlvisit/equals.hh"
@ -26,13 +25,12 @@ main(int argc, char **argv)
// The string generated from an abstract tree should be parsable // The string generated from an abstract tree should be parsable
// again. // again.
std::ostringstream os; std::string f1s = spot::ltl::to_string(*f1);
spot::ltl::to_string(*f1, os); std::cout << f1s << std::endl;
std::cout << os.str() << std::endl;
spot::ltl::formula* f2 = spot::ltl::parse(os.str(), p1); spot::ltl::formula* f2 = spot::ltl::parse(f1s, p1);
if (spot::ltl::format_parse_errors(std::cerr, os.str(), p1)) if (spot::ltl::format_parse_errors(std::cerr, f1s, p1))
return 2; return 2;
// This second abstract tree should be equal to the first. // This second abstract tree should be equal to the first.
@ -42,11 +40,10 @@ main(int argc, char **argv)
// It should also map to the same string. // It should also map to the same string.
std::ostringstream os2; std::string f2s = spot::ltl::to_string(*f2);
spot::ltl::to_string(*f2, os2); std::cout << f2s << std::endl;
std::cout << os2.str() << std::endl;
if (os2.str() != os.str()) if (f2s != f1s)
return 1; return 1;
} }

View file

@ -1,4 +1,5 @@
#include <cassert> #include <cassert>
#include <sstream>
#include "tostring.hh" #include "tostring.hh"
#include "ltlast/visitor.hh" #include "ltlast/visitor.hh"
#include "ltlast/allnodes.hh" #include "ltlast/allnodes.hh"
@ -9,7 +10,7 @@ namespace spot
namespace ltl namespace ltl
{ {
class to_string_visitor : public spot::ltl::const_visitor class to_string_visitor : public const_visitor
{ {
public: public:
to_string_visitor(std::ostream& os = std::cout) to_string_visitor(std::ostream& os = std::cout)
@ -21,88 +22,87 @@ namespace spot
~to_string_visitor() ~to_string_visitor()
{ {
} }
void void
visit(const spot::ltl::atomic_prop* ap) visit(const atomic_prop* ap)
{ {
os_ << ap->name(); os_ << ap->name();
} }
void void
visit(const spot::ltl::constant* c) visit(const constant* c)
{ {
os_ << c->val_name(); os_ << c->val_name();
} }
void void
visit(const spot::ltl::binop* bo) visit(const binop* bo)
{ {
os_ << "("; os_ << "(";
bo->first()->accept(*this); bo->first()->accept(*this);
switch(bo->op()) switch(bo->op())
{ {
case spot::ltl::binop::Xor: case binop::Xor:
os_ << " ^ "; os_ << " ^ ";
break; break;
case spot::ltl::binop::Implies: case binop::Implies:
os_ << " => "; os_ << " => ";
break; break;
case spot::ltl::binop::Equiv: case binop::Equiv:
os_ << " <=> "; os_ << " <=> ";
break; break;
case spot::ltl::binop::U: case binop::U:
os_ << " U "; os_ << " U ";
break; break;
case spot::ltl::binop::R: case binop::R:
os_ << " R "; os_ << " R ";
break; break;
} }
bo->second()->accept(*this); bo->second()->accept(*this);
os_ << ")"; os_ << ")";
} }
void void
visit(const spot::ltl::unop* uo) visit(const unop* uo)
{ {
switch(uo->op()) switch(uo->op())
{ {
case spot::ltl::unop::Not: case unop::Not:
os_ << "!"; os_ << "!";
break; break;
case spot::ltl::unop::X: case unop::X:
os_ << "X"; os_ << "X";
break; break;
case spot::ltl::unop::F: case unop::F:
os_ << "F"; os_ << "F";
break; break;
case spot::ltl::unop::G: case unop::G:
os_ << "G"; os_ << "G";
break; break;
} }
uo->child()->accept(*this); uo->child()->accept(*this);
} }
void void
visit(const spot::ltl::multop* mo) visit(const multop* mo)
{ {
os_ << "("; os_ << "(";
unsigned max = mo->size(); unsigned max = mo->size();
mo->nth(0)->accept(*this); mo->nth(0)->accept(*this);
const char* ch = " "; const char* ch = " ";
switch (mo->op()) switch (mo->op())
{ {
case spot::ltl::multop::Or: case multop::Or:
ch = " | "; ch = " | ";
break; break;
case spot::ltl::multop::And: case multop::And:
ch = " & "; ch = " & ";
break; break;
} }
for (unsigned n = 1; n < max; ++n) for (unsigned n = 1; n < max; ++n)
{ {
os_ << ch; os_ << ch;
@ -113,7 +113,7 @@ namespace spot
private: private:
std::ostream& os_; std::ostream& os_;
}; };
void void
to_string(const formula& f, std::ostream& os) to_string(const formula& f, std::ostream& os)
{ {
@ -121,5 +121,12 @@ namespace spot
f.accept(v); f.accept(v);
} }
std::string
to_string(const formula& f)
{
std::ostringstream os;
to_string(f, os);
return os.str();
}
} }
} }

View file

@ -9,6 +9,7 @@ namespace spot
namespace ltl namespace ltl
{ {
void to_string(const formula& f, std::ostream& os); void to_string(const formula& f, std::ostream& os);
std::string to_string(const formula& f);
} }
} }