Skip to content

Commit

Permalink
Fixing up some issues with the assignment operator closures
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotchance committed Aug 12, 2017
1 parent 87517d7 commit b78a50b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion transpiler/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -437,7 +443,6 @@ func transpileDoStmt(n *ast.DoStmt, p *program.Program) (
// | `-BreakStmt 0x3bb1d80 <line:16:4>
// `-<<<NULL>>>
func createIfWithNotConditionAndBreak(condition ast.Node) (ifStmt ast.IfStmt) {

ifStmt.AddChild(nil)

var par ast.ParenExpr
Expand Down
6 changes: 3 additions & 3 deletions transpiler/transpiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b78a50b

Please sign in to comment.