2002-09-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / mbas / rootcontext.cs
index cf2d1b08240527af6edc3b23d8c40659e712fe45..9d7ac28af7885c0bd3a9428d6e2461e1a5a543b4 100644 (file)
@@ -332,12 +332,9 @@ namespace Mono.CSharp {
                        // These are classes that depends on the core interfaces
                        //
                        string [] classes_second_stage = {
-                               "System.String", "System.Enum",
-                               "System.Array",  "System.MulticastDelegate",
-                               "System.Delegate",
-
                                "System.Reflection.MemberInfo",
                                "System.Type",
+                               "System.Exception",
 
                                //
                                // These are not really important in the order, but they
@@ -351,10 +348,19 @@ namespace Mono.CSharp {
                                "System.Runtime.InteropServices.DllImportAttribute",
                                "System.Runtime.CompilerServices.MethodImplAttribute",
                                "System.Runtime.InteropServices.MarshalAsAttribute",
+                               "System.Diagnostics.ConditionalAttribute",
+                               "System.ObsoleteAttribute",
                                "System.ParamArrayAttribute",
                                "System.Security.UnverifiableCodeAttribute",
                                "System.Runtime.CompilerServices.IndexerNameAttribute",
                        };
+
+                       // We must store them here before calling BootstrapCorlib_ResolveDelegate.
+                       TypeManager.string_type = BootstrapCorlib_ResolveClass (root, "System.String");
+                       TypeManager.enum_type = BootstrapCorlib_ResolveClass (root, "System.Enum");
+                       TypeManager.array_type = BootstrapCorlib_ResolveClass (root, "System.Array");
+                       TypeManager.multicast_delegate_type = BootstrapCorlib_ResolveClass (root, "System.MulticastDelegate");
+                       TypeManager.delegate_type = BootstrapCorlib_ResolveClass (root, "System.Delegate");
                        
                        foreach (string cname in classes_second_stage)
                                BootstrapCorlib_ResolveClass (root, cname);
@@ -596,6 +602,7 @@ namespace Mono.CSharp {
                {
                        DeclSpace ds = (DeclSpace) root.GetDefinition (name);
 
+                       ds.DefineMembers (root);
                        ds.Define (root);
                }
                
@@ -620,30 +627,39 @@ namespace Mono.CSharp {
 
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
-                                       tc.Define (root);
+                                       tc.DefineMembers (root);
                        
                        if (interface_resolve_order != null){
                                foreach (Interface iface in interface_resolve_order)
                                        if ((iface.ModFlags & Modifiers.NEW) == 0)
-                                               iface.Define (root);
+                                               iface.DefineMembers (root);
                                        else
                                                Report1530 (iface.Location);
                        }
 
 
                        if (type_container_resolve_order != null){
-                               foreach (TypeContainer tc in type_container_resolve_order)
+                               foreach (TypeContainer tc in type_container_resolve_order) {
+                                       // When compiling corlib, these types have already been
+                                       // populated from BootCorlib_PopulateCoreTypes ().
+                                       if (!RootContext.StdLib &&
+                                           ((tc.Name == "System.Object") ||
+                                            (tc.Name == "System.Attribute") ||
+                                            (tc.Name == "System.ValueType")))
+                                               continue;
+
                                        if ((tc.ModFlags & Modifiers.NEW) == 0)
-                                               tc.Define (root);
+                                               tc.DefineMembers (root);
                                        else
                                                Report1530 (tc.Location);
+                               }
                        }
 
                        ArrayList delegates = root.Delegates;
                        if (delegates != null){
                                foreach (Delegate d in delegates)
                                        if ((d.ModFlags & Modifiers.NEW) == 0)
-                                               d.Define (root);
+                                               d.DefineMembers (root);
                                        else
                                                Report1530 (d.Location);
                        }
@@ -652,12 +668,57 @@ namespace Mono.CSharp {
                        if (enums != null){
                                foreach (Enum en in enums)
                                        if ((en.ModFlags & Modifiers.NEW) == 0)
-                                               en.Define (root);
+                                               en.DefineMembers (root);
                                        else
                                                Report1530 (en.Location);
                        }
                }
 
+               static public void DefineTypes ()
+               {
+                       TypeContainer root = Tree.Types;
+
+                       if (attribute_types != null)
+                               foreach (TypeContainer tc in attribute_types)
+                                       tc.Define (root);
+                       
+                       if (interface_resolve_order != null){
+                               foreach (Interface iface in interface_resolve_order)
+                                       if ((iface.ModFlags & Modifiers.NEW) == 0)
+                                               iface.Define (root);
+                       }
+
+
+                       if (type_container_resolve_order != null){
+                               foreach (TypeContainer tc in type_container_resolve_order) {
+                                       // When compiling corlib, these types have already been
+                                       // populated from BootCorlib_PopulateCoreTypes ().
+                                       if (!RootContext.StdLib &&
+                                           ((tc.Name == "System.Object") ||
+                                            (tc.Name == "System.Attribute") ||
+                                            (tc.Name == "System.ValueType")))
+                                               continue;
+
+                                       if ((tc.ModFlags & Modifiers.NEW) == 0)
+                                               tc.Define (root);
+                               }
+                       }
+
+                       ArrayList delegates = root.Delegates;
+                       if (delegates != null){
+                               foreach (Delegate d in delegates)
+                                       if ((d.ModFlags & Modifiers.NEW) == 0)
+                                               d.Define (root);
+                       }
+
+                       ArrayList enums = root.Enums;
+                       if (enums != null){
+                               foreach (Enum en in enums)
+                                       if ((en.ModFlags & Modifiers.NEW) == 0)
+                                               en.Define (root);
+                       }
+               }
+
                static public void EmitCode ()
                {
                        //
@@ -678,7 +739,7 @@ namespace Mono.CSharp {
                                        Attribute.ApplyAttributes (temp_ec, ab, ab, attrs, attrs.Location);
                                }
                        }
-                       
+
                        if (attribute_types != null)
                                foreach (TypeContainer tc in attribute_types)
                                        tc.Emit ();
@@ -692,14 +753,12 @@ namespace Mono.CSharp {
                        }
                        
                        if (Unsafe) {
-                               ConstructorInfo ci = TypeManager.unverifiable_code_type.GetConstructor (new Type [0]);
-                                       
-                               if (ci == null) {
-                                       Console.WriteLine ("Internal error !");
+                               if (TypeManager.unverifiable_code_ctor == null) {
+                                       Console.WriteLine ("Internal error ! Cannot set unverifiable code attribute.");
                                        return;
                                }
                                
-                               CustomAttributeBuilder cb = new CustomAttributeBuilder (ci, new object [0]);
+                               CustomAttributeBuilder cb = new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]);
                                CodeGen.ModuleBuilder.SetCustomAttribute (cb);
                        }
                }
@@ -741,7 +800,7 @@ namespace Mono.CSharp {
                        
                        if (impl_details_class == null)
                                impl_details_class = CodeGen.ModuleBuilder.DefineType (
-                                       "<PrivateImplementationDetails>", TypeAttributes.NotPublic);
+                                       "<PrivateImplementationDetails>", TypeAttributes.NotPublic, TypeManager.object_type);
 
                        fb = impl_details_class.DefineInitializedData (
                                "$$field-" + (field_count++), data,