mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-13 22:06:55 +00:00
31ba8659f0
A previous change enabled running OIL tests with specific features enabled. This highlighted that pointer code generation under TreeBuilder-v2 was very broken. This change updates pointer code generation to work and enables the skipped tests. All enabled tests need `expected_json_v2` added to them due to formatting differences. Reformatted and rewrote the basic type handler that handles primitives and pointers. Removed the reliance on `features` to decide whether to generate for TreeBuilder-v2 as the intermediate features have been removed. Pointers are treated as containers with a capacity of 1 and a length of 0 if null/a cycle and 1 if followed. This holds for void pointers where, although they aren't followed, the length is still set. There were a couple of other changes needed to enable these tests on TBv2 that aren't worth their own issues and PRs, I sneaked them in here. Extra changes: - Added `Pointer` and `Reference` to TopoSorter so they generate `NameProvider` instances. It might be worth visiting the graph differently for `NameProvider` as it requires so many instances that others generators do not. Will consider that in the future. - Follow typedefs when calculating exclusive size for a type. Closes #458. Test plan: - CI - Enabled previously disabled tests.
348 lines
11 KiB
TOML
348 lines
11 KiB
TOML
includes = ["vector"]
|
|
|
|
definitions = '''
|
|
struct PrimitivePtrs {
|
|
int a;
|
|
int *b;
|
|
void *c; // No dynamic size, we can't know what it points to!
|
|
};
|
|
|
|
struct VectorPtr {
|
|
std::vector<int> *vec;
|
|
};
|
|
'''
|
|
|
|
[cases]
|
|
[cases.int]
|
|
skip = "top-level pointers are skipped over" # https://github.com/facebookexperimental/object-introspection/issues/19
|
|
param_types = ["int*"]
|
|
setup = "return new int(1);"
|
|
features = ["chase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"typeName": "int *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 4,
|
|
"NOT": {"pointer": 0},
|
|
"members": [
|
|
{
|
|
"typeName": "int",
|
|
"staticSize": 4,
|
|
"dynamicSize": 0
|
|
}
|
|
]
|
|
}]'''
|
|
[cases.int_no_follow]
|
|
skip = "top-level pointers are skipped over" # https://github.com/facebookexperimental/object-introspection/issues/19
|
|
param_types = ["int*"]
|
|
setup = "return new int(1);"
|
|
expect_json = '''[{
|
|
"typeName": "int *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 0,
|
|
"NOT": {"pointer": 0},
|
|
"NOT": "members"
|
|
}]'''
|
|
[cases.int_null]
|
|
skip = "top-level pointers are skipped over" # https://github.com/facebookexperimental/object-introspection/issues/19
|
|
param_types = ["int*"]
|
|
setup = "return nullptr;"
|
|
expect_json = '''[{
|
|
"typeName": "int *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 0,
|
|
"pointer": 0,
|
|
"NOT": "members"
|
|
}]'''
|
|
|
|
|
|
[cases.void]
|
|
skip = "top-level pointers are skipped over" # https://github.com/facebookexperimental/object-introspection/issues/19
|
|
param_types = ["void*"]
|
|
setup = "return new int(1);"
|
|
features = ["chase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"typeName": "void *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 0,
|
|
"NOT": {"pointer": 0},
|
|
"NOT": "members"
|
|
}]'''
|
|
[cases.void_no_follow]
|
|
skip = "top-level pointers are skipped over" # https://github.com/facebookexperimental/object-introspection/issues/19
|
|
param_types = ["void*"]
|
|
setup = "return new int(1);"
|
|
expect_json = '''[{
|
|
"typeName": "void *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 0,
|
|
"NOT": {"pointer": 0},
|
|
"NOT": "members"
|
|
}]'''
|
|
[cases.void_null]
|
|
skip = "top-level pointers are skipped over" # https://github.com/facebookexperimental/object-introspection/issues/19
|
|
param_types = ["void*"]
|
|
setup = "return nullptr;"
|
|
expect_json = '''[{
|
|
"typeName": "void *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 0,
|
|
"pointer": 0,
|
|
"NOT": "members"
|
|
}]'''
|
|
|
|
|
|
[cases.vector]
|
|
skip = "top-level pointers are skipped over" # https://github.com/facebookexperimental/object-introspection/issues/19
|
|
param_types = ["std::vector<int>*"]
|
|
setup = "return new std::vector<int>{1,2,3};"
|
|
features = ["chase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"typeName": "std::vector<int> *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 36,
|
|
"NOT": {"pointer": 0},
|
|
"members": [
|
|
{
|
|
"typeName": "std::vector<int>",
|
|
"staticSize": 24,
|
|
"dynamicSize": 12
|
|
}
|
|
]
|
|
}]'''
|
|
[cases.vector_no_follow]
|
|
skip = "top-level pointers are skipped over" # https://github.com/facebookexperimental/object-introspection/issues/19
|
|
param_types = ["std::vector<int>*"]
|
|
setup = "return new std::vector<int>{1,2,3};"
|
|
expect_json = '''[{
|
|
"typeName": "std::vector<int> *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 0,
|
|
"NOT": {"pointer": 0},
|
|
"NOT": "members"
|
|
}]'''
|
|
[cases.vector_null]
|
|
skip = "BAD DATA SEGMENT!!! top-level pointers are skipped over" # https://github.com/facebookexperimental/object-introspection/issues/19
|
|
param_types = ["std::vector<int>*"]
|
|
setup = "return nullptr;"
|
|
expect_json = '''[{
|
|
"typeName": "std::vector<int> *",
|
|
"staticSize": 8,
|
|
"dynamicSize": 0,
|
|
"pointer": 0,
|
|
"NOT": "members"
|
|
}]'''
|
|
|
|
|
|
[cases.struct_primitive_ptrs]
|
|
param_types = ["const PrimitivePtrs&"]
|
|
setup = "return PrimitivePtrs{0, new int(0), new int(0)};"
|
|
features = ["chase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"staticSize":24,
|
|
"dynamicSize":4,
|
|
"exclusiveSize":4,
|
|
"members":[
|
|
{"name":"a", "staticSize":4, "exclusiveSize":4, "dynamicSize":0},
|
|
{"name":"b", "staticSize":8, "exclusiveSize":8, "dynamicSize":4},
|
|
{"name":"c", "staticSize":8, "exclusiveSize":8, "dynamicSize":0}
|
|
]}]'''
|
|
expect_json_v2 = '''[{
|
|
"staticSize":24,
|
|
"exclusiveSize":4,
|
|
"size":28,
|
|
"members":[
|
|
{"name":"a", "typeNames":["int32_t"], "staticSize":4, "exclusiveSize":4, "size":4},
|
|
{"name":"b", "typeNames":["int32_t*"], "staticSize":8, "exclusiveSize":8, "size":12, "capacity":1, "length":1},
|
|
{"name":"c", "typeNames":["void*"], "staticSize":8, "exclusiveSize":8, "size":8, "capacity":1, "length":1}
|
|
]
|
|
}]'''
|
|
[cases.struct_primitive_ptrs_no_follow]
|
|
param_types = ["const PrimitivePtrs&"]
|
|
setup = "return PrimitivePtrs{0, new int(0), new int(0)};"
|
|
expect_json = '''[{
|
|
"staticSize":24,
|
|
"dynamicSize":0,
|
|
"exclusiveSize":4,
|
|
"size":24,
|
|
"members":[
|
|
{"name":"a", "staticSize":4, "dynamicSize":0, "exclusiveSize":4, "size":4},
|
|
{"name":"b", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8},
|
|
{"name":"c", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8}
|
|
]}]'''
|
|
[cases.struct_primitive_ptrs_null]
|
|
param_types = ["const PrimitivePtrs&"]
|
|
setup = "return PrimitivePtrs{0, nullptr, nullptr};"
|
|
features = ["chase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"staticSize":24,
|
|
"dynamicSize":0,
|
|
"exclusiveSize":4,
|
|
"size":24,
|
|
"members":[
|
|
{"name":"a", "staticSize":4, "dynamicSize":0, "exclusiveSize":4, "size":4},
|
|
{"name":"b", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8},
|
|
{"name":"c", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8}
|
|
]}]'''
|
|
expect_json_v2 = '''[{
|
|
"staticSize":24,
|
|
"exclusiveSize":4,
|
|
"size":24,
|
|
"members":[
|
|
{"name":"a", "typeNames":["int32_t"], "staticSize":4, "exclusiveSize":4, "size":4},
|
|
{"name":"b", "typeNames":["int32_t*"], "staticSize":8, "exclusiveSize":8, "size":8, "capacity":1, "length":0},
|
|
{"name":"c", "typeNames":["void*"], "staticSize":8, "exclusiveSize":8, "size":8, "capacity":1, "length":0}
|
|
]
|
|
}]'''
|
|
|
|
|
|
[cases.struct_vector_ptr]
|
|
param_types = ["const VectorPtr&"]
|
|
setup = "return VectorPtr{new std::vector<int>{1,2,3}};"
|
|
features = ["chase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"staticSize":8,
|
|
"dynamicSize":36,
|
|
"members":[
|
|
{"name":"vec", "staticSize":8, "dynamicSize":36}
|
|
]}]'''
|
|
expect_json_v2 = '''[{
|
|
"staticSize":8,
|
|
"exclusiveSize":0,
|
|
"size":44,
|
|
"members": [
|
|
{
|
|
"typeNames":["std::vector<int32_t, std::allocator<int32_t>>*"],
|
|
"staticSize":8,
|
|
"exclusiveSize":8,
|
|
"size":44,
|
|
"length":1,
|
|
"capacity":1,
|
|
"members":[{ "staticSize":24, "exclusiveSize":24, "size":36 }]
|
|
}
|
|
]
|
|
}]'''
|
|
[cases.struct_vector_ptr_no_follow]
|
|
param_types = ["const VectorPtr&"]
|
|
setup = "return VectorPtr{new std::vector<int>{1,2,3}};"
|
|
expect_json = '''[{
|
|
"staticSize":8,
|
|
"dynamicSize":0,
|
|
"exclusiveSize":0,
|
|
"size":8,
|
|
"members":[
|
|
{"name":"vec", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8}
|
|
]}]'''
|
|
[cases.struct_vector_ptr_null]
|
|
param_types = ["const VectorPtr&"]
|
|
setup = "return VectorPtr{nullptr};"
|
|
features = ["chase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"staticSize":8,
|
|
"dynamicSize":0,
|
|
"exclusiveSize":0,
|
|
"size":8,
|
|
"members":[
|
|
{"name":"vec", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8}
|
|
]}]'''
|
|
expect_json_v2 = '''[{
|
|
"staticSize":8,
|
|
"exclusiveSize":0,
|
|
"size":8,
|
|
"members": [
|
|
{
|
|
"typeNames":["std::vector<int32_t, std::allocator<int32_t>>*"],
|
|
"staticSize":8,
|
|
"exclusiveSize":8,
|
|
"size":8,
|
|
"length":0,
|
|
"capacity":1,
|
|
"members":[]
|
|
}
|
|
]
|
|
}]'''
|
|
|
|
|
|
[cases.vector_of_pointers]
|
|
param_types = ["const std::vector<int*>&"]
|
|
setup = "return {{new int(1), nullptr, new int(3)}};"
|
|
features = ["chase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"staticSize":24,
|
|
"dynamicSize":32,
|
|
"length":3,
|
|
"capacity":3,
|
|
"elementStaticSize":8,
|
|
"members":[
|
|
{"staticSize":8, "dynamicSize":4, "NOT": {"pointer":0}},
|
|
{"staticSize":8, "dynamicSize":0, "pointer":0},
|
|
{"staticSize":8, "dynamicSize":4, "NOT": {"pointer":0}}
|
|
]}]'''
|
|
expect_json_v2 = '''[{
|
|
"staticSize":24,
|
|
"exclusiveSize":24,
|
|
"size":56,
|
|
"length":3,
|
|
"capacity":3,
|
|
"members":[
|
|
{"staticSize":8, "exclusiveSize":8, "size":12, "NOT": {"pointer":0}},
|
|
{"staticSize":8, "exclusiveSize":8, "size":8, "pointer":0},
|
|
{"staticSize":8, "exclusiveSize":8, "size":12, "NOT": {"pointer":0}}
|
|
]
|
|
}]'''
|
|
[cases.vector_of_pointers_no_follow]
|
|
skip = "pointer field is missing from results" # https://github.com/facebookexperimental/object-introspection/issues/21
|
|
param_types = ["const std::vector<int*>&"]
|
|
setup = "return {{new int(1), nullptr, new int(3)}};"
|
|
expect_json = '''[{
|
|
"staticSize":24,
|
|
"dynamicSize":24,
|
|
"length":3,
|
|
"capacity":3,
|
|
"elementStaticSize":8,
|
|
"members":[
|
|
{"staticSize":8, "dynamicSize":0, "NOT": {"pointer":0}},
|
|
{"staticSize":8, "dynamicSize":0, "pointer":0},
|
|
{"staticSize":8, "dynamicSize":0, "NOT": {"pointer":0}}
|
|
]}]'''
|
|
[cases.feature_flag_disabled]
|
|
param_types = ["const PrimitivePtrs&"]
|
|
setup = "return PrimitivePtrs{0, new int(0), new int(0)};"
|
|
cli_options = ["-fchase-raw-pointers", "-Fchase-raw-pointers"]
|
|
expect_json = '''[{
|
|
"staticSize":24,
|
|
"dynamicSize":0,
|
|
"exclusiveSize":4,
|
|
"size":24,
|
|
"members":[
|
|
{"name":"a", "staticSize":4, "dynamicSize":0, "exclusiveSize":4, "size":4},
|
|
{"name":"b", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8},
|
|
{"name":"c", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8}
|
|
]}]'''
|
|
[cases.feature_config]
|
|
param_types = ["const std::vector<int*>&"]
|
|
setup = "return {{new int(1), nullptr, new int(3)}};"
|
|
config_prefix = 'features = ["chase-raw-pointers"]'
|
|
expect_json = '''[{
|
|
"staticSize":24,
|
|
"dynamicSize":32,
|
|
"length":3,
|
|
"capacity":3,
|
|
"elementStaticSize":8,
|
|
"members":[
|
|
{"staticSize":8, "dynamicSize":4, "NOT": {"pointer":0}},
|
|
{"staticSize":8, "dynamicSize":0, "pointer":0},
|
|
{"staticSize":8, "dynamicSize":4, "NOT": {"pointer":0}}
|
|
]}]'''
|
|
expect_json_v2 = '''[{
|
|
"staticSize":24,
|
|
"exclusiveSize":24,
|
|
"size":56,
|
|
"length":3,
|
|
"capacity":3,
|
|
"members":[
|
|
{"staticSize":8, "exclusiveSize":8, "size":12, "NOT": {"pointer":0}},
|
|
{"staticSize":8, "exclusiveSize":8, "size":8, "pointer":0},
|
|
{"staticSize":8, "exclusiveSize":8, "size":12, "NOT": {"pointer":0}}
|
|
]
|
|
}]'''
|