|
|
|
@ -15,7 +15,6 @@ use PhpAot\Php\Entity\ConstantDef; |
|
|
|
use PhpAot\Php\Entity\FunctionDef; |
|
|
|
use PhpAot\Php\Entity\FunctionDef; |
|
|
|
use PhpAot\Php\Entity\InterfaceDef; |
|
|
|
use PhpAot\Php\Entity\InterfaceDef; |
|
|
|
use PhpAot\Php\Entity\MethodDef; |
|
|
|
use PhpAot\Php\Entity\MethodDef; |
|
|
|
use PhpAot\Php\Entity\PropertyDef; |
|
|
|
|
|
|
|
use PhpAot\Php\Exception\DynamicCall; |
|
|
|
use PhpAot\Php\Exception\DynamicCall; |
|
|
|
use PhpAot\Php\Exception\PlaceHolder; |
|
|
|
use PhpAot\Php\Exception\PlaceHolder; |
|
|
|
use PhpAot\Php\Exception\Redo; |
|
|
|
use PhpAot\Php\Exception\Redo; |
|
|
|
@ -563,6 +562,12 @@ class CompilerBase extends \PhpAot\Core\Translator |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function getRelativePath($path, $cwd = ''): string |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$cwd = $cwd ?: getcwd(); |
|
|
|
|
|
|
|
return ltrim($this->removeCommonPrefix($cwd, $path), '/'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function removeCommonPrefix(string $short, string $long): string |
|
|
|
protected function removeCommonPrefix(string $short, string $long): string |
|
|
|
{ |
|
|
|
{ |
|
|
|
$len = min(strlen($short), strlen($long)); |
|
|
|
$len = min(strlen($short), strlen($long)); |
|
|
|
@ -1769,7 +1774,8 @@ class CompilerBase extends \PhpAot\Core\Translator |
|
|
|
if ($nativeFunc) { |
|
|
|
if ($nativeFunc) { |
|
|
|
$funcDef = $this->functions[$nativeFunc]; |
|
|
|
$funcDef = $this->functions[$nativeFunc]; |
|
|
|
return $funcDef->returnType; |
|
|
|
return $funcDef->returnType; |
|
|
|
} elseif ($this->isTypedObject($object)) { |
|
|
|
} |
|
|
|
|
|
|
|
if ($this->isTypedObject($object)) { |
|
|
|
return $this->detectMethodCallReturnType($this->getObjectType($object), $method); |
|
|
|
return $this->detectMethodCallReturnType($this->getObjectType($object), $method); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -3045,7 +3051,8 @@ class CompilerBase extends \PhpAot\Core\Translator |
|
|
|
} |
|
|
|
} |
|
|
|
if ($this->isInternalConstant($name)) { |
|
|
|
if ($this->isInternalConstant($name)) { |
|
|
|
return 'php::constant(' . $this->getLiteralString($name) . ')'; |
|
|
|
return 'php::constant(' . $this->getLiteralString($name) . ')'; |
|
|
|
} elseif (isset($this->useAliases[$name])) { |
|
|
|
} |
|
|
|
|
|
|
|
if (isset($this->useAliases[$name])) { |
|
|
|
$name = $this->useAliases[$name]; |
|
|
|
$name = $this->useAliases[$name]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$fullName = $this->getNamespacedClassName($name); |
|
|
|
$fullName = $this->getNamespacedClassName($name); |
|
|
|
@ -3133,14 +3140,18 @@ class CompilerBase extends \PhpAot\Core\Translator |
|
|
|
|
|
|
|
|
|
|
|
protected function isInheritedFrom(string $class, string $expected): bool |
|
|
|
protected function isInheritedFrom(string $class, string $expected): bool |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($this->isInternalClass($class) and ($this->isInternalClass($expected) or $this->isInternalInterface($expected))) { |
|
|
|
$internal = ($this->isInternalClass($expected) or $this->isInternalInterface($expected)); |
|
|
|
return $class === $expected or is_subclass_of($class, $expected); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
while (true) { |
|
|
|
while (true) { |
|
|
|
if (strcasecmp($class, $expected) === 0) { |
|
|
|
if (strcasecmp($class, $expected) === 0) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!$this->hasClass($class)) { |
|
|
|
if (!$this->hasClass($class)) { |
|
|
|
|
|
|
|
// 原生类继承自一个内置类,例如: UserError extends Exception ,然后 $expected 预期是 Throwable |
|
|
|
|
|
|
|
// 这种情况,需要使用 ZendVM 获取继承关系 |
|
|
|
|
|
|
|
if ($this->isInternalClass($class) and $internal) { |
|
|
|
|
|
|
|
return $class === $expected or is_subclass_of($class, $expected); |
|
|
|
|
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
$classDef = $this->getClass($class); |
|
|
|
$classDef = $this->getClass($class); |
|
|
|
@ -3363,7 +3374,7 @@ class CompilerBase extends \PhpAot\Core\Translator |
|
|
|
protected function formatCppCode(string $file): void |
|
|
|
protected function formatCppCode(string $file): void |
|
|
|
{ |
|
|
|
{ |
|
|
|
$cmd = 'cd ' . $this->rootPath . ' && clang-format -i ' . $file; |
|
|
|
$cmd = 'cd ' . $this->rootPath . ' && clang-format -i ' . $file; |
|
|
|
$this->climate->info('format: ' . $file); |
|
|
|
$this->climate->info('format: ' . $this->getRelativePath($file)); |
|
|
|
$this->climate->comment($cmd); |
|
|
|
$this->climate->comment($cmd); |
|
|
|
shell_exec($cmd); |
|
|
|
shell_exec($cmd); |
|
|
|
} |
|
|
|
} |
|
|
|
|