refactor(php): 优化SSA类型优化器代码结构

- 移除未使用的 Expr 导入并添加 SsaVar 导入
- 简化 detectSsaDefType 方法中的类型声明
- 移除 Foreach 和 Switch 语句中冗余的节点类型检查
- 提高代码可读性和维护性
pull/1/head
韩天峰 3 months ago
parent 1e7401b57d
commit 51772c1e27
  1. 12
      src/Php/Optimizer/SsaTypeOptimizer.php

@ -11,8 +11,8 @@ namespace PhpAot\Php\Optimizer;
use PhpAot\Php\Analysis\SsaBuilder;
use PhpAot\Php\Analysis\SsaFlags;
use PhpAot\Php\Analysis\SsaVar;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\NodeAbstract;
trait SsaTypeOptimizer
@ -190,7 +190,7 @@ trait SsaTypeOptimizer
* Detect the type produced by a single SSA variable definition.
* Returns null if the type cannot be determined from the AST.
*/
protected function detectSsaDefType(\PhpAot\Php\Analysis\SsaVar $ssaVar): ?string
protected function detectSsaDefType(SsaVar $ssaVar): ?string
{
$def = $ssaVar->definition;
if (!$def) {
@ -412,13 +412,13 @@ trait SsaTypeOptimizer
}
}
if ($stmt instanceof Node\Stmt\Foreach_ && $stmt->expr instanceof Node) {
if ($stmt instanceof Node\Stmt\Foreach_) {
if ($this->exprHasIntHazard($stmt->expr, $varName)) {
return true;
}
}
if ($stmt instanceof Node\Stmt\Switch_ && $stmt->cond instanceof Node) {
if ($stmt instanceof Node\Stmt\Switch_) {
if ($this->exprHasIntHazard($stmt->cond, $varName)) {
return true;
}
@ -621,13 +621,13 @@ trait SsaTypeOptimizer
}
}
if ($stmt instanceof Node\Stmt\Foreach_ && $stmt->expr instanceof Node) {
if ($stmt instanceof Node\Stmt\Foreach_) {
if ($this->exprHasFloatHazard($stmt->expr, $varName)) {
return true;
}
}
if ($stmt instanceof Node\Stmt\Switch_ && $stmt->cond instanceof Node) {
if ($stmt instanceof Node\Stmt\Switch_) {
if ($this->exprHasFloatHazard($stmt->cond, $varName)) {
return true;
}

Loading…
Cancel
Save