[Nice-commit] Nice/src/bossa/syntax NiceClass.java,1.69,1.70 MethodImplementation.java,1.1,1.2 Metho
Brought to you by:
bonniot
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv1298/src/bossa/syntax Modified Files: NiceClass.java MethodImplementation.java MethodBodyDefinition.java DefaultMethodImplementation.java Log Message: Make private readObject and writeObject member methods when those methods are defined on a Nice class, so that Java serialization picks them up. Make the serialVersionUID field really private. Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** NiceClass.java 23 Nov 2003 19:54:44 -0000 1.69 --- NiceClass.java 24 Nov 2003 14:47:50 -0000 1.70 *************** *** 925,929 **** fieldDecl.setCanRead(true); fieldDecl.setFlag(Declaration.IS_CONSTANT); ! fieldDecl.setPrivate(true); fieldDecl.setFlag(Declaration.STATIC_SPECIFIED); fieldDecl.setFlag(Declaration.TYPE_SPECIFIED); --- 925,929 ---- fieldDecl.setCanRead(true); fieldDecl.setFlag(Declaration.IS_CONSTANT); ! fieldDecl.setSpecifiedPrivate(true); fieldDecl.setFlag(Declaration.STATIC_SPECIFIED); fieldDecl.setFlag(Declaration.TYPE_SPECIFIED); Index: MethodImplementation.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodImplementation.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MethodImplementation.java 11 Sep 2003 20:51:46 -0000 1.1 --- MethodImplementation.java 24 Nov 2003 14:47:50 -0000 1.2 *************** *** 156,159 **** --- 156,161 ---- getRefExp(); + + createSerializationMethod(); } *************** *** 180,183 **** --- 182,224 ---- (new MiscAttr("patterns", Pattern.bytecodeRepresentation(formals).getBytes())); + } + + abstract TypeConstructor firstArgument(); + + /** + If the method implemented corresponds to readObject or writeObject, + create private member methods in the class of the first argument, + so that the Java serialization process picks them up. + */ + private void createSerializationMethod() + { + final int arity = formals.length; + + if (arity != 2) + return; + + String name = this.name.toString(); + + if (name.equals("writeObject") || name.equals("readObject")) + { + ClassDefinition def = ClassDefinition.get(firstArgument()); + if (def == null || ! (def.getImplementation() instanceof NiceClass)) + return; + + NiceClass c = (NiceClass) def.getImplementation(); + + gnu.expr.Expression[] params = new gnu.expr.Expression[arity]; + gnu.expr.LambdaExp method = Gen.createMemberMethod + (name.toString(), + c.getClassExp().getType(), + new Type[]{declaration.javaArgTypes()[1]}, + declaration.javaReturnType(), + params); + + Gen.setMethodBody(method, + new gnu.expr.ApplyExp(getRefExp(), params)); + + c.getClassExp().addMethod(method, true); + } } Index: MethodBodyDefinition.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodBodyDefinition.java,v retrieving revision 1.143 retrieving revision 1.144 diff -C2 -d -r1.143 -r1.144 *** MethodBodyDefinition.java 8 Oct 2003 22:30:11 -0000 1.143 --- MethodBodyDefinition.java 24 Nov 2003 14:47:50 -0000 1.144 *************** *** 90,94 **** final TypeConstructor firstArgument() { ! return formals[0].tc; } --- 90,101 ---- final TypeConstructor firstArgument() { ! if (formals[0].tc != null) ! return formals[0].tc; ! else ! // Either there is no specialization on the first parameter, or ! // it was equivalent to the declaration type and has been erased, ! // so we return the information in the declaration. ! return nice.tools.code.Types.equivalent(declaration.getArgTypes()[0]). ! head(); } Index: DefaultMethodImplementation.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/DefaultMethodImplementation.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DefaultMethodImplementation.java 13 Sep 2003 00:39:53 -0000 1.2 --- DefaultMethodImplementation.java 24 Nov 2003 14:47:50 -0000 1.3 *************** *** 53,56 **** --- 53,61 ---- } + final mlsub.typing.TypeConstructor firstArgument() + { + return nice.tools.code.Types.equivalent(declaration.getArgTypes()[0]).head(); + } + void doResolve() { |