mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
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:
parent
3b6b739d55
commit
1e1b319a69
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
)");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user