mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: remove start_tmp() entirely
This commit is contained in:
parent
91896af877
commit
b3143bb559
@ -105,25 +105,28 @@ fn (g mut CGen) save() {
|
|||||||
g.out.close()
|
g.out.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (g mut CGen) start_tmp() {
|
|
||||||
if g.is_tmp {
|
// returns expression's type, and entire expression's string representation)
|
||||||
g.prev_tmps << g.tmp_line
|
fn (p mut Parser) tmp_expr() (string, string) {
|
||||||
|
// former start_tmp()
|
||||||
|
if p.cgen.is_tmp {
|
||||||
|
p.cgen.prev_tmps << p.cgen.tmp_line
|
||||||
}
|
}
|
||||||
// kg.tmp_lines_pos++
|
// kg.tmp_lines_pos++
|
||||||
g.tmp_line = ''
|
p.cgen.tmp_line = ''
|
||||||
g.is_tmp = true
|
p.cgen.is_tmp = true
|
||||||
}
|
//
|
||||||
|
typ := p.bool_expression()
|
||||||
fn (g mut CGen) end_tmp() string {
|
|
||||||
res := g.tmp_line
|
res := p.cgen.tmp_line
|
||||||
if g.prev_tmps.len > 0 {
|
if p.cgen.prev_tmps.len > 0 {
|
||||||
g.tmp_line = g.prev_tmps.last()
|
p.cgen.tmp_line = p.cgen.prev_tmps.last()
|
||||||
g.prev_tmps = g.prev_tmps[0..g.prev_tmps.len-1]
|
p.cgen.prev_tmps = p.cgen.prev_tmps[0..p.cgen.prev_tmps.len-1]
|
||||||
} else {
|
} else {
|
||||||
g.tmp_line = ''
|
p.cgen.tmp_line = ''
|
||||||
g.is_tmp = false
|
p.cgen.is_tmp = false
|
||||||
}
|
}
|
||||||
return res
|
return typ, res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (g &CGen) add_placeholder() int {
|
fn (g &CGen) add_placeholder() int {
|
||||||
|
@ -12,13 +12,10 @@ import (
|
|||||||
fn (p mut Parser) match_statement(is_expr bool) string {
|
fn (p mut Parser) match_statement(is_expr bool) string {
|
||||||
p.check(.key_match)
|
p.check(.key_match)
|
||||||
p.fspace()
|
p.fspace()
|
||||||
p.cgen.start_tmp()
|
typ, expr := p.tmp_expr()
|
||||||
typ := p.bool_expression()
|
|
||||||
if typ.starts_with('array_') {
|
if typ.starts_with('array_') {
|
||||||
p.error('arrays cannot be compared')
|
p.error('arrays cannot be compared')
|
||||||
}
|
}
|
||||||
expr := p.cgen.end_tmp()
|
|
||||||
|
|
||||||
// is it safe to use p.cgen.insert_before ???
|
// is it safe to use p.cgen.insert_before ???
|
||||||
tmp_var := p.get_tmp()
|
tmp_var := p.get_tmp()
|
||||||
p.cgen.insert_before('$typ $tmp_var = $expr;')
|
p.cgen.insert_before('$typ $tmp_var = $expr;')
|
||||||
|
@ -2450,13 +2450,6 @@ fn (p mut Parser) get_tmp_counter() int {
|
|||||||
return p.tmp_cnt
|
return p.tmp_cnt
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns expression's type, and entire expression's string representation)
|
|
||||||
fn (p mut Parser) tmp_expr() (string, string) {
|
|
||||||
p.cgen.start_tmp()
|
|
||||||
typ := p.bool_expression()
|
|
||||||
val := p.cgen.end_tmp()
|
|
||||||
return typ, val
|
|
||||||
}
|
|
||||||
|
|
||||||
fn (p mut Parser) if_st(is_expr bool, elif_depth int) string {
|
fn (p mut Parser) if_st(is_expr bool, elif_depth int) string {
|
||||||
if is_expr {
|
if is_expr {
|
||||||
|
@ -90,21 +90,18 @@ fn (p mut Parser) select_query(fn_ph int) string {
|
|||||||
// `where` statement
|
// `where` statement
|
||||||
if p.tok == .name && p.lit == 'where' {
|
if p.tok == .name && p.lit == 'where' {
|
||||||
p.next()
|
p.next()
|
||||||
p.cgen.start_tmp()
|
_, expr := p.tmp_expr()
|
||||||
p.is_sql = true
|
p.is_sql = true
|
||||||
p.bool_expression()
|
|
||||||
p.is_sql = false
|
p.is_sql = false
|
||||||
q += ' where ' + p.cgen.end_tmp()
|
q += ' where ' + expr
|
||||||
}
|
}
|
||||||
// limit?
|
// limit?
|
||||||
mut query_one := false
|
mut query_one := false
|
||||||
if p.tok == .name && p.lit == 'limit' {
|
if p.tok == .name && p.lit == 'limit' {
|
||||||
p.next()
|
p.next()
|
||||||
p.cgen.start_tmp()
|
_, limit := p.tmp_expr()
|
||||||
p.is_sql = true
|
p.is_sql = true
|
||||||
p.bool_expression()
|
|
||||||
p.is_sql = false
|
p.is_sql = false
|
||||||
limit := p.cgen.end_tmp()
|
|
||||||
q += ' limit ' + limit
|
q += ' limit ' + limit
|
||||||
// `limit 1` means we are getting `?User`, not `[]User`
|
// `limit 1` means we are getting `?User`, not `[]User`
|
||||||
if limit.trim_space() == '1' {
|
if limit.trim_space() == '1' {
|
||||||
|
Loading…
Reference in New Issue
Block a user