/src/lib/sequencer/loop_stack.e

http://github.com/tybor/Liberty · Specman e · 132 lines · 86 code · 12 blank · 34 comment · 6 complexity · dbccecb4d29bb771ac9d4ff4e29402e5 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class LOOP_STACK
  5. -- Manage `LOOP_ITEM'. When a new loop is pushed, all jobs in the currently
  6. -- running loop are suspended until the new loop ends (all jobs end or break).
  7. --
  8. create {ANY}
  9. make
  10. feature {}
  11. loop_stack: FAST_ARRAY[LOOP_ITEM]
  12. make
  13. do
  14. create loop_stack.make(0)
  15. loop_stack.add_last(create {LOOP_ITEM}.make)
  16. ensure
  17. current_loop /= Void
  18. end
  19. feature {ANY}
  20. stop: BOOLEAN
  21. new_loop
  22. -- create new empty loop (ie without job) and push it on the stack
  23. local
  24. loop_item: LOOP_ITEM
  25. do
  26. if not loop_stack.is_empty then
  27. current_loop.pause_loop
  28. end
  29. create loop_item.make
  30. loop_stack.add_last(loop_item)
  31. end
  32. push_loop (l: like current_loop)
  33. -- `l' is restarted and pushed on the stack
  34. require
  35. l /= Void
  36. do
  37. if not loop_stack.is_empty then
  38. current_loop.pause_loop
  39. end
  40. l.restart
  41. loop_stack.add_last(l)
  42. ensure
  43. current_loop = l
  44. end
  45. run
  46. -- run `current_loop' (ie execute it's jobs)
  47. require
  48. current_loop /= Void
  49. do
  50. from
  51. stop := False
  52. until
  53. stop or else loop_stack.is_empty
  54. loop
  55. current_loop.run
  56. if current_loop /= Void then
  57. --may be Void after `break'
  58. if not current_loop.pause then
  59. loop_stack.remove_last
  60. end
  61. end
  62. end
  63. ensure
  64. loop_stack.is_empty or stop
  65. end
  66. add_job (j: JOB)
  67. -- Add a job to the current loop
  68. require
  69. j /= Void
  70. do
  71. current_loop.add_job(j)
  72. end
  73. break
  74. -- Exit current loop
  75. require
  76. current_loop /= Void
  77. do
  78. current_loop.break_loop
  79. loop_stack.remove_last
  80. ensure
  81. current_loop /= old current_loop
  82. end
  83. exit_all
  84. --TODO: Really needed feature ?
  85. require
  86. stop = False
  87. do
  88. stop := True
  89. current_loop.pause_loop
  90. ensure
  91. stop = True
  92. end
  93. current_loop: LOOP_ITEM
  94. --TODO: change this function into an attribute to be more efficient
  95. do
  96. if not loop_stack.is_empty then
  97. Result := loop_stack.last
  98. end
  99. end
  100. end -- class LOOP_STACK
  101. --
  102. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  103. --
  104. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  105. -- of this software and associated documentation files (the "Software"), to deal
  106. -- in the Software without restriction, including without limitation the rights
  107. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  108. -- copies of the Software, and to permit persons to whom the Software is
  109. -- furnished to do so, subject to the following conditions:
  110. --
  111. -- The above copyright notice and this permission notice shall be included in
  112. -- all copies or substantial portions of the Software.
  113. --
  114. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  115. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  116. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  117. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  118. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  119. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  120. -- THE SOFTWARE.