ignore fully qualified types

This commit is contained in:
Jon Haslam 2024-02-07 07:41:52 -08:00 committed by Facebook Community Bot
parent 89b230395f
commit 7103680894
4 changed files with 211 additions and 16 deletions

View File

@ -30,7 +30,7 @@ workflows:
requires: requires:
- build-clang - build-clang
# Tests disabled due to bad DWARF generated by the old clang compiler in CI # Tests disabled due to bad DWARF generated by the old clang compiler in CI
exclude_regex: ".*inheritance_polymorphic.*|.*arrays_member_int0|.*fbstring.*|.*std_string_*|.*multi_arg_tb_.*|.*ignored_a|OilIntegration.fbstring_.*|OilIntegration.capture_keys_string|OilIntegration.capture_keys_multi_level" exclude_regex: ".*inheritance_polymorphic.*|.*arrays_member_int0|.*fbstring.*|.*std_string_*|.*multi_arg_tb_.*|.*ignored_member|OilIntegration.fbstring_.*|OilIntegration.capture_keys_string|OilIntegration.capture_keys_multi_level"
executors: executors:
nix-docker: nix-docker:

View File

@ -61,7 +61,7 @@ void RemoveMembers::visit(Class& c) {
} }
std::erase_if(c.members, [this, &c](Member member) { std::erase_if(c.members, [this, &c](Member member) {
if (ignoreMember(c.name(), member.name)) if (ignoreMember(c.inputName(), member.name))
return true; return true;
if (dynamic_cast<Incomplete*>(&member.type())) if (dynamic_cast<Incomplete*>(&member.type()))
return true; return true;
@ -69,10 +69,11 @@ void RemoveMembers::visit(Class& c) {
}); });
} }
bool RemoveMembers::ignoreMember(const std::string& typeName, bool RemoveMembers::ignoreMember(std::string_view typeName,
const std::string& memberName) const { const std::string& memberName) const {
for (const auto& [ignoredType, ignoredMember] : membersToIgnore_) { for (const auto& [ignoredType, ignoredMember] : membersToIgnore_) {
if (typeName == ignoredType && memberName == ignoredMember) { if (typeName == ignoredType &&
(memberName == ignoredMember || ignoredMember == "*")) {
return true; return true;
} }
} }

View File

@ -47,7 +47,7 @@ class RemoveMembers : public RecursiveVisitor {
void visit(Class& c) override; void visit(Class& c) override;
private: private:
bool ignoreMember(const std::string& typeName, bool ignoreMember(std::string_view typeName,
const std::string& memberName) const; const std::string& memberName) const;
std::unordered_set<Type*> visited_; std::unordered_set<Type*> visited_;

View File

@ -6,11 +6,15 @@ definitions = '''
struct Bar { struct Bar {
std::string a, b, c; std::string a, b, c;
}; };
struct FooBar {
Foo a;
Bar b;
};
''' '''
[cases] [cases]
[cases.a] [cases.roottype]
skip = 'v2 hides the member entirely when it should show it with static size' # todo: github issue
param_types = ["const Bar&"] param_types = ["const Bar&"]
setup = """ setup = """
return Bar{ return Bar{
@ -21,18 +25,208 @@ definitions = '''
""" """
config_suffix = """ config_suffix = """
[[codegen.ignore]] [[codegen.ignore]]
type = "Foo" type = "ns_ignored::Bar"
"""
expect_json_v2 = '''[{
"staticSize":96,
"exclusiveSize":96,
"members":[]
}]'''
expect_json ='''
[
{
"name": "a0",
"typePath": "a0",
"typeName": "ns_ignored::Bar",
"isTypedef": false,
"staticSize": 96,
"dynamicSize": 0,
"exclusiveSize": 96
}
]
'''
[cases.subtype]
param_types = ["const FooBar&"]
setup = """
return FooBar{
{ 1, 2, 3}, {
"The first member of the struct Bar",
"The second member of the struct Bar",
"The 3rd member of the struct Bar"
}} ;
"""
config_suffix = """
[[codegen.ignore]]
type = "ns_ignored::Bar"
"""
expect_json_v2 = '''[{
"staticSize":112,
"exclusiveSize":4,
"members":[
{
"name": "a",
"staticSize": 12,
"exclusiveSize": 0,
"members": [
{ "name":"a", "staticSize":4, "exclusiveSize":4 },
{ "name":"b", "staticSize":4, "exclusiveSize":4 },
{ "name":"c", "staticSize":4, "exclusiveSize":4 }
]
},
{
"name":"b",
"staticSize":96,
"exclusiveSize":96
}
]}]'''
expect_json = '''
[
{
"name": "a0",
"typePath": "a0",
"typeName": "ns_ignored::FooBar",
"isTypedef": false,
"staticSize": 112,
"dynamicSize": 0,
"exclusiveSize": 4,
"members": [
{
"name": "a",
"typePath": "a",
"typeName": "ns_ignored::Foo",
"isTypedef": false,
"staticSize": 12,
"dynamicSize": 0,
"exclusiveSize": 0,
"members": [
{
"name": "a",
"typePath": "a",
"typeName": "int32_t",
"isTypedef": false,
"staticSize": 4,
"dynamicSize": 0,
"exclusiveSize": 4
},
{
"name": "b",
"typePath": "b",
"typeName": "int32_t",
"isTypedef": false,
"staticSize": 4,
"dynamicSize": 0,
"exclusiveSize": 4
},
{
"name": "c",
"typePath": "c",
"typeName": "int32_t",
"isTypedef": false,
"staticSize": 4,
"dynamicSize": 0,
"exclusiveSize": 4
}
]
},
{
"name": "b",
"typePath": "b",
"typeName": "ns_ignored::Bar",
"isTypedef": false,
"staticSize": 96,
"dynamicSize": 0,
"exclusiveSize": 96
}
]
}
]
'''
[cases.member]
param_types = ["const Bar&"]
setup = """
return Bar{
"The first member of the struct Bar",
"The second member of the struct Bar",
"The 3rd member of the struct Bar"
};
"""
config_suffix = """
[[codegen.ignore]]
type = "ns_ignored::Bar"
members = ["a"] members = ["a"]
[[codegen.ignore]]
type = "Bar"
members = ["b"]
""" """
expect_json = '''[{ expect_json_v2 = '''[{
"staticSize":96, "staticSize":96,
"dynamicSize":66, "exclusiveSize":32,
"members":[ "members":[
{"name":"a", "staticSize":32, "dynamicSize":34}, { "name":"b", "staticSize":32, "exclusiveSize":67 },
{"name":"b", "staticSize":32, "dynamicSize":0}, { "name":"c", "staticSize":32, "exclusiveSize":64 }
{"name":"c", "staticSize":32, "dynamicSize":32}
]}]''' ]}]'''
expect_json = '''
[
{
"staticSize": 96,
"dynamicSize": 67,
"exclusiveSize": 32,
"members": [
{
"name": "b",
"typePath": "b",
"typeName": "string",
"isTypedef": true,
"staticSize": 32,
"dynamicSize": 35,
"exclusiveSize": 0,
"members": [
{
"name": "",
"typePath": "",
"typeName": "std::__cxx11::basic_string<int8_t, std::char_traits<int8_t>, std::allocator<int8_t>>",
"isTypedef": false,
"staticSize": 32,
"dynamicSize": 35,
"exclusiveSize": 67,
"length": 35,
"capacity": 35,
"elementStaticSize": 1
}
]
},
{
"name": "c",
"typePath": "c",
"typeName": "string",
"isTypedef": true,
"staticSize": 32,
"dynamicSize": 32,
"exclusiveSize": 0,
"members": [
{
"name": "",
"typePath": "",
"typeName": "std::__cxx11::basic_string<int8_t, std::char_traits<int8_t>, std::allocator<int8_t>>",
"isTypedef": false,
"staticSize": 32,
"dynamicSize": 32,
"exclusiveSize": 64,
"length": 32,
"capacity": 32,
"elementStaticSize": 1
}
]
}
]
}
]
'''