Add support for multiple namespace entities with the same name
This commit is contained in:
parent
08717b2ae7
commit
d21d017d8a
13 changed files with 207 additions and 203 deletions
|
|
@ -180,9 +180,9 @@ struct g
|
|||
REQUIRE(!base.is_virtual());
|
||||
|
||||
REQUIRE(!base.entity().is_overloaded());
|
||||
auto entity = base.entity().get(idx)[0u];
|
||||
REQUIRE(entity);
|
||||
REQUIRE(entity.value().name() == "a");
|
||||
auto entities = base.entity().get(idx);
|
||||
REQUIRE(entities.size() == 1u);
|
||||
REQUIRE(entities[0u]->name() == "a");
|
||||
}
|
||||
else if (base.name() == "d")
|
||||
{
|
||||
|
|
@ -190,9 +190,9 @@ struct g
|
|||
REQUIRE(!base.is_virtual());
|
||||
|
||||
REQUIRE(!base.entity().is_overloaded());
|
||||
auto entity = base.entity().get(idx)[0u];
|
||||
REQUIRE(entity);
|
||||
REQUIRE(entity.value().name() == "d");
|
||||
auto entities = base.entity().get(idx);
|
||||
REQUIRE(entities.size() == 1u);
|
||||
REQUIRE(entities[0u]->name() == "d");
|
||||
}
|
||||
else
|
||||
REQUIRE(false);
|
||||
|
|
@ -217,10 +217,10 @@ struct g
|
|||
REQUIRE(!base.is_virtual());
|
||||
|
||||
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");
|
||||
auto entities = base.entity().get(idx);
|
||||
REQUIRE(entities.size() == 1u);
|
||||
REQUIRE(entities[0u]->name() == "base");
|
||||
REQUIRE(full_name(*entities[0u]) == "ns::base");
|
||||
}
|
||||
else if (base.name() == "e")
|
||||
{
|
||||
|
|
@ -228,9 +228,9 @@ struct g
|
|||
REQUIRE(base.is_virtual());
|
||||
|
||||
REQUIRE(!base.entity().is_overloaded());
|
||||
auto entity = base.entity().get(idx)[0u];
|
||||
REQUIRE(entity);
|
||||
REQUIRE(entity.value().name() == "e");
|
||||
auto entities = base.entity().get(idx);
|
||||
REQUIRE(entities.size() == 1u);
|
||||
REQUIRE(entities[0u]->name() == "e");
|
||||
}
|
||||
else
|
||||
REQUIRE(false);
|
||||
|
|
@ -255,10 +255,10 @@ struct g
|
|||
REQUIRE(!base.is_virtual());
|
||||
|
||||
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");
|
||||
auto entities = base.entity().get(idx);
|
||||
REQUIRE(entities.size() == 1u);
|
||||
REQUIRE(entities[0u]->name() == "base");
|
||||
REQUIRE(full_name(*entities[0u]) == "ns::base");
|
||||
}
|
||||
else
|
||||
REQUIRE(false);
|
||||
|
|
|
|||
|
|
@ -54,18 +54,18 @@ namespace c
|
|||
TEST_CASE("cpp_namespace_alias")
|
||||
{
|
||||
auto code = R"(
|
||||
namespace ns1 {}
|
||||
namespace ns2 {}
|
||||
namespace outer {}
|
||||
namespace ns {}
|
||||
|
||||
namespace a = ns1;
|
||||
namespace b = ns2;
|
||||
namespace a = outer;
|
||||
namespace b = ns;
|
||||
|
||||
namespace outer
|
||||
{
|
||||
namespace ns {}
|
||||
|
||||
namespace c = ns;
|
||||
namespace d = ns1;
|
||||
namespace d = ::outer;
|
||||
}
|
||||
|
||||
namespace e = outer::ns;
|
||||
|
|
@ -74,36 +74,37 @@ namespace f = outer::c;
|
|||
|
||||
cpp_entity_index idx;
|
||||
auto check_alias = [&](const cpp_namespace_alias& alias, const char* target_name,
|
||||
const char* target_full_name) {
|
||||
const char* target_full_name, unsigned no) {
|
||||
auto& target = alias.target();
|
||||
REQUIRE(target.name() == target_name);
|
||||
REQUIRE(!target.is_overloaded());
|
||||
|
||||
auto entity = target.get(idx)[0u];
|
||||
REQUIRE(entity);
|
||||
REQUIRE(full_name(entity.value()) == target_full_name);
|
||||
auto entities = target.get(idx);
|
||||
REQUIRE(entities.size() == no);
|
||||
for (auto& entity : entities)
|
||||
REQUIRE(full_name(*entity) == target_full_name);
|
||||
};
|
||||
|
||||
auto file = parse(idx, "cpp_namespace_alias.cpp", code);
|
||||
auto count = test_visit<cpp_namespace_alias>(*file, [&](const cpp_namespace_alias& alias) {
|
||||
if (alias.name() == "a")
|
||||
check_alias(alias, "ns1", "ns1");
|
||||
check_alias(alias, "outer", "outer", 2u);
|
||||
else if (alias.name() == "b")
|
||||
check_alias(alias, "ns2", "ns2");
|
||||
check_alias(alias, "ns", "ns", 1u);
|
||||
else if (alias.name() == "c")
|
||||
{
|
||||
check_parent(alias, "outer", "outer::c");
|
||||
check_alias(alias, "ns", "outer::ns");
|
||||
check_alias(alias, "ns", "outer::ns", 1u);
|
||||
}
|
||||
else if (alias.name() == "d")
|
||||
{
|
||||
check_parent(alias, "outer", "outer::d");
|
||||
check_alias(alias, "ns1", "ns1");
|
||||
check_alias(alias, "::outer", "outer", 2u);
|
||||
}
|
||||
else if (alias.name() == "e")
|
||||
check_alias(alias, "outer::ns", "outer::ns");
|
||||
check_alias(alias, "outer::ns", "outer::ns", 1u);
|
||||
else if (alias.name() == "f")
|
||||
check_alias(alias, "outer::c", "outer::ns");
|
||||
check_alias(alias, "outer::c", "outer::ns", 1u);
|
||||
else
|
||||
REQUIRE(false);
|
||||
});
|
||||
|
|
@ -135,9 +136,9 @@ using namespace outer::ns;
|
|||
auto target = directive.target();
|
||||
REQUIRE(!target.is_overloaded());
|
||||
|
||||
auto entity = target.get(idx)[0u];
|
||||
REQUIRE(entity);
|
||||
REQUIRE(full_name(entity.value()) == target_full_name);
|
||||
auto entities = target.get(idx);
|
||||
REQUIRE(entities.size() == 1u);
|
||||
REQUIRE(full_name(*entities[0u]) == target_full_name);
|
||||
};
|
||||
|
||||
auto file = parse(idx, "cpp_using_directive.cpp", code);
|
||||
|
|
@ -195,13 +196,13 @@ namespace outer
|
|||
using outer::ns::c;
|
||||
using outer::c;
|
||||
|
||||
namespace ns
|
||||
namespace ns1
|
||||
{
|
||||
void d(int);
|
||||
void d(float);
|
||||
}
|
||||
|
||||
using ns::d;
|
||||
using ns1::d;
|
||||
)";
|
||||
|
||||
cpp_entity_index idx;
|
||||
|
|
@ -211,8 +212,7 @@ using ns::d;
|
|||
REQUIRE((target.no_overloaded() == no));
|
||||
for (auto entity : target.get(idx))
|
||||
{
|
||||
REQUIRE(entity);
|
||||
REQUIRE(full_name(entity.value()) == target_full_name);
|
||||
REQUIRE(full_name(*entity) == target_full_name);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -233,8 +233,8 @@ using ns::d;
|
|||
check_declaration(decl, "outer::ns::c", 1u);
|
||||
else if (decl.target().name() == "outer::c")
|
||||
check_declaration(decl, "outer::ns::c", 1u);
|
||||
else if (decl.target().name() == "ns::d")
|
||||
check_declaration(decl, "ns::d", 2u);
|
||||
else if (decl.target().name() == "ns1::d")
|
||||
check_declaration(decl, "ns1::d", 2u);
|
||||
else
|
||||
REQUIRE(false);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ bool equal_types(const cpp_entity_index& idx, const cpp_type& parsed, const cpp_
|
|||
return false;
|
||||
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());
|
||||
auto entities = user_parsed.get(idx);
|
||||
REQUIRE(entities.size() == 1u);
|
||||
return entities[0u]->name().empty() || full_name(*entities[0u]) == user_parsed.name();
|
||||
}
|
||||
|
||||
case cpp_type_kind::cv_qualified:
|
||||
|
|
|
|||
|
|
@ -69,12 +69,15 @@ static struct {} l;
|
|||
else if (var.name() == "b")
|
||||
check_variable(var, *cpp_builtin_type::build("unsigned long long"),
|
||||
// unexposed due to implicit cast, I think
|
||||
*cpp_unexposed_expression::build(cpp_builtin_type::build("int"), "42"),
|
||||
type_safe::ref(
|
||||
*cpp_unexposed_expression::build(cpp_builtin_type::build("int"),
|
||||
"42")),
|
||||
cpp_storage_class_none, false, false);
|
||||
else if (var.name() == "c")
|
||||
check_variable(var, *cpp_builtin_type::build("float"),
|
||||
*cpp_unexposed_expression::build(cpp_builtin_type::build("float"),
|
||||
"3.f+0.14f"),
|
||||
type_safe::ref(
|
||||
*cpp_unexposed_expression::build(cpp_builtin_type::build("float"),
|
||||
"3.f+0.14f")),
|
||||
cpp_storage_class_none, false, false);
|
||||
else if (var.name() == "d")
|
||||
check_variable(var, *int_type, nullptr, cpp_storage_class_extern, false, true);
|
||||
|
|
@ -88,7 +91,9 @@ static struct {} l;
|
|||
else if (var.name() == "h")
|
||||
check_variable(var, *cpp_cv_qualified_type::build(cpp_builtin_type::build("int"),
|
||||
cpp_cv_const),
|
||||
*cpp_literal_expression::build(cpp_builtin_type::build("int"), "12"),
|
||||
type_safe::ref(
|
||||
*cpp_literal_expression::build(cpp_builtin_type::build("int"),
|
||||
"12")),
|
||||
cpp_storage_class_none, true, false);
|
||||
else if (var.name() == "i")
|
||||
check_variable(var,
|
||||
|
|
@ -99,18 +104,20 @@ static struct {} l;
|
|||
cpp_type_ref(cpp_entity_id(""),
|
||||
"bar")),
|
||||
cpp_cv_const),
|
||||
*cpp_unexposed_expression::build(cpp_user_defined_type::build(
|
||||
cpp_type_ref(cpp_entity_id(""),
|
||||
"bar")),
|
||||
"bar()"),
|
||||
type_safe::ref(
|
||||
*cpp_unexposed_expression::build(cpp_user_defined_type::build(
|
||||
cpp_type_ref(cpp_entity_id(""),
|
||||
"bar")),
|
||||
"bar()")),
|
||||
cpp_storage_class_none, false, false);
|
||||
else if (var.name() == "k")
|
||||
check_variable(var,
|
||||
*cpp_user_defined_type::build(cpp_type_ref(cpp_entity_id(""), "baz")),
|
||||
*cpp_unexposed_expression::build(cpp_user_defined_type::build(
|
||||
cpp_type_ref(cpp_entity_id(""),
|
||||
"baz")),
|
||||
"{}"),
|
||||
type_safe::ref(
|
||||
*cpp_unexposed_expression::build(cpp_user_defined_type::build(
|
||||
cpp_type_ref(cpp_entity_id(""),
|
||||
"baz")),
|
||||
"{}")),
|
||||
cpp_storage_class_none, false, false);
|
||||
else if (var.name() == "l")
|
||||
check_variable(var, *cpp_user_defined_type::build(cpp_type_ref(cpp_entity_id(""), "")),
|
||||
|
|
|
|||
|
|
@ -33,7 +33,10 @@ inline std::unique_ptr<cppast::cpp_file> parse(const cppast::cpp_entity_index& i
|
|||
|
||||
static stderr_diagnostic_logger logger;
|
||||
libclang_parser p(type_safe::ref(logger));
|
||||
return p.parse(idx, name, config);
|
||||
|
||||
auto result = p.parse(idx, name, config);
|
||||
REQUIRE(!logger.error_logged());
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T, typename Func>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue