浏览代码

removed some errors

Kolja Strohm 6 年之前
父节点
当前提交
b4a1cc2957
共有 4 个文件被更改,包括 26 次插入19 次删除
  1. 10 10
      src/animation/Memory.java
  2. 1 1
      src/bk/Compaction.java
  3. 6 5
      src/bk/PlaceBlock.java
  4. 9 3
      src/view/PseudoCodeRenderer.java

+ 10 - 10
src/animation/Memory.java

@@ -41,27 +41,27 @@ public class Memory {
         global = new StackFrame( FrameType.FUNCTION );
         global = new StackFrame( FrameType.FUNCTION );
     }
     }
     
     
-    public ReadOnlyMemory createReadOnlyMemory()
+    public synchronized ReadOnlyMemory createReadOnlyMemory()
     {
     {
         return new ReadOnlyMemory();
         return new ReadOnlyMemory();
     }
     }
     
     
-    public int getSize() 
+    public synchronized int getSize() 
     {
     {
         return stack.size();
         return stack.size();
     }
     }
     
     
-    public void addFrame( StackFrame frame )
+    public synchronized void addFrame( StackFrame frame )
     {
     {
         stack.push( frame );
         stack.push( frame );
     }
     }
     
     
-    public StackFrame removeFrame()
+    public synchronized StackFrame removeFrame()
     {
     {
         return stack.pop();
         return stack.pop();
     }
     }
     
     
