diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index 39e33dfc10ebb2d8464b773a8939446967ecddd8..723c8f4c9c5079b5e0d9d4e9f5f99a59acb46b94 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -465,8 +465,10 @@ static bool PerformRelationOperation(InputType left, InputType right, lexer::Tok // Compare floating point numbers in two steps: // 1. With fixed epsilon // 2. with adaptive epsilon + // Minimal possible difference between two float values + // For float (IEEE-754 binary32) it is 2^(-23) and its bit representation is 0x34000000. // CC-OFFNXT(G.FMT.03-CPP) project code style - static constexpr auto EPSILON = 1.0e-5F; + static auto EPSILON = bit_cast(0x34000000); if (std::fabs(left - right) <= EPSILON) { return true; } @@ -735,8 +737,25 @@ static ir::AstNode *PerformStringAdditiveOperation(const ir::BinaryExpression *e { auto const lhs = expr->Left()->AsLiteral(); auto const rhs = expr->Right()->AsLiteral(); - auto const resStr = util::UString(lhs->ToString() + rhs->ToString(), context->allocator).View(); - auto resNode = util::NodeAllocator::Alloc(context->allocator, resStr); + auto resStr = util::UString(context->allocator); + + auto appendLiteral = [&resStr, allocator = context->allocator](const ir::Literal *lit) { + if (lit->IsCharLiteral()) { + resStr.Append(static_cast(lit->AsCharLiteral()->Char()) & 0xFFFF); + return; + } + if (lit->IsStringLiteral()) { + // No need to create new temporary string (util::UString) for string literal + resStr.Append(lit->AsStringLiteral()->Str()); + return; + } + resStr.Append(util::UString(lit->ToString(), allocator).View()); + }; + + appendLiteral(lhs); + appendLiteral(rhs); + + auto resNode = util::NodeAllocator::Alloc(context->allocator, resStr.View()); resNode->SetParent(const_cast(expr)->Parent()); resNode->SetRange(expr->Range()); return resNode;