mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
fix handling of subopertions in a SWITCH and add more asserts. #43
This commit is contained in:
parent
4958cb2f46
commit
a46cbe2bc5
@ -910,6 +910,9 @@ class BranchManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int end = parsedBlock.endPosition;
|
int end = parsedBlock.endPosition;
|
||||||
|
if( end > parent.endPos ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if( start < end ) {
|
if( start < end ) {
|
||||||
BranchNode branch = blockNode;
|
BranchNode branch = blockNode;
|
||||||
while( branch.size() > 0 ) {
|
while( branch.size() > 0 ) {
|
||||||
@ -942,6 +945,12 @@ class BranchManager {
|
|||||||
|
|
||||||
parent.add( blockNode );
|
parent.add( blockNode );
|
||||||
|
|
||||||
|
blockNode = cases[0].node;
|
||||||
|
do {
|
||||||
|
calculateSubOperations( blockNode, parsedOperations );
|
||||||
|
blockNode = blockNode.parent;
|
||||||
|
} while( blockNode != parent );
|
||||||
|
|
||||||
if( brTableNode != null ) {
|
if( brTableNode != null ) {
|
||||||
// sort back in the natural order and create a br_table
|
// sort back in the natural order and create a br_table
|
||||||
Arrays.sort( cases, ( a, b ) -> Long.compare( a.key, b.key ) );
|
Arrays.sort( cases, ( a, b ) -> Long.compare( a.key, b.key ) );
|
||||||
@ -951,12 +960,6 @@ class BranchManager {
|
|||||||
}
|
}
|
||||||
brTableNode.data = data;
|
brTableNode.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockNode = cases[0].node;
|
|
||||||
do {
|
|
||||||
calculateSubOperations( blockNode, parsedOperations );
|
|
||||||
blockNode = blockNode.parent;
|
|
||||||
} while( blockNode != parent );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1699,6 +1702,7 @@ class BranchManager {
|
|||||||
int nodeStartPos = node.startPos;
|
int nodeStartPos = node.startPos;
|
||||||
for( int i = size - 1; i >= 0; i-- ) {
|
for( int i = size - 1; i >= 0; i-- ) {
|
||||||
if( get( i ).endPos <= nodeStartPos ) {
|
if( get( i ).endPos <= nodeStartPos ) {
|
||||||
|
assert !overlapped( i + 1, node ): "Node on wrong level: " + node + "; parent: " + this;
|
||||||
super.add( i + 1, node );
|
super.add( i + 1, node );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1715,9 +1719,35 @@ class BranchManager {
|
|||||||
public void add( int index, BranchNode node ) {
|
public void add( int index, BranchNode node ) {
|
||||||
node.parent = this;
|
node.parent = this;
|
||||||
assert node.startOp == null || (node.startPos >= startPos && node.endPos <= endPos): "Node outside parent: " + this + " + " + node;
|
assert node.startOp == null || (node.startPos >= startPos && node.endPos <= endPos): "Node outside parent: " + this + " + " + node;
|
||||||
|
assert !overlapped( index, node ): "Node on wrong level: " + node + "; parent: " + this;
|
||||||
super.add( index, node );
|
super.add( index, node );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the given node overlapped with other existing child nodes and should not be added.
|
||||||
|
* @param index the possible insert code position
|
||||||
|
* @param node the node
|
||||||
|
* @return true, if the position is already consumed from a child
|
||||||
|
*/
|
||||||
|
private boolean overlapped( int index, @Nonnull BranchNode node ) {
|
||||||
|
if( node.startOp == null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if( index > 0 ) {
|
||||||
|
BranchNode before = get( index - 1 );
|
||||||
|
if( before.endPos > node.startPos ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( index < size() ) {
|
||||||
|
BranchNode after = get( index );
|
||||||
|
if( node.endPos > after.startPos ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the given position overlapped with other existing child nodes
|
* If the given position overlapped with other existing child nodes
|
||||||
* @param startPos the code position
|
* @param startPos the code position
|
||||||
|
Loading…
x
Reference in New Issue
Block a user