compiler: add support for panic_debug with -cg

pull/4693/head
Delyan Angelov 2020-05-03 22:13:40 +03:00
parent 0b750a234f
commit 242670a33d
5 changed files with 14 additions and 1 deletions

View File

@ -213,6 +213,7 @@ pub:
is_builtin bool // this function is defined in builtin/strconv is_builtin bool // this function is defined in builtin/strconv
ctdefine string // has [if myflag] tag ctdefine string // has [if myflag] tag
pos token.Position pos token.Position
file string
pub mut: pub mut:
return_type table.Type return_type table.Type
} }
@ -930,7 +931,7 @@ fn (stmt Stmt) position() token.Position {
} }
// TODO: remove this fugly hack :-| // TODO: remove this fugly hack :-|
// fe2ex/1 and ex2fe/1 are used to convert back and forth from // fe2ex/1 and ex2fe/1 are used to convert back and forth from
// table.FExpr to ast.Expr , which in turn is needed to break // table.FExpr to ast.Expr , which in turn is needed to break
// a dependency cycle between v.ast and v.table, for the single // a dependency cycle between v.ast and v.table, for the single
// field table.Field.default_expr, which should be ast.Expr // field table.Field.default_expr, which should be ast.Expr

View File

@ -479,6 +479,14 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
} }
g.write('))') g.write('))')
} }
} else if g.pref.is_debug && node.name == 'panic' {
paline := node.pos.line_nr + 1
pafile := g.fn_decl.file
pafn := g.fn_decl.name.after('.')
pamod := g.fn_decl.name.all_before_last('.')
g.write('panic_debug($paline, tos3("$pafile"), tos3("$pamod"), tos3("$pafn"), ')
g.call_args(node.args, node.expected_arg_types)
g.write(')')
} else { } else {
g.write('${name}(') g.write('${name}(')
g.call_args(node.args, node.expected_arg_types) g.call_args(node.args, node.expected_arg_types)

View File

@ -255,6 +255,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
is_js: is_js is_js: is_js
no_body: no_body no_body: no_body
pos: start_pos.extend(end_pos) pos: start_pos.extend(end_pos)
file: p.file_name
is_builtin: p.builtin_mod || p.mod in util.builtin_module_parts is_builtin: p.builtin_mod || p.mod in util.builtin_module_parts
ctdefine: ctdefine ctdefine: ctdefine
} }
@ -305,6 +306,7 @@ fn (mut p Parser) anon_fn() ast.AnonFn {
is_anon: true is_anon: true
no_body: no_body no_body: no_body
pos: pos pos: pos
file: p.file_name
} }
typ: typ typ: typ
} }

View File

@ -106,6 +106,7 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme
if p.pref.is_script && !p.pref.is_test && p.mod == 'main' && !have_fn_main(stmts) { if p.pref.is_script && !p.pref.is_test && p.mod == 'main' && !have_fn_main(stmts) {
stmts << ast.FnDecl { stmts << ast.FnDecl {
name: 'main' name: 'main'
file: p.file_name
return_type: table.void_type return_type: table.void_type
} }
} }

View File

@ -286,6 +286,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
mut method := ast.FnDecl{ mut method := ast.FnDecl{
name: name name: name
args: args args: args
file: p.file_name
return_type: table.void_type return_type: table.void_type
} }
if p.tok.kind.is_start_of_type() && p.tok.line_nr == line_nr { if p.tok.kind.is_start_of_type() && p.tok.line_nr == line_nr {