RemoveIgnored: Recurse into params,parents,members,children of Classes

Previously this code would not have removed all members which it was
supposed to.

Also remove some now-redundant code from TypeIdentifier. RemoveIgnored
will take over the responsibility of removing members from classes.
This commit is contained in:
Alastair Robertson 2023-07-19 06:35:09 -07:00 committed by Alastair Robertson
parent 323daed329
commit 6ca846232c
5 changed files with 129 additions and 137 deletions

View File

@ -41,6 +41,19 @@ void RemoveIgnored::accept(Type& type) {
}
void RemoveIgnored::visit(Class& c) {
for (const auto& param : c.templateParams) {
accept(param.type());
}
for (const auto& parent : c.parents) {
accept(parent.type());
}
for (const auto& mem : c.members) {
accept(mem.type());
}
for (const auto& child : c.children) {
accept(child);
}
for (size_t i = 0; i < c.members.size(); i++) {
if (!ignoreMember(c.name(), c.members[i].name)) {
continue;

View File

@ -55,21 +55,6 @@ void TypeIdentifier::accept(Type& type) {
type.accept(*this);
}
void TypeIdentifier::visit(Class& c) {
for (const auto& param : c.templateParams) {
accept(param.type());
}
for (const auto& parent : c.parents) {
accept(parent.type());
}
for (const auto& mem : c.members) {
accept(mem.type());
}
for (const auto& child : c.children) {
accept(child);
}
}
void TypeIdentifier::visit(Container& c) {
const auto& stubParams = c.containerInfo_.stubTemplateParams;
// TODO these two arrays could be looped over in sync for better performance

View File

@ -48,7 +48,6 @@ class TypeIdentifier : public RecursiveVisitor {
using RecursiveVisitor::accept;
void accept(Type& type) override;
void visit(Class& c) override;
void visit(Container& c) override;
private:

View File

@ -84,3 +84,119 @@ TEST(RemoveIgnoredTest, MemberMatchWrongType) {
[1]
)");
}
TEST(RemoveIgnoredTest, RecurseClassParam) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassA", "b"},
};
test(RemoveIgnored::createPass(membersToIgnore), R"(
[0] Class: MyClass (size: 0)
Param
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Param
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: __oi_padding (offset: 4)
[2] Array: (length: 4)
Primitive: int8_t
Member: c (offset: 8)
Primitive: int32_t
)");
}
TEST(RemoveIgnoredTest, RecurseClassParent) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassA", "b"},
};
test(RemoveIgnored::createPass(membersToIgnore), R"(
[0] Class: MyClass (size: 0)
Parent (offset: 0)
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Parent (offset: 0)
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: __oi_padding (offset: 4)
[2] Array: (length: 4)
Primitive: int8_t
Member: c (offset: 8)
Primitive: int32_t
)");
}
TEST(RemoveIgnoredTest, RecurseClassMember) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassA", "b"},
};
test(RemoveIgnored::createPass(membersToIgnore), R"(
[0] Class: MyClass (size: 0)
Member: xxx (offset: 0)
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Member: xxx (offset: 0)
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: __oi_padding (offset: 4)
[2] Array: (length: 4)
Primitive: int8_t
Member: c (offset: 8)
Primitive: int32_t
)");
}
TEST(RemoveIgnoredTest, RecurseClassChild) {
const std::vector<std::pair<std::string, std::string>>& membersToIgnore = {
{"ClassA", "b"},
};
test(RemoveIgnored::createPass(membersToIgnore), R"(
[0] Class: MyClass (size: 0)
Child
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Child
[1] Class: ClassA (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: __oi_padding (offset: 4)
[2] Array: (length: 4)
Primitive: int8_t
Member: c (offset: 8)
Primitive: int32_t
)");
}

View File

@ -234,124 +234,3 @@ TEST(TypeIdentifierTest, DummyAllocatorNotReplaced) {
Primitive: int32_t
)");
}
TEST(TypeIdentifierTest, ClassParam) {
test(TypeIdentifier::createPass({}), R"(
[0] Class: MyClass (size: 0)
Param
[1] Container: std::vector (size: 24)
Param
Primitive: int32_t
Param
[2] Struct: MyParam (size: 4)
Member: a (offset: 0)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Param
[1] Container: std::vector (size: 24)
Param
Primitive: int32_t
Param
Dummy (size: 4)
)");
}
TEST(TypeIdentifierTest, ClassParent) {
test(TypeIdentifier::createPass({}), R"(
[0] Class: MyClass (size: 0)
Parent (offset: 0)
[1] Container: std::vector (size: 24)
Param
Primitive: int32_t
Param
[2] Struct: MyParam (size: 4)
Member: a (offset: 0)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Parent (offset: 0)
[1] Container: std::vector (size: 24)
Param
Primitive: int32_t
Param
Dummy (size: 4)
)");
}
TEST(TypeIdentifierTest, ClassMember) {
test(TypeIdentifier::createPass({}), R"(
[0] Class: MyClass (size: 0)
Member: xxx (offset: 0)
[1] Container: std::vector (size: 24)
Param
Primitive: int32_t
Param
[2] Struct: MyParam (size: 4)
Member: a (offset: 0)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Member: xxx (offset: 0)
[1] Container: std::vector (size: 24)
Param
Primitive: int32_t
Param
Dummy (size: 4)
)");
}
TEST(TypeIdentifierTest, ClassChild) {
test(TypeIdentifier::createPass({}), R"(
[0] Class: MyClass (size: 0)
Child
[1] Class: ChildClass (size: 0)
Parent (offset: 0)
[0]
Member: c (offset: 0)
[2] Container: std::vector (size: 24)
Param
Primitive: int32_t
Param
[3] Struct: MyParam (size: 4)
Member: a (offset: 0)
Primitive: int32_t
)",
R"(
[0] Class: MyClass (size: 0)
Child
[1] Class: ChildClass (size: 0)
Parent (offset: 0)
[0]
Member: c (offset: 0)
[2] Container: std::vector (size: 24)
Param
Primitive: int32_t
Param
Dummy (size: 4)
)");
}
TEST(TypeIdentifierTest, Union) {
test(TypeIdentifier::createPass({}), R"(
[0] Union: MyUnion (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)",
R"(
[0] Union: MyUnion (size: 12)
Member: a (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Member: c (offset: 8)
Primitive: int32_t
)");
}