KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > Type


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997-1999 Raja Vallee-Rai
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * 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
27 package soot;
28
29 import soot.util.*;
30 import java.util.*;
31 import java.io.*;
32
33 /** Represents types within Soot, eg <code>int</code>, <code>java.lang.String</code>. */
34 public abstract class Type implements Switchable, Serializable, Numberable
35 {
36     public Type() {
37         Scene.v().getTypeNumberer().add( this );
38     }
39     /** Returns a textual representation of this type. */
40     public abstract String JavaDoc toString();
41     
42     /** Converts the int-like types (short, byte, boolean and char) to IntType. */
43     public static Type toMachineType(Type t)
44     {
45         if(t.equals(ShortType.v()) || t.equals(ByteType.v()) ||
46             t.equals(BooleanType.v()) || t.equals(CharType.v()))
47         {
48             return IntType.v();
49         }
50         else
51             return t;
52     }
53
54
55     /** Returns the least common superclass of this type and other. */
56     public Type merge(Type other, Scene cm)
57     {
58         // method overriden in subclasses UnknownType and RefType
59
throw new RuntimeException JavaDoc("illegal type merge: "
60                                    + this + " and " + other);
61     }
62
63     /** Method required for use of Switchable. */
64     public void apply(Switch sw)
65     {
66     }
67
68     public void setArrayType( ArrayType at ) {
69         arrayType = at;
70     }
71     public ArrayType getArrayType() {
72         return arrayType;
73     }
74     public ArrayType makeArrayType() {
75         return ArrayType.v( this, 1 );
76     }
77
78     public final int getNumber() { return number; }
79     public final void setNumber( int number ) { this.number = number; }
80
81     protected ArrayType arrayType;
82     private int number = 0;
83 }
84
Popular Tags