Flip > and >= in for loop conditions to < and <= respectively #48
Closed
Desetude
wants to merge 1 commits from Desetude:feature/for-loop-condition-flip
into master
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'Desetude:feature/for-loop-condition-flip'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Here's a diff of the client produced on my branch and the one produced on master: https://gist.github.com/Desetude/1453e2df162cd508ea5f6a1da89058dc.
Resolves bullet point 6 of #7.
class ForLoopConditionTransformer : Transformer() {
override fun transform(unit: CompilationUnit) {
unit.walk(Node.TreeTraversal.POSTORDER) { stmt: ForStmt ->
if (stmt.compare.isEmpty) {
isEmpty
doesn't seem to be a function/property onOptional
for me, so this doesn't build for me. I don't know if that's some sort of Kotlin set up problem on my end though.I think I might also prefer using
.ifPresent()
with a lambda rather than separateisPresent()
andget()
calls, as it's then guaranteed that you can't forget theisPresent()
. Some of the other transformers do this.else -> return@walk
}
stmt.setCompare(BinaryExpr(expr.right, expr.left, flipped))
Does
stmt.compare = ...
work here instead? I think that'd be the preferred Kotlin style, if so.I think it doesn't work.
cherry-picked, thanks!