2009-07-07 Rodrigo Kumpera <rkumpera@novell.com>
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 7 Jul 2009 23:20:45 +0000 (23:20 -0000)
committerRodrigo Kumpera <kumpera@gmail.com>
Tue, 7 Jul 2009 23:20:45 +0000 (23:20 -0000)
* Type.cs (IsUserType): Only TypeDelegator and types
outside of corlib are unhandled usertypes.

2009-07-07 Rodrigo Kumpera  <rkumpera@novell.com>

* TypeBuilder.cs (IsArrayImpl): Return false always as a
typebuilder will never represent an array.

* TypeBuilder.cs (MakeArrayType): Return a new instance of
ArrayType instead of calling into MonoType machinery.

* DerivedTypes.cs: New file with all the internal types
used by SRE to represent derived types from TypeBuilder:
arrays, pointers and byrefs'.

svn path=/trunk/mcs/; revision=137521

mcs/class/corlib/System.Reflection.Emit/ChangeLog
mcs/class/corlib/System.Reflection.Emit/DerivedTypes.cs [new file with mode: 0644]
mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/Type.cs
mcs/class/corlib/corlib.dll.sources

index 97bdb8816308466647c7220740298348a0da2ef6..5c13ccdb000e103698fc74d44a0fee6a6dd80ab6 100644 (file)
@@ -1,3 +1,15 @@
+2009-07-07 Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * TypeBuilder.cs (IsArrayImpl): Return false always as a
+       typebuilder will never represent an array.
+
+       * TypeBuilder.cs (MakeArrayType): Return a new instance of
+       ArrayType instead of calling into MonoType machinery.
+
+       * DerivedTypes.cs: New file with all the internal types
+       used by SRE to represent derived types from TypeBuilder:
+       arrays, pointers and byrefs'.
+
 2009-07-02 Rodrigo Kumpera  <rkumpera@novell.com>
 
        * AssemblyBuilder.cs: Add IsRun property that returns true if
