- 将 findNativeStaticProperty 方法重命名为 resolveNativeStaticPropertyFetch 并返回对象 - 引入 StaticPropertyFetchResolution 类来封装静态属性获取的结果 - 修改条件判断从 if ($native) 到 if ($native !== null) 以明确检查 null 值 - 更新 parseNativeStaticPropertyFetch 方法的返回类型为 ?string - 优化静态属性引用变量的生成逻辑,使用解析结果中的类名 - 移除不再使用的 $class 参数并简化方法调用 - 添加新的解析器相关类文件以支持属性访问解析功能pull/4/head
parent
6f15c61720
commit
f631b395fc
6 changed files with 158 additions and 19 deletions
@ -0,0 +1,31 @@ |
||||
<?php |
||||
/** |
||||
* This file is part of Swoole-Compiler(AOT). |
||||
* |
||||
* @link https://www.swoole.com/ |
||||
* @contact service@swoole.com |
||||
*/ |
||||
|
||||
namespace PhpAot\Php\Resolver; |
||||
|
||||
use PhpAot\Php\Entity\ClassDef; |
||||
use PhpAot\Php\Entity\PropertyDef; |
||||
|
||||
final readonly class NativePropertyAccess |
||||
{ |
||||
public function __construct( |
||||
public string $offset, |
||||
public PropertyAccessResult $resolution, |
||||
) { |
||||
} |
||||
|
||||
public function getClassDef(): ClassDef |
||||
{ |
||||
return $this->resolution->classDef; |
||||
} |
||||
|
||||
public function getPropertyDef(): PropertyDef |
||||
{ |
||||
return $this->resolution->propertyDef; |
||||
} |
||||
} |
||||
@ -0,0 +1,21 @@ |
||||
<?php |
||||
/** |
||||
* This file is part of Swoole-Compiler(AOT). |
||||
* |
||||
* @link https://www.swoole.com/ |
||||
* @contact service@swoole.com |
||||
*/ |
||||
|
||||
namespace PhpAot\Php\Resolver; |
||||
|
||||
use PhpAot\Php\Entity\ClassDef; |
||||
use PhpParser\NodeAbstract; |
||||
|
||||
interface PropertyAccessContext |
||||
{ |
||||
public function getClassDef(string $name): ?ClassDef; |
||||
|
||||
public function getParentClass(string $class): string; |
||||
|
||||
public function fatalError(NodeAbstract $node, string $msg): never; |
||||
} |
||||
@ -0,0 +1,66 @@ |
||||
<?php |
||||
/** |
||||
* This file is part of Swoole-Compiler(AOT). |
||||
* |
||||
* @link https://www.swoole.com/ |
||||
* @contact service@swoole.com |
||||
*/ |
||||
|
||||
namespace PhpAot\Php\Resolver; |
||||
|
||||
use PhpAot\Php\CompilerBase; |
||||
use PhpAot\Php\Entity\PropertyDef; |
||||
|
||||
final class PropertyAssignTypeInfo |
||||
{ |
||||
public function getFixedDefaultValue(PropertyDef $def): ?string |
||||
{ |
||||
return match ($def->type) { |
||||
CompilerBase::TYPE_INT => $def->default ?? '0', |
||||
CompilerBase::TYPE_FLOAT => $def->default ?? '0.0', |
||||
CompilerBase::TYPE_BOOL => $def->default ?? 'false', |
||||
CompilerBase::TYPE_STR => $def->default ?? CompilerBase::TYPE_STR . '()', |
||||
CompilerBase::TYPE_ARRAY => $def->default ?? CompilerBase::TYPE_ARRAY . '{}', |
||||
default => null, |
||||
}; |
||||
} |
||||
|
||||
public function isFixed(PropertyDef $def): bool |
||||
{ |
||||
return in_array($def->type, [ |
||||
CompilerBase::TYPE_INT, |
||||
CompilerBase::TYPE_FLOAT, |
||||
CompilerBase::TYPE_BOOL, |
||||
CompilerBase::TYPE_STR, |
||||
CompilerBase::TYPE_ARRAY, |
||||
], true) && !$def->nullable; |
||||
} |
||||
|
||||
public function getRuntimeTypeCheck(PropertyDef $def): array |
||||
{ |
||||
if (!empty($def->typeCheck)) { |
||||
return $def->typeCheck; |
||||
} |
||||
if ($def->type !== CompilerBase::TYPE_OBJECT || $def->class === '') { |
||||
return []; |
||||
} |
||||
|
||||
$check = []; |
||||
if ($def->nullable) { |
||||
$check[] = ['kind' => 'isNull']; |
||||
} |
||||
$check[] = ['kind' => 'instanceof', 'class' => $def->class]; |
||||
return $check; |
||||
} |
||||
|
||||
public function getTypeString(PropertyDef $def): string |
||||
{ |
||||
if ($def->typeStr !== '') { |
||||
return $def->typeStr; |
||||
} |
||||
if ($def->class !== '') { |
||||
return ($def->nullable ? '?' : '') . $def->class; |
||||
} |
||||
return $def->type; |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@ |
||||
<?php |
||||
/** |
||||
* This file is part of Swoole-Compiler(AOT). |
||||
* |
||||
* @link https://www.swoole.com/ |
||||
* @contact service@swoole.com |
||||
*/ |
||||
|
||||
namespace PhpAot\Php\Resolver; |
||||
|
||||
final readonly class StaticPropertyFetchResolution |
||||
{ |
||||
public function __construct( |
||||
public ?string $class, |
||||
public string $expression, |
||||
public bool $nativeProperty, |
||||
) { |
||||
} |
||||
} |
||||
Loading…
Reference in new issue