-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgen_stub.php.diff
132 lines (124 loc) · 5.31 KB
/
gen_stub.php.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
diff --git a/build/gen_stub.php b/build/gen_stub.php
index 486ff67949..71265c12fa 100755
--- a/build/gen_stub.php
+++ b/build/gen_stub.php
@@ -733,10 +733,6 @@ class ArgInfo {
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;
}
@@ -793,7 +789,7 @@ class FunctionName implements FunctionOrMethodName {
}
public function getDeclarationName(): string {
- return $this->name->getLast();
+ return strtr($this->name->toString(), "\\", "_");
}
public function getDeclaration(): string {
@@ -910,10 +906,6 @@ class ReturnInfo {
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;
@@ -1152,8 +1144,8 @@ class FuncInfo {
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());
}
@@ -1616,7 +1608,7 @@ class EnumCaseInfo {
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");
@@ -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
@@ -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
);
@@ -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);
@@ -2829,7 +2845,9 @@ function generateArgInfoCode(FileInfo $fileInfo, string $stubHash): string {
}
$generatedFunctionDeclarations[$key] = true;
- return $fileInfo->declarationPrefix . $funcInfo->getDeclaration();
+ if ($decl = $funcInfo->getDeclaration()) {
+ return $fileInfo->declarationPrefix . $decl;
+ }
}
);
@@ -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);