/src/tools/interpreter/liberty_interpreter_object.e

http://github.com/tybor/Liberty · Specman e · 200 lines · 153 code · 30 blank · 17 comment · 2 complexity · a409ce0c784da13347af2a8e86bb1e1b 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. deferred class LIBERTY_INTERPRETER_OBJECT
  16. inherit
  17. LIBERTY_EXPRESSION
  18. redefine
  19. is_equal
  20. end
  21. HASHABLE
  22. insert
  23. ARRAYED_COLLECTION_HANDLER
  24. feature {ANY}
  25. is_void: BOOLEAN is False
  26. is_equal (other: LIBERTY_INTERPRETER_OBJECT): BOOLEAN is
  27. deferred
  28. end
  29. result_type: LIBERTY_TYPE is
  30. do
  31. Result := type
  32. end
  33. type: LIBERTY_KNOWN_TYPE is
  34. -- the actual dynamic type of the object
  35. deferred
  36. end
  37. is_open: BOOLEAN is False
  38. is_between (lower, upper: LIBERTY_INTERPRETER_OBJECT; a_position: LIBERTY_POSITION): BOOLEAN is
  39. local
  40. fd: LIBERTY_FEATURE_DEFINITION
  41. cmp: LIBERTY_INTERPRETER_OBJECT_NATIVE[BOOLEAN]
  42. do
  43. fd := type.feature_definition(le_feature_name)
  44. cmp ::= interpreter.item_feature(lower, fd, {FAST_ARRAY[LIBERTY_INTERPRETER_OBJECT] << Current >> }, a_position)
  45. if cmp.item then
  46. cmp ::= interpreter.item_feature(Current, fd, {FAST_ARRAY[LIBERTY_INTERPRETER_OBJECT] << upper >> }, a_position)
  47. Result := cmp.item
  48. end
  49. end
  50. as_target (a_position: LIBERTY_POSITION): like Current is
  51. -- Current when used as a target
  52. do
  53. Result := Current
  54. ensure
  55. Result = Current
  56. end
  57. as_right_value: like Current is
  58. -- either Current or a twin depending on the storage class (expanded, reference, separate)
  59. do
  60. if type.is_expanded then
  61. Result := expanded_twin
  62. elseif type.is_separate then
  63. not_yet_implemented
  64. else
  65. Result := Current
  66. end
  67. ensure
  68. is_equal(Result)
  69. end
  70. converted_to (target_type: LIBERTY_ACTUAL_TYPE): LIBERTY_INTERPRETER_OBJECT is
  71. require
  72. type.converts_to(target_type)
  73. deferred
  74. ensure
  75. Result.type = target_type
  76. end
  77. specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
  78. do
  79. check False end
  80. crash
  81. end
  82. feature {LIBERTY_INTERPRETER_EXTERNAL_TYPE_ANY_BUILTINS} -- Standard builtings
  83. builtin_is_equal (other: LIBERTY_INTERPRETER_OBJECT; a_position: LIBERTY_POSITION): BOOLEAN is
  84. require
  85. not other.is_void
  86. deferred
  87. end
  88. builtin_standard_is_equal (other: LIBERTY_INTERPRETER_OBJECT; a_position: LIBERTY_POSITION): BOOLEAN is
  89. require
  90. not other.is_void
  91. deferred
  92. end
  93. builtin_is_deep_equal (other: LIBERTY_INTERPRETER_OBJECT; a_position: LIBERTY_POSITION): BOOLEAN is
  94. require
  95. not other.is_void
  96. local
  97. deep_equal_memory: SET[LIBERTY_INTERPRETER_OBJECT]
  98. do
  99. create {HASHED_SET[LIBERTY_INTERPRETER_OBJECT]} deep_equal_memory.make
  100. Result := do_deep_equal(other, deep_equal_memory, a_position)
  101. end
  102. builtin_copy (other: LIBERTY_INTERPRETER_OBJECT; a_position: LIBERTY_POSITION) is
  103. require
  104. not other.is_void
  105. deferred
  106. end
  107. builtin_twin (a_position: LIBERTY_POSITION): like Current is
  108. deferred
  109. end
  110. builtin_standard_copy (other: LIBERTY_INTERPRETER_OBJECT; a_position: LIBERTY_POSITION) is
  111. require
  112. not other.is_void
  113. deferred
  114. end
  115. builtin_standard_twin (a_position: LIBERTY_POSITION): like Current is
  116. deferred
  117. end
  118. builtin_deep_twin (a_position: LIBERTY_POSITION): LIBERTY_INTERPRETER_OBJECT is
  119. local
  120. deep_twin_memory: DICTIONARY[LIBERTY_INTERPRETER_OBJECT, LIBERTY_INTERPRETER_OBJECT]
  121. do
  122. create {HASHED_DICTIONARY[LIBERTY_INTERPRETER_OBJECT, LIBERTY_INTERPRETER_OBJECT]} deep_twin_memory.make
  123. Result := do_deep_twin(deep_twin_memory, a_position)
  124. end
  125. feature {LIBERTY_INTERPRETER_OBJECT}
  126. do_deep_twin (deep_twin_memory: DICTIONARY[LIBERTY_INTERPRETER_OBJECT, LIBERTY_INTERPRETER_OBJECT]; a_position: LIBERTY_POSITION): LIBERTY_INTERPRETER_OBJECT is
  127. require
  128. deep_twin_memory /= Void
  129. deferred
  130. end
  131. do_deep_equal (object: LIBERTY_INTERPRETER_OBJECT; deep_equal_memory: SET[LIBERTY_INTERPRETER_OBJECT]; a_position: LIBERTY_POSITION): BOOLEAN is
  132. require
  133. object /= Void
  134. deep_equal_memory /= Void
  135. deferred
  136. end
  137. feature {LIBERTY_INTERPRETER_OBJECT_PRINTER, LIBERTY_INTERPRETER_FEATURE_CALL}
  138. show_stack (o: OUTPUT_STREAM; indent: INTEGER) is
  139. deferred
  140. end
  141. feature {}
  142. expanded_twin: like Current is
  143. require
  144. type.is_expanded
  145. deferred
  146. ensure
  147. is_equal(Result)
  148. end
  149. interpreter: LIBERTY_INTERPRETER
  150. le_feature_name: LIBERTY_FEATURE_NAME is
  151. once
  152. create Result.infixed("<=".intern)
  153. end
  154. feature {ANY}
  155. accept (visitor: VISITOR) is
  156. local
  157. v: LIBERTY_INTERPRETER_OBJECT_VISITOR
  158. do
  159. v ::= visitor
  160. v.visit_liberty_object(Current)
  161. end
  162. feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
  163. mark_reachable_code (mark: INTEGER) is
  164. do
  165. check False end
  166. end
  167. invariant
  168. type /= Void
  169. interpreter /= Void
  170. end -- class LIBERTY_INTERPRETER_OBJECT