spot  0.9.2
formula.hh
Go to the documentation of this file.
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2008, 2009, 2010, 2011, 2012 Laboratoire de Recherche
3 // et Développement de l'Epita (LRDE).
4 // Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de
5 //
6 // This file is part of Spot, a model checking library.
7 //
8 // Spot is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // Spot is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 // License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Spot; see the file COPYING. If not, write to the Free
20 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 // 02111-1307, USA.
22 
25 #ifndef SPOT_LTLAST_FORMULA_HH
26 # define SPOT_LTLAST_FORMULA_HH
27 
28 #include <string>
29 #include <cassert>
30 #include "predecl.hh"
31 #include <list>
32 
33 namespace spot
34 {
35  namespace ltl
36  {
40 
43 
46 
50 
53 
56 
59 
62 
65 
66 
73  class formula
74  {
75  public:
77  enum opkind { Constant,
84 
85  protected:
87  {
88  // If the counter of formulae ever loops, we want to skip the
89  // first three values, because they are permanently associated
90  // to constants, and it is convenient to have constants smaller
91  // than all other formulae.
92  if (max_count == 0)
93  max_count = 3;
94  }
95 
96  public:
98  virtual void accept(visitor& v) const = 0;
99 
104  const formula* clone() const;
109  void destroy() const;
110 
112  virtual std::string dump() const = 0;
113 
115  opkind kind() const
116  {
117  return kind_;
118  }
119 
121  // Properties //
123 
125  bool is_boolean() const
126  {
127  return is.boolean;
128  }
129 
132  {
133  return is.sugar_free_boolean;
134  }
135 
140  bool is_in_nenoform() const
141  {
142  return is.in_nenoform;
143  }
144 
146  bool is_X_free() const
147  {
148  return is.X_free;
149  }
150 
152  bool is_sugar_free_ltl() const
153  {
154  return is.sugar_free_ltl;
155  }
156 
158  bool is_ltl_formula() const
159  {
160  return is.ltl_formula;
161  }
162 
164  bool is_eltl_formula() const
165  {
166  return is.eltl_formula;
167  }
168 
170  bool is_psl_formula() const
171  {
172  return is.psl_formula;
173  }
174 
176  bool is_sere_formula() const
177  {
178  return is.sere_formula;
179  }
180 
183  bool is_finite() const
184  {
185  return is.finite;
186  }
187 
208  bool is_eventual() const
209  {
210  return is.eventual;
211  }
212 
233  bool is_universal() const
234  {
235  return is.universal;
236  }
237 
239  bool is_syntactic_safety() const
240  {
241  return is.syntactic_safety;
242  }
243 
246  {
247  return is.syntactic_guarantee;
248  }
249 
252  {
253  return is.syntactic_obligation;
254  }
255 
258  {
259  return is.syntactic_recurrence;
260  }
261 
264  {
265  return is.syntactic_persistence;
266  }
267 
269  bool is_marked() const
270  {
271  return !is.not_marked;
272  }
273 
275  bool accepts_eword() const
276  {
277  return is.accepting_eword;
278  }
279 
281  unsigned get_props() const
282  {
283  return props;
284  }
285 
287  size_t
288  hash() const
289  {
290  return count_;
291  }
292  protected:
293  virtual ~formula();
294 
296  virtual void ref_() const;
299  virtual bool unref_() const;
300 
302  size_t count_;
303 
304  struct ltl_prop
305  {
306  // All properties here should be expressed in such a a way
307  // that property(f && g) is just property(f)&property(g).
308  // This allows us to compute all properties of a compound
309  // formula in one operation.
310  //
311  // For instance we do not use a property that says "has
312  // temporal operator", because it would require an OR between
313  // the two arguments. Instead we have a property that
314  // says "no temporal operator", and that one is computed
315  // with an AND between the arguments.
316  //
317  // Also choose a name that makes sense when prefixed with
318  // "the formula is".
319  bool boolean:1; // No temporal operators.
320  bool sugar_free_boolean:1; // Only AND, OR, and NOT operators.
321  bool in_nenoform:1; // Negative Normal Form.
322  bool X_free:1; // No X operators.
323  bool sugar_free_ltl:1; // No F and G operators.
324  bool ltl_formula:1; // Only LTL operators.
325  bool eltl_formula:1; // Only ELTL operators.
326  bool psl_formula:1; // Only PSL operators.
327  bool sere_formula:1; // Only SERE operators.
328  bool finite:1; // Finite SERE formulae, or Bool+X forms.
329  bool eventual:1; // Purely eventual formula.
330  bool universal:1; // Purely universal formula.
331  bool syntactic_safety:1; // Syntactic Safety Property.
332  bool syntactic_guarantee:1; // Syntactic Guarantee Property.
333  bool syntactic_obligation:1; // Syntactic Obligation Property.
334  bool syntactic_recurrence:1; // Syntactic Recurrence Property.
335  bool syntactic_persistence:1; // Syntactic Persistence Property.
336  bool not_marked:1; // No occurrence of EConcatMarked.
337  bool accepting_eword:1; // Accepts the empty word.
338  };
339  union
340  {
341  // Use an unsigned for fast computation of all properties.
342  unsigned props;
344  };
345 
346  private:
348  static size_t max_count;
350  };
351 
366  public std::binary_function<const formula*, const formula*, bool>
367  {
368  bool
369  operator()(const formula* left, const formula* right) const
370  {
371  assert(left);
372  assert(right);
373  if (left == right)
374  return false;
375  size_t l = left->hash();
376  size_t r = right->hash();
377  if (l != r)
378  return l < r;
379  // Because the hash code assigned to each formula is the
380  // number of formulae constructed so far, it is very unlikely
381  // that we will ever reach a case were two different formulae
382  // have the same hash. This will happen only ever with have
383  // produced 256**sizeof(size_t) formulae (i.e. max_count has
384  // looped back to 0 and started over). In that case we can
385  // order two formulae by looking at their text representation.
386  // We could be more efficient and look at their AST, but it's
387  // not worth the burden. (Also ordering pointers is ruled out
388  // because it breaks the determinism of the implementation.)
389  return left->dump() < right->dump();
390  }
391  };
392 
408  public std::unary_function<const formula*, size_t>
409  {
410  size_t
411  operator()(const formula* that) const
412  {
413  assert(that);
414  return that->hash();
415  }
416  };
417 
419  std::ostream& print_formula_props(std::ostream& out,
420  const formula* f,
421  bool abbreviated = false);
422 
424  std::list<std::string> list_formula_props(const formula* f);
425  }
426 }
427 
428 #endif // SPOT_LTLAST_FORMULA_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Mon Jul 2 2012 17:35:47 for spot by doxygen 1.8.1.1