commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
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 GMT
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<String> 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<TrackingValue> 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<String> mathClasses, final ClassNode derivedClass)
{
-        this.mathClasses  = mathClasses;
-        this.derivedClass  = derivedClass;
-        this.converted    = new HashSet<TrackingValue>();
-        this.frames       = new IdentityHashMap<AbstractInsnNode, Frame<TrackingValue>>();
-        this.successors   = new IdentityHashMap<AbstractInsnNode, Set<AbstractInsnNode>>();
+    public MethodDifferentiator(final Set<String> mathClasses,
+                                final ClassDifferentiator classDifferentiator) {
+        this.mathClasses         = mathClasses;
+        this.classDifferentiator = classDifferentiator;
+        this.converted           = new HashSet<TrackingValue>();
+        this.frames              = new IdentityHashMap<AbstractInsnNode, Frame<TrackingValue>>();
+        this.successors          = new IdentityHashMap<AbstractInsnNode, Set<AbstractInsnNode>>();
     }
 
     /** 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 (<em>will</em> 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<TrackingValue>[] array = analyzer.analyze(primitiveName, method);
+            final Frame<TrackingValue>[] 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());
             }
         }
     }



Mime
View raw message