001: /*
002: * Spoon - http://spoon.gforge.inria.fr/
003: * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
004: *
005: * This software is governed by the CeCILL-C License under French law and
006: * abiding by the rules of distribution of free software. You can use, modify
007: * and/or redistribute the software under the terms of the CeCILL-C license as
008: * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
009: *
010: * This program is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
013: *
014: * The fact that you are presently reading this means that you have had
015: * knowledge of the CeCILL-C license and that you accept its terms.
016: */
017:
018: package spoon.reflect.eval;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: /**
024: * This class defines a symbolic evaluation path as a list of abstract
025: * evaluation steps (see {@link spoon.reflect.eval.SymbolicEvaluationStep}).
026: */
027: public class SymbolicEvaluationPath {
028:
029: /**
030: * Creates a symbolic evaluation path.
031: */
032: public SymbolicEvaluationPath() {
033: }
034:
035: List<SymbolicEvaluationStep> steps = new ArrayList<SymbolicEvaluationStep>();
036:
037: /**
038: * Adds a step to this path.
039: *
040: * @return the just added SymbolicEvaluationStep
041: */
042: public SymbolicEvaluationStep addStep(SymbolicEvaluationStep step) {
043: steps.add(step);
044: return step;
045: }
046:
047: /**
048: * Gets the ith step.
049: */
050: public SymbolicEvaluationStep getStep(int i) {
051: return steps.get(i);
052: }
053:
054: /**
055: * Returns the evaluation steps list.
056: */
057: public List<SymbolicEvaluationStep> getSteps() {
058: return steps;
059: }
060:
061: /**
062: * Gets the number of steps in this path.
063: */
064: public int getStepCount() {
065: return steps.size();
066: }
067:
068: /**
069: * Dumps this path on the screen.
070: */
071: public void dump() {
072: for (int i = 0; i < steps.size(); i++) {
073: System.out.println((i + 1) + "\t" + steps.get(i).getKind()
074: + " " + steps.get(i).getFrame());
075: steps.get(i).getHeap().dump();
076: }
077: }
078:
079: /**
080: * A string representation.
081: */
082: @Override
083: public String toString() {
084: String res = "";
085: for (int i = 0; i < steps.size(); i++) {
086: res += steps.get(i).getKind()
087: + "("
088: + steps.get(i).getFrame().getExecutable()
089: .getSimpleName() + ");";
090: }
091: return res;
092: }
093:
094: /**
095: * Returns a new symbolic evaluation path that only contains the
096: * {@link StepKind#ENTER} steps of this current path.
097: */
098: public SymbolicEvaluationPath getEnterSteps() {
099: SymbolicEvaluationPath res = new SymbolicEvaluationPath();
100: for (SymbolicEvaluationStep s : getSteps()) {
101: if (s.kind == StepKind.ENTER) {
102: res.getSteps().add(s);
103: }
104: }
105: return res;
106: }
107:
108: /**
109: * Returns a new symbolic evaluation path that only contains the
110: * {@link StepKind#EXIT} steps of this current path.
111: */
112: public SymbolicEvaluationPath getExitSteps() {
113: SymbolicEvaluationPath res = new SymbolicEvaluationPath();
114: for (SymbolicEvaluationStep s : getSteps()) {
115: if (s.kind == StepKind.EXIT) {
116: res.getSteps().add(s);
117: }
118: }
119: return res;
120: }
121:
122: }
|