PageRenderTime 23ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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