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
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
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
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
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)
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
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
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)
def assertIsa(self, t, p): self.assertTrue(protocol.isa(t, p), "%r is not type %r." % (t, p))
def assertIsa(self, t, p): self.assertTrue(protocol.isa(t, p))