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

parser: fix nested amp (#6402)

This commit is contained in:
Daniel Däschle 2020-09-18 01:04:56 +02:00 committed by GitHub
parent 69c592e0d6
commit f59b771c76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 7 deletions

View File

@ -1921,6 +1921,7 @@ fn (mut g Gen) expr(node ast.Expr) {
// &Foo(0) => ((Foo*)0)
g.out.go_back(1)
}
g.is_amp = false
sym := g.table.get_type_symbol(node.typ)
if sym.kind == .string && !node.typ.is_ptr() {
// `string(x)` needs `tos()`, but not `&string(x)
@ -1950,14 +1951,8 @@ fn (mut g Gen) expr(node ast.Expr) {
g.expr(node.expr)
g.write('))')
} else {
// styp := g.table.Type_to_str(it.typ)
styp := g.typ(node.typ)
// g.write('($styp)(')
g.write('(($styp)(')
// if g.is_amp {
// g.write('*')
// }
// g.write(')(')
g.expr(node.expr)
if node.expr is ast.IntegerLiteral &&
node.typ in [table.u64_type, table.u32_type, table.u16_type] {

View File

@ -1061,6 +1061,10 @@ pub fn (mut p Parser) name_expr() ast.Expr {
// Handle `&Foo(0)`
to_typ = to_typ.to_ptr()
}
// this prevents inner casts to also have an `&`
// example: &Foo(malloc(int(num)))
// without the next line int would result in int*
p.is_amp = false
p.check(.lpar)
mut expr := ast.Expr{}
mut arg := ast.Expr{}

View File

@ -340,7 +340,7 @@ fn (mut p Parser) prefix_expr() ast.PrefixExpr {
p.next()
mut right := if op == .minus { p.expr(token.Precedence.call) } else { p.expr(token.Precedence.prefix) }
p.is_amp = false
if mut right is ast.CastExpr {
if right is ast.CastExpr {
right.in_prexpr = true
}
mut or_stmts := []ast.Stmt{}