Пример #1
0
    def visit_RelUpdate(self, node):
        if not isinstance(node.op, (L.SetAdd, L.SetRemove)):
            return node

        code = (node, )

        auxmaps = self.auxmaps_by_rel.get(node.rel, set())
        for auxmap in auxmaps:
            func_name = auxmap.get_maint_func_name(node.op)
            call_code = (L.Expr(L.Call(func_name, [L.Name(node.elem)])), )
            code = L.insert_rel_maint(code, call_code, node.op)

        wraps = self.wraps_by_rel.get(node.rel, set())
        for wrap in wraps:
            func_name = wrap.get_maint_func_name(node.op)
            call_code = (L.Expr(L.Call(func_name, [L.Name(node.elem)])), )
            code = L.insert_rel_maint(code, call_code, node.op)

        return code
Пример #2
0
    def visit_MapDelete(self, node):
        sfm = self.setfrommaps_by_map.get(node.map, None)
        if sfm is None:
            return node

        code = (node, )
        func_name = sfm.get_maint_func_name('delete')
        call_code = (L.Expr(L.Call(func_name, [L.Name(node.key)])), )
        code = L.insert_rel_maint(code, call_code, L.SetRemove())
        return code
Пример #3
0
    def visit_MapAssign(self, node):
        sfm = self.setfrommaps_by_map.get(node.map, None)
        if sfm is None:
            return node

        code = (node, )
        func_name = sfm.get_maint_func_name('assign')
        call_code = (L.Expr(
            L.Call(func_name,
                   [L.Name(node.key), L.Name(node.value)])), )
        code = L.insert_rel_maint(code, call_code, L.SetAdd())
        return code
Пример #4
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
Пример #5
0
    def add_demand_function_call(self, query_sym, query_node, ann):
        """Return a Query node wrapped with a call to a demand function,
        if needed.
        """
        # Skip if there's no demand set associated with this query.
        if query_sym.name not in self.queries_with_usets:
            return query_node
        # Skip if we have a nodemand annotation.
        if ann is not None and ann.get('nodemand', False):
            return query_node

        demand_call = L.Call(N.get_query_demand_func_name(query_sym.name),
                             [L.tuplify(query_sym.demand_params)])
        return L.FirstThen(demand_call, query_node)
Пример #6
0
 def rewrite_aggr(self, symbol, name, aggr):
     # Only operate on min and max nodes.
     if isinstance(aggr.op, L.Min):
         func = 'min2'
     elif isinstance(aggr.op, L.Max):
         func = 'max2'
     else:
         return
     
     parts = L.get_setunion(aggr.value)
     if len(parts) <= 1:
         return
     multiple_queries = \
         len([p for p in parts if not isinstance(p, L.Set)]) > 1
     
     i = 2
     done_first_query = False
     new_parts = []
     for p in parts:
         if isinstance(p, L.Set):
             # Flatten the literal elements as arguments to
             # min2/max2.
             new_parts.extend(p.elts)
         else:
             new_query_node = aggr._replace(value=p)
             if done_first_query:
                 # Create a new query symbol and node for this
                 # non-literal argument.
                 new_name = name + '_aggrop' + str(i)
                 i += 1
                 new_parts.append(L.Query(new_name, new_query_node,
                                          None))
                 symtab.define_query(new_name, node=new_query_node,
                                     impl=symbol.impl)
             else:
                 # Push the Query node down to the first non-literal
                 # argument.
                 new_parts.append(L.Query(name, new_query_node, None))
                 symbol.node = new_query_node
                 done_first_query = True
     
     return L.Call(func, new_parts)
Пример #7
0
 def rewrite_comp(self, symbol, name, comp):
     if name == query.name:
         return L.Call(func_name, [L.Name(p) for p in query.params])