Ejemplo n.º 1
0
def test_unify_ir0_certain_nontrivial_with_variadic_type_variable_matches_empty_list_suffix(
):
    result = _unify([
        ir0.FunctionTypeExpr(type_literal('int'),
                             arg_exprs=[type_literal('float')])
    ], [
        ir0.FunctionTypeExpr(type_literal('int'),
                             arg_exprs=[
                                 type_literal('float'),
                                 ir0.VariadicTypeExpansion(
                                     ir0.AtomicTypeLiteral.for_local(
                                         cpp_type='Ts',
                                         expr_type=ir0.TypeType(),
                                         is_variadic=True))
                             ])
    ],
                    expr_variables=set(),
                    pattern_variables={'Ts'})
    assert result.kind == UnificationResultKind.CERTAIN
    assert result.value_by_pattern_variable == []
    assert result.value_by_expanded_pattern_variable == [
        (ir0.VariadicTypeExpansion(
            ir0.AtomicTypeLiteral.for_local(cpp_type='Ts',
                                            expr_type=ir0.TypeType(),
                                            is_variadic=True)), []),
    ]
Ejemplo n.º 2
0
def test_unify_ir0_certain_nontrivial_with_variadic_type_variable() -> None:
    result = _unify(
        (ir0.FunctionTypeExpr(
            type_literal('int'),
            arg_exprs=(type_literal('float'), type_literal('double'),
                       local_type_literal('T'), type_literal('char'),
                       type_literal('void'))), ),
        (ir0.FunctionTypeExpr(
            type_literal('int'),
            arg_exprs=(type_literal('float'), type_literal('double'),
                       ir0.VariadicTypeExpansion(
                           ir0.AtomicTypeLiteral.for_local(
                               cpp_type='Ts',
                               expr_type=ir0.TypeType(),
                               is_variadic=True)), type_literal('void'))), ),
        expr_variables={'T'},
        pattern_variables={'Ts'})
    assert result.kind == UnificationResultKind.CERTAIN
    assert result.value_by_pattern_variable == ()
    assert result.value_by_expanded_pattern_variable == (
        (ir0.VariadicTypeExpansion(
            ir0.AtomicTypeLiteral.for_local(cpp_type='Ts',
                                            expr_type=ir0.TypeType(),
                                            is_variadic=True)),
         (local_type_literal('T'), type_literal('char'))), )
Ejemplo n.º 3
0
def test_unify_ir0_variadic_type_variable_matches_multiple_variadics():
    result = _unify([
        ir0.FunctionTypeExpr(
            type_literal('int'),
            arg_exprs=[
                type_literal('float'),
                type_literal('double'),
                ir0.VariadicTypeExpansion(
                    ir0.AtomicTypeLiteral.for_local(cpp_type='Ts',
                                                    expr_type=ir0.TypeType(),
                                                    is_variadic=True)),
                type_literal('char'),
                ir0.VariadicTypeExpansion(
                    ir0.AtomicTypeLiteral.for_local(cpp_type='Us',
                                                    expr_type=ir0.TypeType(),
                                                    is_variadic=True)),
                type_literal('void')
            ])
    ], [
        ir0.FunctionTypeExpr(type_literal('int'),
                             arg_exprs=[
                                 type_literal('float'),
                                 type_literal('double'),
                                 ir0.VariadicTypeExpansion(
                                     ir0.AtomicTypeLiteral.for_local(
                                         cpp_type='Vs',
                                         expr_type=ir0.TypeType(),
                                         is_variadic=True)),
                                 type_literal('void')
                             ])
    ],
                    expr_variables={'Ts', 'Us'},
                    pattern_variables={'Vs'})
    assert result.kind == UnificationResultKind.CERTAIN
    assert result.value_by_pattern_variable == []
    assert result.value_by_expanded_pattern_variable == [
        (ir0.VariadicTypeExpansion(
            ir0.AtomicTypeLiteral.for_local(cpp_type='Vs',
                                            expr_type=ir0.TypeType(),
                                            is_variadic=True)),
         [
             ir0.VariadicTypeExpansion(
                 ir0.AtomicTypeLiteral.for_local(cpp_type='Ts',
                                                 expr_type=ir0.TypeType(),
                                                 is_variadic=True)),
             type_literal('char'),
             ir0.VariadicTypeExpansion(
                 ir0.AtomicTypeLiteral.for_local(cpp_type='Us',
                                                 expr_type=ir0.TypeType(),
                                                 is_variadic=True))
         ]),
    ]
Ejemplo n.º 4
0
def test_unify_ir0_certain_nontrivial_with_variadic_type_variable_does_not_match(
) -> None:
    result = _unify(
        (ir0.FunctionTypeExpr(type_literal('int'), arg_exprs=()), ),
        (ir0.FunctionTypeExpr(type_literal('int'),
                              arg_exprs=(
                                  type_literal('float'),
                                  ir0.VariadicTypeExpansion(
                                      ir0.AtomicTypeLiteral.for_local(
                                          cpp_type='Ts',
                                          expr_type=ir0.TypeType(),
                                          is_variadic=True)),
                              )), ),
        expr_variables=set(),
        pattern_variables={'Ts'})
    assert result.kind == UnificationResultKind.IMPOSSIBLE
Ejemplo n.º 5
0
def local_type_literal(cpp_type: str):
    return ir0.AtomicTypeLiteral.for_local(cpp_type,
                                           expr_type=ir0.TypeType(),
                                           is_variadic=False)


@pytest.mark.parametrize('expr_generator', [
    lambda: ir0.Literal(1),
    lambda: ir0.AtomicTypeLiteral.for_nonlocal_type('int', may_be_alias=False),
    lambda: ir0.PointerTypeExpr(type_literal('int')),
    lambda: ir0.ReferenceTypeExpr(type_literal('int')),
    lambda: ir0.RvalueReferenceTypeExpr(type_literal('int')),
    lambda: ir0.ConstTypeExpr(type_literal('int')),
    lambda: ir0.ArrayTypeExpr(type_literal('int')),
    lambda: ir0.FunctionTypeExpr(type_literal('int'), []),
    lambda: ir0.FunctionTypeExpr(type_literal('int'), [type_literal('float')]),
    lambda: ir0.ComparisonExpr(literal(1), literal(2), op='=='),
    lambda: ir0.Int64BinaryOpExpr(literal(1), literal(2), op='+'),
    lambda: ir0.BoolBinaryOpExpr(literal(True), literal(False), op='||'),
    lambda: ir0.NotExpr(literal(True)),
    lambda: ir0.UnaryMinusExpr(literal(1)),
    lambda: ir0.TemplateInstantiation(
        template_expr=ir0.AtomicTypeLiteral.for_nonlocal_template(
            cpp_type='std::vector',
            args=[],
            is_metafunction_that_may_return_error=False,
            may_be_alias=False),
        args=[],
        instantiation_might_trigger_static_asserts=False),
    lambda: ir0.TemplateInstantiation(
Ejemplo n.º 6
0
def fun(return_type_expr: ir0.Expr, arg_exprs: List[ir0.Expr]):
    return ir0.FunctionTypeExpr(return_type_expr, arg_exprs)
Ejemplo n.º 7
0
def fun(return_type_expr: ir0.Expr, arg_exprs: Tuple[ir0.Expr, ...]):
    return ir0.FunctionTypeExpr(return_type_expr, arg_exprs)