EqualsExpression.java
package edu.udel.cis.vsl.tass.model.impl.expression;
import edu.udel.cis.vsl.tass.model.IF.ModelFactoryIF;
import edu.udel.cis.vsl.tass.model.IF.SyntaxException;
import edu.udel.cis.vsl.tass.model.IF.type.TypeIF;
import edu.udel.cis.vsl.tass.model.IF.type.TypeIF.TypeKind;
public class EqualsExpression extends BinaryExpression {
public EqualsExpression(ModelFactoryIF factory, Expression left,
Expression right) throws SyntaxException {
super(factory, ExpressionKind.EQUALS, left, right);
TypeIF leftType = left.type;
TypeIF rightType = right.type;
if (leftType.kind() == TypeKind.BOOLEAN) {
if (rightType.kind() != TypeKind.BOOLEAN)
throw new SyntaxException(right, "type incompatible with "
+ leftType);
} else if (leftType.kind() == TypeKind.POINTER) {
if (rightType.kind() != TypeKind.POINTER)
throw new SyntaxException(right, "type incompatible with "
+ leftType);
} else if (leftType.kind() == TypeKind.RECORD) {
if (!leftType.equals(rightType))
throw new SyntaxException(right, "type incompatible with "
+ leftType);
} else if (leftType.kind() == TypeKind.CHAR) {
if (!leftType.equals(rightType))
throw new SyntaxException(right, "type incompatible with "
+ leftType);
}
// TODO: experiment: allow array equality: appears to be working...
// else if (false) {
// if (!leftType.isNumeric())
// throw new SyntaxException(left,
// "type cannot be used with equals: " + leftType);
// if (!rightType.isNumeric())
// throw new SyntaxException(right,
// "type cannot be used with equals: " + rightType);
// }
type = factory.booleanType();
}
public String toString() {
return left.atomString() + "==" + right.atomString();
}
public String atomString() {
return "(" + this + ")";
}
}