ast: minor cleanup of register_type_symbol (#12213)

pull/12227/head
yuyi 2021-10-17 20:50:42 +08:00 committed by GitHub
parent 29f068997b
commit a006090b08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 16 deletions

View File

@ -732,29 +732,29 @@ fn (mut t Table) check_for_already_registered_symbol(typ TypeSymbol, existing_id
} }
[inline] [inline]
pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int { pub fn (mut t Table) register_type_symbol(sym TypeSymbol) int {
mut typ_idx := -2 mut idx := -2
mut existing_idx := t.type_idxs[typ.name] mut existing_idx := t.type_idxs[sym.name]
if existing_idx > 0 { if existing_idx > 0 {
typ_idx = t.check_for_already_registered_symbol(typ, existing_idx) idx = t.check_for_already_registered_symbol(sym, existing_idx)
if typ_idx != -2 { if idx != -2 {
return typ_idx return idx
} }
} }
if typ.mod == 'main' { if sym.mod == 'main' {
existing_idx = t.type_idxs[typ.name.trim_prefix('main.')] existing_idx = t.type_idxs[sym.name.trim_prefix('main.')]
if existing_idx > 0 { if existing_idx > 0 {
typ_idx = t.check_for_already_registered_symbol(typ, existing_idx) idx = t.check_for_already_registered_symbol(sym, existing_idx)
if typ_idx != -2 { if idx != -2 {
return typ_idx return idx
} }
} }
} }
typ_idx = t.type_symbols.len idx = t.type_symbols.len
t.type_symbols << typ t.type_symbols << sym
t.type_symbols[typ_idx].idx = typ_idx t.type_symbols[idx].idx = idx
t.type_idxs[typ.name] = typ_idx t.type_idxs[sym.name] = idx
return typ_idx return idx
} }
[inline] [inline]