* MenuAPI.cs: On instance of MenuTracker check if source control is
[mono.git] / mcs / mcs / rootcontext.cs
index 6868ea9981063fd307168b47eb9446691bdef3e5..baa9af15093de05a3d5c76d8a3a2eb1c00fcf691 100644 (file)
@@ -2,7 +2,9 @@
 // rootcontext.cs: keeps track of our tree representation, and assemblies loaded.
 //
 // Author: Miguel de Icaza (miguel@ximian.com)
-//         Ravi Pratap     (ravi@ximian.com)
+//            Ravi Pratap  (ravi@ximian.com)
+//            Marek Safar  (marek.safar@gmail.com)
+//
 //
 // Licensed under the terms of the GNU GPL
 //
@@ -19,9 +21,16 @@ namespace Mono.CSharp {
 
        public enum LanguageVersion
        {
-               Default = 0,
-               ISO_1   = 1,
-               LINQ
+               ISO_1           = 1,
+               Default_MCS     = 2,
+               ISO_2           = 3,
+               LINQ            = 4,
+
+#if GMCS_SOURCE
+               Default         = LINQ
+#else
+               Default         = Default_MCS
+#endif
        }
 
        public class RootContext {
@@ -63,8 +72,6 @@ namespace Mono.CSharp {
                
                static TypeBuilder impl_details_class;
 
-               public static int WarningLevel;
-
                public static Target Target;
                public static string TargetExt;
 
@@ -105,7 +112,7 @@ namespace Mono.CSharp {
                        root = new RootTypes ();
                        type_container_resolve_order = new ArrayList ();
                        EntryPoint = null;
-                       WarningLevel = 3;
+                       Report.WarningLevel = 3;
                        Checked = false;
                        Unsafe = false;
                        StdLib = true;
@@ -159,20 +166,9 @@ namespace Mono.CSharp {
                        // a set of interfaces, we need to be able to tell
                        // them appart by just using the TypeManager.
                        //
-                       ArrayList ifaces = root.Interfaces;
-                       if (ifaces != null) {
-                               foreach (TypeContainer i in ifaces) 
-                                       i.CreateType ();
-                       }
-
                        foreach (TypeContainer tc in root.Types)
                                tc.CreateType ();
 
-                       if (ifaces != null) {
-                               foreach (TypeContainer i in ifaces) 
-                                       i.DefineType ();
-                       }
-
                        foreach (TypeContainer tc in root.Types)
                                tc.DefineType ();
 
@@ -181,96 +177,79 @@ namespace Mono.CSharp {
                                        d.DefineType ();
                }
 
-               static void Error_TypeConflict (string name, Location loc)
-               {
-                       Report.Error (
-                               520, loc, "`" + name + "' conflicts with a predefined type");
-               }
+               delegate bool VerifyBootstrapType (Type t);
 
-               static void Error_TypeConflict (string name)
+               static Type BootstrapCorlib_ResolveType (TypeContainer root, string name, VerifyBootstrapType typeVerifier)
                {
-                       Report.Error (
-                               520, "`" + name + "' conflicts with a predefined type");
-               }
-
-               //
-               // Resolves a single class during the corlib bootstrap process
-               //
-               static Type BootstrapCorlib_ResolveClass (TypeContainer root, string name)
-               {
-                       object o = root.GetDefinition (name);
-                       if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
+                       TypeLookupExpression tle = new TypeLookupExpression (name);
+                       Report.DisableReporting ();
+                       TypeExpr te = tle.ResolveAsTypeTerminal (root, false);
+                       Report.EnableReporting ();
+                       if (te == null) {
+                               Report.Error (518, "The predefined type `{0}' is not defined or imported", name);
                                return null;
                        }
 
-                       if (!(o is Class)){
-                               if (o is DeclSpace){
-                                       DeclSpace d = (DeclSpace) o;
-
-                                       Error_TypeConflict (name, d.Location);
-                               } else
-                                       Error_TypeConflict (name);
+                       Type t = te.Type;
+                       if (!typeVerifier (t)) {
+                               MemberCore mc = root.GetDefinition (name);
+                               Location loc = Location.Null;
+                               if (mc != null) {
+                                       name = mc.GetSignatureForError ();
+                                       loc = mc.Location;
+                               }
 
+                               Report.Error (520, loc, "The predefined type `{0}' is not declared correctly", name);
                                return null;
                        }
 
-                       Type t = ((DeclSpace) o).DefineType ();
-                       if (t != null)
-                               AttributeTester.RegisterNonObsoleteType (t);
+                       AttributeTester.RegisterNonObsoleteType (t);
                        return t;
                }
-
                //
-               // Resolves a struct during the corlib bootstrap process
+               // Resolves a single class during the corlib bootstrap process
                //
-               static void BootstrapCorlib_ResolveStruct (TypeContainer root, string name)
+               static Type BootstrapCorlib_ResolveClass (TypeContainer root, string name)
                {
-                       object o = root.GetDefinition (name);
-                       if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
-                               return;
-                       }
-
-                       if (!(o is Struct)){
-                               if (o is DeclSpace){
-                                       DeclSpace d = (DeclSpace) o;
-
-                                       Error_TypeConflict (name, d.Location);
-                               } else
-                                       Error_TypeConflict (name);
-
-                               return;
-                       }
+                       return BootstrapCorlib_ResolveType (root, name, IsClass);
+               }
 
-                       ((DeclSpace) o).DefineType ();
+               static bool IsClass (Type t)
+               {
+                       DeclSpace ds = TypeManager.LookupDeclSpace (t);
+                       if (ds != null)
+                               return ds is Class;
+                       return t.IsClass;
                }
 
                //
                // Resolves a struct during the corlib bootstrap process
                //
-               static void BootstrapCorlib_ResolveInterface (TypeContainer root, string name)
+               static Type BootstrapCorlib_ResolveStruct (TypeContainer root, string name)
                {
-                       object o = root.GetDefinition (name);
-                       if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
-                               return;
-                       }
-
-                       if (!(o is Interface)){
-                               if (o is DeclSpace){
-                                       DeclSpace d = (DeclSpace) o;
+                       return BootstrapCorlib_ResolveType (root, name, IsStruct);
+               }
 
-                                       Error_TypeConflict (name, d.Location);
-                               } else
-                                       Error_TypeConflict (name);
+               static bool IsStruct (Type t)
+               {
+                       DeclSpace ds = TypeManager.LookupDeclSpace (t);
+                       if (ds != null)
+                               return ds is Struct;
+                       
+                       return TypeManager.IsSubclassOf (t, TypeManager.value_type);                    
+               }
 
-                               return;
-                       }
+               //
+               // Resolves an interface during the corlib bootstrap process
+               //
+               static void BootstrapCorlib_ResolveInterface (TypeContainer root, string name)
+               {
+                       BootstrapCorlib_ResolveType (root, name, IsInterface);
+               }
 
-                       Type t = ((DeclSpace) o).DefineType ();
-                       if (t != null)
-                               AttributeTester.RegisterNonObsoleteType (t);
+               static bool IsInterface (Type t)
+               {
+                       return t.IsInterface;
                }
 
                //
@@ -278,20 +257,13 @@ namespace Mono.CSharp {
                //
                static void BootstrapCorlib_ResolveDelegate (TypeContainer root, string name)
                {
-                       object o = root.GetDefinition (name);
-                       if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
-                               return;
-                       }
-
-                       if (!(o is Delegate)){
-                               Error_TypeConflict (name);
-                               return;
-                       }
+                       BootstrapCorlib_ResolveType (root, name, IsDelegate);
+               }
 
-                       ((DeclSpace) o).DefineType ();
+               static bool IsDelegate (Type t)
+               {
+                       return TypeManager.IsDelegateType (t);
                }
-               
 
                /// <summary>
                ///    Resolves the core types in the compiler when compiling with --nostdlib
@@ -309,6 +281,11 @@ namespace Mono.CSharp {
                        BootstrapCorlib_ResolveInterface (root, "System.Runtime.InteropServices._Attribute");
                        TypeManager.attribute_type = BootstrapCorlib_ResolveClass (root, "System.Attribute");
                        TypeManager.obsolete_attribute_type = BootstrapCorlib_ResolveClass (root, "System.ObsoleteAttribute");
+                       if (TypeManager.obsolete_attribute_type != null) {
+                               Class c = TypeManager.LookupClass (TypeManager.obsolete_attribute_type);
+                               c.DefineMembers ();
+                       }
+                       
                        TypeManager.indexer_name_type = BootstrapCorlib_ResolveClass (root, "System.Runtime.CompilerServices.IndexerNameAttribute");
                        
                        string [] interfaces_first_stage = {
@@ -349,7 +326,7 @@ namespace Mono.CSharp {
                                "System.Int32",   "System.UInt32",
                                "System.Int64",   "System.UInt64",
                        };
-
+                       
                        foreach (string cname in structs_first_stage)
                                BootstrapCorlib_ResolveStruct (root, cname);
 
@@ -361,7 +338,7 @@ namespace Mono.CSharp {
 
                        string [] structs_second_stage = {
                                "System.Single",  "System.Double",
-                               "System.Char",    "System.Boolean",
+                               "System.Char",
                                "System.Decimal", "System.Void",
                                "System.RuntimeFieldHandle",
                                "System.RuntimeArgumentHandle",
@@ -371,6 +348,8 @@ namespace Mono.CSharp {
                                "System.ArgIterator"
                        };
                        
+                       TypeManager.bool_type = BootstrapCorlib_ResolveStruct (root, "System.Boolean");
+                       
                        foreach (string cname in structs_second_stage)
                                BootstrapCorlib_ResolveStruct (root, cname);
                        
@@ -432,13 +411,10 @@ namespace Mono.CSharp {
 #if GMCS_SOURCE
                        BootstrapCorlib_ResolveStruct (root, "System.Nullable`1");
 #endif
-                       BootstrapCorlib_ResolveDelegate (root, "System.AsyncCallback");
+                       TypeManager.delegate_type = BootstrapCorlib_ResolveClass (root, "System.Delegate");
+                       BootstrapCorlib_ResolveClass (root, "System.MulticastDelegate");
 
-                       // These will be defined indirectly during the previous ResolveDelegate.
-                       // However make sure the rest of the checks happen.
-                       string [] delegate_types = { "System.Delegate", "System.MulticastDelegate" };
-                       foreach (string cname in delegate_types)
-                               BootstrapCorlib_ResolveClass (root, cname);
+                       BootstrapCorlib_ResolveDelegate (root, "System.AsyncCallback");
                }
                        
                // <summary>
@@ -508,6 +484,9 @@ namespace Mono.CSharp {
                static public void PopulateCoreType (TypeContainer root, string name)
                {
                        DeclSpace ds = (DeclSpace) root.GetDefinition (name);
+                       // Core type was imported
+                       if (ds == null)
+                               return;
 
                        ds.DefineMembers ();
                        ds.Define ();