1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ast: minor cleanup in table.v (#18856)

This commit is contained in:
yuyi 2023-07-14 17:17:20 +08:00 committed by GitHub
parent 3081919a8f
commit 7e067c5fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -493,7 +493,7 @@ pub fn (t &Table) find_field(s &TypeSymbol, name string) !StructField {
}
}
SumType {
t.resolve_common_sumtype_fields(ts)
t.resolve_common_sumtype_fields(mut ts)
if field := ts.info.find_field(name) {
return field
}
@ -560,8 +560,7 @@ pub fn (t &Table) find_field_with_embeds(sym &TypeSymbol, field_name string) !St
}
}
pub fn (t &Table) resolve_common_sumtype_fields(sym_ &TypeSymbol) {
mut sym := unsafe { sym_ }
pub fn (t &Table) resolve_common_sumtype_fields(mut sym TypeSymbol) {
mut info := sym.info as SumType
if info.found_fields {
return
@ -575,7 +574,7 @@ pub fn (t &Table) resolve_common_sumtype_fields(sym_ &TypeSymbol) {
t.struct_fields(v_sym)
}
SumType {
t.resolve_common_sumtype_fields(v_sym)
t.resolve_common_sumtype_fields(mut v_sym)
v_sym.info.fields
}
else {
@ -654,9 +653,9 @@ pub fn (t &Table) sym(typ Type) &TypeSymbol {
pub fn (t &Table) final_sym(typ Type) &TypeSymbol {
mut idx := typ.idx()
if idx > 0 {
current_symbol := t.type_symbols[idx]
if current_symbol.kind == .alias {
idx = (current_symbol.info as Alias).parent_type.idx()
cur_sym := t.type_symbols[idx]
if cur_sym.info is Alias {
idx = cur_sym.info.parent_type.idx()
}
return t.type_symbols[idx]
}
@ -667,23 +666,20 @@ pub fn (t &Table) final_sym(typ Type) &TypeSymbol {
[inline]
pub fn (t &Table) get_type_name(typ Type) string {
sym := t.sym(typ)
return sym.name
return t.sym(typ).name
}
[inline]
pub fn (t &Table) get_final_type_name(typ Type) string {
sym := t.final_sym(typ)
return sym.name
return t.final_sym(typ).name
}
[inline]
pub fn (t &Table) unalias_num_type(typ Type) Type {
sym := t.sym(typ)
if sym.kind == .alias {
pt := (sym.info as Alias).parent_type
if pt <= char_type && pt >= void_type {
return pt
if sym.info is Alias {
if sym.info.parent_type <= char_type && sym.info.parent_type >= void_type {
return sym.info.parent_type
}
}
return typ
@ -692,9 +688,8 @@ pub fn (t &Table) unalias_num_type(typ Type) Type {
[inline]
pub fn (t &Table) unaliased_type(typ Type) Type {
sym := t.sym(typ)
if sym.kind == .alias {
pt := (sym.info as Alias).parent_type
return pt
if sym.info is Alias {
return sym.info.parent_type
}
return typ
}