KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > optimize > evaluation > StoringInvocationUnit


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.optimize.evaluation;
22
23 import proguard.classfile.*;
24 import proguard.classfile.constant.RefConstant;
25 import proguard.evaluation.*;
26 import proguard.evaluation.value.*;
27 import proguard.optimize.info.*;
28
29 /**
30  * This InvocationUbit stores parameter values and return values with the
31  * methods that are invoked.
32  *
33  * @see LoadingInvocationUnit
34  * @author Eric Lafortune
35  */

36 public class StoringInvocationUnit
37 extends BasicInvocationUnit
38 {
39     // Implementations for BasicInvocationUnit.
40

41     protected void setFieldClassValue(Clazz clazz,
42                                       RefConstant refConstant,
43                                       ReferenceValue value)
44     {
45         Member referencedMember = refConstant.referencedMember;
46         if (referencedMember != null)
47         {
48             generalizeFieldClassValue((Field)referencedMember, value);
49         }
50     }
51
52
53     protected void setFieldValue(Clazz clazz,
54                                  RefConstant refConstant,
55                                  Value value)
56     {
57         Member referencedMember = refConstant.referencedMember;
58         if (referencedMember != null)
59         {
60             generalizeFieldValue((Field)referencedMember, value);
61         }
62     }
63
64
65     protected void setMethodParameterValue(Clazz clazz,
66                                            RefConstant refConstant,
67                                            int parameterIndex,
68                                            Value value)
69     {
70         Member referencedMember = refConstant.referencedMember;
71         if (referencedMember != null)
72         {
73             generalizeMethodParameterValue((Method)referencedMember,
74                                            parameterIndex,
75                                            value);
76         }
77     }
78
79
80     protected void setMethodReturnValue(Clazz clazz,
81                                         Method method,
82                                         Value value)
83     {
84         generalizeMethodReturnValue(method, value);
85     }
86
87
88     // Small utility methods.
89

90     private static void generalizeFieldClassValue(Field field, ReferenceValue value)
91     {
92         FieldOptimizationInfo info = FieldOptimizationInfo.getFieldOptimizationInfo(field);
93         if (info != null)
94         {
95             info.generalizeReferencedClass(value);
96         }
97     }
98
99
100     public static ReferenceValue getFieldClassValue(Field field)
101     {
102         FieldOptimizationInfo info = FieldOptimizationInfo.getFieldOptimizationInfo(field);
103         return info != null ?
104             info.getReferencedClass() :
105             null;
106     }
107
108
109     private static void generalizeFieldValue(Field field, Value value)
110     {
111         FieldOptimizationInfo info = FieldOptimizationInfo.getFieldOptimizationInfo(field);
112         if (info != null)
113         {
114             info.generalizeValue(value);
115         }
116     }
117
118
119     public static Value getFieldValue(Field field)
120     {
121         FieldOptimizationInfo info = FieldOptimizationInfo.getFieldOptimizationInfo(field);
122         return info != null ?
123             info.getValue() :
124             null;
125     }
126
127
128     private static void generalizeMethodParameterValue(Method method, int parameterIndex, Value value)
129     {
130         MethodOptimizationInfo info = MethodOptimizationInfo.getMethodOptimizationInfo(method);
131         if (info != null)
132         {
133             info.generalizeParameter(parameterIndex, value);
134         }
135     }
136
137
138     public static Value getMethodParameterValue(Method method, int parameterIndex)
139     {
140         MethodOptimizationInfo info = MethodOptimizationInfo.getMethodOptimizationInfo(method);
141         return info != null ?
142             info.getParameter(parameterIndex) :
143             null;
144     }
145
146
147     private static void generalizeMethodReturnValue(Method method, Value value)
148     {
149         MethodOptimizationInfo info = MethodOptimizationInfo.getMethodOptimizationInfo(method);
150         if (info != null)
151         {
152             info.generalizeReturnValue(value);
153         }
154     }
155
156
157     public static Value getMethodReturnValue(Method method)
158     {
159         MethodOptimizationInfo info = MethodOptimizationInfo.getMethodOptimizationInfo(method);
160         return info != null ?
161             info.getReturnValue() :
162             null;
163     }
164 }
165
Popular Tags