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

ast: return types, variable declaration

This commit is contained in:
Alexander Medvednikov
2019-12-26 13:27:35 +03:00
parent 320174bd5b
commit 0a3adb5de8
8 changed files with 187 additions and 48 deletions

View File

@@ -4,8 +4,9 @@
module compiler
fn (p mut Parser) bool_expression() string {
is_ret := p.prev_tok == .key_return
start_ph := p.cgen.add_placeholder()
expected := p.expected_type
mut expected := p.expected_type
tok := p.tok
typ := p.bterm()
mut got_and := false // to catch `a && b || c` in one expression without ()
@@ -46,7 +47,11 @@ fn (p mut Parser) bool_expression() string {
println(tok.str())
p.error('expr() returns empty type')
}
if p.inside_return_expr { //is_ret { // return a,b hack TODO
expected = p.expected_type
}
if expected != typ && expected in p.table.sum_types { // TODO perf
//p.warn('SUM CAST exp=$expected typ=$typ p.exp=$p.expected_type')
p.cgen.set_placeholder(start_ph,
//'/*SUM TYPE CAST*/($expected) { .obj = &($typ[]) { ')
'/*SUM TYPE CAST*/($expected) { .obj = memdup(& ')

View File

@@ -272,8 +272,9 @@ fn (p &Parser) gen_fmt() {
s3 := s2.replace(') or{', ') or {')
s4 := s3.replace(')or{', ') or {')
s5 := s4.replace('or{', 'or {')
s6 := s5.replace('}}\n', '}\n\t}\n')
s := s5
s := s6
if s == '' {
return