示例#1
0
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
示例#2
0
    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
示例#3
0
 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
示例#4
0
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
示例#5
0
 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)
示例#6
0
 def get_maint_func_name(self, op):
     assert op in ['assign', 'delete']
     return N.get_maint_func_name(self.rel, self.map, op)
示例#7
0
 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)
示例#8
0
 def get_maint_func_name(self, op):
     assert op in ['assign', 'delete']
     return N.get_maint_func_name(self.rel, self.map, op)
示例#9
0
 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)
示例#10
0
 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)