parser: fix tmp is already started issue

pull/2577/head
Danil-Lapirow 2019-10-28 22:50:58 +02:00 committed by Alexander Medvednikov
parent 6a609cb046
commit f161ff9db5
1 changed files with 9 additions and 5 deletions

View File

@ -25,6 +25,7 @@ mut:
consts_init []string consts_init []string
pass Pass pass Pass
nogen bool nogen bool
prev_tmps []string
tmp_line string tmp_line string
cur_line string cur_line string
prev_line string prev_line string
@ -105,9 +106,7 @@ fn (g mut CGen) save() {
fn (g mut CGen) start_tmp() { fn (g mut CGen) start_tmp() {
if g.is_tmp { if g.is_tmp {
println(g.tmp_line) g.prev_tmps << g.tmp_line
println('start_tmp() already started. cur_line="$g.cur_line"')
exit(1)
} }
// kg.tmp_lines_pos++ // kg.tmp_lines_pos++
g.tmp_line = '' g.tmp_line = ''
@ -115,9 +114,14 @@ fn (g mut CGen) start_tmp() {
} }
fn (g mut CGen) end_tmp() string { fn (g mut CGen) end_tmp() string {
g.is_tmp = false
res := g.tmp_line res := g.tmp_line
if g.prev_tmps.len > 0 {
g.tmp_line = g.prev_tmps.last()
g.prev_tmps = g.prev_tmps[0..g.prev_tmps.len-1]
} else {
g.tmp_line = '' g.tmp_line = ''
g.is_tmp = false
}
return res return res
} }