Exemple #1
0
    def from_AST(cls, node, factory):
        """Construct from an Enumerator node of form
        
            <vars> in <rel>
        
        Alternatively, the rhs may be a setmatch of a rel, where
        the mask is a lookupmask and the key is a vartuple.
        """
        checktype(node, L.Enumerator)

        lhs = L.get_vartuple(node.target)
        rhs = node.iter

        if L.is_name(rhs):
            rel = L.get_name(rhs)

        elif isinstance(rhs, L.SetMatch) and L.is_vartuple(rhs.key):
            keyvars = L.get_vartuple(rhs.key)
            # Make sure we're dealing with a lookupmask and that the
            # key vars agree with the mask.
            mask = Mask(rhs.mask)
            assert mask.is_lookupmask
            assert mask.lookup_arity == len(keyvars)

            lhs = keyvars + lhs
            rel = L.get_name(rhs.target)

        else:
            raise TypeError

        return cls(lhs, rel)
Exemple #2
0
 def from_comp(cls, node, factory):
     """Construct from Comp node. Requires a ClauseFactory."""
     checktype(node, L.Comp)
     
     join = Join.from_comp(node, factory)
     
     return cls(join, node.resexp, node.params)
Exemple #3
0
 def from_AST(cls, node, factory):
     """Construct from an Enumerator node of form
     
         <vars> in <rel>
     
     Alternatively, the rhs may be a setmatch of a rel, where
     the mask is a lookupmask and the key is a vartuple.
     """
     checktype(node, L.Enumerator)
     
     lhs = L.get_vartuple(node.target)
     rhs = node.iter
     
     if L.is_name(rhs):
         rel = L.get_name(rhs)
     
     elif isinstance(rhs, L.SetMatch) and L.is_vartuple(rhs.key):
         keyvars = L.get_vartuple(rhs.key)
         # Make sure we're dealing with a lookupmask and that the
         # key vars agree with the mask.
         mask = Mask(rhs.mask)
         assert mask.is_lookupmask
         assert mask.lookup_arity == len(keyvars)
         
         lhs = keyvars + lhs
         rel = L.get_name(rhs.target)
     
     else:
         raise TypeError
     
     return cls(lhs, rel)
Exemple #4
0
 def from_comp(cls, node, factory):
     """Construct from Comp node, ignoring the result expression.
     factory is used to construct clauses from their ASTs.
     """
     checktype(node, L.Comp)
     clauses = [factory.from_AST(clast) for clast in node.clauses]
     delta = DeltaInfo.from_options(node.options)
     return cls(clauses, factory, delta)
Exemple #5
0
 def from_comp(cls, node, factory):
     """Construct from Comp node, ignoring the result expression.
     factory is used to construct clauses from their ASTs.
     """
     checktype(node, L.Comp)
     clauses = [factory.from_AST(clast) for clast in node.clauses]
     delta = DeltaInfo.from_options(node.options)
     return cls(clauses, factory, delta)
Exemple #6
0
    def from_AST(cls, node, factory):
        """Construct from Enumerator node of form
        
            <vars> in {<expr>}
        """
        checktype(node, L.Enumerator)

        lhs = L.get_vartuple(node.target)
        val = L.get_singletonset(node.iter)

        return cls(lhs, val)
Exemple #7
0
 def from_AST(cls, node, factory):
     """Construct from Enumerator node of form
     
         <vars> in {<expr>}
     """
     checktype(node, L.Enumerator)
     
     lhs = L.get_vartuple(node.target)
     val = L.get_singletonset(node.iter)
     
     return cls(lhs, val)
Exemple #8
0
 def from_expr(cls, node):
     """Construct from a condition expression of form
     
         <vars> == <rel>
     """
     checktype(node, L.AST)
     
     left, op, val = L.get_cmp(node)
     checktype(op, L.Eq)
     lhs = L.get_vartuple(left)
     
     return cls(lhs, val)
Exemple #9
0
    def from_expr(cls, node):
        """Construct from a condition expression of form
        
            <vars> == <rel>
        """
        checktype(node, L.AST)

        left, op, val = L.get_cmp(node)
        checktype(op, L.Eq)
        lhs = L.get_vartuple(left)

        return cls(lhs, val)
Exemple #10
0
    def from_AST(cls, node, factory):
        """Construct from Enumerator node of form
        
            <vars> in <rel> + {<expr>}
        """
        checktype(node, L.Enumerator)

        rhs, extra = L.get_singadd(node.iter)

        innernode = node._replace(iter=rhs)
        innerclause = factory.from_AST(innernode)

        return cls(innerclause, extra)
