PageRenderTime 20ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/semantics/types/type_resolver/liberty_type_resolver_in_type.e

http://github.com/tybor/Liberty
Specman e | 171 lines | 138 code | 16 blank | 17 comment | 7 complexity | 440f6df3e335097d810aaa38d7dabab7 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_TYPE_RESOLVER_IN_TYPE
 16
 17inherit
 18   LIBERTY_TYPE_RESOLVER
 19
 20creation {LIBERTY_TYPE_BUILDER}
 21   make
 22
 23feature {ANY}
 24   out_in_tagged_out_memory is
 25      do
 26         tagged_out_memory.append(once "resolver in type ")
 27         current_type.out_in_tagged_out_memory
 28      end
 29
 30   current_type: LIBERTY_ACTUAL_TYPE
 31
 32   specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
 33      do
 34         Result := a_type.type_resolver
 35      ensure then
 36         Result.current_type = a_type
 37      end
 38
 39feature {LIBERTY_TYPE_BUILDER}
 40   set_effective_parameters (effective: like effective_parameters) is
 41      require
 42         useful: not effective.is_empty
 43      do
 44         effective_parameters := effective
 45      ensure
 46         effective_parameters = effective
 47      end
 48
 49feature {}
 50   universe: LIBERTY_UNIVERSE
 51   effective_parameters: DICTIONARY[LIBERTY_ACTUAL_TYPE, FIXED_STRING]
 52
 53   lookup_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
 54      local
 55         fn: LIBERTY_FEATURE_NAME
 56      do
 57         if type_definition.is_like_current then
 58            create {LIBERTY_DELAYED_TYPE} Result.make(create {LIBERTY_DELAYED_RESOLVER_IN_TYPE}.like_current(current_type))
 59         elseif type_definition.is_like_result then
 60            breakpoint
 61         elseif type_definition.is_anchor then
 62            -- like <feature>
 63            create fn.make_from_ast_entity_name(type_definition.entity_anchor, current_type.ast, current_type.file)
 64            create {LIBERTY_DELAYED_TYPE} Result.make(create {LIBERTY_DELAYED_RESOLVER_IN_TYPE}.like_feature(current_type, fn))
 65         else
 66            Result := effective_parameters.fast_reference_at(type_definition.type_name.image.image.intern)
 67            if Result = Void then
 68               Result := universe.get_type_from_type_definition(type_definition, current_type.cluster)
 69            end
 70         end
 71      end
 72
 73   lookup_export_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
 74      do
 75         if type_definition.type_parameters.list_count = 0 then
 76            Result := type_from_legacy_class_name_or_full_liberty_type(type_definition)
 77         else
 78            Result := universe.get_type_from_type_definition(type_definition, current_type.cluster)
 79         end
 80      end
 81
 82   lookup_position (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_POSITION is
 83      do
 84         Result := errors.semantics_position(type_definition.type_name.image.index, current_type.ast, current_type.file)
 85      end
 86
 87   make (a_universe: like universe; a_current_type: like current_type; a_effective_parameters: like effective_parameters) is
 88      require
 89         a_universe /= Void
 90         a_current_type /= Void
 91         a_effective_parameters /= Void
 92      do
 93         universe := a_universe
 94         current_type := a_current_type
 95         effective_parameters := a_effective_parameters
 96      ensure
 97         current_type = a_current_type
 98         effective_parameters = a_effective_parameters
 99      end
100
101feature {}
102   type_from_legacy_class_name_or_full_liberty_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_ACTUAL_TYPE is
103         -- Special code to handle legacy Eiffel class marks (in exports and precursors) or full-fledged type
104         -- marks Liberty recommends
105      require
106         not type_definition.is_anchor
107         not errors.has_error
108      local
109         descriptor: LIBERTY_TYPE_DESCRIPTOR
110         cluster: LIBERTY_CLUSTER
111         class_name: FIXED_STRING
112         parameters: TRAVERSABLE[LIBERTY_TYPE]
113         pos: LIBERTY_POSITION
114      do
115         pos := position(type_definition)
116         class_name := type_definition.type_name.image.image.intern
117         cluster := current_type.cluster.find(class_name)
118         if cluster /= Void then
119            parameters := get_parameter_constraints(universe.parse_class(cluster, class_name, pos))
120            create descriptor.make(create {LIBERTY_CLASS_DESCRIPTOR}.make(cluster, class_name, pos), parameters)
121            Result := universe.get_type_from_descriptor(descriptor)
122         end
123      end
124
125   get_parameter_constraints (a_class: LIBERTY_AST_ONE_CLASS): COLLECTION[LIBERTY_TYPE] is
126      local
127         type_parameters: LIBERTY_AST_TYPE_PARAMETERS
128         type_parameter: LIBERTY_AST_TYPE_PARAMETER
129         i: INTEGER
130      do
131         type_parameters := a_class.class_header.type_parameters
132         if type_parameters.is_empty or else type_parameters.list_is_empty then
133            Result := no_parameters
134         else
135            create {FAST_ARRAY[LIBERTY_TYPE]} Result.with_capacity(type_parameters.list_count)
136            from
137               i := type_parameters.list_lower
138            until
139               i > type_parameters.list_upper
140            loop
141               type_parameter := type_parameters.list_item(i)
142               if type_parameter.has_constraint then
143                  Result.add_last(type(type_parameter.constraint))
144               else
145                  Result.add_last(universe.type_any)
146               end
147               i := i + 1
148            end
149            debug
150               log.trace.put_string(once " ***** inferred implicit parameters of ")
151               log.trace.put_string(a_class.class_header.class_name.image.image)
152               log.trace.put_string(once ": ")
153               log.trace.put_line(Result.out)
154               check
155                  Result.count = type_parameters.list_count
156               end
157            end
158         end
159      end
160
161   no_parameters: COLLECTION[LIBERTY_TYPE] is
162      once
163         create {FAST_ARRAY[LIBERTY_TYPE]} Result.with_capacity(0)
164      end
165
166invariant
167   universe /= Void
168   current_type /= Void
169   effective_parameters /= Void
170
171end -- class LIBERTY_TYPE_RESOLVER_IN_TYPE