refactor(compiler): remove unused imports and move global headers to translator

- Removed unused TypePhp\Exception\PlaceHolder import
- Removed unused TypePhp\Resolver\InstancePropertyFetchTarget import
- Removed unused TypePhp\Resolver\PropertyAssignTypeInfo, PropertyWriteTarget, StaticPropertyFetchResolution, and StaticPropertyFetchTarget imports
- Removed unused PhpParser\Node\Stmt\Foreach_ import
- Removed unused TypePhp\Platform\Linux import
- Removed unused getTargetFileName method from NativeBuildConfigurationTrait
- Moved globalHeaders array from CompilerBase to Translator class
- Moved classCeList and classCeInfo arrays from CompilerBase to Translator class
- Updated ABI version retrieval to use constant() function instead of direct constants
- Added proper PHPDoc comments for functions and classes arrays in SymbolRepository
pull/17/head
韩天峰 2 months ago
parent b6925518bc
commit 995e223915
  1. 18
      src/Build/NativeBuildConfigurationTrait.php
  2. 40
      src/CompilerBase.php
  3. 10
      src/Symbol/SymbolRepository.php
  4. 28
      src/Translator.php

@ -7,7 +7,6 @@
namespace TypePhp\Build;
use TypePhp\Platform\Linux;
use TypePhp\Platform\Windows;
trait NativeBuildConfigurationTrait
@ -162,21 +161,4 @@ trait NativeBuildConfigurationTrait
return $this->getPlatform()->getLibraryFlags($this->getLibraries());
}
protected function getTargetFileName(): string
{
$targetFile = $this->targetName;
$extension = $this->getPlatform()->getTargetExtension($this->buildMode);
if ($extension !== '' && !str_ends_with($targetFile, $extension)) {
$targetFile .= $extension;
}
if ($this->outputDir !== '') {
$targetFile = rtrim($this->outputDir, '/\\') . '/' . $targetFile;
}
return $targetFile;
}
}

@ -26,7 +26,6 @@ use TypePhp\Entity\InterfaceDef;
use TypePhp\Entity\MethodDef;
use TypePhp\Entity\PropertyDef;
use TypePhp\Exception\DynamicCall;
use TypePhp\Exception\PlaceHolder;
use TypePhp\Exception\Redo;
use TypePhp\Generator\AnonClassGenerator;
use TypePhp\Generator\CallArgumentGenerator;
@ -67,7 +66,6 @@ use TypePhp\Platform\Macos;
use TypePhp\Platform\PlatformBase;
use TypePhp\Platform\PlatformFactory;
use TypePhp\Platform\Windows;
use TypePhp\Resolver\InstancePropertyFetchTarget;
use TypePhp\Resolver\DeclarationSymbolTrait;
use TypePhp\Resolver\MagicMethodDetector;
use TypePhp\Resolver\PropertyAccessContext;
@ -75,11 +73,7 @@ use TypePhp\Resolver\NativePropertyAccess;
use TypePhp\Resolver\NameResolutionTrait;
use TypePhp\Resolver\PropertyAccessResult;
use TypePhp\Resolver\PropertyAccessResolver;
use TypePhp\Resolver\PropertyAssignTypeInfo;
use TypePhp\Resolver\PropertyWriteTarget;
use TypePhp\Resolver\Reflection;
use TypePhp\Resolver\StaticPropertyFetchResolution;
use TypePhp\Resolver\StaticPropertyFetchTarget;
use TypePhp\Symbol\SymbolRepository;
use TypePhp\TypeSystem\CompositeTypeCheckerTrait;
use TypePhp\TypeSystem\NativeTypeCompatibilityTrait;
@ -90,7 +84,6 @@ use PhpParser\Node\Expr;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\NodeAbstract;
use PhpParser\NodeFinder;
use PhpParser\Parser;
@ -270,16 +263,6 @@ class CompilerBase implements PropertyAccessContext
'decimal' => Type::DECIMAL,
'box' => Type::BOX,
];
protected array $globalHeaders = [
'phpx.h',
'phpx_helper.h',
'phpx_big_int.h',
'phpx_big_float.h',
'phpx_decimal.h',
'typephp_helper.h',
'typephp_fiber_generator.h',
'phpx_std.h',
];
protected array $localHeaders = [];
protected array $internalFunctions = [];
protected array $internalConstants = [];
@ -338,46 +321,23 @@ class CompilerBase implements PropertyAccessContext
protected string $class = '';
protected string $parentClass = '';
protected string $interface = '';
/**
* @var array<string, InterfaceDef>
*/
/**
* 存储所有函数、类方法的定义,key 是 native name,命名空间需要转为 `_`,并且必须为小写
* @var array<string, FunctionDef>
*/
/**
* key 类名,包含命名空间
* @var array<string, ClassDef>
*/
/**
* @var array<string, ConstantDef>
*/
protected array $constants = [];
/**
* @var array<string, ClassDef>
*/
protected array $classesDefineInFile = [];
/**
* @var array<string, InterfaceDef>
*/
protected array $interfacesDefineInFile = [];
/**
* @var array<string, FunctionDef>
*/
protected array $functionDefineInFile = [];
/**
* @var array<string>
*/
protected array $classCeList = [];
protected array $classCeInfo = [];
protected ?FunctionDef $functionDef = null;
protected ?ClassDef $classDef = null;
protected ?MethodDef $methodDef = null;

