Thread: [Nice-commit] Nice/src/bossa/syntax TypeIdent.java,1.26,1.27 CustomConstructor.java,1.10,1.11 Constr
Brought to you by:
bonniot
From: <bo...@us...> - 2003-12-22 20:28:13
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv1721/src/bossa/syntax Modified Files: TypeIdent.java CustomConstructor.java Constraint.java Log Message: Handle custom constructors for classes with type parameters. Index: TypeIdent.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/TypeIdent.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** TypeIdent.java 9 Dec 2003 15:21:05 -0000 1.26 --- TypeIdent.java 22 Dec 2003 20:28:10 -0000 1.27 *************** *** 58,62 **** Monotype substitute(Map map) { ! Monotype res = (Monotype) map.get(this); if(res!=null) return res; --- 58,62 ---- Monotype substitute(Map map) { ! Monotype res = (Monotype) map.get(name.toString()); if(res!=null) return res; Index: CustomConstructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/CustomConstructor.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CustomConstructor.java 22 Dec 2003 01:30:59 -0000 1.10 --- CustomConstructor.java 22 Dec 2003 20:28:10 -0000 1.11 *************** *** 30,42 **** { public static CustomConstructor make ! (LocatedString className, FormalParameters params, Block body) { ! return new SourceCustomConstructor(className, params, body); } ! CustomConstructor(LocatedString className, FormalParameters params) { ! super(new LocatedString("<init>", className.location()), Constraint.True, ! returnType(className), params, Contract.noContract); } --- 30,44 ---- { public static CustomConstructor make ! (LocatedString className, Constraint cst, FormalParameters params, ! Block body) { ! return new SourceCustomConstructor(className, cst, params, body); } ! CustomConstructor(LocatedString className, Constraint cst, ! FormalParameters params) { ! super(new LocatedString("<init>", className.location()), cst, ! returnType(className, cst), params, Contract.noContract); } *************** *** 44,48 **** { super(new LocatedString("<init>", def.definition.location()), ! def.definition.classConstraint, returnType(def.definition), parameters, Contract.noContract); --- 46,51 ---- { super(new LocatedString("<init>", def.definition.location()), ! def.definition.classConstraint == null ? ! null : def.definition.classConstraint.shallowClone(), returnType(def.definition), parameters, Contract.noContract); *************** *** 64,70 **** } ! private static Monotype returnType(LocatedString className) { ! Monotype res = new TypeIdent(className); res.nullness = Monotype.sure; return res; --- 67,90 ---- } ! private static Monotype returnType(LocatedString className, Constraint cst) { ! TypeIdent classe = new TypeIdent(className); ! classe.nullness = Monotype.sure; ! ! if (cst == Constraint.True) ! return classe; ! ! TypeSymbol[] syms = cst.getBinderArray(); ! Monotype[] params = new Monotype[syms.length]; ! ! for (int i = 0; i < syms.length; i++) ! { ! if (! (syms[i] instanceof mlsub.typing.MonotypeVar)) ! User.error(classe, syms[i] + " is not a type"); ! params[i] = Monotype.create((MonotypeVar) syms[i]); ! } ! ! Monotype res = new MonotypeConstructor ! (classe, new TypeParameters(params), classe.location()); res.nullness = Monotype.sure; return res; *************** *** 99,106 **** static class SourceCustomConstructor extends CustomConstructor { ! SourceCustomConstructor(LocatedString className, FormalParameters params, ! Block body) { ! super(className, params); this.className = className; --- 119,126 ---- static class SourceCustomConstructor extends CustomConstructor { ! SourceCustomConstructor(LocatedString className, Constraint cst, ! FormalParameters params, Block body) { ! super(className, cst, params); this.className = className; *************** *** 169,172 **** --- 189,202 ---- } + private Map map(TypeSymbol[] source, mlsub.typing.Monotype[] destination) + { + Map res = new HashMap(source.length); + + for (int i = 0; i < source.length; i++) + res.put(source[i].toString(), Monotype.create(destination[i])); + + return res; + } + protected gnu.expr.Expression computeCode() { *************** *** 176,179 **** --- 206,218 ---- Gen.setMethodBody(lambda, body.generateCode()); classe.getClassExp().addMethod(lambda); + + // In the bytecode, we want to use the same type parameter names + // as the class definition, even if the source of this custom constructor + // renamed them locally. + mlsub.typing.Constraint cst = getType().getConstraint(); + if (mlsub.typing.Constraint.hasBinders(cst)) + parameters.substitute + (map(cst.binders(), classe.definition.getTypeParameters())); + lambda.addBytecodeAttribute(parameters.asBytecodeAttribute()); initializationCode = Index: Constraint.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Constraint.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** Constraint.java 15 Nov 2003 17:25:47 -0000 1.37 --- Constraint.java 22 Dec 2003 20:28:10 -0000 1.38 *************** *** 93,97 **** * The lists are new, but the list elements are the same. */ ! private Constraint shallowClone() { return new Constraint(cloneList(binders), --- 93,97 ---- * The lists are new, but the list elements are the same. */ ! Constraint shallowClone() { return new Constraint(cloneList(binders), |