mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
AlignmentCalc: Recurse into params,parents,members,children of Classes
This commit is contained in:
parent
623f896e9e
commit
14d193df64
@ -47,11 +47,16 @@ void AlignmentCalc::accept(Type& type) {
|
|||||||
type.accept(*this);
|
type.accept(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO we will need to calculate alignment for c.templateParams too??
|
|
||||||
// TODO same for children. test this
|
|
||||||
void AlignmentCalc::visit(Class& c) {
|
void AlignmentCalc::visit(Class& c) {
|
||||||
// AlignmentCalc should be run after Flattener
|
for (const auto& param : c.templateParams) {
|
||||||
assert(c.parents.empty());
|
accept(param.type());
|
||||||
|
}
|
||||||
|
for (const auto& parent : c.parents) {
|
||||||
|
accept(parent.type());
|
||||||
|
}
|
||||||
|
for (const auto& child : c.children) {
|
||||||
|
accept(child);
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t alignment = 1;
|
uint64_t alignment = 1;
|
||||||
for (auto& member : c.members) {
|
for (auto& member : c.members) {
|
||||||
|
@ -81,3 +81,87 @@ TEST(AlignmentCalcTest, Packed) {
|
|||||||
Primitive: int64_t
|
Primitive: int64_t
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(AlignmentCalcTest, RecurseClassParam) {
|
||||||
|
test(AlignmentCalc::createPass(), R"(
|
||||||
|
[0] Class: MyClass (size: 0)
|
||||||
|
Param
|
||||||
|
[1] Class: ClassA (size: 16)
|
||||||
|
Member: a (offset: 0)
|
||||||
|
Primitive: int8_t
|
||||||
|
Member: b (offset: 4)
|
||||||
|
Primitive: int64_t
|
||||||
|
)",
|
||||||
|
R"(
|
||||||
|
[0] Class: MyClass (size: 0, align: 1)
|
||||||
|
Param
|
||||||
|
[1] Class: ClassA (size: 16, align: 8)
|
||||||
|
Member: a (offset: 0, align: 1)
|
||||||
|
Primitive: int8_t
|
||||||
|
Member: b (offset: 4, align: 8)
|
||||||
|
Primitive: int64_t
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(AlignmentCalcTest, RecurseClassParent) {
|
||||||
|
test(AlignmentCalc::createPass(), R"(
|
||||||
|
[0] Class: MyClass (size: 0)
|
||||||
|
Parent (offset: 0)
|
||||||
|
[1] Class: ClassA (size: 16)
|
||||||
|
Member: a (offset: 0)
|
||||||
|
Primitive: int8_t
|
||||||
|
Member: b (offset: 4)
|
||||||
|
Primitive: int64_t
|
||||||
|
)",
|
||||||
|
R"(
|
||||||
|
[0] Class: MyClass (size: 0, align: 1)
|
||||||
|
Parent (offset: 0)
|
||||||
|
[1] Class: ClassA (size: 16, align: 8)
|
||||||
|
Member: a (offset: 0, align: 1)
|
||||||
|
Primitive: int8_t
|
||||||
|
Member: b (offset: 4, align: 8)
|
||||||
|
Primitive: int64_t
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(AlignmentCalcTest, RecurseClassMember) {
|
||||||
|
test(AlignmentCalc::createPass(), R"(
|
||||||
|
[0] Class: MyClass (size: 0)
|
||||||
|
Member: xxx (offset: 0)
|
||||||
|
[1] Class: ClassA (size: 16)
|
||||||
|
Member: a (offset: 0)
|
||||||
|
Primitive: int8_t
|
||||||
|
Member: b (offset: 4)
|
||||||
|
Primitive: int64_t
|
||||||
|
)",
|
||||||
|
R"(
|
||||||
|
[0] Class: MyClass (size: 0, align: 8)
|
||||||
|
Member: xxx (offset: 0, align: 8)
|
||||||
|
[1] Class: ClassA (size: 16, align: 8)
|
||||||
|
Member: a (offset: 0, align: 1)
|
||||||
|
Primitive: int8_t
|
||||||
|
Member: b (offset: 4, align: 8)
|
||||||
|
Primitive: int64_t
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(AlignmentCalcTest, RecurseClassChild) {
|
||||||
|
test(AlignmentCalc::createPass(), R"(
|
||||||
|
[0] Class: MyClass (size: 0)
|
||||||
|
Child
|
||||||
|
[1] Class: ClassA (size: 16)
|
||||||
|
Member: a (offset: 0)
|
||||||
|
Primitive: int8_t
|
||||||
|
Member: b (offset: 4)
|
||||||
|
Primitive: int64_t
|
||||||
|
)",
|
||||||
|
R"(
|
||||||
|
[0] Class: MyClass (size: 0, align: 1)
|
||||||
|
Child
|
||||||
|
[1] Class: ClassA (size: 16, align: 8)
|
||||||
|
Member: a (offset: 0, align: 1)
|
||||||
|
Primitive: int8_t
|
||||||
|
Member: b (offset: 4, align: 8)
|
||||||
|
Primitive: int64_t
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user