Exemple #1
0
    def visit_BinaryExpression(self, expr, **kwargs):
        lhst = self.visit(expr.lhs, **kwargs)
        if not protocol.isa(lhst, expr.type_signature[0]):
            raise errors.EfilterTypeError(query=self.query, root=expr.lhs,
                                          expected=expr.type_signature[0],
                                          actual=lhst)

        rhst = self.visit(expr.rhs, **kwargs)
        if not protocol.isa(rhst, expr.type_signature[1]):
            raise errors.EfilterTypeError(query=self.query, root=expr.rhs,
                                          expected=expr.type_signature[1],
                                          actual=rhst)

        return expr.return_signature
Exemple #2
0
def validate(expr, scope):
    lhs_type = infer_type.infer_type(expr.lhs, scope)
    if not (lhs_type is protocol.AnyType
            or protocol.isa(lhs_type, expr.type_signature[0])):
        raise errors.EfilterTypeError(root=expr.lhs,
                                      expected=expr.type_signature[0],
                                      actual=lhs_type)

    rhs_type = infer_type.infer_type(expr.rhs, scope)
    if not (lhs_type is protocol.AnyType
            or protocol.isa(rhs_type, expr.type_signature[1])):
        raise errors.EfilterTypeError(root=expr.rhs,
                                      expected=expr.type_signature[1],
                                      actual=rhs_type)

    return True
Exemple #3
0
def validate(expr, scope):
    lhs_type = infer_type.infer_type(expr.lhs, scope)
    if not (lhs_type is protocol.AnyType
            or protocol.isa(lhs_type, expr.type_signature[0])):
        raise errors.EfilterTypeError(root=expr.lhs,
                                      expected=expr.type_signature[0],
                                      actual=lhs_type)

    rhs_type = infer_type.infer_type(expr.rhs, scope)
    if not (lhs_type is protocol.AnyType
            or protocol.isa(rhs_type, expr.type_signature[1])):
        raise errors.EfilterTypeError(root=expr.rhs,
                                      expected=expr.type_signature[1],
                                      actual=rhs_type)

    return True
Exemple #4
0
    def visit_LetAny(self, expr, **kwargs):
        t = self.visit_Let(expr, **kwargs)
        if not protocol.isa(t, boolean.IBoolean):
            raise errors.EfilterTypeError(query=self.query, root=expr,
                                          actual=t,
                                          expected=associative.IBoolean)

        return boolean.IBoolean
Exemple #5
0
def validate(expr, scope):
    t = infer_type.infer_type(expr.value, scope)
    if not protocol.isa(t, boolean.IBoolean):
        raise errors.EfilterTypeError(root=expr,
                                      actual=t,
                                      expected=boolean.IBoolean)

    return True
Exemple #6
0
def validate(expr, scope):
    t = infer_type.infer_type(expr.value, scope)
    if not protocol.isa(t, boolean.IBoolean):
        raise errors.EfilterTypeError(root=expr,
                                      actual=t,
                                      expected=boolean.IBoolean)

    return True
Exemple #7
0
    def visit_Let(self, expr, scope=None, **kwargs):
        t = self.visit(expr.context, scope=scope, **kwargs)
        if not (t is protocol.AnyType
                or protocol.isa(t, associative.IAssociative)):
            raise errors.EfilterTypeError(query=self.query, root=expr,
                                          actual=t,
                                          expected=associative.IAssociative)

        return self.visit(expr.expression, scope=t, **kwargs)
Exemple #8
0
    def visit_VariadicExpression(self, expr, **kwargs):
        for subexpr in expr.children:
            t = self.visit(subexpr, **kwargs)
            if not protocol.isa(t, expr.type_signature):
                raise errors.EfilterTypeError(query=self.query,
                                              root=subexpr,
                                              expected=expr.type_signature,
                                              actual=t)

        return expr.return_signature
Exemple #9
0
def validate(expr, scope):
    for subexpr in expr.children:
        validate(subexpr, scope)

        t = infer_type.infer_type(subexpr, scope)
        if not (t is protocol.AnyType or protocol.isa(t, expr.type_signature)):
            raise errors.EfilterTypeError(root=subexpr,
                                          expected=expr.type_signature,
                                          actual=t)

    return True
Exemple #10
0
def validate(expr, scope):
    for subexpr in expr.children:
        validate(subexpr, scope)

        t = infer_type.infer_type(subexpr, scope)
        if not (t is protocol.AnyType
                or protocol.isa(t, expr.type_signature)):
            raise errors.EfilterTypeError(root=subexpr,
                                          expected=expr.type_signature,
                                          actual=t)

    return True
Exemple #11
0
def validate(expr, scope):
    # Make sure there's an ELSE block.
    if expr.default() is None:
        raise errors.EfilterLogicError(
            root=expr, message="Else blocks are required in EFILTER.")

    # Make sure conditions evaluate to IBoolean.
    for condition, _ in expr.conditions():
        t = infer_type.infer_type(condition, scope)
        if not protocol.isa(t, boolean.IBoolean):
            raise errors.EfilterTypeError(root=expr,
                                          actual=t,
                                          expected=boolean.IBoolean)
Exemple #12
0
def validate(expr, scope):
    # Make sure there's an ELSE block.
    if expr.default() is None:
        raise errors.EfilterLogicError(
            root=expr,
            message="Else blocks are required in EFILTER.")

    # Make sure conditions evaluate to IBoolean.
    for condition, _ in expr.conditions():
        t = infer_type.infer_type(condition, scope)
        if not protocol.isa(t, boolean.IBoolean):
            raise errors.EfilterTypeError(root=expr, actual=t,
                                          expected=boolean.IBoolean)
Exemple #13
0
 def assertIsa(self, t, p):
     self.assertTrue(protocol.isa(t, p), "%r is not type %r." % (t, p))
Exemple #14
0
 def assertIsa(self, t, p):
     self.assertTrue(protocol.isa(t, p), "%r is not type %r." % (t, p))
Exemple #15
0
 def assertIsa(self, t, p):
     self.assertTrue(protocol.isa(t, p))
Exemple #16
0
 def assertIsa(self, t, p):
     self.assertTrue(protocol.isa(t, p))