def _cmd_check_sat(self, current, tokens): """(check-sat)""" self.parse_atoms(tokens, current, 0) return SmtLibCommand(current, [])
def test_smtlib_info_quoting(self): cmd = SmtLibCommand(smtcmd.SET_INFO, [":source", "This\nis\nmultiline!"]) output = cmd.serialize_to_string() self.assertEqual(output, "(set-info :source |This\nis\nmultiline!|)")
def _cmd_set_option(self, current, tokens): """(set-option <option>)""" elements = self.parse_atoms(tokens, current, 2) return SmtLibCommand(current, elements)
def get_command(self, tokens): """Builds an SmtLibCommand instance out of a parsed term.""" while True: self.consume_opening(tokens, "<main>") current = next(tokens) if current in [smtcmd.SET_INFO, smtcmd.SET_OPTION]: elements = self.parse_atoms(tokens, current, 2) yield SmtLibCommand(current, elements) elif current == smtcmd.ASSERT: expr = self.get_expression(tokens) self.consume_closing(tokens, current) yield SmtLibCommand(current, [expr]) elif current == smtcmd.CHECK_SAT: self.parse_atoms(tokens, current, 0) yield SmtLibCommand(current, []) elif current == smtcmd.PUSH: elements = self.parse_atoms(tokens, current, 0, 1) levels = 1 if len(elements) > 0: levels = int(elements[0]) yield SmtLibCommand(current, [levels]) elif current == smtcmd.POP: elements = self.parse_atoms(tokens, current, 0, 1) levels = 1 if len(elements) > 0: levels = int(elements[0]) yield SmtLibCommand(current, [levels]) elif current == smtcmd.EXIT: self.parse_atoms(tokens, current, 0) yield SmtLibCommand(current, []) elif current == smtcmd.SET_LOGIC: elements = self.parse_atoms(tokens, current, 1) name = elements[0] try: self.logic = get_logic_by_name(name) yield SmtLibCommand(current, [self.logic]) except UndefinedLogicError: warn("Unknown logic '" + name + \ "'. Ignoring set-logic command.") yield SmtLibCommand(current, [None]) elif current == smtcmd.DECLARE_CONST: elements = self.parse_atoms(tokens, current, 2) (var, typename) = elements v = self._get_var(var, typename) self.cache.bind(var, v) yield SmtLibCommand(current, [v]) elif current == smtcmd.GET_VALUE: params = self.parse_expr_list(tokens, current) self.consume_closing(tokens, current) yield SmtLibCommand(current, params) elif current == smtcmd.DECLARE_FUN: var = self.parse_atom(tokens, current) params = self.parse_params(tokens, current) typename = self.parse_atom(tokens, current) self.consume_closing(tokens, current) v = self._get_var(var, typename, params) if v.symbol_type().is_function_type(): self.cache.bind(var, \ functools.partial(self._function_call_helper, v)) else: self.cache.bind(var, v) yield SmtLibCommand(current, [v]) elif current == smtcmd.DEFINE_FUN: var = self.parse_atom(tokens, current) params = self.parse_params(tokens, current) typename = self.parse_atom(tokens, current) ebody = self.get_expression(tokens) self.consume_closing(tokens, current) formal = [] for k in params: (x, t) = k[0], k[1] v = self._get_var(x, t) self.cache.bind(x, v) formal.append(v) for x in formal: self.cache.unbind(x.symbol_name()) self.cache.define(var, formal, ebody) yield SmtLibCommand(current, [var, formal, ebody]) else: raise UnknownSmtLibCommandError(current)
def print_script_command_line(cout, name, args): script = SmtLibScript() script.add_command(SmtLibCommand(name=name, args=args)) script.serialize(cout, daggify=False)
def _cmd_echo(self, current, tokens): """(echo <string>)""" elements = self.parse_atoms(tokens, current, 1) return SmtLibCommand(current, elements)
def _cmd_get_unsat_assumptions(self, current, tokens): """(get-unsat-assumptions)""" self.parse_atoms(tokens, current, 0) return SmtLibCommand(current, [])
def push(self, levels=1): self._send_silent_command(SmtLibCommand(smtcmd.PUSH, [levels]))
def pop(self, levels=1): self._send_silent_command(SmtLibCommand(smtcmd.POP, [levels]))
def _declare_variable(self, symbol): cmd = SmtLibCommand(smtcmd.DECLARE_FUN, [symbol]) self._send_silent_command(cmd) self.declared_vars.add(symbol)
def reset_assertions(self): self._send_silent_command(SmtLibCommand(smtcmd.RESET_ASSERTIONS, [])) return
def set_logic(self, logic): self._send_silent_command(SmtLibCommand(smtcmd.SET_LOGIC, [logic]))
def set_option(self, name, value): self._send_silent_command( SmtLibCommand(smtcmd.SET_OPTION, [name, value]))
def _declare_sort(self, sort): cmd = SmtLibCommand(smtcmd.DECLARE_SORT, [sort]) self._send_silent_command(cmd) self.declared_sorts.add(sort)
def add_assertion(self, formula, named=None): deps = formula.get_free_variables() for d in deps: if d not in self.declared_vars: self._declare_variable(d) self._send_command(SmtLibCommand(smtcmd.ASSERT, [formula]))
def get_value(self, item): self._send_command(SmtLibCommand(smtcmd.GET_VALUE, [item])) lst = self._get_value_answer() assert len(lst) == 1 assert len(lst[0]) == 2 return lst[0][1]
def _cmd_check_sat_assuming(self, current, tokens): """(check-sat-assuming (<prop_literal>*) ) """ params = self.parse_expr_list(tokens, current) self.consume_closing(tokens, current) return SmtLibCommand(current, params)
def _cmd_exit(self, current, tokens): """(exit)""" self.parse_atoms(tokens, current, 0) return SmtLibCommand(current, [])
def _cmd_get_assignment(self, current, tokens): """(get-assignment)""" self.parse_atoms(tokens, current, 0) return SmtLibCommand(current, [])
def _cmd_get_value(self, current, tokens): """(get-value (<term>+)""" params = self.parse_expr_list(tokens, current) self.consume_closing(tokens, current) return SmtLibCommand(current, params)
def _cmd_reset_assertions(self, current, tokens): """(reset-assertions)""" self.parse_atoms(tokens, current, 0) return SmtLibCommand(current, [])
def _cmd_get_info(self, current, tokens): """(get-info <info_flag>)""" keyword = self.parse_atoms(tokens, current, 1) return SmtLibCommand(current, keyword)
def add_var(script, a, type): var = Symbol(a, type) c = SmtLibCommand(name='declare-fun', args=(var, )) script.commands.insert(1, c)
def _cmd_get_model(self, current, tokens): """(get-model)""" self.parse_atoms(tokens, current, 0) return SmtLibCommand(current, [])
def _cmd_get_option(self, current, tokens): """(get-option <keyword>)""" keyword = self.parse_atoms(tokens, current, 1) return SmtLibCommand(current, keyword)
def _cmd_set_info(self, current, tokens): """(set-info <attribute>)""" elements = self.parse_atoms(tokens, current, 2) return SmtLibCommand(current, elements)
def _cmd_get_proof(self, current, tokens): """(get-proof)""" self.parse_atoms(tokens, current, 0) return SmtLibCommand(current, [])
def _cmd_assert(self, current, tokens): """(assert <term>)""" expr = self.get_expression(tokens) self.consume_closing(tokens, current) return SmtLibCommand(current, [expr])
def _cmd_get_unsat_core(self, current, tokens): """(get-unsat-core)""" self.parse_atoms(tokens, current, 0) return SmtLibCommand(current, [])
def test_smtlib_info_quoting(self): cmd = SmtLibCommand(smtcmd.SET_INFO, [":source", "This\nis\nmultiline!"]) outstream = cStringIO() cmd.serialize(outstream) output = outstream.getvalue() self.assertEqual(output, "(set-info :source |This\nis\nmultiline!|)")
def exit(self): self._send_command(SmtLibCommand(smtcmd.EXIT, [])) self.solver_stdin.close() self.solver_stdout.close() self.solver.terminate() return