refactor(docs): update file paths and directory structure references

- Change src/Php/Translator.php to src/Translator.php in documentation
- Update class hierarchy diagram to remove Php subdirectory references
- Modify composer.json autoloader to map TypePhp namespace to src directory only
- Adjust all src/Php/* paths to src/* in configuration and test files
- Update project.yml sources to include ./src instead of individual Php subdirectories
- Remove Php subdirectory from file paths in platform and analysis tests
- Clean up directory references in test results documentation
pull/15/head
韩天峰 2 months ago
parent 8ac4c5872d
commit 631a1ef6b2
  1. 2
      .github/copilot-instructions.md
  2. 38
      CLAUDE.md
  3. 5
      composer.json
  4. 2
      phpunit/TEST_RESULTS.md
  5. 2
      phpunit/src/Platform/PlatformTest.php
  6. 2
      phpunit/src/SsaAnalysisTest.php
  7. 9
      project.yml
  8. 0
      src/Analysis/SsaBuilder.php
  9. 0
      src/ArgInfo.php
  10. 0
      src/AstNodeType.php
  11. 0
      src/Backend/Clang.php
  12. 0
      src/Backend/CompilerBackend.php
  13. 0
      src/Backend/CompilerFactory.php
  14. 0
      src/Backend/Gcc.php
  15. 0
      src/Backend/GccLikeBackend.php
  16. 0
      src/Backend/Msvc.php
  17. 0
      src/CompilerBase.php
  18. 0
      src/CompilerTest.php
  19. 0
      src/Constants.php
  20. 0
      src/Context/FunctionContext.php
  21. 0
      src/Context/ScopeContext.php
  22. 0
      src/Entity/ArrayInitPlan.php
  23. 0
      src/Entity/ClassDef.php
  24. 0
      src/Entity/ClassLikeDef.php
  25. 0
      src/Entity/ConstantDef.php
  26. 0
      src/Entity/FunctionDef.php
  27. 0
      src/Entity/InterfaceDef.php
  28. 0
      src/Entity/MethodDef.php
  29. 0
      src/Entity/PropertyDef.php
  30. 0
      src/Exception/DynamicCall.php
  31. 0
      src/Exception/PlaceHolder.php
  32. 0
      src/Exception/Redo.php
  33. 0
      src/Exception/Skip.php
  34. 0
      src/Exception/SyntaxError.php
  35. 0
      src/Exception/TestError.php
  36. 0
      src/Exception/Unsupported.php
  37. 0
      src/Extractor.php
  38. 0
      src/FileScanner.php
  39. 0
      src/Generator/AnonClassGenerator.php
  40. 0
      src/Generator/ClosureGenerator.php
  41. 0
      src/Generator/PlaceHolderGenerator.php
  42. 0
      src/Generator/PropertyPromotion.php
  43. 0
      src/Generator/ResourceFileGenerator.php
  44. 0
      src/Generator/TypeCheckGenerator.php
  45. 0
      src/Generator/Utils.php
  46. 0
      src/MagicMethodDetector.php
  47. 0
      src/Optimizer/FuncCallOptimizer.php
  48. 0
      src/Optimizer/LoopVarOptimizer.php
  49. 0
      src/Optimizer/SsaPropOptimizer.php
  50. 0
      src/Optimizer/SsaTypeOptimizer.php
  51. 0
      src/Parser/AssignOpTrait.php
  52. 0
      src/Parser/BinaryOpTrait.php
  53. 0
      src/Parser/StdContainerTrait.php
  54. 0
      src/Parser/TypeConversionTrait.php
  55. 0
      src/Parser/TypeDetectionTrait.php
  56. 0
      src/Platform/Linux.php
  57. 0
      src/Platform/Macos.php
  58. 0
      src/Platform/PlatformBase.php
  59. 0
      src/Platform/PlatformFactory.php
  60. 0
      src/Platform/UnixPlatform.php
  61. 0
      src/Platform/Windows.php
  62. 0
      src/Preprocessor.php
  63. 0
      src/Reflection.php
  64. 0
      src/Resolver/InstancePropertyFetchTarget.php
  65. 0
      src/Resolver/NativePropertyAccess.php
  66. 0
      src/Resolver/PropertyAccessContext.php
  67. 0
      src/Resolver/PropertyAccessResolver.php
  68. 0
      src/Resolver/PropertyAccessResult.php
  69. 0
      src/Resolver/PropertyAssignTypeInfo.php
  70. 0
      src/Resolver/PropertyWriteTarget.php
  71. 0
      src/Resolver/StaticPropertyFetchResolution.php
  72. 0
      src/Resolver/StaticPropertyFetchTarget.php
  73. 0
      src/Symbol.php
  74. 0
      src/Translator.php
  75. 0
      src/UniversalMethodCall.php
  76. 0
      src/Visitor.php

@ -9,7 +9,7 @@ TypePHP is an ahead-of-time compiler that translates PHP source into C++, then c
3. `compile()` chooses the platform/compiler backend, generates support sources and headers, and compiles sources, using `pcntl` parallelism when available.
4. `build()` links object files into the final executable or extension.
`src/Php/CompilerBase.php` contains most PHP-to-C++ translation logic and mixes in many traits for syntax handling and optimizations. `src/Php/Preprocessor.php` owns dependency discovery and file ordering. Platform-specific behavior lives under `src/Php/Platform/`, compiler backends under `src/Php/Backend/`, and metadata/state objects under `src/Php/Entity/` and `src/Php/Context/`.
`src/CompilerBase.php` contains most PHP-to-C++ translation logic and mixes in many traits for syntax handling and optimizations. `src/Preprocessor.php` owns dependency discovery and file ordering. Platform-specific behavior lives under `src/Platform/`, compiler backends under `src/Backend/`, and metadata/state objects under `src/Entity/` and `src/Context/`.
## Setup and build commands

@ -50,7 +50,7 @@ php run-tests.php tests/aot/arrays.phpt
### Translation Pipeline
The compiler follows a 4-stage pipeline, orchestrated by `src/Php/Translator.php` (the main entry point):
The compiler follows a 4-stage pipeline, orchestrated by `src/Translator.php` (the main entry point):
1. **prepare()** — Scan PHP files, collect symbol declarations and dependencies, topological-sort for compilation order
2. **convert()** — Parse PHP AST via `nikic/php-parser`, translate each node to C++ source code
@ -60,31 +60,31 @@ The compiler follows a 4-stage pipeline, orchestrated by `src/Php/Translator.php
### Class Hierarchy
```
src/Php/CompilerBase (core PHP→C++ translation logic, indent/output/mode helpers)
src/CompilerBase.php (core PHP→C++ translation logic, indent/output/mode helpers)
├─ uses traits: AstNodeType, FuncCallOptimizer, ClosureGenerator,
│ PlaceHolderGenerator, PropertyPromotion, MagicMethodDetector
└─ src/Php/Preprocessor (scanning, symbol tables, dependency sort, YAML config)
└─ src/Php/Translator (full pipeline: prepare→convert→compile→build)
└─ src/Php/CompilerTest (test-only subclass, used by PHPUnit tests)
└─ src/Preprocessor.php (scanning, symbol tables, dependency sort, YAML config)
└─ src/Translator.php (full pipeline: prepare→convert→compile→build)
└─ src/CompilerTest.php (test-only subclass, used by PHPUnit tests)
```
### Key Components
| Directory | Purpose |
|-----------|---------|
| `src/Php/Entity/` | Data classes: `ClassDef`, `FunctionDef`, `MethodDef`, `PropertyDef`, `ConstantDef`, `InterfaceDef` |
| `src/Php/Generator/` | Codegen helpers: `ClosureGenerator`, `PlaceHolderGenerator`, `PropertyPromotion`, `Utils` |
| `src/Php/Backend/` | Compiler abstraction: `CompilerBackend` (abstract) → `Gcc`, `Clang`, `Msvc`. Factory pattern via `CompilerFactory` |
| `src/Php/Platform/` | OS abstraction: `PlatformBase``Linux`, `Macos`, `Windows`. Factory via `PlatformFactory` |
| `src/Php/Context/` | `ScopeContext` and `FunctionContext` for variable scoping and type tracking |
| `src/Php/Exception/` | `SyntaxError`, `Unsupported`, `DynamicCall`, `PlaceHolder`, `Skip`, `Redo`, `TestError` |
| `src/Php/Parser/` | Special-purpose parsers like `StdContainerParser` (C++ std container foreach support) |
| `src/Php/Reflection.php` | Static helpers wrapping PHP reflection (internal class/function detection) |
| `src/Php/Symbol.php` | Maps PHP operations to `phpx` C++ API symbol names |
| `src/Php/FileScanner.php` | Recursive file discovery with extension filtering (supports `.php`, `.cpp`, `.c`, `.s`, `.m`, `.mm`) |
| `src/Php/ArgInfo.php` | Generates C function argument info structures for internal function registration |
| `src/Php/Extractor.php` | Extracts interfaces from PHP classes |
| `src/Php/Visitor.php` | Base `NodeVisitorAbstract` extension (skeleton for custom AST visitors) |
| `src/Entity/` | Data classes: `ClassDef`, `FunctionDef`, `MethodDef`, `PropertyDef`, `ConstantDef`, `InterfaceDef` |
| `src/Generator/` | Codegen helpers: `ClosureGenerator`, `PlaceHolderGenerator`, `PropertyPromotion`, `Utils` |
| `src/Backend/` | Compiler abstraction: `CompilerBackend` (abstract) → `Gcc`, `Clang`, `Msvc`. Factory pattern via `CompilerFactory` |
| `src/Platform/` | OS abstraction: `PlatformBase``Linux`, `Macos`, `Windows`. Factory via `PlatformFactory` |
| `src/Context/` | `ScopeContext` and `FunctionContext` for variable scoping and type tracking |
| `src/Exception/` | `SyntaxError`, `Unsupported`, `DynamicCall`, `PlaceHolder`, `Skip`, `Redo`, `TestError` |
| `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/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/ArgInfo.php` | Generates C function argument info structures for internal function registration |
| `src/Extractor.php` | Extracts interfaces from PHP classes |
| `src/Visitor.php` | Base `NodeVisitorAbstract` extension (skeleton for custom AST visitors) |
### Configuration
@ -100,4 +100,4 @@ Generated `.cc` and `.o` files land in `build/` directory. The compiled binary i
- **PHPUnit tests** (`phpunit/src/`) — unit/integration tests for compiler internals. Bootstrap at `phpunit/bootstrap.php` defines a `BaseTest` class with an `exec()` helper that runs the compiler and expects a `TestError` exception containing a given string
- **PHPT tests** (`tests/aot/`) — end-to-end tests using the standard PHPT format (`run-tests.php`). Each `.phpt` contains PHP source and expected output sections
When writing new compiler tests, use `CompilerTest::create(ROOT_PATH)` (in `src/Php/CompilerTest.php`) which sets `forTest = true` to enable test-specific behavior without writing files to disk.
When writing new compiler tests, use `CompilerTest::create(ROOT_PATH)` (in `src/CompilerTest.php`) which sets `forTest = true` to enable test-specific behavior without writing files to disk.

@ -15,10 +15,7 @@
},
"autoload": {
"psr-4": {
"TypePhp\\": [
"src/Php",
"src"
]
"TypePhp\\": "src"
}
},
"scripts": {

@ -255,7 +255,7 @@ protected const string MODULE_NAME_PREFIX = 'app_';
### 方案 B:临时修改代码
修改 `src/Php/Translator.php`
修改 `src/Translator.php`
```php
// 第 31-32 行

@ -72,7 +72,7 @@ class PlatformTest extends TestCase
{
$platform = new Windows();
$this->assertEquals('src\Php\Backend', $platform->normalizePath('src/Php/Backend'));
$this->assertEquals('src\Backend', $platform->normalizePath('src/Backend'));
$this->assertEquals('C:\PHP\include', $platform->normalizePath('C:/PHP/include'));
}

@ -32,7 +32,7 @@ class SsaAnalysisTest extends TestCase
parent::setUp();
// SsaFlags, SsaVar, SsaBlock, etc. are defined in SsaBuilder.php
// but PSR-4 expects each class in its own file. Load them early.
require_once __DIR__ . '/../../src/Php/Analysis/SsaBuilder.php';
require_once __DIR__ . '/../../src/Analysis/SsaBuilder.php';
$this->tmpDir = sys_get_temp_dir() . '/ssa_test_' . uniqid();
mkdir($this->tmpDir, 0777, true);
$this->compiler = CompilerTest::create($this->tmpDir);

@ -30,9 +30,10 @@ resource:
# manifest: app.manifest
sources:
- ./src/Php
- ./src/functions.php
- ./src/gen_stub.php
- ./src/compiler.php
- ./src
- vendor/nikic/php-parser/lib/PhpParser/NodeVisitor.php
- vendor/nikic/php-parser/lib/PhpParser/NodeVisitorAbstract.php
ignore:
- ./src/Assert.php
- ./src/polyfills.php

Loading…
Cancel
Save