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

http://github.com/tybor/Liberty · Specman e · 147 lines · 116 code · 17 blank · 14 comment · 5 complexity · 710e4b9a7bbb7df1837af49a1d27527b 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_INSPECT
  16. inherit
  17. LIBERTY_INSTRUCTION
  18. create {LIBERTY_BUILDER_TOOLS}
  19. make
  20. create {LIBERTY_INSPECT}
  21. specialized
  22. feature {ANY}
  23. expression: LIBERTY_EXPRESSION
  24. clauses: TRAVERSABLE[LIBERTY_INSPECT_CLAUSE] is
  25. do
  26. Result := clauses_list
  27. ensure
  28. Result = clauses_list
  29. end
  30. else_clause: LIBERTY_DEFAULT
  31. specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
  32. local
  33. e: like expression
  34. c: like clauses_list
  35. clause: LIBERTY_INSPECT_CLAUSE
  36. d: like else_clause
  37. i: INTEGER
  38. do
  39. e := expression.specialized_in(a_type)
  40. from
  41. c := clauses_list
  42. i := c.lower
  43. until
  44. i > c.upper
  45. loop
  46. clause := c.item(i).specialized_in(a_type)
  47. if clause /= c.item(i) then
  48. if c = clauses_list then
  49. c := c.twin
  50. end
  51. c.put(clause, i)
  52. end
  53. i := i + 1
  54. end
  55. if else_clause /= Void then
  56. d := else_clause.specialized_in(a_type)
  57. end
  58. if e = expression and then c = clauses_list and then d = else_clause then
  59. Result := Current
  60. else
  61. create Result.specialized(e, c, d, position)
  62. end
  63. end
  64. feature {LIBERTY_BUILDER_TOOLS}
  65. add_clause (a_clause: LIBERTY_INSPECT_CLAUSE) is
  66. require
  67. a_clause /= Void
  68. do
  69. clauses_list.add_last(a_clause)
  70. ensure
  71. clauses.last = a_clause
  72. end
  73. set_else_clause (a_else_clause: like else_clause) is
  74. do
  75. else_clause := a_else_clause
  76. ensure
  77. else_clause = a_else_clause
  78. end
  79. feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
  80. mark_reachable_code (mark: INTEGER) is
  81. do
  82. expression.mark_reachable_code(mark)
  83. inspect_clauses_marker.mark_reachable_code(mark, clauses)
  84. if else_clause /= Void then
  85. else_clause.mark_reachable_code(mark)
  86. end
  87. end
  88. feature {}
  89. make (a_expression: like expression; a_position: like position) is
  90. require
  91. a_expression /= Void
  92. a_position /= Void
  93. do
  94. create {FAST_ARRAY[LIBERTY_INSPECT_CLAUSE]} clauses_list.with_capacity(8)
  95. expression := a_expression
  96. position := a_position
  97. ensure
  98. expression = a_expression
  99. position = a_position
  100. end
  101. specialized (a_expression: like expression; a_clauses_list: like clauses_list; a_else_clause: like else_clause; a_position: like position) is
  102. require
  103. a_expression /= Void
  104. a_clauses_list /= Void
  105. a_position /= Void
  106. do
  107. expression := a_expression
  108. clauses_list := a_clauses_list
  109. else_clause := a_else_clause
  110. position := a_position
  111. ensure
  112. expression = a_expression
  113. clauses_list = a_clauses_list
  114. else_clause = a_else_clause
  115. position = a_position
  116. end
  117. clauses_list: COLLECTION[LIBERTY_INSPECT_CLAUSE]
  118. inspect_clauses_marker: LIBERTY_REACHABLE_COLLECTION_MARKER[LIBERTY_INSPECT_CLAUSE]
  119. feature {ANY}
  120. accept (v: VISITOR) is
  121. local
  122. v0: LIBERTY_INSPECT_VISITOR
  123. do
  124. v0 ::= v
  125. v0.visit_liberty_inspect(Current)
  126. end
  127. invariant
  128. expression /= Void
  129. clauses_list /= Void
  130. end