From: <mt...@us...> - 2010-09-22 08:09:57
|
Revision: 16619 http://x10.svn.sourceforge.net/x10/?rev=16619&view=rev Author: mtake Date: 2010-09-22 08:09:51 +0000 (Wed, 22 Sep 2010) Log Message: ----------- Implement custom serialization Modified Paths: -------------- trunk/x10.compiler/src/x10/emitter/Emitter.java trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java Added Paths: ----------- trunk/x10.runtime/src-x10/x10/io/CustomSerialization.x10 Modified: trunk/x10.compiler/src/x10/emitter/Emitter.java =================================================================== --- trunk/x10.compiler/src/x10/emitter/Emitter.java 2010-09-22 06:56:17 UTC (rev 16618) +++ trunk/x10.compiler/src/x10/emitter/Emitter.java 2010-09-22 08:09:51 UTC (rev 16619) @@ -2212,6 +2212,24 @@ } } + public void generateCustomSerializer(X10ClassDef def) { + String fieldName = "__serialized__"; + w.write("// custom serializer"); + w.newline(); + w.write("private Object " + fieldName + ";"); + w.newline(); + w.write("private Object writeReplace() { " + fieldName + " = serialize(); return this; }"); + w.newline(); + w.write("private Object readResolve() { return new "); + printType(def.asType(), X10PrettyPrinterVisitor.BOX_PRIMITIVES | X10PrettyPrinterVisitor.NO_QUALIFIER); + w.write("(" + fieldName + "); }"); + w.newline(); + w.write("private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException { oos.writeObject(" + fieldName + "); }"); + w.newline(); + w.write("private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException { " + fieldName + " = ois.readObject(); }"); + w.newline(); + } + private void printParents(X10ClassDef def, Type type) { if (type instanceof ConstrainedType_c) { type = ((ConstrainedType_c) type).baseType().get(); Modified: trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java =================================================================== --- trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-22 06:56:17 UTC (rev 16618) +++ trunk/x10.compiler/src/x10/visit/X10PrettyPrinterVisitor.java 2010-09-22 08:09:51 UTC (rev 16619) @@ -719,6 +719,15 @@ } + private boolean hasCustomSerializer(X10ClassDecl_c n) { + boolean hasCustomSerializer = false; + for (TypeNode tn: n.interfaces()) { + if ("x10.io.CustomSerialization".equals(tn.type().toString())) { + hasCustomSerializer = true; + } + } + return hasCustomSerializer; + } public void visit(X10ClassDecl_c n) { String className = n.classDef().name().toString(); @@ -911,6 +920,10 @@ // XTENLANG-1102 er.generateRTTInstance(def); + if (hasCustomSerializer(n)) { + er.generateCustomSerializer(def); + } + // Generate dispatcher methods. // er.generateDispatchers(def); Added: trunk/x10.runtime/src-x10/x10/io/CustomSerialization.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/io/CustomSerialization.x10 (rev 0) +++ trunk/x10.runtime/src-x10/x10/io/CustomSerialization.x10 2010-09-22 08:09:51 UTC (rev 16619) @@ -0,0 +1,16 @@ +/* + * This file is part of the X10 project (http://x10-lang.org). + * + * This file is licensed to You under the Eclipse Public License (EPL); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.opensource.org/licenses/eclipse-1.0.php + * + * (C) Copyright IBM Corporation 2006-2010. + */ + +package x10.io; + +public interface CustomSerialization { + def serialize(): Any; +} Property changes on: trunk/x10.runtime/src-x10/x10/io/CustomSerialization.x10 ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |