1 package polyglot.ext.param.types; 2 3 import polyglot.ext.jl.types.TypeSystem_c; 4 import polyglot.types.*; 5 import polyglot.util.*; 6 7 import java.util.*; 8 9 12 public abstract class ParamTypeSystem_c extends TypeSystem_c 13 implements ParamTypeSystem 14 { 15 20 public MuPClass mutablePClass(Position pos) { 21 return new MuPClass_c(this, pos); 22 } 23 24 33 public ClassType instantiate(Position pos, PClass base, List actuals) 34 throws SemanticException 35 { 36 checkInstantiation(pos, base, actuals); 37 return uncheckedInstantiate(pos, base, actuals); 38 } 39 40 50 protected void checkInstantiation(Position pos, PClass base, 51 List actuals) throws SemanticException 52 { 53 if (base.formals().size() != actuals.size()) { 54 throw new SemanticException("Wrong number of actual parameters " + 55 "for instantiation of \"" + 56 base + "\".", pos); 57 } 58 } 59 60 68 protected ClassType uncheckedInstantiate(Position pos, PClass base, 69 List actuals) 70 { 71 Map substMap = new HashMap(); 72 Iterator i = base.formals().iterator(); 73 Iterator j = actuals.iterator(); 74 75 while (i.hasNext() && j.hasNext()) { 76 Object formal = i.next(); 77 Object actual = j.next(); 78 substMap.put(formal, actual); 79 } 80 81 if (i.hasNext() || j.hasNext()) { 82 throw new InternalCompilerError("Wrong number of actual " + 83 "parameters for instantiation " + "of \"" + base + "\".", pos); 84 } 85 86 Type inst = subst(base.clazz(), substMap, new HashMap()); 87 if (!inst.isClass()) { 88 throw new InternalCompilerError("Instantiating a PClass " 89 + "produced something other than a ClassType.", pos); 90 } 91 92 return inst.toClass(); 93 } 94 95 102 public Type subst(Type t, Map substMap) { 103 return subst(t, substMap, new HashMap()); 104 } 105 106 116 public Type subst(Type t, Map substMap, Map cache) { 117 return subst(substMap, cache).substType(t); 118 } 119 120 129 public Subst subst(Map substMap, Map cache) { 130 return new Subst_c(this, substMap, cache); 131 } 132 } 133 | Popular Tags |