Debug TypeOf

Share your advanced PureBasic knowledge/code with the community.
User avatar
Piero
Addict
Addict
Posts: 914
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Debug TypeOf

Post by Piero »

Code: Select all

; compilerif #pb_compiler_debugger
   procedure.s PrintTypeOf(t)
      select t
         case #pb_byte : procedurereturn "Byte"
         case #pb_word : procedurereturn "Word"
         case #pb_long : procedurereturn "Long"
         case #pb_string : procedurereturn "String"
         case #pb_structure : procedurereturn "Structure"
         case #pb_float : procedurereturn "Float"
         case #pb_character : procedurereturn "Character"
         case #pb_double : procedurereturn "Double"
         case #pb_quad : procedurereturn "Quad"
         case #pb_list : procedurereturn "List"
         case #pb_array : procedurereturn "Array"
         case #pb_integer : procedurereturn "Integer"
         case #pb_map : procedurereturn "Map"
         case #pb_ascii : procedurereturn "Ascii"
         case #pb_unicode : procedurereturn "Unicode"
         case #pb_interface : procedurereturn "Interface"
         default : procedurereturn "Unknown"
      endselect
   endprocedure

   macro dq
      "
   endmacro
; compilerendif

macro dto(t)
   compilerif #pb_compiler_debugger
      debug dq#t#dq + ~":\n" +
         "#"+typeof(t)+" | "+printtypeof(typeof(t))+" | "+sizeof(t)+" byte"+mid("s",bool(sizeof(t)=1)+1)
   compilerendif
endmacro

define d.d
dto(D)
Please see my next post below for an updated version…
Last edited by Piero on Fri Aug 29, 2025 11:14 pm, edited 1 time in total.
User avatar
Skipper
User
User
Posts: 54
Joined: Thu Dec 19, 2024 1:26 pm
Location: NW-Europe

Re: Debug TypeOf

Post by Skipper »

Thank you, Piero. Very interesting!
<< Win-11 (x64) / Mint linux (x64) / MacOS Monterey (x64) >>
User avatar
Piero
Addict
Addict
Posts: 914
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Debug TypeOf

Post by Piero »

More (optional) infos:

Code: Select all

; compilerif #pb_compiler_debugger
   procedure.s PrintTypeOf(t)
      select t
         case #pb_byte : procedurereturn "Byte"
         case #pb_word : procedurereturn "Word"
         case #pb_long : procedurereturn "Long"
         case #pb_string : procedurereturn "String"
         case #pb_structure : procedurereturn "Structure"
         case #pb_float : procedurereturn "Float"
         case #pb_character : procedurereturn "Character"
         case #pb_double : procedurereturn "Double"
         case #pb_quad : procedurereturn "Quad"
         case #pb_list : procedurereturn "List"
         case #pb_array : procedurereturn "Array"
         case #pb_integer : procedurereturn "Integer"
         case #pb_map : procedurereturn "Map"
         case #pb_ascii : procedurereturn "Ascii"
         case #pb_unicode : procedurereturn "Unicode"
         case #pb_interface : procedurereturn "Interface"
         case #pb_fixedstring : procedurereturn "Fixed String"
         default : procedurereturn "Unknown"
      endselect
   endprocedure

   procedure.s PrintTypeInfo(t.s)
      select t
         case "Byte" : procedurereturn "-128 to +127 .b"
         case "Ascii" : procedurereturn "0 to +255 .a"
         case "Character" : procedurereturn "0 to +65535 .c"
         case "Word" : procedurereturn "-32768 to +32767 .w"
         case "Unicode" : procedurereturn "0 to +65535 .u"
         case "Long" : procedurereturn "-2147483648 to +2147483647 .l"
         case "Integer" : procedurereturn ~"64 bit -9223372036854775808 to +9223372036854775807 .i\n"+
            "32 bit -2147483648 to +2147483647 .i"
         case "Float" : procedurereturn "Unlimited .f"
         case "Quad" : procedurereturn "-9223372036854775808 to +9223372036854775807 .q"
         case "Double" : procedurereturn "Unlimited .d"
         case "String" : procedurereturn "Unlimited .s $"
         case "Fixed String" : procedurereturn "Unlimited .s{Length}"
         default : procedurereturn "N/A"
      endselect
   endprocedure

   macro dq
      "
   endmacro
