/**
* Type-check this expression, and possibly child expressions.
*/
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
// Get the left and right operand types
Type tleft = _left.typeCheck(stable);
Type tright = _right.typeCheck(stable);
// Check if the operator supports the two operand types
MethodType wantType = new MethodType(Type.Void, tleft, tright);
MethodType haveType = lookupPrimop(stable, Ops[_op], wantType);
// Yes, the operation is supported
if (haveType != null) {
// Check if left-hand side operand must be type casted
Type arg1 = (Type)haveType.argsType().elementAt(0);
if (!arg1.identicalTo(tleft))
_left = new CastExpr(_left, arg1);
// Check if right-hand side operand must be type casted
Type arg2 = (Type) haveType.argsType().elementAt(1);
if (!arg2.identicalTo(tright))
_right = new CastExpr(_right, arg1);
// Return the result type for the operator we will use
return _type = haveType.resultType();
}
throw new TypeCheckError(this);