Skip to content

Commit cfcecf8

Browse files
committed
v.ast: add .free() methods, so vls can be more decoupled
1 parent eaf930a commit cfcecf8

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

vlib/v/ast/ast.v

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,24 @@ pub mut:
564564
global_labels []string // from `asm { .globl labelname }`
565565
}
566566

567+
[unsafe]
568+
pub fn (f &File) free() {
569+
unsafe {
570+
f.path.free()
571+
f.path_base.free()
572+
f.scope.free()
573+
f.stmts.free()
574+
f.imports.free()
575+
f.auto_imports.free()
576+
f.embedded_files.free()
577+
f.imported_symbols.free()
578+
f.errors.free()
579+
f.warnings.free()
580+
f.notices.free()
581+
f.global_labels.free()
582+
}
583+
}
584+
567585
pub struct IdentFn {
568586
pub mut:
569587
typ Type

vlib/v/ast/scope.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ pub mut:
1515
end_pos int
1616
}
1717

18+
[unsafe]
19+
pub fn (s &Scope) free() {
20+
unsafe {
21+
s.objects.free()
22+
s.struct_fields.free()
23+
for child in s.children {
24+
child.free()
25+
}
26+
s.children.free()
27+
}
28+
}
29+
1830
pub fn new_scope(parent &Scope, start_pos int) &Scope {
1931
return &Scope{
2032
parent: parent

vlib/v/ast/table.v

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ pub mut:
2424
used_consts map[string]bool // filled in by the checker, when pref.skip_unused = true;
2525
}
2626

27+
[unsafe]
28+
pub fn (t &Table) free() {
29+
unsafe {
30+
t.type_symbols.free()
31+
t.type_idxs.free()
32+
t.fns.free()
33+
t.dumps.free()
34+
t.imports.free()
35+
t.modules.free()
36+
t.cflags.free()
37+
t.redefined_fns.free()
38+
t.fn_generic_types.free()
39+
t.cmod_prefix.free()
40+
t.used_fns.free()
41+
t.used_consts.free()
42+
}
43+
}
44+
2745
pub struct Fn {
2846
pub:
2947
params []Param

0 commit comments

Comments
 (0)