[Nice-commit] Nice/src/bossa/syntax typeConstructors.nice,NONE,1.1 Pattern.java,1.96,1.97 ai.nice,1.
Brought to you by:
bonniot
From: Arjan B. <ar...@us...> - 2004-12-20 16:05:34
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16420/F:/nice/src/bossa/syntax Modified Files: Pattern.java ai.nice customConstructor.nice dispatch.java.bootstrap importedconstructor.nice javaMethod.nice methodbody.nice new.nice niceclass.nice pattern.nice retypedMethod.nice tools.nice typedef.nice Added Files: typeConstructors.nice Removed Files: TypeConstructors.java Log Message: Converted TypeConstructors. Index: Pattern.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Pattern.java,v retrieving revision 1.96 retrieving revision 1.97 diff -C2 -d -r1.96 -r1.97 *** Pattern.java 18 Dec 2004 19:41:00 -0000 1.96 --- Pattern.java 20 Dec 2004 16:05:18 -0000 1.97 *************** *** 101,105 **** " is not a declared class or interface"); ! if (exactlyAtType() && !TypeConstructors.instantiable(tc)) User.error (typeConstructor.location(), --- 101,105 ---- " is not a declared class or interface"); ! if (exactlyAtType() && !dispatch.instantiableTC(tc)) User.error (typeConstructor.location(), Index: customConstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/customConstructor.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** customConstructor.nice 18 Dec 2004 19:41:01 -0000 1.4 --- customConstructor.nice 20 Dec 2004 16:05:18 -0000 1.5 *************** *** 44,48 **** let tc = Node.getGlobalTypeScope().globalLookup(className); ! TypeConstructors.addConstructor(tc, this); classe = NiceClass.get(tc); --- 44,48 ---- let tc = Node.getGlobalTypeScope().globalLookup(className); ! addConstructor(tc, this); classe = NiceClass.get(tc); Index: methodbody.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodbody.nice,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** methodbody.nice 19 Dec 2004 03:40:59 -0000 1.5 --- methodbody.nice 20 Dec 2004 16:05:18 -0000 1.6 *************** *** 52,56 **** if (d instanceof JavaMethod) { d.registerForDispatch(); ! if (TypeConstructors.isInterface(formals[0].tc)) User.error(this, notNull(name) + " is a native method. Dispatch can only occur if the first argument is not an interface."); } --- 52,56 ---- if (d instanceof JavaMethod) { d.registerForDispatch(); ! if (isInterfaceTC(notNull(formals[0].tc))) User.error(this, notNull(name) + " is a native method. Dispatch can only occur if the first argument is not an interface."); } Index: new.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/new.nice,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** new.nice 19 Dec 2004 22:37:31 -0000 1.9 --- new.nice 20 Dec 2004 16:05:18 -0000 1.10 *************** *** 43,52 **** this.tc = tc; ! if (! TypeConstructors.instantiable(tc)) { String message; ! if (TypeConstructors.isInterface(tc)) message = tc + " is an interface, it can't be instantiated"; ! else if (TypeConstructors.isClass(tc)) message = tc + " is an abstract class, it can't be instantiated"; else --- 43,52 ---- this.tc = tc; ! if (! instantiableTC(tc)) { String message; ! if (isInterfaceTC(tc)) message = tc + " is an interface, it can't be instantiated"; ! else if (isClassTC(tc)) message = tc + " is an abstract class, it can't be instantiated"; else *************** *** 60,64 **** definition.resolve(); ! let constructors = TypeConstructors.getConstructors(tc); if (constructors == null) { --- 60,64 ---- definition.resolve(); ! let constructors = getConstructors(tc); if (constructors == null) { *************** *** 73,77 **** // the list of constructors must be cloned, as // OverloadedSymbolExp removes elements from it ! function = createOverloadedSymbolExp(new LinkedList(notNull(constructors)), new LocatedString("new " + tc, this.location())); } --- 73,77 ---- // the list of constructors must be cloned, as // OverloadedSymbolExp removes elements from it ! function = createOverloadedSymbolExp(new LinkedList(cast(constructors)), new LocatedString("new " + tc, this.location())); } Index: niceclass.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceclass.nice,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** niceclass.nice 14 Dec 2004 22:49:12 -0000 1.8 --- niceclass.nice 20 Dec 2004 16:05:18 -0000 1.9 *************** *** 377,381 **** getNativeConstructorParameters(TypeConstructor tc) { ! let constructors = TypeConstructors.getConstructors(tc); if (constructors == null) { --- 377,381 ---- getNativeConstructorParameters(TypeConstructor tc) { ! let constructors = getConstructors(tc); if (constructors == null) { *************** *** 555,559 **** Monotype.sure(new mlsub.typing.MonotypeConstructor(definition.getTC(), definition.getTypeParameters())), classe: this, isDefault: true, fields: fields, parent: parent); ! TypeConstructors.addConstructor(definition.getTC(), notNull(constructorMethod)[i]); } } --- 555,559 ---- Monotype.sure(new mlsub.typing.MonotypeConstructor(definition.getTC(), definition.getTypeParameters())), classe: this, isDefault: true, fields: fields, parent: parent); ! addConstructor(definition.getTC(), notNull(constructorMethod)[i]); } } Index: javaMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/javaMethod.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** javaMethod.nice 19 Dec 2004 22:37:31 -0000 1.1 --- javaMethod.nice 20 Dec 2004 16:05:18 -0000 1.2 *************** *** 242,246 **** let res = makeJavaMethod(m, true); assert res != null; ! TypeConstructors.addConstructor(tc, res); retyped.put(m, res); } --- 242,246 ---- let res = makeJavaMethod(m, true); assert res != null; ! addConstructor(tc, res); retyped.put(m, res); } Index: retypedMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/retypedMethod.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** retypedMethod.nice 19 Dec 2004 22:37:31 -0000 1.1 --- retypedMethod.nice 20 Dec 2004 16:05:18 -0000 1.2 *************** *** 136,140 **** if (tc != null) { ! TypeConstructors.addConstructor(tc, this); registerNativeConstructor(this, reflectMethod, tc); } --- 136,140 ---- if (tc != null) { ! addConstructor(tc, this); registerNativeConstructor(this, reflectMethod, tc); } *************** *** 269,273 **** */ if (auto != null && ! (auto instanceof RetypedJavaMethod)) ! TypeConstructors.removeConstructor(classe, auto); } --- 269,273 ---- */ if (auto != null && ! (auto instanceof RetypedJavaMethod)) ! removeConstructor(classe, auto); } Index: typedef.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typedef.nice,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** typedef.nice 19 Dec 2004 22:37:32 -0000 1.7 --- typedef.nice 20 Dec 2004 16:05:19 -0000 1.8 *************** *** 208,212 **** // We found a cycle. String message; ! if (TypeConstructors.isInterface(tc)) message = "Interface " + this.getName() + " extends itself"; else --- 208,212 ---- // We found a cycle. String message; ! if (isInterfaceTC(tc)) message = "Interface " + this.getName() + " extends itself"; else *************** *** 312,316 **** { let tc = s; ! if (!TypeConstructors.isInterface(tc)) throw User.error(name, tc + " is not an interface"); --- 312,316 ---- { let tc = s; ! if (!isInterfaceTC(tc)) throw User.error(name, tc + " is not an interface"); *************** *** 492,496 **** User.error(superClassIdent, superClass + " is a final class. It cannot be extended"); ! if (TypeConstructors.isInterface(superClass)) User.error(superClassIdent, superClass + " is an interface, so " + name + --- 492,496 ---- User.error(superClassIdent, superClass + " is a final class. It cannot be extended"); ! if (isInterfaceTC(superClass)) User.error(superClassIdent, superClass + " is an interface, so " + name + Index: pattern.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/pattern.nice,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** pattern.nice 18 Dec 2004 19:41:01 -0000 1.12 --- pattern.nice 20 Dec 2004 16:05:18 -0000 1.13 *************** *** 375,379 **** return this.tc != that.tc; ! if (TypeConstructors.isClass(this.tc) && TypeConstructors.isClass(that.tc)) return (! Typing.testRigidLeq(this.tc, that.tc)) && (! Typing.testRigidLeq(that.tc, this.tc)); --- 375,379 ---- return this.tc != that.tc; ! if (isClassTC(notNull(this.tc)) && isClassTC(notNull(that.tc))) return (! Typing.testRigidLeq(this.tc, that.tc)) && (! Typing.testRigidLeq(that.tc, this.tc)); *************** *** 385,389 **** disjoint(Pattern this, Pattern that) { ! if (TypeConstructors.isClass(this.tc) && TypeConstructors.isClass(that.tc)) return (! Typing.testRigidLeq(this.tc, that.tc)) && (! Typing.testRigidLeq(that.tc, this.tc)); --- 385,389 ---- disjoint(Pattern this, Pattern that) { ! if (isClassTC(notNull(this.tc)) && isClassTC(notNull(that.tc))) return (! Typing.testRigidLeq(this.tc, that.tc)) && (! Typing.testRigidLeq(that.tc, this.tc)); --- NEW FILE: typeConstructors.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.*; /** Tools for classes and type constructors. */ var HashMap<mlsub.typing.TypeConstructor,?LinkedList<VarSymbol>> constructorsMap = new HashMap(); public void resetConstructorsMap() { constructorsMap = new HashMap(); } /** The list can be modified by the caller. It should thus be cloned each time. @return a list of the MethodDefinition.Symbols of each constructor of this class. */ ?LinkedList<VarSymbol> getConstructors(mlsub.typing.TypeConstructor tc) { return constructorsMap.get(tc); } void addConstructor(mlsub.typing.TypeConstructor tc, MethodDeclaration m) { ?LinkedList<VarSymbol> l = constructorsMap.get(tc); if (l==null) { l = new LinkedList(); constructorsMap.put(tc, notNull(l)); } notNull(l).add(m.getSymbol()); } void removeConstructor(TypeConstructor tc, MethodDeclaration m) { ?LinkedList<VarSymbol> l = constructorsMap.get(tc); if (l == null) return; l.remove(m.getSymbol()); } /** Test if a type constructor can be instantiated. That is, if <code>new</code> is valid on this tc. */ boolean instantiableTC(mlsub.typing.TypeConstructor tc) { if(tc.isConcrete()) return true; let definition = getTypeDefinition(tc); return definition != null && definition.isConcrete(); } boolean isInterfaceTC(mlsub.typing.TypeConstructor tc) { let def = getTypeDefinition(tc); if (def != null) return def.getAssociatedInterface() != null; ?gnu.bytecode.ClassType c = cast(nice.tools.code.Types.get(tc)); return c != null && c.isInterface(); } boolean isClassTC(mlsub.typing.TypeConstructor tc) { return nice.tools.code.Types.get(tc) != null; } Index: ai.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ai.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ai.nice 18 Dec 2004 19:41:01 -0000 1.2 --- ai.nice 20 Dec 2004 16:05:18 -0000 1.3 *************** *** 103,107 **** classTC = new TypeIdent(name: className).resolveToTC(notNull(typeScope)); ! if (TypeConstructors.isInterface(classTC)) { if (!_interface) User.error(this, ""+classTC+" is not a class"); --- 103,107 ---- classTC = new TypeIdent(name: className).resolveToTC(notNull(typeScope)); ! if (isInterfaceTC(notNull(classTC))) { if (!_interface) User.error(this, ""+classTC+" is not a class"); Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.81 retrieving revision 1.82 diff -C2 -d -r1.81 -r1.82 *** tools.nice 19 Dec 2004 22:37:32 -0000 1.81 --- tools.nice 20 Dec 2004 16:05:18 -0000 1.82 *************** *** 216,220 **** <T> String map(String, String, String, ?Collection<T>) = native String bossa.util.Util.map(String, String, String, Collection); Stack<bossa.link.Alternative> sortedAlternatives(MethodDeclaration) = native Stack bossa.link.Alternative.sortedAlternatives(MethodDeclaration); - ?LinkedList<VarSymbol> getConstructors(mlsub.typing.TypeConstructor) = native LinkedList TypeConstructors.getConstructors(mlsub.typing.TypeConstructor); void addValues(Pattern, List<ConstantExp>) = native void Pattern.addValues(List); ?mlsub.typing.TypeConstructor getRuntimeTC(Pattern) = native mlsub.typing.TypeConstructor Pattern.getRuntimeTC(); --- 216,219 ---- *************** *** 246,250 **** mlsub.typing.TypeSymbol[?] getBinders(MethodContainer) = native mlsub.typing.TypeSymbol[] MethodContainer.getBinders(); ?Expression value(FormalParameters.Parameter) = native Expression FormalParameters.Parameter.value(); - ?LinkedList<MethodSymbol> getConstructors(TypeConstructor) = native LinkedList TypeConstructors.getConstructors(TypeConstructor); ?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); --- 245,248 ---- Index: importedconstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/importedconstructor.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** importedconstructor.nice 19 Dec 2004 22:37:31 -0000 1.4 --- importedconstructor.nice 20 Dec 2004 16:05:18 -0000 1.5 *************** *** 110,114 **** method: method); ! TypeConstructors.addConstructor(res.classe.getDefinition().getTC(), res); return res; } --- 110,114 ---- method: method); ! addConstructor(res.classe.getDefinition().getTC(), res); return res; } Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** dispatch.java.bootstrap 20 Dec 2004 02:16:30 -0000 1.41 --- dispatch.java.bootstrap 20 Dec 2004 16:05:18 -0000 1.42 *************** *** 13,16 **** --- 13,21 ---- public class dispatch { + public static void resetConstructorsMap() {} + + static boolean instantiableTC(mlsub.typing.TypeConstructor tc) + { return false; } + public static void loadJavaMethods(String name) {} --- TypeConstructors.java DELETED --- |