TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
3.9 KiB
154 lines
3.9 KiB
<?php
|
|
/**
|
|
* This file is part of TypePHP.
|
|
*
|
|
* @link https://www.swoole.com/
|
|
* @contact service@swoole.com
|
|
*/
|
|
|
|
namespace TypePhp\Entity;
|
|
|
|
use TypePhp\Context\FunctionContext;
|
|
use PhpParser\Modifiers;
|
|
use PhpParser\Node\Stmt\Trait_;
|
|
|
|
class ClassDef extends ClassLikeDef
|
|
{
|
|
/**
|
|
* @var array<string, MethodDef>
|
|
*/
|
|
public array $methods = [];
|
|
|
|
/**
|
|
* @var array<string, PropertyDef>
|
|
*/
|
|
public array $properties = [];
|
|
|
|
/**
|
|
* @var array<string, ConstantDef>
|
|
*/
|
|
public array $constants = [];
|
|
public array $implements = [];
|
|
public string $extends = '';
|
|
public bool $requireCtor = false;
|
|
public bool $enum = false;
|
|
public ?string $extensionProviderTarget = null;
|
|
|
|
/**
|
|
* Backing type for backed enums ('int' or 'string'), null for pure enums.
|
|
*/
|
|
public ?string $enumBackingType = null;
|
|
|
|
/**
|
|
* Enum cases: case name => backing value (int/string for backed enums, null for pure enums).
|
|
* @var array<string, int|string|null>
|
|
*/
|
|
public array $enumCases = [];
|
|
/**
|
|
* Abstract method name (lowercase) => flags
|
|
* @var array<string, int>
|
|
*/
|
|
public array $abstractMethods = [];
|
|
|
|
/**
|
|
* Abstract method name (lowercase) => method definition
|
|
* @var array<string, MethodDef>
|
|
*/
|
|
public array $abstractMethodDefs = [];
|
|
public ?Trait_ $trait = null;
|
|
|
|
/**
|
|
* FullMethodName -> alias list
|
|
* @var array<string, array<int, array{newName: string, newModifier: int}>>
|
|
*/
|
|
public array $traitAliases = [];
|
|
|
|
/**
|
|
* FullMethodName -> true
|
|
* @var array<string, bool>
|
|
*/
|
|
public array $traitIgnored = [];
|
|
public int $flags;
|
|
public bool $inheritedFromInternalClass = false;
|
|
public string $ctorInit = '';
|
|
public string $ctorClean = '';
|
|
public FunctionContext $propertyContext;
|
|
|
|
public function __construct(string $name, int $flags, string $namespace = '')
|
|
{
|
|
$this->flags = $flags;
|
|
$this->propertyContext = new FunctionContext();
|
|
parent::__construct($name, $namespace);
|
|
}
|
|
|
|
public function addMethod(MethodDef $method): void
|
|
{
|
|
$this->methods[strtolower($method->name)] = $method;
|
|
}
|
|
|
|
public function addAbstractMethod(string $name, int $flags, ?MethodDef $methodDef = null): void
|
|
{
|
|
$lower = strtolower($name);
|
|
$this->abstractMethods[$lower] = $flags;
|
|
if ($methodDef !== null) {
|
|
$this->abstractMethodDefs[$lower] = $methodDef;
|
|
}
|
|
}
|
|
|
|
public function hasMethod(string $method): bool
|
|
{
|
|
return isset($this->methods[strtolower($method)]);
|
|
}
|
|
|
|
public function hasAbstractMethod(string $method): bool
|
|
{
|
|
return isset($this->abstractMethods[strtolower($method)]);
|
|
}
|
|
|
|
/**
|
|
* Returns method flags for concrete or abstract methods. Returns 0 if not found.
|
|
*/
|
|
public function getMethodFlags(string $method): int
|
|
{
|
|
$lower = strtolower($method);
|
|
if (isset($this->methods[$lower])) {
|
|
return $this->methods[$lower]->flags;
|
|
}
|
|
return $this->abstractMethods[$lower] ?? 0;
|
|
}
|
|
|
|
public function hasProperty(string $property): bool
|
|
{
|
|
return isset($this->properties[$property]);
|
|
}
|
|
|
|
public function hasConstant(string $name): bool
|
|
{
|
|
return isset($this->constants[$name]);
|
|
}
|
|
|
|
public function getProperty($property): PropertyDef
|
|
{
|
|
return $this->properties[$property];
|
|
}
|
|
|
|
public function getMethod($method): MethodDef
|
|
{
|
|
return $this->methods[strtolower($method)];
|
|
}
|
|
|
|
public function getAbstractMethod($method): MethodDef
|
|
{
|
|
return $this->abstractMethodDefs[strtolower($method)];
|
|
}
|
|
|
|
public function getConstant($name): ConstantDef
|
|
{
|
|
return $this->constants[$name];
|
|
}
|
|
|
|
public function isAbstract(): bool
|
|
{
|
|
return $this->flags & Modifiers::ABSTRACT;
|
|
}
|
|
}
|
|
|