mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
NameGen: Fix naming of const pointers
This commit is contained in:
parent
ed2c6f357d
commit
e9975286b2
@ -113,10 +113,16 @@ void NameGen::visit(Container& c) {
|
||||
if (param.value) {
|
||||
name += *param.value;
|
||||
} else {
|
||||
name += param.type()->name();
|
||||
// The "const" keyword must come after the type name so that pointers are
|
||||
// handled correctly.
|
||||
//
|
||||
// When we're told that we have a const member with type "Foo*", we want
|
||||
// "Foo* const", meaning const pointer to Foo, rather than "const Foo*",
|
||||
// meaning pointer to const Foo.
|
||||
if (param.qualifiers[Qualifier::Const]) {
|
||||
name += " const";
|
||||
}
|
||||
name += param.type()->name();
|
||||
}
|
||||
name += ", ";
|
||||
}
|
||||
|
@ -148,14 +148,14 @@ TEST(CodeGenTest, TransformContainerAllocatorParamInParent) {
|
||||
Function: deallocate
|
||||
)",
|
||||
R"(
|
||||
[0] Container: std::map<int32_t, int32_t, DummyAllocator<std::pair<const int32_t, int32_t>, 0, 0>> (size: 24)
|
||||
[0] Container: std::map<int32_t, int32_t, DummyAllocator<std::pair<int32_t const, int32_t>, 0, 0>> (size: 24)
|
||||
Param
|
||||
Primitive: int32_t
|
||||
Param
|
||||
Primitive: int32_t
|
||||
Param
|
||||
DummyAllocator (size: 0)
|
||||
[1] Container: std::pair<const int32_t, int32_t> (size: 8)
|
||||
[1] Container: std::pair<int32_t const, int32_t> (size: 8)
|
||||
Param
|
||||
Primitive: int32_t
|
||||
Qualifiers: const
|
||||
|
@ -171,18 +171,24 @@ TEST(NameGenTest, ContainerParamsDuplicatesAcrossContainers) {
|
||||
TEST(NameGenTest, ContainerParamsConst) {
|
||||
auto myparam1 = Class{0, Class::Kind::Struct, "MyConstParam", 13};
|
||||
auto myparam2 = Class{1, Class::Kind::Struct, "MyParam", 13};
|
||||
auto ptrParam = Class{2, Class::Kind::Struct, "PtrParam", 13};
|
||||
auto myparam3 = Pointer{3, ptrParam};
|
||||
|
||||
auto mycontainer = getVector();
|
||||
mycontainer.templateParams.push_back(
|
||||
TemplateParam{myparam1, {Qualifier::Const}});
|
||||
mycontainer.templateParams.push_back(TemplateParam{myparam2});
|
||||
mycontainer.templateParams.push_back(
|
||||
TemplateParam{myparam3, {Qualifier::Const}});
|
||||
|
||||
NameGen nameGen;
|
||||
nameGen.generateNames({mycontainer});
|
||||
|
||||
EXPECT_EQ(myparam1.name(), "MyConstParam_0");
|
||||
EXPECT_EQ(myparam2.name(), "MyParam_1");
|
||||
EXPECT_EQ(mycontainer.name(), "std::vector<const MyConstParam_0, MyParam_1>");
|
||||
EXPECT_EQ(myparam3.name(), "PtrParam_2*");
|
||||
EXPECT_EQ(mycontainer.name(),
|
||||
"std::vector<MyConstParam_0 const, MyParam_1, PtrParam_2* const>");
|
||||
}
|
||||
|
||||
TEST(NameGenTest, ContainerNoParams) {
|
||||
|
Loading…
Reference in New Issue
Block a user