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

http://github.com/tybor/Liberty · Specman e · 126 lines · 94 code · 18 blank · 14 comment · 3 complexity · caccb08746b74986057837f8f3c86654 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_COMPOUND
  16. inherit
  17. LIBERTY_INSTRUCTION
  18. TRAVERSABLE[LIBERTY_INSTRUCTION]
  19. create {LIBERTY_BUILDER_TOOLS, LIBERTY_COMPOUND}
  20. make
  21. feature {ANY}
  22. count: INTEGER is
  23. do
  24. Result := instructions.count
  25. ensure then
  26. Result > 1
  27. end
  28. is_empty: BOOLEAN is False
  29. lower: INTEGER is
  30. do
  31. Result := instructions.lower
  32. end
  33. upper: INTEGER is
  34. do
  35. Result := instructions.upper
  36. end
  37. first: LIBERTY_INSTRUCTION is
  38. do
  39. Result := instructions.first
  40. end
  41. last: LIBERTY_INSTRUCTION is
  42. do
  43. Result := instructions.last
  44. end
  45. item (i: INTEGER): LIBERTY_INSTRUCTION is
  46. do
  47. Result := instructions.item(i)
  48. end
  49. new_iterator: ITERATOR[LIBERTY_INSTRUCTION] is
  50. do
  51. Result := instructions.new_iterator
  52. end
  53. specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
  54. local
  55. i: INTEGER
  56. ins: like instructions
  57. inst: LIBERTY_INSTRUCTION
  58. do
  59. from
  60. ins := instructions
  61. i := ins.lower
  62. until
  63. i > ins.upper
  64. loop
  65. inst := ins.item(i).specialized_in(a_type)
  66. if inst /= ins.item(i) then
  67. if ins = instructions then
  68. ins := instructions.twin
  69. end
  70. ins.put(inst, i)
  71. end
  72. i := i + 1
  73. end
  74. if ins = instructions then
  75. Result := Current
  76. else
  77. create Result.make(ins, position)
  78. end
  79. end
  80. feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
  81. mark_reachable_code (mark: INTEGER) is
  82. do
  83. instructions_marker.mark_reachable_code(mark, instructions)
  84. end
  85. feature {}
  86. make (a_instructions: like instructions; a_position: like position) is
  87. require
  88. a_instructions.count > 1
  89. a_position /= Void
  90. do
  91. instructions := a_instructions
  92. position := a_position
  93. ensure
  94. instructions = a_instructions
  95. position = a_position
  96. end
  97. instructions: COLLECTION[LIBERTY_INSTRUCTION]
  98. feature {ANY}
  99. accept (v: VISITOR) is
  100. local
  101. v0: LIBERTY_COMPOUND_VISITOR
  102. do
  103. v0 ::= v
  104. v0.visit_liberty_compound(Current)
  105. end
  106. invariant
  107. instructions /= Void
  108. end