internal override void TranslateToIL(ILGenerator il, Type rtype){
if (this.metaData == null){
Type bbrType = BitwiseBinary.ResultType(this.type1, this.type2, this.operatorTok);
if (Convert.IsPrimitiveNumericType(this.type1)){
this.operand1.TranslateToIL(il, this.type1);
Convert.Emit(this, il, this.type1, bbrType, true);
}else{
this.operand1.TranslateToIL(il, Typeob.Double);
Convert.Emit(this, il, Typeob.Double, bbrType, true);
}
Type op2type = BitwiseBinary.Operand2Type(this.operatorTok, bbrType);
if (Convert.IsPrimitiveNumericType(this.type2)){
this.operand2.TranslateToIL(il, this.type2);
Convert.Emit(this, il, this.type2, op2type, true);
}else{
this.operand2.TranslateToIL(il, Typeob.Double);
Convert.Emit(this, il, Typeob.Double, op2type, true);
}
switch (this.operatorTok){
case JSToken.BitwiseAnd:
il.Emit(OpCodes.And);
break;
case JSToken.BitwiseOr:
il.Emit(OpCodes.Or);
break;
case JSToken.BitwiseXor:
il.Emit(OpCodes.Xor);
break;
case JSToken.LeftShift:
BitwiseBinary.TranslateToBitCountMask(il, bbrType, this.operand2);
il.Emit(OpCodes.Shl);
break;
case JSToken.RightShift:
BitwiseBinary.TranslateToBitCountMask(il, bbrType, this.operand2);
il.Emit(OpCodes.Shr);
break;
case JSToken.UnsignedRightShift:
BitwiseBinary.TranslateToBitCountMask(il, bbrType, this.operand2);
il.Emit(OpCodes.Shr_Un);
break;
default:
throw new JScriptException(JSError.InternalError, this.context);
}
Convert.Emit(this, il, bbrType, 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.evaluateBitwiseBinaryMethod);
Convert.Emit(this, il, Typeob.Object, rtype);
}