mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
options: use panic_debug() for opt()? calls in main with -cg
This commit is contained in:
parent
801bca1ef2
commit
70f0115e27
@ -731,6 +731,7 @@ pub struct OrExpr {
|
||||
pub:
|
||||
stmts []Stmt
|
||||
kind OrKind
|
||||
pos token.Position
|
||||
}
|
||||
|
||||
pub struct Assoc {
|
||||
|
@ -2973,7 +2973,12 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table.
|
||||
}
|
||||
} else if or_block.kind == .propagate {
|
||||
if g.file.mod.name == 'main' && g.cur_fn.name == 'main' {
|
||||
g.writeln('\tv_panic(${cvar_name}.v_error);')
|
||||
if g.pref.is_debug {
|
||||
paline, pafile, pamod, pafn := g.panic_debug_info(or_block.pos)
|
||||
g.writeln('panic_debug($paline, tos3("$pafile"), tos3("$pamod"), tos3("$pafn"), ${cvar_name}.v_error );')
|
||||
}else{
|
||||
g.writeln('\tv_panic(${cvar_name}.v_error);')
|
||||
}
|
||||
} else {
|
||||
g.writeln('\treturn $cvar_name;')
|
||||
}
|
||||
@ -3982,3 +3987,18 @@ fn (g &Gen) interface_call(typ, interface_type table.Type) {
|
||||
g.write('&')
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut g Gen) panic_debug_info(pos token.Position) (int, string, string, string) {
|
||||
paline := pos.line_nr + 1
|
||||
pafile := g.fn_decl.file.replace('\\', '/')
|
||||
pafn := g.fn_decl.name.after('.')
|
||||
mut pamod := g.fn_decl.name.all_before_last('.')
|
||||
if pamod == pafn {
|
||||
pamod = if g.fn_decl.is_builtin {
|
||||
'builtin'
|
||||
} else {
|
||||
'main'
|
||||
}
|
||||
}
|
||||
return paline, pafile, pamod, pafn
|
||||
}
|
||||
|
@ -533,17 +533,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
||||
g.write('))')
|
||||
}
|
||||
} else if g.pref.is_debug && node.name == 'panic' {
|
||||
paline := node.pos.line_nr + 1
|
||||
pafile := g.fn_decl.file.replace('\\', '/')
|
||||
pafn := g.fn_decl.name.after('.')
|
||||
mut pamod := g.fn_decl.name.all_before_last('.')
|
||||
if pamod == pafn {
|
||||
pamod = if g.fn_decl.is_builtin {
|
||||
'builtin'
|
||||
} else {
|
||||
'main'
|
||||
}
|
||||
}
|
||||
paline, pafile, pamod, pafn := g.panic_debug_info(node.pos)
|
||||
g.write('panic_debug($paline, tos3("$pafile"), tos3("$pamod"), tos3("$pafn"), ')
|
||||
g.call_args(node.args, node.expected_arg_types)
|
||||
g.write(')')
|
||||
|
@ -80,6 +80,7 @@ pub fn (mut p Parser) call_expr(language table.Language, mod string) ast.CallExp
|
||||
or_block: ast.OrExpr{
|
||||
stmts: or_stmts
|
||||
kind: or_kind
|
||||
pos: pos
|
||||
}
|
||||
generic_type: generic_type
|
||||
}
|
||||
|
@ -1026,6 +1026,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
|
||||
or_block: ast.OrExpr{
|
||||
stmts: or_stmts
|
||||
kind: or_kind
|
||||
pos: pos
|
||||
}
|
||||
}
|
||||
if is_filter {
|
||||
|
Loading…
Reference in New Issue
Block a user