/src/tools/semantics/code/expressions/liberty_array_manifest.e

http://github.com/tybor/Liberty · Specman e · 191 lines · 155 code · 20 blank · 16 comment · 3 complexity · e656f9cd754efe7ce4e6bce22a362e39 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_ARRAY_MANIFEST
  16. inherit
  17. LIBERTY_EXPRESSION
  18. insert
  19. LIBERTY_ARRAY_MANIFEST_CONSTANTS
  20. create {LIBERTY_BUILDER_TOOLS}
  21. make, make_array
  22. create {LIBERTY_ARRAY_MANIFEST}
  23. specialized
  24. feature {ANY}
  25. parameters: TRAVERSABLE[LIBERTY_EXPRESSION] is
  26. do
  27. Result := parameters_list
  28. ensure
  29. Result = parameters_list
  30. end
  31. contents: TRAVERSABLE[LIBERTY_EXPRESSION] is
  32. do
  33. Result := contents_list
  34. ensure
  35. Result = contents_list
  36. end
  37. separators: TRAVERSABLE[LIBERTY_ARRAY_MANIFEST_SEPARATOR] is
  38. do
  39. Result := separators_list
  40. ensure
  41. Result = separators_list
  42. end
  43. result_type: LIBERTY_TYPE
  44. specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
  45. local
  46. r: like result_type
  47. p: like parameters_list
  48. c: like contents_list
  49. do
  50. r := result_type.specialized_in(a_type)
  51. p := specialized_expressions(parameters_list, a_type)
  52. c := specialized_expressions(contents_list, a_type)
  53. if r = result_type and then p = parameters and then c = contents then
  54. Result := Current
  55. else
  56. create Result.specialized(r, p, c, separators_list, position)
  57. end
  58. end
  59. feature {}
  60. specialized_expressions (a_expressions: COLLECTION[LIBERTY_EXPRESSION]; a_type: LIBERTY_ACTUAL_TYPE): COLLECTION[LIBERTY_EXPRESSION] is
  61. local
  62. e: LIBERTY_EXPRESSION
  63. i: INTEGER
  64. do
  65. from
  66. Result := a_expressions
  67. i := Result.lower
  68. until
  69. i > Result.upper
  70. loop
  71. e := Result.item(i).specialized_in(a_type)
  72. if e /= Result.item(i) then
  73. if Result = a_expressions then
  74. Result := Result.twin
  75. end
  76. Result.put(e, i)
  77. end
  78. i := i + 1
  79. end
  80. end
  81. feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
  82. mark_reachable_code (mark: INTEGER) is
  83. do
  84. result_type.mark_reachable_code(mark)
  85. expressions_marker.mark_reachable_code(mark, parameters_list)
  86. expressions_marker.mark_reachable_code(mark, contents_list)
  87. end
  88. feature {LIBERTY_BUILDER_TOOLS}
  89. add_parameter (a_parameter: LIBERTY_EXPRESSION) is
  90. do
  91. parameters_list.add_last(a_parameter)
  92. end
  93. add_content (a_content: LIBERTY_EXPRESSION; a_separator: LIBERTY_ARRAY_MANIFEST_SEPARATOR) is
  94. do
  95. contents_list.add_last(a_content)
  96. separators_list.add_last(a_separator)
  97. end
  98. feature {}
  99. make (a_type: like result_type; a_position: like position) is
  100. require
  101. a_type /= Void
  102. a_position /= Void
  103. do
  104. result_type := a_type
  105. create {FAST_ARRAY[LIBERTY_EXPRESSION]} parameters_list.make(0)
  106. create {FAST_ARRAY[LIBERTY_EXPRESSION]} contents_list.make(0)
  107. create {FAST_ARRAY[LIBERTY_ARRAY_MANIFEST_SEPARATOR]} separators_list.make(0)
  108. position := a_position
  109. ensure
  110. result_type = a_type
  111. position = a_position
  112. end
  113. make_array (a_type: like result_type; a_contents: like contents_list; a_separators: like separators_list; a_position: like position) is
  114. require
  115. a_type /= Void
  116. a_contents /= Void
  117. -- all a_contents items conform to a_type
  118. a_separators /= Void
  119. a_position /= Void
  120. do
  121. result_type := a_type
  122. create {FAST_ARRAY[LIBERTY_EXPRESSION]} parameters_list.make(0)
  123. contents_list := a_contents
  124. separators_list := a_separators
  125. position := a_position
  126. ensure
  127. result_type = a_type
  128. contents = a_contents
  129. separators = a_separators
  130. position = a_position
  131. end
  132. specialized (a_type: like result_type; a_parameters: like parameters_list; a_contents: like contents_list; a_separators: like separators_list; a_position: like position) is
  133. require
  134. a_type /= Void
  135. a_position /= Void
  136. a_contents /= Void
  137. -- all a_contents items conform to a_type
  138. a_separators /= Void
  139. a_position /= Void
  140. do
  141. result_type := a_type
  142. parameters_list := a_parameters
  143. contents_list := a_contents
  144. separators_list := a_separators
  145. position := a_position
  146. ensure
  147. result_type = a_type
  148. parameters_list = a_parameters
  149. contents = a_contents
  150. separators = a_separators
  151. position = a_position
  152. end
  153. parameters_list: COLLECTION[LIBERTY_EXPRESSION]
  154. contents_list: COLLECTION[LIBERTY_EXPRESSION]
  155. separators_list: COLLECTION[LIBERTY_ARRAY_MANIFEST_SEPARATOR]
  156. feature {ANY}
  157. accept (v: VISITOR) is
  158. local
  159. v0: LIBERTY_ARRAY_MANIFEST_VISITOR
  160. do
  161. v0 ::= v
  162. v0.visit_liberty_array_manifest(Current)
  163. end
  164. invariant
  165. result_type /= Void
  166. parameters_list /= Void
  167. contents_list /= Void
  168. separators_list /= Void
  169. contents_list.count = separators_list.count
  170. contents_list.lower = separators_list.lower
  171. end