Author: sudha
Date: 2005-04-29 08:00:08 -0400 (Fri, 29 Apr 2005)
New Revision: 43785
Modified:
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/ChangeLog
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinding.cs
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/ObjectType.cs
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/VBBinder.cs
Log:
Support for 'lateSet', 'LateIndexGet', 'LateIndexSet'
Modified:
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/ChangeLog
===================================================================
---
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/ChangeLog
2005-04-29 11:58:58 UTC (rev 43784)
+++
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/ChangeLog
2005-04-29 12:00:08 UTC (rev 43785)
@@ -1,3 +1,10 @@
+2005-04-29 Satya Sudha K <[EMAIL PROTECTED]>
+ * LateBinding.cs:
+ * VBBinder.cs :
+ - Support for 'LateIndexGet', 'LateIndexSet', 'LateSet'
+ * ObjectType.cs :
+ Some minor fixes in conversions
+
2005-04-22 Satya Sudha K <[EMAIL PROTECTED]>
* LateBinding.cs:
* VBBinder.cs :
Modified:
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinding.cs
===================================================================
---
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinding.cs
2005-04-29 11:58:58 UTC (rev 43784)
+++
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/LateBinding.cs
2005-04-29 12:00:08 UTC (rev 43785)
@@ -70,6 +70,7 @@
BindingFlags.Instance |
BindingFlags.Public |
BindingFlags.Static |
+ BindingFlags.GetProperty |
BindingFlags.InvokeMethod;
if (name == null) {
@@ -81,6 +82,11 @@
throw new MissingMemberException ("Public
Member '" + name + "' not found on type '" + objType + "'");
}
+ MemberInfo mi = GetMostDerivedMemberInfo (memberinfo);
+ if (mi.MemberType == MemberTypes.Field) {
+ FieldInfo fi = (FieldInfo) mi;
+ return fi.GetValue (o);
+ }
VBBinder binder = new VBBinder (CopyBack);
return binder.InvokeMember (name, flags, objType,
objReflect, o, args, null, null, paramnames);
}
@@ -96,48 +102,67 @@
bool OptimisticSet,
bool RValueBase)
{
- LateSet(o, objType, name, args, paramnames);
+ LateSet(o, objType, name, args, paramnames, null);
}
[System.Diagnostics.DebuggerStepThroughAttribute]
[System.Diagnostics.DebuggerHiddenAttribute]
- public static void LateSet(
- object o,
- Type objType,
- string name,
- object[] args,
- string[] paramnames) {
+ public static void LateSet (object o,
+ Type objType,
+ string name,
+ object[] args,
+ string[] paramnames,
+ bool[] CopyBack) {
- BindingFlags invokeAttr;
-
if (objType == null) {
if (o == null)
throw new NullReferenceException();
objType = o.GetType();
}
- Type[] typeArr = null;
- if (args != null) {
- typeArr = new Type[args.Length];
- for (int i = 0; i < typeArr.Length; i++) {
- typeArr[i] = args[i].GetType();
- }
+
+ IReflect objReflect = (IReflect) objType;
+
+ BindingFlags flags = BindingFlags.FlattenHierarchy |
+ BindingFlags.IgnoreCase |
+ BindingFlags.Instance |
+ BindingFlags.Public |
+ BindingFlags.Static |
+ BindingFlags.SetProperty |
+ BindingFlags.InvokeMethod;
+
+ if (name == null) {
+ name = "";
}
- MemberInfo[] memberInfo = objType.GetMember(name);
+ MemberInfo [] memberinfo = objReflect.GetMember (name,
flags);
- if (((memberInfo == null) || (memberInfo.Length == 0)))
{
- throw new NullReferenceException();
+ if (memberinfo == null || memberinfo.Length == 0) {
+ throw new MissingMemberException ("Public
Member '" + name + "' not found on type '" + objType + "'");
}
- if (memberInfo[0] is PropertyInfo)
- invokeAttr = BindingFlags.SetProperty;
- else if (memberInfo[0] is FieldInfo)
- invokeAttr = BindingFlags.SetField;
- else
- throw new NullReferenceException();
+ MemberInfo mi = GetMostDerivedMemberInfo (memberinfo);
+ if (mi.MemberType == MemberTypes.Field) {
+ FieldInfo fi = (FieldInfo) mi;
+ if (args == null || args.Length == 0) {
+ throw new MissingMemberException
("Public Member '" + name + "' not found on type '" + objType + "' that can be
assigned the given set of arguments");
+ }
- objType.InvokeMember(name, invokeAttr, null, o, args);
+ if (fi.IsInitOnly || fi.IsPrivate) {
+ throw new MissingMemberException
("Member '" + name + "' is a readonly field");
+ }
+
+ object value = null;
+ if (args.Length == 1)
+ value = args [0];
+
+ fi.SetValue (o, value);
+ return;
+ }
+
+ VBBinder binder = new VBBinder (null);
+ binder.InvokeMember (name, flags, objType, objReflect,
o, args, null, null, paramnames);
}
+
//mono implmentation
//
[System.Diagnostics.DebuggerStepThroughAttribute]
// [System.Diagnostics.DebuggerHiddenAttribute]
@@ -210,39 +235,28 @@
//late binding for array
if (type.IsArray) {
- // TODO:
- throw new NotImplementedException("LateBinding not
implmented");
- //int rank = ArrayStaticWrapper.get_Rank(o);
- //if (rank != args.Length)
- // throw new RankException();
- //int[] indices = new int[args.Length];
- //for (int i = 0; i < indices.Length; i++)
- // indices[i] =
IntegerType.FromObject(args[i]);
- //return ArrayStaticWrapper.GetValue(o,
indices);
+ Array objAsArray = (Array) o;
+ if (objAsArray.Rank != args.Length)
+ throw new RankException ();
+
+ int numArgs = args.Length;
+ int [] indexArray = new int [numArgs];
+ for (int index = 0; index < numArgs; index ++)
+ indexArray [index] =
IntegerType.FromObject (args [index]);
+ return objAsArray.GetValue (indexArray);
}
+
//late binding for default property
- Type[] types = new Type[args.Length];
- for (int i = 0; i < types.Length; i++) {
- types[i] = args[i].GetType();
- }
- // TODO:
- //string defaultPropName;
- throw new NotImplementedException("LateBinding not
implmented");
- //if (type is TypeInfo)
- // defaultPropName = getDefaultMemberName(type);
- //else if (type == Type.StringType ||
- // type ==
Type.GetType("System.Text.StringBuilder"))
- // defaultPropName = "Chars";
- //else
- // defaultPropName = "Item";
- //PropertyInfo propertyInfo = null;
- //if (defaultPropName != null)
- // propertyInfo =
type.GetProperty(defaultPropName, types);
- //if (propertyInfo != null) {
- // return propertyInfo.GetValue(o, args);
- //}
- //else
- // throw new NotSupportedException();
+ VBBinder binder = new VBBinder (null);
+ BindingFlags flags = BindingFlags.FlattenHierarchy |
+ BindingFlags.IgnoreCase |
+ BindingFlags.Instance |
+ BindingFlags.Public |
+ BindingFlags.Static |
+ BindingFlags.GetProperty |
+ BindingFlags.InvokeMethod;
+ IReflect objReflect = (IReflect) type;
+ return binder.InvokeMember ("", flags, type,
objReflect, o, args, null, null, paramnames);
}
private static string getDefaultMemberName(Type type) {
@@ -332,53 +346,33 @@
string[] paramnames) {
if (o == null)
throw new NullReferenceException();
- if (args == null)
+ if (args == null || args.Length == 0)
throw new NullReferenceException();
Type type = o.GetType();
//late binding for array
if (type.IsArray) {
- // TODO:
- throw new NotImplementedException("LateBinding
not implmented");
- //int rank = ArrayStaticWrapper.get_Rank(o);
- //if (rank != (args.Length - 1))
- // throw new RankException();
- //int[] indices = new int[args.Length - 1];
- //for (int i = 0; i < (indices.Length - 1); i++)
- // indices[i] =
IntegerType.FromObject(args[i]);
- //ArrayStaticWrapper.SetValue(o,
args[args.Length - 1], indices);
- //return;
+ Array array = (Array) o;
+ if (array.Rank != args.Length - 1)
+ throw new RankException ();
+ object setValue = args [args.GetUpperBound (0)];
+ int [] indexArray = new int [args.GetUpperBound
(0)];
+ for (int index = 0; index < indexArray.Length;
index ++) {
+ indexArray [index] =
IntegerType.FromObject (args [index]);
+ }
+ array.SetValue (setValue, indexArray);
+ return;
}
//late binding for default property
- Type[] types = new Type[args.Length - 1];
- for (int i = 0; i < types.Length; i++) {
- // TODO:
- throw new NotImplementedException("LateBinding
not implmented");
- //types[i] =
ObjectStaticWrapper.GetType(args[i]);
- //System.out.println("in Set:" +
types[i].get_FullName());
- }
- //string defaultPropName;
- // TODO:
- throw new NotImplementedException("LateBinding
not implmented");
- //if (type is TypeInfo)
- // defaultPropName = getDefaultMemberName(type);
- //else if (type == Type.StringType ||
- // type ==
Type.GetType("System.Text.StringBuilder"))
- // defaultPropName = "Chars";
- //else
- // defaultPropName = "Item";
- //PropertyInfo propertyInfo = null;
- //if (defaultPropName != null)
- // propertyInfo =
type.GetProperty(defaultPropName, types);
- //if (propertyInfo != null) {
- // object newVal = args[args.Length - 1];
- // object[] Params = new object[args.Length - 1];
-
- // Array.Copy(args, 0, Params, 0, args.Length - 1);
- // // java System.arraycopy(args, 0, Params, 0,
args.Length - 1);
- // propertyInfo.SetValue(o, newVal, Params);
- //}
- //else
- // throw new NotSupportedException();
+ VBBinder binder = new VBBinder (null);
+ BindingFlags flags = BindingFlags.FlattenHierarchy |
+ BindingFlags.IgnoreCase |
+ BindingFlags.Instance |
+ BindingFlags.Public |
+ BindingFlags.Static |
+ BindingFlags.SetProperty |
+ BindingFlags.InvokeMethod;
+ IReflect objReflect = (IReflect) type;
+ binder.InvokeMember ("", flags, type, objReflect, o,
args, null, null, paramnames);
}
[System.Diagnostics.DebuggerHiddenAttribute]
@@ -450,6 +444,17 @@
return binder.InvokeMember (name, flags, objType,
objReflect, o, args, null, null, paramnames);
}
-
+ private static MemberInfo GetMostDerivedMemberInfo (MemberInfo
[] mi)
+ {
+ if (mi == null || mi.Length == 0)
+ return null;
+ MemberInfo m = mi [0];
+ for (int index = 1; index < mi.Length; index ++) {
+ MemberInfo m1 = mi [index];
+ if (m1.DeclaringType.IsSubclassOf
(m.DeclaringType))
+ m = m1;
+ }
+ return m;
+ }
}
}
Modified:
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/ObjectType.cs
===================================================================
---
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/ObjectType.cs
2005-04-29 11:58:58 UTC (rev 43784)
+++
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/ObjectType.cs
2005-04-29 12:00:08 UTC (rev 43785)
@@ -1337,6 +1337,10 @@
}
internal static bool ImplicitConversionExists (Type FromType,
Type ToType) {
+ if (FromType == null)
+ return true;
+ if (ToType == typeof (object))
+ return true;
if (FromType.IsEnum)
FromType = GetTypeFromTypeCode
(Type.GetTypeCode (FromType));
if (ToType.IsEnum)
@@ -1405,12 +1409,16 @@
}
internal static bool IsWideningConversion(Type FromType, Type
ToType) {
+ if (FromType == null)
+ return true;
TypeCode typeCode1 = Type.GetTypeCode(FromType);
TypeCode typeCode2 = Type.GetTypeCode(ToType);
if (FromType == ToType)
return true;
+ if (ToType == typeof (object))
+ return true;
if (IsWiderNumeric (ToType, FromType))
return true;
@@ -1445,6 +1453,7 @@
return false;
}
if (! ToType.IsValueType) {
+ Console.WriteLine ("Sudha--> {0} {1}" ,
FromType, ToType);
return ToType.IsAssignableFrom(FromType);
}
return false;
@@ -1453,6 +1462,8 @@
//checked
[MonoTODO]
internal static bool IsWiderNumeric(Type Type1, Type Type2) {
+ if (Type1 == null)
+ return true;
TypeCode typeCode1 = Type.GetTypeCode(Type1);
TypeCode typeCode2 = Type.GetTypeCode(Type2);
if (!Utils.IsNumericType(Type1) ||
!Utils.IsNumericType(Type2)) {
@@ -1850,7 +1861,7 @@
case TypeCode.DateTime:
return null;
case TypeCode.String:
- return null;
+ return "";
default:
return null;
}
Modified:
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/VBBinder.cs
===================================================================
---
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/VBBinder.cs
2005-04-29 11:58:58 UTC (rev 43784)
+++
trunk/mcs/class/Microsoft.VisualBasic/Microsoft.VisualBasic.CompilerServices/VBBinder.cs
2005-04-29 12:00:08 UTC (rev 43785)
@@ -169,7 +169,6 @@
throw new AmbiguousMatchException ("No
overloaded '" + this.objectType + "." + this.bindToName + "' can be called
without a widening conversion");
}
-
if (mbase == null)
return null;
@@ -183,6 +182,10 @@
for(int y = 0; y < numFixedParams; y++)
{
+ if (args [y] == null) {
+ count ++;
+ continue;
+ }
if((args [y] = ObjectType.CTypeHelper (args[y],
pars[y].ParameterType)) != null)
count++;
else
@@ -358,8 +361,12 @@
ConversionType ctype = ConversionType.None;
for (int index = 0; index < minParams; index ++) {
ConversionType currentCType =
ConversionType.None;
- Type type1 = args [index].GetType ();
+ Type type1 = null;
+ if (args [index] != null)
+ type1 = args [index].GetType ();
Type type2 = parameters [index].ParameterType;
+ if (type2.IsByRef)
+ type2 = type2.GetElementType ();
if (type1 == type2) {
currentCType = ConversionType.Exact;
if (ctype < currentCType) {
@@ -508,7 +515,7 @@
this.objectType = objType;
this.bindToName = name;
- if (name == null) {
+ if (name == null || name.Equals ("")) {
// Must be a default property
Type t = objType;
while (t != null) {
@@ -522,11 +529,12 @@
}
}
- if (name == null) {
+ if (name == null || name.Equals ("")) {
throw new MissingMemberException ("No default
members defined for type '" + objType + "'");
}
- MemberInfo[] memberinfo = objReflect.GetMember (name,
flags);
+ MemberInfo[] memberinfo = GetMembers (objReflect,
objType, name, flags);
+
if (memberinfo == null || memberinfo.Length == 0) {
throw new MissingMemberException ("No member '"
+ name + "' defined for type '" + objType + "'");
}
@@ -575,12 +583,15 @@
return true;
for (int index = 0; index < numFixedParams; index ++) {
- Type argType = args [index].GetType ();
- Type paramType = parameters
[index].ParameterType;
- if (paramType.IsByRef)
- paramType = paramType.GetElementType ();
- if (!ObjectType.ImplicitConversionExists
(argType, paramType))
- return false;
+ Type argType = null;
+ if (args [index] != null) {
+ argType = args [index].GetType ();
+ Type paramType = parameters
[index].ParameterType;
+ if (paramType.IsByRef)
+ paramType =
paramType.GetElementType ();
+ if
(!ObjectType.ImplicitConversionExists (argType, paramType))
+ return false;
+ }
}
if (usesParamArray) {
@@ -647,5 +658,24 @@
}
return newMemberList;
}
+
+ internal MemberInfo [] GetMembers (IReflect objReflect, Type
objType, string name, BindingFlags invokeFlags)
+ {
+ MemberInfo [] mi = objReflect.GetMember (name,
invokeFlags);
+ if (mi == null || mi.Length == 0)
+ return null;
+
+ for (int index = 0; index < mi.Length; index ++)
+ {
+ if (mi [index].MemberType ==
MemberTypes.Property) {
+ PropertyInfo propinfo = (PropertyInfo)
mi [index];
+ if ((invokeFlags &
BindingFlags.GetProperty) == BindingFlags.GetProperty)
+ mi [index] =
propinfo.GetGetMethod ();
+ else if ((invokeFlags &
BindingFlags.SetProperty) == BindingFlags.SetProperty)
+ mi [index] =
propinfo.GetSetMethod ();
+ }
+ }
+ return mi;
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches