lubomir@319: /** lubomir@319: * Back 2 Browser Bytecode Translator lubomir@319: * Copyright (C) 2012 Jaroslav Tulach lubomir@319: * lubomir@319: * This program is free software: you can redistribute it and/or modify lubomir@319: * it under the terms of the GNU General Public License as published by lubomir@319: * the Free Software Foundation, version 2 of the License. lubomir@319: * lubomir@319: * This program is distributed in the hope that it will be useful, lubomir@319: * but WITHOUT ANY WARRANTY; without even the implied warranty of lubomir@319: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the lubomir@319: * GNU General Public License for more details. lubomir@319: * lubomir@319: * You should have received a copy of the GNU General Public License lubomir@319: * along with this program. Look for COPYING file in the top folder. lubomir@319: * If not, see http://opensource.org/licenses/GPL-2.0. lubomir@319: */ lubomir@319: package org.apidesign.vm4brwsr; lubomir@319: lubomir@319: import org.apidesign.javap.RuntimeConstants; lubomir@319: lubomir@319: final class VarType { lubomir@319: public static final int INTEGER = 0; lubomir@319: public static final int LONG = 1; lubomir@319: public static final int FLOAT = 2; lubomir@319: public static final int DOUBLE = 3; lubomir@319: public static final int REFERENCE = 4; lubomir@319: lubomir@319: public static final int LAST = REFERENCE; lubomir@319: lubomir@319: private VarType() { lubomir@319: } lubomir@319: lubomir@319: public static boolean isCategory2(final int varType) { lubomir@319: return (varType == LONG) || (varType == DOUBLE); lubomir@319: } lubomir@319: lubomir@319: public static int fromStackMapType(final int smType) { lubomir@319: switch (smType & 0xff) { lubomir@319: case RuntimeConstants.ITEM_Integer: lubomir@319: return VarType.INTEGER; lubomir@319: case RuntimeConstants.ITEM_Float: lubomir@319: return VarType.FLOAT; lubomir@319: case RuntimeConstants.ITEM_Double: lubomir@319: return VarType.DOUBLE; lubomir@319: case RuntimeConstants.ITEM_Long: lubomir@319: return VarType.LONG; lubomir@584: case RuntimeConstants.ITEM_Null: lubomir@584: case RuntimeConstants.ITEM_InitObject: lubomir@319: case RuntimeConstants.ITEM_Object: lubomir@584: case RuntimeConstants.ITEM_NewObject: lubomir@319: return VarType.REFERENCE; lubomir@319: lubomir@319: case RuntimeConstants.ITEM_Bogus: lubomir@319: /* unclear how to handle for now */ lubomir@319: default: lubomir@319: throw new IllegalStateException("Unhandled stack map type"); lubomir@319: } lubomir@319: } lubomir@319: lubomir@319: public static int fromConstantType(final byte constantTag) { lubomir@319: switch (constantTag) { lubomir@319: case RuntimeConstants.CONSTANT_INTEGER: lubomir@319: return VarType.INTEGER; lubomir@319: case RuntimeConstants.CONSTANT_FLOAT: lubomir@319: return VarType.FLOAT; lubomir@319: case RuntimeConstants.CONSTANT_LONG: lubomir@319: return VarType.LONG; lubomir@319: case RuntimeConstants.CONSTANT_DOUBLE: lubomir@319: return VarType.DOUBLE; lubomir@319: lubomir@319: case RuntimeConstants.CONSTANT_CLASS: lubomir@319: case RuntimeConstants.CONSTANT_UTF8: lubomir@319: case RuntimeConstants.CONSTANT_UNICODE: lubomir@319: case RuntimeConstants.CONSTANT_STRING: lubomir@319: return VarType.REFERENCE; lubomir@319: lubomir@319: case RuntimeConstants.CONSTANT_FIELD: lubomir@319: case RuntimeConstants.CONSTANT_METHOD: lubomir@319: case RuntimeConstants.CONSTANT_INTERFACEMETHOD: lubomir@319: case RuntimeConstants.CONSTANT_NAMEANDTYPE: lubomir@319: /* unclear how to handle for now */ lubomir@319: default: lubomir@319: throw new IllegalStateException("Unhandled constant tag"); lubomir@319: } lubomir@319: } lubomir@319: lubomir@319: public static int fromFieldType(final char fieldType) { lubomir@319: switch (fieldType) { lubomir@319: case 'B': lubomir@319: case 'C': lubomir@319: case 'S': lubomir@319: case 'Z': lubomir@319: case 'I': lubomir@319: return VarType.INTEGER; lubomir@319: case 'J': lubomir@319: return VarType.LONG; lubomir@319: case 'F': lubomir@319: return VarType.FLOAT; lubomir@319: case 'D': lubomir@319: return VarType.DOUBLE; lubomir@319: case 'L': lubomir@319: case '[': lubomir@319: return VarType.REFERENCE; lubomir@319: lubomir@319: default: lubomir@319: throw new IllegalStateException("Unhandled field type"); lubomir@319: } lubomir@319: } lubomir@319: }