ASTSimpleVariableDeclaration.java

package edu.udel.cis.vsl.tass.front.minimp.ast.declaration;

import edu.udel.cis.vsl.tass.front.minimp.ast.expression.ASTExpressionIF;
import edu.udel.cis.vsl.tass.front.minimp.ast.misc.ASTIdentifier;
import edu.udel.cis.vsl.tass.front.minimp.ast.type.ASTTypeIF;
import edu.udel.cis.vsl.tass.model.IF.SyntaxException;

public class ASTSimpleVariableDeclaration extends ASTVariableDeclaration
		implements ASTDeclarationIF {
	public ASTSimpleVariableDeclaration(ASTIdentifier name, ASTTypeIF type,
			VariableCategory category) {
		super(name, type, category);
	}

	public ASTSimpleVariableDeclaration(ASTIdentifier name, ASTTypeIF type,
			VariableCategory category, ASTExpressionIF init)
			throws SyntaxException {
		super(name, type, category, init);
		if (!(init.getType().equals(type))) {
			throw new edu.udel.cis.vsl.tass.model.IF.SyntaxException(name
					.source(),
					"Type inconsistency in variable initialization: " + type
							+ " and " + init.getType());
		}
	}

	public String toString() {
		String result = "begin simple variable declaration: \n";
		result += this.getVariableCategory() + " " + this.getType() + " "
				+ this.variableName.toString();
		if (this.assumption != null) {
			result += " {" + this.assumption + "}";
		}
		result += "line:" + source.firstLine() + ":" + source.lastLine()
				+ ", column:" + source.firstColumn() + ":"
				+ source.lastColumn() + ";\n";
		result += "end variable declaration.";
		return result;
	}
}