kripkeprint.cc 3.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright (C) 2011 Laboratoire de Recherche et Developpement
// 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 2 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 Spot; see the file COPYING.  If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.


#include "kripkeprint.hh"
#include "kripkeexplicit.hh"
24
#include "tgba/bddprint.hh"
25
#include "misc/escape.hh"
26
#include "tgbaalgos/reachiter.hh"
27
#include <iostream>
28
#include <sstream>
29
30
31

namespace spot
{
32
  namespace
33
  {
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

    class kripke_printer : public tgba_reachable_iterator_breadth_first
    {
    public:
      kripke_printer(const kripke* a, std::ostream& os)
	: tgba_reachable_iterator_breadth_first(a), os_(os)
      {
      }

      void process_state(const state* s, int, tgba_succ_iterator* si)
      {
	const bdd_dict* d = automata_->get_dict();
	os_ << "\"";
	escape_str(os_, automata_->format_state(s));
	os_ << "\", \"";
	const kripke* automata = down_cast<const kripke*> (automata_);
	assert(automata);
	escape_str(os_, bdd_format_formula(d,
					   automata->state_condition(s)));

	os_ << "\",";
	for (si->first(); !si->done(); si->next())
	  {
	    state* dest = si->current_state();
	    os_ << " \"";
	    escape_str(os_, automata_->format_state(dest));
	    os_ << "\"";
	}
	os_ << ";\n";
      }

    private:
      std::ostream& os_;
    };

    class kripke_printer_renumbered :
      public tgba_reachable_iterator_breadth_first
    {
    public:
      kripke_printer_renumbered(const kripke* a, std::ostream& os)
	: tgba_reachable_iterator_breadth_first(a), os_(os),
	  notfirst(false)
      {
      }

      void finish_state()
      {
	os_ << lastsuccs.str() << ";\n";
	lastsuccs.str("");
      }

      void process_state(const state* s, int in_s, tgba_succ_iterator*)
      {
	if (notfirst)
	  finish_state();
	else
	  notfirst = true;

	const bdd_dict* d = automata_->get_dict();
	std::string cur = automata_->format_state(s);
	os_ << "S" << in_s << ", \"";
	const kripke* automata = down_cast<const kripke*>(automata_);
	assert(automata);
	escape_str(os_, bdd_format_formula(d,
					   automata->state_condition(s)));
	os_ << "\",";
      }

      void
      process_link(const state*, int, const state*, int d,
		   const tgba_succ_iterator*)
      {
	lastsuccs << " S" << d;
      }

      void
      end()
      {
	finish_state();
      }

    private:
      std::ostream& os_;
      std::ostringstream lastsuccs;
      bool notfirst;
    };

121
122
  }

123
124
  std::ostream&
  kripke_save_reachable(std::ostream& os, const kripke* k)
125
  {
126
127
128
    kripke_printer p(k, os);
    p.run();
    return os;
129
130
  }

131
132
  std::ostream&
  kripke_save_reachable_renumbered(std::ostream& os, const kripke* k)
133
  {
134
135
136
    kripke_printer_renumbered p(k, os);
    p.run();
    return os;
137
138
  }

139

140
} // End namespace Spot