Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9D596DF4B for ; Tue, 2 Oct 2012 15:15:48 +0000 (UTC) Received: (qmail 837 invoked by uid 500); 2 Oct 2012 15:15:48 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 763 invoked by uid 500); 2 Oct 2012 15:15:48 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 754 invoked by uid 99); 2 Oct 2012 15:15:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Oct 2012 15:15:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Oct 2012 15:15:46 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 107B523888E3 for ; Tue, 2 Oct 2012 15:15:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1392964 - in /commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis: ClassDifferentiator.java MethodDifferentiator.java Date: Tue, 02 Oct 2012 15:15:02 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121002151503.107B523888E3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: luc Date: Tue Oct 2 15:15:01 2012 New Revision: 1392964 URL: http://svn.apache.org/viewvc?rev=1392964&view=rev Log: Reorganize work between class and method differentiators. Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/ClassDifferentiator.java commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/ClassDifferentiator.java URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/ClassDifferentiator.java?rev=1392964&r1=1392963&r2=1392964&view=diff ============================================================================== --- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/ClassDifferentiator.java (original) +++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/ClassDifferentiator.java Tue Oct 2 15:15:01 2012 @@ -132,6 +132,20 @@ public class ClassDifferentiator { } + /** Get the name of the primitive class. + * @return name of the primitive class + */ + public String getPrimitiveName() { + return primitiveNode.name; + } + + /** Get the name of the derived class. + * @return name of the derived class + */ + public String getDerivedName() { + return classNode.name; + } + /** * Differentiate a method. * @param name of the method @@ -146,9 +160,9 @@ public class ClassDifferentiator { for (final MethodNode method : primitiveNode.methods) { if (method.name.equals(name) && Type.getType(method.desc).equals(primitiveMethodType)) { - final MethodDifferentiator differentiator = - new MethodDifferentiator(mathClasses, classNode); - differentiator.differentiate(primitiveNode.name, method, derivativedMethodType); + final MethodDifferentiator differentiator = new MethodDifferentiator(mathClasses, this); + differentiator.differentiate(method, derivativedMethodType); + classNode.methods.add(method); } } Modified: commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java URL: http://svn.apache.org/viewvc/commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java?rev=1392964&r1=1392963&r2=1392964&view=diff ============================================================================== --- commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java (original) +++ commons/sandbox/nabla/trunk/src/main/java/org/apache/commons/nabla/forward/analysis/MethodDifferentiator.java Tue Oct 2 15:15:01 2012 @@ -52,7 +52,6 @@ import org.apache.commons.nabla.forward. import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.tree.AbstractInsnNode; -import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.InsnNode; import org.objectweb.asm.tree.MethodInsnNode; @@ -73,8 +72,8 @@ public class MethodDifferentiator { /** Math implementation classes. */ private final Set mathClasses; - /** Derived class (which is under construction). */ - private final ClassNode derivedClass; + /** Differentiator for the complete class. */ + private final ClassDifferentiator classDifferentiator; /** Set of converted values. */ private final Set converted; @@ -87,32 +86,31 @@ public class MethodDifferentiator { /** Build a differentiator for a method. * @param mathClasses math implementation classes - * @param derivedName name of the derived class + * @param classDifferentiator differentiator for the complete class */ - public MethodDifferentiator(final Set mathClasses, final ClassNode derivedClass) { - this.mathClasses = mathClasses; - this.derivedClass = derivedClass; - this.converted = new HashSet(); - this.frames = new IdentityHashMap>(); - this.successors = new IdentityHashMap>(); + public MethodDifferentiator(final Set mathClasses, + final ClassDifferentiator classDifferentiator) { + this.mathClasses = mathClasses; + this.classDifferentiator = classDifferentiator; + this.converted = new HashSet(); + this.frames = new IdentityHashMap>(); + this.successors = new IdentityHashMap>(); } /** Get the name of the derived class. * @return name of the derived class */ public String getDerivedName() { - return derivedClass.name; + return classDifferentiator.getDerivedName(); } /** * Differentiate a method. - * @param primitiveName primitive class name * @param method method to differentiate (will be modified) * @param derivedMethodType type of the derived method * @exception DifferentiationException if method cannot be differentiated */ - public void differentiate(final String primitiveName, final MethodNode method, - final Type derivedMethodType) + public void differentiate(final MethodNode method, final Type derivedMethodType) throws DifferentiationException { try { @@ -122,7 +120,8 @@ public class MethodDifferentiator { // analyze the original code, tracing values production/consumption final FlowAnalyzer analyzer = new FlowAnalyzer(new TrackingInterpreter(), method.instructions); - final Frame[] array = analyzer.analyze(primitiveName, method); + final Frame[] array = + analyzer.analyze(classDifferentiator.getPrimitiveName(), method); // convert the array into a map, since code changes will shift all indices for (int i = 0; i < array.length; ++i) { @@ -174,17 +173,14 @@ public class MethodDifferentiator { method.access |= Opcodes.ACC_SYNTHETIC; method.maxLocals = dsIndex + 1; - // store the new method in the class - derivedClass.methods.add(method); - - } catch (AnalyzerException ae) { ae.printStackTrace(System.err); if ((ae.getCause() != null) && ae.getCause() instanceof DifferentiationException) { throw (DifferentiationException) ae.getCause(); } else { throw new DifferentiationException(NablaMessages.UNABLE_TO_ANALYZE_METHOD, - primitiveName, method.name, ae.getMessage()); + classDifferentiator.getPrimitiveName(), + method.name, ae.getMessage()); } } }