nice-commit Mailing List for The Nice Programming Language (Page 31)
Brought to you by:
bonniot
You can subscribe to this list here.
2003 |
Jan
|
Feb
(60) |
Mar
(125) |
Apr
(183) |
May
(140) |
Jun
(227) |
Jul
(141) |
Aug
(181) |
Sep
(75) |
Oct
(89) |
Nov
(187) |
Dec
(162) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(69) |
Feb
(197) |
Mar
(98) |
Apr
(26) |
May
(10) |
Jun
(85) |
Jul
(88) |
Aug
(79) |
Sep
(80) |
Oct
(81) |
Nov
(53) |
Dec
(109) |
2005 |
Jan
(68) |
Feb
(77) |
Mar
(232) |
Apr
(79) |
May
(37) |
Jun
(37) |
Jul
(3) |
Aug
(18) |
Sep
|
Oct
|
Nov
|
Dec
|
2006 |
Jan
(10) |
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(9) |
2007 |
Jan
(2) |
Feb
(8) |
Mar
(2) |
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
(4) |
Sep
|
Oct
|
Nov
(17) |
Dec
(6) |
2008 |
Jan
|
Feb
(3) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Arjan B. <ar...@us...> - 2004-11-06 21:47:17
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23128/F:/nice/src/bossa/syntax Modified Files: if.nice Log Message: Improved pretty printing of if and ?:. Index: if.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/if.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** if.nice 3 Sep 2004 18:07:27 -0000 1.2 --- if.nice 6 Nov 2004 21:46:13 -0000 1.3 *************** *** 52,64 **** toString() { ! return ! "if(" + ! String.valueOf(condition) + ! ")\n" + ! String.valueOf(thenExp) + ! "\nelse\n" + ! String.valueOf(elseExp) + ! "\n" ! ; } } --- 52,62 ---- toString() { ! if (elseExp instanceof VoidConstantExp) ! return "if (" + condition + ")\n" + thenExp + "\n"; ! ! if (! (elseExp instanceof StatementExp)) ! return condition + " ? " + thenExp + " : " + elseExp; ! ! return "if (" + condition + ")\n" + thenExp + "\nelse\n" + elseExp + "\n"; } } |
From: Arjan B. <ar...@us...> - 2004-11-06 20:40:19
|
Update of /cvsroot/nice/Nice/src/nice/tools/code In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32385/F:/nice/src/nice/tools/code Modified Files: TypeImport.java Log Message: Handling of classloading exceptions. (patch by Luc Perrin) Index: TypeImport.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/TypeImport.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TypeImport.java 4 Jul 2004 02:01:42 -0000 1.8 --- TypeImport.java 6 Nov 2004 20:00:56 -0000 1.9 *************** *** 154,165 **** Class c = null; ! try{ ! c = classLoader.loadClass(className); } catch(ClassNotFoundException e) {} // The class does not exist. ! catch(NoClassDefFoundError e){} // idem stringToReflectClass.put(className, c); ! return c; } --- 154,174 ---- Class c = null; ! try { ! c = classLoader.loadClass(className); } catch(ClassNotFoundException e) {} // The class does not exist. ! catch(NoClassDefFoundError e) ! { ! User.error("Class "+className+" depends on class "+ ! e.getMessage().replace( '/', '.' ) + " which is not available on the classpath." ); ! } ! catch(UnsupportedClassVersionError e) ! { ! User.error("Class "+className+" could not be loaded. The version of its class "+ ! "file is not supported by the running JVM." ); ! } stringToReflectClass.put(className, c); ! return c; } |
From: Arjan B. <ar...@us...> - 2004-11-06 19:40:04
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27610/F:/nice/src/bossa/syntax Modified Files: Arguments.java Constructor.java FormalParameters.java overloadedsymbol.nice tools.nice Log Message: Avoid misleading error messages with named arguments. Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** tools.nice 6 Nov 2004 00:28:17 -0000 1.57 --- tools.nice 6 Nov 2004 19:39:50 -0000 1.58 *************** *** 193,197 **** List<VarSymbol> findJavaMethods(?gnu.bytecode.ClassType, String) = native List JavaClasses.findJavaMethods(gnu.bytecode.ClassType,java.lang.String); TypeParameters TypeParameters(List<Monotype>) = native new bossa.syntax.TypeParameters(List); ! String explainNoMatch(Arguments, List<VarSymbol>) = native String Arguments.explainNoMatch(List); Map<VarSymbol,mlsub.typing.Polytype> types(Arguments) = native Arguments.types; <T> String map(String, String, String, T[]) = native String bossa.util.Util.map(String, String, String, Object[]); --- 193,197 ---- List<VarSymbol> findJavaMethods(?gnu.bytecode.ClassType, String) = native List JavaClasses.findJavaMethods(gnu.bytecode.ClassType,java.lang.String); TypeParameters TypeParameters(List<Monotype>) = native new bossa.syntax.TypeParameters(List); ! ?String explainNoMatch(Arguments, List<VarSymbol>) = native String Arguments.explainNoMatch(List); Map<VarSymbol,mlsub.typing.Polytype> types(Arguments) = native Arguments.types; <T> String map(String, String, String, T[]) = native String bossa.util.Util.map(String, String, String, Object[]); Index: FormalParameters.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/FormalParameters.java,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** FormalParameters.java 13 Oct 2004 20:42:21 -0000 1.42 --- FormalParameters.java 6 Nov 2004 19:39:50 -0000 1.43 *************** *** 501,524 **** } ! public Iterator iterator() { if (parameters != null) ! return Arrays.asList(parameters).iterator(); ! return new ArrayList().iterator(); ! } ! ! public List getNamedParameters() ! { ! LinkedList res = new LinkedList(); ! for(int i = 0; i < size; i++) ! { ! Parameter param = parameters[i]; ! if (param instanceof NamedParameter) ! { ! res.add(parameters[i]); ! } ! } ! return res; } --- 501,510 ---- } ! public List asList() { if (parameters != null) ! return Arrays.asList(parameters); ! return new ArrayList(); } Index: Constructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Constructor.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Constructor.java 5 Nov 2004 14:57:57 -0000 1.14 --- Constructor.java 6 Nov 2004 19:39:50 -0000 1.15 *************** *** 108,112 **** res = new StringBuffer(); List missing = arguments.missingArgs(parameters); ! Iterator fieldsToList; if (arguments.size() == 0) --- 108,112 ---- res = new StringBuffer(); List missing = arguments.missingArgs(parameters); ! List fieldsToList; if (arguments.size() == 0) *************** *** 116,125 **** res.append(syntaxExample()) .append("Class ").append(name).append(" has the following fields:\n"); ! fieldsToList = parameters.iterator(); } else if (missing.size() > 0) { res.append("The following fields require initial values:\n"); ! fieldsToList = missing.iterator(); } else --- 116,125 ---- res.append(syntaxExample()) .append("Class ").append(name).append(" has the following fields:\n"); ! fieldsToList = parameters.asList(); } else if (missing.size() > 0) { res.append("The following fields require initial values:\n"); ! fieldsToList = missing; } else *************** *** 129,138 **** .append(".\n") .append("The constructor accepts the following arguments:\n" ); ! fieldsToList = parameters.iterator(); } ! while (fieldsToList.hasNext()) { res.append(" ") ! .append(fieldsToList.next()) .append("\n"); } --- 129,139 ---- .append(".\n") .append("The constructor accepts the following arguments:\n" ); ! fieldsToList = parameters.asList(); } ! Iterator fieldsIt = fieldsToList.iterator(); ! while (fieldsIt.hasNext()) { res.append(" ") ! .append(fieldsIt.next()) .append("\n"); } Index: Arguments.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Arguments.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** Arguments.java 13 Oct 2004 20:42:21 -0000 1.26 --- Arguments.java 6 Nov 2004 19:39:50 -0000 1.27 *************** *** 241,248 **** if (!argnames.isEmpty()) return " has an argument named " + argnames.get(0); - - return " has compatible named arguments"; } ! return " has " + arguments.length + " arguments"; } --- 241,247 ---- if (!argnames.isEmpty()) return " has an argument named " + argnames.get(0); } ! //fall back to default error message ! return null; } Index: overloadedsymbol.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/overloadedsymbol.nice,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** overloadedsymbol.nice 13 Oct 2004 23:22:22 -0000 1.5 --- overloadedsymbol.nice 6 Nov 2004 19:39:50 -0000 1.6 *************** *** 103,107 **** } ! User.error(this, this.noMatchError(removed, arguments)); } --- 103,107 ---- } ! User.error(this, this.noMatchByNameError(removed, arguments)); } *************** *** 149,160 **** } ! if (removed.size() == 1) ! User.error(this, "Arguments " + arguments.printTypes() + ! " do not fit:\n" + removed[0]); ! else ! User.error(this, "No possible call for " + ident + ! ".\nArguments: " + arguments.printTypes() + ! "\nPossibilities:\n" + ! Util.map("", "\n", "", removed.toArray())); } --- 149,153 ---- } ! User.error(this, this.noMatchError(removed, arguments)); } *************** *** 380,384 **** /** No method in removed matched these arguments. */ ! private String noMatchError(List<VarSymbol> removed, Arguments arguments) { if (removed.size() == 0) --- 373,377 ---- /** No method in removed matched these arguments. */ ! private String noMatchByNameError(List<VarSymbol> removed, Arguments arguments) { if (removed.size() == 0) *************** *** 396,400 **** } ! return "No method with name " + ident + arguments.explainNoMatch(removed); } --- 389,409 ---- } ! let reason = arguments.explainNoMatch(removed); ! if (reason != null) ! return "No method with name " + ident + reason; ! ! return this.noMatchError(removed, arguments); ! } ! ! private String noMatchError(List<VarSymbol> removed, Arguments arguments) ! { ! if (removed.size() == 1) ! return "Arguments " + arguments.printTypes() + ! " do not fit:\n" + removed[0]; ! else ! return "No possible call for " + ident + ! ".\nArguments: " + arguments.printTypes() + ! "\nPossibilities:\n" + ! Util.map("", "\n", "", removed.toArray()); } |
From: Arjan B. <ar...@us...> - 2004-11-06 11:23:24
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24364/F:/nice/src/bossa/syntax Modified Files: ClassDefinition.java Log Message: Check whether a class being extended is visible and make Nice classes public by default. (patch by Luc Perrin) Index: ClassDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ClassDefinition.java,v retrieving revision 1.109 retrieving revision 1.110 diff -C2 -d -r1.109 -r1.110 *** ClassDefinition.java 1 Sep 2004 12:06:51 -0000 1.109 --- ClassDefinition.java 6 Nov 2004 11:23:07 -0000 1.110 *************** *** 71,75 **** } ! int getBytecodeFlags() { return Access.INTERFACE; } boolean implementsJavaInterface(String name) --- 71,78 ---- } ! int getBytecodeFlags() ! { ! return Access.INTERFACE | Access.PUBLIC; ! } boolean implementsJavaInterface(String name) *************** *** 210,218 **** int getBytecodeFlags() { ! if (isFinal) ! return Access.FINAL; ! else if (isAbstract) ! return Access.ABSTRACT; ! else return 0; } --- 213,223 ---- int getBytecodeFlags() { ! int flags = Access.PUBLIC; ! if (isFinal) ! flags |= Access.FINAL; ! if (isAbstract) ! flags |= Access.ABSTRACT; ! ! return flags; } *************** *** 276,279 **** --- 281,287 ---- superClass + " is an interface, so " + name + " may only implement it"); + if (! nice.tools.code.Types.legalAccess(superClass, module.getName())) + User.error(superClassIdent, name + " cannot extend " + + superClass + ". It is not available to this package."); superClassIdent = null; |
From: Arjan B. <ar...@us...> - 2004-11-06 11:23:24
|
Update of /cvsroot/nice/Nice/src/nice/tools/code In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24364/F:/nice/src/nice/tools/code Modified Files: Types.java Log Message: Check whether a class being extended is visible and make Nice classes public by default. (patch by Luc Perrin) Index: Types.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/Types.java,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** Types.java 30 Jul 2004 19:08:44 -0000 1.59 --- Types.java 6 Nov 2004 11:23:07 -0000 1.60 *************** *** 651,653 **** --- 651,665 ---- Import.reset(); } + + /** + * Test if use of a TypeConstructor is legal within a given package + */ + public static boolean legalAccess(TypeConstructor tc, String packageName ) + { + Type type = get(tc); + if (! (type instanceof ClassType)) + return true; + + return Access.legal((ClassType)type, packageName); + } } |
From: Arjan B. <ar...@us...> - 2004-11-06 11:23:24
|
Update of /cvsroot/nice/Nice/src/gnu/bytecode In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24364/F:/nice/src/gnu/bytecode Modified Files: Access.java Log Message: Check whether a class being extended is visible and make Nice classes public by default. (patch by Luc Perrin) Index: Access.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/bytecode/Access.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Access.java 20 Sep 2004 10:24:41 -0000 1.7 --- Access.java 6 Nov 2004 11:23:08 -0000 1.8 *************** *** 76,78 **** --- 76,97 ---- c.isSubclass(target) && receiver.isSubtype(c); } + + /*** + * Returns true if classType is legally accessible in the given package. + */ + public static boolean legal(ClassType classType, String packageName) + { + int mod = classType.getModifiers(); + + if ((mod & PUBLIC) != 0) + return true; + + if ((mod & PRIVATE ) != 0) + return false; + + if (! packageName.equals(classType.getPackageName())) + return false; + + return true; + } } |
From: Arjan B. <ar...@us...> - 2004-11-06 00:28:30
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14811/F:/nice/src/bossa/syntax Modified Files: niceclass.nice tools.nice Added Files: importedconstructor.nice Removed Files: ImportedConstructor.java Log Message: Converted ImportedConstructor. Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** tools.nice 5 Nov 2004 22:46:55 -0000 1.56 --- tools.nice 6 Nov 2004 00:28:17 -0000 1.57 *************** *** 233,236 **** --- 233,237 ---- ?Expression value(FormalParameters.Parameter) = native Expression FormalParameters.Parameter.value(); ?LinkedList<MethodDeclaration.Symbol> 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); // Retypings needed since java types are not strict. --- NEW FILE: importedconstructor.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.*; /** A constructor imported from a compiled package. */ public class ImportedConstructor extends Constructor { private gnu.bytecode.Method method; doResolve() { // Make sure the type is computed first this.removeChild(this.getSymbol()); this.getSymbol().doResolve(); super; this.addConstructorCallSymbol(); } resolve() { super; // Adding the constraint in the type scope. It can be useful for // the default values of the formal parameters // (e.g. an anonymous function refering to a type parameter). let cst = this.getType().getConstraint(); if (mlsub.typing.Constraint.hasBinders(cst)) try { notNull(typeScope).addSymbols(notNull(cst).binders()); } catch (TypeScope.DuplicateName ex) { User.error(this, "Double declaration of the same type parameter"); } } computeCode() { return new gnu.expr.QuoteExp(new gnu.expr.InstantiateProc(method, notNull(method.arg_types).length - arity)); } getConstructorInvocation(boolean omitDefaults) { return new gnu.expr.QuoteExp(new gnu.expr.InitializeProc( omitDefaults ? this.getMethodUsingDefaults() : method, false, notNull(method.arg_types).length - arity)); } getInitializationCode(boolean implicitThis) { return new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(method, implicitThis, notNull(method.arg_types).length - arity)); } /** Return the Method for this constructor with the optional parameters left out. */ private gnu.bytecode.Method getMethodUsingDefaults() { gnu.bytecode.Type[] fullArgTypes = cast(method.arg_types); List<gnu.bytecode.Type> argTypes = new LinkedList(); for (int i = 0; i < parameters.size; i++) if (! parameters.hasDefaultValue(i)) argTypes.add(fullArgTypes[i]); return method.getDeclaringClass().getDeclaredMethod("<init>", argTypes.toArray()); } } public ?ImportedConstructor loadImportedConstructor(NiceClass def, gnu.bytecode.Method method) { if (! method.isConstructor()) return null; ?gnu.bytecode.MiscAttr attr = cast(gnu.bytecode.Attribute.get(method, "parameters")); if (attr == null) return null; let classDef = def.getDefinition(); let returnType = Monotype.create(Monotype.sure (new mlsub.typing.MonotypeConstructor(classDef.tc, classDef.getTypeParameters()))); let constraint = classDef.classConstraint == null ? null : notNull(classDef.classConstraint).shallowClone(); let res = new ImportedConstructor(def, gnu.bytecode.Attribute.get(method, "default") != null, def.getDefinition().location(), FormalParameters.readBytecodeAttribute(attr, notNull(JavaClasses.compilation).parser), constraint, returnType, method: method); TypeConstructors.addConstructor(res.classe.getDefinition().tc, res); return res; } Index: niceclass.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceclass.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** niceclass.nice 5 Nov 2004 22:46:55 -0000 1.2 --- niceclass.nice 6 Nov 2004 00:28:17 -0000 1.3 *************** *** 665,669 **** { if (method.isConstructor()) ! return ImportedConstructor.load(this, method); if (method.getArity() == 0 && method.getName().equals("$init")) --- 665,669 ---- { if (method.isConstructor()) ! return loadImportedConstructor(this, method); if (method.getArity() == 0 && method.getName().equals("$init")) --- ImportedConstructor.java DELETED --- |
From: Arjan B. <ar...@us...> - 2004-11-05 22:47:08
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23623/F:/nice/src/bossa/syntax Modified Files: defaultconstructor.nice niceclass.nice nicefield.nice tools.nice Log Message: Minor cleanup. Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** tools.nice 5 Nov 2004 14:57:57 -0000 1.55 --- tools.nice 5 Nov 2004 22:46:55 -0000 1.56 *************** *** 29,36 **** { ?LocatedString f = identString(e.function); ! if (f == null) ! return false; ! else ! return f.toString().equals(name); } --- 29,33 ---- { ?LocatedString f = identString(e.function); ! return (f != null) && f.toString().equals(name); } *************** *** 40,58 **** { let sym = e.getSymbol(); ! if (sym instanceof bossa.syntax.MonoSymbol) { ! //don't allow nullness inference on global variables. ! if (sym instanceof GlobalVarDeclaration.GlobalVarSymbol && ! sym.isAssignable()) ! return null; ! // no type inference on captured variables ! if (sym.captured) ! return null; ! return sym; ! } ! return null; } ! localVariable(AssignExp e) = localVariable(notNull(e.to)); mlsub.typing.Monotype makeSure(mlsub.typing.Monotype m) = --- 37,54 ---- { let sym = e.getSymbol(); ! if (! (sym instanceof bossa.syntax.MonoSymbol)) ! return null; ! //don't allow nullness inference on global variables. ! if (sym instanceof GlobalVarDeclaration.GlobalVarSymbol && sym.isAssignable()) ! return null; ! // no type inference on captured variables ! if (sym.captured) ! return null; ! ! return sym; } ! localVariable(AssignExp e) = localVariable(e.to); mlsub.typing.Monotype makeSure(mlsub.typing.Monotype m) = *************** *** 100,105 **** return null; ! ?MonoSymbol sym = localVariable(condition.arguments.getExp(0)); ! if (sym == null) return null; --- 96,100 ---- return null; ! let sym = localVariable(condition.arguments.getExp(0)); if (sym == null) return null; *************** *** 109,126 **** return null; ! TypeConstantExp type = cast(arg2); ! if (type.getTC() == null) return null; - TypeConstructor tc = notNull(type.getTC()); - if (tc == PrimitiveType.arrayTC) ! return (sym, notNull(type.representedType)); ! mlsub.typing.Monotype[?] parameters; ! if (tc.arity() == 0) ! parameters = null; ! else { let originalType = nice.tools.typing.Types.rawType(sym.getMonotype()); --- 104,117 ---- return null; ! ?TypeConstructor tc = arg2.getTC(); ! if (tc == null) return null; if (tc == PrimitiveType.arrayTC) ! return (sym, notNull(arg2.representedType)); ! mlsub.typing.Monotype[?] parameters = null; ! if (tc.arity() != 0) { let originalType = nice.tools.typing.Types.rawType(sym.getMonotype()); *************** *** 175,182 **** missingThisError(); - Location loc = ident.location(); call.function = createOverloadedSymbolExp(new ArrayList(cast(classe).getConstructorCallSymbols()), FormalParameters.thisName); ! notNull(call.function).setLocation(loc); } --- 166,172 ---- missingThisError(); call.function = createOverloadedSymbolExp(new ArrayList(cast(classe).getConstructorCallSymbols()), FormalParameters.thisName); ! call.function.setLocation(ident.location()); } Index: niceclass.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceclass.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** niceclass.nice 5 Nov 2004 14:57:57 -0000 1.1 --- niceclass.nice 5 Nov 2004 22:46:55 -0000 1.2 *************** *** 55,59 **** */ classe = notNull(definition.module).getClassExp(this); - } --- 55,58 ---- Index: nicefield.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/nicefield.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** nicefield.nice 5 Nov 2004 14:57:57 -0000 1.1 --- nicefield.nice 5 Nov 2004 22:46:55 -0000 1.2 *************** *** 11,14 **** --- 11,18 ---- /**************************************************************************/ + package bossa.syntax; + + import bossa.util.*; + /** A field or field override in a Nice class. *************** *** 42,46 **** bossa.util.User.error(sym, "A field cannot have void type"); ! value = dispatch.analyse(value, scope, typeScope); } --- 46,51 ---- bossa.util.User.error(sym, "A field cannot have void type"); ! if (value != null) ! value = analyse(notNull(value), scope, typeScope); } *************** *** 62,66 **** mlsub.typing.Polytype declaredType = sym.getType(); value = notNull(value).resolveOverloading(declaredType); ! dispatch.typecheck(notNull(value)); try { --- 67,71 ---- mlsub.typing.Polytype declaredType = sym.getType(); value = notNull(value).resolveOverloading(declaredType); ! typecheck(notNull(value)); try { *************** *** 148,152 **** final class OverridenField extends NiceField { - isFinal() = true; --- 153,156 ---- Index: defaultconstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/defaultconstructor.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** defaultconstructor.nice 5 Nov 2004 14:57:57 -0000 1.1 --- defaultconstructor.nice 5 Nov 2004 22:46:55 -0000 1.2 *************** *** 56,59 **** --- 56,62 ---- computeCode() { + if (classe.getDefinition().inInterfaceFile()) + throw new Error("Constructors are loaded from the compiled package"); + this.createBytecode(true); this.createBytecode(false); *************** *** 92,100 **** return; ! gnu.bytecode.Type[] argTypesArray = argTypes.toArray(); ! MonoSymbol[] argsArray = args.toArray(); ! ! if (classe.getDefinition().inInterfaceFile()) ! throw new Error("Constructors are loaded from the compiled package"); let lambda = nice.tools.code.Gen.createConstructor --- 95,100 ---- return; ! let argTypesArray = argTypes.toArray(); ! let argsArray = args.toArray(); let lambda = nice.tools.code.Gen.createConstructor *************** *** 105,126 **** classe.getClassExp().addMethod(lambda); - // Add attributes useful for the nice compiler. These are not needed - // for the version omitting defaults, since that one is only there for - // Java users' sake. if (! omitDefaults) { lambda.addBytecodeAttribute(parameters.asBytecodeAttribute()); lambda.addBytecodeAttribute(new gnu.bytecode.MiscAttr("default")); } - - if (omitDefaults) - { - initializeOmitDefaults = new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(lambda)); - } else { ! initialize = new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(lambda)); ! initializeFromConstructor = new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(lambda, true)); ! instantiate = new gnu.expr.QuoteExp(new gnu.expr.InstantiateProc(lambda)); } } --- 105,123 ---- classe.getClassExp().addMethod(lambda); if (! omitDefaults) { + initialize = new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(lambda)); + initializeFromConstructor = new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(lambda, true)); + instantiate = new gnu.expr.QuoteExp(new gnu.expr.InstantiateProc(lambda)); + + // Add attributes useful for the nice compiler. These are not needed + // for the version omitting defaults, since that one is only there for + // Java users' sake. lambda.addBytecodeAttribute(parameters.asBytecodeAttribute()); lambda.addBytecodeAttribute(new gnu.bytecode.MiscAttr("default")); } else { ! initializeOmitDefaults = new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(lambda)); } } |
From: Arjan B. <ar...@us...> - 2004-11-05 15:42:52
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19806/F:/nice/src/bossa/syntax Modified Files: MethodBodyDefinition.java Log Message: Save error messages instead of errors in ErrorList. Index: MethodBodyDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodBodyDefinition.java,v retrieving revision 1.155 retrieving revision 1.156 diff -C2 -d -r1.155 -r1.156 *** MethodBodyDefinition.java 5 Nov 2004 14:57:57 -0000 1.155 --- MethodBodyDefinition.java 5 Nov 2004 15:42:42 -0000 1.156 *************** *** 120,129 **** boolean multipleErrors = false; ! void add(MethodDeclaration method, UserError error) { if (errors == null) errors = new ArrayList(); ! errors.add(error); } --- 120,129 ---- boolean multipleErrors = false; ! void add(MethodDeclaration method, LocatedString message) { if (errors == null) errors = new ArrayList(); ! errors.add(message); } *************** *** 131,135 **** { if (errors != null && errors.size() == 1) ! throw (UserError) errors.get(0); } } --- 131,138 ---- { if (errors != null && errors.size() == 1) ! { ! LocatedString message = (LocatedString)errors.get(0); ! throw new UserError(message.location(), message.toString()); ! } } } *************** *** 191,199 **** } catch (TypingEx e) { ! errorList.add ! (m, ! new UserError(formals[p], ! "Pattern " + formals[p] + ! " is incompatible with " + domain[p])); throw e; --- 194,200 ---- } catch (TypingEx e) { ! errorList.add(m, new LocatedString("Pattern " + formals[p] + ! " is incompatible with " + domain[p], ! formals[p].location())); throw e; *************** *** 273,280 **** if (formals[i].atAny() && formals[i].name != null && params.getName(i) != null && !formals[i].name.toString().equals(params.getName(i).toString())) { ! errorList.add(m, ! new UserError(formals[i], "Parameter " + formals[i] + ! " should be called " + ! params.getName(i))); it.remove(); continue outer; --- 274,280 ---- if (formals[i].atAny() && formals[i].name != null && params.getName(i) != null && !formals[i].name.toString().equals(params.getName(i).toString())) { ! errorList.add(m, new LocatedString("Parameter " + formals[i] + ! " should be called " + params.getName(i), ! formals[i].location())); it.remove(); continue outer; |
From: Arjan B. <ar...@us...> - 2004-11-05 15:22:17
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14991/F:/nice/stdlib/nice/lang Modified Files: prelude.nice Log Message: Nake clone() not accept maybe null arguments. Index: prelude.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/prelude.nice,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** prelude.nice 17 Sep 2004 13:39:19 -0000 1.39 --- prelude.nice 5 Nov 2004 15:22:05 -0000 1.40 *************** *** 123,127 **** cloneable classes of arbitrary variances. */ ! <T> T clone(T) = native Object java.lang.Object.clone(); /**************************************************************** --- 123,127 ---- cloneable classes of arbitrary variances. */ ! <T> !T clone(!T) = native Object java.lang.Object.clone(); /**************************************************************** |
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8798/F:/nice/src/bossa/syntax Modified Files: Constructor.java CustomConstructor.java EnumDefinition.java ImportedConstructor.java MethodBodyDefinition.java NiceClass.java NiceUtils.java dispatch.java.bootstrap new.nice tools.nice Added Files: defaultconstructor.nice niceclass.nice nicefield.nice nicefieldaccess.nice Removed Files: DefaultConstructor.java NiceFieldAccess.java Log Message: Converted NiceClass, DefaultConstructor and Nice field classes to nice code. Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** dispatch.java.bootstrap 7 Oct 2004 22:03:44 -0000 1.23 --- dispatch.java.bootstrap 5 Nov 2004 14:57:57 -0000 1.24 *************** *** 13,16 **** --- 13,19 ---- public class dispatch { + public static NiceClass createNiceClass(ClassDefinition cdef) + {return null;} + public static Statement createReturnStmt(Expression value, boolean fake) { return null; } Index: Constructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Constructor.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Constructor.java 7 Oct 2004 19:34:00 -0000 1.13 --- Constructor.java 5 Nov 2004 14:57:57 -0000 1.14 *************** *** 82,86 **** return super.explainWhyMatchFails(arguments); ! String name = classe.getName(); StringBuffer res = new StringBuffer(); --- 82,86 ---- return super.explainWhyMatchFails(arguments); ! String name = classe.getName().toString(); StringBuffer res = new StringBuffer(); *************** *** 143,147 **** private String syntaxExample() { ! String name = classe.getName(); StringBuffer res = new StringBuffer(); res.append("Use the following syntax:\n") --- 143,147 ---- private String syntaxExample() { ! String name = classe.getName().toString(); StringBuffer res = new StringBuffer(); res.append("Use the following syntax:\n") Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** tools.nice 14 Oct 2004 09:37:27 -0000 1.54 --- tools.nice 5 Nov 2004 14:57:57 -0000 1.55 *************** *** 176,180 **** Location loc = ident.location(); ! call.function = createOverloadedSymbolExp(classe.getConstructorCallSymbols(), FormalParameters.thisName); notNull(call.function).setLocation(loc); --- 176,180 ---- Location loc = ident.location(); ! call.function = createOverloadedSymbolExp(new ArrayList(cast(classe).getConstructorCallSymbols()), FormalParameters.thisName); notNull(call.function).setLocation(loc); *************** *** 208,212 **** <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); - List<VarSymbol> getConstructorCallSymbols(NiceClass) = native List NiceClass.getConstructorCallSymbols(); LinkedList<VarSymbol> getConstructors(mlsub.typing.TypeConstructor) = native LinkedList TypeConstructors.getConstructors(mlsub.typing.TypeConstructor); List<VarSymbol> symbols(EnumDefinition) = native EnumDefinition.symbols; --- 208,211 ---- *************** *** 228,233 **** ?mlsub.typing.Constraint getConstraint(mlsub.typing.Polytype) = native mlsub.typing.Constraint mlsub.typing.Polytype.getConstraint(); MonoSymbol[?] getMonoSymbols(FormalParameters) = native MonoSymbol[] FormalParameters.getMonoSymbols(); ! // Retypings needed since java types are not strict. mlsub.typing.Polytype boolPolytype() = native PrimitiveType.boolPolytype; mlsub.typing.Polytype longPolytype() = native PrimitiveType.longPolytype; --- 227,248 ---- ?mlsub.typing.Constraint getConstraint(mlsub.typing.Polytype) = native mlsub.typing.Constraint mlsub.typing.Polytype.getConstraint(); MonoSymbol[?] getMonoSymbols(FormalParameters) = native MonoSymbol[] FormalParameters.getMonoSymbols(); ! mlsub.typing.AtomicConstraint[?] AtomicConstraint_substitute(java.util.Map<mlsub.typing.TypeSymbol,mlsub.typing.TypeSymbol>, AtomicConstraint[?]) = native mlsub.typing.AtomicConstraint[] mlsub.typing.AtomicConstraint.substitute(java.util.Map, mlsub.typing.AtomicConstraint[]); ! NiceClass classe(Constructor) = native Constructor.classe; ! FormalParameters parameters(MethodDeclaration) = native MethodDeclaration.parameters; ! ?gnu.expr.Expression getInitializer(NiceClass) = native gnu.expr.Expression NiceClass.getInitializer(); ! void addConstructorCallSymbol(NiceClass, MethodDeclaration.Symbol) = native void NiceClass.addConstructorCallSymbol(MethodDeclaration.Symbol); ! gnu.expr.Expression callSuperMethod(NiceClass, gnu.bytecode.Method) = native gnu.expr.Expression NiceClass.callSuperMethod(gnu.bytecode.Method); ! Module module(Definition) = native Definition.module; ! ?Definition importMethod(NiceClass, gnu.bytecode.Method) = native Definition NiceClass.importMethod(gnu.bytecode.Method); ! boolean equals(LocatedString, LocatedString) = native boolean LocatedString.equals(LocatedString); ! ?mlsub.typing.TypeConstructor getSuperClass(ClassDefinition) = native mlsub.typing.TypeConstructor ClassDefinition.getSuperClass(); ! List<mlsub.typing.Interface> interfaces(ClassDefinition) = native ClassDefinition.interfaces; ! List<FormalParameters.Parameter> getParameters(FormalParameters, TypeScope) = native List FormalParameters.getParameters(TypeScope); ! mlsub.typing.AtomicConstraint[?] resolvedConstraints(MethodContainer) = native MethodContainer.resolvedConstraints; ! mlsub.typing.TypeSymbol[?] getBinders(MethodContainer) = native mlsub.typing.TypeSymbol[] MethodContainer.getBinders(); ! ?Expression value(FormalParameters.Parameter) = native Expression FormalParameters.Parameter.value(); ! ?LinkedList<MethodDeclaration.Symbol> getConstructors(TypeConstructor) = native LinkedList TypeConstructors.getConstructors(TypeConstructor); + // Retypings needed since java types are not strict. mlsub.typing.Polytype boolPolytype() = native PrimitiveType.boolPolytype; mlsub.typing.Polytype longPolytype() = native PrimitiveType.longPolytype; Index: ImportedConstructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ImportedConstructor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ImportedConstructor.java 7 Oct 2004 15:29:29 -0000 1.1 --- ImportedConstructor.java 5 Nov 2004 14:57:57 -0000 1.2 *************** *** 47,59 **** super(def, Attribute.get(method, "default") != null, ! def.definition.location(), FormalParameters.readBytecodeAttribute (attr, JavaClasses.compilation.parser), ! def.definition.classConstraint == null ? ! null : def.definition.classConstraint.shallowClone(), ! returnType(def.definition)); this.method = method; ! TypeConstructors.addConstructor(classe.definition.tc, this); } --- 47,59 ---- super(def, Attribute.get(method, "default") != null, ! def.getDefinition().location(), FormalParameters.readBytecodeAttribute (attr, JavaClasses.compilation.parser), ! def.getDefinition().classConstraint == null ? ! null : def.getDefinition().classConstraint.shallowClone(), ! returnType(def.getDefinition())); this.method = method; ! TypeConstructors.addConstructor(classe.getDefinition().tc, this); } Index: CustomConstructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/CustomConstructor.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** CustomConstructor.java 7 Oct 2004 22:03:43 -0000 1.21 --- CustomConstructor.java 5 Nov 2004 14:57:57 -0000 1.22 *************** *** 158,162 **** if (mlsub.typing.Constraint.hasBinders(cst)) parameters.substitute ! (map(cst.binders(), classe.definition.getTypeParameters())); lambda.addBytecodeAttribute(parameters.asBytecodeAttribute()); --- 158,162 ---- if (mlsub.typing.Constraint.hasBinders(cst)) parameters.substitute ! (map(cst.binders(), classe.getTypeParameters())); lambda.addBytecodeAttribute(parameters.asBytecodeAttribute()); --- NEW FILE: niceclass.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.*; /** Concrete Nice Class definition. */ public class CNiceClass extends NiceClass { ClassDefinition definition; private List<NewField> fields = new ArrayList(); private List<OverridenField> overrides = new ArrayList(); private List<ValueOverride> valueOverrides = new ArrayList(); private List<Statement> initializers = new ArrayList(); private ?Long serialVersionUIDValue = null; private ?MonoSymbol thisSymbol = null; private ?gnu.expr.Expression thisExp = null; /** List of symbols for calling constructors of this class. */ private List<MethodDeclaration.Symbol> constructors = new ArrayList(); private Constructor[?] constructorMethod = null; // Used to resolve fields, and constructor constraint. private ?TypeScope localScope = null; /** Reference to the method performing instance initialization for this class. */ private ?gnu.expr.Expression initializerMethod = null; gnu.expr.ClassExp classe = cast(null); { /* We always generate a new ClassExp object, even for classes from already compiled packages. The reason is that we might need to add methods for the multiple dispatch of java methods in the class (and maybe for adding fields, or optimizing the dispatch of Nice methods in the future). However, the ClassExp object refers to the existing ClassType object, and only adds or modifies features when needed. */ classe = notNull(definition.module).getClassExp(this); } getName() = definition.getName(); getDefinition() = definition; getTypeParameters() = definition.getTypeParameters(); addField(sym, value, isFinal, isTransient, isVolatile, docString) { if (this.isInterface()) bossa.util.User.error(sym, "An interface cannot have a field."); if (isFinal && notNull(sym).getName().toString().equals("serialVersionUID")) { if (value instanceof ConstantExp && value.value instanceof Long) serialVersionUIDValue = cast(value.value); else bossa.util.User.error(sym, "the value of an serialVersionUID should a constant of type long"); return; } if (isFinal && isVolatile) throw bossa.util.User.error(sym, "A field cannot be final and volatile"); fields.add(new NewField(declaringClass: this, sym: notNull(sym), value: value, isFinal_: isFinal, isVolatile: isVolatile, isTransient: isTransient, docString: docString)); } public void addOverride(MonoSymbol sym, ?Expression value) { if (this.isInterface()) bossa.util.User.error(sym, "An interface cannot have a field."); overrides.add(new OverridenField(declaringClass: this, sym: sym, value: value)); } public void addValueOverride(LocatedString fname, Expression value) { if (this.isInterface()) bossa.util.User.error(fname, "An interface cannot have a field."); valueOverrides.add(new ValueOverride(declaringClass: this, name: fname, value: value)); } isInterface() = definition instanceof ClassDefinition.Interface; ?CNiceClass getParent() { return cast(NiceClass.get(definition.getSuperClass())); } addConstructorCallSymbol(sym) { constructors.add(sym); } List<MethodDeclaration.Symbol> getConstructorCallSymbols() = new LinkedList(constructors); resolveClass() { classe.supers = cast(this.computeSupers()); localScope = definition.getLocalScope(); definition.setJavaType(classe.getType()); this.resolveFields(); this.resolveIntitializers(); this.createDefaultConstructors(); this.addPublicCloneMethod(); } private void resolveFields() { for (field : fields) field.resolve(notNull(definition.scope), notNull(localScope)); for (o : overrides) o.resolve(notNull(definition.scope), notNull(localScope)); for (valueOverride : valueOverrides) valueOverride.resolve(notNull(definition.scope), notNull(localScope)); } private ?gnu.expr.Declaration getOverridenField (OverridenField field, boolean checkValue) { let name = field.getName(); for (original : fields) if (original.hasName(name)) { if (! original.isFinal()) bossa.util.User.error(name, "The original field in class " + this + " is not final, so its type cannot be overriden"); checkValue = field.checkOverride(original, checkValue); return original.method.fieldDecl; } for (original : overrides) if (original.hasName(name)) checkValue = field.checkOverride(original, checkValue); if (checkValue) for (original : valueOverrides) if (original.hasName(name)) { field.checkOverride(original); checkValue = false; break; } let parent = this.getParent(); if (parent != null) return parent.getOverridenField(field, checkValue); else return null; } private boolean checkValueOverride(LocatedString name, Expression value) { ?NiceField original = null; for (field : fields) if (field.hasName(name)) original = field; for (or : overrides) if (or.hasName(name)) original = or; if (original != null) { this.enterTypingContext(); let declaredType = original.sym.getType(); value = value.resolveOverloading(declaredType); typecheck(value); try { Typing.leq(value.getType(), declaredType); } catch (mlsub.typing.TypingEx ex) { bossa.util.User.error(name, "Value does not fit in the overriden field of type " + declaredType); } return true; } let parent = this.getParent(); if (parent != null) return parent.checkValueOverride(name, value); else return false; } /**************************************************************** * Initializers ****************************************************************/ public void addInitializer(Statement init) { initializers.add(init); } private void resolveIntitializers() { if (initializers.isEmpty()) return; VarScope scope = notNull(definition.scope); mlsub.typing.Monotype thisType = Monotype.sure(new mlsub.typing.MonotypeConstructor(definition.tc, definition.getTypeParameters())); thisSymbol = new ThisSymbol(FormalParameters.thisName, thisType, declaringClass: this); Node.thisExp = new SymbolExp(thisSymbol, definition.location()); scope.addSymbol(thisSymbol); for (int i = 0; i < initializers.size(); i++) initializers[i] = analyse(initializers[i], notNull(definition.scope), notNull(localScope), false); Node.thisExp = null; scope.removeSymbol(thisSymbol); } getInitializer() { if (initializerMethod != null) return notNull(initializerMethod); ?gnu.expr.Expression parentInitializer = null; let parent = this.getParent(); if (parent != null) { parentInitializer = parent.getInitializer(); } if (initializers.size() == 0 && parentInitializer == null) return null; gnu.expr.Expression[] params = cast(new gnu.expr.Expression[1]); let lambda = nice.tools.code.Gen.createMemberMethod("$init", classe.getType(), null, gnu.bytecode.Type.void_type, params); thisExp = params[0]; List<gnu.expr.Expression> body = new ArrayList(); if (parentInitializer != null) body.add(nice.tools.code.Gen.superCall(parentInitializer, [notNull(thisExp)])); for (init : initializers) body.add(init.generateCode()); nice.tools.code.Gen.setMethodBody(lambda, new gnu.expr.BeginExp(body.toArray())); initializerMethod = this.addJavaMethod(lambda); return initializerMethod; } /**************************************************************** * Type checking ****************************************************************/ typecheck() { try { for (field : fields) field.typecheck(); for (or : overrides) or.typecheck(); for (valueOverride : valueOverrides) valueOverride.typecheck(); if (! initializers.isEmpty()) { this.enterTypingContext(); Node.thisExp = new SymbolExp(thisSymbol, definition.location()); for (init : initializers) typecheck(init); } } finally { if (entered) { entered = false; Node.thisExp = null; try { mlsub.typing.Typing.leave(); } catch(TypingEx ex) { User.error(this.definition, "Type error in field declarations"); } } } } private boolean entered = false; private void enterTypingContext() { if (entered || definition.classConstraint == null) return; mlsub.typing.Typing.enter(); entered = true; mlsub.typing.lowlevel.Element[] typeParameters = cast(notNull(definition.classConstraint).typeParameters); mlsub.typing.Typing.introduce(typeParameters); try { mlsub.typing.Typing.implies(); } catch(mlsub.typing.TypingEx ex) { bossa.util.Internal.error(ex); } } printInterface(s) { notNull(s).print(" {\n" + Util.map("", ";\n", ";\n", fields) + Util.map("", ";\n", ";\n", overrides) + ((serialVersionUIDValue == null) ? "" : ("final long serialVersionUID = " + serialVersionUIDValue + "L;\n")) + "}\n\n" ); } private void addPublicCloneMethod() { if (! definition.implementsJavaInterface("java.lang.Cloneable")) return; gnu.expr.Expression[] params = cast(new gnu.expr.Expression[1]); let lambda = this.createJavaMethod("clone", cloneMethod, params); nice.tools.code.Gen.setMethodBody (lambda, new gnu.expr.ApplyExp(nice.tools.code.Gen.superCaller(cloneMethod), params)); this.addJavaMethod(lambda); } createClassExp() { gnu.expr.ClassExp res = new gnu.expr.ClassExp(); res.setName(this.getName().toString()); definition.location().write(res); res.setSimple(true); res.setAccessFlags(definition.getBytecodeFlags()); definition.module.addUserClass(res); return res; } getClassExp() = classe; /** Collect in 'constraints' the constraints set by each class on the type parameters. */ private List<(?MethodDeclaration, List<FormalParameters.Parameter>)> getNativeConstructorParameters(TypeConstructor tc) { let constructors = TypeConstructors.getConstructors(tc); if (constructors == null) { // null stands for the Object() constructor return new ArrayList([(null, new ArrayList())]); } List<(?MethodDeclaration, List<FormalParameters.Parameter>)> res = new ArrayList(constructors.size()); for (msym : constructors) { let m = msym.getMethodDeclaration(); // Only consider parent methods for which a call from this class // is legal. if (m instanceof JavaMethod) { let thisClass = classe.getClassType(); if (! gnu.bytecode.Access.legal(thisClass, m.reflectMethod, thisClass)) continue; } List<FormalParameters.Parameter> params = new ArrayList(); for (arg : m.getArgTypes()) params.add(new FormalParameters.Parameter(Monotype.create(arg))); res.add((m, params)); } return res; } private List<(?MethodDeclaration, List<FormalParameters.Parameter>)> getParentConstructorParameters(mlsub.typing.Monotype[?] typeParameters, ?List<mlsub.typing.AtomicConstraint> constraints) { TypeScope scope = Node.getGlobalTypeScope(); ?Map<TypeSymbol,TypeSymbol> map = null; if (typeParameters != null) { // Constructs a type scope that maps the type parameters of this // class to the corresponding symbol in the constructor. scope = new TypeScope(scope); map = new HashMap(); let ourTypeParameters = definition.getTypeParameters(); for (int i = 0; i < ourTypeParameters.length; i++) try { TypeSymbol ourSym = asTypeSymbol(ourTypeParameters[i]); TypeSymbol sym = asTypeSymbol(typeParameters[i]); scope.addMapping(ourSym.toString(), sym); notNull(map).put(ourSym, sym); } catch(TypeScope.DuplicateName e) {} } List<(?MethodDeclaration, List<FormalParameters.Parameter>)> res = new ArrayList(); for (msym : constructors) { let decl = msym.getMethodDeclaration(); res.add((decl, decl.formalParameters().getParameters(scope))); } if (definition.classConstraint != null) { let newAtoms = mlsub.typing.AtomicConstraint.substitute(notNull(map), cast(definition.resolvedConstraints)); if (newAtoms != null) notNull(constraints).addAll(newAtoms); } return res; } private List<(?MethodDeclaration, List<FormalParameters.Parameter>)> getConstructorParameters(?List<mlsub.typing.AtomicConstraint> constraints, mlsub.typing.Monotype[] typeParameters) { let supTC = definition.getSuperClass(); let ?NiceClass sup = (supTC == null) ? null : NiceClass.get(supTC); List<(?MethodDeclaration, List<FormalParameters.Parameter>)> res; if (sup == null) res = this.getNativeConstructorParameters(cast(supTC)); else res = cast(sup).getParentConstructorParameters(typeParameters, constraints); /** This must be done in a given class for every subclass, since they have different type parameters. */ if ((! overrides.isEmpty()) || (! valueOverrides.isEmpty())) for (cparams : res) { (?MethodDeclaration m, List<FormalParameters.Parameter> params) = cparams; for (or : overrides) or.updateConstructorParameter(params); for (valueOverride : valueOverrides) valueOverride.updateConstructorParameter(params); } if (! fields.isEmpty()) for (cparams : res) { (?MethodDeclaration m, List<FormalParameters.Parameter> params) = cparams; for (field : fields) params.add(field.asParameter()); } if (definition.resolvedConstraints != null) notNull(constraints).addAll(notNull(definition.resolvedConstraints)); return res; } /** This must be done only once per class. */ private void checkFields(List<FormalParameters.Parameter> allFields) { for (int f = 0; f < fields.size(); f++) fields[f].checkNoDuplicate(allFields, f); List<LocatedString> names = overrides.map(OverridenField o => o.sym.getName()); names.addAll(valueOverrides.map(ValueOverride o => o.name())); for (int i = 0; i < names.size(); i++) for (int k = i+1; k < names.size(); k++) if (names[i].equals(names[k])) User.error(names[k], "A field override of the same field exists in this class"); } private void createDefaultConstructors() { if (definition.inInterfaceFile()) // The constructors are loaded from the compiled package. return; if (this.isInterface()) return; ?List<mlsub.typing.AtomicConstraint> constraints; let binders = definition.getBinders(); if (binders == null) constraints = null; else constraints = new LinkedList(); mlsub.typing.Monotype[] typeParameters = definition.getTypeParameters(); List<(?MethodDeclaration, List<FormalParameters.Parameter>)> allConstructorParams = this.getConstructorParameters(constraints, typeParameters); mlsub.typing.Constraint cst; if (binders != null) cst = new mlsub.typing.Constraint(binders, constraints == null ? null : constraints.toArray()); else cst = mlsub.typing.Constraint.True; constructorMethod = cast(new Constructor[allConstructorParams.size()]); for (int i = 0; i < allConstructorParams.size(); i++) { (?MethodDeclaration parent, List<FormalParameters.Parameter> params) = allConstructorParams[i]; // Check only once. if (i == 0) this.checkFields(params); FormalParameters values = new FormalParameters(params.toArray()); notNull(constructorMethod)[i] = new DefaultConstructor (this, true, definition.location(), values, cst, Monotype.resolve(definition.getLocalScope(), values.types()), Monotype.sure(new mlsub.typing.MonotypeConstructor(definition.tc, definition.getTypeParameters())), fields: fields, parent: parent); TypeConstructors.addConstructor(definition.tc, notNull(constructorMethod)[i]); } } precompile() { // We have to do this after resolution, so that bytecode types are known, // but before compilation. for (field : fields) field.createField(); } compile() { this.recompile(); this.createSerialUIDField(); } /** Called instead of compile if the package is up-to-date. */ recompile() { // This needs to be done even if we don't recompile, // since classes are always regenerated. if (constructorMethod != null) for (int i = 0; i < notNull(constructorMethod).length; i++) notNull(constructorMethod)[i].getCode(); // Take into account external interface implementations, which // can add new interfaces to implement in the bytecode. classe.supers = cast(this.computeSupers()); classe.recomputeInterfaces(); } private gnu.expr.Expression[?] computeSupers() { List<gnu.expr.Expression> res = new ArrayList(); let superClass = definition.getSuperClass(); if (superClass != null) res.add(typeExpression(superClass)); for (intf : definition.interfaces) { let ?mlsub.typing.TypeConstructor assocTC = intf.associatedTC(); if (assocTC != null) res.add(typeExpression(assocTC)); } if (definition.javaInterfaces != null) for (itf : notNull(definition.javaInterfaces)) res.add(typeExpression(notNull(itf))); if (res.isEmpty()) return null; return res.toArray(); } /** This native method is redefined for this Nice class. */ addJavaMethod(method) = classe.addMethod(method); private gnu.expr.LambdaExp createJavaMethod(String name, gnu.bytecode.Method likeMethod, gnu.expr.Expression[] params) { return nice.tools.code.Gen.createMemberMethod(name, this.getClassExp().getType(), likeMethod.getParameterTypes(), likeMethod.getReturnType(), params); } /** Returns an expression to call a super method from outside a class method. This is needed because the JVM restricts call to a specific implementation to occur inside a method of the same class. So this generates a stub class method that calls the desired super method, and return a reference to this stub. */ callSuperMethod(superMethod) { gnu.expr.Expression[] params = cast(new gnu.expr.Expression [superMethod.getParameterTypes().length + 1]); let lambda = this.createJavaMethod("$super$" + superMethod.getName(), superMethod, params); nice.tools.code.Gen.setMethodBody(lambda, new gnu.expr.ApplyExp(new gnu.expr.QuoteExp( gnu.expr.PrimProcedure.specialCall(superMethod)), params)); return this.addJavaMethod(lambda); } void createSerialUIDField() { if (serialVersionUIDValue == null) return; let fieldDecl = classe.addDeclaration("serialVersionUID", nice.tools.code.SpecialTypes.longType); fieldDecl.setSimple(false); fieldDecl.setCanRead(true); fieldDecl.setFlag(gnu.expr.Declaration.IS_CONSTANT); fieldDecl.setSpecifiedPrivate(true); fieldDecl.setFlag(gnu.expr.Declaration.STATIC_SPECIFIED); fieldDecl.setFlag(gnu.expr.Declaration.TYPE_SPECIFIED); fieldDecl.noteValue(new gnu.expr.QuoteExp(serialVersionUIDValue, nice.tools.code.SpecialTypes.longType)); } importMethod(gnu.bytecode.Method method) { if (method.isConstructor()) return ImportedConstructor.load(this, method); if (method.getArity() == 0 && method.getName().equals("$init")) initializerMethod = nice.tools.code.Gen.superCaller(method); return null; } toString() = definition.toString(); } let gnu.bytecode.Method cloneMethod = notNull(gnu.bytecode.Type.pointer_type).getDeclaredMethod("clone", 0); class ThisSymbol extends MonoSymbol { compile() = notNull(declaringClass.thisExp); final CNiceClass declaringClass; } NiceClass createNiceClass(ClassDefinition cdef) = new CNiceClass(definition: cdef); private TypeSymbol asTypeSymbol(mlsub.typing.Monotype type) { if (type instanceof TypeSymbol) return type; assert (type instanceof mlsub.typing.MonotypeConstructor); return type.getTC(); } private gnu.expr.Expression typeExpression(TypeConstructor tc) { let c = ClassDefinition.get(tc); if (c != null && c.implementation instanceof NiceClass) { CNiceClass nc = cast(c.implementation); return nc.classe; } else return new gnu.expr.QuoteExp(nice.tools.code.Types.javaType(tc)); } Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.91 retrieving revision 1.92 diff -C2 -d -r1.91 -r1.92 *** NiceClass.java 15 Oct 2004 12:56:21 -0000 1.91 --- NiceClass.java 5 Nov 2004 14:57:57 -0000 1.92 *************** *** 2,6 **** /* N I C E */ /* A high-level object-oriented research language */ ! /* (c) Daniel Bonniot 2002 */ /* */ /* This program is free software; you can redistribute it and/or modify */ --- 2,6 ---- /* N I C E */ /* A high-level object-oriented research language */ ! /* (c) Daniel Bonniot 2004 */ /* */ [...1219 lines suppressed...] ! /**************************************************************** ! * Misc. ! ****************************************************************/ ! public String toString() { return definition.toString(); } ! private NewField[] fields; ! private OverridenField[] overrides; ! private List valueOverrides; ! private Long serialVersionUIDValue; } --- 80,87 ---- stub. */ ! abstract gnu.expr.Expression callSuperMethod(gnu.bytecode.Method superMethod); ! abstract public Definition importMethod(gnu.bytecode.Method method); ! abstract public mlsub.typing.Monotype[] getTypeParameters(); } --- NEW FILE: nicefield.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. */ /* */ /**************************************************************************/ /** A field or field override in a Nice class. */ abstract class NiceField { CNiceClass declaringClass; MonoSymbol sym; ?Expression value; NiceFieldAccess method = cast(null); { sym.propagate = Node.none; method = createNiceFieldAccess(this); declaringClass.definition.addChild(method); } ClassDefinition getClassDefinition() = declaringClass.definition; LocatedString getName() = sym.getName(); boolean hasName(LocatedString name) = sym.hasName(name); boolean isFinal(); void resolve(VarScope scope, TypeScope typeScope) { sym.type = notNull(sym.syntacticType).resolve(typeScope); if (nice.tools.typing.Types.isVoid(sym.type)) bossa.util.User.error(sym, "A field cannot have void type"); value = dispatch.analyse(value, scope, typeScope); } FormalParameters.Parameter asParameter() { Monotype type = notNull(sym.syntacticType); if (value == null) return new FormalParameters.NamedParameter(type, sym.getName(), true); else return new FormalParameters.OptionalParameter (type, sym.getName(), true, value); } void typecheck() { if (value != null) { declaringClass.enterTypingContext(); mlsub.typing.Polytype declaredType = sym.getType(); value = notNull(value).resolveOverloading(declaredType); dispatch.typecheck(notNull(value)); try { Typing.leq(notNull(value).getType(), declaredType); } catch (mlsub.typing.TypingEx ex) { throw assignmentError(notNull(value), sym.getName().toString(), sym.getType().toString(), notNull(value)); } } } toString() = sym + (value == null ? "" : " = " + value); } final class NewField extends NiceField { boolean isFinal_; boolean isTransient; boolean isVolatile; public ?String docString; isFinal() = isFinal_; void createField() { let decl = declaringClass.classe.addField (sym.name.toString(), nice.tools.code.Types.javaType(sym.type)); method.fieldDecl = decl; decl.setFlag(isFinal_, gnu.expr.Declaration.IS_CONSTANT); decl.setFlag(isTransient, gnu.expr.Declaration.TRANSIENT); decl.setFlag(isVolatile , gnu.expr.Declaration.VOLATILE); if (! declaringClass.definition.inInterfaceFile()) { String fname = sym.getName().toString(); String suffix = Character.toUpperCase(fname.charAt(0)) + fname.substring(1); this.createGetter(suffix); if (!isFinal_) this.createSetter(suffix); } } void createGetter(String nameSuffix) { gnu.expr.Expression[] params = cast(new gnu.expr.Expression[1]); let getter = nice.tools.code.Gen.createMemberMethod("get"+nameSuffix, declaringClass.classe.getType(), null, notNull(method.fieldDecl).getType(), params); nice.tools.code.Gen.setMethodBody(getter, NiceUtils.doInline(new nice.tools.code.GetFieldProc(method.fieldDecl), params[0])); declaringClass.classe.addMethod(getter); } void createSetter(String nameSuffix) { gnu.expr.Expression[] params = cast(new gnu.expr.Expression[2]); gnu.bytecode.Type[] argTypes = [notNull(method.fieldDecl).getType()]; let setter = nice.tools.code.Gen.createMemberMethod("set"+nameSuffix, declaringClass.classe.getType(), argTypes, notNull(method.fieldDecl).getType(), params); nice.tools.code.Gen.setMethodBody(setter, NiceUtils.doInline(new nice.tools.code.SetFieldProc(method.fieldDecl), params[0], params[1])); declaringClass.classe.addMethod(setter); } void checkNoDuplicate(List<FormalParameters.Parameter> fields, int rankInThisClass) { /* We check that there is no duplicate in all the inherited fields, but also in the fields of this class stricly before this one. */ int max = fields.size() - declaringClass.fields.size() + rankInThisClass; String name = sym.getName().toString(); for (int i = 0; i < max; i++) if (fields[i].match(name)) bossa.util.User.error(sym, (max - i >= declaringClass.fields.size()) ? "A field with the same name exists in a super-class" : "A field with the same name exists in this class"); } toString()= (isFinal_ ? "final " : "") + super; } final class OverridenField extends NiceField { isFinal() = true; /** Update the type and default values for the constructor, according to this overriding. */ void updateConstructorParameter(List<FormalParameters.Parameter> inherited) { String name = sym.getName().toString(); Monotype type = notNull(sym.syntacticType); for (int i = 0; i < inherited.size(); i++) { let param = inherited[i]; if (param.match(name)) { if (value != null) inherited[i] = new FormalParameters.OptionalParameter(type, sym.getName(), true, value, param.value() == null || param.isOverriden()); else param.resetType(type); } } } typecheck() { ?gnu.expr.Declaration decl = null; let parent = declaringClass.getParent(); if (parent != null) decl = parent.getOverridenField(this, value == null); if (decl == null) throw bossa.util.User.error(sym, "No field with this name exists in a super-class"); method.fieldDecl = decl; super; } /** @param checkValue Whether to check that the original field's value, if it exists, must be checked against the overriden type. @return the checkValue to be used for other versions of this field higher up in the hierarchy. */ boolean checkOverride(NiceField original, boolean checkValue) { declaringClass.enterTypingContext(); mlsub.typing.Monotype originalType = notNull(original.sym.syntacticType).resolve (original.declaringClass.translationScope(declaringClass)); try { Typing.leq(this.sym.type, originalType); } catch (TypingEx ex) { User.error(this.sym, "The new type must be a subtype of the original type declared in " + original.declaringClass + ".\n" + "Original type: " + originalType); } if (checkValue && original.value != null) { this.checkValue(notNull(original.value), original.declaringClass); return false; } return checkValue; } void checkOverride(ValueOverride original) { this.checkValue(original.value, original.declaringClass); } private void checkValue(Expression value, NiceClass location) { try { Typing.leq(value.getType(), this.sym.getType()); } catch (mlsub.typing.TypingEx ex) { User.error(sym, "The default value declared in " + location + "\nis not compatible with the overriden type"); } } toString() = "override " + super; } public final class ValueOverride { CNiceClass declaringClass; LocatedString name; Expression value; boolean hasName(LocatedString name) = this.name.equals(name); void updateConstructorParameter(List<FormalParameters.Parameter> inherited) { for (int i = 0; i < inherited.size(); i++) { let param = inherited[i]; if (param.match(name.toString())) inherited[i] = new FormalParameters.OptionalParameter(param.type, name, true, value, param.value() == null || param.isOverriden()); } } void resolve(VarScope scope, TypeScope typeScope) { value = analyse(value, scope, typeScope); } void typecheck() { boolean exists = false; let parent = declaringClass.getParent(); if (parent != null) exists = parent.checkValueOverride(name, value); if (! exists) throw bossa.util.User.error(name, "No field with this name exists in a super-class"); } } /** @return the scope that maps the type parameters of the other class to the corresponding symbol in the constructor of this class. */ private TypeScope translationScope(CNiceClass this, CNiceClass other) { let binders = other.definition.getBinders(); let ourBinders = this.definition.getBinders(); TypeScope scope = Node.getGlobalTypeScope(); if (binders != null) { scope = new TypeScope(scope); for (int i = 0; i < binders.length; i++) try { scope.addMapping(notNull(ourBinders)[i].toString(), binders[i]); } catch(TypeScope.DuplicateName e) {} } return scope; } --- NEW FILE: defaultconstructor.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.*; /** A constructor automatically generated from the list of field of the class whose instances it constructs. */ class DefaultConstructor extends Constructor { { this.addConstructorCallSymbol(); } List<NewField> fields; ?MethodDeclaration parent; /** Call the constructor, with all the arguments. */ private ?gnu.expr.Expression initialize = null; /** Call the constructor, with all the arguments, with an implicit this argument. */ private ?gnu.expr.Expression initializeFromConstructor = null; /** Call the constructor, with only non-default arguments. */ private ?gnu.expr.Expression initializeOmitDefaults = null; /** Instantiate the class, calling the constructor with all the arguments. */ private ?gnu.expr.Expression instantiate = null; getInitializationCode(implicitThis) { this.getCode(); return notNull(initializeFromConstructor); } getConstructorInvocation(omitDefaults) { this.getCode(); return // lambdaOmitDefaults is null if the two versions are identical omitDefaults && initializeOmitDefaults != null ? notNull(initializeOmitDefaults) : notNull(initialize); } computeCode() { this.createBytecode(true); this.createBytecode(false); return notNull(instantiate); } /** @param omitDefaults if true, do not take the value of fields with default values as parameters, but use that default instead. */ private void createBytecode(boolean omitDefaults) { gnu.bytecode.ClassType thisType = cast(this.javaReturnType()); let thisDecl = new gnu.expr.Declaration("this"); thisDecl.setType(thisType); let thisExp = new gnu.expr.ThisExp(thisDecl); let fullArgs = notNull(parameters.getMonoSymbols()); let fullArgTypes = this.javaArgTypes(); List<MonoSymbol> args = new LinkedList(); List<gnu.bytecode.Type> argTypes = new LinkedList(); for (int i = 0; i < parameters.size; i++) { if (omitDefaults && parameters.hasDefaultValue(i)) continue; args.add(fullArgs[i]); argTypes.add(fullArgTypes[i]); } // Do not create a second constructor omiting defaults if there is // no default to omit! if (omitDefaults && args.size() == fullArgs.length) return; gnu.bytecode.Type[] argTypesArray = argTypes.toArray(); MonoSymbol[] argsArray = args.toArray(); if (classe.getDefinition().inInterfaceFile()) throw new Error("Constructors are loaded from the compiled package"); let lambda = nice.tools.code.Gen.createConstructor (thisDecl, argTypesArray, argsArray); lambda.setSuperCall(this.callSuper(thisExp, fullArgs, omitDefaults)); nice.tools.code.Gen.setMethodBody(lambda, this.body(thisExp, fullArgs, omitDefaults)); classe.getClassExp().addMethod(lambda); // Add attributes useful for the nice compiler. These are not needed // for the version omitting defaults, since that one is only there for // Java users' sake. if (! omitDefaults) { lambda.addBytecodeAttribute(parameters.asBytecodeAttribute()); lambda.addBytecodeAttribute(new gnu.bytecode.MiscAttr("default")); } if (omitDefaults) { initializeOmitDefaults = new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(lambda)); } else { initialize = new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(lambda)); initializeFromConstructor = new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(lambda, true)); instantiate = new gnu.expr.QuoteExp(new gnu.expr.InstantiateProc(lambda)); } } private gnu.expr.Expression callSuper(gnu.expr.Expression thisExp, MonoSymbol[] args, boolean omitDefaults) { int len = args.length - fields.size(); List<gnu.expr.Expression> superArgs = new LinkedList(); superArgs.add(thisExp); for (int i = 0; i < len; i++) { if (! (omitDefaults && parameters.hasDefaultValue(i))) superArgs.add(args[i].compile()); } // A null parent means no parent class: call the Object constructor. let superExp = parent == null ? objectConstructor : notNull(parent).getConstructorInvocation(omitDefaults); return new gnu.expr.ApplyExp(superExp, superArgs.toArray()); } private gnu.expr.Expression body(gnu.expr.Expression thisExp, MonoSymbol[] fullArgs, boolean omitDefaults) { List<gnu.expr.Expression> body = new ArrayList(); let superArgs = fullArgs.length - fields.size(); for (int i = 0; i < fields.size(); i++) { let value = fields[i].value; gnu.expr.Expression fieldValue; if (!omitDefaults || value == null) // Use the provided parameter. fieldValue = fullArgs[superArgs + i].compile(); else // Use the default value. fieldValue = value.compile(); body.add(fields[i].method.compileAssign(thisExp, fieldValue)); } let initializer = classe.getInitializer(); if (initializer != null) body.add(new gnu.expr.IfExp( nice.tools.code.Gen.isOfClass(thisExp, classe.getClassExp().getType(), false), new gnu.expr.ApplyExp(initializer, [thisExp]), gnu.expr.QuoteExp.voidExp)); if (body.isEmpty()) return gnu.expr.QuoteExp.voidExp; return new gnu.expr.BeginExp(body.toArray()); } } let gnu.expr.Expression objectConstructor = new gnu.expr.QuoteExp (new gnu.expr.InitializeProc( notNull(gnu.bytecode.Type.pointer_type).getDeclaredMethod("<init>", 0))); Index: NiceUtils.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceUtils.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NiceUtils.java 28 Jul 2004 14:40:33 -0000 1.1 --- NiceUtils.java 5 Nov 2004 14:57:57 -0000 1.2 *************** *** 20,23 **** --- 20,28 ---- } + public static gnu.expr.Expression doInline(gnu.mapping.Procedure2 proc, gnu.expr.Expression arg1, gnu.expr.Expression arg2) + { + return nice.tools.code.Inline.inline(proc, arg1, arg2); + } + } Index: new.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/new.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** new.nice 13 Oct 2004 23:22:22 -0000 1.4 --- new.nice 5 Nov 2004 14:57:57 -0000 1.5 *************** *** 60,64 **** definition.resolve(); ! ?LinkedList<VarSymbol> constructors = TypeConstructors.getConstructors(tc); if (constructors == null) { --- 60,64 ---- definition.resolve(); ! ?LinkedList<MethodDeclaration.Symbol> constructors = TypeConstructors.getConstructors(tc); if (constructors == null) { *************** *** 73,79 **** // the list of constructors must be cloned, as // OverloadedSymbolExp removes elements from it ! constructors = constructors.clone(); ! ! function = createOverloadedSymbolExp(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(notNull(constructors)), new LocatedString("new " + tc, this.location())); } Index: EnumDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/EnumDefinition.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** EnumDefinition.java 14 Oct 2004 15:42:11 -0000 1.16 --- EnumDefinition.java 5 Nov 2004 14:57:57 -0000 1.17 *************** *** 2,6 **** /* N I C E */ /* A high-level object-oriented research language */ ! /* (c) Daniel Bonniot 2003 */ /* */ /* This program is free software; you can redistribute it and/or modify */ --- 2,6 ---- /* 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 */ *************** *** 36,40 **** new MonotypeConstructor(new TypeIdent(new LocatedString("nice.lang.Enum",name.location())), null, this.location()), interfaces,null); ! NiceClass impl = new NiceClass(classDef); int fieldsCount = fields.size(); if (fieldsCount > 0) --- 36,40 ---- new MonotypeConstructor(new TypeIdent(new LocatedString("nice.lang.Enum",name.location())), null, this.location()), interfaces,null); ! NiceClass impl = dispatch.createNiceClass(classDef); int fieldsCount = fields.size(); if (fieldsCount > 0) *************** *** 42,55 **** List newFields = new ArrayList(fieldsCount); for (Iterator it = fields.iterator(); it.hasNext(); ) ! newFields.add(impl.makeField((MonoSymbol)it.next(), null, true, ! false, false, null)); - impl.setFields(newFields); } - else - impl.setFields(null); - - impl.setOverrides(null); - impl.setValueOverrides(null); if (! inInterfaceFile()) --- 42,49 ---- List newFields = new ArrayList(fieldsCount); for (Iterator it = fields.iterator(); it.hasNext(); ) ! impl.addField((MonoSymbol)it.next(), null, true, ! false, false, null); } if (! inInterfaceFile()) --- DefaultConstructor.java DELETED --- --- NEW FILE: nicefieldaccess.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.*; /** A field access in a Nice class. In terms of scoping, this is the symbol that is returned when the access to a field is done, either a 'get' or a 'set'. */ public class NiceFieldAccess extends FieldAccess { final NiceField field; isFinal() = field.isFinal(); printInterface(s) { bossa.util.Internal.error("Should not be part of the module interface"); } toString() { return "" + field.sym.type + " " + field.getClassDefinition().name + "." + field.getName(); } } NiceFieldAccess createNiceFieldAccess(NiceField field) { let classDef = field.getClassDefinition(); let argType = Monotype.sure(classDef.lowlevelMonotype()); return new NiceFieldAccess(field.getName(), Constraint.create(classDef.getBinders()), new FormalParameters([new FormalParameters.Parameter(Monotype.create(argType))]), field.sym.syntacticType, field: field); } private FormalParameters makeList(mlsub.typing.Monotype t) { return new FormalParameters([new FormalParameters.Parameter(Monotype.create(t))]); } Index: MethodBodyDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodBodyDefinition.java,v retrieving revision 1.154 retrieving revision 1.155 diff -C2 -d -r1.154 -r1.155 *** MethodBodyDefinition.java 11 Oct 2004 13:55:35 -0000 1.154 --- MethodBodyDefinition.java 5 Nov 2004 14:57:57 -0000 1.155 *************** *** 76,80 **** Pattern[] res = new Pattern[formals.size() + 1]; res[0] = bossa.syntax.dispatch.createPattern(new LocatedString("this", loc), ! new TypeIdent(container.definition.getName())); int n = 1; for(Iterator f = formals.iterator(); f.hasNext(); n++) --- 76,80 ---- Pattern[] res = new Pattern[formals.size() + 1]; res[0] = bossa.syntax.dispatch.createPattern(new LocatedString("this", loc), ! new TypeIdent(container.getName())); int n = 1; for(Iterator f = formals.iterator(); f.hasNext(); n++) --- NiceFieldAccess.java DELETED --- |
From: Arjan B. <ar...@us...> - 2004-11-05 14:58:10
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8798/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Converted NiceClass, DefaultConstructor and Nice field classes to nice code. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.271 retrieving revision 1.272 diff -C2 -d -r1.271 -r1.272 *** Parser.jj 14 Oct 2004 15:42:10 -0000 1.271 --- Parser.jj 5 Nov 2004 14:57:57 -0000 1.272 *************** *** 966,970 **** } ! List getField(NiceClass c, List fields, List overrides, boolean storeDocString): { MonoSymbol field; --- 966,970 ---- } ! void getField(CNiceClass c, boolean storeDocString): { MonoSymbol field; *************** *** 998,1006 **** { if (isOverride) ! overrides.add(c.makeOverride(field, value)); else ! fields.add(c.makeField(field, value, isFinal, isTransient, isVolatile, docString)); ! ! return overrides; } } --- 998,1004 ---- { if (isOverride) ! c.addOverride(field, value); else ! c.addField(field, value, isFinal, isTransient, isVolatile, docString); } } *************** *** 1051,1072 **** ( "{" ! { NiceClass impl = new NiceClass(res); } // internal fields and methods - { List fields = new LinkedList(), overrides = new LinkedList(), - methods = new ArrayList(5), initializers = new LinkedList(), - valueOverrides = new LinkedList(); } ( // Initializer { Statement init; } init = Block() ! { initializers.add(init); } | LOOKAHEAD ( "override" ident() "=" ) { LocatedString fname; Expression value;} "override" fname=ident() "=" value=Expression() ";" ! { valueOverrides.add(impl.makeValueOverride(fname, value)); } | LOOKAHEAD( fieldLookahead() ) ! overrides = getField(impl, fields, overrides, storeDocString) | { Definition m; Token t = getToken(1); boolean isOverride = false; } [ "public" | "private" ] --- 1049,1067 ---- ( "{" ! { CNiceClass impl = new CNiceClass(res); List methods = new ArrayList();} // internal fields and methods ( // Initializer { Statement init; } init = Block() ! { impl.addInitializer(init); } | LOOKAHEAD ( "override" ident() "=" ) { LocatedString fname; Expression value;} "override" fname=ident() "=" value=Expression() ";" ! { impl.addValueOverride(fname, value); } | LOOKAHEAD( fieldLookahead() ) ! getField(impl, storeDocString) | { Definition m; Token t = getToken(1); boolean isOverride = false; } [ "public" | "private" ] *************** *** 1086,1093 **** "}" { - impl.setFields(fields); - impl.setOverrides(overrides); - impl.setValueOverrides(valueOverrides); - impl.setInitializers(initializers); res.setImplementation(impl); definitions.addAll(methods); --- 1081,1084 ---- |
From: Daniel B. <bo...@us...> - 2004-11-05 14:25:51
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32529/testsuite/compiler/classes Added Files: visibility.testsuite Log Message: Testcase for bug #1060712. --- NEW FILE: visibility.testsuite --- /// FAIL bug // bug #1060712 //let a = new A(); // this would trigger a verification error /// Toplevel // Try to extends a class that has only private constructors class A extends javax.swing.KeyStroke {} |
From: Arjan B. <ar...@us...> - 2004-11-03 12:08:11
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23248/F:/nice/src/bossa/link Modified Files: Alternative.java Dispatch.java Log Message: Extended the short coverage test to detect non-ambigious alternatives in more cases. Index: Dispatch.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Dispatch.java,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** Dispatch.java 7 Aug 2004 14:20:27 -0000 1.71 --- Dispatch.java 3 Nov 2004 12:07:54 -0000 1.72 *************** *** 164,168 **** if (! (Alternative.leq(altA, altB) || Alternative.disjoint(altA, altB))) ! return false; } --- 164,183 ---- if (! (Alternative.leq(altA, altB) || Alternative.disjoint(altA, altB))) ! { ! Alternative glb = Alternative.greatestLowerBound(altA, altB); ! if (glb == null) ! return false; ! ! boolean glbMatch = false; ! for (int j = i-1; j >= 0; j--) ! if (Alternative.leq(glb, (Alternative)alternatives.get(j))) ! { ! glbMatch = true; ! break; ! } ! ! if (! glbMatch) ! return false; ! } } Index: Alternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Alternative.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** Alternative.java 13 Oct 2004 14:27:49 -0000 1.55 --- Alternative.java 3 Nov 2004 12:07:54 -0000 1.56 *************** *** 93,96 **** --- 93,112 ---- } + static Alternative greatestLowerBound(Alternative a, Alternative b) + { + Pattern[] pats = new Pattern[a.patterns.length]; + for (int i = 0; i < a.patterns.length; i++) + { + if (bossa.syntax.dispatch.leq(a.patterns[i], b.patterns[i])) + pats[i] = a.patterns[i]; + else if (bossa.syntax.dispatch.leq(b.patterns[i], a.patterns[i])) + pats[i] = b.patterns[i]; + else + return null; + } + + return new Alternative(a.methodName, pats); + } + /** * Tests the matching of tags against a method alternative. |
From: Daniel B. <bo...@us...> - 2004-10-20 10:52:31
|
Update of /cvsroot/nice/Nice/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20125 Modified Files: new.xsl Log Message: Added site search box. Index: new.xsl =================================================================== RCS file: /cvsroot/nice/Nice/web/new.xsl,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** new.xsl 10 Sep 2004 13:04:06 -0000 1.17 --- new.xsl 20 Oct 2004 10:52:12 -0000 1.18 *************** *** 229,232 **** --- 229,258 ---- <br /> + <!-- SEARCH sidebox --> + <table bgcolor="#000000" border="0" cellpadding="0" cellspacing="0" width="100%"> + <tr> + <td> + <table border="0" cellpadding="3" cellspacing="1" width="100%"> + <tr> + <td bgcolor="#cccccc"> + + <div align="center"> + <form method="get" action="http://www.google.com/custom"> + <input type="text" name="q" class="find-text" maxlength="255" value="" /> + <input type="hidden" name="domains" value="nice.sourceforge.net" /> + <input type="hidden" name="sitesearch" value="nice.sourceforge.net" /> + <input type="submit" name="sa" class="find-submit" value="Search" /> + </form> + </div> + + </td> + </tr> + </table> + </td> + </tr> + </table> + <!-- end SEARCH sidebox --> + <br /> + <div align="center"> <a href="http://sourceforge.net/projects/nice"> |
From: Daniel B. <bo...@us...> - 2004-10-15 12:56:33
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12386/src/bossa/syntax Modified Files: NiceClass.java Log Message: Fixed field type override checking when there is a value override higher up in the hierarchy. Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.90 retrieving revision 1.91 diff -C2 -d -r1.90 -r1.91 *** NiceClass.java 15 Oct 2004 11:39:17 -0000 1.90 --- NiceClass.java 15 Oct 2004 12:56:21 -0000 1.91 *************** *** 409,420 **** if (checkValue && original.value != null) { ! try { ! Typing.leq(original.value.getType(), this.sym.getType()); ! } ! catch (mlsub.typing.TypingEx ex) { ! User.error(sym, "The default value declared in " + ! original.getDeclaringClass() + ! "\nis not compatible with the overriden type"); ! } return false; } --- 409,413 ---- if (checkValue && original.value != null) { ! checkValue(original.value, original.getDeclaringClass()); return false; } *************** *** 423,426 **** --- 416,436 ---- } + void checkOverride(ValueOverride original) + { + checkValue(original.value, original.getDeclaringClass()); + } + + private void checkValue(Expression value, NiceClass location) + { + try { + Typing.leq(value.getType(), this.sym.getType()); + } + catch (mlsub.typing.TypingEx ex) { + User.error(sym, "The default value declared in " + + location + + "\nis not compatible with the overriden type"); + } + } + public String toString() { *************** *** 437,440 **** --- 447,460 ---- } + NiceClass getDeclaringClass() + { + return NiceClass.this; + } + + boolean hasName(String name) + { + return this.name.toString().equals(name); + } + void updateConstructorParameter(List inherited) { *************** *** 497,501 **** for (Iterator it = valueOverrides.iterator(); it.hasNext(); ) ((ValueOverride)it.next()).resolve(definition.scope, localScope); - } --- 517,520 ---- *************** *** 527,530 **** --- 546,561 ---- checkValue = field.checkOverride(overrides[i], checkValue); + if (checkValue) + for (Iterator it = valueOverrides.iterator(); it.hasNext(); ) + { + ValueOverride original = (ValueOverride) it.next(); + if (original.hasName(name)) + { + field.checkOverride(original); + checkValue = false; + break; + } + } + NiceClass parent = getParent(); if (parent != null) |
From: Daniel B. <bo...@us...> - 2004-10-15 12:56:33
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12386/testsuite/compiler/classes Modified Files: value-override.testsuite Log Message: Fixed field type override checking when there is a value override higher up in the hierarchy. Index: value-override.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/value-override.testsuite,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** value-override.testsuite 14 Oct 2004 15:42:11 -0000 1.1 --- value-override.testsuite 15 Oct 2004 12:56:21 -0000 1.2 *************** *** 89,93 **** } ! /// FAIL bug /// Toplevel class A { --- 89,93 ---- } ! /// FAIL /// Toplevel class A { *************** *** 98,101 **** } class C extends B { ! override /* /// FAIL HERE */ byte x; } --- 98,114 ---- } class C extends B { ! override byte /* /// FAIL HERE */ x; ! } ! ! /// FAIL ! let c = new C(); ! /// Toplevel ! class A { ! final List<int> x = new LinkedList(); ! } ! class B extends A { ! override x = new ArrayList(); ! } ! class C extends B { ! override LinkedList<int> /* /// FAIL HERE */ x; } |
From: Arjan B. <ar...@us...> - 2004-10-15 12:49:39
|
Update of /cvsroot/nice/Nice/testsuite/compiler/methods In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10732/F:/nice/testsuite/compiler/methods Modified Files: namedParameters.testsuite Log Message: Testcase for order of evaluation of named arguments. Index: namedParameters.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/methods/namedParameters.testsuite,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** namedParameters.testsuite 24 Nov 2003 15:09:00 -0000 1.1 --- namedParameters.testsuite 15 Oct 2004 12:49:29 -0000 1.2 *************** *** 8,9 **** --- 8,15 ---- void foo() {} + /// PASS bug + int i = 2; + (int a, int b) = foo(y: i, x: ++i); + assert a == 3 && b == 2; + /// Toplevel + (int, int) foo(int x, int y) = (x, y); |
From: Daniel B. <bo...@us...> - 2004-10-15 11:39:29
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27272/src/bossa/syntax Modified Files: NiceClass.java Log Message: Cleanup. Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.89 retrieving revision 1.90 diff -C2 -d -r1.89 -r1.90 *** NiceClass.java 14 Oct 2004 15:42:11 -0000 1.89 --- NiceClass.java 15 Oct 2004 11:39:17 -0000 1.90 *************** *** 29,33 **** /** Abstract syntax for a class definition. ! @version $Date$ @author Daniel Bonniot --- 29,33 ---- /** Abstract syntax for a class definition. ! @version $Date$ @author Daniel Bonniot *************** *** 56,60 **** { Field field = (Field)it.next(); ! if (field.isFinal() && field.sym.getName().toString().equals("serialVersionUID")) { it.remove(); --- 56,60 ---- { Field field = (Field)it.next(); ! if (field.isFinal() && field.hasName("serialVersionUID")) { it.remove(); *************** *** 97,101 **** private static NewField[] noFields = new NewField[0]; private static OverridenField[] noOverrides = new OverridenField[0]; ! static NiceClass get(TypeConstructor tc) { --- 97,101 ---- private static NewField[] noFields = new NewField[0]; private static OverridenField[] noOverrides = new OverridenField[0]; ! static NiceClass get(TypeConstructor tc) { *************** *** 136,140 **** * Fields ****************************************************************/ ! public Field makeField (MonoSymbol sym, Expression value, --- 136,140 ---- * Fields ****************************************************************/ ! public Field makeField (MonoSymbol sym, Expression value, *************** *** 184,191 **** abstract boolean isFinal(); void resolve(VarScope scope, TypeScope typeScope) { sym.type = sym.syntacticType.resolve(typeScope); ! if (nice.tools.typing.Types.isVoid(sym.type)) User.error(sym, "A field cannot have void type"); --- 184,196 ---- abstract boolean isFinal(); + boolean hasName(String name) + { + return sym.getName().toString().equals(name); + } + void resolve(VarScope scope, TypeScope typeScope) { sym.type = sym.syntacticType.resolve(typeScope); ! if (nice.tools.typing.Types.isVoid(sym.type)) User.error(sym, "A field cannot have void type"); *************** *** 217,221 **** try { Typing.leq(value.getType(), declaredType); ! } catch (mlsub.typing.TypingEx ex) { throw bossa.syntax.dispatch.assignmentError --- 222,226 ---- try { Typing.leq(value.getType(), declaredType); ! } catch (mlsub.typing.TypingEx ex) { throw bossa.syntax.dispatch.assignmentError *************** *** 230,234 **** sym + (value == null ? "" : " = " + value); } ! MonoSymbol sym; Expression value; --- 235,239 ---- sym + (value == null ? "" : " = " + value); } ! MonoSymbol sym; Expression value; *************** *** 273,277 **** } } ! void createGetter(String nameSuffix) { --- 278,282 ---- } } ! void createGetter(String nameSuffix) { *************** *** 321,325 **** super.toString(); } ! boolean isFinal; boolean isTransient; --- 326,330 ---- super.toString(); } ! boolean isFinal; boolean isTransient; *************** *** 406,413 **** try { Typing.leq(original.value.getType(), this.sym.getType()); ! } catch (mlsub.typing.TypingEx ex) { ! User.error(sym, "The default value declared in " + ! original.getDeclaringClass() + "\nis not compatible with the overriden type"); } --- 411,418 ---- try { Typing.leq(original.value.getType(), this.sym.getType()); ! } catch (mlsub.typing.TypingEx ex) { ! User.error(sym, "The default value declared in " + ! original.getDeclaringClass() + "\nis not compatible with the overriden type"); } *************** *** 424,428 **** } ! public final class ValueOverride { ValueOverride(LocatedString name, Expression value) --- 429,433 ---- } ! public final class ValueOverride { ValueOverride(LocatedString name, Expression value) *************** *** 489,493 **** for (int i = 0; i < overrides.length; i++) overrides[i].resolve(definition.scope, localScope); ! for (Iterator it = valueOverrides.iterator(); it.hasNext(); ) ((ValueOverride)it.next()).resolve(definition.scope, localScope); --- 494,498 ---- for (int i = 0; i < overrides.length; i++) overrides[i].resolve(definition.scope, localScope); ! for (Iterator it = valueOverrides.iterator(); it.hasNext(); ) ((ValueOverride)it.next()).resolve(definition.scope, localScope); *************** *** 507,514 **** for (int i = 0; i < fields.length; i++) ! if (fields[i].sym.getName().toString().equals(name)) { if (! fields[i].isFinal) ! User.error(field.sym, "The original field in class " + this + " is not final, so its type cannot be overriden"); --- 512,519 ---- for (int i = 0; i < fields.length; i++) ! if (fields[i].hasName(name)) { if (! fields[i].isFinal) ! User.error(field.sym, "The original field in class " + this + " is not final, so its type cannot be overriden"); *************** *** 517,523 **** return fields[i].method.fieldDecl; } ! for (int i = 0; i < overrides.length; i++) ! if (overrides[i].sym.getName().toString().equals(name)) checkValue = field.checkOverride(overrides[i], checkValue); --- 522,528 ---- return fields[i].method.fieldDecl; } ! for (int i = 0; i < overrides.length; i++) ! if (overrides[i].hasName(name)) checkValue = field.checkOverride(overrides[i], checkValue); *************** *** 531,543 **** private boolean checkValueOverride(LocatedString name, Expression value) { - Field original = null; for (int i = 0; i < fields.length; i++) ! if (fields[i].sym.getName().toString().equals(name.toString())) original = fields[i]; for (int i = 0; i < overrides.length; i++) ! if (overrides[i].sym.getName().toString().equals(name.toString())) original = overrides[i]; --- 536,547 ---- private boolean checkValueOverride(LocatedString name, Expression value) { Field original = null; for (int i = 0; i < fields.length; i++) ! if (fields[i].hasName(name.toString())) original = fields[i]; for (int i = 0; i < overrides.length; i++) ! if (overrides[i].hasName(name.toString())) original = overrides[i]; *************** *** 553,561 **** try { Typing.leq(value.getType(), declaredType); ! } catch (mlsub.typing.TypingEx ex) { User.error(name, "Value does not fit in the overriden field of type " + declaredType); } ! return true; } --- 557,565 ---- try { Typing.leq(value.getType(), declaredType); ! } catch (mlsub.typing.TypingEx ex) { User.error(name, "Value does not fit in the overriden field of type " + declaredType); } ! return true; } *************** *** 588,596 **** VarScope scope = definition.scope; ! mlsub.typing.Monotype thisType = Monotype.sure (new mlsub.typing.MonotypeConstructor (definition.tc, definition.getTypeParameters())); ! thisSymbol = new MonoSymbol(FormalParameters.thisName, thisType) { --- 592,600 ---- VarScope scope = definition.scope; ! mlsub.typing.Monotype thisType = Monotype.sure (new mlsub.typing.MonotypeConstructor (definition.tc, definition.getTypeParameters())); ! thisSymbol = new MonoSymbol(FormalParameters.thisName, thisType) { *************** *** 702,706 **** private void enterTypingContext() { ! if (entered || definition.classConstraint == null) return; Typing.enter(); --- 706,710 ---- private void enterTypingContext() { ! if (entered || definition.classConstraint == null) return; Typing.enter(); *************** *** 736,742 **** if (serialVersionUIDValue == null) return ""; ! return "final long serialVersionUID = " + serialVersionUIDValue + "L;\n"; ! } /**************************************************************** * Code generation --- 740,747 ---- if (serialVersionUIDValue == null) return ""; ! return "final long serialVersionUID = " + serialVersionUIDValue + "L;\n"; ! } ! /**************************************************************** * Code generation *************** *** 1099,1107 **** { TypeConstructor assocTC = interfaces[i].associatedTC(); ! if (assocTC == null) // This interface is abstract: ignore it. continue; ! res[--len] = typeExpression(assocTC); } --- 1104,1112 ---- { TypeConstructor assocTC = interfaces[i].associatedTC(); ! if (assocTC == null) // This interface is abstract: ignore it. continue; ! res[--len] = typeExpression(assocTC); } *************** *** 1165,1169 **** if (serialVersionUIDValue == null) return; ! Declaration fieldDecl = classe.addDeclaration("serialVersionUID", SpecialTypes.longType); fieldDecl.setSimple(false); --- 1170,1174 ---- if (serialVersionUIDValue == null) return; ! Declaration fieldDecl = classe.addDeclaration("serialVersionUID", SpecialTypes.longType); fieldDecl.setSimple(false); |
Update of /cvsroot/nice/Nice/regtest/basic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3107/regtest/basic Modified Files: optionalParameters.nice null.nice native.nice main.nice higherOrder.nice functions.nice exceptions.nice classes.nice arrays.nice Log Message: Removed the Any keyword. Index: higherOrder.nice =================================================================== RCS file: /cvsroot/nice/Nice/regtest/basic/higherOrder.nice,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** higherOrder.nice 20 Feb 2003 11:16:14 -0000 1.8 --- higherOrder.nice 14 Oct 2004 20:50:09 -0000 1.9 *************** *** 3,9 **** /** Tests higher order functions */ ! <Any T, Any U> U apply(T->U f, T x) = f(x); ! <Any T, Any U> U apply2(T->U f, T x); apply2(f, x) = f(x); --- 3,9 ---- /** Tests higher order functions */ ! <T, U> U apply(T->U f, T x) = f(x); ! <T, U> U apply2(T->U f, T x); apply2(f, x) = f(x); *************** *** 26,31 **** { println(id("ID")); ! println((<Any T>(T x)=>x)("LAMBDA")); ! println(apply(<Any T>(T x)=>x, "LAMBDA")); println(apply(nativeToString, "Using native methods as first class values")); println(apply(id(intIdentity), 42)); --- 26,31 ---- { println(id("ID")); ! println((<T>(T x)=>x)("LAMBDA")); ! println(apply(<T>(T x)=>x, "LAMBDA")); println(apply(nativeToString, "Using native methods as first class values")); println(apply(id(intIdentity), 42)); Index: functions.nice =================================================================== RCS file: /cvsroot/nice/Nice/regtest/basic/functions.nice,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** functions.nice 1 May 2002 21:13:26 -0000 1.7 --- functions.nice 14 Oct 2004 20:50:09 -0000 1.8 *************** *** 28,32 **** // Function with a parametric type ! <Any T> T identity(T x) = x; // anonymous argument is ok --- 28,32 ---- // Function with a parametric type ! <T> T identity(T x) = x; // anonymous argument is ok Index: arrays.nice =================================================================== RCS file: /cvsroot/nice/Nice/regtest/basic/arrays.nice,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** arrays.nice 17 Jan 2004 16:38:42 -0000 1.24 --- arrays.nice 14 Oct 2004 20:50:09 -0000 1.25 *************** *** 4,8 **** // Array<T> and T[] are synonyms ! <Any T> void p(Array<T>); p(a) { --- 4,8 ---- // Array<T> and T[] are synonyms ! <T> void p(Array<T>); p(a) { *************** *** 13,17 **** } ! <Any T> Array<T> rev(Array<T>); /* this is an interesting case to keep: dispatch on Array for a method that only accepts (polymorphic) arrays. --- 13,17 ---- } ! <T> Array<T> rev(Array<T>); /* this is an interesting case to keep: dispatch on Array for a method that only accepts (polymorphic) arrays. *************** *** 163,171 **** // We test how functions on polymorphic arrays deal with native type components ! <Any T> T getFirst(T[] a) = a[0]; // Use a polymorphic array as a collection after losing its type // because of bytecode types' monomorphicity. ! <Any T> void polyArrayAsCollection(T[] a) { a = id(a).map(id); } class V<T> --- 163,171 ---- // We test how functions on polymorphic arrays deal with native type components ! <T> T getFirst(T[] a) = a[0]; // Use a polymorphic array as a collection after losing its type // because of bytecode types' monomorphicity. ! <T> void polyArrayAsCollection(T[] a) { a = id(a).map(id); } class V<T> *************** *** 174,178 **** } ! <Any T> V<T> makeV() = new V(elements: cast(new T[1])); void test_polymorphism() --- 174,178 ---- } ! <T> V<T> makeV() = new V(elements: cast(new T[1])); void test_polymorphism() *************** *** 237,242 **** } ! <Any T> ?Array<T> arrayId(?Array<T> a) = id(a); // Using array -> Collection implicit conversion in the returned value ! <Any T> Collection<T> wrap(T x) = [ x ]; --- 237,242 ---- } ! <T> ?Array<T> arrayId(?Array<T> a) = id(a); // Using array -> Collection implicit conversion in the returned value ! <T> Collection<T> wrap(T x) = [ x ]; Index: optionalParameters.nice =================================================================== RCS file: /cvsroot/nice/Nice/regtest/basic/optionalParameters.nice,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** optionalParameters.nice 16 Jul 2003 19:41:55 -0000 1.9 --- optionalParameters.nice 14 Oct 2004 20:50:09 -0000 1.10 *************** *** 25,29 **** line 148 as of CVS version 1.41. */ ! //<Any T> void printAny(T what = "Nothing"); //printAny(what) = println(what); --- 25,29 ---- line 148 as of CVS version 1.41. */ ! //<T> void printAny(T what = "Nothing"); //printAny(what) = println(what); Index: main.nice =================================================================== RCS file: /cvsroot/nice/Nice/regtest/basic/main.nice,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** main.nice 26 Feb 2003 16:07:58 -0000 1.31 --- main.nice 14 Oct 2004 20:50:09 -0000 1.32 *************** *** 6,10 **** } ! <Any I> I id(I); id(x) = x; --- 6,10 ---- } ! <I> I id(I); id(x) = x; Index: classes.nice =================================================================== RCS file: /cvsroot/nice/Nice/regtest/basic/classes.nice,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** classes.nice 17 Jan 2004 16:38:42 -0000 1.14 --- classes.nice 14 Oct 2004 20:50:09 -0000 1.15 *************** *** 48,52 **** pToString(s@String) = "String"; ! <Any T> boolean isNull(T); isNull(x) = false; isNull(null) = true; --- 48,52 ---- pToString(s@String) = "String"; ! <T> boolean isNull(T); isNull(x) = false; isNull(null) = true; Index: exceptions.nice =================================================================== RCS file: /cvsroot/nice/Nice/regtest/basic/exceptions.nice,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** exceptions.nice 9 Jun 2003 22:22:57 -0000 1.11 --- exceptions.nice 14 Oct 2004 20:50:09 -0000 1.12 *************** *** 64,68 **** } ! <Any T> T neverReturns() { throw new Error(); --- 64,68 ---- } ! <T> T neverReturns() { throw new Error(); Index: native.nice =================================================================== RCS file: /cvsroot/nice/Nice/regtest/basic/native.nice,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** native.nice 15 Jun 2003 12:58:30 -0000 1.14 --- native.nice 14 Oct 2004 20:50:09 -0000 1.15 *************** *** 12,16 **** import java.io.*; ! //<Any T> T nop(T) = inline regtest.basic.Nop(); // rebind static and non-static fields --- 12,16 ---- import java.io.*; ! //<T> T nop(T) = inline regtest.basic.Nop(); // rebind static and non-static fields Index: null.nice =================================================================== RCS file: /cvsroot/nice/Nice/regtest/basic/null.nice,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** null.nice 15 Jun 2003 12:58:30 -0000 1.12 --- null.nice 14 Oct 2004 20:50:09 -0000 1.13 *************** *** 21,25 **** // Testing the coverage test ! <Any T1, Any T2 | T1 <: ?String , T2 <: T1> void cov(T1 s1, T2 s2); // The domain of cov is exactly (?String, ?String) --- 21,25 ---- // Testing the coverage test ! <T1, T2 | T1 <: ?String , T2 <: T1> void cov(T1 s1, T2 s2); // The domain of cov is exactly (?String, ?String) *************** *** 32,36 **** // nullness marker with a parameterized type in constraint ! <Any T | T <: ?List<String>> void cov2(T x) {} // Test inference of non-nullness --- 32,36 ---- // nullness marker with a parameterized type in constraint ! <T | T <: ?List<String>> void cov2(T x) {} // Test inference of non-nullness |
From: Daniel B. <bo...@us...> - 2004-10-14 20:35:45
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv316/testsuite/compiler/typing Modified Files: coverage.testsuite Log Message: When check class constraints during method coverage tests, make sure not to modify a type parameter, which would prevent some solutions to be found later. Index: coverage.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/typing/coverage.testsuite,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** coverage.testsuite 2 Sep 2003 19:57:52 -0000 1.2 --- coverage.testsuite 14 Oct 2004 20:35:34 -0000 1.3 *************** *** 24,25 **** --- 24,74 ---- method3(f@String) {} // this case is mandatory to cover method3 method3(/*/// FAIL HERE */null) {} + + /// FAIL + new B().foo(""); + /// Toplevel + abstract interface I<T> { + void /*/// FAIL HERE */ foo(T); + } + + class A<T> implements I<T> { + int x; + foo(t) { this.x = 0; } + } + + class B<T> implements I<T> { + // Missing implementation of foo. + } + + /// FAIL + new B().foo(""); + /// Toplevel + abstract interface I<T> { + void /*/// FAIL HERE */ foo(T); + } + + class A implements I<String> { + foo(t) { this.bar(); } + } + void bar(A a) {} + + + class B<T> implements I<T> { + // Missing implementation of foo. + } + + /// FAIL + new B().foo(0); + /// Toplevel + abstract interface I<T> { + void /*/// FAIL HERE */ foo(T); + } + + class A implements I<String> { + foo(t) { this.bar(); } + } + void bar(A a) {} + + class B implements I<int> { + // Missing implementation of foo. + } |
From: Daniel B. <bo...@us...> - 2004-10-14 20:35:45
|
Update of /cvsroot/nice/Nice/src/mlsub/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv316/src/mlsub/typing Modified Files: Enumeration.java Constraint.java Log Message: When check class constraints during method coverage tests, make sure not to modify a type parameter, which would prevent some solutions to be found later. Index: Enumeration.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/Enumeration.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Enumeration.java 13 Oct 2004 15:55:53 -0000 1.14 --- Enumeration.java 14 Oct 2004 20:35:34 -0000 1.15 *************** *** 374,378 **** Constraint constraint = def.getResolvedConstraint(); ! if (constraint == mlsub.typing.Constraint.True) return true; --- 374,378 ---- Constraint constraint = def.getResolvedConstraint(); ! if (mlsub.typing.Constraint.trivial(constraint)) return true; *************** *** 382,387 **** Monotype m = (Monotype) var; ! MonotypeConstructor type = ! new MonotypeConstructor(sol, def.getTypeParameters()); try { --- 382,399 ---- Monotype m = (Monotype) var; ! /* We don't want to modify var by reducing its domain, since that would ! prevent other valid solutions to be discovered later. ! Therefore we introduce a new tc, since what we want is to test ! the type parameters. ! ! Another approach would be to mark/backtrack here. That would at least ! require to slightly change the marking system, so that the exisisting ! domain is backed-up and the cloned one is used immediately, since ! the existing one is held by Satisfier. ! */ ! TypeConstructor tc = new TypeConstructor(sol.variance); ! Typing.introduce(tc); ! MonotypeConstructor type = ! new MonotypeConstructor(tc, def.getTypeParameters()); try { Index: Constraint.java =================================================================== RCS file: /cvsroot/nice/Nice/src/mlsub/typing/Constraint.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Constraint.java 17 Mar 2004 16:55:34 -0000 1.9 --- Constraint.java 14 Oct 2004 20:35:34 -0000 1.10 *************** *** 63,67 **** public static final Constraint True = null; ! public static final boolean hasBinders(Constraint c) { --- 63,67 ---- public static final Constraint True = null; ! public static final boolean hasBinders(Constraint c) { *************** *** 69,72 **** --- 69,77 ---- } + public static final boolean trivial(Constraint c) + { + return c == null || c.natoms == 0; + } + public TypeSymbol[] binders() { |
From: Arjan B. <ar...@us...> - 2004-10-14 18:16:07
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27528/F:/nice/stdlib/nice/lang Modified Files: bigint.nice Log Message: Added overloaded operators for BigDecimal. Index: bigint.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/bigint.nice,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** bigint.nice 29 Jul 2004 12:36:12 -0000 1.5 --- bigint.nice 14 Oct 2004 18:15:54 -0000 1.6 *************** *** 18,22 **** package nice.lang; ! // Operators to manipulate java.math.BigInteger. import java.math.*; --- 18,22 ---- package nice.lang; ! // Operators to manipulate java.math.BigInteger and java.math.BigDecimal. import java.math.*; *************** *** 48,49 **** --- 48,58 ---- */ `<`(BigInteger x, BigInteger y) = x.compareTo(y) < 0; + + + BigDecimal `-`(BigDecimal) = native BigDecimal BigDecimal.negate(); + BigDecimal `+`(BigDecimal, BigDecimal) = native BigDecimal BigDecimal.add(BigDecimal); + BigDecimal `-`(BigDecimal, BigDecimal) = native BigDecimal BigDecimal.subtract(BigDecimal); + BigDecimal `*`(BigDecimal, BigDecimal) = native BigDecimal BigDecimal.multiply(BigDecimal); + BigDecimal `/`(BigDecimal x, BigDecimal y) = x.divide(y, BigDecimal.ROUND_HALF_UP); + + `<`(BigDecimal x, BigDecimal y) = x.compareTo(y) < 0; |
From: Arjan B. <ar...@us...> - 2004-10-14 17:23:16
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13872/Nice Modified Files: NEWS Log Message: Added field default value overriding. Index: NEWS =================================================================== RCS file: /cvsroot/nice/Nice/NEWS,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** NEWS 11 Oct 2004 20:01:46 -0000 1.53 --- NEWS 14 Oct 2004 17:23:04 -0000 1.54 *************** *** 3,6 **** --- 3,14 ---- * Better error messages for wrong constructor calls and method implementations with wrong parameter names. + * Default value of fields can be overriden in subclasses. For instance: + class A { + int x = 1; + } + class B extends A { + override x = 5; + } + It's possible for final fields too. * Bug fixes (disallowed redefinition of parameters, execution order of initializers in super classes, ... ) |
From: Arjan B. <ar...@us...> - 2004-10-14 15:42:21
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19244/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Added field default value overriding. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.270 retrieving revision 1.271 diff -C2 -d -r1.270 -r1.271 *** Parser.jj 13 Oct 2004 20:42:21 -0000 1.270 --- Parser.jj 14 Oct 2004 15:42:10 -0000 1.271 *************** *** 1054,1058 **** // internal fields and methods { List fields = new LinkedList(), overrides = new LinkedList(), ! methods = new ArrayList(5), initializers = new LinkedList(); } ( // Initializer --- 1054,1059 ---- // internal fields and methods { List fields = new LinkedList(), overrides = new LinkedList(), ! methods = new ArrayList(5), initializers = new LinkedList(), ! valueOverrides = new LinkedList(); } ( // Initializer *************** *** 1061,1064 **** --- 1062,1070 ---- { initializers.add(init); } | + LOOKAHEAD ( "override" ident() "=" ) + { LocatedString fname; Expression value;} + "override" fname=ident() "=" value=Expression() ";" + { valueOverrides.add(impl.makeValueOverride(fname, value)); } + | LOOKAHEAD( fieldLookahead() ) overrides = getField(impl, fields, overrides, storeDocString) *************** *** 1082,1085 **** --- 1088,1092 ---- impl.setFields(fields); impl.setOverrides(overrides); + impl.setValueOverrides(valueOverrides); impl.setInitializers(initializers); res.setImplementation(impl); |