mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
cgen: cleanup in array.v (#19429)
This commit is contained in:
parent
a685088fbd
commit
7bfb35dd1c
1 changed files with 13 additions and 25 deletions
|
@ -126,11 +126,7 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
|
||||||
g.indent++
|
g.indent++
|
||||||
g.writeln('int it = index;') // FIXME: Remove this line when it is fully forbidden
|
g.writeln('int it = index;') // FIXME: Remove this line when it is fully forbidden
|
||||||
g.write('*pelem = ')
|
g.write('*pelem = ')
|
||||||
if node.elem_type.has_flag(.option) {
|
g.expr_with_default(node)
|
||||||
g.expr_with_opt(node.default_expr, node.default_type, node.elem_type)
|
|
||||||
} else {
|
|
||||||
g.expr_with_cast(node.default_expr, node.default_type, node.elem_type)
|
|
||||||
}
|
|
||||||
g.writeln(';')
|
g.writeln(';')
|
||||||
g.indent--
|
g.indent--
|
||||||
g.writeln('}')
|
g.writeln('}')
|
||||||
|
@ -171,11 +167,7 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
|
||||||
} else if node.has_default {
|
} else if node.has_default {
|
||||||
info := array_type.unaliased_sym.info as ast.ArrayFixed
|
info := array_type.unaliased_sym.info as ast.ArrayFixed
|
||||||
for i in 0 .. info.size {
|
for i in 0 .. info.size {
|
||||||
if info.elem_type.has_flag(.option) {
|
g.expr_with_default(node)
|
||||||
g.expr_with_opt(node.default_expr, node.default_type, info.elem_type)
|
|
||||||
} else {
|
|
||||||
g.expr_with_cast(node.default_expr, node.default_type, info.elem_type)
|
|
||||||
}
|
|
||||||
if i != info.size - 1 {
|
if i != info.size - 1 {
|
||||||
g.write(', ')
|
g.write(', ')
|
||||||
}
|
}
|
||||||
|
@ -244,6 +236,14 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn (mut g Gen) expr_with_default(node ast.ArrayInit) {
|
||||||
|
if node.elem_type.has_flag(.option) {
|
||||||
|
g.expr_with_opt(node.default_expr, node.default_type, node.elem_type)
|
||||||
|
} else {
|
||||||
|
g.expr_with_cast(node.default_expr, node.default_type, node.elem_type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn (mut g Gen) struct_has_array_or_map_field(elem_typ ast.Type) bool {
|
fn (mut g Gen) struct_has_array_or_map_field(elem_typ ast.Type) bool {
|
||||||
unaliased_sym := g.table.final_sym(elem_typ)
|
unaliased_sym := g.table.final_sym(elem_typ)
|
||||||
if unaliased_sym.kind == .struct_ {
|
if unaliased_sym.kind == .struct_ {
|
||||||
|
@ -342,11 +342,7 @@ fn (mut g Gen) array_init_with_fields(node ast.ArrayInit, elem_type Type, is_amp
|
||||||
g.indent++
|
g.indent++
|
||||||
g.writeln('int it = index;') // FIXME: Remove this line when it is fully forbidden
|
g.writeln('int it = index;') // FIXME: Remove this line when it is fully forbidden
|
||||||
g.write('*pelem = ')
|
g.write('*pelem = ')
|
||||||
if node.elem_type.has_flag(.option) {
|
g.expr_with_default(node)
|
||||||
g.expr_with_opt(node.default_expr, node.default_type, node.elem_type)
|
|
||||||
} else {
|
|
||||||
g.expr_with_cast(node.default_expr, node.default_type, node.elem_type)
|
|
||||||
}
|
|
||||||
g.writeln(';')
|
g.writeln(';')
|
||||||
g.indent--
|
g.indent--
|
||||||
g.writeln('}')
|
g.writeln('}')
|
||||||
|
@ -409,11 +405,7 @@ fn (mut g Gen) array_init_with_fields(node ast.ArrayInit, elem_type Type, is_amp
|
||||||
g.writeln('; ${ind}++) {')
|
g.writeln('; ${ind}++) {')
|
||||||
g.write('\t${tmp}[${ind}] = ')
|
g.write('\t${tmp}[${ind}] = ')
|
||||||
if node.has_default {
|
if node.has_default {
|
||||||
if node.elem_type.has_flag(.option) {
|
g.expr_with_default(node)
|
||||||
g.expr_with_opt(node.default_expr, node.default_type, node.elem_type)
|
|
||||||
} else {
|
|
||||||
g.expr_with_cast(node.default_expr, node.default_type, node.elem_type)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if node.elem_type.has_flag(.option) {
|
if node.elem_type.has_flag(.option) {
|
||||||
g.expr_with_opt(ast.None{}, ast.none_type, node.elem_type)
|
g.expr_with_opt(ast.None{}, ast.none_type, node.elem_type)
|
||||||
|
@ -427,11 +419,7 @@ fn (mut g Gen) array_init_with_fields(node ast.ArrayInit, elem_type Type, is_amp
|
||||||
g.write(' (voidptr)${tmp})')
|
g.write(' (voidptr)${tmp})')
|
||||||
} else if node.has_default {
|
} else if node.has_default {
|
||||||
g.write('&(${elem_styp}[]){')
|
g.write('&(${elem_styp}[]){')
|
||||||
if node.elem_type.has_flag(.option) {
|
g.expr_with_default(node)
|
||||||
g.expr_with_opt(node.default_expr, node.default_type, node.elem_type)
|
|
||||||
} else {
|
|
||||||
g.expr_with_cast(node.default_expr, node.default_type, node.elem_type)
|
|
||||||
}
|
|
||||||
g.write('})')
|
g.write('})')
|
||||||
} else if node.has_len && node.elem_type.has_flag(.option) {
|
} else if node.has_len && node.elem_type.has_flag(.option) {
|
||||||
g.write('&')
|
g.write('&')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue