Bläddra i källkod

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/processor/PseudoCodeProcessor.java
Eren Yilmaz 6 år sedan
förälder
incheckning
942f6f8cbc

+ 2 - 1
src/bk/PlaceBlock.java

@@ -188,7 +188,8 @@ public class PlaceBlock{
         for( LayeredGraphNode n : graph.getContainedNodes() )
         {
             NodeView v = ((LayeredNode)n).getView( layout );
-            max = Math.max( max, v.getOriginalWidth() );
+            if( v != null )
+                max = Math.max( max, v.getOriginalWidth() );
         }
         return max + 20;
     }

+ 6 - 2
src/codeline/AbstractForLoop.java

@@ -24,18 +24,22 @@ public abstract class AbstractForLoop<T> extends CodeLine {
     
     @Override
     public ControlFlow runForward(Memory m) {
-        if( !m.isDefined( loopVar, Visibility.LOCAL ) )
+        if( !m.isSomewhereDefined( "line_" + lineId + "_index", Visibility.LOCAL ) )
         { // first loop step
+            m.declare( "line_" + lineId + "_index", 0, Visibility.LOCAL );
             m.addFrame( new StackFrame( FrameType.LOOP ) );
             m.declare( loopVar, intialize( m.createReadOnlyMemory() ), Visibility.LOCAL ); // set loop variable
             if( !condition( m.createReadOnlyMemory() ) ) // prove if the loop has finished
             {
                 m.removeFrame();
-                actions.push( (Memory mem) -> {} );
+                actions.push( (Memory mem) -> {
+                    mem.undeclare( "line_" + lineId + "_index", Visibility.LOCAL );
+                    } );
                 return new ControlFlow( ControlFlow.STEP_OVER ); // don't execute the loop body
             }
             actions.push( (Memory mem) -> {
                 mem.removeFrame();
+                mem.undeclare( "line_" + lineId + "_index", Visibility.LOCAL );
             } );
             return new ControlFlow( ControlFlow.STEP_INTO );
         }

+ 1 - 3
src/codeline/ForEachLoop.java

@@ -34,7 +34,6 @@ public abstract class ForEachLoop <T> extends CodeLine {
 		}
 		if( m.<Integer>read( "line_" + lineId + "_index", Visibility.LOCAL ) > list( m.createReadOnlyMemory() ).size() - 1 ) // prove if the loop has finished
 		{
-			m.undeclare( "line_" + lineId + "_index", Visibility.LOCAL );
 			actions.push( (Memory mem) -> {});
 			return new ControlFlow( ControlFlow.STEP_OVER ); // don't execute the loop body
 		}
@@ -54,9 +53,8 @@ public abstract class ForEachLoop <T> extends CodeLine {
 			if( m.<Integer>read( "line_" + lineId + "_index", Visibility.LOCAL ) > list( m.createReadOnlyMemory() ).size() - 1 ) // prove if loop was finished
 			{
 				StackFrame sf = m.removeFrame(); // remove loop stack
-				m.undeclare( "line_" + lineId + "_index", Visibility.LOCAL );
 				actions.push( (Memory mem) -> {
-					mem.write( "line_" + lineId + "_index", oldIndex, Visibility.LOCAL );
+                    mem.write( "line_" + lineId + "_index", oldIndex, Visibility.LOCAL );
 					mem.addFrame( sf ); // restore last loop stack
 				});
 				return new ControlFlow( ControlFlow.STEP_OVER ); // step out of the loop

+ 0 - 4
src/codeline/ForLoop.java

@@ -31,7 +31,6 @@ public abstract class ForLoop extends CodeLine {
 		}
 		if( m.<Integer>read( "line_" + lineId + "_index", Visibility.LOCAL ) > maximum( m.createReadOnlyMemory() ) ) // prove if the loop has finished
 		{
-			m.undeclare( "line_" + lineId + "_index", Visibility.LOCAL );
 			actions.push( (Memory mem) -> {});
 			return new ControlFlow( ControlFlow.STEP_OVER ); // don't execute the loop body
 		}
@@ -51,9 +50,6 @@ public abstract class ForLoop extends CodeLine {
 			if( m.<Integer>read( "line_" + lineId + "_index", Visibility.LOCAL ) > maximum( m.createReadOnlyMemory() ) ) // prove if loop was finished
 			{
 				StackFrame sf = m.removeFrame(); // remove loop stack
-				m.undeclare( "line_" + lineId + "_index", Visibility.LOCAL );
-                //int old = m.read( loopVar, false );
-                //m.undeclare( loopVar, false );
 				actions.add( (Memory mem) -> {
 	                //m.declare( loopVar, old, false );
 					mem.write( "line_" + lineId + "_index", oldIndex, Visibility.LOCAL );

+ 6 - 6
src/processor/PseudoCodeProcessor.java

@@ -90,7 +90,7 @@ public class PseudoCodeProcessor extends Thread {
      * perform one forward step of the algorithm assigned to this processor
      * @return the status of execution after that step
      */
-    public CodeStatus forwardStep()
+    protected CodeStatus forwardStep()
     {
         if( programPointer == null )
             return CodeStatus.FINISHED;
@@ -173,7 +173,7 @@ public class PseudoCodeProcessor extends Thread {
         return status;
     }
     
-    private CodeStatus forwardStepOver()
+    protected CodeStatus forwardStepOver()
     {
         if( programPointer == null )
             return CodeStatus.FINISHED;
@@ -185,7 +185,7 @@ public class PseudoCodeProcessor extends Thread {
         return status;
     }
     
-    private CodeStatus forwardStepOut()
+    protected CodeStatus forwardStepOut()
     {
         if( programPointer == null )
             return CodeStatus.FINISHED;
@@ -216,7 +216,7 @@ public class PseudoCodeProcessor extends Thread {
         return CodeStatus.UNFINISHED;
     }
     
-    private CodeStatus backwardStep()
+    protected CodeStatus backwardStep()
     {
         if( programPointer == null || controlStack.isEmpty() )
             return CodeStatus.FINISHED;
@@ -241,7 +241,7 @@ public class PseudoCodeProcessor extends Thread {
         return status;
     }
     
-    private CodeStatus backwardStepOver()
+    protected CodeStatus backwardStepOver()
     {
         if( programPointer == null )
             return CodeStatus.FINISHED;
@@ -253,7 +253,7 @@ public class PseudoCodeProcessor extends Thread {
         return status;
     }
     
-    private CodeStatus backwardStepOut()
+    protected CodeStatus backwardStepOut()
     {
         if( programPointer == null )
             return CodeStatus.FINISHED;

+ 63 - 0
src/test/StepInProcessor.java

@@ -0,0 +1,63 @@
+package test;
+
+import javax.swing.JFrame;
+
+import graph.LayeredGraphNode;
+import processor.PseudoCodeNode;
+import processor.PseudoCodeProcessor;
+
+public class StepInProcessor extends PseudoCodeProcessor{
+
+    public StepInProcessor(PseudoCodeNode start, LayeredGraphNode graph, JFrame view) {
+        super(start, graph, view);
+    }
+    
+    @Override
+    public void run()
+    {
+        while( true )
+        {
+            CodeStatus status = null;
+            try {
+                status = forwardStep();
+                forwardStep();
+                if( status == CodeStatus.FINISHED )
+                {
+                    System.out.println( "Step Into works in forward direction.");
+                    break;
+                }
+                backwardStep();
+            } catch (Exception e) {
+                e.printStackTrace();
+                return;
+            }
+            if( status == CodeStatus.FINISHED )
+            {
+                System.out.println( "Step Into works in forward direction.");
+                break;
+            }
+        }
+        while( true )
+        {
+            CodeStatus status = null;
+            try {
+                status = backwardStep();
+                if( status == CodeStatus.FINISHED )
+                {
+                    System.out.println( "Step Into works in backward direction.");
+                    break;
+                }
+                backwardStep();
+                forwardStep();
+            } catch (Exception e) {
+                e.printStackTrace();
+                return;
+            }
+            if( status == CodeStatus.FINISHED )
+            {
+                System.out.println( "Step Into works in backward direction.");
+                break;
+            }
+        }
+    }
+}

+ 26 - 0
src/test/TestProcessor.java

@@ -0,0 +1,26 @@
+package test;
+
+import javax.swing.JFrame;
+import javax.swing.JTree;
+
+import bk.BKNodePlacement;
+import graph.LayeredGraphNode;
+import graph.io.Reader;
+import lib.SimpleNodePlacement;
+import processor.PseudoCodeNode;
+
+public class TestProcessor {
+    
+    public static void main(String[] args) {
+        Reader r = new Reader( "logo.json" );
+        LayeredGraphNode graph = r.readInputGraph();
+        SimpleNodePlacement.placeNodes( graph );
+
+        BKNodePlacement algorithm = new BKNodePlacement();
+        JTree pseudoTree = new JTree();
+        PseudoCodeNode tree = algorithm.createPseudocodeTree( pseudoTree );
+        JFrame frame = new JFrame( "NodeShuffler" );
+        StepInProcessor processor = new StepInProcessor( tree, graph, frame );
+        processor.start();
+    }
+}