Exemplo n.º 1
0
    def test_walker_is_complete(self):
        tree_walker = TreeWalker()
        self.assertTrue(tree_walker.is_complete(verbose=True))

        tree_walker.functions = dict((x, tree_walker.walk_skip)
                                     for x in op.ALL_TYPES if x is not op.AND)
        self.assertFalse(tree_walker.is_complete())
Exemplo n.º 2
0
    def __init__(self, stream, env=None):
        TreeWalker.__init__(self, env=env)
        self.stream = stream
        self.write = self.stream.write

        self.set_function(partial(self._walk_nary, " & "), op.AND, op.BV_AND)
        self.set_function(partial(self._walk_nary, " | "), op.OR, op.BV_OR)
        self.set_function(partial(self._walk_nary, " + "), op.PLUS, op.BV_ADD)
        self.set_function(partial(self._walk_nary, " * "), op.TIMES, op.BV_MUL)
        self.set_function(partial(self._walk_nary, " / "), op.DIV)
        self.set_function(partial(self._walk_nary, " ^ "), op.POW)
        self.set_function(partial(self._walk_nary, " <-> "), op.IFF)
        self.set_function(partial(self._walk_nary, " -> "), op.IMPLIES)
        self.set_function(partial(self._walk_nary, " - "), op.MINUS, op.BV_SUB)
        self.set_function(partial(self._walk_nary, " = "), op.EQUALS)
        self.set_function(partial(self._walk_nary, " <= "), op.LE)
        self.set_function(partial(self._walk_nary, " < "), op.LT)

        self.set_function(partial(self._walk_nary, " xor "), op.BV_XOR)
        self.set_function(partial(self._walk_nary, "::"), op.BV_CONCAT)
        self.set_function(partial(self._walk_nary, " u/ "), op.BV_UDIV)
        self.set_function(partial(self._walk_nary, " u% "), op.BV_UREM)
        self.set_function(partial(self._walk_nary, " s/ "), op.BV_SDIV)
        self.set_function(partial(self._walk_nary, " s% "), op.BV_SREM)
        self.set_function(partial(self._walk_nary, " s<= "), op.BV_SLE)
        self.set_function(partial(self._walk_nary, " s< "), op.BV_SLT)
        self.set_function(partial(self._walk_nary, " u<= "), op.BV_ULE)
        self.set_function(partial(self._walk_nary, " u< "), op.BV_ULT)
        self.set_function(partial(self._walk_nary, " << "), op.BV_LSHL)
        self.set_function(partial(self._walk_nary, " >> "), op.BV_LSHR)
        self.set_function(partial(self._walk_nary, " a>> "), op.BV_ASHR)
        self.set_function(partial(self._walk_nary, " bvcomp "), op.BV_COMP)
        self.set_function(self.walk_not, op.BV_NOT)
Exemplo n.º 3
0
    def __init__(self, stream, env=None):
        TreeWalker.__init__(self, env=env)
        self.stream = stream
        self.write = self.stream.write

        self.set_function(partial(self._walk_nary, " & "), op.AND, op.BV_AND)
        self.set_function(partial(self._walk_nary, " | "), op.OR, op.BV_OR)
        self.set_function(partial(self._walk_nary, " + "), op.PLUS, op.BV_ADD)
        self.set_function(partial(self._walk_nary, " * "), op.TIMES, op.BV_MUL)
        self.set_function(partial(self._walk_nary, " / "), op.DIV)
        self.set_function(partial(self._walk_nary, " ^ "), op.POW)
        self.set_function(partial(self._walk_nary, " <-> "), op.IFF)
        self.set_function(partial(self._walk_nary, " -> "), op.IMPLIES)
        self.set_function(partial(self._walk_nary, " - "), op.MINUS, op.BV_SUB)
        self.set_function(partial(self._walk_nary, " = "), op.EQUALS)
        self.set_function(partial(self._walk_nary, " <= "), op.LE)
        self.set_function(partial(self._walk_nary, " < "), op.LT)

        self.set_function(partial(self._walk_nary, " xor "), op.BV_XOR)
        self.set_function(partial(self._walk_nary, "::"), op.BV_CONCAT)
        self.set_function(partial(self._walk_nary, " u/ "), op.BV_UDIV)
        self.set_function(partial(self._walk_nary, " u% "), op.BV_UREM)
        self.set_function(partial(self._walk_nary, " s/ "), op.BV_SDIV)
        self.set_function(partial(self._walk_nary, " s% "), op.BV_SREM)
        self.set_function(partial(self._walk_nary, " s<= "), op.BV_SLE)
        self.set_function(partial(self._walk_nary, " s< "), op.BV_SLT)
        self.set_function(partial(self._walk_nary, " u<= "), op.BV_ULE)
        self.set_function(partial(self._walk_nary, " u< "), op.BV_ULT)
        self.set_function(partial(self._walk_nary, " << "), op.BV_LSHL)
        self.set_function(partial(self._walk_nary, " >> "), op.BV_LSHR)
        self.set_function(partial(self._walk_nary, " a>> "), op.BV_ASHR)
        self.set_function(partial(self._walk_nary, " bvcomp "), op.BV_COMP)
        self.set_function(self.walk_not, op.BV_NOT)
