/src/tools/semantics/types/utils/liberty_class_descriptor.e

http://github.com/tybor/Liberty · Specman e · 110 lines · 84 code · 12 blank · 14 comment · 3 complexity · a70b7b1fcb2cd9b26246978ba45c022b 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_CLASS_DESCRIPTOR
  16. insert
  17. HASHABLE
  18. create {LIBERTY_UNIVERSE, LIBERTY_TYPE_RESOLVER_IN_TYPE}
  19. make
  20. create {LIBERTY_VOID_TYPE}
  21. make_void
  22. feature {ANY}
  23. cluster: LIBERTY_CLUSTER
  24. name: FIXED_STRING
  25. position: LIBERTY_POSITION
  26. file: FIXED_STRING
  27. hash_code: INTEGER
  28. is_equal (other: like Current): BOOLEAN is
  29. do
  30. Result := name.is_equal(other.name) and then cluster.is_equal(other.cluster)
  31. end
  32. make (a_cluster: like cluster; a_name: like name; a_position: like position) is
  33. require
  34. a_cluster /= Void
  35. a_name /= Void
  36. do
  37. cluster := a_cluster
  38. name := a_name
  39. position := a_position
  40. compute_hash_code
  41. compute_file
  42. ensure
  43. cluster = a_cluster
  44. name = a_name
  45. position = a_position
  46. end
  47. make_void (a_position: like position) is
  48. do
  49. create cluster.make_void
  50. name := "<Void>".intern
  51. position := a_position
  52. file := name
  53. ensure
  54. position = a_position
  55. end
  56. compute_file is
  57. local
  58. n, f: STRING
  59. do
  60. n := once ""
  61. n.clear_count
  62. n.append(name)
  63. n.to_lower
  64. n.append(once ".e")
  65. f := once ""
  66. f.make_from_string(cluster.location_of(name))
  67. dir.compute_file_path_with(f, n)
  68. f.copy(dir.last_entry)
  69. if f.is_empty or else not file_tools.is_file(f) then
  70. std_error.put_string(" *** Unknown class: ")
  71. std_error.put_string(name)
  72. std_error.put_string(" in cluster ")
  73. std_error.put_line(cluster.name)
  74. breakpoint
  75. die_with_code(1)
  76. end
  77. file := f.intern
  78. ensure
  79. file /= Void
  80. end
  81. feature {}
  82. compute_hash_code is
  83. local
  84. h: like hash_code
  85. do
  86. h := name.hash_code #*31 #+ cluster.hash_code
  87. if h < 0 then
  88. h := ~h
  89. end
  90. hash_code := h
  91. end
  92. file_tools: FILE_TOOLS
  93. dir: BASIC_DIRECTORY
  94. invariant
  95. cluster /= Void
  96. name /= Void
  97. file /= Void
  98. end