From ecbb00542e6b60f02aaedc434f4a9d8867f2d9d8 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 12 Jan 2026 14:16:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(compiler):=20=E4=BF=AE=E5=A4=8DPHP=E5=88=B0?= =?UTF-8?q?C++=E7=BC=96=E8=AF=91=E5=99=A8=E4=B8=AD=E7=9A=84=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在循环中添加键值引用以支持数组元素删除操作 - 当遇到不支持的语法时从列表中移除对应文件 - 添加varTypes属性用于存储变量类型信息 - 为parseType方法添加返回类型声明 - 将未知类型默认处理为对象类型并记录到varTypes中 - 在示例代码中添加测试函数验证类型解析功能 --- bin/compiler.php | 3 ++- examples/class/main.php | 5 +++++ src/Php/CompilerBase.php | 7 ++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/compiler.php b/bin/compiler.php index cb9ae8a1..ba9b950e 100755 --- a/bin/compiler.php +++ b/bin/compiler.php @@ -48,7 +48,7 @@ foreach ($list as $k => $file) { $translator->sortFiles($list); // 生成 C++ 文件 -foreach ($list as $file) { +foreach ($list as $k => $file) { try { if (FileScanner::isPhpFile($file)) { $cppFile = $translator->convert($file); @@ -61,6 +61,7 @@ foreach ($list as $file) { } catch (Unsupported $e) { echo " unsupported syntax: " . $e->getMessage() . "\n"; echo " skip: " . $file . "\n"; + unset($list[$k]); } } diff --git a/examples/class/main.php b/examples/class/main.php index 37ed55f1..04e5dfb7 100644 --- a/examples/class/main.php +++ b/examples/class/main.php @@ -4,3 +4,8 @@ function main() { var_dump("hello"); } + +function test2(stdClass $o) +{ + var_dump($o); +} diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 27c4c6a3..657c8b01 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -100,6 +100,7 @@ class CompilerBase extends \PhpAot\Core\Translator 'argv' => self::TYPE_ARRAY, ]; protected array $localVars = []; + protected array $varTypes = []; protected array $objectWrappers = []; protected bool $strictTypes = false; @@ -969,7 +970,7 @@ class CompilerBase extends \PhpAot\Core\Translator '}'; } - protected function parseType($type) + protected function parseType($type): string { if ($type == null) { return self::TYPE_VAR; @@ -990,8 +991,8 @@ class CompilerBase extends \PhpAot\Core\Translator case 'string': return self::TYPE_STR; default: - var_dump($name); - abort($type); + $this->varTypes[$name] = $name; + return self::TYPE_OBJECT; } }