001    /*
002     *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003     *
004     *  This file is licensed to You under the Eclipse Public License (EPL);
005     *  You may not use this file except in compliance with the License. You
006     *  may obtain a copy of the License at
007     *
008     *      http://www.opensource.org/licenses/eclipse-1.0.php
009     *
010     *  See the COPYRIGHT.txt file distributed with this work for information
011     *  regarding copyright ownership.
012     */
013    package org.jikesrvm.compilers.opt.liveness;
014    
015    import java.util.Enumeration;
016    
017    import org.jikesrvm.compilers.opt.regalloc.LiveIntervalElement;
018    
019    /**
020     * Enumerator for a list of live intervals stored on a basic block.
021     * <p>
022     * Note: This is fragile.  Use with care iff you know what you're doing.
023     * <p>
024     * TODO: redesign the way live info is stored on the IR to be a bit more
025     * robust.  e.g., don't use scratch fields.
026     */
027    public class LiveIntervalEnumeration implements Enumeration<LiveIntervalElement> {
028      private LiveIntervalElement currentElement;
029    
030      /**
031       * @param first  The first live interval in a list to be enumerated
032       */
033      public LiveIntervalEnumeration(LiveIntervalElement first) {
034        this.currentElement = first;
035      }
036    
037      @Override
038      public boolean hasMoreElements() {
039        return currentElement != null;
040      }
041    
042      @Override
043      public LiveIntervalElement nextElement() {
044        LiveIntervalElement result = currentElement;
045        currentElement = currentElement.getNext();
046        return result;
047      }
048    }