2009-03-27 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / rootcontext.cs
index 22c784d62b7ab3baa085304bc20a1439d7a1e03b..e6c2c4b2f1dc5ea543ad89cab34d2add27f13dc4 100644 (file)
@@ -25,6 +25,7 @@ namespace Mono.CSharp {
                Default_MCS     = 2,
                ISO_2           = 3,
                LINQ            = 4,
+               Future          = 5,
 
 #if GMCS_SOURCE
                Default         = LINQ
@@ -101,13 +102,13 @@ namespace Mono.CSharp {
                //
                // Contains the parsed tree
                //
-               static RootTypes root;
+               static ModuleContainer root;
 
                //
                // This hashtable contains all of the #definitions across the source code
                // it is used by the ConditionalAttribute handler.
                //
-               static ArrayList AllDefines = new ArrayList ();
+               static ArrayList AllDefines;
                
                //
                // This keeps track of the order in which classes were defined
@@ -144,7 +145,7 @@ namespace Mono.CSharp {
                public static void Reset (bool full)
                {
                        if (full)
-                               root = new RootTypes ();
+                               root = null;
                        
                        type_container_resolve_order = new ArrayList ();
                        EntryPoint = null;
@@ -166,8 +167,8 @@ namespace Mono.CSharp {
                        //
                        // Setup default defines
                        //
-                       RootContext.AllDefines = new ArrayList ();
-                       RootContext.AddConditional ("__MonoCS__");
+                       AllDefines = new ArrayList ();
+                       AddConditional ("__MonoCS__");
                }
 
                public static void AddConditional (string p)
@@ -182,8 +183,9 @@ namespace Mono.CSharp {
                        return AllDefines.Contains (value);
                }
 
-               static public RootTypes ToplevelTypes {
+               static public ModuleContainer ToplevelTypes {
                        get { return root; }
+                       set { root = value; }
                }
 
                public static void RegisterOrder (TypeContainer tc)
@@ -200,6 +202,8 @@ namespace Mono.CSharp {
                // </remarks>
                static public void ResolveTree ()
                {
+                       root.Resolve ();
+
                        //
                        // Interfaces are processed next, as classes and
                        // structs might inherit from an object or implement
@@ -256,9 +260,7 @@ namespace Mono.CSharp {
                        //
                        if (helper_classes != null){
                                foreach (TypeBuilder type_builder in helper_classes) {
-#if GMCS_SOURCE
-                                       type_builder.SetCustomAttribute (TypeManager.GetCompilerGeneratedAttribute (Location.Null));
-#endif
+                                       PredefinedAttributes.Get.CompilerGenerated.EmitAttribute (type_builder);
                                        type_builder.CreateType ();
                                }
                        }
@@ -288,7 +290,6 @@ namespace Mono.CSharp {
                        if (ds == null)
                                return;
 
-                       ds.DefineMembers ();
                        ds.Define ();
                }
                
@@ -312,14 +313,19 @@ namespace Mono.CSharp {
                        if (type_container_resolve_order != null){
                                foreach (TypeContainer tc in type_container_resolve_order)
                                        tc.ResolveType ();
-                               foreach (TypeContainer tc in type_container_resolve_order)
-                                       tc.DefineMembers ();
+                               foreach (TypeContainer tc in type_container_resolve_order) {
+                                       try {
+                                               tc.Define ();
+                                       } catch (Exception e) {
+                                               throw new InternalErrorException (tc, e);
+                                       }
+                               }
                        }
 
                        ArrayList delegates = root.Delegates;
                        if (delegates != null){
                                foreach (Delegate d in delegates)
-                                       d.DefineMembers ();
+                                       d.Define ();
                        }
 
                        //
@@ -332,33 +338,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               //
-               // DefineTypes is used to fill in the members of each type.
-               //
-               static public void DefineTypes ()
-               {
-                       ArrayList delegates = root.Delegates;
-                       if (delegates != null){
-                               foreach (Delegate d in delegates)
-                                       d.Define ();
-                       }
-
-                       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") ||
-                                            (tc.Name == "System.Runtime.CompilerServices.IndexerNameAttribute")))
-                                               continue;
-
-                                       tc.Define ();
-                               }
-                       }
-               }
-
                static public void EmitCode ()
                {
                        if (type_container_resolve_order != null) {
@@ -378,19 +357,14 @@ namespace Mono.CSharp {
                        }                       
 
                        CodeGen.Assembly.Emit (root);
-                       CodeGen.Module.Emit (root);
+                       root.Emit ();
                }
                
                //
                // Public Field, used to track which method is the public entry
                // point.
                //
-               static public MethodInfo EntryPoint;
-
-                //
-                // Track the location of the entry point.
-                //
-                static public Location EntryPointLocation;
+               static public Method EntryPoint;
 
                //
                // These are used to generate unique names on the structs and fields.
@@ -416,7 +390,7 @@ namespace Mono.CSharp {
                        FieldBuilder fb;
                        
                        if (impl_details_class == null){
-                               impl_details_class = CodeGen.Module.Builder.DefineType (
+                               impl_details_class = ToplevelTypes.Builder.DefineType (
                                        "<PrivateImplementationDetails>",
                                         TypeAttributes.NotPublic,
                                         TypeManager.object_type);