refactor(core): restructure source directory organization and update imports

- Move Reflection.php from src/ to src/Resolver/
- Move Symbol.php from src/ to src/Generator/
- Move FileScanner.php from src/ to src/Build/
- Move ArgInfo.php from src/ to src/Entity/
- Move Visitor.php from src/ to src/Transform/
- Update all import statements across compiler base and related files
- Add new dependencies in CompilerBase.php and Preprocessor.php
- Update example files to use new namespace paths
- Correct documentation links in universal methods guide
- Add necessary use statements in metadata constants and generator files
pull/17/head
韩天峰 2 months ago
parent 3372e4c59c
commit 41aaff4094
  1. 10
      CLAUDE.md
  2. 2
      docs/UNIVERSAL_METHODS.md
  3. 4
      examples/file_scanner_example.php
  4. 4
      examples/file_scanner_usage.php
  5. 4
      examples/scan_with_exclusions.php
  6. 4
      examples/simple_scan.php
  7. 4
      examples/test_exclusions.php
  8. 4
      examples/test_php_parser_check.php
  9. 4
      examples/test_php_syntax_check.php
  10. 6
      src/CompilerBase.php
  11. 2
      src/Generator/Symbol.php
  12. 2
      src/Metadata/Constants.php
  13. 1
      src/Parser/UniversalMethodCall.php
  14. 3
      src/Preprocessor.php
  15. 6
      src/Translator.php

