PageRenderTime 12ms CodeModel.GetById 9ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

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