1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: clarify field name

This commit is contained in:
joe-conigliaro 2020-03-31 19:11:47 +11:00
parent f8169fee48
commit 21e4f2422d
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1

View File

@ -32,8 +32,8 @@ mut:
tmp_count int tmp_count int
variadic_args map[string]int variadic_args map[string]int
is_c_call bool // e.g. `C.printf("v")` is_c_call bool // e.g. `C.printf("v")`
is_assign bool // inside right part of assign after `=` (val expr) is_assign_lhs bool // inside left part of assign expr (for array_set(), etc)
is_assign_expr bool // inside left part of assign expr (for array_set(), etc) is_assign_rhs bool // inside right part of assign after `=` (val expr)
is_array_set bool is_array_set bool
is_amp bool // for `&Foo{}` to merge PrefixExpr `&` and StructInit `Foo{}`; also for `&byte(0)` etc is_amp bool // for `&Foo{}` to merge PrefixExpr `&` and StructInit `Foo{}`; also for `&byte(0)` etc
optionals []string // to avoid duplicates TODO perf, use map optionals []string // to avoid duplicates TODO perf, use map
@ -585,9 +585,9 @@ fn (g mut Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
mr_var_name := 'mr_$assign_stmt.pos.pos' mr_var_name := 'mr_$assign_stmt.pos.pos'
mr_styp := g.typ(return_type) mr_styp := g.typ(return_type)
g.write('$mr_styp $mr_var_name = ') g.write('$mr_styp $mr_var_name = ')
g.is_assign = true g.is_assign_rhs = true
g.expr(assign_stmt.right[0]) g.expr(assign_stmt.right[0])
g.is_assign = false g.is_assign_rhs = false
if is_optional { if is_optional {
g.or_block(mr_var_name, or_stmts, return_type) g.or_block(mr_var_name, or_stmts, return_type)
} }
@ -629,7 +629,7 @@ fn (g mut Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
else {} else {}
} }
gen_or := is_call && table.type_is_optional(return_type) gen_or := is_call && table.type_is_optional(return_type)
g.is_assign = true g.is_assign_rhs = true
if ident.kind == .blank_ident { if ident.kind == .blank_ident {
if is_call { if is_call {
g.expr(val) g.expr(val)
@ -686,7 +686,7 @@ fn (g mut Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
g.or_block(ident.name, or_stmts, return_type) g.or_block(ident.name, or_stmts, return_type)
} }
} }
g.is_assign = false g.is_assign_rhs = false
g.writeln(';') g.writeln(';')
} }
} }
@ -1140,7 +1140,7 @@ fn (g mut Gen) assign_expr(node ast.AssignExpr) {
rstyp := g.typ(return_type) rstyp := g.typ(return_type)
g.write('$rstyp $tmp_opt =') g.write('$rstyp $tmp_opt =')
} }
g.is_assign = true g.is_assign_rhs = true
if ast.expr_is_blank_ident(node.left) { if ast.expr_is_blank_ident(node.left) {
if is_call { if is_call {
g.expr(node.val) g.expr(node.val)
@ -1152,7 +1152,7 @@ fn (g mut Gen) assign_expr(node ast.AssignExpr) {
} }
} }
else { else {
g.is_assign_expr = true g.is_assign_lhs = true
if table.type_is_optional(node.right_type) { if table.type_is_optional(node.right_type) {
g.right_is_opt = true g.right_is_opt = true
} }
@ -1172,7 +1172,7 @@ fn (g mut Gen) assign_expr(node ast.AssignExpr) {
else if str_add { else if str_add {
g.write(', ') g.write(', ')
} }
g.is_assign_expr = false g.is_assign_lhs = false
g.expr_with_cast(node.val, node.right_type, node.left_type) g.expr_with_cast(node.val, node.right_type, node.left_type)
if g.is_array_set { if g.is_array_set {
g.write(' })') g.write(' })')
@ -1186,7 +1186,7 @@ fn (g mut Gen) assign_expr(node ast.AssignExpr) {
if gen_or { if gen_or {
g.or_block(tmp_opt, or_stmts, return_type) g.or_block(tmp_opt, or_stmts, return_type)
} }
g.is_assign = false g.is_assign_rhs = false
} }
fn (g mut Gen) infix_expr(node ast.InfixExpr) { fn (g mut Gen) infix_expr(node ast.InfixExpr) {
@ -1434,7 +1434,7 @@ fn (g mut Gen) ident(node ast.Ident) {
// `x = 10` => `x.data = 10` (g.right_is_opt == false) // `x = 10` => `x.data = 10` (g.right_is_opt == false)
// `x = new_opt()` => `x = new_opt()` (g.right_is_opt == true) // `x = new_opt()` => `x = new_opt()` (g.right_is_opt == true)
// `println(x)` => `println(*(int*)x.data)` // `println(x)` => `println(*(int*)x.data)`
if it.is_optional && !(g.is_assign_expr && g.right_is_opt) { if it.is_optional && !(g.is_assign_lhs && g.right_is_opt) {
g.write('/*opt*/') g.write('/*opt*/')
styp := g.typ(it.typ)[7..] // Option_int => int TODO perf? styp := g.typ(it.typ)[7..] // Option_int => int TODO perf?
g.write('(*($styp*)${name}.data)') g.write('(*($styp*)${name}.data)')
@ -1577,7 +1577,7 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) {
} }
else {} else {}
} }
if g.is_assign_expr && !is_selector { if g.is_assign_lhs && !is_selector {
g.is_array_set = true g.is_array_set = true
g.write('array_set(&') g.write('array_set(&')
g.expr(node.left) g.expr(node.left)
@ -1612,7 +1612,7 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) {
else if sym.kind == .map { else if sym.kind == .map {
info := sym.info as table.Map info := sym.info as table.Map
elem_type_str := g.typ(info.value_type) elem_type_str := g.typ(info.value_type)
if g.is_assign_expr { if g.is_assign_lhs {
g.is_array_set = true g.is_array_set = true
g.write('map_set(&') g.write('map_set(&')
g.expr(node.left) g.expr(node.left)
@ -2187,7 +2187,7 @@ fn (g mut Gen) insert_before(s string) {
} }
fn (g mut Gen) call_expr(node ast.CallExpr) { fn (g mut Gen) call_expr(node ast.CallExpr) {
gen_or := !g.is_assign && node.or_block.stmts.len > 0 gen_or := !g.is_assign_rhs && node.or_block.stmts.len > 0
tmp_opt := if gen_or { g.new_tmp_var() } else { '' } tmp_opt := if gen_or { g.new_tmp_var() } else { '' }
if gen_or { if gen_or {
styp := g.typ(node.return_type) styp := g.typ(node.return_type)