01: /*
02: * Spoon - http://spoon.gforge.inria.fr/
03: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
04: *
05: * This software is governed by the CeCILL-C License under French law and
06: * abiding by the rules of distribution of free software. You can use, modify
07: * and/or redistribute the software under the terms of the CeCILL-C license as
08: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
09: *
10: * This program is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
13: *
14: * The fact that you are presently reading this means that you have had
15: * knowledge of the CeCILL-C license and that you accept its terms.
16: */
17:
18: package spoon.reflect.eval;
19:
20: /**
21: * This class defines a symbolic evaluation step for a given
22: * {@link spoon.reflect.eval.SymbolicEvaluator}. a symbolic evaluation step
23: * contains a copy of the interpretor's state when the step happened.
24: */
25: public class SymbolicEvaluationStep {
26:
27: SymbolicStackFrame frame;
28:
29: SymbolicHeap heap;
30:
31: StepKind kind;
32:
33: /**
34: * Creates a new step.
35: *
36: * @param kind
37: * the step kind
38: * @param frame
39: * the stack frame (should be a copy)
40: * @param heap
41: * the heap (should be a copy)
42: */
43: public SymbolicEvaluationStep(StepKind kind,
44: SymbolicStackFrame frame, SymbolicHeap heap) {
45: super ();
46: this .frame = frame;
47: this .heap = heap;
48: this .kind = kind;
49: }
50:
51: /**
52: * Gets the stack frame that corresponds to this state.
53: */
54: public SymbolicStackFrame getFrame() {
55: return frame;
56: }
57:
58: /**
59: * Gets the heap that corresponds to this state.
60: */
61: public SymbolicHeap getHeap() {
62: return heap;
63: }
64:
65: /**
66: * A string representation.
67: */
68: @Override
69: public String toString() {
70: return kind.toString() + " " + frame.toString() + " heap="
71: + heap.toString();
72: }
73:
74: /**
75: * Gets the step kind.
76: */
77: public StepKind getKind() {
78: return kind;
79: }
80:
81: /**
82: * Gets a symbolic instance from its id at the current evaluation step.
83: *
84: * @return null if not found
85: */
86: public SymbolicInstance<?> get(String id) {
87: SymbolicInstance<?> res = heap.get(id);
88: if (res != null)
89: return res;
90: for (SymbolicInstance<?> i : frame.getVariables().values()) {
91: if (i != null && i.getId().equals(id)) {
92: return i;
93: }
94: }
95: return null;
96: }
97:
98: }
|