Skip to content

Commit 43a1d2c

Browse files
authored
ast: cleanup table.v (#12561)
1 parent 70ff00e commit 43a1d2c

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

vlib/v/ast/table.v

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ pub:
9292
pos token.Position
9393
return_type_pos token.Position
9494
pub mut:
95-
return_type Type
96-
name string
97-
params []Param
98-
source_fn voidptr // set in the checker, while processing fn declarations
99-
usages int
100-
//
95+
return_type Type
96+
name string
97+
params []Param
98+
source_fn voidptr // set in the checker, while processing fn declarations
99+
usages int
101100
generic_names []string
102101
attrs []Attr // all fn attributes
103102
is_conditional bool // true for `[if abc]fn(){}`
@@ -168,16 +167,6 @@ fn (p []Param) equals(o []Param) bool {
168167
return true
169168
}
170169

171-
/*
172-
pub struct Var {
173-
pub:
174-
name string
175-
is_mut bool
176-
mut:
177-
typ Type
178-
}
179-
*/
180-
181170
pub fn new_table() &Table {
182171
mut t := &Table{
183172
type_symbols: []TypeSymbol{cap: 64000}
@@ -301,7 +290,6 @@ pub fn (t &Table) known_fn(name string) bool {
301290
}
302291

303292
pub fn (mut t Table) register_fn(new_fn Fn) {
304-
// println('reg fn $new_fn.name nr_args=$new_fn.args.len')
305293
t.fns[new_fn.name] = new_fn
306294
}
307295

@@ -312,7 +300,6 @@ pub fn (mut t Table) register_interface(idecl InterfaceDecl) {
312300
pub fn (mut t TypeSymbol) register_method(new_fn Fn) int {
313301
// returns a method index, stored in the ast.FnDecl
314302
// for faster lookup in the checker's fn_decl method
315-
// println('reg me $new_fn.name nr_args=$new_fn.args.len')
316303
t.methods << new_fn
317304
return t.methods.len - 1
318305
}
@@ -344,16 +331,12 @@ pub fn (t &Table) register_aggregate_method(mut sym TypeSymbol, name string) ?Fn
344331
}
345332

346333
pub fn (t &Table) type_has_method(s &TypeSymbol, name string) bool {
347-
// println('type_has_method($s.name, $name) types.len=$t.types.len s.parent_idx=$s.parent_idx')
348-
if _ := t.type_find_method(s, name) {
349-
return true
350-
}
351-
return false
334+
t.type_find_method(s, name) or { return false }
335+
return true
352336
}
353337

354338
// type_find_method searches from current type up through each parent looking for method
355339
pub fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn {
356-
// println('type_find_method($s.name, $name) types.len=$t.types.len s.parent_idx=$s.parent_idx')
357340
mut ts := unsafe { s }
358341
for {
359342
if method := ts.find_method(name) {
@@ -454,11 +437,8 @@ fn (t &Table) register_aggregate_field(mut sym TypeSymbol, name string) ?StructF
454437
}
455438

456439
pub fn (t &Table) struct_has_field(struct_ &TypeSymbol, name string) bool {
457-
// println('struct_has_field($s.name, $name) types.len=$t.types.len s.parent_idx=$s.parent_idx')
458-
if _ := t.find_field(struct_, name) {
459-
return true
460-
}
461-
return false
440+
t.find_field(struct_, name) or { return false }
441+
return true
462442
}
463443

464444
// struct_fields returns all fields including fields from embeds
@@ -477,7 +457,6 @@ pub fn (t &Table) struct_fields(sym &TypeSymbol) []StructField {
477457

478458
// search from current type up through each parent looking for field
479459
pub fn (t &Table) find_field(s &TypeSymbol, name string) ?StructField {
480-
// println('find_field($s.name, $name) types.len=$t.types.len s.parent_idx=$s.parent_idx')
481460
mut ts := unsafe { s }
482461
for {
483462
match mut ts.info {
@@ -707,7 +686,6 @@ fn (mut t Table) check_for_already_registered_symbol(typ TypeSymbol, existing_id
707686
match ex_type.kind {
708687
.placeholder {
709688
// override placeholder
710-
// println('overriding type placeholder `$typ.name`')
711689
t.type_symbols[existing_idx] = TypeSymbol{
712690
...typ
713691
methods: ex_type.methods
@@ -914,7 +892,6 @@ pub fn (t &Table) map_cname(key_type Type, value_type Type) string {
914892
value_type_sym := t.get_type_symbol(value_type)
915893
suffix := if value_type.is_ptr() { '_ptr' } else { '' }
916894
return 'Map_${key_type_sym.cname}_$value_type_sym.cname' + suffix
917-
// return 'map_${value_type_sym.name}' + suffix
918895
}
919896

920897
pub fn (mut t Table) find_or_register_chan(elem_type Type, is_mut bool) int {
@@ -1099,7 +1076,6 @@ pub fn (mut t Table) add_placeholder_type(name string, language Language) int {
10991076
language: language
11001077
mod: modname
11011078
}
1102-
// println('added placeholder: $name - $ph_type.idx')
11031079
return t.register_type_symbol(ph_type)
11041080
}
11051081

0 commit comments

Comments
 (0)