mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-13 22:06:55 +00:00
45c3697f6b
This lets us remove fields from types when they are no longer needed, speeding up later passes. A secondary benefit of pruning unused types means that we sometimes remove types for which we can't generate correct C++ code. This can allow us to CodeGen for complex types which reference these broken types without actually requiring them (e.g. as template parameters). Add a new feature flag "prune-type-graph" to control this pass. It makes sense to prune most of the time, but for testing CodeGen functionality on a wider range of types, it will be useful to have the option to not prune.
62 lines
1.3 KiB
C++
62 lines
1.3 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include "oi/type_graph/Prune.h"
|
|
#include "test/type_graph_utils.h"
|
|
|
|
using type_graph::Prune;
|
|
|
|
TEST(PruneTest, PruneClass) {
|
|
test(Prune::createPass(), R"(
|
|
[0] Class: MyClass (size: 8)
|
|
Param
|
|
Primitive: int32_t
|
|
Param
|
|
Value: "123"
|
|
Parent (offset: 0)
|
|
[1] Class: MyParent (size: 4)
|
|
Member: a (offset: 0)
|
|
Primitive: int32_t
|
|
Member: a (offset: 0)
|
|
Primitive: int32_t
|
|
Member: b (offset: 4)
|
|
Primitive: int32_t
|
|
Function: foo
|
|
Function: bar
|
|
)",
|
|
R"(
|
|
[0] Class: MyClass (size: 8)
|
|
Member: a (offset: 0)
|
|
Primitive: int32_t
|
|
Member: b (offset: 4)
|
|
Primitive: int32_t
|
|
)");
|
|
}
|
|
|
|
TEST(PruneTest, RecurseClassMember) {
|
|
test(Prune::createPass(), R"(
|
|
[0] Class: MyClass (size: 0)
|
|
Member: xxx (offset: 0)
|
|
[1] Class: ClassA (size: 12)
|
|
Function: foo
|
|
)",
|
|
R"(
|
|
[0] Class: MyClass (size: 0)
|
|
Member: xxx (offset: 0)
|
|
[1] Class: ClassA (size: 12)
|
|
)");
|
|
}
|
|
|
|
TEST(PruneTest, RecurseClassChild) {
|
|
test(Prune::createPass(), R"(
|
|
[0] Class: MyClass (size: 0)
|
|
Child
|
|
[1] Class: ClassA (size: 12)
|
|
Function: foo
|
|
)",
|
|
R"(
|
|
[0] Class: MyClass (size: 0)
|
|
Child
|
|
[1] Class: ClassA (size: 12)
|
|
)");
|
|
}
|