Exemplo n.º 4
0
    def __init__(self, stream):
        TreeWalker.__init__(self)
        self.stream = stream
        self.write = self.stream.write

        self.functions[op.FORALL] = self.walk_forall
        self.functions[op.EXISTS] = self.walk_exists
        self.functions[op.SYMBOL] = self.walk_symbol
        self.functions[op.FUNCTION] = self.walk_function
        self.functions[op.REAL_CONSTANT] = self.walk_real_constant
        self.functions[op.BOOL_CONSTANT] = self.walk_bool_constant
        self.functions[op.INT_CONSTANT] = self.walk_int_constant

        self.functions[op.AND] = partial(self._walk_nary, "and")
        self.functions[op.OR] = partial(self._walk_nary, "or")
        self.functions[op.NOT] = partial(self._walk_nary, "not")
        self.functions[op.IMPLIES] = partial(self._walk_nary, "=>")
        self.functions[op.IFF] = partial(self._walk_nary, "=")
        self.functions[op.PLUS]   = partial(self._walk_nary, "+")
        self.functions[op.MINUS]  = partial(self._walk_nary, "-")
        self.functions[op.TIMES]  = partial(self._walk_nary, "*")
        self.functions[op.EQUALS] = partial(self._walk_nary, "=")
        self.functions[op.LE]     = partial(self._walk_nary, "<=")
        self.functions[op.LT]     = partial(self._walk_nary, "<")
        self.functions[op.ITE]    = partial(self._walk_nary, "ite")
        self.functions[op.TOREAL] = partial(self._walk_nary, "to_real")
Exemplo n.º 5
0
 def __init__(self, stream, annotations=None):
     TreeWalker.__init__(self)
     self.stream = stream
     self.write = self.stream.write
     self.mgr = get_env().formula_manager
     if not annotations:
         self.annotations = Annotations()
     else:
         self.annotations = annotations
Exemplo n.º 6
0
    def test_undefined_node(self):
        varA = Symbol("At", INT)

        dag_walker = DagWalker()
        with self.assertRaises(UnsupportedOperatorError):
            dag_walker.walk(varA)

        tree_walker = TreeWalker()
        with self.assertRaises(UnsupportedOperatorError):
            tree_walker.walk(varA)
Exemplo n.º 7
0
    def test_undefined_node(self):
        varA = Symbol("At", INT)

        dag_walker = DagWalker()
        with self.assertRaises(NotImplementedError):
            dag_walker.walk(varA)

        tree_walker = TreeWalker()
        with self.assertRaises(NotImplementedError):
            tree_walker.walk(varA)
Exemplo n.º 8
0
    def test_undefined_node(self):
        varA = Symbol("At", INT)

        dag_walker = DagWalker()
        with self.assertRaises(UnsupportedOperatorError):
            dag_walker.walk(varA)

        tree_walker = TreeWalker()
        with self.assertRaises(UnsupportedOperatorError):
            tree_walker.walk(varA)
