mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-12 21:56:54 +00:00
NameGen: Override inputName for anonymous members
This commit is contained in:
parent
c874f72ae2
commit
aa87c3f2d1
@ -77,8 +77,14 @@ void NameGen::visit(Class& c) {
|
||||
|
||||
// Deduplicate member names. Duplicates may be present after flattening.
|
||||
for (size_t i = 0; i < c.members.size(); i++) {
|
||||
if (c.members[i].name.empty())
|
||||
c.members[i].name = AnonPrefix;
|
||||
|
||||
c.members[i].name += "_" + std::to_string(i);
|
||||
|
||||
if (c.members[i].inputName.empty())
|
||||
c.members[i].inputName = c.members[i].name;
|
||||
|
||||
// GCC includes dots in vptr member names, e.g. "_vptr.MyClass"
|
||||
// These aren't valid in C++, so we must replace them
|
||||
std::replace(c.members[i].name.begin(), c.members[i].name.end(), '.', '$');
|
||||
|
@ -192,7 +192,6 @@ definitions = '''
|
||||
}]'''
|
||||
|
||||
[cases.anon_union]
|
||||
oil_skip = "anonymous unions are fully stubbed in the generated code" # https://github.com/facebookexperimental/object-introspection/issues/292
|
||||
param_types = ["const AnonUnionContainer&"]
|
||||
setup = 'return AnonUnionContainer{ .a = 3 };'
|
||||
cli_options = ["-fchase-raw-pointers"]
|
||||
@ -209,8 +208,8 @@ definitions = '''
|
||||
"staticSize": 24,
|
||||
"exclusiveSize": 10,
|
||||
"members": [
|
||||
{"name":"__anon_member_0", "staticSize":2, "exclusiveSize":2},
|
||||
{"name":"__anon_member_1", "staticSize":8, "exclusiveSize":8},
|
||||
{"name":"__oi_anon_0", "staticSize":2, "exclusiveSize":2},
|
||||
{"name":"__oi_anon_2", "staticSize":8, "exclusiveSize":8},
|
||||
{"name":"e", "staticSize":4, "exclusiveSize":4, "typeNames":["int32_t"]}
|
||||
]
|
||||
}]'''
|
||||
|
@ -475,3 +475,29 @@ TEST(NameGenTest, AnonymousTypes) {
|
||||
EXPECT_EQ(myenum.inputName(), "__oi_anon_1");
|
||||
EXPECT_EQ(mytypedef.inputName(), "");
|
||||
}
|
||||
|
||||
TEST(NameGenTest, AnonymousMembers) {
|
||||
auto myint = Primitive{Primitive::Kind::Int32};
|
||||
|
||||
auto myclass = Class{0, Class::Kind::Class, "C", 69};
|
||||
auto myunion1 = Class{1, Class::Kind::Union, "", 4};
|
||||
auto myunion2 = Class{2, Class::Kind::Union, "", 4};
|
||||
|
||||
myclass.members.push_back(Member{myunion1, "", 0});
|
||||
myclass.members.push_back(Member{myunion2, "", 4});
|
||||
|
||||
NameGen nameGen;
|
||||
nameGen.generateNames({myclass, myunion1, myunion2});
|
||||
|
||||
EXPECT_EQ(myclass.name(), "C_0");
|
||||
EXPECT_EQ(myunion1.name(), "__oi_anon_1");
|
||||
EXPECT_EQ(myunion2.name(), "__oi_anon_2");
|
||||
EXPECT_EQ(myclass.members[0].name, "__oi_anon_0");
|
||||
EXPECT_EQ(myclass.members[1].name, "__oi_anon_1");
|
||||
|
||||
EXPECT_EQ(myclass.inputName(), "C");
|
||||
EXPECT_EQ(myunion1.inputName(), "__oi_anon_1");
|
||||
EXPECT_EQ(myunion2.inputName(), "__oi_anon_2");
|
||||
EXPECT_EQ(myclass.members[0].inputName, "__oi_anon_0");
|
||||
EXPECT_EQ(myclass.members[1].inputName, "__oi_anon_1");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user