[Nice-commit] Nice/src/bossa/syntax methodContainer.nice,NONE,1.1 ai.nice,1.3,1.4 niceclass.nice,1.1
Brought to you by:
bonniot
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9476/F:/nice/src/bossa/syntax Modified Files: ai.nice niceclass.nice nicefieldaccess.nice tools.nice typedef.nice Added Files: methodContainer.nice Removed Files: MethodContainer.java Log Message: Converted MethodContainer. Index: nicefieldaccess.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/nicefieldaccess.nice,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** nicefieldaccess.nice 3 Jan 2005 01:24:28 -0000 1.5 --- nicefieldaccess.nice 5 Jan 2005 02:02:44 -0000 1.6 *************** *** 47,51 **** let params = createFormalParameters([new Parameter(type: Monotype.create(argType))]); ! let constr = Constraint.create(classDef.getBinders()); let res = new NiceFieldAccess(field.getName(), Node.down, parameters: params, --- 47,51 ---- let params = createFormalParameters([new Parameter(type: Monotype.create(argType))]); ! let constr = bossa.syntax.Constraint.create(classDef.getBinders()); let res = new NiceFieldAccess(field.getName(), Node.down, parameters: params, Index: typedef.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typedef.nice,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** typedef.nice 4 Jan 2005 21:20:51 -0000 1.9 --- typedef.nice 5 Jan 2005 02:02:46 -0000 1.10 *************** *** 36,40 **** ?ClassImplementation implementation = null; ?gnu.bytecode.Type javaType = null; ! ?List<int> typeParametersVariances = null; // Interfaces --- 36,40 ---- ?ClassImplementation implementation = null; ?gnu.bytecode.Type javaType = null; ! ?List<?boolean> typeParametersVariances = null; // Interfaces *************** *** 371,375 **** } ! MethodContainer.Constraint specialize(?MethodContainer.Constraint our, mlsub.typing.Monotype[?] params) { --- 371,375 ---- } ! ClassConstraint specialize(?ClassConstraint our, mlsub.typing.Monotype[?] params) { *************** *** 411,419 **** } ! return new MethodContainer.Constraint( ! binders.toArray(), ! atoms, ! typeParameters, ! this.location()); } --- 411,416 ---- } ! return new ClassConstraint(binders, atoms, ! typeParameters: cast(typeParameters)); } *************** *** 720,724 **** //used in mlsub.typing.Enumeration ! public mlsub.typing.Monotype[] getTypeDefTypeParameters(mlsub.typing.TypeConstructor tc) { return notNull(getTypeDefinition(tc)).getTypeParameters(); --- 717,721 ---- //used in mlsub.typing.Enumeration ! public mlsub.typing.Monotype[?] getTypeDefTypeParameters(mlsub.typing.TypeConstructor tc) { return notNull(getTypeDefinition(tc)).getTypeParameters(); *************** *** 758,762 **** requires exactly these type parameters because it specializes its parent. */ ! ?mlsub.typing.Monotype getTypeWithTC(TypeConstructor tc, mlsub.typing.Monotype[] sourceParams ) { ?TypeDefinition def = cast(getTypeDefinition(tc)); --- 755,759 ---- requires exactly these type parameters because it specializes its parent. */ ! ?mlsub.typing.Monotype getTypeWithTC(TypeConstructor tc, mlsub.typing.Monotype[?] sourceParams ) { ?TypeDefinition def = cast(getTypeDefinition(tc)); *************** *** 777,781 **** if (params[i] == null) { ! fullParams[i] = sourceParams[paramMap[i]]; used++; } --- 774,778 ---- if (params[i] == null) { ! fullParams[i] = notNull(sourceParams)[paramMap[i]]; used++; } *************** *** 854,859 **** ClassDefinition makeClass(LocatedString name, boolean isFinal, boolean isAbstract, ! ?MethodContainer.Constraint typeParameters, ! List<int> typeParametersVariances, MonotypeConstructor superClassIdent, ?List<MonotypeConstructor> implementations, --- 851,856 ---- ClassDefinition makeClass(LocatedString name, boolean isFinal, boolean isAbstract, ! ?ClassConstraint typeParameters, ! List<?boolean> typeParametersVariances, MonotypeConstructor superClassIdent, ?List<MonotypeConstructor> implementations, *************** *** 865,869 **** return new ClassDefinition( ! name, Node.upper, typeParameters, modifiers : mod, typeParametersVariances : typeParametersVariances, --- 862,866 ---- return new ClassDefinition( ! name, Node.upper, classConstraint: typeParameters, modifiers : mod, typeParametersVariances : typeParametersVariances, *************** *** 874,879 **** InterfaceDefinition makeInterface(LocatedString name, ! ?MethodContainer.Constraint typeParameters, ! List<int> typeParametersVariances, ?List<MonotypeConstructor> extensions, ?List<MonotypeConstructor> implementations, --- 871,876 ---- InterfaceDefinition makeInterface(LocatedString name, ! ?ClassConstraint typeParameters, ! List<?boolean> typeParametersVariances, ?List<MonotypeConstructor> extensions, ?List<MonotypeConstructor> implementations, *************** *** 881,885 **** { return new InterfaceDefinition( ! name, Node.upper, typeParameters, typeParametersVariances : typeParametersVariances, extensions : extensions, --- 878,882 ---- { return new InterfaceDefinition( ! name, Node.upper, classConstraint: typeParameters, typeParametersVariances : typeParametersVariances, extensions : extensions, --- MethodContainer.java DELETED --- --- NEW FILE: methodContainer.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; import bossa.util.*; /** An entity in which methods can be declared. It can have type parameters, that are implicitely added to the englobed methods. */ public abstract class MethodContainer extends Definition { ?mlsub.typing.Variance variance = null; ?ClassConstraint classConstraint = null; mlsub.typing.AtomicConstraint[?] resolvedConstraints = null; { this.name.prepend(module.getName() + "."); } /** The name of this method container without package qualification. */ String getSimpleName() { String name = this.getName().toString(); return name.substring(name.lastIndexOf('.') + 1); } mlsub.typing.TypeSymbol getTypeSymbol(); resolve() { if (classConstraint != null) { TypeScope scope = new TypeScope(this.typeScope); try { scope.addSymbols(notNull(classConstraint).getBinders()); } catch(TypeScope.DuplicateName ex) {} resolvedConstraints = AtomicConstraint.resolve(scope, notNull(classConstraint).getAtoms()); } } /** The binders of the constraint. */ public mlsub.typing.TypeSymbol[?] getBinders() { if (classConstraint == null) return null; else return notNull(classConstraint).getBinderArray(); } /** The type parameters of the class. */ public mlsub.typing.Monotype[?] getTypeParameters () { if (classConstraint == null) return null; else return notNull(classConstraint).typeParameters; } public mlsub.typing.Constraint getResolvedConstraint() { if (classConstraint == null) return mlsub.typing.Constraint.True; else return new mlsub.typing.Constraint (notNull(classConstraint).getBinderArray(), resolvedConstraints); } /** Children should call this implementation (super) then print their specific information. */ printInterface(s) { // Always print the constraint as a prefix constraint. if (classConstraint == null) return; s.print(classConstraint); } String printTypeParameters() { if (classConstraint == null) return ""; mlsub.typing.Monotype[] typeParameters = notNull(classConstraint).typeParameters; StringBuffer res = new StringBuffer("<"); for (int n = 0; n < typeParameters.length; n++) { let vari = notNull(variance).getVariance(n); if (vari == mlsub.typing.Variance.CONTRAVARIANT) res.append("-"); else if (vari == mlsub.typing.Variance.COVARIANT) res.append("+"); res.append(typeParameters[n].toString()); if (n + 1 < typeParameters.length) res.append(", "); } return res.append(">").toString(); } } ?mlsub.typing.Variance makeVariance(List<?boolean> typeParametersVariances) { int[] variances = new int[typeParametersVariances.size()]; for (int i = typeParametersVariances.size(); --i >= 0;) if (typeParametersVariances.get(i) != null) if (typeParametersVariances.get(i) == true) variances[i] = mlsub.typing.Variance.COVARIANT; else variances[i] = mlsub.typing.Variance.CONTRAVARIANT; return mlsub.typing.Variance.make(variances); } public class ClassConstraint extends bossa.syntax.Constraint { /** The type parameters of the class. */ mlsub.typing.Monotype[] typeParameters; } /** @param cst an additional constraint for the type parameters of this class. */ public ClassConstraint createClassConstraint(?bossa.syntax.Constraint cst, mlsub.typing.MonotypeVar[] typeParameters, List<AtomicConstraint> atoms, Location loc) { mlsub.typing.TypeSymbol[] binders; List<AtomicConstraint> constraints; boolean resolve; if (cst == bossa.syntax.Constraint.True || cst == null) { binders = cast(typeParameters); constraints = atoms; resolve = false; } else { constraints = cst.getAtoms(); binders = cst.getBinderArray(); resolve = true; } return createClassConstraint(binders, constraints, typeParameters, resolve, loc); } ClassConstraint createClassConstraint(mlsub.typing.TypeSymbol[] binders, List<AtomicConstraint> atoms, mlsub.typing.MonotypeVar[] typeParameters, boolean resolve, Location loc) { mlsub.typing.Monotype[] tps; if (resolve) /** Replace those type parameters that have been introduced in the constraint by their definition. */ tps = cast(typeParameters.mapToArray(mlsub.typing.MonotypeVar binder => { for (s : binders) if (s.toString().equals(binder.getName())) { if (s instanceof mlsub.typing.MonotypeVar) return s; else // The type parameter must be in fact a type constructor // of variance zero. return new mlsub.typing.MonotypeConstructor(cast(s), null); } throw User.error(loc, binder + " is not declared in the constraint"); })); else tps = cast(typeParameters); // The type parameters have nullness markers. for (tp : typeParameters) nice.tools.typing.Types.makeMarkedType(tp); return new ClassConstraint(binders, atoms, typeParameters: tps); } Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.91 retrieving revision 1.92 diff -C2 -d -r1.91 -r1.92 *** tools.nice 4 Jan 2005 21:20:40 -0000 1.91 --- tools.nice 5 Jan 2005 02:02:45 -0000 1.92 *************** *** 226,240 **** ?Definition importMethod(NiceClass, gnu.bytecode.Method) = native Definition NiceClass.importMethod(gnu.bytecode.Method); boolean equals(LocatedString, LocatedString) = native boolean LocatedString.equals(LocatedString); - mlsub.typing.AtomicConstraint[?] resolvedConstraints(MethodContainer) = native MethodContainer.resolvedConstraints; - mlsub.typing.TypeSymbol[?] getBinders(MethodContainer) = native mlsub.typing.TypeSymbol[] MethodContainer.getBinders(); ?gnu.bytecode.Attribute get(gnu.bytecode.AttrContainer, String) = native gnu.bytecode.Attribute gnu.bytecode.Attribute.get(gnu.bytecode.AttrContainer, String); void printInterface(Definition, java.io.PrintWriter) = native void Definition.printInterface(java.io.PrintWriter); ?gnu.expr.Declaration getDeclaration(VarSymbol) = native gnu.expr.Declaration VarSymbol.getDeclaration(); void printInterface(ClassImplementation, java.io.PrintWriter) = native void ClassImplementation.printInterface(java.io.PrintWriter); - ?Variance makeVariance(List<int>) = native Variance MethodContainer.makeVariance(List); List<AtomicConstraint> getAtoms(Constraint) = native List Constraint.getAtoms(); mlsub.typing.Monotype[?] resolve(TypeMap, Monotype[?]) = native mlsub.typing.Monotype[] Monotype.resolve(TypeMap, Monotype[]); - MethodContainer.Constraint MethodContainer$Constraint(TypeSymbol[], List<AtomicConstraint>, ?mlsub.typing.Monotype[], Location) - = native new MethodContainer.Constraint(TypeSymbol[], List, mlsub.typing.Monotype[], Location); ?gnu.bytecode.Type TypeImport_lookup(LocatedString) = native gnu.bytecode.Type nice.tools.code.TypeImport.lookup(LocatedString); List<Node> children(Node) = native Node.children; --- 226,235 ---- *************** *** 242,246 **** void addMappingsLS(TypeScope, Collection<LocatedString>, TypeSymbol[]) = native void TypeScope.addMappingsLS(Collection, TypeSymbol[]); gnu.expr.CopyArgument CopyArgument(Stack<gnu.bytecode.Variable>) = native new gnu.expr.CopyArgument(Stack); - MethodContainer MethodContainer(LocatedString, int, MethodContainer.Constraint, List<?boolean>) = native new MethodContainer(LocatedString, int, MethodContainer.Constraint, List); AST AST(List<Definition>, int) = native new AST(List, int); ?String getParentFor(AtomicConstraint, mlsub.typing.TypeConstructor) = native String AtomicConstraint.getParentFor(mlsub.typing.TypeConstructor); --- 237,240 ---- *************** *** 261,264 **** --- 255,259 ---- Map<VarSymbol, int[]> usedArguments(Arguments) = native Arguments.usedArguments; Map<VarSymbol, Expression[]> applicationExpressions(Arguments) = native Arguments.applicationExpressions; + Constraint _Constraint(mlsub.typing.TypeSymbol[], List<AtomicConstraint>) = native new Constraint(mlsub.typing.TypeSymbol[], List); // Retypings needed since java types are not strict. Index: ai.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ai.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ai.nice 20 Dec 2004 16:05:18 -0000 1.3 --- ai.nice 5 Jan 2005 02:02:43 -0000 1.4 *************** *** 70,80 **** public AbstractInterface createAbstractInterface(LocatedString name, ! MethodContainer.Constraint typeParameters, List<?boolean> typeParametersVariances, List<MonotypeConstructor> extensions ) { ! let res = new AbstractInterface(name, Node.global, typeParameters, ! typeParametersVariances, extensions: extensions); res.itf = new Interface(res.variance, name.toString()); --- 70,80 ---- public AbstractInterface createAbstractInterface(LocatedString name, ! ClassConstraint typeParameters, List<?boolean> typeParametersVariances, List<MonotypeConstructor> extensions ) { ! let res = new AbstractInterface(name, Node.global, classConstraint: typeParameters, ! variance: makeVariance(typeParametersVariances), extensions: extensions); res.itf = new Interface(res.variance, name.toString()); Index: niceclass.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceclass.nice,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** niceclass.nice 4 Jan 2005 21:20:39 -0000 1.13 --- niceclass.nice 5 Jan 2005 02:02:44 -0000 1.14 *************** *** 61,65 **** TypeDefinition getDefinition() = definition; ! public mlsub.typing.Monotype[] getTypeParameters() = definition.getTypeParameters(); public void addField(MonoSymbol sym, ?Expression value, boolean isFinal, --- 61,65 ---- TypeDefinition getDefinition() = definition; ! public mlsub.typing.Monotype[] getTypeParameters() = notNull(definition.getTypeParameters()); public void addField(MonoSymbol sym, ?Expression value, boolean isFinal, *************** *** 429,433 **** scope = new TypeScope(scope); map = new HashMap(); ! let ourTypeParameters = definition.getTypeParameters(); for (int i = 0; i < ourTypeParameters.length; i++) try { --- 429,433 ---- scope = new TypeScope(scope); map = new HashMap(); ! let ourTypeParameters = notNull(definition.getTypeParameters()); for (int i = 0; i < ourTypeParameters.length; i++) try { *************** *** 460,464 **** private List<(?MethodDeclaration, List<Parameter>)> getConstructorParameters(?List<mlsub.typing.AtomicConstraint> constraints, ! mlsub.typing.Monotype[] typeParameters) { let supTC = definition.getSuperClass(); --- 460,464 ---- private List<(?MethodDeclaration, List<Parameter>)> getConstructorParameters(?List<mlsub.typing.AtomicConstraint> constraints, ! mlsub.typing.Monotype[?] typeParameters) { let supTC = definition.getSuperClass(); *************** *** 534,538 **** constraints = new LinkedList(); ! mlsub.typing.Monotype[] typeParameters = definition.getTypeParameters(); List<(?MethodDeclaration, List<Parameter>)> allConstructorParams = --- 534,538 ---- constraints = new LinkedList(); ! mlsub.typing.Monotype[?] typeParameters = definition.getTypeParameters(); List<(?MethodDeclaration, List<Parameter>)> allConstructorParams = *************** *** 563,567 **** // duplicating the type variables. if (parent instanceof JavaMethod && ! notNull(parent.getType()).isMonomorphic()) ! specificCst = identifyTypeParameters(cst, parent, typeParameters); let cname = new LocatedString("<init>",definition.location()); --- 563,567 ---- // duplicating the type variables. if (parent instanceof JavaMethod && ! notNull(parent.getType()).isMonomorphic()) ! specificCst = identifyTypeParameters(cst, parent, notNull(typeParameters)); let cname = new LocatedString("<init>",definition.location()); |