PageRenderTime 61ms CodeModel.GetById 50ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/semantics/code/expressions/liberty_array_manifest.e

http://github.com/tybor/Liberty
Specman e | 191 lines | 155 code | 20 blank | 16 comment | 3 complexity | e656f9cd754efe7ce4e6bce22a362e39 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_ARRAY_MANIFEST
 16
 17inherit
 18   LIBERTY_EXPRESSION
 19
 20insert
 21   LIBERTY_ARRAY_MANIFEST_CONSTANTS
 22
 23create {LIBERTY_BUILDER_TOOLS}
 24   make, make_array
 25
 26create {LIBERTY_ARRAY_MANIFEST}
 27   specialized
 28
 29feature {ANY}
 30   parameters: TRAVERSABLE[LIBERTY_EXPRESSION] is
 31      do
 32         Result := parameters_list
 33      ensure
 34         Result = parameters_list
 35      end
 36
 37   contents: TRAVERSABLE[LIBERTY_EXPRESSION] is
 38      do
 39         Result := contents_list
 40      ensure
 41         Result = contents_list
 42      end
 43
 44   separators: TRAVERSABLE[LIBERTY_ARRAY_MANIFEST_SEPARATOR] is
 45      do
 46         Result := separators_list
 47      ensure
 48         Result = separators_list
 49      end
 50
 51   result_type: LIBERTY_TYPE
 52
 53   specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
 54      local
 55         r: like result_type
 56         p: like parameters_list
 57         c: like contents_list
 58      do
 59         r := result_type.specialized_in(a_type)
 60         p := specialized_expressions(parameters_list, a_type)
 61         c := specialized_expressions(contents_list, a_type)
 62         if r = result_type and then p = parameters and then c = contents then
 63            Result := Current
 64         else
 65            create Result.specialized(r, p, c, separators_list, position)
 66         end
 67      end
 68
 69feature {}
 70   specialized_expressions (a_expressions: COLLECTION[LIBERTY_EXPRESSION]; a_type: LIBERTY_ACTUAL_TYPE): COLLECTION[LIBERTY_EXPRESSION] is
 71      local
 72         e: LIBERTY_EXPRESSION
 73         i: INTEGER
 74      do
 75         from
 76            Result := a_expressions
 77            i := Result.lower
 78         until
 79            i > Result.upper
 80         loop
 81            e := Result.item(i).specialized_in(a_type)
 82            if e /= Result.item(i) then
 83               if Result = a_expressions then
 84                  Result := Result.twin
 85               end
 86               Result.put(e, i)
 87            end
 88            i := i + 1
 89         end
 90      end
 91
 92feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
 93   mark_reachable_code (mark: INTEGER) is
 94      do
 95         result_type.mark_reachable_code(mark)
 96         expressions_marker.mark_reachable_code(mark, parameters_list)
 97         expressions_marker.mark_reachable_code(mark, contents_list)
 98      end
 99
100feature {LIBERTY_BUILDER_TOOLS}
101   add_parameter (a_parameter: LIBERTY_EXPRESSION) is
102      do
103         parameters_list.add_last(a_parameter)
104      end
105
106   add_content (a_content: LIBERTY_EXPRESSION; a_separator: LIBERTY_ARRAY_MANIFEST_SEPARATOR) is
107      do
108         contents_list.add_last(a_content)
109         separators_list.add_last(a_separator)
110      end
111
112feature {}
113   make (a_type: like result_type; a_position: like position) is
114      require
115         a_type /= Void
116         a_position /= Void
117      do
118         result_type := a_type
119         create {FAST_ARRAY[LIBERTY_EXPRESSION]} parameters_list.make(0)
120         create {FAST_ARRAY[LIBERTY_EXPRESSION]} contents_list.make(0)
121         create {FAST_ARRAY[LIBERTY_ARRAY_MANIFEST_SEPARATOR]} separators_list.make(0)
122         position := a_position
123      ensure
124         result_type = a_type
125         position = a_position
126      end
127
128   make_array (a_type: like result_type; a_contents: like contents_list; a_separators: like separators_list; a_position: like position) is
129      require
130         a_type /= Void
131         a_contents /= Void
132         -- all a_contents items conform to a_type
133         a_separators /= Void
134         a_position /= Void
135      do
136         result_type := a_type
137         create {FAST_ARRAY[LIBERTY_EXPRESSION]} parameters_list.make(0)
138         contents_list := a_contents
139         separators_list := a_separators
140         position := a_position
141      ensure
142         result_type = a_type
143         contents = a_contents
144         separators = a_separators
145         position = a_position
146      end
147
148   specialized (a_type: like result_type; a_parameters: like parameters_list; a_contents: like contents_list; a_separators: like separators_list; a_position: like position) is
149      require
150         a_type /= Void
151         a_position /= Void
152         a_contents /= Void
153         -- all a_contents items conform to a_type
154         a_separators /= Void
155         a_position /= Void
156      do
157         result_type := a_type
158         parameters_list := a_parameters
159         contents_list := a_contents
160         separators_list := a_separators
161         position := a_position
162      ensure
163         result_type = a_type
164         parameters_list = a_parameters
165         contents = a_contents
166         separators = a_separators
167         position = a_position
168      end
169
170   parameters_list: COLLECTION[LIBERTY_EXPRESSION]
171   contents_list: COLLECTION[LIBERTY_EXPRESSION]
172   separators_list: COLLECTION[LIBERTY_ARRAY_MANIFEST_SEPARATOR]
173
174feature {ANY}
175   accept (v: VISITOR) is
176      local
177         v0: LIBERTY_ARRAY_MANIFEST_VISITOR
178      do
179         v0 ::= v
180         v0.visit_liberty_array_manifest(Current)
181      end
182
183invariant
184   result_type /= Void
185   parameters_list /= Void
186   contents_list /= Void
187   separators_list /= Void
188   contents_list.count = separators_list.count
189   contents_list.lower = separators_list.lower
190
191end