Add support for overloaded entity references

This commit is contained in:
Jonathan Müller 2017-03-19 16:07:54 +01:00
commit 08717b2ae7
8 changed files with 197 additions and 47 deletions

View file

@ -179,7 +179,8 @@ struct g
REQUIRE(base.access_specifier() == cpp_private);
REQUIRE(!base.is_virtual());
auto entity = base.entity().get(idx);
REQUIRE(!base.entity().is_overloaded());
auto entity = base.entity().get(idx)[0u];
REQUIRE(entity);
REQUIRE(entity.value().name() == "a");
}
@ -188,7 +189,8 @@ struct g
REQUIRE(base.access_specifier() == cpp_private);
REQUIRE(!base.is_virtual());
auto entity = base.entity().get(idx);
REQUIRE(!base.entity().is_overloaded());
auto entity = base.entity().get(idx)[0u];
REQUIRE(entity);
REQUIRE(entity.value().name() == "d");
}
@ -214,7 +216,8 @@ struct g
REQUIRE(base.access_specifier() == cpp_public);
REQUIRE(!base.is_virtual());
auto entity = base.entity().get(idx);
REQUIRE(!base.entity().is_overloaded());
auto entity = base.entity().get(idx)[0u];
REQUIRE(entity);
REQUIRE(entity.value().name() == "base");
REQUIRE(full_name(entity.value()) == "ns::base");
@ -224,7 +227,8 @@ struct g
REQUIRE(base.access_specifier() == cpp_protected);
REQUIRE(base.is_virtual());
auto entity = base.entity().get(idx);
REQUIRE(!base.entity().is_overloaded());
auto entity = base.entity().get(idx)[0u];
REQUIRE(entity);
REQUIRE(entity.value().name() == "e");
}
@ -250,7 +254,8 @@ struct g
REQUIRE(base.access_specifier() == cpp_public);
REQUIRE(!base.is_virtual());
auto entity = base.entity().get(idx);
REQUIRE(!base.entity().is_overloaded());
auto entity = base.entity().get(idx)[0u];
REQUIRE(entity);
REQUIRE(entity.value().name() == "base");
REQUIRE(full_name(entity.value()) == "ns::base");

View file

@ -77,8 +77,9 @@ namespace f = outer::c;
const char* target_full_name) {
auto& target = alias.target();
REQUIRE(target.name() == target_name);
REQUIRE(!target.is_overloaded());
auto entity = target.get(idx);
auto entity = target.get(idx)[0u];
REQUIRE(entity);
REQUIRE(full_name(entity.value()) == target_full_name);
};
@ -132,8 +133,9 @@ using namespace outer::ns;
cpp_entity_index idx;
auto check_directive = [&](const cpp_using_directive& directive, const char* target_full_name) {
auto target = directive.target();
REQUIRE(!target.is_overloaded());
auto entity = target.get(idx);
auto entity = target.get(idx)[0u];
REQUIRE(entity);
REQUIRE(full_name(entity.value()) == target_full_name);
};
@ -164,7 +166,6 @@ using namespace outer::ns;
TEST_CASE("cpp_using_declaration")
{
// TODO: test overloaded functions
auto code = R"(
namespace ns1
{
@ -193,34 +194,49 @@ namespace outer
using outer::ns::c;
using outer::c;
namespace ns
{
void d(int);
void d(float);
}
using ns::d;
)";
cpp_entity_index idx;
auto check_declaration = [&](const cpp_using_declaration& decl, const char* target_full_name) {
auto check_declaration = [&](const cpp_using_declaration& decl, const char* target_full_name,
unsigned no) {
auto target = decl.target();
auto entity = target.get(idx);
REQUIRE(entity);
REQUIRE(full_name(entity.value()) == target_full_name);
REQUIRE((target.no_overloaded() == no));
for (auto entity : target.get(idx))
{
REQUIRE(entity);
REQUIRE(full_name(entity.value()) == target_full_name);
}
};
auto file = parse(idx, "cpp_using_declaration.cpp", code);
auto count = test_visit<cpp_using_declaration>(*file, [&](const cpp_using_declaration& decl) {
REQUIRE(decl.name().empty());
if (decl.target().name() == "ns1::a")
check_declaration(decl, "ns1::a");
check_declaration(decl, "ns1::a", 1u);
else if (decl.target().name() == "ns2::b")
check_declaration(decl, "ns2::b");
check_declaration(decl, "ns2::b", 1u);
else if (decl.target().name() == "ns::c")
{
check_parent(decl, "outer", "");
check_declaration(decl, "outer::ns::c");
check_declaration(decl, "outer::ns::c", 1u);
}
else if (decl.target().name() == "outer::ns::c")
check_declaration(decl, "outer::ns::c");
check_declaration(decl, "outer::ns::c", 1u);
else if (decl.target().name() == "outer::c")
check_declaration(decl, "outer::ns::c");
check_declaration(decl, "outer::ns::c", 1u);
else if (decl.target().name() == "ns::d")
check_declaration(decl, "ns::d", 2u);
else
REQUIRE(false);
});
REQUIRE(count == 5u);
REQUIRE(count == 6u);
}

View file

@ -28,7 +28,9 @@ bool equal_types(const cpp_entity_index& idx, const cpp_type& parsed, const cpp_
auto user_synthesized = static_cast<const cpp_user_defined_type&>(synthesized).entity();
if (user_parsed.name() != user_synthesized.name())
return false;
auto entity = user_parsed.get(idx);
else if (user_parsed.is_overloaded())
return false;
auto entity = user_parsed.get(idx)[0u];
return entity.has_value() && (entity.value().name().empty()
|| full_name(entity.value()) == user_parsed.name());
}