2007-03-20 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / mcs / rootcontext.cs
index 2a21658548944efab7200bca5efcdc231ffcef63..9eb5fdae489425a26ca8e12048d9b8cccb147720 100644 (file)
@@ -20,7 +20,8 @@ namespace Mono.CSharp {
        public enum LanguageVersion
        {
                Default = 0,
-               ISO_1   = 1
+               ISO_1   = 1,
+               LINQ
        }
 
        public class RootContext {
@@ -28,7 +29,7 @@ namespace Mono.CSharp {
                //
                // Contains the parsed tree
                //
-               static Tree tree;
+               static RootTypes root;
 
                //
                // This hashtable contains all of the #definitions across the source code
@@ -63,7 +64,7 @@ namespace Mono.CSharp {
                static TypeBuilder impl_details_class;
 
                public static int WarningLevel;
-               
+
                public static Target Target;
                public static string TargetExt;
 
@@ -101,7 +102,7 @@ namespace Mono.CSharp {
 
                public static void Reset ()
                {
-                       tree = new Tree ();
+                       root = new RootTypes ();
                        type_container_resolve_order = new ArrayList ();
                        EntryPoint = null;
                        WarningLevel = 3;
@@ -119,17 +120,13 @@ namespace Mono.CSharp {
                        impl_details_class = null;
                        helper_classes = null;
                }
-               
+
                public static bool NeedsEntryPoint {
-                       get {
-                               return RootContext.Target == Target.Exe || RootContext.Target == Target.WinExe;
-                       }
+                       get { return RootContext.Target == Target.Exe || RootContext.Target == Target.WinExe; }
                }
 
-               static public Tree Tree {
-                       get {
-                               return tree;
-                       }
+               static public RootTypes ToplevelTypes {
+                       get { return root; }
                }
 
                public static void RegisterOrder (TypeContainer tc)
@@ -162,13 +159,8 @@ namespace Mono.CSharp {
                        // a set of interfaces, we need to be able to tell
                        // them appart by just using the TypeManager.
                        //
-                       TypeContainer root = Tree.Types;
-
-                       ArrayList ifaces = root.Interfaces;
-                       if (ifaces != null){
-                               foreach (TypeContainer i in ifaces) 
-                                       i.DefineType ();
-                       }
+                       foreach (TypeContainer tc in root.Types)
+                               tc.CreateType ();
 
                        foreach (TypeContainer tc in root.Types)
                                tc.DefineType ();
@@ -176,10 +168,6 @@ namespace Mono.CSharp {
                        if (root.Delegates != null)
                                foreach (Delegate d in root.Delegates) 
                                        d.DefineType ();
-
-                       if (root.Enums != null)
-                               foreach (Enum e in root.Enums)
-                                       e.DefineType ();
                }
 
                static void Error_TypeConflict (string name, Location loc)
@@ -197,7 +185,7 @@ namespace Mono.CSharp {
                //
                // Resolves a single class during the corlib bootstrap process
                //
-               static TypeBuilder BootstrapCorlib_ResolveClass (TypeContainer root, string name)
+               static Type BootstrapCorlib_ResolveClass (TypeContainer root, string name)
                {
                        object o = root.GetDefinition (name);
                        if (o == null){
@@ -216,7 +204,10 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       return ((DeclSpace) o).DefineType ();
+                       Type t = ((DeclSpace) o).DefineType ();
+                       if (t != null)
+                               AttributeTester.RegisterNonObsoleteType (t);
+                       return t;
                }
 
                //
@@ -266,7 +257,9 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       ((DeclSpace) o).DefineType ();
+                       Type t = ((DeclSpace) o).DefineType ();
+                       if (t != null)
+                               AttributeTester.RegisterNonObsoleteType (t);
                }
 
                //
@@ -294,13 +287,17 @@ namespace Mono.CSharp {
                /// </summary>
                static public void ResolveCore ()
                {
-                       TypeContainer root = Tree.Types;
-
                        TypeManager.object_type = BootstrapCorlib_ResolveClass (root, "System.Object");
                        TypeManager.system_object_expr.Type = TypeManager.object_type;
                        TypeManager.value_type = BootstrapCorlib_ResolveClass (root, "System.ValueType");
                        TypeManager.system_valuetype_expr.Type = TypeManager.value_type;
+
+                       //
+                       // The core attributes
+                       //
+                       BootstrapCorlib_ResolveInterface (root, "System.Runtime.InteropServices._Attribute");
                        TypeManager.attribute_type = BootstrapCorlib_ResolveClass (root, "System.Attribute");
+                       TypeManager.obsolete_attribute_type = BootstrapCorlib_ResolveClass (root, "System.ObsoleteAttribute");
                        TypeManager.indexer_name_type = BootstrapCorlib_ResolveClass (root, "System.Runtime.CompilerServices.IndexerNameAttribute");
                        
                        string [] interfaces_first_stage = {
@@ -317,7 +314,16 @@ namespace Mono.CSharp {
                                "System.Runtime.Serialization.ISerializable",
 
                                "System.Reflection.IReflect",
-                               "System.Reflection.ICustomAttributeProvider"
+                               "System.Reflection.ICustomAttributeProvider",
+#if GMCS_SOURCE
+                               "System.Runtime.InteropServices._Exception",
+
+                               //
+                               // Generic types
+                               //
+                               "System.Collections.Generic.IEnumerator`1",
+                               "System.Collections.Generic.IEnumerable`1"
+#endif
                        };
 
                        foreach (string iname in interfaces_first_stage)
@@ -367,6 +373,9 @@ namespace Mono.CSharp {
                                "System.Reflection.MemberInfo",
                                "System.Type",
                                "System.Exception",
+#if GMCS_SOURCE
+                               "System.Activator",
+#endif
 
                                //
                                // These are not really important in the order, but they
@@ -375,13 +384,17 @@ namespace Mono.CSharp {
                                "System.Runtime.CompilerServices.RuntimeHelpers",
                                "System.Reflection.DefaultMemberAttribute",
                                "System.Threading.Monitor",
+                               "System.Threading.Interlocked",
                                
                                "System.AttributeUsageAttribute",
                                "System.Runtime.InteropServices.DllImportAttribute",
                                "System.Runtime.CompilerServices.MethodImplAttribute",
                                "System.Runtime.InteropServices.MarshalAsAttribute",
+#if GMCS_SOURCE
+                               "System.Runtime.CompilerServices.CompilerGeneratedAttribute",
+                               "System.Runtime.CompilerServices.FixedBufferAttribute",
+#endif
                                "System.Diagnostics.ConditionalAttribute",
-                               "System.ObsoleteAttribute",
                                "System.ParamArrayAttribute",
                                "System.CLSCompliantAttribute",
                                "System.Security.UnverifiableCodeAttribute",
@@ -391,6 +404,9 @@ namespace Mono.CSharp {
                                "System.Runtime.InteropServices.OutAttribute",
                                "System.Runtime.InteropServices.StructLayoutAttribute",
                                "System.Runtime.InteropServices.FieldOffsetAttribute",
+#if GMCS_SOURCE
+                               "System.Runtime.InteropServices.DefaultCharSetAttribute",
+#endif
                                "System.InvalidOperationException",
                                "System.NotSupportedException",
                                "System.MarshalByRefObject",
@@ -402,7 +418,9 @@ namespace Mono.CSharp {
 
                        foreach (string cname in classes_second_stage)
                                BootstrapCorlib_ResolveClass (root, cname);
-
+#if GMCS_SOURCE
+                       BootstrapCorlib_ResolveStruct (root, "System.Nullable`1");
+#endif
                        BootstrapCorlib_ResolveDelegate (root, "System.AsyncCallback");
 
                        // These will be defined indirectly during the previous ResolveDelegate.
@@ -424,12 +442,6 @@ namespace Mono.CSharp {
                // </remarks>
                static public void CloseTypes ()
                {
-                       TypeContainer root = Tree.Types;
-                       
-                       if (root.Enums != null)
-                               foreach (Enum en in root.Enums)
-                                       en.CloseType ();
-
                        //
                        // We do this in two passes, first we close the structs,
                        // then the classes, because it seems the code needs it this
@@ -437,13 +449,13 @@ namespace Mono.CSharp {
                        // make sure that we define the structs in order as well.
                        //
                        foreach (TypeContainer tc in type_container_resolve_order){
-                               if (tc.Kind == Kind.Struct && tc.Parent == tree.Types){
+                               if (tc.Kind == Kind.Struct && tc.Parent == root){
                                        tc.CloseType ();
                                }
                        }
 
                        foreach (TypeContainer tc in type_container_resolve_order){
-                               if (!(tc.Kind == Kind.Struct && tc.Parent == tree.Types))
+                               if (!(tc.Kind == Kind.Struct && tc.Parent == root))
                                        tc.CloseType ();                                        
                        }
                        
@@ -457,7 +469,7 @@ namespace Mono.CSharp {
                        //
                        if (helper_classes != null){
                                foreach (TypeBuilder type_builder in helper_classes) {
-#if NET_2_0
+#if GMCS_SOURCE
                                        type_builder.SetCustomAttribute (TypeManager.compiler_generated_attr);
 #endif
                                        type_builder.CreateType ();
@@ -466,7 +478,7 @@ namespace Mono.CSharp {
                        
                        type_container_resolve_order = null;
                        helper_classes = null;
-                       //tree = null;
+                       //root = null;
                        TypeManager.CleanUp ();
                }
 
@@ -492,8 +504,6 @@ namespace Mono.CSharp {
                
                static public void BootCorlib_PopulateCoreTypes ()
                {
-                       TypeContainer root = tree.Types;
-
                        PopulateCoreType (root, "System.Object");
                        PopulateCoreType (root, "System.ValueType");
                        PopulateCoreType (root, "System.Attribute");
@@ -508,9 +518,10 @@ namespace Mono.CSharp {
                // have been defined through `ResolveTree' 
                static public void PopulateTypes ()
                {
-                       TypeContainer root = Tree.Types;
 
                        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 ();
                        }
@@ -521,12 +532,6 @@ namespace Mono.CSharp {
                                        d.DefineMembers ();
                        }
 
-                       ArrayList enums = root.Enums;
-                       if (enums != null){
-                               foreach (Enum en in enums)
-                                       en.DefineMembers ();
-                       }
-
                        //
                        // Check for cycles in the struct layout
                        //
@@ -552,8 +557,6 @@ namespace Mono.CSharp {
                //
                static public void DefineTypes ()
                {
-                       TypeContainer root = Tree.Types;
-
                        ArrayList delegates = root.Delegates;
                        if (delegates != null){
                                foreach (Delegate d in delegates)
@@ -574,21 +577,10 @@ namespace Mono.CSharp {
                                        tc.Define ();
                                }
                        }
-
-                       ArrayList enums = root.Enums;
-                       if (enums != null){
-                               foreach (Enum en in enums)
-                                       en.Define ();
-                       }
                }
 
                static public void EmitCode ()
                {
-                       if (Tree.Types.Enums != null) {
-                               foreach (Enum e in Tree.Types.Enums)
-                                       e.Emit ();
-                       }
-
                        if (type_container_resolve_order != null) {
                                foreach (TypeContainer tc in type_container_resolve_order)
                                        tc.EmitType ();
@@ -600,8 +592,8 @@ namespace Mono.CSharp {
                                        tc.VerifyMembers ();
                        }
                        
-                       if (Tree.Types.Delegates != null) {
-                               foreach (Delegate d in Tree.Types.Delegates)
+                       if (root.Delegates != null) {
+                               foreach (Delegate d in root.Delegates)
                                        d.Emit ();
                        }                       
                        //
@@ -612,8 +604,8 @@ namespace Mono.CSharp {
                        if (EmitCodeHook != null)
                                EmitCodeHook ();
 
-                       CodeGen.Assembly.Emit (Tree.Types);
-                       CodeGen.Module.Emit (Tree.Types);
+                       CodeGen.Assembly.Emit (root);
+                       CodeGen.Module.Emit (root);
                }
                
                //