From 56330686be55e5ccb67cf8ba355f4532335ee3b7 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 8 Jan 2021 11:58:07 +0100 Subject: [PATCH] Fixed crash when creating an enum --- source/lang/parser.cpp | 49 ++++++------------------------------------ 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/source/lang/parser.cpp b/source/lang/parser.cpp index d0e40917a..8043c21d6 100644 --- a/source/lang/parser.cpp +++ b/source/lang/parser.cpp @@ -462,53 +462,18 @@ namespace hex::lang { while (!MATCHES(sequence(SEPARATOR_CURLYBRACKETCLOSE))) { if (MATCHES(sequence(IDENTIFIER, OPERATOR_ASSIGNMENT))) { auto name = getValue(-2); - enumNode->addEntry(name, parseMathematicalExpression()); + auto value = parseMathematicalExpression(); + + enumNode->addEntry(name, value); + lastEntry = value; } else if (MATCHES(sequence(IDENTIFIER))) { ASTNode *valueExpr; auto name = getValue(-1); - if (enumNode->getEntries().empty()) { - auto type = underlyingType->getType(); - - switch (type) { - case Token::ValueType::Signed8Bit: - valueExpr = new ASTNodeIntegerLiteral({ type, s8(0) }); - break; - case Token::ValueType::Unsigned8Bit: - valueExpr = new ASTNodeIntegerLiteral({ type, u8(0) }); - break; - case Token::ValueType::Signed16Bit: - valueExpr = new ASTNodeIntegerLiteral({ type, s16(0) }); - break; - case Token::ValueType::Unsigned16Bit: - valueExpr = new ASTNodeIntegerLiteral({ type, u16(0) }); - break; - case Token::ValueType::Signed32Bit: - valueExpr = new ASTNodeIntegerLiteral({ type, s32(0) }); - break; - case Token::ValueType::Unsigned32Bit: - valueExpr = new ASTNodeIntegerLiteral({ type, u32(0) }); - break; - case Token::ValueType::Signed64Bit: - valueExpr = new ASTNodeIntegerLiteral({ type, s64(0) }); - break; - case Token::ValueType::Unsigned64Bit: - valueExpr = new ASTNodeIntegerLiteral({ type, u64(0) }); - break; - case Token::ValueType::Signed128Bit: - valueExpr = new ASTNodeIntegerLiteral({ type, s128(0) }); - break; - case Token::ValueType::Unsigned128Bit: - valueExpr = new ASTNodeIntegerLiteral({ type, u128(0) }); - break; - default: - throwParseError("invalid enum underlying type", -1); - } - - lastEntry = valueExpr; - } + if (enumNode->getEntries().empty()) + lastEntry = TO_NUMERIC_EXPRESSION(new ASTNodeIntegerLiteral({ Token::ValueType::Unsigned8Bit, u8(0) })); else - valueExpr = new ASTNodeNumericExpression(lastEntry, new ASTNodeIntegerLiteral({ Token::ValueType::Signed32Bit, s32(1) }), Token::Operator::Plus); + valueExpr = new ASTNodeNumericExpression(lastEntry->clone(), new ASTNodeIntegerLiteral({ Token::ValueType::Signed32Bit, s32(1) }), Token::Operator::Plus); enumNode->addEntry(name, valueExpr); }