Author: cesar
Date: 2005-05-25 16:29:51 -0400 (Wed, 25 May 2005)
New Revision: 45013
Modified:
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/BitwiseBinary.cs
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Convert.cs
Log:
Patch from [EMAIL PROTECTED]> that implements EvaluateBitwiseBinary
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/BitwiseBinary.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/BitwiseBinary.cs
2005-05-25 19:27:14 UTC (rev 45012)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/BitwiseBinary.cs
2005-05-25 20:29:51 UTC (rev 45013)
@@ -3,6 +3,7 @@
//
// Author:
// Cesar Lopez Nataren ([EMAIL PROTECTED])
+// Efren Serra ([EMAIL PROTECTED])
//
// (C) 2003, Cesar Lopez Nataren
//
@@ -44,9 +45,105 @@
[DebuggerHiddenAttribute]
public object EvaluateBitwiseBinary (object v1, object v2)
{
- return new object ();
+ return new EvaluateBitwiseBinary (v1, v2,
this.operatorTok);
}
+ private object EvaluateBitwiseBinary (object v1, object v2,
JSToken operatorTok)
+ {
+ IConvertible v1_ic = Convert.GetIConvertible (v1);
+ IConvertible v2_ic = Convert.GetIConvertible (v2);
+ TypeCode v1_tc = Convert.GetTypeCode (v1, v1_ic);
+ TypeCode v2_tc = Convert.GetTypeCode (v2, v2_ic);
+
+ switch (v1_tc) {
+ case TypeCode.Empty:
+ case TypeCode.DBNull:
+ return EvaluateBitwiseBinary (0, v2,
operatorTok);
+ break;
+
+ case Boolean:
+ case Char:
+ case SByte:
+ case Byte:
+ case Int16:
+ case UInt16:
+ case Int32:
+ int i = v1_ic.ToInt32 (null);
+ switch (v2_tc) {
+ case TypeCode.Empty:
+ case TypeCode.DBNull:
+ return EvaluateBitwiseBinary (i, 0,
operatorTok);
+ break;
+ case Boolean:
+ case Char:
+ case SByte:
+ case Byte:
+ case Int16:
+ case UInt16:
+ case Int32:
+ return DoOp (i, v2_ic.ToInt32 (null),
operatorTok);
+ break;
+ case UInt32:
+ case Int64:
+ case UInt64:
+ case Single:
+ case Double:
+ return DoOp (i,
(int)(long)v2_ic.ToDouble (null), operatorTok);
+ break;
+ case Object:
+ case Decimal:
+ case DateTime:
+ case String:
+ break;
+ }
+ break;
+ case UInt32:
+ case Int64:
+ case UInt64:
+ case Single:
+ case Double:
+ i = (int)(long)v1_ic.ToDouble (null);
+ switch (v2_tc) {
+ case TypeCode.Empty:
+ case TypeCode.DBNull:
+ return DoOp (i, 0, opertorTok);
+ break;
+ case Boolean:
+ case Char:
+ case SByte:
+ case Byte:
+ case Int16:
+ case UInt16:
+ case Int32:
+ return DoOp (i, v2_ic.ToInt32 (null),
operatorTok);
+ break;
+ case UInt32:
+ case Int64:
+ case UInt64:
+ case Single:
+ case Double:
+ return DoOp (i,
(int)(long)v2_ic.ToDouble (null));
+ break;
+ case Object:
+ case Decimal:
+ case DateTime:
+ case String:
+ break;
+ }
+ break;
+ case Object:
+ case Decimal:
+ case DateTime:
+ case String:
+ break;
+ }
+
+ if (v2 == null)
+ return DoOp (Convert.ToInt32 (v1), 0,
operatorTok);
+ else
+ return DoOp (Convert.ToInt32 (v1),
Convert.ToInt32 (v2), operatorTok);
+ }
+
internal override bool Resolve (IdentificationTable context)
{
throw new NotImplementedException ();
@@ -61,5 +158,25 @@
{
throw new NotImplementedException ();
}
+
+ internal static object DoOp (int i, int j, JSToken operatorTok)
+ {
+ switch (operatorTok) {
+ case JSToken.BitwiseOr:
+ return i | j;
+ case JSToken:BitwiseXor:
+ return i ^ j;
+ case JSToken.BitwiseAnd:
+ return i & j;
+ case JSToken.LeftShift:
+ return i << j;
+ case JSToken.RightShift:
+ return i >> j;
+ case JSToken.UnsignedRightShift:
+ return ((uint)i) >> j;
+ default:
+ throw new JScriptException
(JSError.InternalError);
+ }
+ }
}
}
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
2005-05-25 19:27:14 UTC (rev 45012)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/ChangeLog
2005-05-25 20:29:51 UTC (rev 45013)
@@ -1,3 +1,8 @@
+2005-05-25 Efren Serra <[EMAIL PROTECTED]>
+
+ * BitwiseBinary.cs: Implement EvaluateBitwiseBinary. Add DoOp.
+ * Convert.cs: Add GetIConvertible method.
+
2005-05-19 Cesar Lopez Nataren <[EMAIL PROTECTED]>
* Parser.cs: Throw NotImplementedException for function
Modified: trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Convert.cs
===================================================================
--- trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Convert.cs
2005-05-25 19:27:14 UTC (rev 45012)
+++ trunk/mcs/class/Microsoft.JScript/Microsoft.JScript/Convert.cs
2005-05-25 20:29:51 UTC (rev 45013)
@@ -42,7 +42,6 @@
throw new NotImplementedException ();
}
-
public static double CheckIfDoubleIsInteger (double d)
{
if (d == Math.Round (d))
@@ -218,5 +217,10 @@
else
return ic.GetTypeCode ();
}
+
+ internal static IConvertible GetIConvertible (object obj)
+ {
+ return obj as IConvertible;
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches