Parse cpp_converison_op

This commit is contained in:
Jonathan Müller 2017-03-12 17:43:57 +01:00
commit 8691628ec5
9 changed files with 184 additions and 25 deletions

View file

@ -130,3 +130,58 @@ struct bar : foo
});
REQUIRE(count == 12u);
}
TEST_CASE("cpp_conversion_op")
{
auto code = R"(
namespace ns
{
using type = char;
}
// most of it only need to be check in member function
struct foo
{
operator int&();
explicit operator bool() const;
constexpr operator ns::type();
};
)";
cpp_entity_index idx;
auto file = parse(idx, "cpp_conversion_op.cpp", code);
auto count = test_visit<cpp_conversion_op>(*file, [&](const cpp_conversion_op& op) {
REQUIRE(op.name().empty());
REQUIRE(count_children(op) == 0u);
REQUIRE(!op.is_variadic());
REQUIRE(op.body_kind() == cpp_function_declaration);
REQUIRE(op.ref_qualifier() == cpp_ref_none);
REQUIRE(!op.virtual_info());
REQUIRE(!op.noexcept_condition());
if (!op.is_explicit() && !op.is_constexpr())
{
REQUIRE(equal_types(idx, op.return_type(),
*cpp_reference_type::build(cpp_builtin_type::build("int"),
cpp_ref_lvalue)));
REQUIRE(op.cv_qualifier() == cpp_cv_none);
REQUIRE(!op.is_explicit());
REQUIRE(!op.is_constexpr());
}
else if (op.is_explicit() && !op.is_constexpr())
{
REQUIRE(equal_types(idx, op.return_type(), *cpp_builtin_type::build("bool")));
REQUIRE(op.cv_qualifier() == cpp_cv_const);
}
else if (!op.is_explicit() && op.is_constexpr())
{
REQUIRE(equal_types(idx, op.return_type(),
*cpp_user_defined_type::build(
cpp_type_ref(cpp_entity_id(""), "ns::type"))));
REQUIRE(op.cv_qualifier() == cpp_cv_none);
}
else
REQUIRE(false);
});
REQUIRE(count == 3u);
}

View file

@ -29,8 +29,8 @@ bool equal_types(const cpp_entity_index& idx, const cpp_type& parsed, const cpp_
if (user_parsed.name() != user_synthesized.name())
return false;
auto entity = user_parsed.get(idx);
return entity.has_value() && entity.value().name().empty()
|| entity.value().name() == user_parsed.name();
return entity.has_value() && (entity.value().name().empty()
|| full_name(entity.value()) == user_parsed.name());
}
case cpp_type_kind::cv_qualified: