]> granicus.if.org Git - php/commitdiff
Renumber zval types, clarify allowed overlap
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 7 Jan 2020 13:53:25 +0000 (14:53 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 7 Jan 2020 13:55:52 +0000 (14:55 +0100)
Make it clear that types used for type declarations can overlap
with the rest, and can also overlap in MAY_BE space.

This makes things more robust against the addition of new primitive
types.

.gdbinit
Zend/zend_type_info.h
Zend/zend_types.h

index a903c086e53b427cde2d735e5cdf2672cc674858..be901f80a2f29c4bcffeaf294baac95446cebb75 100644 (file)
--- a/.gdbinit
+++ b/.gdbinit
@@ -255,31 +255,22 @@ define ____printzv_contents
                printf "CONSTANT_AST"
        end
        if $type == 12
-               printf "CALLABLE"
-       end
-       if $type == 13
-               printf "ITERABLE"
-       end
-       if $type == 14
-               printf "VOID"
-       end
-       if $type == 15
                printf "indirect: "
                ____printzv $zvalue->value.zv $arg1
        end
-       if $type == 16
+       if $type == 13
                printf "pointer: %p", $zvalue->value.ptr
        end
-       if $type == 17
+       if $type == 15
                printf "_ERROR"
        end
-       if $type == 18
+       if $type == 16
                printf "_BOOL"
        end
-       if $type == 19
+       if $type == 17
                printf "_NUMBER"
        end
-       if $type > 19
+       if $type > 17
                printf "unknown type %d", $type
        end
        printf "\n"
index ef2c6a19bc8e57fc97250cb70a63c954dc2e4d4c..752e6a4b850e9cbfef1e2eab7287a90d44795372 100644 (file)
 #define MAY_BE_ANY                  (MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_RESOURCE)
 #define MAY_BE_REF                  (1 << IS_REFERENCE) /* may be reference */
 
-/* These are used in zend_type, but not for type inference. */
+/* These are used in zend_type, but not for type inference.
+ * They are allowed to overlap with types used during inference. */
 #define MAY_BE_CALLABLE             (1 << IS_CALLABLE)
 #define MAY_BE_ITERABLE             (1 << IS_ITERABLE)
 #define MAY_BE_VOID                 (1 << IS_VOID)
 
-#define MAY_BE_ARRAY_SHIFT          (IS_VOID)
+#define MAY_BE_ARRAY_SHIFT          (IS_REFERENCE)
 
 #define MAY_BE_ARRAY_OF_NULL           (MAY_BE_NULL     << MAY_BE_ARRAY_SHIFT)
 #define MAY_BE_ARRAY_OF_FALSE          (MAY_BE_FALSE    << MAY_BE_ARRAY_SHIFT)
 #define MAY_BE_ARRAY_OF_ANY                    (MAY_BE_ANY      << MAY_BE_ARRAY_SHIFT)
 #define MAY_BE_ARRAY_OF_REF                    (MAY_BE_REF      << MAY_BE_ARRAY_SHIFT)
 
-#define MAY_BE_ARRAY_KEY_LONG       (1<<25)
-#define MAY_BE_ARRAY_KEY_STRING     (1<<26)
+#define MAY_BE_ARRAY_KEY_LONG       (1<<21)
+#define MAY_BE_ARRAY_KEY_STRING     (1<<22)
 #define MAY_BE_ARRAY_KEY_ANY        (MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_KEY_STRING)
 
-/* Bit 27 unused  */
-#define MAY_BE_CLASS                (1<<28)
+#define MAY_BE_CLASS                (1<<23)
 
 #endif /* ZEND_TYPE_INFO_H */
index e32538591b656aba95655a049c65337655cbf021..20fddd74c992e26616c97b59b20ec82b11371252 100644 (file)
@@ -137,7 +137,6 @@ typedef struct {
 
 #define _ZEND_TYPE_EXTRA_FLAGS_SHIFT 24
 #define _ZEND_TYPE_MASK ((1u << 24) - 1)
-#define _ZEND_TYPE_MAY_BE_MASK ((1u << (IS_VOID+1)) - 1)
 /* Only one of these bits may be set. */
 #define _ZEND_TYPE_NAME_BIT (1u << 23)
 #define _ZEND_TYPE_CE_BIT   (1u << 22)
@@ -145,6 +144,8 @@ typedef struct {
 #define _ZEND_TYPE_KIND_MASK (_ZEND_TYPE_LIST_BIT|_ZEND_TYPE_CE_BIT|_ZEND_TYPE_NAME_BIT)
 /* Whether the type list is arena allocated */
 #define _ZEND_TYPE_ARENA_BIT (1u << 20)
+/* Type mask excluding the flags above. */
+#define _ZEND_TYPE_MAY_BE_MASK ((1u << 20) - 1)
 /* Must have same value as MAY_BE_NULL */
 #define _ZEND_TYPE_NULLABLE_BIT 0x2
 
@@ -533,20 +534,21 @@ struct _zend_ast_ref {
 #define IS_REFERENCE                           10
 #define IS_CONSTANT_AST                                11 /* Constant expressions */
 
-/* Fake types used only for type hinting. IS_VOID should be the last. */
+/* Fake types used only for type hinting.
+ * These are allowed to overlap with the types below. */
 #define IS_CALLABLE                                    12
 #define IS_ITERABLE                                    13
 #define IS_VOID                                                14
 
 /* internal types */
-#define IS_INDIRECT                    15
-#define IS_PTR                                         16
-#define IS_ALIAS_PTR                           17
-#define _IS_ERROR                                      17
+#define IS_INDIRECT                    12
+#define IS_PTR                                         13
+#define IS_ALIAS_PTR                           14
+#define _IS_ERROR                                      15
 
 /* used for casts */
-#define _IS_BOOL                                       18
-#define _IS_NUMBER                                     19
+#define _IS_BOOL                                       16
+#define _IS_NUMBER                                     17
 
 static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
        return pz->u1.v.type;