def test_unify_ir0_certain_nontrivial_with_local_variable() -> None: result = _unify((ir0.PointerTypeExpr(local_type_literal('X')), ), (ir0.PointerTypeExpr(local_type_literal('T')), ), expr_variables={'X'}, pattern_variables={'T'}) assert result.kind == UnificationResultKind.CERTAIN assert result.value_by_pattern_variable == ((local_type_literal('T'), local_type_literal('X')), ) assert result.value_by_expanded_pattern_variable == ()
def test_unify_ir0_certain_nontrivial_with_local(): result = _unify([ir0.PointerTypeExpr(local_type_literal('X'))], [ir0.PointerTypeExpr(local_type_literal('T'))], expr_variables=set(), pattern_variables={'T'}) assert result.kind == UnificationResultKind.CERTAIN assert result.value_by_pattern_variable == [ (local_type_literal('T'), local_type_literal('X')), ] assert result.value_by_expanded_pattern_variable == []
def test_unify_ir0_certain_nontrivial_multiple_equalities() -> None: result = _unify(( ir0.PointerTypeExpr(type_literal('int')), ir0.PointerTypeExpr(type_literal('int')), ), ( ir0.PointerTypeExpr(local_type_literal('T')), ir0.PointerTypeExpr(local_type_literal('T')), ), expr_variables=set(), pattern_variables={'T'}) assert result.kind == UnificationResultKind.CERTAIN assert result.value_by_pattern_variable == ((local_type_literal('T'), type_literal('int')), ) assert result.value_by_expanded_pattern_variable == ()
def type_literal(cpp_type: str): return ir0.AtomicTypeLiteral.for_nonlocal_type(cpp_type, may_be_alias=False) 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=[],
def pointer(expr: ir0.Expr): return ir0.PointerTypeExpr(expr)