Esempio n. 1
0
 def analyze(self, cond, before_analysis: PartitionState) -> PartitionState:
     if has_side_effects(cond):
         return before_analysis.copy().separate_all()
     else:
         self._neg = False
         self._analysis = before_analysis.copy()
         self.visit(cond)
         return self._analysis
Esempio n. 2
0
def _recursive_update(lhs, rhs, analysis: PartitionState, merge: bool):
    if isinstance(lhs, TupleExpr) and isinstance(rhs, TupleExpr):
        for l, r in zip(lhs.elements, rhs.elements):
            _recursive_update(l, r, analysis, merge)
    else:
        lhs = lhs.privacy_annotation_label()
        rhs = rhs.privacy_annotation_label()
        if lhs and rhs:
            if merge:
                analysis.merge(lhs, rhs)
            else:
                analysis.move_to(lhs, rhs)
Esempio n. 3
0
    def test_remove(self):
        s = PartitionState()

        for i in range(10):
            s.insert(i)

        for i in range(9):
            s.merge(i, i + 1)

        for i in range(5, 10):
            s.remove(i)

        for i in range(5):
            self.assertTrue(s.same_partition(0, i))
Esempio n. 4
0
 def visitConstructorOrFunctionDefinition(
         self, ast: ConstructorOrFunctionDefinition):
     s: PartitionState[PrivacyLabelExpr] = PartitionState()
     s.insert(MeExpr().privacy_annotation_label())
     s.insert(AllExpr().privacy_annotation_label())
     for d in ast.parent.state_variable_declarations:
         s.insert(d.idf)
     for p in ast.parameters:
         s.insert(p.idf)
     ast.body.before_analysis = s
     return self.visit(ast.body)
Esempio n. 5
0
    def test_merge_indirect(self):
        s = PartitionState()

        for i in range(10):
            s.insert(i)

        for i in range(9):
            s.merge(i, i + 1)

        for i in range(10):
            self.assertTrue(s.same_partition(0, i))
Esempio n. 6
0
    def test_merge(self):
        s = PartitionState()

        for i in range(10):
            s.insert(i)

        for i in range(5):
            s.merge(i, i + 5)

        for i in range(5):
            self.assertTrue(s.same_partition(i, i + 5))
Esempio n. 7
0
    def test_same_partition(self):
        s = PartitionState()

        for i in range(10):
            s.insert(i)

        self.assertTrue(s.same_partition(0, 0))

        for i in range(1, 10):
            self.assertFalse(s.same_partition(0, i))
Esempio n. 8
0
    def test_move_to(self):
        s = PartitionState()

        for i in range(10):
            s.insert(i)

        for i in range(5):
            s.merge(0, i)

        for i in range(5, 10):
            s.merge(5, i)

        s.move_to(0, 5)

        for i in range(1, 5):
            self.assertTrue(s.same_partition(1, i))

        for i in range(5, 10):
            self.assertTrue(s.same_partition(0, i))
Esempio n. 9
0
 def test_self_merge(self):
     s = PartitionState()
     s.insert(0)
     s.merge(0, 0)
     self.assertTrue(s.same_partition(0, 0))