PageRenderTime 22ms CodeModel.GetById 19ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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