memory: autofree fix

pull/4101/head
Alexander Medvednikov 2020-03-22 12:06:33 +01:00
parent 7b689d8c52
commit 3a938972df
1 changed files with 11 additions and 2 deletions

View File

@ -38,7 +38,7 @@ const (
)
pub fn cgen(files []ast.File, table &table.Table) string {
println('start cgen2')
// println('start cgen2')
mut g := Gen{
out: strings.new_builder(100)
typedefs: strings.new_builder(100)
@ -50,15 +50,24 @@ pub fn cgen(files []ast.File, table &table.Table) string {
indent: -1
}
g.init()
mut autofree_used := false
for file in files {
// println('cgen "$g.file.path" $file.stmts.len')
g.file = file
// println('\ncgen "$g.file.path" nr_stmts=$file.stmts.len')
if g.file.path == '' || g.file.path.ends_with('.vv') || g.file.path.contains('/vlib/') {
// cgen test or building V
// println('autofree=false')
g.autofree = false
}
else {
g.autofree = true
autofree_used = true
}
g.stmts(file.stmts)
}
if autofree_used {
g.autofree = true // so that void _vcleanup is generated
}
g.write_variadic_types()
// g.write_str_definitions()
g.write_init_function()