feat(generator): 添加变量名参数支持PHP全局变量初始化

- 为initializeZval方法添加varName参数以支持全局变量赋值
- 在ZVAL初始化后添加php::global_vars映射设置
- 重置ZVAL类型标志确保正确的内存管理
- 更新函数调用以传递变量名称信息
pull/1/head
韩天峰 7 months ago
parent af9ecf336f
commit c3f5aca1a8
  1. 6
      bin/gen_stub.php

@ -2360,7 +2360,7 @@ class EvaluatedValue
$this->isUnknownConstValue = $isUnknownConstValue;
}
public function initializeZval(string $zvalName, bool $alreadyExists = false, string $forStringDef = ''): string
public function initializeZval(string $zvalName, bool $alreadyExists = false, string $forStringDef = '', string $varName = ''): string
{
$cExpr = $this->getCExpr();
@ -2401,6 +2401,8 @@ class EvaluatedValue
$tmpVar = $translator->genTmpVarName();
$code .= "\tauto $tmpVar = " . $translator->parseExpr($this->expr) . ";\n";
$code .= "\t{$tmpVar}.moveTo(&$zvalName);\n";
$code .= "\tphp::global_vars[\"$varName\"] = $zvalName;\n";
$code .= "\tZ_TYPE_FLAGS($zvalName) = 0;\n";
}
} else {
throw new Exception("Invalid default value: " . print_r($this->value, true) . ", type: " . print_r($this->type, true));
@ -3192,7 +3194,7 @@ class PropertyInfo extends VariableLike
if ($this->defaultValue === null && $this->type !== null) {
$code .= "\tzval $zvalName;\n\tZVAL_UNDEF(&$zvalName);\n";
} else {
$code .= $defaultValue->initializeZval($zvalName);
$code .= $defaultValue->initializeZval($zvalName, varName: $this->name->__toString());
}
[$stringInit, $nameCode, $stringRelease] = StringBuilder::getString(

Loading…
Cancel
Save