TypeGraphv2: correctly handle bitfields in code generation (#495)

Currently in TypeGraph when generating inst::Field objects in the
generated source we use the `sizeof` operator to construct the static
and exclusive size. As you can't use sizeof() on a bitfield this
generates invalid code. This fix special cases bit fields and sets the
static and exclusive size to 0 as there size will be rolled up in the
parent object.
This commit is contained in:
Jon Haslam 2024-04-23 14:56:09 +01:00 committed by GitHub
parent 479545d4b8
commit 3513f9580a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -822,16 +822,23 @@ void CodeGen::genClassTreeBuilderInstructions(const Class& c,
code += std::to_string(numFields);
code += "> fields{\n";
index = 0;
for (const auto& m : c.members) {
++index;
if (m.name.starts_with(AddPadding::MemberPrefix))
continue;
std::string fullName = c.name() + "::" + m.name;
bool isbitField = m.bitsize;
bool isPrimitive = dynamic_cast<const Primitive*>(&m.type());
if (!isbitField) {
code += " inst::Field{sizeof(";
code += fullName;
code += "), ";
code += std::to_string(calculateExclusiveSize(m.type()));
} else {
code += " inst::Field{0, 0";
}
code += ", \"";
code += m.inputName;
code += "\", member_";