Procházet zdrojové kódy

Merge remote-tracking branch 'origin/BetterStructure' into BetterStructure

Eren Yilmaz před 6 roky
rodič
revize
3c3665014a

+ 2 - 2
src/animation/PseudoCodeProcessor.java

@@ -75,8 +75,8 @@ public class PseudoCodeProcessor {
                     mem.undeclare( "_returnTo" + programPointer.getId(), MemoryType.LOCAL );
                 });
             }
-            if( programPointer.children() == null )
-                throw new IllegalStateException( "A Codeline without sublines tried to make a STEP_INTO." );
+            if( programPointer.getChildCount() == 0 )
+                throw new IllegalStateException( "A Codeline without sublines tryd to make a STEP_INTO." );
             else
                 return selectNextNode( (PseudoCodeNode)programPointer.getFirstChild(), programPointer );
         case ControlFlow.STEP_OVER:

+ 1 - 1
src/bk/BKNodePlacement.java

@@ -118,7 +118,7 @@ public class BKNodePlacement extends AnimatedAlgorithm {
         mainFunction.add( new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "call combine( graph )", vars ), tree, new FunctionCall( combine, new String[]{ "graph" } ) ) );
         root.add( new PseudoCodeNode( TextLayoutHelper.setupPseudoCodeStage( "-- mark type 1 conflicts --" ), tree, new Comment() ) );
         root.add( conflictDetectionFunction );
-        PseudoCodeNode blockCalc = new BlockCalc().createPseudocodeTree( tree );
+        PseudoCodeNode blockCalc = new BlockCalc( this ).createPseudocodeTree( tree );
         PseudoCodeNode horizontalCompaction = new Compaction().createPseudocodeTree( tree );
         calcLayout.add( new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "call calculateBlockGraph( layout, graph )", vars ), tree, new FunctionCall( blockCalc, vars ) ) );
         calcLayout.add( new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "call horizontalCompaction( layout, graph )", vars ), tree, new FunctionCall( horizontalCompaction, vars ) ) );

+ 47 - 1
src/bk/BlockCalc.java

@@ -12,6 +12,7 @@ import animation.Memory;
 import animation.PseudoCodeNode;
 import animation.Memory.MemoryType;
 import animation.Memory.ReadOnlyMemory;
+import bk.BKNodePlacement.State;
 import codelines.AbstractForLoop;
 import codelines.DeclareVariable;
 import codelines.ForEachLoop;
@@ -29,10 +30,55 @@ import lib.TextLayoutHelper;
  */
 public class BlockCalc implements AlgorithmStage {
 
+    BKNodePlacement alg;
+    
+    public BlockCalc( BKNodePlacement a )
+    {
+        alg = a;
+    }
+    
     @Override
     public PseudoCodeNode createPseudocodeTree( JTree tree ) {
         String[] vars = { "graph", "L", "r", "neighbors", "layout", "m", "i", "k", "mids" };
-        PseudoCodeNode root = new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "function calculateBlockGraph( layout, graph )", vars ), tree, new FunctionDefinition( new String[]{ "layout", "graph" } ) );
+        @SuppressWarnings("serial")
+        PseudoCodeNode root = new PseudoCodeNode( TextLayoutHelper.setupPseudoCode( "function calculateBlockGraph( layout, graph )", vars ), tree, new FunctionDefinition( new String[]{ "layout", "graph" } ) ) {
+            @Override
+            public String getDebugOutput( Memory m )
+            {
+                switch( m.<String>read( "layout", MemoryType.LOCAL ) )
+                {
+                case "DOWN_RIGHT":
+                    alg.setAlgorithmState( State.LAYOUT1 );
+                    break;
+                case "DOWN_LEFT":
+                    alg.setAlgorithmState( State.LAYOUT2 );
+                    break;
+                case "UP_RIGHT":
+                    alg.setAlgorithmState( State.LAYOUT3 );
+                    break;
+                case "UP_LEFT":
+                    alg.setAlgorithmState( State.LAYOUT4 );
+                    break;
+                }
+                if( m.isSomewhereDefined( "i", MemoryType.LOCAL ) && m.isSomewhereDefined( "k", MemoryType.LOCAL ) )
+                    m.<LayeredGraphNode>read( "graph", MemoryType.LOCAL).getContainedLayers().get(m.read( "i", MemoryType.LOCAL )).get(m.<Integer>read( "k", MemoryType.LOCAL ) ).setSelected( LayoutType.fromString( m.read( "layout", MemoryType.LOCAL ) ) );
+                String info = "| Node | Shift | Sink | Root | Align |  x  |  xDef  |\n";
+                info +=       "|------|-------|------|------|-------|-----|--------|\n";
+                LayeredGraphNode graph = m.read( "graph", MemoryType.LOCAL );
+                LayoutType layout = LayoutType.fromString( m.read( "layout", MemoryType.LOCAL ) );
+                for( LayeredGraphNode n : graph.getContainedNodes() )
+                {
+                    info += "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) + 
+                            "|" + TextLayoutHelper.strToLen( n.getShift( layout ) + "", 7 ) + 
+                            "|" + TextLayoutHelper.strToLen( n.getSink( layout ).getName(), 6 ) + 
+                            "|" + TextLayoutHelper.strToLen( n.getRoot( layout ).getName(), 6 ) + 
+                            "|" + TextLayoutHelper.strToLen( n.getAlign( layout ).getName(), 7 ) + 
+                            "|" + TextLayoutHelper.strToLen( n.getX( layout ) + "", 5 ) + 
+                            "|" + TextLayoutHelper.strToLen( !n.isXUndefined( layout ) + "", 8 ) + "|\n";
+                }
+                return info;
+            }
+        };
         root.add( new PseudoCodeNode(TextLayoutHelper.setupPseudoCode( "L = graph.getContainedLayers();", vars), tree, new DeclareVariable<ArrayList<ArrayList<LayeredGraphNode>>>( "L" ) {
             @Override
             protected ArrayList<ArrayList<LayeredGraphNode>> value(ReadOnlyMemory m) {