From b78a50bc6b088c8ad2db025245fc0a13bcef8372 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Sat, 12 Aug 2017 11:39:25 +1000 Subject: [PATCH] Fixing up some issues with the assignment operator closures --- transpiler/branch.go | 7 ++++++- transpiler/transpiler.go | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/transpiler/branch.go b/transpiler/branch.go index 5770a22a3..880b72bdb 100644 --- a/transpiler/branch.go +++ b/transpiler/branch.go @@ -60,6 +60,8 @@ func transpileIfStmt(n *ast.IfStmt, p *program.Program) ( panic("non-nil child 0 in IfStmt") } + // The last parameter must be false because we are transpiling an + // expression - assignment operators need to be wrapped in closures. conditional, conditionalType, newPre, newPost, err := transpileToExpr(children[1], p, false) if err != nil { return nil, nil, nil, err @@ -247,6 +249,9 @@ func transpileForStmt(n *ast.ForStmt, p *program.Program) ( if children[2] != nil { var conditionType string var newPre, newPost []goast.Stmt + + // The last parameter must be false because we are transpiling an + // expression - assignment operators need to be wrapped in closures. condition, conditionType, newPre, newPost, err = transpileToExpr(children[2], p, false) if err != nil { return nil, nil, nil, err @@ -340,6 +345,7 @@ func transpileWhileStmt(n *ast.WhileStmt, p *program.Program) ( forOperator.AddChild(n.Children[1]) forOperator.AddChild(nil) forOperator.AddChild(n.Children[2]) + return transpileForStmt(&forOperator, p) } @@ -437,7 +443,6 @@ func transpileDoStmt(n *ast.DoStmt, p *program.Program) ( // | `-BreakStmt 0x3bb1d80 // `-<<>> func createIfWithNotConditionAndBreak(condition ast.Node) (ifStmt ast.IfStmt) { - ifStmt.AddChild(nil) var par ast.ParenExpr diff --git a/transpiler/transpiler.go b/transpiler/transpiler.go index 00aa97aff..b7a0a1275 100644 --- a/transpiler/transpiler.go +++ b/transpiler/transpiler.go @@ -97,7 +97,7 @@ func transpileToExpr(node ast.Node, p *program.Program, exprIsStmt bool) ( expr, exprType, preStmts, postStmts, err = transpileMemberExpr(n, p) case *ast.ImplicitCastExpr: - expr, exprType, preStmts, postStmts, err = transpileToExpr(n.Children[0], p, false) + expr, exprType, preStmts, postStmts, err = transpileToExpr(n.Children[0], p, exprIsStmt) case *ast.DeclRefExpr: expr, exprType, err = transpileDeclRefExpr(n, p) @@ -109,7 +109,7 @@ func transpileToExpr(node ast.Node, p *program.Program, exprIsStmt bool) ( expr, exprType, preStmts, postStmts, err = transpileParenExpr(n, p) case *ast.CStyleCastExpr: - expr, exprType, preStmts, postStmts, err = transpileToExpr(n.Children[0], p, false) + expr, exprType, preStmts, postStmts, err = transpileToExpr(n.Children[0], p, exprIsStmt) case *ast.CharacterLiteral: expr, exprType, err = transpileCharacterLiteral(n), "char", nil @@ -209,7 +209,7 @@ func transpileToStmt(node ast.Node, p *program.Program) ( } // We do not care about the return type. - expr, _, preStmts, postStmts, err = transpileToExpr(node, p, false) + expr, _, preStmts, postStmts, err = transpileToExpr(node, p, true) if err != nil { return }