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

http://github.com/tybor/Liberty · Specman e · 116 lines · 86 code · 15 blank · 15 comment · 3 complexity · f3a6732cf6aa8f1ab27d7e61c92d5136 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_TUPLE
  16. inherit
  17. LIBERTY_EXPRESSION
  18. create {LIBERTY_BUILDER_TOOLS, LIBERTY_TUPLE}
  19. make
  20. feature {ANY}
  21. result_type: LIBERTY_TYPE
  22. count: INTEGER is
  23. do
  24. Result := elements.count
  25. end
  26. lower: INTEGER is 1
  27. upper: INTEGER is
  28. do
  29. Result := count
  30. end
  31. is_empty: BOOLEAN is
  32. do
  33. Result := count = 0
  34. end
  35. item (i: INTEGER): LIBERTY_EXPRESSION is
  36. do
  37. Result := elements.item(i - lower)
  38. end
  39. specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
  40. local
  41. r: like result_type
  42. e: like elements
  43. x: LIBERTY_EXPRESSION
  44. i: INTEGER
  45. do
  46. r := result_type.specialized_in(a_type)
  47. from
  48. e := elements
  49. i := e.lower
  50. until
  51. i > e.upper
  52. loop
  53. x := e.item(i).specialized_in(a_type)
  54. if x /= e.item(i) then
  55. if e = elements then
  56. e := e.twin
  57. end
  58. e.put(x, i)
  59. end
  60. i := i + 1
  61. end
  62. if r = result_type and then e = elements then
  63. Result := Current
  64. else
  65. create Result.make(r, e, position)
  66. end
  67. end
  68. feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
  69. mark_reachable_code (mark: INTEGER) is
  70. do
  71. result_type.mark_reachable_code(mark)
  72. expressions_marker.mark_reachable_code(mark, elements)
  73. end
  74. feature {}
  75. make (a_result_type: like result_type; a_elements: like elements; a_position: like position) is
  76. require
  77. a_result_type /= Void
  78. -- a_result_type is a TUPLE type
  79. a_elements /= Void
  80. a_position /= Void
  81. do
  82. result_type := a_result_type
  83. elements := a_elements
  84. position := a_position
  85. ensure
  86. result_type = a_result_type
  87. elements = a_elements
  88. position = a_position
  89. end
  90. elements: COLLECTION[LIBERTY_EXPRESSION]
  91. feature {ANY}
  92. accept (v: VISITOR) is
  93. local
  94. v0: LIBERTY_TUPLE_VISITOR
  95. do
  96. v0 ::= v
  97. v0.visit_liberty_tuple(Current)
  98. end
  99. invariant
  100. elements /= Void implies elements.count = count
  101. end