Exemple #11
0
 def from_AST(cls, node, factory):
     """Construct from Enumerator node of form
     
         <vars> in <rel> + {<expr>}
     """
     checktype(node, L.Enumerator)
     
     rhs, extra = L.get_singadd(node.iter)
     
     innernode = node._replace(iter=rhs)
     innerclause = factory.from_AST(innernode)
     
     return cls(innerclause, extra)
Exemple #12
0
 def from_expr(cls, node):
     """Construct from a membership condition expression of form
     
         <vars> in <rel>
     
     Note that this is syntactically different from the form used
     in comprehensions, even though their textual representation
     in source code is the same.
     """
     checktype(node, L.AST)
     
     left, op, right = L.get_cmp(node)
     checktype(op, L.In)
     lhs = L.get_vartuple(left)
     rel = L.get_name(right)
     return cls(lhs, rel)
Exemple #13
0
    def from_expr(cls, node):
        """Construct from a membership condition expression of form
        
            <vars> in <rel>
        
        Note that this is syntactically different from the form used
        in comprehensions, even though their textual representation
        in source code is the same.
        """
        checktype(node, L.AST)

        left, op, right = L.get_cmp(node)
        checktype(op, L.In)
        lhs = L.get_vartuple(left)
        rel = L.get_name(right)
        return cls(lhs, rel)
Exemple #14
0
 def from_AST(cls, node, factory):
     """Construct from Enumerator node of form
     
         <vars> in deltamatch(<rel>, <mask>, <val>, <limit>)
     """
     checktype(node, L.Enumerator)
     
     lhs = L.get_vartuple(node.target)
     checktype(node.iter, L.DeltaMatch)
     rel = L.get_name(node.iter.target)
     mask = Mask(node.iter.mask)
     val = node.iter.elem
     limit = node.iter.limit
     if limit not in [0, 1]:
         raise TypeError
     
     inferred_mask = Mask.from_vars(lhs, lhs)
     assert mask == inferred_mask
     
     return cls(lhs, rel, val, limit)
Exemple #15
0
    def from_AST(cls, node, factory):
        """Construct from Enumerator node of form
        
            <vars> in deltamatch(<rel>, <mask>, <val>, <limit>)
        """
        checktype(node, L.Enumerator)

        lhs = L.get_vartuple(node.target)
        checktype(node.iter, L.DeltaMatch)
        rel = L.get_name(node.iter.target)
        mask = Mask(node.iter.mask)
        val = node.iter.elem
        limit = node.iter.limit
        if limit not in [0, 1]:
            raise TypeError

        inferred_mask = Mask.from_vars(lhs, lhs)
        assert mask == inferred_mask

        return cls(lhs, rel, val, limit)
Exemple #16
0
 def from_AST(cls, node, factory):
     """Construct from an Enumerator node of form
     
         var in {<rel>.smlookup(<mask>, <key vars>)}
     
     """
     checktype(node, L.Enumerator)
     
     var = L.get_name(node.target)
     sm = L.get_singletonset(node.iter)
     checktype(sm, L.SMLookup)
     rel = L.get_name(sm.target)
     mask = Mask(sm.mask)
     keyvars = L.get_vartuple(sm.key)
     # Ensure the mask is consistent with how it's used.
     if mask != Mask.from_keylen(len(keyvars)):
         raise TypeError
     
     lhs = keyvars + (var,)
     return cls(lhs, rel)
Exemple #17
0
    def from_AST(cls, node, factory):
        """Construct from an Enumerator node of form
        
            var in {<rel>.smlookup(<mask>, <key vars>)}
        
        """
        checktype(node, L.Enumerator)

        var = L.get_name(node.target)
        sm = L.get_singletonset(node.iter)
        checktype(sm, L.SMLookup)
        rel = L.get_name(sm.target)
        mask = Mask(sm.mask)
        keyvars = L.get_vartuple(sm.key)
        # Ensure the mask is consistent with how it's used.
        if mask != Mask.from_keylen(len(keyvars)):
            raise TypeError

        lhs = keyvars + (var, )
        return cls(lhs, rel)
Exemple #18
0
 def from_AST(cls, node, factory):
     """Construct from expression node."""
     checktype(node, L.expr)
     
     return cls(node)
Exemple #19
0
    def from_AST(cls, node, factory):
        """Construct from expression node."""
        checktype(node, L.expr)

        return cls(node)