|
@@ -0,0 +1,86 @@
|
|
|
|
+package test;
|
|
|
|
+
|
|
|
|
+import javax.swing.JFrame;
|
|
|
|
+
|
|
|
|
+import graph.LayeredGraphNode;
|
|
|
|
+import processor.PseudoCodeNode;
|
|
|
|
+import processor.PseudoCodeProcessor;
|
|
|
|
+
|
|
|
|
+public class StepOverProcessor extends PseudoCodeProcessor {
|
|
|
|
+
|
|
|
|
+ public StepOverProcessor(PseudoCodeNode start, LayeredGraphNode graph, JFrame view) {
|
|
|
|
+ super(start, graph, view);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private CodeStatus doStepForward()
|
|
|
|
+ {
|
|
|
|
+ PseudoCodeNode oldPP = programPointer;
|
|
|
|
+ if( programPointer.getChildCount() > 0 ) {
|
|
|
|
+ if( forwardStep() == CodeStatus.FINISHED )
|
|
|
|
+ return CodeStatus.FINISHED;
|
|
|
|
+ while( oldPP != programPointer && oldPP.isNodeChild( programPointer ) )
|
|
|
|
+ doStepForward();
|
|
|
|
+ if( backwardStepOver() == CodeStatus.FINISHED )
|
|
|
|
+ return CodeStatus.FINISHED;
|
|
|
|
+ return forwardStepOver();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ return forwardStepOver();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private CodeStatus doStepBackward()
|
|
|
|
+ {
|
|
|
|
+ if( controlStack.isEmpty() )
|
|
|
|
+ return CodeStatus.FINISHED;
|
|
|
|
+ PseudoCodeNode oldPP = getLastProgramPointer();
|
|
|
|
+ if( oldPP.getChildCount() > 0 ) {
|
|
|
|
+ if( backwardStep() == CodeStatus.FINISHED )
|
|
|
|
+ return CodeStatus.FINISHED;
|
|
|
|
+ while( oldPP != getLastProgramPointer() && getLastProgramPointer() != null && oldPP.isNodeChild( getLastProgramPointer() ) )
|
|
|
|
+ doStepBackward();
|
|
|
|
+ if( forwardStepOver() == CodeStatus.FINISHED )
|
|
|
|
+ return CodeStatus.FINISHED;
|
|
|
|
+ return backwardStepOver();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ return backwardStepOver();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void run()
|
|
|
|
+ {
|
|
|
|
+ while( true )
|
|
|
|
+ {
|
|
|
|
+ CodeStatus status = null;
|
|
|
|
+ try {
|
|
|
|
+ status = doStepForward();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if( status == CodeStatus.FINISHED )
|
|
|
|
+ {
|
|
|
|
+ System.out.println( "Step Over works in forward direction.");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println( controlStack.size() + " Actions done.");
|
|
|
|
+ while( true )
|
|
|
|
+ {
|
|
|
|
+ CodeStatus status = null;
|
|
|
|
+ try {
|
|
|
|
+ status = doStepBackward();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if( status == CodeStatus.FINISHED )
|
|
|
|
+ {
|
|
|
|
+ System.out.println( "Step Over works in backward direction.");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if( !controlStack.isEmpty() )
|
|
|
|
+ throw new IllegalStateException( "There are too manny Objects in the control Stack." );
|
|
|
|
+ }
|
|
|
|
+}
|