atomic_prop.cc 3.5 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
// Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Laboratoire de
3
// Recherche et Développement de l'Epita (LRDE).
Guillaume Sadegh's avatar
Guillaume Sadegh committed
4
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de
5
6
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
7
8
9
10
11
//
// 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
#include "config.h"
24
25
#include "atomic_prop.hh"
#include "visitor.hh"
26
#include <cstddef>
27
28
29
30
31
32
33
34
35
#include <cassert>
#include <ostream>

namespace spot
{
  namespace ltl
  {

    atomic_prop::atomic_prop(const std::string& name, environment& env)
36
      : formula(AtomicProp), name_(name), env_(&env)
37
    {
38
39
40
      is.boolean = true;
      is.sugar_free_boolean = true;
      is.in_nenoform = true;
41
42
43
44
      is.syntactic_si = true;	// Assuming LTL (for PSL a Boolean
				// term is not stared will be regarded
				// as not stuttering were this
				// matters.)
45
46
47
48
      is.sugar_free_ltl = true;
      is.ltl_formula = true;
      is.eltl_formula = true;
      is.psl_formula = true;
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
49
      is.sere_formula = true;
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
50
      is.finite = true;
51
52
      is.eventual = false;
      is.universal = false;
53
54
55
56
57
      is.syntactic_safety = true;
      is.syntactic_guarantee = true;
      is.syntactic_obligation = true;
      is.syntactic_recurrence = true;
      is.syntactic_persistence = true;
58
      is.not_marked = true;
59
      is.accepting_eword = false;
60
61
62
63
64
65
66
67
68
      // is.lbt_atomic_props should be true if the name has the form
      // pNN where NN is any number of digit.
      std::string::const_iterator pos = name.begin();
      is.lbt_atomic_props = (pos != name.end() && *pos++ == 'p');
      while (is.lbt_atomic_props && pos != name.end())
	{
	  char l = *pos++;
	  is.lbt_atomic_props = (l >= '0' && l <= '9');
	}
69
70
71
72
73
    }

    atomic_prop::~atomic_prop()
    {
      // Get this instance out of the instance map.
74
75
76
      size_t c = instances.erase(key(name(), &env()));
      assert(c == 1);
      (void) c;			// For the NDEBUG case.
77
78
    }

79
80
81
82
83
84
    std::string
    atomic_prop::dump() const
    {
      return "AP(" + name() + ")";
    }

85
    void
86
    atomic_prop::accept(visitor& v) const
87
88
89
90
91
92
    {
      v.visit(this);
    }

    atomic_prop::map atomic_prop::instances;

93
    const atomic_prop*
94
95
    atomic_prop::instance(const std::string& name, environment& env)
    {
96
      const atomic_prop* ap;
97
      auto ires = instances.emplace(key(name, &env), nullptr);
98
      if (!ires.second)
99
100
101
102
	{
	  ap = ires.first->second;
	  ap->clone();
	}
103
      else
104
105
106
	{
	  ap = ires.first->second = new atomic_prop(name, env);
	}
107
      return ap;
108
109
110
111
112
113
114
115
116
117
118
    }

    unsigned
    atomic_prop::instance_count()
    {
      return instances.size();
    }

    std::ostream&
    atomic_prop::dump_instances(std::ostream& os)
    {
119
      for (const auto& i: instances)
120
	os << i.second << " = " << 1 + i.second->refs_
121
	   << " * atomic_prop(" << i.first.first << ", "
122
	   << i.first.second->name() << ")\n";
123
124
125
126
127
      return os;
    }

  }
}