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 */ 013package org.jikesrvm.compilers.opt.liveness; 014 015import java.util.Enumeration; 016import java.util.NoSuchElementException; 017 018import org.jikesrvm.compilers.opt.ir.operand.RegisterOperand; 019 020/** 021 * An enumeration over live set lists 022 */ 023public 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 @Override 043 public boolean hasMoreElements() { 044 return current != null; 045 } 046 047 /** 048 * Returns the next element, if one exists, otherwise throws an exception. 049 * 050 * @return the next element 051 * @throws NoSuchElementException if no next element exists 052 */ 053 @Override 054 public RegisterOperand nextElement() { 055 if (current != null) { 056 LiveSetElement ret = current; 057 current = current.getNext(); 058 return ret.getRegisterOperand(); 059 } else { 060 throw new NoSuchElementException("LiveSetEnumerator"); 061 } 062 } 063} 064 065 066