|
@@ -5,6 +5,8 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
import javax.swing.tree.MutableTreeNode;
|
|
|
import javax.swing.tree.TreePath;
|
|
|
|
|
|
+import animation.StackFrame.FrameType;
|
|
|
+
|
|
|
/**
|
|
|
* represents a line of pseudocode
|
|
|
* @author kolja
|
|
@@ -68,7 +70,7 @@ public class PseudoCodeNode extends DefaultMutableTreeNode {
|
|
|
controller = c;
|
|
|
}
|
|
|
|
|
|
- private void writeToStack( Memory m )
|
|
|
+ public void writeToStack( Memory m )
|
|
|
{
|
|
|
if( m.isDefined( "_pos" + nodeId, false ) )
|
|
|
throw new IllegalStateException( "variable _pos" + nodeId + " should not exist in current stack frame, but it exists" );
|
|
@@ -76,6 +78,8 @@ public class PseudoCodeNode extends DefaultMutableTreeNode {
|
|
|
throw new IllegalStateException( "variable _func" + nodeId + " should not exist in current stack frame, but it exists" );
|
|
|
m.declare( "_pos" + nodeId, currentCodeLine, false );
|
|
|
m.declare( "_func" + nodeId, function, false );
|
|
|
+ currentCodeLine = -1;
|
|
|
+ function = false;
|
|
|
setSelected( false );
|
|
|
if( children == null )
|
|
|
return;
|
|
@@ -83,7 +87,7 @@ public class PseudoCodeNode extends DefaultMutableTreeNode {
|
|
|
((PseudoCodeNode)c).writeToStack( m );
|
|
|
}
|
|
|
|
|
|
- private void loadFromStack( Memory m )
|
|
|
+ public void loadFromStack( Memory m )
|
|
|
{
|
|
|
if( !m.isDefined( "_pos" + nodeId, false ) )
|
|
|
throw new IllegalStateException( "variable _pos" + nodeId + "should exist in current stack frame, but it is undefined" );
|
|
@@ -236,23 +240,20 @@ public class PseudoCodeNode extends DefaultMutableTreeNode {
|
|
|
{
|
|
|
if( currentCodeLine == -1 )
|
|
|
{
|
|
|
- if( !m.isDefined( "line_" + nodeId + "_call", false ) )
|
|
|
+ if( !m.isDefined( "node_" + nodeId + "_call", false ) )
|
|
|
{
|
|
|
StackFrame tmp = null;
|
|
|
if( function )
|
|
|
{
|
|
|
tmp = m.removeFrame();
|
|
|
m.addFrame( tmp ); // a little abuse of the stack to get direct access of the current frame before it could be destroyed by the user defined function
|
|
|
- }ControlFlow cf = code.runForward( m );
|
|
|
+ }
|
|
|
+ ControlFlow cf = code.runForward( m );
|
|
|
switch( cf.getStatus() )
|
|
|
{
|
|
|
case ControlFlow.STEP_INTO:
|
|
|
+ writeToStack( m );
|
|
|
function = true;
|
|
|
- if( children != null )
|
|
|
- {
|
|
|
- for( Object c : children )
|
|
|
- ((PseudoCodeNode)c).writeToStack( m );
|
|
|
- }
|
|
|
switch( stepInto( m ) )
|
|
|
{
|
|
|
case BREAKPOINT:
|
|
@@ -275,17 +276,13 @@ public class PseudoCodeNode extends DefaultMutableTreeNode {
|
|
|
if( function )
|
|
|
{
|
|
|
m.addFrame( tmp ); // add old stack frame
|
|
|
- if( children != null )
|
|
|
- {
|
|
|
- for( Object c : children )
|
|
|
- ((PseudoCodeNode)c).loadFromStack( m ); // load stored variables
|
|
|
- }
|
|
|
+ loadFromStack( m ); // load stored variables
|
|
|
m.removeFrame(); // remove the stack frame
|
|
|
}
|
|
|
return CodeStatus.FINISHED;
|
|
|
case ControlFlow.CALL:
|
|
|
alg.addActiveFunction( cf.getFunction() );
|
|
|
- m.declare( "line_" + nodeId + "_call", true, false );
|
|
|
+ m.declare( "node_" + nodeId + "_call", cf.getFunction(), false );
|
|
|
setSelected( false );
|
|
|
m.declare( "callback", this, true );
|
|
|
switch( cf.getFunction().setSelected( true ) )
|
|
@@ -311,7 +308,7 @@ public class PseudoCodeNode extends DefaultMutableTreeNode {
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- m.undeclare( "line_" + nodeId + "_call", false );
|
|
|
+ m.undeclare( "node_" + nodeId + "_call", false );
|
|
|
return CodeStatus.FINISHED;
|
|
|
}
|
|
|
}
|