1 package polyglot.ext.coffer.extension; 2 3 import polyglot.ast.*; 4 import polyglot.types.*; 5 import polyglot.util.*; 6 import polyglot.ext.jl.ast.*; 7 import polyglot.ext.coffer.ast.*; 8 import polyglot.ext.coffer.types.*; 9 10 import java.util.*; 11 12 public class CofferExt_c extends Ext_c implements CofferExt { 13 public String KeysToString(KeySet set) { 14 return "K" + eysToString(set); 15 } 16 17 public String keysToString(KeySet set) { 18 return "k" + eysToString(set); 19 } 20 21 private String eysToString(KeySet set) { 22 if (set.size() == 1) { 23 Key k = (Key) set.iterator().next(); 24 return "ey \"" + k + "\""; 25 } 26 else { 27 String s = "eys ["; 28 for (Iterator i = set.iterator(); i.hasNext(); ) { 29 s += "\"" + i.next() + "\""; 30 if (i.hasNext()) 31 s += ", "; 32 } 33 s += "]"; 34 return s; 35 } 36 } 37 38 public KeySet keyFlow(KeySet held_keys, Type throwType) { return held_keys; } 39 public KeySet keyAlias(KeySet stored_keys, Type throwType) { return stored_keys; } 40 41 public void checkHeldKeys(KeySet held, KeySet stored) throws SemanticException { 42 if (node() instanceof Expr) { 43 Expr e = (Expr) node(); 44 45 if (e.type() instanceof CofferClassType) { 46 Key key = ((CofferClassType) e.type()).key(); 47 48 if (key != null) { 49 if (! held.contains(key)) { 50 throw new SemanticException( 51 "Can evaluate expression of type \"" + 52 e.type() + "\" only if key \"" + key + 53 "\" is held.", e.position()); 54 } 55 if (stored.contains(key)) { 56 throw new SemanticException( 57 "Can evaluate expression of type \"" + 58 e.type() + "\" only if key \"" + key + 59 "\" is not held in a variable.", 60 e.position()); 61 } 62 } 63 } 64 } 65 } 66 } 67 | Popular Tags |