/src/tools/semantics/types/liberty_type_resolver.e

http://github.com/tybor/Liberty · Specman e · 134 lines · 96 code · 16 blank · 22 comment · 7 complexity · a4fbcf62a16225aef0b49e7b970788cd 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. deferred class LIBERTY_TYPE_RESOLVER
  16. insert
  17. LIBERTY_AST_HANDLER
  18. undefine out_in_tagged_out_memory
  19. end
  20. LOGGING
  21. undefine out_in_tagged_out_memory
  22. end
  23. feature {ANY}
  24. parent: LIBERTY_TYPE_RESOLVER
  25. type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
  26. -- Try to find a class using the resolver context. Depending on the resolver, anchors may be resolved
  27. -- or not.
  28. do
  29. Result := undelayed_type(type_definition)
  30. if Result = Void then
  31. Result := delayed_type(type_definition)
  32. end
  33. end
  34. export_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
  35. -- More lenient version, reserved for exports. If the class is not found and is not used anywhere but
  36. -- in export clauses then there will not be any error (a dummy object will be returned).
  37. require
  38. not type_definition.is_anchor
  39. do
  40. Result := lookup_export_type(type_definition)
  41. if Result = Void and then parent /= Void then
  42. Result := parent.export_type(type_definition)
  43. end
  44. if Result = Void then
  45. create {LIBERTY_UNKNOWN_TYPE} Result.make(type_definition.type_name.image.image.intern)
  46. end
  47. ensure
  48. Result /= Void
  49. end
  50. position (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_POSITION is
  51. -- Try to find the position of the type definition. Useful for error reporting.
  52. do
  53. Result := lookup_position(type_definition)
  54. if Result = Void and then parent /= Void then
  55. Result := parent.position(type_definition)
  56. end
  57. if Result = Void then
  58. Result := errors.unknown_position
  59. end
  60. ensure
  61. Result /= Void
  62. end
  63. specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
  64. require
  65. a_type /= Void
  66. deferred
  67. ensure
  68. Result /= Void
  69. end
  70. feature {LIBERTY_DELAYED_TYPE_DEFINITION, LIBERTY_TYPE_RESOLVER}
  71. undelayed_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
  72. do
  73. Result := lookup_type(type_definition)
  74. if Result = Void and then parent /= Void then
  75. Result := parent.undelayed_type(type_definition)
  76. end
  77. end
  78. feature {LIBERTY_UNIVERSE, LIBERTY_DELAYED_TYPE}
  79. delayed_types: COLLECTION[LIBERTY_DELAYED_TYPE] is
  80. once
  81. create {RING_ARRAY[LIBERTY_DELAYED_TYPE]} Result.with_capacity(1024, 0)
  82. end
  83. feature {}
  84. delayed_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_DELAYED_TYPE is
  85. do
  86. create Result.make(create {LIBERTY_DELAYED_TYPE_DEFINITION}.make(type_definition, Current))
  87. end
  88. feature {LIBERTY_TYPE_LOOKUP}
  89. set_parent (a_parent: like parent) is
  90. require
  91. dont_change_parent: parent = Void or else parent = a_parent
  92. do
  93. parent := a_parent
  94. ensure
  95. parent = a_parent
  96. end
  97. feature {}
  98. lookup_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
  99. -- May be Void if the type is not resolved.
  100. require
  101. type_definition /= Void
  102. deferred
  103. end
  104. lookup_export_type (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_TYPE is
  105. -- May be Void if the type is not resolved.
  106. require
  107. not type_definition.is_anchor
  108. deferred
  109. end
  110. lookup_position (type_definition: LIBERTY_AST_TYPE_DEFINITION): LIBERTY_POSITION is
  111. -- May be Void if the position cannot be calculated.
  112. deferred
  113. end
  114. feature {}
  115. errors: LIBERTY_ERRORS
  116. invariant
  117. delayed_types /= Void
  118. end -- class LIBERTY_TYPE_RESOLVER