| 1 | module c |
| 2 | |
| 3 | struct PastTmpVar { |
| 4 | mut: |
| 5 | var_name string |
| 6 | tmp_var string |
| 7 | s string |
| 8 | s_ends_with_ln bool |
| 9 | } |
| 10 | |
| 11 | fn (mut g Gen) past_tmp_var_new() PastTmpVar { |
| 12 | tmp_var := g.new_tmp_var() |
| 13 | mut s := g.go_before_last_stmt() |
| 14 | s_ends_with_ln := s.ends_with('\n') |
| 15 | s = s.trim_space() |
| 16 | g.empty_line = true |
| 17 | return PastTmpVar{ |
| 18 | tmp_var: tmp_var |
| 19 | s: s |
| 20 | s_ends_with_ln: s_ends_with_ln |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | fn (mut g Gen) past_tmp_var_from_var_name(var_name string) PastTmpVar { |
| 25 | mut tmp_var := g.new_tmp_var() |
| 26 | mut s := '' |
| 27 | if var_name != '' { |
| 28 | tmp_var = var_name |
| 29 | } else { |
| 30 | s = g.go_before_last_stmt() |
| 31 | } |
| 32 | s_ends_with_ln := s.ends_with('\n') |
| 33 | s = s.trim_space() |
| 34 | g.empty_line = true |
| 35 | return PastTmpVar{ |
| 36 | var_name: var_name |
| 37 | tmp_var: tmp_var |
| 38 | s: s |
| 39 | s_ends_with_ln: s_ends_with_ln |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | fn (mut g Gen) past_tmp_var_done(p &PastTmpVar) { |
| 44 | if p.var_name.len == 0 { |
| 45 | if p.s_ends_with_ln { |
| 46 | g.writeln(p.s) |
| 47 | } else { |
| 48 | g.write(p.s) |
| 49 | } |
| 50 | if g.inside_return { |
| 51 | g.write(' ') |
| 52 | } |
| 53 | g.write(p.tmp_var) |
| 54 | } |
| 55 | } |
| 56 | |