Kolja Strohm 6 жил өмнө
parent
commit
a5c0494e04

+ 2 - 6
src/animation/AnimatedAlgorithm.java

@@ -20,7 +20,6 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
     protected PseudoCodeNode root;
     protected Stack<PseudoCodeNode> activeFunction;
     protected Memory mem;
-    private Memory fstack;
 
     public AnimatedAlgorithm( AnimationController controller, LayeredGraphNode graph, JFrame view )
     {
@@ -32,14 +31,12 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
         mem.declare( "graph", graph, true );
         mem.addFrame( new StackFrame( FrameType.FUNCTION ) );
         activeFunction = new Stack<PseudoCodeNode>();
-        fstack = new Memory();
     }
     
     public void addActiveFunction( PseudoCodeNode n )
     {
     	if( !activeFunction.empty() )
-    		activeFunction.peek().writeToStack( fstack );
-        fstack.addFrame( new StackFrame( FrameType.FUNCTION ) );
+    		activeFunction.peek().writeToStack( mem );
     	activeFunction.push( n );
     }
 
@@ -96,9 +93,8 @@ public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage
             {
             	if( activeFunction.size() > 1 )
             	{
-            		fstack.removeFrame();
             		activeFunction.pop();
-            		activeFunction.peek().loadFromStack( fstack );
+            		activeFunction.peek().loadFromStack( mem );
             	}
             	else
             	{

+ 0 - 12
src/animation/PseudoCodeNode.java

@@ -5,8 +5,6 @@ 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
@@ -72,10 +70,6 @@ public class PseudoCodeNode extends DefaultMutableTreeNode {
     
     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" );
-    	if( m.isDefined( "_func" + nodeId, false ) )
-    		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;
@@ -89,14 +83,8 @@ public class PseudoCodeNode extends DefaultMutableTreeNode {
     
     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" );
-    	if( !m.isDefined( "_func" + nodeId, false ) )
-    		throw new IllegalStateException( "variable _func" + nodeId + "should exist in current stack frame, but it is undefined" );
     	currentCodeLine = m.read( "_pos" + nodeId, false );
     	function = m.read( "_func" + nodeId, false );
-    	m.undeclare( "_pos" + nodeId, false );
-    	m.undeclare( "_func" + nodeId, false );
     	if( children == null )
     		return;
     	for( Object c : children )

+ 5 - 5
src/bk/BKNodePlacement.java

@@ -45,11 +45,11 @@ public class BKNodePlacement extends AnimatedAlgorithm {
         state = State.CONFLICTS;
         conftion = new ConflictDetection( this );
         layouts = new ExtremalLayoutCalc[ 4 ];
-        layouts[ 0 ] = new ExtremalLayoutCalc( graph, this );
-        layouts[ 1 ] = new ExtremalLayoutCalc( graph, this );
-        layouts[ 2 ] = new ExtremalLayoutCalc( graph, this );
-        layouts[ 3 ] = new ExtremalLayoutCalc( graph, this );
-        combine = new Combine( graph, this );
+        layouts[ 0 ] = new ExtremalLayoutCalc( this );
+        layouts[ 1 ] = new ExtremalLayoutCalc( this );
+        layouts[ 2 ] = new ExtremalLayoutCalc( this );
+        layouts[ 3 ] = new ExtremalLayoutCalc( this );
+        combine = new Combine( this );
     }
     
     public State getAlgorithmState()

+ 1 - 3
src/bk/BlockCalc.java

@@ -18,12 +18,10 @@ import lib.TextLayoutHelper;
  */
 public class BlockCalc implements AlgorithmStage {
 
-    private LayeredGraphNode graph;
     private AnimatedAlgorithm alg;
 
-    public BlockCalc( LayeredGraphNode graph, AnimatedAlgorithm alg  )
+    public BlockCalc( AnimatedAlgorithm alg  )
     {
-        this.graph = graph;
         this.alg = alg;
     }
 

+ 1 - 4
src/bk/Combine.java

@@ -8,7 +8,6 @@ import animation.CodeLine;
 import animation.ControlFlow;
 import animation.Memory;
 import animation.PseudoCodeNode;
-import graph.LayeredGraphNode;
 import lib.TextLayoutHelper;
 
 /**
@@ -18,12 +17,10 @@ import lib.TextLayoutHelper;
  */
 public class Combine implements AlgorithmStage {
 
-    private LayeredGraphNode graph;
     private AnimatedAlgorithm alg;
 
-    public Combine( LayeredGraphNode graph, AnimatedAlgorithm alg )
+    public Combine( AnimatedAlgorithm alg )
     {
-        this.graph = graph;
         this.alg = alg;
     }
 

+ 1 - 8
src/bk/Compaction.java

@@ -1,8 +1,5 @@
 package bk;
 
-import java.util.ArrayList;
-import java.util.Collections;
-
 import javax.swing.JTree;
 
 import animation.AlgorithmStage;
@@ -11,8 +8,6 @@ import animation.CodeLine;
 import animation.ControlFlow;
 import animation.Memory;
 import animation.PseudoCodeNode;
-import animation.PseudoCodeNode.CodeAction;
-import graph.LayeredGraphNode;
 import lib.TextLayoutHelper;
 
 /**
@@ -22,13 +17,11 @@ import lib.TextLayoutHelper;
  */
 public class Compaction implements AlgorithmStage{
 
-    private LayeredGraphNode graph;
     private AnimatedAlgorithm alg;
 
 
-    public Compaction( LayeredGraphNode graph, AnimatedAlgorithm alg )
+    public Compaction( AnimatedAlgorithm alg )
     {
-        this.graph = graph;
         this.alg = alg;
     }
 

+ 1 - 4
src/bk/ExtremalLayoutCalc.java

@@ -8,7 +8,6 @@ import animation.CodeLine;
 import animation.ControlFlow;
 import animation.Memory;
 import animation.PseudoCodeNode;
-import graph.LayeredGraphNode;
 import lib.TextLayoutHelper;
 
 /**
@@ -32,12 +31,10 @@ public class ExtremalLayoutCalc implements AlgorithmStage {
         COMBINED
     }
 	
-    private LayeredGraphNode graph;
     private AnimatedAlgorithm alg;
 
-    public ExtremalLayoutCalc( LayeredGraphNode graph, AnimatedAlgorithm alg )
+    public ExtremalLayoutCalc( AnimatedAlgorithm alg )
     {
-        this.graph = graph;
         this.alg = alg;
     }