Skip to content

Commit be369de

Browse files
committed
Deduplicate code for handling zend_type in inference
This should be doing the same for the argument and the property type case.
1 parent ed88dae commit be369de

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,23 +2210,29 @@ static uint32_t zend_convert_type_declaration_mask(uint32_t type_mask) {
22102210
return result_mask;
22112211
}
22122212

2213-
ZEND_API uint32_t zend_fetch_arg_info_type(const zend_script *script, zend_arg_info *arg_info, zend_class_entry **pce)
2213+
static uint32_t zend_convert_type(const zend_script *script, zend_type type, zend_class_entry **pce)
22142214
{
2215-
uint32_t tmp;
2215+
if (pce) {
2216+
*pce = NULL;
2217+
}
22162218

2217-
*pce = NULL;
2218-
if (!ZEND_TYPE_IS_SET(arg_info->type)) {
2219+
if (!ZEND_TYPE_IS_SET(type)) {
22192220
return MAY_BE_ANY|MAY_BE_ARRAY_KEY_ANY|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF|MAY_BE_RC1|MAY_BE_RCN;
22202221
}
22212222

2222-
tmp = zend_convert_type_declaration_mask(ZEND_TYPE_PURE_MASK(arg_info->type));
2223-
if (ZEND_TYPE_HAS_CLASS(arg_info->type)) {
2223+
uint32_t tmp = zend_convert_type_declaration_mask(ZEND_TYPE_PURE_MASK(type));
2224+
if (ZEND_TYPE_HAS_CLASS(type)) {
22242225
tmp |= MAY_BE_OBJECT;
2225-
/* As we only have space to store one CE, we use a plain object type for class unions. */
2226-
if (ZEND_TYPE_HAS_NAME(arg_info->type)) {
2227-
zend_string *lcname = zend_string_tolower(ZEND_TYPE_NAME(arg_info->type));
2228-
*pce = zend_optimizer_get_class_entry(script, lcname);
2229-
zend_string_release_ex(lcname, 0);
2226+
if (pce) {
2227+
/* As we only have space to store one CE,
2228+
* we use a plain object type for class unions. */
2229+
if (ZEND_TYPE_HAS_CE(type)) {
2230+
*pce = ZEND_TYPE_CE(type);
2231+
} else if (ZEND_TYPE_HAS_NAME(type)) {
2232+
zend_string *lcname = zend_string_tolower(ZEND_TYPE_NAME(type));
2233+
*pce = zend_optimizer_get_class_entry(script, lcname);
2234+
zend_string_release_ex(lcname, 0);
2235+
}
22302236
}
22312237
}
22322238
if (tmp & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) {
@@ -2235,6 +2241,11 @@ ZEND_API uint32_t zend_fetch_arg_info_type(const zend_script *script, zend_arg_i
22352241
return tmp;
22362242
}
22372243

2244+
ZEND_API uint32_t zend_fetch_arg_info_type(const zend_script *script, zend_arg_info *arg_info, zend_class_entry **pce)
2245+
{
2246+
return zend_convert_type(script, arg_info->type, pce);
2247+
}
2248+
22382249
static zend_property_info *lookup_prop_info(zend_class_entry *ce, zend_string *name, zend_class_entry *scope) {
22392250
zend_property_info *prop_info;
22402251

@@ -2323,29 +2334,14 @@ static zend_property_info *zend_fetch_static_prop_info(const zend_script *script
23232334

23242335
static uint32_t zend_fetch_prop_type(const zend_script *script, zend_property_info *prop_info, zend_class_entry **pce)
23252336
{
2326-
if (pce) {
2327-
*pce = NULL;
2328-
}
2329-
if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) {
2330-
uint32_t type = zend_convert_type_declaration_mask(ZEND_TYPE_PURE_MASK(prop_info->type));
2331-
if (ZEND_TYPE_HAS_CLASS(prop_info->type)) {
2332-
type |= MAY_BE_OBJECT;
2333-
if (pce) {
2334-
if (ZEND_TYPE_HAS_CE(prop_info->type)) {
2335-
*pce = ZEND_TYPE_CE(prop_info->type);
2336-
} else if (ZEND_TYPE_HAS_NAME(prop_info->type)) {
2337-
zend_string *lcname = zend_string_tolower(ZEND_TYPE_NAME(prop_info->type));
2338-
*pce = zend_optimizer_get_class_entry(script, lcname);
2339-
zend_string_release(lcname);
2340-
}
2341-
}
2337+
if (!prop_info) {
2338+
if (pce) {
2339+
*pce = NULL;
23422340
}
2343-
if (type & (MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)) {
2344-
type |= MAY_BE_RC1 | MAY_BE_RCN;
2345-
}
2346-
return type;
2341+
return MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_RC1 | MAY_BE_RCN;
23472342
}
2348-
return MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF | MAY_BE_RC1 | MAY_BE_RCN;
2343+
2344+
return zend_convert_type(script, prop_info->type, pce);
23492345
}
23502346

23512347
static zend_always_inline int _zend_update_type_info(

0 commit comments

Comments
 (0)