/src/tools/semantics/types/conformance_checker/liberty_agent_conformance_checker.e

http://github.com/tybor/Liberty · Specman e · 84 lines · 61 code · 8 blank · 15 comment · 4 complexity · 3e1c6ad89b61133329072b9c246a96a2 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_AGENT_CONFORMANCE_CHECKER
  16. inherit
  17. LIBERTY_GENERICS_CONFORMANCE_CHECKER
  18. undefine
  19. is_equal
  20. end
  21. insert
  22. SINGLETON
  23. creation {LIBERTY_UNIVERSE}
  24. make
  25. feature {LIBERTY_ACTUAL_TYPE}
  26. inherits (parent, child: LIBERTY_KNOWN_TYPE): BOOLEAN is
  27. do
  28. Result := check_inheritance(parent, child, True)
  29. end
  30. inserts (parent, child: LIBERTY_KNOWN_TYPE): BOOLEAN is
  31. do
  32. Result := check_inheritance(parent, child, False)
  33. end
  34. feature {}
  35. check_inheritance (parent, child: LIBERTY_KNOWN_TYPE; conformance: BOOLEAN): BOOLEAN is
  36. local
  37. i: INTEGER
  38. do
  39. check
  40. parent.parameters.lower = child.parameters.lower
  41. not parent.parameters.is_empty
  42. not child.parameters.is_empty
  43. end
  44. Result := parent.parameters.count = child.parameters.count
  45. if Result then
  46. check
  47. -- parent.parameters.first and child.parameters.first both are tuples
  48. end
  49. if conformance then
  50. Result := parent.parameters.first.known_type.is_conform_to(child.parameters.first.known_type)
  51. else
  52. Result := parent.parameters.first.known_type.is_non_conformant_child_of(child.parameters.first.known_type)
  53. end
  54. from
  55. i := parent.parameters.lower + 1
  56. until
  57. not Result or else i > parent.parameters.upper
  58. loop
  59. check
  60. parent.parameters.item(i).is_known
  61. child.parameters.item(i).is_known
  62. end
  63. if conformance then
  64. Result := child.parameters.item(i).known_type.is_conform_to(parent.parameters.item(i).known_type)
  65. else
  66. Result := child.parameters.item(i).known_type.is_non_conformant_child_of(parent.parameters.item(i).known_type)
  67. end
  68. i := i + 1
  69. end
  70. end
  71. end
  72. feature {}
  73. make is
  74. do
  75. end
  76. end -- class LIBERTY_AGENT_CONFORMANCE_CHECKER