TypeIdentifier: Create custom visitor for Class types

This is just laying some foundations - it doesn't do anything useful
yet.
This commit is contained in:
Alastair Robertson 2023-07-18 05:53:41 -07:00 committed by Alastair Robertson
parent 3b6b739d55
commit 1e1b319a69
3 changed files with 137 additions and 0 deletions

View File

@ -55,6 +55,21 @@ 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,6 +48,7 @@ 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

@ -234,3 +234,124 @@ 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
)");
}