PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/src/tools/semantics/types/delayed_resolver/liberty_delayed_resolver_in_type.e

http://github.com/tybor/Liberty
Specman e | 151 lines | 120 code | 17 blank | 14 comment | 6 complexity | 22c2621f94c2c02805c727e3da77e682 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_DELAYED_RESOLVER_IN_TYPE
 16
 17inherit
 18   LIBERTY_DELAYED_RESOLVER
 19
 20insert
 21   EIFFEL_NODE_HANDLER
 22      redefine out_in_tagged_out_memory, is_equal
 23      end
 24
 25creation {LIBERTY_TYPE_RESOLVER_IN_TYPE}
 26   like_current, like_feature
 27
 28creation {LIBERTY_DELAYED_RESOLVER_IN_TYPE}
 29   specialized
 30
 31feature {ANY}
 32   out_in_tagged_out_memory is
 33      do
 34         current_type.out_in_tagged_out_memory
 35         if feature_name /= Void then
 36            tagged_out_memory.append(once ".")
 37            feature_name.out_in_tagged_out_memory
 38         end
 39      end
 40
 41   hash_code: INTEGER is
 42      do
 43         Result := current_type.hash_code
 44      end
 45
 46   is_equal (other: like Current): BOOLEAN is
 47      do
 48         Result := other = Current
 49      end
 50
 51feature {LIBERTY_DELAYED_TYPE}
 52   can_resolve: BOOLEAN is
 53      local
 54         fd: LIBERTY_FEATURE_DEFINITION
 55         bound_feature: LIBERTY_FEATURE
 56      do
 57         if feature_name = Void then
 58            Result := True
 59         elseif current_type.has_feature(feature_name) then
 60            fd := definition_type.feature_definition(feature_name)
 61            if definition_type = current_type then
 62               bound_feature := fd.the_feature
 63            elseif fd.the_feature.is_bound(current_type) then
 64               bound_feature := fd.the_feature.bound(current_type)
 65            end
 66            if bound_feature /= Void then
 67               Result := bound_feature.result_type.is_known
 68            end
 69         end
 70      end
 71
 72   resolved: LIBERTY_KNOWN_TYPE is
 73      do
 74         if feature_name = Void then
 75            Result := current_type
 76         else
 77            Result := definition_type.feature_definition(feature_name).the_feature.bound(current_type).result_type.known_type
 78         end
 79      end
 80
 81   full_name: FIXED_STRING is
 82      do
 83         Result := current_type.full_name
 84      end
 85
 86   specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
 87      do
 88         if a_type.is_child_of(definition_type) then
 89            create Result.specialized(a_type, definition_type, feature_name)
 90         else
 91            Result := Current
 92         end
 93      end
 94
 95feature {}
 96   like_current (a_type: like current_type) is
 97      require
 98         a_type /= Void
 99      do
100         current_type := a_type
101         definition_type := a_type
102      ensure
103         current_type = a_type
104         definition_type = a_type
105         feature_name = Void
106      end
107
108    like_feature (a_type: like current_type; a_feature_name: like feature_name) is
109      require
110         a_type /= Void
111         a_feature_name /= Void
112      do
113         current_type := a_type
114         definition_type := a_type
115         feature_name := a_feature_name
116      ensure
117         current_type = a_type
118         definition_type = a_type
119         feature_name = a_feature_name
120      end
121
122    specialized (a_type: like current_type; a_definition_type: like definition_type; a_feature_name: like feature_name) is
123      require
124         a_type /= Void
125         a_definition_type /= Void
126         a_type.is_child_of(a_definition_type)
127      do
128         debug ("feature.specialization")
129            log.trace.put_string(once "Creating specialized type resolver from ")
130            log.trace.put_string(a_definition_type.full_name)
131            log.trace.put_string(once " to ")
132            log.trace.put_line(a_type.full_name)
133         end
134         current_type := a_type
135         definition_type := a_definition_type
136         feature_name := a_feature_name
137      ensure
138         current_type = a_type
139         definition_type = a_definition_type
140         feature_name = a_feature_name
141      end
142
143   current_type: LIBERTY_ACTUAL_TYPE
144   definition_type: LIBERTY_ACTUAL_TYPE
145   feature_name: LIBERTY_FEATURE_NAME
146
147invariant
148   current_type /= Void
149   definition_type /= Void
150
151end -- class LIBERTY_DELAYED_RESOLVER_IN_TYPE