vm/src/main/java/org/apidesign/vm4brwsr/VarType.java
author Lubomir Nerad <lubomir.nerad@oracle.com>
Wed, 12 Dec 2012 14:07:53 +0100
branchregisters
changeset 310 ec7d8bc17725
parent 307 eaf4e8387065
child 319 83f638b13242
permissions -rwxr-xr-x
Made helper classes package private
lubomir@307
     1
/**
lubomir@307
     2
 * Back 2 Browser Bytecode Translator
lubomir@307
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
lubomir@307
     4
 *
lubomir@307
     5
 * This program is free software: you can redistribute it and/or modify
lubomir@307
     6
 * it under the terms of the GNU General Public License as published by
lubomir@307
     7
 * the Free Software Foundation, version 2 of the License.
lubomir@307
     8
 *
lubomir@307
     9
 * This program is distributed in the hope that it will be useful,
lubomir@307
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
lubomir@307
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
lubomir@307
    12
 * GNU General Public License for more details.
lubomir@307
    13
 *
lubomir@307
    14
 * You should have received a copy of the GNU General Public License
lubomir@307
    15
 * along with this program. Look for COPYING file in the top folder.
lubomir@307
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
lubomir@307
    17
 */
lubomir@307
    18
package org.apidesign.vm4brwsr;
lubomir@307
    19
lubomir@307
    20
import org.apidesign.javap.RuntimeConstants;
lubomir@307
    21
lubomir@310
    22
final class VarType {
lubomir@307
    23
    public static final int INTEGER = 0;
lubomir@307
    24
    public static final int LONG = 1;
lubomir@307
    25
    public static final int FLOAT = 2;
lubomir@307
    26
    public static final int DOUBLE = 3;
lubomir@307
    27
    public static final int REFERENCE = 4;
lubomir@307
    28
lubomir@307
    29
    public static final int LAST = REFERENCE;
lubomir@307
    30
lubomir@307
    31
    private VarType() {
lubomir@307
    32
    }
lubomir@307
    33
lubomir@307
    34
    public static boolean isCategory2(final int varType) {
lubomir@307
    35
        return (varType == LONG) || (varType == DOUBLE);
lubomir@307
    36
    }
lubomir@307
    37
lubomir@307
    38
    public static int fromStackMapType(final int smType) {
lubomir@307
    39
        switch (smType & 0xff) {
lubomir@307
    40
            case RuntimeConstants.ITEM_Integer:
lubomir@307
    41
                return VarType.INTEGER;
lubomir@307
    42
            case RuntimeConstants.ITEM_Float:
lubomir@307
    43
                return VarType.FLOAT;
lubomir@307
    44
            case RuntimeConstants.ITEM_Double:
lubomir@307
    45
                return VarType.DOUBLE;
lubomir@307
    46
            case RuntimeConstants.ITEM_Long:
lubomir@307
    47
                return VarType.LONG;
lubomir@307
    48
            case RuntimeConstants.ITEM_Object:
lubomir@307
    49
                return VarType.REFERENCE;
lubomir@307
    50
lubomir@307
    51
            case RuntimeConstants.ITEM_Bogus:
lubomir@307
    52
            case RuntimeConstants.ITEM_Null:
lubomir@307
    53
            case RuntimeConstants.ITEM_InitObject:
lubomir@307
    54
            case RuntimeConstants.ITEM_NewObject:
lubomir@307
    55
                /* unclear how to handle for now */
lubomir@307
    56
            default:
lubomir@307
    57
                throw new IllegalStateException("Unhandled stack map type");
lubomir@307
    58
        }
lubomir@307
    59
    }
lubomir@307
    60
lubomir@307
    61
    public static int fromConstantType(final byte constantTag) {
lubomir@307
    62
        switch (constantTag) {
lubomir@307
    63
            case RuntimeConstants.CONSTANT_INTEGER:
lubomir@307
    64
                return VarType.INTEGER;
lubomir@307
    65
            case RuntimeConstants.CONSTANT_FLOAT:
lubomir@307
    66
                return VarType.FLOAT;
lubomir@307
    67
            case RuntimeConstants.CONSTANT_LONG:
lubomir@307
    68
                return VarType.LONG;
lubomir@307
    69
            case RuntimeConstants.CONSTANT_DOUBLE:
lubomir@307
    70
                return VarType.DOUBLE;
lubomir@307
    71
lubomir@307
    72
            case RuntimeConstants.CONSTANT_CLASS:
lubomir@307
    73
            case RuntimeConstants.CONSTANT_UTF8:
lubomir@307
    74
            case RuntimeConstants.CONSTANT_UNICODE:
lubomir@307
    75
            case RuntimeConstants.CONSTANT_STRING:
lubomir@307
    76
                return VarType.REFERENCE;
lubomir@307
    77
lubomir@307
    78
            case RuntimeConstants.CONSTANT_FIELD:
lubomir@307
    79
            case RuntimeConstants.CONSTANT_METHOD:
lubomir@307
    80
            case RuntimeConstants.CONSTANT_INTERFACEMETHOD:
lubomir@307
    81
            case RuntimeConstants.CONSTANT_NAMEANDTYPE:
lubomir@307
    82
                /* unclear how to handle for now */
lubomir@307
    83
            default:
lubomir@307
    84
                throw new IllegalStateException("Unhandled constant tag");
lubomir@307
    85
        }
lubomir@307
    86
    }
lubomir@307
    87
lubomir@307
    88
    public static int fromFieldType(final char fieldType) {
lubomir@307
    89
        switch (fieldType) {
lubomir@307
    90
            case 'B':
lubomir@307
    91
            case 'C':
lubomir@307
    92
            case 'S':
lubomir@307
    93
            case 'Z':
lubomir@307
    94
            case 'I':
lubomir@307
    95
                return VarType.INTEGER;
lubomir@307
    96
            case 'J':
lubomir@307
    97
                return VarType.LONG;
lubomir@307
    98
            case 'F':
lubomir@307
    99
                return VarType.FLOAT;
lubomir@307
   100
            case 'D':
lubomir@307
   101
                return VarType.DOUBLE;
lubomir@307
   102
            case 'L':
lubomir@307
   103
            case '[':
lubomir@307
   104
                return VarType.REFERENCE;
lubomir@307
   105
lubomir@307
   106
            default:
lubomir@307
   107
                throw new IllegalStateException("Unhandled field type");
lubomir@307
   108
        }
lubomir@307
   109
    }
lubomir@307
   110
}