/src/tools/semantics/code/instructions/liberty_conditional.e

http://github.com/tybor/Liberty · Specman e · 133 lines · 103 code · 16 blank · 14 comment · 5 complexity · f521b74204b0e2fbb3571b09fbff4893 MD5 · raw file

  1. -- This file is part of Liberty Eiffel.
  2. --
  3. -- Liberty Eiffel is free software: you can redistribute it and/or modify
  4. -- it under the terms of the GNU General Public License as published by
  5. -- the Free Software Foundation, version 3 of the License.
  6. --
  7. -- Liberty Eiffel is distributed in the hope that it will be useful,
  8. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. -- GNU General Public License for more details.
  11. --
  12. -- You should have received a copy of the GNU General Public License
  13. -- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>.
  14. --
  15. class LIBERTY_CONDITIONAL
  16. inherit
  17. LIBERTY_INSTRUCTION
  18. create {LIBERTY_BUILDER_TOOLS}
  19. make
  20. create {LIBERTY_CONDITIONAL}
  21. make_specialized
  22. feature {ANY}
  23. conditions: TRAVERSABLE[LIBERTY_CONDITION] is
  24. do
  25. Result := conditions_list
  26. ensure
  27. Result = conditions_list
  28. end
  29. else_clause: LIBERTY_DEFAULT
  30. specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
  31. local
  32. i: INTEGER
  33. c: like conditions_list
  34. cond: LIBERTY_CONDITION
  35. e: like else_clause
  36. do
  37. from
  38. c := conditions_list
  39. i := c.lower
  40. until
  41. i > c.upper
  42. loop
  43. cond := c.item(i).specialized_in(a_type)
  44. if cond /= c.item(i) then
  45. if c = conditions_list then
  46. c := c.twin
  47. end
  48. c.put(cond, i)
  49. end
  50. i := i + 1
  51. end
  52. if else_clause /= Void then
  53. e := else_clause.specialized_in(a_type)
  54. end
  55. if c = conditions_list and then e = else_clause then
  56. Result := Current
  57. else
  58. create Result.make_specialized(c, e, position)
  59. end
  60. end
  61. feature {LIBERTY_BUILDER_TOOLS}
  62. add_condition (a_condition: LIBERTY_CONDITION) is
  63. do
  64. conditions_list.add_last(a_condition)
  65. ensure
  66. conditions.last = a_condition
  67. end
  68. set_else_clause (a_else_clause: like else_clause) is
  69. do
  70. else_clause := a_else_clause
  71. ensure
  72. else_clause = a_else_clause
  73. end
  74. feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
  75. mark_reachable_code (mark: INTEGER) is
  76. do
  77. conditions_marker.mark_reachable_code(mark, conditions)
  78. if else_clause /= Void then
  79. else_clause.mark_reachable_code(mark)
  80. end
  81. end
  82. feature {}
  83. make (a_position: like position) is
  84. require
  85. a_position /= Void
  86. do
  87. create {FAST_ARRAY[LIBERTY_CONDITION]} conditions_list.with_capacity(4)
  88. position := a_position
  89. ensure
  90. position = a_position
  91. end
  92. make_specialized (a_conditions: like conditions_list; a_else: like else_clause; a_position: like position) is
  93. require
  94. a_conditions /= Void
  95. a_position /= Void
  96. do
  97. conditions_list := a_conditions
  98. else_clause := a_else
  99. position := a_position
  100. ensure
  101. conditions_list = a_conditions
  102. else_clause = a_else
  103. position = a_position
  104. end
  105. conditions_list: COLLECTION[LIBERTY_CONDITION]
  106. conditions_marker: LIBERTY_REACHABLE_COLLECTION_MARKER[LIBERTY_CONDITION]
  107. feature {ANY}
  108. accept (v: VISITOR) is
  109. local
  110. v0: LIBERTY_CONDITIONAL_VISITOR
  111. do
  112. v0 ::= v
  113. v0.visit_liberty_conditional(Current)
  114. end
  115. invariant
  116. conditions_list /= Void
  117. end