17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.lang.invoke; 27 28 import java.util.ArrayList; 29 import java.util.Arrays; 30 import static java.lang.invoke.LambdaForm.*; 31 import static java.lang.invoke.LambdaForm.BasicType.*; 32 33 /** Working storage for an LF that is being transformed. 34 * Similarly to a StringBuffer, the editing can take place in multiple steps. 35 */ 36 final class LambdaFormBuffer { 37 private int arity, length; 38 private Name[] names; 39 private Name[] originalNames; // snapshot of pre-transaction names 40 private byte flags; 41 private int firstChange; 42 private Name resultName; 43 private String debugName; 44 private ArrayList<Name> dups; 45 46 private static final int F_TRANS = 0x10, F_OWNED = 0x03; 47 48 LambdaFormBuffer(LambdaForm lf) { 49 this(lf.arity, lf.names, lf.result); 50 debugName = lf.debugName; 51 assert(lf.nameRefsAreLegal()); 52 } 53 54 private LambdaFormBuffer(int arity, Name[] names, int result) { 55 this.arity = arity; 56 setNames(names); 57 if (result == LAST_RESULT) result = length - 1; 58 if (result >= 0 && names[result].type != V_TYPE) 59 resultName = names[result]; 60 } 61 62 private LambdaForm lambdaForm() { 63 assert(!inTrans()); // need endEdit call to tidy things up 64 return new LambdaForm(debugName, arity, nameArray(), resultIndex()); 65 } 66 67 Name name(int i) { 68 assert(i < length); 69 return names[i]; 70 } 71 72 Name[] nameArray() { 73 return Arrays.copyOf(names, length); 74 } 75 76 int resultIndex() { 77 if (resultName == null) return VOID_RESULT; 78 int index = indexOf(resultName, names); 79 assert(index >= 0); 80 return index; 81 } 82 83 void setNames(Name[] names2) { 84 names = originalNames = names2; // keep a record of where everything was to start with | 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.lang.invoke; 27 28 import java.util.ArrayList; 29 import java.util.Arrays; 30 import static java.lang.invoke.LambdaForm.*; 31 import static java.lang.invoke.LambdaForm.BasicType.*; 32 33 /** Working storage for an LF that is being transformed. 34 * Similarly to a StringBuffer, the editing can take place in multiple steps. 35 */ 36 final class LambdaFormBuffer { 37 private final LambdaForm lambdaForm; 38 private int arity, length; 39 private Name[] names; 40 private Name[] originalNames; // snapshot of pre-transaction names 41 private byte flags; 42 private int firstChange; 43 private Name resultName; 44 private String debugName; 45 private ArrayList<Name> dups; 46 47 private static final int F_TRANS = 0x10, F_OWNED = 0x03; 48 49 LambdaFormBuffer(LambdaForm lf) { 50 this.lambdaForm = lf; 51 this.arity = lf.arity; 52 setNames(lf.names); 53 int result = lf.result; 54 if (result == LAST_RESULT) result = length - 1; 55 if (result >= 0 && lf.names[result].type != V_TYPE) 56 resultName = lf.names[result]; 57 debugName = lf.debugName; 58 assert(lf.nameRefsAreLegal()); 59 } 60 61 private LambdaForm lambdaForm() { 62 assert(!inTrans()); // need endEdit call to tidy things up 63 return new LambdaForm(lambdaForm, debugName, arity, nameArray(), resultIndex()); 64 } 65 66 Name name(int i) { 67 assert(i < length); 68 return names[i]; 69 } 70 71 Name[] nameArray() { 72 return Arrays.copyOf(names, length); 73 } 74 75 int resultIndex() { 76 if (resultName == null) return VOID_RESULT; 77 int index = indexOf(resultName, names); 78 assert(index >= 0); 79 return index; 80 } 81 82 void setNames(Name[] names2) { 83 names = originalNames = names2; // keep a record of where everything was to start with |