mirror of https://github.com/WerWolv/ImHex.git
Properly convert rvalue to mathematical expression
This commit is contained in:
parent
f1339f8b4a
commit
af42d2ff66
|
@ -317,11 +317,13 @@ namespace hex::lang {
|
||||||
|
|
||||||
auto startOffset = this->m_currOffset;
|
auto startOffset = this->m_currOffset;
|
||||||
|
|
||||||
auto sizeNode = dynamic_cast<ASTNodeNumericExpression*>(node->getSize());
|
ASTNodeIntegerLiteral *valueNode;
|
||||||
if (sizeNode == nullptr)
|
|
||||||
|
if (auto sizeNumericExpression = dynamic_cast<ASTNodeNumericExpression*>(node->getSize()); sizeNumericExpression != nullptr)
|
||||||
|
valueNode = evaluateMathematicalExpression(sizeNumericExpression);
|
||||||
|
else
|
||||||
throwEvaluateError("array size not a numeric expression", node->getLineNumber());
|
throwEvaluateError("array size not a numeric expression", node->getLineNumber());
|
||||||
|
|
||||||
auto valueNode = evaluateMathematicalExpression(sizeNode);
|
|
||||||
SCOPE_EXIT( delete valueNode; );
|
SCOPE_EXIT( delete valueNode; );
|
||||||
|
|
||||||
auto arraySize = std::get<s128>(valueNode->getValue());
|
auto arraySize = std::get<s128>(valueNode->getValue());
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#define MATCHES(x) (begin() && x)
|
#define MATCHES(x) (begin() && x)
|
||||||
|
|
||||||
|
#define TO_NUMERIC_EXPRESSION(node) new ASTNodeNumericExpression((node), new ASTNodeIntegerLiteral(0, Token::ValueType::Signed128Bit), Token::Operator::Plus)
|
||||||
|
|
||||||
// Definition syntax:
|
// Definition syntax:
|
||||||
// [A] : Either A or no token
|
// [A] : Either A or no token
|
||||||
// [A|B] : Either A, B or no token
|
// [A|B] : Either A, B or no token
|
||||||
|
@ -27,13 +29,13 @@ namespace hex::lang {
|
||||||
else
|
else
|
||||||
throwParseError("expected member name", -1);
|
throwParseError("expected member name", -1);
|
||||||
} else
|
} else
|
||||||
return new ASTNodeRValue(path);
|
return TO_NUMERIC_EXPRESSION(new ASTNodeRValue(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
// <Integer|((parseMathematicalExpression))>
|
// <Integer|((parseMathematicalExpression))>
|
||||||
ASTNode* Parser::parseFactor() {
|
ASTNode* Parser::parseFactor() {
|
||||||
if (MATCHES(sequence(INTEGER)))
|
if (MATCHES(sequence(INTEGER)))
|
||||||
return new ASTNodeNumericExpression(new ASTNodeIntegerLiteral(getValue<s128>(-1), Token::ValueType::Signed128Bit), new ASTNodeIntegerLiteral(0, Token::ValueType::Signed128Bit), Token::Operator::Plus);
|
return TO_NUMERIC_EXPRESSION(new ASTNodeIntegerLiteral(getValue<s128>(-1), Token::ValueType::Signed128Bit));
|
||||||
else if (MATCHES(sequence(SEPARATOR_ROUNDBRACKETOPEN))) {
|
else if (MATCHES(sequence(SEPARATOR_ROUNDBRACKETOPEN))) {
|
||||||
auto node = this->parseMathematicalExpression();
|
auto node = this->parseMathematicalExpression();
|
||||||
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
||||||
|
|
Loading…
Reference in New Issue