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