refactor(Php): 优化对象值解析逻辑并添加方法标识支持

- 简化 CompilerBase.php 中的对象值解析条件判断
- 在 FunctionDef.php 中添加 method 属性用于标识是否为方法
- 在 MethodDef.php 构造函数中设置 functionDef 的 method 标志
- 在 Translator.php 参数列表生成时为方法添加 this_ 对象参数
pull/1/head
韩天峰 7 months ago
parent 9b94b287cb
commit 51f039e6b4
  1. 7
      src/Php/CompilerBase.php
  2. 1
      src/Php/FunctionDef.php
  3. 1
      src/Php/MethodDef.php
  4. 3
      src/Php/Translator.php

@ -844,11 +844,10 @@ class CompilerBase extends \PhpAot\Core\Translator
$type = self::TYPE_OBJECT;
} elseif ($this->isFuncCallExpr($right) and $this->isNameExpr($right->name)) {
$fn = $this->parseIdentifier($right->name);
$arg2 = $right->args[1]->value;
if (count($right->args) === 2 and $fn === 'objval' and $this->isScalarString($arg2)) {
$this->objects[$var] = $arg2->value;
if (count($right->args) === 2 and $fn === 'objval' and $this->isScalarString($right->args[1]->value)) {
$this->objects[$var] = $right->args[1]->value;
$type = self::TYPE_OBJECT;
}
$type = self::TYPE_OBJECT;
}
if (!$this->hasVar($var)) {

@ -9,6 +9,7 @@ class FunctionDef
public array $argInfoList = [];
public int $argCountRequired = 0;
public string $params = '';
public bool $method = false;
public function __construct(string $name, string $returnType)

@ -13,6 +13,7 @@ class MethodDef
$this->flags = $flags;
$this->name = $name;
$this->functionDef = $def;
$this->functionDef->method = true;
}
public function getReturnType(): string

@ -426,6 +426,9 @@ class Translator extends Preprocessor
$argInfoList = $func->argInfoList;
if ($argInfoList) {
$list = [];
if ($func->method) {
$list[] = 'php::Object &this_';
}
foreach ($argInfoList as $argInfo) {
$arg = $argInfo->type . ' ' . $argInfo->name;
if ($argInfo->default) {

Loading…
Cancel
Save