patterns: Added padding expressions in bitfields.

Closes #326
This commit is contained in:
WerWolv 2021-10-14 20:28:13 +02:00
parent a4c5d0bb62
commit 3e5d6cf88c
2 changed files with 9 additions and 5 deletions

View File

@ -1334,11 +1334,14 @@ namespace hex::pl {
[](auto &&offset) -> u8 { return static_cast<u8>(offset); } [](auto &&offset) -> u8 { return static_cast<u8>(offset); }
}, dynamic_cast<ASTNodeLiteral*>(literal)->getValue()); }, dynamic_cast<ASTNodeLiteral*>(literal)->getValue());
auto field = new PatternDataBitfieldField(evaluator->dataOffset(), bitOffset, bitSize, evaluator); // If a field is named padding, it was created through a padding expression and only advances the bit position
field->setVariableName(name); if (name != "padding") {
auto field = new PatternDataBitfieldField(evaluator->dataOffset(), bitOffset, bitSize, evaluator);
field->setVariableName(name);
fields.push_back(field);
}
bitOffset += bitSize; bitOffset += bitSize;
fields.push_back(field);
} }
evaluator->popScope(); evaluator->popScope();

View File

@ -986,8 +986,9 @@ namespace hex::pl {
if (MATCHES(sequence(IDENTIFIER, OPERATOR_INHERIT))) { if (MATCHES(sequence(IDENTIFIER, OPERATOR_INHERIT))) {
auto name = getValue<Token::Identifier>(-2).get(); auto name = getValue<Token::Identifier>(-2).get();
bitfieldNode->addEntry(name, parseMathematicalExpression()); bitfieldNode->addEntry(name, parseMathematicalExpression());
} } else if (MATCHES(sequence(VALUETYPE_PADDING, OPERATOR_INHERIT))) {
else if (MATCHES(sequence(SEPARATOR_ENDOFPROGRAM))) bitfieldNode->addEntry("padding", parseMathematicalExpression());
} else if (MATCHES(sequence(SEPARATOR_ENDOFPROGRAM)))
throwParseError("unexpected end of program", -2); throwParseError("unexpected end of program", -2);
else else
throwParseError("invalid bitfield member", 0); throwParseError("invalid bitfield member", 0);