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

ast: improve support for type aliases, in TypeSymbol.xyz_info methods

This commit is contained in:
Delyan Angelov 2021-12-30 13:16:56 +02:00
parent 7531f78f67
commit bf9f684c59
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -564,76 +564,135 @@ pub fn (t TypeSymbol) str() string {
return t.name
}
[noreturn]
fn (t &TypeSymbol) no_info_panic(fname string) {
panic('$fname: no info for type: $t.name')
}
[inline]
pub fn (t &TypeSymbol) enum_info() Enum {
match mut t.info {
Enum { return t.info }
else { panic('TypeSymbol.enum_info(): no enum info for type: $t.name') }
if t.info is Enum {
return t.info
}
if t.info is Alias {
fsym := global_table.final_sym(t.info.parent_type)
if fsym.info is Enum {
return fsym.info
}
}
t.no_info_panic(@METHOD)
}
[inline]
pub fn (t &TypeSymbol) mr_info() MultiReturn {
match mut t.info {
MultiReturn { return t.info }
else { panic('TypeSymbol.mr_info(): no multi return info for type: $t.name') }
if t.info is MultiReturn {
return t.info
}
if t.info is Alias {
fsym := global_table.final_sym(t.info.parent_type)
if fsym.info is MultiReturn {
return fsym.info
}
}
t.no_info_panic(@METHOD)
}
[inline]
pub fn (t &TypeSymbol) array_info() Array {
match mut t.info {
Array { return t.info }
else { panic('TypeSymbol.array_info(): no array info for type: $t.name') }
if t.info is Array {
return t.info
}
if t.info is Alias {
fsym := global_table.final_sym(t.info.parent_type)
if fsym.info is Array {
return fsym.info
}
}
t.no_info_panic(@METHOD)
}
[inline]
pub fn (t &TypeSymbol) array_fixed_info() ArrayFixed {
match mut t.info {
ArrayFixed { return t.info }
else { panic('TypeSymbol.array_fixed(): no array fixed info for type: $t.name') }
if t.info is ArrayFixed {
return t.info
}
if t.info is Alias {
fsym := global_table.final_sym(t.info.parent_type)
if fsym.info is ArrayFixed {
return fsym.info
}
}
t.no_info_panic(@METHOD)
}
[inline]
pub fn (t &TypeSymbol) chan_info() Chan {
match mut t.info {
Chan { return t.info }
else { panic('TypeSymbol.chan_info(): no chan info for type: $t.name') }
if t.info is Chan {
return t.info
}
if t.info is Alias {
fsym := global_table.final_sym(t.info.parent_type)
if fsym.info is Chan {
return fsym.info
}
}
t.no_info_panic(@METHOD)
}
[inline]
pub fn (t &TypeSymbol) thread_info() Thread {
match mut t.info {
Thread { return t.info }
else { panic('TypeSymbol.thread_info(): no thread info for type: $t.name') }
if t.info is Thread {
return t.info
}
if t.info is Alias {
fsym := global_table.final_sym(t.info.parent_type)
if fsym.info is Thread {
return fsym.info
}
}
t.no_info_panic(@METHOD)
}
[inline]
pub fn (t &TypeSymbol) map_info() Map {
match mut t.info {
Map { return t.info }
else { panic('TypeSymbol.map_info(): no map info for type: $t.name') }
if t.info is Map {
return t.info
}
if t.info is Alias {
fsym := global_table.final_sym(t.info.parent_type)
if fsym.info is Map {
return fsym.info
}
}
t.no_info_panic(@METHOD)
}
[inline]
pub fn (t &TypeSymbol) struct_info() Struct {
match mut t.info {
Struct { return t.info }
else { panic('TypeSymbol.struct_info(): no struct info for type: $t.name') }
if t.info is Struct {
return t.info
}
if t.info is Alias {
fsym := global_table.final_sym(t.info.parent_type)
if fsym.info is Struct {
return fsym.info
}
}
t.no_info_panic(@METHOD)
}
[inline]
pub fn (t &TypeSymbol) sumtype_info() SumType {
match mut t.info {
SumType { return t.info }
else { panic('TypeSymbol.sumtype_info(): no sumtype info for type: $t.name') }
if t.info is SumType {
return t.info
}
if t.info is SumType {
fsym := global_table.final_sym(t.info.parent_type)
if fsym.info is SumType {
return fsym.info
}
}
t.no_info_panic(@METHOD)
}
pub fn (t &TypeSymbol) is_heap() bool {