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:
parent
7531f78f67
commit
bf9f684c59
@ -564,76 +564,135 @@ pub fn (t TypeSymbol) str() string {
|
|||||||
return t.name
|
return t.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[noreturn]
|
||||||
|
fn (t &TypeSymbol) no_info_panic(fname string) {
|
||||||
|
panic('$fname: no info for type: $t.name')
|
||||||
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
pub fn (t &TypeSymbol) enum_info() Enum {
|
pub fn (t &TypeSymbol) enum_info() Enum {
|
||||||
match mut t.info {
|
if t.info is Enum {
|
||||||
Enum { return t.info }
|
return t.info
|
||||||
else { panic('TypeSymbol.enum_info(): no enum info for type: $t.name') }
|
|
||||||
}
|
}
|
||||||
|
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]
|
[inline]
|
||||||
pub fn (t &TypeSymbol) mr_info() MultiReturn {
|
pub fn (t &TypeSymbol) mr_info() MultiReturn {
|
||||||
match mut t.info {
|
if t.info is MultiReturn {
|
||||||
MultiReturn { return t.info }
|
return t.info
|
||||||
else { panic('TypeSymbol.mr_info(): no multi return info for type: $t.name') }
|
|
||||||
}
|
}
|
||||||
|
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]
|
[inline]
|
||||||
pub fn (t &TypeSymbol) array_info() Array {
|
pub fn (t &TypeSymbol) array_info() Array {
|
||||||
match mut t.info {
|
if t.info is Array {
|
||||||
Array { return t.info }
|
return t.info
|
||||||
else { panic('TypeSymbol.array_info(): no array info for type: $t.name') }
|
|
||||||
}
|
}
|
||||||
|
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]
|
[inline]
|
||||||
pub fn (t &TypeSymbol) array_fixed_info() ArrayFixed {
|
pub fn (t &TypeSymbol) array_fixed_info() ArrayFixed {
|
||||||
match mut t.info {
|
if t.info is ArrayFixed {
|
||||||
ArrayFixed { return t.info }
|
return t.info
|
||||||
else { panic('TypeSymbol.array_fixed(): no array fixed info for type: $t.name') }
|
|
||||||
}
|
}
|
||||||
|
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]
|
[inline]
|
||||||
pub fn (t &TypeSymbol) chan_info() Chan {
|
pub fn (t &TypeSymbol) chan_info() Chan {
|
||||||
match mut t.info {
|
if t.info is Chan {
|
||||||
Chan { return t.info }
|
return t.info
|
||||||
else { panic('TypeSymbol.chan_info(): no chan info for type: $t.name') }
|
|
||||||
}
|
}
|
||||||
|
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]
|
[inline]
|
||||||
pub fn (t &TypeSymbol) thread_info() Thread {
|
pub fn (t &TypeSymbol) thread_info() Thread {
|
||||||
match mut t.info {
|
if t.info is Thread {
|
||||||
Thread { return t.info }
|
return t.info
|
||||||
else { panic('TypeSymbol.thread_info(): no thread info for type: $t.name') }
|
|
||||||
}
|
}
|
||||||
|
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]
|
[inline]
|
||||||
pub fn (t &TypeSymbol) map_info() Map {
|
pub fn (t &TypeSymbol) map_info() Map {
|
||||||
match mut t.info {
|
if t.info is Map {
|
||||||
Map { return t.info }
|
return t.info
|
||||||
else { panic('TypeSymbol.map_info(): no map info for type: $t.name') }
|
|
||||||
}
|
}
|
||||||
|
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]
|
[inline]
|
||||||
pub fn (t &TypeSymbol) struct_info() Struct {
|
pub fn (t &TypeSymbol) struct_info() Struct {
|
||||||
match mut t.info {
|
if t.info is Struct {
|
||||||
Struct { return t.info }
|
return t.info
|
||||||
else { panic('TypeSymbol.struct_info(): no struct info for type: $t.name') }
|
|
||||||
}
|
}
|
||||||
|
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]
|
[inline]
|
||||||
pub fn (t &TypeSymbol) sumtype_info() SumType {
|
pub fn (t &TypeSymbol) sumtype_info() SumType {
|
||||||
match mut t.info {
|
if t.info is SumType {
|
||||||
SumType { return t.info }
|
return t.info
|
||||||
else { panic('TypeSymbol.sumtype_info(): no sumtype info for type: $t.name') }
|
|
||||||
}
|
}
|
||||||
|
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 {
|
pub fn (t &TypeSymbol) is_heap() bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user