@ -8,9 +8,15 @@ use TypePhp\Entity\InterfaceDef;
final class SymbolRepository
{
/** @var array<string, FunctionDef> */
/**
* 存储所有函数、类方法的定义,key 是 native name,命名空间需要转为 `_`,并且必须为小写
* @var array<string, FunctionDef>
*/
private array $functions = [];
/** @var array<string, ClassDef> */
/**
* key 类名,包含命名空间
* @var array<string, ClassDef>
*/
private array $classes = [];
/** @var array<string, InterfaceDef> */
private array $interfaces = [];

@ -27,8 +27,6 @@ use TypePhp\Entity\MethodDef;
use TypePhp\Entity\PropertyDef;
use TypePhp\Exception\Redo;
use TypePhp\Exception\Skip;
use TypePhp\Exception\SyntaxError;
use TypePhp\Exception\Unsupported;
use TypePhp\Generator\DefaultArgumentGenerator;
use TypePhp\Generator\Symbol;
use TypePhp\Metadata\Constants;
@ -39,7 +37,6 @@ use TypePhp\Resolver\ClassConstantValueTrait;
use TypePhp\Transform\Visitor;
use PhpParser\Modifiers;
use PhpParser\Node;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\NodeAbstract;
use PhpParser\NodeTraverser;
@ -54,6 +51,8 @@ class Translator extends Preprocessor
public const string VERSION = '0.3.0';
public const string APP_NAME = 'TypePHP Compiler (AOT)';
protected const string MODULE_NAME_PREFIX = 'app_';
protected string $targetName = 'app';
protected bool $hasExplicitOutput = false;
protected ?string $explicitOutputExtension = null;
@ -69,17 +68,28 @@ class Translator extends Preprocessor
// Windows 资源文件配置(图标、版本信息等)
protected array $resourceConfig = [];
protected bool $useRegisterSymbolsFn = false;
protected const string MODULE_NAME_PREFIX = 'app_';
protected array $globalHeaders = [
'phpx.h',
'phpx_helper.h',
'phpx_big_int.h',
'phpx_big_float.h',
'phpx_decimal.h',
'typephp_helper.h',
'typephp_fiber_generator.h',
'phpx_std.h',
];
/**
* @var array<string>
*/
protected array $classCeList = [];
protected array $classCeInfo = [];
protected function isConstructorNativeFunction(FunctionDef $func): bool
{
return $func->method && str_ends_with($func->name, self::NAMESPACE_SEPARATOR . '__construct');
}
public function __construct(string $rootPath)
{
parent::__construct($rootPath);
@ -1074,8 +1084,8 @@ CODE;
{
$abi = [
'php_version_id' => PHP_VERSION_ID,
'php_api_version' => defined('PHP_API_VERSION') ? PHP_API_VERSION : null,
'zend_module_api' => defined('ZEND_MODULE_API_NO') ? ZEND_MODULE_API_NO : null,
'php_api_version' => defined('PHP_API_VERSION') ? constant('PHP_API_VERSION') : null,
'zend_module_api' => defined('ZEND_MODULE_API_NO') ? constant('ZEND_MODULE_API_NO') : null,
'php_zts' => defined('PHP_ZTS') ? PHP_ZTS : null,
'php_debug' => defined('PHP_DEBUG') ? PHP_DEBUG : null,
'integer_size' => PHP_INT_SIZE,

Loading…
Cancel
Save