Exemplo n.º 9
0
    def __init__(self, stream):
        TreeWalker.__init__(self)
        self.stream = stream
        self.write = self.stream.write
        self.mgr = get_env().formula_manager

        self.set_function(partial(self._walk_nary, "and"), op.AND)
        self.set_function(partial(self._walk_nary, "or"), op.OR)
        self.set_function(partial(self._walk_nary, "not"), op.NOT)
        self.set_function(partial(self._walk_nary, "=>"), op.IMPLIES)
        self.set_function(partial(self._walk_nary, "="), op.IFF)
        self.set_function(partial(self._walk_nary, "+"), op.PLUS)
        self.set_function(partial(self._walk_nary, "-"), op.MINUS)
        self.set_function(partial(self._walk_nary, "*"), op.TIMES)
        self.set_function(partial(self._walk_nary, "="), op.EQUALS)
        self.set_function(partial(self._walk_nary, "<="), op.LE)
        self.set_function(partial(self._walk_nary, "<"), op.LT)
        self.set_function(partial(self._walk_nary, "ite"), op.ITE)
        self.set_function(partial(self._walk_nary, "to_real"), op.TOREAL)
        self.set_function(partial(self._walk_nary, "/"), op.DIV)
        self.set_function(partial(self._walk_nary, "pow"), op.POW)

        self.set_function(partial(self._walk_nary, "bvand"), op.BV_AND)
        self.set_function(partial(self._walk_nary, "bvor"), op.BV_OR)
        self.set_function(partial(self._walk_nary, "bvnot"), op.BV_NOT)
        self.set_function(partial(self._walk_nary, "bvxor"), op.BV_XOR)
        self.set_function(partial(self._walk_nary, "bvadd"), op.BV_ADD)
        self.set_function(partial(self._walk_nary, "bvsub"), op.BV_SUB)
        self.set_function(partial(self._walk_nary, "bvneg"), op.BV_NEG)
        self.set_function(partial(self._walk_nary, "bvmul"), op.BV_MUL)
        self.set_function(partial(self._walk_nary, "bvudiv"), op.BV_UDIV)
        self.set_function(partial(self._walk_nary, "bvurem"), op.BV_UREM)
        self.set_function(partial(self._walk_nary, "bvshl"), op.BV_LSHL)
        self.set_function(partial(self._walk_nary, "bvlshr"), op.BV_LSHR)
        self.set_function(partial(self._walk_nary, "bvult"), op.BV_ULT)
        self.set_function(partial(self._walk_nary, "bvule"), op.BV_ULE)
        self.set_function(partial(self._walk_nary, "bvslt"), op.BV_SLT)
        self.set_function(partial(self._walk_nary, "bvsle"), op.BV_SLE)
        self.set_function(partial(self._walk_nary, "concat"), op.BV_CONCAT)
        self.set_function(partial(self._walk_nary, "bvcomp"), op.BV_COMP)
        self.set_function(partial(self._walk_nary, "bvashr"), op.BV_ASHR)
        self.set_function(partial(self._walk_nary, "bvsdiv"), op.BV_SDIV)
        self.set_function(partial(self._walk_nary, "bvsrem"), op.BV_SREM)
        self.set_function(self.walk_bv_extract, op.BV_EXTRACT)
        self.set_function(self.walk_bv_rotate, op.BV_ROR)
        self.set_function(self.walk_bv_rotate, op.BV_ROL)
        self.set_function(self.walk_bv_extend, op.BV_ZEXT)
        self.set_function(self.walk_bv_extend, op.BV_SEXT)

        self.set_function(partial(self._walk_nary, "select"), op.ARRAY_SELECT)
        self.set_function(partial(self._walk_nary, "store"), op.ARRAY_STORE)
Exemplo n.º 10
0
 def test_walker_is_complete(self):
     op.ALL_TYPES.append(-1)
     with self.assertRaises(AssertionError):
         TreeWalker()
     op.ALL_TYPES.remove(-1)
Exemplo n.º 11
0
 def __init__(self, stream):
     TreeWalker.__init__(self)
     self.stream = stream
     self.write = self.stream.write
     self.mgr = get_env().formula_manager
Exemplo n.º 12
0
 def __init__(self, stream, env=None):
     TreeWalker.__init__(self, env=env)
     self.stream = stream
     self.write = self.stream.write
Exemplo n.º 13
0
 def __init__(self, stream):
     TreeWalker.__init__(self)
     self.stream = stream
     return
Exemplo n.º 14
0
 def __init__(self, stream, env=None, pretty=False):
     TreeWalker.__init__(self, env=env)
     self.stream = stream
     self.write = self.stream.write
     self.pretty = pretty
Exemplo n.º 15
0
 def __init__(self, stream):
     TreeWalker.__init__(self)
     self.stream = stream
     self.write = self.stream.write
Exemplo n.º 16
0
 def __init__(self, stream):
     TreeWalker.__init__(self)
     self.stream = stream
     self.write = self.stream.write