refactor(php): 将异常类移动到Exception命名空间

- 将RedoException重命名为Redo并移至PhpAot\Php\Exception命名空间
- 将SkipException重命名为Skip并移至PhpAot\Php\Exception命名空间
- 将SyntaxError移至PhpAot\Php\Exception命名空间
- 将Unsupported移至PhpAot\Php\Exception命名空间
- 更新所有相关文件中的use语句和异常引用
- 移除不再使用的PrettyPrinter导入
pull/1/head
韩天峰 7 months ago
parent d91362c032
commit 67ace98bb6
  1. 4
      bin/compiler.php
  2. 11
      src/Php/CompilerBase.php
  3. 4
      src/Php/Exception/Redo.php
  4. 8
      src/Php/Exception/Skip.php
  5. 2
      src/Php/Exception/SyntaxError.php
  6. 2
      src/Php/Exception/Unsupported.php
  7. 1
      src/Php/Preprocessor.php
  8. 8
      src/Php/SkipException.php
  9. 3
      src/Php/Translator.php
  10. 2
      src/functions.php

@ -2,10 +2,10 @@
<?php
require __DIR__ . '/bootstrap.php';
use PhpAot\Php\Exception\SyntaxError;
use PhpAot\Php\Exception\Unsupported;
use PhpAot\Php\FileScanner;
use PhpAot\Php\SyntaxError;
use PhpAot\Php\Translator;
use PhpAot\Php\Unsupported;
if (empty($argv[1])) {
die("php compiler.php [file]\n");

@ -9,6 +9,8 @@
namespace PhpAot\Php;
use League\CLImate\CLImate;
use PhpAot\Php\Exception\Redo;
use PhpAot\Php\Exception\Skip;
use PhpParser\Modifiers;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
@ -20,7 +22,6 @@ use PhpParser\Node\UnionType;
use PhpParser\NodeAbstract;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter;
class CompilerBase extends \PhpAot\Core\Translator
{
@ -652,7 +653,7 @@ class CompilerBase extends \PhpAot\Core\Translator
if (isset($this->redoAfterDeclare[$name])) {
unset($this->redoAfterDeclare[$name]);
$this->climate->cyan('Received redo request, retrying...');
throw new RedoException();
throw new Redo();
}
}
@ -675,7 +676,7 @@ class CompilerBase extends \PhpAot\Core\Translator
$this->indentLevel++;
try {
$stmts = $this->parseStmts($v->stmts);
} catch (SkipException $e) {
} catch (Skip $e) {
$stmts = '';
}
$this->indentLevel--;
@ -1254,7 +1255,7 @@ class CompilerBase extends \PhpAot\Core\Translator
$this->functionDef->returnType = $type;
// 返回值变更,需要重新解析
$this->climate->cyan('Return type changed, retrying...');
throw new RedoException();
throw new Redo();
}
protected function detectVarType($var): string
@ -1741,7 +1742,7 @@ class CompilerBase extends \PhpAot\Core\Translator
and $this->functionDeclInFile[$name] === $this->file
and !$this->isNativeFunction($name)) {
$this->redoAfterDeclare[$name] = true;
throw new SkipException();
throw new Skip();
}
if ($this->isNativeFunction($name)) {
return $name;

@ -6,8 +6,8 @@
* @contact service@swoole.com
*/
namespace PhpAot\Php;
namespace PhpAot\Php\Exception;
class RedoException extends \RuntimeException
class Redo extends \RuntimeException
{
}

@ -0,0 +1,8 @@
<?php
namespace PhpAot\Php\Exception;
class Skip extends \RuntimeException
{
}

@ -6,7 +6,7 @@
* @contact service@swoole.com
*/
namespace PhpAot\Php;
namespace PhpAot\Php\Exception;
class SyntaxError extends \RuntimeException
{

@ -6,7 +6,7 @@
* @contact service@swoole.com
*/
namespace PhpAot\Php;
namespace PhpAot\Php\Exception;
class Unsupported extends \RuntimeException
{

@ -8,6 +8,7 @@
namespace PhpAot\Php;
use PhpAot\Php\Exception\SyntaxError;
use PhpParser\Node;
use PhpParser\NodeFinder;
use PhpParser\NodeTraverser;

@ -1,8 +0,0 @@
<?php
namespace PhpAot\Php;
class SkipException extends \RuntimeException
{
}

@ -9,6 +9,7 @@
namespace PhpAot\Php;
use MJS\TopSort\Implementations\StringSort;
use PhpAot\Php\Exception\Redo;
use PhpParser\Modifiers;
use PhpParser\Node;
use PhpParser\Node\Stmt\Foreach_;
@ -101,7 +102,7 @@ class Translator extends Preprocessor
$this->phpSrcFiles[] = $file;
return $cppFile;
} catch (RedoException $e) {
} catch (Redo $e) {
continue;
}
}

@ -1,7 +1,7 @@
<?php
use PhpAot\Core\Translator;
use PhpAot\Php\Unsupported;
use PhpAot\Php\Exception\Unsupported;
function abort($v)
{

Loading…
Cancel
Save