ast: cleanup table.v (#12561)
parent
70ff00efbb
commit
43a1d2cfea
|
@ -97,7 +97,6 @@ pub mut:
|
||||||
params []Param
|
params []Param
|
||||||
source_fn voidptr // set in the checker, while processing fn declarations
|
source_fn voidptr // set in the checker, while processing fn declarations
|
||||||
usages int
|
usages int
|
||||||
//
|
|
||||||
generic_names []string
|
generic_names []string
|
||||||
attrs []Attr // all fn attributes
|
attrs []Attr // all fn attributes
|
||||||
is_conditional bool // true for `[if abc]fn(){}`
|
is_conditional bool // true for `[if abc]fn(){}`
|
||||||
|
@ -168,16 +167,6 @@ fn (p []Param) equals(o []Param) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
pub struct Var {
|
|
||||||
pub:
|
|
||||||
name string
|
|
||||||
is_mut bool
|
|
||||||
mut:
|
|
||||||
typ Type
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub fn new_table() &Table {
|
pub fn new_table() &Table {
|
||||||
mut t := &Table{
|
mut t := &Table{
|
||||||
type_symbols: []TypeSymbol{cap: 64000}
|
type_symbols: []TypeSymbol{cap: 64000}
|
||||||
|
@ -301,7 +290,6 @@ pub fn (t &Table) known_fn(name string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut t Table) register_fn(new_fn Fn) {
|
pub fn (mut t Table) register_fn(new_fn Fn) {
|
||||||
// println('reg fn $new_fn.name nr_args=$new_fn.args.len')
|
|
||||||
t.fns[new_fn.name] = new_fn
|
t.fns[new_fn.name] = new_fn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +300,6 @@ pub fn (mut t Table) register_interface(idecl InterfaceDecl) {
|
||||||
pub fn (mut t TypeSymbol) register_method(new_fn Fn) int {
|
pub fn (mut t TypeSymbol) register_method(new_fn Fn) int {
|
||||||
// returns a method index, stored in the ast.FnDecl
|
// returns a method index, stored in the ast.FnDecl
|
||||||
// for faster lookup in the checker's fn_decl method
|
// for faster lookup in the checker's fn_decl method
|
||||||
// println('reg me $new_fn.name nr_args=$new_fn.args.len')
|
|
||||||
t.methods << new_fn
|
t.methods << new_fn
|
||||||
return t.methods.len - 1
|
return t.methods.len - 1
|
||||||
}
|
}
|
||||||
|
@ -344,16 +331,12 @@ pub fn (t &Table) register_aggregate_method(mut sym TypeSymbol, name string) ?Fn
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (t &Table) type_has_method(s &TypeSymbol, name string) bool {
|
pub fn (t &Table) type_has_method(s &TypeSymbol, name string) bool {
|
||||||
// println('type_has_method($s.name, $name) types.len=$t.types.len s.parent_idx=$s.parent_idx')
|
t.type_find_method(s, name) or { return false }
|
||||||
if _ := t.type_find_method(s, name) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// type_find_method searches from current type up through each parent looking for method
|
// type_find_method searches from current type up through each parent looking for method
|
||||||
pub fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn {
|
pub fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn {
|
||||||
// println('type_find_method($s.name, $name) types.len=$t.types.len s.parent_idx=$s.parent_idx')
|
|
||||||
mut ts := unsafe { s }
|
mut ts := unsafe { s }
|
||||||
for {
|
for {
|
||||||
if method := ts.find_method(name) {
|
if method := ts.find_method(name) {
|
||||||
|
@ -454,12 +437,9 @@ fn (t &Table) register_aggregate_field(mut sym TypeSymbol, name string) ?StructF
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (t &Table) struct_has_field(struct_ &TypeSymbol, name string) bool {
|
pub fn (t &Table) struct_has_field(struct_ &TypeSymbol, name string) bool {
|
||||||
// println('struct_has_field($s.name, $name) types.len=$t.types.len s.parent_idx=$s.parent_idx')
|
t.find_field(struct_, name) or { return false }
|
||||||
if _ := t.find_field(struct_, name) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// struct_fields returns all fields including fields from embeds
|
// struct_fields returns all fields including fields from embeds
|
||||||
// use this instead symbol.info.fields to get all fields
|
// use this instead symbol.info.fields to get all fields
|
||||||
|
@ -477,7 +457,6 @@ pub fn (t &Table) struct_fields(sym &TypeSymbol) []StructField {
|
||||||
|
|
||||||
// search from current type up through each parent looking for field
|
// search from current type up through each parent looking for field
|
||||||
pub fn (t &Table) find_field(s &TypeSymbol, name string) ?StructField {
|
pub fn (t &Table) find_field(s &TypeSymbol, name string) ?StructField {
|
||||||
// println('find_field($s.name, $name) types.len=$t.types.len s.parent_idx=$s.parent_idx')
|
|
||||||
mut ts := unsafe { s }
|
mut ts := unsafe { s }
|
||||||
for {
|
for {
|
||||||
match mut ts.info {
|
match mut ts.info {
|
||||||
|
@ -707,7 +686,6 @@ fn (mut t Table) check_for_already_registered_symbol(typ TypeSymbol, existing_id
|
||||||
match ex_type.kind {
|
match ex_type.kind {
|
||||||
.placeholder {
|
.placeholder {
|
||||||
// override placeholder
|
// override placeholder
|
||||||
// println('overriding type placeholder `$typ.name`')
|
|
||||||
t.type_symbols[existing_idx] = TypeSymbol{
|
t.type_symbols[existing_idx] = TypeSymbol{
|
||||||
...typ
|
...typ
|
||||||
methods: ex_type.methods
|
methods: ex_type.methods
|
||||||
|
@ -914,7 +892,6 @@ pub fn (t &Table) map_cname(key_type Type, value_type Type) string {
|
||||||
value_type_sym := t.get_type_symbol(value_type)
|
value_type_sym := t.get_type_symbol(value_type)
|
||||||
suffix := if value_type.is_ptr() { '_ptr' } else { '' }
|
suffix := if value_type.is_ptr() { '_ptr' } else { '' }
|
||||||
return 'Map_${key_type_sym.cname}_$value_type_sym.cname' + suffix
|
return 'Map_${key_type_sym.cname}_$value_type_sym.cname' + suffix
|
||||||
// return 'map_${value_type_sym.name}' + suffix
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut t Table) find_or_register_chan(elem_type Type, is_mut bool) int {
|
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 {
|
||||||
language: language
|
language: language
|
||||||
mod: modname
|
mod: modname
|
||||||
}
|
}
|
||||||
// println('added placeholder: $name - $ph_type.idx')
|
|
||||||
return t.register_type_symbol(ph_type)
|
return t.register_type_symbol(ph_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue