changeset 22434:c11ce7d2e2c3

Documenting that FrameDescriptor#copy doesn't copy info and kind - isn't that an error?
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 03 Dec 2015 19:37:45 +0100
parents 7f3fbd797e39
children dc2bfc816011
files truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/FrameDescriptorTest.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/FrameDescriptorTest.java	Thu Dec 03 19:20:09 2015 +0100
+++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/FrameDescriptorTest.java	Thu Dec 03 19:37:45 2015 +0100
@@ -25,10 +25,12 @@
 import com.oracle.truffle.api.frame.Frame;
 import com.oracle.truffle.api.frame.FrameDescriptor;
 import com.oracle.truffle.api.frame.FrameSlot;
+import com.oracle.truffle.api.frame.FrameSlotKind;
 import com.oracle.truffle.api.frame.FrameSlotTypeException;
 import com.oracle.truffle.api.frame.VirtualFrame;
 import org.junit.Assert;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import org.junit.Test;
 
 public class FrameDescriptorTest {
@@ -66,4 +68,24 @@
     public void nullDefaultValue() {
         Assert.assertNull(new FrameDescriptor().getDefaultValue());
     }
+
+    @Test
+    public void copy() throws Exception {
+        Object defaultValue = "default";
+        FrameDescriptor d = new FrameDescriptor(defaultValue);
+        s1 = d.addFrameSlot("v1", "i1", FrameSlotKind.Boolean);
+        s2 = d.addFrameSlot("v2", "i2", FrameSlotKind.Float);
+
+        assertEquals(2, d.getSize());
+        assertEquals(d.getSlots().get(1).getInfo(), "i2");
+        assertEquals(d.getSlots().get(1).getKind(), FrameSlotKind.Float);
+        assertEquals(d.getSlots().get(1).getIndex(), 1);
+
+        FrameDescriptor copy = d.copy();
+
+        assertEquals(copy.getSlots().get(1).getIndex(), 1);
+
+        assertNull("Info isn't copied!", copy.getSlots().get(1).getInfo());
+        assertEquals("Kind isn't copied!", copy.getSlots().get(1).getKind(), FrameSlotKind.Illegal);
+    }
 }
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java	Thu Dec 03 19:20:09 2015 +0100
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java	Thu Dec 03 19:37:45 2015 +0100
@@ -233,6 +233,12 @@
         return Collections.unmodifiableSet(identifierToSlotMap.keySet());
     }
 
+    /**
+     * Deeper copy of the descriptor. Copies all slots in the descriptor, but only their identifiers
+     * - not their {@link FrameSlot#getInfo()} neither their {@link FrameSlot#getKind()}!
+     * 
+     * @return new instance of a descritor with copies of values from this one
+     */
     public FrameDescriptor copy() {
         FrameDescriptor clonedFrameDescriptor = new FrameDescriptor(this.defaultValue);
         for (int i = 0; i < this.getSlots().size(); i++) {