2006-05-01 Rafael Teixeira <rafaelteixeirabr@hotmail.com>
[mono.git] / mcs / gmcs / rootcontext.cs
index c4c064d0eaeea8adc8148ba46da55f91a4a6ba96..f5ad0c98a628e98b442f466f84a483d464fe13c3 100644 (file)
@@ -42,7 +42,7 @@ namespace Mono.CSharp {
                // This is only used to tell whether `System.Object' should
                // have a base class or not.
                //
-               public static bool StdLib = true;
+               public static bool StdLib;
 
                //
                // This keeps track of the order in which classes were defined
@@ -63,10 +63,10 @@ namespace Mono.CSharp {
                
                static TypeBuilder impl_details_class;
 
-               public static int WarningLevel = 3;
+               public static int WarningLevel;
 
-               public static Target Target = Target.Exe;
-               public static string TargetExt = ".exe";
+               public static Target Target;
+               public static string TargetExt;
 
                public static bool VerifyClsCompliance = true;
 
@@ -75,7 +75,7 @@ namespace Mono.CSharp {
                /// </summary>
                public static bool Optimize = true;
 
-               public static LanguageVersion Version = LanguageVersion.Default;
+               public static LanguageVersion Version;
 
                //
                // We keep strongname related info here because
@@ -83,20 +83,42 @@ namespace Mono.CSharp {
                //
                public static string StrongNameKeyFile;
                public static string StrongNameKeyContainer;
-               public static bool StrongNameDelaySign = false;
+               public static bool StrongNameDelaySign;
 
+               public static bool BrokenCircularDeps;
                //
                // If set, enable XML documentation generation
                //
                public static Documentation Documentation;
 
+               static public string MainClass;
+
                //
                // Constructor
                //
                static RootContext ()
+               {
+                       Reset ();
+               }
+
+               public static void Reset ()
                {
                        tree = new Tree ();
                        type_container_resolve_order = new ArrayList ();
+                       EntryPoint = null;
+                       WarningLevel = 3;
+                       Checked = false;
+                       Unsafe = false;
+                       StdLib = true;
+                       StrongNameKeyFile = null;
+                       StrongNameKeyContainer = null;
+                       StrongNameDelaySign = false;
+                       MainClass = null;
+                       Target = Target.Exe;
+                       TargetExt = ".exe";
+                       Version = LanguageVersion.Default;
+                       Documentation = null;
+                       impl_details_class = null;
                }
 
                public static bool NeedsEntryPoint {
@@ -111,8 +133,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               static public string MainClass;
-               
                public static void RegisterOrder (TypeContainer tc)
                {
                        type_container_resolve_order.Add (tc);
@@ -121,20 +141,13 @@ namespace Mono.CSharp {
                // 
                // The default compiler checked state
                //
-               static public bool Checked = false;
+               static public bool Checked;
 
                //
                // Whether to allow Unsafe code
                //
-               static public bool Unsafe = false;
+               static public bool Unsafe;
                
-               static string MakeFQN (string nsn, string name)
-               {
-                       if (nsn == "")
-                               return name;
-                       return String.Concat (nsn, ".", name);
-               }
-
                // <remarks>
                //   This function is used to resolve the hierarchy tree.
                //   It processes interfaces, structs and classes in that order.
@@ -154,7 +167,7 @@ namespace Mono.CSharp {
 
                        ArrayList ifaces = root.Interfaces;
                        if (ifaces != null){
-                               foreach (Interface i in ifaces) 
+                               foreach (TypeContainer i in ifaces) 
                                        i.DefineType ();
                        }
 
@@ -189,7 +202,7 @@ namespace Mono.CSharp {
                {
                        object o = root.GetDefinition (name);
                        if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined");
+                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
                                return null;
                        }
 
@@ -214,7 +227,7 @@ namespace Mono.CSharp {
                {
                        object o = root.GetDefinition (name);
                        if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined");
+                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
                                return;
                        }
 
@@ -239,7 +252,7 @@ namespace Mono.CSharp {
                {
                        object o = root.GetDefinition (name);
                        if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined");
+                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
                                return;
                        }
 
@@ -264,8 +277,8 @@ namespace Mono.CSharp {
                {
                        object o = root.GetDefinition (name);
                        if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined");
-                               Environment.Exit (1);
+                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
+                               return;
                        }
 
                        if (!(o is Delegate)){
@@ -285,7 +298,9 @@ namespace Mono.CSharp {
                        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;
                        TypeManager.attribute_type = BootstrapCorlib_ResolveClass (root, "System.Attribute");
                        TypeManager.indexer_name_type = BootstrapCorlib_ResolveClass (root, "System.Runtime.CompilerServices.IndexerNameAttribute");
                        
@@ -310,7 +325,7 @@ namespace Mono.CSharp {
                                // Generic types
                                //
                                "System.Collections.Generic.IEnumerator`1",
-                               "System.Collections.Generic.IEnumerable`1",
+                               "System.Collections.Generic.IEnumerable`1"
                        };
 
                        foreach (string iname in interfaces_first_stage)
@@ -374,7 +389,6 @@ namespace Mono.CSharp {
                                "System.Runtime.InteropServices.DllImportAttribute",
                                "System.Runtime.CompilerServices.MethodImplAttribute",
                                "System.Runtime.InteropServices.MarshalAsAttribute",
-                               "System.Runtime.CompilerServices.NewConstraintAttribute",
                                "System.Runtime.CompilerServices.CompilerGeneratedAttribute",
                                "System.Runtime.CompilerServices.FixedBufferAttribute",
                                "System.Diagnostics.ConditionalAttribute",
@@ -388,10 +402,14 @@ namespace Mono.CSharp {
                                "System.Runtime.InteropServices.OutAttribute",
                                "System.Runtime.InteropServices.StructLayoutAttribute",
                                "System.Runtime.InteropServices.FieldOffsetAttribute",
+                               "System.Runtime.InteropServices.DefaultCharSetAttribute",
                                "System.InvalidOperationException",
                                "System.NotSupportedException",
                                "System.MarshalByRefObject",
-                               "System.Security.CodeAccessPermission"
+                               "System.Security.CodeAccessPermission",
+                               "System.Runtime.CompilerServices.RequiredAttributeAttribute",
+                               "System.Runtime.InteropServices.GuidAttribute",
+                               "System.Reflection.AssemblyCultureAttribute"
                        };
 
                        foreach (string cname in classes_second_stage)
@@ -476,16 +494,11 @@ namespace Mono.CSharp {
                        helper_classes.Add (helper_class);
                }
                
-               static void Report1530 (Location loc)
-               {
-                       Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
-               }
-               
                static public void PopulateCoreType (TypeContainer root, string name)
                {
                        DeclSpace ds = (DeclSpace) root.GetDefinition (name);
 
-                       ds.DefineMembers (root);
+                       ds.DefineMembers ();
                        ds.Define ();
                }
                
@@ -510,40 +523,22 @@ namespace Mono.CSharp {
                        TypeContainer root = Tree.Types;
 
                        if (type_container_resolve_order != null){
-                               if (RootContext.StdLib){
-                                       foreach (TypeContainer tc in type_container_resolve_order)
-                                               tc.DefineMembers (root);
-                               } else {
-                                       foreach (TypeContainer tc in type_container_resolve_order) {
-                                               // When compiling corlib, these types have already been
-                                               // populated from BootCorlib_PopulateCoreTypes ().
-                                               if (((tc.Name == "System.Object") ||
-                                                       (tc.Name == "System.Attribute") ||
-                                                       (tc.Name == "System.ValueType") ||
-                                                       (tc.Name == "System.Runtime.CompilerServices.IndexerNameAttribute")))
-                                               continue;
-
-                                               tc.DefineMembers (root);
-                                       }
-                               } 
+                               foreach (TypeContainer tc in type_container_resolve_order)
+                                       tc.ResolveType ();
+                               foreach (TypeContainer tc in type_container_resolve_order)
+                                       tc.DefineMembers ();
                        }
 
                        ArrayList delegates = root.Delegates;
                        if (delegates != null){
                                foreach (Delegate d in delegates)
-                                       if ((d.ModFlags & Modifiers.NEW) == 0)
-                                               d.DefineMembers (root);
-                                       else
-                                               Report1530 (d.Location);
+                                       d.DefineMembers ();
                        }
 
                        ArrayList enums = root.Enums;
                        if (enums != null){
                                foreach (Enum en in enums)
-                                       if ((en.ModFlags & Modifiers.NEW) == 0)
-                                               en.DefineMembers (root);
-                                       else
-                                               Report1530 (en.Location);
+                                       en.DefineMembers ();
                        }
 
                        //
@@ -573,6 +568,12 @@ namespace Mono.CSharp {
                {
                        TypeContainer root = Tree.Types;
 
+                       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
@@ -584,23 +585,14 @@ namespace Mono.CSharp {
                                             (tc.Name == "System.Runtime.CompilerServices.IndexerNameAttribute")))
                                                continue;
 
-                                       if ((tc.ModFlags & Modifiers.NEW) == 0)
-                                               tc.Define ();
+                                       tc.Define ();
                                }
                        }
 
-                       ArrayList delegates = root.Delegates;
-                       if (delegates != null){
-                               foreach (Delegate d in delegates)
-                                       if ((d.ModFlags & Modifiers.NEW) == 0)
-                                               d.Define ();
-                       }
-
                        ArrayList enums = root.Enums;
                        if (enums != null){
                                foreach (Enum en in enums)
-                                       if ((en.ModFlags & Modifiers.NEW) == 0)
-                                               en.Define ();
+                                       en.Define ();
                        }
                }
 
@@ -614,6 +606,12 @@ namespace Mono.CSharp {
                        if (type_container_resolve_order != null) {
                                foreach (TypeContainer tc in type_container_resolve_order)
                                        tc.EmitType ();
+
+                               if (Report.Errors > 0)
+                                       return;
+
+                               foreach (TypeContainer tc in type_container_resolve_order)
+                                       tc.VerifyMembers ();
                        }
                        
                        if (Tree.Types.Delegates != null) {
@@ -681,6 +679,14 @@ namespace Mono.CSharp {
                        
                        return fb;
                }
+
+               public static void CheckUnsafeOption (Location loc)
+               {
+                       if (!Unsafe) {
+                               Report.Error (227, loc, 
+                                       "Unsafe code requires the `unsafe' command line option to be specified");
+                       }
+               }
        }
 }