simpfg.cc 2.73 KB
Newer Older
1
2
// -*- coding: utf-8 -*-
// Copyright (C) 2010, 2012 Laboratoire de Recherche et Développement de
3
// l'Epita (LRDE).
4
// Copyright (C) 2004  Laboratoire d'Informatique de Paris 6 (LIP6),
5
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
6
7
8
9
10
11
// et Marie Curie.
//
// 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
12
// the Free Software Foundation; either version 3 of the License, or
13
14
15
16
17
18
19
20
// (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
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
22

23
24
#include "ltlast/allnodes.hh"
#include "ltlvisit/clone.hh"
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "simpfg.hh"
#include <cassert>

namespace spot
{
  namespace ltl
  {

    simplify_f_g_visitor::simplify_f_g_visitor()
    {
    }

    simplify_f_g_visitor::~simplify_f_g_visitor()
    {
    }

    void
42
    simplify_f_g_visitor::visit(const binop* bo)
43
    {
44
45
      const formula* f1 = recurse(bo->first());
      const formula* f2 = recurse(bo->second());
46
      binop::type op = bo->op();
47

48
      switch (op)
49
50
51
52
	{
	case binop::Xor:
	case binop::Implies:
	case binop::Equiv:
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
53
54
	case binop::UConcat:
	case binop::EConcat:
55
	case binop::EConcatMarked:
56
	  result_ = binop::instance(op, f1, f2);
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
	  return;
	  /* true U f2 == F(f2) */
	case binop::U:
	  if (f1 == constant::true_instance())
	    result_ = unop::instance(unop::F, f2);
	  else
	    result_ = binop::instance(binop::U, f1, f2);
	  return;
	  /* false R f2 == G(f2) */
	case binop::R:
	  if (f1 == constant::false_instance())
	    result_ = unop::instance(unop::G, f2);
	  else
	    result_ = binop::instance(binop::R, f1, f2);
	  return;
72
73
74
75
76
77
78
79
80
	  /* f1 W false == G(f1) */
	case binop::W:
	  if (f2 == constant::false_instance())
	    result_ = unop::instance(unop::G, f1);
	  else
	    result_ = binop::instance(binop::W, f1, f2);
	  return;
	  /* f1 M true == F(f1) */
	case binop::M:
81
82
	  if (f2 == constant::true_instance())
	    result_ = unop::instance(unop::F, f1);
83
84
85
	  else
	    result_ = binop::instance(binop::M, f1, f2);
	  return;
86
87
88
89
90
	}
      /* Unreachable code. */
      assert(0);
    }

91
92
    const formula*
    simplify_f_g_visitor::recurse(const formula* f)
93
94
95
96
    {
      return simplify_f_g(f);
    }

97
    const formula*
98
99
    simplify_f_g(const formula* f)
    {
100
101
      if (f->is_boolean())
	return f->clone();
102
      simplify_f_g_visitor v;
103
      f->accept(v);
104
105
106
107
      return v.result();
    }
  }
}