gen/checker: copy ptr & flag info in unwrap_generic

pull/5224/head
joe-conigliaro 2020-06-05 18:41:15 +10:00
parent 30e0bda434
commit 3c4e4d4825
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
3 changed files with 15 additions and 4 deletions

View File

@ -1749,7 +1749,9 @@ fn (mut c Checker) stmts(stmts []ast.Stmt) {
pub fn (mut c Checker) unwrap_generic(typ table.Type) table.Type {
if typ.idx() == table.t_type_idx {
return c.cur_generic_type
// return c.cur_generic_type
// its more efficient to set the id rather than to copy flags/nr_muls
return typ.set_idx(c.cur_generic_type)
}
return typ
}

View File

@ -243,7 +243,7 @@ fn (mut g Gen) fn_args(args []table.Arg, is_variadic bool) ([]string, []string)
no_names := args.len > 0 && args[0].name == 'arg_1'
for i, arg in args {
caname := c_name(arg.name)
typ := g.unwrap_generic(arg.typ).set_nr_muls(arg.typ.nr_muls())
typ := g.unwrap_generic(arg.typ)
arg_type_sym := g.table.get_type_symbol(typ)
mut arg_type_name := g.typ(typ) // arg_type_sym.name.replace('.', '__')
// if arg.name == 'xxx' {
@ -330,7 +330,9 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
pub fn (mut g Gen) unwrap_generic(typ table.Type) table.Type {
if typ.idx() == table.t_type_idx {
return g.cur_generic_type
// return g.cur_generic_type
// its more efficient to set the id rather than to copy flags/nr_muls
return typ.set_idx(g.cur_generic_type)
}
return typ
}

View File

@ -70,6 +70,12 @@ pub fn (t Type) is_ptr() bool {
return (int(t) >> 16) & 0xff > 0
}
// set idx on `t` and return it
[inline]
pub fn (t Type) set_idx(idx int) Type {
return (((int(t) >> 24) & 0xff) << 24) | (((int(t) >> 16) & 0xff) << 16) | (u16(idx) & 0xffff)
}
// set nr_muls on `t` and return it
[inline]
pub fn (t Type) set_nr_muls(nr_muls int) Type {
@ -112,11 +118,12 @@ pub fn (t Type) clear_flag(flag TypeFlag) Type {
}
// clear all flags
[inline]
pub fn (t Type) clear_flags() Type {
return 0 | (((int(t) >> 16) & 0xff) << 16) | (u16(t) & 0xffff)
}
// return true if `flag` is set in `t`
// return true if `flag` is set on `t`
[inline]
pub fn (t Type) has_flag(flag TypeFlag) bool {
return (((int(t) >> 24) & 0xff) >> int(flag)) & 1 == 1