mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.ast: cleanup Table.resolve_generic_to_concrete/3 (#10559)
This commit is contained in:
parent
e2f7fd16c2
commit
e3ea5c1e17
@ -1142,12 +1142,15 @@ pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_name
|
||||
}
|
||||
typ := concrete_types[index]
|
||||
return typ.derive(generic_type).clear_flag(.generic)
|
||||
} else if sym.kind == .array {
|
||||
mut elem_type := (sym.info as Array).elem_type
|
||||
}
|
||||
match mut sym.info {
|
||||
Array {
|
||||
mut elem_type := sym.info.elem_type
|
||||
mut elem_sym := t.get_type_symbol(elem_type)
|
||||
mut dims := 1
|
||||
for mut elem_sym.info is Array {
|
||||
elem_type = elem_sym.info.elem_type
|
||||
info := elem_sym.info as Array
|
||||
elem_type = info.elem_type
|
||||
elem_sym = t.get_type_symbol(elem_type)
|
||||
dims++
|
||||
}
|
||||
@ -1155,18 +1158,46 @@ pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_name
|
||||
idx := t.find_or_register_array_with_dims(typ, dims)
|
||||
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
||||
}
|
||||
} else if sym.kind == .array_fixed {
|
||||
info := sym.info as ArrayFixed
|
||||
if typ := t.resolve_generic_to_concrete(info.elem_type, generic_names, concrete_types) {
|
||||
idx := t.find_or_register_array_fixed(typ, info.size, None{})
|
||||
}
|
||||
ArrayFixed {
|
||||
if typ := t.resolve_generic_to_concrete(sym.info.elem_type, generic_names,
|
||||
concrete_types)
|
||||
{
|
||||
idx := t.find_or_register_array_fixed(typ, sym.info.size, None{})
|
||||
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
||||
}
|
||||
} else if mut sym.info is Chan {
|
||||
if typ := t.resolve_generic_to_concrete(sym.info.elem_type, generic_names, concrete_types) {
|
||||
}
|
||||
Chan {
|
||||
if typ := t.resolve_generic_to_concrete(sym.info.elem_type, generic_names,
|
||||
concrete_types)
|
||||
{
|
||||
idx := t.find_or_register_chan(typ, typ.nr_muls() > 0)
|
||||
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
||||
}
|
||||
} else if mut sym.info is MultiReturn {
|
||||
}
|
||||
FnType {
|
||||
mut func := sym.info.func
|
||||
if func.return_type.has_flag(.generic) {
|
||||
if typ := t.resolve_generic_to_concrete(func.return_type, generic_names,
|
||||
concrete_types)
|
||||
{
|
||||
func.return_type = typ
|
||||
}
|
||||
}
|
||||
func.params = func.params.clone()
|
||||
for mut param in func.params {
|
||||
if param.typ.has_flag(.generic) {
|
||||
if typ := t.resolve_generic_to_concrete(param.typ, generic_names,
|
||||
concrete_types)
|
||||
{
|
||||
param.typ = typ
|
||||
}
|
||||
}
|
||||
}
|
||||
idx := t.find_or_register_fn_type('', func, true, false)
|
||||
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
||||
}
|
||||
MultiReturn {
|
||||
mut types := []Type{}
|
||||
mut type_changed := false
|
||||
for ret_type in sym.info.types {
|
||||
@ -1181,15 +1212,20 @@ pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_name
|
||||
idx := t.find_or_register_multi_return(types)
|
||||
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
||||
}
|
||||
} else if mut sym.info is Map {
|
||||
}
|
||||
Map {
|
||||
mut type_changed := false
|
||||
mut unwrapped_key_type := sym.info.key_type
|
||||
mut unwrapped_value_type := sym.info.value_type
|
||||
if typ := t.resolve_generic_to_concrete(sym.info.key_type, generic_names, concrete_types) {
|
||||
if typ := t.resolve_generic_to_concrete(sym.info.key_type, generic_names,
|
||||
concrete_types)
|
||||
{
|
||||
unwrapped_key_type = typ
|
||||
type_changed = true
|
||||
}
|
||||
if typ := t.resolve_generic_to_concrete(sym.info.value_type, generic_names, concrete_types) {
|
||||
if typ := t.resolve_generic_to_concrete(sym.info.value_type, generic_names,
|
||||
concrete_types)
|
||||
{
|
||||
unwrapped_value_type = typ
|
||||
type_changed = true
|
||||
}
|
||||
@ -1197,12 +1233,13 @@ pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_name
|
||||
idx := t.find_or_register_map(unwrapped_key_type, unwrapped_value_type)
|
||||
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
||||
}
|
||||
} else if mut sym.info is Struct {
|
||||
}
|
||||
Struct {
|
||||
if sym.info.is_generic {
|
||||
mut nrt := '$sym.name<'
|
||||
for i in 0 .. sym.info.generic_types.len {
|
||||
if ct := t.resolve_generic_to_concrete(sym.info.generic_types[i], generic_names,
|
||||
concrete_types)
|
||||
if ct := t.resolve_generic_to_concrete(sym.info.generic_types[i],
|
||||
generic_names, concrete_types)
|
||||
{
|
||||
gts := t.get_type_symbol(ct)
|
||||
nrt += gts.name
|
||||
@ -1218,23 +1255,8 @@ pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_name
|
||||
}
|
||||
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
||||
}
|
||||
} else if mut sym.info is FnType {
|
||||
mut func := sym.info.func
|
||||
if func.return_type.has_flag(.generic) {
|
||||
if typ := t.resolve_generic_to_concrete(func.return_type, generic_names, concrete_types) {
|
||||
func.return_type = typ
|
||||
}
|
||||
}
|
||||
func.params = func.params.clone()
|
||||
for mut param in func.params {
|
||||
if param.typ.has_flag(.generic) {
|
||||
if typ := t.resolve_generic_to_concrete(param.typ, generic_names, concrete_types) {
|
||||
param.typ = typ
|
||||
}
|
||||
}
|
||||
}
|
||||
idx := t.find_or_register_fn_type('', func, true, false)
|
||||
return new_type(idx).derive(generic_type).clear_flag(.generic)
|
||||
else {}
|
||||
}
|
||||
return none
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user