# HG changeset patch # User Andreas Woess # Date 1449769901 -3600 # Node ID fa86f9f3848d84863b10f86bcd612cccf586d08c # Parent 28227895fa3577a7eaee3f8c2087a4798e995792 change FrameDescriptor#copy to also copy info diff -r 28227895fa35 -r fa86f9f3848d truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/FrameDescriptorTest.java --- a/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/FrameDescriptorTest.java Thu Dec 10 15:00:16 2015 +0100 +++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/FrameDescriptorTest.java Thu Dec 10 18:51:41 2015 +0100 @@ -22,16 +22,17 @@ */ package com.oracle.truffle.api; +import static org.junit.Assert.assertEquals; + +import org.junit.Assert; +import org.junit.Test; + 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 { @@ -82,11 +83,10 @@ 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); + assertEquals(2, copy.getSize()); + assertEquals(1, copy.getSlots().get(1).getIndex()); + assertEquals("Info is copied", "i2", copy.getSlots().get(1).getInfo()); + assertEquals("Kind isn't copied", FrameSlotKind.Illegal, copy.getSlots().get(1).getKind()); } @Test diff -r 28227895fa35 -r fa86f9f3848d truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java Thu Dec 10 15:00:16 2015 +0100 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameDescriptor.java Thu Dec 10 18:51:41 2015 +0100 @@ -54,7 +54,7 @@ /** * Constructs new descriptor with specified {@link #getDefaultValue()}. - * + * * @param defaultValue to be returned from {@link #getDefaultValue()} */ public FrameDescriptor(Object defaultValue) { @@ -67,7 +67,7 @@ /** * Use {@link #FrameDescriptor()}. - * + * * @return new instance of the descriptor * @deprecated */ @@ -78,7 +78,7 @@ /** * Use {@link #FrameDescriptor(java.lang.Object) }. - * + * * @return new instance of the descriptor * @deprecated */ @@ -92,7 +92,7 @@ * {@link #addFrameSlot(java.lang.Object, java.lang.Object, com.oracle.truffle.api.frame.FrameSlotKind) * addFrameSlot}(identifier, null, {@link FrameSlotKind#Illegal}). This is slow * operation that switches to interpreter mode. - * + * * @param identifier key for the slot * @return the newly created slot */ @@ -105,7 +105,7 @@ * {@link #addFrameSlot(java.lang.Object, java.lang.Object, com.oracle.truffle.api.frame.FrameSlotKind) * addFrameSlot}(identifier, null, kind). This is slow operation that * switches to interpreter mode. - * + * * @param identifier key for the slot * @param kind the kind of the new slot * @return the newly created slot @@ -117,7 +117,7 @@ /** * Adds new frame slot to {@link #getSlots()} list. This is slow operation that switches to * interpreter mode. - * + * * @param identifier key for the slot - it needs proper {@link #equals(java.lang.Object)} and * {@link Object#hashCode()} implementations * @param info additional {@link FrameSlot#getInfo() information for the slot} @@ -137,7 +137,7 @@ /** * Finds an existing slot. This is slow operation. - * + * * @param identifier the key of the slot to search for * @return the slot or null */ @@ -148,7 +148,7 @@ /** * Finds an existing slot or creates new one. This is slow operation. - * + * * @param identifier the key of the slot to search for * @return the slot */ @@ -162,7 +162,7 @@ /** * Finds an existing slot or creates new one. This is slow operation. - * + * * @param identifier the key of the slot to search for * @param kind the kind for the newly created slot * @return the found or newly created slot @@ -177,7 +177,7 @@ /** * Finds an existing slot or creates new one. This is slow operation. - * + * * @param identifier the key of the slot to search for * @param info info for the newly created slot * @param kind the kind for the newly created slot @@ -194,7 +194,7 @@ /** * Removes a slot. If the identifier is found, its slot is removed from this descriptor. This is * slow operation. - * + * * @param identifier identifies the slot to remove */ public void removeFrameSlot(Object identifier) { @@ -208,7 +208,7 @@ /** * Returns number of slots in the descriptor. - * + * * @return the same value as {@link #getSlots()}.{@link List#size()} would return */ public int getSize() { @@ -217,7 +217,7 @@ /** * Current set of slots in the descriptor. - * + * * @return unmodifiable list of {@link FrameSlot} */ public List getSlots() { @@ -234,16 +234,17 @@ } /** - * 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()}! - * + * Deeper copy of the descriptor. Copies all slots in the descriptor, but only their + * {@linkplain FrameSlot#getIdentifier() identifier} and {@linkplain FrameSlot#getInfo() info} + * but not their {@linkplain FrameSlot#getKind() kind}! + * * @return new instance of a descriptor 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++) { - Object identifier = this.getSlots().get(i).getIdentifier(); - clonedFrameDescriptor.addFrameSlot(identifier); + for (int i = 0; i < slots.size(); i++) { + FrameSlot slot = slots.get(i); + clonedFrameDescriptor.addFrameSlot(slot.getIdentifier(), slot.getInfo(), FrameSlotKind.Illegal); } return clonedFrameDescriptor; } @@ -252,7 +253,7 @@ * Shallow copy of the descriptor. Re-uses the existing slots in new descriptor. As a result, if * you {@link FrameSlot#setKind(com.oracle.truffle.api.frame.FrameSlotKind) change kind} of one * of the slots it is changed in the original as well as in the shallow copy. - * + * * @return new instance of a descriptor with copies of values from this one */ public FrameDescriptor shallowCopy() { @@ -277,7 +278,7 @@ /** * Default value for the created slots. - * + * * @return value provided to {@link #FrameDescriptor(java.lang.Object)} */ public Object getDefaultValue() {