1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.experimental.bytecode; 25 26 public enum TypeTag implements Type { 27 /** 28 * byte 29 */ 30 B("B", 0, 1, 8), 31 /** 32 * short 33 */ 34 S("S", 0, 1, 9), 35 /** 36 * int 37 */ 38 I("I", 0, 1, 10), 39 /** 40 * float 41 */ 42 F("F", 2, 1, 6), 43 /** 44 * long 45 */ 46 J("J", 1, 2, 11), 47 /** 48 * double 49 */ 50 D("D", 3, 2, 7), 51 /** 52 * Reference type 53 */ 54 A("A", 4, 1, -1), 55 /** 56 * char 57 */ 58 C("C", 0, 1, 5), 59 /** 60 * boolean 61 */ 62 Z("Z", 0, 1, 4), 63 /** 64 * void 65 */ 66 V("V", -1, -1, -1), 67 /** 68 * Value type 69 */ 70 Q("Q", -1, 1, -1); 71 72 String typeStr; 73 int offset; 74 int width; 75 int newarraycode; 76 77 TypeTag(String typeStr, int offset, int width, int newarraycode) { 78 this.typeStr = typeStr; 79 this.offset = offset; 80 this.width = width; 81 this.newarraycode = newarraycode; 82 } 83 84 static TypeTag commonSupertype(TypeTag t1, TypeTag t2) { 85 if (t1.isIntegral() && t2.isIntegral()) { 86 int p1 = t1.ordinal(); 87 int p2 = t2.ordinal(); 88 return (p1 <= p2) ? t2 : t1; 89 } else { 90 return null; 91 } 92 } 93 94 public int width() { 95 return width; 96 } 97 98 boolean isIntegral() { 99 switch (this) { 100 case B: 101 case S: 102 case I: 103 return true; 104 default: 105 return false; 106 } 107 } 108 109 @Override 110 public TypeTag getTag() { 111 return this; 112 } 113 }