diff --git a/oi/type_graph/TypeIdentifier.cpp b/oi/type_graph/TypeIdentifier.cpp index 0982d03..08fbc8c 100644 --- a/oi/type_graph/TypeIdentifier.cpp +++ b/oi/type_graph/TypeIdentifier.cpp @@ -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 diff --git a/oi/type_graph/TypeIdentifier.h b/oi/type_graph/TypeIdentifier.h index e451996..b237320 100644 --- a/oi/type_graph/TypeIdentifier.h +++ b/oi/type_graph/TypeIdentifier.h @@ -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: diff --git a/test/test_type_identifier.cpp b/test/test_type_identifier.cpp index 9bbb1cb..091cae2 100644 --- a/test/test_type_identifier.cpp +++ b/test/test_type_identifier.cpp @@ -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 +)"); +}