ast: rename 'table.get_type_symbol()' to 'table.sym()' and more related calls (#12898)

pull/12902/head
yuyi 2021-12-20 00:25:18 +08:00 committed by GitHub
parent c957f59071
commit cd0b581445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
56 changed files with 820 additions and 828 deletions

View File

@ -1,7 +1,7 @@
module ast module ast
pub fn resolve_init(node StructInit, typ Type, t &Table) Expr { pub fn resolve_init(node StructInit, typ Type, t &Table) Expr {
type_sym := t.get_type_symbol(typ) type_sym := t.sym(typ)
if type_sym.kind == .array { if type_sym.kind == .array {
array_info := type_sym.info as Array array_info := type_sym.info as Array
mut has_len := false mut has_len := false

View File

@ -92,9 +92,9 @@ fn stringify_fn_after_name(node &FnDecl, mut f strings.Builder, t &Table, cur_mo
mut add_para_types := true mut add_para_types := true
if node.generic_names.len > 0 { if node.generic_names.len > 0 {
if node.is_method { if node.is_method {
sym := t.get_type_symbol(node.params[0].typ) sym := t.sym(node.params[0].typ)
if sym.info is Struct { if sym.info is Struct {
generic_names := sym.info.generic_types.map(t.get_type_symbol(it).name) generic_names := sym.info.generic_types.map(t.sym(it).name)
if generic_names == node.generic_names { if generic_names == node.generic_names {
add_para_types = false add_para_types = false
} }
@ -132,7 +132,7 @@ fn stringify_fn_after_name(node &FnDecl, mut f strings.Builder, t &Table, cur_mo
f.write_string(arg.name) f.write_string(arg.name)
mut s := t.type_to_str(arg.typ.clear_flag(.shared_f)) mut s := t.type_to_str(arg.typ.clear_flag(.shared_f))
if arg.is_mut { if arg.is_mut {
arg_sym := t.get_type_symbol(arg.typ) arg_sym := t.sym(arg.typ)
if s.starts_with('&') && ((!arg_sym.is_number() && arg_sym.kind != .bool) if s.starts_with('&') && ((!arg_sym.is_number() && arg_sym.kind != .bool)
|| node.language != .v) { || node.language != .v) {
s = s[1..] s = s[1..]
@ -452,7 +452,7 @@ pub fn (x Expr) str() string {
return x.var_name + ' := ' + x.expr.str() return x.var_name + ' := ' + x.expr.str()
} }
StructInit { StructInit {
sname := global_table.get_type_symbol(x.typ).name sname := global_table.sym(x.typ).name
return '$sname{....}' return '$sname{....}'
} }
ArrayDecompose { ArrayDecompose {

View File

@ -199,7 +199,7 @@ pub fn (t &Table) fn_type_signature(f &Fn) string {
for i, arg in f.params { for i, arg in f.params {
// TODO: for now ignore mut/pts in sig for now // TODO: for now ignore mut/pts in sig for now
typ := arg.typ.set_nr_muls(0) typ := arg.typ.set_nr_muls(0)
arg_type_sym := t.get_type_symbol(typ) arg_type_sym := t.sym(typ)
sig += arg_type_sym.str().to_lower().replace_each(['.', '__', '&', '', '[', 'arr_', 'chan ', sig += arg_type_sym.str().to_lower().replace_each(['.', '__', '&', '', '[', 'arr_', 'chan ',
'chan_', 'map[', 'map_of_', ']', '_to_', '<', '_T_', ',', '_', ' ', '', '>', '']) 'chan_', 'map[', 'map_of_', ']', '_to_', '<', '_T_', ',', '_', ' ', '', '>', ''])
if i < f.params.len - 1 { if i < f.params.len - 1 {
@ -207,7 +207,7 @@ pub fn (t &Table) fn_type_signature(f &Fn) string {
} }
} }
if f.return_type != 0 && f.return_type != void_type { if f.return_type != 0 && f.return_type != void_type {
sym := t.get_type_symbol(f.return_type) sym := t.sym(f.return_type)
opt := if f.return_type.has_flag(.optional) { 'option_' } else { '' } opt := if f.return_type.has_flag(.optional) { 'option_' } else { '' }
sig += '__$opt$sym.kind' sig += '__$opt$sym.kind'
} }
@ -225,7 +225,7 @@ pub fn (t &Table) fn_type_source_signature(f &Fn) string {
if t.is_fmt && arg.name.len > 0 { if t.is_fmt && arg.name.len > 0 {
sig += '$arg.name ' sig += '$arg.name '
} }
arg_type_sym := t.get_type_symbol(arg.typ) arg_type_sym := t.sym(arg.typ)
sig += arg_type_sym.name sig += arg_type_sym.name
if i < f.params.len - 1 { if i < f.params.len - 1 {
sig += ', ' sig += ', '
@ -235,7 +235,7 @@ pub fn (t &Table) fn_type_source_signature(f &Fn) string {
if f.return_type == ovoid_type { if f.return_type == ovoid_type {
sig += ' ?' sig += ' ?'
} else if f.return_type != void_type { } else if f.return_type != void_type {
return_type_sym := t.get_type_symbol(f.return_type) return_type_sym := t.sym(f.return_type)
if f.return_type.has_flag(.optional) { if f.return_type.has_flag(.optional) {
sig += ' ?$return_type_sym.name' sig += ' ?$return_type_sym.name'
} else { } else {
@ -260,8 +260,8 @@ pub fn (t &Table) is_same_method(f &Fn, func &Fn) string {
// don't check receiver for `.typ` // don't check receiver for `.typ`
has_unexpected_type := i > 0 && f.params[i].typ != func.params[i].typ has_unexpected_type := i > 0 && f.params[i].typ != func.params[i].typ
// temporary hack for JS ifaces // temporary hack for JS ifaces
lsym := t.get_type_symbol(f.params[i].typ) lsym := t.sym(f.params[i].typ)
rsym := t.get_type_symbol(func.params[i].typ) rsym := t.sym(func.params[i].typ)
if lsym.language == .js && rsym.language == .js { if lsym.language == .js && rsym.language == .js {
return '' return ''
} }
@ -316,7 +316,7 @@ pub fn (t &Table) register_aggregate_method(mut sym TypeSymbol, name string) ?Fn
mut found_once := false mut found_once := false
mut new_fn := Fn{} mut new_fn := Fn{}
for typ in agg_info.types { for typ in agg_info.types {
ts := t.get_type_symbol(typ) ts := t.sym(typ)
if type_method := ts.find_method(name) { if type_method := ts.find_method(name) {
if !found_once { if !found_once {
found_once = true found_once = true
@ -365,10 +365,10 @@ pub struct GetEmbedsOptions {
// the hierarchy of embeds is returned as a list // the hierarchy of embeds is returned as a list
pub fn (t &Table) get_embeds(sym &TypeSymbol, options GetEmbedsOptions) [][]Type { pub fn (t &Table) get_embeds(sym &TypeSymbol, options GetEmbedsOptions) [][]Type {
mut embeds := [][]Type{} mut embeds := [][]Type{}
unalias_sym := if sym.info is Alias { t.get_type_symbol(sym.info.parent_type) } else { sym } unalias_sym := if sym.info is Alias { t.sym(sym.info.parent_type) } else { sym }
if unalias_sym.info is Struct { if unalias_sym.info is Struct {
for embed in unalias_sym.info.embeds { for embed in unalias_sym.info.embeds {
embed_sym := t.get_type_symbol(embed) embed_sym := t.sym(embed)
mut preceding := options.preceding mut preceding := options.preceding
preceding << embed preceding << embed
embeds << t.get_embeds(embed_sym, preceding: preceding) embeds << t.get_embeds(embed_sym, preceding: preceding)
@ -385,7 +385,7 @@ pub fn (t &Table) find_method_from_embeds(sym &TypeSymbol, method_name string) ?
mut found_methods := []Fn{} mut found_methods := []Fn{}
mut embed_of_found_methods := []Type{} mut embed_of_found_methods := []Type{}
for embed in sym.info.embeds { for embed in sym.info.embeds {
embed_sym := t.get_type_symbol(embed) embed_sym := t.sym(embed)
if m := t.find_method(embed_sym, method_name) { if m := t.find_method(embed_sym, method_name) {
found_methods << m found_methods << m
embed_of_found_methods << embed embed_of_found_methods << embed
@ -403,7 +403,7 @@ pub fn (t &Table) find_method_from_embeds(sym &TypeSymbol, method_name string) ?
} }
} else if sym.info is Aggregate { } else if sym.info is Aggregate {
for typ in sym.info.types { for typ in sym.info.types {
agg_sym := t.get_type_symbol(typ) agg_sym := t.sym(typ)
method, embed_types := t.find_method_from_embeds(agg_sym, method_name) or { continue } method, embed_types := t.find_method_from_embeds(agg_sym, method_name) or { continue }
if embed_types.len != 0 { if embed_types.len != 0 {
return method, embed_types return method, embed_types
@ -434,7 +434,7 @@ fn (t &Table) register_aggregate_field(mut sym TypeSymbol, name string) ?StructF
mut found_once := false mut found_once := false
mut new_field := StructField{} mut new_field := StructField{}
for typ in agg_info.types { for typ in agg_info.types {
ts := t.get_type_symbol(typ) ts := t.sym(typ)
if type_field := t.find_field(ts, name) { if type_field := t.find_field(ts, name) {
if !found_once { if !found_once {
found_once = true found_once = true
@ -467,7 +467,7 @@ pub fn (t &Table) struct_fields(sym &TypeSymbol) []StructField {
if sym.info is Struct { if sym.info is Struct {
fields << sym.info.fields fields << sym.info.fields
for embed in sym.info.embeds { for embed in sym.info.embeds {
embed_sym := t.get_type_symbol(embed) embed_sym := t.sym(embed)
fields << t.struct_fields(embed_sym) fields << t.struct_fields(embed_sym)
} }
} }
@ -521,7 +521,7 @@ pub fn (t &Table) find_field_from_embeds(sym &TypeSymbol, field_name string) ?(S
mut found_fields := []StructField{} mut found_fields := []StructField{}
mut embeds_of_found_fields := []Type{} mut embeds_of_found_fields := []Type{}
for embed in sym.info.embeds { for embed in sym.info.embeds {
embed_sym := t.get_type_symbol(embed) embed_sym := t.sym(embed)
if field := t.find_field(embed_sym, field_name) { if field := t.find_field(embed_sym, field_name) {
found_fields << field found_fields << field
embeds_of_found_fields << embed embeds_of_found_fields << embed
@ -539,14 +539,14 @@ pub fn (t &Table) find_field_from_embeds(sym &TypeSymbol, field_name string) ?(S
} }
} else if sym.info is Aggregate { } else if sym.info is Aggregate {
for typ in sym.info.types { for typ in sym.info.types {
agg_sym := t.get_type_symbol(typ) agg_sym := t.sym(typ)
field, embed_types := t.find_field_from_embeds(agg_sym, field_name) or { continue } field, embed_types := t.find_field_from_embeds(agg_sym, field_name) or { continue }
if embed_types.len > 0 { if embed_types.len > 0 {
return field, embed_types return field, embed_types
} }
} }
} else if sym.info is Alias { } else if sym.info is Alias {
unalias_sym := t.get_type_symbol(sym.info.parent_type) unalias_sym := t.sym(sym.info.parent_type)
return t.find_field_from_embeds(unalias_sym, field_name) return t.find_field_from_embeds(unalias_sym, field_name)
} }
return none return none
@ -573,7 +573,7 @@ pub fn (t &Table) resolve_common_sumtype_fields(sym_ &TypeSymbol) {
mut field_map := map[string]StructField{} mut field_map := map[string]StructField{}
mut field_usages := map[string]int{} mut field_usages := map[string]int{}
for variant in info.variants { for variant in info.variants {
mut v_sym := t.get_final_type_symbol(variant) mut v_sym := t.final_sym(variant)
fields := match mut v_sym.info { fields := match mut v_sym.info {
Struct { Struct {
t.struct_fields(v_sym) t.struct_fields(v_sym)
@ -629,24 +629,24 @@ pub const invalid_type_symbol = &TypeSymbol{
} }
[inline] [inline]
pub fn (t &Table) get_type_symbol_by_idx(idx int) &TypeSymbol { pub fn (t &Table) sym_by_idx(idx int) &TypeSymbol {
return t.type_symbols[idx] return t.type_symbols[idx]
} }
pub fn (t &Table) get_type_symbol(typ Type) &TypeSymbol { pub fn (t &Table) sym(typ Type) &TypeSymbol {
idx := typ.idx() idx := typ.idx()
if idx > 0 { if idx > 0 {
return t.type_symbols[idx] return t.type_symbols[idx]
} }
// this should never happen // this should never happen
t.panic('get_type_symbol: invalid type (typ=$typ idx=$idx). Compiler bug. This should never happen. Please report the bug using `v bug file.v`. t.panic('sym: invalid type (typ=$typ idx=$idx). Compiler bug. This should never happen. Please report the bug using `v bug file.v`.
') ')
return ast.invalid_type_symbol return ast.invalid_type_symbol
} }
// get_final_type_symbol follows aliases until it gets to a "real" Type // final_sym follows aliases until it gets to a "real" Type
[inline] [inline]
pub fn (t &Table) get_final_type_symbol(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] current_symbol := t.type_symbols[idx]
@ -656,19 +656,19 @@ pub fn (t &Table) get_final_type_symbol(typ Type) &TypeSymbol {
return t.type_symbols[idx] return t.type_symbols[idx]
} }
// this should never happen // this should never happen
t.panic('get_final_type_symbol: invalid type (typ=$typ idx=$idx). Compiler bug. This should never happen. Please report the bug using `v bug file.v`.') t.panic('final_sym: invalid type (typ=$typ idx=$idx). Compiler bug. This should never happen. Please report the bug using `v bug file.v`.')
return ast.invalid_type_symbol return ast.invalid_type_symbol
} }
[inline] [inline]
pub fn (t &Table) get_type_name(typ Type) string { pub fn (t &Table) get_type_name(typ Type) string {
sym := t.get_type_symbol(typ) sym := t.sym(typ)
return sym.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.get_type_symbol(typ) sym := t.sym(typ)
if sym.kind == .alias { if sym.kind == .alias {
pt := (sym.info as Alias).parent_type pt := (sym.info as Alias).parent_type
if pt <= f64_type && pt >= void_type { if pt <= f64_type && pt >= void_type {
@ -751,7 +751,7 @@ pub fn (t &Table) known_type_idx(typ Type) bool {
if typ == 0 { if typ == 0 {
return false return false
} }
sym := t.get_type_symbol(typ) sym := t.sym(typ)
match sym.kind { match sym.kind {
.placeholder { .placeholder {
return sym.language != .v || sym.name.starts_with('C.') return sym.language != .v || sym.name.starts_with('C.')
@ -775,14 +775,14 @@ pub fn (t &Table) known_type_idx(typ Type) bool {
// e. g. []int // e. g. []int
[inline] [inline]
pub fn (t &Table) array_name(elem_type Type) string { pub fn (t &Table) array_name(elem_type Type) string {
elem_type_sym := t.get_type_symbol(elem_type) elem_type_sym := t.sym(elem_type)
ptr := if elem_type.is_ptr() { '&'.repeat(elem_type.nr_muls()) } else { '' } ptr := if elem_type.is_ptr() { '&'.repeat(elem_type.nr_muls()) } else { '' }
return '[]$ptr$elem_type_sym.name' return '[]$ptr$elem_type_sym.name'
} }
[inline] [inline]
pub fn (t &Table) array_cname(elem_type Type) string { pub fn (t &Table) array_cname(elem_type Type) string {
elem_type_sym := t.get_type_symbol(elem_type) elem_type_sym := t.sym(elem_type)
mut res := '' mut res := ''
if elem_type.is_ptr() { if elem_type.is_ptr() {
res = '_ptr'.repeat(elem_type.nr_muls()) res = '_ptr'.repeat(elem_type.nr_muls())
@ -799,7 +799,7 @@ pub fn (t &Table) array_cname(elem_type Type) string {
// e. g. [16][8]int // e. g. [16][8]int
[inline] [inline]
pub fn (t &Table) array_fixed_name(elem_type Type, size int, size_expr Expr) string { pub fn (t &Table) array_fixed_name(elem_type Type, size int, size_expr Expr) string {
elem_type_sym := t.get_type_symbol(elem_type) elem_type_sym := t.sym(elem_type)
ptr := if elem_type.is_ptr() { '&'.repeat(elem_type.nr_muls()) } else { '' } ptr := if elem_type.is_ptr() { '&'.repeat(elem_type.nr_muls()) } else { '' }
size_str := if size_expr is EmptyExpr || size != 987654321 { size_str := if size_expr is EmptyExpr || size != 987654321 {
size.str() size.str()
@ -811,7 +811,7 @@ pub fn (t &Table) array_fixed_name(elem_type Type, size int, size_expr Expr) str
[inline] [inline]
pub fn (t &Table) array_fixed_cname(elem_type Type, size int) string { pub fn (t &Table) array_fixed_cname(elem_type Type, size int) string {
elem_type_sym := t.get_type_symbol(elem_type) elem_type_sym := t.sym(elem_type)
mut res := '' mut res := ''
if elem_type.is_ptr() { if elem_type.is_ptr() {
res = '_ptr$elem_type.nr_muls()' res = '_ptr$elem_type.nr_muls()'
@ -821,7 +821,7 @@ pub fn (t &Table) array_fixed_cname(elem_type Type, size int) string {
[inline] [inline]
pub fn (t &Table) chan_name(elem_type Type, is_mut bool) string { pub fn (t &Table) chan_name(elem_type Type, is_mut bool) string {
elem_type_sym := t.get_type_symbol(elem_type) elem_type_sym := t.sym(elem_type)
mut ptr := '' mut ptr := ''
if is_mut { if is_mut {
ptr = 'mut ' ptr = 'mut '
@ -833,7 +833,7 @@ pub fn (t &Table) chan_name(elem_type Type, is_mut bool) string {
[inline] [inline]
pub fn (t &Table) chan_cname(elem_type Type, is_mut bool) string { pub fn (t &Table) chan_cname(elem_type Type, is_mut bool) string {
elem_type_sym := t.get_type_symbol(elem_type) elem_type_sym := t.sym(elem_type)
mut suffix := '' mut suffix := ''
if is_mut { if is_mut {
suffix = '_mut' suffix = '_mut'
@ -849,7 +849,7 @@ pub fn (t &Table) promise_name(return_type Type) string {
return 'Promise<JS.Any,JS.Any>' return 'Promise<JS.Any,JS.Any>'
} }
return_type_sym := t.get_type_symbol(return_type) return_type_sym := t.sym(return_type)
return 'Promise<$return_type_sym.name, JS.Any>' return 'Promise<$return_type_sym.name, JS.Any>'
} }
@ -859,7 +859,7 @@ pub fn (t &Table) promise_cname(return_type Type) string {
return 'Promise_Any_Any' return 'Promise_Any_Any'
} }
return_type_sym := t.get_type_symbol(return_type) return_type_sym := t.sym(return_type)
return 'Promise_${return_type_sym.name}_Any' return 'Promise_${return_type_sym.name}_Any'
} }
@ -872,7 +872,7 @@ pub fn (t &Table) thread_name(return_type Type) string {
return 'thread' return 'thread'
} }
} }
return_type_sym := t.get_type_symbol(return_type) return_type_sym := t.sym(return_type)
ptr := if return_type.is_ptr() { '&' } else { '' } ptr := if return_type.is_ptr() { '&' } else { '' }
opt := if return_type.has_flag(.optional) { '?' } else { '' } opt := if return_type.has_flag(.optional) { '?' } else { '' }
return 'thread $opt$ptr$return_type_sym.name' return 'thread $opt$ptr$return_type_sym.name'
@ -887,7 +887,7 @@ pub fn (t &Table) thread_cname(return_type Type) string {
return '__v_thread' return '__v_thread'
} }
} }
return_type_sym := t.get_type_symbol(return_type) return_type_sym := t.sym(return_type)
suffix := if return_type.is_ptr() { '_ptr' } else { '' } suffix := if return_type.is_ptr() { '_ptr' } else { '' }
prefix := if return_type.has_flag(.optional) { 'Option_' } else { '' } prefix := if return_type.has_flag(.optional) { 'Option_' } else { '' }
return '__v_thread_$prefix$return_type_sym.cname$suffix' return '__v_thread_$prefix$return_type_sym.cname$suffix'
@ -897,16 +897,16 @@ pub fn (t &Table) thread_cname(return_type Type) string {
// e. g. map[string]int // e. g. map[string]int
[inline] [inline]
pub fn (t &Table) map_name(key_type Type, value_type Type) string { pub fn (t &Table) map_name(key_type Type, value_type Type) string {
key_type_sym := t.get_type_symbol(key_type) key_type_sym := t.sym(key_type)
value_type_sym := t.get_type_symbol(value_type) value_type_sym := t.sym(value_type)
ptr := if value_type.is_ptr() { '&' } else { '' } ptr := if value_type.is_ptr() { '&' } else { '' }
return 'map[$key_type_sym.name]$ptr$value_type_sym.name' return 'map[$key_type_sym.name]$ptr$value_type_sym.name'
} }
[inline] [inline]
pub fn (t &Table) map_cname(key_type Type, value_type Type) string { pub fn (t &Table) map_cname(key_type Type, value_type Type) string {
key_type_sym := t.get_type_symbol(key_type) key_type_sym := t.sym(key_type)
value_type_sym := t.get_type_symbol(value_type) value_type_sym := t.sym(value_type)
suffix := if value_type.is_ptr() { '_ptr' } else { '' } suffix := if value_type.is_ptr() { '_ptr' } else { '' }
return 'Map_${key_type_sym.cname}_$value_type_sym.cname' + suffix return 'Map_${key_type_sym.cname}_$value_type_sym.cname' + suffix
} }
@ -1055,7 +1055,7 @@ pub fn (mut t Table) find_or_register_multi_return(mr_typs []Type) int {
mut name := '(' mut name := '('
mut cname := 'multi_return' mut cname := 'multi_return'
for i, mr_typ in mr_typs { for i, mr_typ in mr_typs {
mr_type_sym := t.get_type_symbol(mr_typ) mr_type_sym := t.sym(mr_typ)
name += mr_type_sym.name name += mr_type_sym.name
cname += '_$mr_type_sym.cname' cname += '_$mr_type_sym.cname'
if i < mr_typs.len - 1 { if i < mr_typs.len - 1 {
@ -1122,7 +1122,7 @@ pub fn (mut t Table) add_placeholder_type(name string, language Language) int {
[inline] [inline]
pub fn (t &Table) value_type(typ Type) Type { pub fn (t &Table) value_type(typ Type) Type {
sym := t.get_final_type_symbol(typ) sym := t.final_sym(typ)
if typ.has_flag(.variadic) { if typ.has_flag(.variadic) {
// ...string => string // ...string => string
// return typ.clear_flag(.variadic) // return typ.clear_flag(.variadic)
@ -1183,10 +1183,10 @@ pub fn (mut t Table) register_fn_concrete_types(fn_name string, types []Type) bo
// TODO: there is a bug when casting sumtype the other way if its pointer // TODO: there is a bug when casting sumtype the other way if its pointer
// so until fixed at least show v (not C) error `x(variant) = y(SumType*)` // so until fixed at least show v (not C) error `x(variant) = y(SumType*)`
pub fn (t &Table) sumtype_has_variant(parent Type, variant Type, is_as bool) bool { pub fn (t &Table) sumtype_has_variant(parent Type, variant Type, is_as bool) bool {
parent_sym := t.get_type_symbol(parent) parent_sym := t.sym(parent)
if parent_sym.kind == .sum_type { if parent_sym.kind == .sum_type {
parent_info := parent_sym.info as SumType parent_info := parent_sym.info as SumType
var_sym := t.get_type_symbol(variant) var_sym := t.sym(variant)
if var_sym.kind == .aggregate { if var_sym.kind == .aggregate {
var_info := var_sym.info as Aggregate var_info := var_sym.info as Aggregate
for var_type in var_info.types { for var_type in var_info.types {
@ -1212,7 +1212,7 @@ pub fn (t &Table) known_type_names() []string {
for _, idx in t.type_idxs { for _, idx in t.type_idxs {
// Skip `int_literal_type_idx` and `float_literal_type_idx` because they shouldn't be visible to the User. // Skip `int_literal_type_idx` and `float_literal_type_idx` because they shouldn't be visible to the User.
if idx !in [0, int_literal_type_idx, float_literal_type_idx] && t.known_type_idx(idx) if idx !in [0, int_literal_type_idx, float_literal_type_idx] && t.known_type_idx(idx)
&& t.get_type_symbol(idx).kind != .function { && t.sym(idx).kind != .function {
res << t.type_to_str(idx) res << t.type_to_str(idx)
} }
} }
@ -1225,7 +1225,7 @@ pub fn (t &Table) known_type_names() []string {
pub fn (t &Table) has_deep_child_no_ref(ts &TypeSymbol, name string) bool { pub fn (t &Table) has_deep_child_no_ref(ts &TypeSymbol, name string) bool {
if ts.info is Struct { if ts.info is Struct {
for field in ts.info.fields { for field in ts.info.fields {
sym := t.get_type_symbol(field.typ) sym := t.sym(field.typ)
if !field.typ.is_ptr() && (sym.name == name || t.has_deep_child_no_ref(sym, name)) { if !field.typ.is_ptr() && (sym.name == name || t.has_deep_child_no_ref(sym, name)) {
return true return true
} }
@ -1257,8 +1257,7 @@ pub fn (mut t Table) complete_interface_check() {
continue continue
} }
// empty interface only generate type cast functions of the current module // empty interface only generate type cast functions of the current module
if idecl.methods.len == 0 && idecl.fields.len == 0 if idecl.methods.len == 0 && idecl.fields.len == 0 && tsym.mod != t.sym(idecl.typ).mod {
&& tsym.mod != t.get_type_symbol(idecl.typ).mod {
continue continue
} }
if t.does_type_implement_interface(tk, idecl.typ) { if t.does_type_implement_interface(tk, idecl.typ) {
@ -1315,7 +1314,7 @@ pub fn (t Table) does_type_implement_interface(typ Type, inter_typ Type) bool {
// `none` "implements" the Error interface // `none` "implements" the Error interface
return true return true
} }
sym := t.get_type_symbol(typ) sym := t.sym(typ)
if sym.language != .v { if sym.language != .v {
return false return false
} }
@ -1325,7 +1324,7 @@ pub fn (t Table) does_type_implement_interface(typ Type, inter_typ Type) bool {
return false return false
} }
} }
mut inter_sym := t.get_type_symbol(inter_typ) mut inter_sym := t.sym(inter_typ)
if sym.kind == .interface_ && inter_sym.kind == .interface_ { if sym.kind == .interface_ && inter_sym.kind == .interface_ {
return false return false
} }
@ -1387,7 +1386,7 @@ pub fn (t Table) does_type_implement_interface(typ Type, inter_typ Type) bool {
// Even map[string]map[string]T can be resolved. // Even map[string]map[string]T can be resolved.
// This is used for resolving the generic return type of CallExpr white `unwrap_generic` is used to resolve generic usage in FnDecl. // This is used for resolving the generic return type of CallExpr white `unwrap_generic` is used to resolve generic usage in FnDecl.
pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_names []string, concrete_types []Type) ?Type { pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_names []string, concrete_types []Type) ?Type {
mut sym := t.get_type_symbol(generic_type) mut sym := t.sym(generic_type)
if sym.name in generic_names { if sym.name in generic_names {
index := generic_names.index(sym.name) index := generic_names.index(sym.name)
if index >= concrete_types.len { if index >= concrete_types.len {
@ -1402,12 +1401,12 @@ pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_name
match mut sym.info { match mut sym.info {
Array { Array {
mut elem_type := sym.info.elem_type mut elem_type := sym.info.elem_type
mut elem_sym := t.get_type_symbol(elem_type) mut elem_sym := t.sym(elem_type)
mut dims := 1 mut dims := 1
for mut elem_sym.info is Array { for mut elem_sym.info is Array {
info := elem_sym.info as Array info := elem_sym.info as Array
elem_type = info.elem_type elem_type = info.elem_type
elem_sym = t.get_type_symbol(elem_type) elem_sym = t.sym(elem_type)
dims++ dims++
} }
if typ := t.resolve_generic_to_concrete(elem_type, generic_names, concrete_types) { if typ := t.resolve_generic_to_concrete(elem_type, generic_names, concrete_types) {
@ -1498,7 +1497,7 @@ pub fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_name
if ct := t.resolve_generic_to_concrete(sym.info.generic_types[i], if ct := t.resolve_generic_to_concrete(sym.info.generic_types[i],
generic_names, concrete_types) generic_names, concrete_types)
{ {
gts := t.get_type_symbol(ct) gts := t.sym(ct)
nrt += gts.name nrt += gts.name
if i != sym.info.generic_types.len - 1 { if i != sym.info.generic_types.len - 1 {
nrt += ', ' nrt += ', '
@ -1523,16 +1522,16 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
mut fields := []StructField{} mut fields := []StructField{}
mut nrt := '' mut nrt := ''
mut c_nrt := '' mut c_nrt := ''
ts := t.get_type_symbol(typ) ts := t.sym(typ)
match mut ts.info { match mut ts.info {
Array { Array {
mut elem_type := ts.info.elem_type mut elem_type := ts.info.elem_type
mut elem_sym := t.get_type_symbol(elem_type) mut elem_sym := t.sym(elem_type)
mut dims := 1 mut dims := 1
for mut elem_sym.info is Array { for mut elem_sym.info is Array {
info := elem_sym.info as Array info := elem_sym.info as Array
elem_type = info.elem_type elem_type = info.elem_type
elem_sym = t.get_type_symbol(elem_type) elem_sym = t.sym(elem_type)
dims++ dims++
} }
unwrap_typ := t.unwrap_generic_type(elem_type, generic_names, concrete_types) unwrap_typ := t.unwrap_generic_type(elem_type, generic_names, concrete_types)
@ -1567,7 +1566,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
if ct := t.resolve_generic_to_concrete(ts.info.generic_types[i], generic_names, if ct := t.resolve_generic_to_concrete(ts.info.generic_types[i], generic_names,
concrete_types) concrete_types)
{ {
gts := t.get_type_symbol(ct) gts := t.sym(ct)
nrt += gts.name nrt += gts.name
c_nrt += gts.cname c_nrt += gts.cname
if i != ts.info.generic_types.len - 1 { if i != ts.info.generic_types.len - 1 {
@ -1585,7 +1584,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
fields = ts.info.fields.clone() fields = ts.info.fields.clone()
for i in 0 .. fields.len { for i in 0 .. fields.len {
if fields[i].typ.has_flag(.generic) { if fields[i].typ.has_flag(.generic) {
sym := t.get_type_symbol(fields[i].typ) sym := t.sym(fields[i].typ)
if sym.kind == .struct_ && fields[i].typ.idx() != typ.idx() { if sym.kind == .struct_ && fields[i].typ.idx() != typ.idx() {
fields[i].typ = t.unwrap_generic_type(fields[i].typ, generic_names, fields[i].typ = t.unwrap_generic_type(fields[i].typ, generic_names,
concrete_types) concrete_types)
@ -1669,7 +1668,7 @@ pub fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concr
mod: ts.mod mod: ts.mod
info: info info: info
) )
mut ts_copy := t.get_type_symbol(new_idx) mut ts_copy := t.sym(new_idx)
for method in all_methods { for method in all_methods {
ts_copy.register_method(method) ts_copy.register_method(method)
} }
@ -1699,7 +1698,7 @@ pub fn (mut t Table) generic_insts_to_concrete() {
} }
mut fields := parent_info.fields.clone() mut fields := parent_info.fields.clone()
if parent_info.generic_types.len == info.concrete_types.len { if parent_info.generic_types.len == info.concrete_types.len {
generic_names := parent_info.generic_types.map(t.get_type_symbol(it).name) generic_names := parent_info.generic_types.map(t.sym(it).name)
for i in 0 .. fields.len { for i in 0 .. fields.len {
if fields[i].typ.has_flag(.generic) { if fields[i].typ.has_flag(.generic) {
if fields[i].typ.idx() != info.parent_idx { if fields[i].typ.idx() != info.parent_idx {
@ -1727,7 +1726,7 @@ pub fn (mut t Table) generic_insts_to_concrete() {
typ.is_public = true typ.is_public = true
typ.kind = parent.kind typ.kind = parent.kind
parent_sym := t.get_type_symbol(parent_info.parent_type) parent_sym := t.sym(parent_info.parent_type)
for method in parent_sym.methods { for method in parent_sym.methods {
if method.generic_names.len == info.concrete_types.len { if method.generic_names.len == info.concrete_types.len {
t.register_fn_concrete_types(method.name, info.concrete_types) t.register_fn_concrete_types(method.name, info.concrete_types)
@ -1745,7 +1744,7 @@ pub fn (mut t Table) generic_insts_to_concrete() {
} }
if parent_info.generic_types.len == info.concrete_types.len { if parent_info.generic_types.len == info.concrete_types.len {
mut fields := parent_info.fields.clone() mut fields := parent_info.fields.clone()
generic_names := parent_info.generic_types.map(t.get_type_symbol(it).name) generic_names := parent_info.generic_types.map(t.sym(it).name)
for i in 0 .. fields.len { for i in 0 .. fields.len {
if t_typ := t.resolve_generic_to_concrete(fields[i].typ, generic_names, if t_typ := t.resolve_generic_to_concrete(fields[i].typ, generic_names,
info.concrete_types) info.concrete_types)
@ -1803,7 +1802,7 @@ pub fn (mut t Table) generic_insts_to_concrete() {
if parent_info.generic_types.len == info.concrete_types.len { if parent_info.generic_types.len == info.concrete_types.len {
mut fields := parent_info.fields.clone() mut fields := parent_info.fields.clone()
mut variants := parent_info.variants.clone() mut variants := parent_info.variants.clone()
generic_names := parent_info.generic_types.map(t.get_type_symbol(it).name) generic_names := parent_info.generic_types.map(t.sym(it).name)
for i in 0 .. fields.len { for i in 0 .. fields.len {
if t_typ := t.resolve_generic_to_concrete(fields[i].typ, generic_names, if t_typ := t.resolve_generic_to_concrete(fields[i].typ, generic_names,
info.concrete_types) info.concrete_types)
@ -1813,7 +1812,7 @@ pub fn (mut t Table) generic_insts_to_concrete() {
} }
for i in 0 .. variants.len { for i in 0 .. variants.len {
if variants[i].has_flag(.generic) { if variants[i].has_flag(.generic) {
sym := t.get_type_symbol(variants[i]) sym := t.sym(variants[i])
if sym.kind == .struct_ && variants[i].idx() != info.parent_idx { if sym.kind == .struct_ && variants[i].idx() != info.parent_idx {
variants[i] = t.unwrap_generic_type(variants[i], generic_names, variants[i] = t.unwrap_generic_type(variants[i], generic_names,
info.concrete_types) info.concrete_types)

View File

@ -78,7 +78,7 @@ pub fn pref_arch_to_table_language(pref_arch pref.Arch) Language {
// * Table.type_to_str(typ) not TypeSymbol.name. // * Table.type_to_str(typ) not TypeSymbol.name.
// * Table.type_kind(typ) not TypeSymbol.kind. // * Table.type_kind(typ) not TypeSymbol.kind.
// Each TypeSymbol is entered into `Table.types`. // Each TypeSymbol is entered into `Table.types`.
// See also: Table.get_type_symbol. // See also: Table.sym.
pub struct TypeSymbol { pub struct TypeSymbol {
pub: pub:
@ -262,7 +262,7 @@ pub fn (t Type) str() string {
} }
pub fn (t &Table) type_str(typ Type) string { pub fn (t &Table) type_str(typ Type) string {
sym := t.get_type_symbol(typ) sym := t.sym(typ)
return sym.name return sym.name
} }
@ -514,7 +514,7 @@ pub fn (t &Table) type_kind(typ Type) Kind {
if typ.nr_muls() > 0 || typ.has_flag(.optional) { if typ.nr_muls() > 0 || typ.has_flag(.optional) {
return Kind.placeholder return Kind.placeholder
} }
return t.get_type_symbol(typ).kind return t.sym(typ).kind
} }
pub enum Kind { pub enum Kind {
@ -933,14 +933,14 @@ pub fn (t &Table) type_to_str(typ Type) string {
// type name in code (for builtin) // type name in code (for builtin)
pub fn (mytable &Table) type_to_code(t Type) string { pub fn (mytable &Table) type_to_code(t Type) string {
match t { match t {
ast.int_literal_type, ast.float_literal_type { return mytable.get_type_symbol(t).kind.str() } ast.int_literal_type, ast.float_literal_type { return mytable.sym(t).kind.str() }
else { return mytable.type_to_str_using_aliases(t, map[string]string{}) } else { return mytable.type_to_str_using_aliases(t, map[string]string{}) }
} }
} }
// import_aliases is a map of imported symbol aliases 'module.Type' => 'Type' // import_aliases is a map of imported symbol aliases 'module.Type' => 'Type'
pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]string) string { pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]string) string {
sym := t.get_type_symbol(typ) sym := t.sym(typ)
mut res := sym.name mut res := sym.name
// Note, that the duplication of code in some of the match branches here // Note, that the duplication of code in some of the match branches here
// is VERY deliberate. DO NOT be tempted to use `else {}` instead, because // is VERY deliberate. DO NOT be tempted to use `else {}` instead, because
@ -1039,7 +1039,7 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]
Struct, Interface, SumType { Struct, Interface, SumType {
res += '<' res += '<'
for i, gtyp in sym.info.generic_types { for i, gtyp in sym.info.generic_types {
res += t.get_type_symbol(gtyp).name res += t.sym(gtyp).name
if i != sym.info.generic_types.len - 1 { if i != sym.info.generic_types.len - 1 {
res += ', ' res += ', '
} }
@ -1214,12 +1214,12 @@ pub fn (t &TypeSymbol) find_method_with_generic_parent(name string) ?Fn {
match t.info { match t.info {
Struct, Interface, SumType { Struct, Interface, SumType {
if t.info.parent_type.has_flag(.generic) { if t.info.parent_type.has_flag(.generic) {
parent_sym := table.get_type_symbol(t.info.parent_type) parent_sym := table.sym(t.info.parent_type)
if x := parent_sym.find_method(name) { if x := parent_sym.find_method(name) {
match parent_sym.info { match parent_sym.info {
Struct, Interface, SumType { Struct, Interface, SumType {
mut method := x mut method := x
generic_names := parent_sym.info.generic_types.map(table.get_type_symbol(it).name) generic_names := parent_sym.info.generic_types.map(table.sym(it).name)
if rt := table.resolve_generic_to_concrete(method.return_type, if rt := table.resolve_generic_to_concrete(method.return_type,
generic_names, t.info.concrete_types) generic_names, t.info.concrete_types)
{ {
@ -1262,7 +1262,7 @@ pub fn (t &TypeSymbol) is_js_compatible() bool {
match t.info { match t.info {
SumType { SumType {
for variant in t.info.variants { for variant in t.info.variants {
sym := table.get_final_type_symbol(variant) sym := table.final_sym(variant)
if !sym.is_js_compatible() { if !sym.is_js_compatible() {
return false return false
} }

View File

@ -72,7 +72,7 @@ fn (mut m Mapper) fn_name(fname string, receiver_type ast.Type, is_method bool)
if !is_method { if !is_method {
return fname return fname
} }
rec_sym := m.table.get_type_symbol(receiver_type) rec_sym := m.table.sym(receiver_type)
return '${rec_sym.name}.$fname' return '${rec_sym.name}.$fname'
} }

View File

@ -24,7 +24,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
c.check_expr_opt_call(right, right_type0), c.check_expr_opt_call(right, right_type0),
] ]
} }
right_type_sym := c.table.get_type_symbol(right_type) right_type_sym := c.table.sym(right_type)
if right_type_sym.kind == .multi_return { if right_type_sym.kind == .multi_return {
if node.right.len > 1 { if node.right.len > 1 {
c.error('cannot use multi-value $right_type_sym.name in single-value context', c.error('cannot use multi-value $right_type_sym.name in single-value context',
@ -91,7 +91,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
c.expected_type = c.unwrap_generic(left_type) c.expected_type = c.unwrap_generic(left_type)
// `map = {}` // `map = {}`
if left_type != 0 { if left_type != 0 {
sym := c.table.get_type_symbol(left_type) sym := c.table.sym(left_type)
if sym.kind == .map { if sym.kind == .map {
if node.right.len <= i { if node.right.len <= i {
// `map_1, map_2, map_3 = f()`, where f returns (map[int]int, map[int]int, map[int]int) // `map_1, map_2, map_3 = f()`, where f returns (map[int]int, map[int]int, map[int]int)
@ -124,7 +124,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
right := if i < node.right.len { node.right[i] } else { node.right[0] } right := if i < node.right.len { node.right[i] } else { node.right[0] }
mut right_type := node.right_types[i] mut right_type := node.right_types[i]
if right is ast.Ident { if right is ast.Ident {
right_sym := c.table.get_type_symbol(right_type) right_sym := c.table.sym(right_type)
if right_sym.info is ast.Struct { if right_sym.info is ast.Struct {
if right_sym.info.generic_types.len > 0 { if right_sym.info.generic_types.len > 0 {
if obj := right.scope.find(right.name) { if obj := right.scope.find(right.name) {
@ -176,7 +176,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
obj = c.fn_scope.find_var(right.obj.name) or { obj } obj = c.fn_scope.find_var(right.obj.name) or { obj }
} }
if obj.is_stack_obj && !c.inside_unsafe { if obj.is_stack_obj && !c.inside_unsafe {
type_sym := c.table.get_type_symbol(obj.typ.set_nr_muls(0)) type_sym := c.table.sym(obj.typ.set_nr_muls(0))
if !type_sym.is_heap() && !c.pref.translated { if !type_sym.is_heap() && !c.pref.translated {
suggestion := if type_sym.kind == .struct_ { suggestion := if type_sym.kind == .struct_ {
'declaring `$type_sym.name` as `[heap]`' 'declaring `$type_sym.name` as `[heap]`'
@ -193,7 +193,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
// Do not allow `a := 0; b := 0; a = &b` // Do not allow `a := 0; b := 0; a = &b`
if !is_decl && left is ast.Ident && !is_blank_ident && !left_type.is_real_pointer() if !is_decl && left is ast.Ident && !is_blank_ident && !left_type.is_real_pointer()
&& right_type.is_real_pointer() { && right_type.is_real_pointer() {
left_sym := c.table.get_type_symbol(left_type) left_sym := c.table.sym(left_type)
if left_sym.kind != .function { if left_sym.kind != .function {
c.warn( c.warn(
'cannot assign a reference to a value (this will be an error soon) left=${c.table.type_str(left_type)} $left_type.is_ptr() ' + 'cannot assign a reference to a value (this will be an error soon) left=${c.table.type_str(left_type)} $left_type.is_ptr() ' +
@ -246,7 +246,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
left.obj.is_used = true left.obj.is_used = true
} }
if !left_type.is_ptr() { if !left_type.is_ptr() {
if c.table.get_type_symbol(left_type).is_heap() { if c.table.sym(left_type).is_heap() {
left.obj.is_auto_heap = true left.obj.is_auto_heap = true
} }
} }
@ -326,8 +326,8 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
if left_type_unwrapped == 0 { if left_type_unwrapped == 0 {
continue continue
} }
left_sym := c.table.get_type_symbol(left_type_unwrapped) left_sym := c.table.sym(left_type_unwrapped)
right_sym := c.table.get_type_symbol(right_type_unwrapped) right_sym := c.table.sym(right_type_unwrapped)
if left_sym.kind == .array && !c.inside_unsafe && node.op in [.assign, .decl_assign] if left_sym.kind == .array && !c.inside_unsafe && node.op in [.assign, .decl_assign]
&& right_sym.kind == .array && (left is ast.Ident && !left.is_blank_ident()) && right_sym.kind == .array && (left is ast.Ident && !left.is_blank_ident())
&& right is ast.Ident { && right is ast.Ident {
@ -398,13 +398,11 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
} }
} }
.mult_assign, .div_assign { .mult_assign, .div_assign {
if !left_sym.is_number() if !left_sym.is_number() && !c.table.final_sym(left_type_unwrapped).is_int()
&& !c.table.get_final_type_symbol(left_type_unwrapped).is_int()
&& left_sym.kind !in [.struct_, .alias] { && left_sym.kind !in [.struct_, .alias] {
c.error('operator $node.op.str() not defined on left operand type `$left_sym.name`', c.error('operator $node.op.str() not defined on left operand type `$left_sym.name`',
left.position()) left.position())
} else if !right_sym.is_number() } else if !right_sym.is_number() && !c.table.final_sym(left_type_unwrapped).is_int()
&& !c.table.get_final_type_symbol(left_type_unwrapped).is_int()
&& left_sym.kind !in [.struct_, .alias] { && left_sym.kind !in [.struct_, .alias] {
c.error('operator $node.op.str() not defined on right operand type `$right_sym.name`', c.error('operator $node.op.str() not defined on right operand type `$right_sym.name`',
right.position()) right.position())
@ -412,12 +410,10 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
} }
.and_assign, .or_assign, .xor_assign, .mod_assign, .left_shift_assign, .and_assign, .or_assign, .xor_assign, .mod_assign, .left_shift_assign,
.right_shift_assign { .right_shift_assign {
if !left_sym.is_int() if !left_sym.is_int() && !c.table.final_sym(left_type_unwrapped).is_int() {
&& !c.table.get_final_type_symbol(left_type_unwrapped).is_int() {
c.error('operator $node.op.str() not defined on left operand type `$left_sym.name`', c.error('operator $node.op.str() not defined on left operand type `$left_sym.name`',
left.position()) left.position())
} else if !right_sym.is_int() } else if !right_sym.is_int() && !c.table.final_sym(right_type_unwrapped).is_int() {
&& !c.table.get_final_type_symbol(right_type_unwrapped).is_int() {
c.error('operator $node.op.str() not defined on right operand type `$right_sym.name`', c.error('operator $node.op.str() not defined on right operand type `$right_sym.name`',
right.position()) right.position())
} }
@ -429,7 +425,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
} }
modified_left_type := if !left_type.is_int() { modified_left_type := if !left_type.is_int() {
c.error('invalid operation: shift on type `${c.table.get_type_symbol(left_type).name}`', c.error('invalid operation: shift on type `${c.table.sym(left_type).name}`',
node.pos) node.pos)
ast.void_type_idx ast.void_type_idx
} else if left_type.is_int_literal() { } else if left_type.is_int_literal() {
@ -483,7 +479,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|| left_sym.kind == .alias) { || left_sym.kind == .alias) {
left_name := c.table.type_to_str(left_type_unwrapped) left_name := c.table.type_to_str(left_type_unwrapped)
right_name := c.table.type_to_str(right_type_unwrapped) right_name := c.table.type_to_str(right_type_unwrapped)
parent_sym := c.table.get_final_type_symbol(left_type_unwrapped) parent_sym := c.table.final_sym(left_type_unwrapped)
if left_sym.kind == .alias && right_sym.kind != .alias { if left_sym.kind == .alias && right_sym.kind != .alias {
c.error('mismatched types `$left_name` and `$right_name`', node.pos) c.error('mismatched types `$left_name` and `$right_name`', node.pos)
} }
@ -577,7 +573,7 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
} }
if right_node.op == .arrow { if right_node.op == .arrow {
if assigned_var.is_mut { if assigned_var.is_mut {
right_sym := c.table.get_type_symbol(right_type0) right_sym := c.table.sym(right_type0)
if right_sym.kind == .chan { if right_sym.kind == .chan {
chan_info := right_sym.chan_info() chan_info := right_sym.chan_info()
if chan_info.elem_type.is_ptr() && !chan_info.is_mut { if chan_info.elem_type.is_ptr() && !chan_info.is_mut {

View File

@ -20,7 +20,7 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
// return true // return true
//} //}
deref := expected.deref() deref := expected.deref()
got_sym := c.table.get_type_symbol(got) got_sym := c.table.sym(got)
if deref.is_number() && (got_sym.is_number() || got_sym.kind == .enum_) { if deref.is_number() && (got_sym.is_number() || got_sym.kind == .enum_) {
return true return true
} }
@ -61,7 +61,7 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
return true return true
} }
if expected.has_flag(.optional) { if expected.has_flag(.optional) {
sym := c.table.get_type_symbol(got) sym := c.table.sym(got)
if (sym.kind == .interface_ && sym.name == 'IError') if (sym.kind == .interface_ && sym.name == 'IError')
|| got in [ast.none_type, ast.error_type] { || got in [ast.none_type, ast.error_type] {
return true return true
@ -79,7 +79,7 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
return true return true
} }
if c.promote_num(expected, got) != expected { if c.promote_num(expected, got) != expected {
// println('could not promote ${c.table.get_type_symbol(got).name} to ${c.table.get_type_symbol(expected).name}') // println('could not promote ${c.table.sym(got).name} to ${c.table.sym(expected).name}')
return false return false
} }
} }
@ -96,7 +96,7 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
mut expected := expected_ mut expected := expected_
// variadic // variadic
if expected.has_flag(.variadic) { if expected.has_flag(.variadic) {
exp_type_sym := c.table.get_type_symbol(expected_) exp_type_sym := c.table.sym(expected_)
exp_info := exp_type_sym.info as ast.Array exp_info := exp_type_sym.info as ast.Array
expected = exp_info.elem_type expected = exp_info.elem_type
} }
@ -112,7 +112,7 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
&& got.idx() in [ast.int_type_idx, ast.int_literal_type_idx]) { && got.idx() in [ast.int_type_idx, ast.int_literal_type_idx]) {
return return
} }
exp_sym := c.table.get_type_symbol(expected) exp_sym := c.table.sym(expected)
// unknown C types are set to int, allow int to be used for types like `&C.FILE` // unknown C types are set to int, allow int to be used for types like `&C.FILE`
// eg. `C.fflush(C.stderr)` - error: cannot use `int` as `&C.FILE` in argument 1 to `C.fflush` // eg. `C.fflush(C.stderr)` - error: cannot use `int` as `&C.FILE` in argument 1 to `C.fflush`
if expected.is_ptr() && exp_sym.language == .c && exp_sym.kind in [.placeholder, .struct_] if expected.is_ptr() && exp_sym.language == .c && exp_sym.kind in [.placeholder, .struct_]
@ -158,7 +158,7 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
if c.check_types(got, expected) { if c.check_types(got, expected) {
if language != .v || expected.is_ptr() == got.is_ptr() || arg.is_mut if language != .v || expected.is_ptr() == got.is_ptr() || arg.is_mut
|| arg.expr.is_auto_deref_var() || got.has_flag(.shared_f) || arg.expr.is_auto_deref_var() || got.has_flag(.shared_f)
|| c.table.get_type_symbol(expected_).kind !in [.array, .map] { || c.table.sym(expected_).kind !in [.array, .map] {
return return
} }
} }
@ -184,7 +184,7 @@ pub fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool {
if expected.idx() == ast.array_type_idx || got.idx() == ast.array_type_idx { if expected.idx() == ast.array_type_idx || got.idx() == ast.array_type_idx {
return true return true
} }
got_sym, exp_sym := c.table.get_type_symbol(got), c.table.get_type_symbol(expected) got_sym, exp_sym := c.table.sym(got), c.table.sym(expected)
// array/map as argument // array/map as argument
if got_sym.kind in [.array, .map, .array_fixed] && exp_sym.kind == got_sym.kind { if got_sym.kind in [.array, .map, .array_fixed] && exp_sym.kind == got_sym.kind {
if c.table.type_to_str(got) == c.table.type_to_str(expected).trim('&') { if c.table.type_to_str(got) == c.table.type_to_str(expected).trim('&') {
@ -261,7 +261,7 @@ pub fn (mut c Checker) check_matching_function_symbols(got_type_sym &ast.TypeSym
fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type ast.Type, right_type ast.Type) ast.Type { fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type ast.Type, right_type ast.Type) ast.Type {
if !left_type.is_int() { if !left_type.is_int() {
left_sym := c.table.get_type_symbol(left_type) left_sym := c.table.sym(left_type)
// maybe it's an int alias? TODO move this to is_int() ? // maybe it's an int alias? TODO move this to is_int() ?
if left_sym.kind == .alias && (left_sym.info as ast.Alias).parent_type.is_int() { if left_sym.kind == .alias && (left_sym.info as ast.Alias).parent_type.is_int() {
return left_type return left_type
@ -274,8 +274,8 @@ fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type ast.Type, right
return ast.void_type return ast.void_type
} }
if !right_type.is_int() && !c.pref.translated { if !right_type.is_int() && !c.pref.translated {
left_sym := c.table.get_type_symbol(left_type) left_sym := c.table.sym(left_type)
right_sym := c.table.get_type_symbol(right_type) right_sym := c.table.sym(right_type)
c.error('cannot shift non-integer type `$right_sym.name` into type `$left_sym.name`', c.error('cannot shift non-integer type `$right_sym.name` into type `$left_sym.name`',
node.right.position()) node.right.position())
return ast.void_type return ast.void_type
@ -315,7 +315,7 @@ fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type ast.Type, right
// non-negative value, the value of the result is the integral // non-negative value, the value of the result is the integral
// part of the quotient of E1/2^E2. If E1 has a signed type and // part of the quotient of E1/2^E2. If E1 has a signed type and
// a negative value, the resulting value is implementation-defined (ID). // a negative value, the resulting value is implementation-defined (ID).
left_sym_final := c.table.get_final_type_symbol(left_type) left_sym_final := c.table.final_sym(left_type)
left_type_final := ast.Type(left_sym_final.idx) left_type_final := ast.Type(left_sym_final.idx)
if node.op == .left_shift && left_type_final.is_signed() && !(c.inside_unsafe if node.op == .left_shift && left_type_final.is_signed() && !(c.inside_unsafe
&& c.is_generated) { && c.is_generated) {
@ -478,11 +478,11 @@ pub fn (mut c Checker) get_default_fmt(ftyp ast.Type, typ ast.Type) byte {
} else if typ.is_pointer() { } else if typ.is_pointer() {
return `p` return `p`
} else { } else {
mut sym := c.table.get_type_symbol(c.unwrap_generic(ftyp)) mut sym := c.table.sym(c.unwrap_generic(ftyp))
if sym.kind == .alias { if sym.kind == .alias {
// string aliases should be printable // string aliases should be printable
info := sym.info as ast.Alias info := sym.info as ast.Alias
sym = c.table.get_type_symbol(info.parent_type) sym = c.table.sym(info.parent_type)
if info.parent_type == ast.string_type { if info.parent_type == ast.string_type {
return `s` return `s`
} }
@ -692,7 +692,7 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr
mut to_set := ast.void_type mut to_set := ast.void_type
// resolve generic struct receiver // resolve generic struct receiver
if i == 0 && node.is_method && param.typ.has_flag(.generic) { if i == 0 && node.is_method && param.typ.has_flag(.generic) {
sym := c.table.get_type_symbol(node.receiver_type) sym := c.table.sym(node.receiver_type)
match sym.info { match sym.info {
ast.Struct, ast.Interface, ast.SumType { ast.Struct, ast.Interface, ast.SumType {
if c.table.cur_fn.generic_names.len > 0 { // in generic fn if c.table.cur_fn.generic_names.len > 0 { // in generic fn
@ -702,7 +702,7 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr
typ = c.table.cur_concrete_types[idx] typ = c.table.cur_concrete_types[idx]
} }
} else { // in non-generic fn } else { // in non-generic fn
receiver_generic_names := sym.info.generic_types.map(c.table.get_type_symbol(it).name) receiver_generic_names := sym.info.generic_types.map(c.table.sym(it).name)
if gt_name in receiver_generic_names if gt_name in receiver_generic_names
&& sym.info.generic_types.len == sym.info.concrete_types.len { && sym.info.generic_types.len == sym.info.concrete_types.len {
idx := receiver_generic_names.index(gt_name) idx := receiver_generic_names.index(gt_name)
@ -719,11 +719,11 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr
} }
mut arg := node.args[arg_i] mut arg := node.args[arg_i]
arg.typ = c.unwrap_generic(arg.typ) arg.typ = c.unwrap_generic(arg.typ)
param_type_sym := c.table.get_type_symbol(param.typ) param_type_sym := c.table.sym(param.typ)
if param.typ.has_flag(.generic) && param_type_sym.name == gt_name { if param.typ.has_flag(.generic) && param_type_sym.name == gt_name {
to_set = c.table.mktyp(arg.typ) to_set = c.table.mktyp(arg.typ)
sym := c.table.get_type_symbol(arg.typ) sym := c.table.sym(arg.typ)
if sym.info is ast.FnType { if sym.info is ast.FnType {
mut func_ := sym.info.func mut func_ := sym.info.func
func_.name = '' func_.name = ''
@ -742,21 +742,21 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr
to_set = c.unwrap_generic(to_set) to_set = c.unwrap_generic(to_set)
} }
} else if param.typ.has_flag(.generic) { } else if param.typ.has_flag(.generic) {
arg_sym := c.table.get_type_symbol(arg.typ) arg_sym := c.table.sym(arg.typ)
if param.typ.has_flag(.variadic) { if param.typ.has_flag(.variadic) {
to_set = c.table.mktyp(arg.typ) to_set = c.table.mktyp(arg.typ)
} else if arg_sym.kind == .array && param_type_sym.kind == .array { } else if arg_sym.kind == .array && param_type_sym.kind == .array {
mut arg_elem_info := arg_sym.info as ast.Array mut arg_elem_info := arg_sym.info as ast.Array
mut param_elem_info := param_type_sym.info as ast.Array mut param_elem_info := param_type_sym.info as ast.Array
mut arg_elem_sym := c.table.get_type_symbol(arg_elem_info.elem_type) mut arg_elem_sym := c.table.sym(arg_elem_info.elem_type)
mut param_elem_sym := c.table.get_type_symbol(param_elem_info.elem_type) mut param_elem_sym := c.table.sym(param_elem_info.elem_type)
for { for {
if arg_elem_sym.kind == .array && param_elem_sym.kind == .array if arg_elem_sym.kind == .array && param_elem_sym.kind == .array
&& param_elem_sym.name !in c.table.cur_fn.generic_names { && param_elem_sym.name !in c.table.cur_fn.generic_names {
arg_elem_info = arg_elem_sym.info as ast.Array arg_elem_info = arg_elem_sym.info as ast.Array
arg_elem_sym = c.table.get_type_symbol(arg_elem_info.elem_type) arg_elem_sym = c.table.sym(arg_elem_info.elem_type)
param_elem_info = param_elem_sym.info as ast.Array param_elem_info = param_elem_sym.info as ast.Array
param_elem_sym = c.table.get_type_symbol(param_elem_info.elem_type) param_elem_sym = c.table.sym(param_elem_info.elem_type)
} else { } else {
to_set = arg_elem_info.elem_type to_set = arg_elem_info.elem_type
break break
@ -765,15 +765,15 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr
} else if arg_sym.kind == .array_fixed && param_type_sym.kind == .array_fixed { } else if arg_sym.kind == .array_fixed && param_type_sym.kind == .array_fixed {
mut arg_elem_info := arg_sym.info as ast.ArrayFixed mut arg_elem_info := arg_sym.info as ast.ArrayFixed
mut param_elem_info := param_type_sym.info as ast.ArrayFixed mut param_elem_info := param_type_sym.info as ast.ArrayFixed
mut arg_elem_sym := c.table.get_type_symbol(arg_elem_info.elem_type) mut arg_elem_sym := c.table.sym(arg_elem_info.elem_type)
mut param_elem_sym := c.table.get_type_symbol(param_elem_info.elem_type) mut param_elem_sym := c.table.sym(param_elem_info.elem_type)
for { for {
if arg_elem_sym.kind == .array_fixed && param_elem_sym.kind == .array_fixed if arg_elem_sym.kind == .array_fixed && param_elem_sym.kind == .array_fixed
&& param_elem_sym.name !in c.table.cur_fn.generic_names { && param_elem_sym.name !in c.table.cur_fn.generic_names {
arg_elem_info = arg_elem_sym.info as ast.ArrayFixed arg_elem_info = arg_elem_sym.info as ast.ArrayFixed
arg_elem_sym = c.table.get_type_symbol(arg_elem_info.elem_type) arg_elem_sym = c.table.sym(arg_elem_info.elem_type)
param_elem_info = param_elem_sym.info as ast.ArrayFixed param_elem_info = param_elem_sym.info as ast.ArrayFixed
param_elem_sym = c.table.get_type_symbol(param_elem_info.elem_type) param_elem_sym = c.table.sym(param_elem_info.elem_type)
} else { } else {
to_set = arg_elem_info.elem_type to_set = arg_elem_info.elem_type
break break
@ -783,11 +783,11 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr
arg_map_info := arg_sym.info as ast.Map arg_map_info := arg_sym.info as ast.Map
param_map_info := param_type_sym.info as ast.Map param_map_info := param_type_sym.info as ast.Map
if param_map_info.key_type.has_flag(.generic) if param_map_info.key_type.has_flag(.generic)
&& c.table.get_type_symbol(param_map_info.key_type).name == gt_name { && c.table.sym(param_map_info.key_type).name == gt_name {
typ = arg_map_info.key_type typ = arg_map_info.key_type
} }
if param_map_info.value_type.has_flag(.generic) if param_map_info.value_type.has_flag(.generic)
&& c.table.get_type_symbol(param_map_info.value_type).name == gt_name { && c.table.sym(param_map_info.value_type).name == gt_name {
typ = arg_map_info.value_type typ = arg_map_info.value_type
} }
} else if arg_sym.kind in [.struct_, .interface_, .sum_type] { } else if arg_sym.kind in [.struct_, .interface_, .sum_type] {
@ -800,7 +800,7 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr
} }
else {} else {}
} }
generic_names := generic_types.map(c.table.get_type_symbol(it).name) generic_names := generic_types.map(c.table.sym(it).name)
if gt_name in generic_names && generic_types.len == concrete_types.len { if gt_name in generic_names && generic_types.len == concrete_types.len {
idx := generic_names.index(gt_name) idx := generic_names.index(gt_name)
typ = concrete_types[idx] typ = concrete_types[idx]
@ -819,7 +819,7 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr
} }
} }
if !c.check_types(typ, to_set) { if !c.check_types(typ, to_set) {
c.error('inferred generic type `$gt_name` is ambiguous: got `${c.table.get_type_symbol(to_set).name}`, expected `${c.table.get_type_symbol(typ).name}`', c.error('inferred generic type `$gt_name` is ambiguous: got `${c.table.sym(to_set).name}`, expected `${c.table.sym(typ).name}`',
arg.pos) arg.pos)
} }
} }

View File

@ -414,11 +414,11 @@ pub fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
c.check_valid_pascal_case(node.name, 'type alias', node.pos) c.check_valid_pascal_case(node.name, 'type alias', node.pos)
} }
c.ensure_type_exists(node.parent_type, node.type_pos) or { return } c.ensure_type_exists(node.parent_type, node.type_pos) or { return }
typ_sym := c.table.get_type_symbol(node.parent_type) typ_sym := c.table.sym(node.parent_type)
if typ_sym.kind in [.placeholder, .int_literal, .float_literal] { if typ_sym.kind in [.placeholder, .int_literal, .float_literal] {
c.error('unknown type `$typ_sym.name`', node.type_pos) c.error('unknown type `$typ_sym.name`', node.type_pos)
} else if typ_sym.kind == .alias { } else if typ_sym.kind == .alias {
orig_sym := c.table.get_type_symbol((typ_sym.info as ast.Alias).parent_type) orig_sym := c.table.sym((typ_sym.info as ast.Alias).parent_type)
c.error('type `$typ_sym.str()` is an alias, use the original alias type `$orig_sym.name` instead', c.error('type `$typ_sym.str()` is an alias, use the original alias type `$orig_sym.name` instead',
node.type_pos) node.type_pos)
} else if typ_sym.kind == .chan { } else if typ_sym.kind == .chan {
@ -428,17 +428,17 @@ pub fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
pub fn (mut c Checker) fn_type_decl(node ast.FnTypeDecl) { pub fn (mut c Checker) fn_type_decl(node ast.FnTypeDecl) {
c.check_valid_pascal_case(node.name, 'fn type', node.pos) c.check_valid_pascal_case(node.name, 'fn type', node.pos)
typ_sym := c.table.get_type_symbol(node.typ) typ_sym := c.table.sym(node.typ)
fn_typ_info := typ_sym.info as ast.FnType fn_typ_info := typ_sym.info as ast.FnType
fn_info := fn_typ_info.func fn_info := fn_typ_info.func
c.ensure_type_exists(fn_info.return_type, fn_info.return_type_pos) or {} c.ensure_type_exists(fn_info.return_type, fn_info.return_type_pos) or {}
ret_sym := c.table.get_type_symbol(fn_info.return_type) ret_sym := c.table.sym(fn_info.return_type)
if ret_sym.kind == .placeholder { if ret_sym.kind == .placeholder {
c.error('unknown type `$ret_sym.name`', fn_info.return_type_pos) c.error('unknown type `$ret_sym.name`', fn_info.return_type_pos)
} }
for arg in fn_info.params { for arg in fn_info.params {
c.ensure_type_exists(arg.typ, arg.type_pos) or { return } c.ensure_type_exists(arg.typ, arg.type_pos) or { return }
arg_sym := c.table.get_type_symbol(arg.typ) arg_sym := c.table.sym(arg.typ)
if arg_sym.kind == .placeholder { if arg_sym.kind == .placeholder {
c.error('unknown type `$arg_sym.name`', arg.type_pos) c.error('unknown type `$arg_sym.name`', arg.type_pos)
} }
@ -453,7 +453,7 @@ pub fn (mut c Checker) sum_type_decl(node ast.SumTypeDecl) {
c.error('sum type cannot hold a reference type', variant.pos) c.error('sum type cannot hold a reference type', variant.pos)
} }
c.ensure_type_exists(variant.typ, variant.pos) or {} c.ensure_type_exists(variant.typ, variant.pos) or {}
mut sym := c.table.get_type_symbol(variant.typ) mut sym := c.table.sym(variant.typ)
if sym.name in names_used { if sym.name in names_used {
c.error('sum type $node.name cannot hold the type `$sym.name` more than once', c.error('sum type $node.name cannot hold the type `$sym.name` more than once',
variant.pos) variant.pos)
@ -514,7 +514,7 @@ pub fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
if embed.typ.has_flag(.generic) { if embed.typ.has_flag(.generic) {
has_generic_types = true has_generic_types = true
} }
embed_sym := c.table.get_type_symbol(embed.typ) embed_sym := c.table.sym(embed.typ)
if embed_sym.kind != .struct_ { if embed_sym.kind != .struct_ {
c.error('`$embed_sym.name` is not a struct', embed.pos) c.error('`$embed_sym.name` is not a struct', embed.pos)
} else { } else {
@ -541,7 +541,7 @@ pub fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
if node.language == .v { if node.language == .v {
c.check_valid_snake_case(field.name, 'field name', field.pos) c.check_valid_snake_case(field.name, 'field name', field.pos)
} }
sym := c.table.get_type_symbol(field.typ) sym := c.table.sym(field.typ)
for j in 0 .. i { for j in 0 .. i {
if field.name == node.fields[j].name { if field.name == node.fields[j].name {
c.error('field name `$field.name` duplicate', field.pos) c.error('field name `$field.name` duplicate', field.pos)
@ -565,7 +565,7 @@ pub fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
&& c.type_implements(field_expr_type, field.typ, field.pos) { && c.type_implements(field_expr_type, field.typ, field.pos) {
if !field_expr_type.is_ptr() && !field_expr_type.is_pointer() if !field_expr_type.is_ptr() && !field_expr_type.is_pointer()
&& !c.inside_unsafe { && !c.inside_unsafe {
field_expr_type_sym := c.table.get_type_symbol(field_expr_type) field_expr_type_sym := c.table.sym(field_expr_type)
if field_expr_type_sym.kind != .interface_ { if field_expr_type_sym.kind != .interface_ {
c.mark_as_referenced(mut &node.fields[i].default_expr, c.mark_as_referenced(mut &node.fields[i].default_expr,
true) true)
@ -612,14 +612,14 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
c.error('unexpected short struct syntax', node.pos) c.error('unexpected short struct syntax', node.pos)
return ast.void_type return ast.void_type
} }
sym := c.table.get_type_symbol(c.expected_type) sym := c.table.sym(c.expected_type)
if sym.kind == .array { if sym.kind == .array {
node.typ = c.table.value_type(c.expected_type) node.typ = c.table.value_type(c.expected_type)
} else { } else {
node.typ = c.expected_type node.typ = c.expected_type
} }
} }
struct_sym := c.table.get_type_symbol(node.typ) struct_sym := c.table.sym(node.typ)
if struct_sym.info is ast.Struct { if struct_sym.info is ast.Struct {
if struct_sym.info.generic_types.len > 0 && struct_sym.info.concrete_types.len == 0 if struct_sym.info.generic_types.len > 0 && struct_sym.info.concrete_types.len == 0
&& c.table.cur_concrete_types.len == 0 { && c.table.cur_concrete_types.len == 0 {
@ -627,7 +627,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
node.pos) node.pos)
} }
} else if struct_sym.info is ast.Alias { } else if struct_sym.info is ast.Alias {
parent_sym := c.table.get_type_symbol(struct_sym.info.parent_type) parent_sym := c.table.sym(struct_sym.info.parent_type)
// e.g. ´x := MyMapAlias{}´, should be a cast to alias type ´x := MyMapAlias(map[...]...)´ // e.g. ´x := MyMapAlias{}´, should be a cast to alias type ´x := MyMapAlias(map[...]...)´
if parent_sym.kind == .map { if parent_sym.kind == .map {
alias_str := c.table.type_to_str(node.typ) alias_str := c.table.type_to_str(node.typ)
@ -642,7 +642,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
c.table.unwrap_generic_type(node.typ, c.table.cur_fn.generic_names, c.table.cur_concrete_types) c.table.unwrap_generic_type(node.typ, c.table.cur_fn.generic_names, c.table.cur_concrete_types)
} }
c.ensure_type_exists(node.typ, node.pos) or {} c.ensure_type_exists(node.typ, node.pos) or {}
type_sym := c.table.get_type_symbol(node.typ) type_sym := c.table.sym(node.typ)
if !c.inside_unsafe && type_sym.kind == .sum_type { if !c.inside_unsafe && type_sym.kind == .sum_type {
c.note('direct sum type init (`x := SumType{}`) will be removed soon', node.pos) c.note('direct sum type init (`x := SumType{}`) will be removed soon', node.pos)
} }
@ -696,7 +696,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
mut info := ast.Struct{} mut info := ast.Struct{}
if type_sym.kind == .alias { if type_sym.kind == .alias {
info_t := type_sym.info as ast.Alias info_t := type_sym.info as ast.Alias
sym := c.table.get_type_symbol(info_t.parent_type) sym := c.table.sym(info_t.parent_type)
if sym.kind == .placeholder { // pending import symbol did not resolve if sym.kind == .placeholder { // pending import symbol did not resolve
c.error('unknown struct: $type_sym.name', node.pos) c.error('unknown struct: $type_sym.name', node.pos)
return ast.void_type return ast.void_type
@ -752,14 +752,14 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
mut expr_type := ast.Type(0) mut expr_type := ast.Type(0)
mut expected_type := ast.Type(0) mut expected_type := ast.Type(0)
inited_fields << field_name inited_fields << field_name
field_type_sym := c.table.get_type_symbol(field_info.typ) field_type_sym := c.table.sym(field_info.typ)
expected_type = field_info.typ expected_type = field_info.typ
c.expected_type = expected_type c.expected_type = expected_type
expr_type = c.expr(field.expr) expr_type = c.expr(field.expr)
if !field_info.typ.has_flag(.optional) { if !field_info.typ.has_flag(.optional) {
expr_type = c.check_expr_opt_call(field.expr, expr_type) expr_type = c.check_expr_opt_call(field.expr, expr_type)
} }
expr_type_sym := c.table.get_type_symbol(expr_type) expr_type_sym := c.table.sym(expr_type)
if field_type_sym.kind == .interface_ { if field_type_sym.kind == .interface_ {
if c.type_implements(expr_type, field_info.typ, field.pos) { if c.type_implements(expr_type, field_info.typ, field.pos) {
if !expr_type.is_ptr() && !expr_type.is_pointer() if !expr_type.is_ptr() && !expr_type.is_pointer()
@ -800,7 +800,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
obj = c.fn_scope.find_var(obj.name) or { obj } obj = c.fn_scope.find_var(obj.name) or { obj }
} }
if obj.is_stack_obj && !c.inside_unsafe { if obj.is_stack_obj && !c.inside_unsafe {
sym := c.table.get_type_symbol(obj.typ.set_nr_muls(0)) sym := c.table.sym(obj.typ.set_nr_muls(0))
if !sym.is_heap() && !c.pref.translated { if !sym.is_heap() && !c.pref.translated {
suggestion := if sym.kind == .struct_ { suggestion := if sym.kind == .struct_ {
'declaring `$sym.name` as `[heap]`' 'declaring `$sym.name` as `[heap]`'
@ -826,7 +826,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
node.pos) node.pos)
} }
// Do not allow empty uninitialized interfaces // Do not allow empty uninitialized interfaces
sym := c.table.get_type_symbol(field.typ) sym := c.table.sym(field.typ)
if sym.kind == .interface_ { if sym.kind == .interface_ {
// TODO: should be an error instead, but first `ui` needs updating. // TODO: should be an error instead, but first `ui` needs updating.
c.note('interface field `${type_sym.name}.$field.name` must be initialized', c.note('interface field `${type_sym.name}.$field.name` must be initialized',
@ -834,7 +834,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
} }
// Do not allow empty uninitialized sum types // Do not allow empty uninitialized sum types
/* /*
sym := c.table.get_type_symbol(field.typ) sym := c.table.sym(field.typ)
if sym.kind == .sum_type { if sym.kind == .sum_type {
c.warn('sum type field `${type_sym.name}.$field.name` must be initialized', c.warn('sum type field `${type_sym.name}.$field.name` must be initialized',
node.pos) node.pos)
@ -865,8 +865,8 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
s := c.table.type_to_str(update_type) s := c.table.type_to_str(update_type)
c.error('expected struct, found `$s`', node.update_expr.position()) c.error('expected struct, found `$s`', node.update_expr.position())
} else if update_type != node.typ { } else if update_type != node.typ {
from_sym := c.table.get_type_symbol(update_type) from_sym := c.table.sym(update_type)
to_sym := c.table.get_type_symbol(node.typ) to_sym := c.table.sym(node.typ)
from_info := from_sym.info as ast.Struct from_info := from_sym.info as ast.Struct
to_info := to_sym.info as ast.Struct to_info := to_sym.info as ast.Struct
// TODO this check is too strict // TODO this check is too strict
@ -923,10 +923,10 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
&& left_type in [ast.int_literal_type, ast.float_literal_type] { && left_type in [ast.int_literal_type, ast.float_literal_type] {
node.left_type = right_type node.left_type = right_type
} }
mut right_sym := c.table.get_type_symbol(right_type) mut right_sym := c.table.sym(right_type)
right_final := c.table.get_final_type_symbol(right_type) right_final := c.table.final_sym(right_type)
mut left_sym := c.table.get_type_symbol(left_type) mut left_sym := c.table.sym(left_type)
left_final := c.table.get_final_type_symbol(left_type) left_final := c.table.final_sym(left_type)
left_pos := node.left.position() left_pos := node.left.position()
right_pos := node.right.position() right_pos := node.right.position()
left_right_pos := left_pos.extend(right_pos) left_right_pos := left_pos.extend(right_pos)
@ -1002,17 +1002,17 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
.plus, .minus, .mul, .div, .mod, .xor, .amp, .pipe { // binary operators that expect matching types .plus, .minus, .mul, .div, .mod, .xor, .amp, .pipe { // binary operators that expect matching types
if right_sym.info is ast.Alias && (right_sym.info as ast.Alias).language != .c if right_sym.info is ast.Alias && (right_sym.info as ast.Alias).language != .c
&& c.mod == c.table.type_to_str(right_type).split('.')[0] && c.mod == c.table.type_to_str(right_type).split('.')[0]
&& c.table.get_type_symbol((right_sym.info as ast.Alias).parent_type).is_primitive() { && c.table.sym((right_sym.info as ast.Alias).parent_type).is_primitive() {
right_sym = c.table.get_type_symbol((right_sym.info as ast.Alias).parent_type) right_sym = c.table.sym((right_sym.info as ast.Alias).parent_type)
} }
if left_sym.info is ast.Alias && (left_sym.info as ast.Alias).language != .c if left_sym.info is ast.Alias && (left_sym.info as ast.Alias).language != .c
&& c.mod == c.table.type_to_str(left_type).split('.')[0] && c.mod == c.table.type_to_str(left_type).split('.')[0]
&& c.table.get_type_symbol((left_sym.info as ast.Alias).parent_type).is_primitive() { && c.table.sym((left_sym.info as ast.Alias).parent_type).is_primitive() {
left_sym = c.table.get_type_symbol((left_sym.info as ast.Alias).parent_type) left_sym = c.table.sym((left_sym.info as ast.Alias).parent_type)
} }
// Check if the alias type is not a primitive then allow using operator overloading for aliased `arrays` and `maps` // Check if the alias type is not a primitive then allow using operator overloading for aliased `arrays` and `maps`
if left_sym.kind == .alias && left_sym.info is ast.Alias if left_sym.kind == .alias && left_sym.info is ast.Alias
&& !(c.table.get_type_symbol((left_sym.info as ast.Alias).parent_type).is_primitive()) { && !(c.table.sym((left_sym.info as ast.Alias).parent_type).is_primitive()) {
if left_sym.has_method(node.op.str()) { if left_sym.has_method(node.op.str()) {
if method := left_sym.find_method(node.op.str()) { if method := left_sym.find_method(node.op.str()) {
return_type = method.return_type return_type = method.return_type
@ -1030,7 +1030,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
} }
} }
} else if right_sym.kind == .alias && right_sym.info is ast.Alias } else if right_sym.kind == .alias && right_sym.info is ast.Alias
&& !(c.table.get_type_symbol((right_sym.info as ast.Alias).parent_type).is_primitive()) { && !(c.table.sym((right_sym.info as ast.Alias).parent_type).is_primitive()) {
if right_sym.has_method(node.op.str()) { if right_sym.has_method(node.op.str()) {
if method := right_sym.find_method(node.op.str()) { if method := right_sym.find_method(node.op.str()) {
return_type = method.return_type return_type = method.return_type
@ -1182,7 +1182,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
c.check_expr_opt_call(node.right, right_type) c.check_expr_opt_call(node.right, right_type)
node.auto_locked, _ = c.fail_if_immutable(node.left) node.auto_locked, _ = c.fail_if_immutable(node.left)
left_value_type := c.table.value_type(c.unwrap_generic(left_type)) left_value_type := c.table.value_type(c.unwrap_generic(left_type))
left_value_sym := c.table.get_type_symbol(c.unwrap_generic(left_value_type)) left_value_sym := c.table.sym(c.unwrap_generic(left_value_type))
if left_value_sym.kind == .interface_ { if left_value_sym.kind == .interface_ {
if right_final.kind != .array { if right_final.kind != .array {
// []Animal << Cat // []Animal << Cat
@ -1221,7 +1221,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
} }
.unsigned_right_shift { .unsigned_right_shift {
modified_left_type := if !left_type.is_int() { modified_left_type := if !left_type.is_int() {
c.error('invalid operation: shift on type `${c.table.get_type_symbol(left_type).name}`', c.error('invalid operation: shift on type `${c.table.sym(left_type).name}`',
left_pos) left_pos)
ast.void_type_idx ast.void_type_idx
} else if left_type.is_int_literal() { } else if left_type.is_int_literal() {
@ -1278,7 +1278,7 @@ pub fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
} }
} }
if typ != ast.Type(0) { if typ != ast.Type(0) {
typ_sym := c.table.get_type_symbol(typ) typ_sym := c.table.sym(typ)
op := node.op.str() op := node.op.str()
if typ_sym.kind == .placeholder { if typ_sym.kind == .placeholder {
c.error('$op: type `$typ_sym.name` does not exist', right_expr.position()) c.error('$op: type `$typ_sym.name` does not exist', right_expr.position())
@ -1437,7 +1437,7 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
} }
} }
ast.IndexExpr { ast.IndexExpr {
left_sym := c.table.get_type_symbol(expr.left_type) left_sym := c.table.sym(expr.left_type)
mut elem_type := ast.Type(0) mut elem_type := ast.Type(0)
mut kind := '' mut kind := ''
match left_sym.info { match left_sym.info {
@ -1470,7 +1470,7 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) (string, token.Position) {
} }
// retrieve ast.Field // retrieve ast.Field
c.ensure_type_exists(expr.expr_type, expr.pos) or { return '', pos } c.ensure_type_exists(expr.expr_type, expr.pos) or { return '', pos }
mut typ_sym := c.table.get_final_type_symbol(c.unwrap_generic(expr.expr_type)) mut typ_sym := c.table.final_sym(c.unwrap_generic(expr.expr_type))
match typ_sym.kind { match typ_sym.kind {
.struct_ { .struct_ {
mut has_field := true mut has_field := true
@ -1678,8 +1678,8 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
eprintln('> type_implements typ: $typ.debug() (`${c.table.type_to_str(typ)}`) | inter_typ: $interface_type.debug() (`${c.table.type_to_str(interface_type)}`)') eprintln('> type_implements typ: $typ.debug() (`${c.table.type_to_str(typ)}`) | inter_typ: $interface_type.debug() (`${c.table.type_to_str(interface_type)}`)')
} }
utyp := c.unwrap_generic(typ) utyp := c.unwrap_generic(typ)
typ_sym := c.table.get_type_symbol(utyp) typ_sym := c.table.sym(utyp)
mut inter_sym := c.table.get_type_symbol(interface_type) mut inter_sym := c.table.sym(interface_type)
// small hack for JS.Any type. Since `any` in regular V is getting deprecated we have our own JS.Any type for JS backend. // small hack for JS.Any type. Since `any` in regular V is getting deprecated we have our own JS.Any type for JS backend.
if typ_sym.name == 'JS.Any' { if typ_sym.name == 'JS.Any' {
@ -1689,7 +1689,7 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
mut generic_type := interface_type mut generic_type := interface_type
mut generic_info := inter_sym.info mut generic_info := inter_sym.info
if inter_sym.info.parent_type.has_flag(.generic) { if inter_sym.info.parent_type.has_flag(.generic) {
parent_sym := c.table.get_type_symbol(inter_sym.info.parent_type) parent_sym := c.table.sym(inter_sym.info.parent_type)
if parent_sym.info is ast.Interface { if parent_sym.info is ast.Interface {
generic_type = inter_sym.info.parent_type generic_type = inter_sym.info.parent_type
generic_info = parent_sym.info generic_info = parent_sym.info
@ -1967,7 +1967,7 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
node.pos) node.pos)
} }
field_name := node.field_name field_name := node.field_name
sym := c.table.get_type_symbol(typ) sym := c.table.sym(typ)
if (typ.has_flag(.variadic) || sym.kind == .array_fixed) && field_name == 'len' { if (typ.has_flag(.variadic) || sym.kind == .array_fixed) && field_name == 'len' {
node.typ = ast.int_type node.typ = ast.int_type
return ast.int_type return ast.int_type
@ -1988,7 +1988,7 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
&& sym.language == .v { && sym.language == .v {
// x.Foo.y => access the embedded struct // x.Foo.y => access the embedded struct
for embed in sym.info.embeds { for embed in sym.info.embeds {
embed_sym := c.table.get_type_symbol(embed) embed_sym := c.table.sym(embed)
if embed_sym.embed_name() == field_name { if embed_sym.embed_name() == field_name {
node.typ = embed node.typ = embed
return embed return embed
@ -2023,7 +2023,7 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
} }
} }
if typ.has_flag(.generic) && !has_field { if typ.has_flag(.generic) && !has_field {
gs := c.table.get_type_symbol(c.unwrap_generic(typ)) gs := c.table.sym(c.unwrap_generic(typ))
if f := c.table.find_field(gs, field_name) { if f := c.table.find_field(gs, field_name) {
has_field = true has_field = true
field = f field = f
@ -2044,10 +2044,10 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
} }
if has_field { if has_field {
if sym.mod != c.mod && !field.is_pub && sym.language != .c { if sym.mod != c.mod && !field.is_pub && sym.language != .c {
unwrapped_sym := c.table.get_type_symbol(c.unwrap_generic(typ)) unwrapped_sym := c.table.sym(c.unwrap_generic(typ))
c.error('field `${unwrapped_sym.name}.$field_name` is not public', node.pos) c.error('field `${unwrapped_sym.name}.$field_name` is not public', node.pos)
} }
field_sym := c.table.get_type_symbol(field.typ) field_sym := c.table.sym(field.typ)
if field_sym.kind in [.sum_type, .interface_] { if field_sym.kind in [.sum_type, .interface_] {
if !prevent_sum_type_unwrapping_once { if !prevent_sum_type_unwrapping_once {
if scope_field := node.scope.find_struct_field(node.expr.str(), typ, field_name) { if scope_field := node.scope.find_struct_field(node.expr.str(), typ, field_name) {
@ -2060,7 +2060,7 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
} }
if sym.kind !in [.struct_, .aggregate, .interface_, .sum_type] { if sym.kind !in [.struct_, .aggregate, .interface_, .sum_type] {
if sym.kind != .placeholder { if sym.kind != .placeholder {
unwrapped_sym := c.table.get_type_symbol(c.unwrap_generic(typ)) unwrapped_sym := c.table.sym(c.unwrap_generic(typ))
c.error('`$unwrapped_sym.name` has no property `$node.field_name`', node.pos) c.error('`$unwrapped_sym.name` has no property `$node.field_name`', node.pos)
} }
} else { } else {
@ -2175,14 +2175,14 @@ pub fn (mut c Checker) enum_decl(mut node ast.EnumDecl) {
} }
fn (mut c Checker) check_array_init_para_type(para string, expr ast.Expr, pos token.Position) { fn (mut c Checker) check_array_init_para_type(para string, expr ast.Expr, pos token.Position) {
sym := c.table.get_type_symbol(c.expr(expr)) sym := c.table.sym(c.expr(expr))
if sym.kind !in [.int, .int_literal] { if sym.kind !in [.int, .int_literal] {
c.error('array $para needs to be an int', pos) c.error('array $para needs to be an int', pos)
} }
} }
pub fn (mut c Checker) ensure_sumtype_array_has_default_value(node ast.ArrayInit) { pub fn (mut c Checker) ensure_sumtype_array_has_default_value(node ast.ArrayInit) {
sym := c.table.get_type_symbol(node.elem_type) sym := c.table.sym(node.elem_type)
if sym.kind == .sum_type && !node.has_default { if sym.kind == .sum_type && !node.has_default {
c.error('cannot initialize sum type array without default value', node.pos) c.error('cannot initialize sum type array without default value', node.pos)
} }
@ -2209,7 +2209,7 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
} }
if node.has_len { if node.has_len {
if node.has_len && !node.has_default { if node.has_len && !node.has_default {
elem_type_sym := c.table.get_type_symbol(node.elem_type) elem_type_sym := c.table.sym(node.elem_type)
if elem_type_sym.kind == .interface_ { if elem_type_sym.kind == .interface_ {
c.error('cannot instantiate an array of interfaces without also giving a default `init:` value', c.error('cannot instantiate an array of interfaces without also giving a default `init:` value',
node.len_expr.position()) node.len_expr.position())
@ -2233,7 +2233,7 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
if c.expected_type == ast.void_type && c.expected_or_type != ast.void_type { if c.expected_type == ast.void_type && c.expected_or_type != ast.void_type {
c.expected_type = c.expected_or_type c.expected_type = c.expected_or_type
} }
mut type_sym := c.table.get_type_symbol(c.expected_type) mut type_sym := c.table.sym(c.expected_type)
if type_sym.kind != .array || type_sym.array_info().elem_type == ast.void_type { if type_sym.kind != .array || type_sym.array_info().elem_type == ast.void_type {
c.error('array_init: no type specified (maybe: `[]Type{}` instead of `[]`)', c.error('array_init: no type specified (maybe: `[]Type{}` instead of `[]`)',
node.pos) node.pos)
@ -2255,13 +2255,13 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
mut expecting_interface_array := false mut expecting_interface_array := false
if c.expected_type != 0 { if c.expected_type != 0 {
expected_value_type = c.table.value_type(c.expected_type) expected_value_type = c.table.value_type(c.expected_type)
if c.table.get_type_symbol(expected_value_type).kind == .interface_ { if c.table.sym(expected_value_type).kind == .interface_ {
// Array of interfaces? (`[dog, cat]`) Save the interface type (`Animal`) // Array of interfaces? (`[dog, cat]`) Save the interface type (`Animal`)
expecting_interface_array = true expecting_interface_array = true
} }
} }
// expecting_interface_array := c.expected_type != 0 && // expecting_interface_array := c.expected_type != 0 &&
// c.table.get_type_symbol(c.table.value_type(c.expected_type)).kind == .interface_ // c.table.sym(c.table.value_type(c.expected_type)).kind == .interface_
// //
// if expecting_interface_array { // if expecting_interface_array {
// println('ex $c.expected_type') // println('ex $c.expected_type')
@ -2277,7 +2277,7 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
c.type_implements(typ, elem_type, expr.position()) c.type_implements(typ, elem_type, expr.position())
} }
if !typ.is_ptr() && !typ.is_pointer() && !c.inside_unsafe { if !typ.is_ptr() && !typ.is_pointer() && !c.inside_unsafe {
typ_sym := c.table.get_type_symbol(typ) typ_sym := c.table.sym(typ)
if typ_sym.kind != .interface_ { if typ_sym.kind != .interface_ {
c.mark_as_referenced(mut &expr, true) c.mark_as_referenced(mut &expr, true)
} }
@ -2469,7 +2469,7 @@ fn (mut c Checker) stmt(node ast.Stmt) {
if !c.pref.is_repl && (c.stmt_level == 1 || (c.stmt_level > 1 && !c.is_last_stmt)) { if !c.pref.is_repl && (c.stmt_level == 1 || (c.stmt_level > 1 && !c.is_last_stmt)) {
if node.expr is ast.InfixExpr { if node.expr is ast.InfixExpr {
if node.expr.op == .left_shift { if node.expr.op == .left_shift {
left_sym := c.table.get_final_type_symbol(node.expr.left_type) left_sym := c.table.final_sym(node.expr.left_type)
if left_sym.kind != .array { if left_sym.kind != .array {
c.error('unused expression', node.pos) c.error('unused expression', node.pos)
} }
@ -2544,7 +2544,7 @@ fn (mut c Checker) assert_stmt(node ast.AssertStmt) {
cur_exp_typ := c.expected_type cur_exp_typ := c.expected_type
assert_type := c.check_expr_opt_call(node.expr, c.expr(node.expr)) assert_type := c.check_expr_opt_call(node.expr, c.expr(node.expr))
if assert_type != ast.bool_type_idx { if assert_type != ast.bool_type_idx {
atype_name := c.table.get_type_symbol(assert_type).name atype_name := c.table.sym(assert_type).name
c.error('assert can be used only with `bool` expressions, but found `$atype_name` instead', c.error('assert can be used only with `bool` expressions, but found `$atype_name` instead',
node.pos) node.pos)
} }
@ -2593,7 +2593,7 @@ fn (mut c Checker) for_c_stmt(node ast.ForCStmt) {
fn (mut c Checker) comptime_for(node ast.ComptimeFor) { fn (mut c Checker) comptime_for(node ast.ComptimeFor) {
typ := c.unwrap_generic(node.typ) typ := c.unwrap_generic(node.typ)
sym := c.table.get_type_symbol(typ) sym := c.table.sym(typ)
if sym.kind == .placeholder || typ.has_flag(.generic) { if sym.kind == .placeholder || typ.has_flag(.generic) {
c.error('unknown type `$sym.name`', node.typ_pos) c.error('unknown type `$sym.name`', node.typ_pos)
} }
@ -2635,7 +2635,7 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
node.high_type = high_type node.high_type = high_type
node.scope.update_var_type(node.val_var, node.val_type) node.scope.update_var_type(node.val_var, node.val_type)
} else { } else {
sym := c.table.get_final_type_symbol(typ) sym := c.table.final_sym(typ)
if sym.kind == .struct_ { if sym.kind == .struct_ {
// iterators // iterators
next_fn := sym.find_method_with_generic_parent('next') or { next_fn := sym.find_method_with_generic_parent('next') or {
@ -2735,7 +2735,7 @@ fn (mut c Checker) for_stmt(mut node ast.ForStmt) {
true true
} }
left_type := c.expr(infix.left) left_type := c.expr(infix.left)
left_sym := c.table.get_type_symbol(left_type) left_sym := c.table.sym(left_type)
if is_variable { if is_variable {
if left_sym.kind in [.sum_type, .interface_] { if left_sym.kind in [.sum_type, .interface_] {
c.smartcast(infix.left, infix.left_type, infix.right.typ, mut c.smartcast(infix.left, infix.left_type, infix.right.typ, mut
@ -2759,7 +2759,7 @@ fn (mut c Checker) global_decl(mut node ast.GlobalDecl) {
if field.name in c.global_names { if field.name in c.global_names {
c.error('duplicate global `$field.name`', field.pos) c.error('duplicate global `$field.name`', field.pos)
} }
sym := c.table.get_type_symbol(field.typ) sym := c.table.sym(field.typ)
if sym.kind == .placeholder { if sym.kind == .placeholder {
c.error('unknown type `$sym.name`', field.typ_pos) c.error('unknown type `$sym.name`', field.typ_pos)
} }
@ -3138,7 +3138,7 @@ pub fn (mut c Checker) expr(node ast.Expr) ast.Type {
} }
ast.ArrayDecompose { ast.ArrayDecompose {
typ := c.expr(node.expr) typ := c.expr(node.expr)
type_sym := c.table.get_type_symbol(typ) type_sym := c.table.sym(typ)
if type_sym.kind != .array { if type_sym.kind != .array {
c.error('decomposition can only be used on arrays', node.expr.position()) c.error('decomposition can only be used on arrays', node.expr.position())
return ast.void_type return ast.void_type
@ -3154,8 +3154,8 @@ pub fn (mut c Checker) expr(node ast.Expr) ast.Type {
} }
ast.AsCast { ast.AsCast {
node.expr_type = c.expr(node.expr) node.expr_type = c.expr(node.expr)
expr_type_sym := c.table.get_type_symbol(node.expr_type) expr_type_sym := c.table.sym(node.expr_type)
type_sym := c.table.get_type_symbol(node.typ) type_sym := c.table.sym(node.typ)
if expr_type_sym.kind == .sum_type { if expr_type_sym.kind == .sum_type {
c.ensure_type_exists(node.typ, node.pos) or {} c.ensure_type_exists(node.typ, node.pos) or {}
if !c.table.sumtype_has_variant(node.expr_type, node.typ, true) { if !c.table.sumtype_has_variant(node.expr_type, node.typ, true) {
@ -3225,7 +3225,7 @@ pub fn (mut c Checker) expr(node ast.Expr) ast.Type {
ast.ComptimeSelector { ast.ComptimeSelector {
node.left_type = c.unwrap_generic(c.expr(node.left)) node.left_type = c.unwrap_generic(c.expr(node.left))
expr_type := c.unwrap_generic(c.expr(node.field_expr)) expr_type := c.unwrap_generic(c.expr(node.field_expr))
expr_sym := c.table.get_type_symbol(expr_type) expr_sym := c.table.sym(expr_type)
if expr_type != ast.string_type { if expr_type != ast.string_type {
c.error('expected `string` instead of `$expr_sym.name` (e.g. `field.name`)', c.error('expected `string` instead of `$expr_sym.name` (e.g. `field.name`)',
node.field_expr.position()) node.field_expr.position())
@ -3255,7 +3255,7 @@ pub fn (mut c Checker) expr(node ast.Expr) ast.Type {
c.error('dump expression can not be void', node.expr.position()) c.error('dump expression can not be void', node.expr.position())
return ast.void_type return ast.void_type
} }
tsym := c.table.get_type_symbol(node.expr_type) tsym := c.table.sym(node.expr_type)
c.table.dumps[int(node.expr_type)] = tsym.cname c.table.dumps[int(node.expr_type)] = tsym.cname
node.cname = tsym.cname node.cname = tsym.cname
return node.expr_type return node.expr_type
@ -3403,7 +3403,7 @@ pub fn (mut c Checker) expr(node ast.Expr) ast.Type {
ast.Likely { ast.Likely {
ltype := c.expr(node.expr) ltype := c.expr(node.expr)
if !c.check_types(ltype, ast.bool_type) { if !c.check_types(ltype, ast.bool_type) {
ltype_sym := c.table.get_type_symbol(ltype) ltype_sym := c.table.sym(ltype)
lname := if node.is_likely { '_likely_' } else { '_unlikely_' } lname := if node.is_likely { '_likely_' } else { '_unlikely_' }
c.error('`${lname}()` expects a boolean expression, instead it got `$ltype_sym.name`', c.error('`${lname}()` expects a boolean expression, instead it got `$ltype_sym.name`',
node.pos) node.pos)
@ -3439,10 +3439,10 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
mut from_type := node.expr_type mut from_type := node.expr_type
to_type := node.typ to_type := node.typ
// //
from_type_sym := c.table.get_type_symbol(from_type) from_type_sym := c.table.sym(from_type)
from_type_sym_final := c.table.get_final_type_symbol(from_type) from_type_sym_final := c.table.final_sym(from_type)
to_type_sym := c.table.get_type_symbol(to_type) // type to be used as cast to_type_sym := c.table.sym(to_type) // type to be used as cast
to_type_sym_final := c.table.get_final_type_symbol(to_type) to_type_sym_final := c.table.final_sym(to_type)
// //
if (to_type_sym.is_number() && from_type_sym.name == 'JS.Number') if (to_type_sym.is_number() && from_type_sym.name == 'JS.Number')
|| (to_type_sym.is_number() && from_type_sym.name == 'JS.BigInt') || (to_type_sym.is_number() && from_type_sym.name == 'JS.BigInt')
@ -3624,7 +3624,7 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
} }
} }
node.typname = c.table.get_type_symbol(to_type).name node.typname = c.table.sym(to_type).name
return to_type return to_type
} }
@ -3784,7 +3784,7 @@ pub fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
node.pos) node.pos)
} }
// if typ == ast.t_type { // if typ == ast.t_type {
// sym := c.table.get_type_symbol(c.cur_generic_type) // sym := c.table.sym(c.cur_generic_type)
// println('IDENT T unresolved $node.name typ=$sym.name') // println('IDENT T unresolved $node.name typ=$sym.name')
// Got a var with type T, return current generic type // Got a var with type T, return current generic type
// typ = c.cur_generic_type // typ = c.cur_generic_type
@ -3917,13 +3917,13 @@ pub fn (mut c Checker) concat_expr(mut node ast.ConcatExpr) ast.Type {
// smartcast takes the expression with the current type which should be smartcasted to the target type in the given scope // smartcast takes the expression with the current type which should be smartcasted to the target type in the given scope
fn (c Checker) smartcast(expr ast.Expr, cur_type ast.Type, to_type_ ast.Type, mut scope ast.Scope) { fn (c Checker) smartcast(expr ast.Expr, cur_type ast.Type, to_type_ ast.Type, mut scope ast.Scope) {
sym := c.table.get_type_symbol(cur_type) sym := c.table.sym(cur_type)
to_type := if sym.kind == .interface_ { to_type_.ref() } else { to_type_ } to_type := if sym.kind == .interface_ { to_type_.ref() } else { to_type_ }
match expr { match expr {
ast.SelectorExpr { ast.SelectorExpr {
mut is_mut := false mut is_mut := false
mut smartcasts := []ast.Type{} mut smartcasts := []ast.Type{}
expr_sym := c.table.get_type_symbol(expr.expr_type) expr_sym := c.table.sym(expr.expr_type)
mut orig_type := 0 mut orig_type := 0
if field := c.table.find_field(expr_sym, expr.field_name) { if field := c.table.find_field(expr_sym, expr.field_name) {
if field.is_mut { if field.is_mut {
@ -3993,7 +3993,7 @@ pub fn (mut c Checker) select_expr(mut node ast.SelectExpr) ast.Type {
ast.ExprStmt { ast.ExprStmt {
if branch.is_timeout { if branch.is_timeout {
if !branch.stmt.typ.is_int() { if !branch.stmt.typ.is_int() {
tsym := c.table.get_type_symbol(branch.stmt.typ) tsym := c.table.sym(branch.stmt.typ)
c.error('invalid type `$tsym.name` for timeout - expected integer number of nanoseconds aka `time.Duration`', c.error('invalid type `$tsym.name` for timeout - expected integer number of nanoseconds aka `time.Duration`',
branch.stmt.pos) branch.stmt.pos)
} }
@ -4145,7 +4145,7 @@ fn (c &Checker) has_return(stmts []ast.Stmt) ?bool {
pub fn (mut c Checker) postfix_expr(mut node ast.PostfixExpr) ast.Type { pub fn (mut c Checker) postfix_expr(mut node ast.PostfixExpr) ast.Type {
typ := c.unwrap_generic(c.expr(node.expr)) typ := c.unwrap_generic(c.expr(node.expr))
typ_sym := c.table.get_type_symbol(typ) typ_sym := c.table.sym(typ)
is_non_void_pointer := (typ.is_ptr() || typ.is_pointer()) && typ_sym.kind != .voidptr is_non_void_pointer := (typ.is_ptr() || typ.is_pointer()) && typ_sym.kind != .voidptr
if !c.inside_unsafe && is_non_void_pointer && !node.expr.is_auto_deref_var() { if !c.inside_unsafe && is_non_void_pointer && !node.expr.is_auto_deref_var() {
c.warn('pointer arithmetic is only allowed in `unsafe` blocks', node.pos) c.warn('pointer arithmetic is only allowed in `unsafe` blocks', node.pos)
@ -4167,7 +4167,7 @@ pub fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool)
if c.fn_scope != voidptr(0) { if c.fn_scope != voidptr(0) {
obj = c.fn_scope.find_var(node.obj.name) or { obj } obj = c.fn_scope.find_var(node.obj.name) or { obj }
} }
type_sym := c.table.get_type_symbol(obj.typ.set_nr_muls(0)) type_sym := c.table.sym(obj.typ.set_nr_muls(0))
if obj.is_stack_obj && !type_sym.is_heap() && !c.pref.translated { if obj.is_stack_obj && !type_sym.is_heap() && !c.pref.translated {
suggestion := if type_sym.kind == .struct_ { suggestion := if type_sym.kind == .struct_ {
'declaring `$type_sym.name` as `[heap]`' 'declaring `$type_sym.name` as `[heap]`'
@ -4258,7 +4258,7 @@ pub fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
else {} else {}
} }
if mut node.right is ast.IndexExpr { if mut node.right is ast.IndexExpr {
typ_sym := c.table.get_type_symbol(node.right.left_type) typ_sym := c.table.sym(node.right.left_type)
mut is_mut := false mut is_mut := false
if mut node.right.left is ast.Ident { if mut node.right.left is ast.Ident {
ident := node.right.left ident := node.right.left
@ -4310,7 +4310,7 @@ pub fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
// FIXME // FIXME
// there are currently other issues to investigate if right_type // there are currently other issues to investigate if right_type
// is unwraped directly as initialization, so do it here // is unwraped directly as initialization, so do it here
right_sym := c.table.get_final_type_symbol(c.unwrap_generic(right_type)) right_sym := c.table.final_sym(c.unwrap_generic(right_type))
if node.op == .minus && !right_sym.is_number() { if node.op == .minus && !right_sym.is_number() {
c.error('- operator can only be used with numeric types', node.pos) c.error('- operator can only be used with numeric types', node.pos)
} }
@ -4325,7 +4325,7 @@ pub fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
} }
fn (mut c Checker) check_index(typ_sym &ast.TypeSymbol, index ast.Expr, index_type ast.Type, pos token.Position, range_index bool) { fn (mut c Checker) check_index(typ_sym &ast.TypeSymbol, index ast.Expr, index_type ast.Type, pos token.Position, range_index bool) {
index_type_sym := c.table.get_type_symbol(index_type) index_type_sym := c.table.sym(index_type)
// println('index expr left=$typ_sym.name $node.pos.line_nr') // println('index expr left=$typ_sym.name $node.pos.line_nr')
// if typ_sym.kind == .array && (!(ast.type_idx(index_type) in ast.number_type_idxs) && // if typ_sym.kind == .array && (!(ast.type_idx(index_type) in ast.number_type_idxs) &&
// index_type_sym.kind != .enum_) { // index_type_sym.kind != .enum_) {
@ -4362,7 +4362,7 @@ fn (mut c Checker) check_index(typ_sym &ast.TypeSymbol, index ast.Expr, index_ty
pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type { pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
mut typ := c.expr(node.left) mut typ := c.expr(node.left)
mut typ_sym := c.table.get_final_type_symbol(typ) mut typ_sym := c.table.final_sym(typ)
node.left_type = typ node.left_type = typ
for { for {
match typ_sym.kind { match typ_sym.kind {
@ -4382,7 +4382,7 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
gname := typ_sym.name gname := typ_sym.name
typ = c.unwrap_generic(typ) typ = c.unwrap_generic(typ)
node.left_type = typ node.left_type = typ
typ_sym = c.table.get_final_type_symbol(typ) typ_sym = c.table.final_sym(typ)
if typ.is_ptr() { if typ.is_ptr() {
continue continue
} else { } else {
@ -4445,7 +4445,7 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
err := c.expected_msg(index_type, info.key_type) err := c.expected_msg(index_type, info.key_type)
c.error('invalid key: $err', node.pos) c.error('invalid key: $err', node.pos)
} }
value_sym := c.table.get_type_symbol(info.value_type) value_sym := c.table.sym(info.value_type)
if !node.is_setter && value_sym.kind == .sum_type && node.or_expr.kind == .absent if !node.is_setter && value_sym.kind == .sum_type && node.or_expr.kind == .absent
&& !c.inside_unsafe && !c.inside_if_guard { && !c.inside_unsafe && !c.inside_if_guard {
c.warn('`or {}` block required when indexing a map with sum type value', c.warn('`or {}` block required when indexing a map with sum type value',
@ -4496,11 +4496,11 @@ pub fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type {
c.error('not an enum', node.pos) c.error('not an enum', node.pos)
return ast.void_type return ast.void_type
} }
mut typ_sym := c.table.get_type_symbol(typ) mut typ_sym := c.table.sym(typ)
if typ_sym.kind == .array && node.enum_name.len == 0 { if typ_sym.kind == .array && node.enum_name.len == 0 {
array_info := typ_sym.info as ast.Array array_info := typ_sym.info as ast.Array
typ = array_info.elem_type typ = array_info.elem_type
typ_sym = c.table.get_type_symbol(typ) typ_sym = c.table.sym(typ)
} }
if typ_sym.kind != .enum_ && !c.pref.translated { if typ_sym.kind != .enum_ && !c.pref.translated {
// TODO in C int fields can be compared to enums, need to handle that in C2V // TODO in C int fields can be compared to enums, need to handle that in C2V
@ -4526,7 +4526,7 @@ pub fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type {
pub fn (mut c Checker) chan_init(mut node ast.ChanInit) ast.Type { pub fn (mut c Checker) chan_init(mut node ast.ChanInit) ast.Type {
if node.typ != 0 { if node.typ != 0 {
info := c.table.get_type_symbol(node.typ).chan_info() info := c.table.sym(node.typ).chan_info()
node.elem_type = info.elem_type node.elem_type = info.elem_type
if node.has_cap { if node.has_cap {
c.check_array_init_para_type('cap', node.cap_expr, node.pos) c.check_array_init_para_type('cap', node.cap_expr, node.pos)
@ -4539,7 +4539,7 @@ pub fn (mut c Checker) chan_init(mut node ast.ChanInit) ast.Type {
} }
pub fn (mut c Checker) offset_of(node ast.OffsetOf) ast.Type { pub fn (mut c Checker) offset_of(node ast.OffsetOf) ast.Type {
sym := c.table.get_final_type_symbol(node.struct_type) sym := c.table.final_sym(node.struct_type)
if sym.kind != .struct_ { if sym.kind != .struct_ {
c.error('first argument of __offsetof must be struct', node.pos) c.error('first argument of __offsetof must be struct', node.pos)
return ast.u32_type return ast.u32_type
@ -4576,7 +4576,7 @@ pub fn (mut c Checker) check_dup_keys(node &ast.MapInit, i int) {
pub fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type { pub fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
// `map = {}` // `map = {}`
if node.keys.len == 0 && node.vals.len == 0 && node.typ == 0 { if node.keys.len == 0 && node.vals.len == 0 && node.typ == 0 {
sym := c.table.get_type_symbol(c.expected_type) sym := c.table.sym(c.expected_type)
if sym.kind == .map { if sym.kind == .map {
info := sym.map_info() info := sym.map_info()
node.typ = c.expected_type node.typ = c.expected_type
@ -4596,7 +4596,7 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
} }
// `x := map[string]string` - set in parser // `x := map[string]string` - set in parser
if node.typ != 0 { if node.typ != 0 {
info := c.table.get_type_symbol(node.typ).map_info() info := c.table.sym(node.typ).map_info()
c.ensure_type_exists(info.key_type, node.pos) or {} c.ensure_type_exists(info.key_type, node.pos) or {}
c.ensure_type_exists(info.value_type, node.pos) or {} c.ensure_type_exists(info.value_type, node.pos) or {}
node.key_type = info.key_type node.key_type = info.key_type
@ -4607,9 +4607,9 @@ pub fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
mut key0_type := ast.void_type mut key0_type := ast.void_type
mut val0_type := ast.void_type mut val0_type := ast.void_type
use_expected_type := c.expected_type != ast.void_type && !c.inside_const use_expected_type := c.expected_type != ast.void_type && !c.inside_const
&& c.table.get_type_symbol(c.expected_type).kind == .map && c.table.sym(c.expected_type).kind == .map
if use_expected_type { if use_expected_type {
sym := c.table.get_type_symbol(c.expected_type) sym := c.table.sym(c.expected_type)
info := sym.map_info() info := sym.map_info()
key0_type = c.unwrap_generic(info.key_type) key0_type = c.unwrap_generic(info.key_type)
val0_type = c.unwrap_generic(info.value_type) val0_type = c.unwrap_generic(info.value_type)
@ -4807,7 +4807,7 @@ fn (mut c Checker) fetch_field_name(field ast.StructField) string {
break break
} }
} }
sym := c.table.get_type_symbol(field.typ) sym := c.table.sym(field.typ)
if sym.kind == .struct_ && sym.name != 'time.Time' { if sym.kind == .struct_ && sym.name != 'time.Time' {
name = '${name}_id' name = '${name}_id'
} }
@ -4846,7 +4846,7 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Position) ? {
c.error('unknown type', pos) c.error('unknown type', pos)
return return
} }
sym := c.table.get_type_symbol(typ) sym := c.table.sym(typ)
match sym.kind { match sym.kind {
.placeholder { .placeholder {
if sym.language == .v && !sym.name.starts_with('C.') { if sym.language == .v && !sym.name.starts_with('C.') {

View File

@ -93,7 +93,7 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) ast.Type {
} else { } else {
c.error('todo: not a string literal', node.method_pos) c.error('todo: not a string literal', node.method_pos)
} }
left_sym := c.table.get_type_symbol(c.unwrap_generic(node.left_type)) left_sym := c.table.sym(c.unwrap_generic(node.left_type))
f := left_sym.find_method(method_name) or { f := left_sym.find_method(method_name) or {
c.error('could not find method `$method_name`', node.method_pos) c.error('could not find method `$method_name`', node.method_pos)
return ast.void_type return ast.void_type
@ -313,7 +313,7 @@ fn (mut c Checker) verify_vweb_params_for_method(node ast.Fn) (bool, int, int) {
} }
if node.params.len > 1 { if node.params.len > 1 {
for param in node.params[1..] { for param in node.params[1..] {
param_sym := c.table.get_final_type_symbol(param.typ) param_sym := c.table.final_sym(param.typ)
if !(param_sym.is_string() || param_sym.is_number() || param_sym.is_float() if !(param_sym.is_string() || param_sym.is_number() || param_sym.is_float()
|| param_sym.kind == .bool) { || param_sym.kind == .bool) {
c.error('invalid type `$param_sym.name` for parameter `$param.name` in vweb app method `$node.name`', c.error('invalid type `$param_sym.name` for parameter `$param.name` in vweb app method `$node.name`',
@ -338,7 +338,7 @@ fn (mut c Checker) verify_all_vweb_routes() {
typ_vweb_result := c.table.find_type_idx('vweb.Result') typ_vweb_result := c.table.find_type_idx('vweb.Result')
old_file := c.file old_file := c.file
for vgt in c.vweb_gen_types { for vgt in c.vweb_gen_types {
sym_app := c.table.get_type_symbol(vgt) sym_app := c.table.sym(vgt)
for m in sym_app.methods { for m in sym_app.methods {
if m.return_type == typ_vweb_result { if m.return_type == typ_vweb_result {
is_ok, nroute_attributes, nargs := c.verify_vweb_params_for_method(m) is_ok, nroute_attributes, nargs := c.verify_vweb_params_for_method(m)
@ -440,7 +440,7 @@ fn (mut c Checker) comptime_if_branch(cond ast.Expr, pos token.Position) bool {
.key_is, .not_is { .key_is, .not_is {
if cond.left is ast.TypeNode && cond.right is ast.TypeNode { if cond.left is ast.TypeNode && cond.right is ast.TypeNode {
// `$if Foo is Interface {` // `$if Foo is Interface {`
sym := c.table.get_type_symbol(cond.right.typ) sym := c.table.sym(cond.right.typ)
if sym.kind != .interface_ { if sym.kind != .interface_ {
c.expr(cond.left) c.expr(cond.left)
// c.error('`$sym.name` is not an interface', cond.right.position()) // c.error('`$sym.name` is not an interface', cond.right.position())
@ -577,7 +577,7 @@ fn (mut c Checker) check_map_and_filter(is_map bool, elem_typ ast.Type, node ast
// Finish early so that it doesn't fail later // Finish early so that it doesn't fail later
return return
} }
elem_sym := c.table.get_type_symbol(elem_typ) elem_sym := c.table.sym(elem_typ)
arg_expr := node.args[0].expr arg_expr := node.args[0].expr
match arg_expr { match arg_expr {
ast.AnonFn { ast.AnonFn {
@ -733,13 +733,13 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
'`.sort()` requires a `<` or `>` comparison as the first and only argument' + '`.sort()` requires a `<` or `>` comparison as the first and only argument' +
'\ne.g. `users.sort(a.id < b.id)`', node.pos) '\ne.g. `users.sort(a.id < b.id)`', node.pos)
} }
} else if !(c.table.get_type_symbol(elem_typ).has_method('<') } else if !(c.table.sym(elem_typ).has_method('<')
|| c.table.unalias_num_type(elem_typ) in [ast.int_type, ast.int_type.ref(), ast.string_type, ast.string_type.ref(), ast.i8_type, ast.i16_type, ast.i64_type, ast.byte_type, ast.rune_type, ast.u16_type, ast.u32_type, ast.u64_type, ast.f32_type, ast.f64_type, ast.char_type, ast.bool_type, ast.float_literal_type, ast.int_literal_type]) { || c.table.unalias_num_type(elem_typ) in [ast.int_type, ast.int_type.ref(), ast.string_type, ast.string_type.ref(), ast.i8_type, ast.i16_type, ast.i64_type, ast.byte_type, ast.rune_type, ast.u16_type, ast.u32_type, ast.u64_type, ast.f32_type, ast.f64_type, ast.char_type, ast.bool_type, ast.float_literal_type, ast.int_literal_type]) {
c.error('custom sorting condition must be supplied for type `${c.table.type_to_str(elem_typ)}`', c.error('custom sorting condition must be supplied for type `${c.table.type_to_str(elem_typ)}`',
node.pos) node.pos)
} }
} else if method_name == 'wait' { } else if method_name == 'wait' {
elem_sym := c.table.get_type_symbol(elem_typ) elem_sym := c.table.sym(elem_typ)
if elem_sym.kind == .thread { if elem_sym.kind == .thread {
if node.args.len != 0 { if node.args.len != 0 {
c.error('`.wait()` does not have any arguments', node.args[0].pos) c.error('`.wait()` does not have any arguments', node.args[0].pos)
@ -763,7 +763,7 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
if method_name == 'map' { if method_name == 'map' {
// check fn // check fn
c.check_map_and_filter(true, elem_typ, node) c.check_map_and_filter(true, elem_typ, node)
arg_sym := c.table.get_type_symbol(arg_type) arg_sym := c.table.sym(arg_type)
ret_type := match arg_sym.info { ret_type := match arg_sym.info {
ast.FnType { arg_sym.info.func.return_type } ast.FnType { arg_sym.info.func.return_type }
else { arg_type } else { arg_type }

View File

@ -73,7 +73,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
node.pos) node.pos)
} }
if node.generic_names.len > 0 { if node.generic_names.len > 0 {
gs := c.table.get_type_symbol(node.return_type) gs := c.table.sym(node.return_type)
if gs.info is ast.Struct { if gs.info is ast.Struct {
if gs.info.is_generic && !node.return_type.has_flag(.generic) { if gs.info.is_generic && !node.return_type.has_flag(.generic) {
c.error('return generic struct in fn declaration must specify the generic type names, e.g. Foo<T>', c.error('return generic struct in fn declaration must specify the generic type names, e.g. Foo<T>',
@ -81,10 +81,10 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
} }
} }
} }
return_sym := c.table.get_type_symbol(node.return_type) return_sym := c.table.sym(node.return_type)
if return_sym.info is ast.MultiReturn { if return_sym.info is ast.MultiReturn {
for multi_type in return_sym.info.types { for multi_type in return_sym.info.types {
multi_sym := c.table.get_type_symbol(multi_type) multi_sym := c.table.sym(multi_type)
if multi_type == ast.error_type { if multi_type == ast.error_type {
c.error('type `IError` cannot be used in multi-return, return an option instead', c.error('type `IError` cannot be used in multi-return, return an option instead',
node.return_type_pos) node.return_type_pos)
@ -106,7 +106,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
} }
} }
if node.is_method { if node.is_method {
mut sym := c.table.get_type_symbol(node.receiver.typ) mut sym := c.table.sym(node.receiver.typ)
if sym.kind == .array && !c.is_builtin_mod && node.name == 'map' { if sym.kind == .array && !c.is_builtin_mod && node.name == 'map' {
// TODO `node.map in array_builtin_methods` // TODO `node.map in array_builtin_methods`
c.error('method overrides built-in array method', node.pos) c.error('method overrides built-in array method', node.pos)
@ -134,7 +134,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
} }
if mut sym.info is ast.Struct { if mut sym.info is ast.Struct {
if field := c.table.find_field(sym, node.name) { if field := c.table.find_field(sym, node.name) {
field_sym := c.table.get_type_symbol(field.typ) field_sym := c.table.sym(field.typ)
if field_sym.kind == .function { if field_sym.kind == .function {
c.error('type `$sym.name` has both field and method named `$node.name`', c.error('type `$sym.name` has both field and method named `$node.name`',
node.pos) node.pos)
@ -171,7 +171,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
param.pos) param.pos)
} }
if !param.typ.is_ptr() { // value parameter, i.e. on stack - check for `[heap]` if !param.typ.is_ptr() { // value parameter, i.e. on stack - check for `[heap]`
arg_typ_sym := c.table.get_type_symbol(param.typ) arg_typ_sym := c.table.sym(param.typ)
if arg_typ_sym.kind == .struct_ { if arg_typ_sym.kind == .struct_ {
info := arg_typ_sym.info as ast.Struct info := arg_typ_sym.info as ast.Struct
if info.is_heap { // set auto_heap to promote value parameter if info.is_heap { // set auto_heap to promote value parameter
@ -229,8 +229,8 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
if node.params.len != 2 { if node.params.len != 2 {
c.error('operator methods should have exactly 1 argument', node.pos) c.error('operator methods should have exactly 1 argument', node.pos)
} else { } else {
receiver_sym := c.table.get_type_symbol(node.receiver.typ) receiver_sym := c.table.sym(node.receiver.typ)
param_sym := c.table.get_type_symbol(node.params[1].typ) param_sym := c.table.sym(node.params[1].typ)
if param_sym.kind == .string && receiver_sym.kind == .string { if param_sym.kind == .string && receiver_sym.kind == .string {
// bypass check for strings // bypass check for strings
// TODO there must be a better way to handle that // TODO there must be a better way to handle that
@ -239,7 +239,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
c.error('operator methods are only allowed for struct and type alias', c.error('operator methods are only allowed for struct and type alias',
node.pos) node.pos)
} else { } else {
parent_sym := c.table.get_final_type_symbol(node.receiver.typ) parent_sym := c.table.final_sym(node.receiver.typ)
if node.rec_mut { if node.rec_mut {
c.error('receiver cannot be `mut` for operator overloading', node.receiver_pos) c.error('receiver cannot be `mut` for operator overloading', node.receiver_pos)
} else if node.params[1].is_mut { } else if node.params[1].is_mut {
@ -285,7 +285,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
// Add return if `fn(...) ? {...}` have no return at end // Add return if `fn(...) ? {...}` have no return at end
if node.return_type != ast.void_type && node.return_type.has_flag(.optional) if node.return_type != ast.void_type && node.return_type.has_flag(.optional)
&& (node.stmts.len == 0 || node.stmts[node.stmts.len - 1] !is ast.Return) { && (node.stmts.len == 0 || node.stmts[node.stmts.len - 1] !is ast.Return) {
sym := c.table.get_type_symbol(node.return_type) sym := c.table.sym(node.return_type)
if sym.kind == .void { if sym.kind == .void {
node.stmts << ast.Return{ node.stmts << ast.Return{
pos: node.pos pos: node.pos
@ -375,7 +375,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
} }
typ := c.expr(node.args[0].expr) typ := c.expr(node.args[0].expr)
tsym := c.table.get_type_symbol(typ) tsym := c.table.sym(typ)
if !tsym.name.starts_with('Promise<') { if !tsym.name.starts_with('Promise<') {
c.error('JS.await: first argument must be a promise, got `$tsym.name`', node.pos) c.error('JS.await: first argument must be a promise, got `$tsym.name`', node.pos)
@ -405,7 +405,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
} }
expr := node.args[0].expr expr := node.args[0].expr
if expr is ast.TypeNode { if expr is ast.TypeNode {
sym := c.table.get_type_symbol(expr.typ) sym := c.table.sym(expr.typ)
if !c.table.known_type(sym.name) { if !c.table.known_type(sym.name) {
c.error('json.decode: unknown type `$sym.name`', node.pos) c.error('json.decode: unknown type `$sym.name`', node.pos)
} }
@ -435,7 +435,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
node.name = '' node.name = ''
c.expr(node.left) c.expr(node.left)
if node.left.typ != ast.Type(0) { if node.left.typ != ast.Type(0) {
anon_fn_sym := c.table.get_type_symbol(node.left.typ) anon_fn_sym := c.table.sym(node.left.typ)
func = (anon_fn_sym.info as ast.FnType).func func = (anon_fn_sym.info as ast.FnType).func
found = true found = true
} }
@ -453,10 +453,10 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
if !found && node.left is ast.IndexExpr { if !found && node.left is ast.IndexExpr {
c.expr(node.left) c.expr(node.left)
expr := node.left as ast.IndexExpr expr := node.left as ast.IndexExpr
sym := c.table.get_type_symbol(expr.left_type) sym := c.table.sym(expr.left_type)
if sym.kind == .array { if sym.kind == .array {
info := sym.info as ast.Array info := sym.info as ast.Array
elem_typ := c.table.get_type_symbol(info.elem_type) elem_typ := c.table.sym(info.elem_type)
if elem_typ.info is ast.FnType { if elem_typ.info is ast.FnType {
return elem_typ.info.func.return_type return elem_typ.info.func.return_type
} else { } else {
@ -465,7 +465,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
} }
} else if sym.kind == .map { } else if sym.kind == .map {
info := sym.info as ast.Map info := sym.info as ast.Map
value_typ := c.table.get_type_symbol(info.value_type) value_typ := c.table.sym(info.value_type)
if value_typ.info is ast.FnType { if value_typ.info is ast.FnType {
return value_typ.info.func.return_type return value_typ.info.func.return_type
} else { } else {
@ -473,7 +473,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
} }
} else if sym.kind == .array_fixed { } else if sym.kind == .array_fixed {
info := sym.info as ast.ArrayFixed info := sym.info as ast.ArrayFixed
elem_typ := c.table.get_type_symbol(info.elem_type) elem_typ := c.table.sym(info.elem_type)
if elem_typ.info is ast.FnType { if elem_typ.info is ast.FnType {
return elem_typ.info.func.return_type return elem_typ.info.func.return_type
} else { } else {
@ -534,14 +534,14 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
} }
if typ != 0 { if typ != 0 {
generic_vts := c.table.get_final_type_symbol(typ) generic_vts := c.table.final_sym(typ)
if generic_vts.kind == .function { if generic_vts.kind == .function {
info := generic_vts.info as ast.FnType info := generic_vts.info as ast.FnType
func = info.func func = info.func
found = true found = true
found_in_args = true found_in_args = true
} else { } else {
vts := c.table.get_type_symbol(c.unwrap_generic(typ)) vts := c.table.sym(c.unwrap_generic(typ))
if vts.kind == .function { if vts.kind == .function {
info := vts.info as ast.FnType info := vts.info as ast.FnType
func = info.func func = info.func
@ -554,7 +554,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
// global fn? // global fn?
if !found { if !found {
if obj := c.file.global_scope.find(fn_name) { if obj := c.file.global_scope.find(fn_name) {
sym := c.table.get_type_symbol(obj.typ) sym := c.table.sym(obj.typ)
if sym.kind == .function { if sym.kind == .function {
found = true found = true
func = (sym.info as ast.FnType).func func = (sym.info as ast.FnType).func
@ -631,7 +631,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
// `println(T_str(*(T**)array_get(a, 0)));` // `println(T_str(*(T**)array_get(a, 0)));`
prexpr := node.args[0].expr prexpr := node.args[0].expr
prtyp := node.args[0].typ prtyp := node.args[0].typ
prtyp_sym := c.table.get_type_symbol(prtyp) prtyp_sym := c.table.sym(prtyp)
prtyp_is_ptr := prtyp.is_ptr() prtyp_is_ptr := prtyp.is_ptr()
prhas_str, prexpects_ptr, prnr_args := prtyp_sym.str_method_info() prhas_str, prexpects_ptr, prnr_args := prtyp_sym.str_method_info()
eprintln('>>> println hack typ: ${prtyp} | sym.name: ${prtyp_sym.name} | is_ptr: $prtyp_is_ptr | has_str: $prhas_str | expects_ptr: $prexpects_ptr | nr_args: $prnr_args | expr: ${prexpr.str()} ') eprintln('>>> println hack typ: ${prtyp} | sym.name: ${prtyp_sym.name} | is_ptr: $prtyp_is_ptr | has_str: $prhas_str | expects_ptr: $prexpects_ptr | nr_args: $prnr_args | expr: ${prexpr.str()} ')
@ -665,7 +665,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
} }
c.expected_type = param.typ c.expected_type = param.typ
e_sym := c.table.get_type_symbol(c.expected_type) e_sym := c.table.sym(c.expected_type)
if call_arg.expr is ast.MapInit && e_sym.kind == .struct_ { if call_arg.expr is ast.MapInit && e_sym.kind == .struct_ {
c.error('cannot initialize a struct with a map', call_arg.pos) c.error('cannot initialize a struct with a map', call_arg.pos)
continue continue
@ -676,8 +676,8 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
typ := c.check_expr_opt_call(call_arg.expr, c.expr(call_arg.expr)) typ := c.check_expr_opt_call(call_arg.expr, c.expr(call_arg.expr))
node.args[i].typ = typ node.args[i].typ = typ
typ_sym := c.table.get_type_symbol(typ) typ_sym := c.table.sym(typ)
param_typ_sym := c.table.get_type_symbol(param.typ) param_typ_sym := c.table.sym(param.typ)
if func.is_variadic && typ.has_flag(.variadic) && node.args.len - 1 > i { if func.is_variadic && typ.has_flag(.variadic) && node.args.len - 1 > i {
c.error('when forwarding a variadic variable, it must be the final argument', c.error('when forwarding a variadic variable, it must be the final argument',
call_arg.pos) call_arg.pos)
@ -718,7 +718,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
mut final_param_typ := param.typ mut final_param_typ := param.typ
if func.is_variadic && param_typ_sym.info is ast.Array { if func.is_variadic && param_typ_sym.info is ast.Array {
final_param_typ = param_typ_sym.array_info().elem_type final_param_typ = param_typ_sym.array_info().elem_type
final_param_sym = c.table.get_type_symbol(final_param_typ) final_param_sym = c.table.sym(final_param_typ)
} }
// NB: Casting to voidptr is used as an escape mechanism, so: // NB: Casting to voidptr is used as an escape mechanism, so:
// 1. allow passing *explicit* voidptr (native or through cast) to functions // 1. allow passing *explicit* voidptr (native or through cast) to functions
@ -793,7 +793,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
if func.language != .c && !c.inside_unsafe && typ.nr_muls() != param.typ.nr_muls() if func.language != .c && !c.inside_unsafe && typ.nr_muls() != param.typ.nr_muls()
&& !(call_arg.is_mut && param.is_mut) && !(!call_arg.is_mut && !param.is_mut) && !(call_arg.is_mut && param.is_mut) && !(!call_arg.is_mut && !param.is_mut)
&& param.typ !in [ast.byteptr_type, ast.charptr_type, ast.voidptr_type] { && param.typ !in [ast.byteptr_type, ast.charptr_type, ast.voidptr_type] {
// sym := c.table.get_type_symbol(typ) // sym := c.table.sym(typ)
c.warn('automatic referencing/dereferencing is deprecated and will be removed soon (got: $typ.nr_muls() references, expected: $param.typ.nr_muls() references)', c.warn('automatic referencing/dereferencing is deprecated and will be removed soon (got: $typ.nr_muls() references, expected: $param.typ.nr_muls() references)',
call_arg.pos) call_arg.pos)
} }
@ -818,11 +818,11 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
concrete_types) concrete_types)
{ {
utyp := c.unwrap_generic(typ) utyp := c.unwrap_generic(typ)
unwrap_sym := c.table.get_type_symbol(unwrap_typ) unwrap_sym := c.table.sym(unwrap_typ)
if unwrap_sym.kind == .interface_ { if unwrap_sym.kind == .interface_ {
if c.type_implements(utyp, unwrap_typ, call_arg.expr.position()) { if c.type_implements(utyp, unwrap_typ, call_arg.expr.position()) {
if !utyp.is_ptr() && !utyp.is_pointer() && !c.inside_unsafe if !utyp.is_ptr() && !utyp.is_pointer() && !c.inside_unsafe
&& c.table.get_type_symbol(utyp).kind != .interface_ { && c.table.sym(utyp).kind != .interface_ {
c.mark_as_referenced(mut &call_arg.expr, true) c.mark_as_referenced(mut &call_arg.expr, true)
} }
} }
@ -871,7 +871,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
mut is_generic := left_type.has_flag(.generic) mut is_generic := left_type.has_flag(.generic)
// x is Bar<T>, x.foo() -> x.foo<T>() // x is Bar<T>, x.foo() -> x.foo<T>()
if is_generic && node.concrete_types.len == 0 { if is_generic && node.concrete_types.len == 0 {
rec_sym := c.table.get_type_symbol(left_type) rec_sym := c.table.sym(left_type)
if rec_sym.info is ast.Struct { if rec_sym.info is ast.Struct {
node.concrete_types = rec_sym.info.generic_types node.concrete_types = rec_sym.info.generic_types
} }
@ -886,8 +886,8 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
c.table.unwrap_generic_type(left_type, c.table.cur_fn.generic_names, c.table.cur_concrete_types) c.table.unwrap_generic_type(left_type, c.table.cur_fn.generic_names, c.table.cur_concrete_types)
} }
unwrapped_left_type := c.unwrap_generic(left_type) unwrapped_left_type := c.unwrap_generic(left_type)
left_sym := c.table.get_type_symbol(unwrapped_left_type) left_sym := c.table.sym(unwrapped_left_type)
final_left_sym := c.table.get_final_type_symbol(unwrapped_left_type) final_left_sym := c.table.final_sym(unwrapped_left_type)
method_name := node.name method_name := node.name
mut unknown_method_msg := if field := c.table.find_field(left_sym, method_name) { mut unknown_method_msg := if field := c.table.find_field(left_sym, method_name) {
@ -962,7 +962,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
info := left_sym.info as ast.Array info := left_sym.info as ast.Array
arg_expr := if method_name == 'insert' { node.args[1].expr } else { node.args[0].expr } arg_expr := if method_name == 'insert' { node.args[1].expr } else { node.args[0].expr }
arg_type := c.expr(arg_expr) arg_type := c.expr(arg_expr)
arg_sym := c.table.get_type_symbol(arg_type) arg_sym := c.table.sym(arg_type)
if !c.check_types(arg_type, info.elem_type) && !c.check_types(left_type, arg_type) { if !c.check_types(arg_type, info.elem_type) && !c.check_types(left_type, arg_type) {
c.error('cannot $method_name `$arg_sym.name` to `$left_sym.name`', arg_expr.position()) c.error('cannot $method_name `$arg_sym.name` to `$left_sym.name`', arg_expr.position())
} }
@ -1010,7 +1010,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
parent_type = left_sym.info.parent_type parent_type = left_sym.info.parent_type
} }
if parent_type != 0 { if parent_type != 0 {
type_sym := c.table.get_type_symbol(parent_type) type_sym := c.table.sym(parent_type)
if m := c.table.find_method(type_sym, method_name) { if m := c.table.find_method(type_sym, method_name) {
method = m method = m
has_method = true has_method = true
@ -1101,13 +1101,13 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
param_is_mut = false param_is_mut = false
no_type_promotion = false no_type_promotion = false
} }
exp_arg_sym := c.table.get_type_symbol(exp_arg_typ) exp_arg_sym := c.table.sym(exp_arg_typ)
c.expected_type = exp_arg_typ c.expected_type = exp_arg_typ
got_arg_typ := c.check_expr_opt_call(arg.expr, c.expr(arg.expr)) got_arg_typ := c.check_expr_opt_call(arg.expr, c.expr(arg.expr))
node.args[i].typ = got_arg_typ node.args[i].typ = got_arg_typ
if no_type_promotion { if no_type_promotion {
if got_arg_typ != exp_arg_typ { if got_arg_typ != exp_arg_typ {
c.error('cannot use `${c.table.get_type_symbol(got_arg_typ).name}` as argument for `$method.name` (`$exp_arg_sym.name` expected)', c.error('cannot use `${c.table.sym(got_arg_typ).name}` as argument for `$method.name` (`$exp_arg_sym.name` expected)',
arg.pos) arg.pos)
} }
} }
@ -1119,13 +1119,13 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
mut final_arg_typ := exp_arg_typ mut final_arg_typ := exp_arg_typ
if method.is_variadic && exp_arg_sym.info is ast.Array { if method.is_variadic && exp_arg_sym.info is ast.Array {
final_arg_typ = exp_arg_sym.array_info().elem_type final_arg_typ = exp_arg_sym.array_info().elem_type
final_arg_sym = c.table.get_type_symbol(final_arg_typ) final_arg_sym = c.table.sym(final_arg_typ)
} }
// Handle expected interface // Handle expected interface
if final_arg_sym.kind == .interface_ { if final_arg_sym.kind == .interface_ {
if c.type_implements(got_arg_typ, final_arg_typ, arg.expr.position()) { if c.type_implements(got_arg_typ, final_arg_typ, arg.expr.position()) {
if !got_arg_typ.is_ptr() && !got_arg_typ.is_pointer() && !c.inside_unsafe { if !got_arg_typ.is_ptr() && !got_arg_typ.is_pointer() && !c.inside_unsafe {
got_arg_typ_sym := c.table.get_type_symbol(got_arg_typ) got_arg_typ_sym := c.table.sym(got_arg_typ)
if got_arg_typ_sym.kind != .interface_ { if got_arg_typ_sym.kind != .interface_ {
c.mark_as_referenced(mut &arg.expr, true) c.mark_as_referenced(mut &arg.expr, true)
} }
@ -1261,7 +1261,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
// call struct field fn type // call struct field fn type
// TODO: can we use SelectorExpr for all? this dosent really belong here // TODO: can we use SelectorExpr for all? this dosent really belong here
if field := c.table.find_field(left_sym, method_name) { if field := c.table.find_field(left_sym, method_name) {
field_sym := c.table.get_type_symbol(c.unwrap_generic(field.typ)) field_sym := c.table.sym(c.unwrap_generic(field.typ))
if field_sym.kind == .function { if field_sym.kind == .function {
node.is_method = false node.is_method = false
node.is_field = true node.is_field = true
@ -1347,7 +1347,7 @@ pub fn (mut c Checker) check_expected_arg_count(mut node ast.CallExpr, f &ast.Fn
if nr_args < min_required_params { if nr_args < min_required_params {
if min_required_params == nr_args + 1 { if min_required_params == nr_args + 1 {
last_typ := f.params.last().typ last_typ := f.params.last().typ
last_sym := c.table.get_type_symbol(last_typ) last_sym := c.table.sym(last_typ)
if last_sym.info is ast.Struct { if last_sym.info is ast.Struct {
is_params := last_sym.info.attrs.filter(it.name == 'params' && !it.has_arg).len > 0 is_params := last_sym.info.attrs.filter(it.name == 'params' && !it.has_arg).len > 0
if is_params { if is_params {

View File

@ -57,7 +57,7 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
return 0 return 0
} }
got_type := c.unwrap_generic((branch.cond.right as ast.TypeNode).typ) got_type := c.unwrap_generic((branch.cond.right as ast.TypeNode).typ)
sym := c.table.get_type_symbol(got_type) sym := c.table.sym(got_type)
if sym.kind == .placeholder || got_type.has_flag(.generic) { if sym.kind == .placeholder || got_type.has_flag(.generic) {
c.error('unknown type `$sym.name`', branch.cond.right.position()) c.error('unknown type `$sym.name`', branch.cond.right.position())
} }
@ -187,8 +187,7 @@ pub fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
} }
} }
} }
if node.is_expr if node.is_expr && c.table.sym(former_expected_type).kind == .sum_type {
&& c.table.get_type_symbol(former_expected_type).kind == .sum_type {
continue continue
} }
if is_noreturn_callexpr(last_expr.expr) { if is_noreturn_callexpr(last_expr.expr) {
@ -264,8 +263,8 @@ fn (mut c Checker) smartcast_if_conds(node ast.Expr, mut scope ast.Scope) {
} }
right_type = c.unwrap_generic(right_type) right_type = c.unwrap_generic(right_type)
if right_type != ast.Type(0) { if right_type != ast.Type(0) {
left_sym := c.table.get_type_symbol(node.left_type) left_sym := c.table.sym(node.left_type)
right_sym := c.table.get_type_symbol(right_type) right_sym := c.table.sym(right_type)
expr_type := c.unwrap_generic(c.expr(node.left)) expr_type := c.unwrap_generic(c.expr(node.left))
if left_sym.kind == .interface_ { if left_sym.kind == .interface_ {
if right_sym.kind != .interface_ { if right_sym.kind != .interface_ {

View File

@ -8,7 +8,7 @@ import v.token
pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) { pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) {
c.check_valid_pascal_case(node.name, 'interface name', node.pos) c.check_valid_pascal_case(node.name, 'interface name', node.pos)
mut decl_sym := c.table.get_type_symbol(node.typ) mut decl_sym := c.table.sym(node.typ)
is_js := node.language == .js is_js := node.language == .js
if mut decl_sym.info is ast.Interface { if mut decl_sym.info is ast.Interface {
if node.ifaces.len > 0 { if node.ifaces.len > 0 {
@ -31,7 +31,7 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) {
} }
// //
for iface in all_ifaces { for iface in all_ifaces {
isym := c.table.get_type_symbol(iface.typ) isym := c.table.sym(iface.typ)
if isym.kind != .interface_ { if isym.kind != .interface_ {
c.error('interface `$node.name` tries to embed `$isym.name`, but `$isym.name` is not an interface, but `$isym.kind`', c.error('interface `$node.name` tries to embed `$isym.name`, but `$isym.name` is not an interface, but `$isym.kind`',
iface.pos) iface.pos)
@ -105,7 +105,7 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) {
} }
c.ensure_type_exists(method.return_type, method.return_type_pos) or { return } c.ensure_type_exists(method.return_type, method.return_type_pos) or { return }
if is_js { if is_js {
mtyp := c.table.get_type_symbol(method.return_type) mtyp := c.table.sym(method.return_type)
if !mtyp.is_js_compatible() { if !mtyp.is_js_compatible() {
c.error('method $method.name returns non JS type', method.pos) c.error('method $method.name returns non JS type', method.pos)
} }
@ -120,7 +120,7 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) {
param.pos) param.pos)
} }
if is_js { if is_js {
ptyp := c.table.get_type_symbol(param.typ) ptyp := c.table.sym(param.typ)
if !ptyp.is_js_compatible() && !(j == method.params.len - 1 if !ptyp.is_js_compatible() && !(j == method.params.len - 1
&& method.is_variadic) { && method.is_variadic) {
c.error('method `$method.name` accepts non JS type as parameter', c.error('method `$method.name` accepts non JS type as parameter',
@ -129,7 +129,7 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) {
} }
} }
for field in node.fields { for field in node.fields {
field_sym := c.table.get_type_symbol(field.typ) field_sym := c.table.sym(field.typ)
if field.name == method.name && field_sym.kind == .function { if field.name == method.name && field_sym.kind == .function {
c.error('type `$decl_sym.name` has both field and method named `$method.name`', c.error('type `$decl_sym.name` has both field and method named `$method.name`',
method.pos) method.pos)
@ -147,7 +147,7 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) {
} }
c.ensure_type_exists(field.typ, field.pos) or { return } c.ensure_type_exists(field.typ, field.pos) or { return }
if is_js { if is_js {
tsym := c.table.get_type_symbol(field.typ) tsym := c.table.sym(field.typ)
if !tsym.is_js_compatible() { if !tsym.is_js_compatible() {
c.error('field `$field.name` uses non JS type', field.pos) c.error('field `$field.name` uses non JS type', field.pos)
} }
@ -167,8 +167,8 @@ pub fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) {
fn (mut c Checker) resolve_generic_interface(typ ast.Type, interface_type ast.Type, pos token.Position) ast.Type { fn (mut c Checker) resolve_generic_interface(typ ast.Type, interface_type ast.Type, pos token.Position) ast.Type {
utyp := c.unwrap_generic(typ) utyp := c.unwrap_generic(typ)
typ_sym := c.table.get_type_symbol(utyp) typ_sym := c.table.sym(utyp)
mut inter_sym := c.table.get_type_symbol(interface_type) mut inter_sym := c.table.sym(interface_type)
if mut inter_sym.info is ast.Interface { if mut inter_sym.info is ast.Interface {
if inter_sym.info.is_generic { if inter_sym.info.is_generic {
@ -189,8 +189,8 @@ fn (mut c Checker) resolve_generic_interface(typ ast.Type, interface_type ast.Ty
typ_sym.find_method_with_generic_parent(imethod.name) or { ast.Fn{} } typ_sym.find_method_with_generic_parent(imethod.name) or { ast.Fn{} }
} }
if imethod.return_type.has_flag(.generic) { if imethod.return_type.has_flag(.generic) {
imret_sym := c.table.get_type_symbol(imethod.return_type) imret_sym := c.table.sym(imethod.return_type)
mret_sym := c.table.get_type_symbol(method.return_type) mret_sym := c.table.sym(method.return_type)
if imret_sym.info is ast.MultiReturn && mret_sym.info is ast.MultiReturn { if imret_sym.info is ast.MultiReturn && mret_sym.info is ast.MultiReturn {
for i, mr_typ in imret_sym.info.types { for i, mr_typ in imret_sym.info.types {
if mr_typ.has_flag(.generic) if mr_typ.has_flag(.generic)

View File

@ -14,7 +14,7 @@ pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
node.cond_type = c.table.mktyp(cond_type) node.cond_type = c.table.mktyp(cond_type)
c.ensure_type_exists(node.cond_type, node.pos) or { return ast.void_type } c.ensure_type_exists(node.cond_type, node.pos) or { return ast.void_type }
c.check_expr_opt_call(node.cond, cond_type) c.check_expr_opt_call(node.cond, cond_type)
cond_type_sym := c.table.get_type_symbol(cond_type) cond_type_sym := c.table.sym(cond_type)
node.is_sum_type = cond_type_sym.kind in [.interface_, .sum_type] node.is_sum_type = cond_type_sym.kind in [.interface_, .sum_type]
c.match_exprs(mut node, cond_type_sym) c.match_exprs(mut node, cond_type_sym)
c.expected_type = cond_type c.expected_type = cond_type
@ -65,7 +65,7 @@ pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
} else if node.is_expr && ret_type.idx() != expr_type.idx() { } else if node.is_expr && ret_type.idx() != expr_type.idx() {
if !c.check_types(ret_type, expr_type) if !c.check_types(ret_type, expr_type)
&& !c.check_types(expr_type, ret_type) { && !c.check_types(expr_type, ret_type) {
ret_sym := c.table.get_type_symbol(ret_type) ret_sym := c.table.sym(ret_type)
is_noreturn := is_noreturn_callexpr(stmt.expr) is_noreturn := is_noreturn_callexpr(stmt.expr)
if !(node.is_expr && ret_sym.kind == .sum_type) && !is_noreturn { if !(node.is_expr && ret_sym.kind == .sum_type) && !is_noreturn {
c.error('return type mismatch, it should be `$ret_sym.name`', c.error('return type mismatch, it should be `$ret_sym.name`',
@ -204,7 +204,7 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym
// parser failed, stop checking // parser failed, stop checking
return return
} }
expr_type_sym := c.table.get_type_symbol(expr_type) expr_type_sym := c.table.sym(expr_type)
if cond_type_sym.kind == .interface_ { if cond_type_sym.kind == .interface_ {
// TODO // TODO
// This generates a memory issue with TCC // This generates a memory issue with TCC

View File

@ -10,7 +10,7 @@ fn (mut c Checker) sql_expr(mut node ast.SqlExpr) ast.Type {
defer { defer {
c.inside_sql = false c.inside_sql = false
} }
sym := c.table.get_type_symbol(node.table_expr.typ) sym := c.table.sym(node.table_expr.typ)
c.ensure_type_exists(node.table_expr.typ, node.pos) or { return ast.void_type } c.ensure_type_exists(node.table_expr.typ, node.pos) or { return ast.void_type }
c.cur_orm_ts = *sym c.cur_orm_ts = *sym
if sym.info !is ast.Struct { if sym.info !is ast.Struct {
@ -21,13 +21,13 @@ fn (mut c Checker) sql_expr(mut node ast.SqlExpr) ast.Type {
fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, sym.name) fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, sym.name)
mut sub_structs := map[int]ast.SqlExpr{} mut sub_structs := map[int]ast.SqlExpr{}
for f in fields.filter((c.table.type_symbols[int(it.typ)].kind == .struct_ for f in fields.filter((c.table.type_symbols[int(it.typ)].kind == .struct_
|| (c.table.get_type_symbol(it.typ).kind == .array || (c.table.sym(it.typ).kind == .array
&& c.table.get_type_symbol(c.table.get_type_symbol(it.typ).array_info().elem_type).kind == .struct_)) && c.table.sym(c.table.sym(it.typ).array_info().elem_type).kind == .struct_))
&& c.table.get_type_name(it.typ) != 'time.Time') { && c.table.get_type_name(it.typ) != 'time.Time') {
typ := if c.table.get_type_symbol(f.typ).kind == .struct_ { typ := if c.table.sym(f.typ).kind == .struct_ {
f.typ f.typ
} else if c.table.get_type_symbol(f.typ).kind == .array { } else if c.table.sym(f.typ).kind == .array {
c.table.get_type_symbol(f.typ).array_info().elem_type c.table.sym(f.typ).array_info().elem_type
} else { } else {
ast.Type(0) ast.Type(0)
} }
@ -113,7 +113,7 @@ fn (mut c Checker) sql_stmt_line(mut node ast.SqlStmtLine) ast.Type {
c.inside_sql = false c.inside_sql = false
} }
c.ensure_type_exists(node.table_expr.typ, node.pos) or { return ast.void_type } c.ensure_type_exists(node.table_expr.typ, node.pos) or { return ast.void_type }
table_sym := c.table.get_type_symbol(node.table_expr.typ) table_sym := c.table.sym(node.table_expr.typ)
c.cur_orm_ts = *table_sym c.cur_orm_ts = *table_sym
if table_sym.info !is ast.Struct { if table_sym.info !is ast.Struct {
c.error('unknown type `$table_sym.name`', node.pos) c.error('unknown type `$table_sym.name`', node.pos)
@ -123,13 +123,13 @@ fn (mut c Checker) sql_stmt_line(mut node ast.SqlStmtLine) ast.Type {
fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, table_sym.name) fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, table_sym.name)
mut sub_structs := map[int]ast.SqlStmtLine{} mut sub_structs := map[int]ast.SqlStmtLine{}
for f in fields.filter(((c.table.type_symbols[int(it.typ)].kind == .struct_) for f in fields.filter(((c.table.type_symbols[int(it.typ)].kind == .struct_)
|| (c.table.get_type_symbol(it.typ).kind == .array || (c.table.sym(it.typ).kind == .array
&& c.table.get_type_symbol(c.table.get_type_symbol(it.typ).array_info().elem_type).kind == .struct_)) && c.table.sym(c.table.sym(it.typ).array_info().elem_type).kind == .struct_))
&& c.table.get_type_name(it.typ) != 'time.Time') { && c.table.get_type_name(it.typ) != 'time.Time') {
typ := if c.table.get_type_symbol(f.typ).kind == .struct_ { typ := if c.table.sym(f.typ).kind == .struct_ {
f.typ f.typ
} else if c.table.get_type_symbol(f.typ).kind == .array { } else if c.table.sym(f.typ).kind == .array {
c.table.get_type_symbol(f.typ).array_info().elem_type c.table.sym(f.typ).array_info().elem_type
} else { } else {
ast.Type(0) ast.Type(0)
} }
@ -178,8 +178,8 @@ fn (mut c Checker) fetch_and_verify_orm_fields(info ast.Struct, pos token.Positi
fields := info.fields.filter( fields := info.fields.filter(
(it.typ in [ast.string_type, ast.bool_type] || int(it.typ) in ast.number_type_idxs (it.typ in [ast.string_type, ast.bool_type] || int(it.typ) in ast.number_type_idxs
|| c.table.type_symbols[int(it.typ)].kind == .struct_ || c.table.type_symbols[int(it.typ)].kind == .struct_
|| (c.table.get_type_symbol(it.typ).kind == .array || (c.table.sym(it.typ).kind == .array
&& c.table.get_type_symbol(c.table.get_type_symbol(it.typ).array_info().elem_type).kind == .struct_)) && c.table.sym(c.table.sym(it.typ).array_info().elem_type).kind == .struct_))
&& !it.attrs.contains('skip')) && !it.attrs.contains('skip'))
if fields.len == 0 { if fields.len == 0 {
c.error('V orm: select: empty fields in `$table_name`', pos) c.error('V orm: select: empty fields in `$table_name`', pos)

View File

@ -9,7 +9,7 @@ import v.pref
pub fn (mut c Checker) return_stmt(mut node ast.Return) { pub fn (mut c Checker) return_stmt(mut node ast.Return) {
c.expected_type = c.table.cur_fn.return_type c.expected_type = c.table.cur_fn.return_type
mut expected_type := c.unwrap_generic(c.expected_type) mut expected_type := c.unwrap_generic(c.expected_type)
expected_type_sym := c.table.get_type_symbol(expected_type) expected_type_sym := c.table.sym(expected_type)
if node.exprs.len > 0 && c.table.cur_fn.return_type == ast.void_type { if node.exprs.len > 0 && c.table.cur_fn.return_type == ast.void_type {
c.error('unexpected argument, current function does not return anything', node.exprs[0].position()) c.error('unexpected argument, current function does not return anything', node.exprs[0].position())
return return
@ -38,7 +38,7 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) {
c.error('`$expr` used as value', node.pos) c.error('`$expr` used as value', node.pos)
} }
// Unpack multi return types // Unpack multi return types
sym := c.table.get_type_symbol(typ) sym := c.table.sym(typ)
if sym.kind == .multi_return { if sym.kind == .multi_return {
for t in sym.mr_info().types { for t in sym.mr_info().types {
got_types << t got_types << t
@ -87,8 +87,8 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) {
pos) pos)
} }
if !c.check_types(got_typ, exp_type) { if !c.check_types(got_typ, exp_type) {
got_typ_sym := c.table.get_type_symbol(got_typ) got_typ_sym := c.table.sym(got_typ)
mut exp_typ_sym := c.table.get_type_symbol(exp_type) mut exp_typ_sym := c.table.sym(exp_type)
if exp_typ_sym.kind == .interface_ { if exp_typ_sym.kind == .interface_ {
if c.type_implements(got_typ, exp_type, node.pos) { if c.type_implements(got_typ, exp_type, node.pos) {
if !got_typ.is_ptr() && !got_typ.is_pointer() && got_typ_sym.kind != .interface_ if !got_typ.is_ptr() && !got_typ.is_pointer() && got_typ_sym.kind != .interface_
@ -130,7 +130,7 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) {
obj = c.fn_scope.find_var(r_expr.obj.name) or { obj } obj = c.fn_scope.find_var(r_expr.obj.name) or { obj }
} }
if obj.is_stack_obj && !c.inside_unsafe { if obj.is_stack_obj && !c.inside_unsafe {
type_sym := c.table.get_type_symbol(obj.typ.set_nr_muls(0)) type_sym := c.table.sym(obj.typ.set_nr_muls(0))
if !type_sym.is_heap() && !c.pref.translated { if !type_sym.is_heap() && !c.pref.translated {
suggestion := if type_sym.kind == .struct_ { suggestion := if type_sym.kind == .struct_ {
'declaring `$type_sym.name` as `[heap]`' 'declaring `$type_sym.name` as `[heap]`'

View File

@ -3,7 +3,7 @@ import v.ast
fn main() { fn main() {
t := ast.new_table() t := ast.new_table()
ityp := ast.int_type ityp := ast.int_type
isym := t.get_type_symbol(ityp) isym := t.sym(ityp)
println(ityp.debug()) println(ityp.debug())
println(isym) println(isym)
println(isym.debug()) println(isym.debug())

View File

@ -263,7 +263,7 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
} }
} }
else { else {
e.error('unknown cast: ${e.table.get_type_symbol(expr.expr_type).str()} to ${e.table.get_type_symbol(expr.typ).str()}') e.error('unknown cast: ${e.table.sym(expr.expr_type).str()} to ${e.table.sym(expr.typ).str()}')
} }
} }
} else if expr.typ in ast.unsigned_integer_type_idxs { } else if expr.typ in ast.unsigned_integer_type_idxs {
@ -306,7 +306,7 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
} }
} }
else { else {
e.error('unknown cast: ${e.table.get_type_symbol(expr.expr_type).str()} to ${e.table.get_type_symbol(expr.typ).str()}') e.error('unknown cast: ${e.table.sym(expr.expr_type).str()} to ${e.table.sym(expr.typ).str()}')
} }
} }
} else if expr.typ in ast.float_type_idxs { } else if expr.typ in ast.float_type_idxs {
@ -336,7 +336,7 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
} }
} }
else { else {
e.error('unknown cast: ${e.table.get_type_symbol(expr.expr_type).str()} to ${e.table.get_type_symbol(expr.typ).str()}') e.error('unknown cast: ${e.table.sym(expr.expr_type).str()} to ${e.table.sym(expr.typ).str()}')
} }
} }
} else if expr.typ in ast.pointer_type_idxs { } else if expr.typ in ast.pointer_type_idxs {
@ -351,7 +351,7 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
} }
} }
else { else {
e.error('unknown cast: ${e.table.get_type_symbol(expr.expr_type).str()} to ${e.table.get_type_symbol(expr.typ).str()}') e.error('unknown cast: ${e.table.sym(expr.expr_type).str()} to ${e.table.sym(expr.typ).str()}')
} }
} }
} else if expr.typ == ast.voidptr_type_idx { } else if expr.typ == ast.voidptr_type_idx {
@ -362,7 +362,7 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
} }
} }
else { else {
e.error('unknown cast: ${e.table.get_type_symbol(expr.expr_type).str()} to ${e.table.get_type_symbol(expr.typ).str()}') e.error('unknown cast: ${e.table.sym(expr.expr_type).str()} to ${e.table.sym(expr.typ).str()}')
} }
} }
} else if expr.typ == ast.charptr_type_idx { } else if expr.typ == ast.charptr_type_idx {
@ -375,17 +375,17 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
} }
} }
else { else {
e.error('unknown cast: ${e.table.get_type_symbol(expr.expr_type).str()} to ${e.table.get_type_symbol(expr.typ).str()}') e.error('unknown cast: ${e.table.sym(expr.expr_type).str()} to ${e.table.sym(expr.typ).str()}')
} }
} }
} }
} else if e.table.get_type_symbol(expr.typ).kind in [.interface_, .sum_type] { } else if e.table.sym(expr.typ).kind in [.interface_, .sum_type] {
if e.pref.is_verbose { if e.pref.is_verbose {
eprintln(util.formatted_error('warning:', 'sumtype or interface casts return void currently', eprintln(util.formatted_error('warning:', 'sumtype or interface casts return void currently',
e.cur_file, expr.pos)) e.cur_file, expr.pos))
} }
} else { } else {
e.error('unknown cast: ${e.table.get_type_symbol(expr.expr_type).str()} to ${e.table.get_type_symbol(expr.typ).str()}') e.error('unknown cast: ${e.table.sym(expr.expr_type).str()} to ${e.table.sym(expr.typ).str()}')
} }
} }
ast.SelectorExpr { ast.SelectorExpr {
@ -540,7 +540,7 @@ fn (e Eval) type_to_size(typ ast.Type) u64 {
return u64(math.exp2(f64(typ - 8))) // this formula converts the type number to the bitsize return u64(math.exp2(f64(typ - 8))) // this formula converts the type number to the bitsize
} }
else { else {
e.error('type_to_size(): unknown type: ${e.table.get_type_symbol(typ).str()}') e.error('type_to_size(): unknown type: ${e.table.sym(typ).str()}')
return -1 return -1
} }
} }

View File

@ -13,7 +13,7 @@ fn(e Eval)infix_expr(left Object,right Object,op token.Kind,expecting ast.Type)O
footer = "else{e.error('unknown infix expression: \$op')}}return empty // should e.error before this anyway footer = "else{e.error('unknown infix expression: \$op')}}return empty // should e.error before this anyway
} }
" "
uk_expect_footer = "else{e.error('unknown infix expectation: \${e.table.get_type_symbol(expecting).str()}')}}" uk_expect_footer = "else{e.error('unknown infix expectation: \${e.table.sym(expecting).str()}')}}"
comparison = { comparison = {
'gt': '>' 'gt': '>'
'lt': '<' 'lt': '<'

View File

@ -262,7 +262,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -277,7 +277,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -292,7 +292,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -307,7 +307,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -322,7 +322,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -344,7 +344,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -359,7 +359,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -374,7 +374,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -389,7 +389,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -404,7 +404,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -426,7 +426,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -441,7 +441,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -456,7 +456,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -471,7 +471,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -486,7 +486,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -508,7 +508,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -523,7 +523,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -538,7 +538,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -553,7 +553,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -568,7 +568,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -590,7 +590,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -605,7 +605,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -620,7 +620,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -635,7 +635,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -650,7 +650,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -679,7 +679,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right.val)) return f64(f64(left.val) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -694,7 +694,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right.val)) return f64(f64(left.val) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -709,7 +709,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right.val)) return f64(f64(left.val) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -724,7 +724,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right)) return f64(f64(left.val) * f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -739,7 +739,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right)) return f64(f64(left.val) * f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -761,7 +761,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right.val)) return f64(f64(left.val) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -776,7 +776,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right.val)) return f64(f64(left.val) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -791,7 +791,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right.val)) return f64(f64(left.val) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -806,7 +806,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right)) return f64(f64(left.val) * f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -821,7 +821,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right)) return f64(f64(left.val) * f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -843,7 +843,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right.val)) return f64(f64(left.val) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -858,7 +858,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right.val)) return f64(f64(left.val) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -873,7 +873,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right.val)) return f64(f64(left.val) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -888,7 +888,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right)) return f64(f64(left.val) * f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -903,7 +903,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) * f64(right)) return f64(f64(left.val) * f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -925,7 +925,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) * f64(right.val)) return f64(f64(left) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -940,7 +940,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) * f64(right.val)) return f64(f64(left) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -955,7 +955,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) * f64(right.val)) return f64(f64(left) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -970,7 +970,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) * f64(right)) return f64(f64(left) * f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -985,7 +985,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) * f64(right)) return f64(f64(left) * f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1007,7 +1007,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) * f64(right.val)) return f64(f64(left) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1022,7 +1022,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) * f64(right.val)) return f64(f64(left) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1037,7 +1037,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) * f64(right.val)) return f64(f64(left) * f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1052,7 +1052,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) * f64(right)) return f64(f64(left) * f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1067,7 +1067,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) * f64(right)) return f64(f64(left) * f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1096,7 +1096,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1111,7 +1111,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1126,7 +1126,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1141,7 +1141,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1156,7 +1156,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1178,7 +1178,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1193,7 +1193,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1208,7 +1208,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1223,7 +1223,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1238,7 +1238,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1260,7 +1260,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1275,7 +1275,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1290,7 +1290,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1305,7 +1305,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1320,7 +1320,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1342,7 +1342,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1357,7 +1357,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1372,7 +1372,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1387,7 +1387,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1402,7 +1402,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1424,7 +1424,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1439,7 +1439,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1454,7 +1454,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1469,7 +1469,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1484,7 +1484,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1513,7 +1513,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1528,7 +1528,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1543,7 +1543,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1558,7 +1558,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1573,7 +1573,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1595,7 +1595,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1610,7 +1610,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1625,7 +1625,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1640,7 +1640,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1655,7 +1655,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1677,7 +1677,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1692,7 +1692,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1707,7 +1707,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right.val)) return f64(f64(left.val) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1722,7 +1722,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1737,7 +1737,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left.val) + f64(right)) return f64(f64(left.val) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1759,7 +1759,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1774,7 +1774,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1789,7 +1789,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1804,7 +1804,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1819,7 +1819,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1841,7 +1841,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1856,7 +1856,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Float { Float {
@ -1871,7 +1871,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right.val)) return f64(f64(left) + f64(right.val))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1886,7 +1886,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
f64 { f64 {
@ -1901,7 +1901,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
} else if expecting == ast.float_literal_type_idx { } else if expecting == ast.float_literal_type_idx {
return f64(f64(left) + f64(right)) return f64(f64(left) + f64(right))
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1928,7 +1928,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) >> i64(right.val)) return i64(i64(left.val) >> i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1941,7 +1941,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) >> i64(right.val)) return i64(i64(left.val) >> i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -1954,7 +1954,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) >> i64(right)) return i64(i64(left.val) >> i64(right))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -1974,7 +1974,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) >> i64(right.val)) return i64(i64(left.val) >> i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -1987,7 +1987,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) >> i64(right.val)) return i64(i64(left.val) >> i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -2000,7 +2000,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) >> i64(right)) return i64(i64(left.val) >> i64(right))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -2020,7 +2020,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left) >> i64(right.val)) return i64(i64(left) >> i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -2033,7 +2033,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left) >> i64(right.val)) return i64(i64(left) >> i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -2046,7 +2046,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left) >> i64(right)) return i64(i64(left) >> i64(right))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -2073,7 +2073,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) << i64(right.val)) return i64(i64(left.val) << i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -2086,7 +2086,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) << i64(right.val)) return i64(i64(left.val) << i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -2099,7 +2099,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) << i64(right)) return i64(i64(left.val) << i64(right))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -2119,7 +2119,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) << i64(right.val)) return i64(i64(left.val) << i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -2132,7 +2132,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) << i64(right.val)) return i64(i64(left.val) << i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -2145,7 +2145,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left.val) << i64(right)) return i64(i64(left.val) << i64(right))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {
@ -2165,7 +2165,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left) << i64(right.val)) return i64(i64(left) << i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
Uint { Uint {
@ -2178,7 +2178,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left) << i64(right.val)) return i64(i64(left) << i64(right.val))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
i64 { i64 {
@ -2191,7 +2191,7 @@ fn (e Eval) infix_expr(left Object, right Object, op token.Kind, expecting ast.T
return i64(i64(left) << i64(right)) return i64(i64(left) << i64(right))
} }
} else { } else {
e.error('unknown infix expectation: ${e.table.get_type_symbol(expecting).str()}') e.error('unknown infix expectation: ${e.table.sym(expecting).str()}')
} }
} }
else { else {

View File

@ -244,7 +244,7 @@ pub fn (mut f Fmt) short_module(name string) string {
//=== Import-related methods ===// //=== Import-related methods ===//
pub fn (mut f Fmt) mark_types_import_as_used(typ ast.Type) { pub fn (mut f Fmt) mark_types_import_as_used(typ ast.Type) {
sym := f.table.get_type_symbol(typ) sym := f.table.sym(typ)
if sym.info is ast.Map { if sym.info is ast.Map {
map_info := sym.map_info() map_info := sym.map_info()
f.mark_types_import_as_used(map_info.key_type) f.mark_types_import_as_used(map_info.key_type)
@ -1184,7 +1184,7 @@ pub fn (mut f Fmt) sql_stmt(node ast.SqlStmt) {
} }
pub fn (mut f Fmt) sql_stmt_line(node ast.SqlStmtLine) { pub fn (mut f Fmt) sql_stmt_line(node ast.SqlStmtLine) {
table_name := util.strip_mod_name(f.table.get_type_symbol(node.table_expr.typ).name) table_name := util.strip_mod_name(f.table.sym(node.table_expr.typ).name)
f.mark_types_import_as_used(node.table_expr.typ) f.mark_types_import_as_used(node.table_expr.typ)
f.write('\t') f.write('\t')
match node.kind { match node.kind {
@ -1245,7 +1245,7 @@ pub fn (mut f Fmt) fn_type_decl(node ast.FnTypeDecl) {
if node.is_pub { if node.is_pub {
f.write('pub ') f.write('pub ')
} }
typ_sym := f.table.get_type_symbol(node.typ) typ_sym := f.table.sym(node.typ)
fn_typ_info := typ_sym.info as ast.FnType fn_typ_info := typ_sym.info as ast.FnType
fn_info := fn_typ_info.func fn_info := fn_typ_info.func
fn_name := f.no_cur_mod(node.name) fn_name := f.no_cur_mod(node.name)
@ -1621,7 +1621,7 @@ fn (mut f Fmt) write_generic_call_if_require(node ast.CallExpr) {
f.write('<') f.write('<')
for i, concrete_type in node.concrete_types { for i, concrete_type in node.concrete_types {
mut name := f.table.type_to_str_using_aliases(concrete_type, f.mod2alias) mut name := f.table.type_to_str_using_aliases(concrete_type, f.mod2alias)
tsym := f.table.get_type_symbol(concrete_type) tsym := f.table.sym(concrete_type)
if tsym.language != .js && !tsym.name.starts_with('JS.') { if tsym.language != .js && !tsym.name.starts_with('JS.') {
name = f.short_module(name) name = f.short_module(name)
} else if tsym.language == .js && !tsym.name.starts_with('JS.') { } else if tsym.language == .js && !tsym.name.starts_with('JS.') {
@ -1675,7 +1675,7 @@ pub fn (mut f Fmt) cast_expr(node ast.CastExpr) {
} }
pub fn (mut f Fmt) chan_init(mut node ast.ChanInit) { pub fn (mut f Fmt) chan_init(mut node ast.ChanInit) {
info := f.table.get_type_symbol(node.typ).chan_info() info := f.table.sym(node.typ).chan_info()
if node.elem_type == 0 && node.typ > 0 { if node.elem_type == 0 && node.typ > 0 {
node.elem_type = info.elem_type node.elem_type = info.elem_type
} }
@ -2081,7 +2081,7 @@ pub fn (mut f Fmt) lock_expr(node ast.LockExpr) {
pub fn (mut f Fmt) map_init(node ast.MapInit) { pub fn (mut f Fmt) map_init(node ast.MapInit) {
if node.keys.len == 0 { if node.keys.len == 0 {
if node.typ > ast.void_type { if node.typ > ast.void_type {
sym := f.table.get_type_symbol(node.typ) sym := f.table.sym(node.typ)
info := sym.info as ast.Map info := sym.info as ast.Map
f.mark_types_import_as_used(info.key_type) f.mark_types_import_as_used(info.key_type)
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias)) f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
@ -2353,7 +2353,7 @@ pub fn (mut f Fmt) sql_expr(node ast.SqlExpr) {
f.expr(node.db_expr) f.expr(node.db_expr)
f.writeln(' {') f.writeln(' {')
f.write('\tselect ') f.write('\tselect ')
table_name := util.strip_mod_name(f.table.get_type_symbol(node.table_expr.typ).name) table_name := util.strip_mod_name(f.table.sym(node.table_expr.typ).name)
if node.is_count { if node.is_count {
f.write('count ') f.write('count ')
} else { } else {

View File

@ -179,7 +179,7 @@ pub fn (mut f Fmt) struct_init(node ast.StructInit) {
f.is_struct_init = struct_init_save f.is_struct_init = struct_init_save
} }
type_sym := f.table.get_type_symbol(node.typ) type_sym := f.table.sym(node.typ)
// f.write('<old name: $type_sym.name>') // f.write('<old name: $type_sym.name>')
mut name := type_sym.name mut name := type_sym.name
if !name.starts_with('C.') && !name.starts_with('JS.') { if !name.starts_with('C.') && !name.starts_with('JS.') {

View File

@ -279,8 +279,8 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
// println('filter s="$s"') // println('filter s="$s"')
ret_typ := g.typ(node.return_type) ret_typ := g.typ(node.return_type)
// inp_typ := g.typ(node.receiver_type) // inp_typ := g.typ(node.receiver_type)
ret_sym := g.table.get_type_symbol(node.return_type) ret_sym := g.table.sym(node.return_type)
inp_sym := g.table.get_type_symbol(node.receiver_type) inp_sym := g.table.sym(node.receiver_type)
ret_info := ret_sym.info as ast.Array ret_info := ret_sym.info as ast.Array
ret_elem_type := g.typ(ret_info.elem_type) ret_elem_type := g.typ(ret_info.elem_type)
inp_info := inp_sym.info as ast.Array inp_info := inp_sym.info as ast.Array
@ -321,7 +321,7 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
g.write('${c_name(expr.name)}(it)') g.write('${c_name(expr.name)}(it)')
} else if expr.kind == .variable { } else if expr.kind == .variable {
var_info := expr.var_info() var_info := expr.var_info()
sym := g.table.get_type_symbol(var_info.typ) sym := g.table.sym(var_info.typ)
if sym.kind == .function { if sym.kind == .function {
g.write('${c_name(expr.name)}(it)') g.write('${c_name(expr.name)}(it)')
} else { } else {
@ -367,7 +367,7 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) {
// `users.sort(a.age < b.age)` // `users.sort(a.age < b.age)`
fn (mut g Gen) gen_array_sort(node ast.CallExpr) { fn (mut g Gen) gen_array_sort(node ast.CallExpr) {
// println('filter s="$s"') // println('filter s="$s"')
rec_sym := g.table.get_type_symbol(node.receiver_type) rec_sym := g.table.sym(node.receiver_type)
if rec_sym.kind != .array { if rec_sym.kind != .array {
println(node.name) println(node.name)
println(g.typ(node.receiver_type)) println(g.typ(node.receiver_type))
@ -479,7 +479,7 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) {
s_ends_with_ln := s.ends_with('\n') s_ends_with_ln := s.ends_with('\n')
s = s.trim_space() s = s.trim_space()
// println('filter s="$s"') // println('filter s="$s"')
sym := g.table.get_type_symbol(node.return_type) sym := g.table.sym(node.return_type)
if sym.kind != .array { if sym.kind != .array {
verror('filter() requires an array') verror('filter() requires an array')
} }
@ -519,7 +519,7 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) {
g.write('${c_name(expr.name)}(it)') g.write('${c_name(expr.name)}(it)')
} else if expr.kind == .variable { } else if expr.kind == .variable {
var_info := expr.var_info() var_info := expr.var_info()
sym_t := g.table.get_type_symbol(var_info.typ) sym_t := g.table.sym(var_info.typ)
if sym_t.kind == .function { if sym_t.kind == .function {
g.write('${c_name(expr.name)}(it)') g.write('${c_name(expr.name)}(it)')
} else { } else {
@ -564,10 +564,10 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) {
// `nums.insert(0, 2)` `nums.insert(0, [2,3,4])` // `nums.insert(0, 2)` `nums.insert(0, [2,3,4])`
fn (mut g Gen) gen_array_insert(node ast.CallExpr) { fn (mut g Gen) gen_array_insert(node ast.CallExpr) {
left_sym := g.table.get_type_symbol(node.left_type) left_sym := g.table.sym(node.left_type)
left_info := left_sym.info as ast.Array left_info := left_sym.info as ast.Array
elem_type_str := g.typ(left_info.elem_type) elem_type_str := g.typ(left_info.elem_type)
arg2_sym := g.table.get_type_symbol(node.args[1].typ) arg2_sym := g.table.sym(node.args[1].typ)
is_arg2_array := arg2_sym.kind == .array && node.args[1].typ == node.left_type is_arg2_array := arg2_sym.kind == .array && node.args[1].typ == node.left_type
noscan := g.check_noscan(left_info.elem_type) noscan := g.check_noscan(left_info.elem_type)
if is_arg2_array { if is_arg2_array {
@ -599,10 +599,10 @@ fn (mut g Gen) gen_array_insert(node ast.CallExpr) {
// `nums.prepend(2)` `nums.prepend([2,3,4])` // `nums.prepend(2)` `nums.prepend([2,3,4])`
fn (mut g Gen) gen_array_prepend(node ast.CallExpr) { fn (mut g Gen) gen_array_prepend(node ast.CallExpr) {
left_sym := g.table.get_type_symbol(node.left_type) left_sym := g.table.sym(node.left_type)
left_info := left_sym.info as ast.Array left_info := left_sym.info as ast.Array
elem_type_str := g.typ(left_info.elem_type) elem_type_str := g.typ(left_info.elem_type)
arg_sym := g.table.get_type_symbol(node.args[0].typ) arg_sym := g.table.sym(node.args[0].typ)
is_arg_array := arg_sym.kind == .array && node.args[0].typ == node.left_type is_arg_array := arg_sym.kind == .array && node.args[0].typ == node.left_type
noscan := g.check_noscan(left_info.elem_type) noscan := g.check_noscan(left_info.elem_type)
if is_arg_array { if is_arg_array {
@ -625,7 +625,7 @@ fn (mut g Gen) gen_array_prepend(node ast.CallExpr) {
} }
fn (mut g Gen) get_array_contains_method(typ ast.Type) string { fn (mut g Gen) get_array_contains_method(typ ast.Type) string {
t := g.table.get_final_type_symbol(g.unwrap_generic(typ).set_nr_muls(0)).idx t := g.table.final_sym(g.unwrap_generic(typ).set_nr_muls(0)).idx
g.array_contains_types << t g.array_contains_types << t
return g.typ(t) + '_contains' return g.typ(t) + '_contains'
} }
@ -633,8 +633,8 @@ fn (mut g Gen) get_array_contains_method(typ ast.Type) string {
fn (mut g Gen) gen_array_contains_methods() { fn (mut g Gen) gen_array_contains_methods() {
mut done := []ast.Type{} mut done := []ast.Type{}
for t in g.array_contains_types { for t in g.array_contains_types {
left_final_sym := g.table.get_final_type_symbol(t) left_final_sym := g.table.final_sym(t)
if left_final_sym.idx in done || g.table.get_type_symbol(t).has_method('contains') { if left_final_sym.idx in done || g.table.sym(t).has_method('contains') {
continue continue
} }
done << t done << t
@ -642,7 +642,7 @@ fn (mut g Gen) gen_array_contains_methods() {
fn_name := '${left_type_str}_contains' fn_name := '${left_type_str}_contains'
left_info := left_final_sym.info as ast.Array left_info := left_final_sym.info as ast.Array
mut elem_type_str := g.typ(left_info.elem_type) mut elem_type_str := g.typ(left_info.elem_type)
elem_sym := g.table.get_type_symbol(left_info.elem_type) elem_sym := g.table.sym(left_info.elem_type)
if elem_sym.kind == .function { if elem_sym.kind == .function {
left_type_str = 'Array_voidptr' left_type_str = 'Array_voidptr'
elem_type_str = 'voidptr' elem_type_str = 'voidptr'
@ -708,16 +708,16 @@ fn (mut g Gen) get_array_index_method(typ ast.Type) string {
fn (mut g Gen) gen_array_index_methods() { fn (mut g Gen) gen_array_index_methods() {
mut done := []ast.Type{} mut done := []ast.Type{}
for t in g.array_index_types { for t in g.array_index_types {
if t in done || g.table.get_type_symbol(t).has_method('index') { if t in done || g.table.sym(t).has_method('index') {
continue continue
} }
done << t done << t
final_left_sym := g.table.get_final_type_symbol(t) final_left_sym := g.table.final_sym(t)
mut left_type_str := g.typ(t) mut left_type_str := g.typ(t)
fn_name := '${left_type_str}_index' fn_name := '${left_type_str}_index'
info := final_left_sym.info as ast.Array info := final_left_sym.info as ast.Array
mut elem_type_str := g.typ(info.elem_type) mut elem_type_str := g.typ(info.elem_type)
elem_sym := g.table.get_type_symbol(info.elem_type) elem_sym := g.table.sym(info.elem_type)
if elem_sym.kind == .function { if elem_sym.kind == .function {
left_type_str = 'Array_voidptr' left_type_str = 'Array_voidptr'
elem_type_str = 'voidptr' elem_type_str = 'voidptr'
@ -775,11 +775,11 @@ fn (mut g Gen) gen_array_index(node ast.CallExpr) {
} }
fn (mut g Gen) gen_array_wait(node ast.CallExpr) { fn (mut g Gen) gen_array_wait(node ast.CallExpr) {
arr := g.table.get_type_symbol(node.receiver_type) arr := g.table.sym(node.receiver_type)
thread_type := arr.array_info().elem_type thread_type := arr.array_info().elem_type
thread_sym := g.table.get_type_symbol(thread_type) thread_sym := g.table.sym(thread_type)
thread_ret_type := thread_sym.thread_info().return_type thread_ret_type := thread_sym.thread_info().return_type
eltyp := g.table.get_type_symbol(thread_ret_type).cname eltyp := g.table.sym(thread_ret_type).cname
fn_name := g.register_thread_array_wait_call(eltyp) fn_name := g.register_thread_array_wait_call(eltyp)
g.write('${fn_name}(') g.write('${fn_name}(')
g.expr(node.left) g.expr(node.left)
@ -791,7 +791,7 @@ fn (mut g Gen) gen_array_any(node ast.CallExpr) {
mut s := g.go_before_stmt(0) mut s := g.go_before_stmt(0)
s_ends_with_ln := s.ends_with('\n') s_ends_with_ln := s.ends_with('\n')
s = s.trim_space() s = s.trim_space()
sym := g.table.get_type_symbol(node.left_type) sym := g.table.sym(node.left_type)
info := sym.info as ast.Array info := sym.info as ast.Array
// styp := g.typ(node.return_type) // styp := g.typ(node.return_type)
elem_type_str := g.typ(info.elem_type) elem_type_str := g.typ(info.elem_type)
@ -826,7 +826,7 @@ fn (mut g Gen) gen_array_any(node ast.CallExpr) {
g.write('${c_name(expr.name)}(it)') g.write('${c_name(expr.name)}(it)')
} else if expr.kind == .variable { } else if expr.kind == .variable {
var_info := expr.var_info() var_info := expr.var_info()
sym_t := g.table.get_type_symbol(var_info.typ) sym_t := g.table.sym(var_info.typ)
if sym_t.kind == .function { if sym_t.kind == .function {
g.write('${c_name(expr.name)}(it)') g.write('${c_name(expr.name)}(it)')
} else { } else {
@ -875,7 +875,7 @@ fn (mut g Gen) gen_array_all(node ast.CallExpr) {
mut s := g.go_before_stmt(0) mut s := g.go_before_stmt(0)
s_ends_with_ln := s.ends_with('\n') s_ends_with_ln := s.ends_with('\n')
s = s.trim_space() s = s.trim_space()
sym := g.table.get_type_symbol(node.left_type) sym := g.table.sym(node.left_type)
info := sym.info as ast.Array info := sym.info as ast.Array
// styp := g.typ(node.return_type) // styp := g.typ(node.return_type)
elem_type_str := g.typ(info.elem_type) elem_type_str := g.typ(info.elem_type)
@ -911,7 +911,7 @@ fn (mut g Gen) gen_array_all(node ast.CallExpr) {
g.write('${c_name(expr.name)}(it)') g.write('${c_name(expr.name)}(it)')
} else if expr.kind == .variable { } else if expr.kind == .variable {
var_info := expr.var_info() var_info := expr.var_info()
sym_t := g.table.get_type_symbol(var_info.typ) sym_t := g.table.sym(var_info.typ)
if sym_t.kind == .function { if sym_t.kind == .function {
g.write('${c_name(expr.name)}(it)') g.write('${c_name(expr.name)}(it)')
} else { } else {

View File

@ -69,7 +69,7 @@ fn (mut g Gen) assert_subexpression_to_ctemp(expr ast.Expr, expr_type ast.Type)
} }
ast.SelectorExpr { ast.SelectorExpr {
if expr.expr is ast.CallExpr { if expr.expr is ast.CallExpr {
sym := g.table.get_final_type_symbol(g.unwrap_generic(expr.expr.return_type)) sym := g.table.final_sym(g.unwrap_generic(expr.expr.return_type))
if sym.kind == .struct_ { if sym.kind == .struct_ {
if (sym.info as ast.Struct).is_union { if (sym.info as ast.Struct).is_union {
return c.unsupported_ctemp_assert_transform return c.unsupported_ctemp_assert_transform
@ -149,7 +149,7 @@ fn (mut g Gen) gen_assert_single_expr(expr ast.Expr, typ ast.Type) {
} }
} }
ast.TypeNode { ast.TypeNode {
sym := g.table.get_type_symbol(g.unwrap_generic(typ)) sym := g.table.sym(g.unwrap_generic(typ))
g.write(ctoslit('$sym.name')) g.write(ctoslit('$sym.name'))
} }
else { else {

View File

@ -19,7 +19,7 @@ fn (mut g Gen) gen_equality_fns() {
if needed_typ in g.generated_eq_fns { if needed_typ in g.generated_eq_fns {
continue continue
} }
sym := g.table.get_type_symbol(needed_typ) sym := g.table.sym(needed_typ)
match sym.kind { match sym.kind {
.sum_type { .sum_type {
g.gen_sumtype_equality_fn(needed_typ) g.gen_sumtype_equality_fn(needed_typ)
@ -182,7 +182,7 @@ fn (mut g Gen) gen_alias_equality_fn(left_type ast.Type) string {
mut fn_builder := strings.new_builder(512) mut fn_builder := strings.new_builder(512)
fn_builder.writeln('static bool ${ptr_styp}_alias_eq($ptr_styp a, $ptr_styp b) {') fn_builder.writeln('static bool ${ptr_styp}_alias_eq($ptr_styp a, $ptr_styp b) {')
sym := g.table.get_type_symbol(info.parent_type) sym := g.table.sym(info.parent_type)
if sym.kind == .string { if sym.kind == .string {
fn_builder.writeln('\treturn string__eq(a, b);') fn_builder.writeln('\treturn string__eq(a, b);')
} else if sym.kind == .sum_type && !left.typ.is_ptr() { } else if sym.kind == .sum_type && !left.typ.is_ptr() {

View File

@ -7,11 +7,11 @@ import strings
fn (mut g Gen) gen_free_method_for_type(typ ast.Type) string { fn (mut g Gen) gen_free_method_for_type(typ ast.Type) string {
styp := g.typ(typ).replace('*', '') styp := g.typ(typ).replace('*', '')
mut sym := g.table.get_type_symbol(g.unwrap_generic(typ)) mut sym := g.table.sym(g.unwrap_generic(typ))
mut fn_name := styp_to_free_fn_name(styp) mut fn_name := styp_to_free_fn_name(styp)
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
if sym.info.is_import { if sym.info.is_import {
sym = g.table.get_type_symbol(sym.info.parent_type) sym = g.table.sym(sym.info.parent_type)
} }
} }
@ -44,7 +44,7 @@ fn (mut g Gen) gen_free_for_struct(info ast.Struct, styp string, fn_name string)
} }
fn_builder.writeln('void ${fn_name}($styp* it) {') fn_builder.writeln('void ${fn_name}($styp* it) {')
for field in info.fields { for field in info.fields {
sym := g.table.get_type_symbol(g.unwrap_generic(field.typ)) sym := g.table.sym(g.unwrap_generic(field.typ))
if sym.kind !in [.string, .array, .map, .struct_] { if sym.kind !in [.string, .array, .map, .struct_] {
continue continue
@ -68,7 +68,7 @@ fn (mut g Gen) gen_free_for_array(info ast.Array, styp string, fn_name string) {
} }
fn_builder.writeln('void ${fn_name}($styp* it) {') fn_builder.writeln('void ${fn_name}($styp* it) {')
sym := g.table.get_type_symbol(g.unwrap_generic(info.elem_type)) sym := g.table.sym(g.unwrap_generic(info.elem_type))
if sym.kind in [.string, .array, .map, .struct_] { if sym.kind in [.string, .array, .map, .struct_] {
fn_builder.writeln('\tfor (int i = 0; i < it->len; i++) {') fn_builder.writeln('\tfor (int i = 0; i < it->len; i++) {')

View File

@ -142,11 +142,11 @@ fn (mut g Gen) get_str_fn(typ ast.Type) string {
unwrapped.set_flag(.optional) unwrapped.set_flag(.optional)
} }
styp := g.typ(unwrapped) styp := g.typ(unwrapped)
mut sym := g.table.get_type_symbol(unwrapped) mut sym := g.table.sym(unwrapped)
mut str_fn_name := styp_to_str_fn_name(styp) mut str_fn_name := styp_to_str_fn_name(styp)
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
if sym.info.is_import { if sym.info.is_import {
sym = g.table.get_type_symbol(sym.info.parent_type) sym = g.table.sym(sym.info.parent_type)
str_fn_name = styp_to_str_fn_name(sym.name) str_fn_name = styp_to_str_fn_name(sym.name)
} }
} }
@ -168,7 +168,7 @@ fn (mut g Gen) final_gen_str(typ StrType) {
eprintln('> final_gen_str: $typ') eprintln('> final_gen_str: $typ')
} }
g.generated_str_fns << typ g.generated_str_fns << typ
sym := g.table.get_type_symbol(typ.typ) sym := g.table.sym(typ.typ)
if sym.has_method_with_generic_parent('str') && !typ.typ.has_flag(.optional) { if sym.has_method_with_generic_parent('str') && !typ.typ.has_flag(.optional) {
return return
} }
@ -230,7 +230,7 @@ fn (mut g Gen) gen_str_for_option(typ ast.Type, styp string, str_fn_name string)
eprintln('> gen_str_for_option: $typ.debug() | $styp | $str_fn_name') eprintln('> gen_str_for_option: $typ.debug() | $styp | $str_fn_name')
} }
parent_type := typ.clear_flag(.optional) parent_type := typ.clear_flag(.optional)
sym := g.table.get_type_symbol(parent_type) sym := g.table.sym(parent_type)
sym_has_str_method, _, _ := sym.str_method_info() sym_has_str_method, _, _ := sym.str_method_info()
parent_str_fn_name := g.get_str_fn(parent_type) parent_str_fn_name := g.get_str_fn(parent_type)
@ -291,7 +291,7 @@ fn (mut g Gen) gen_str_for_multi_return(info ast.MultiReturn, styp string, str_f
fn_builder.writeln('\tstrings__Builder sb = strings__new_builder($info.types.len * 10);') fn_builder.writeln('\tstrings__Builder sb = strings__new_builder($info.types.len * 10);')
fn_builder.writeln('\tstrings__Builder_write_string(&sb, _SLIT("("));') fn_builder.writeln('\tstrings__Builder_write_string(&sb, _SLIT("("));')
for i, typ in info.types { for i, typ in info.types {
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
is_arg_ptr := typ.is_ptr() is_arg_ptr := typ.is_ptr()
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info() sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
arg_str_fn_name := g.get_str_fn(typ) arg_str_fn_name := g.get_str_fn(typ)
@ -384,7 +384,7 @@ fn (mut g Gen) gen_str_for_interface(info ast.Interface, styp string, str_fn_nam
clean_interface_v_type_name = util.strip_main_name(clean_interface_v_type_name) clean_interface_v_type_name = util.strip_main_name(clean_interface_v_type_name)
fn_builder.writeln('static string indent_${str_fn_name}($styp x, int indent_count) { /* gen_str_for_interface */') fn_builder.writeln('static string indent_${str_fn_name}($styp x, int indent_count) { /* gen_str_for_interface */')
for typ in info.types { for typ in info.types {
subtype := g.table.get_type_symbol(typ) subtype := g.table.sym(typ)
mut func_name := g.get_str_fn(typ) mut func_name := g.get_str_fn(typ)
sym_has_str_method, str_method_expects_ptr, _ := subtype.str_method_info() sym_has_str_method, str_method_expects_ptr, _ := subtype.str_method_info()
if should_use_indent_func(subtype.kind) && !sym_has_str_method { if should_use_indent_func(subtype.kind) && !sym_has_str_method {
@ -448,7 +448,7 @@ fn (mut g Gen) gen_str_for_union_sum_type(info ast.SumType, styp string, str_fn_
for typ in info.variants { for typ in info.variants {
typ_str := g.typ(typ) typ_str := g.typ(typ)
mut func_name := g.get_str_fn(typ) mut func_name := g.get_str_fn(typ)
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info() sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
deref := if sym_has_str_method && str_method_expects_ptr { ' ' } else { '*' } deref := if sym_has_str_method && str_method_expects_ptr { ' ' } else { '*' }
if should_use_indent_func(sym.kind) && !sym_has_str_method { if should_use_indent_func(sym.kind) && !sym_has_str_method {
@ -559,10 +559,10 @@ fn (mut g Gen) gen_str_for_array(info ast.Array, styp string, str_fn_name string
eprintln('> gen_str_for_array: $info.elem_type.debug() | $styp | $str_fn_name') eprintln('> gen_str_for_array: $info.elem_type.debug() | $styp | $str_fn_name')
} }
mut typ := info.elem_type mut typ := info.elem_type
mut sym := g.table.get_type_symbol(info.elem_type) mut sym := g.table.sym(info.elem_type)
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
typ = sym.info.parent_type typ = sym.info.parent_type
sym = g.table.get_type_symbol(typ) sym = g.table.sym(typ)
} }
field_styp := g.typ(typ) field_styp := g.typ(typ)
is_elem_ptr := typ.is_ptr() is_elem_ptr := typ.is_ptr()
@ -635,10 +635,10 @@ fn (mut g Gen) gen_str_for_array_fixed(info ast.ArrayFixed, styp string, str_fn_
eprintln('> gen_str_for_array_fixed: $info.elem_type.debug() | $styp | $str_fn_name') eprintln('> gen_str_for_array_fixed: $info.elem_type.debug() | $styp | $str_fn_name')
} }
mut typ := info.elem_type mut typ := info.elem_type
mut sym := g.table.get_type_symbol(info.elem_type) mut sym := g.table.sym(info.elem_type)
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
typ = sym.info.parent_type typ = sym.info.parent_type
sym = g.table.get_type_symbol(typ) sym = g.table.sym(typ)
} }
is_elem_ptr := typ.is_ptr() is_elem_ptr := typ.is_ptr()
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info() sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
@ -698,10 +698,10 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
eprintln('> gen_str_for_map: $info.key_type.debug() -> $info.value_type.debug() | $styp | $str_fn_name') eprintln('> gen_str_for_map: $info.key_type.debug() -> $info.value_type.debug() | $styp | $str_fn_name')
} }
mut key_typ := info.key_type mut key_typ := info.key_type
mut key_sym := g.table.get_type_symbol(key_typ) mut key_sym := g.table.sym(key_typ)
if mut key_sym.info is ast.Alias { if mut key_sym.info is ast.Alias {
key_typ = key_sym.info.parent_type key_typ = key_sym.info.parent_type
key_sym = g.table.get_type_symbol(key_typ) key_sym = g.table.sym(key_typ)
} }
key_styp := g.typ(key_typ) key_styp := g.typ(key_typ)
key_str_fn_name := key_styp.replace('*', '') + '_str' key_str_fn_name := key_styp.replace('*', '') + '_str'
@ -710,10 +710,10 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
} }
mut val_typ := info.value_type mut val_typ := info.value_type
mut val_sym := g.table.get_type_symbol(val_typ) mut val_sym := g.table.sym(val_typ)
if mut val_sym.info is ast.Alias { if mut val_sym.info is ast.Alias {
val_typ = val_sym.info.parent_type val_typ = val_sym.info.parent_type
val_sym = g.table.get_type_symbol(val_typ) val_sym = g.table.sym(val_typ)
} }
val_styp := g.typ(val_typ) val_styp := g.typ(val_typ)
elem_str_fn_name := val_styp.replace('*', '') + '_str' elem_str_fn_name := val_styp.replace('*', '') + '_str'
@ -790,7 +790,7 @@ fn (g &Gen) type_to_fmt(typ ast.Type) StrIntpType {
// return '%C\\000' // a C string // return '%C\\000' // a C string
return .si_s return .si_s
} }
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
if typ.is_ptr() && (typ.is_int_valptr() || typ.is_float_valptr()) { if typ.is_ptr() && (typ.is_int_valptr() || typ.is_float_valptr()) {
return .si_s return .si_s
} else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_,
@ -866,7 +866,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri
// manage prefix and quote symbol for the filed // manage prefix and quote symbol for the filed
mut quote_str := '' mut quote_str := ''
mut prefix := '' mut prefix := ''
sym := g.table.get_type_symbol(g.unwrap_generic(field.typ)) sym := g.table.sym(g.unwrap_generic(field.typ))
if sym.kind == .string { if sym.kind == .string {
quote_str = "'" quote_str = "'"
} else if field.typ in ast.charptr_types { } else if field.typ in ast.charptr_types {

View File

@ -745,7 +745,7 @@ pub fn (mut g Gen) write_typeof_functions() {
if g.pref.build_mode == .build_module { if g.pref.build_mode == .build_module {
g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return "${util.strip_main_name(sym.name)}";') g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return "${util.strip_main_name(sym.name)}";')
for v in sum_info.variants { for v in sum_info.variants {
subtype := g.table.get_type_symbol(v) subtype := g.table.sym(v)
g.writeln('\tif( sidx == _v_type_idx_${subtype.cname}() ) return "${util.strip_main_name(subtype.name)}";') g.writeln('\tif( sidx == _v_type_idx_${subtype.cname}() ) return "${util.strip_main_name(subtype.name)}";')
} }
g.writeln('\treturn "unknown ${util.strip_main_name(sym.name)}";') g.writeln('\treturn "unknown ${util.strip_main_name(sym.name)}";')
@ -754,7 +754,7 @@ pub fn (mut g Gen) write_typeof_functions() {
g.writeln('\tswitch(sidx) {') g.writeln('\tswitch(sidx) {')
g.writeln('\t\tcase $tidx: return "${util.strip_main_name(sym.name)}";') g.writeln('\t\tcase $tidx: return "${util.strip_main_name(sym.name)}";')
for v in sum_info.variants { for v in sum_info.variants {
subtype := g.table.get_type_symbol(v) subtype := g.table.sym(v)
g.writeln('\t\tcase $v: return "${util.strip_main_name(subtype.name)}";') g.writeln('\t\tcase $v: return "${util.strip_main_name(subtype.name)}";')
} }
g.writeln('\t\tdefault: return "unknown ${util.strip_main_name(sym.name)}";') g.writeln('\t\tdefault: return "unknown ${util.strip_main_name(sym.name)}";')
@ -766,7 +766,7 @@ pub fn (mut g Gen) write_typeof_functions() {
if g.pref.build_mode == .build_module { if g.pref.build_mode == .build_module {
g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return ${int(ityp)};') g.writeln('\t\tif( sidx == _v_type_idx_${sym.cname}() ) return ${int(ityp)};')
for v in sum_info.variants { for v in sum_info.variants {
subtype := g.table.get_type_symbol(v) subtype := g.table.sym(v)
g.writeln('\tif( sidx == _v_type_idx_${subtype.cname}() ) return ${int(v)};') g.writeln('\tif( sidx == _v_type_idx_${subtype.cname}() ) return ${int(v)};')
} }
g.writeln('\treturn ${int(ityp)};') g.writeln('\treturn ${int(ityp)};')
@ -792,7 +792,7 @@ pub fn (mut g Gen) write_typeof_functions() {
g.definitions.writeln('static char * v_typeof_interface_${sym.cname}(int sidx);') g.definitions.writeln('static char * v_typeof_interface_${sym.cname}(int sidx);')
g.writeln('static char * v_typeof_interface_${sym.cname}(int sidx) { /* $sym.name */ ') g.writeln('static char * v_typeof_interface_${sym.cname}(int sidx) { /* $sym.name */ ')
for t in inter_info.types { for t in inter_info.types {
subtype := g.table.get_type_symbol(t) subtype := g.table.sym(t)
g.writeln('\tif (sidx == _${sym.cname}_${subtype.cname}_index) return "${util.strip_main_name(subtype.name)}";') g.writeln('\tif (sidx == _${sym.cname}_${subtype.cname}_index) return "${util.strip_main_name(subtype.name)}";')
} }
g.writeln('\treturn "unknown ${util.strip_main_name(sym.name)}";') g.writeln('\treturn "unknown ${util.strip_main_name(sym.name)}";')
@ -800,7 +800,7 @@ pub fn (mut g Gen) write_typeof_functions() {
g.writeln('') g.writeln('')
g.writeln('static int v_typeof_interface_idx_${sym.cname}(int sidx) { /* $sym.name */ ') g.writeln('static int v_typeof_interface_idx_${sym.cname}(int sidx) { /* $sym.name */ ')
for t in inter_info.types { for t in inter_info.types {
subtype := g.table.get_type_symbol(t) subtype := g.table.sym(t)
g.writeln('\tif (sidx == _${sym.cname}_${subtype.cname}_index) return ${int(t)};') g.writeln('\tif (sidx == _${sym.cname}_${subtype.cname}_index) return ${int(t)};')
} }
g.writeln('\treturn ${int(ityp)};') g.writeln('\treturn ${int(ityp)};')
@ -1063,7 +1063,7 @@ static inline Option_void __Option_${styp}_pushval($styp ch, $el_type e) {
// cc_type whether to prefix 'struct' or not (C__Foo -> struct Foo) // cc_type whether to prefix 'struct' or not (C__Foo -> struct Foo)
fn (mut g Gen) cc_type(typ ast.Type, is_prefix_struct bool) string { fn (mut g Gen) cc_type(typ ast.Type, is_prefix_struct bool) string {
sym := g.table.get_type_symbol(g.unwrap_generic(typ)) sym := g.table.sym(g.unwrap_generic(typ))
mut styp := sym.cname mut styp := sym.cname
// TODO: this needs to be removed; cgen shouldn't resolve generic types (job of checker) // TODO: this needs to be removed; cgen shouldn't resolve generic types (job of checker)
match mut sym.info { match mut sym.info {
@ -1071,7 +1071,7 @@ fn (mut g Gen) cc_type(typ ast.Type, is_prefix_struct bool) string {
if sym.info.is_generic { if sym.info.is_generic {
mut sgtyps := '_T' mut sgtyps := '_T'
for gt in sym.info.generic_types { for gt in sym.info.generic_types {
gts := g.table.get_type_symbol(g.unwrap_generic(gt)) gts := g.table.sym(g.unwrap_generic(gt))
sgtyps += '_$gts.cname' sgtyps += '_$gts.cname'
} }
styp += sgtyps styp += sgtyps
@ -1094,7 +1094,7 @@ fn (mut g Gen) cc_type(typ ast.Type, is_prefix_struct bool) string {
[inline] [inline]
fn (g &Gen) type_sidx(t ast.Type) string { fn (g &Gen) type_sidx(t ast.Type) string {
if g.pref.build_mode == .build_module { if g.pref.build_mode == .build_module {
sym := g.table.get_type_symbol(t) sym := g.table.sym(t)
return '_v_type_idx_${sym.cname}()' return '_v_type_idx_${sym.cname}()'
} }
return t.idx().str() return t.idx().str()
@ -1109,14 +1109,14 @@ pub fn (mut g Gen) write_typedef_types() {
match sym.kind { match sym.kind {
.array { .array {
info := sym.info as ast.Array info := sym.info as ast.Array
elem_sym := g.table.get_type_symbol(info.elem_type) elem_sym := g.table.sym(info.elem_type)
if elem_sym.kind != .placeholder && !info.elem_type.has_flag(.generic) { if elem_sym.kind != .placeholder && !info.elem_type.has_flag(.generic) {
g.type_definitions.writeln('typedef array $sym.cname;') g.type_definitions.writeln('typedef array $sym.cname;')
} }
} }
.array_fixed { .array_fixed {
info := sym.info as ast.ArrayFixed info := sym.info as ast.ArrayFixed
elem_sym := g.table.get_type_symbol(info.elem_type) elem_sym := g.table.sym(info.elem_type)
if elem_sym.is_builtin() { if elem_sym.is_builtin() {
// .array_fixed { // .array_fixed {
styp := sym.cname styp := sym.cname
@ -1235,7 +1235,7 @@ pub fn (mut g Gen) write_interface_typesymbol_declaration(sym ast.TypeSymbol) {
g.type_definitions.writeln('\tunion {') g.type_definitions.writeln('\tunion {')
g.type_definitions.writeln('\t\tvoid* _object;') g.type_definitions.writeln('\t\tvoid* _object;')
for variant in info.types { for variant in info.types {
vcname := g.table.get_type_symbol(variant).cname vcname := g.table.sym(variant).cname
g.type_definitions.writeln('\t\t$vcname* _$vcname;') g.type_definitions.writeln('\t\t$vcname* _$vcname;')
} }
g.type_definitions.writeln('\t};') g.type_definitions.writeln('\t};')
@ -1755,7 +1755,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
ast.Import {} ast.Import {}
ast.InterfaceDecl { ast.InterfaceDecl {
// definitions are sorted and added in write_types // definitions are sorted and added in write_types
ts := g.table.get_type_symbol(node.typ) ts := g.table.sym(node.typ)
if !(ts.info as ast.Interface).is_generic { if !(ts.info as ast.Interface).is_generic {
for method in node.methods { for method in node.methods {
if method.return_type.has_flag(.optional) { if method.return_type.has_flag(.optional) {
@ -1791,7 +1791,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
// g.gen_attrs(node.attrs) // g.gen_attrs(node.attrs)
// g.writeln('typedef struct {') // g.writeln('typedef struct {')
// for field in it.fields { // for field in it.fields {
// field_type_sym := g.table.get_type_symbol(field.typ) // field_type_sym := g.table.sym(field.typ)
// g.writeln('\t$field_type_sym.name $field.name;') // g.writeln('\t$field_type_sym.name $field.name;')
// } // }
// g.writeln('} $name;') // g.writeln('} $name;')
@ -1976,7 +1976,7 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
// `for num in nums {` // `for num in nums {`
// g.writeln('// FOR IN array') // g.writeln('// FOR IN array')
styp := g.typ(node.val_type) styp := g.typ(node.val_type)
val_sym := g.table.get_type_symbol(node.val_type) val_sym := g.table.sym(node.val_type)
mut cond_var := '' mut cond_var := ''
if node.cond is ast.Ident || node.cond is ast.SelectorExpr { if node.cond is ast.Ident || node.cond is ast.SelectorExpr {
cond_var = g.expr_string(node.cond) cond_var = g.expr_string(node.cond)
@ -2040,11 +2040,11 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
cond_var = g.expr_string(node.cond) cond_var = g.expr_string(node.cond)
} }
idx := if node.key_var in ['', '_'] { g.new_tmp_var() } else { node.key_var } idx := if node.key_var in ['', '_'] { g.new_tmp_var() } else { node.key_var }
cond_sym := g.table.get_type_symbol(node.cond_type) cond_sym := g.table.sym(node.cond_type)
info := cond_sym.info as ast.ArrayFixed info := cond_sym.info as ast.ArrayFixed
g.writeln('for (int $idx = 0; $idx != $info.size; ++$idx) {') g.writeln('for (int $idx = 0; $idx != $info.size; ++$idx) {')
if node.val_var != '_' { if node.val_var != '_' {
val_sym := g.table.get_type_symbol(node.val_type) val_sym := g.table.sym(node.val_type)
is_fixed_array := val_sym.kind == .array_fixed && !node.val_is_mut is_fixed_array := val_sym.kind == .array_fixed && !node.val_is_mut
if val_sym.kind == .function { if val_sym.kind == .function {
g.write('\t') g.write('\t')
@ -2113,7 +2113,7 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
} }
} }
if node.val_var != '_' { if node.val_var != '_' {
val_sym := g.table.get_type_symbol(node.val_type) val_sym := g.table.sym(node.val_type)
if val_sym.kind == .function { if val_sym.kind == .function {
g.write_fn_ptr_decl(val_sym.info as ast.FnType, c_name(node.val_var)) g.write_fn_ptr_decl(val_sym.info as ast.FnType, c_name(node.val_var))
g.write(' = (*(voidptr*)') g.write(' = (*(voidptr*)')
@ -2153,7 +2153,7 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
g.writeln('.str[$i];') g.writeln('.str[$i];')
} }
} else if node.kind == .struct_ { } else if node.kind == .struct_ {
cond_type_sym := g.table.get_type_symbol(node.cond_type) cond_type_sym := g.table.sym(node.cond_type)
next_fn := cond_type_sym.find_method_with_generic_parent('next') or { next_fn := cond_type_sym.find_method_with_generic_parent('next') or {
verror('`next` method not found') verror('`next` method not found')
return return
@ -2172,7 +2172,7 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) {
receiver_typ := next_fn.params[0].typ receiver_typ := next_fn.params[0].typ
receiver_styp := g.typ(receiver_typ) receiver_styp := g.typ(receiver_typ)
mut fn_name := receiver_styp.replace_each(['*', '', '.', '__']) + '_next' mut fn_name := receiver_styp.replace_each(['*', '', '.', '__']) + '_next'
receiver_sym := g.table.get_type_symbol(receiver_typ) receiver_sym := g.table.sym(receiver_typ)
if receiver_sym.info is ast.Struct { if receiver_sym.info is ast.Struct {
if receiver_sym.info.concrete_types.len > 0 { if receiver_sym.info.concrete_types.len > 0 {
fn_name = g.generic_fn_name(receiver_sym.info.concrete_types, fn_name, fn_name = g.generic_fn_name(receiver_sym.info.concrete_types, fn_name,
@ -2226,7 +2226,7 @@ struct SumtypeCastingFn {
fn (mut g Gen) get_sumtype_casting_fn(got_ ast.Type, exp_ ast.Type) string { fn (mut g Gen) get_sumtype_casting_fn(got_ ast.Type, exp_ ast.Type) string {
got, exp := got_.idx(), exp_.idx() got, exp := got_.idx(), exp_.idx()
i := got | int(u32(exp) << 16) i := got | int(u32(exp) << 16)
got_cname, exp_cname := g.table.get_type_symbol(got).cname, g.table.get_type_symbol(exp).cname got_cname, exp_cname := g.table.sym(got).cname, g.table.sym(exp).cname
fn_name := '${got_cname}_to_sumtype_$exp_cname' fn_name := '${got_cname}_to_sumtype_$exp_cname'
if got == exp || g.sumtype_definitions[i] { if got == exp || g.sumtype_definitions[i] {
return fn_name return fn_name
@ -2242,7 +2242,7 @@ fn (mut g Gen) get_sumtype_casting_fn(got_ ast.Type, exp_ ast.Type) string {
fn (mut g Gen) write_sumtype_casting_fn(fun SumtypeCastingFn) { fn (mut g Gen) write_sumtype_casting_fn(fun SumtypeCastingFn) {
got, exp := fun.got, fun.exp got, exp := fun.got, fun.exp
got_sym, exp_sym := g.table.get_type_symbol(got), g.table.get_type_symbol(exp) got_sym, exp_sym := g.table.sym(got), g.table.sym(exp)
got_cname, exp_cname := got_sym.cname, exp_sym.cname got_cname, exp_cname := got_sym.cname, exp_sym.cname
mut sb := strings.new_builder(128) mut sb := strings.new_builder(128)
sb.writeln('static inline $exp_cname ${fun.fn_name}($got_cname* x) {') sb.writeln('static inline $exp_cname ${fun.fn_name}($got_cname* x) {')
@ -2253,7 +2253,7 @@ fn (mut g Gen) write_sumtype_casting_fn(fun SumtypeCastingFn) {
mut embed_name := '' mut embed_name := ''
mut accessor := '&x->' mut accessor := '&x->'
for j, embed in embed_hierarchy { for j, embed in embed_hierarchy {
embed_sym := g.table.get_type_symbol(embed) embed_sym := g.table.sym(embed)
embed_cname = embed_sym.cname embed_cname = embed_sym.cname
embed_name = embed_sym.embed_name() embed_name = embed_sym.embed_name()
if j > 0 { if j > 0 {
@ -2272,7 +2272,7 @@ fn (mut g Gen) write_sumtype_casting_fn(fun SumtypeCastingFn) {
ast.StructField{}, []ast.Type{} ast.StructField{}, []ast.Type{}
} }
if embed_types.len > 0 { if embed_types.len > 0 {
embed_sym := g.table.get_type_symbol(embed_types.last()) embed_sym := g.table.sym(embed_types.last())
ptr = '${embed_sym.embed_name()}_ptr' ptr = '${embed_sym.embed_name()}_ptr'
type_cname = embed_sym.cname type_cname = embed_sym.cname
} }
@ -2311,8 +2311,8 @@ fn (mut g Gen) call_cfn_for_casting_expr(fname string, expr ast.Expr, exp_is_ptr
// use instead of expr() when you need to cast to a different type // use instead of expr() when you need to cast to a different type
fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_type ast.Type) { fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_type ast.Type) {
got_type := g.table.mktyp(got_type_raw) got_type := g.table.mktyp(got_type_raw)
exp_sym := g.table.get_type_symbol(expected_type) exp_sym := g.table.sym(expected_type)
got_sym := g.table.get_type_symbol(got_type) got_sym := g.table.sym(got_type)
expected_is_ptr := expected_type.is_ptr() expected_is_ptr := expected_type.is_ptr()
got_is_ptr := got_type.is_ptr() got_is_ptr := got_type.is_ptr()
// allow using the new Error struct as a string, to avoid a breaking change // allow using the new Error struct as a string, to avoid a breaking change
@ -2364,8 +2364,8 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ
if expected_type != ast.void_type { if expected_type != ast.void_type {
unwrapped_expected_type := g.unwrap_generic(expected_type) unwrapped_expected_type := g.unwrap_generic(expected_type)
unwrapped_got_type := g.unwrap_generic(got_type) unwrapped_got_type := g.unwrap_generic(got_type)
unwrapped_exp_sym := g.table.get_type_symbol(unwrapped_expected_type) unwrapped_exp_sym := g.table.sym(unwrapped_expected_type)
unwrapped_got_sym := g.table.get_type_symbol(unwrapped_got_type) unwrapped_got_sym := g.table.sym(unwrapped_got_type)
expected_deref_type := if expected_is_ptr { expected_deref_type := if expected_is_ptr {
unwrapped_expected_type.deref() unwrapped_expected_type.deref()
@ -2427,7 +2427,7 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ
if got_is_ptr && !expected_is_ptr && neither_void && exp_sym.kind != .placeholder if got_is_ptr && !expected_is_ptr && neither_void && exp_sym.kind != .placeholder
&& expr !is ast.InfixExpr { && expr !is ast.InfixExpr {
got_deref_type := got_type.deref() got_deref_type := got_type.deref()
deref_sym := g.table.get_type_symbol(got_deref_type) deref_sym := g.table.sym(got_deref_type)
deref_will_match := expected_type in [got_type, got_deref_type, deref_sym.parent_idx] deref_will_match := expected_type in [got_type, got_deref_type, deref_sym.parent_idx]
got_is_opt := got_type.has_flag(.optional) got_is_opt := got_type.has_flag(.optional)
if deref_will_match || got_is_opt || expr.is_auto_deref_var() { if deref_will_match || got_is_opt || expr.is_auto_deref_var() {
@ -2725,7 +2725,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
mut type_to_free := '' mut type_to_free := ''
if af { if af {
first_left_type := assign_stmt.left_types[0] first_left_type := assign_stmt.left_types[0]
first_left_sym := g.table.get_type_symbol(assign_stmt.left_types[0]) first_left_sym := g.table.sym(assign_stmt.left_types[0])
if first_left_type == ast.string_type || first_left_sym.kind == .array { if first_left_type == ast.string_type || first_left_sym.kind == .array {
type_to_free = if first_left_type == ast.string_type { 'string' } else { 'array' } type_to_free = if first_left_type == ast.string_type { 'string' } else { 'array' }
mut ok := true mut ok := true
@ -2795,7 +2795,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
*/ */
// json_test failed w/o this check // json_test failed w/o this check
if return_type != ast.void_type && return_type != 0 { if return_type != ast.void_type && return_type != 0 {
sym := g.table.get_type_symbol(return_type) sym := g.table.sym(return_type)
if sym.kind == .multi_return { if sym.kind == .multi_return {
// multi return // multi return
// TODO Handle in if_expr // TODO Handle in if_expr
@ -2879,7 +2879,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
match left { match left {
ast.Ident { ast.Ident {
left_typ := assign_stmt.left_types[i] left_typ := assign_stmt.left_types[i]
left_sym := g.table.get_type_symbol(left_typ) left_sym := g.table.sym(left_typ)
if left_sym.kind == .function { if left_sym.kind == .function {
g.write_fn_ptr_decl(left_sym.info as ast.FnType, '_var_$left.pos.pos') g.write_fn_ptr_decl(left_sym.info as ast.FnType, '_var_$left.pos.pos')
g.writeln(' = $left.name;') g.writeln(' = $left.name;')
@ -2889,13 +2889,13 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
} }
} }
ast.IndexExpr { ast.IndexExpr {
sym := g.table.get_type_symbol(left.left_type) sym := g.table.sym(left.left_type)
if sym.kind == .array { if sym.kind == .array {
info := sym.info as ast.Array info := sym.info as ast.Array
elem_typ := g.table.get_type_symbol(info.elem_type) elem_typ := g.table.sym(info.elem_type)
if elem_typ.kind == .function { if elem_typ.kind == .function {
left_typ := assign_stmt.left_types[i] left_typ := assign_stmt.left_types[i]
left_sym := g.table.get_type_symbol(left_typ) left_sym := g.table.sym(left_typ)
g.write_fn_ptr_decl(left_sym.info as ast.FnType, '_var_$left.pos.pos') g.write_fn_ptr_decl(left_sym.info as ast.FnType, '_var_$left.pos.pos')
g.write(' = *(voidptr*)array_get(') g.write(' = *(voidptr*)array_get(')
} else { } else {
@ -2921,10 +2921,10 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
skeytyp := g.typ(info.key_type) skeytyp := g.typ(info.key_type)
styp := g.typ(info.value_type) styp := g.typ(info.value_type)
zero := g.type_default(info.value_type) zero := g.type_default(info.value_type)
val_typ := g.table.get_type_symbol(info.value_type) val_typ := g.table.sym(info.value_type)
if val_typ.kind == .function { if val_typ.kind == .function {
left_type := assign_stmt.left_types[i] left_type := assign_stmt.left_types[i]
left_sym := g.table.get_type_symbol(left_type) left_sym := g.table.sym(left_type)
g.write_fn_ptr_decl(left_sym.info as ast.FnType, '_var_$left.pos.pos') g.write_fn_ptr_decl(left_sym.info as ast.FnType, '_var_$left.pos.pos')
g.write(' = *(voidptr*)map_get(') g.write(' = *(voidptr*)map_get(')
} else { } else {
@ -2986,7 +2986,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
mut ident := ast.Ident{ mut ident := ast.Ident{
scope: 0 scope: 0
} }
left_sym := g.table.get_type_symbol(g.unwrap_generic(var_type)) left_sym := g.table.sym(g.unwrap_generic(var_type))
if mut left is ast.Ident { if mut left is ast.Ident {
ident = left ident = left
// id_info := ident.var_info() // id_info := ident.var_info()
@ -3052,7 +3052,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
g.is_assign_lhs = false g.is_assign_lhs = false
g.is_arraymap_set = false g.is_arraymap_set = false
if left is ast.IndexExpr { if left is ast.IndexExpr {
sym := g.table.get_type_symbol(left.left_type) sym := g.table.sym(left.left_type)
if sym.kind in [.map, .array] { if sym.kind in [.map, .array] {
g.expr(val) g.expr(val)
g.writeln('});') g.writeln('});')
@ -3071,8 +3071,8 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
else {} else {}
} }
unwrapped_val_type := g.unwrap_generic(val_type) unwrapped_val_type := g.unwrap_generic(val_type)
right_sym := g.table.get_type_symbol(unwrapped_val_type) right_sym := g.table.sym(unwrapped_val_type)
unaliased_right_sym := g.table.get_final_type_symbol(unwrapped_val_type) unaliased_right_sym := g.table.final_sym(unwrapped_val_type)
is_fixed_array_var := unaliased_right_sym.kind == .array_fixed && val !is ast.ArrayInit is_fixed_array_var := unaliased_right_sym.kind == .array_fixed && val !is ast.ArrayInit
&& (val in [ast.Ident, ast.IndexExpr, ast.CallExpr, ast.SelectorExpr] && (val in [ast.Ident, ast.IndexExpr, ast.CallExpr, ast.SelectorExpr]
|| (val is ast.CastExpr && (val as ast.CastExpr).expr !is ast.ArrayInit)) || (val is ast.CastExpr && (val as ast.CastExpr).expr !is ast.ArrayInit))
@ -3208,7 +3208,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
} }
mut is_used_var_styp := false mut is_used_var_styp := false
if ident.name !in g.defer_vars { if ident.name !in g.defer_vars {
val_sym := g.table.get_type_symbol(val_type) val_sym := g.table.sym(val_type)
if val_sym.info is ast.Struct { if val_sym.info is ast.Struct {
if val_sym.info.generic_types.len > 0 { if val_sym.info.generic_types.len > 0 {
if val is ast.StructInit { if val is ast.StructInit {
@ -3376,7 +3376,7 @@ fn (mut g Gen) gen_cross_tmp_variable(left []ast.Expr, val ast.Expr) {
} }
} }
ast.InfixExpr { ast.InfixExpr {
sym := g.table.get_type_symbol(val.left_type) sym := g.table.sym(val.left_type)
if _ := g.table.find_method(sym, val.op.str()) { if _ := g.table.find_method(sym, val.op.str()) {
left_styp := g.typ(val.left_type.set_nr_muls(0)) left_styp := g.typ(val.left_type.set_nr_muls(0))
g.write(left_styp) g.write(left_styp)
@ -3445,7 +3445,7 @@ fn (mut g Gen) gen_clone_assignment(val ast.Expr, typ ast.Type, add_eq bool) boo
if val !is ast.Ident && val !is ast.SelectorExpr { if val !is ast.Ident && val !is ast.SelectorExpr {
return false return false
} }
right_sym := g.table.get_type_symbol(typ) right_sym := g.table.sym(typ)
if g.is_autofree { if g.is_autofree {
if add_eq { if add_eq {
g.write('=') g.write('=')
@ -3570,7 +3570,7 @@ fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int
} }
fn (mut g Gen) autofree_variable(v ast.Var) { fn (mut g Gen) autofree_variable(v ast.Var) {
sym := g.table.get_type_symbol(v.typ) sym := g.table.sym(v.typ)
// if v.name.contains('output2') { // if v.name.contains('output2') {
if g.is_autofree { if g.is_autofree {
// eprintln(' > var name: ${v.name:-20s} | is_arg: ${v.is_arg.str():6} | var type: ${int(v.typ):8} | type_name: ${sym.name:-33s}') // eprintln(' > var name: ${v.name:-20s} | is_arg: ${v.is_arg.str():6} | var type: ${int(v.typ):8} | type_name: ${sym.name:-33s}')
@ -3688,9 +3688,9 @@ fn (mut g Gen) map_fn_ptrs(key_typ ast.TypeSymbol) (string, string, string, stri
} }
.voidptr { .voidptr {
ts := if g.pref.m64 { ts := if g.pref.m64 {
unsafe { g.table.get_type_symbol_by_idx(ast.u64_type_idx) } unsafe { g.table.sym_by_idx(ast.u64_type_idx) }
} else { } else {
unsafe { g.table.get_type_symbol_by_idx(ast.u32_type_idx) } unsafe { g.table.sym_by_idx(ast.u32_type_idx) }
} }
return g.map_fn_ptrs(ts) return g.map_fn_ptrs(ts)
} }
@ -3759,7 +3759,7 @@ fn (mut g Gen) expr(node ast.Expr) {
} }
mut shared_styp := '' mut shared_styp := ''
if g.is_shared && !ret_type.has_flag(.shared_f) { if g.is_shared && !ret_type.has_flag(.shared_f) {
ret_sym := g.table.get_type_symbol(ret_type) ret_sym := g.table.sym(ret_type)
shared_typ := ret_type.set_flag(.shared_f) shared_typ := ret_type.set_flag(.shared_f)
shared_styp = g.typ(shared_typ) shared_styp = g.typ(shared_typ)
if ret_sym.kind == .array { if ret_sym.kind == .array {
@ -3906,7 +3906,7 @@ fn (mut g Gen) expr(node ast.Expr) {
node.typ node.typ
} }
node_typ := g.unwrap_generic(typ) node_typ := g.unwrap_generic(typ)
sym := g.table.get_type_symbol(node_typ) sym := g.table.sym(node_typ)
if sym.language == .v && sym.kind in [.placeholder, .any] { if sym.language == .v && sym.kind in [.placeholder, .any] {
g.error('unknown type `$sym.name`', node.pos) g.error('unknown type `$sym.name`', node.pos)
} }
@ -3974,7 +3974,7 @@ fn (mut g Gen) expr(node ast.Expr) {
} }
if node.op == .arrow { if node.op == .arrow {
styp := g.typ(node.right_type) styp := g.typ(node.right_type)
right_sym := g.table.get_type_symbol(node.right_type) right_sym := g.table.sym(node.right_type)
mut right_inf := right_sym.info as ast.Chan mut right_inf := right_sym.info as ast.Chan
elem_type := right_inf.elem_type elem_type := right_inf.elem_type
is_gen_or_and_assign_rhs := gen_or && !g.discard_or_result is_gen_or_and_assign_rhs := gen_or && !g.discard_or_result
@ -4030,7 +4030,7 @@ fn (mut g Gen) expr(node ast.Expr) {
node.typ node.typ
} }
node_typ := g.unwrap_generic(typ) node_typ := g.unwrap_generic(typ)
sym := g.table.get_type_symbol(node_typ) sym := g.table.sym(node_typ)
if sym.language == .v && sym.kind in [.placeholder, .any] { if sym.language == .v && sym.kind in [.placeholder, .any] {
g.error('unknown type `$sym.name`', node.pos) g.error('unknown type `$sym.name`', node.pos)
} }
@ -4059,7 +4059,7 @@ fn (mut g Gen) expr(node ast.Expr) {
// g.write('/* Type */') // g.write('/* Type */')
// type_idx := node.typ.idx() // type_idx := node.typ.idx()
typ := g.unwrap_generic(node.typ) typ := g.unwrap_generic(node.typ)
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
sidx := g.type_sidx(typ) sidx := g.type_sidx(typ)
// g.write('$type_idx /* $sym.name */') // g.write('$type_idx /* $sym.name */')
g.write('$sidx /* $sym.name */') g.write('$sidx /* $sym.name */')
@ -4078,7 +4078,7 @@ fn (mut g Gen) expr(node ast.Expr) {
// T.name, typeof(expr).name // T.name, typeof(expr).name
fn (mut g Gen) type_name(raw_type ast.Type) { fn (mut g Gen) type_name(raw_type ast.Type) {
typ := if raw_type == g.field_data_type { g.comptime_for_field_value.typ } else { raw_type } typ := if raw_type == g.field_data_type { g.comptime_for_field_value.typ } else { raw_type }
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
mut s := '' mut s := ''
if sym.kind == .function { if sym.kind == .function {
if typ.is_ptr() { if typ.is_ptr() {
@ -4098,7 +4098,7 @@ fn (mut g Gen) typeof_expr(node ast.TypeOf) {
} else { } else {
node.expr_type node.expr_type
} }
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
if sym.kind == .sum_type { if sym.kind == .sum_type {
// When encountering a .sum_type, typeof() should be done at runtime, // When encountering a .sum_type, typeof() should be done at runtime,
// because the subtype of the expression may change: // because the subtype of the expression may change:
@ -4113,7 +4113,7 @@ fn (mut g Gen) typeof_expr(node ast.TypeOf) {
info := sym.info as ast.FnType info := sym.info as ast.FnType
g.write('_SLIT("${g.fn_decl_str(info)}")') g.write('_SLIT("${g.fn_decl_str(info)}")')
} else if typ.has_flag(.variadic) { } else if typ.has_flag(.variadic) {
varg_elem_type_sym := g.table.get_type_symbol(g.table.value_type(typ)) varg_elem_type_sym := g.table.sym(g.table.value_type(typ))
g.write('_SLIT("...${util.strip_main_name(varg_elem_type_sym.name)}")') g.write('_SLIT("...${util.strip_main_name(varg_elem_type_sym.name)}")')
} else { } else {
x := g.table.type_to_str(typ) x := g.table.type_to_str(typ)
@ -4163,7 +4163,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
if node.expr_type == 0 { if node.expr_type == 0 {
g.checker_bug('unexpected SelectorExpr.expr_type = 0', node.pos) g.checker_bug('unexpected SelectorExpr.expr_type = 0', node.pos)
} }
sym := g.table.get_type_symbol(g.unwrap_generic(node.expr_type)) sym := g.table.sym(g.unwrap_generic(node.expr_type))
// if node expr is a root ident and an optional // if node expr is a root ident and an optional
mut is_optional := node.expr is ast.Ident && node.expr_type.has_flag(.optional) mut is_optional := node.expr is ast.Ident && node.expr_type.has_flag(.optional)
if is_optional { if is_optional {
@ -4190,7 +4190,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
mut sum_type_deref_field := '' mut sum_type_deref_field := ''
mut sum_type_dot := '.' mut sum_type_dot := '.'
if f := g.table.find_field(sym, node.field_name) { if f := g.table.find_field(sym, node.field_name) {
field_sym := g.table.get_type_symbol(f.typ) field_sym := g.table.sym(f.typ)
if field_sym.kind in [.sum_type, .interface_] { if field_sym.kind in [.sum_type, .interface_] {
if !prevent_sum_type_unwrapping_once { if !prevent_sum_type_unwrapping_once {
// check first if field is sum type because scope searching is expensive // check first if field is sum type because scope searching is expensive
@ -4204,13 +4204,13 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
if field_sym.kind == .sum_type { if field_sym.kind == .sum_type {
g.write('*') g.write('*')
} }
cast_sym := g.table.get_type_symbol(typ) cast_sym := g.table.sym(typ)
if i != 0 { if i != 0 {
dot := if field.typ.is_ptr() { '->' } else { '.' } dot := if field.typ.is_ptr() { '->' } else { '.' }
sum_type_deref_field += ')$dot' sum_type_deref_field += ')$dot'
} }
if mut cast_sym.info is ast.Aggregate { if mut cast_sym.info is ast.Aggregate {
agg_sym := g.table.get_type_symbol(cast_sym.info.types[g.aggregate_type_idx]) agg_sym := g.table.sym(cast_sym.info.types[g.aggregate_type_idx])
sum_type_deref_field += '_$agg_sym.cname' sum_type_deref_field += '_$agg_sym.cname'
} else { } else {
sum_type_deref_field += '_$cast_sym.cname' sum_type_deref_field += '_$cast_sym.cname'
@ -4235,7 +4235,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
// struct embedding // struct embedding
if sym.info in [ast.Struct, ast.Aggregate] { if sym.info in [ast.Struct, ast.Aggregate] {
for embed in node.from_embed_types { for embed in node.from_embed_types {
embed_sym := g.table.get_type_symbol(embed) embed_sym := g.table.sym(embed)
embed_name := embed_sym.embed_name() embed_name := embed_sym.embed_name()
if node.expr_type.is_ptr() { if node.expr_type.is_ptr() {
g.write('->') g.write('->')
@ -4381,8 +4381,8 @@ fn (mut g Gen) unlock_locks() {
fn (mut g Gen) need_tmp_var_in_match(node ast.MatchExpr) bool { fn (mut g Gen) need_tmp_var_in_match(node ast.MatchExpr) bool {
if node.is_expr && node.return_type != ast.void_type && node.return_type != 0 { if node.is_expr && node.return_type != ast.void_type && node.return_type != 0 {
cond_sym := g.table.get_final_type_symbol(node.cond_type) cond_sym := g.table.final_sym(node.cond_type)
sym := g.table.get_type_symbol(node.return_type) sym := g.table.sym(node.return_type)
if g.table.type_kind(node.return_type) == .sum_type { if g.table.type_kind(node.return_type) == .sum_type {
return true return true
} }
@ -4465,7 +4465,7 @@ fn (mut g Gen) match_expr(node ast.MatchExpr) {
// brackets needed otherwise '?' will apply to everything on the left // brackets needed otherwise '?' will apply to everything on the left
g.write('(') g.write('(')
} }
typ := g.table.get_final_type_symbol(node.cond_type) typ := g.table.final_sym(node.cond_type)
if node.is_sum_type { if node.is_sum_type {
g.match_expr_sumtype(node, is_expr, cond_var, tmp_var) g.match_expr_sumtype(node, is_expr, cond_var, tmp_var)
} else if typ.kind == .enum_ && g.loop_depth == 0 && node.branches.len > 5 && g.fn_decl != 0 { // do not optimize while in top-level } else if typ.kind == .enum_ && g.loop_depth == 0 && node.branches.len > 5 && g.fn_decl != 0 { // do not optimize while in top-level
@ -4491,7 +4491,7 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str
for { for {
g.aggregate_type_idx = sumtype_index g.aggregate_type_idx = sumtype_index
is_last := j == node.branches.len - 1 is_last := j == node.branches.len - 1
sym := g.table.get_type_symbol(node.cond_type) sym := g.table.sym(node.cond_type)
if branch.is_else || (node.is_expr && is_last && tmp_var.len == 0) { if branch.is_else || (node.is_expr && is_last && tmp_var.len == 0) {
if is_expr && tmp_var.len == 0 { if is_expr && tmp_var.len == 0 {
// TODO too many branches. maybe separate ?: matches // TODO too many branches. maybe separate ?: matches
@ -4527,7 +4527,7 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str
} else if sym.kind == .interface_ { } else if sym.kind == .interface_ {
if branch.exprs[sumtype_index] is ast.TypeNode { if branch.exprs[sumtype_index] is ast.TypeNode {
typ := branch.exprs[sumtype_index] as ast.TypeNode typ := branch.exprs[sumtype_index] as ast.TypeNode
branch_sym := g.table.get_type_symbol(g.unwrap_generic(typ.typ)) branch_sym := g.table.sym(g.unwrap_generic(typ.typ))
g.write('${dot_or_ptr}_typ == _${sym.cname}_${branch_sym.cname}_index') g.write('${dot_or_ptr}_typ == _${sym.cname}_${branch_sym.cname}_index')
} else if branch.exprs[sumtype_index] is ast.None && sym.name == 'IError' { } else if branch.exprs[sumtype_index] is ast.None && sym.name == 'IError' {
g.write('${dot_or_ptr}_typ == _IError_None___index') g.write('${dot_or_ptr}_typ == _IError_None___index')
@ -4539,8 +4539,7 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str
g.writeln(') {') g.writeln(') {')
} }
} }
if is_expr && tmp_var.len > 0 if is_expr && tmp_var.len > 0 && g.table.sym(node.return_type).kind == .sum_type {
&& g.table.get_type_symbol(node.return_type).kind == .sum_type {
g.expected_cast_type = node.return_type g.expected_cast_type = node.return_type
} }
g.stmts_with_tmp_var(branch.stmts, tmp_var) g.stmts_with_tmp_var(branch.stmts, tmp_var)
@ -4631,7 +4630,7 @@ fn (mut g Gen) match_expr_switch(node ast.MatchExpr, is_expr bool, cond_var stri
} }
g.indent++ g.indent++
g.writeln('{') g.writeln('{')
if is_expr && tmp_var.len > 0 && g.table.get_type_symbol(node.return_type).kind == .sum_type { if is_expr && tmp_var.len > 0 && g.table.sym(node.return_type).kind == .sum_type {
g.expected_cast_type = node.return_type g.expected_cast_type = node.return_type
} }
g.stmts_with_tmp_var(branch.stmts, tmp_var) g.stmts_with_tmp_var(branch.stmts, tmp_var)
@ -4684,7 +4683,7 @@ fn (mut g Gen) match_expr_switch(node ast.MatchExpr, is_expr bool, cond_var stri
} }
fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var string, tmp_var string) { fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var string, tmp_var string) {
type_sym := g.table.get_type_symbol(node.cond_type) type_sym := g.table.sym(node.cond_type)
for j, branch in node.branches { for j, branch in node.branches {
is_last := j == node.branches.len - 1 is_last := j == node.branches.len - 1
if branch.is_else || (node.is_expr && is_last && tmp_var.len == 0) { if branch.is_else || (node.is_expr && is_last && tmp_var.len == 0) {
@ -4784,7 +4783,7 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str
g.writeln(') {') g.writeln(') {')
} }
} }
if is_expr && tmp_var.len > 0 && g.table.get_type_symbol(node.return_type).kind == .sum_type { if is_expr && tmp_var.len > 0 && g.table.sym(node.return_type).kind == .sum_type {
g.expected_cast_type = node.return_type g.expected_cast_type = node.return_type
} }
g.stmts_with_tmp_var(branch.stmts, tmp_var) g.stmts_with_tmp_var(branch.stmts, tmp_var)
@ -4800,8 +4799,8 @@ fn (mut g Gen) map_init(node ast.MapInit) {
unwrap_val_typ := g.unwrap_generic(node.value_type) unwrap_val_typ := g.unwrap_generic(node.value_type)
key_typ_str := g.typ(unwrap_key_typ) key_typ_str := g.typ(unwrap_key_typ)
value_typ_str := g.typ(unwrap_val_typ) value_typ_str := g.typ(unwrap_val_typ)
value_typ := g.table.get_type_symbol(unwrap_val_typ) value_typ := g.table.sym(unwrap_val_typ)
key_typ := g.table.get_final_type_symbol(unwrap_key_typ) key_typ := g.table.final_sym(unwrap_key_typ)
hash_fn, key_eq_fn, clone_fn, free_fn := g.map_fn_ptrs(key_typ) hash_fn, key_eq_fn, clone_fn, free_fn := g.map_fn_ptrs(key_typ)
size := node.vals.len size := node.vals.len
mut shared_styp := '' // only needed for shared &[]{...} mut shared_styp := '' // only needed for shared &[]{...}
@ -5056,7 +5055,7 @@ fn (mut g Gen) ident(node ast.Ident) {
g.write('(*(') g.write('(*(')
} }
if v.smartcasts.len > 0 { if v.smartcasts.len > 0 {
v_sym := g.table.get_type_symbol(v.typ) v_sym := g.table.sym(v.typ)
if !prevent_sum_type_unwrapping_once { if !prevent_sum_type_unwrapping_once {
for _ in v.smartcasts { for _ in v.smartcasts {
g.write('(') g.write('(')
@ -5065,7 +5064,7 @@ fn (mut g Gen) ident(node ast.Ident) {
} }
} }
for i, typ in v.smartcasts { for i, typ in v.smartcasts {
cast_sym := g.table.get_type_symbol(g.unwrap_generic(typ)) cast_sym := g.table.sym(g.unwrap_generic(typ))
mut is_ptr := false mut is_ptr := false
if i == 0 { if i == 0 {
g.write(name) g.write(name)
@ -5075,7 +5074,7 @@ fn (mut g Gen) ident(node ast.Ident) {
} }
dot := if is_ptr || is_auto_heap { '->' } else { '.' } dot := if is_ptr || is_auto_heap { '->' } else { '.' }
if mut cast_sym.info is ast.Aggregate { if mut cast_sym.info is ast.Aggregate {
sym := g.table.get_type_symbol(cast_sym.info.types[g.aggregate_type_idx]) sym := g.table.sym(cast_sym.info.types[g.aggregate_type_idx])
g.write('${dot}_$sym.cname') g.write('${dot}_$sym.cname')
} else { } else {
g.write('${dot}_$cast_sym.cname') g.write('${dot}_$cast_sym.cname')
@ -5122,7 +5121,7 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
g.out.go_back(1) g.out.go_back(1)
} }
g.is_amp = false g.is_amp = false
sym := g.table.get_type_symbol(node.typ) sym := g.table.sym(node.typ)
if sym.kind in [.sum_type, .interface_] { if sym.kind in [.sum_type, .interface_] {
g.expr_with_cast(node.expr, node.expr_type, node.typ) g.expr_with_cast(node.expr, node.expr_type, node.typ)
} else if sym.kind == .struct_ && !node.typ.is_ptr() && !(sym.info as ast.Struct).is_typedef { } else if sym.kind == .struct_ && !node.typ.is_ptr() && !(sym.info as ast.Struct).is_typedef {
@ -5131,7 +5130,7 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
g.write('*(($styp *)(&') g.write('*(($styp *)(&')
g.expr(node.expr) g.expr(node.expr)
g.write('))') g.write('))')
} else if sym.kind == .alias && g.table.get_final_type_symbol(node.typ).kind == .array_fixed { } else if sym.kind == .alias && g.table.final_sym(node.typ).kind == .array_fixed {
g.expr(node.expr) g.expr(node.expr)
} else { } else {
styp := g.typ(node.typ) styp := g.typ(node.typ)
@ -5172,7 +5171,7 @@ fn (mut g Gen) concat_expr(node ast.ConcatExpr) {
if g.inside_return { if g.inside_return {
styp = g.typ(g.fn_decl.return_type) styp = g.typ(g.fn_decl.return_type)
} }
sym := g.table.get_type_symbol(node.return_type) sym := g.table.sym(node.return_type)
is_multi := sym.kind == .multi_return is_multi := sym.kind == .multi_return
if !is_multi { if !is_multi {
g.expr(node.vals[0]) g.expr(node.vals[0])
@ -5206,7 +5205,7 @@ fn (mut g Gen) need_tmp_var_in_if(node ast.IfExpr) bool {
} }
if stmt.expr is ast.CallExpr { if stmt.expr is ast.CallExpr {
if stmt.expr.is_method { if stmt.expr.is_method {
left_sym := g.table.get_type_symbol(stmt.expr.receiver_type) left_sym := g.table.sym(stmt.expr.receiver_type)
if left_sym.kind in [.array, .array_fixed, .map] { if left_sym.kind in [.array, .array_fixed, .map] {
return true return true
} }
@ -5394,7 +5393,7 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
[inline] [inline]
fn (g &Gen) expr_is_multi_return_call(expr ast.Expr) bool { fn (g &Gen) expr_is_multi_return_call(expr ast.Expr) bool {
match expr { match expr {
ast.CallExpr { return g.table.get_type_symbol(expr.return_type).kind == .multi_return } ast.CallExpr { return g.table.sym(expr.return_type).kind == .multi_return }
else { return false } else { return false }
} }
} }
@ -5424,7 +5423,7 @@ fn (mut g Gen) return_stmt(node ast.Return) {
} }
// got to do a correct check for multireturn // got to do a correct check for multireturn
sym := g.table.get_type_symbol(g.fn_decl.return_type) sym := g.table.sym(g.fn_decl.return_type)
fn_return_is_multi := sym.kind == .multi_return fn_return_is_multi := sym.kind == .multi_return
fn_return_is_optional := g.fn_decl.return_type.has_flag(.optional) fn_return_is_optional := g.fn_decl.return_type.has_flag(.optional)
mut has_semicolon := false mut has_semicolon := false
@ -5485,7 +5484,7 @@ fn (mut g Gen) return_stmt(node ast.Return) {
g.writeln('return $tmpvar;') g.writeln('return $tmpvar;')
return return
} }
// typ_sym := g.table.get_type_symbol(g.fn_decl.return_type) // typ_sym := g.table.sym(g.fn_decl.return_type)
// mr_info := typ_sym.info as ast.MultiReturn // mr_info := typ_sym.info as ast.MultiReturn
mut styp := '' mut styp := ''
if fn_return_is_optional { if fn_return_is_optional {
@ -5508,7 +5507,7 @@ fn (mut g Gen) return_stmt(node ast.Return) {
// Check if we are dealing with a multi return and handle it seperately // Check if we are dealing with a multi return and handle it seperately
if g.expr_is_multi_return_call(expr) { if g.expr_is_multi_return_call(expr) {
c := expr as ast.CallExpr c := expr as ast.CallExpr
expr_sym := g.table.get_type_symbol(c.return_type) expr_sym := g.table.sym(c.return_type)
// Create a tmp for this call // Create a tmp for this call
mut tmp := g.new_tmp_var() mut tmp := g.new_tmp_var()
if !c.return_type.has_flag(.optional) { if !c.return_type.has_flag(.optional) {
@ -5574,7 +5573,7 @@ fn (mut g Gen) return_stmt(node ast.Return) {
} }
} else if node.exprs.len >= 1 { } else if node.exprs.len >= 1 {
// normal return // normal return
return_sym := g.table.get_type_symbol(node.types[0]) return_sym := g.table.sym(node.types[0])
expr0 := node.exprs[0] expr0 := node.exprs[0]
// `return opt_ok(expr)` for functions that expect an optional // `return opt_ok(expr)` for functions that expect an optional
expr_type_is_opt := match expr0 { expr_type_is_opt := match expr0 {
@ -5853,7 +5852,7 @@ fn (mut g Gen) const_decl_init_later(mod string, name string, expr ast.Expr, typ
} }
} }
if g.is_autofree { if g.is_autofree {
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
if styp.starts_with('Array_') { if styp.starts_with('Array_') {
if sym.has_method_with_generic_parent('free') { if sym.has_method_with_generic_parent('free') {
g.cleanup.writeln('\t${styp}_free(&$cname);') g.cleanup.writeln('\t${styp}_free(&$cname);')
@ -5924,7 +5923,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
g.go_back_out(3) g.go_back_out(3)
return return
} }
mut sym := g.table.get_final_type_symbol(g.unwrap_generic(node.typ)) mut sym := g.table.final_sym(g.unwrap_generic(node.typ))
is_amp := g.is_amp is_amp := g.is_amp
is_multiline := node.fields.len > 5 is_multiline := node.fields.len > 5
g.is_amp = false // reset the flag immediately so that other struct inits in this expr are handled correctly g.is_amp = false // reset the flag immediately so that other struct inits in this expr are handled correctly
@ -5980,7 +5979,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
if field.typ == 0 { if field.typ == 0 {
g.checker_bug('struct init, field.typ is 0', field.pos) g.checker_bug('struct init, field.typ is 0', field.pos)
} }
field_type_sym := g.table.get_type_symbol(field.typ) field_type_sym := g.table.sym(field.typ)
mut cloned := false mut cloned := false
if g.is_autofree && !field.typ.is_ptr() && field_type_sym.kind in [.array, .string] { if g.is_autofree && !field.typ.is_ptr() && field_type_sym.kind in [.array, .string] {
g.write('/*clone1*/') g.write('/*clone1*/')
@ -6023,7 +6022,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
// fields that are initialized but belong to the embedding // fields that are initialized but belong to the embedding
init_fields_to_embed := node.fields.filter(it.name !in init_field_names) init_fields_to_embed := node.fields.filter(it.name !in init_field_names)
for embed in info.embeds { for embed in info.embeds {
embed_sym := g.table.get_type_symbol(embed) embed_sym := g.table.sym(embed)
embed_name := embed_sym.embed_name() embed_name := embed_sym.embed_name()
if embed_name !in inited_fields { if embed_name !in inited_fields {
embed_info := embed_sym.info as ast.Struct embed_info := embed_sym.info as ast.Struct
@ -6078,7 +6077,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
continue continue
} }
g.write('.$field_name = ') g.write('.$field_name = ')
field_type_sym := g.table.get_type_symbol(sfield.typ) field_type_sym := g.table.sym(sfield.typ)
mut cloned := false mut cloned := false
if g.is_autofree && !sfield.typ.is_ptr() && field_type_sym.kind in [.array, .string] { if g.is_autofree && !sfield.typ.is_ptr() && field_type_sym.kind in [.array, .string] {
g.write('/*clone1*/') g.write('/*clone1*/')
@ -6173,7 +6172,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
} }
fn (mut g Gen) zero_struct_field(field ast.StructField) bool { fn (mut g Gen) zero_struct_field(field ast.StructField) bool {
sym := g.table.get_type_symbol(field.typ) sym := g.table.sym(field.typ)
if sym.kind == .struct_ { if sym.kind == .struct_ {
info := sym.info as ast.Struct info := sym.info as ast.Struct
if info.fields.len == 0 { if info.fields.len == 0 {
@ -6209,7 +6208,7 @@ fn (mut g Gen) assoc(node ast.Assoc) {
inited_fields[field] = i inited_fields[field] = i
} }
// Merge inited_fields in the rest of the fields. // Merge inited_fields in the rest of the fields.
sym := g.table.get_type_symbol(node.typ) sym := g.table.sym(node.typ)
info := sym.info as ast.Struct info := sym.info as ast.Struct
for field in info.fields { for field in info.fields {
field_name := c_name(field.name) field_name := c_name(field.name)
@ -6342,7 +6341,7 @@ fn (mut g Gen) write_builtin_types() {
// builtin types need to be on top // builtin types need to be on top
// everything except builtin will get sorted // everything except builtin will get sorted
for builtin_name in c.builtins { for builtin_name in c.builtins {
sym := g.table.get_type_symbol_by_idx(g.table.type_idxs[builtin_name]) sym := g.table.sym_by_idx(g.table.type_idxs[builtin_name])
if sym.kind == .interface_ { if sym.kind == .interface_ {
g.write_interface_typedef(sym) g.write_interface_typedef(sym)
g.write_interface_typesymbol_declaration(sym) g.write_interface_typesymbol_declaration(sym)
@ -6382,7 +6381,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) {
g.type_definitions.writeln('};') g.type_definitions.writeln('};')
g.typedefs.writeln('typedef struct none none;') g.typedefs.writeln('typedef struct none none;')
} }
// sym := g.table.get_type_symbol(typ) // sym := g.table.sym(typ)
mut name := sym.cname mut name := sym.cname
match mut sym.info { match mut sym.info {
ast.Struct { ast.Struct {
@ -6491,7 +6490,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) {
g.type_definitions.writeln('struct $name {') g.type_definitions.writeln('struct $name {')
g.type_definitions.writeln('\tunion {') g.type_definitions.writeln('\tunion {')
for variant in sym.info.variants { for variant in sym.info.variants {
variant_sym := g.table.get_type_symbol(variant) variant_sym := g.table.sym(variant)
g.type_definitions.writeln('\t\t${g.typ(variant.ref())} _$variant_sym.cname;') g.type_definitions.writeln('\t\t${g.typ(variant.ref())} _$variant_sym.cname;')
} }
g.type_definitions.writeln('\t};') g.type_definitions.writeln('\t};')
@ -6506,7 +6505,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) {
g.type_definitions.writeln('') g.type_definitions.writeln('')
} }
ast.ArrayFixed { ast.ArrayFixed {
elem_sym := g.table.get_type_symbol(sym.info.elem_type) elem_sym := g.table.sym(sym.info.elem_type)
if !elem_sym.is_builtin() && !sym.info.elem_type.has_flag(.generic) { if !elem_sym.is_builtin() && !sym.info.elem_type.has_flag(.generic) {
// .array_fixed { // .array_fixed {
styp := sym.cname styp := sym.cname
@ -6560,14 +6559,14 @@ fn (g &Gen) sort_structs(typesa []&ast.TypeSymbol) []&ast.TypeSymbol {
mut field_deps := []string{} mut field_deps := []string{}
match mut sym.info { match mut sym.info {
ast.ArrayFixed { ast.ArrayFixed {
dep := g.table.get_type_symbol(sym.info.elem_type).name dep := g.table.sym(sym.info.elem_type).name
if dep in type_names { if dep in type_names {
field_deps << dep field_deps << dep
} }
} }
ast.Struct { ast.Struct {
for embed in sym.info.embeds { for embed in sym.info.embeds {
dep := g.table.get_type_symbol(embed).name dep := g.table.sym(embed).name
// skip if not in types list or already in deps // skip if not in types list or already in deps
if dep !in type_names || dep in field_deps { if dep !in type_names || dep in field_deps {
continue continue
@ -6575,7 +6574,7 @@ fn (g &Gen) sort_structs(typesa []&ast.TypeSymbol) []&ast.TypeSymbol {
field_deps << dep field_deps << dep
} }
for field in sym.info.fields { for field in sym.info.fields {
dep := g.table.get_type_symbol(field.typ).name dep := g.table.sym(field.typ).name
// skip if not in types list or already in deps // skip if not in types list or already in deps
if dep !in type_names || dep in field_deps || field.typ.is_ptr() { if dep !in type_names || dep in field_deps || field.typ.is_ptr() {
continue continue
@ -6602,7 +6601,7 @@ fn (g &Gen) sort_structs(typesa []&ast.TypeSymbol) []&ast.TypeSymbol {
// sort types // sort types
mut sorted_symbols := []&ast.TypeSymbol{cap: dep_graph_sorted.nodes.len} mut sorted_symbols := []&ast.TypeSymbol{cap: dep_graph_sorted.nodes.len}
for node in dep_graph_sorted.nodes { for node in dep_graph_sorted.nodes {
sorted_symbols << g.table.get_type_symbol_by_idx(g.table.type_idxs[node.name]) sorted_symbols << g.table.sym_by_idx(g.table.type_idxs[node.name])
} }
return sorted_symbols return sorted_symbols
} }
@ -6749,7 +6748,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
// Default values for other types are not needed because of mandatory initialization // Default values for other types are not needed because of mandatory initialization
return '0' return '0'
} }
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
match sym.kind { match sym.kind {
.string { .string {
return '(string){.str=(byteptr)"", .is_lit=1}' return '(string){.str=(byteptr)"", .is_lit=1}'
@ -6776,7 +6775,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
noscan := g.check_noscan(elem_typ) noscan := g.check_noscan(elem_typ)
init_str := '__new_array${noscan}(0, 0, sizeof($elem_type_str))' init_str := '__new_array${noscan}(0, 0, sizeof($elem_type_str))'
if typ.has_flag(.shared_f) { if typ.has_flag(.shared_f) {
atyp := '__shared__Array_${g.table.get_type_symbol(elem_typ).cname}' atyp := '__shared__Array_${g.table.sym(elem_typ).cname}'
return '($atyp*)__dup_shared_array(&($atyp){.mtx = {0}, .val =$init_str}, sizeof($atyp))' return '($atyp*)__dup_shared_array(&($atyp){.mtx = {0}, .val =$init_str}, sizeof($atyp))'
} else { } else {
return init_str return init_str
@ -6784,7 +6783,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
} }
.map { .map {
info := sym.map_info() info := sym.map_info()
key_typ := g.table.get_type_symbol(info.key_type) key_typ := g.table.sym(info.key_type)
hash_fn, key_eq_fn, clone_fn, free_fn := g.map_fn_ptrs(key_typ) hash_fn, key_eq_fn, clone_fn, free_fn := g.map_fn_ptrs(key_typ)
noscan_key := g.check_noscan(info.key_type) noscan_key := g.check_noscan(info.key_type)
noscan_value := g.check_noscan(info.value_type) noscan_value := g.check_noscan(info.value_type)
@ -6799,7 +6798,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
} }
init_str := 'new_map${noscan}(sizeof(${g.typ(info.key_type)}), sizeof(${g.typ(info.value_type)}), $hash_fn, $key_eq_fn, $clone_fn, $free_fn)' init_str := 'new_map${noscan}(sizeof(${g.typ(info.key_type)}), sizeof(${g.typ(info.value_type)}), $hash_fn, $key_eq_fn, $clone_fn, $free_fn)'
if typ.has_flag(.shared_f) { if typ.has_flag(.shared_f) {
mtyp := '__shared__Map_${key_typ.cname}_${g.table.get_type_symbol(info.value_type).cname}' mtyp := '__shared__Map_${key_typ.cname}_${g.table.sym(info.value_type).cname}'
return '($mtyp*)__dup_shared_map(&($mtyp){.mtx = {0}, .val =$init_str}, sizeof($mtyp))' return '($mtyp*)__dup_shared_map(&($mtyp){.mtx = {0}, .val =$init_str}, sizeof($mtyp))'
} else { } else {
return init_str return init_str
@ -6812,13 +6811,13 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
typ_is_shared_f := typ.has_flag(.shared_f) typ_is_shared_f := typ.has_flag(.shared_f)
if sym.language == .v && !typ_is_shared_f { if sym.language == .v && !typ_is_shared_f {
for field in info.fields { for field in info.fields {
field_sym := g.table.get_type_symbol(field.typ) field_sym := g.table.sym(field.typ)
if field.has_default_expr if field.has_default_expr
|| field_sym.kind in [.array, .map, .string, .bool, .alias, .i8, .i16, .int, .i64, .byte, .u16, .u32, .u64, .char, .voidptr, .byteptr, .charptr, .struct_] { || field_sym.kind in [.array, .map, .string, .bool, .alias, .i8, .i16, .int, .i64, .byte, .u16, .u32, .u64, .char, .voidptr, .byteptr, .charptr, .struct_] {
field_name := c_name(field.name) field_name := c_name(field.name)
if field.has_default_expr { if field.has_default_expr {
mut expr_str := '' mut expr_str := ''
if g.table.get_type_symbol(field.typ).kind in [.sum_type, .interface_] { if g.table.sym(field.typ).kind in [.sum_type, .interface_] {
expr_str = g.expr_string_with_cast(field.default_expr, expr_str = g.expr_string_with_cast(field.default_expr,
field.default_expr_typ, field.typ) field.default_expr_typ, field.typ)
} else { } else {
@ -6849,7 +6848,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
init_str += '0}' init_str += '0}'
} }
if typ.has_flag(.shared_f) { if typ.has_flag(.shared_f) {
styp := '__shared__${g.table.get_type_symbol(typ).cname}' styp := '__shared__${g.table.sym(typ).cname}'
return '($styp*)__dup${styp}(&($styp){.mtx = {0}, .val =$init_str}, sizeof($styp))' return '($styp*)__dup${styp}(&($styp){.mtx = {0}, .val =$init_str}, sizeof($styp))'
} else { } else {
return init_str return init_str
@ -6912,7 +6911,7 @@ fn (mut g Gen) go_expr(node ast.GoExpr) {
} }
} }
if expr.is_method { if expr.is_method {
receiver_sym := g.table.get_type_symbol(expr.receiver_type) receiver_sym := g.table.sym(expr.receiver_type)
name = receiver_sym.name + '_' + name name = receiver_sym.name + '_' + name
} else if mut expr.left is ast.AnonFn { } else if mut expr.left is ast.AnonFn {
g.gen_anon_fn_decl(mut expr.left) g.gen_anon_fn_decl(mut expr.left)
@ -6922,7 +6921,7 @@ fn (mut g Gen) go_expr(node ast.GoExpr) {
if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') { if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') {
mut key := expr.name mut key := expr.name
if expr.is_method { if expr.is_method {
sym := g.table.get_type_symbol(expr.receiver_type) sym := g.table.sym(expr.receiver_type)
key = sym.name + '.' + expr.name key = sym.name + '.' + expr.name
} }
g.write('/* obf go: $key */') g.write('/* obf go: $key */')
@ -6961,7 +6960,7 @@ fn (mut g Gen) go_expr(node ast.GoExpr) {
gohandle_name = if is_opt { '__v_thread_Option_void' } else { '__v_thread' } gohandle_name = if is_opt { '__v_thread_Option_void' } else { '__v_thread' }
} else { } else {
opt := if is_opt { 'Option_' } else { '' } opt := if is_opt { 'Option_' } else { '' }
gohandle_name = '__v_thread_$opt${g.table.get_type_symbol(g.unwrap_generic(node.call_expr.return_type)).cname}' gohandle_name = '__v_thread_$opt${g.table.sym(g.unwrap_generic(node.call_expr.return_type)).cname}'
} }
if g.pref.os == .windows { if g.pref.os == .windows {
simple_handle := if node.is_expr && node.call_expr.return_type != ast.void_type { simple_handle := if node.is_expr && node.call_expr.return_type != ast.void_type {
@ -7075,7 +7074,7 @@ fn (mut g Gen) go_expr(node ast.GoExpr) {
} }
if expr.is_method { if expr.is_method {
unwrapped_rec_type := g.unwrap_generic(expr.receiver_type) unwrapped_rec_type := g.unwrap_generic(expr.receiver_type)
typ_sym := g.table.get_type_symbol(unwrapped_rec_type) typ_sym := g.table.sym(unwrapped_rec_type)
if typ_sym.kind == .interface_ if typ_sym.kind == .interface_
&& (typ_sym.info as ast.Interface).defines_method(expr.name) { && (typ_sym.info as ast.Interface).defines_method(expr.name) {
rec_cc_type := g.cc_type(unwrapped_rec_type, false) rec_cc_type := g.cc_type(unwrapped_rec_type, false)
@ -7100,8 +7099,8 @@ fn (mut g Gen) go_expr(node ast.GoExpr) {
if expr.args.len > 0 { if expr.args.len > 0 {
mut has_cast := false mut has_cast := false
for i in 0 .. expr.args.len { for i in 0 .. expr.args.len {
if g.table.get_type_symbol(expr.expected_arg_types[i]).kind == .interface_ if g.table.sym(expr.expected_arg_types[i]).kind == .interface_
&& g.table.get_type_symbol(expr.args[i].typ).kind != .interface_ { && g.table.sym(expr.args[i].typ).kind != .interface_ {
has_cast = true has_cast = true
break break
} }
@ -7148,8 +7147,8 @@ fn (mut g Gen) as_cast(node ast.AsCast) {
// are the same), otherwise panic. // are the same), otherwise panic.
// g.insert_before(' // g.insert_before('
styp := g.typ(node.typ) styp := g.typ(node.typ)
sym := g.table.get_type_symbol(node.typ) sym := g.table.sym(node.typ)
mut expr_type_sym := g.table.get_type_symbol(node.expr_type) mut expr_type_sym := g.table.sym(node.expr_type)
if mut expr_type_sym.info is ast.SumType { if mut expr_type_sym.info is ast.SumType {
dot := if node.expr_type.is_ptr() { '->' } else { '.' } dot := if node.expr_type.is_ptr() { '->' } else { '.' }
g.write('/* as */ *($styp*)__as_cast(') g.write('/* as */ *($styp*)__as_cast(')
@ -7164,7 +7163,7 @@ fn (mut g Gen) as_cast(node ast.AsCast) {
g.write(dot) g.write(dot)
// g.write('typ, /*expected:*/$node.typ)') // g.write('typ, /*expected:*/$node.typ)')
sidx := g.type_sidx(node.typ) sidx := g.type_sidx(node.typ)
expected_sym := g.table.get_type_symbol(node.typ) expected_sym := g.table.sym(node.typ)
g.write('_typ, $sidx) /*expected idx: $sidx, name: $expected_sym.name */ ') g.write('_typ, $sidx) /*expected idx: $sidx, name: $expected_sym.name */ ')
// fill as cast name table // fill as cast name table
@ -7173,7 +7172,7 @@ fn (mut g Gen) as_cast(node ast.AsCast) {
if idx in g.as_cast_type_names { if idx in g.as_cast_type_names {
continue continue
} }
variant_sym := g.table.get_type_symbol(variant) variant_sym := g.table.sym(variant)
g.as_cast_type_names[idx] = variant_sym.name g.as_cast_type_names[idx] = variant_sym.name
} }
} else if expr_type_sym.kind == .interface_ && sym.kind == .interface_ { } else if expr_type_sym.kind == .interface_ && sym.kind == .interface_ {
@ -7270,7 +7269,7 @@ fn (mut g Gen) interface_table() string {
iinidx_minimum_base := 1000 // NB: NOT 0, to avoid map entries set to 0 later, so `if already_generated_mwrappers[name] > 0 {` works. iinidx_minimum_base := 1000 // NB: NOT 0, to avoid map entries set to 0 later, so `if already_generated_mwrappers[name] > 0 {` works.
mut current_iinidx := iinidx_minimum_base mut current_iinidx := iinidx_minimum_base
for st in inter_info.types { for st in inter_info.types {
st_sym := g.table.get_type_symbol(st) st_sym := g.table.sym(st)
// cctype is the Cleaned Concrete Type name, *without ptr*, // cctype is the Cleaned Concrete Type name, *without ptr*,
// i.e. cctype is always just Cat, not Cat_ptr: // i.e. cctype is always just Cat, not Cat_ptr:
cctype := g.cc_type(st, true) cctype := g.cc_type(st, true)
@ -7303,7 +7302,7 @@ fn (mut g Gen) interface_table() string {
cast_struct.write_string('/*.... ast.voidptr_type */') cast_struct.write_string('/*.... ast.voidptr_type */')
} else { } else {
for embed_type in st_sym.struct_info().embeds { for embed_type in st_sym.struct_info().embeds {
embed_sym := g.table.get_type_symbol(embed_type) embed_sym := g.table.sym(embed_type)
if _ := embed_sym.find_field(field.name) { if _ := embed_sym.find_field(field.name) {
cast_struct.write_string(' + __offsetof_ptr(x, $cctype, $embed_sym.embed_name()) + __offsetof_ptr(x, $embed_sym.cname, $cname)') cast_struct.write_string(' + __offsetof_ptr(x, $cctype, $embed_sym.embed_name()) + __offsetof_ptr(x, $embed_sym.cname, $cname)')
break break
@ -7338,7 +7337,7 @@ static inline $interface_name I_${cctype}_to_Interface_${interface_name}($cctype
match st_sym.info { match st_sym.info {
ast.Struct, ast.Interface, ast.SumType { ast.Struct, ast.Interface, ast.SumType {
if st_sym.info.parent_type.has_flag(.generic) { if st_sym.info.parent_type.has_flag(.generic) {
parent_sym := g.table.get_type_symbol(st_sym.info.parent_type) parent_sym := g.table.sym(st_sym.info.parent_type)
for method in parent_sym.methods { for method in parent_sym.methods {
if method.name in methodidx { if method.name in methodidx {
methods << st_sym.find_method_with_generic_parent(method.name) or { methods << st_sym.find_method_with_generic_parent(method.name) or {
@ -7352,7 +7351,7 @@ static inline $interface_name I_${cctype}_to_Interface_${interface_name}($cctype
} }
if st_sym.info is ast.Struct { if st_sym.info is ast.Struct {
for embed in st_sym.info.embeds { for embed in st_sym.info.embeds {
embed_sym := g.table.get_type_symbol(embed) embed_sym := g.table.sym(embed)
for embed_method in embed_sym.methods { for embed_method in embed_sym.methods {
if embed_method.name !in method_names { if embed_method.name !in method_names {
methods << embed_method methods << embed_method
@ -7363,7 +7362,7 @@ static inline $interface_name I_${cctype}_to_Interface_${interface_name}($cctype
for method in methods { for method in methods {
mut name := method.name mut name := method.name
if inter_info.parent_type.has_flag(.generic) { if inter_info.parent_type.has_flag(.generic) {
parent_sym := g.table.get_type_symbol(inter_info.parent_type) parent_sym := g.table.sym(inter_info.parent_type)
match mut parent_sym.info { match mut parent_sym.info {
ast.Struct, ast.Interface, ast.SumType { ast.Struct, ast.Interface, ast.SumType {
name = g.generic_fn_name(parent_sym.info.concrete_types, method.name, name = g.generic_fn_name(parent_sym.info.concrete_types, method.name,
@ -7408,11 +7407,11 @@ static inline $interface_name I_${cctype}_to_Interface_${interface_name}($cctype
ast.Fn{}, []ast.Type{} ast.Fn{}, []ast.Type{}
} }
if embed_types.len > 0 && method.name !in method_names { if embed_types.len > 0 && method.name !in method_names {
embed_sym := g.table.get_type_symbol(embed_types.last()) embed_sym := g.table.sym(embed_types.last())
method_name := '${embed_sym.cname}_$method.name' method_name := '${embed_sym.cname}_$method.name'
methods_wrapper.write_string('${method_name}(${fargs[0]}') methods_wrapper.write_string('${method_name}(${fargs[0]}')
for embed in embed_types { for embed in embed_types {
esym := g.table.get_type_symbol(embed) esym := g.table.sym(embed)
methods_wrapper.write_string('->$esym.embed_name()') methods_wrapper.write_string('->$esym.embed_name()')
} }
methods_wrapper.writeln('${fargs[1..].join(', ')});') methods_wrapper.writeln('${fargs[1..].join(', ')});')
@ -7438,10 +7437,10 @@ static inline $interface_name I_${cctype}_to_Interface_${interface_name}($cctype
} }
} }
for vtyp, variants in inter_info.conversions { for vtyp, variants in inter_info.conversions {
vsym := g.table.get_type_symbol(vtyp) vsym := g.table.sym(vtyp)
conversion_functions.write_string('static inline bool I_${interface_name}_is_I_${vsym.cname}($interface_name x) {\n\treturn ') conversion_functions.write_string('static inline bool I_${interface_name}_is_I_${vsym.cname}($interface_name x) {\n\treturn ')
for i, variant in variants { for i, variant in variants {
variant_sym := g.table.get_type_symbol(variant) variant_sym := g.table.sym(variant)
if i > 0 { if i > 0 {
conversion_functions.write_string(' || ') conversion_functions.write_string(' || ')
} }
@ -7451,7 +7450,7 @@ static inline $interface_name I_${cctype}_to_Interface_${interface_name}($cctype
conversion_functions.writeln('static inline $vsym.cname I_${interface_name}_as_I_${vsym.cname}($interface_name x) {') conversion_functions.writeln('static inline $vsym.cname I_${interface_name}_as_I_${vsym.cname}($interface_name x) {')
for variant in variants { for variant in variants {
variant_sym := g.table.get_type_symbol(variant) variant_sym := g.table.sym(variant)
conversion_functions.writeln('\tif (x._typ == _${interface_name}_${variant_sym.cname}_index) return I_${variant_sym.cname}_to_Interface_${vsym.cname}(x._$variant_sym.cname);') conversion_functions.writeln('\tif (x._typ == _${interface_name}_${variant_sym.cname}_index) return I_${variant_sym.cname}_to_Interface_${vsym.cname}(x._$variant_sym.cname);')
} }
pmessage := 'string__plus(string__plus(tos3("`as_cast`: cannot convert "), tos3(v_typeof_interface_${interface_name}(x._typ))), tos3(" to ${util.strip_main_name(vsym.name)}"))' pmessage := 'string__plus(string__plus(tos3("`as_cast`: cannot convert "), tos3(v_typeof_interface_${interface_name}(x._typ))), tos3(" to ${util.strip_main_name(vsym.name)}"))'
@ -7525,7 +7524,7 @@ fn (mut g Gen) trace(fbase string, message string) {
pub fn (mut g Gen) get_array_depth(el_typ ast.Type) int { pub fn (mut g Gen) get_array_depth(el_typ ast.Type) int {
typ := g.unwrap_generic(el_typ) typ := g.unwrap_generic(el_typ)
sym := g.table.get_final_type_symbol(typ) sym := g.table.final_sym(typ)
if sym.kind == .array { if sym.kind == .array {
info := sym.info as ast.Array info := sym.info as ast.Array
return 1 + g.get_array_depth(info.elem_type) return 1 + g.get_array_depth(info.elem_type)
@ -7544,7 +7543,7 @@ pub fn (mut g Gen) contains_ptr(el_typ ast.Type) bool {
if typ.is_ptr() { if typ.is_ptr() {
return true return true
} }
sym := g.table.get_final_type_symbol(typ) sym := g.table.final_sym(typ)
if sym.language != .v { if sym.language != .v {
return true return true
} }

View File

@ -76,7 +76,7 @@ fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
} }
return return
} }
sym := g.table.get_type_symbol(g.unwrap_generic(node.left_type)) sym := g.table.sym(g.unwrap_generic(node.left_type))
g.trace_autofree('// \$method call. sym="$sym.name"') g.trace_autofree('// \$method call. sym="$sym.name"')
if node.method_name == 'method' { if node.method_name == 'method' {
// `app.$method()` // `app.$method()`
@ -335,11 +335,11 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) bool {
// Handle `$if x is Interface {` // Handle `$if x is Interface {`
// mut matches_interface := 'false' // mut matches_interface := 'false'
if left is ast.TypeNode && cond.right is ast.TypeNode if left is ast.TypeNode && cond.right is ast.TypeNode
&& g.table.get_type_symbol(got_type).kind == .interface_ { && g.table.sym(got_type).kind == .interface_ {
// `$if Foo is Interface {` // `$if Foo is Interface {`
interface_sym := g.table.get_type_symbol(got_type) interface_sym := g.table.sym(got_type)
if interface_sym.info is ast.Interface { if interface_sym.info is ast.Interface {
// q := g.table.get_type_symbol(interface_sym.info.types[0]) // q := g.table.sym(interface_sym.info.types[0])
checked_type := g.unwrap_generic(left.typ) checked_type := g.unwrap_generic(left.typ)
// TODO PERF this check is run twice (also in the checker) // TODO PERF this check is run twice (also in the checker)
// store the result in a field // store the result in a field
@ -408,7 +408,7 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) bool {
} }
fn (mut g Gen) comptime_for(node ast.ComptimeFor) { fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
sym := g.table.get_type_symbol(g.unwrap_generic(node.typ)) sym := g.table.sym(g.unwrap_generic(node.typ))
g.writeln('/* \$for $node.val_var in ${sym.name}($node.kind.str()) */ {') g.writeln('/* \$for $node.val_var in ${sym.name}($node.kind.str()) */ {')
g.indent++ g.indent++
// vweb_result_type := ast.new_type(g.table.find_type_idx('vweb.Result')) // vweb_result_type := ast.new_type(g.table.find_type_idx('vweb.Result'))
@ -509,7 +509,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
'\t${node.val_var}.attrs = new_array_from_c_array($attrs.len, $attrs.len, sizeof(string), _MOV((string[$attrs.len]){' + '\t${node.val_var}.attrs = new_array_from_c_array($attrs.len, $attrs.len, sizeof(string), _MOV((string[$attrs.len]){' +
attrs.join(', ') + '}));\n') attrs.join(', ') + '}));\n')
} }
// field_sym := g.table.get_type_symbol(field.typ) // field_sym := g.table.sym(field.typ)
// g.writeln('\t${node.val_var}.typ = _SLIT("$field_sym.name");') // g.writeln('\t${node.val_var}.typ = _SLIT("$field_sym.name");')
styp := field.typ styp := field.typ
g.writeln('\t${node.val_var}.typ = $styp;') g.writeln('\t${node.val_var}.typ = $styp;')

View File

@ -22,7 +22,7 @@ fn (mut g Gen) dump_expr_definitions() {
mut dump_typedefs := map[string]bool{} mut dump_typedefs := map[string]bool{}
mut dump_fns := strings.new_builder(100) mut dump_fns := strings.new_builder(100)
for dump_type, cname in g.table.dumps { for dump_type, cname in g.table.dumps {
dump_sym := g.table.get_type_symbol(dump_type) dump_sym := g.table.sym(dump_type)
_, str_method_expects_ptr, _ := dump_sym.str_method_info() _, str_method_expects_ptr, _ := dump_sym.str_method_info()
is_ptr := ast.Type(dump_type).is_ptr() is_ptr := ast.Type(dump_type).is_ptr()
deref, _ := deref_kind(str_method_expects_ptr, is_ptr, dump_type) deref, _ := deref_kind(str_method_expects_ptr, is_ptr, dump_type)

View File

@ -158,7 +158,7 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
// loop thru each generic type and generate a function // loop thru each generic type and generate a function
for concrete_types in g.table.fn_generic_types[node.name] { for concrete_types in g.table.fn_generic_types[node.name] {
if g.pref.is_verbose { if g.pref.is_verbose {
syms := concrete_types.map(g.table.get_type_symbol(it)) syms := concrete_types.map(g.table.sym(it))
the_type := syms.map(it.name).join(', ') the_type := syms.map(it.name).join(', ')
println('gen fn `$node.name` for type `$the_type`') println('gen fn `$node.name` for type `$the_type`')
} }
@ -203,12 +203,12 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
name = util.replace_op(name) name = util.replace_op(name)
} }
if node.is_method { if node.is_method {
unwrapped_rec_sym := g.table.get_type_symbol(g.unwrap_generic(node.receiver.typ)) unwrapped_rec_sym := g.table.sym(g.unwrap_generic(node.receiver.typ))
if unwrapped_rec_sym.kind == .placeholder { if unwrapped_rec_sym.kind == .placeholder {
return return
} }
name = g.cc_type(node.receiver.typ, false) + '_' + name name = g.cc_type(node.receiver.typ, false) + '_' + name
// name = g.table.get_type_symbol(node.receiver.typ).name + '_' + name // name = g.table.sym(node.receiver.typ).name + '_' + name
} }
if node.language == .c { if node.language == .c {
name = util.no_dots(name) name = util.no_dots(name)
@ -241,7 +241,7 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
&& node.name != 'str' { && node.name != 'str' {
mut key := node.name mut key := node.name
if node.is_method { if node.is_method {
sym := g.table.get_type_symbol(node.receiver.typ) sym := g.table.sym(node.receiver.typ)
key = sym.name + '.' + node.name key = sym.name + '.' + node.name
} }
g.writeln('/* obf: $key */') g.writeln('/* obf: $key */')
@ -345,7 +345,7 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
} }
} }
info := var.obj as ast.Var info := var.obj as ast.Var
if g.table.get_type_symbol(info.typ).kind != .function { if g.table.sym(info.typ).kind != .function {
g.writeln('${g.typ(info.typ)}$deref $var.name;') g.writeln('${g.typ(info.typ)}$deref $var.name;')
} }
} }
@ -529,7 +529,7 @@ fn (mut g Gen) fn_args(args []ast.Param, scope &ast.Scope) ([]string, []string,
for i, arg in args { for i, arg in args {
mut caname := if arg.name == '_' { g.new_tmp_declaration_name() } else { c_name(arg.name) } mut caname := if arg.name == '_' { g.new_tmp_declaration_name() } else { c_name(arg.name) }
typ := g.unwrap_generic(arg.typ) typ := g.unwrap_generic(arg.typ)
arg_type_sym := g.table.get_type_symbol(typ) arg_type_sym := g.table.sym(typ)
mut arg_type_name := g.typ(typ) // util.no_dots(arg_type_sym.name) mut arg_type_name := g.typ(typ) // util.no_dots(arg_type_sym.name)
if arg_type_sym.kind == .function { if arg_type_sym.kind == .function {
info := arg_type_sym.info as ast.FnType info := arg_type_sym.info as ast.FnType
@ -622,7 +622,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
if node.is_method && !node.is_field { if node.is_method && !node.is_field {
if node.name == 'writeln' && g.pref.experimental && node.args.len > 0 if node.name == 'writeln' && g.pref.experimental && node.args.len > 0
&& node.args[0].expr is ast.StringInterLiteral && node.args[0].expr is ast.StringInterLiteral
&& g.table.get_type_symbol(node.receiver_type).name == 'strings.Builder' { && g.table.sym(node.receiver_type).name == 'strings.Builder' {
g.string_inter_literal_sb_optimized(node) g.string_inter_literal_sb_optimized(node)
} else { } else {
g.method_call(node) g.method_call(node)
@ -638,7 +638,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
unwrapped_styp := g.typ(unwrapped_typ) unwrapped_styp := g.typ(unwrapped_typ)
if unwrapped_typ == ast.void_type { if unwrapped_typ == ast.void_type {
g.write('\n $cur_line') g.write('\n $cur_line')
} else if g.table.get_type_symbol(node.return_type).kind == .multi_return { } else if g.table.sym(node.return_type).kind == .multi_return {
g.write('\n $cur_line $tmp_opt /*U*/') g.write('\n $cur_line $tmp_opt /*U*/')
} else { } else {
if !g.inside_const { if !g.inside_const {
@ -687,10 +687,10 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
if g.cur_fn != 0 && g.cur_fn.generic_names.len > 0 { // in generic fn if g.cur_fn != 0 && g.cur_fn.generic_names.len > 0 { // in generic fn
unwrapped_rec_type = g.unwrap_generic(node.receiver_type) unwrapped_rec_type = g.unwrap_generic(node.receiver_type)
} else { // in non-generic fn } else { // in non-generic fn
sym := g.table.get_type_symbol(node.receiver_type) sym := g.table.sym(node.receiver_type)
match sym.info { match sym.info {
ast.Struct, ast.Interface, ast.SumType { ast.Struct, ast.Interface, ast.SumType {
generic_names := sym.info.generic_types.map(g.table.get_type_symbol(it).name) generic_names := sym.info.generic_types.map(g.table.sym(it).name)
// see comment at top of vlib/v/gen/c/utils.v // see comment at top of vlib/v/gen/c/utils.v
mut muttable := unsafe { &ast.Table(g.table) } mut muttable := unsafe { &ast.Table(g.table) }
if utyp := muttable.resolve_generic_to_concrete(node.receiver_type, generic_names, if utyp := muttable.resolve_generic_to_concrete(node.receiver_type, generic_names,
@ -702,11 +702,11 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
else {} else {}
} }
} }
mut typ_sym := g.table.get_type_symbol(unwrapped_rec_type) mut typ_sym := g.table.sym(unwrapped_rec_type)
// alias type that undefined this method (not include `str`) need to use parent type // alias type that undefined this method (not include `str`) need to use parent type
if typ_sym.kind == .alias && node.name != 'str' && !typ_sym.has_method(node.name) { if typ_sym.kind == .alias && node.name != 'str' && !typ_sym.has_method(node.name) {
unwrapped_rec_type = (typ_sym.info as ast.Alias).parent_type unwrapped_rec_type = (typ_sym.info as ast.Alias).parent_type
typ_sym = g.table.get_type_symbol(unwrapped_rec_type) typ_sym = g.table.sym(unwrapped_rec_type)
} }
rec_cc_type := g.cc_type(unwrapped_rec_type, false) rec_cc_type := g.cc_type(unwrapped_rec_type, false)
mut receiver_type_name := util.no_dots(rec_cc_type) mut receiver_type_name := util.no_dots(rec_cc_type)
@ -729,8 +729,8 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
g.write(')') g.write(')')
return return
} }
left_sym := g.table.get_type_symbol(node.left_type) left_sym := g.table.sym(node.left_type)
final_left_sym := g.table.get_final_type_symbol(node.left_type) final_left_sym := g.table.final_sym(node.left_type)
if left_sym.kind == .array { if left_sym.kind == .array {
match node.name { match node.name {
'filter' { 'filter' {
@ -853,7 +853,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
g.gen_expr_to_string(node.left, rec_type) g.gen_expr_to_string(node.left, rec_type)
return return
} else if node.left.obj.smartcasts.len > 0 { } else if node.left.obj.smartcasts.len > 0 {
cast_sym := g.table.get_type_symbol(node.left.obj.smartcasts.last()) cast_sym := g.table.sym(node.left.obj.smartcasts.last())
if cast_sym.info is ast.Aggregate { if cast_sym.info is ast.Aggregate {
rec_type = cast_sym.info.types[g.aggregate_type_idx] rec_type = cast_sym.info.types[g.aggregate_type_idx]
g.gen_expr_to_string(node.left, rec_type) g.gen_expr_to_string(node.left, rec_type)
@ -912,7 +912,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
} }
if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__')
&& node.name != 'str' { && node.name != 'str' {
sym := g.table.get_type_symbol(node.receiver_type) sym := g.table.sym(node.receiver_type)
key := sym.name + '.' + node.name key := sym.name + '.' + node.name
g.write('/* obf method call: $key */') g.write('/* obf method call: $key */')
name = g.obf_table[key] or { name = g.obf_table[key] or {
@ -1011,7 +1011,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
g.expr(node.left) g.expr(node.left)
} }
for embed in node.from_embed_types { for embed in node.from_embed_types {
embed_sym := g.table.get_type_symbol(embed) embed_sym := g.table.sym(embed)
embed_name := embed_sym.embed_name() embed_name := embed_sym.embed_name()
if node.left_type.is_ptr() { if node.left_type.is_ptr() {
g.write('->') g.write('->')
@ -1037,7 +1037,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
if name.contains('subkeys') { if name.contains('subkeys') {
println('call_args $name $node.arg_types.len') println('call_args $name $node.arg_types.len')
for t in node.arg_types { for t in node.arg_types {
sym := g.table.get_type_symbol(t) sym := g.table.sym(t)
print('$sym.name ') print('$sym.name ')
} }
println('') println('')
@ -1059,7 +1059,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
mut is_interface_call := false mut is_interface_call := false
mut is_selector_call := false mut is_selector_call := false
if node.left_type != 0 { if node.left_type != 0 {
left_sym := g.table.get_type_symbol(node.left_type) left_sym := g.table.sym(node.left_type)
if left_sym.kind == .interface_ { if left_sym.kind == .interface_ {
is_interface_call = true is_interface_call = true
g.write('(*') g.write('(*')
@ -1167,7 +1167,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
} }
if typ != ast.string_type || g.comptime_for_method.len > 0 { if typ != ast.string_type || g.comptime_for_method.len > 0 {
expr := node.args[0].expr expr := node.args[0].expr
typ_sym := g.table.get_type_symbol(typ) typ_sym := g.table.sym(typ)
if typ_sym.kind == .interface_ && (typ_sym.info as ast.Interface).defines_method('str') { if typ_sym.kind == .interface_ && (typ_sym.info as ast.Interface).defines_method('str') {
g.write('${c_name(print_method)}(') g.write('${c_name(print_method)}(')
rec_type_name := util.no_dots(g.cc_type(typ, false)) rec_type_name := util.no_dots(g.cc_type(typ, false))
@ -1200,7 +1200,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
if expr.obj is ast.Var { if expr.obj is ast.Var {
typ = expr.obj.typ typ = expr.obj.typ
if expr.obj.smartcasts.len > 0 { if expr.obj.smartcasts.len > 0 {
cast_sym := g.table.get_type_symbol(expr.obj.smartcasts.last()) cast_sym := g.table.sym(expr.obj.smartcasts.last())
if cast_sym.info is ast.Aggregate { if cast_sym.info is ast.Aggregate {
typ = cast_sym.info.types[g.aggregate_type_idx] typ = cast_sym.info.types[g.aggregate_type_idx]
} }
@ -1234,7 +1234,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
g.write('(*') g.write('(*')
} }
for i, typ in obj.smartcasts { for i, typ in obj.smartcasts {
cast_sym := g.table.get_type_symbol(g.unwrap_generic(typ)) cast_sym := g.table.sym(g.unwrap_generic(typ))
mut is_ptr := false mut is_ptr := false
if i == 0 { if i == 0 {
g.write(node.name) g.write(node.name)
@ -1244,7 +1244,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
} }
dot := if is_ptr { '->' } else { '.' } dot := if is_ptr { '->' } else { '.' }
if mut cast_sym.info is ast.Aggregate { if mut cast_sym.info is ast.Aggregate {
sym := g.table.get_type_symbol(cast_sym.info.types[g.aggregate_type_idx]) sym := g.table.sym(cast_sym.info.types[g.aggregate_type_idx])
g.write('${dot}_$sym.cname') g.write('${dot}_$sym.cname')
} else { } else {
g.write('${dot}_$cast_sym.cname') g.write('${dot}_$cast_sym.cname')
@ -1479,7 +1479,7 @@ fn (mut g Gen) call_args(node ast.CallExpr) {
if is_variadic { if is_variadic {
varg_type := expected_types.last() varg_type := expected_types.last()
variadic_count := args.len - arg_nr variadic_count := args.len - arg_nr
arr_sym := g.table.get_type_symbol(varg_type) arr_sym := g.table.sym(varg_type)
mut arr_info := arr_sym.info as ast.Array mut arr_info := arr_sym.info as ast.Array
if varg_type.has_flag(.generic) { if varg_type.has_flag(.generic) {
if fn_def := g.table.find_fn(node.name) { if fn_def := g.table.find_fn(node.name) {
@ -1530,7 +1530,7 @@ fn (mut g Gen) keep_alive_call_pregen(node ast.CallExpr) int {
// save all arguments in temp vars (not only pointers) to make sure the // save all arguments in temp vars (not only pointers) to make sure the
// evaluation order is preserved // evaluation order is preserved
expected_type := node.expected_arg_types[i] expected_type := node.expected_arg_types[i]
typ := g.table.get_type_symbol(expected_type).cname typ := g.table.sym(expected_type).cname
g.write('$typ __tmp_arg_${tmp_cnt_save + i} = ') g.write('$typ __tmp_arg_${tmp_cnt_save + i} = ')
// g.expr(arg.expr) // g.expr(arg.expr)
g.ref_or_deref_arg(arg, expected_type, node.language) g.ref_or_deref_arg(arg, expected_type, node.language)
@ -1556,7 +1556,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
if expected_type == 0 { if expected_type == 0 {
g.checker_bug('ref_or_deref_arg expected_type is 0', arg.pos) g.checker_bug('ref_or_deref_arg expected_type is 0', arg.pos)
} }
exp_sym := g.table.get_type_symbol(expected_type) exp_sym := g.table.sym(expected_type)
arg_typ := g.unwrap_generic(arg.typ) arg_typ := g.unwrap_generic(arg.typ)
mut needs_closing := false mut needs_closing := false
if arg.is_mut && !arg_is_ptr { if arg.is_mut && !arg_is_ptr {
@ -1582,13 +1582,13 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
if arg_typ == 0 { if arg_typ == 0 {
g.checker_bug('ref_or_deref_arg arg.typ is 0', arg.pos) g.checker_bug('ref_or_deref_arg arg.typ is 0', arg.pos)
} }
arg_typ_sym := g.table.get_type_symbol(arg_typ) arg_typ_sym := g.table.sym(arg_typ)
expected_deref_type := if expected_type.is_ptr() { expected_deref_type := if expected_type.is_ptr() {
expected_type.deref() expected_type.deref()
} else { } else {
expected_type expected_type
} }
deref_sym := g.table.get_type_symbol(expected_deref_type) deref_sym := g.table.sym(expected_deref_type)
if !((arg_typ_sym.kind == .function) if !((arg_typ_sym.kind == .function)
|| deref_sym.kind in [.sum_type, .interface_]) && lang != .c { || deref_sym.kind in [.sum_type, .interface_]) && lang != .c {
if arg.expr.is_lvalue() { if arg.expr.is_lvalue() {

View File

@ -10,7 +10,7 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
if node.index is ast.RangeExpr { if node.index is ast.RangeExpr {
g.range_expr(node, node.index) g.range_expr(node, node.index)
} else { } else {
sym := g.table.get_final_type_symbol(node.left_type) sym := g.table.final_sym(node.left_type)
if sym.kind == .array { if sym.kind == .array {
g.index_of_array(node, sym) g.index_of_array(node, sym)
} else if sym.kind == .array_fixed { } else if sym.kind == .array_fixed {
@ -58,7 +58,7 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
} }
fn (mut g Gen) range_expr(node ast.IndexExpr, range ast.RangeExpr) { fn (mut g Gen) range_expr(node ast.IndexExpr, range ast.RangeExpr) {
sym := g.table.get_final_type_symbol(node.left_type) sym := g.table.final_sym(node.left_type)
if sym.kind == .string { if sym.kind == .string {
g.write('string_substr(') g.write('string_substr(')
g.expr(node.left) g.expr(node.left)
@ -123,7 +123,7 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) {
info := sym.info as ast.Array info := sym.info as ast.Array
elem_type_str := g.typ(info.elem_type) elem_type_str := g.typ(info.elem_type)
elem_type := info.elem_type elem_type := info.elem_type
elem_typ := g.table.get_type_symbol(elem_type) elem_typ := g.table.sym(elem_type)
// `vals[i].field = x` is an exception and requires `array_get`: // `vals[i].field = x` is an exception and requires `array_get`:
// `(*(Val*)array_get(vals, i)).field = x;` // `(*(Val*)array_get(vals, i)).field = x;`
is_selector := node.left is ast.SelectorExpr is_selector := node.left is ast.SelectorExpr
@ -287,7 +287,7 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) {
fn (mut g Gen) index_of_fixed_array(node ast.IndexExpr, sym ast.TypeSymbol) { fn (mut g Gen) index_of_fixed_array(node ast.IndexExpr, sym ast.TypeSymbol) {
info := sym.info as ast.ArrayFixed info := sym.info as ast.ArrayFixed
elem_type := info.elem_type elem_type := info.elem_type
elem_sym := g.table.get_type_symbol(elem_type) elem_sym := g.table.sym(elem_type)
is_fn_index_call := g.is_fn_index_call && elem_sym.info is ast.FnType is_fn_index_call := g.is_fn_index_call && elem_sym.info is ast.FnType
if is_fn_index_call { if is_fn_index_call {
@ -323,7 +323,7 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) {
key_type_str := g.typ(info.key_type) key_type_str := g.typ(info.key_type)
elem_type := info.value_type elem_type := info.value_type
elem_type_str := g.typ(elem_type) elem_type_str := g.typ(elem_type)
elem_typ := g.table.get_type_symbol(elem_type) elem_typ := g.table.sym(elem_type)
get_and_set_types := elem_typ.kind in [.struct_, .map] get_and_set_types := elem_typ.kind in [.struct_, .map]
if g.is_assign_lhs && !g.is_arraymap_set && !get_and_set_types { if g.is_assign_lhs && !g.is_arraymap_set && !get_and_set_types {
if g.assign_op == .assign || info.value_type == ast.string_type { if g.assign_op == .assign || info.value_type == ast.string_type {

View File

@ -448,7 +448,7 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) {
// i.e. `a in [1,2,3]` => `a == 1 || a == 2 || a == 3` // i.e. `a in [1,2,3]` => `a == 1 || a == 2 || a == 3`
fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, right ast.ArrayInit) { fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, right ast.ArrayInit) {
is_str := right.elem_type.idx() == ast.string_type_idx is_str := right.elem_type.idx() == ast.string_type_idx
elem_sym := g.table.get_type_symbol(right.elem_type) elem_sym := g.table.sym(right.elem_type)
is_array := elem_sym.kind == .array is_array := elem_sym.kind == .array
for i, array_expr in right.exprs { for i, array_expr in right.exprs {
if is_str { if is_str {
@ -475,8 +475,8 @@ fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, right ast.ArrayInit) {
// infix_expr_is_op generates code for `is` and `!is` // infix_expr_is_op generates code for `is` and `!is`
fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) { fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) {
sym := g.table.get_type_symbol(node.left_type) sym := g.table.sym(node.left_type)
right_sym := g.table.get_type_symbol(node.right_type) right_sym := g.table.sym(node.right_type)
if sym.kind == .interface_ && right_sym.kind == .interface_ { if sym.kind == .interface_ && right_sym.kind == .interface_ {
g.gen_interface_is_op(node) g.gen_interface_is_op(node)
return return
@ -499,7 +499,7 @@ fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) {
ast.None { g.table.type_idxs['None__'] } ast.None { g.table.type_idxs['None__'] }
else { ast.Type(0) } else { ast.Type(0) }
} }
sub_sym := g.table.get_type_symbol(sub_type) sub_sym := g.table.sym(sub_type)
g.write('_${c_name(sym.name)}_${c_name(sub_sym.name)}_index') g.write('_${c_name(sym.name)}_${c_name(sub_sym.name)}_index')
return return
} else if sym.kind == .sum_type { } else if sym.kind == .sum_type {
@ -509,8 +509,8 @@ fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) {
} }
fn (mut g Gen) gen_interface_is_op(node ast.InfixExpr) { fn (mut g Gen) gen_interface_is_op(node ast.InfixExpr) {
mut left_sym := g.table.get_type_symbol(node.left_type) mut left_sym := g.table.sym(node.left_type)
right_sym := g.table.get_type_symbol(node.right_type) right_sym := g.table.sym(node.right_type)
mut info := left_sym.info as ast.Interface mut info := left_sym.info as ast.Interface
@ -595,7 +595,7 @@ fn (mut g Gen) infix_expr_left_shift_op(node ast.InfixExpr) {
} else { } else {
// push a single element // push a single element
elem_type_str := g.typ(array_info.elem_type) elem_type_str := g.typ(array_info.elem_type)
elem_sym := g.table.get_type_symbol(array_info.elem_type) elem_sym := g.table.sym(array_info.elem_type)
g.write('array_push${noscan}((array*)') g.write('array_push${noscan}((array*)')
if node.left_type.has_flag(.shared_f) && !node.left_type.deref().is_ptr() { if node.left_type.has_flag(.shared_f) && !node.left_type.deref().is_ptr() {
} }
@ -631,7 +631,7 @@ fn (mut g Gen) infix_expr_left_shift_op(node ast.InfixExpr) {
fn (mut g Gen) need_tmp_var_in_array_call(node ast.Expr) bool { fn (mut g Gen) need_tmp_var_in_array_call(node ast.Expr) bool {
match node { match node {
ast.CallExpr { ast.CallExpr {
if node.left_type != 0 && g.table.get_type_symbol(node.left_type).kind == .array if node.left_type != 0 && g.table.sym(node.left_type).kind == .array
&& node.name in ['all', 'any', 'filter', 'map'] { && node.name in ['all', 'any', 'filter', 'map'] {
return true return true
} }

View File

@ -20,7 +20,7 @@ import strings
// Codegen json_decode/encode funcs // Codegen json_decode/encode funcs
fn (mut g Gen) gen_json_for_type(typ ast.Type) { fn (mut g Gen) gen_json_for_type(typ ast.Type) {
utyp := g.unwrap_generic(typ).set_nr_muls(0) utyp := g.unwrap_generic(typ).set_nr_muls(0)
sym := g.table.get_type_symbol(utyp) sym := g.table.sym(utyp)
if is_js_prim(sym.name) || sym.kind == .enum_ { if is_js_prim(sym.name) || sym.kind == .enum_ {
return return
} }
@ -37,7 +37,7 @@ fn (mut g Gen) gen_jsons() {
done << utyp done << utyp
mut dec := strings.new_builder(100) mut dec := strings.new_builder(100)
mut enc := strings.new_builder(100) mut enc := strings.new_builder(100)
sym := g.table.get_type_symbol(utyp) sym := g.table.sym(utyp)
styp := g.typ(utyp) styp := g.typ(utyp)
g.register_optional(utyp) g.register_optional(utyp)
// println('gen_json_for_type($sym.name)') // println('gen_json_for_type($sym.name)')
@ -85,7 +85,7 @@ $enc_fn_dec {
} else if sym.kind == .alias { } else if sym.kind == .alias {
a := sym.info as ast.Alias a := sym.info as ast.Alias
parent_typ := a.parent_type parent_typ := a.parent_type
psym := g.table.get_type_symbol(parent_typ) psym := g.table.sym(parent_typ)
if is_js_prim(g.typ(parent_typ)) { if is_js_prim(g.typ(parent_typ)) {
g.gen_json_for_type(parent_typ) g.gen_json_for_type(parent_typ)
continue continue
@ -146,7 +146,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(sym ast.TypeSymbol, mut enc strings.Builder,
for variant in info.variants { for variant in info.variants {
variant_typ := g.typ(variant) variant_typ := g.typ(variant)
variant_types << variant_typ variant_types << variant_typ
variant_sym := g.table.get_type_symbol(variant) variant_sym := g.table.sym(variant)
variant_symbols << variant_sym variant_symbols << variant_sym
at_least_one_prim = at_least_one_prim || is_js_prim(variant_typ) at_least_one_prim = at_least_one_prim || is_js_prim(variant_typ)
|| variant_sym.kind == .enum_ || variant_sym.name == 'time.Time' || variant_sym.kind == .enum_ || variant_sym.name == 'time.Time'
@ -323,7 +323,7 @@ fn (mut g Gen) gen_struct_enc_dec(type_info ast.TypeInfo, styp string, mut enc s
continue continue
} }
field_type := g.typ(field.typ) field_type := g.typ(field.typ)
field_sym := g.table.get_type_symbol(field.typ) field_sym := g.table.sym(field.typ)
// First generate decoding // First generate decoding
if is_raw { if is_raw {
dec.writeln('\tres.${c_name(field.name)} = tos5(cJSON_PrintUnformatted(' + dec.writeln('\tres.${c_name(field.name)} = tos5(cJSON_PrintUnformatted(' +
@ -470,7 +470,7 @@ fn (mut g Gen) encode_array(value_type ast.Type) string {
fn (mut g Gen) decode_map(key_type ast.Type, value_type ast.Type) string { fn (mut g Gen) decode_map(key_type ast.Type, value_type ast.Type) string {
styp := g.typ(key_type) styp := g.typ(key_type)
styp_v := g.typ(value_type) styp_v := g.typ(value_type)
key_type_symbol := g.table.get_type_symbol(key_type) key_type_symbol := g.table.sym(key_type)
hash_fn, key_eq_fn, clone_fn, free_fn := g.map_fn_ptrs(key_type_symbol) hash_fn, key_eq_fn, clone_fn, free_fn := g.map_fn_ptrs(key_type_symbol)
fn_name_v := js_dec_name(styp_v) fn_name_v := js_dec_name(styp_v)
mut s := '' mut s := ''

View File

@ -50,7 +50,7 @@ fn (mut g Gen) sql_stmt(node ast.SqlStmt) {
fn (mut g Gen) sql_stmt_line(nd ast.SqlStmtLine, expr string) { fn (mut g Gen) sql_stmt_line(nd ast.SqlStmtLine, expr string) {
mut node := nd mut node := nd
table_name := g.get_table_name(node.table_expr) table_name := g.get_table_name(node.table_expr)
g.sql_table_name = g.table.get_type_symbol(node.table_expr.typ).name g.sql_table_name = g.table.sym(node.table_expr.typ).name
res := g.new_tmp_var() res := g.new_tmp_var()
mut subs := false mut subs := false
mut dcheck := false mut dcheck := false
@ -111,7 +111,7 @@ fn (mut g Gen) sql_create_table(node ast.SqlStmtLine, expr string, table_name st
if node.fields.len > 0 { if node.fields.len > 0 {
g.write(' _MOV((orm__TableField[$node.fields.len]){') g.write(' _MOV((orm__TableField[$node.fields.len]){')
for field in node.fields { for field in node.fields {
sym := g.table.get_type_symbol(field.typ) sym := g.table.sym(field.typ)
g.write('(orm__TableField){') g.write('(orm__TableField){')
g.write('.name = _SLIT("$field.name"),') g.write('.name = _SLIT("$field.name"),')
mut typ := int(field.typ) mut typ := int(field.typ)
@ -154,7 +154,7 @@ fn (mut g Gen) sql_insert(node ast.SqlStmtLine, expr string, table_name string,
mut field_names := []string{} mut field_names := []string{}
for f in node.fields { for f in node.fields {
sym := g.table.get_type_symbol(f.typ) sym := g.table.sym(f.typ)
if sym.kind == .struct_ && sym.name != 'time.Time' { if sym.kind == .struct_ && sym.name != 'time.Time' {
subs << node.sub_structs[int(f.typ)] subs << node.sub_structs[int(f.typ)]
} else if sym.kind == .array { } else if sym.kind == .array {
@ -178,7 +178,7 @@ fn (mut g Gen) sql_insert(node ast.SqlStmtLine, expr string, table_name string,
} }
} }
fields := node.fields.filter(g.table.get_type_symbol(it.typ).kind != .array) fields := node.fields.filter(g.table.sym(it.typ).kind != .array)
for sub in subs { for sub in subs {
g.sql_stmt_line(sub, expr) g.sql_stmt_line(sub, expr)
@ -209,7 +209,7 @@ fn (mut g Gen) sql_insert(node ast.SqlStmtLine, expr string, table_name string,
g.write('$pid, ') g.write('$pid, ')
continue continue
} }
mut sym := g.table.get_type_symbol(f.typ) mut sym := g.table.sym(f.typ)
mut typ := sym.cname mut typ := sym.cname
if sym.kind == .struct_ && typ != 'time__Time' { if sym.kind == .struct_ && typ != 'time__Time' {
g.write('(*(orm__Primitive*) array_get($last_ids_arr, $structs)),') g.write('(*(orm__Primitive*) array_get($last_ids_arr, $structs)),')
@ -336,7 +336,7 @@ fn (mut g Gen) sql_expr_to_orm_primitive(expr ast.Expr) {
} }
fn (mut g Gen) sql_write_orm_primitive(t ast.Type, expr ast.Expr) { fn (mut g Gen) sql_write_orm_primitive(t ast.Type, expr ast.Expr) {
mut sym := g.table.get_type_symbol(t) mut sym := g.table.sym(t)
mut typ := sym.cname mut typ := sym.cname
if typ == 'orm__Primitive' { if typ == 'orm__Primitive' {
g.expr(expr) g.expr(expr)
@ -550,7 +550,7 @@ fn (mut g Gen) sql_select(node ast.SqlExpr, expr string, left string) {
res := g.new_tmp_var() res := g.new_tmp_var()
table_name := g.get_table_name(node.table_expr) table_name := g.get_table_name(node.table_expr)
g.sql_table_name = g.table.get_type_symbol(node.table_expr.typ).name g.sql_table_name = g.table.sym(node.table_expr.typ).name
g.write('Option_Array_Array_orm__Primitive _o$res = orm__Connection_name_table[${expr}._typ]._method_select(${expr}._object, ') g.write('Option_Array_Array_orm__Primitive _o$res = orm__Connection_name_table[${expr}._typ]._method_select(${expr}._object, ')
g.write('(orm__SelectConfig){') g.write('(orm__SelectConfig){')
g.write('.table = _SLIT("$table_name"),') g.write('.table = _SLIT("$table_name"),')
@ -572,14 +572,14 @@ fn (mut g Gen) sql_select(node ast.SqlExpr, expr string, left string) {
if prim != '' { if prim != '' {
g.write('.primary = _SLIT("$prim"),') g.write('.primary = _SLIT("$prim"),')
} }
select_fields := fields.filter(g.table.get_type_symbol(it.typ).kind != .array) select_fields := fields.filter(g.table.sym(it.typ).kind != .array)
g.write('.fields = new_array_from_c_array($select_fields.len, $select_fields.len, sizeof(string),') g.write('.fields = new_array_from_c_array($select_fields.len, $select_fields.len, sizeof(string),')
mut types := []int{} mut types := []int{}
if select_fields.len > 0 { if select_fields.len > 0 {
g.write(' _MOV((string[$select_fields.len]){') g.write(' _MOV((string[$select_fields.len]){')
for field in select_fields { for field in select_fields {
g.write('_SLIT("${g.get_field_name(field)}"),') g.write('_SLIT("${g.get_field_name(field)}"),')
sym := g.table.get_type_symbol(field.typ) sym := g.table.sym(field.typ)
if sym.name == 'time.Time' { if sym.name == 'time.Time' {
types << -2 types << -2
continue continue
@ -648,12 +648,12 @@ fn (mut g Gen) sql_select(node ast.SqlExpr, expr string, left string) {
g.writeln('int $idx = 0;') g.writeln('int $idx = 0;')
mut typ_str := '' mut typ_str := ''
if node.is_array { if node.is_array {
info := g.table.get_type_symbol(node.typ).array_info() info := g.table.sym(node.typ).array_info()
typ_str = g.typ(info.elem_type) typ_str = g.typ(info.elem_type)
g.writeln('$styp ${tmp}_array = __new_array(0, ${res}.len, sizeof($typ_str));') g.writeln('$styp ${tmp}_array = __new_array(0, ${res}.len, sizeof($typ_str));')
g.writeln('for (; $idx < ${res}.len; $idx++) {') g.writeln('for (; $idx < ${res}.len; $idx++) {')
g.write('\t$typ_str $tmp = ($typ_str) {') g.write('\t$typ_str $tmp = ($typ_str) {')
inf := g.table.get_type_symbol(info.elem_type).struct_info() inf := g.table.sym(info.elem_type).struct_info()
for i, field in inf.fields { for i, field in inf.fields {
g.zero_struct_field(field) g.zero_struct_field(field)
if i != inf.fields.len - 1 { if i != inf.fields.len - 1 {
@ -663,7 +663,7 @@ fn (mut g Gen) sql_select(node ast.SqlExpr, expr string, left string) {
g.writeln('};') g.writeln('};')
} else { } else {
g.write('$styp $tmp = ($styp){') g.write('$styp $tmp = ($styp){')
info := g.table.get_type_symbol(node.typ).struct_info() info := g.table.sym(node.typ).struct_info()
for i, field in info.fields { for i, field in info.fields {
g.zero_struct_field(field) g.zero_struct_field(field)
if i != info.fields.len - 1 { if i != info.fields.len - 1 {
@ -676,7 +676,7 @@ fn (mut g Gen) sql_select(node ast.SqlExpr, expr string, left string) {
g.writeln('if (${res}.len > 0) {') g.writeln('if (${res}.len > 0) {')
for i, field in fields { for i, field in fields {
sel := '(*(orm__Primitive*) array_get((*(Array_orm__Primitive*) array_get($res, $idx)), $i))' sel := '(*(orm__Primitive*) array_get((*(Array_orm__Primitive*) array_get($res, $idx)), $i))'
sym := g.table.get_type_symbol(field.typ) sym := g.table.sym(field.typ)
if sym.kind == .struct_ && sym.name != 'time.Time' { if sym.kind == .struct_ && sym.name != 'time.Time' {
mut sub := node.sub_structs[int(field.typ)] mut sub := node.sub_structs[int(field.typ)]
mut where_expr := sub.where_expr as ast.InfixExpr mut where_expr := sub.where_expr as ast.InfixExpr
@ -801,8 +801,8 @@ fn (mut g Gen) parse_db_from_type_string(name string) SqlType {
} }
fn (mut g Gen) get_table_name(table_expr ast.TypeNode) string { fn (mut g Gen) get_table_name(table_expr ast.TypeNode) string {
info := g.table.get_type_symbol(table_expr.typ).struct_info() info := g.table.sym(table_expr.typ).struct_info()
mut tablename := util.strip_mod_name(g.table.get_type_symbol(table_expr.typ).name) mut tablename := util.strip_mod_name(g.table.sym(table_expr.typ).name)
for attr in info.attrs { for attr in info.attrs {
if attr.kind == .string && attr.name == 'table' && attr.arg != '' { if attr.kind == .string && attr.name == 'table' && attr.arg != '' {
tablename = attr.arg tablename = attr.arg
@ -813,7 +813,7 @@ fn (mut g Gen) get_table_name(table_expr ast.TypeNode) string {
} }
fn (mut g Gen) get_struct_field(name string) ast.StructField { fn (mut g Gen) get_struct_field(name string) ast.StructField {
info := g.table.get_type_symbol(g.table.type_idxs[g.sql_table_name]).struct_info() info := g.table.sym(g.table.type_idxs[g.sql_table_name]).struct_info()
mut f := ast.StructField{} mut f := ast.StructField{}
for field in info.fields { for field in info.fields {
if field.name == name { if field.name == name {
@ -831,7 +831,7 @@ fn (mut g Gen) get_field_name(field ast.StructField) string {
break break
} }
} }
sym := g.table.get_type_symbol(field.typ) sym := g.table.sym(field.typ)
if sym.kind == .struct_ && sym.name != 'time.Time' { if sym.kind == .struct_ && sym.name != 'time.Time' {
name = '${name}_id' name = '${name}_id'
} }

View File

@ -52,7 +52,7 @@ fn (mut g Gen) string_inter_literal_sb_optimized(call_expr ast.CallExpr) {
typ := node.expr_types[i] typ := node.expr_types[i]
g.write(g.typ(typ)) g.write(g.typ(typ))
g.write('_str(') g.write('_str(')
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
if sym.kind != .function { if sym.kind != .function {
g.expr(node.exprs[i]) g.expr(node.exprs[i])
} }
@ -69,10 +69,10 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
if is_shared { if is_shared {
typ = typ.clear_flag(.shared_f).set_nr_muls(0) typ = typ.clear_flag(.shared_f).set_nr_muls(0)
} }
mut sym := g.table.get_type_symbol(typ) mut sym := g.table.sym(typ)
// when type is alias, print the aliased value // when type is alias, print the aliased value
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
parent_sym := g.table.get_type_symbol(sym.info.parent_type) parent_sym := g.table.sym(sym.info.parent_type)
if parent_sym.has_method('str') { if parent_sym.has_method('str') {
typ = sym.info.parent_type typ = sym.info.parent_type
sym = parent_sym sym = parent_sym

View File

@ -16,7 +16,7 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int) (u64, string) {
mut base := 0 // numeric base mut base := 0 // numeric base
mut upper_case := false // set upercase for the result string mut upper_case := false // set upercase for the result string
mut typ := g.unwrap_generic(node.expr_types[i]) mut typ := g.unwrap_generic(node.expr_types[i])
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
if sym.kind == .alias { if sym.kind == .alias {
typ = (sym.info as ast.Alias).parent_type typ = (sym.info as ast.Alias).parent_type
} }
@ -125,7 +125,7 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int) {
expr := node.exprs[i] expr := node.exprs[i]
typ := g.unwrap_generic(node.expr_types[i]) typ := g.unwrap_generic(node.expr_types[i])
typ_sym := g.table.get_type_symbol(typ) typ_sym := g.table.sym(typ)
if typ == ast.string_type && g.comptime_for_method.len == 0 { if typ == ast.string_type && g.comptime_for_method.len == 0 {
if g.inside_vweb_tmpl { if g.inside_vweb_tmpl {
g.write('vweb__filter(') g.write('vweb__filter(')
@ -156,7 +156,7 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int) {
if g.comptime_var_type_map.len > 0 || g.comptime_for_method.len > 0 { if g.comptime_var_type_map.len > 0 || g.comptime_for_method.len > 0 {
exp_typ = expr.obj.typ exp_typ = expr.obj.typ
} else if expr.obj.smartcasts.len > 0 { } else if expr.obj.smartcasts.len > 0 {
cast_sym := g.table.get_type_symbol(expr.obj.smartcasts.last()) cast_sym := g.table.sym(expr.obj.smartcasts.last())
if cast_sym.info is ast.Aggregate { if cast_sym.info is ast.Aggregate {
exp_typ = cast_sym.info.types[g.aggregate_type_idx] exp_typ = cast_sym.info.types[g.aggregate_type_idx]
} }

View File

@ -43,7 +43,7 @@ struct Type {
// * alias unwrapped // * alias unwrapped
fn (mut g Gen) unwrap(typ ast.Type) Type { fn (mut g Gen) unwrap(typ ast.Type) Type {
no_generic := g.unwrap_generic(typ) no_generic := g.unwrap_generic(typ)
no_generic_sym := g.table.get_type_symbol(no_generic) no_generic_sym := g.table.sym(no_generic)
if no_generic_sym.kind != .alias { if no_generic_sym.kind != .alias {
return Type{ return Type{
typ: no_generic typ: no_generic
@ -56,6 +56,6 @@ fn (mut g Gen) unwrap(typ ast.Type) Type {
typ: no_generic typ: no_generic
sym: no_generic_sym sym: no_generic_sym
unaliased: no_generic_sym.parent_idx unaliased: no_generic_sym.parent_idx
unaliased_sym: g.table.get_type_symbol(no_generic_sym.parent_idx) unaliased_sym: g.table.sym(no_generic_sym.parent_idx)
} }
} }

View File

@ -15,13 +15,13 @@ const (
fn (mut g JsGen) gen_array_index_method(left_type ast.Type) string { fn (mut g JsGen) gen_array_index_method(left_type ast.Type) string {
unwrap_left_type := g.unwrap_generic(left_type) unwrap_left_type := g.unwrap_generic(left_type)
mut left_sym := g.table.get_type_symbol(unwrap_left_type) mut left_sym := g.table.sym(unwrap_left_type)
mut left_type_str := g.typ(unwrap_left_type).trim('*') mut left_type_str := g.typ(unwrap_left_type).trim('*')
fn_name := '${left_type_str}_index' fn_name := '${left_type_str}_index'
if !left_sym.has_method('index') { if !left_sym.has_method('index') {
info := left_sym.info as ast.Array info := left_sym.info as ast.Array
elem_sym := g.table.get_type_symbol(info.elem_type) elem_sym := g.table.sym(info.elem_type)
if elem_sym.kind == .function { if elem_sym.kind == .function {
left_type_str = 'Array_voidptr' left_type_str = 'Array_voidptr'
} }
@ -79,7 +79,7 @@ fn (mut g JsGen) gen_array_method_call(it ast.CallExpr) {
} }
'insert' { 'insert' {
g.write('array_') g.write('array_')
arg2_sym := g.table.get_type_symbol(node.args[1].typ) arg2_sym := g.table.sym(node.args[1].typ)
is_arg2_array := arg2_sym.kind == .array && node.args[1].typ == node.left_type is_arg2_array := arg2_sym.kind == .array && node.args[1].typ == node.left_type
if is_arg2_array { if is_arg2_array {
g.write('insert_many(') g.write('insert_many(')
@ -108,7 +108,7 @@ fn (mut g JsGen) gen_array_method_call(it ast.CallExpr) {
} }
'prepend' { 'prepend' {
g.write('array_') g.write('array_')
arg_sym := g.table.get_type_symbol(node.args[0].typ) arg_sym := g.table.sym(node.args[0].typ)
is_arg_array := arg_sym.kind == .array && node.args[0].typ == node.left_type is_arg_array := arg_sym.kind == .array && node.args[0].typ == node.left_type
if is_arg_array { if is_arg_array {
g.write('prepend_many(') g.write('prepend_many(')
@ -165,13 +165,13 @@ fn (mut g JsGen) gen_array_contains_method(left_type ast.Type) string {
if unwrap_left_type.share() == .shared_t { if unwrap_left_type.share() == .shared_t {
unwrap_left_type = unwrap_left_type.clear_flag(.shared_f) unwrap_left_type = unwrap_left_type.clear_flag(.shared_f)
} }
mut left_sym := g.table.get_type_symbol(unwrap_left_type) mut left_sym := g.table.sym(unwrap_left_type)
left_final_sym := g.table.get_final_type_symbol(unwrap_left_type) left_final_sym := g.table.final_sym(unwrap_left_type)
mut left_type_str := g.typ(unwrap_left_type).replace('*', '') mut left_type_str := g.typ(unwrap_left_type).replace('*', '')
fn_name := '${left_type_str}_contains' fn_name := '${left_type_str}_contains'
if !left_sym.has_method('contains') { if !left_sym.has_method('contains') {
left_info := left_final_sym.info as ast.Array left_info := left_final_sym.info as ast.Array
elem_sym := g.table.get_type_symbol(left_info.elem_type) elem_sym := g.table.sym(left_info.elem_type)
if elem_sym.kind == .function { if elem_sym.kind == .function {
left_type_str = 'Array_voidptr' left_type_str = 'Array_voidptr'
} }
@ -214,7 +214,7 @@ fn (mut g JsGen) gen_array_contains_method(left_type ast.Type) string {
} }
fn (mut g JsGen) gen_array_sort(node ast.CallExpr) { fn (mut g JsGen) gen_array_sort(node ast.CallExpr) {
rec_sym := g.table.get_type_symbol(node.receiver_type) rec_sym := g.table.sym(node.receiver_type)
if rec_sym.kind != .array { if rec_sym.kind != .array {
println(node.name) println(node.name)
verror('.sort() is an array method') verror('.sort() is an array method')

View File

@ -134,7 +134,7 @@ fn (mut g JsGen) gen_alias_equality_fn(left_type ast.Type) string {
g.definitions.writeln(fn_builder.str()) g.definitions.writeln(fn_builder.str())
} }
fn_builder.writeln('function ${ptr_styp}_alias_eq(a,b) {') fn_builder.writeln('function ${ptr_styp}_alias_eq(a,b) {')
sym := g.table.get_type_symbol(info.parent_type) sym := g.table.sym(info.parent_type)
if sym.kind == .string { if sym.kind == .string {
fn_builder.writeln('\treturn new bool(a.str == b.str);') fn_builder.writeln('\treturn new bool(a.str == b.str);')
} else if sym.kind == .sum_type && !left.typ.is_ptr() { } else if sym.kind == .sum_type && !left.typ.is_ptr() {

View File

@ -26,11 +26,11 @@ fn (mut g JsGen) get_str_fn(typ ast.Type) string {
unwrapped.set_flag(.optional) unwrapped.set_flag(.optional)
} }
styp := g.typ(unwrapped) styp := g.typ(unwrapped)
mut sym := g.table.get_type_symbol(unwrapped) mut sym := g.table.sym(unwrapped)
mut str_fn_name := styp_to_str_fn_name(styp) mut str_fn_name := styp_to_str_fn_name(styp)
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
if sym.info.is_import { if sym.info.is_import {
sym = g.table.get_type_symbol(sym.info.parent_type) sym = g.table.sym(sym.info.parent_type)
str_fn_name = styp_to_str_fn_name(sym.name) str_fn_name = styp_to_str_fn_name(sym.name)
} }
} }
@ -46,7 +46,7 @@ fn (mut g JsGen) final_gen_str(typ StrType) {
return return
} }
g.generated_str_fns << typ g.generated_str_fns << typ
sym := g.table.get_type_symbol(typ.typ) sym := g.table.sym(typ.typ)
if sym.has_method('str') && !typ.typ.has_flag(.optional) { if sym.has_method('str') && !typ.typ.has_flag(.optional) {
return return
} }
@ -218,7 +218,7 @@ fn (mut g JsGen) gen_str_default(sym ast.TypeSymbol, styp string, str_fn_name st
fn (mut g JsGen) gen_str_for_option(typ ast.Type, styp string, str_fn_name string) { fn (mut g JsGen) gen_str_for_option(typ ast.Type, styp string, str_fn_name string) {
parent_type := typ.clear_flag(.optional) parent_type := typ.clear_flag(.optional)
sym := g.table.get_type_symbol(parent_type) sym := g.table.sym(parent_type)
sym_has_str_method, _, _ := sym.str_method_info() sym_has_str_method, _, _ := sym.str_method_info()
parent_str_fn_name := g.get_str_fn(parent_type) parent_str_fn_name := g.get_str_fn(parent_type)
@ -262,7 +262,7 @@ fn (mut g JsGen) gen_str_for_multi_return(info ast.MultiReturn, styp string, str
fn_builder.writeln('\tlet sb = strings__new_builder($info.types.len * 10);') fn_builder.writeln('\tlet sb = strings__new_builder($info.types.len * 10);')
fn_builder.writeln('\tstrings__Builder_write_string(sb, new string("("));') fn_builder.writeln('\tstrings__Builder_write_string(sb, new string("("));')
for i, typ in info.types { for i, typ in info.types {
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
is_arg_ptr := typ.is_ptr() is_arg_ptr := typ.is_ptr()
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info() sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
arg_str_fn_name := g.get_str_fn(typ) arg_str_fn_name := g.get_str_fn(typ)
@ -348,7 +348,7 @@ fn (mut g JsGen) gen_str_for_interface(info ast.Interface, styp string, str_fn_n
clean_interface_v_type_name = util.strip_main_name(clean_interface_v_type_name) clean_interface_v_type_name = util.strip_main_name(clean_interface_v_type_name)
fn_builder.writeln('function indent_${str_fn_name}(x,indent_count) { /* gen_str_for_interface */') fn_builder.writeln('function indent_${str_fn_name}(x,indent_count) { /* gen_str_for_interface */')
for typ in info.types { for typ in info.types {
subtype := g.table.get_type_symbol(typ) subtype := g.table.sym(typ)
mut func_name := g.get_str_fn(typ) mut func_name := g.get_str_fn(typ)
sym_has_str_method, str_method_expects_ptr, _ := subtype.str_method_info() sym_has_str_method, str_method_expects_ptr, _ := subtype.str_method_info()
if should_use_indent_func(subtype.kind) && !sym_has_str_method { if should_use_indent_func(subtype.kind) && !sym_has_str_method {
@ -383,7 +383,7 @@ fn (mut g JsGen) gen_str_for_union_sum_type(info ast.SumType, styp string, str_f
for typ in info.variants { for typ in info.variants {
typ_str := g.typ(typ) typ_str := g.typ(typ)
mut func_name := g.get_str_fn(typ) mut func_name := g.get_str_fn(typ)
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info() sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
deref := if sym_has_str_method && str_method_expects_ptr { deref := if sym_has_str_method && str_method_expects_ptr {
' ' ' '
@ -458,10 +458,10 @@ fn deref_kind(str_method_expects_ptr bool, is_elem_ptr bool, typ ast.Type) (stri
fn (mut g JsGen) gen_str_for_array(info ast.Array, styp string, str_fn_name string) { fn (mut g JsGen) gen_str_for_array(info ast.Array, styp string, str_fn_name string) {
mut typ := info.elem_type mut typ := info.elem_type
mut sym := g.table.get_type_symbol(info.elem_type) mut sym := g.table.sym(info.elem_type)
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
typ = sym.info.parent_type typ = sym.info.parent_type
sym = g.table.get_type_symbol(typ) sym = g.table.sym(typ)
} }
is_elem_ptr := typ.is_ptr() is_elem_ptr := typ.is_ptr()
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info() sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
@ -518,10 +518,10 @@ fn (mut g JsGen) gen_str_for_array(info ast.Array, styp string, str_fn_name stri
fn (mut g JsGen) gen_str_for_array_fixed(info ast.ArrayFixed, styp string, str_fn_name string) { fn (mut g JsGen) gen_str_for_array_fixed(info ast.ArrayFixed, styp string, str_fn_name string) {
mut typ := info.elem_type mut typ := info.elem_type
mut sym := g.table.get_type_symbol(info.elem_type) mut sym := g.table.sym(info.elem_type)
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
typ = sym.info.parent_type typ = sym.info.parent_type
sym = g.table.get_type_symbol(typ) sym = g.table.sym(typ)
} }
is_elem_ptr := typ.is_ptr() is_elem_ptr := typ.is_ptr()
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info() sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
@ -572,10 +572,10 @@ fn (mut g JsGen) gen_str_for_array_fixed(info ast.ArrayFixed, styp string, str_f
fn (mut g JsGen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) { fn (mut g JsGen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
mut key_typ := info.key_type mut key_typ := info.key_type
mut key_sym := g.table.get_type_symbol(key_typ) mut key_sym := g.table.sym(key_typ)
if mut key_sym.info is ast.Alias { if mut key_sym.info is ast.Alias {
key_typ = key_sym.info.parent_type key_typ = key_sym.info.parent_type
key_sym = g.table.get_type_symbol(key_typ) key_sym = g.table.sym(key_typ)
} }
key_styp := g.typ(key_typ) key_styp := g.typ(key_typ)
key_str_fn_name := key_styp.replace('*', '') + '_str' key_str_fn_name := key_styp.replace('*', '') + '_str'
@ -584,10 +584,10 @@ fn (mut g JsGen) gen_str_for_map(info ast.Map, styp string, str_fn_name string)
} }
mut val_typ := info.value_type mut val_typ := info.value_type
mut val_sym := g.table.get_type_symbol(val_typ) mut val_sym := g.table.sym(val_typ)
if mut val_sym.info is ast.Alias { if mut val_sym.info is ast.Alias {
val_typ = val_sym.info.parent_type val_typ = val_sym.info.parent_type
val_sym = g.table.get_type_symbol(val_typ) val_sym = g.table.sym(val_typ)
} }
val_styp := g.typ(val_typ) val_styp := g.typ(val_typ)
elem_str_fn_name := val_styp.replace('*', '') + '_str' elem_str_fn_name := val_styp.replace('*', '') + '_str'
@ -656,7 +656,7 @@ fn (g &JsGen) type_to_fmt(typ ast.Type) StrIntpType {
// return '%C\\000' // a C string // return '%C\\000' // a C string
return .si_s return .si_s
} }
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
if typ.is_ptr() && (typ.is_int_valptr() || typ.is_float_valptr()) { if typ.is_ptr() && (typ.is_int_valptr() || typ.is_float_valptr()) {
return .si_s return .si_s
} else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_,
@ -726,7 +726,7 @@ fn (mut g JsGen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name st
} }
quote_str = quote_str quote_str = quote_str
*/ */
sym := g.table.get_type_symbol(g.unwrap_generic(field.typ)) sym := g.table.sym(g.unwrap_generic(field.typ))
// first fields doesn't need \n // first fields doesn't need \n
if i == 0 { if i == 0 {
fn_builder.write_string('res.str += " $field.name: $ptr_amp$prefix" + ') fn_builder.write_string('res.str += " $field.name: $ptr_amp$prefix" + ')

View File

@ -22,7 +22,7 @@ fn (mut g JsGen) copy_val(t ast.Type, tmp string) string {
} }
fn (mut g JsGen) to_js_typ_val(t ast.Type) string { fn (mut g JsGen) to_js_typ_val(t ast.Type) string {
sym := g.table.get_type_symbol(t) sym := g.table.sym(t)
mut styp := '' mut styp := ''
mut prefix := 'new ' mut prefix := 'new '
match sym.kind { match sym.kind {
@ -135,7 +135,7 @@ fn (mut g JsGen) base_type(_t ast.Type) string {
} }
pub fn (mut g JsGen) typ(t ast.Type) string { pub fn (mut g JsGen) typ(t ast.Type) string {
sym := g.table.get_final_type_symbol(t) sym := g.table.final_sym(t)
if sym.kind == .voidptr { if sym.kind == .voidptr {
return 'voidptr' return 'voidptr'
} }
@ -146,7 +146,7 @@ pub fn (mut g JsGen) typ(t ast.Type) string {
// V type to JS type // V type to JS type
pub fn (mut g JsGen) doc_typ(t ast.Type) string { pub fn (mut g JsGen) doc_typ(t ast.Type) string {
sym := g.table.get_type_symbol(t) sym := g.table.sym(t)
mut styp := '' mut styp := ''
match sym.kind { match sym.kind {
.placeholder { .placeholder {
@ -214,7 +214,7 @@ pub fn (mut g JsGen) doc_typ(t ast.Type) string {
styp = 'union_sym_type' styp = 'union_sym_type'
} }
.alias { .alias {
fsym := g.table.get_final_type_symbol(t) fsym := g.table.final_sym(t)
name := g.js_name(fsym.name) name := g.js_name(fsym.name)
styp += '$name' styp += '$name'
} }

View File

@ -96,11 +96,11 @@ fn (mut g JsGen) comptime_if_cond(cond ast.Expr, pkg_exist bool) bool {
// Handle `$if x is Interface {` // Handle `$if x is Interface {`
// mut matches_interface := 'false' // mut matches_interface := 'false'
if left is ast.TypeNode && cond.right is ast.TypeNode if left is ast.TypeNode && cond.right is ast.TypeNode
&& g.table.get_type_symbol(got_type).kind == .interface_ { && g.table.sym(got_type).kind == .interface_ {
// `$if Foo is Interface {` // `$if Foo is Interface {`
interface_sym := g.table.get_type_symbol(got_type) interface_sym := g.table.sym(got_type)
if interface_sym.info is ast.Interface { if interface_sym.info is ast.Interface {
// q := g.table.get_type_symbol(interface_sym.info.types[0]) // q := g.table.sym(interface_sym.info.types[0])
checked_type := g.unwrap_generic(left.typ) checked_type := g.unwrap_generic(left.typ)
// TODO PERF this check is run twice (also in the checker) // TODO PERF this check is run twice (also in the checker)
// store the result in a field // store the result in a field

View File

@ -22,11 +22,11 @@ fn (mut g JsGen) get_copy_fn(typ ast.Type) string {
unwrapped.set_flag(.optional) unwrapped.set_flag(.optional)
} }
styp := g.typ(unwrapped) styp := g.typ(unwrapped)
mut sym := g.table.get_type_symbol(unwrapped) mut sym := g.table.sym(unwrapped)
mut copy_fn_name := styp_to_copy_fn_name(styp) mut copy_fn_name := styp_to_copy_fn_name(styp)
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
if sym.info.is_import { if sym.info.is_import {
sym = g.table.get_type_symbol(sym.info.parent_type) sym = g.table.sym(sym.info.parent_type)
copy_fn_name = styp_to_copy_fn_name(sym.name) copy_fn_name = styp_to_copy_fn_name(sym.name)
} }
} }
@ -55,7 +55,7 @@ fn (mut g JsGen) gen_copy_for_multi_return(info ast.MultiReturn, styp string, co
fn_builder.writeln('function ${copy_fn_name}(a) {') fn_builder.writeln('function ${copy_fn_name}(a) {')
fn_builder.writeln('\tlet arr = []') fn_builder.writeln('\tlet arr = []')
for i, typ in info.types { for i, typ in info.types {
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
arg_copy_fn_name := g.get_copy_fn(typ) arg_copy_fn_name := g.get_copy_fn(typ)
if sym.kind in [.f32, .f64] { if sym.kind in [.f32, .f64] {
@ -108,7 +108,7 @@ fn (mut g JsGen) gen_copy_for_interface(info ast.Interface, styp string, copy_fn
fn_builder.writeln('function ${copy_fn_name}(x) { return x; }') fn_builder.writeln('function ${copy_fn_name}(x) { return x; }')
/* /*
for typ in info.types { for typ in info.types {
subtype := g.table.get_type_symbol(typ) subtype := g.table.sym(typ)
mut func_name := g.get_copy_fn(typ) mut func_name := g.get_copy_fn(typ)
if typ == ast.string_type { if typ == ast.string_type {
@ -188,7 +188,7 @@ fn (mut g JsGen) final_gen_copy(typ StrType) {
return return
} }
g.generated_copy_fns << typ g.generated_copy_fns << typ
sym := g.table.get_type_symbol(typ.typ) sym := g.table.sym(typ.typ)
if sym.has_method('\$copy') && !typ.typ.has_flag(.optional) { if sym.has_method('\$copy') && !typ.typ.has_flag(.optional) {
return return
} }

View File

@ -190,8 +190,7 @@ fn (mut g JsGen) method_call(node ast.CallExpr) {
g.gen_expr_to_string(node.left, node.left_type) g.gen_expr_to_string(node.left, node.left_type)
return return
} }
is_async := node.name == 'wait' is_async := node.name == 'wait' && g.table.sym(node.receiver_type).name.starts_with('Promise<')
&& g.table.get_type_symbol(node.receiver_type).name.starts_with('Promise<')
call_return_is_optional := it.return_type.has_flag(.optional) call_return_is_optional := it.return_type.has_flag(.optional)
if call_return_is_optional { if call_return_is_optional {
if is_async { if is_async {
@ -215,10 +214,10 @@ fn (mut g JsGen) method_call(node ast.CallExpr) {
if g.fn_decl != 0 && g.fn_decl.generic_names.len > 0 { // in generic fn if g.fn_decl != 0 && g.fn_decl.generic_names.len > 0 { // in generic fn
unwrapped_rec_type = g.unwrap_generic(node.receiver_type) unwrapped_rec_type = g.unwrap_generic(node.receiver_type)
} else { // in non-generic fn } else { // in non-generic fn
sym := g.table.get_type_symbol(node.receiver_type) sym := g.table.sym(node.receiver_type)
match sym.info { match sym.info {
ast.Struct, ast.Interface, ast.SumType { ast.Struct, ast.Interface, ast.SumType {
generic_names := sym.info.generic_types.map(g.table.get_type_symbol(it).name) generic_names := sym.info.generic_types.map(g.table.sym(it).name)
// see comment at top of vlib/v/gen/c/utils.v // see comment at top of vlib/v/gen/c/utils.v
mut muttable := unsafe { &ast.Table(g.table) } mut muttable := unsafe { &ast.Table(g.table) }
if utyp := muttable.resolve_generic_to_concrete(node.receiver_type, generic_names, if utyp := muttable.resolve_generic_to_concrete(node.receiver_type, generic_names,
@ -231,13 +230,13 @@ fn (mut g JsGen) method_call(node ast.CallExpr) {
} }
} }
mut typ_sym := g.table.get_type_symbol(unwrapped_rec_type) mut typ_sym := g.table.sym(unwrapped_rec_type)
rec_cc_type := g.cc_type(unwrapped_rec_type, false) rec_cc_type := g.cc_type(unwrapped_rec_type, false)
mut receiver_type_name := util.no_dots(rec_cc_type) mut receiver_type_name := util.no_dots(rec_cc_type)
// alias type that undefined this method (not include `str`) need to use parent type // alias type that undefined this method (not include `str`) need to use parent type
if typ_sym.kind == .alias && node.name != 'str' && !typ_sym.has_method(node.name) { if typ_sym.kind == .alias && node.name != 'str' && !typ_sym.has_method(node.name) {
unwrapped_rec_type = (typ_sym.info as ast.Alias).parent_type unwrapped_rec_type = (typ_sym.info as ast.Alias).parent_type
typ_sym = g.table.get_type_symbol(unwrapped_rec_type) typ_sym = g.table.sym(unwrapped_rec_type)
} }
if typ_sym.kind == .interface_ && (typ_sym.info as ast.Interface).defines_method(node.name) { if typ_sym.kind == .interface_ && (typ_sym.info as ast.Interface).defines_method(node.name) {
@ -254,8 +253,8 @@ fn (mut g JsGen) method_call(node ast.CallExpr) {
return return
} }
left_sym := g.table.get_type_symbol(node.left_type) left_sym := g.table.sym(node.left_type)
final_left_sym := g.table.get_final_type_symbol(node.left_type) final_left_sym := g.table.final_sym(node.left_type)
if final_left_sym.kind == .array { if final_left_sym.kind == .array {
if final_left_sym.kind == .array && it.name in ['map', 'filter'] { if final_left_sym.kind == .array && it.name in ['map', 'filter'] {
@ -283,7 +282,7 @@ fn (mut g JsGen) method_call(node ast.CallExpr) {
g.write(')') g.write(')')
return return
} else if expr.kind == .variable { } else if expr.kind == .variable {
v_sym := g.table.get_type_symbol(expr.var_info().typ) v_sym := g.table.sym(expr.var_info().typ)
if v_sym.kind == .function { if v_sym.kind == .function {
g.write(g.js_name(expr.name)) g.write(g.js_name(expr.name))
g.write(')') g.write(')')
@ -376,7 +375,7 @@ fn (mut g JsGen) gen_call_expr(it ast.CallExpr) {
if it.should_be_skipped { if it.should_be_skipped {
return return
} }
if it.is_method && g.table.get_type_symbol(it.receiver_type).name.starts_with('JS.') { if it.is_method && g.table.sym(it.receiver_type).name.starts_with('JS.') {
g.js_method_call(it) g.js_method_call(it)
return return
} else if it.name.starts_with('JS.') { } else if it.name.starts_with('JS.') {
@ -396,7 +395,7 @@ fn (mut g JsGen) gen_call_expr(it ast.CallExpr) {
name = 'builtin__$name' name = 'builtin__$name'
} }
print_method := name print_method := name
ret_sym := g.table.get_type_symbol(it.return_type) ret_sym := g.table.sym(it.return_type)
if it.language == .js && ret_sym.name in v_types && ret_sym.name != 'void' { if it.language == .js && ret_sym.name in v_types && ret_sym.name != 'void' {
g.write('new ') g.write('new ')
g.write(ret_sym.name) g.write(ret_sym.name)
@ -479,9 +478,9 @@ enum FnGenType {
} }
fn (g &JsGen) fn_gen_type(it &ast.FnDecl) FnGenType { fn (g &JsGen) fn_gen_type(it &ast.FnDecl) FnGenType {
if it.is_method && g.table.get_type_symbol(it.params[0].typ).kind == .alias { if it.is_method && g.table.sym(it.params[0].typ).kind == .alias {
return .alias_method return .alias_method
} else if it.is_method && g.table.get_type_symbol(it.params[0].typ).kind == .interface_ { } else if it.is_method && g.table.sym(it.params[0].typ).kind == .interface_ {
return .iface_method return .iface_method
} else if it.is_method || it.no_body { } else if it.is_method || it.no_body {
return .struct_method return .struct_method
@ -572,7 +571,7 @@ fn (mut g JsGen) gen_method_decl(it ast.FnDecl, typ FnGenType) {
// loop thru each generic type and generate a function // loop thru each generic type and generate a function
for concrete_types in g.table.fn_generic_types[node.name] { for concrete_types in g.table.fn_generic_types[node.name] {
if g.pref.is_verbose { if g.pref.is_verbose {
syms := concrete_types.map(g.table.get_type_symbol(it)) syms := concrete_types.map(g.table.sym(it))
the_type := syms.map(it.name).join(', ') the_type := syms.map(it.name).join(', ')
println('gen fn `$node.name` for type `$the_type`') println('gen fn `$node.name` for type `$the_type`')
} }
@ -665,7 +664,7 @@ fn (mut g JsGen) gen_method_decl(it ast.FnDecl, typ FnGenType) {
if is_varg { if is_varg {
g.writeln('$arg_name = new array(new array_buffer({arr: $arg_name,len: new int(${arg_name}.length),index_start: new int(0)}));') g.writeln('$arg_name = new array(new array_buffer({arr: $arg_name,len: new int(${arg_name}.length),index_start: new int(0)}));')
} else { } else {
asym := g.table.get_type_symbol(arg.typ) asym := g.table.sym(arg.typ)
if asym.kind != .interface_ && asym.language != .js { if asym.kind != .interface_ && asym.language != .js {
if arg.typ.is_ptr() || arg.is_mut { if arg.typ.is_ptr() || arg.is_mut {
g.writeln('$arg_name = new \$ref($arg_name)') g.writeln('$arg_name = new \$ref($arg_name)')
@ -791,7 +790,7 @@ fn (mut g JsGen) gen_anon_fn(mut fun ast.AnonFn) {
if is_varg { if is_varg {
g.writeln('$arg_name = new array(new array_buffer({arr: $arg_name,len: new int(${arg_name}.length),index_start: new int(0)}));') g.writeln('$arg_name = new array(new array_buffer({arr: $arg_name,len: new int(${arg_name}.length),index_start: new int(0)}));')
} else { } else {
asym := g.table.get_type_symbol(arg.typ) asym := g.table.sym(arg.typ)
if arg.typ.is_ptr() || (arg.is_mut && asym.kind != .interface_ && asym.language != .js) { if arg.typ.is_ptr() || (arg.is_mut && asym.kind != .interface_ && asym.language != .js) {
g.writeln('$arg_name = new \$ref($arg_name)') g.writeln('$arg_name = new \$ref($arg_name)')

View File

@ -5,8 +5,8 @@ import v.ast
fn (mut g JsGen) gen_plain_infix_expr(node ast.InfixExpr) { fn (mut g JsGen) gen_plain_infix_expr(node ast.InfixExpr) {
it := node it := node
l_sym := g.table.get_final_type_symbol(it.left_type) l_sym := g.table.final_sym(it.left_type)
r_sym := g.table.get_final_type_symbol(it.right_type) r_sym := g.table.final_sym(it.right_type)
greater_typ := g.greater_typ(it.left_type, it.right_type) greater_typ := g.greater_typ(it.left_type, it.right_type)
cast_ty := if greater_typ == it.left_type { l_sym.cname } else { r_sym.cname } cast_ty := if greater_typ == it.left_type { l_sym.cname } else { r_sym.cname }
g.write('new ${g.js_name(cast_ty)}( ') g.write('new ${g.js_name(cast_ty)}( ')
@ -338,7 +338,7 @@ fn (mut g JsGen) infix_in_not_in_op(node ast.InfixExpr) {
fn (mut g JsGen) infix_is_not_is_op(node ast.InfixExpr) { fn (mut g JsGen) infix_is_not_is_op(node ast.InfixExpr) {
g.expr(node.left) g.expr(node.left)
rsym := g.table.get_type_symbol(g.unwrap(node.right_type).typ) rsym := g.table.sym(g.unwrap(node.right_type).typ)
g.gen_deref_ptr(node.left_type) g.gen_deref_ptr(node.left_type)
g.write(' instanceof ') g.write(' instanceof ')

View File

@ -177,9 +177,9 @@ pub fn gen(files []&ast.File, table &ast.Table, pref &pref.Preferences) string {
for iface_name, iface_types in g.table.iface_types { for iface_name, iface_types in g.table.iface_types {
iface := g.table.find_type(iface_name) or { panic('unreachable: interface must exist') } iface := g.table.find_type(iface_name) or { panic('unreachable: interface must exist') }
for ty in iface_types { for ty in iface_types {
sym := g.table.get_type_symbol(ty) sym := g.table.sym(ty)
for method in iface.methods { for method in iface.methods {
p_sym := g.table.get_type_symbol(ty) p_sym := g.table.sym(ty)
mname := if p_sym.has_method(method.name) { mname := if p_sym.has_method(method.name) {
g.js_name(p_sym.name) + '_' + method.name g.js_name(p_sym.name) + '_' + method.name
@ -907,7 +907,7 @@ fn (mut g JsGen) expr(node ast.Expr) {
g.write('/* ast.DumpExpr: $node.expr */') g.write('/* ast.DumpExpr: $node.expr */')
} }
ast.EnumVal { ast.EnumVal {
sym := g.table.get_type_symbol(node.typ) sym := g.table.sym(node.typ)
styp := g.js_name(sym.name) styp := g.js_name(sym.name)
g.write('${styp}.$node.val') g.write('${styp}.$node.val')
} }
@ -1036,7 +1036,7 @@ fn (mut g JsGen) expr(node ast.Expr) {
} }
ast.TypeNode { ast.TypeNode {
typ := g.unwrap_generic(node.typ) typ := g.unwrap_generic(node.typ)
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
g.write('${g.js_name(sym.name)}') g.write('${g.js_name(sym.name)}')
} }
@ -1069,7 +1069,7 @@ fn (mut g JsGen) assert_subexpression_to_ctemp(expr ast.Expr, expr_type ast.Type
} }
ast.SelectorExpr { ast.SelectorExpr {
if expr.expr is ast.CallExpr { if expr.expr is ast.CallExpr {
sym := g.table.get_final_type_symbol(g.unwrap_generic(expr.expr.return_type)) sym := g.table.final_sym(g.unwrap_generic(expr.expr.return_type))
if sym.kind == .struct_ { if sym.kind == .struct_ {
if (sym.info as ast.Struct).is_union { if (sym.info as ast.Struct).is_union {
return js.unsupported_ctemp_assert_transform return js.unsupported_ctemp_assert_transform
@ -1158,7 +1158,7 @@ fn (mut g JsGen) gen_assert_single_expr(expr ast.Expr, typ ast.Type) {
} }
} }
ast.TypeNode { ast.TypeNode {
sym := g.table.get_type_symbol(g.unwrap_generic(typ)) sym := g.table.sym(g.unwrap_generic(typ))
g.write('new string("$sym.name"') g.write('new string("$sym.name"')
} }
else { else {
@ -1276,7 +1276,7 @@ fn (mut g JsGen) gen_assign_stmt(stmt ast.AssignStmt, semicolon bool) {
} }
mut styp := if stmt.left_types.len > i { g.typ(stmt.left_types[i]) } else { '' } mut styp := if stmt.left_types.len > i { g.typ(stmt.left_types[i]) } else { '' }
// l_sym := g.table.get_type_symbol(stmt.left_types[i]) // l_sym := g.table.sym(stmt.left_types[i])
if !g.inside_loop && styp.len > 0 { if !g.inside_loop && styp.len > 0 {
g.doc.gen_typ(styp) g.doc.gen_typ(styp)
} }
@ -1297,7 +1297,7 @@ fn (mut g JsGen) gen_assign_stmt(stmt ast.AssignStmt, semicolon bool) {
} }
array_set = true array_set = true
if g.table.get_type_symbol(left.left_type).kind == .map { if g.table.sym(left.left_type).kind == .map {
g.writeln('.length++;') g.writeln('.length++;')
g.expr(left.left) g.expr(left.left)
g.write('.map[') g.write('.map[')
@ -1338,7 +1338,7 @@ fn (mut g JsGen) gen_assign_stmt(stmt ast.AssignStmt, semicolon bool) {
if is_assign && array_set { if is_assign && array_set {
g.write('new ${styp}(') g.write('new ${styp}(')
g.expr(left) g.expr(left)
l_sym := g.table.get_type_symbol(stmt.left_types[i]) l_sym := g.table.sym(stmt.left_types[i])
if l_sym.kind == .string { if l_sym.kind == .string {
g.write('.str') g.write('.str')
} else { } else {
@ -1381,7 +1381,7 @@ fn (mut g JsGen) gen_assign_stmt(stmt ast.AssignStmt, semicolon bool) {
} }
} }
} else if is_assign && !array_set { } else if is_assign && !array_set {
l_sym := g.table.get_type_symbol(stmt.left_types[i]) l_sym := g.table.sym(stmt.left_types[i])
if l_sym.kind == .string { if l_sym.kind == .string {
g.write('.str') g.write('.str')
} else { } else {
@ -1558,14 +1558,14 @@ fn (mut g JsGen) gen_expr_stmt_no_semi(it ast.ExprStmt) {
// cc_type whether to prefix 'struct' or not (C__Foo -> struct Foo) // cc_type whether to prefix 'struct' or not (C__Foo -> struct Foo)
fn (mut g JsGen) cc_type(typ ast.Type, is_prefix_struct bool) string { fn (mut g JsGen) cc_type(typ ast.Type, is_prefix_struct bool) string {
sym := g.table.get_type_symbol(g.unwrap_generic(typ)) sym := g.table.sym(g.unwrap_generic(typ))
mut styp := sym.cname.replace('>', '').replace('<', '') mut styp := sym.cname.replace('>', '').replace('<', '')
match mut sym.info { match mut sym.info {
ast.Struct, ast.Interface, ast.SumType { ast.Struct, ast.Interface, ast.SumType {
if sym.info.is_generic { if sym.info.is_generic {
mut sgtyps := '_T' mut sgtyps := '_T'
for gt in sym.info.generic_types { for gt in sym.info.generic_types {
gts := g.table.get_type_symbol(g.unwrap_generic(gt)) gts := g.table.sym(g.unwrap_generic(gt))
sgtyps += '_$gts.cname' sgtyps += '_$gts.cname'
} }
styp += sgtyps styp += sgtyps
@ -1761,7 +1761,7 @@ fn (mut g JsGen) gen_optional_error(expr ast.Expr) {
fn (mut g JsGen) gen_return_stmt(it ast.Return) { fn (mut g JsGen) gen_return_stmt(it ast.Return) {
node := it node := it
// sym := g.table.get_type_symbol(g.fn_decl.return_type) // sym := g.table.sym(g.fn_decl.return_type)
fn_return_is_optional := g.fn_decl.return_type.has_flag(.optional) fn_return_is_optional := g.fn_decl.return_type.has_flag(.optional)
if node.exprs.len == 0 { if node.exprs.len == 0 {
if fn_return_is_optional { if fn_return_is_optional {
@ -1873,7 +1873,7 @@ fn (mut g JsGen) gen_struct_decl(node ast.StructDecl) {
for iface, iface_types in g.table.iface_types { for iface, iface_types in g.table.iface_types {
if iface.starts_with('JS.') { if iface.starts_with('JS.') {
for ty in iface_types { for ty in iface_types {
sym := g.table.get_type_symbol(ty) sym := g.table.sym(ty)
if sym.name == node.name { if sym.name == node.name {
g.writeln('...${g.js_name(iface)}.prototype,') g.writeln('...${g.js_name(iface)}.prototype,')
@ -2057,8 +2057,8 @@ fn (mut g JsGen) gen_lock_expr(node ast.LockExpr) {
fn (mut g JsGen) need_tmp_var_in_match(node ast.MatchExpr) bool { fn (mut g JsGen) need_tmp_var_in_match(node ast.MatchExpr) bool {
if node.is_expr && node.return_type != ast.void_type && node.return_type != 0 { if node.is_expr && node.return_type != ast.void_type && node.return_type != 0 {
cond_sym := g.table.get_final_type_symbol(node.cond_type) cond_sym := g.table.final_sym(node.cond_type)
sym := g.table.get_type_symbol(node.return_type) sym := g.table.sym(node.return_type)
if sym.kind == .multi_return { if sym.kind == .multi_return {
return false return false
} }
@ -2085,7 +2085,7 @@ fn (mut g JsGen) need_tmp_var_in_match(node ast.MatchExpr) bool {
} }
fn (mut g JsGen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var MatchCond, tmp_var string) { fn (mut g JsGen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var MatchCond, tmp_var string) {
type_sym := g.table.get_type_symbol(node.cond_type) type_sym := g.table.sym(node.cond_type)
for j, branch in node.branches { for j, branch in node.branches {
is_last := j == node.branches.len - 1 is_last := j == node.branches.len - 1
if branch.is_else || (node.is_expr && is_last && tmp_var.len == 0) { if branch.is_else || (node.is_expr && is_last && tmp_var.len == 0) {
@ -2293,7 +2293,7 @@ fn (mut g JsGen) match_expr(node ast.MatchExpr) {
if is_expr && !need_tmp_var { if is_expr && !need_tmp_var {
g.write('(') g.write('(')
} }
typ := g.table.get_final_type_symbol(node.cond_type) typ := g.table.final_sym(node.cond_type)
if node.is_sum_type { if node.is_sum_type {
g.match_expr_sumtype(node, is_expr, cond_var, tmp_var) g.match_expr_sumtype(node, is_expr, cond_var, tmp_var)
} else if typ.kind == .enum_ && !g.inside_loop && node.branches.len > 5 && g.fn_decl != 0 { // do not optimize while in top-level } else if typ.kind == .enum_ && !g.inside_loop && node.branches.len > 5 && g.fn_decl != 0 { // do not optimize while in top-level
@ -2359,7 +2359,7 @@ fn (mut g JsGen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var M
mut sumtype_index := 0 mut sumtype_index := 0
for { for {
is_last := j == node.branches.len - 1 is_last := j == node.branches.len - 1
sym := g.table.get_type_symbol(node.cond_type) sym := g.table.sym(node.cond_type)
if branch.is_else || (node.is_expr && is_last && tmp_var.len == 0) { if branch.is_else || (node.is_expr && is_last && tmp_var.len == 0) {
if is_expr && tmp_var.len == 0 { if is_expr && tmp_var.len == 0 {
g.write(' : ') g.write(' : ')
@ -2387,7 +2387,7 @@ fn (mut g JsGen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var M
if x is ast.TypeNode { if x is ast.TypeNode {
typ := g.unwrap_generic(x.typ) typ := g.unwrap_generic(x.typ)
tsym := g.table.get_type_symbol(typ) tsym := g.table.sym(typ)
if tsym.language == .js && (tsym.name == 'JS.Number' if tsym.language == .js && (tsym.name == 'JS.Number'
|| tsym.name == 'JS.Boolean' || tsym.name == 'JS.String') { || tsym.name == 'JS.Boolean' || tsym.name == 'JS.String') {
g.write('typeof ') g.write('typeof ')
@ -2399,7 +2399,7 @@ fn (mut g JsGen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var M
x := branch.exprs[sumtype_index] x := branch.exprs[sumtype_index]
if x is ast.TypeNode { if x is ast.TypeNode {
typ := g.unwrap_generic(x.typ) typ := g.unwrap_generic(x.typ)
tsym := g.table.get_type_symbol(typ) tsym := g.table.sym(typ)
if tsym.language == .js && (tsym.name == 'JS.Number' if tsym.language == .js && (tsym.name == 'JS.Number'
|| tsym.name == 'JS.Boolean' || tsym.name == 'JS.String') { || tsym.name == 'JS.Boolean' || tsym.name == 'JS.String') {
g.write(' === "${tsym.name[3..].to_lower()}"') g.write(' === "${tsym.name[3..].to_lower()}"')
@ -2418,7 +2418,7 @@ fn (mut g JsGen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var M
x := branch.exprs[sumtype_index] x := branch.exprs[sumtype_index]
if x is ast.TypeNode { if x is ast.TypeNode {
typ := g.unwrap_generic(x.typ) typ := g.unwrap_generic(x.typ)
tsym := g.table.get_type_symbol(typ) tsym := g.table.sym(typ)
if tsym.language == .js && (tsym.name == 'Number' if tsym.language == .js && (tsym.name == 'Number'
|| tsym.name == 'Boolean' || tsym.name == 'String') { || tsym.name == 'Boolean' || tsym.name == 'String') {
g.write(' === $tsym.name.to_lower()') g.write(' === $tsym.name.to_lower()')
@ -2585,7 +2585,7 @@ fn (mut g JsGen) need_tmp_var_in_if(node ast.IfExpr) bool {
stmt := branch.stmts[0] as ast.ExprStmt stmt := branch.stmts[0] as ast.ExprStmt
if stmt.expr is ast.CallExpr { if stmt.expr is ast.CallExpr {
if stmt.expr.is_method { if stmt.expr.is_method {
left_sym := g.table.get_type_symbol(stmt.expr.receiver_type) left_sym := g.table.sym(stmt.expr.receiver_type)
if left_sym.kind in [.array, .array_fixed, .map] { if left_sym.kind in [.array, .array_fixed, .map] {
return true return true
} }
@ -2729,7 +2729,7 @@ fn (mut g JsGen) gen_if_expr(node ast.IfExpr) {
} }
fn (mut g JsGen) gen_index_expr(expr ast.IndexExpr) { fn (mut g JsGen) gen_index_expr(expr ast.IndexExpr) {
left_typ := g.table.get_type_symbol(expr.left_type) left_typ := g.table.sym(expr.left_type)
// TODO: Handle splice setting if it's implemented // TODO: Handle splice setting if it's implemented
if expr.index is ast.RangeExpr { if expr.index is ast.RangeExpr {
if left_typ.kind == .string { if left_typ.kind == .string {
@ -2828,8 +2828,8 @@ fn (mut g JsGen) expr_string(expr ast.Expr) string {
} }
fn (mut g JsGen) gen_infix_expr(it ast.InfixExpr) { fn (mut g JsGen) gen_infix_expr(it ast.InfixExpr) {
l_sym := g.table.get_final_type_symbol(it.left_type) l_sym := g.table.final_sym(it.left_type)
r_sym := g.table.get_final_type_symbol(it.right_type) r_sym := g.table.final_sym(it.right_type)
is_not := it.op in [.not_in, .not_is, .ne] is_not := it.op in [.not_in, .not_is, .ne]
if is_not { if is_not {
@ -3082,8 +3082,8 @@ fn (mut g JsGen) greater_typ(left ast.Type, right ast.Type) ast.Type {
} }
fn (mut g JsGen) gen_map_init_expr(it ast.MapInit) { fn (mut g JsGen) gen_map_init_expr(it ast.MapInit) {
// key_typ_sym := g.table.get_type_symbol(it.key_type) // key_typ_sym := g.table.sym(it.key_type)
// value_typ_sym := g.table.get_type_symbol(it.value_type) // value_typ_sym := g.table.sym(it.value_type)
// key_typ_str := util.no_dots(key_typ_sym.name) // key_typ_str := util.no_dots(key_typ_sym.name)
// value_typ_str := util.no_dots(value_typ_sym.name) // value_typ_str := util.no_dots(value_typ_sym.name)
g.writeln('new map(') g.writeln('new map(')
@ -3114,7 +3114,7 @@ fn (mut g JsGen) gen_map_init_expr(it ast.MapInit) {
fn (mut g JsGen) type_name(raw_type ast.Type) { fn (mut g JsGen) type_name(raw_type ast.Type) {
typ := raw_type typ := raw_type
sym := g.table.get_type_symbol(typ) sym := g.table.sym(typ)
mut s := '' mut s := ''
if sym.kind == .function { if sym.kind == .function {
// todo: properly print function signatures // todo: properly print function signatures
@ -3161,7 +3161,7 @@ fn (mut g JsGen) gen_selector_expr(it ast.SelectorExpr) {
} }
g.expr(it.expr) g.expr(it.expr)
mut ltyp := it.expr_type mut ltyp := it.expr_type
lsym := g.table.get_type_symbol(ltyp) lsym := g.table.sym(ltyp)
if lsym.kind != .interface_ && lsym.language != .js { if lsym.kind != .interface_ && lsym.language != .js {
for ltyp.is_ptr() { for ltyp.is_ptr() {
g.write('.val') g.write('.val')
@ -3237,7 +3237,7 @@ fn (mut g JsGen) gen_string_literal(it ast.StringLiteral) {
} }
fn (mut g JsGen) gen_struct_init(it ast.StructInit) { fn (mut g JsGen) gen_struct_init(it ast.StructInit) {
type_sym := g.table.get_type_symbol(it.typ) type_sym := g.table.sym(it.typ)
mut name := type_sym.name mut name := type_sym.name
if name.contains('<') { if name.contains('<') {
name = name[0..name.index('<') or { name.len }] name = name[0..name.index('<') or { name.len }]
@ -3290,7 +3290,7 @@ fn (mut g JsGen) gen_struct_init(it ast.StructInit) {
} }
fn (mut g JsGen) gen_typeof_expr(it ast.TypeOf) { fn (mut g JsGen) gen_typeof_expr(it ast.TypeOf) {
sym := g.table.get_type_symbol(it.expr_type) sym := g.table.sym(it.expr_type)
if sym.kind == .sum_type { if sym.kind == .sum_type {
// TODO: JS sumtypes not implemented yet // TODO: JS sumtypes not implemented yet
} else if sym.kind == .array_fixed { } else if sym.kind == .array_fixed {
@ -3319,7 +3319,7 @@ fn (mut g JsGen) gen_typeof_expr(it ast.TypeOf) {
fn (mut g JsGen) gen_cast_tmp(tmp string, typ_ ast.Type) { fn (mut g JsGen) gen_cast_tmp(tmp string, typ_ ast.Type) {
// Skip cast if type is the same as the parrent caster // Skip cast if type is the same as the parrent caster
tsym := g.table.get_final_type_symbol(typ_) tsym := g.table.final_sym(typ_)
if !g.pref.output_es5 && (tsym.kind == .i64 || tsym.kind == .u64) { if !g.pref.output_es5 && (tsym.kind == .i64 || tsym.kind == .u64) {
g.write('new ') g.write('new ')
@ -3354,8 +3354,8 @@ fn (mut g JsGen) gen_cast_tmp(tmp string, typ_ ast.Type) {
fn (mut g JsGen) gen_type_cast_expr(it ast.CastExpr) { fn (mut g JsGen) gen_type_cast_expr(it ast.CastExpr) {
is_literal := ((it.expr is ast.IntegerLiteral && it.typ in ast.integer_type_idxs) is_literal := ((it.expr is ast.IntegerLiteral && it.typ in ast.integer_type_idxs)
|| (it.expr is ast.FloatLiteral && it.typ in ast.float_type_idxs)) || (it.expr is ast.FloatLiteral && it.typ in ast.float_type_idxs))
from_type_sym := g.table.get_type_symbol(it.expr_type) from_type_sym := g.table.sym(it.expr_type)
to_type_sym := g.table.get_type_symbol(it.typ) // type to be used as cast to_type_sym := g.table.sym(it.typ) // type to be used as cast
if it.typ.is_bool() && from_type_sym.name == 'JS.Boolean' { if it.typ.is_bool() && from_type_sym.name == 'JS.Boolean' {
g.write('new bool(') g.write('new bool(')
g.expr(it.expr) g.expr(it.expr)
@ -3540,7 +3540,7 @@ fn replace_op(s string) string {
} }
fn (mut g JsGen) gen_postfix_index_expr(expr ast.IndexExpr, op token.Kind) { fn (mut g JsGen) gen_postfix_index_expr(expr ast.IndexExpr, op token.Kind) {
left_typ := g.table.get_type_symbol(expr.left_type) left_typ := g.table.sym(expr.left_type)
// TODO: Handle splice setting if it's implemented // TODO: Handle splice setting if it's implemented
if expr.index is ast.RangeExpr { if expr.index is ast.RangeExpr {
if left_typ.kind == .array { if left_typ.kind == .array {
@ -3585,7 +3585,7 @@ fn (mut g JsGen) gen_postfix_index_expr(expr ast.IndexExpr, op token.Kind) {
g.write(')') g.write(')')
} else { } else {
g.write(',') g.write(',')
lsym := g.table.get_type_symbol(expr.left_type) lsym := g.table.sym(expr.left_type)
key_typ := match lsym.info { key_typ := match lsym.info {
ast.Map { ast.Map {
lsym.info.value_type lsym.info.value_type

View File

@ -10,10 +10,10 @@ fn (mut g JsGen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
typ = typ.clear_flag(.shared_f).set_nr_muls(0) typ = typ.clear_flag(.shared_f).set_nr_muls(0)
} }
mut sym := g.table.get_type_symbol(typ) mut sym := g.table.sym(typ)
// when type is alias, print the aliased value // when type is alias, print the aliased value
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
parent_sym := g.table.get_type_symbol(sym.info.parent_type) parent_sym := g.table.sym(sym.info.parent_type)
if parent_sym.has_method('str') { if parent_sym.has_method('str') {
typ = sym.info.parent_type typ = sym.info.parent_type
sym = parent_sym sym = parent_sym
@ -81,10 +81,10 @@ fn (mut g JsGen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
if is_shared { if is_shared {
typ = typ.clear_flag(.shared_f).set_nr_muls(0) typ = typ.clear_flag(.shared_f).set_nr_muls(0)
} }
mut sym := g.table.get_type_symbol(typ) mut sym := g.table.sym(typ)
// when type is alias, print the aliased value // when type is alias, print the aliased value
if mut sym.info is ast.Alias { if mut sym.info is ast.Alias {
parent_sym := g.table.get_type_symbol(sym.info.parent_type) parent_sym := g.table.sym(sym.info.parent_type)
if parent_sym.has_method('str') { if parent_sym.has_method('str') {
typ = sym.info.parent_type typ = sym.info.parent_type
sym = parent_sym sym = parent_sym

View File

@ -17,7 +17,7 @@ struct Type {
// * alias unwrapped // * alias unwrapped
fn (mut g JsGen) unwrap(typ ast.Type) Type { fn (mut g JsGen) unwrap(typ ast.Type) Type {
no_generic := g.unwrap_generic(typ) no_generic := g.unwrap_generic(typ)
no_generic_sym := g.table.get_type_symbol(no_generic) no_generic_sym := g.table.sym(no_generic)
if no_generic_sym.kind != .alias { if no_generic_sym.kind != .alias {
return Type{ return Type{
typ: no_generic typ: no_generic
@ -30,6 +30,6 @@ fn (mut g JsGen) unwrap(typ ast.Type) Type {
typ: no_generic typ: no_generic
sym: no_generic_sym sym: no_generic_sym
unaliased: no_generic_sym.parent_idx unaliased: no_generic_sym.parent_idx
unaliased_sym: g.table.get_type_symbol(no_generic_sym.parent_idx) unaliased_sym: g.table.sym(no_generic_sym.parent_idx)
} }
} }

View File

@ -1089,7 +1089,7 @@ g.v_error('oops', node.pos)
// a += b // a += b
} }
ast.StructInit { ast.StructInit {
sym := g.table.get_type_symbol(right.typ) sym := g.table.sym(right.typ)
info := sym.info as ast.Struct info := sym.info as ast.Struct
for field in info.fields { for field in info.fields {
field_name := name + '.' + field.name field_name := name + '.' + field.name

View File

@ -294,7 +294,7 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
typ_vweb_context := ast.Type(table.find_type_idx('vweb.Context')).set_nr_muls(1) typ_vweb_context := ast.Type(table.find_type_idx('vweb.Context')).set_nr_muls(1)
all_fn_root_names << '${int(typ_vweb_context)}.html' all_fn_root_names << '${int(typ_vweb_context)}.html'
for vgt in table.used_vweb_types { for vgt in table.used_vweb_types {
sym_app := table.get_type_symbol(vgt) sym_app := table.sym(vgt)
for m in sym_app.methods { for m in sym_app.methods {
if m.return_type == typ_vweb_result { if m.return_type == typ_vweb_result {
pvgt := vgt.set_nr_muls(1) pvgt := vgt.set_nr_muls(1)

View File

@ -142,7 +142,7 @@ pub fn (mut w Walker) stmt(node ast.Stmt) {
} }
if node.kind == .struct_ { if node.kind == .struct_ {
// the .next() method of the struct will be used for iteration: // the .next() method of the struct will be used for iteration:
cond_type_sym := w.table.get_type_symbol(node.cond_type) cond_type_sym := w.table.sym(node.cond_type)
if next_fn := cond_type_sym.find_method('next') { if next_fn := cond_type_sym.find_method('next') {
w.fn_decl(mut &ast.FnDecl(next_fn.source_fn)) w.fn_decl(mut &ast.FnDecl(next_fn.source_fn))
} }
@ -275,7 +275,7 @@ fn (mut w Walker) expr(node ast.Expr) {
w.expr(node.left) w.expr(node.left)
w.expr(node.index) w.expr(node.index)
w.or_block(node.or_expr) w.or_block(node.or_expr)
sym := w.table.get_final_type_symbol(node.left_type) sym := w.table.final_sym(node.left_type)
if sym.kind == .map { if sym.kind == .map {
w.table.used_maps++ w.table.used_maps++
} }
@ -287,13 +287,13 @@ fn (mut w Walker) expr(node ast.Expr) {
if node.left_type == 0 { if node.left_type == 0 {
return return
} }
sym := w.table.get_type_symbol(node.left_type) sym := w.table.sym(node.left_type)
if sym.kind == .struct_ { if sym.kind == .struct_ {
if opmethod := sym.find_method(node.op.str()) { if opmethod := sym.find_method(node.op.str()) {
w.fn_decl(mut &ast.FnDecl(opmethod.source_fn)) w.fn_decl(mut &ast.FnDecl(opmethod.source_fn))
} }
} }
right_sym := w.table.get_type_symbol(node.right_type) right_sym := w.table.sym(node.right_type)
if node.op in [.not_in, .key_in] && right_sym.kind == .map { if node.op in [.not_in, .key_in] && right_sym.kind == .map {
w.table.used_maps++ w.table.used_maps++
} }
@ -375,14 +375,14 @@ fn (mut w Walker) expr(node ast.Expr) {
w.expr(node.where_expr) w.expr(node.where_expr)
} }
ast.StructInit { ast.StructInit {
sym := w.table.get_type_symbol(node.typ) sym := w.table.sym(node.typ)
if sym.kind == .struct_ { if sym.kind == .struct_ {
info := sym.info as ast.Struct info := sym.info as ast.Struct
for ifield in info.fields { for ifield in info.fields {
if ifield.has_default_expr { if ifield.has_default_expr {
w.expr(ifield.default_expr) w.expr(ifield.default_expr)
} }
fsym := w.table.get_type_symbol(ifield.typ) fsym := w.table.sym(ifield.typ)
if fsym.kind == .map { if fsym.kind == .map {
w.table.used_maps++ w.table.used_maps++
} }

View File

@ -169,7 +169,7 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
} else if p.is_amp && p.peek_tok.kind == .rsbr && p.peek_token(3).kind != .lcbr { } else if p.is_amp && p.peek_tok.kind == .rsbr && p.peek_token(3).kind != .lcbr {
pos := p.tok.position() pos := p.tok.position()
typ := p.parse_type() typ := p.parse_type()
typname := p.table.get_type_symbol(typ).name typname := p.table.sym(typ).name
p.check(.lpar) p.check(.lpar)
expr := p.expr(0) expr := p.expr(0)
p.check(.rpar) p.check(.rpar)
@ -632,6 +632,6 @@ fn (mut p Parser) prefix_expr() ast.Expr {
fn (mut p Parser) recast_as_pointer(mut cast_expr ast.CastExpr, pos token.Position) { fn (mut p Parser) recast_as_pointer(mut cast_expr ast.CastExpr, pos token.Position) {
cast_expr.typ = cast_expr.typ.ref() cast_expr.typ = cast_expr.typ.ref()
cast_expr.typname = p.table.get_type_symbol(cast_expr.typ).name cast_expr.typname = p.table.sym(cast_expr.typ).name
cast_expr.pos = pos.extend(cast_expr.pos) cast_expr.pos = pos.extend(cast_expr.pos)
} }

View File

@ -262,7 +262,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
scope: 0 scope: 0
} }
} }
type_sym := p.table.get_type_symbol(rec.typ) type_sym := p.table.sym(rec.typ)
if is_method { if is_method {
mut is_duplicate := type_sym.has_method(name) mut is_duplicate := type_sym.has_method(name)
// make sure this is a normal method and not an interface method // make sure this is a normal method and not an interface method
@ -313,9 +313,9 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
_, mut generic_names := p.parse_generic_types() _, mut generic_names := p.parse_generic_types()
// generic names can be infer with receiver's generic names // generic names can be infer with receiver's generic names
if is_method && rec.typ.has_flag(.generic) { if is_method && rec.typ.has_flag(.generic) {
sym := p.table.get_type_symbol(rec.typ) sym := p.table.sym(rec.typ)
if sym.info is ast.Struct { if sym.info is ast.Struct {
rec_generic_names := sym.info.generic_types.map(p.table.get_type_symbol(it).name) rec_generic_names := sym.info.generic_types.map(p.table.sym(it).name)
for gname in rec_generic_names { for gname in rec_generic_names {
if gname !in generic_names { if gname !in generic_names {
generic_names << gname generic_names << gname
@ -372,14 +372,14 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
file_mode := p.file_backend_mode file_mode := p.file_backend_mode
// Register // Register
if is_method { if is_method {
mut type_sym := p.table.get_type_symbol(rec.typ) mut type_sym := p.table.sym(rec.typ)
// Do not allow to modify / add methods to types from other modules // Do not allow to modify / add methods to types from other modules
// arrays/maps dont belong to a module only their element types do // arrays/maps dont belong to a module only their element types do
// we could also check if kind is .array, .array_fixed, .map instead of mod.len // we could also check if kind is .array, .array_fixed, .map instead of mod.len
mut is_non_local := type_sym.mod.len > 0 && type_sym.mod != p.mod && type_sym.language == .v mut is_non_local := type_sym.mod.len > 0 && type_sym.mod != p.mod && type_sym.language == .v
// check maps & arrays, must be defined in same module as the elem type // check maps & arrays, must be defined in same module as the elem type
if !is_non_local && !(p.builtin_mod && p.pref.is_fmt) && type_sym.kind in [.array, .map] { if !is_non_local && !(p.builtin_mod && p.pref.is_fmt) && type_sym.kind in [.array, .map] {
elem_type_sym := p.table.get_type_symbol(p.table.value_type(rec.typ)) elem_type_sym := p.table.sym(p.table.value_type(rec.typ))
is_non_local = elem_type_sym.mod.len > 0 && elem_type_sym.mod != p.mod is_non_local = elem_type_sym.mod.len > 0 && elem_type_sym.mod != p.mod
&& elem_type_sym.language == .v && elem_type_sym.language == .v
} }
@ -588,7 +588,7 @@ fn (mut p Parser) fn_receiver(mut params []ast.Param, mut rec ReceiverParsingInf
rec.typ = rec.typ.set_flag(.atomic_f) rec.typ = rec.typ.set_flag(.atomic_f)
} }
// optimize method `automatic use fn (a &big_foo) instead of fn (a big_foo)` // optimize method `automatic use fn (a &big_foo) instead of fn (a big_foo)`
type_sym := p.table.get_type_symbol(rec.typ) type_sym := p.table.sym(rec.typ)
mut is_auto_rec := false mut is_auto_rec := false
if type_sym.kind == .struct_ { if type_sym.kind == .struct_ {
info := type_sym.info as ast.Struct info := type_sym.info as ast.Struct
@ -793,7 +793,7 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
} }
p.next() p.next()
} }
alanguage := p.table.get_type_symbol(arg_type).language alanguage := p.table.sym(arg_type).language
if alanguage != .v { if alanguage != .v {
p.check_for_impure_v(alanguage, pos) p.check_for_impure_v(alanguage, pos)
} }
@ -882,7 +882,7 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
typ = ast.new_type(p.table.find_or_register_array(typ)).derive(typ).set_flag(.variadic) typ = ast.new_type(p.table.find_or_register_array(typ)).derive(typ).set_flag(.variadic)
} }
for i, arg_name in arg_names { for i, arg_name in arg_names {
alanguage := p.table.get_type_symbol(typ).language alanguage := p.table.sym(typ).language
if alanguage != .v { if alanguage != .v {
p.check_for_impure_v(alanguage, type_pos[i]) p.check_for_impure_v(alanguage, type_pos[i])
} }
@ -958,7 +958,7 @@ fn (mut p Parser) closure_vars() []ast.Param {
} }
fn (mut p Parser) check_fn_mutable_arguments(typ ast.Type, pos token.Position) { fn (mut p Parser) check_fn_mutable_arguments(typ ast.Type, pos token.Position) {
sym := p.table.get_type_symbol(typ) sym := p.table.sym(typ)
if sym.kind in [.array, .array_fixed, .interface_, .map, .placeholder, .struct_, .generic_inst, if sym.kind in [.array, .array_fixed, .interface_, .map, .placeholder, .struct_, .generic_inst,
.sum_type] { .sum_type] {
return return
@ -981,7 +981,7 @@ fn (mut p Parser) check_fn_mutable_arguments(typ ast.Type, pos token.Position) {
} }
fn (mut p Parser) check_fn_shared_arguments(typ ast.Type, pos token.Position) { fn (mut p Parser) check_fn_shared_arguments(typ ast.Type, pos token.Position) {
sym := p.table.get_type_symbol(typ) sym := p.table.sym(typ)
if sym.kind !in [.array, .struct_, .map, .placeholder] && !typ.is_ptr() { if sym.kind !in [.array, .struct_, .map, .placeholder] && !typ.is_ptr() {
p.error_with_pos('shared arguments are only allowed for arrays, maps, and structs\n', p.error_with_pos('shared arguments are only allowed for arrays, maps, and structs\n',
pos) pos)
@ -989,7 +989,7 @@ fn (mut p Parser) check_fn_shared_arguments(typ ast.Type, pos token.Position) {
} }
fn (mut p Parser) check_fn_atomic_arguments(typ ast.Type, pos token.Position) { fn (mut p Parser) check_fn_atomic_arguments(typ ast.Type, pos token.Position) {
sym := p.table.get_type_symbol(typ) sym := p.table.sym(typ)
if sym.kind !in [.u32, .int, .u64] { if sym.kind !in [.u32, .int, .u64] {
p.error_with_pos('atomic arguments are only allowed for 32/64 bit integers\n' + p.error_with_pos('atomic arguments are only allowed for 32/64 bit integers\n' +
'use shared arguments instead: `fn foo(atomic n $sym.name) {` => `fn foo(shared n $sym.name) {`', 'use shared arguments instead: `fn foo(atomic n $sym.name) {` => `fn foo(shared n $sym.name) {`',

View File

@ -68,7 +68,7 @@ pub fn (mut p Parser) parse_array_type() ast.Type {
if fixed_size <= 0 { if fixed_size <= 0 {
p.error_with_pos('fixed size cannot be zero or negative', size_expr.position()) p.error_with_pos('fixed size cannot be zero or negative', size_expr.position())
} }
// sym := p.table.get_type_symbol(elem_type) // sym := p.table.sym(elem_type)
idx := p.table.find_or_register_array_fixed(elem_type, fixed_size, size_expr) idx := p.table.find_or_register_array_fixed(elem_type, fixed_size, size_expr)
if elem_type.has_flag(.generic) { if elem_type.has_flag(.generic) {
return ast.new_type(idx).set_flag(.generic) return ast.new_type(idx).set_flag(.generic)
@ -107,7 +107,7 @@ pub fn (mut p Parser) parse_map_type() ast.Type {
} }
p.check(.lsbr) p.check(.lsbr)
key_type := p.parse_type() key_type := p.parse_type()
key_sym := p.table.get_type_symbol(key_type) key_sym := p.table.sym(key_type)
is_alias := key_sym.kind == .alias is_alias := key_sym.kind == .alias
if key_type.idx() == 0 { if key_type.idx() == 0 {
// error is reported in parse_type // error is reported in parse_type
@ -551,7 +551,7 @@ pub fn (mut p Parser) parse_generic_inst_type(name string) ast.Type {
if !gt.has_flag(.generic) { if !gt.has_flag(.generic) {
is_instance = true is_instance = true
} }
gts := p.table.get_type_symbol(gt) gts := p.table.sym(gt)
bs_name += gts.name bs_name += gts.name
bs_cname += gts.cname bs_cname += gts.cname
concrete_types << gt concrete_types << gt
@ -577,7 +577,7 @@ pub fn (mut p Parser) parse_generic_inst_type(name string) ast.Type {
if parent_idx == 0 { if parent_idx == 0 {
parent_idx = p.table.add_placeholder_type(name, .v) parent_idx = p.table.add_placeholder_type(name, .v)
} }
parent_sym := p.table.get_type_symbol(ast.new_type(parent_idx)) parent_sym := p.table.sym(ast.new_type(parent_idx))
match parent_sym.info { match parent_sym.info {
ast.Struct { ast.Struct {
if parent_sym.info.generic_types.len == 0 { if parent_sym.info.generic_types.len == 0 {

View File

@ -2233,7 +2233,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
p.check(.rpar) p.check(.rpar)
node = ast.CastExpr{ node = ast.CastExpr{
typ: to_typ typ: to_typ
typname: p.table.get_type_symbol(to_typ).name typname: p.table.sym(to_typ).name
expr: expr expr: expr
arg: arg arg: arg
has_arg: has_arg has_arg: has_arg
@ -3384,7 +3384,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
// function type: `type mycallback = fn(string, int)` // function type: `type mycallback = fn(string, int)`
fn_name := p.prepend_mod(name) fn_name := p.prepend_mod(name)
fn_type := p.parse_fn_type(fn_name) fn_type := p.parse_fn_type(fn_name)
p.table.get_type_symbol(fn_type).is_public = is_pub p.table.sym(fn_type).is_public = is_pub
type_pos = type_pos.extend(p.tok.position()) type_pos = type_pos.extend(p.tok.position())
comments = p.eat_comments(same_line: true) comments = p.eat_comments(same_line: true)
return ast.FnTypeDecl{ return ast.FnTypeDecl{
@ -3459,7 +3459,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
return ast.AliasTypeDecl{} return ast.AliasTypeDecl{}
} }
parent_type := first_type parent_type := first_type
parent_sym := p.table.get_type_symbol(parent_type) parent_sym := p.table.sym(parent_type)
pidx := parent_type.idx() pidx := parent_type.idx()
p.check_for_impure_v(parent_sym.language, decl_pos) p.check_for_impure_v(parent_sym.language, decl_pos)
prepend_mod_name := p.prepend_mod(name) prepend_mod_name := p.prepend_mod(name)

View File

@ -193,7 +193,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
type_pos) type_pos)
return ast.StructDecl{} return ast.StructDecl{}
} }
sym := p.table.get_type_symbol(typ) sym := p.table.sym(typ)
if typ in embed_types { if typ in embed_types {
p.error_with_pos('cannot embed `$sym.name` more than once', type_pos) p.error_with_pos('cannot embed `$sym.name` more than once', type_pos)
return ast.StructDecl{} return ast.StructDecl{}
@ -339,7 +339,7 @@ fn (mut p Parser) struct_init(short_syntax bool) ast.StructInit {
first_pos := (if short_syntax && p.prev_tok.kind == .lcbr { p.prev_tok } else { p.tok }).position() first_pos := (if short_syntax && p.prev_tok.kind == .lcbr { p.prev_tok } else { p.tok }).position()
typ := if short_syntax { ast.void_type } else { p.parse_type() } typ := if short_syntax { ast.void_type } else { p.parse_type() }
p.expr_mod = '' p.expr_mod = ''
// sym := p.table.get_type_symbol(typ) // sym := p.table.sym(typ)
// p.warn('struct init typ=$sym.name') // p.warn('struct init typ=$sym.name')
if !short_syntax { if !short_syntax {
p.check(.lcbr) p.check(.lcbr)
@ -486,7 +486,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
return ast.InterfaceDecl{} return ast.InterfaceDecl{}
} }
typ := ast.new_type(reg_idx) typ := ast.new_type(reg_idx)
mut ts := p.table.get_type_symbol(typ) mut ts := p.table.sym(typ)
mut info := ts.info as ast.Interface mut info := ts.info as ast.Interface
// if methods were declared before, it's an error, ignore them // if methods were declared before, it's an error, ignore them
ts.methods = []ast.Fn{cap: 20} ts.methods = []ast.Fn{cap: 20}
@ -502,7 +502,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
mut iface_name := p.tok.lit mut iface_name := p.tok.lit
iface_type := p.parse_type() iface_type := p.parse_type()
if iface_name == 'JS' { if iface_name == 'JS' {
iface_name = p.table.get_type_symbol(iface_type).name iface_name = p.table.sym(iface_type).name
} }
comments := p.eat_comments() comments := p.eat_comments()
ifaces << ast.InterfaceEmbedding{ ifaces << ast.InterfaceEmbedding{