Flattener: Pull up children of children

This commit is contained in:
Alastair Robertson 2023-07-07 06:41:55 -07:00 committed by Alastair Robertson
parent 17633983b5
commit 43303ae6d3
4 changed files with 14 additions and 5 deletions

View File

@ -205,6 +205,13 @@ void Flattener::visit(Class& c) {
for (const auto& child : c.children) {
accept(child);
}
// Pull in children from flattened children
// This may result in duplicates, but that shouldn't be a big deal
for (const Class& child : c.children) {
c.children.insert(c.children.end(), child.children.begin(),
child.children.end());
}
}
void Flattener::visit(Container& c) {

View File

@ -204,7 +204,7 @@ void Printer::print_function(const Function& function) {
void Printer::print_child(const Type& child) {
depth_++;
prefix();
out_ << "Child:" << std::endl;
out_ << "Child" << std::endl;
print(child);
depth_--;
}

View File

@ -235,7 +235,7 @@ class Class : public Type {
std::vector<Parent> parents; // Sorted by offset
std::vector<Member> members; // Sorted by offset
std::vector<Function> functions;
std::vector<std::reference_wrapper<Type>>
std::vector<std::reference_wrapper<Class>>
children; // Only for dynamic classes
private:

View File

@ -625,7 +625,7 @@ TEST(FlattenerTest, Children) {
[0] Class: ClassB (size: 4)
Member: b (offset: 0)
Primitive: int32_t
Child:
Child
[1] Class: ClassA (size: 8)
Member: b (offset: 0)
Primitive: int32_t
@ -665,13 +665,13 @@ TEST(FlattenerTest, ChildrenTwoDeep) {
[0] Class: ClassD (size: 4)
Member: d (offset: 0)
Primitive: int32_t
Child:
Child
[1] Class: ClassB (size: 8)
Member: d (offset: 0)
Primitive: int32_t
Member: b (offset: 4)
Primitive: int32_t
Child:
Child
[2] Class: ClassA (size: 16)
Member: d (offset: 0)
Primitive: int32_t
@ -681,6 +681,8 @@ TEST(FlattenerTest, ChildrenTwoDeep) {
Primitive: int32_t
Member: a (offset: 12)
Primitive: int32_t
Child
[2]
)");
}