mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: use c_name() while generating code for or {}
This commit is contained in:
parent
ff88906e9a
commit
9e715b8701
@ -2654,18 +2654,19 @@ fn (mut g Gen) insert_before(s string) {
|
|||||||
// to access its fields (`.ok`, `.error` etc)
|
// to access its fields (`.ok`, `.error` etc)
|
||||||
// `os.cp(...)` => `Option bool tmp = os__cp(...); if (!tmp.ok) { ... }`
|
// `os.cp(...)` => `Option bool tmp = os__cp(...); if (!tmp.ok) { ... }`
|
||||||
fn (mut g Gen) or_block(var_name string, stmts []ast.Stmt, return_type table.Type) {
|
fn (mut g Gen) or_block(var_name string, stmts []ast.Stmt, return_type table.Type) {
|
||||||
|
cvar_name := c_name(var_name)
|
||||||
mr_styp := g.base_type(return_type)
|
mr_styp := g.base_type(return_type)
|
||||||
g.writeln(';') // or')
|
g.writeln(';') // or')
|
||||||
g.writeln('if (!${var_name}.ok) {')
|
g.writeln('if (!${cvar_name}.ok) {')
|
||||||
g.writeln('\tstring err = ${var_name}.v_error;')
|
g.writeln('\tstring err = ${cvar_name}.v_error;')
|
||||||
g.writeln('\tint errcode = ${var_name}.ecode;')
|
g.writeln('\tint errcode = ${cvar_name}.ecode;')
|
||||||
last_type, type_of_last_expression := g.type_of_last_statement(stmts)
|
last_type, type_of_last_expression := g.type_of_last_statement(stmts)
|
||||||
if last_type == 'v.ast.ExprStmt' && type_of_last_expression != 'void' {
|
if last_type == 'v.ast.ExprStmt' && type_of_last_expression != 'void' {
|
||||||
g.indent++
|
g.indent++
|
||||||
for i, stmt in stmts {
|
for i, stmt in stmts {
|
||||||
if i == stmts.len - 1 {
|
if i == stmts.len - 1 {
|
||||||
g.indent--
|
g.indent--
|
||||||
g.write('\t*(${mr_styp}*) ${var_name}.data = ')
|
g.write('\t*(${mr_styp}*) ${cvar_name}.data = ')
|
||||||
}
|
}
|
||||||
g.stmt(stmt)
|
g.stmt(stmt)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user