Skip to content

Commit 62f92e0

Browse files
committed
Zend: make zend_type_kind a real enum, drop the leading underscore
Address review feedback. Signed-off-by: azjezz <azjezz@protonmail.com>
1 parent 4ebadfb commit 62f92e0

3 files changed

Lines changed: 27 additions & 24 deletions

File tree

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,7 @@ static void zend_convert_internal_arg_info_type(zend_type *type, bool persistent
29502950
zend_string *str = zend_string_init_interned(class_name, strlen(class_name), persistent);
29512951
zend_alloc_ce_cache(str);
29522952
ZEND_TYPE_SET_PTR(*type, str);
2953-
type->kind = _ZEND_TYPE_KIND_NAME;
2953+
type->kind = ZEND_TYPE_KIND_NAME;
29542954
} else {
29552955
/* Union type */
29562956
zend_type_list *list = pemalloc(ZEND_TYPE_LIST_SIZE(num_types), persistent);

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7621,7 +7621,7 @@ static zend_type zend_compile_typename_ex(
76217621
if (ZEND_TYPE_IS_COMPLEX(single_type)) {
76227622
if (!ZEND_TYPE_IS_COMPLEX(type) && !is_composite) {
76237623
/* The first class type can be stored directly as the type ptr payload. */
7624-
ZEND_TYPE_SET_PTR_AND_KIND(type, ZEND_TYPE_NAME(single_type), _ZEND_TYPE_KIND_NAME);
7624+
ZEND_TYPE_SET_PTR_AND_KIND(type, ZEND_TYPE_NAME(single_type), ZEND_TYPE_KIND_NAME);
76257625
} else {
76267626
if (type_list->num_types == 0) {
76277627
/* Switch from single name to name list. */

Zend/zend_types.h

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,22 @@ typedef void (*copy_ctor_func_t)(zval *pElement);
113113
* ZEND_TYPE_INIT_*() should be used for construction.
114114
*/
115115

116+
/* zend_type.kind discriminates what type.ptr points at. Exactly one value
117+
* applies at a time; it is a plain enum, not a bitmask like type_mask. */
118+
typedef enum {
119+
ZEND_TYPE_KIND_NONE = 0, /* no payload; ptr is NULL */
120+
ZEND_TYPE_KIND_NAME = 1, /* a `zend_string*` (class name) */
121+
ZEND_TYPE_KIND_LITERAL_NAME = 2, /* a `const char*` (literal class name) */
122+
ZEND_TYPE_KIND_LIST = 3, /* a `zend_type_list*` */
123+
} zend_type_kind;
124+
116125
typedef struct {
117126
/* Not using a union here, because there's no good way to initialize them
118127
* in a way that is supported in both C and C++ (designated initializers
119128
* are only supported since C++20). */
120129
void *ptr;
121130
uint32_t type_mask;
122-
uint32_t kind;
131+
zend_type_kind kind;
123132
} zend_type;
124133

125134
typedef struct {
@@ -141,28 +150,22 @@ typedef struct {
141150
#define _ZEND_TYPE_MAY_BE_MASK ((1u << 18) - 1)
142151
/* Must have same value as MAY_BE_NULL */
143152
#define _ZEND_TYPE_NULLABLE_BIT 0x2u
144-
/* zend_type.kind discriminates what type.ptr points at. It is a plain value,
145-
* not a bitmask: exactly one of these applies at a time. */
146-
#define _ZEND_TYPE_KIND_NONE 0u /* no payload; ptr is NULL */
147-
#define _ZEND_TYPE_KIND_NAME 1u /* a `zend_string*` (class name) */
148-
#define _ZEND_TYPE_KIND_LITERAL_NAME 2u /* a `const char*` (literal class name) */
149-
#define _ZEND_TYPE_KIND_LIST 3u /* a `zend_type_list*` */
150153

151154
#define ZEND_TYPE_IS_SET(t) \
152-
(((t).type_mask & _ZEND_TYPE_MASK) != 0 || (t).kind != _ZEND_TYPE_KIND_NONE)
155+
(((t).type_mask & _ZEND_TYPE_MASK) != 0 || (t).kind != ZEND_TYPE_KIND_NONE)
153156

154157
/* A complex type carries a ptr payload: a class name or a type list. */
155158
#define ZEND_TYPE_IS_COMPLEX(t) \
156-
((t).kind != _ZEND_TYPE_KIND_NONE)
159+
((t).kind != ZEND_TYPE_KIND_NONE)
157160

158161
#define ZEND_TYPE_HAS_NAME(t) \
159-
((t).kind == _ZEND_TYPE_KIND_NAME)
162+
((t).kind == ZEND_TYPE_KIND_NAME)
160163

161164
#define ZEND_TYPE_HAS_LITERAL_NAME(t) \
162-
((t).kind == _ZEND_TYPE_KIND_LITERAL_NAME)
165+
((t).kind == ZEND_TYPE_KIND_LITERAL_NAME)
163166

164167
#define ZEND_TYPE_HAS_LIST(t) \
165-
((t).kind == _ZEND_TYPE_KIND_LIST)
168+
((t).kind == ZEND_TYPE_KIND_LIST)
166169

167170
#define ZEND_TYPE_IS_ITERABLE_FALLBACK(t) \
168171
((((t).type_mask) & _ZEND_TYPE_ITERABLE_BIT) != 0)
@@ -251,7 +254,7 @@ typedef struct {
251254
} while (0)
252255

253256
#define ZEND_TYPE_SET_LIST(t, list) \
254-
ZEND_TYPE_SET_PTR_AND_KIND(t, list, _ZEND_TYPE_KIND_LIST)
257+
ZEND_TYPE_SET_PTR_AND_KIND(t, list, ZEND_TYPE_KIND_LIST)
255258

256259
/* FULL_MASK() includes the MAY_BE_* type mask, as well as additional metadata bits.
257260
* The PURE_MASK() only includes the MAY_BE_* type mask. */
@@ -282,10 +285,10 @@ typedef struct {
282285
#endif
283286

284287
#define ZEND_TYPE_INIT_NONE(extra_flags) \
285-
_ZEND_TYPE_PREFIX { NULL, (extra_flags), 0 }
288+
_ZEND_TYPE_PREFIX { NULL, (extra_flags), ZEND_TYPE_KIND_NONE }
286289

287290
#define ZEND_TYPE_INIT_MASK(_type_mask) \
288-
_ZEND_TYPE_PREFIX { NULL, (_type_mask), 0 }
291+
_ZEND_TYPE_PREFIX { NULL, (_type_mask), ZEND_TYPE_KIND_NONE }
289292

290293
#define ZEND_TYPE_INIT_CODE(code, allow_null, extra_flags) \
291294
ZEND_TYPE_INIT_MASK(((code) == _IS_BOOL ? MAY_BE_BOOL : ( (code) == IS_ITERABLE ? _ZEND_TYPE_ITERABLE_BIT : ((code) == IS_MIXED ? MAY_BE_ANY : (1 << (code))))) \
@@ -296,25 +299,25 @@ typedef struct {
296299
(((allow_null) ? _ZEND_TYPE_NULLABLE_BIT : 0) | (extra_flags)), (type_kind) }
297300

298301
#define ZEND_TYPE_INIT_PTR_MASK(ptr, type_mask) \
299-
_ZEND_TYPE_PREFIX { (void *) (ptr), (type_mask), 0 }
302+
_ZEND_TYPE_PREFIX { (void *) (ptr), (type_mask), ZEND_TYPE_KIND_NONE }
300303

301304
#define ZEND_TYPE_INIT_UNION(ptr, extra_flags) \
302-
_ZEND_TYPE_PREFIX { (void *) (ptr), (_ZEND_TYPE_UNION_BIT) | (extra_flags), _ZEND_TYPE_KIND_LIST }
305+
_ZEND_TYPE_PREFIX { (void *) (ptr), (_ZEND_TYPE_UNION_BIT) | (extra_flags), ZEND_TYPE_KIND_LIST }
303306

304307
#define ZEND_TYPE_INIT_INTERSECTION(ptr, extra_flags) \
305-
_ZEND_TYPE_PREFIX { (void *) (ptr), (_ZEND_TYPE_INTERSECTION_BIT) | (extra_flags), _ZEND_TYPE_KIND_LIST }
308+
_ZEND_TYPE_PREFIX { (void *) (ptr), (_ZEND_TYPE_INTERSECTION_BIT) | (extra_flags), ZEND_TYPE_KIND_LIST }
306309

307310
#define ZEND_TYPE_INIT_CLASS(class_name, allow_null, extra_flags) \
308-
ZEND_TYPE_INIT_PTR(class_name, _ZEND_TYPE_KIND_NAME, allow_null, extra_flags)
311+
ZEND_TYPE_INIT_PTR(class_name, ZEND_TYPE_KIND_NAME, allow_null, extra_flags)
309312

310313
#define ZEND_TYPE_INIT_CLASS_MASK(class_name, type_mask) \
311-
_ZEND_TYPE_PREFIX { (void *) (class_name), (type_mask), _ZEND_TYPE_KIND_NAME }
314+
_ZEND_TYPE_PREFIX { (void *) (class_name), (type_mask), ZEND_TYPE_KIND_NAME }
312315

313316
#define ZEND_TYPE_INIT_CLASS_CONST(class_name, allow_null, extra_flags) \
314-
ZEND_TYPE_INIT_PTR(class_name, _ZEND_TYPE_KIND_LITERAL_NAME, allow_null, extra_flags)
317+
ZEND_TYPE_INIT_PTR(class_name, ZEND_TYPE_KIND_LITERAL_NAME, allow_null, extra_flags)
315318

316319
#define ZEND_TYPE_INIT_CLASS_CONST_MASK(class_name, type_mask) \
317-
_ZEND_TYPE_PREFIX { (void *) (class_name), (type_mask), _ZEND_TYPE_KIND_LITERAL_NAME }
320+
_ZEND_TYPE_PREFIX { (void *) (class_name), (type_mask), ZEND_TYPE_KIND_LITERAL_NAME }
318321

319322
typedef union _zend_value {
320323
zend_long lval; /* long value */

0 commit comments

Comments
 (0)