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 import java.util.NoSuchElementException;
017
018 import org.jikesrvm.compilers.opt.ir.operand.RegisterOperand;
019
020 /**
021 * An enumeration over live set lists
022 */
023 public class LiveSetEnumerator implements Enumeration<RegisterOperand> {
024
025 /**
026 * the current element on this list
027 */
028 private LiveSetElement current;
029
030 /**
031 * The constructor
032 * @param list The {@link LiveSetElement} at the head of the list.
033 */
034 public LiveSetEnumerator(LiveSetElement list) {
035 current = list;
036 }
037
038 /**
039 * Are there any more elements?
040 * @return whether there are any more elements?
041 */
042 public boolean hasMoreElements() {
043 return current != null;
044 }
045
046 /**
047 * Returns the next element, if one exists, otherwise throws an exception
048 * @return the next element, if one exists, otherwise throws an exception
049 */
050 public RegisterOperand nextElement() {
051 if (current != null) {
052 LiveSetElement ret = current;
053 current = current.getNext();
054 return ret.getRegisterOperand();
055 } else {
056 throw new NoSuchElementException("LiveSetEnumerator");
057 }
058 }
059 }
060
061
062