This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / corlib / System.Reflection.Emit / TypeBuilder.cs
index d51e53d03437e5ea011660c69e8719989e4f6771..edcf429d9cc55167a63c75ed876ab94c314b6d44 100644 (file)
@@ -7,6 +7,29 @@
 // (C) 2001 Ximian, Inc.  http://www.ximian.com
 //
 
+//
+// Copyright (C) 2004 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;
 using System.Text;
 using System.Reflection;
@@ -36,12 +59,12 @@ namespace System.Reflection.Emit {
        private EventBuilder[] events;
        private CustomAttributeBuilder[] cattrs;
        internal TypeBuilder[] subtypes;
-       private TypeAttributes attrs;
+       internal TypeAttributes attrs;
        private int table_idx;
        private ModuleBuilder pmodule;
        private int class_size;
        private PackingSize packing_size;
-#if NET_2_0
+#if NET_2_0 || BOOTSTRAP_NET_2_0
        private GenericTypeParameterBuilder[] generic_params;
 #else
         private Object generic_params; /* so offsets don't change */
@@ -72,8 +95,9 @@ namespace System.Reflection.Emit {
                internal TypeBuilder (ModuleBuilder mb, TypeAttributes attr) {
                        this.parent = null;
                        this.attrs = attr;
-                       this.class_size = -1;
+                       this.class_size = 0;
                        fullname = this.tname = "<Module>";
+                       this.table_idx = 1;
                        this.nspace = "";
                        pmodule = mb;
                        setup_internal_class (this);
@@ -357,7 +381,7 @@ namespace System.Reflection.Emit {
                        return DefineConstructor (attributes, callingConvention, parameterTypes, null, null);
                }
 
-#if NET_2_0
+#if NET_2_0 || BOOTSTRAP_NET_2_0
                public
 #else
                internal
@@ -426,7 +450,7 @@ namespace System.Reflection.Emit {
                        return DefineMethod (name, attributes, callingConvention, returnType, null, null, parameterTypes, null, null);
                }
 
-#if NET_2_0
+#if NET_2_0 || BOOTSTRAP_NET_2_0
                public
 #else
                internal
@@ -451,7 +475,7 @@ namespace System.Reflection.Emit {
                        return DefinePInvokeMethod (name, dllName, entryName, attributes, callingConvention, returnType, null, null, parameterTypes, null, null, nativeCallConv, nativeCharSet);
                }
 
-#if NET_2_0
+#if NET_2_0 || BOOTSTRAP_NET_2_0
                public
 #else
                internal
@@ -522,7 +546,7 @@ namespace System.Reflection.Emit {
                        return DefineField (fieldName, type, null, null, attributes);
                }
 
-#if NET_2_0
+#if NET_2_0 || BOOTSTRAP_NET_2_0
                public
 #else
                internal
@@ -964,7 +988,7 @@ namespace System.Reflection.Emit {
                public override Type[] GetNestedTypes (BindingFlags bindingAttr) {
                        bool match;
                        ArrayList result = new ArrayList ();
-               
+
                        if (subtypes == null)
                                return Type.EmptyTypes;
                        foreach (TypeBuilder t in subtypes) {
@@ -1108,8 +1132,19 @@ namespace System.Reflection.Emit {
                                for (int i = 0; i < nnamed; ++i) {
                                        byte named_type = data [pos++];
                                        byte type = data [pos++];
-                                       int len = CustomAttributeBuilder.decode_len (data, pos, out pos);
-                                       string named_name = CustomAttributeBuilder.string_from_bytes (data, pos, len);
+                                       int len;
+                                       string named_name;
+
+                                       if (type == 0x55) {
+                                               len = CustomAttributeBuilder.decode_len (data, pos, out pos);
+                                               string named_typename = CustomAttributeBuilder.string_from_bytes (data, pos, len);
+                                               pos += len;
+                                               // FIXME: Check that 'named_type' and 'named_typename' match, etc.
+                                               //        See related code/FIXME in mono/mono/metadata/reflection.c
+                                       }
+
+                                       len = CustomAttributeBuilder.decode_len (data, pos, out pos);
+                                       named_name = CustomAttributeBuilder.string_from_bytes (data, pos, len);
                                        pos += len;
                                        /* all the fields are integers in StructLayout */
                                        int value = (int)data [pos++];
@@ -1223,6 +1258,8 @@ namespace System.Reflection.Emit {
                                throw not_after_created ();
 
                        parent = parentType;
+                       // will just set the parent-related bits if called a second time
+                       setup_internal_class (this);
                }
                internal int get_next_table_index (object obj, int table, bool inc) {
                        return pmodule.get_next_table_index (obj, table, inc);
@@ -1262,7 +1299,24 @@ namespace System.Reflection.Emit {
                                throw new ArgumentException (argName, "Illegal name.");
                }
 
-#if NET_2_0
+               public override String ToString ()
+               {
+                       return FullName;
+               }
+
+               [MonoTODO]
+               public override bool IsAssignableFrom (Type c)
+               {
+                       return base.IsAssignableFrom (c);
+               }
+
+               [MonoTODO]
+               public override bool IsSubclassOf (Type c)
+               {
+                       return base.IsSubclassOf (c);
+               }
+
+#if NET_2_0 || BOOTSTRAP_NET_2_0
                public override Type[] GetGenericArguments ()
                {
                        if (generic_params != null)