BinaryChoiceLocation.java
package edu.udel.cis.vsl.tass.model.impl.location;
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.scope.LocalScopeIF;
import edu.udel.cis.vsl.tass.model.IF.statement.NoopStatementIF;
/**
* A binary choice location is a location which has a branch condition
* expression, a true branch (executed when the condition is true) and a false
* branch (executed when the condition is false). Both "if" statements and
* "while" loops have associated to them this kind of location.
*
* @author siegel
*/
public class BinaryChoiceLocation extends Location {
protected ExpressionIF condition = null;
protected NoopStatementIF trueBranch = null;
protected NoopStatementIF falseBranch = null;
public BinaryChoiceLocation(LocalScopeIF scope, ExpressionIF condition) {
super(scope, LocationKind.CHOICE);
if (condition == null)
throw new NullPointerException("null condition");
/* check appropriateness of condition */
this.condition = condition;
}
public ExpressionIF condition() {
return condition;
}
public NoopStatementIF trueBranch() {
return trueBranch;
}
public NoopStatementIF falseBranch() {
return falseBranch;
}
public void setTrueBranch(NoopStatementIF statement) {
this.trueBranch = statement;
super.addOutgoing(statement);
}
public void setFalseBranch(NoopStatementIF statement) {
this.falseBranch = statement;
super.addOutgoing(statement);
}
@Override
public void complete() throws SyntaxException {
if (trueBranch == null)
throw new SyntaxException(this,
"no true branch for this binary choice location");
if (falseBranch == null)
throw new SyntaxException(this,
"no false branch for this binary choice location");
super.complete();
}
}