/src/tools/interpreter/liberty_interpreter_assertion_checker.e

http://github.com/tybor/Liberty · Specman e · 153 lines · 121 code · 18 blank · 14 comment · 8 complexity · 16a6d396352b7c8f9ea880ce68762eb6 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_INTERPRETER_ASSERTION_CHECKER
  16. inherit
  17. LIBERTY_ASSERTION_VISITOR
  18. creation {LIBERTY_INTERPRETER}
  19. make
  20. feature {LIBERTY_INTERPRETER_FEATURE_CALL, LIBERTY_INTERPRETER_INSTRUCTIONS}
  21. validate (contract: LIBERTY_ASSERTIONS; error_message: ABSTRACT_STRING) is
  22. do
  23. failed_tag := Void
  24. if contract /= Void then
  25. contract.accept(Current)
  26. if failed_tag /= Void then
  27. interpreter.fatal_error(error_message + " failed: " + failed_tag, failed_position)
  28. end
  29. end
  30. end
  31. feature {LIBERTY_ASSERTIONS_AND_THEN}
  32. visit_liberty_assertions_and_then (v: LIBERTY_ASSERTIONS_AND_THEN) is
  33. do
  34. v.left.accept(Current)
  35. if failed_tag = Void then
  36. v.right.accept(Current)
  37. end
  38. end
  39. feature {LIBERTY_ASSERTIONS_OR_ELSE}
  40. visit_liberty_assertions_or_else (v: LIBERTY_ASSERTIONS_OR_ELSE) is
  41. local
  42. tag_left: FIXED_STRING
  43. do
  44. v.left.accept(Current)
  45. if failed_tag /= Void then
  46. tag_left := failed_tag
  47. v.right.accept(Current)
  48. if failed_tag /= Void then
  49. failed_tag := tag_left
  50. end
  51. end
  52. end
  53. feature {LIBERTY_CHECK}
  54. visit_liberty_check (v: LIBERTY_CHECK) is
  55. do
  56. check_written_assertions(v)
  57. end
  58. feature {LIBERTY_ENSURE}
  59. visit_liberty_ensure (v: LIBERTY_ENSURE) is
  60. do
  61. check_written_assertions(v)
  62. end
  63. feature {LIBERTY_ENSURE_THEN}
  64. visit_liberty_ensure_then (v: LIBERTY_ENSURE_THEN) is
  65. do
  66. check_written_assertions(v)
  67. end
  68. feature {LIBERTY_INVARIANT}
  69. visit_liberty_invariant (v: LIBERTY_INVARIANT) is
  70. do
  71. check_written_assertions(v)
  72. end
  73. feature {LIBERTY_REQUIRE}
  74. visit_liberty_require (v: LIBERTY_REQUIRE) is
  75. do
  76. check_written_assertions(v)
  77. end
  78. feature {LIBERTY_REQUIRE_ELSE}
  79. visit_liberty_require_else (v: LIBERTY_REQUIRE_ELSE) is
  80. do
  81. check_written_assertions(v)
  82. end
  83. feature {LIBERTY_REQUIRE_THEN}
  84. visit_liberty_require_then (v: LIBERTY_REQUIRE_THEN) is
  85. do
  86. check_written_assertions(v)
  87. end
  88. feature {LIBERTY_VARIANT}
  89. visit_liberty_variant (v: LIBERTY_VARIANT) is
  90. do
  91. check False end
  92. end
  93. feature {}
  94. check_written_assertions (contract: LIBERTY_WRITTEN_ASSERTIONS) is
  95. local
  96. assertions: TRAVERSABLE[LIBERTY_ASSERTION]
  97. assertion: LIBERTY_ASSERTION
  98. assertion_value: LIBERTY_INTERPRETER_OBJECT_NATIVE[BOOLEAN]
  99. i: INTEGER
  100. do
  101. failed_tag := Void
  102. assertions := contract.assertions
  103. if not assertions.is_empty then
  104. interpreter.evaluate_feature_parameters
  105. from
  106. i := assertions.lower
  107. until
  108. failed_tag /= Void or else i > assertions.upper
  109. loop
  110. assertion := assertions.item(i)
  111. assertion.assertion.accept(interpreter.expressions)
  112. assertion_value ::= interpreter.expressions.eval_memory
  113. if not assertion_value.item then
  114. failed_tag := assertion.tag
  115. failed_position := assertion.assertion.position
  116. end
  117. i := i + 1
  118. end
  119. end
  120. end
  121. feature {}
  122. make (a_interpreter: like interpreter) is
  123. require
  124. a_interpreter /= Void
  125. do
  126. interpreter := a_interpreter
  127. ensure
  128. interpreter = a_interpreter
  129. end
  130. interpreter: LIBERTY_INTERPRETER
  131. failed_tag: FIXED_STRING
  132. failed_position: LIBERTY_POSITION
  133. invariant
  134. interpreter /= Void
  135. end -- class LIBERTY_INTERPRETER_ASSERTION_CHECKER