Thread: [Nice-commit] Nice/src/bossa/syntax NiceMethod.java,1.24,1.25 NiceFieldAccess.java,1.17,1.18 NiceCla
Brought to you by:
bonniot
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv23249/src/bossa/syntax Modified Files: NiceMethod.java NiceFieldAccess.java NiceClass.java MethodContainer.java Constraint.java ClassDefinition.java AbstractInterface.java Log Message: Initial support for constraints prefixing a class definition. Index: NiceMethod.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceMethod.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** NiceMethod.java 11 Sep 2003 20:50:27 -0000 1.24 --- NiceMethod.java 15 Nov 2003 13:02:15 -0000 1.25 *************** *** 55,62 **** MethodContainer.Constraint thisConstraint = c.classConstraint; ! mlsub.typing.MonotypeVar[] thisTypeParams = c.getTypeParameters(); ! int thisTypeParamsLen = (thisTypeParams == null ? 0 ! : thisTypeParams.length); TypeSymbol container = c.getTypeSymbol(); --- 55,62 ---- MethodContainer.Constraint thisConstraint = c.classConstraint; ! mlsub.typing.TypeSymbol[] thisBinders = c.getBinders(); ! int thisBindersLen = (thisBinders == null ? 0 ! : thisBinders.length); TypeSymbol container = c.getTypeSymbol(); *************** *** 78,86 **** if(constraint == Constraint.True) constraint = new Constraint ! (new ArrayList(thisTypeParamsLen + (hasAlike ? 1 : 0)), new ArrayList((hasAlike ? 1 : 0) + (thisConstraint == null ? 0 : thisConstraint.atoms.size()))); ! constraint.addBinders(thisTypeParams); if (thisConstraint != null) constraint.addAtoms(thisConstraint.atoms); --- 78,86 ---- if(constraint == Constraint.True) 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); *************** *** 107,111 **** constraint.addAtom(AtomicConstraint.create(atom)); ! thisType = new mlsub.typing.MonotypeConstructor(alikeTC, thisTypeParams); if (hasAlike) --- 107,111 ---- constraint.addAtom(AtomicConstraint.create(atom)); ! thisType = new mlsub.typing.MonotypeConstructor(alikeTC, c.getTypeParameters()); if (hasAlike) *************** *** 119,123 **** else thisType = ! new mlsub.typing.MonotypeConstructor(tc, thisTypeParams); params.addThis(Monotype.create(Monotype.sure(thisType))); --- 119,123 ---- else thisType = ! new mlsub.typing.MonotypeConstructor(tc, c.getTypeParameters()); params.addThis(Monotype.create(Monotype.sure(thisType))); Index: NiceFieldAccess.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceFieldAccess.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** NiceFieldAccess.java 31 Jul 2003 18:45:35 -0000 1.17 --- NiceFieldAccess.java 15 Nov 2003 13:02:15 -0000 1.18 *************** *** 36,40 **** { super(field.sym.name, ! Constraint.create(classDef.definition.getTypeParameters()), makeList(Monotype.sure(classDef.definition.lowlevelMonotype())), field.sym.syntacticType); --- 36,40 ---- { super(field.sym.name, ! Constraint.create(classDef.definition.getBinders()), makeList(Monotype.sure(classDef.definition.lowlevelMonotype())), field.sym.syntacticType); Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** NiceClass.java 25 Oct 2003 20:34:37 -0000 1.63 --- NiceClass.java 15 Nov 2003 13:02:15 -0000 1.64 *************** *** 562,571 **** private static FormalParameters.Parameter[][] getFieldsAsParameters (TypeConstructor tc, int nbFields, List constraints, ! MonotypeVar[] typeParams) { ClassDefinition sup = ClassDefinition.get(tc); if (sup != null && sup.implementation instanceof NiceClass) return ((NiceClass) sup.implementation). ! getFieldsAsParameters(nbFields, constraints, typeParams); List constructors = TypeConstructors.getConstructors(tc); --- 562,571 ---- private static FormalParameters.Parameter[][] getFieldsAsParameters (TypeConstructor tc, int nbFields, List constraints, ! TypeSymbol[] binders) { ClassDefinition sup = ClassDefinition.get(tc); if (sup != null && sup.implementation instanceof NiceClass) return ((NiceClass) sup.implementation). ! getFieldsAsParameters(nbFields, constraints, binders); List constructors = TypeConstructors.getConstructors(tc); *************** *** 594,606 **** private TypeScope translationScope(NiceClass other) { ! mlsub.typing.MonotypeVar[] typeParams = other.definition.getTypeParameters(); TypeScope scope = Node.getGlobalTypeScope(); Map map = null; ! if (typeParams != null) { scope = new TypeScope(scope); ! for (int i = 0; i < typeParams.length; i++) try { ! scope.addMapping(definition.classConstraint.typeParameters[i].getName(), typeParams[i]); } catch(TypeScope.DuplicateName e) {} } --- 594,606 ---- private TypeScope translationScope(NiceClass other) { ! mlsub.typing.TypeSymbol[] binders = other.definition.getBinders(); TypeScope scope = Node.getGlobalTypeScope(); Map map = null; ! if (binders != null) { scope = new TypeScope(scope); ! for (int i = 0; i < binders.length; i++) try { ! scope.addMapping(definition.classConstraint.binders[i].toString(), binders[i]); } catch(TypeScope.DuplicateName e) {} } *************** *** 610,618 **** private FormalParameters.Parameter[][] getFieldsAsParameters ! (int nbFields, List constraints, MonotypeVar[] typeParams) { nbFields += this.fields.length; FormalParameters.Parameter[][] res = getFieldsAsParameters ! (definition.getSuperClass(), nbFields, constraints, typeParams); if (fields.length == 0 && overrides.length == 0 && --- 610,618 ---- private FormalParameters.Parameter[][] getFieldsAsParameters ! (int nbFields, List constraints, TypeSymbol[] binders) { nbFields += this.fields.length; FormalParameters.Parameter[][] res = getFieldsAsParameters ! (definition.getSuperClass(), nbFields, constraints, binders); if (fields.length == 0 && overrides.length == 0 && *************** *** 622,626 **** TypeScope scope = Node.getGlobalTypeScope(); Map map = null; ! if (typeParams != null) { // Constructs a type scope that maps the type parameters of this --- 622,626 ---- TypeScope scope = Node.getGlobalTypeScope(); Map map = null; ! if (binders != null) { // Constructs a type scope that maps the type parameters of this *************** *** 628,635 **** scope = new TypeScope(scope); map = new HashMap(); ! for (int i = 0; i < typeParams.length; i++) try { ! scope.addMapping(definition.classConstraint.typeParameters[i].getName(), typeParams[i]); ! map.put(definition.classConstraint.typeParameters[i], typeParams[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) {} } *************** *** 690,695 **** List constraints; ! mlsub.typing.MonotypeVar[] typeParams = definition.getTypeParameters(); ! if (typeParams == null) constraints = null; else --- 690,695 ---- List constraints; ! mlsub.typing.TypeSymbol[] binders = definition.getBinders(); ! if (binders == null) constraints = null; else *************** *** 697,708 **** FormalParameters.Parameter[][] params = ! getFieldsAsParameters(0, constraints, typeParams); checkFields(params[0]); Constraint cst; ! if (typeParams != null) cst = new Constraint ! (typeParams, (AtomicConstraint[]) constraints.toArray(new AtomicConstraint[constraints.size()])); else --- 697,708 ---- FormalParameters.Parameter[][] params = ! getFieldsAsParameters(0, constraints, binders); checkFields(params[0]); Constraint cst; ! if (binders != null) cst = new Constraint ! (binders, (AtomicConstraint[]) constraints.toArray(new AtomicConstraint[constraints.size()])); else *************** *** 719,723 **** cst, Monotype.resolve(definition.typeScope, values.types()), ! Monotype.sure(new MonotypeConstructor(definition.tc, typeParams))); TypeConstructors.addConstructor(definition.tc, constructorMethod[i]); --- 719,723 ---- cst, Monotype.resolve(definition.typeScope, values.types()), ! Monotype.sure(new MonotypeConstructor(definition.tc, definition.getTypeParameters()))); TypeConstructors.addConstructor(definition.tc, constructorMethod[i]); Index: MethodContainer.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodContainer.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** MethodContainer.java 29 Apr 2003 16:00:59 -0000 1.11 --- MethodContainer.java 15 Nov 2003 13:02:15 -0000 1.12 *************** *** 15,18 **** --- 15,21 ---- import mlsub.typing.Variance; import mlsub.typing.MonotypeVar; + import mlsub.typing.TypeSymbol; + import mlsub.typing.TypeConstructor; + import bossa.util.User; import java.util.List; *************** *** 71,82 **** public static class Constraint { ! public Constraint(MonotypeVar[] typeParameters, List atoms) { ! this.typeParameters = typeParameters; ! this.atoms = atoms; } ! MonotypeVar[] typeParameters; List atoms; } --- 74,139 ---- public static class Constraint { ! /** ! @param cst an additional constraint for the type parameters ! 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); ! } } ! /** ! Replace those type parameters that have been introduced in the ! constraint by their definition. ! */ ! private void findBinders(MonotypeVar[] typeParameters) ! { ! this.typeParameters = new mlsub.typing.Monotype[typeParameters.length]; ! for (int i = 0; i < typeParameters.length; i++) ! { ! this.typeParameters[i] = findBinder(typeParameters[i]); ! } ! } ! ! 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. ! return binder; ! } ! ! /** The binders of the constraint. */ ! TypeSymbol[] binders; ! ! /** The type parameters of the class. */ ! mlsub.typing.Monotype[] typeParameters; ! List atoms; + + String syntacticConstraint; } *************** *** 89,93 **** { TypeScope scope = new TypeScope(this.typeScope); ! try { scope.addSymbols(classConstraint.typeParameters); } catch(TypeScope.DuplicateName ex) {} resolvedConstraints = --- 146,150 ---- { TypeScope scope = new TypeScope(this.typeScope); ! try { scope.addSymbols(classConstraint.binders); } catch(TypeScope.DuplicateName ex) {} resolvedConstraints = *************** *** 96,100 **** } ! public mlsub.typing.MonotypeVar[] getTypeParameters () { if (classConstraint == null) --- 153,167 ---- } ! /** The binders of the constraint. */ ! public mlsub.typing.TypeSymbol[] getBinders () ! { ! if (classConstraint == null) ! return null; ! else ! return classConstraint.binders; ! } ! ! /** The type parameters of the class. */ ! public mlsub.typing.Monotype[] getTypeParameters () { if (classConstraint == null) *************** *** 110,114 **** else return new mlsub.typing.Constraint ! (classConstraint.typeParameters, resolvedConstraints); } --- 177,181 ---- else return new mlsub.typing.Constraint ! (classConstraint.binders, resolvedConstraints); } *************** *** 117,120 **** --- 184,200 ---- ****************************************************************/ + /** + Children should call this implementation (super) then print + their specific information. + */ + 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); + } + String printTypeParameters() { *************** *** 122,126 **** return ""; ! MonotypeVar[] typeParameters = classConstraint.typeParameters; StringBuffer res = new StringBuffer("<"); for (int n = 0; n < typeParameters.length; n++) --- 202,206 ---- return ""; ! mlsub.typing.Monotype[] typeParameters = classConstraint.typeParameters; StringBuffer res = new StringBuffer("<"); for (int n = 0; n < typeParameters.length; n++) Index: Constraint.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Constraint.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Constraint.java 15 Jul 2003 10:36:18 -0000 1.35 --- Constraint.java 15 Nov 2003 13:02:15 -0000 1.36 *************** *** 261,264 **** --- 261,267 ---- } + List getBinders() { return binders; } + List getAtoms() { return atomics; } + 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.97 retrieving revision 1.98 diff -C2 -d -r1.97 -r1.98 *** ClassDefinition.java 28 Oct 2003 10:36:43 -0000 1.97 --- ClassDefinition.java 15 Nov 2003 13:02:15 -0000 1.98 *************** *** 128,131 **** --- 128,132 ---- public void printInterface(java.io.PrintWriter s) { + super.printInterface(s); s.print("interface "); s.print(getSimpleName()); *************** *** 328,331 **** --- 329,333 ---- public void printInterface(java.io.PrintWriter s) { + super.printInterface(s); if (isFinal) s.print("final "); if (isAbstract) s.print("abstract "); *************** *** 443,451 **** try{ localScope = new TypeScope(localScope); ! mlsub.typing.MonotypeVar[] typeParams = classConstraint.typeParameters; //add only nonvariant type parameter so no possibly unsafe co/contra-variant fields can exist. ! for (int i = 0; i < typeParams.length; i++) if (variance.getVariance(i) == mlsub.typing.Variance.INVARIANT) ! localScope.addSymbol(typeParams[i]); } catch(TypeScope.DuplicateName e){ --- 445,453 ---- 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++) if (variance.getVariance(i) == mlsub.typing.Variance.INVARIANT) ! localScope.addSymbol(binders[i]); } catch(TypeScope.DuplicateName e){ Index: AbstractInterface.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/AbstractInterface.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** AbstractInterface.java 11 Sep 2003 20:50:27 -0000 1.16 --- AbstractInterface.java 15 Nov 2003 13:02:16 -0000 1.17 *************** *** 104,107 **** --- 104,108 ---- public void printInterface(java.io.PrintWriter w) { + super.printInterface(w); w.print("abstract interface " + getSimpleName() |