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 sizeNode = dynamic_cast<ASTNodeNumericExpression*>(node->getSize());
|
||||
if (sizeNode == nullptr)
|
||||
ASTNodeIntegerLiteral *valueNode;
|
||||
|
||||
if (auto sizeNumericExpression = dynamic_cast<ASTNodeNumericExpression*>(node->getSize()); sizeNumericExpression != nullptr)
|
||||
valueNode = evaluateMathematicalExpression(sizeNumericExpression);
|
||||
else
|
||||
throwEvaluateError("array size not a numeric expression", node->getLineNumber());
|
||||
|
||||
auto valueNode = evaluateMathematicalExpression(sizeNode);
|
||||
SCOPE_EXIT( delete valueNode; );
|
||||
|
||||
auto arraySize = std::get<s128>(valueNode->getValue());
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
#define MATCHES(x) (begin() && x)
|
||||
|
||||
#define TO_NUMERIC_EXPRESSION(node) new ASTNodeNumericExpression((node), new ASTNodeIntegerLiteral(0, Token::ValueType::Signed128Bit), Token::Operator::Plus)
|
||||
|
||||
// Definition syntax:
|
||||
// [A] : Either A or no token
|
||||
// [A|B] : Either A, B or no token
|
||||
@ -27,13 +29,13 @@ namespace hex::lang {
|
||||
else
|
||||
throwParseError("expected member name", -1);
|
||||
} else
|
||||
return new ASTNodeRValue(path);
|
||||
return TO_NUMERIC_EXPRESSION(new ASTNodeRValue(path));
|
||||
}
|
||||
|
||||
// <Integer|((parseMathematicalExpression))>
|
||||
ASTNode* Parser::parseFactor() {
|
||||
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))) {
|
||||
auto node = this->parseMathematicalExpression();
|
||||
if (!MATCHES(sequence(SEPARATOR_ROUNDBRACKETCLOSE)))
|
||||
|
Loading…
Reference in New Issue
Block a user