mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
fix
This commit is contained in:
parent
24f91280d9
commit
745b03963c
6 changed files with 22 additions and 5 deletions
|
@ -254,6 +254,9 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
|
||||||
}
|
}
|
||||||
if node.val_is_mut {
|
if node.val_is_mut {
|
||||||
value_type = value_type.ref()
|
value_type = value_type.ref()
|
||||||
|
if value_type.has_flag(.option) {
|
||||||
|
value_type = value_type.set_flag(.option_mut_param_t)
|
||||||
|
}
|
||||||
match mut node.cond {
|
match mut node.cond {
|
||||||
ast.Ident {
|
ast.Ident {
|
||||||
if mut node.cond.obj is ast.Var {
|
if mut node.cond.obj is ast.Var {
|
||||||
|
|
|
@ -866,9 +866,19 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
|
||||||
g.write('*')
|
g.write('*')
|
||||||
}
|
}
|
||||||
if node_.op == .assign && var_type.has_flag(.option_mut_param_t) {
|
if node_.op == .assign && var_type.has_flag(.option_mut_param_t) {
|
||||||
|
if val is ast.CastExpr {
|
||||||
|
g.expr(left)
|
||||||
|
g.write('->state = ')
|
||||||
|
g.expr(val)
|
||||||
|
g.writeln('.state;')
|
||||||
|
}
|
||||||
g.write('memcpy(&')
|
g.write('memcpy(&')
|
||||||
g.expr(left)
|
g.expr(left)
|
||||||
|
if val is ast.CastExpr {
|
||||||
|
g.write('->data, ')
|
||||||
|
} else {
|
||||||
g.write('->data, *(${g.styp(val_type)}**)&')
|
g.write('->data, *(${g.styp(val_type)}**)&')
|
||||||
|
}
|
||||||
} else if var_type.has_flag(.option_mut_param_t) {
|
} else if var_type.has_flag(.option_mut_param_t) {
|
||||||
g.expr(left)
|
g.expr(left)
|
||||||
g.write(' = ')
|
g.write(' = ')
|
||||||
|
|
|
@ -322,7 +322,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
|
||||||
g.writeln('\t${styp} ${c_name(node.val_var)};')
|
g.writeln('\t${styp} ${c_name(node.val_var)};')
|
||||||
g.writeln('\tmemcpy(*(${styp}*)${c_name(node.val_var)}, (byte*)${cond_var}[${idx}], sizeof(${styp}));')
|
g.writeln('\tmemcpy(*(${styp}*)${c_name(node.val_var)}, (byte*)${cond_var}[${idx}], sizeof(${styp}));')
|
||||||
} else {
|
} else {
|
||||||
styp := g.styp(node.val_type)
|
mut styp := g.styp(node.val_type)
|
||||||
g.write('\t${styp} ${c_name(node.val_var)}')
|
g.write('\t${styp} ${c_name(node.val_var)}')
|
||||||
}
|
}
|
||||||
if !is_fixed_array {
|
if !is_fixed_array {
|
||||||
|
|
|
@ -120,7 +120,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
||||||
exp_typ := if unwrap_option { typ.clear_flag(.option) } else { typ }
|
exp_typ := if unwrap_option { typ.clear_flag(.option) } else { typ }
|
||||||
is_dump_expr := expr is ast.DumpExpr
|
is_dump_expr := expr is ast.DumpExpr
|
||||||
is_var_mut := expr.is_auto_deref_var()
|
is_var_mut := expr.is_auto_deref_var()
|
||||||
str_fn_name := g.get_str_fn(exp_typ)
|
mut str_fn_name := g.get_str_fn(exp_typ)
|
||||||
temp_var_needed := expr is ast.CallExpr
|
temp_var_needed := expr is ast.CallExpr
|
||||||
&& (expr.return_type.is_ptr() || g.table.sym(expr.return_type).is_c_struct())
|
&& (expr.return_type.is_ptr() || g.table.sym(expr.return_type).is_c_struct())
|
||||||
mut tmp_var := ''
|
mut tmp_var := ''
|
||||||
|
@ -171,7 +171,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
||||||
}
|
}
|
||||||
} else if is_ptr && typ.has_flag(.option) {
|
} else if is_ptr && typ.has_flag(.option) {
|
||||||
if typ.has_flag(.option_mut_param_t) {
|
if typ.has_flag(.option_mut_param_t) {
|
||||||
g.write('*')
|
g.write('/**/*')
|
||||||
} else {
|
} else {
|
||||||
g.write('*(${g.styp(typ)}*)&')
|
g.write('*(${g.styp(typ)}*)&')
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int, fmts []u8) (u64, s
|
||||||
mut base := 0 // numeric base
|
mut base := 0 // numeric base
|
||||||
mut upper_case := false // set uppercase for the result string
|
mut upper_case := false // set uppercase for the result string
|
||||||
mut typ := g.unwrap_generic(node.expr_types[i])
|
mut typ := g.unwrap_generic(node.expr_types[i])
|
||||||
if node.exprs[i].is_auto_deref_var() {
|
if node.exprs[i].is_auto_deref_var() && !typ.has_flag(.option_mut_param_t) {
|
||||||
typ = typ.deref()
|
typ = typ.deref()
|
||||||
}
|
}
|
||||||
typ = g.table.final_type(typ)
|
typ = g.table.final_type(typ)
|
||||||
|
|
|
@ -1300,6 +1300,10 @@ fn (mut w Walker) mark_resource_dependencies() {
|
||||||
w.fn_by_name(builderptr_idx + '.write_string')
|
w.fn_by_name(builderptr_idx + '.write_string')
|
||||||
w.fn_by_name('strings.new_builder')
|
w.fn_by_name('strings.new_builder')
|
||||||
w.uses_free[ast.string_type] = true
|
w.uses_free[ast.string_type] = true
|
||||||
|
|
||||||
|
if w.table.dumps.keys().any(ast.Type(u32(it)).clear_flags(.shared_f).has_flag(.option)) {
|
||||||
|
w.fn_by_name('str_intp')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if w.features.auto_str_ptr {
|
if w.features.auto_str_ptr {
|
||||||
w.fn_by_name('isnil')
|
w.fn_by_name('isnil')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue