Пример #1
0
    def visit_Member(self, node):
        # For clauses that wrap around another clause, like
        # WithoutMember, reorient the target and iter before recursing.
        handled = False

        # <target> in <expr> - {<elem>}
        if (isinstance(node.iter, L.BinOp) and isinstance(node.iter.op, L.Sub)
                and isinstance(node.iter.right, L.Set)
                and len(node.iter.right.elts) == 1):
            inner_clause = L.Member(node.target, node.iter.left)
            node = L.WithoutMember(inner_clause, node.iter.right.elts[0])
            handled = True

        node = self.generic_visit(node)
        if handled:
            return node

        # <vars> in {<elem>}
        if (L.is_tuple_of_names(node.target) and isinstance(node.iter, L.Set)
                and len(node.iter.elts) == 1):
            return L.SingMember(L.detuplify(node.target), node.iter.elts[0])

        return node
Пример #2
0
 def process(cl):
     if (isinstance(cl, L.Cond) and isinstance(cl.cond, L.Compare)
             and isinstance(cl.cond.op, L.In)):
         cl = L.Member(cl.cond.left, cl.cond.right)
         return cl, [], []
Пример #3
0
 def visit_RelMember(self, node):
     return L.Member(L.tuplify(node.vars), L.Name(node.rel))
Пример #4
0
    def visit_VarsMember(self, node):
        node = self.generic_visit(node)

        return L.Member(L.tuplify(node.vars), node.iter)
Пример #5
0
    def visit_WithoutMember(self, node):
        node = self.generic_visit(node)

        new_iter = L.BinOp(node.cl.iter, L.Sub(), L.Set([node.value]))
        return L.Member(node.cl.target, new_iter)
Пример #6
0
    def visit_SingMember(self, node):
        node = self.generic_visit(node)

        return L.Member(L.tuplify(node.vars), L.Set([node.value]))