FormalVariable.java
package edu.udel.cis.vsl.tass.model.impl.variable;
import edu.udel.cis.vsl.tass.model.IF.SyntaxException;
import edu.udel.cis.vsl.tass.model.IF.expression.ExpressionIF;
import edu.udel.cis.vsl.tass.model.IF.type.TypeIF;
import edu.udel.cis.vsl.tass.model.IF.variable.FormalVariableIF;
import edu.udel.cis.vsl.tass.model.impl.scope.LocalScope;
public class FormalVariable extends LocalVariable implements FormalVariableIF {
public FormalVariable(String name, TypeIF type, LocalScope scope, int index) {
super(name, type, scope);
if (index < 0 || index >= scope().function().numFormals())
throw new IllegalArgumentException("Illegal index for formal "
+ name + " in function " + scope().function() + ": "
+ index);
assert scope.depth() == 0;
this.idInScope = index;
}
/**
* Returns the index of this formal in the list of formal parameters for the
* function. The first parameter for the function has index 0, the next has
* index 1, etc.
*/
public int index() {
return idInScope;
}
public void setInitializationExpression(ExpressionIF expression)
throws SyntaxException {
throw new SyntaxException(this,
"Formal parameters cannot be assigned an initial value");
}
}