fix parsing bug where BenkoBox is used instead of Destination
authoradam <adam@megacz.com>
Wed, 28 Feb 2007 11:01:50 +0000 (12:01 +0100)
committeradam <adam@megacz.com>
Wed, 28 Feb 2007 11:01:50 +0000 (12:01 +0100)
src/edu/berkeley/fleet/assembler/Parser.java
src/edu/berkeley/fleet/slipway/Slipway.java
src/edu/berkeley/fleet/slipway/SlipwayBenkoBox.java

index 1ca71d8..629bb44 100644 (file)
@@ -161,20 +161,36 @@ public class Parser {
         String subPort = t.size()<3 ? null : name(t.child(2));
         Ship ship = shipMap.get(shipName);
         if (ship==null) throw new RuntimeException("no such ship \""+shipName+"\"");
-        BenkoBox ret = null;
+        Destination ret = null;
+        BenkoBox bb = null;
         for(BenkoBox b : ship.getBenkoBoxes())
             if (b.getName().equals(portName)) {
-                ret = b;
+                bb = b;
             }
-        if (subPort != null)
-            for(Destination d : ret.getDestinations())
-                if (d.getDestinationName().equals(subPort))
-                    return d;
+        if (bb==null)
+            throw new RuntimeException("no such benkobox \""+portName+"\"");
+        if (subPort==null) subPort="";
+        for(Destination d : bb.getDestinations())
+            if (d.getDestinationName().equals(subPort))
+                return d;
         if (ret==null)
             throw new RuntimeException("no such benkobox \""+portName+"\" on ships of type \""+ship.getType()+"\"");
         return ret;
     }
 
+    BenkoBox benkoBox(Tree<String> t) {
+        if (!"Port".equals(t.head()) && !"SubPort".equals(t.head()) && !"ShipSpecificLiteral".equals(t.head())) return null;
+        String shipName = name(t.child(0));
+        String portName = name(t.child(1));
+        Ship ship = shipMap.get(shipName);
+        if (ship==null) throw new RuntimeException("no such ship \""+shipName+"\"");
+        BenkoBox bb = null;
+        for(BenkoBox b : ship.getBenkoBoxes())
+            if (b.getName().equals(portName))
+                return b;
+        throw new RuntimeException("no such benkobox \""+portName+"\"");
+    }
+
     private HashMap<String,Integer> numAllocated = new HashMap<String,Integer>();
 
     Ship allocateShip(String shipType) {
@@ -224,7 +240,7 @@ public class Parser {
             cb.add(new Instruction.Literal.CodeBagDescriptor(portReference(t.child(1)), cb2.getFakeAddress(), 0));
 
         } else if (t.head().equals("Fiber")) {
-            BenkoBox benkobox = (BenkoBox)portReference(t.child(0));
+            BenkoBox benkobox = (BenkoBox)benkoBox(t.child(0));
             
             OUTER: for(Tree tt : t.child(1)) {
                 int count = 1;
index 1de2f01..bd7d781 100644 (file)
@@ -434,13 +434,10 @@ public class Slipway extends Fleet {
         public long getBoxInstAddr(BenkoBox box) { return ((SlipwayBenkoBox)box).instr_addr; }
         public Destination getDestByAddr(long dest) {
             for(Ship ship : Slipway.this)
-                for(BenkoBox bb : ship.getBenkoBoxes()) {
-                    if (((SlipwayBenkoBox)bb).addr == dest)
-                        return bb;
+                for(BenkoBox bb : ship.getBenkoBoxes())
                     for(Destination d : bb.getDestinations())
                         if (getDestAddr(d)==dest)
                             return d;
-                }
             return null;
         }
         public BenkoBox getBoxByInstAddr(long dest) {
index aa43e0b..a43a659 100644 (file)
@@ -48,10 +48,7 @@ public class SlipwayBenkoBox extends BenkoBox {
         String[] ports = new String[] { "" };
         this.ports = new Destination[ports.length];
         for(int i=0; i<ports.length; i++)
-            this.ports[i] =
-                ports[i].equals("")
-                ? this
-                : new VirtualPort(ports[i]);
+            this.ports[i] = new VirtualPort(ports[i]);
         ship.addBenkoBox(name, this);
     }