@ -79,12 +79,12 @@ src/CompilerBase.php (core PHP→C++ translation logic, indent/output/mode helpe
| `src/Context/` | `ScopeContext` and `FunctionContext` for variable scoping and type tracking | | `src/Context/` | `ScopeContext` and `FunctionContext` for variable scoping and type tracking |
| `src/Exception/` | `SyntaxError`, `Unsupported`, `DynamicCall`, `PlaceHolder`, `Skip`, `Redo`, `TestError` | | `src/Exception/` | `SyntaxError`, `Unsupported`, `DynamicCall`, `PlaceHolder`, `Skip`, `Redo`, `TestError` |
| `src/Parser/` | Special-purpose parsers like `StdContainerParser` (C++ std container foreach support) | | `src/Parser/` | Special-purpose parsers like `StdContainerParser` (C++ std container foreach support) |
| `src/Reflection.php` | Static helpers wrapping PHP reflection (internal class/function detection) | | `src/Resolver/Reflection.php` | Static helpers wrapping PHP reflection (internal class/function detection) |
| `src/Symbol.php` | Maps PHP operations to `phpx` C++ API symbol names | | `src/Generator/Symbol.php` | Maps PHP operations to `phpx` C++ API symbol names |
| `src/FileScanner.php` | Recursive file discovery with extension filtering (supports `.php`, `.cpp`, `.c`, `.s`, `.m`, `.mm`) | | `src/Build/FileScanner.php` | Recursive file discovery with extension filtering (supports `.php`, `.cpp`, `.c`, `.s`, `.m`, `.mm`) |
| `src/ArgInfo.php` | Generates C function argument info structures for internal function registration | | `src/Entity/ArgInfo.php` | Generates C function argument info structures for internal function registration |
| `src/Extractor.php` | Extracts interfaces from PHP classes | | `src/Extractor.php` | Extracts interfaces from PHP classes |
| `src/Visitor.php` | Base `NodeVisitorAbstract` extension (skeleton for custom AST visitors) | | `src/Transform/Visitor.php` | Base `NodeVisitorAbstract` extension (skeleton for custom AST visitors) |
### Configuration ### Configuration

@ -1103,7 +1103,7 @@ function main(): void {
- **高精度类型教程**:[`docs/HIGH_PRECISION_TYPES.md`](HIGH_PRECISION_TYPES.md) - **高精度类型教程**:[`docs/HIGH_PRECISION_TYPES.md`](HIGH_PRECISION_TYPES.md)
- **类型系统规范**:[`docs/NATIVE_TYPES.md`](NATIVE_TYPES.md) - **类型系统规范**:[`docs/NATIVE_TYPES.md`](NATIVE_TYPES.md)
- **通用方法实现**:[`src/UniversalMethodCall.php`](../src/UniversalMethodCall.php) - **通用方法实现**:[`src/Parser/UniversalMethodCall.php`](../src/Parser/UniversalMethodCall.php)
- **集成测试** - **集成测试**
- [`tests/aot/string_method/`](../tests/aot/string_method/) — String 通用方法测试 - [`tests/aot/string_method/`](../tests/aot/string_method/) — String 通用方法测试
- [`tests/aot/array_method/`](../tests/aot/array_method/) — Array 通用方法测试 - [`tests/aot/array_method/`](../tests/aot/array_method/) — Array 通用方法测试

@ -1,6 +1,8 @@
<?php <?php
require_once __DIR__ . '/../src/FileScanner.php'; require_once __DIR__ . '/../src/Build/FileScanner.php';
use TypePhp\Build\FileScanner;
// 创建文件扫描器实例,用于扫描 PHP 和 C++ 文件 // 创建文件扫描器实例,用于扫描 PHP 和 C++ 文件
$scanner = new FileScanner(['.php', '.cc', '.cpp', '.cxx', '.c', '.h', '.hpp']); $scanner = new FileScanner(['.php', '.cc', '.cpp', '.cxx', '.c', '.h', '.hpp']);

@ -1,9 +1,9 @@
<?php <?php
require_once __DIR__ . '/../vendor/autoload.php'; // 添加自动加载器 require_once __DIR__ . '/../vendor/autoload.php'; // 添加自动加载器
require_once __DIR__ . '/../src/Php/FileScanner.php'; require_once __DIR__ . '/../src/Build/FileScanner.php';
use PhpAot\FileScanner; use TypePhp\Build\FileScanner;
echo "测试 FileScanner 类...\n"; echo "测试 FileScanner 类...\n";

@ -1,6 +1,8 @@
<?php <?php
require_once __DIR__ . '/../src/FileScanner.php'; require_once __DIR__ . '/../src/Build/FileScanner.php';
use TypePhp\Build\FileScanner;
// 创建文件扫描器实例,用于扫描 PHP 和 C++ 文件 // 创建文件扫描器实例,用于扫描 PHP 和 C++ 文件
$scanner = new FileScanner(['.php', '.cc', '.cpp', '.cxx', '.c', '.h', '.hpp']); $scanner = new FileScanner(['.php', '.cc', '.cpp', '.cxx', '.c', '.h', '.hpp']);

@ -1,6 +1,8 @@
<?php <?php
require_once __DIR__ . '/../src/FileScanner.php'; require_once __DIR__ . '/../src/Build/FileScanner.php';
use TypePhp\Build\FileScanner;
// 创建文件扫描器实例,用于扫描 PHP 和 C++ 文件 // 创建文件扫描器实例,用于扫描 PHP 和 C++ 文件
$scanner = new FileScanner(['.php', '.cc', '.cpp', '.cxx', '.c', '.h', '.hpp']); $scanner = new FileScanner(['.php', '.cc', '.cpp', '.cxx', '.c', '.h', '.hpp']);

@ -1,8 +1,8 @@
<?php <?php
require_once __DIR__ . '/../src/Php/FileScanner.php'; require_once __DIR__ . '/../src/Build/FileScanner.php';
use PhpAot\FileScanner; use TypePhp\Build\FileScanner;
echo "测试基本扫描功能...\n"; echo "测试基本扫描功能...\n";
$scanner = new FileScanner(__DIR__ . '/..', ['.php', '.cc', '.cpp', '.cxx', '.c', '.h', '.hpp']); $scanner = new FileScanner(__DIR__ . '/..', ['.php', '.cc', '.cpp', '.cxx', '.c', '.h', '.hpp']);

@ -1,9 +1,9 @@
<?php <?php
require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../src/Php/FileScanner.php'; require_once __DIR__ . '/../src/Build/FileScanner.php';
use PhpAot\FileScanner; use TypePhp\Build\FileScanner;
echo "测试使用 PHP-Parser 的语法检查功能...\n"; echo "测试使用 PHP-Parser 的语法检查功能...\n";

@ -1,8 +1,8 @@
<?php <?php
require_once __DIR__ . '/../src/Php/FileScanner.php'; require_once __DIR__ . '/../src/Build/FileScanner.php';
use PhpAot\FileScanner; use TypePhp\Build\FileScanner;
echo "测试 PHP 语法检查功能...\n"; echo "测试 PHP 语法检查功能...\n";

@ -12,6 +12,7 @@ use League\CLImate\CLImate;
use TypePhp\Backend\CompilerBackend; use TypePhp\Backend\CompilerBackend;
use TypePhp\Backend\CompilerFactory; use TypePhp\Backend\CompilerFactory;
use TypePhp\Build\NativeBuildConfigurationTrait; use TypePhp\Build\NativeBuildConfigurationTrait;
use TypePhp\Entity\ArgInfo;
use TypePhp\Context\FunctionContext; use TypePhp\Context\FunctionContext;
use TypePhp\Context\CompilationStateTrait; use TypePhp\Context\CompilationStateTrait;
use TypePhp\Entity\ClassDef; use TypePhp\Entity\ClassDef;
@ -30,6 +31,7 @@ use TypePhp\Generator\ClosureGenerator;
use TypePhp\Generator\FiberGenerator; use TypePhp\Generator\FiberGenerator;
use TypePhp\Generator\PlaceHolderGenerator; use TypePhp\Generator\PlaceHolderGenerator;
use TypePhp\Generator\PropertyPromotion; use TypePhp\Generator\PropertyPromotion;
use TypePhp\Generator\Symbol;
use TypePhp\Generator\Utils; use TypePhp\Generator\Utils;
use TypePhp\Generator\TypeCheckGenerator; use TypePhp\Generator\TypeCheckGenerator;
use TypePhp\Optimizer\SsaPropOptimizer; use TypePhp\Optimizer\SsaPropOptimizer;
@ -38,6 +40,7 @@ use TypePhp\Optimizer\LoopVarOptimizer;
use TypePhp\Parser\StdContainerTrait; use TypePhp\Parser\StdContainerTrait;
use TypePhp\Parser\AssignOpTrait; use TypePhp\Parser\AssignOpTrait;
use TypePhp\Parser\ArrayExpressionTrait; use TypePhp\Parser\ArrayExpressionTrait;
use TypePhp\Parser\AstNodeType;
use TypePhp\Parser\BinaryOpTrait; use TypePhp\Parser\BinaryOpTrait;
use TypePhp\Parser\ClassConstantFetchTrait; use TypePhp\Parser\ClassConstantFetchTrait;
use TypePhp\Parser\ConditionalControlTrait; use TypePhp\Parser\ConditionalControlTrait;
@ -53,6 +56,7 @@ use TypePhp\Parser\SelectionExpressionTrait;
use TypePhp\Parser\SwitchTrait; use TypePhp\Parser\SwitchTrait;
use TypePhp\Parser\TypeConversionTrait; use TypePhp\Parser\TypeConversionTrait;
use TypePhp\Parser\TypeDetectionTrait; use TypePhp\Parser\TypeDetectionTrait;
use TypePhp\Parser\UniversalMethodCall;
use TypePhp\Optimizer\FuncCallOptimizer; use TypePhp\Optimizer\FuncCallOptimizer;
use TypePhp\Platform\Linux; use TypePhp\Platform\Linux;
use TypePhp\Platform\Macos; use TypePhp\Platform\Macos;
@ -61,6 +65,7 @@ use TypePhp\Platform\PlatformFactory;
use TypePhp\Platform\Windows; use TypePhp\Platform\Windows;
use TypePhp\Resolver\InstancePropertyFetchTarget; use TypePhp\Resolver\InstancePropertyFetchTarget;
use TypePhp\Resolver\DeclarationSymbolTrait; use TypePhp\Resolver\DeclarationSymbolTrait;
use TypePhp\Resolver\MagicMethodDetector;
use TypePhp\Resolver\PropertyAccessContext; use TypePhp\Resolver\PropertyAccessContext;
use TypePhp\Resolver\NativePropertyAccess; use TypePhp\Resolver\NativePropertyAccess;
use TypePhp\Resolver\NameResolutionTrait; use TypePhp\Resolver\NameResolutionTrait;
@ -68,6 +73,7 @@ use TypePhp\Resolver\PropertyAccessResult;
use TypePhp\Resolver\PropertyAccessResolver; use TypePhp\Resolver\PropertyAccessResolver;
use TypePhp\Resolver\PropertyAssignTypeInfo; use TypePhp\Resolver\PropertyAssignTypeInfo;
use TypePhp\Resolver\PropertyWriteTarget; use TypePhp\Resolver\PropertyWriteTarget;
use TypePhp\Resolver\Reflection;
use TypePhp\Resolver\StaticPropertyFetchResolution; use TypePhp\Resolver\StaticPropertyFetchResolution;
use TypePhp\Resolver\StaticPropertyFetchTarget; use TypePhp\Resolver\StaticPropertyFetchTarget;
use TypePhp\TypeSystem\CompositeTypeCheckerTrait; use TypePhp\TypeSystem\CompositeTypeCheckerTrait;

@ -8,6 +8,8 @@
namespace TypePhp\Generator; namespace TypePhp\Generator;
use TypePhp\CompilerBase;
class Symbol class Symbol
{ {
public static function getStaticProperty(): string public static function getStaticProperty(): string

@ -8,6 +8,8 @@
namespace TypePhp\Metadata; namespace TypePhp\Metadata;
use TypePhp\CompilerBase;
class Constants class Constants
{ {
public const array CPP_RESERVED_NAMES = [ public const array CPP_RESERVED_NAMES = [

@ -2,6 +2,7 @@
namespace TypePhp\Parser; namespace TypePhp\Parser;
use TypePhp\CompilerBase;
use TypePhp\Resolver\Reflection; use TypePhp\Resolver\Reflection;
use PhpParser\Node; use PhpParser\Node;

@ -9,6 +9,7 @@
namespace TypePhp; namespace TypePhp;
use MJS\TopSort\Implementations\StringSort; use MJS\TopSort\Implementations\StringSort;
use TypePhp\Entity\ArgInfo;
use TypePhp\Entity\ArrayInitPlan; use TypePhp\Entity\ArrayInitPlan;
use TypePhp\Entity\ClassDef; use TypePhp\Entity\ClassDef;
use TypePhp\Entity\ConstantDef; use TypePhp\Entity\ConstantDef;
@ -17,6 +18,8 @@ use TypePhp\Entity\InterfaceDef;
use TypePhp\Entity\MethodDef; use TypePhp\Entity\MethodDef;
use TypePhp\Entity\PropertyDef; use TypePhp\Entity\PropertyDef;
use TypePhp\Exception\SyntaxError; use TypePhp\Exception\SyntaxError;
use TypePhp\Transform\PropertyHookLowering;
use TypePhp\Transform\Visitor;
use PhpParser\Modifiers; use PhpParser\Modifiers;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\IntersectionType; use PhpParser\Node\IntersectionType;

@ -11,6 +11,8 @@ namespace TypePhp;
use MJS\TopSort\Implementations\StringSort; use MJS\TopSort\Implementations\StringSort;
use TypePhp\Analysis\SsaBuilder; use TypePhp\Analysis\SsaBuilder;
use TypePhp\Backend\CompilerFactory; use TypePhp\Backend\CompilerFactory;
use TypePhp\Build\FileScanner;
use TypePhp\Entity\ArgInfo;
use TypePhp\Entity\ClassDef; use TypePhp\Entity\ClassDef;
use TypePhp\Entity\ClassLikeDef; use TypePhp\Entity\ClassLikeDef;
use TypePhp\Entity\ConstantDef; use TypePhp\Entity\ConstantDef;
@ -24,8 +26,12 @@ use TypePhp\Exception\SyntaxError;
use TypePhp\Exception\Unsupported; use TypePhp\Exception\Unsupported;
use TypePhp\Generator\ResourceFileGenerator; use TypePhp\Generator\ResourceFileGenerator;
use TypePhp\Generator\DefaultArgumentGenerator; use TypePhp\Generator\DefaultArgumentGenerator;
use TypePhp\Generator\Symbol;
use TypePhp\Metadata\Constants;
use TypePhp\Platform\PlatformFactory; use TypePhp\Platform\PlatformFactory;
use TypePhp\Platform\Windows; use TypePhp\Platform\Windows;
use TypePhp\Resolver\Reflection;
use TypePhp\Transform\Visitor;
use PhpParser\Modifiers; use PhpParser\Modifiers;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\ArrayItem; use PhpParser\Node\ArrayItem;

Loading…
Cancel
Save