cgen: fix ->

pull/3978/head
Alexander Medvednikov 2020-03-08 19:38:27 +01:00
parent a58be3af0c
commit 754a6cc93e
4 changed files with 12 additions and 7 deletions

View File

@ -319,9 +319,9 @@ fn (g mut Gen) gen_fn_decl(it ast.FnDecl) {
if it.is_method { if it.is_method {
mut styp := g.typ(it.receiver.typ) mut styp := g.typ(it.receiver.typ)
// if table.type_nr_muls(it.receiver.typ) > 0 { // if table.type_nr_muls(it.receiver.typ) > 0 {
if it.rec_mut { // if it.rec_mut {
styp += '*' // styp += '*'
} // }
g.write('$styp $it.receiver.name') g.write('$styp $it.receiver.name')
// TODO mut // TODO mut
g.definitions.write('$styp $it.receiver.name') g.definitions.write('$styp $it.receiver.name')
@ -642,7 +642,8 @@ fn (g mut Gen) expr(node ast.Expr) {
} }
ast.SelectorExpr { ast.SelectorExpr {
g.expr(it.expr) g.expr(it.expr)
if table.type_nr_muls(it.expr_type) > 0 { // if table.type_nr_muls(it.expr_type) > 0 {
if table.type_is_ptr(it.expr_type) {
g.write('->') g.write('->')
} }
else { else {

View File

@ -94,7 +94,7 @@ i < 10; i++) {
} }
void User_inc_age(User* u, int n) { void User_inc_age(User* u, int n) {
u.age += n; u->age += n;
} }
int get_int(string a) { int get_int(string a) {

View File

@ -80,7 +80,7 @@ fn (p mut Parser) fn_decl() ast.FnDecl {
p.next() p.next()
rec_name = p.check_name() rec_name = p.check_name()
if p.tok.kind == .key_mut { if p.tok.kind == .key_mut {
p.next() // p.next()
rec_mut = true rec_mut = true
} }
rec_type = p.parse_type() rec_type = p.parse_type()

View File

@ -90,6 +90,10 @@ pub fn (p mut Parser) parse_type() table.Type {
p.check(.amp) p.check(.amp)
nr_muls++ nr_muls++
} }
if p.tok.kind == .key_mut {
nr_muls++
p.next()
}
is_c := p.tok.lit == 'C' is_c := p.tok.lit == 'C'
if is_c { if is_c {
p.next() p.next()
@ -215,7 +219,7 @@ pub fn (p mut Parser) parse_any_type(is_c, is_ptr bool) table.Type {
// println('NOT FOUND: $name - adding placeholder - $idx') // println('NOT FOUND: $name - adding placeholder - $idx')
return table.new_type(idx) return table.new_type(idx)
} }
} }
} }
} }
} }