diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index 696f48babd22bb5cc663c0fcc299719b579eec63..494ef80d8f14a34cf5b25b7e9f8d1572c4b73f05 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -421,9 +421,6 @@ static bool TestLiteral(const ir::Literal *lit) if (lit->IsStringLiteral()) { return !lit->AsStringLiteral()->Str().Empty(); } - if (lit->IsNullLiteral() || lit->IsUndefinedLiteral()) { - return false; - } if (lit->IsCharLiteral()) { return lit->AsCharLiteral()->Char() != 0; } @@ -516,49 +513,6 @@ static ir::AstNode *HandleNumericalRelationalExpression(const ir::BinaryExpressi return CreateBooleanLiteral(res, const_cast(expr)->Parent(), expr->Range(), allocator); } -static ir::AstNode *HandleNullUndefinedRelation(const ir::BinaryExpression *expr, public_lib::Context *context) -{ - auto left = expr->Left()->AsLiteral(); - auto right = expr->Right()->AsLiteral(); - auto opType = expr->OperatorType(); - - bool isLeftNullUndefined = left->IsNullLiteral() || left->IsUndefinedLiteral(); - bool isRightNullUndefined = right->IsNullLiteral() || right->IsUndefinedLiteral(); - - // Either left operand is null/undefined or right operand is null/undefined - ES2PANDA_ASSERT(isLeftNullUndefined || isRightNullUndefined); - - auto allocator = context->allocator; - auto parent = const_cast(expr)->Parent(); - auto loc = expr->Range(); - - switch (opType) { - case lexer::TokenType::PUNCTUATOR_EQUAL: { - if ((isLeftNullUndefined && !isRightNullUndefined) || (!isLeftNullUndefined && isRightNullUndefined)) { - return CreateBooleanLiteral(false, parent, loc, allocator); - } - return CreateBooleanLiteral(true, parent, loc, allocator); - } - case lexer::TokenType::PUNCTUATOR_NOT_EQUAL: { - if ((isLeftNullUndefined && !isRightNullUndefined) || (!isLeftNullUndefined && isRightNullUndefined)) { - return CreateBooleanLiteral(true, parent, loc, allocator); - } - return CreateBooleanLiteral(false, parent, loc, allocator); - } - case lexer::TokenType::PUNCTUATOR_STRICT_EQUAL: { - // null === null and undefined === undefined are true - return CreateBooleanLiteral(left->IsNullLiteral() == right->IsNullLiteral(), parent, loc, allocator); - } - case lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL: - // null !== undefined is true - return CreateBooleanLiteral(left->IsNullLiteral() != right->IsNullLiteral(), parent, loc, allocator); - default: { - LogError(context, diagnostic::WRONG_OPERAND_TYPE_FOR_BINARY_EXPRESSION, {}, expr->Start()); - return CreateErrorIdentifier(expr, context->allocator); - } - } -} - static ir::AstNode *HandleRelationalExpression(const ir::BinaryExpression *expr, public_lib::Context *context) { auto left = expr->Left()->AsLiteral(); @@ -581,11 +535,6 @@ static ir::AstNode *HandleRelationalExpression(const ir::BinaryExpression *expr, context->allocator); } - if ((left->IsNullLiteral() || left->IsUndefinedLiteral()) || - (right->IsNullLiteral() || right->IsUndefinedLiteral())) { - return HandleNullUndefinedRelation(expr, context); - } - LogError(context, diagnostic::WRONG_OPERAND_TYPE_FOR_BINARY_EXPRESSION, {}, expr->Start()); return CreateErrorIdentifier(expr, context->allocator); } @@ -1162,12 +1111,6 @@ static ir::AstNode *FoldTemplateLiteral(ir::TemplateLiteral *expr, ArenaAllocato if (lit->IsStringLiteral()) { return lit->AsStringLiteral()->Str(); } - if (lit->IsUndefinedLiteral()) { - return util::UString(lit->AsUndefinedLiteral()->ToString(), allocator).View(); - } - if (lit->IsNullLiteral()) { - return util::UString(lit->AsNullLiteral()->ToString(), allocator).View(); - } ES2PANDA_UNREACHABLE(); }; diff --git a/ets2panda/test/unit/lowerings/const_expression.cpp b/ets2panda/test/unit/lowerings/const_expression.cpp index a371f983232f53396a34f57a8d728b8d1fcff2c0..bd975462252297af4ba86e87af941c1dd3cbd882 100644 --- a/ets2panda/test/unit/lowerings/const_expression.cpp +++ b/ets2panda/test/unit/lowerings/const_expression.cpp @@ -34,15 +34,13 @@ TEST_F(LoweringTest, TestConstantExpressionConcatExtendedBoolean1) { char const *text = R"( @interface MyAnno { - a : int c : int d : int } - @MyAnno({a = null ? 1 : 0, c = "a" ? 5 : 4, d = 12 ? 7 : 6}) + @MyAnno({c = "a" ? 5 : 4, d = 12 ? 7 : 6}) function main() {} )"; - int const expectA = 0; int const expectC = 5; int const expectD = 7; CONTEXT(ES2PANDA_STATE_CHECKED, text) @@ -52,9 +50,6 @@ TEST_F(LoweringTest, TestConstantExpressionConcatExtendedBoolean1) return node->IsBinaryExpression() || node->IsUnaryExpression() || node->IsConditionalExpression(); })); - ASSERT_TRUE( - ast->IsAnyChild([](ir::AstNode *const node) { return CheckNumberLiteral(node); })); - ASSERT_TRUE( ast->IsAnyChild([](ir::AstNode *const node) { return CheckNumberLiteral(node); })); @@ -67,15 +62,13 @@ TEST_F(LoweringTest, TestConstantExpressionConcatExtendedBoolean2) { char const *text = R"( @interface MyAnno { - a : int c : int d : int } - @MyAnno({a = undefined ? 1 : 0, c = "" ? 5 : 4, d = 0 ? 7 : 6}) + @MyAnno({c = "" ? 5 : 4, d = 0 ? 7 : 6}) function main() {} )"; - int const expectA = 0; int const expectC = 4; int const expectD = 6; CONTEXT(ES2PANDA_STATE_CHECKED, text) @@ -85,9 +78,6 @@ TEST_F(LoweringTest, TestConstantExpressionConcatExtendedBoolean2) return node->IsBinaryExpression() || node->IsUnaryExpression() || node->IsConditionalExpression(); })); - ASSERT_TRUE( - ast->IsAnyChild([](ir::AstNode *const node) { return CheckNumberLiteral(node); })); - ASSERT_TRUE( ast->IsAnyChild([](ir::AstNode *const node) { return CheckNumberLiteral(node); })); @@ -133,7 +123,7 @@ TEST_F(LoweringTest, TestConstantExpressionConcatExtendedBoolean3) a : int b : int } - @MyAnno({a = !null ? 10 : 20, b= "test" && !undefined ? 1 : 2}) + @MyAnno({a = !0 ? 10 : 20, b= "test" ? 1 : 2}) function main() {} )";