refactor(php): 优化标识符转换方法以支持字面量模式

- 在 identifierToStr 方法中添加 literal 参数以控制字符串生成方式
- 修改 MethodCall 处理逻辑以使用字面量模式进行标识符转换
- 实现字面量模式下的字符串处理逻辑,根据参数决定返回字面量还是指针
- 更新方法签名以兼容新的字面量参数选项
pull/1/head
韩天峰 6 months ago
parent 7871eb2820
commit 4f375bf869
  1. 6
      src/Php/CompilerBase.php

@ -3345,7 +3345,7 @@ class CompilerBase extends \PhpAot\Core\Translator
$class = '';
}
$method = $this->identifierToStr($expr->name);
$method = $this->identifierToStr($expr->name, literal: true);
// 可转为原生调用的 MethodCall
if ($this->isVarExpr($expr->var) and $this->isNamedMethod($expr->name)) {
@ -3378,7 +3378,7 @@ class CompilerBase extends \PhpAot\Core\Translator
}
}
protected function identifierToStr(NodeAbstract $node, bool $require = true): string
protected function identifierToStr(NodeAbstract $node, bool $require = true, bool $literal = false): string
{
$id = $this->parseIdentifier($node);
if ($this->isVarExpr($node)) {
@ -3395,7 +3395,7 @@ class CompilerBase extends \PhpAot\Core\Translator
$id = $this->getNamespacedClassName($this->class);
}
if ($this->isNameExpr($node) or $this->isIdExpr($node)) {
return $this->genCharPtr($id, true);
return $literal ? $this->getLiteralString($id) : $this->genCharPtr($id, true);
}
return $id;
}

Loading…
Cancel
Save