From 33ee85c1224ca5b699afe3997696a236330d4c0f Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 3 Jun 2026 12:10:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Php):=20=E6=9B=B4=E6=96=B0=E6=95=B0?= =?UTF-8?q?=E5=80=BC=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 php::newBigInt() 替换为 php::toBigInt() - 将 php::newDecimal() 替换为 php::toDecimal() - 将 php::newBigFloat() 替换为 php::toBigFloat() - 移除不再使用的 mpdec++ 和 mpdec 库依赖 --- src/Php/CompilerBase.php | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 4d1819b5..588f31af 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1214,17 +1214,17 @@ class CompilerBase extends \PhpAot\Core\Translator switch ($type) { case 'Scalar_Int': if ($this->bigintTypes) { - return 'php::newBigInt(' . $expr->value . ')'; + return 'php::toBigInt(' . $expr->value . ')'; } return $expr->value . $this->getPlatform()->getIntegerLiteralSuffix(); case 'Scalar_Float': if ($this->isBigIntLiteral($expr)) { - return 'php::newBigInt(' . $this->getLiteralString($this->getBigIntLiteralString($expr)) . ')'; + return 'php::toBigInt(' . $this->getLiteralString($this->getBigIntLiteralString($expr)) . ')'; } if ($this->isDecimalLiteral($expr) || $this->decimalTypes) { $rawValue = $expr->getAttribute('rawValue'); $clean = $rawValue !== null ? $this->stripNumericUnderscores($rawValue) : (string) $expr->value; - return 'php::newDecimal(' . $this->getLiteralString($clean) . ')'; + return 'php::toDecimal(' . $this->getLiteralString($clean) . ')'; } return $this->parseScalarFloat($expr); case 'Scalar_String': @@ -2859,8 +2859,6 @@ class CompilerBase extends \PhpAot\Core\Translator $libraries[] = 'gmp'; $libraries[] = 'gmpxx'; $libraries[] = 'mpfr'; - $libraries[] = 'mpdec++'; - $libraries[] = 'mpdec'; } return $libraries; @@ -3992,21 +3990,21 @@ class CompilerBase extends \PhpAot\Core\Translator if ($node instanceof Node\Scalar\Float_) { $rawValue = $node->getAttribute('rawValue'); $clean = $rawValue !== null ? $this->stripNumericUnderscores($rawValue) : (string) $node->value; - return 'php::newDecimal(' . $this->getLiteralString($clean) . ')'; + return 'php::toDecimal(' . $this->getLiteralString($clean) . ')'; } $this->fatalError($node, 'Cannot convert float expression to Decimal, use a literal value or string instead'); } if ($fromType === self::TYPE_STR) { if ($node instanceof Node\Scalar\String_) { - return 'php::newDecimal(' . $this->getLiteralString($node->value) . ')'; + return 'php::toDecimal(' . $this->getLiteralString($node->value) . ')'; } - return 'php::newDecimal(php::toString(' . $this->trimBrackets($expr) . '))'; + return 'php::toDecimal(php::toString(' . $this->trimBrackets($expr) . '))'; } if ($fromType === self::TYPE_INT) { - return 'php::newDecimal(php::toString(' . $this->trimBrackets($expr) . '))'; + return 'php::toDecimal(php::toString(' . $this->trimBrackets($expr) . '))'; } if ($fromType === self::TYPE_BIGINT) { - return 'php::newDecimal(php::BigInt::toString(' . $this->trimBrackets($expr) . '))'; + return 'php::toDecimal(php::BigInt::toString(' . $this->trimBrackets($expr) . '))'; } return $expr; } @@ -4014,13 +4012,13 @@ class CompilerBase extends \PhpAot\Core\Translator protected function convertBigIntExpr(string $expr, string $fromType = ''): string { if ($fromType === self::TYPE_INT) { - return 'php::newBigInt(' . $this->trimBrackets($expr) . ')'; + return 'php::toBigInt(' . $this->trimBrackets($expr) . ')'; } if ($fromType === self::TYPE_FLOAT) { $this->fatalError(null, 'Cannot convert float to BigInt, use string or int instead'); } if ($fromType === self::TYPE_STR) { - return 'php::newBigInt(php::toString(' . $this->trimBrackets($expr) . '))'; + return 'php::toBigInt(php::toString(' . $this->trimBrackets($expr) . '))'; } return $expr; } @@ -4028,13 +4026,13 @@ class CompilerBase extends \PhpAot\Core\Translator protected function convertBigFloatExpr(string $expr, string $fromType = ''): string { if ($fromType === self::TYPE_INT) { - return 'php::newBigFloat(' . $this->trimBrackets($expr) . ')'; + return 'php::toBigFloat(' . $this->trimBrackets($expr) . ')'; } if ($fromType === self::TYPE_FLOAT) { - return 'php::newBigFloat(' . $this->trimBrackets($expr) . ')'; + return 'php::toBigFloat(' . $this->trimBrackets($expr) . ')'; } if ($fromType === self::TYPE_STR) { - return 'php::newBigFloat(php::toString(' . $this->trimBrackets($expr) . '))'; + return 'php::toBigFloat(php::toString(' . $this->trimBrackets($expr) . '))'; } if ($fromType === self::TYPE_BIGINT) { return 'php::BigFloat::newInstance(php::BigInt::toString(' . $this->trimBrackets($expr) . '))'; @@ -6143,7 +6141,7 @@ class CompilerBase extends \PhpAot\Core\Translator $this->fatalError($expr, 'Cannot construct BigInt from float, use string or int instead'); } if ($argType === self::TYPE_INT) { - return 'php::newBigInt(' . $this->trimBrackets($valueExpr) . ')'; + return 'php::toBigInt(' . $this->trimBrackets($valueExpr) . ')'; } return 'php::BigInt::newInstance(' . $valueExpr . ')'; } @@ -6153,21 +6151,21 @@ class CompilerBase extends \PhpAot\Core\Translator if ($argNode instanceof Node\Scalar\Float_) { $rawValue = $argNode->getAttribute('rawValue'); $clean = $rawValue !== null ? $this->stripNumericUnderscores($rawValue) : (string)$argNode->value; - return 'php::newDecimal(' . $this->getLiteralString($clean) . ')'; + return 'php::toDecimal(' . $this->getLiteralString($clean) . ')'; } $this->fatalError($expr, 'Cannot construct Decimal from float variable, use string or int instead'); } if ($argType === self::TYPE_INT) { - return 'php::newDecimal(' . $this->trimBrackets($valueExpr) . ')'; + return 'php::toDecimal(' . $this->trimBrackets($valueExpr) . ')'; } return 'php::Decimal::newInstance(' . $valueExpr . ')'; } if ($type === self::TYPE_BIGFLOAT) { if ($argType === self::TYPE_INT) { - return 'php::newBigFloat(' . $this->trimBrackets($valueExpr) . ')'; + return 'php::toBigFloat(' . $this->trimBrackets($valueExpr) . ')'; } if ($argType === self::TYPE_FLOAT) { - return 'php::newBigFloat(' . $this->trimBrackets($valueExpr) . ')'; + return 'php::toBigFloat(' . $this->trimBrackets($valueExpr) . ')'; } return 'php::BigFloat::newInstance(' . $valueExpr . ')'; }