vm/src/main/java/org/apidesign/vm4brwsr/VarType.java
branchregisters
changeset 319 83f638b13242
parent 310 ec7d8bc17725
child 584 925d2de2a277
     1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/VarType.java	Wed Dec 12 14:07:53 2012 +0100
     1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VarType.java	Fri Dec 14 15:06:53 2012 +0100
     1.3 @@ -1,110 +1,110 @@
     1.4 -/**
     1.5 - * Back 2 Browser Bytecode Translator
     1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 - *
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, version 2 of the License.
    1.11 - *
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 - * GNU General Public License for more details.
    1.16 - *
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program. Look for COPYING file in the top folder.
    1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 - */
    1.21 -package org.apidesign.vm4brwsr;
    1.22 -
    1.23 -import org.apidesign.javap.RuntimeConstants;
    1.24 -
    1.25 -final class VarType {
    1.26 -    public static final int INTEGER = 0;
    1.27 -    public static final int LONG = 1;
    1.28 -    public static final int FLOAT = 2;
    1.29 -    public static final int DOUBLE = 3;
    1.30 -    public static final int REFERENCE = 4;
    1.31 -
    1.32 -    public static final int LAST = REFERENCE;
    1.33 -
    1.34 -    private VarType() {
    1.35 -    }
    1.36 -
    1.37 -    public static boolean isCategory2(final int varType) {
    1.38 -        return (varType == LONG) || (varType == DOUBLE);
    1.39 -    }
    1.40 -
    1.41 -    public static int fromStackMapType(final int smType) {
    1.42 -        switch (smType & 0xff) {
    1.43 -            case RuntimeConstants.ITEM_Integer:
    1.44 -                return VarType.INTEGER;
    1.45 -            case RuntimeConstants.ITEM_Float:
    1.46 -                return VarType.FLOAT;
    1.47 -            case RuntimeConstants.ITEM_Double:
    1.48 -                return VarType.DOUBLE;
    1.49 -            case RuntimeConstants.ITEM_Long:
    1.50 -                return VarType.LONG;
    1.51 -            case RuntimeConstants.ITEM_Object:
    1.52 -                return VarType.REFERENCE;
    1.53 -
    1.54 -            case RuntimeConstants.ITEM_Bogus:
    1.55 -            case RuntimeConstants.ITEM_Null:
    1.56 -            case RuntimeConstants.ITEM_InitObject:
    1.57 -            case RuntimeConstants.ITEM_NewObject:
    1.58 -                /* unclear how to handle for now */
    1.59 -            default:
    1.60 -                throw new IllegalStateException("Unhandled stack map type");
    1.61 -        }
    1.62 -    }
    1.63 -
    1.64 -    public static int fromConstantType(final byte constantTag) {
    1.65 -        switch (constantTag) {
    1.66 -            case RuntimeConstants.CONSTANT_INTEGER:
    1.67 -                return VarType.INTEGER;
    1.68 -            case RuntimeConstants.CONSTANT_FLOAT:
    1.69 -                return VarType.FLOAT;
    1.70 -            case RuntimeConstants.CONSTANT_LONG:
    1.71 -                return VarType.LONG;
    1.72 -            case RuntimeConstants.CONSTANT_DOUBLE:
    1.73 -                return VarType.DOUBLE;
    1.74 -
    1.75 -            case RuntimeConstants.CONSTANT_CLASS:
    1.76 -            case RuntimeConstants.CONSTANT_UTF8:
    1.77 -            case RuntimeConstants.CONSTANT_UNICODE:
    1.78 -            case RuntimeConstants.CONSTANT_STRING:
    1.79 -                return VarType.REFERENCE;
    1.80 -
    1.81 -            case RuntimeConstants.CONSTANT_FIELD:
    1.82 -            case RuntimeConstants.CONSTANT_METHOD:
    1.83 -            case RuntimeConstants.CONSTANT_INTERFACEMETHOD:
    1.84 -            case RuntimeConstants.CONSTANT_NAMEANDTYPE:
    1.85 -                /* unclear how to handle for now */
    1.86 -            default:
    1.87 -                throw new IllegalStateException("Unhandled constant tag");
    1.88 -        }
    1.89 -    }
    1.90 -
    1.91 -    public static int fromFieldType(final char fieldType) {
    1.92 -        switch (fieldType) {
    1.93 -            case 'B':
    1.94 -            case 'C':
    1.95 -            case 'S':
    1.96 -            case 'Z':
    1.97 -            case 'I':
    1.98 -                return VarType.INTEGER;
    1.99 -            case 'J':
   1.100 -                return VarType.LONG;
   1.101 -            case 'F':
   1.102 -                return VarType.FLOAT;
   1.103 -            case 'D':
   1.104 -                return VarType.DOUBLE;
   1.105 -            case 'L':
   1.106 -            case '[':
   1.107 -                return VarType.REFERENCE;
   1.108 -
   1.109 -            default:
   1.110 -                throw new IllegalStateException("Unhandled field type");
   1.111 -        }
   1.112 -    }
   1.113 -}
   1.114 +/**
   1.115 + * Back 2 Browser Bytecode Translator
   1.116 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
   1.117 + *
   1.118 + * This program is free software: you can redistribute it and/or modify
   1.119 + * it under the terms of the GNU General Public License as published by
   1.120 + * the Free Software Foundation, version 2 of the License.
   1.121 + *
   1.122 + * This program is distributed in the hope that it will be useful,
   1.123 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   1.124 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   1.125 + * GNU General Public License for more details.
   1.126 + *
   1.127 + * You should have received a copy of the GNU General Public License
   1.128 + * along with this program. Look for COPYING file in the top folder.
   1.129 + * If not, see http://opensource.org/licenses/GPL-2.0.
   1.130 + */
   1.131 +package org.apidesign.vm4brwsr;
   1.132 +
   1.133 +import org.apidesign.javap.RuntimeConstants;
   1.134 +
   1.135 +final class VarType {
   1.136 +    public static final int INTEGER = 0;
   1.137 +    public static final int LONG = 1;
   1.138 +    public static final int FLOAT = 2;
   1.139 +    public static final int DOUBLE = 3;
   1.140 +    public static final int REFERENCE = 4;
   1.141 +
   1.142 +    public static final int LAST = REFERENCE;
   1.143 +
   1.144 +    private VarType() {
   1.145 +    }
   1.146 +
   1.147 +    public static boolean isCategory2(final int varType) {
   1.148 +        return (varType == LONG) || (varType == DOUBLE);
   1.149 +    }
   1.150 +
   1.151 +    public static int fromStackMapType(final int smType) {
   1.152 +        switch (smType & 0xff) {
   1.153 +            case RuntimeConstants.ITEM_Integer:
   1.154 +                return VarType.INTEGER;
   1.155 +            case RuntimeConstants.ITEM_Float:
   1.156 +                return VarType.FLOAT;
   1.157 +            case RuntimeConstants.ITEM_Double:
   1.158 +                return VarType.DOUBLE;
   1.159 +            case RuntimeConstants.ITEM_Long:
   1.160 +                return VarType.LONG;
   1.161 +            case RuntimeConstants.ITEM_Object:
   1.162 +                return VarType.REFERENCE;
   1.163 +
   1.164 +            case RuntimeConstants.ITEM_Bogus:
   1.165 +            case RuntimeConstants.ITEM_Null:
   1.166 +            case RuntimeConstants.ITEM_InitObject:
   1.167 +            case RuntimeConstants.ITEM_NewObject:
   1.168 +                /* unclear how to handle for now */
   1.169 +            default:
   1.170 +                throw new IllegalStateException("Unhandled stack map type");
   1.171 +        }
   1.172 +    }
   1.173 +
   1.174 +    public static int fromConstantType(final byte constantTag) {
   1.175 +        switch (constantTag) {
   1.176 +            case RuntimeConstants.CONSTANT_INTEGER:
   1.177 +                return VarType.INTEGER;
   1.178 +            case RuntimeConstants.CONSTANT_FLOAT:
   1.179 +                return VarType.FLOAT;
   1.180 +            case RuntimeConstants.CONSTANT_LONG:
   1.181 +                return VarType.LONG;
   1.182 +            case RuntimeConstants.CONSTANT_DOUBLE:
   1.183 +                return VarType.DOUBLE;
   1.184 +
   1.185 +            case RuntimeConstants.CONSTANT_CLASS:
   1.186 +            case RuntimeConstants.CONSTANT_UTF8:
   1.187 +            case RuntimeConstants.CONSTANT_UNICODE:
   1.188 +            case RuntimeConstants.CONSTANT_STRING:
   1.189 +                return VarType.REFERENCE;
   1.190 +
   1.191 +            case RuntimeConstants.CONSTANT_FIELD:
   1.192 +            case RuntimeConstants.CONSTANT_METHOD:
   1.193 +            case RuntimeConstants.CONSTANT_INTERFACEMETHOD:
   1.194 +            case RuntimeConstants.CONSTANT_NAMEANDTYPE:
   1.195 +                /* unclear how to handle for now */
   1.196 +            default:
   1.197 +                throw new IllegalStateException("Unhandled constant tag");
   1.198 +        }
   1.199 +    }
   1.200 +
   1.201 +    public static int fromFieldType(final char fieldType) {
   1.202 +        switch (fieldType) {
   1.203 +            case 'B':
   1.204 +            case 'C':
   1.205 +            case 'S':
   1.206 +            case 'Z':
   1.207 +            case 'I':
   1.208 +                return VarType.INTEGER;
   1.209 +            case 'J':
   1.210 +                return VarType.LONG;
   1.211 +            case 'F':
   1.212 +                return VarType.FLOAT;
   1.213 +            case 'D':
   1.214 +                return VarType.DOUBLE;
   1.215 +            case 'L':
   1.216 +            case '[':
   1.217 +                return VarType.REFERENCE;
   1.218 +
   1.219 +            default:
   1.220 +                throw new IllegalStateException("Unhandled field type");
   1.221 +        }
   1.222 +    }
   1.223 +}