blob: ae5924d866ba53914aa952f1b129d168782448c5 [file] [log] [blame]
/*
* (c) Copyright IBM Corp. 2000, 2001, 2002.
* All Rights Reserved.
*/
package org.eclipse.jdt.internal.debug.eval.ast.instructions;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.dom.Message;
import org.eclipse.jdt.debug.core.IJavaValue;
import org.eclipse.jdt.debug.eval.ICompiledExpression;
import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
import org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext;
import org.eclipse.jdt.internal.debug.eval.ast.engine.Interpreter;
public class InstructionSequence implements ICompiledExpression {
private List fInstructions;
/**
* A collection of errors (Message) that occurred while
* creating this expression
*/
private List fErrors;
private String fSnippet;
private CoreException fException;
public InstructionSequence(String snippet) {
fInstructions= new ArrayList(10);
fErrors= new ArrayList();
fSnippet= snippet;
}
/**
* Returns the runtime exception that occurred while evaluating this expression
* or <code>null</code> if no exception occurred.
*/
public CoreException getException() {
return fException;
}
/**
* @see ICompiledExpression#getSnippet()
*/
public String getSnippet() {
return fSnippet;
}
/**
* Adds the given error to the list of errors that occurred
* while compiling this instruction sequence
*/
public void addError(Message error) {
fErrors.add(error);
}
/**
* @see ICompiledExpression#hasErrors()
*/
public boolean hasErrors() {
return !fErrors.isEmpty();
}
/**
* @see ICompiledExpression#getErrors()
*/
public Message[] getErrors() {
return (Message[])fErrors.toArray(new Message[fErrors.size()]);
}
/**
* Answers the array of instructions, or an empty array.
*/
public Instruction[] getInstructions() {
int size= fInstructions.size();
Instruction[] instructions= new Instruction[size];
if (size > 0) {
fInstructions.toArray(instructions);
}
return instructions;
}
/**
* Answer the instruction at the given address
*/
public Instruction getInstruction(int address) {
return (Instruction)fInstructions.get(address);
}
/**
* Add the given instruction to the end of the list
*/
public void add(Instruction instruction) {
fInstructions.add(instruction);
}
/**
* Answers true if there are no instructions in this sequence
*/
public boolean isEmpty() {
return fInstructions.isEmpty();
}
/**
* Inserts the instruction at the given index. If
* the index is less than 0 or greater than the current
* instruction count, the instruction is added at the end
* of the sequence.
*
* Instructs the instructions to update their program counters.
*/
public void insert(Instruction instruction, int index) {
fInstructions.add(index, instruction);
}
public Instruction get(int address) {
return (Instruction)fInstructions.get(address);
}
public int getEnd() {
return fInstructions.size() - 1;
}
}