mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: array and fixed array fixes
This commit is contained in:
parent
750f37fde7
commit
24bcc7a93b
@ -273,6 +273,10 @@ pub fn (c mut Checker) method_call_expr(method_call_expr mut ast.MethodCallExpr)
|
||||
info := typ_sym.info as table.Array
|
||||
return info.elem_type
|
||||
}
|
||||
// repeat() returns `array`, need to return `array_xxx`
|
||||
else if typ_sym.kind == .array && name in ['repeat'] {
|
||||
return typ
|
||||
}
|
||||
if method := typ_sym.find_method(name) {
|
||||
for i, arg_expr in method_call_expr.args {
|
||||
c.expected_type = method.args[i].typ
|
||||
|
@ -66,12 +66,19 @@ pub fn (g &Gen) styp(t string) string {
|
||||
|
||||
pub fn (g mut Gen) write_array_types() {
|
||||
for typ in g.table.types {
|
||||
if typ.kind != .array {
|
||||
continue
|
||||
}
|
||||
if typ.kind == .array {
|
||||
styp := typ.name.replace('.', '__')
|
||||
g.definitions.writeln('typedef array $styp;')
|
||||
}
|
||||
else if typ.kind == .array_fixed {
|
||||
styp := typ.name.replace('.', '__')
|
||||
// array_fixed_char_300 => char x[300]
|
||||
mut fixed := styp[12..]
|
||||
len := styp.after('_')
|
||||
fixed = fixed[..fixed.len - len.len - 1]
|
||||
g.definitions.writeln('typedef $fixed $styp [$len];')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (g mut Gen) write_multi_return_types() {
|
||||
@ -491,6 +498,13 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||
g.expr(it.right)
|
||||
g.write(')')
|
||||
}
|
||||
else if it.op == .eq && it.left_type == table.string_type_idx {
|
||||
g.write('string_eq(')
|
||||
g.expr(it.left)
|
||||
g.write(', ')
|
||||
g.expr(it.right)
|
||||
g.write(')')
|
||||
}
|
||||
// arr << val
|
||||
else if it.op == .left_shift && g.table.get_type_symbol(it.left_type).kind == .array {
|
||||
g.write('array_push(')
|
||||
@ -576,6 +590,9 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||
if it.typ != 0 {
|
||||
typ_sym := g.table.get_type_symbol(it.typ)
|
||||
receiver_name = typ_sym.name
|
||||
// if typ_sym.kind == .array {
|
||||
// receiver_name = 'array'
|
||||
// }
|
||||
}
|
||||
name := '${receiver_name}_$it.name'.replace('.', '__')
|
||||
g.write('${name}(')
|
||||
|
Loading…
Reference in New Issue
Block a user