KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > spark > internal > SparkNativeHelper


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.internal;
21 import soot.jimple.spark.*;
22 import soot.jimple.spark.pag.*;
23 import soot.jimple.toolkits.pointer.representations.*;
24 import soot.jimple.toolkits.pointer.util.*;
25 import soot.toolkits.scalar.Pair;
26 import soot.*;
27
28 public class SparkNativeHelper extends NativeHelper {
29     protected PAG pag;
30
31     public SparkNativeHelper( PAG pag ) {
32     this.pag = pag;
33     }
34     protected void assignImpl(ReferenceVariable lhs, ReferenceVariable rhs) {
35         pag.addEdge( (Node) rhs, (Node) lhs );
36     }
37     protected void assignObjectToImpl(ReferenceVariable lhs, AbstractObject obj) {
38     AllocNode objNode = pag.makeAllocNode(
39         new Pair( "AbstractObject", obj.getType() ),
40          obj.getType(), null );
41
42         VarNode var;
43         if( lhs instanceof FieldRefNode ) {
44         var = pag.makeGlobalVarNode( objNode, objNode.getType() );
45             pag.addEdge( (Node) lhs, var );
46         } else {
47             var = (VarNode) lhs;
48         }
49         pag.addEdge( objNode, var );
50     }
51     protected void throwExceptionImpl(AbstractObject obj) {
52     AllocNode objNode = pag.makeAllocNode(
53         new Pair( "AbstractObject", obj.getType() ),
54          obj.getType(), null );
55         pag.addEdge( objNode, pag.nodeFactory().caseThrow() );
56     }
57     protected ReferenceVariable arrayElementOfImpl(ReferenceVariable base) {
58         Node n = (Node) base;
59         VarNode l;
60     if( base instanceof VarNode ) {
61         l = (VarNode) base;
62     } else {
63         FieldRefNode b = (FieldRefNode) base;
64         l = pag.makeGlobalVarNode( b, b.getType() );
65         pag.addEdge( b, l );
66     }
67         return pag.makeFieldRefNode( l, ArrayElement.v() );
68     }
69     protected ReferenceVariable cloneObjectImpl(ReferenceVariable source) {
70     return source;
71     }
72     protected ReferenceVariable newInstanceOfImpl(ReferenceVariable cls) {
73         return pag.nodeFactory().caseNewInstance( (VarNode) cls );
74     }
75     protected ReferenceVariable staticFieldImpl(String JavaDoc className, String JavaDoc fieldName ) {
76     SootClass c = RefType.v( className ).getSootClass();
77     SootField f = c.getFieldByName( fieldName );
78     return pag.makeGlobalVarNode( f, f.getType() );
79     }
80     protected ReferenceVariable tempFieldImpl(String JavaDoc fieldsig) {
81     return pag.makeGlobalVarNode( new Pair( "tempField", fieldsig ),
82             RefType.v( "java.lang.Object" ) );
83     }
84     protected ReferenceVariable tempVariableImpl() {
85     return pag.makeGlobalVarNode( new Pair( "TempVar", new Integer JavaDoc( ++G.v().SparkNativeHelper_tempVar ) ),
86         RefType.v( "java.lang.Object" ) );
87     }
88     protected ReferenceVariable tempLocalVariableImpl(SootMethod method) {
89         return pag.makeLocalVarNode( new Pair( "TempVar", new Integer JavaDoc( ++G.v().SparkNativeHelper_tempVar ) ),
90                                      RefType.v( "java.lang.Object" ) , method);
91     }
92     
93 }
94
Popular Tags