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.
 
 

89 lines
2.7 KiB

<?php
/**
* This file is part of TypePHP.
*
* @link https://www.swoole.com/
* @contact service@swoole.com
*/
namespace TypePhp\Entity;
use TypePhp\Entity\ArgInfo;
use PhpParser\NodeAbstract;
class FunctionDef
{
public string $name;
public string $returnType;
/**
* @var array<ArgInfo>
*/
public array $argInfoList = [];
public int $argCountRequired = 0;
public string $params = '';
public string $namespace;
public bool $method = false;
public bool $stub = false;
/** Library that owns this stub function, as declared by @typephp-library. */
public string $library = '';
public bool $returnTypeUndeclared = false;
public bool $returnsByRef = false;
public bool $generator = false;
/** Number of fixed positional values returned through the internal tuple fast path. */
public int $multiReturnCount = 0;
/** Source file containing this function definition. */
public string $sourceFile = '';
/** First source line of this function definition. */
public int $startLine = 1;
/**
* @var string 必须是带有命名空间的完整类名
*/
public string $returnClass = '';
/**
* Late-bound return type keyword: 'self', 'static' or 'parent'.
* Empty for ordinary class-name return types. When set, the effective class
* depends on the consuming context (e.g. a trait method's `self` resolves to
* the class that uses the trait), so it must be re-resolved when the method
* is flattened into a class.
*/
public string $returnTypeKeyword = '';
/** Same format as ArgInfo::$typeCheck. Null means no runtime return type check. */
public ?array $returnTypeCheck = null;
/** Human-readable return type string for error messages. */
public string $returnTypeStr = '';
/** Original union/nullable return type AST node. */
public ?NodeAbstract $returnTypeNode = null;
public function __construct(string $name, string $returnType, string $namespace)
{
$this->name = $name;
$this->returnType = $returnType;
$this->namespace = $namespace;
}
public function getNamespacedName(): string
{
return $this->namespace ? $this->namespace . '\\' . $this->name : $this->name;
}
public function hasVariadicArg(): bool
{
return $this->argInfoList && $this->argInfoList[count($this->argInfoList) - 1]->variadic;
}
public function hasMultiReturn(): bool
{
return $this->multiReturnCount > 0;
}
public function getMultiReturnCppType(): string
{
return 'std::tuple<' . implode(', ', array_fill(0, $this->multiReturnCount, 'php::Var')) . '>';
}
}