# HG changeset patch # User Lubomir Nerad # Date 1355494013 -3600 # Node ID 83f638b1324261b1e08763c314b9532e8dfb85ae # Parent 15cbc8cb2163b8fea5e7cb82fa6870b71f2de6e2 Changed unintentionally changed file modes / line endings diff -r 15cbc8cb2163 -r 83f638b13242 javap/src/main/java/org/apidesign/javap/TypeArray.java --- a/javap/src/main/java/org/apidesign/javap/TypeArray.java Fri Dec 14 11:15:37 2012 +0100 +++ b/javap/src/main/java/org/apidesign/javap/TypeArray.java Fri Dec 14 15:06:53 2012 +0100 @@ -1,186 +1,186 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package org.apidesign.javap; - -import static org.apidesign.javap.RuntimeConstants.ITEM_Bogus; -import static org.apidesign.javap.RuntimeConstants.ITEM_Integer; -import static org.apidesign.javap.RuntimeConstants.ITEM_Float; -import static org.apidesign.javap.RuntimeConstants.ITEM_Double; -import static org.apidesign.javap.RuntimeConstants.ITEM_Long; -import static org.apidesign.javap.RuntimeConstants.ITEM_Null; -import static org.apidesign.javap.RuntimeConstants.ITEM_InitObject; -import static org.apidesign.javap.RuntimeConstants.ITEM_Object; -import static org.apidesign.javap.RuntimeConstants.ITEM_NewObject; - -public final class TypeArray { - private static final int CAPACITY_INCREMENT = 16; - - private int[] types; - private int size; - - public TypeArray() { - } - - public TypeArray(final TypeArray initialTypes) { - setAll(initialTypes); - } - - public void add(final int newType) { - ensureCapacity(size + 1); - types[size++] = newType; - } - - public void addAll(final TypeArray newTypes) { - addAll(newTypes.types, 0, newTypes.size); - } - - public void addAll(final int[] newTypes) { - addAll(newTypes, 0, newTypes.length); - } - - public void addAll(final int[] newTypes, - final int offset, - final int count) { - if (count > 0) { - ensureCapacity(size + count); - arraycopy(newTypes, offset, types, size, count); - size += count; - } - } - - public void set(final int index, final int newType) { - types[index] = newType; - } - - public void setAll(final TypeArray newTypes) { - setAll(newTypes.types, 0, newTypes.size); - } - - public void setAll(final int[] newTypes) { - setAll(newTypes, 0, newTypes.length); - } - - public void setAll(final int[] newTypes, - final int offset, - final int count) { - if (count > 0) { - ensureCapacity(count); - arraycopy(newTypes, offset, types, 0, count); - size = count; - } else { - clear(); - } - } - - public void setSize(final int newSize) { - if (size != newSize) { - ensureCapacity(newSize); - - for (int i = size; i < newSize; ++i) { - types[i] = 0; - } - size = newSize; - } - } - - public void clear() { - size = 0; - } - - public int getSize() { - return size; - } - - public int get(final int index) { - return types[index]; - } - - public static String typeString(final int type) { - switch (type & 0xff) { - case ITEM_Bogus: - return "_top_"; - case ITEM_Integer: - return "_int_"; - case ITEM_Float: - return "_float_"; - case ITEM_Double: - return "_double_"; - case ITEM_Long: - return "_long_"; - case ITEM_Null: - return "_null_"; - case ITEM_InitObject: // UninitializedThis - return "_init_"; - case ITEM_Object: - return "_object_"; - case ITEM_NewObject: // Uninitialized - return "_new_"; - default: - throw new IllegalArgumentException("Unknown type"); - } - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("["); - if (size > 0) { - sb.append(typeString(types[0])); - for (int i = 1; i < size; ++i) { - sb.append(", "); - sb.append(typeString(types[i])); - } - } - - return sb.append(']').toString(); - } - - private void ensureCapacity(final int minCapacity) { - if ((minCapacity == 0) - || (types != null) && (minCapacity <= types.length)) { - return; - } - - final int newCapacity = - ((minCapacity + CAPACITY_INCREMENT - 1) / CAPACITY_INCREMENT) - * CAPACITY_INCREMENT; - final int[] newTypes = new int[newCapacity]; - - if (size > 0) { - arraycopy(types, 0, newTypes, 0, size); - } - - types = newTypes; - } - - // no System.arraycopy - private void arraycopy(final int[] src, final int srcPos, - final int[] dest, final int destPos, - final int length) { - for (int i = 0; i < length; ++i) { - dest[destPos + i] = src[srcPos + i]; - } - } -} +/* + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package org.apidesign.javap; + +import static org.apidesign.javap.RuntimeConstants.ITEM_Bogus; +import static org.apidesign.javap.RuntimeConstants.ITEM_Integer; +import static org.apidesign.javap.RuntimeConstants.ITEM_Float; +import static org.apidesign.javap.RuntimeConstants.ITEM_Double; +import static org.apidesign.javap.RuntimeConstants.ITEM_Long; +import static org.apidesign.javap.RuntimeConstants.ITEM_Null; +import static org.apidesign.javap.RuntimeConstants.ITEM_InitObject; +import static org.apidesign.javap.RuntimeConstants.ITEM_Object; +import static org.apidesign.javap.RuntimeConstants.ITEM_NewObject; + +public final class TypeArray { + private static final int CAPACITY_INCREMENT = 16; + + private int[] types; + private int size; + + public TypeArray() { + } + + public TypeArray(final TypeArray initialTypes) { + setAll(initialTypes); + } + + public void add(final int newType) { + ensureCapacity(size + 1); + types[size++] = newType; + } + + public void addAll(final TypeArray newTypes) { + addAll(newTypes.types, 0, newTypes.size); + } + + public void addAll(final int[] newTypes) { + addAll(newTypes, 0, newTypes.length); + } + + public void addAll(final int[] newTypes, + final int offset, + final int count) { + if (count > 0) { + ensureCapacity(size + count); + arraycopy(newTypes, offset, types, size, count); + size += count; + } + } + + public void set(final int index, final int newType) { + types[index] = newType; + } + + public void setAll(final TypeArray newTypes) { + setAll(newTypes.types, 0, newTypes.size); + } + + public void setAll(final int[] newTypes) { + setAll(newTypes, 0, newTypes.length); + } + + public void setAll(final int[] newTypes, + final int offset, + final int count) { + if (count > 0) { + ensureCapacity(count); + arraycopy(newTypes, offset, types, 0, count); + size = count; + } else { + clear(); + } + } + + public void setSize(final int newSize) { + if (size != newSize) { + ensureCapacity(newSize); + + for (int i = size; i < newSize; ++i) { + types[i] = 0; + } + size = newSize; + } + } + + public void clear() { + size = 0; + } + + public int getSize() { + return size; + } + + public int get(final int index) { + return types[index]; + } + + public static String typeString(final int type) { + switch (type & 0xff) { + case ITEM_Bogus: + return "_top_"; + case ITEM_Integer: + return "_int_"; + case ITEM_Float: + return "_float_"; + case ITEM_Double: + return "_double_"; + case ITEM_Long: + return "_long_"; + case ITEM_Null: + return "_null_"; + case ITEM_InitObject: // UninitializedThis + return "_init_"; + case ITEM_Object: + return "_object_"; + case ITEM_NewObject: // Uninitialized + return "_new_"; + default: + throw new IllegalArgumentException("Unknown type"); + } + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("["); + if (size > 0) { + sb.append(typeString(types[0])); + for (int i = 1; i < size; ++i) { + sb.append(", "); + sb.append(typeString(types[i])); + } + } + + return sb.append(']').toString(); + } + + private void ensureCapacity(final int minCapacity) { + if ((minCapacity == 0) + || (types != null) && (minCapacity <= types.length)) { + return; + } + + final int newCapacity = + ((minCapacity + CAPACITY_INCREMENT - 1) / CAPACITY_INCREMENT) + * CAPACITY_INCREMENT; + final int[] newTypes = new int[newCapacity]; + + if (size > 0) { + arraycopy(types, 0, newTypes, 0, size); + } + + types = newTypes; + } + + // no System.arraycopy + private void arraycopy(final int[] src, final int srcPos, + final int[] dest, final int destPos, + final int length) { + for (int i = 0; i < length; ++i) { + dest[destPos + i] = src[srcPos + i]; + } + } +} diff -r 15cbc8cb2163 -r 83f638b13242 vm/src/main/java/org/apidesign/vm4brwsr/LocalsMapper.java --- a/vm/src/main/java/org/apidesign/vm4brwsr/LocalsMapper.java Fri Dec 14 11:15:37 2012 +0100 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/LocalsMapper.java Fri Dec 14 15:06:53 2012 +0100 @@ -1,141 +1,141 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.vm4brwsr; - -import java.io.IOException; -import org.apidesign.javap.RuntimeConstants; -import org.apidesign.javap.TypeArray; - -final class LocalsMapper { - private final TypeArray argTypeRecords; - private final TypeArray localTypeRecords; - - public LocalsMapper(final TypeArray stackMapArgs) { - final TypeArray initTypeRecords = new TypeArray(); - updateRecords(initTypeRecords, stackMapArgs); - - argTypeRecords = initTypeRecords; - localTypeRecords = new TypeArray(initTypeRecords); - } - - public void outputArguments(final Appendable out) throws IOException { - final int argRecordCount = argTypeRecords.getSize(); - if (argRecordCount > 0) { - Variable variable = getVariable(argTypeRecords, 0); - out.append(variable); - - int i = variable.isCategory2() ? 2 : 1; - while (i < argRecordCount) { - variable = getVariable(argTypeRecords, i); - out.append(", "); - out.append(variable); - i += variable.isCategory2() ? 2 : 1; - } - } - } - - public void syncWithFrameLocals(final TypeArray frameLocals) { - updateRecords(localTypeRecords, frameLocals); - } - - public Variable setI(final int index) { - return setT(index, VarType.INTEGER); - } - - public Variable setL(final int index) { - return setT(index, VarType.LONG); - } - - public Variable setF(final int index) { - return setT(index, VarType.FLOAT); - } - - public Variable setD(final int index) { - return setT(index, VarType.DOUBLE); - } - - public Variable setA(final int index) { - return setT(index, VarType.REFERENCE); - } - - public Variable setT(final int index, final int type) { - updateRecord(localTypeRecords, index, type); - return Variable.getLocalVariable(type, index); - } - - public Variable getI(final int index) { - return getT(index, VarType.INTEGER); - } - - public Variable getL(final int index) { - return getT(index, VarType.LONG); - } - - public Variable getF(final int index) { - return getT(index, VarType.FLOAT); - } - - public Variable getD(final int index) { - return getT(index, VarType.DOUBLE); - } - - public Variable getA(final int index) { - return getT(index, VarType.REFERENCE); - } - - public Variable getT(final int index, final int type) { - final int oldRecordValue = localTypeRecords.get(index); - if ((oldRecordValue & 0xff) != type) { - throw new IllegalStateException("Type mismatch"); - } - - return Variable.getLocalVariable(type, index); - } - - private static void updateRecords(final TypeArray typeRecords, - final TypeArray stackMapTypes) { - final int srcSize = stackMapTypes.getSize(); - for (int i = 0, dstIndex = 0; i < srcSize; ++i) { - final int smType = stackMapTypes.get(i); - if (smType == RuntimeConstants.ITEM_Bogus) { - ++dstIndex; - continue; - } - final int varType = VarType.fromStackMapType(smType); - updateRecord(typeRecords, dstIndex, varType); - dstIndex += VarType.isCategory2(varType) ? 2 : 1; - } - } - - private static void updateRecord(final TypeArray typeRecords, - final int index, final int type) { - if (typeRecords.getSize() < (index + 1)) { - typeRecords.setSize(index + 1); - } - - final int oldRecordValue = typeRecords.get(index); - final int usedTypesMask = - (oldRecordValue >> 8) | (1 << type); - typeRecords.set(index, (usedTypesMask << 8) | type); - } - - private static Variable getVariable(final TypeArray typeRecords, - final int index) { - return Variable.getLocalVariable(typeRecords.get(index) & 0xff, index); - } -} +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.vm4brwsr; + +import java.io.IOException; +import org.apidesign.javap.RuntimeConstants; +import org.apidesign.javap.TypeArray; + +final class LocalsMapper { + private final TypeArray argTypeRecords; + private final TypeArray localTypeRecords; + + public LocalsMapper(final TypeArray stackMapArgs) { + final TypeArray initTypeRecords = new TypeArray(); + updateRecords(initTypeRecords, stackMapArgs); + + argTypeRecords = initTypeRecords; + localTypeRecords = new TypeArray(initTypeRecords); + } + + public void outputArguments(final Appendable out) throws IOException { + final int argRecordCount = argTypeRecords.getSize(); + if (argRecordCount > 0) { + Variable variable = getVariable(argTypeRecords, 0); + out.append(variable); + + int i = variable.isCategory2() ? 2 : 1; + while (i < argRecordCount) { + variable = getVariable(argTypeRecords, i); + out.append(", "); + out.append(variable); + i += variable.isCategory2() ? 2 : 1; + } + } + } + + public void syncWithFrameLocals(final TypeArray frameLocals) { + updateRecords(localTypeRecords, frameLocals); + } + + public Variable setI(final int index) { + return setT(index, VarType.INTEGER); + } + + public Variable setL(final int index) { + return setT(index, VarType.LONG); + } + + public Variable setF(final int index) { + return setT(index, VarType.FLOAT); + } + + public Variable setD(final int index) { + return setT(index, VarType.DOUBLE); + } + + public Variable setA(final int index) { + return setT(index, VarType.REFERENCE); + } + + public Variable setT(final int index, final int type) { + updateRecord(localTypeRecords, index, type); + return Variable.getLocalVariable(type, index); + } + + public Variable getI(final int index) { + return getT(index, VarType.INTEGER); + } + + public Variable getL(final int index) { + return getT(index, VarType.LONG); + } + + public Variable getF(final int index) { + return getT(index, VarType.FLOAT); + } + + public Variable getD(final int index) { + return getT(index, VarType.DOUBLE); + } + + public Variable getA(final int index) { + return getT(index, VarType.REFERENCE); + } + + public Variable getT(final int index, final int type) { + final int oldRecordValue = localTypeRecords.get(index); + if ((oldRecordValue & 0xff) != type) { + throw new IllegalStateException("Type mismatch"); + } + + return Variable.getLocalVariable(type, index); + } + + private static void updateRecords(final TypeArray typeRecords, + final TypeArray stackMapTypes) { + final int srcSize = stackMapTypes.getSize(); + for (int i = 0, dstIndex = 0; i < srcSize; ++i) { + final int smType = stackMapTypes.get(i); + if (smType == RuntimeConstants.ITEM_Bogus) { + ++dstIndex; + continue; + } + final int varType = VarType.fromStackMapType(smType); + updateRecord(typeRecords, dstIndex, varType); + dstIndex += VarType.isCategory2(varType) ? 2 : 1; + } + } + + private static void updateRecord(final TypeArray typeRecords, + final int index, final int type) { + if (typeRecords.getSize() < (index + 1)) { + typeRecords.setSize(index + 1); + } + + final int oldRecordValue = typeRecords.get(index); + final int usedTypesMask = + (oldRecordValue >> 8) | (1 << type); + typeRecords.set(index, (usedTypesMask << 8) | type); + } + + private static Variable getVariable(final TypeArray typeRecords, + final int index) { + return Variable.getLocalVariable(typeRecords.get(index) & 0xff, index); + } +} diff -r 15cbc8cb2163 -r 83f638b13242 vm/src/main/java/org/apidesign/vm4brwsr/VarType.java --- a/vm/src/main/java/org/apidesign/vm4brwsr/VarType.java Fri Dec 14 11:15:37 2012 +0100 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VarType.java Fri Dec 14 15:06:53 2012 +0100 @@ -1,110 +1,110 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.vm4brwsr; - -import org.apidesign.javap.RuntimeConstants; - -final class VarType { - public static final int INTEGER = 0; - public static final int LONG = 1; - public static final int FLOAT = 2; - public static final int DOUBLE = 3; - public static final int REFERENCE = 4; - - public static final int LAST = REFERENCE; - - private VarType() { - } - - public static boolean isCategory2(final int varType) { - return (varType == LONG) || (varType == DOUBLE); - } - - public static int fromStackMapType(final int smType) { - switch (smType & 0xff) { - case RuntimeConstants.ITEM_Integer: - return VarType.INTEGER; - case RuntimeConstants.ITEM_Float: - return VarType.FLOAT; - case RuntimeConstants.ITEM_Double: - return VarType.DOUBLE; - case RuntimeConstants.ITEM_Long: - return VarType.LONG; - case RuntimeConstants.ITEM_Object: - return VarType.REFERENCE; - - case RuntimeConstants.ITEM_Bogus: - case RuntimeConstants.ITEM_Null: - case RuntimeConstants.ITEM_InitObject: - case RuntimeConstants.ITEM_NewObject: - /* unclear how to handle for now */ - default: - throw new IllegalStateException("Unhandled stack map type"); - } - } - - public static int fromConstantType(final byte constantTag) { - switch (constantTag) { - case RuntimeConstants.CONSTANT_INTEGER: - return VarType.INTEGER; - case RuntimeConstants.CONSTANT_FLOAT: - return VarType.FLOAT; - case RuntimeConstants.CONSTANT_LONG: - return VarType.LONG; - case RuntimeConstants.CONSTANT_DOUBLE: - return VarType.DOUBLE; - - case RuntimeConstants.CONSTANT_CLASS: - case RuntimeConstants.CONSTANT_UTF8: - case RuntimeConstants.CONSTANT_UNICODE: - case RuntimeConstants.CONSTANT_STRING: - return VarType.REFERENCE; - - case RuntimeConstants.CONSTANT_FIELD: - case RuntimeConstants.CONSTANT_METHOD: - case RuntimeConstants.CONSTANT_INTERFACEMETHOD: - case RuntimeConstants.CONSTANT_NAMEANDTYPE: - /* unclear how to handle for now */ - default: - throw new IllegalStateException("Unhandled constant tag"); - } - } - - public static int fromFieldType(final char fieldType) { - switch (fieldType) { - case 'B': - case 'C': - case 'S': - case 'Z': - case 'I': - return VarType.INTEGER; - case 'J': - return VarType.LONG; - case 'F': - return VarType.FLOAT; - case 'D': - return VarType.DOUBLE; - case 'L': - case '[': - return VarType.REFERENCE; - - default: - throw new IllegalStateException("Unhandled field type"); - } - } -} +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.vm4brwsr; + +import org.apidesign.javap.RuntimeConstants; + +final class VarType { + public static final int INTEGER = 0; + public static final int LONG = 1; + public static final int FLOAT = 2; + public static final int DOUBLE = 3; + public static final int REFERENCE = 4; + + public static final int LAST = REFERENCE; + + private VarType() { + } + + public static boolean isCategory2(final int varType) { + return (varType == LONG) || (varType == DOUBLE); + } + + public static int fromStackMapType(final int smType) { + switch (smType & 0xff) { + case RuntimeConstants.ITEM_Integer: + return VarType.INTEGER; + case RuntimeConstants.ITEM_Float: + return VarType.FLOAT; + case RuntimeConstants.ITEM_Double: + return VarType.DOUBLE; + case RuntimeConstants.ITEM_Long: + return VarType.LONG; + case RuntimeConstants.ITEM_Object: + return VarType.REFERENCE; + + case RuntimeConstants.ITEM_Bogus: + case RuntimeConstants.ITEM_Null: + case RuntimeConstants.ITEM_InitObject: + case RuntimeConstants.ITEM_NewObject: + /* unclear how to handle for now */ + default: + throw new IllegalStateException("Unhandled stack map type"); + } + } + + public static int fromConstantType(final byte constantTag) { + switch (constantTag) { + case RuntimeConstants.CONSTANT_INTEGER: + return VarType.INTEGER; + case RuntimeConstants.CONSTANT_FLOAT: + return VarType.FLOAT; + case RuntimeConstants.CONSTANT_LONG: + return VarType.LONG; + case RuntimeConstants.CONSTANT_DOUBLE: + return VarType.DOUBLE; + + case RuntimeConstants.CONSTANT_CLASS: + case RuntimeConstants.CONSTANT_UTF8: + case RuntimeConstants.CONSTANT_UNICODE: + case RuntimeConstants.CONSTANT_STRING: + return VarType.REFERENCE; + + case RuntimeConstants.CONSTANT_FIELD: + case RuntimeConstants.CONSTANT_METHOD: + case RuntimeConstants.CONSTANT_INTERFACEMETHOD: + case RuntimeConstants.CONSTANT_NAMEANDTYPE: + /* unclear how to handle for now */ + default: + throw new IllegalStateException("Unhandled constant tag"); + } + } + + public static int fromFieldType(final char fieldType) { + switch (fieldType) { + case 'B': + case 'C': + case 'S': + case 'Z': + case 'I': + return VarType.INTEGER; + case 'J': + return VarType.LONG; + case 'F': + return VarType.FLOAT; + case 'D': + return VarType.DOUBLE; + case 'L': + case '[': + return VarType.REFERENCE; + + default: + throw new IllegalStateException("Unhandled field type"); + } + } +} diff -r 15cbc8cb2163 -r 83f638b13242 vm/src/main/java/org/apidesign/vm4brwsr/Variable.java --- a/vm/src/main/java/org/apidesign/vm4brwsr/Variable.java Fri Dec 14 11:15:37 2012 +0100 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Variable.java Fri Dec 14 15:06:53 2012 +0100 @@ -1,100 +1,100 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.vm4brwsr; - -final class Variable implements CharSequence { - private static final String STACK_VAR_PREFIX = "st"; - private static final String LOCAL_VAR_PREFIX = "lc"; - - private final String name; - private final int type; - private final int index; - - private static final char[] TYPE_IDS = { 'I', 'L', 'F', 'D', 'A' }; - - private Variable(final String prefix, final int type, final int index) { - this.name = prefix + TYPE_IDS[type] + index; - this.type = type; - this.index = index; - } - - public static Variable getStackVariable( - final int type, final int index) { - // TODO: precreate frequently used variables - return new Variable(STACK_VAR_PREFIX, type, index); - } - - public static Variable getLocalVariable( - final int type, final int index) { - // TODO: precreate frequently used variables - return new Variable(LOCAL_VAR_PREFIX, type, index); - } - - public String getName() { - return name; - } - - public int getType() { - return type; - } - - public int getIndex() { - return index; - } - - public boolean isCategory2() { - return VarType.isCategory2(type); - } - - @Override - public int length() { - return name.length(); - } - - @Override - public char charAt(final int index) { - return name.charAt(index); - } - - @Override - public CharSequence subSequence(final int start, final int end) { - return name.subSequence(start, end); - } - - @Override - public int hashCode() { - return name.hashCode(); - } - - @Override - public boolean equals(final Object other) { - if (this == other) { - return true; - } - if (!(other instanceof Variable)) { - return false; - } - - return name.equals(((Variable) other).name); - } - - @Override - public String toString() { - return name; - } -} +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.vm4brwsr; + +final class Variable implements CharSequence { + private static final String STACK_VAR_PREFIX = "st"; + private static final String LOCAL_VAR_PREFIX = "lc"; + + private final String name; + private final int type; + private final int index; + + private static final char[] TYPE_IDS = { 'I', 'L', 'F', 'D', 'A' }; + + private Variable(final String prefix, final int type, final int index) { + this.name = prefix + TYPE_IDS[type] + index; + this.type = type; + this.index = index; + } + + public static Variable getStackVariable( + final int type, final int index) { + // TODO: precreate frequently used variables + return new Variable(STACK_VAR_PREFIX, type, index); + } + + public static Variable getLocalVariable( + final int type, final int index) { + // TODO: precreate frequently used variables + return new Variable(LOCAL_VAR_PREFIX, type, index); + } + + public String getName() { + return name; + } + + public int getType() { + return type; + } + + public int getIndex() { + return index; + } + + public boolean isCategory2() { + return VarType.isCategory2(type); + } + + @Override + public int length() { + return name.length(); + } + + @Override + public char charAt(final int index) { + return name.charAt(index); + } + + @Override + public CharSequence subSequence(final int start, final int end) { + return name.subSequence(start, end); + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(final Object other) { + if (this == other) { + return true; + } + if (!(other instanceof Variable)) { + return false; + } + + return name.equals(((Variable) other).name); + } + + @Override + public String toString() { + return name; + } +}