gen: add typedefs for optional enums & array clone receiver type fix
parent
be01a32f0b
commit
408553e967
|
@ -298,11 +298,18 @@ pub fn (c mut Checker) method_call_expr(method_call_expr mut ast.MethodCallExpr)
|
||||||
}
|
}
|
||||||
// need to return `array_xxx` instead of `array`
|
// need to return `array_xxx` instead of `array`
|
||||||
method_call_expr.return_type = typ
|
method_call_expr.return_type = typ
|
||||||
|
if name == 'clone' {
|
||||||
|
method_call_expr.receiver_type = table.type_to_ptr(typ)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
method_call_expr.receiver_type = typ
|
||||||
|
}
|
||||||
return typ
|
return typ
|
||||||
}
|
}
|
||||||
else if typ_sym.kind == .array && name in ['first', 'last'] {
|
else if typ_sym.kind == .array && name in ['first', 'last'] {
|
||||||
info := typ_sym.info as table.Array
|
info := typ_sym.info as table.Array
|
||||||
method_call_expr.return_type = info.elem_type
|
method_call_expr.return_type = info.elem_type
|
||||||
|
method_call_expr.receiver_type = typ
|
||||||
return info.elem_type
|
return info.elem_type
|
||||||
}
|
}
|
||||||
if method := c.table.type_find_method(typ_sym, name) {
|
if method := c.table.type_find_method(typ_sym, name) {
|
||||||
|
|
|
@ -688,7 +688,15 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||||
}
|
}
|
||||||
ast.EnumVal {
|
ast.EnumVal {
|
||||||
// g.write('/*EnumVal*/${it.mod}${it.enum_name}_$it.val')
|
// g.write('/*EnumVal*/${it.mod}${it.enum_name}_$it.val')
|
||||||
g.write(g.typ(it.typ))
|
styp := g.typ(it.typ)
|
||||||
|
if table.type_is_optional(it.typ) {
|
||||||
|
ostyp := styp + '_$it.val'
|
||||||
|
if !(ostyp in g.optionals) {
|
||||||
|
g.definitions.writeln('typedef Option $ostyp;')
|
||||||
|
g.optionals << ostyp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g.write(styp)
|
||||||
g.write('_$it.val')
|
g.write('_$it.val')
|
||||||
}
|
}
|
||||||
ast.FloatLiteral {
|
ast.FloatLiteral {
|
||||||
|
@ -743,7 +751,7 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||||
if it.expr_type == 0 {
|
if it.expr_type == 0 {
|
||||||
verror('method receiver type is 0, this means there are some uchecked exprs')
|
verror('method receiver type is 0, this means there are some uchecked exprs')
|
||||||
}
|
}
|
||||||
typ_sym := g.table.get_type_symbol(it.expr_type)
|
typ_sym := g.table.get_type_symbol(it.receiver_type)
|
||||||
// rec_sym := g.table.get_type_symbol(it.receiver_type)
|
// rec_sym := g.table.get_type_symbol(it.receiver_type)
|
||||||
mut receiver_name := typ_sym.name
|
mut receiver_name := typ_sym.name
|
||||||
if typ_sym.kind == .array && it.name in
|
if typ_sym.kind == .array && it.name in
|
||||||
|
|
Loading…
Reference in New Issue