implement am26 support for constants
[fleet.git] / src / edu / berkeley / fleet / doc / BenkoBoxDescription.java
1 package edu.berkeley.fleet.doc;
2
3 import java.io.*;
4 import java.util.*;
5
6 public class BenkoBoxDescription implements Iterable<String> {
7
8     public String getName() { return name; }
9     public boolean isInbox() { return inbox; }
10     public boolean isOutbox() { return !inbox; }
11     public boolean tokensOnly() { return tokenOnly; }
12     public String  getShortcut() { return shortcut; }
13     public Iterator<String> iterator() { return destinations.iterator(); }
14
15     // private //////////////////////////////////////////////////////////////////////////////
16
17     private final ShipDescription ship;
18     private final String shortcut;
19     private final String name;
20     private final boolean inbox;
21     private final boolean tokenOnly;
22     private ArrayList<String> destinations = new ArrayList<String>();
23
24     // FIXME
25     public HashMap<String,Constant> constants = new HashMap<String,Constant>();
26
27     BenkoBoxDescription(ShipDescription ship, String name, boolean tokenOnly, boolean inbox) {
28         this(ship, name, tokenOnly, inbox, null);
29     }
30     BenkoBoxDescription(ShipDescription ship, String name, boolean tokenOnly, boolean inbox, String shortcut) {
31         this.ship = ship;
32         this.name = name;
33         this.inbox = inbox;
34         this.tokenOnly = tokenOnly;
35         this.shortcut = shortcut;
36         ship.add(this);
37     }
38
39     void addDest(String dest) { destinations.add(dest); }
40
41     public Constant getConstant(String name) {
42         Constant ret = constants.get(name);
43         if (ret == null) ret = ship.getConstant(name);
44         return ret;
45     }
46
47     public long resolveLiteral(String s) {
48         long val = 0;
49         long ret = 0;
50         if (s.indexOf('=') != -1) {
51             val = Long.parseLong(s.substring(s.indexOf('=')+1));
52             s = s.substring(0, s.indexOf('='));
53         }
54         Constant c = getConstant(s);
55         if (c==null) throw new RuntimeException("no constant " + s + " on benkobox " + this);
56         ret |= c.setbits;
57         ret &= ~c.clearbits;
58         // FIXME: val
59         return ret;
60     }
61 }