/src/tools/semantics/types/type_builder/liberty_type_parent_loader.e

http://github.com/tybor/Liberty · Specman e · 121 lines · 95 code · 8 blank · 18 comment · 7 complexity · b81871b2c5b4ee3bd25ea43db7bcdf9d 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_PARENT_LOADER
  16. --
  17. -- Loads the type's parents
  18. --
  19. insert
  20. LIBERTY_TYPE_BUILDER_TOOLS
  21. LOGGING
  22. creation {LIBERTY_TYPE_BUILDER}
  23. make
  24. feature {}
  25. make (a_builder: like builder; a_type: like type; a_universe: like universe; default_effective_generic_parameters: like effective_generic_parameters) is
  26. require
  27. a_builder /= Void
  28. a_type /= Void
  29. a_universe /= Void
  30. do
  31. builder := a_builder
  32. type := a_type
  33. universe := a_universe
  34. effective_generic_parameters := default_effective_generic_parameters
  35. ensure
  36. builder = a_builder
  37. type = a_type
  38. universe = a_universe
  39. effective_generic_parameters = default_effective_generic_parameters
  40. end
  41. universe: LIBERTY_UNIVERSE
  42. feature {LIBERTY_TYPE_BUILDER}
  43. load is
  44. local
  45. ast_class: LIBERTY_AST_ONE_CLASS
  46. has_parents: BOOLEAN
  47. do
  48. ast_class := type.ast
  49. if ast_class.obsolete_clause.count > 0 then
  50. errors.add_position(semantics_position_at(ast_class.obsolete_clause.string))
  51. errors.set(level_warning, decoded_string(ast_class.obsolete_clause.string))
  52. end
  53. if is_any then
  54. torch.burn
  55. else
  56. has_parents := add_parents(ast_class.inherit_clause, True, False)
  57. has_parents := add_parents(ast_class.insert_clause, False, has_parents)
  58. check
  59. has_parents
  60. end
  61. end
  62. end
  63. feature {}
  64. add_parents (parents: LIBERTY_AST_LIST[LIBERTY_AST_PARENT]; conformant, had_parents: BOOLEAN): BOOLEAN is
  65. -- Returns True if at least a parent was added
  66. local
  67. i: INTEGER; parent_clause: LIBERTY_AST_PARENT
  68. parent: LIBERTY_TYPE; actual_parent: LIBERTY_ACTUAL_TYPE
  69. do
  70. if conformant then
  71. log.trace.put_string(once "Adding conformant parents to ")
  72. else
  73. log.trace.put_string(once "Adding non-conformant parents to ")
  74. end
  75. log.trace.put_line(type.full_name)
  76. from
  77. Result := had_parents
  78. i := parents.list_lower
  79. until
  80. errors.has_error or else i > parents.list_upper
  81. loop
  82. parent_clause := parents.list_item(i)
  83. parent := type_lookup.resolver.type(parent_clause.type_definition)
  84. debug
  85. log.trace.put_string(once " ")
  86. log.trace.put_string(type.full_name)
  87. if conformant then
  88. log.trace.put_string(once " --> ")
  89. else
  90. log.trace.put_string(once " -+> ")
  91. end
  92. log.trace.put_line(parent.full_name)
  93. end
  94. if parent /= Void then
  95. check
  96. parent.is_known
  97. end
  98. actual_parent ::= parent.known_type
  99. type.add_parent(actual_parent, conformant)
  100. Result := True
  101. end
  102. i := i + 1
  103. end
  104. if not conformant and then not Result and then not errors.has_error then
  105. debug
  106. log.trace.put_string(type.name)
  107. log.trace.put_line(once ": adding default parent ANY")
  108. end
  109. type.add_parent(universe.type_any, False)
  110. Result := True
  111. end
  112. end
  113. end -- class LIBERTY_TYPE_PARENT_LOADER