Example #1
0
    def construct(self):
        # Accept as a prefix all types that can have a null value
        expr = construct(
            self.expr,
            lambda cls: cls.null_allowed,
            'Invalid prefix type for .then: {expr_type}'
        )
        self.var_expr.set_type(expr.type)

        # Create a then-expr specific scope to restrict the span of the "then"
        # variable in the debugger.
        with PropertyDef.get_scope().new_child() as then_scope:
            then_scope.add(self.var_expr.local_var)
            then_expr = construct(self.then_expr)
            var_expr = construct(self.var_expr)
        then_expr = BindingScope(then_expr, [var_expr], scope=then_scope)

        # Affect default value to the fallback expression
        then_expr, default_expr = expr_or_null(
            then_expr, self.default_val,
            'Then expression', "function's return type"
        )

        return Then.Expr(expr, construct(self.var_expr), then_expr,
                         default_expr, then_scope)
Example #2
0
    def construct(self):
        """
        Construct a resolved expression for this.

        :rtype: If.Expr
        """
        then, else_then = expr_or_null(self._then, self.else_then,
                                       'If expression', None)
        return If.Expr(construct(self.cond, T.Bool), then, else_then,
                       abstract_expr=self)