Author: jambunathan
Date: 2005-04-09 12:21:31 -0400 (Sat, 09 Apr 2005)
New Revision: 42735
Modified:
trunk/mcs/bmcs/ChangeLog
trunk/mcs/bmcs/convert.cs
trunk/mcs/bmcs/typemanager.cs
Log:
* convert.cs (ObjectTypeToPrimitiveTypes): Added. Converts an
'Object' to a 'Primitive Type'.
(WideningAndNarrowingConversion): Inserted call to
'ObjectTypeToPrimitiveTypes' to convert from 'Object' to a
'Primitive Type'.
* typemanager.cs (InitVisualBasicCodeHelpers): Added helper
methods that handles above conversions to the TypeManager's method
cache.
Modified: trunk/mcs/bmcs/ChangeLog
===================================================================
--- trunk/mcs/bmcs/ChangeLog 2005-04-09 15:13:23 UTC (rev 42734)
+++ trunk/mcs/bmcs/ChangeLog 2005-04-09 16:21:31 UTC (rev 42735)
@@ -1,3 +1,16 @@
+2005-04-09 Jambunathan K <[EMAIL PROTECTED]>
+
+ * convert.cs (ObjectTypeToPrimitiveTypes): Added. Converts an
+ 'Object' to a 'Primitive Type'.
+
+ (WideningAndNarrowingConversion): Inserted call to
+ 'ObjectTypeToPrimitiveTypes' to convert from 'Object' to a
+ 'Primitive Type'.
+
+ * typemanager.cs (InitVisualBasicCodeHelpers): Added helper
+ methods that handles above conversions to the TypeManager's method
+ cache.
+
2005-04-02 Jambunathan K <[EMAIL PROTECTED]>
* Makefile: Added '/r:Microsoft.VisualBasic.dll' to the compile
Modified: trunk/mcs/bmcs/convert.cs
===================================================================
--- trunk/mcs/bmcs/convert.cs 2005-04-09 15:13:23 UTC (rev 42734)
+++ trunk/mcs/bmcs/convert.cs 2005-04-09 16:21:31 UTC (rev 42735)
@@ -1942,6 +1942,61 @@
return null;
}
+
+ /// <summary>
+ /// VB.NET specific: Conversions from Object to Primitive Types
+ /// </summary>
+
+ static public Expression ObjectTypeToPrimitiveTypes
(EmitContext ec, Expression expr,
+ Type
target_type, Location loc)
+ {
+ Type expr_type = expr.Type;
+ Type real_target_type = target_type;
+ MethodInfo helper_method = null;
+ Expression retexpr;
+
+ if (expr_type != TypeManager.object_type)
+ return null;
+
+ if (target_type.IsSubclassOf (TypeManager.enum_type))
+ real_target_type = TypeManager.EnumToUnderlying
(target_type);
+
+
+ if (real_target_type == TypeManager.bool_type)
+ helper_method =
TypeManager.msvbcs_booleantype_fromobject_object;
+ if (real_target_type == TypeManager.byte_type)
+ helper_method =
TypeManager.msvbcs_bytetype_fromobject_object;
+ if (real_target_type == TypeManager.short_type)
+ helper_method =
TypeManager.msvbcs_shorttype_fromobject_object;
+ if (real_target_type == TypeManager.char_type)
+ helper_method =
TypeManager.msvbcs_chartype_fromobject_object;
+ if (real_target_type == TypeManager.int32_type)
+ helper_method =
TypeManager.msvbcs_integertype_fromobject_object;
+ if (real_target_type == TypeManager.int64_type)
+ helper_method =
TypeManager.msvbcs_longtype_fromobject_object;
+ if (real_target_type == TypeManager.float_type)
+ helper_method =
TypeManager.msvbcs_singletype_fromobject_object;
+ if (real_target_type == TypeManager.double_type)
+ helper_method =
TypeManager.msvbcs_doubletype_fromobject_object;
+ if (real_target_type == TypeManager.decimal_type)
+ helper_method =
TypeManager.msvbcs_decimaltype_fromobject_object;
+ if (real_target_type == TypeManager.date_type)
+ helper_method =
TypeManager.msvbcs_datetype_fromobject_object;
+ if (real_target_type == TypeManager.string_type)
+ helper_method =
TypeManager.msvbcs_stringtype_fromobject_object;
+
+ if (helper_method != null) {
+ retexpr = new HelperMethodInvocation (ec, loc,
real_target_type, helper_method, expr);
+ if (target_type != real_target_type)
+ retexpr = new EmptyCast (retexpr,
target_type);
+
+ return retexpr;
+ }
+
+ return null;
+ }
+
+
/// <summary>
/// Returns whether an explicit reference conversion can be
performed
/// from source_type to target_type
@@ -2217,6 +2272,17 @@
//
// Unboxing conversion.
//
+
+ //
+ // VB.NET treats conversions from object to
+ // the primitive types using the helper
+ // routines in Microsoft.VisualBasic.dll
+ //
+
+ ne = ObjectTypeToPrimitiveTypes(ec, expr, target_type,
loc);
+ if (ne != null)
+ return ne;
+
if (expr_type == TypeManager.object_type &&
target_type.IsValueType)
return new UnboxCast (expr, target_type);
Modified: trunk/mcs/bmcs/typemanager.cs
===================================================================
--- trunk/mcs/bmcs/typemanager.cs 2005-04-09 15:13:23 UTC (rev 42734)
+++ trunk/mcs/bmcs/typemanager.cs 2005-04-09 16:21:31 UTC (rev 42735)
@@ -296,7 +296,20 @@
static public MethodInfo msvbcs_stringtype_strcmp_string_string_boolean;
static public MethodInfo
msvbcs_stringtype_strlike_string_string_comparemethod;
-
+
+ static public MethodInfo msvbcs_booleantype_fromobject_object;
+ static public MethodInfo msvbcs_bytetype_fromobject_object;
+ static public MethodInfo msvbcs_shorttype_fromobject_object;
+ static public MethodInfo msvbcs_integertype_fromobject_object;
+ static public MethodInfo msvbcs_longtype_fromobject_object;
+ static public MethodInfo msvbcs_singletype_fromobject_object;
+ static public MethodInfo msvbcs_doubletype_fromobject_object;
+ static public MethodInfo msvbcs_decimaltype_fromobject_object;
+ static public MethodInfo msvbcs_chartype_fromobject_object;
+ static public MethodInfo msvbcs_datetype_fromobject_object;
+ static public MethodInfo msvbcs_stringtype_fromobject_object;
+
+
static public ConstructorInfo void_datetime_ctor_ticks_arg;
// <remarks>
@@ -1606,6 +1619,7 @@
//
public static void InitVisualBasicCodeHelpers ()
{
+ Type [] object_arg = { object_type };
Type [] boolean_arg = { bool_type };
Type [] byte_arg = { byte_type };
Type [] short_arg = { short_type };
@@ -1671,6 +1685,29 @@
msvbcs_stringtype_strlike_string_string_comparemethod =
GetMethod (
msvbcs_string_type, "StrLike",
string_string_comparemethod_arg);
+ msvbcs_booleantype_fromobject_object = GetMethod (
+ msvbcs_boolean_type, "FromObject", object_arg);
+ msvbcs_bytetype_fromobject_object = GetMethod (
+ msvbcs_byte_type, "FromObject", object_arg);
+ msvbcs_shorttype_fromobject_object = GetMethod (
+ msvbcs_short_type, "FromObject", object_arg);
+ msvbcs_integertype_fromobject_object = GetMethod (
+ msvbcs_integer_type, "FromObject", object_arg);
+ msvbcs_longtype_fromobject_object = GetMethod (
+ msvbcs_long_type, "FromObject", object_arg);
+ msvbcs_singletype_fromobject_object = GetMethod (
+ msvbcs_single_type, "FromObject", object_arg);
+ msvbcs_doubletype_fromobject_object = GetMethod (
+ msvbcs_double_type, "FromObject", object_arg);
+ msvbcs_decimaltype_fromobject_object = GetMethod (
+ msvbcs_decimal_type, "FromObject", object_arg);
+ msvbcs_chartype_fromobject_object = GetMethod (
+ msvbcs_char_type, "FromObject", object_arg);
+ msvbcs_datetype_fromobject_object = GetMethod (
+ msvbcs_date_type, "FromObject", object_arg);
+ msvbcs_stringtype_fromobject_object = GetMethod (
+ msvbcs_string_type, "FromObject", object_arg);
+
}
const BindingFlags instance_and_static = BindingFlags.Static |
BindingFlags.Instance;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches