1 /*
   2  * Copyright (c) 2000, 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 
  25 package sun.jvm.hotspot.runtime;
  26 
  27 /** Encapsulates the BasicType enum in globalDefinitions.hpp in the
  28     VM. */
  29 
  30 public class BasicType {
  31   public static final int tBoolean  = 4;
  32   public static final int tChar     = 5;
  33   public static final int tFloat    = 6;
  34   public static final int tDouble   = 7;
  35   public static final int tByte     = 8;
  36   public static final int tShort    = 9;
  37   public static final int tInt      = 10;
  38   public static final int tLong     = 11;
  39   public static final int tObject   = 12;
  40   public static final int tArray    = 13;
  41   public static final int tVoid     = 14;
  42   public static final int tAddress  = 15;
  43   public static final int tConflict = 16;
  44   public static final int tIllegal  = 99;
  45 
  46   public static final BasicType T_BOOLEAN = new BasicType(tBoolean, "boolean");
  47   public static final BasicType T_CHAR = new BasicType(tChar, "char");
  48   public static final BasicType T_FLOAT = new BasicType(tFloat, "float");
  49   public static final BasicType T_DOUBLE = new BasicType(tDouble, "double");
  50   public static final BasicType T_BYTE = new BasicType(tByte, "byte");
  51   public static final BasicType T_SHORT = new BasicType(tShort, "short");
  52   public static final BasicType T_INT = new BasicType(tInt, "int");
  53   public static final BasicType T_LONG = new BasicType(tLong, "long");
  54   public static final BasicType T_OBJECT = new BasicType(tObject, "object");
  55   public static final BasicType T_ARRAY = new BasicType(tArray, "array");
  56   public static final BasicType T_VOID = new BasicType(tVoid, "void");
  57   public static final BasicType T_ADDRESS = new BasicType(tAddress, "*address");
  58   public static final BasicType T_CONFLICT = new BasicType(tConflict, "*conflict");
  59   public static final BasicType T_ILLEGAL = new BasicType(tIllegal, "ILLEGAL TYPE");
  60 
  61   public static int getTBoolean() {
  62     return tBoolean;
  63   }
  64 
  65   public static int getTChar() {
  66     return tChar;
  67   }
  68 
  69   public static int getTFloat() {
  70     return tFloat;
  71   }
  72 
  73   public static int getTDouble() {
  74     return tDouble;
  75   }
  76 
  77   public static int getTByte() {
  78     return tByte;
  79   }
  80 
  81   public static int getTShort() {
  82     return tShort;
  83   }
  84 
  85   public static int getTInt() {
  86     return tInt;
  87   }
  88 
  89   public static int getTLong() {
  90     return tLong;
  91   }
  92 
  93   public static int getTObject() {
  94     return tObject;
  95   }
  96 
  97   public static int getTArray() {
  98     return tArray;
  99   }
 100 
 101   public static int getTVoid() {
 102     return tVoid;
 103   }
 104 
 105   public static int getTAddress() {
 106     return tAddress;
 107   }
 108 
 109   /** For stack value type with conflicting contents */
 110   public static int getTConflict() {
 111     return tConflict;
 112   }
 113 
 114   public static int getTIllegal() {
 115     return tIllegal;
 116   }
 117 
 118   public static BasicType intToBasicType(int i) {
 119     switch( i ) {
 120     case tByte: return T_BYTE;
 121     case tChar: return T_CHAR;
 122     case tDouble: return T_DOUBLE;
 123     case tFloat: return T_FLOAT;
 124     case tInt: return T_INT;
 125     case tLong: return T_LONG;
 126     case tShort: return T_SHORT;
 127     case tBoolean: return T_BOOLEAN;
 128     case tVoid: return T_VOID;
 129     case tObject: return T_OBJECT;
 130     case tArray: return T_ARRAY;
 131     }
 132     return T_ILLEGAL;
 133   }
 134 
 135   public static BasicType charToBasicType(char c) {
 136     switch( c ) {
 137     case 'B': return T_BYTE;
 138     case 'C': return T_CHAR;
 139     case 'D': return T_DOUBLE;
 140     case 'F': return T_FLOAT;
 141     case 'I': return T_INT;
 142     case 'J': return T_LONG;
 143     case 'S': return T_SHORT;
 144     case 'Z': return T_BOOLEAN;
 145     case 'V': return T_VOID;
 146     case 'L': return T_OBJECT;
 147     case '[': return T_ARRAY;
 148     }
 149     return T_ILLEGAL;
 150   }
 151 
 152   public static int charToType(char c) {
 153     return charToBasicType(c).getType();
 154   }
 155 
 156   public int getType() {
 157     return type;
 158   }
 159 
 160   public String getName() {
 161     return name;
 162   }
 163 
 164   //-- Internals only below this point
 165   private BasicType(int type, String name) {
 166     this.type = type;
 167     this.name = name;
 168   }
 169 
 170   private int type;
 171   private String name;
 172 }
--- EOF ---