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

http://github.com/tybor/Liberty · Specman e · 138 lines · 105 code · 16 blank · 17 comment · 4 complexity · c60481f87ce7390e664d0e2880155551 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_DELAYED_TYPE_DEFINITION
  16. inherit
  17. LIBERTY_DELAYED_RESOLVER
  18. insert
  19. EIFFEL_NODE_HANDLER
  20. redefine out_in_tagged_out_memory, is_equal
  21. end
  22. creation {LIBERTY_TYPE_RESOLVER, LIBERTY_DELAYED_TYPE_DEFINITION}
  23. make
  24. feature {ANY}
  25. out_in_tagged_out_memory is
  26. do
  27. if can_resolve then
  28. resolved.out_in_tagged_out_memory
  29. else
  30. tagged_out_memory.extend('"')
  31. full_name_memory.out_in_tagged_out_memory
  32. tagged_out_memory.append(once "%" using ")
  33. resolver.out_in_tagged_out_memory
  34. end
  35. end
  36. hash_code: INTEGER is
  37. do
  38. Result := full_name_memory.hash_code
  39. end
  40. is_equal (other: like Current): BOOLEAN is
  41. do
  42. Result := other = Current
  43. end
  44. feature {LIBERTY_DELAYED_TYPE}
  45. can_resolve: BOOLEAN is
  46. do
  47. if type_memory /= Void then
  48. Result := True
  49. else
  50. type_memory ::= resolver.undelayed_type(type_definition)
  51. Result := type_memory /= Void
  52. debug
  53. if Result then
  54. log.trace.put_string(once " >>> Resolved ")
  55. log.trace.put_string(full_name_memory)
  56. log.trace.put_string(once " => ")
  57. log.trace.put_line(type_memory.out)
  58. end
  59. end
  60. end
  61. ensure
  62. Result implies type_memory /= Void
  63. end
  64. resolved: LIBERTY_KNOWN_TYPE is
  65. local
  66. ok: BOOLEAN
  67. do
  68. ok := can_resolve
  69. check
  70. ok
  71. type_memory /= Void
  72. end
  73. Result := type_memory
  74. end
  75. full_name: FIXED_STRING is
  76. do
  77. Result := full_name_memory
  78. end
  79. specialized_in (a_type: LIBERTY_ACTUAL_TYPE): like Current is
  80. local
  81. r: like resolver
  82. do
  83. r := resolver.specialized_in(a_type)
  84. if r = resolver then
  85. Result := Current
  86. else
  87. --|*** TODO: ??? Not sure about that. Maybe we should keep track of the original type to find the
  88. --| good entity (esp. in case of renamings).
  89. --| Then again, maybe the resolver should do that.
  90. create Result.make(type_definition, r)
  91. end
  92. end
  93. feature {}
  94. make (a_type_definition: like type_definition; a_resolver: like resolver) is
  95. require
  96. a_type_definition /= Void
  97. a_resolver /= Void
  98. do
  99. type_definition := a_type_definition
  100. resolver := a_resolver
  101. create_full_name_memory
  102. ensure
  103. type_definition = a_type_definition
  104. resolver = a_resolver
  105. end
  106. type_definition: LIBERTY_AST_TYPE_DEFINITION
  107. resolver: LIBERTY_TYPE_RESOLVER
  108. type_memory: LIBERTY_ACTUAL_TYPE
  109. create_full_name_memory is
  110. do
  111. buffer_stream.clear
  112. type_definition.generate(buffer_stream)
  113. full_name_memory := buffer_stream.to_string.intern
  114. ensure
  115. full_name_memory /= Void
  116. end
  117. buffer_stream: STRING_OUTPUT_STREAM is
  118. once
  119. create Result.make
  120. end
  121. full_name_memory: FIXED_STRING
  122. end -- class LIBERTY_DELAYED_TYPE_DEFINITION