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