cgen: fix [cinit]
parent
2525a30b5f
commit
d7adb67d52
|
@ -4372,7 +4372,6 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
|
||||||
cinit := node.attrs.contains('cinit')
|
cinit := node.attrs.contains('cinit')
|
||||||
should_init := (!g.pref.use_cache && g.pref.build_mode != .build_module)
|
should_init := (!g.pref.use_cache && g.pref.build_mode != .build_module)
|
||||||
|| (g.pref.build_mode == .build_module && g.module_built == node.mod)
|
|| (g.pref.build_mode == .build_module && g.module_built == node.mod)
|
||||||
|| cinit
|
|
||||||
mut attributes := ''
|
mut attributes := ''
|
||||||
if node.attrs.contains('weak') {
|
if node.attrs.contains('weak') {
|
||||||
attributes += 'VWEAK '
|
attributes += 'VWEAK '
|
||||||
|
@ -4395,10 +4394,10 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
g.definitions.write_string('$visibility_kw$styp $attributes $field.name')
|
g.definitions.write_string('$visibility_kw$styp $attributes $field.name')
|
||||||
if field.has_expr {
|
if field.has_expr || cinit {
|
||||||
if g.pref.translated {
|
if g.pref.translated {
|
||||||
g.definitions.write_string(' = ${g.expr_string(field.expr)}')
|
g.definitions.write_string(' = ${g.expr_string(field.expr)}')
|
||||||
} else if field.expr.is_literal() && should_init {
|
} else if (field.expr.is_literal() && should_init) || cinit {
|
||||||
// Simple literals can be initialized right away in global scope in C.
|
// Simple literals can be initialized right away in global scope in C.
|
||||||
// e.g. `int myglobal = 10;`
|
// e.g. `int myglobal = 10;`
|
||||||
g.definitions.write_string(' = ${g.expr_string(field.expr)}')
|
g.definitions.write_string(' = ${g.expr_string(field.expr)}')
|
||||||
|
|
Loading…
Reference in New Issue