01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 1997-1999 Raja Vallee-Rai
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: */
19:
20: /*
21: * Modified by the Sable Research Group and others 1997-1999.
22: * See the 'credits' file distributed with Soot for the complete list of
23: * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24: */
25:
26: package soot;
27:
28: import soot.util.*;
29: import java.io.*;
30:
31: /** Represents types within Soot, eg <code>int</code>, <code>java.lang.String</code>. */
32: public abstract class Type implements Switchable, Serializable,
33: Numberable {
34: public Type() {
35: Scene.v().getTypeNumberer().add(this );
36: }
37:
38: /** Returns a textual representation of this type. */
39: public abstract String toString();
40:
41: /** Converts the int-like types (short, byte, boolean and char) to IntType. */
42: public static Type toMachineType(Type t) {
43: if (t.equals(ShortType.v()) || t.equals(ByteType.v())
44: || t.equals(BooleanType.v()) || t.equals(CharType.v())) {
45: return IntType.v();
46: } else
47: return t;
48: }
49:
50: /** Returns the least common superclass of this type and other. */
51: public Type merge(Type other, Scene cm) {
52: // method overriden in subclasses UnknownType and RefType
53: throw new RuntimeException("illegal type merge: " + this
54: + " and " + other);
55: }
56:
57: /** Method required for use of Switchable. */
58: public void apply(Switch sw) {
59: }
60:
61: public void setArrayType(ArrayType at) {
62: arrayType = at;
63: }
64:
65: public ArrayType getArrayType() {
66: return arrayType;
67: }
68:
69: public ArrayType makeArrayType() {
70: return ArrayType.v(this , 1);
71: }
72:
73: public final int getNumber() {
74: return number;
75: }
76:
77: public final void setNumber(int number) {
78: this .number = number;
79: }
80:
81: protected ArrayType arrayType;
82: private int number = 0;
83: }
|