1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: add calls to all typeof functions for interfaces and sum-types (#17490)

This commit is contained in:
Petr Makhnev 2023-03-04 16:59:00 +04:00 committed by GitHub
parent 3f8821b8d8
commit 1a48d08d7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5316,6 +5316,37 @@ fn (g &Gen) checker_bug(s string, pos token.Pos) {
g.error('checker bug; ${s}', pos)
}
// write_debug_calls_typeof_functions inserts calls to all typeof functions for
// interfaces and sum-types in debug mode so that the compiler does not optimize them.
// These functions are needed to be able to get the name of a specific structure/type in the debugger.
fn (mut g Gen) write_debug_calls_typeof_functions() {
if !g.pref.is_debug {
return
}
g.writeln('\t// we call these functions in debug mode so that the C compiler')
g.writeln('\t// does not optimize them and we can access them in the debugger.')
for _, sym in g.table.type_symbols {
if sym.kind == .sum_type {
sum_info := sym.info as ast.SumType
if sum_info.is_generic {
continue
}
g.writeln('\tv_typeof_sumtype_${sym.cname}(0);')
}
if sym.kind == .interface_ {
if sym.info !is ast.Interface {
continue
}
inter_info := sym.info as ast.Interface
if inter_info.is_generic {
continue
}
g.writeln('\tv_typeof_interface_${sym.cname}(0);')
}
}
}
fn (mut g Gen) write_init_function() {
if g.pref.no_builtin || (g.pref.translated && g.pref.is_o) {
return
@ -5332,6 +5363,8 @@ fn (mut g Gen) write_init_function() {
// ___argv is declared as voidptr here, because that unifies the windows/unix logic
g.writeln('void _vinit(int ___argc, voidptr ___argv) {')
g.write_debug_calls_typeof_functions()
if g.pref.trace_calls {
g.writeln('\tv__trace_calls__on_call(_SLIT("_vinit"));')
}