node: implement *expr.Ternary (a hoisting pass would be better)
This commit is contained in:
parent
ce3cd1065d
commit
92abcfe5b9
19
node.go
19
node.go
@ -1090,6 +1090,25 @@ func (this *conversionState) convertNoFreeFloating(n_ node.Node) (string, error)
|
||||
|
||||
return "!(" + rhs + ")", nil
|
||||
|
||||
case *expr.Ternary:
|
||||
cond, err := this.convert(n.Condition)
|
||||
if err != nil {
|
||||
return "", parseErr{n, err}
|
||||
}
|
||||
|
||||
iftrue, err := this.convert(n.IfTrue)
|
||||
if err != nil {
|
||||
return "", parseErr{n, err}
|
||||
}
|
||||
|
||||
iffalse, err := this.convert(n.IfFalse)
|
||||
if err != nil {
|
||||
return "", parseErr{n, err}
|
||||
}
|
||||
|
||||
// FIXME this is (A) not idiomatic, and (B) doesn't work in assignment expressions
|
||||
return "(func() unknown {\nif (" + cond + ") {\nreturn (" + iftrue + ")\n} else {\nreturn (" + iffalse + ")\n } })()", nil
|
||||
|
||||
case *expr.ArrayDimFetch:
|
||||
// Might be x[foo], might be x[] (i.e. append() call)
|
||||
// In order to make the append() transformation, we need to lookahead
|
||||
|
Loading…
Reference in New Issue
Block a user