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

interactive debugging

This commit is contained in:
Emily Hudson 2019-07-26 15:45:16 +01:00 committed by Alexander Medvednikov
parent 8b195ba32a
commit 90bb48db5d
4 changed files with 27 additions and 14 deletions

View File

@ -24,14 +24,17 @@ struct CGen {
//buf strings.Builder //buf strings.Builder
is_user bool is_user bool
mut: mut:
run Pass run Pass
nogen bool nogen bool
tmp_line string tmp_line string
cur_line string cur_line string
prev_line string prev_line string
is_tmp bool is_tmp bool
fn_main string fn_main string
stash string stash string
file string
line int
line_directives bool
} }
fn new_cgen(out_name_c string) *CGen { fn new_cgen(out_name_c string) *CGen {
@ -59,6 +62,9 @@ fn (g mut CGen) genln(s string) {
} }
g.cur_line = '$g.cur_line $s' g.cur_line = '$g.cur_line $s'
if g.cur_line != '' { if g.cur_line != '' {
if g.line_directives && g.cur_line.trim_space() != '' {
g.lines << '#line $g.line "$g.file"'
}
g.lines << g.cur_line g.lines << g.cur_line
g.prev_line = g.cur_line g.prev_line = g.cur_line
g.cur_line = '' g.cur_line = ''

View File

@ -90,6 +90,7 @@ mut:
is_run bool is_run bool
show_c_cmd bool // `v -show_c_cmd` prints the C command to build program.v.c show_c_cmd bool // `v -show_c_cmd` prints the C command to build program.v.c
sanitize bool // use Clang's new "-fsanitize" option sanitize bool // use Clang's new "-fsanitize" option
is_debuggable bool
is_debug bool // keep compiled C files is_debug bool // keep compiled C files
no_auto_free bool // `v -nofree` disable automatic `free()` insertion for better performance in some applications (e.g. compilers) no_auto_free bool // `v -nofree` disable automatic `free()` insertion for better performance in some applications (e.g. compilers)
cflags string // Additional options which will be passed to the C compiler. cflags string // Additional options which will be passed to the C compiler.
@ -1158,7 +1159,8 @@ fn new_v(args[]string) *V {
is_play: args.contains('play') is_play: args.contains('play')
is_prod: args.contains('-prod') is_prod: args.contains('-prod')
is_verbose: args.contains('-verbose') is_verbose: args.contains('-verbose')
is_debug: args.contains('-debug') is_debuggable: args.contains('-g') // -debuggable implys debug
is_debug: args.contains('-debug') || args.contains('-g')
obfuscate: obfuscate obfuscate: obfuscate
is_prof: args.contains('-prof') is_prof: args.contains('-prof')
is_live: args.contains('-live') is_live: args.contains('-live')

View File

@ -104,6 +104,10 @@ fn (c mut V) new_parser(path string, run Pass) Parser {
path.contains('v/vlib')) path.contains('v/vlib'))
} }
c.cgen.line_directives = c.pref.is_debuggable
c.cgen.file = path
p.next() p.next()
// p.scanner.debug_tokens() // p.scanner.debug_tokens()
return p return p
@ -1243,7 +1247,7 @@ fn (p mut Parser) var_decl() {
// User user = *(User*)tmp.data; // User user = *(User*)tmp.data;
// p.assigned_var = '' // p.assigned_var = ''
p.cgen.set_placeholder(pos, '$typ $tmp = ') p.cgen.set_placeholder(pos, '$typ $tmp = ')
p.gen(';') p.genln(';')
typ = typ.replace('Option_', '') typ = typ.replace('Option_', '')
p.next() p.next()
p.check(.lcbr) p.check(.lcbr)
@ -3317,7 +3321,7 @@ fn (p mut Parser) return_st() {
p.cgen.resetln('return $ret') p.cgen.resetln('return $ret')
} else { } else {
tmp := p.get_tmp() tmp := p.get_tmp()
p.cgen.resetln('$expr_type $tmp = $ret;') p.cgen.resetln('$expr_type $tmp = $ret;\n')
p.genln(p.cur_fn.defer_text) p.genln(p.cur_fn.defer_text)
p.genln('return $tmp;') p.genln('return $tmp;')
} }
@ -3525,6 +3529,7 @@ fn (p mut Parser) fgenln(s string) {
fn (p mut Parser) peek() Token { fn (p mut Parser) peek() Token {
for { for {
p.cgen.line = p.scanner.line_nr + 1
tok := p.scanner.peek() tok := p.scanner.peek()
if tok != .nl { if tok != .nl {
return tok return tok

View File

@ -210,7 +210,7 @@ fn (s mut Scanner) skip_whitespace() {
for s.pos < s.text.len && s.text[s.pos].is_white() { for s.pos < s.text.len && s.text[s.pos].is_white() {
// Count \r\n as one line // Count \r\n as one line
if is_nl(s.text[s.pos]) && !s.expect('\r\n', s.pos-1) { if is_nl(s.text[s.pos]) && !s.expect('\r\n', s.pos-1) {
s.line_nr++ s.line_nr++
} }
s.pos++ s.pos++
} }