KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > reflect > eval > SymbolicStackFrame


1 package spoon.reflect.eval;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.List JavaDoc;
6 import java.util.Map JavaDoc;
7 import java.util.Map.Entry;
8
9 import spoon.reflect.code.CtAbstractInvocation;
10 import spoon.reflect.reference.CtExecutableReference;
11 import spoon.reflect.reference.CtVariableReference;
12
13 /**
14  * This class represents a frame of a symbolic evaluation stack.
15  */

16 public class SymbolicStackFrame {
17
18     /**
19      * Copies a frame from a given one (does not clone stateless info).
20      */

21     public SymbolicStackFrame(SymbolicStackFrame frame) {
22         for (Entry<CtVariableReference, SymbolicInstance> e : frame.variables
23                 .entrySet()) {
24             SymbolicInstance<?> i = e.getValue();
25             variables.put(e.getKey(), i == null ? null : i.getClone());
26         }
27         target = frame.target == null ? null : frame.target.getClone();
28         result = frame.result == null ? null : frame.result.getClone();
29         invocation = frame.invocation;
30         executable = frame.executable;
31         if (frame.arguments != null) {
32             arguments = new ArrayList JavaDoc<SymbolicInstance>();
33             for (SymbolicInstance i : frame.arguments) {
34                 arguments.add(i.getClone());
35             }
36         }
37     }
38
39     /**
40      * Frame equality.
41      */

42     @Override JavaDoc
43     public boolean equals(Object JavaDoc obj) {
44         SymbolicStackFrame f = (SymbolicStackFrame) obj;
45         return (target == null ? target == f.target : target.equals(f.target))
46                 && invocation == f.invocation
47                 && executable.equals(f.executable)
48                 && variables.equals(f.variables);
49     }
50
51     private Map JavaDoc<CtVariableReference, SymbolicInstance> variables = new HashMap JavaDoc<CtVariableReference, SymbolicInstance>();
52
53     private SymbolicInstance target;
54
55     private CtAbstractInvocation invocation;
56
57     private CtExecutableReference executable;
58
59     /**
60      * Gets the parent invocation of this frame.
61      */

62     public CtAbstractInvocation getInvocation() {
63         return invocation;
64     }
65
66     /**
67      * Gets the <code>this</code> value.
68      */

69     public SymbolicInstance getThis() {
70         return target;
71     }
72
73     /**
74      * Gets the local variables defined for this frame.
75      */

76     public Map JavaDoc<CtVariableReference, SymbolicInstance> getVariables() {
77         return variables;
78     }
79
80     List JavaDoc<SymbolicInstance> arguments;
81
82     /**
83      * Return the arguments (also present in the variables).
84      */

85     public List JavaDoc<SymbolicInstance> getArguments() {
86         return arguments;
87     }
88
89     /**
90      * Creates a new evalutation stack frame.
91      *
92      * @param invocation
93      * the parent invocation
94      * @param instance
95      * the target (this) of the frame ({@link #getThis()})
96      * @param executable
97      * the executable that corresponds to this frame
98      * @param variables
99      * the local variables defined within this frame (should be a copy)
100      */

101     public SymbolicStackFrame(CtAbstractInvocation invocation,
102             SymbolicInstance instance, CtExecutableReference executable,
103             List JavaDoc<SymbolicInstance> arguments,
104             Map JavaDoc<CtVariableReference, SymbolicInstance> variables) {
105         super();
106         this.variables = variables;
107         this.target = instance;
108         this.invocation = invocation;
109         this.executable = executable;
110         this.arguments = arguments;
111     }
112
113     /**
114      * A string representation.
115      */

116     @Override JavaDoc
117     public String JavaDoc toString() {
118         return "" + executable.getSimpleName() + " on " + target + " variables="
119                 + variables + " arguments=" + arguments +" result="+result;
120     }
121
122     /**
123      * Gets the executable of the frame.
124      */

125     public CtExecutableReference getExecutable() {
126         return executable;
127     }
128
129     private SymbolicInstance result=null;
130
131     /**
132      * Gets the result of this frame execution.
133      */

134     public SymbolicInstance getResult() {
135         return result;
136     }
137
138     /**
139      * Sets the result of this frame execution.
140      */

141     public void setResult(SymbolicInstance result) {
142         this.result = result;
143     }
144
145
146     
147 }
148
Popular Tags