File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -384,17 +384,28 @@ trait CGenIfThenElse extends CGenEffect with BaseGenIfThenElse {
384
384
emitBlock(b)
385
385
stream.println(" }" )
386
386
case _ =>
387
- val ten = quote(sym) + " True"
388
- val fen = quote(sym) + " False"
389
- def emitCondFun [T : Manifest ](fname : String , block : Block [T ]) {
390
- stream.println(" auto " + fname + " = [&]() {" );
391
- emitBlock(block)
392
- stream.println(" return " + quote(getBlockResult(block)) + " ;" )
393
- stream.println(" };" )
387
+ if (cppIfElseAutoRet == " true" ) {
388
+ val ten = quote(sym) + " True"
389
+ val fen = quote(sym) + " False"
390
+ def emitCondFun [T : Manifest ](fname : String , block : Block [T ]) {
391
+ stream.println(" auto " + fname + " = [&]() {" );
392
+ emitBlock(block)
393
+ stream.println(" return " + quote(getBlockResult(block)) + " ;" )
394
+ stream.println(" };" )
395
+ }
396
+ emitCondFun(ten, a)
397
+ emitCondFun(fen, b)
398
+ stream.println(" auto " + quote(sym) + " = " + quote(c) + " ? " + ten + " () : " + fen + " ();" )
399
+ } else {
400
+ stream.println(" %s %s;" .format(remap(sym.tp),quote(sym)))
401
+ stream.println(" if (" + quote(c) + " ) {" )
402
+ emitBlock(a)
403
+ stream.println(" %s = %s;" .format(quote(sym),quote(getBlockResult(a))))
404
+ stream.println(" } else {" )
405
+ emitBlock(b)
406
+ stream.println(" %s = %s;" .format(quote(sym),quote(getBlockResult(b))))
407
+ stream.println(" }" )
394
408
}
395
- emitCondFun(ten, a)
396
- emitCondFun(fen, b)
397
- stream.println(" auto " + quote(sym) + " = " + quote(c) + " ? " + ten + " () : " + fen + " ();" )
398
409
}
399
410
/*
400
411
val booll = remap(sym.tp).equals("void")
Original file line number Diff line number Diff line change @@ -11,4 +11,7 @@ trait Config {
11
11
12
12
// explicit return type of lambda functions (allows recursive functions but is less generic)
13
13
val cppExplicitFunRet = System .getProperty(" lms.cpp.explicitFunRet" ," true" )
14
+
15
+ // auto return value of if-else expressions (allows type deduction on if-then-else expressions)
16
+ val cppIfElseAutoRet = System .getProperty(" lms.cpp.ifElseAutoRet" ," false" )
14
17
}
You can’t perform that action at this time.
0 commit comments