@@ -5316,6 +5316,37 @@ fn (g &Gen) checker_bug(s string, pos token.Pos) {
53165316 g.error ('checker bug; ${s} ' , pos)
53175317}
53185318
5319+ // write_debug_calls_typeof_functions inserts calls to all typeof functions for
5320+ // interfaces and sum-types in debug mode so that the compiler does not optimize them.
5321+ // These functions are needed to be able to get the name of a specific structure/type in the debugger.
5322+ fn (mut g Gen) write_debug_calls_typeof_functions () {
5323+ if ! g.pref.is_debug {
5324+ return
5325+ }
5326+
5327+ g.writeln ('\t // we call these functions in debug mode so that the C compiler' )
5328+ g.writeln ('\t // does not optimize them and we can access them in the debugger.' )
5329+ for _, sym in g.table.type_symbols {
5330+ if sym.kind == .sum_type {
5331+ sum_info := sym.info as ast.SumType
5332+ if sum_info.is_generic {
5333+ continue
5334+ }
5335+ g.writeln ('\t v_typeof_sumtype_${sym.cname} (0);' )
5336+ }
5337+ if sym.kind == .interface_ {
5338+ if sym.info ! is ast.Interface {
5339+ continue
5340+ }
5341+ inter_info := sym.info as ast.Interface
5342+ if inter_info.is_generic {
5343+ continue
5344+ }
5345+ g.writeln ('\t v_typeof_interface_${sym.cname} (0);' )
5346+ }
5347+ }
5348+ }
5349+
53195350fn (mut g Gen) write_init_function () {
53205351 if g.pref.no_builtin || (g.pref.translated && g.pref.is_o) {
53215352 return
@@ -5332,6 +5363,8 @@ fn (mut g Gen) write_init_function() {
53325363 // ___argv is declared as voidptr here, because that unifies the windows/unix logic
53335364 g.writeln ('void _vinit(int ___argc, voidptr ___argv) {' )
53345365
5366+ g.write_debug_calls_typeof_functions ()
5367+
53355368 if g.pref.trace_calls {
53365369 g.writeln ('\t v__trace_calls__on_call(_SLIT("_vinit"));' )
53375370 }
0 commit comments