Skip to content

Commit 5a936ed

Browse files
committed
A few other changes
1 parent e5ace7e commit 5a936ed

File tree

3 files changed

+94
-15
lines changed

3 files changed

+94
-15
lines changed

build/gen_stub.php

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -725,13 +725,14 @@ function (Expr $expr) use (&$defaultValueConstant) {
725725
if ($this->type) {
726726
$typeFlags = $this->type->tryToRepresentableType();
727727
if ($typeFlags === null) {
728-
throw new Exception("Unimplemented property type");
728+
echo "Skipping code generation for property $this->name, because it has an unimplemented type\n";
729+
return "";
729730
}
730731

731732
if ($typeFlags->classType) {
732733
$simpleType = $this->type->tryToSimpleType();
733734
if ($simpleType) {
734-
$typeCode = "(zend_type) ZEND_TYPE_INIT_CE(class_entry_" . $typeFlags->classType->toEscapedName() . ", " . ((int) $this->type->isNullable()) . ", 0)";
735+
$typeCode = "(zend_type) ZEND_TYPE_INIT_CE(class_entry_" . str_replace("_", "\\", $typeFlags->classType->name) . ", " . ((int) $this->type->isNullable()) . ", 0)";
735736
} else {
736737
throw new Exception("Property $this->name has an unsupported union type");
737738
}
@@ -874,6 +875,8 @@ class ClassInfo {
874875
public $flags;
875876
/** @var bool */
876877
public $isClass;
878+
/** @var string|null */
879+
public $alias;
877880
/** @var bool */
878881
public $isDeprecated;
879882
/** @var bool */
@@ -897,6 +900,7 @@ public function __construct(
897900
Name $name,
898901
int $flags,
899902
bool $isClass,
903+
?string $alias,
900904
bool $isDeprecated,
901905
bool $isStrictProperties,
902906
array $extends,
@@ -907,6 +911,7 @@ public function __construct(
907911
$this->name = $name;
908912
$this->flags = $flags;
909913
$this->isClass = $isClass;
914+
$this->alias = $alias;
910915
$this->isDeprecated = $isDeprecated;
911916
$this->isStrictProperties = $isStrictProperties;
912917
$this->extends = $extends;
@@ -919,10 +924,10 @@ public function getRegistration(): string
919924
{
920925
$params = ["zend_class_entry *class_entry"];
921926
foreach ($this->extends as $extends) {
922-
$params[] = "zend_class_entry *class_entry_$extends";
927+
$params[] = "zend_class_entry *class_entry_" . implode("_", $extends->parts);
923928
}
924929
foreach ($this->implements as $implements) {
925-
$params[] = "zend_class_entry *class_entry_$implements";
930+
$params[] = "zend_class_entry *class_entry_" . implode("_", $implements->parts);
926931
}
927932
foreach ($this->propertyInfos as $property) {
928933
$type = $property->type;
@@ -932,20 +937,28 @@ public function getRegistration(): string
932937

933938
$representableType = $type->tryToRepresentableType();
934939
if ($representableType && $representableType->classType) {
935-
$params[] = "zend_class_entry *class_entry_" . $representableType->classType->toEscapedName();
940+
$params[] = "zend_class_entry *class_entry_" . str_replace("\\", "_", $representableType->classType->toEscapedName());
936941
}
937942
}
938943
$params = array_unique($params);
939944

940-
$code = "void register_class_{$this->name}(";
941-
$code .= implode(", ", $params);
942-
$code .= ")\n";
945+
$escapedName = implode("_", $this->name->parts);
946+
947+
$code = "void register_class_$escapedName(" . implode(", ", $params) . ")\n";
943948

944949
$code .= "{\n";
945950
$code .= "\tzend_class_entry ce;\n\n";
946-
$code .= "\tINIT_CLASS_ENTRY(ce, \"{$this->name}\", class_{$this->name}_methods);\n";
951+
if (count($this->name->parts) > 1) {
952+
$className = array_pop($this->name->parts);
953+
$namespace = $this->name->toCodeString();
954+
955+
$code .= "\tINIT_NS_CLASS_ENTRY(ce, \"$namespace\", \"$className\", class_{$escapedName}_methods);\n";
956+
} else {
957+
$code .= "\tINIT_CLASS_ENTRY(ce, \"$this->name\", class_{$escapedName}_methods);\n";
958+
}
959+
947960
if ($this->isClass) {
948-
$code .= "\tclass_entry = zend_register_internal_class_ex(&ce, " . (isset($this->extends[0]) ? "class_entry_" . $this->extends[0] : "NULL") . ");\n";
961+
$code .= "\tclass_entry = zend_register_internal_class_ex(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]) : "NULL") . ");\n";
949962
} else {
950963
$code .= "\tclass_entry = zend_register_internal_interface(&ce);\n";
951964
}
@@ -954,15 +967,19 @@ public function getRegistration(): string
954967
}
955968

956969
foreach ($this->implements as $implements) {
957-
$code .= "\tzend_class_implements(class_entry, 1, class_entry_$implements);\n";
970+
$code .= "\tzend_class_implements(class_entry, 1, class_entry_" . implode("_", $implements->parts) . ");\n";
958971
}
959972

960973
if ($this->isClass === false && $this->extends) {
961974
foreach ($this->extends as $extends) {
962-
$code .= "\tzend_class_implements(class_entry, 1, class_entry_$extends);\n";
975+
$code .= "\tzend_class_implements(class_entry, 1, class_entry_" . implode("_", $extends->parts) . ");\n";
963976
}
964977
}
965978

979+
if ($this->alias) {
980+
$code .= "\tzend_register_class_alias(\"" . str_replace("_", "\\", $this->alias) . "\", class_entry);\n";
981+
}
982+
966983
foreach ($this->propertyInfos as $property) {
967984
$code .= $property->getDeclaration();
968985
}
@@ -1269,13 +1286,16 @@ function parseProperty(
12691286
function parseClass(Name $name, Stmt\ClassLike $class, array $properties, array $methods): ClassInfo {
12701287
$flags = $class instanceof Class_ ? $class->flags : 0;
12711288
$comment = $class->getDocComment();
1289+
$alias = null;
12721290
$isDeprecated = false;
12731291
$isStrictProperties = false;
12741292

12751293
if ($comment) {
12761294
$tags = parseDocComment($comment);
12771295
foreach ($tags as $tag) {
1278-
if ($tag->name === 'deprecated') {
1296+
if ($tag->name === 'alias') {
1297+
$alias = $tag->getValue();
1298+
} else if ($tag->name === 'deprecated') {
12791299
$isDeprecated = true;
12801300
} else if ($tag->name === 'strict-properties') {
12811301
$isStrictProperties = true;
@@ -1299,6 +1319,7 @@ function parseClass(Name $name, Stmt\ClassLike $class, array $properties, array
12991319
$name,
13001320
$flags,
13011321
$class instanceof Class_,
1322+
$alias,
13021323
$isDeprecated,
13031324
$isStrictProperties,
13041325
$extends,

ext/zend_test/test.stub.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3-
/** @generate-function-entries static */
3+
/**
4+
* @generate-function-entries static
5+
* @generate-class-entries
6+
*/
47

58
namespace {
69

10+
/** @alias _ZendTestClassAlias */
711
class _ZendTestClass {
812
/** @var mixed */
913
public static $_StaticProp = null;

ext/zend_test/test_arginfo.h

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: e392cb9287329c2f71674e3601c705daf9d8833f */
2+
* Stub hash: d21949d572d7cb8440122b58b6fbce3421b18620 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -131,3 +131,57 @@ static const zend_function_entry class_ZendTestNS2_Foo_methods[] = {
131131
ZEND_ME(ZendTestNS2_Foo, method, arginfo_class_ZendTestNS2_Foo_method, ZEND_ACC_PUBLIC)
132132
ZEND_FE_END
133133
};
134+
135+
void register_class__ZendTestClass(zend_class_entry *class_entry, zend_class_entry *class_entry_stdClass)
136+
{
137+
zend_class_entry ce;
138+
139+
INIT_CLASS_ENTRY(ce, "_ZendTestClass", class__ZendTestClass_methods);
140+
class_entry = zend_register_internal_class_ex(&ce, NULL);
141+
zend_register_class_alias("\ZendTestClassAlias", class_entry);
142+
143+
zend_declare_property_null(class_entry, "_StaticProp", sizeof("_StaticProp") - 1, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC);
144+
145+
zval property_staticIntProp_default_value;
146+
ZVAL_LONG(&property_staticIntProp_default_value, 123);
147+
zend_string *property_staticIntProp_name = zend_string_init("staticIntProp", sizeof("staticIntProp") - 1, 1);
148+
zend_declare_typed_property(class_entry, property_staticIntProp_name, &property_staticIntProp_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
149+
zend_string_release(property_staticIntProp_name);
150+
151+
zval property_intProp_default_value;
152+
ZVAL_LONG(&property_intProp_default_value, 123);
153+
zend_string *property_intProp_name = zend_string_init("intProp", sizeof("intProp") - 1, 1);
154+
zend_declare_typed_property(class_entry, property_intProp_name, &property_intProp_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
155+
zend_string_release(property_intProp_name);
156+
157+
zval property_classProp_default_value;
158+
ZVAL_NULL(&property_classProp_default_value);
159+
zend_string *property_classProp_name = zend_string_init("classProp", sizeof("classProp") - 1, 1);
160+
zend_declare_typed_property(class_entry, property_classProp_name, &property_classProp_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_CE(class_entry_stdClass, 1, 0));
161+
zend_string_release(property_classProp_name);
162+
}
163+
164+
void register_class__ZendTestTrait(zend_class_entry *class_entry)
165+
{
166+
zend_class_entry ce;
167+
168+
INIT_CLASS_ENTRY(ce, "_ZendTestTrait", class__ZendTestTrait_methods);
169+
class_entry = zend_register_internal_interface(&ce);
170+
}
171+
172+
void register_class_ZendTestNS_Foo(zend_class_entry *class_entry)
173+
{
174+
zend_class_entry ce;
175+
176+
INIT_NS_CLASS_ENTRY(ce, "ZendTestNS", "Foo", class_ZendTestNS_Foo_methods);
177+
class_entry = zend_register_internal_class_ex(&ce, NULL);
178+
}
179+
180+
void register_class_ZendTestNS2_Foo(zend_class_entry *class_entry)
181+
{
182+
zend_class_entry ce;
183+
184+
INIT_NS_CLASS_ENTRY(ce, "ZendTestNS2", "Foo", class_ZendTestNS2_Foo_methods);
185+
class_entry = zend_register_internal_class_ex(&ce, NULL);
186+
}
187+

0 commit comments

Comments
 (0)