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