diff --git a/mcs/class/corlib/System.Reflection.Emit/DerivedTypes.cs b/mcs/class/corlib/System.Reflection.Emit/DerivedTypes.cs
new file mode 100644 (file)
index 0000000..37237f7
--- /dev/null
@@ -0,0 +1,320 @@
+//
+// System.Reflection.Emit.DerivedTypes.cs
+//
+// Authors:
+//     Rodrigo Kumpera <rkumpera@novell.com>
+//
+//
+// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Collections;
+using System.Runtime.CompilerServices;
+using System.Globalization;
+using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
+
+
+namespace System.Reflection.Emit
+{
+       internal enum TypeKind : int {
+               SZARRAY = 0x1d,
+               ARRAY = 0x14
+       }
+
+       internal abstract class DerivedType : Type
+       {
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal static extern void create_unmanaged_type (Type type);
+       
+       }
+
+       internal class ArrayType : DerivedType
+       {
+               Type elementType;
+               int rank;
+
+               internal ArrayType (Type elementType, int rank)
+               {
+                       this.elementType = elementType;
+                       this.rank = rank;
+               }
+
+               public override Type GetInterface (string name, bool ignoreCase)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override Type[] GetInterfaces ()
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override Type GetElementType ()
+               {
+                       return elementType;
+               }
+
+               public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override EventInfo[] GetEvents (BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override FieldInfo GetField( string name, BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override FieldInfo[] GetFields (BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder,
+                                                            CallingConventions callConvention, Type[] types,
+                                                            ParameterModifier[] modifiers)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override Type GetNestedType (string name, BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override Type[] GetNestedTypes (BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr, Binder binder,
+                                                                Type returnType, Type[] types, ParameterModifier[] modifiers)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
+                                                                      Binder binder,
+                                                                      CallingConventions callConvention,
+                                                                      Type[] types,
+                                                                      ParameterModifier[] modifiers)
+               {
+                       throw new NotSupportedException ();
+               }
+
+
+               protected override TypeAttributes GetAttributeFlagsImpl ()
+               {
+                       /*LAMEIMPL MS just return the elementType.Attributes*/
+                       return elementType.Attributes; 
+               }
+
+               protected override bool HasElementTypeImpl ()
+               {
+                       return true;
+               }
+
+               protected override bool IsArrayImpl ()
+               {
+                       return true;
+               }
+
+               protected override bool IsByRefImpl ()
+               {
+                       return false;
+               }
+
+               protected override bool IsCOMObjectImpl ()
+               {
+                       return false;
+               }
+
+               protected override bool IsPointerImpl ()
+               {
+                       return false;
+               }
+
+               protected override bool IsPrimitiveImpl ()
+               {
+                       return false;
+               }
+
+
+               public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override object InvokeMember (string name, BindingFlags invokeAttr,
+                                                    Binder binder, object target, object[] args,
+                                                    ParameterModifier[] modifiers,
+                                                    CultureInfo culture, string[] namedParameters)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override InterfaceMapping GetInterfaceMap (Type interfaceType)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override bool IsInstanceOfType (object o)
+               {
+                       return false;
+               }
+
+               public override int GetArrayRank ()
+               {
+                       return rank;
+               }
+
+#if NET_2_0
+               //FIXME this should be handled by System.Type
+               public override Type MakeGenericType (params Type[] typeArguments)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override Type MakeArrayType ()
+               {
+                       return MakeArrayType (1);
+               }
+
+               public override Type MakeArrayType (int rank)
+               {
+                       if (rank < 1)
+                               throw new IndexOutOfRangeException ();
+                       return new ArrayType (this, rank);
+               }
+
+               public override Type MakeByRefType ()
+               {
+                       create_unmanaged_type (this);
+                       return base.MakeByRefType ();
+               }
+
+               public override Type MakePointerType ()
+               {
+                       create_unmanaged_type (this);
+                       return base.MakePointerType ();
+               }
+
+               public override GenericParameterAttributes GenericParameterAttributes {
+                       get { throw new NotSupportedException (); }
+               }
+
+               public override StructLayoutAttribute StructLayoutAttribute {
+                       get { throw new NotSupportedException (); }
+               }
+#endif
+
+               public override Assembly Assembly {
+                       get { return elementType.Assembly; }
+               }
+
+               public override string AssemblyQualifiedName {
+                       get { return FullName + ", " + elementType.Assembly.FullName; }
+               }
+
+               public override Type BaseType {
+                       get { return typeof (System.Array); }
+               }
+
+               public override string FullName {
+                       get {
+                               //FIXME use a StringBuilder
+                               String commas = "";
+                               for (int i = 1; i < rank; ++i)
+                                       commas += ",";
+                               return String.Format("{0}[{1}]", elementType.FullName, commas);
+                       }
+               }
+
+               public override Guid GUID {
+                       get { throw new NotSupportedException (); }
+               }
+
+               public override Module Module {
+                       get { return elementType.Module; }
+               }
+       
+               public override string Namespace {
+                       get { return elementType.Namespace; }
+               }
+
+               public override RuntimeTypeHandle TypeHandle {
+                       get { throw new NotSupportedException (); }
+               }
+
+               public override Type UnderlyingSystemType {
+                       get { return this; }
+               }
+
+               //MemberInfo
+               public override bool IsDefined (Type attributeType, bool inherit)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override object [] GetCustomAttributes (bool inherit)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override object [] GetCustomAttributes (Type attributeType, bool inherit)
+               {
+                       throw new NotSupportedException ();
+               }
+
+               public override string Name {
+                       get {
+                               //FIXME use a StringBuilder
+                               String commas = "";
+                               for (int i = 1; i < rank; ++i)
+                                       commas += ",";
+                               return String.Format("{0}[{1}]", elementType.Name, commas);
+                       }
+               }
+       }
+}
index 56729aadd60855432b585839ed0a2ac81cea4f7e..4319ef69cd5cabb9f2ae18522adca4ac637a40c8 100644 (file)
@@ -1347,13 +1347,12 @@ namespace System.Reflection.Emit
 
                protected override bool IsArrayImpl ()
                {
-                       return Type.IsArrayImpl (this);
+                       return false; /*A TypeBuilder never represents a non typedef type.*/
                }
 
                protected override bool IsByRefImpl ()
                {
-                       // FIXME
-                       return false;
+                       return false; /*A TypeBuilder never represents a non typedef type.*/
                }
 
                protected override bool IsCOMObjectImpl ()
@@ -1363,8 +1362,7 @@ namespace System.Reflection.Emit
 
                protected override bool IsPointerImpl ()
                {
-                       // FIXME
-                       return false;
+                       return false; /*A TypeBuilder never represents a non typedef type.*/
                }
 
                protected override bool IsPrimitiveImpl ()
@@ -1385,13 +1383,13 @@ namespace System.Reflection.Emit
                [MonoTODO]
                public override Type MakeArrayType ()
                {
-                       return base.MakeArrayType ();
+                       return MakeArrayType (1);
                }
 
                [MonoTODO]
                public override Type MakeArrayType (int rank)
                {
-                       return base.MakeArrayType (rank);
+                       return new ArrayType (this, rank);
                }
 
                [MonoTODO]
index 3224b9439615535b6ca86e163dd97bc4d8623087..9ae27c5b4f49ec276c346388cbd1c54557ecf272 100644 (file)
@@ -1,3 +1,8 @@
+2009-07-07  Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * Type.cs (IsUserType): Only TypeDelegator and types
+       outside of corlib are unhandled usertypes.
+
 2009-07-02  Marek Safar  <marek.safar@gmail.com>
 
        * Type.cs, AppDomain.cs: 4.0 bits.
index d08f5d9d5c095de64c909c95774dba318c7cf63a..3e9bec1ebe6b275f97ed22d739b43a5f58cbb56e 100644 (file)
@@ -1409,7 +1409,8 @@ namespace System {
                                 * subclasses cannot modify _impl so if it is zero, it means the
                                 * type is not created by the runtime.
                                 */
-                               return _impl.Value == IntPtr.Zero;
+                               return _impl.Value == IntPtr.Zero &&
+                                       (GetType ().Assembly != typeof (Type).Assembly || GetType () == typeof (TypeDelegator));
                        }
                }
 
index 03bddb18389a29179d3de4f6205dccb3f6aed490..3af1a30f8bf18d5fbd70e1d184c10866028420a1 100644 (file)
@@ -514,6 +514,7 @@ System.Reflection.Emit/AssemblyBuilderAccess.cs
 System.Reflection.Emit/ConstructorBuilder.cs
 System.Reflection.Emit/ConstructorOnTypeBuilderInst.cs
 System.Reflection.Emit/CustomAttributeBuilder.cs
+System.Reflection.Emit/DerivedTypes.cs
 System.Reflection.Emit/DynamicILInfo.cs
 System.Reflection.Emit/DynamicMethod.cs
 System.Reflection.Emit/EnumBuilder.cs