mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-09-19 11:09:05 +01:00
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:
parent
479545d4b8
commit
3513f9580a
@ -822,17 +822,24 @@ void CodeGen::genClassTreeBuilderInstructions(const Class& c,
|
|||||||
code += std::to_string(numFields);
|
code += std::to_string(numFields);
|
||||||
code += "> fields{\n";
|
code += "> fields{\n";
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
||||||
for (const auto& m : c.members) {
|
for (const auto& m : c.members) {
|
||||||
++index;
|
++index;
|
||||||
if (m.name.starts_with(AddPadding::MemberPrefix))
|
if (m.name.starts_with(AddPadding::MemberPrefix))
|
||||||
continue;
|
continue;
|
||||||
std::string fullName = c.name() + "::" + m.name;
|
std::string fullName = c.name() + "::" + m.name;
|
||||||
|
bool isbitField = m.bitsize;
|
||||||
bool isPrimitive = dynamic_cast<const Primitive*>(&m.type());
|
bool isPrimitive = dynamic_cast<const Primitive*>(&m.type());
|
||||||
code += " inst::Field{sizeof(";
|
|
||||||
code += fullName;
|
if (!isbitField) {
|
||||||
code += "), ";
|
code += " inst::Field{sizeof(";
|
||||||
code += std::to_string(calculateExclusiveSize(m.type()));
|
code += fullName;
|
||||||
code += ",\"";
|
code += "), ";
|
||||||
|
code += std::to_string(calculateExclusiveSize(m.type()));
|
||||||
|
} else {
|
||||||
|
code += " inst::Field{0, 0";
|
||||||
|
}
|
||||||
|
code += ", \"";
|
||||||
code += m.inputName;
|
code += m.inputName;
|
||||||
code += "\", member_";
|
code += "\", member_";
|
||||||
code += std::to_string(index);
|
code += std::to_string(index);
|
||||||
|
Loading…
Reference in New Issue
Block a user