Some more instrumentation, and playing around with chopping (chops when double-click...
[eclipsethinslicer.git] / Svelte / src / edu / berkeley / cs / bodik / svelte / plugin / bfsliceview / BFSliceInput.java
blob5b55a89e8ffb7bc45469ce4b48e46d2b6069476b
1 /*******************************************************************************
2 * This program and the accompanying materials
3 * are made available under the terms of the Eclipse Public License v1.0
4 * which accompanies this distribution, and is available at
5 * http://www.eclipse.org/legal/epl-v10.html.
6 *
7 * This file is a derivative of code released by the University of
8 * California under the terms listed below.
10 * Refinement Analysis Tools is Copyright ©2007 The Regents of the
11 * University of California (Regents). Provided that this notice and
12 * the following two paragraphs are included in any distribution of
13 * Refinement Analysis Tools or its derivative work, Regents agrees
14 * not to assert any of Regents' copyright rights in Refinement
15 * Analysis Tools against recipient for recipient’s reproduction,
16 * preparation of derivative works, public display, public
17 * performance, distribution or sublicensing of Refinement Analysis
18 * Tools and derivative works, in source code and object code form.
19 * This agreement not to assert does not confer, by implication,
20 * estoppel, or otherwise any license or rights in any intellectual
21 * property of Regents, including, but not limited to, any patents
22 * of Regents or Regents’ employees.
24 * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT,
25 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
26 * INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE
27 * AND ITS DOCUMENTATION, EVEN IF REGENTS HAS BEEN ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
32 * FOR A PARTICULAR PURPOSE AND FURTHER DISCLAIMS ANY STATUTORY
33 * WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE AND ACCOMPANYING
34 * DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
35 * IS". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
36 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
38 package edu.berkeley.cs.bodik.svelte.plugin.bfsliceview;
40 import java.util.ArrayList;
41 import java.util.Hashtable;
42 import java.util.Iterator;
44 import com.ibm.wala.ipa.slicer.Statement;
45 import com.ibm.wala.util.graph.Graph;
47 import edu.berkeley.cs.bodik.svelte.Slice;
49 interface BFSliceStatement {
50 Statement getStatement();
52 public ArrayList<BFSliceStatement> getChildren();
53 public boolean hasChildren();
55 /**
56 * A BFSliceStatement normally keeps a cache of its children. When the children are no longer needed
57 * (i.e. when we go up a level) they can forgotten about so the GC can free the memory. This is necessary
58 * because the <code>BFSliceInput.getChildren()</code> function must generate its children for each parent so we can
59 * have different BFSliceStatements referring to the same Statement.
61 void freeChildren();
63 /**
64 * Markings. Along with freeChildren, these don't really make sense for the RootStatement.
66 public void markCheck();
67 public void unmarkCheck();
68 public boolean isMarkedChecked();
70 public BFSliceStatement getParent();
75 public class BFSliceInput {
76 private Graph<Statement> graph;
77 private Slice seed;
78 private RootStatement root;
80 private Hashtable<Statement,Boolean> markings = new Hashtable<Statement,Boolean>();
82 /**
83 * Wrapper around a real statement.
84 * This allows one Statement in the slice to have more than one incarnation in the viewer, since
85 * they are only equal if they are the same object.
86 * @author evan
89 private class RealStatement implements BFSliceStatement {
90 Statement s;
91 ArrayList<BFSliceStatement> children;
92 private BFSliceStatement parent;
95 public RealStatement(Statement s, BFSliceStatement parent) {
96 this.s = s;
97 children = null;
98 this.parent = parent;
101 public String toString() {
102 return s.toString();
105 public boolean equals(Object x) {
106 return x == this;
109 public Statement getStatement() {
110 return s;
113 public ArrayList<BFSliceStatement> getChildren() {
114 if ( children == null ) {
115 children = new ArrayList<BFSliceStatement>();
116 Iterator<? extends Statement> iter = graph.getSuccNodes(s);
117 while ( iter.hasNext() ) {
118 children.add(new RealStatement(iter.next(), this));
121 return children;
124 public void freeChildren() {
125 if ( children != null ) {
126 children.clear();
127 children = null;
131 public void markCheck() {
132 markings.put(s, new Boolean(true));
135 public void unmarkCheck() {
136 if ( markings.containsKey(s) )
137 markings.remove(s);
140 public boolean isMarkedChecked() {
141 return markings.containsKey(s) && markings.get(s).booleanValue();
144 public BFSliceStatement getParent() {
145 return parent;
148 public boolean hasChildren() {
149 return graph.getSuccNodes(s).hasNext();
154 * Fake statement representing parent of all seeds in a slice.
155 * @author evan
157 private class RootStatement implements BFSliceStatement {
158 ArrayList<BFSliceStatement> children;
160 @Override
161 public boolean equals(Object obj) {
162 return obj == root;
165 @Override
166 public int hashCode() {
167 return graph.hashCode() + seed.hashCode();
170 @Override
171 public String toString() {
172 return "All Seed Statements";
175 public Statement getStatement() {
176 return null;
179 public void freeChildren() {
180 // you cannot back up beyond the root node
183 public ArrayList<BFSliceStatement> getChildren() {
184 if ( children == null ) {
185 children = new ArrayList<BFSliceStatement>();
186 Iterator<? extends Statement> iter = seed.iterator();
187 while ( iter.hasNext() ) {
188 children.add(new RealStatement(iter.next(), root));
191 return children;
194 public boolean isMarkedChecked() {
195 return false;
198 public void markCheck() {
201 public void unmarkCheck() {
204 public BFSliceStatement getParent() {
205 // TODO Auto-generated method stub
206 return null;
209 public boolean hasChildren() {
210 return true;
215 public BFSliceInput(Graph<Statement> graph, Slice seed) {
216 this.graph = graph;
217 this.seed = seed;
218 this.root = new RootStatement();
221 // in the future we might wasn't abstractions to different kinds of slices (CI thin, CS thin, CS thick) in here.
222 public BFSliceStatement getRoot() {
223 return root;
226 // public void add(Word word) {
227 // list.add(word);
228 // writeFile();
229 // if (listener != null)
230 // listener.added(word);
231 // }
233 // public void remove(Word word) {
234 // list.remove(word);
235 // writeFile();
236 // if (listener != null)
237 // listener.removed(word);
238 // }
240 // public Word find(String str) {
241 // Iterator iter = list.iterator();
242 // while (iter.hasNext()) {
243 // Word word = (Word)iter.next();
244 // if (str.equals(word.toString()))
245 // return word;
246 // }
247 // return null;
248 // }