KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > pointer > util > NativeHelper


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Feng Qian
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  * Native method helper
22  *
23  * @author Feng Qian
24  */

25
26
27 package soot.jimple.toolkits.pointer.util;
28 import soot.*;
29 import soot.jimple.toolkits.pointer.representations.*;
30
31 public abstract class NativeHelper {
32
33
34   /**
35    * Regular assignment such as "a = b".
36    */

37   public void assign(ReferenceVariable lhs, ReferenceVariable rhs){
38     assignImpl(lhs, rhs);
39   }
40
41   /**
42    * Assignment of an abstract object to the variable, such as
43    * " a = new A()", which is considered to add a target in a's
44    * points-to set.
45    *
46    * This method is used to fomulate the effect of getting
47    * an environmental constant object such as 'getClass'.
48    */

49   public void assignObjectTo(ReferenceVariable lhs, AbstractObject obj){
50     assignObjectToImpl(lhs, obj);
51   }
52
53   /**
54    * Throw of an abstract object as an exception.
55    */

56   public void throwException(AbstractObject obj){
57     throwExceptionImpl(obj);
58   }
59
60   /**
61    * Returns a reference variable representing the array element of
62    * this variable. Now it does not look at the array index.
63    */

64   public ReferenceVariable arrayElementOf(ReferenceVariable base){
65     return arrayElementOfImpl(base);
66   }
67
68   /**
69    * Returns a variable which has the effect of cloning.
70    * A moderate approach would return the variable itself.
71    *
72    * e.g., a = b.clone() will be rendered to:
73    * Vr.isAssigned(Vb.cloneObject());
74    * Va = Vr;
75    */

76   public ReferenceVariable cloneObject(ReferenceVariable source){
77     return cloneObjectImpl(source);
78   }
79
80   /**
81    * Returns a variable which carries an allocation site with
82    * the least type (an artificial type, subtype of any other types,
83    * which means such type info is useless for resolving invocation
84    * targets).
85    *
86    * It is used for simulating java.lang.Class.newInstance0();
87    * To verify, @this variable mush have CLASSCLASS type.
88    */

89   public ReferenceVariable newInstanceOf(ReferenceVariable cls){
90     return newInstanceOfImpl(cls);
91   }
92   
93   /**
94    * Returns a reference variable representing a static Java field.
95    * The implementation must ensure that there is only one such
96    * representation for each static field.
97    *
98    * @param field, must be a static field
99    */

100   public ReferenceVariable staticField(String JavaDoc className, String JavaDoc fieldName ){
101     return staticFieldImpl(className, fieldName);
102   }
103
104   /**
105    * Returns a variable representing a non-existing Java field, used by
106    * e.g., java.lang.Class: getSingers, setSigners
107    * java.lang.Class: getProtectionDomain0, setProtectionDomain0
108    *
109    * To simplify simulation, the temporary field variable is like a
110    * static field.
111    *
112    * The temporary fields are uniquely indexed by signatures.
113    */

114   public ReferenceVariable tempField(String JavaDoc fieldsig){
115     return tempFieldImpl(fieldsig);
116   }
117
118   /**
119    * Make a temporary variable.
120    * It is used for assignment where both sides are complex variables.
121    * e.g., for java.lang.System arraycopy(src, ..., dst, ...)
122    * instead of make an expression : dst[] = src[],
123    * it introduces a temporary variable
124    * t = src[]
125    * dst[] = t
126    *
127    * The temporary variable has to be unique.
128    */

129   public ReferenceVariable tempVariable(){
130     return tempVariableImpl();
131   }
132
133   public ReferenceVariable tempLocalVariable(SootMethod method) {
134     return tempLocalVariableImpl(method);
135   }
136   /**
137    * Sub classes should implement both.
138    */

139   protected abstract
140     void assignImpl(ReferenceVariable lhs, ReferenceVariable rhs);
141   protected abstract
142     void assignObjectToImpl(ReferenceVariable lhs, AbstractObject obj);
143   protected abstract
144     void throwExceptionImpl(AbstractObject obj);
145   protected abstract
146     ReferenceVariable arrayElementOfImpl(ReferenceVariable base);
147   protected abstract
148     ReferenceVariable cloneObjectImpl(ReferenceVariable source);
149   protected abstract
150     ReferenceVariable newInstanceOfImpl(ReferenceVariable cls);
151   protected abstract
152     ReferenceVariable staticFieldImpl(String JavaDoc className, String JavaDoc fieldName );
153   protected abstract
154     ReferenceVariable tempFieldImpl(String JavaDoc fieldsig);
155   protected abstract
156     ReferenceVariable tempVariableImpl();
157   protected abstract
158     ReferenceVariable tempLocalVariableImpl(SootMethod method);
159 }
160
Popular Tags