Parcourir la source

added option to read in the complete stack

Kolja Strohm il y a 6 ans
Parent
commit
3539d579f4
2 fichiers modifiés avec 25 ajouts et 6 suppressions
  1. 22 3
      src/animation/Memory.java
  2. 3 3
      src/bk/BKNodePlacement.java

+ 22 - 3
src/animation/Memory.java

@@ -9,7 +9,8 @@ public class Memory {
     public enum MemoryType
     {
         GLOBAL,
-        LOCAL
+        LOCAL,
+        COMPLETE_STACK
     }
     
     public class ReadOnlyMemory
@@ -67,6 +68,7 @@ public class Memory {
         case GLOBAL:
             this.global.declare( name, value );
             break;
+        case COMPLETE_STACK:
         case LOCAL:
         	if( stack.size() == 0 )
         		return;
@@ -82,6 +84,7 @@ public class Memory {
         case GLOBAL:
             this.global.set( name, value );
             break;
+        case COMPLETE_STACK:
         case LOCAL:
         	int index = stack.size() - 1;
         	while( index >= 0 ) {
@@ -99,12 +102,12 @@ public class Memory {
     
     public <T> T read( String name, MemoryType type )
     {
+        int index = stack.size() - 1;
         switch( type )
         {
         case GLOBAL:
             return this.global.get( name );
         case LOCAL:
-            int index = stack.size() - 1;
             while( index >= 0 ) {
                 StackFrame stackF = stack.get( index-- );
                 if( stackF.isDefined( name ) )
@@ -112,18 +115,25 @@ public class Memory {
                 if( stackF.getType() == FrameType.FUNCTION )
                     break;
              }
+            break;
+        case COMPLETE_STACK:
+            while( index >= 0 ) {
+                StackFrame stackF = stack.get( index-- );
+                if( stackF.isDefined( name ) )
+                    return stackF.get( name );
+             }
         }
         return null;
     }
     
     public boolean isSomewhereDefined( String name, MemoryType type )
     {
+        int index = stack.size() - 1;
         switch( type )
         {
         case GLOBAL:
             return this.global.isDefined( name );
         case LOCAL:
-            int index = stack.size() - 1;
             while( index >= 0 ) {
                 StackFrame stackF = stack.get( index-- );
                 if( stackF.isDefined( name ) )
@@ -131,6 +141,13 @@ public class Memory {
                 if( stackF.getType() == FrameType.FUNCTION )
                     break;
              }
+            break;
+        case COMPLETE_STACK:
+            while( index >= 0 ) {
+                StackFrame stackF = stack.get( index-- );
+                if( stackF.isDefined( name ) )
+                    return true;
+             }
         }
     	return false;
     }
@@ -141,6 +158,7 @@ public class Memory {
         {
         case GLOBAL:
             return this.global.isDefined( name );
+        case COMPLETE_STACK:
         case LOCAL:
             if( stack.size() == 0 )
                 return false;
@@ -156,6 +174,7 @@ public class Memory {
         case GLOBAL:
             this.global.undeclare( name );
             break;
+        case COMPLETE_STACK:
         case LOCAL:
         	if( stack.size() == 0 )
         		return;

+ 3 - 3
src/bk/BKNodePlacement.java

@@ -159,12 +159,12 @@ public class BKNodePlacement extends AnimatedAlgorithm {
         PseudoCodeNode extremalLayoutStage = new PseudoCodeNode( "-- Compute an extremal layout --", vars, tree, new Comment() ) {
             @Override
             public String getDebugOutput( Memory m ) {
-                if( !m.isDefined( "graph", MemoryType.LOCAL ) || !m.isDefined( "layout", MemoryType.LOCAL ) )
+                if( !m.isSomewhereDefined( "graph", MemoryType.COMPLETE_STACK ) || !m.isSomewhereDefined( "layout", MemoryType.COMPLETE_STACK ) )
                     return "";
                 String info = "| Node | Shift | Sink | Root | Align |  x  |  xDef  |\n";
                 info +=       "|------|-------|------|------|-------|-----|--------|\n";
-                LayeredGraphNode graph = m.read( "graph", MemoryType.LOCAL );
-                LayoutType type = LayoutType.fromString( m.read( "layout", MemoryType.LOCAL ) );
+                LayeredGraphNode graph = m.read( "graph", MemoryType.COMPLETE_STACK );
+                LayoutType type = LayoutType.fromString( m.read( "layout", MemoryType.COMPLETE_STACK ) );
                 for( LayeredGraphNode n : graph.getContainedNodes() )
                 {
                     info += "|" + TextLayoutHelper.strToLen( n.getName(), 6 ) +