Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,6 @@ public function getDefaultValueAsMethodSynopsisString(): ?string {

private function setTypes(?Type $type, ?Type $phpDocType): void
{
if ($phpDocType !== null && Type::equals($type, $phpDocType)) {
throw new Exception('PHPDoc param type "' . $phpDocType->__toString() . '" is unnecessary');
}

$this->type = $type;
$this->phpDocType = $phpDocType;
}
Expand Down Expand Up @@ -793,7 +789,7 @@ public function getNonNamespacedName(): string {
}

public function getDeclarationName(): string {
return $this->name->getLast();
return strtr($this->name->toString(), "\\", "_");
}

public function getDeclaration(): string {
Expand Down Expand Up @@ -910,10 +906,6 @@ public function getMethodSynopsisType(): ?Type {

private function setTypes(?Type $type, ?Type $phpDocType, bool $tentativeReturnType): void
{
if ($phpDocType !== null && Type::equals($type, $phpDocType)) {
throw new Exception('PHPDoc return type "' . $phpDocType->__toString() . '" is unnecessary');
}

$this->type = $type;
$this->phpDocType = $phpDocType;
$this->tentativeReturnType = $tentativeReturnType;
Expand Down Expand Up @@ -1152,8 +1144,8 @@ public function getFunctionEntry(): string {
if ($namespace) {
// Render A\B as "A\\B" in C strings for namespaces
return sprintf(
"\tZEND_NS_FE(\"%s\", %s, %s)\n",
addslashes($namespace), $declarationName, $this->getArgInfoName());
"\tZEND_NS_RAW_FENTRY(\"%s\", \"%s\", ZEND_FN(%s), %s, 0)\n",
addslashes($namespace), substr((string)$this->name, strlen($namespace)+1), $declarationName, $this->getArgInfoName());
} else {
return sprintf("\tZEND_FE(%s, %s)\n", $declarationName, $this->getArgInfoName());
}
Expand Down Expand Up @@ -1616,7 +1608,7 @@ public function __construct(string $name, ?Expr $value) {
public function getDeclaration(): string {
$escapedName = addslashes($this->name);
if ($this->value === null) {
$code = "\n\tzend_enum_add_case_cstr(class_entry, \"$escapedName\", NULL);\n";
$code = "\tzend_enum_add_case_cstr(class_entry, \"$escapedName\", NULL);\n";
} else {
$evaluator = new ConstExprEvaluator(function (Expr $expr) {
throw new Exception("Enum case $this->name has an unsupported value");
Expand Down Expand Up @@ -2373,7 +2365,7 @@ function parseFunctionLike(
function parseProperty(
Name $class,
int $flags,
Stmt\PropertyProperty $property,
Stmt\PropertyProperty|Node\Param $property,
?Node $type,
?DocComment $comment,
PrettyPrinterAbstract $prettyPrinter
Expand Down Expand Up @@ -2411,13 +2403,23 @@ function parseProperty(
}
}

$default = $property->default;
if ($property instanceof Node\Param) {
$name = $property->var->name;
if ($property->flags & Stmt\Class_::MODIFIER_READONLY) {
$default = null;
}
} else {
$name = $property->name;
}

return new PropertyInfo(
new PropertyName($class, $property->name->__toString()),
new PropertyName($class, (string) $name),
$flags,
$propertyType,
$phpDocType ? Type::fromString($phpDocType) : null,
$property->default,
$property->default ? $prettyPrinter->prettyPrintExpr($property->default) : null,
$default,
$default ? $prettyPrinter->prettyPrintExpr($default) : null,
$isDocReadonly,
$link
);
Expand Down Expand Up @@ -2602,6 +2604,20 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
$classStmt,
$cond
);
if ($classStmt->name->toString() === "__construct") {
foreach ($classStmt->params as $param) {
if ($param->flags) {
$propertyInfos[] = parseProperty(
$className,
$param->flags,
$param,
$param->type,
$param->getDocComment(),
$prettyPrinter
);
}
}
}
} else if ($classStmt instanceof Stmt\EnumCase) {
$enumCaseInfos[] = new EnumCaseInfo(
$classStmt->name->toString(), $classStmt->expr);
Expand Down Expand Up @@ -2829,7 +2845,9 @@ function (FuncInfo $funcInfo) use($fileInfo, &$generatedFunctionDeclarations) {
}

$generatedFunctionDeclarations[$key] = true;
return $fileInfo->declarationPrefix . $funcInfo->getDeclaration();
if ($decl = $funcInfo->getDeclaration()) {
return $fileInfo->declarationPrefix . $decl;
}
}
);

Expand Down Expand Up @@ -3275,7 +3293,7 @@ function initPhpParser() {
}

$isInitialized = true;
$version = "4.13.0";
$version = "4.13.2";
$phpParserDir = __DIR__ . "/PHP-Parser-$version";
if (!is_dir($phpParserDir)) {
installPhpParser($version, $phpParserDir);
Expand Down