@@ -112,28 +112,27 @@ def format_type(self, t):
112112 for bit in range (0 , type_mask_size ):
113113 if type_mask & (1 << bit ):
114114 type_name = ZendTypeBits .zendTypeName (bit )
115- match type_name :
116- case None :
117- parts .append ('(1<<%d)' % bit )
118- case 'list' :
119- list = t ['ptr' ].cast (gdb .lookup_type ('zend_type_list' ).pointer ())
120- num_types = int (list ['num_types' ])
121- types = list ['types' ].dereference ().cast (gdb .lookup_type ('zend_type' ).array (num_types ))
122- for i in range (0 , num_types ):
123- str = self .format_type (types [i ])
124- if any ((c in set ('|&()' )) for c in str ):
125- str = '(%s)' % str
126- parts .append (str )
127- case 'union' | 'arena' :
128- meta .append (type_name )
129- case 'intersection' :
130- meta .append (type_name )
131- separator = '&'
132- case 'name' :
133- str = t ['ptr' ].cast (gdb .lookup_type ('zend_string' ).pointer ())
134- parts .append (format_zstr (str ))
135- case _:
136- parts .append (type_name )
115+ if type_name is None :
116+ parts .append ('(1<<%d)' % bit )
117+ elif type_name == 'list' :
118+ list_ptr = t ['ptr' ].cast (gdb .lookup_type ('zend_type_list' ).pointer ())
119+ num_types = int (list_ptr ['num_types' ])
120+ types = list_ptr ['types' ].dereference ().cast (gdb .lookup_type ('zend_type' ).array (num_types ))
121+ for i in range (0 , num_types ):
122+ type_str = self .format_type (types [i ])
123+ if any ((c in set ('|&()' )) for c in type_str ):
124+ type_str = '(%s)' % type_str
125+ parts .append (type_str )
126+ elif type_name == 'union' or type_name == 'arena' :
127+ meta .append (type_name )
128+ elif type_name == 'intersection' :
129+ meta .append (type_name )
130+ separator = '&'
131+ elif type_name == 'name' :
132+ name_str = t ['ptr' ].cast (gdb .lookup_type ('zend_string' ).pointer ())
133+ parts .append (format_zstr (name_str ))
134+ else :
135+ parts .append (type_name )
137136
138137 str = separator .join (parts )
139138
@@ -403,15 +402,15 @@ def __init__(self, val):
403402 self .val = val
404403
405404 def to_string (self ):
406- match int (self .val ['type' ]):
407- case ZendFnTypes .ZEND_INTERNAL_FUNCTION :
408- typestr = 'internal'
409- case ZendFnTypes .ZEND_USER_FUNCTION :
410- typestr = 'user'
411- case ZendFnTypes .ZEND_EVAL_CODE :
412- typestr = 'eval'
413- case _ :
414- typestr = '???'
405+ val_type = int (self .val ['type' ])
406+ if val_type == ZendFnTypes .ZEND_INTERNAL_FUNCTION :
407+ typestr = 'internal'
408+ elif val_type == ZendFnTypes .ZEND_USER_FUNCTION :
409+ typestr = 'user'
410+ elif val_type == ZendFnTypes .ZEND_EVAL_CODE :
411+ typestr = 'eval'
412+ else :
413+ typestr = '???'
415414
416415 if self .val ['common' ]['function_name' ]:
417416 namestr = format_zstr (self .val ['common' ]['function_name' ])
@@ -831,13 +830,12 @@ def format(self, flags):
831830
832831 bits = self ._bits
833832 type_bits = None
834- match type_name :
835- case 'string' :
836- type_bits = self ._str_bits
837- case 'array' :
838- type_bits = self ._array_bits
839- case 'object' :
840- type_bits = self ._obj_bits
833+ if type_name == 'string' :
834+ type_bits = self ._str_bits
835+ elif type_name == 'array' :
836+ type_bits = self ._array_bits
837+ elif type_name == 'object' :
838+ type_bits = self ._obj_bits
841839
842840 type_flags = flags & self ._flags_mask
843841 for i in range (0 , 31 ):
@@ -860,15 +858,14 @@ def format(self, flags):
860858
861859 if (flags & (1 << self .bit ('GC_NOT_COLLECTABLE' ))) == 0 :
862860 gc_color = (flags >> self ._info_shift ) & self ._gc_color
863- match gc_color :
864- case self ._gc_black :
865- names .append ('GC_BLACK' )
866- case self ._gc_white :
867- names .append ('GC_WHITE' )
868- case self ._gc_grey :
869- names .append ('GC_GREY' )
870- case self ._gc_purple :
871- names .append ('GC_PURPLE' )
861+ if gc_color == self ._gc_black :
862+ names .append ('GC_BLACK' )
863+ elif gc_color == self ._gc_white :
864+ names .append ('GC_WHITE' )
865+ elif gc_color == self ._gc_grey :
866+ names .append ('GC_GREY' )
867+ elif gc_color == self ._gc_purple :
868+ names .append ('GC_PURPLE' )
872869
873870 gc_address = (flags >> self ._info_shift ) & self ._gc_address
874871 if gc_address != 0 :
@@ -907,17 +904,16 @@ def _load(self):
907904 pattern = re .compile (r'#define (GC_[^\s]+)\s+((0x)?[0-9a-f]+)' )
908905 matches = pattern .findall (content )
909906 for name , bit , _ in matches :
910- match name :
911- case 'GC_TYPE_MASK' :
912- self ._type_mask = int (bit , 0 )
913- case 'GC_FLAGS_MASK' :
914- self ._flags_mask = int (bit , 0 )
915- case 'GC_INFO_MASK' :
916- self ._info_mask = int (bit , 0 )
917- case 'GC_INFO_SHIFT' :
918- self ._info_shift = int (bit , 0 )
919- case 'GC_FLAGS_SHIFT' :
920- self ._flags_shift = int (bit , 0 )
907+ if name == 'GC_TYPE_MASK' :
908+ self ._type_mask = int (bit , 0 )
909+ elif name == 'GC_FLAGS_MASK' :
910+ self ._flags_mask = int (bit , 0 )
911+ elif name == 'GC_INFO_MASK' :
912+ self ._info_mask = int (bit , 0 )
913+ elif name == 'GC_INFO_SHIFT' :
914+ self ._info_shift = int (bit , 0 )
915+ elif name == 'GC_FLAGS_SHIFT' :
916+ self ._flags_shift = int (bit , 0 )
921917
922918 # IS_STR_INTERNED GC_IMMUTABLE
923919 # IS_STR_PERMANENT (1<<8)
@@ -928,13 +924,12 @@ def _load(self):
928924 bit = bits .get (val )
929925 if bit == None :
930926 continue
931- match type :
932- case 'STR' :
933- target = str_bits
934- case 'ARRAY' :
935- target = array_bits
936- case 'OBJ' :
937- target = obj_bits
927+ if type == 'STR' :
928+ target = str_bits
929+ elif type == 'ARRAY' :
930+ target = array_bits
931+ elif type == 'OBJ' :
932+ target = obj_bits
938933 target [name ] = int (bit )
939934
940935 # Hard coded because these are not exposed in header files
0 commit comments