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