PageRenderTime 18ms CodeModel.GetById 16ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/automaton/state.e

http://github.com/tybor/Liberty
Specman e | 90 lines | 54 code | 11 blank | 25 comment | 1 complexity | a8b0a02e6b7a4afb5f2d0fa1023d33ee MD5 | raw file
 1-- This file is part of a Liberty Eiffel library.
 2-- See the full copyright at the end.
 3--
 4class STATE[E_]
 5
 6create {ANY}
 7   manifest_creation
 8
 9feature {ANY}
10   name: FIXED_STRING
11
12feature {AUTOMATON}
13   set_name (a_name: like name)
14      require
15         a_name /= Void
16         set_once: name = Void
17      do
18         name := a_name
19      ensure
20         name = a_name
21      end
22
23   run (a: AUTOMATON[E_]; e: E_): ABSTRACT_STRING
24      local
25         i: INTEGER; found: BOOLEAN
26      do
27         a.call_before_guards(e, Current)
28         from
29            i := guards.lower
30         until
31            found
32         loop
33            found := guards.item(i).item([e, Current])
34            if found then
35               a.call_after_guards(e, Current)
36               Result := transitions.item(i).item([e, Current])
37            end
38            i := i + 1
39         end
40      end
41
42feature {}
43   guards: COLLECTION[PREDICATE[TUPLE[E_, STATE[E_]]]]
44         -- Each guard tests if the corresponding transition may be done.
45
46   transitions: COLLECTION[FUNCTION[TUPLE[E_, STATE[E_]], ABSTRACT_STRING]]
47         -- The transition gives the name of the successor state.
48
49feature {}
50   manifest_make (needed_capacity: INTEGER)
51      do
52         create {FAST_ARRAY[PREDICATE[TUPLE[E_, STATE[E_]]]]} guards.with_capacity(needed_capacity)
53         create {FAST_ARRAY[FUNCTION[TUPLE[E_, STATE[E_]], ABSTRACT_STRING]]} transitions.with_capacity(needed_capacity)
54      end
55
56   manifest_put (index: INTEGER; guard: PREDICATE[TUPLE[E_, STATE[E_]]]; transition: FUNCTION[TUPLE[E_, STATE[E_]], ABSTRACT_STRING])
57      require
58         index >= 0
59      do
60         guards.add_last(guard)
61         transitions.add_last(transition)
62      end
63
64   manifest_semicolon_check: INTEGER 2
65
66invariant
67   guards.count = transitions.count
68   guards.lower = transitions.lower
69
70end -- class STATE
71--
72-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
73--
74-- Permission is hereby granted, free of charge, to any person obtaining a copy
75-- of this software and associated documentation files (the "Software"), to deal
76-- in the Software without restriction, including without limitation the rights
77-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
78-- copies of the Software, and to permit persons to whom the Software is
79-- furnished to do so, subject to the following conditions:
80--
81-- The above copyright notice and this permission notice shall be included in
82-- all copies or substantial portions of the Software.
83--
84-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
85-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
86-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
87-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
88-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
89-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
90-- THE SOFTWARE.