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