01: /*
02:
03: Derby - Class org.apache.derby.impl.services.bytecode.Type
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derby.impl.services.bytecode;
23:
24: import org.apache.derby.iapi.services.classfile.VMDescriptor;
25: import org.apache.derby.iapi.services.classfile.ClassHolder;
26:
27: final class Type {
28:
29: static final Type LONG = new Type("long", VMDescriptor.LONG);
30: static final Type INT = new Type("int", VMDescriptor.INT);
31: static final Type SHORT = new Type("short", VMDescriptor.SHORT);
32: static final Type BYTE = new Type("byte", VMDescriptor.BYTE);
33: static final Type BOOLEAN = new Type("boolean",
34: VMDescriptor.BOOLEAN);
35: static final Type FLOAT = new Type("float", VMDescriptor.FLOAT);
36: static final Type DOUBLE = new Type("double", VMDescriptor.DOUBLE);
37: static final Type STRING = new Type("java.lang.String",
38: "Ljava/lang/String;");
39:
40: private final String javaName; // e.g. java.lang.Object
41: private final short vmType; // e.g. BCExpr.vm_reference
42: private final String vmName; // e.g. Ljava/lang/Object;
43: final String vmNameSimple; // e.g. java/lang/Object
44:
45: Type(String javaName, String vmName) {
46: this .vmName = vmName;
47: this .javaName = javaName;
48: vmType = BCJava.vmTypeId(vmName);
49: vmNameSimple = ClassHolder.convertToInternalClassName(javaName);
50: }
51:
52: /*
53: ** Class specific methods.
54: */
55:
56: String javaName() {
57: return javaName;
58: }
59:
60: /**
61: * Get the VM Type name (java/lang/Object)
62: */
63: String vmName() {
64: return vmName;
65: }
66:
67: /**
68: Get the VM type (eg. VMDescriptor.INT)
69: */
70: short vmType() {
71: return vmType;
72: }
73:
74: int width() {
75: return Type.width(vmType);
76: }
77:
78: static int width(short type) {
79: switch (type) {
80: case BCExpr.vm_void:
81: return 0;
82: case BCExpr.vm_long:
83: case BCExpr.vm_double:
84: return 2;
85: default:
86: return 1;
87: }
88: }
89: }
|