KickJava   Java API By Example, From Geeks To Geeks.

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


1 package spoon.reflect.eval;
2
3 /**
4  * This class defines a symbolic evaluation step for a given
5  * {@link spoon.reflect.eval.SymbolicEvaluator}. a symbolic evaluation step
6  * contains a copy of the interpretor's state when the step happened.
7  */

8 public class SymbolicEvaluationStep {
9
10     SymbolicStackFrame frame;
11
12     SymbolicHeap heap;
13
14     StepKind kind;
15
16     /**
17      * Creates a new step.
18      *
19      * @param kind
20      * the step kind
21      * @param frame
22      * the stack frame (should be a copy)
23      * @param heap
24      * the heap (should be a copy)
25      */

26     public SymbolicEvaluationStep(StepKind kind, SymbolicStackFrame frame,
27             SymbolicHeap heap) {
28         super();
29         this.frame = frame;
30         this.heap = heap;
31         this.kind = kind;
32     }
33
34     /**
35      * Gets the stack frame that corresponds to this state.
36      */

37     public SymbolicStackFrame getFrame() {
38         return frame;
39     }
40
41     /**
42      * Gets the heap that corresponds to this state.
43      */

44     public SymbolicHeap getHeap() {
45         return heap;
46     }
47
48     /**
49      * A string representation.
50      */

51     @Override JavaDoc
52     public String JavaDoc toString() {
53         return kind.toString() + " " + frame.toString() + " heap="
54                 + heap.toString();
55     }
56
57     /**
58      * Gets the step kind.
59      */

60     public StepKind getKind() {
61         return kind;
62     }
63
64     /**
65      * Gets a symbolic instance from its id at the current evaluation step.
66      *
67      * @return null if not found
68      */

69     public SymbolicInstance get(String JavaDoc id) {
70         SymbolicInstance res = heap.get(id);
71         if (res != null)
72             return res;
73         for (SymbolicInstance i : frame.getVariables().values()) {
74             if (i != null && i.getId().equals(id)) {
75                 return i;
76             }
77         }
78         return null;
79     }
80
81 }
82
Popular Tags