Skip to content

Commit

Permalink
Properly convert rvalue to mathematical expression
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jan 4, 2021
1 parent f1339f8 commit af42d2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions source/lang/evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 4 additions & 2 deletions source/lang/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
Expand Down

0 comments on commit af42d2f

Please sign in to comment.