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

/src/tools/semantics/code/entities/liberty_feature_entity.e

http://github.com/tybor/Liberty
Specman e | 229 lines | 184 code | 26 blank | 19 comment | 11 complexity | 1580f6e38d3f01ae9a6acb04a6ff6b04 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_FEATURE_ENTITY
 16--
 17-- A proxy to the feature itself.
 18--
 19-- See also LIBERTY_WRITABLE_FEATURE
 20--
 21
 22inherit
 23   LIBERTY_ENTITY
 24      redefine out_in_tagged_out_memory
 25      end
 26
 27insert
 28   LIBERTY_REACHABLE_MARKED
 29      redefine out_in_tagged_out_memory
 30      end
 31   LOGGING
 32      redefine out_in_tagged_out_memory
 33      end
 34
 35create {LIBERTY_BUILDER_TOOLS, LIBERTY_CALL, LIBERTY_CALL_PROMOTION}
 36   make
 37
 38create {LIBERTY_FEATURE_ENTITY}
 39   specialized
 40
 41feature {ANY}
 42   target_type: LIBERTY_TYPE
 43
 44   name: FIXED_STRING is
 45      do
 46         Result := feature_name.name
 47      end
 48
 49   out_in_tagged_out_memory is
 50      do
 51         tagged_out_memory.append(once "feature: ")
 52         feature_name.out_in_tagged_out_memory
 53      end
 54
 55   feature_name: LIBERTY_FEATURE_NAME
 56
 57   result_type: LIBERTY_TYPE is
 58      do
 59         if the_feature /= Void then
 60            Result := the_feature.result_type
 61         elseif delayed_feature_type.is_ready then
 62            the_feature := delayed_feature_type.the_feature
 63            Result := the_feature.result_type
 64         else
 65            Result := result_type_memory
 66         end
 67      end
 68
 69   has_feature: BOOLEAN is
 70      do
 71         Result := target_type.known_type.has_feature(feature_name)
 72      end
 73
 74   feature_definition: LIBERTY_FEATURE_DEFINITION is
 75      require
 76         has_feature
 77      do
 78         Result := target_type.known_type.feature_definition(feature_name)
 79      end
 80
 81   debug_display is
 82      do
 83         target_type.known_type.debug_display(log.trace, True)
 84      end
 85
 86   specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
 87      local
 88         f: like the_feature
 89         dft: like delayed_feature_type
 90         tt: like target_type
 91      do
 92         tt := target_type.specialized_in(a_type)
 93         if delayed_feature_type = Void or else delayed_feature_type.is_ready then
 94            if the_feature = Void then
 95               check
 96                  delayed_feature_type /= Void
 97               end
 98               the_feature := delayed_feature_type.the_feature
 99            end
100            f := the_feature.specialized_in(a_type)
101            if f = the_feature and then tt = target_type then
102               Result := Current
103            else
104               create Result.specialized(feature_name, tt, f, Void)
105            end
106         else
107            dft := delayed_feature_type.specialized_in(a_type)
108            if dft = delayed_feature_type and then tt = target_type then
109               Result := Current
110            else
111               create Result.specialized(feature_name, tt, Void, dft)
112            end
113         end
114      end
115
116feature {LIBERTY_CALL_EXPRESSION}
117   can_check_agent_signature (a_agent_call: LIBERTY_CALL_EXPRESSION): BOOLEAN is
118      require
119         a_agent_call /= Void
120      do
121         Result := the_feature /= Void and then the_feature.can_check_agent_signature(a_agent_call)
122      ensure
123         can_also_check_result_type: Result implies (the_feature.result_type = Void or else the_feature.result_type.is_known)
124      end
125
126   agent_signature (a_agent_call: LIBERTY_CALL_EXPRESSION): COLLECTION[LIBERTY_KNOWN_TYPE] is
127      require
128         can_check_agent_signature(a_agent_call)
129         a_agent_call.is_agent_call
130      do
131         Result := the_feature.agent_signature(a_agent_call)
132      end
133
134   check_agent_signature (a_agent_call: LIBERTY_CALL_EXPRESSION) is
135      require
136         can_check_agent_signature(a_agent_call)
137         a_agent_call.is_agent_call
138      do
139         the_feature.check_agent_signature(a_agent_call)
140      end
141
142feature {LIBERTY_REACHABLE, LIBERTY_REACHABLE_COLLECTION_MARKER}
143   mark_reachable_code (mark: INTEGER) is
144      local
145         rt: like result_type
146      do
147         if not is_reachable then
148            debug ("mark.reachable")
149               log.trace.put_string(once "Marked reachable the feature entity {")
150               log.trace.put_string(target_type.full_name)
151               log.trace.put_string(once "}.")
152               log.trace.put_line(feature_name.name)
153            end
154            torch.burn
155         end
156         reachable_mark := mark
157
158         if the_feature /= Void then
159            the_feature.mark_reachable_code(mark)
160         elseif delayed_feature_type /= Void then
161            delayed_feature_type.mark_reachable_code(mark)
162         end
163
164         rt := result_type
165         if rt /= Void then--and then rt.is_known and then rt.known_type.is_runtime_category_set and then rt.known_type.is_expanded then
166            rt.mark_reachable_code(mark)
167         end
168      end
169
170feature {}
171   the_feature: LIBERTY_FEATURE
172   delayed_feature_type: LIBERTY_DELAYED_FEATURE_TYPE
173   result_type_memory: LIBERTY_TYPE
174
175   make (a_name: like feature_name; a_target_type: like target_type) is
176      require
177         a_name /= Void
178         a_target_type /= Void
179      do
180         feature_name := a_name
181         target_type := a_target_type
182         create delayed_feature_type.make(a_target_type, a_name)
183         create {LIBERTY_DELAYED_TYPE} result_type_memory.make(delayed_feature_type)
184         position := a_name.position
185      ensure
186         feature_name = a_name
187         target_type = a_target_type
188         position = a_name.position
189      end
190
191   specialized (a_name: like feature_name; a_target_type: like target_type; a_feature: like the_feature; a_delayed_feature_type: like delayed_feature_type) is
192      require
193         a_name /= Void
194         a_target_type /= Void
195         a_feature /= Void xor a_delayed_feature_type /= Void
196      do
197         feature_name := a_name
198         target_type := a_target_type
199         the_feature := a_feature
200         delayed_feature_type := a_delayed_feature_type
201         if a_delayed_feature_type /= Void then
202            create {LIBERTY_DELAYED_TYPE} result_type_memory.make(a_delayed_feature_type)
203         end
204         position := a_name.position
205      ensure
206         feature_name = a_name
207         target_type = a_target_type
208         the_feature = a_feature
209         delayed_feature_type = a_delayed_feature_type
210         position = a_name.position
211      end
212
213   torch: LIBERTY_ENLIGHTENING_THE_WORLD
214
215feature {ANY}
216   accept (v: VISITOR) is
217      local
218         v0: LIBERTY_FEATURE_ENTITY_VISITOR
219      do
220         v0 ::= v
221         v0.visit_liberty_feature_entity(Current)
222      end
223
224invariant
225   name /= Void
226   the_feature = Void implies delayed_feature_type /= Void
227   target_type /= Void
228
229end