PageRenderTime 14ms CodeModel.GetById 5ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

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