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

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

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