internal override void TranslateToIL(ILGenerator il, Type rtype){
if (this.metaData == null){
Type rt = Typeob.Double;
if (Convert.IsPrimitiveNumericType(rtype) && Convert.IsPromotableTo(this.type1, rtype) && Convert.IsPromotableTo(this.type2, rtype))
rt = rtype;
if (this.operatorTok == JSToken.Divide)
rt = Typeob.Double;
else if (rt == Typeob.SByte || rt == Typeob.Int16)
rt = Typeob.Int32;
else if (rt == Typeob.Byte || rt == Typeob.UInt16 || rt == Typeob.Char)
rt = Typeob.UInt32;
this.operand1.TranslateToIL(il, rt);
this.operand2.TranslateToIL(il, rt);
if (rt == Typeob.Double || rt == Typeob.Single){
switch (this.operatorTok){
case JSToken.Divide:
il.Emit(OpCodes.Div); break;
case JSToken.Minus:
il.Emit(OpCodes.Sub); break;
case JSToken.Modulo:
il.Emit(OpCodes.Rem); break;
case JSToken.Multiply:
il.Emit(OpCodes.Mul); break;
default:
throw new JScriptException(JSError.InternalError, this.context);
}
}else if (rt == Typeob.Int32 || rt == Typeob.Int64){
switch (this.operatorTok){
case JSToken.Divide:
il.Emit(OpCodes.Div); break;
case JSToken.Minus:
il.Emit(OpCodes.Sub_Ovf); break;
case JSToken.Modulo:
il.Emit(OpCodes.Rem); break;
case JSToken.Multiply:
il.Emit(OpCodes.Mul_Ovf); break;
default:
throw new JScriptException(JSError.InternalError, this.context);
}
}else{
switch (this.operatorTok){
case JSToken.Divide:
il.Emit(OpCodes.Div); break;
case JSToken.Minus:
il.Emit(OpCodes.Sub_Ovf_Un); break;
case JSToken.Modulo:
il.Emit(OpCodes.Rem); break;
case JSToken.Multiply:
il.Emit(OpCodes.Mul_Ovf_Un); break;
default:
throw new JScriptException(JSError.InternalError, this.context);
}
}
if (Convert.ToType(this.InferType(null)) == Typeob.Char){
Convert.Emit(this, il, rt, Typeob.Char);
Convert.Emit(this, il, Typeob.Char, rtype);
} else
Convert.Emit(this, il, rt, rtype);
return;
}
if (this.metaData is MethodInfo){
MethodInfo oper = (MethodInfo)this.metaData;
ParameterInfo[] pars = oper.GetParameters();
this.operand1.TranslateToIL(il, pars[0].ParameterType);
this.operand2.TranslateToIL(il, pars[1].ParameterType);
il.Emit(OpCodes.Call, oper);
Convert.Emit(this, il, oper.ReturnType, rtype);
return;
}
//Getting here is just too bad. We do not know until the code runs whether or not to call an overloaded operator method.
//Compile operands to objects and devolve the decision making to run time thunks
il.Emit(OpCodes.Ldloc, (LocalBuilder)this.metaData);
this.operand1.TranslateToIL(il, Typeob.Object);
this.operand2.TranslateToIL(il, Typeob.Object);
il.Emit(OpCodes.Call, CompilerGlobals.evaluateNumericBinaryMethod);
Convert.Emit(this, il, Typeob.Object, rtype);
}