def make_comp_maint_func(clausetools, fresh_var_prefix, fresh_join_names, comp, result_var, rel, op, *, counted): """Make maintenance function for a comprehension.""" assert isinstance(op, (L.SetAdd, L.SetRemove)) op_name = L.set_update_name(op) func_name = N.get_maint_func_name(result_var, rel, op_name) update = L.RelUpdate(rel, op, '_elem') code = clausetools.get_maint_code(fresh_var_prefix, fresh_join_names, comp, result_var, update, counted=counted) func = L.Parser.ps(''' def _FUNC(_elem): _CODE ''', subst={ '_FUNC': func_name, '<c>_CODE': code }) return func
def visit_RelUpdate(self, node): if not isinstance(node.op, (L.SetAdd, L.SetRemove)): return node if node.rel not in self.rels: return node op_name = L.set_update_name(node.op) func_name = N.get_maint_func_name(self.result_var, node.rel, op_name) code = (node, ) call_code = (L.Expr(L.Call(func_name, [L.Name(node.elem)])), ) code = L.insert_rel_maint(code, call_code, node.op) return code
def visit_RelUpdate(self, node): if not isinstance(node.op, (L.SetAdd, L.SetRemove)): return node if node.rel not in self.rels: return node op_name = L.set_update_name(node.op) func_name = N.get_maint_func_name(self.result_var, node.rel, op_name) code = (node,) call_code = (L.Expr(L.Call(func_name, [L.Name(node.elem)])),) code = L.insert_rel_maint(code, call_code, node.op) return code
def make_comp_maint_func(clausetools, fresh_var_prefix, fresh_join_names, comp, result_var, rel, op, *, counted): """Make maintenance function for a comprehension.""" assert isinstance(op, (L.SetAdd, L.SetRemove)) op_name = L.set_update_name(op) func_name = N.get_maint_func_name(result_var, rel, op_name) update = L.RelUpdate(rel, op, '_elem') code = clausetools.get_maint_code(fresh_var_prefix, fresh_join_names, comp, result_var, update, counted=counted) func = L.Parser.ps(''' def _FUNC(_elem): _CODE ''', subst={'_FUNC': func_name, '<c>_CODE': code}) return func
def get_maint_func_name(self, op): op_name = L.set_update_name(op) return N.get_maint_func_name(self.rel, self.oper, op_name)
def get_maint_func_name(self, op): assert op in ['assign', 'delete'] return N.get_maint_func_name(self.rel, self.map, op)
def get_restr_maint_func_name(self, op): assert self.uses_demand op_name = L.set_update_name(op) return N.get_maint_func_name(self.map, self.restr, op_name)