From 766ee8fff19d1d1eb5a0ce4ebc449497f092b0b9 Mon Sep 17 00:00:00 2001 From: lirismankarina Date: Thu, 22 May 2025 19:15:36 +0300 Subject: [PATCH] Removed as folding from CEL Signed-off-by: lirismankarina --- .../ets/constantExpressionLowering.cpp | 54 ------------------- 1 file changed, 54 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index 7004f13dd0..a608172af3 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -219,12 +219,6 @@ static bool IsSupportedLiteral(ir::Expression *const node) literal->IsStringLiteral() || literal->IsUndefinedLiteral() || literal->IsNullLiteral(); } -static bool IsStringTypeReference(ir::ETSTypeReference *type) -{ - auto name = type->Part()->GetIdent()->Name(); - return name == "string" || name == "String"; -} - template static ir::AstNode *CommonCastNumberLiteralTo(const ir::Literal *num, ArenaAllocator *allocator) { @@ -1126,48 +1120,6 @@ static ir::AstNode *FoldUnaryExpression(const ir::UnaryExpression *unary, public return CreateErrorIdentifier(unary, context->allocator); } -static ir::AstNode *TryFoldTSAsExpressionForString(ir::TSAsExpression *expr) -{ - if (expr->Expr()->IsStringLiteral() && expr->TypeAnnotation()->IsETSTypeReference() && - IsStringTypeReference(expr->TypeAnnotation()->AsETSTypeReference())) { - auto res = expr->Expr()->AsStringLiteral(); - res->SetParent(expr->Parent()); - res->SetRange(expr->Range()); - return res; - } - return expr; -} - -static ir::AstNode *FoldTSAsExpression(ir::TSAsExpression *const expr, ArenaAllocator *allocator) -{ - // For correct type inference, don't remove explicit type cast for array elements: - // [1 as int] should be inferred as int[], otherwise ([1]) it will be inferred as number[] - if (expr->TypeAnnotation()->IsETSPrimitiveType() && !expr->Parent()->IsArrayExpression()) { - auto *srcLit = expr->Expr()->AsLiteral(); - switch (expr->TypeAnnotation()->AsETSPrimitiveType()->GetPrimitiveType()) { - case ir::PrimitiveType::CHAR: - return CreateCharLiteral(CastValTo(srcLit), expr->Parent(), expr->Range(), allocator); - case ir::PrimitiveType::BOOLEAN: - return CreateBooleanLiteral(CastValTo(srcLit), expr->Parent(), expr->Range(), allocator); - case ir::PrimitiveType::BYTE: - return CreateNumberLiteral(CastValTo(srcLit), expr->Parent(), expr->Range(), allocator); - case ir::PrimitiveType::SHORT: - return CreateNumberLiteral(CastValTo(srcLit), expr->Parent(), expr->Range(), allocator); - case ir::PrimitiveType::INT: - return CreateNumberLiteral(CastValTo(srcLit), expr->Parent(), expr->Range(), allocator); - case ir::PrimitiveType::LONG: - return CreateNumberLiteral(CastValTo(srcLit), expr->Parent(), expr->Range(), allocator); - case ir::PrimitiveType::FLOAT: - return CreateNumberLiteral(CastValTo(srcLit), expr->Parent(), expr->Range(), allocator); - case ir::PrimitiveType::DOUBLE: - return CreateNumberLiteral(CastValTo(srcLit), expr->Parent(), expr->Range(), allocator); - default: - ES2PANDA_UNREACHABLE(); - } - } - return TryFoldTSAsExpressionForString(expr); -} - static ir::AstNode *FoldTemplateLiteral(ir::TemplateLiteral *expr, ArenaAllocator *allocator) { auto litToString = [allocator](const ir::Literal *lit) { @@ -1398,12 +1350,6 @@ ir::AstNode *ConstantExpressionLowering::Fold(ir::AstNode *constantNode) } return FoldTemplateLiteral(tmpLiteral, context_->allocator); } - if (node->IsTSAsExpression()) { - auto tsAsExpr = node->AsTSAsExpression(); - if (IsSupportedLiteral(tsAsExpr->Expr())) { - return FoldTSAsExpression(tsAsExpr, context_->allocator); - } - } if (node->IsUnaryExpression()) { auto unaryOp = node->AsUnaryExpression(); if (IsSupportedLiteral(unaryOp->Argument())) { -- Gitee