diff graal/com.oracle.truffle.object/src/com/oracle/truffle/object/LocationImpl.java @ 18795:e9cbe1618733

Truffle: refactor size calculation in location allocator to visitor pattern
author Andreas Woess <andreas.woess@jku.at>
date Wed, 07 Jan 2015 15:11:38 +0100
parents 2c3666f44855
children
line wrap: on
line diff
--- a/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/LocationImpl.java	Mon Jan 05 19:01:01 2015 +0100
+++ b/graal/com.oracle.truffle.object/src/com/oracle/truffle/object/LocationImpl.java	Wed Jan 07 15:11:38 2015 +0100
@@ -25,6 +25,29 @@
 import com.oracle.truffle.api.object.*;
 
 public abstract class LocationImpl extends Location {
+
+    public interface EffectivelyFinalLocation<T extends Location> {
+        T toNonFinalLocation();
+    }
+
+    public interface TypedObjectLocation<T extends Location & ObjectLocation> extends ObjectLocation {
+        T toUntypedLocation();
+    }
+
+    public interface InternalLongLocation extends LongLocation {
+        void setLongInternal(DynamicObject store, long value);
+    }
+
+    public interface LocationVisitor {
+        void visitObjectField(int index, int count);
+
+        void visitObjectArray(int index, int count);
+
+        void visitPrimitiveField(int index, int count);
+
+        void visitPrimitiveArray(int index, int count);
+    }
+
     @Override
     public void set(DynamicObject store, Object value, Shape shape) throws IncompatibleLocationException, FinalLocationException {
         setInternal(store, value);
@@ -53,18 +76,6 @@
         return true;
     }
 
-    public interface EffectivelyFinalLocation<T extends Location> {
-        T toNonFinalLocation();
-    }
-
-    public interface TypedObjectLocation<T extends Location & ObjectLocation> extends ObjectLocation {
-        T toUntypedLocation();
-    }
-
-    public interface InternalLongLocation extends LongLocation {
-        void setLongInternal(DynamicObject store, long value);
-    }
-
     @Override
     public boolean isFinal() {
         return false;
@@ -142,6 +153,13 @@
     }
 
     /**
+     * Accept a visitor for location allocation for this and every nested location.
+     *
+     * @param locationVisitor visitor to be notified of every allocated slot in use by this location
+     */
+    public abstract void accept(LocationVisitor locationVisitor);
+
+    /**
      * Boxed values need to be compared by value not by reference.
      *
      * The first parameter should be the one with the more precise type information.