PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/tybor/Liberty
Specman e | 131 lines | 102 code | 15 blank | 14 comment | 3 complexity | 1870acaccffd476bd1e173357e34d5bf 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_INSPECT_CLAUSE
 16
 17insert
 18   LIBERTY_POSITIONABLE
 19   LIBERTY_REACHABLE
 20
 21create {LIBERTY_BUILDER_TOOLS}
 22   make
 23
 24create {LIBERTY_INSPECT_CLAUSE}
 25   make_specialized
 26
 27feature {ANY}
 28   instruction: LIBERTY_INSTRUCTION
 29
 30   values: TRAVERSABLE[LIBERTY_INSPECT_SLICE] is
 31      do
 32         Result := values_list
 33      ensure
 34         Result = values_list
 35      end
 36
 37feature {LIBERTY_INSPECT}
 38   specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
 39      local
 40         ins: like instruction
 41         v: like values_list
 42         slice: LIBERTY_INSPECT_SLICE
 43         i: INTEGER
 44      do
 45         ins := instruction.specialized_in(a_type)
 46         from
 47            v := values_list
 48            i := v.lower
 49         until
 50            i > v.upper
 51         loop
 52            slice := v.item(i).specialized_in(a_type)
 53            if slice /= v.item(i) then
 54               if v = values_list then
 55                  v := v.twin
 56               end
 57               v.put(slice, i)
 58            end
 59            i := i + 1
 60         end
 61         if ins = instruction and then v = values_list then
 62            Result := Current
 63         else
 64            create Result.make_specialized(ins, v, position)
 65         end
 66      end
 67
 68feature {LIBERTY_BUILDER_TOOLS}
 69   add_value (a_value: LIBERTY_INSPECT_SLICE) is
 70      require
 71         a_value /= Void
 72      do
 73         values_list.add_last(a_value)
 74      ensure
 75         values.last = a_value
 76      end
 77
 78feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
 79   mark_reachable_code (mark: INTEGER) is
 80      do
 81         instruction.mark_reachable_code(mark)
 82         inspect_slices_marker.mark_reachable_code(mark, values)
 83      end
 84
 85feature {}
 86   make (a_instruction: like instruction; a_position: like position) is
 87      require
 88         a_instruction /= Void
 89         a_position /= Void
 90      do
 91         instruction := a_instruction
 92         create {FAST_ARRAY[LIBERTY_INSPECT_SLICE]} values_list.with_capacity(2)
 93         position := a_position
 94      ensure
 95         instruction = a_instruction
 96         position = a_position
 97      end
 98
 99   make_specialized (a_instruction: like instruction; a_values_list: like values_list; a_position: like position) is
100      require
101         a_instruction /= Void
102         a_values_list /= Void
103         a_position /= Void
104      do
105         instruction := a_instruction
106         values_list := a_values_list
107         position := a_position
108      ensure
109         instruction = a_instruction
110         values_list = a_values_list
111         position = a_position
112      end
113
114   values_list: COLLECTION[LIBERTY_INSPECT_SLICE]
115
116   inspect_slices_marker: LIBERTY_REACHABLE_COLLECTION_MARKER[LIBERTY_INSPECT_SLICE]
117
118feature {ANY}
119   accept (v: VISITOR) is
120      local
121         v0: LIBERTY_INSPECT_CLAUSE_VISITOR
122      do
123         v0 ::= v
124         v0.visit_liberty_inspect_clause(Current)
125      end
126
127invariant
128   instruction /= Void
129   values_list /= Void
130
131end