ソースを参照

removed the wrong loop behavior for loops

Kolja Strohm 6 年 前
コミット
f6c235b656

+ 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

@@ -28,7 +28,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
 		}
@@ -48,9 +47,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

@@ -26,7 +26,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
 		}
@@ -46,9 +45,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 );

+ 28 - 1
src/test/StepInProcessor.java

@@ -21,6 +21,11 @@ public class StepInProcessor extends PseudoCodeProcessor{
             try {
                 status = forwardStep();
                 forwardStep();
+                if( status == CodeStatus.FINISHED )
+                {
+                    System.out.println( "Step Into works in forward direction.");
+                    break;
+                }
                 backwardStep();
             } catch (Exception e) {
                 e.printStackTrace();
@@ -28,9 +33,31 @@ public class StepInProcessor extends PseudoCodeProcessor{
             }
             if( status == CodeStatus.FINISHED )
             {
-                System.out.println( "Step Into works in both directions.");
+                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;
+            }
         }
     }
 }