mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
fix a while loop in ELSE after an return.
This commit is contained in:
parent
cbcf9fdfbc
commit
71d2b91895
@ -185,6 +185,14 @@ class BranchManager {
|
||||
if( loop == null ) {
|
||||
loop = new ParsedBlock( JavaBlockOperator.LOOP, start, 0, start, parsedBlock.lineNumber );
|
||||
loops.put( start, loop );
|
||||
// if a condition form outside of the loop point inside the loop then it must be conditional return and a jump to the loop condition.
|
||||
for( int n = b - 1; n >= 0; n-- ) {
|
||||
ParsedBlock prevBlock = parsedOperations.get( n );
|
||||
if( prevBlock.op == JavaBlockOperator.IF && prevBlock.startPosition < start && prevBlock.endPosition > start
|
||||
&& prevBlock.endPosition < parsedBlock.startPosition ) {
|
||||
prevBlock.endPosition = start;
|
||||
}
|
||||
}
|
||||
}
|
||||
loop.nextPosition = parsedBlock.startPosition; // Jump position for Continue
|
||||
loop.endPosition = parsedBlock.nextPosition;
|
||||
|
@ -53,6 +53,7 @@ public class ControlFlowOperators extends AbstractBaseTest {
|
||||
addParam( list, script, "whileLoopWithContinue" );
|
||||
addParam( list, script, "whileLoopInElse_3" );
|
||||
addParam( list, script, "whileLoopInElse_13" );
|
||||
addParam( list, script, "whileLoopInElseAfterReturn" );
|
||||
addParam( list, script, "forLoop" );
|
||||
addParam( list, script, "conditionalOperator" );
|
||||
addParam( list, script, "conditionalOperator2" );
|
||||
@ -376,6 +377,21 @@ public class ControlFlowOperators extends AbstractBaseTest {
|
||||
return whileLoopInElse( 13 );
|
||||
}
|
||||
|
||||
@Export
|
||||
public static int whileLoopInElseAfterReturn() {
|
||||
int yIndex = 13;
|
||||
int result = 0;
|
||||
if (yIndex == 3) {
|
||||
return 42;
|
||||
} else {
|
||||
while (yIndex > 7) {
|
||||
result++;
|
||||
yIndex--;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Export
|
||||
static int forLoop() {
|
||||
int a = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user