blob: 04ee188d45e718bf7d203a4b5a043b98b907a3a4 [file] [log] [blame]
// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.ir.code;
import java.util.Iterator;
public interface InstructionIterator extends Iterator<Instruction>, NextUntilIterator<Instruction> {
/** @deprecated Use {@link InstructionListIterator#remove()} instead. */
@Deprecated
@Override
default void remove() {
throw new UnsupportedOperationException("remove");
}
boolean hasPrevious();
Instruction previous();
default void previous(int times) {
while (times > 0) {
previous();
times--;
}
}
/**
* Peek the next instruction.
*
* @return what will be returned by calling {@link #next}. If there is no next instruction <code>
* null</code> is returned.
*/
default Instruction peekNext() {
Instruction next = null;
if (hasNext()) {
next = next();
previous();
}
return next;
}
/**
* Peek the previous instruction.
*
* @return what will be returned by calling {@link #previous}. If there is no previous instruction
* <code>null</code> is returned.
*/
default Instruction peekPrevious() {
Instruction previous = null;
if (hasPrevious()) {
previous = previous();
next();
}
return previous;
}
}