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
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, [], []
def visit_RelMember(self, node): return L.Member(L.tuplify(node.vars), L.Name(node.rel))
def visit_VarsMember(self, node): node = self.generic_visit(node) return L.Member(L.tuplify(node.vars), node.iter)
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)
def visit_SingMember(self, node): node = self.generic_visit(node) return L.Member(L.tuplify(node.vars), L.Set([node.value]))