; compilerendif
   
macro dti(t) ; more info
   compilerif #pb_compiler_debugger
      if typeof(t)=#pb_string: debug "ByteLength: "+stringbytelength(str$) :endif
      debug "Debug Value:" : debug t
      debug "Range and Extension:" : debug printtypeinfo(printtypeof(typeof(t)))
      debug ~"\n--------\n"
   compilerendif
endmacro

macro dto(t,i=0)
   compilerif #pb_compiler_debugger
      debug dq#t#dq + ~":\n" +
         "#"+typeof(t)+" | "+printtypeof(typeof(t))+" | "+sizeof(t)+" byte"+mid("s",bool(sizeof(t)=1)+1)
      if i : dti(t) : else : debug ~"\n--------\n" : endif ; more info?
   compilerendif
endmacro

define d.d
dto(D) ; dto(D,1) ; to print more info

define asciichar.a
dto(AsciiChar,1) ; dto(AsciiChar) ; to print less info

define str.s{11} = "0123456789A"
dto(Str,1)

define str$ = "0123456789A0123456789A" ; size always 8 (needs StringByteLength)
dto(Str$,1)
Edit: Testing strings; fixed the "Fixed String" :mrgreen: (it wasn't in PB help)
Last edited by Piero on Sat Aug 30, 2025 1:17 am, edited 4 times in total.
User avatar
Piero
Addict
Addict
Posts: 914
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Debug TypeOf

Post by Piero »

Skipper wrote: Fri Aug 29, 2025 2:03 pm Thank you, Piero. Very interesting!
You are very welcome :D

I'm "testing PB macro stuff" after seeing I can also pass logic expressions (see IIF) and more…
It also made me refresh my multicolumn selection skills (TextMate Mac, with some quick LibreOffice for even more selection speed…)
I mostly copied the possible values from PB help…
This time I didn't use/need a "PB debug + Regexp" mix…

Hope I wasn't too cryptic :)

Edit: added the Mystery Gadget link :lol:
Last edited by Piero on Fri Aug 29, 2025 8:59 pm, edited 3 times in total.
User avatar
Skipper
User
User
Posts: 54
Joined: Thu Dec 19, 2024 1:26 pm
Location: NW-Europe

Re: Debug TypeOf

Post by Skipper »

Piero wrote: Fri Aug 29, 2025 6:47 pm Hope I wasn't too cryptic :)
No you weren't, all clear, read you '5'. I'm curious about what comes next... :D

Skipper
<< Win-11 (x64) / Mint linux (x64) / MacOS Monterey (x64) >>
User avatar
Piero
Addict
Addict
Posts: 914
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Debug TypeOf

Post by Piero »

Skipper wrote: Fri Aug 29, 2025 8:03 pmI'm curious about what comes next... :D
"The Return of the Mystery Gadget!"² :shock:

Code: Select all

debug #pb_byte
debug #pb_word
debug #pb_long
debug #pb_structure
debug #pb_string
debug #pb_float
debug #pb_fixedstring
debug #pb_character
debug #pb_double
debug #pb_quad
debug #pb_list
debug #pb_array
debug #pb_integer
debug #pb_map
debug #pb_ascii
debug #pb_unicode
debug #pb_interface
Edit: Found on IDE src with TextMate:

Code: Select all

#PB_Byte        = 1
#PB_Word        = 3
#PB_Long        = 5
#PB_Structure   = 7
#PB_String      = 8
#PB_Float       = 9
#PB_FixedString = 10 ; used only internally in some libraries
#PB_Character   = 11
#PB_Double      = 12
#PB_Quad        = 13
#PB_List        = 14
#PB_Array       = 15
#PB_Integer     = 21
#PB_Map         = 22
#PB_Ascii       = 24
#PB_Unicode     = 25
#PB_Constant    = 50 ; Used by Defined()
#PB_Variable    = 51
#PB_Interface   = 52
#PB_Procedure   = 53
#PB_Function    = 54
#PB_OSFunction  = 55
#PB_Label       = 56
#PB_Prototype   = 57
#PB_Module      = 58
#PB_Enumeration = 59
Post Reply