KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > spark > pag > AllocNode


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2002 Ondrej Lhotak
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 package soot.jimple.spark.pag;
21 import soot.jimple.spark.*;
22 import soot.*;
23 import java.util.*;
24
25 /** Represents an allocation site node (Blue) in the pointer assignment graph.
26  * @author Ondrej Lhotak
27  */

28 public class AllocNode extends Node implements Context {
29     /** Returns the new expression of this allocation site. */
30     public Object JavaDoc getNewExpr() { return newExpr; }
31     /** Returns all field ref nodes having this node as their base. */
32     public Collection getAllFieldRefs() {
33         if( fields == null ) return Collections.EMPTY_LIST;
34         return fields.values();
35     }
36     /** Returns the field ref node having this node as its base,
37      * and field as its field; null if nonexistent. */

38     public AllocDotField dot( SparkField field )
39     { return fields == null ? null : (AllocDotField) fields.get( field ); }
40     public String JavaDoc toString() {
41     return "AllocNode "+getNumber()+" "+newExpr+" in method "+method;
42     }
43
44     /* End of public methods. */
45
46     AllocNode( PAG pag, Object JavaDoc newExpr, Type t, SootMethod m ) {
47     super( pag, t );
48         this.method = m;
49         if( t instanceof RefType ) {
50             RefType rt = (RefType) t;
51             if( rt.getSootClass().isAbstract() ) {
52                 throw new RuntimeException JavaDoc( "Attempt to create allocnode with abstract type "+t );
53             }
54         }
55     this.newExpr = newExpr;
56         if( newExpr instanceof ContextVarNode ) throw new RuntimeException JavaDoc();
57         pag.getAllocNodeNumberer().add( this );
58     }
59     /** Registers a AllocDotField as having this node as its base. */
60     void addField( AllocDotField adf, SparkField field ) {
61     if( fields == null ) fields = new HashMap();
62         fields.put( field, adf );
63     }
64
65     public Set getFields() {
66         if( fields == null ) return Collections.EMPTY_SET;
67         return new HashSet( fields.values() );
68     }
69
70     /* End of package methods. */
71
72     protected Object JavaDoc newExpr;
73     protected Map fields;
74
75     private SootMethod method;
76     public SootMethod getMethod() { return method; }
77 }
78
79
Popular Tags