[Nice-commit] Nice/src/bossa/syntax NiceMethod.java,1.25,1.26 NiceClass.java,1.64,1.65 MethodContain
Brought to you by:
bonniot
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv860/src/bossa/syntax Modified Files: NiceMethod.java NiceClass.java MethodContainer.java Constraint.java ClassDefinition.java Log Message: Make the class constraint be a subtype of bossa.syntax.Constraint, which allows to reuse existing code for printing the constraint and get rid of the custom printing code in MethodContainer. Index: NiceMethod.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceMethod.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** NiceMethod.java 15 Nov 2003 13:02:15 -0000 1.25 --- NiceMethod.java 15 Nov 2003 17:25:47 -0000 1.26 *************** *** 79,88 **** constraint = new Constraint (new ArrayList(thisBindersLen + (hasAlike ? 1 : 0)), ! new ArrayList((hasAlike ? 1 : 0) + (thisConstraint == null ? 0 ! : thisConstraint.atoms.size()))); ! constraint.addBinders(thisBinders); if (thisConstraint != null) ! constraint.addAtoms(thisConstraint.atoms); mlsub.typing.Monotype thisType; --- 79,89 ---- constraint = new Constraint (new ArrayList(thisBindersLen + (hasAlike ? 1 : 0)), ! new ArrayList((hasAlike ? 1 : 0) + ! (thisConstraint == null ? 0 : ! thisConstraint.getAtoms().size()))); ! constraint.addBinders(thisBinders); if (thisConstraint != null) ! constraint.addAtoms(thisConstraint.getAtoms()); mlsub.typing.Monotype thisType; Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** NiceClass.java 15 Nov 2003 13:02:15 -0000 1.64 --- NiceClass.java 15 Nov 2003 17:25:47 -0000 1.65 *************** *** 595,598 **** --- 595,599 ---- { mlsub.typing.TypeSymbol[] binders = other.definition.getBinders(); + mlsub.typing.TypeSymbol[] ourBinders = definition.getBinders(); TypeScope scope = Node.getGlobalTypeScope(); Map map = null; *************** *** 602,606 **** for (int i = 0; i < binders.length; i++) try { ! scope.addMapping(definition.classConstraint.binders[i].toString(), binders[i]); } catch(TypeScope.DuplicateName e) {} } --- 603,607 ---- for (int i = 0; i < binders.length; i++) try { ! scope.addMapping(ourBinders[i].toString(), binders[i]); } catch(TypeScope.DuplicateName e) {} } *************** *** 628,635 **** scope = new TypeScope(scope); map = new HashMap(); for (int i = 0; i < binders.length; i++) try { ! scope.addMapping(definition.classConstraint.binders[i].toString(), binders[i]); ! map.put(definition.classConstraint.binders[i], binders[i]); } catch(TypeScope.DuplicateName e) {} } --- 629,637 ---- scope = new TypeScope(scope); map = new HashMap(); + TypeSymbol[] ourBinders = definition.getBinders(); for (int i = 0; i < binders.length; i++) try { ! scope.addMapping(ourBinders[i].toString(), binders[i]); ! map.put(ourBinders[i], binders[i]); } catch(TypeScope.DuplicateName e) {} } Index: MethodContainer.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodContainer.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** MethodContainer.java 15 Nov 2003 13:02:15 -0000 1.12 --- MethodContainer.java 15 Nov 2003 17:25:47 -0000 1.13 *************** *** 72,76 **** ****************************************************************/ ! public static class Constraint { /** --- 72,76 ---- ****************************************************************/ ! public static class Constraint extends bossa.syntax.Constraint { /** *************** *** 78,97 **** of this class. */ ! public Constraint(bossa.syntax.Constraint cst, MonotypeVar[] typeParameters, List atoms) { if (cst == bossa.syntax.Constraint.True || cst == null) { ! this.binders = typeParameters; ! this.typeParameters = typeParameters; ! this.atoms = atoms; } else { ! this.syntacticConstraint = cst.toString(); ! this.atoms = cst.getAtoms(); ! this.binders = (TypeSymbol[]) cst.getBinders(). ! toArray(new TypeSymbol[cst.getBinders().size()]); ! findBinders(typeParameters); } } --- 78,112 ---- of this class. */ ! public static Constraint make(bossa.syntax.Constraint cst, ! MonotypeVar[] typeParameters, List atoms) { + TypeSymbol[] binders; + List constraints; + boolean resolve; + if (cst == bossa.syntax.Constraint.True || cst == null) { ! binders = typeParameters; ! constraints = atoms; ! resolve = false; } else { ! constraints = cst.getAtoms(); ! binders = cst.getBinderArray(); ! resolve = true; } + + return new Constraint(binders, constraints, typeParameters, resolve); + } + + private Constraint (TypeSymbol[] binders, List atoms, + MonotypeVar[] typeParameters, boolean resolve) + { + super(binders, atoms); + if (resolve) + findBinders(typeParameters); + else + this.typeParameters = typeParameters; } *************** *** 111,125 **** private mlsub.typing.Monotype findBinder(MonotypeVar binder) { ! for (int i = 0; i < binders.length; i++) ! if (binders[i].toString().equals(binder.getName())) ! { ! if (binders[i] instanceof MonotypeVar) ! return (MonotypeVar) binders[i]; ! else ! // The type parameter must be in fact a type constructor ! // of variance zero. ! return new mlsub.typing.MonotypeConstructor ! ((TypeConstructor) binders[i], null); ! } // Not found. It was not introduced earlier, use it as the binder. --- 126,143 ---- private mlsub.typing.Monotype findBinder(MonotypeVar binder) { ! for (java.util.Iterator i = this.getBinders().iterator(); i.hasNext(); ) ! { ! TypeSymbol s = (TypeSymbol) i.next(); ! if (s.toString().equals(binder.getName())) ! { ! if (s instanceof MonotypeVar) ! return (MonotypeVar) s; ! else ! // The type parameter must be in fact a type constructor ! // of variance zero. ! return new mlsub.typing.MonotypeConstructor ! ((TypeConstructor) s, null); ! } ! } // Not found. It was not introduced earlier, use it as the binder. *************** *** 127,139 **** } - /** The binders of the constraint. */ - TypeSymbol[] binders; - /** The type parameters of the class. */ mlsub.typing.Monotype[] typeParameters; - - List atoms; - - String syntacticConstraint; } --- 145,150 ---- *************** *** 146,153 **** { TypeScope scope = new TypeScope(this.typeScope); ! try { scope.addSymbols(classConstraint.binders); } catch(TypeScope.DuplicateName ex) {} resolvedConstraints = ! AtomicConstraint.resolve(scope, classConstraint.atoms); } } --- 157,164 ---- { TypeScope scope = new TypeScope(this.typeScope); ! try { scope.addSymbols(classConstraint.getBinders()); } catch(TypeScope.DuplicateName ex) {} resolvedConstraints = ! AtomicConstraint.resolve(scope, classConstraint.getAtoms()); } } *************** *** 159,163 **** return null; else ! return classConstraint.binders; } --- 170,174 ---- return null; else ! return classConstraint.getBinderArray(); } *************** *** 177,181 **** else return new mlsub.typing.Constraint ! (classConstraint.binders, resolvedConstraints); } --- 188,192 ---- else return new mlsub.typing.Constraint ! (classConstraint.getBinderArray(), resolvedConstraints); } *************** *** 190,198 **** public void printInterface(java.io.PrintWriter s) { ! // print the constraint as a prefix constraint ! if (classConstraint == null || classConstraint.syntacticConstraint == null) return; ! s.print(classConstraint.syntacticConstraint); } --- 201,210 ---- public void printInterface(java.io.PrintWriter s) { ! // Always print the constraint as a prefix constraint. ! ! if (classConstraint == null) return; ! s.print(classConstraint); } *************** *** 216,250 **** } - if (resolvedConstraints != null) - for (int i = 0; i < resolvedConstraints.length; i++) - if (resolvedConstraints[i] instanceof mlsub.typing.MonotypeLeqTcCst) - { - mlsub.typing.MonotypeLeqTcCst cst = (mlsub.typing.MonotypeLeqTcCst) resolvedConstraints[i]; - if (cst.m == typeParameters[n]) { - res.append('!'); - break; - } - } - res.append(typeParameters[n].toString()); if (n + 1 < typeParameters.length) res.append(", "); } - - if (resolvedConstraints != null) { - boolean first = true; - for (int n = 0; n < resolvedConstraints.length; n++) - { - if (resolvedConstraints[n] instanceof mlsub.typing.MonotypeLeqTcCst) - break; - if (first) { - res.append(" | "); - first = false; - } - res.append(resolvedConstraints[n]); - if (n + 1 < resolvedConstraints.length) - res.append(", "); - } - } return res.append(">").toString(); --- 228,235 ---- Index: Constraint.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Constraint.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** Constraint.java 15 Nov 2003 13:02:15 -0000 1.36 --- Constraint.java 15 Nov 2003 17:25:47 -0000 1.37 *************** *** 264,267 **** --- 264,272 ---- List getAtoms() { return atomics; } + TypeSymbol[] getBinderArray() + { + return (TypeSymbol[]) binders.toArray(new TypeSymbol[binders.size()]); + } + private List /* of TypeSymbol */ binders; private List /* of AtomicConstraint */ atomics; Index: ClassDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ClassDefinition.java,v retrieving revision 1.98 retrieving revision 1.99 diff -C2 -d -r1.98 -r1.99 *** ClassDefinition.java 15 Nov 2003 13:02:15 -0000 1.98 --- ClassDefinition.java 15 Nov 2003 17:25:47 -0000 1.99 *************** *** 445,449 **** try{ localScope = new TypeScope(localScope); ! mlsub.typing.TypeSymbol[] binders = classConstraint.binders; //add only nonvariant type parameter so no possibly unsafe co/contra-variant fields can exist. for (int i = 0; i < binders.length; i++) --- 445,449 ---- try{ localScope = new TypeScope(localScope); ! mlsub.typing.TypeSymbol[] binders = getBinders(); //add only nonvariant type parameter so no possibly unsafe co/contra-variant fields can exist. for (int i = 0; i < binders.length; i++) |