/* VariableSet (c) 1998 Jochen Hoenicke * * You may distribute under the terms of the GNU General Public License. * * IN NO EVENT SHALL JOCHEN HOENICKE BE LIABLE TO ANY PARTY FOR DIRECT, * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF JOCHEN HOENICKE * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * JOCHEN HOENICKE SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" * BASIS, AND JOCHEN HOENICKE HAS NO OBLIGATION TO PROVIDE MAINTENANCE, * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * $Id$ */ package jode.flow; import jode.LocalInfo; /** * This class represents a set of Variables, which are mainly used in * the in/out sets of StructuredBlock. The type of the Variables is * LocalInfo.

* * It defines some Helper-Function, like intersecting, merging, union * and difference.

* * Note that a variable set can contain LocalInfos that use the same * slot, but are different. */ public class VariableSet implements Cloneable { LocalInfo[] locals; int count; /** * Creates a new empty variable set */ public VariableSet() { locals = null; count = 0; } /** * Creates a new pre initialized variable set */ public VariableSet(LocalInfo[] locals) { count = locals.length; this.locals = locals; } public final void grow(int size) { if (locals != null) { size += count; if (size > locals.length) { int nextSize = locals.length * 2; // System.err.println("wanted: "+size+" next: "+nextSize); LocalInfo[] newLocals = new LocalInfo[nextSize > size ? nextSize : size]; System.arraycopy(locals, 0, newLocals, 0, count); locals = newLocals; } } else if (size > 0) locals = new LocalInfo[size]; } /** * Adds a local info to this variable set. It doesn't check for * duplicates. */ public void addElement(LocalInfo li) { grow(1); locals[count++] = li; } /** * Checks if the variable set contains the given local info. */ public boolean contains(LocalInfo li) { li = li.getLocalInfo(); for (int i=0; i 0) { other.locals = new LocalInfo[count]; System.arraycopy(locals, 0, other.locals, 0, count); } return other; } catch (CloneNotSupportedException ex) { throw new jode.AssertError("Clone?"); } } /** * Merges the current VariableSet with another. For all slots occuring * in both variable sets, all corresponding LocalInfos are merged. * The variable sets are not changed (use union for this). * @return The merged variables. * @param vs the other variable set. */ public VariableSet merge(VariableSet vs) { VariableSet merged = new VariableSet(); merged.grow(Math.min(count,vs.count)); big_loop: for (int i=0; i