Exemplo n.º 1
0
def mod(viper_ast: ViperAST, dividend, divisor, pos=None, info=None):
    # We need a special mod function because Vyper uses truncating division
    # instead of Viper's floor division
    mmod = mangled.MATH_MOD
    domain = mangled.MATH_DOMAIN
    # We pass the Viper floor division as a third argument to trigger a correct
    # division by 0 error instead of an assertion failure if divisor == 0
    args = [dividend, divisor, viper_ast.Mod(dividend, divisor, pos)]
    return viper_ast.DomainFuncApp(mmod, args, viper_ast.Int, pos, info,
                                   domain)
Exemplo n.º 2
0
def w_mod(viper_ast: ViperAST, first, second, pos=None, info=None):
    if isinstance(viper_ast, WrappedViperAST):
        viper_ast = viper_ast.viper_ast
    wi_mod = mangled.WRAPPED_INT_MOD
    domain = mangled.WRAPPED_INT_DOMAIN
    args = [first, second]
    func_app = viper_ast.DomainFuncApp(wi_mod, args,
                                       wrapped_int_type(viper_ast), pos, info,
                                       domain)
    is_div_zero = viper_ast.EqCmp(viper_ast.IntLit(0),
                                  w_unwrap(viper_ast, second, pos, info), pos,
                                  info)
    artificial_div_zero = w_wrap(
        viper_ast,
        viper_ast.Mod(w_unwrap(viper_ast, first, pos, info),
                      w_unwrap(viper_ast, second, pos, info), pos, info), pos,
        info)
    return viper_ast.CondExp(is_div_zero, artificial_div_zero, func_app, pos,
                             info)