mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
fix bug with cascaded if blocks
This commit is contained in:
parent
55ddeac911
commit
f383ef26e8
@ -433,10 +433,21 @@ class BranchManger {
|
||||
// first search for first GOTO, any IF that point after the GOTO can not be part of the primary IF condition.
|
||||
// This occur with a second IF inside of the THEN. This can jump directly to the end of the ELSE.
|
||||
int maxElse = Integer.MAX_VALUE;
|
||||
for( int i = 0; i < parsedOperations.size(); i++ ) {
|
||||
int parsedOpCount = parsedOperations.size();
|
||||
for( int i = 0; i < parsedOpCount; i++ ) {
|
||||
ParsedBlock parsedBlock = parsedOperations.get( i );
|
||||
if( parsedBlock.op == JavaBlockOperator.GOTO ) {
|
||||
maxElse = parsedBlock.nextPosition;
|
||||
maxElse = parsedBlock.endPosition;
|
||||
|
||||
// find the last IF that point to this GOTO
|
||||
int gotoNext = parsedBlock.nextPosition;
|
||||
for( ; i > 0; i-- ) {
|
||||
parsedBlock = parsedOperations.get( i-1 );
|
||||
if( parsedBlock.endPosition == gotoNext ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
parsedOpCount = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -444,7 +455,7 @@ class BranchManger {
|
||||
int ifCount = 0;
|
||||
int thenPos = startBlock.nextPosition;
|
||||
int elsePos = startBlock.endPosition;
|
||||
for( ; ifCount < parsedOperations.size(); ifCount++ ) {
|
||||
for( ; ifCount < parsedOpCount; ifCount++ ) {
|
||||
ParsedBlock parsedBlock = parsedOperations.get( ifCount );
|
||||
if( parsedBlock.op != JavaBlockOperator.IF || parsedBlock.endPosition < elsePos || parsedBlock.endPosition > maxElse ) {
|
||||
// seems a second IF inside the THEN part.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 - 2019 Volker Berlin (i-net software)
|
||||
* Copyright 2018 - 2020 Volker Berlin (i-net software)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -73,6 +73,7 @@ public class ControlFlowOperators extends AbstractBaseTest {
|
||||
addParam( list, script, "ifAndOr6" );
|
||||
addParam( list, script, "ifAndOr8" );
|
||||
addParam( list, script, "ifWithoutElseAndLoop" );
|
||||
addParam( list, script, "ifOrWithMulti" );
|
||||
addParam( list, script, "stringSwitchNormalFoo" );
|
||||
addParam( list, script, "stringSwitchNormalBar" );
|
||||
addParam( list, script, "stringSwitchNormalDefault" );
|
||||
@ -495,6 +496,21 @@ public class ControlFlowOperators extends AbstractBaseTest {
|
||||
return ifWithoutElseAndLoop;
|
||||
}
|
||||
|
||||
@Export
|
||||
static int ifOrWithMulti() {
|
||||
int len = 4;
|
||||
|
||||
// the GOTO before the ELSE is not related to the main IF condition
|
||||
if( (len == 4 || len == 9) ) {
|
||||
if( len == 9 ) {
|
||||
len = 13;
|
||||
} else {
|
||||
len = 42;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
@Export
|
||||
static int stringSwitchNormalFoo() {
|
||||
return stringSwitchNormal( "foo" );
|
||||
|
Loading…
x
Reference in New Issue
Block a user