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