SARLBoundException.java

/*******************************************************************************
 * Copyright (c) 2013 Stephen F. Siegel, University of Delaware.
 * 
 * This file is part of SARL.
 * 
 * SARL is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * 
 * SARL is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with SARL. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package edu.udel.cis.vsl.sarl.IF;

import edu.udel.cis.vsl.sarl.IF.expr.NumericExpression;
import edu.udel.cis.vsl.sarl.IF.expr.SymbolicExpression;

/**
 * An exception that occurs when an index is out of bounds. Typically, this
 * means an array index, though this class uses only a general notion of an
 * index being out of bounds.
 * 
 * @author siegel
 */
public class SARLBoundException extends SARLException {

	/**
	 * Generated by Eclipse.
	 */
	private static final long serialVersionUID = 8406532220408063547L;

	/**
	 * The symbolic expression into which the index points (typically, an array)
	 */
	public SymbolicExpression expr;

	/**
	 * The offending index
	 */
	public NumericExpression index;

	/**
	 * The lowest value that an index should take; can be <code>null</code>,
	 * representing "unknown"
	 */
	public NumericExpression lowerBound;

	/**
	 * The greatest value that an index should take; can be <code>null</code>,
	 * representing "unknown"
	 */
	public NumericExpression upperBound;

	/**
	 * The kind of operation that resulted in the exception, e.g.,
	 * "an array write operation" or "an array read operation"
	 */
	public String location;

	/**
	 * Constructs new out-of-bounds exception with a message formed from the
	 * given parameters.
	 * 
	 * @param expr
	 *            the symbolic expression into which the index points
	 *            (typically, an array)
	 * @param index
	 *            the offending index
	 * @param lowerBound
	 *            the lowest value that an index should take; can be
	 *            <code>null</code>, representing "unknown"
	 * @param upperBound
	 *            the greatest value that an index should take; can be
	 *            <code>null</code>, representing "unknown"
	 * @param location
	 *            the kind of operation that resulted in the exception, e.g.,
	 *            "an array write operation" or "an array read operation"
	 */
	public SARLBoundException(SymbolicExpression expr, NumericExpression index,
			NumericExpression lowerBound, NumericExpression upperBound,
			String location) {
		super("An out-of-bound index error has occurred in " + location + ".\n"
				+ "object: " + expr + "\nindex: " + index + "\nlower bound: "
				+ (lowerBound == null ? "unknown" : lowerBound)
				+ "\nupper bound: "
				+ (upperBound == null ? "unknown" : upperBound) + "\n");
		this.expr = expr;
		this.index = index;
		this.lowerBound = lowerBound;
		this.upperBound = upperBound;
		this.location = location;
	}

}