mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: format module_init generated c code (#14764)
This commit is contained in:
parent
205221074c
commit
f2962c34dd
@ -4791,11 +4791,15 @@ fn (mut g Gen) write_init_function() {
|
||||
g.writeln('\t_closure_mtx_init();')
|
||||
}
|
||||
for mod_name in g.table.modules {
|
||||
g.writeln('\t{ // Initializations for module $mod_name :')
|
||||
mut is_empty := true
|
||||
// write globals and consts init later
|
||||
for var_name in g.sorted_global_const_names {
|
||||
if var := g.global_const_defs[var_name] {
|
||||
if var.mod == mod_name && var.init.len > 0 {
|
||||
if is_empty {
|
||||
is_empty = false
|
||||
g.writeln('\t// Initializations for module $mod_name')
|
||||
}
|
||||
g.writeln(var.init)
|
||||
}
|
||||
}
|
||||
@ -4803,12 +4807,14 @@ fn (mut g Gen) write_init_function() {
|
||||
init_fn_name := '${mod_name}.init'
|
||||
if initfn := g.table.find_fn(init_fn_name) {
|
||||
if initfn.return_type == ast.void_type && initfn.params.len == 0 {
|
||||
if is_empty {
|
||||
g.writeln('\t// Initializations for module $mod_name')
|
||||
}
|
||||
mod_c_name := util.no_dots(mod_name)
|
||||
init_fn_c_name := '${mod_c_name}__init'
|
||||
g.writeln('\t${init_fn_c_name}();')
|
||||
}
|
||||
}
|
||||
g.writeln('\t}')
|
||||
}
|
||||
g.writeln('}')
|
||||
if g.pref.printfn_list.len > 0 && '_vinit' in g.pref.printfn_list {
|
||||
|
2
vlib/v/gen/c/testdata/embed.c.must_have
vendored
2
vlib/v/gen/c/testdata/embed.c.must_have
vendored
@ -15,5 +15,3 @@ v__embed_file__EmbedFileIndexEntry* v__embed_file__find_index_entry_by_path(void
|
||||
|
||||
v__embed_file__EmbedFileData my_source = _v_embed_file_metadata(
|
||||
res.path = _SLIT("embed.vv");
|
||||
|
||||
// Initializations for module v.embed_file :
|
||||
|
@ -28,5 +28,3 @@ v__embed_file__EmbedFileData my_source = _v_embed_file_metadata(
|
||||
res.path = _SLIT("embed.vv");
|
||||
res.apath = _SLIT("");
|
||||
res.uncompressed = v__embed_file__find_index_entry_by_path((voidptr)_v_embed_file_index, _SLIT("embed.vv"), _SLIT("none"))->data;
|
||||
|
||||
// Initializations for module v.embed_file :
|
||||
|
@ -28,5 +28,3 @@ v__embed_file__EmbedFileData my_source = _v_embed_file_metadata(
|
||||
res.path = _SLIT("embed.vv");
|
||||
res.apath = _SLIT("");
|
||||
res.compressed = v__embed_file__find_index_entry_by_path((voidptr)_v_embed_file_index, _SLIT("embed.vv"), _SLIT("zlib"))->data;
|
||||
|
||||
// Initializations for module v.embed_file :
|
||||
|
Loading…
Reference in New Issue
Block a user