TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
31 lines
1.0 KiB
<?php
|
|
|
|
namespace PhpAot\Php;
|
|
|
|
use PhpParser\Node;
|
|
|
|
trait FuncCallOptimizer
|
|
{
|
|
protected function parseFuncCallWithOptimizer(string $name, Node\Expr\FuncCall $expr): string|false
|
|
{
|
|
if ($name === 'strlen' or $name === 'sizeof' or $name === 'count') {
|
|
return 'php::len(' . $this->parseIdentifier($expr->args[0]->value) . ')';
|
|
}
|
|
if (count($expr->args) == 1) {
|
|
switch ($name) {
|
|
case 'intval':
|
|
return $this->convertIntExpr($this->parseExpr($expr->args[0]->value));
|
|
case 'floatval':
|
|
return $this->convertFloatExpr($this->parseExpr($expr->args[0]->value));
|
|
case 'boolval':
|
|
return $this->convertBoolExpr($this->parseExpr($expr->args[0]->value));
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
if ($name === 'abs') {
|
|
return 'php::math::abs(' . $this->parseIdentifier($expr->args[0]->value) . ')';
|
|
}
|
|
return false;
|
|
}
|
|
} |