-    public <T> void declare( String name, T value, MemoryType type )
+    public synchronized <T> void declare( String name, T value, MemoryType type )
     {
     {
         switch( type )
         switch( type )
         {
         {
@@ -77,7 +77,7 @@ public class Memory {
         }
         }
     }
     }
     
     
-    public <T> void write( String name, T value, MemoryType type )
+    public synchronized <T> void write( String name, T value, MemoryType type )
     {
     {
         switch( type )
         switch( type )
         {
         {
@@ -100,7 +100,7 @@ public class Memory {
         }
         }
     }
     }
     
     
-    public <T> T read( String name, MemoryType type )
+    public synchronized <T> T read( String name, MemoryType type )
     {
     {
         int index = stack.size() - 1;
         int index = stack.size() - 1;
         switch( type )
         switch( type )
@@ -126,7 +126,7 @@ public class Memory {
         return null;
         return null;
     }
     }
     
     
-    public boolean isSomewhereDefined( String name, MemoryType type )
+    public synchronized boolean isSomewhereDefined( String name, MemoryType type )
     {
     {
         int index = stack.size() - 1;
         int index = stack.size() - 1;
         switch( type )
         switch( type )
@@ -152,7 +152,7 @@ public class Memory {
     	return false;
     	return false;
     }
     }
     
     
-    public boolean isDefined( String name, MemoryType type )
+    public synchronized boolean isDefined( String name, MemoryType type )
     {
     {
         switch( type )
         switch( type )
         {
         {
@@ -167,7 +167,7 @@ public class Memory {
     	return false;
     	return false;
     }
     }
     
     
-    public void undeclare( String name, MemoryType type )
+    public synchronized void undeclare( String name, MemoryType type )
     {
     {
         switch( type )
         switch( type )
         {
         {

+ 1 - 1
src/bk/Compaction.java

@@ -99,7 +99,7 @@ public class Compaction {
             }
             }
         });
         });
         nodeLoop.add( ifRoot );
         nodeLoop.add( ifRoot );
-        ifRoot.add( new PseudoCodeNode( "call place_block(v);", vars, tree, new FunctionCall( placeBlock, new String[]{ "v" } ) ) );
+        ifRoot.add( new PseudoCodeNode( "call place_block(v, layout);", vars, tree, new FunctionCall( placeBlock, new String[]{ "v", "layout" } ) ) );
         PseudoCodeNode secondLoop = new PseudoCodeNode( "for i=layout.contains('DOWN') ? 0 : |L|-1 to layout.contains('DOWN') ? |L|-1 : 0 do", vars, tree, new AbstractForLoop<Integer>( "i" ) {
         PseudoCodeNode secondLoop = new PseudoCodeNode( "for i=layout.contains('DOWN') ? 0 : |L|-1 to layout.contains('DOWN') ? |L|-1 : 0 do", vars, tree, new AbstractForLoop<Integer>( "i" ) {
             @Override
             @Override
             protected Integer begin(ReadOnlyMemory m) {
             protected Integer begin(ReadOnlyMemory m) {

+ 6 - 5
src/bk/PlaceBlock.java

@@ -8,6 +8,7 @@ import animation.Memory;
 import animation.Memory.MemoryType;
 import animation.Memory.MemoryType;
 import animation.Memory.ReadOnlyMemory;
 import animation.Memory.ReadOnlyMemory;
 import animation.PseudoCodeNode;
 import animation.PseudoCodeNode;
+import codelines.DeclareVariable;
 import codelines.FunctionCall;
 import codelines.FunctionCall;
 import codelines.FunctionDefinition;
 import codelines.FunctionDefinition;
 import codelines.IfLoop;
 import codelines.IfLoop;
@@ -30,16 +31,16 @@ public class PlaceBlock{
             public String getDebugOutput( Memory m )
             public String getDebugOutput( Memory m )
             {
             {
                 if( m.isSomewhereDefined( "v", MemoryType.LOCAL ) && !m.isSomewhereDefined( "w", MemoryType.LOCAL ) )
                 if( m.isSomewhereDefined( "v", MemoryType.LOCAL ) && !m.isSomewhereDefined( "w", MemoryType.LOCAL ) )
-                    m.<LayeredGraphNode>read( "v", MemoryType.LOCAL).setSelected( LayoutType.fromString( m.read( "layout", MemoryType.LOCAL ) ) );
+                    m.<LayeredGraphNode>read( "v", MemoryType.LOCAL ).setSelected( LayoutType.fromString( m.read( "layout", MemoryType.LOCAL ) ) );
                 if( m.isSomewhereDefined( "w", MemoryType.LOCAL ) )
                 if( m.isSomewhereDefined( "w", MemoryType.LOCAL ) )
-                    m.<LayeredGraphNode>read( "w", MemoryType.LOCAL).setSelected( LayoutType.fromString( m.read( "layout", MemoryType.LOCAL ) ) );
+                    m.<LayeredGraphNode>read( "w", MemoryType.LOCAL ).setSelected( LayoutType.fromString( m.read( "layout", MemoryType.LOCAL ) ) );
                 return super.getDebugOutput( m );
                 return super.getDebugOutput( m );
             }
             }
         };
         };
         PseudoCodeNode ifUndef = new PseudoCodeNode( "if x[v] == undefined then", vars, tree, new IfLoop() {
         PseudoCodeNode ifUndef = new PseudoCodeNode( "if x[v] == undefined then", vars, tree, new IfLoop() {
             @Override
             @Override
             protected boolean condition(ReadOnlyMemory m) {
             protected boolean condition(ReadOnlyMemory m) {
-                return m.<LayeredGraphNode>read( "v", MemoryType.LOCAL ).isXUndefined( m.read( "layout", MemoryType.LOCAL ) );
+                return m.<LayeredGraphNode>read( "v", MemoryType.LOCAL ).isXUndefined( LayoutType.fromString( m.read( "layout", MemoryType.LOCAL ) ) );
             }
             }
         });
         });
         root.add( ifUndef );
         root.add( ifUndef );
@@ -81,7 +82,7 @@ public class PlaceBlock{
             }
             }
         });
         });
         whilewv.add( ifPos );
         whilewv.add( ifPos );
-        ifPos.add( new PseudoCodeNode( "u = layout.contains('RIGHT') ? root[fore(w)] : root[foll(w)];", vars, tree, new SetVariable<LayeredGraphNode>( "w" ) {
+        ifPos.add( new PseudoCodeNode( "u = layout.contains('RIGHT') ? root[fore(w)] : root[foll(w)];", vars, tree, new DeclareVariable<LayeredGraphNode>( "u" ){
             @Override
             @Override
             protected LayeredGraphNode value(ReadOnlyMemory m) {
             protected LayeredGraphNode value(ReadOnlyMemory m) {
                 LayeredGraphNode w = m.read( "w", MemoryType.LOCAL );
                 LayeredGraphNode w = m.read( "w", MemoryType.LOCAL );
@@ -90,7 +91,7 @@ public class PlaceBlock{
                     return graph.getContainedLayers().get( w.getLayer() ).get( graph.getContainedLayers().get( w.getLayer() ).indexOf( w ) - 1 );
                     return graph.getContainedLayers().get( w.getLayer() ).get( graph.getContainedLayers().get( w.getLayer() ).indexOf( w ) - 1 );
                 return graph.getContainedLayers().get( w.getLayer() ).get( graph.getContainedLayers().get( w.getLayer() ).indexOf( w ) + 1 );
                 return graph.getContainedLayers().get( w.getLayer() ).get( graph.getContainedLayers().get( w.getLayer() ).indexOf( w ) + 1 );
             }
             }
-        }));
+        } ));
         ifPos.add( new PseudoCodeNode( "call place_block( u, layout );", vars, tree, new FunctionCall( root, new String[]{ "u", "layout" } ) ) );
         ifPos.add( new PseudoCodeNode( "call place_block( u, layout );", vars, tree, new FunctionCall( root, new String[]{ "u", "layout" } ) ) );
         ifPos.add( new PseudoCodeNode( "sink[v] = sink[v] == v ? sink[u] : sink[v];", vars, tree, new CodeLine() {
         ifPos.add( new PseudoCodeNode( "sink[v] = sink[v] == v ? sink[u] : sink[v];", vars, tree, new CodeLine() {
             @Override
             @Override

+ 9 - 3
src/view/PseudoCodeRenderer.java

@@ -75,10 +75,16 @@ public class PseudoCodeRenderer extends DefaultTreeCellRenderer {
         toolTip = "<html>";
         toolTip = "<html>";
         for( String var : TextLayoutHelper.getVariables( (String)node.getUserObject() ) )
         for( String var : TextLayoutHelper.getVariables( (String)node.getUserObject() ) )
         {
         {
-            if( mem != null && mem.isSomewhereDefined( var, MemoryType.LOCAL ) )
+            if( mem != null )
             {
             {
-                Object val = mem.read( var, MemoryType.LOCAL );
-                toolTip += var + "=" + val.toString() + "<br>";
+                synchronized( mem ) {
+                    if( mem.isSomewhereDefined( var, MemoryType.LOCAL ) )
+                    {
+                        Object val = mem.read( var, MemoryType.LOCAL );
+                        if( val != null )
+                            toolTip += var + "=" + val.toString() + "<br>";
+                    }
+                }
             }
             }
         }
         }
         if( toolTip.equals( "<html>" ) )
         if( toolTip.equals( "<html>" ) )