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

cgen: remove opt_ok2() part 1 (#16048)

This commit is contained in:
yuyi 2022-10-12 22:20:41 +08:00 committed by GitHub
parent c590c8250e
commit 211cb2af7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View File

@ -1609,7 +1609,7 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) bool {
g.expr(stmt.expr)
g.writeln(';')
} else {
g.write('opt_ok2(&($styp[]) { ')
g.write('_option_ok(&($styp[]) { ')
g.expr(stmt.expr)
g.writeln(' }, ($c.option_name*)(&$tmp_var), sizeof($styp));')
}
@ -1639,7 +1639,7 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) bool {
g.expr(stmt.expr)
g.writeln(';')
} else {
g.write('opt_ok2(&($styp[]) { ')
g.write('_result_ok(&($styp[]) { ')
g.expr(stmt.expr)
g.writeln(' }, ($c.result_name*)(&$tmp_var), sizeof($styp));')
}
@ -4324,10 +4324,14 @@ fn (mut g Gen) return_stmt(node ast.Return) {
typ_sym := g.table.sym(g.fn_decl.return_type)
mr_info := typ_sym.info as ast.MultiReturn
mut styp := ''
if fn_return_is_optional || fn_return_is_result {
if fn_return_is_optional {
g.writeln('$ret_typ $tmpvar;')
styp = g.base_type(g.fn_decl.return_type)
g.write('opt_ok2(&($styp/*X*/[]) { ')
g.write('_option_ok(&($styp[]) { ')
} else if fn_return_is_result {
g.writeln('$ret_typ $tmpvar;')
styp = g.base_type(g.fn_decl.return_type)
g.write('_result_ok(&($styp[]) { ')
} else {
if use_tmp_var {
g.write('$ret_typ $tmpvar = ')
@ -4426,7 +4430,7 @@ fn (mut g Gen) return_stmt(node ast.Return) {
if fn_return_is_optional && !expr_type_is_opt && return_sym.name != c.option_name {
styp := g.base_type(g.fn_decl.return_type)
g.writeln('$ret_typ $tmpvar;')
g.write('opt_ok2(&($styp[]) { ')
g.write('_option_ok(&($styp[]) { ')
if !g.fn_decl.return_type.is_ptr() && node.types[0].is_ptr() {
if !(node.exprs[0] is ast.Ident && !g.is_amp) {
g.write('*')
@ -4455,7 +4459,7 @@ fn (mut g Gen) return_stmt(node ast.Return) {
if fn_return_is_result && !expr_type_is_result && return_sym.name != c.result_name {
styp := g.base_type(g.fn_decl.return_type)
g.writeln('$ret_typ $tmpvar;')
g.write('${c.result_name}_ok(&($styp[]) { ')
g.write('_result_ok(&($styp[]) { ')
if !g.fn_decl.return_type.is_ptr() && node.types[0].is_ptr() {
if !(node.exprs[0] is ast.Ident && !g.is_amp) {
g.write('*')

View File

@ -154,7 +154,7 @@ $enc_fn_dec {
}
// cJSON_delete
dec.writeln('\t${option_name}_$styp ret;')
dec.writeln('\topt_ok2(&res, ($option_name*)&ret, sizeof(res));')
dec.writeln('\t_option_ok(&res, ($option_name*)&ret, sizeof(res));')
dec.writeln('\treturn ret;\n}')
enc.writeln('\treturn o;\n}')
g.gowrappers.writeln(dec.str())

View File

@ -37,7 +37,6 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F
'tos2',
'tos3',
'isnil',
'opt_ok2',
'_option_ok',
'_result_ok',
'error',