KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > AbstractUnitBox


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
28
29
30 package soot;
31
32 import soot.util.*;
33 import java.util.*;
34
35 /** Reference implementation for UnitBox; just
36  * add a canContainUnit method. */

37 public abstract class AbstractUnitBox implements UnitBox
38 {
39     protected Unit unit;
40
41     public abstract boolean canContainUnit(Unit u);
42
43     public boolean isBranchTarget()
44     {
45         return true;
46     }
47     
48     public void setUnit(Unit unit)
49     {
50         if(!canContainUnit(unit))
51             throw new RuntimeException JavaDoc("attempting to put invalid unit in UnitBox");
52             
53         // Remove this from set of back pointers.
54
if(this.unit != null)
55             {
56                 this.unit.removeBoxPointingToThis(this);
57             }
58
59         // Perform link
60
this.unit = unit;
61
62         // Add this to back pointers
63
if(this.unit != null)
64             {
65                 this.unit.addBoxPointingToThis(this);
66             }
67     }
68
69     public Unit getUnit()
70     {
71         return unit;
72     }
73
74     public void toString(UnitPrinter up) {
75         up.startUnitBox(this);
76         up.unitRef(unit, isBranchTarget());
77         up.endUnitBox(this);
78     }
79 }
80
Popular Tags