options: use panic_debug() for opt()? calls in main with -cg

pull/4997/head
Delyan Angelov 2020-05-23 11:43:20 +03:00
parent 801bca1ef2
commit 70f0115e27
5 changed files with 25 additions and 12 deletions

View File

@ -731,6 +731,7 @@ pub struct OrExpr {
pub:
stmts []Stmt
kind OrKind
pos token.Position
}
pub struct Assoc {

View File

@ -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
}

View File

@ -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(')')

View File

@ -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
}

View File

@ -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 {