_right = new CastExpr(_right, Type.Real); _left = new CastExpr(_left, Type.Real);
if (typeL == null) type = typeR; else if (typeR == null) type = typeL; else { type = Type.Real; } if (type == null) type = Type.Real;
    public Type typeCheck(SymbolTable stable) throws TypeCheckError {	Type tleft = _left.typeCheck(stable); 	Type tright = _right.typeCheck(stable);	//bug fix # 2838, cast to reals if both are result tree fragments	if (tleft instanceof ResultTreeType &&	    tright instanceof ResultTreeType )   	{	    _right = new CastExpr(_right, Type.Real);	    _left = new CastExpr(_left, Type.Real);	    return _type = Type.Boolean; 	}	// If one is of reference type, then convert the other too	if (hasReferenceArgs()) {	    if (tleft instanceof ReferenceType) {		_right = new CastExpr(_right, Type.Reference);	    }	    if (tright instanceof ReferenceType) {		_left = new CastExpr(_left, Type.Reference);	    }	    // bug fix # 2838 	    _right = new CastExpr(_right, Type.Real);            _left = new CastExpr(_left, Type.Real);	    return _type = Type.Boolean;	}	if (hasNodeSetArgs()) {	    // Ensure that the node-set is the left argument	    if (tright instanceof NodeSetType) {		final Expression temp = _right; _right = _left; _left = temp;		_op = (_op == Operators.GT) ? Operators.LT :		    (_op == Operators.LT) ? Operators.GT :		    (_op == Operators.GE) ? Operators.LE : Operators.GE;		tright = _right.getType();	    }	    // Promote nodes to node sets	    if (tright instanceof NodeType) {		_right = new CastExpr(_right, Type.NodeSet);	    }	    // Promote integer to doubles to have fewer compares	    if (tright instanceof IntType) {		_right = new CastExpr(_right, Type.Real);	    }	    return _type = Type.Boolean;	}	// In the node-boolean case, convert node to boolean first	if (hasNodeArgs()) {	    if (tleft instanceof BooleanType) {		_right = new CastExpr(_right, Type.Boolean);		tright = Type.Boolean;	    }	    if (tright instanceof BooleanType) {		_left = new CastExpr(_left, Type.Boolean);		tleft = Type.Boolean;	    }	}	// Lookup the table of primops to find the best match	MethodType ptype = lookupPrimop(stable, Operators.names[_op],					new MethodType(Type.Void, 						       tleft, tright)); 	if (ptype != null) {	    Type arg1 = (Type) ptype.argsType().elementAt(0);	    if (!arg1.identicalTo(tleft)) {		_left = new CastExpr(_left, arg1);	    }	    Type arg2 = (Type) ptype.argsType().elementAt(1);	    if (!arg2.identicalTo(tright)) {		_right = new CastExpr(_right, arg1);					    }	    return _type = ptype.resultType();	}	throw new TypeCheckError(this);    }