Example #1
0
    def test_annotations(self):
        x = Symbol('x')
        x_next = Symbol('x.next')
        f = Iff(x, Not(x_next))

        ann = Annotations()
        ann.add(x, 'next', x_next.symbol_name())
        ann.add(f, 'trans', 'true')
        ann.add(x, 'init', 'true')

        tree_buf = StringIO()
        dag_buf = StringIO()
        tree_printer = SmtPrinter(tree_buf, annotations=ann)
        dag_printer = SmtDagPrinter(dag_buf, annotations=ann)

        dag_printer.printer(f)
        tree_printer.printer(f)

        self.assertEqual(
            tree_buf.getvalue(),
            "(! (= (! x :next x.next :init true) (not x.next)) :trans true)")
        self.assertEqual(
            dag_buf.getvalue(),
            "(let ((.def_0 (not x.next))) (let ((.def_1 (= (! x :next x.next :init true) .def_0))) (! .def_1 :trans true)))"
        )
Example #2
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
    def test_remove_value(self):
        ann = Annotations()
        a = Symbol("a")
        next_a = Symbol("next(a)")
        init_a = Symbol("init(a)")

        ann.add(a, "next", next_a)
        ann.add(a, "init", init_a)
        ann.add(a, "related", next_a)
        ann.add(a, "related", init_a)

        self.assertNotEqual(
            ann.annotations(a)["init"],
            ann.annotations(a)["related"])
        ann.remove_value(a, "related", next_a)
        self.assertEqual(
            ann.annotations(a)["related"],
            ann.annotations(a)["init"])
    def test_basic(self):
        ann = Annotations()
        a = Symbol("a")
        next_a = Symbol("next(a)")
        init_a = Symbol("init(a)")

        ann.add(a, "next", next_a)
        ann.add(a, "init", init_a)
        ann.add(a, "related", next_a)
        ann.add(a, "related", init_a)

        self.assertIn(a, ann)
        self.assertEqual(set([next_a]), ann.annotations(a)["next"])
        self.assertEqual(set([init_a]), ann.annotations(a)["init"])
        self.assertEqual(set([init_a, next_a]), ann.annotations(a)["related"])
        self.assertEqual(set([a]), ann.all_annotated_formulae("next"))
        self.assertEqual(set([a]), ann.all_annotated_formulae("init"))
        self.assertEqual(set([a]), ann.all_annotated_formulae("related"))
        self.assertEqual(set(), ann.all_annotated_formulae("non-existent"))
    def test_remove(self):
        ann = Annotations()
        a = Symbol("a")
        next_a = Symbol("next(a)")
        init_a = Symbol("init(a)")

        ann.add(a, "next", next_a)
        ann.add(a, "init", init_a)
        ann.add(a, "related", next_a)
        ann.add(a, "related", init_a)

        self.assertIn(a, ann)
        ann.remove(a)
        self.assertNotIn(a, ann)

        self.assertEqual(None, ann.annotations(a))
        self.assertEqual(set([]), ann.all_annotated_formulae("next"))
        self.assertEqual(set([]), ann.all_annotated_formulae("init"))
        self.assertEqual(set([]), ann.all_annotated_formulae("related"))
        self.assertEqual(set(), ann.all_annotated_formulae("non-existent"))
Example #6
0
 def __init__(self):
     self.keys = {}
     self.definitions = {}
     self.annotations = Annotations()